PMCORE-4133

This commit is contained in:
Julio Cesar Laura Avendaño
2023-01-27 14:26:35 +00:00
parent d616dcfff1
commit 5ecc8752e5
10 changed files with 98 additions and 56 deletions

View File

@@ -215,9 +215,8 @@ class AppNotesTest extends TestCase
'DOC_ID' => $appNote->NOTE_ID 'DOC_ID' => $appNote->NOTE_ID
]); ]);
$appUid = $appDocument->APP_UID;
$appNotes = new ModelAppNotes(); $appNotes = new ModelAppNotes();
$result = $appNotes->getAttachedFilesFromTheCaseNote($appNote->NOTE_ID); $result = $appNotes->getAttachedFilesFromTheCaseNote($appNote->NOTE_ID, $appDocument->APP_UID);
$this->assertNotEmpty($result); $this->assertNotEmpty($result);
} }

View File

@@ -61,7 +61,7 @@ class DocumentsTest extends TestCase
$appDocument =Documents::factory()->create([ $appDocument =Documents::factory()->create([
'DOC_ID' => $appNote->NOTE_ID 'DOC_ID' => $appNote->NOTE_ID
]); ]);
$result = Documents::getFiles($appDocument->DOC_ID); $result = Documents::getFiles($appDocument->DOC_ID, $appDocument->APP_UID);
$this->assertNotEmpty($result); $this->assertNotEmpty($result);
} }

View File

