PMCORE-1542
This commit is contained in:
@@ -41,7 +41,9 @@ use ProcessMaker\BusinessModel\User as BmUser;
|
||||
use ProcessMaker\Core\System;
|
||||
use ProcessMaker\Exception\UploadException;
|
||||
use ProcessMaker\Model\Application as ModelApplication;
|
||||
use ProcessMaker\Model\AppNotes;
|
||||
use ProcessMaker\Model\Delegation;
|
||||
use ProcessMaker\Model\Documents;
|
||||
use ProcessMaker\Plugins\PluginRegistry;
|
||||
use ProcessMaker\Services\OAuth2\Server;
|
||||
use ProcessMaker\Util\DateTime as UtilDateTime;
|
||||
@@ -3843,6 +3845,138 @@ class Cases
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a case note
|
||||
*
|
||||
* @param string $appUid
|
||||
* @param string $userUid
|
||||
* @param string $note
|
||||
* @param bool $sendMail
|
||||
* @param array $files
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function addNote($appUid, $userUid, $note, $sendMail = false, $files = [])
|
||||
{
|
||||
// Register the note
|
||||
$attributes = [
|
||||
"APP_UID" => $appUid,
|
||||
"USR_UID" => $userUid,
|
||||
"NOTE_DATE" => date("Y-m-d H:i:s"),
|
||||
"NOTE_CONTENT" => $note,
|
||||
"NOTE_TYPE" => "USER",
|
||||
"NOTE_AVAILABILITY" => "PUBLIC",
|
||||
"NOTE_RECIPIENTS" => ""
|
||||
];
|
||||
$response = AppNotes::create($attributes);
|
||||
// Get the FK
|
||||
$noteId = $response->NOTE_ID;
|
||||
|
||||
// Register the files related to the note
|
||||
$this->uploadFilesInCaseNotes($userUid, $appUid, $files, $noteId);
|
||||
|
||||
// Send the email
|
||||
if ($sendMail) {
|
||||
// @todo refactor this section the files attached need to send in the email
|
||||
$case = new ClassesCases();
|
||||
$p = $case->getUsersParticipatedInCase($appUid, 'ACTIVE');
|
||||
$noteRecipientsList = [];
|
||||
|
||||
foreach ($p["array"] as $key => $userParticipated) {
|
||||
if ($key != '') {
|
||||
$noteRecipientsList[] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
$noteRecipients = implode(",", $noteRecipientsList);
|
||||
$note = stripslashes($note);
|
||||
|
||||
$note = new \AppNotes();
|
||||
$note->sendNoteNotification($appUid, $userUid, $note, $noteRecipients);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload file related to the case notes
|
||||
*
|
||||
* @param string $userUid
|
||||
* @param string $appUid
|
||||
* @param array $filesReferences
|
||||
* @param string $appDocUid
|
||||
*
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function uploadFilesInCaseNotes($userUid, $appUid, $filesReferences = [], $noteId = 0)
|
||||
{
|
||||
if (!empty($_FILES["form"]["name"])) {
|
||||
$upload = true;
|
||||
// Array from post upload
|
||||
foreach ($_FILES["form"]["name"] as $fileIndex => $fileName) {
|
||||
if (!is_array($fileName)) {
|
||||
$files[] = [
|
||||
'name' => $_FILES["form"]["name"][$fileIndex],
|
||||
'tmp_name' => $_FILES["form"]["tmp_name"][$fileIndex],
|
||||
'error' => $_FILES["form"]["error"][$fileIndex]
|
||||
];
|
||||
}
|
||||
}
|
||||
} elseif (!empty($filesReferences)) {
|
||||
$upload = false;
|
||||
// Array with path references
|
||||
foreach ($filesReferences as $fileIndex => $fileName) {
|
||||
$nameFile = !is_numeric($fileIndex) ? basename($fileIndex) : basename($fileName);
|
||||
$files[] = [
|
||||
'name' => $nameFile,
|
||||
'tmp_name' => $fileName,
|
||||
'error' => UPLOAD_ERR_OK
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Get the delIndex related to the case
|
||||
$cases = new ClassesCases();
|
||||
$delIndex = $cases->getCurrentDelegation($appUid);
|
||||
|
||||
// We will to register the files in the database
|
||||
$response = [];
|
||||
if (!empty($files)) {
|
||||
$i = 0;
|
||||
foreach ($files as $fileIndex => $fileName) {
|
||||
// There is no error, the file uploaded with success
|
||||
if ($fileName["error"] === UPLOAD_ERR_OK) {
|
||||
$appDocUid = G::generateUniqueID();
|
||||
$attributes = [
|
||||
"DOC_ID" => $noteId,
|
||||
"APP_DOC_UID" => $appDocUid,
|
||||
"DOC_VERSION" => 1,
|
||||
"APP_UID" => $appUid,
|
||||
"DEL_INDEX" => $delIndex,
|
||||
"USR_UID" => $userUid,
|
||||
"DOC_UID" => -1,
|
||||
"APP_DOC_TYPE" => 'CASE_NOTE',
|
||||
"APP_DOC_CREATE_DATE" => date("Y-m-d H:i:s"),
|
||||
"APP_DOC_FILENAME" => $fileName["name"]
|
||||
];
|
||||
Documents::create($attributes);
|
||||
|
||||
// Upload or move the file
|
||||
$isUploaded = saveAppDocument($fileName, $appUid, $appDocUid, 1, $upload);
|
||||
|
||||
// List of files uploaded or copy
|
||||
$response[$i++] = $attributes;
|
||||
} else {
|
||||
throw new UploadException($fileName['error']);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new Exception(G::LoadTranslation('ID_ERROR_UPLOAD_FILE_CONTACT_ADMINISTRATOR'));
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the validations related to an Input Document
|
||||
*
|
||||
|
||||
@@ -6,6 +6,42 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class AppNotes extends Model
|
||||
{
|
||||
// Set our table name
|
||||
protected $table = 'APP_NOTES';
|
||||
// No timestamps
|
||||
public $timestamps = false;
|
||||
// Primary key
|
||||
protected $primaryKey = 'NOTE_ID';
|
||||
// The IDs are auto-incrementing
|
||||
public $incrementing = true;
|
||||
|
||||
/**
|
||||
* The model's default values for attributes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $attributes = [
|
||||
'NOTE_TYPE' => 'USER',
|
||||
'NOTE_ORIGIN_OBJ' => '',
|
||||
'NOTE_AFFECTED_OBJ1' => '',
|
||||
'NOTE_AFFECTED_OBJ2' => ''
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'APP_UID',
|
||||
'USR_UID',
|
||||
'NOTE_DATE',
|
||||
'NOTE_CONTENT',
|
||||
'NOTE_TYPE',
|
||||
'NOTE_AVAILABILITY',
|
||||
'NOTE_ORIGIN_OBJ',
|
||||
'NOTE_AFFECTED_OBJ1',
|
||||
'NOTE_AFFECTED_OBJ2',
|
||||
'NOTE_RECIPIENTS'
|
||||
];
|
||||
}
|
||||
|
||||
96
workflow/engine/src/ProcessMaker/Model/Documents.php
Normal file
96
workflow/engine/src/ProcessMaker/Model/Documents.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\Model;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Documents extends Model
|
||||
{
|
||||
// Set our table name
|
||||
protected $table = 'APP_DOCUMENT';
|
||||
// No timestamps
|
||||
public $timestamps = false;
|
||||
// Primary key
|
||||
protected $primaryKey = 'NOTE_ID';
|
||||
// The IDs are auto-incrementing
|
||||
public $incrementing = false;
|
||||
// Valid AppDocType's
|
||||
const DOC_TYPE_ATTACHED = 'ATTACHED';
|
||||
const DOC_TYPE_CASE_NOTE = 'CASE_NOTE';
|
||||
const DOC_TYPE_INPUT = 'INPUT';
|
||||
const DOC_TYPE_OUTPUT = 'OUTPUT';
|
||||
|
||||
/**
|
||||
* The model's default values for attributes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $attributes = [
|
||||
'APP_DOC_TITLE' => '',
|
||||
'APP_DOC_COMMENT' => '',
|
||||
'DOC_UID' => '-1',
|
||||
'FOLDER_UID' => '',
|
||||
'APP_DOC_PLUGIN' => '',
|
||||
'APP_DOC_TAGS' => '',
|
||||
'APP_DOC_FIELDNAME' => '',
|
||||
'APP_DOC_DRIVE_DOWNLOAD' => 'a:0:{}',
|
||||
'SYNC_WITH_DRIVE' => 'UNSYNCHRONIZED',
|
||||
'SYNC_PERMISSIONS' => '',
|
||||
'APP_DOC_STATUS_DATE' => '',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'DOC_ID',
|
||||
'APP_DOC_UID',
|
||||
'DOC_VERSION',
|
||||
'APP_DOC_FILENAME',
|
||||
'APP_UID',
|
||||
'DEL_INDEX',
|
||||
'DOC_UID',
|
||||
'USR_UID',
|
||||
'APP_DOC_TYPE',
|
||||
'APP_DOC_CREATE_DATE',
|
||||
'APP_DOC_INDEX',
|
||||
'FOLDER_UID',
|
||||
'APP_DOC_STATUS',
|
||||
];
|
||||
|
||||
/**
|
||||
* Scope a query to filter an specific case
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param string $proUid
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeAppUid($query, string $appUid)
|
||||
{
|
||||
return $query->where('APP_UID', $appUid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the documents related to the case
|
||||
*
|
||||
* @param int $proId
|
||||
* @param string $type
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getAppFiles(string $appUid, $type = 'CASE_NOTES')
|
||||
{
|
||||
$query = Documents::query()->select();
|
||||
$query->appUid($appUid);
|
||||
$query->where('APP_DOC_TYPE', $type);
|
||||
$results = $query->get();
|
||||
$documentList = [];
|
||||
$results->each(function ($item, $key) use (&$documentList) {
|
||||
$documentList[] = $item->toArray();
|
||||
});
|
||||
|
||||
return $documentList;
|
||||
}
|
||||
}
|
||||
@@ -601,3 +601,39 @@ function getMysqlVersion()
|
||||
|
||||
return $mysqlVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the uploaded file to the documents folder
|
||||
*
|
||||
* @param array $file
|
||||
* @param string $appUid
|
||||
* @param string $appDocUid
|
||||
* @param int $version
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function saveAppDocument($file, $appUid, $appDocUid, $version = 1, $upload = true)
|
||||
{
|
||||
try {
|
||||
$info = pathinfo($file["name"]);
|
||||
$extension = ((isset($info["extension"])) ? $info["extension"] : "");
|
||||
//$pathCase = G::getPathFromUID($appUid);
|
||||
$fileName = $appDocUid . "_" . $version . "." . $extension;
|
||||
|
||||
$pathCase = PATH_DATA_SITE . 'files' . PATH_SEP . G::getPathFromUID($appUid) . PATH_SEP;
|
||||
|
||||
$response = false;
|
||||
if ($upload) {
|
||||
$response = G::uploadFile(
|
||||
$file["tmp_name"],
|
||||
$pathCase,
|
||||
$fileName
|
||||
);
|
||||
} else {
|
||||
G::verifyPath($pathCase, true);
|
||||
$response = copy($file["tmp_name"], $pathCase . $fileName);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user