@@ -3730,6 +3730,7 @@ class Cases
if ($folderitem->filename == $aRow['APP_DOC_UID']) { if ($folderitem->filename == $aRow['APP_DOC_UID']) {
$aFields['DOWNLOAD_LABEL'] = G::LoadTranslation('ID_GET_EXTERNAL_FILE'); $aFields['DOWNLOAD_LABEL'] = G::LoadTranslation('ID_GET_EXTERNAL_FILE');
$aFields['DOWNLOAD_LINK'] = $folderitem->downloadScript; $aFields['DOWNLOAD_LINK'] = $folderitem->downloadScript;
unset($aFields['NEWVERSION_LABEL'], $aFields['VERSIONHISTORY_LABEL']);
continue; continue;
} }
} }
@@ -3997,7 +3998,7 @@ class Cases
$uploadReturn = $pluginRegistry->executeTriggers(PM_UPLOAD_DOCUMENT, $documentData); $uploadReturn = $pluginRegistry->executeTriggers(PM_UPLOAD_DOCUMENT, $documentData);
if ($uploadReturn) { if ($uploadReturn) {
$arrayField["APP_DOC_PLUGIN"] = $triggerDetail->sNamespace; $arrayField["APP_DOC_PLUGIN"] = $triggerDetail->getNamespace();
if (!isset($arrayField["APP_DOC_UID"])) { if (!isset($arrayField["APP_DOC_UID"])) {
$arrayField["APP_DOC_UID"] = $appDocUid; $arrayField["APP_DOC_UID"] = $appDocUid;

View File

@@ -6,7 +6,9 @@ use ProcessMaker\Core\System;
use ProcessMaker\BusinessModel\DynaForm\SuggestTrait; use ProcessMaker\BusinessModel\DynaForm\SuggestTrait;
use ProcessMaker\BusinessModel\Cases; use ProcessMaker\BusinessModel\Cases;
use ProcessMaker\BusinessModel\DynaForm\ValidatorFactory; use ProcessMaker\BusinessModel\DynaForm\ValidatorFactory;
use ProcessMaker\Model\Documents;
use ProcessMaker\Model\Dynaform as ModelDynaform; use ProcessMaker\Model\Dynaform as ModelDynaform;
use ProcessMaker\Plugins\PluginRegistry;
/** /**
* Implementing pmDynaform library in the running case. * Implementing pmDynaform library in the running case.
@@ -25,6 +27,7 @@ class PmDynaform
private $propertiesToExclude = []; private $propertiesToExclude = [];
private $sysSys = null; private $sysSys = null;
private $fieldsAppData; private $fieldsAppData;
private $filesFromPlugin = [Documents::DOC_TYPE_ATTACHED => null, Documents::DOC_TYPE_INPUT => null];
public $credentials = null; public $credentials = null;
public $displayMode = null; public $displayMode = null;
public $fields = null; public $fields = null;
@@ -567,6 +570,7 @@ class PmDynaform
$oCriteriaAppDocument = new Criteria("workflow"); $oCriteriaAppDocument = new Criteria("workflow");
$oCriteriaAppDocument->addSelectColumn(AppDocumentPeer::APP_DOC_UID); $oCriteriaAppDocument->addSelectColumn(AppDocumentPeer::APP_DOC_UID);
$oCriteriaAppDocument->addSelectColumn(AppDocumentPeer::DOC_VERSION); $oCriteriaAppDocument->addSelectColumn(AppDocumentPeer::DOC_VERSION);
$oCriteriaAppDocument->addSelectColumn(AppDocumentPeer::APP_DOC_TYPE);
$oCriteriaAppDocument->add(AppDocumentPeer::APP_UID, $this->fields["APP_DATA"]["APPLICATION"]); $oCriteriaAppDocument->add(AppDocumentPeer::APP_UID, $this->fields["APP_DATA"]["APPLICATION"]);
$oCriteriaAppDocument->add(AppDocumentPeer::APP_DOC_FIELDNAME, $json->name); $oCriteriaAppDocument->add(AppDocumentPeer::APP_DOC_FIELDNAME, $json->name);
$oCriteriaAppDocument->add(AppDocumentPeer::APP_DOC_STATUS, 'ACTIVE'); $oCriteriaAppDocument->add(AppDocumentPeer::APP_DOC_STATUS, 'ACTIVE');
@@ -582,8 +586,44 @@ class PmDynaform
$oAppDocument = new AppDocument(); $oAppDocument = new AppDocument();
if ($row = $rs->getRow()) { if ($row = $rs->getRow()) {
// Only get the information from the plugin once
if (is_null($this->filesFromPlugin[$row['APP_DOC_TYPE']])) {
// Plugin Hook PM_CASE_DOCUMENT_LIST to get the files uploaded as attachments
$pluginRegistry = PluginRegistry::loadSingleton();
// If the hook exists try to execute
if ($pluginRegistry->existsTrigger(PM_CASE_DOCUMENT_LIST) && class_exists('folderData')) {
// Build the required object
$folderData = new folderData(null, null, $this->fields['APP_DATA']['APPLICATION'], null, null);
$folderData->PMType = $row['APP_DOC_TYPE'];
$folderData->returnList = true;
// Get elements
$this->filesFromPlugin[$row['APP_DOC_TYPE']] = $pluginRegistry->executeTriggers(PM_CASE_DOCUMENT_LIST, $folderData);
} else {
// If not exist, set an empty array
$this->filesFromPlugin[$row['APP_DOC_TYPE']] = [];
}
}
// Load document data
$oAppDocument->load($row["APP_DOC_UID"], $row["DOC_VERSION"]); $oAppDocument->load($row["APP_DOC_UID"], $row["DOC_VERSION"]);
$links[] = "../cases/cases_ShowDocument?a=" . $row["APP_DOC_UID"] . "&v=" . $row["DOC_VERSION"];
// Build the default link
$link = "../cases/cases_ShowDocument?a=" . $row["APP_DOC_UID"] . "&v=" . $row["DOC_VERSION"];
// If exist related file in the plugin, check if the file is the same
if (is_array($this->filesFromPlugin[$row['APP_DOC_TYPE']])) {
foreach ($this->filesFromPlugin[$row['APP_DOC_TYPE']] as $file) {
// If exists the same file, replace the download link
if ($file->filename === $row['APP_DOC_UID']) {
$link = $file->downloadScript;
continue;
}
}
}
// Set the link and another related information
$links[] = $link;
$labelsFromDb[] = $oAppDocument->getAppDocFilename(); $labelsFromDb[] = $oAppDocument->getAppDocFilename();
$appDocUids[] = $row["APP_DOC_UID"]; $appDocUids[] = $row["APP_DOC_UID"];
} }

View File

@@ -670,25 +670,25 @@ class AppFolder extends BaseAppFolder
switch ($row4['OUT_DOC_GENERATE']) { switch ($row4['OUT_DOC_GENERATE']) {
case "PDF": case "PDF":
$downloadLink = "../cases/cases_ShowOutputDocument?a=" . $appDocUid . "&v=" . $docVersion . "&ext=pdf" . "&random=" . rand(); $downloadLink = "../cases/cases_ShowOutputDocument?a=" . $appDocUid . "&v=" . $docVersion . "&ext=pdf" . "&random=" . rand() . "&p=1";
$downloadLink1 = ""; $downloadLink1 = "";
$downloadLabel = ".pdf"; $downloadLabel = ".pdf";
$downloadLabel1 = ""; $downloadLabel1 = "";
break; break;
case "DOC": case "DOC":
$downloadLink = "../cases/cases_ShowOutputDocument?a=" . $appDocUid . "&v=" . $docVersion . "&ext=doc" . "&random=" . rand(); $downloadLink = "../cases/cases_ShowOutputDocument?a=" . $appDocUid . "&v=" . $docVersion . "&ext=doc" . "&random=" . rand() . "&p=1";
$downloadLink1 = ""; $downloadLink1 = "";
$downloadLabel = ".doc"; $downloadLabel = ".doc";
$downloadLabel1 = ""; $downloadLabel1 = "";
break; break;
case "BOTH": case "BOTH":
$downloadLink = "../cases/cases_ShowOutputDocument?a=" . $appDocUid . "&v=" . $docVersion . "&ext=pdf" . "&random=" . rand(); $downloadLink = "../cases/cases_ShowOutputDocument?a=" . $appDocUid . "&v=" . $docVersion . "&ext=pdf" . "&random=" . rand() . "&p=1";
$downloadLink1 = "../cases/cases_ShowOutputDocument?a=" . $appDocUid . "&v=" . $docVersion . "&ext=doc" . "&random=" . rand(); $downloadLink1 = "../cases/cases_ShowOutputDocument?a=" . $appDocUid . "&v=" . $docVersion . "&ext=doc" . "&random=" . rand() . "&p=1";
$downloadLabel = ".pdf"; $downloadLabel = ".pdf";
$downloadLabel1 = ".doc"; $downloadLabel1 = ".doc";
break; break;
case "NOFILE": case "NOFILE":
$downloadLink = "../cases/cases_ShowDocument?a=" . $appDocUid . "&v=" . $docVersion; $downloadLink = "../cases/cases_ShowDocument?a=" . $appDocUid . "&v=" . $docVersion . "&p=1";
$downloadLink1 = ""; $downloadLink1 = "";
$downloadLabel = G::LoadTranslation("ID_DOWNLOAD"); $downloadLabel = G::LoadTranslation("ID_DOWNLOAD");
$downloadLabel1 = ""; $downloadLabel1 = "";
@@ -709,56 +709,23 @@ class AppFolder extends BaseAppFolder
$row4 = array (); $row4 = array ();
$versioningEnabled = false; $versioningEnabled = false;
} }
$downloadLink = "../cases/cases_ShowDocument?a=" . $appDocUid . "&v=" . $docVersion; $downloadLink = "../cases/cases_ShowDocument?a=" . $appDocUid . "&v=" . $docVersion . "&p=1";
$downloadLink1 = ""; $downloadLink1 = "";
$downloadLabel = G::LoadTranslation( 'ID_DOWNLOAD' ); $downloadLabel = G::LoadTranslation( 'ID_DOWNLOAD' );
$downloadLabel1 = ""; $downloadLabel1 = "";
} else { } else {
$row4 = array (); $row4 = array ();
$versioningEnabled = false; $versioningEnabled = false;
$downloadLink = "../cases/cases_ShowDocument?a=" . $appDocUid . "&v=" . $docVersion; $downloadLink = "../cases/cases_ShowDocument?a=" . $appDocUid . "&v=" . $docVersion . "&p=1";
$downloadLink1 = ""; $downloadLink1 = "";
$downloadLabel = G::LoadTranslation( 'ID_DOWNLOAD' ); $downloadLabel = G::LoadTranslation( 'ID_DOWNLOAD' );
$downloadLabel1 = ""; $downloadLabel1 = "";
} }
if (! empty( $row1["APP_DOC_PLUGIN"] )) {
$pluginRegistry = PluginRegistry::loadSingleton();
$pluginName = $row1["APP_DOC_PLUGIN"];
$fieldValue = "";
if (file_exists( PATH_PLUGINS . $pluginName . ".php" )) {
$pluginDetail = $pluginRegistry->getPluginDetails( $pluginName . ".php" );
if ($pluginDetail) {
if ($pluginDetail->isEnabled()) {
require_once (PATH_PLUGINS . $pluginName . ".php");
$pluginNameClass = $pluginName . "Plugin";
$objPluginClass = new $pluginNameClass( $pluginName );
if (isset( $objPluginClass->sMethodGetUrlDownload ) && ! empty( $objPluginClass->sMethodGetUrlDownload )) {
if (file_exists( PATH_PLUGINS . $pluginName . PATH_SEP . "class." . $pluginName . ".php" )) {
require_once (PATH_PLUGINS . $pluginName . PATH_SEP . "class." . $pluginName . ".php");
$pluginNameClass = $pluginName . "Class";
$objClass = new $pluginNameClass();
if (method_exists( $objClass, $objPluginClass->sMethodGetUrlDownload )) {
eval( "\$url = \$objClass->" . $objPluginClass->sMethodGetUrlDownload . "(\"" . $row1["APP_DOC_UID"] . "\");" );
$downloadLink = $url;
$fieldValue = $row1["APP_DOC_PLUGIN"];
}
}
}
}
}
}
$row1["APP_DOC_PLUGIN"] = $fieldValue;
}
break; break;
default: default:
$row4 = array (); $row4 = array ();
$versioningEnabled = false; $versioningEnabled = false;
$downloadLink = "../cases/cases_ShowDocument?a=" . $appDocUid . "&v=" . $docVersion; $downloadLink = "../cases/cases_ShowDocument?a=" . $appDocUid . "&v=" . $docVersion . "&p=1";
$downloadLink1 = ""; $downloadLink1 = "";
$downloadLabel = G::LoadTranslation( 'ID_DOWNLOAD' ); $downloadLabel = G::LoadTranslation( 'ID_DOWNLOAD' );
$downloadLabel1 = ""; $downloadLabel1 = "";

View File

@@ -227,7 +227,7 @@ class AppNotes extends BaseAppNotes
// Get the files related to the specific case note // Get the files related to the specific case note
if ($noteId !== 0) { if ($noteId !== 0) {
$attachFileLinks = $this->getAttachedFilesFromTheCaseNote($noteId); $attachFileLinks = $this->getAttachedFilesFromTheCaseNote($noteId, $appUid);
} }
if (!empty($attachFileLinks)) { if (!empty($attachFileLinks)) {
@@ -282,15 +282,16 @@ class AppNotes extends BaseAppNotes
/** /**
* Get attached files from a specific case note * Get attached files from a specific case note
* @param int $docId * @param int $docId
* @param string $appUid
* @return array * @return array
*/ */
public function getAttachedFilesFromTheCaseNote(int $docId): array public function getAttachedFilesFromTheCaseNote(int $docId, string $appUid): array
{ {
$attachFileLinks = []; $attachFileLinks = [];
$url = System::getServerMainPath(); $url = System::getServerMainPath();
$result = Documents::getFiles($docId); $result = Documents::getFiles($docId, $appUid);
foreach ($result as $item) { foreach ($result as $item) {
$href = $url . "/cases/casesShowCaseNotes?a={$item['APP_DOC_UID']}&v={$item['DOC_VERSION']}"; $href = $url . str_replace('../', '/', $item['LINK']);
$attachFileLinks[] = "<a href='{$href}'>{$item['APP_DOC_FILENAME']}</a>"; $attachFileLinks[] = "<a href='{$href}'>{$item['APP_DOC_FILENAME']}</a>";
} }

View File

@@ -128,7 +128,7 @@ class AppProxy extends HttpProxyController
$iterator = 0; $iterator = 0;
foreach ($response['notes'] as $value) { foreach ($response['notes'] as $value) {
$response['notes'][$iterator]['NOTE_DATE'] = DateTime::convertUtcToTimeZone($value['NOTE_DATE']); $response['notes'][$iterator]['NOTE_DATE'] = DateTime::convertUtcToTimeZone($value['NOTE_DATE']);
$response['notes'][$iterator]['attachments'] = $documents->getFiles($value['NOTE_ID']); $response['notes'][$iterator]['attachments'] = $documents->getFiles($value['NOTE_ID'], $appUid);
$iterator++; $iterator++;
} }
// Get the total of cases notes by case // Get the total of cases notes by case

View File

@@ -185,8 +185,11 @@ try {
$filesPluginArray = $oPluginRegistry->executeTriggers(PM_CASE_DOCUMENT_LIST_ARR, $aFields['APP_UID']); $filesPluginArray = $oPluginRegistry->executeTriggers(PM_CASE_DOCUMENT_LIST_ARR, $aFields['APP_UID']);
//Now search for the file, if exists the change the download URL //Now search for the file, if exists the change the download URL
foreach ($filesPluginArray as $file) { foreach ($filesPluginArray as $file) {
if ($file->filename == $_POST['APP_DOC_UID']) { if ($file->filename == $_POST['APP_DOC_UID'] && $file->type === 'DOC') {
$aFields['FILE2'] = $file->downloadScript; // The PDF is the only one uploaded to KT $aFields['FILE1'] = $file->downloadScript;
}
if ($file->filename == $_POST['APP_DOC_UID'] && $file->type === 'PDF') {
$aFields['FILE2'] = $file->downloadScript;
} }
} }
} }

View File

@@ -2161,7 +2161,7 @@ class Cases
$data[$iterator] = array_change_key_case($value, CASE_LOWER); $data[$iterator] = array_change_key_case($value, CASE_LOWER);
$data[$iterator]['note_date'] = UtilDateTime::convertUtcToTimeZone($value['NOTE_DATE']); $data[$iterator]['note_date'] = UtilDateTime::convertUtcToTimeZone($value['NOTE_DATE']);
if ($files) { if ($files) {
$data[$iterator]['attachments'] = $documents->getFiles($value['NOTE_ID']); $data[$iterator]['attachments'] = $documents->getFiles($value['NOTE_ID'], $appUid);
} }
$iterator++; $iterator++;
} }

View File

@@ -3,7 +3,9 @@
namespace ProcessMaker\Model; namespace ProcessMaker\Model;
use App\Factories\HasFactory; use App\Factories\HasFactory;
use folderData;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use ProcessMaker\Plugins\PluginRegistry;
class Documents extends Model class Documents extends Model
{ {
@@ -131,18 +133,47 @@ class Documents extends Model
* Return the documents related to the specific DOC_ID * Return the documents related to the specific DOC_ID
* *
* @param int $docId * @param int $docId
* @param string $appUid
* *
* @return array * @return array
*/ */
public static function getFiles(int $docId) public static function getFiles(int $docId, string $appUid)
{ {
// Initializing variables
$elements = null;
// Plugin Hook PM_CASE_DOCUMENT_LIST to get the files uploaded in the case notes
$pluginRegistry = PluginRegistry::loadSingleton();
// If the hook exists try to execute
if ($pluginRegistry->existsTrigger(PM_CASE_DOCUMENT_LIST) && class_exists('folderData')) {
// Build the required object
$folderData = new folderData(null, null, $appUid, null, null);
$folderData->PMType = self::DOC_TYPE_CASE_NOTE;
$folderData->returnList = true;
// Get elements
$elements = $pluginRegistry->executeTriggers(PM_CASE_DOCUMENT_LIST, $folderData);
}
$query = Documents::query()->select(['APP_DOC_UID', 'APP_DOC_FILENAME', 'DOC_VERSION']); $query = Documents::query()->select(['APP_DOC_UID', 'APP_DOC_FILENAME', 'DOC_VERSION']);
$query->docId($docId); $query->docId($docId);
$results = $query->get(); $results = $query->get();
$documentList = []; $documentList = [];
$results->each(function ($item, $key) use (&$documentList) { $results->each(function ($item, $key) use (&$documentList, $elements) {
$row = $item->toArray(); $row = $item->toArray();
$row['LINK'] = "../cases/casesShowCaseNotes?a=" . $row["APP_DOC_UID"] . "&v=" . $row["DOC_VERSION"]; $row['LINK'] = "../cases/casesShowCaseNotes?a=" . $row["APP_DOC_UID"] . "&v=" . $row["DOC_VERSION"];
// If an element match, replace the link and exit from the loop
if (!empty($elements) && is_array($elements)) {
foreach ($elements as $element) {
if ($element->filename === $row['APP_DOC_UID']) {
$row['LINK'] = $element->downloadScript;
continue;
}
}
}
$documentList[] = $row; $documentList[] = $row;
}); });