PMCORE-4133
This commit is contained in:
@@ -215,9 +215,8 @@ class AppNotesTest extends TestCase
|
||||
'DOC_ID' => $appNote->NOTE_ID
|
||||
]);
|
||||
|
||||
$appUid = $appDocument->APP_UID;
|
||||
$appNotes = new ModelAppNotes();
|
||||
$result = $appNotes->getAttachedFilesFromTheCaseNote($appNote->NOTE_ID);
|
||||
$result = $appNotes->getAttachedFilesFromTheCaseNote($appNote->NOTE_ID, $appDocument->APP_UID);
|
||||
|
||||
$this->assertNotEmpty($result);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ class DocumentsTest extends TestCase
|
||||
$appDocument =Documents::factory()->create([
|
||||
'DOC_ID' => $appNote->NOTE_ID
|
||||
]);
|
||||
$result = Documents::getFiles($appDocument->DOC_ID);
|
||||
$result = Documents::getFiles($appDocument->DOC_ID, $appDocument->APP_UID);
|
||||
|
||||
$this->assertNotEmpty($result);
|
||||
}
|
||||
|
||||
@@ -3730,6 +3730,7 @@ class Cases
|
||||
if ($folderitem->filename == $aRow['APP_DOC_UID']) {
|
||||
$aFields['DOWNLOAD_LABEL'] = G::LoadTranslation('ID_GET_EXTERNAL_FILE');
|
||||
$aFields['DOWNLOAD_LINK'] = $folderitem->downloadScript;
|
||||
unset($aFields['NEWVERSION_LABEL'], $aFields['VERSIONHISTORY_LABEL']);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -3997,7 +3998,7 @@ class Cases
|
||||
$uploadReturn = $pluginRegistry->executeTriggers(PM_UPLOAD_DOCUMENT, $documentData);
|
||||
|
||||
if ($uploadReturn) {
|
||||
$arrayField["APP_DOC_PLUGIN"] = $triggerDetail->sNamespace;
|
||||
$arrayField["APP_DOC_PLUGIN"] = $triggerDetail->getNamespace();
|
||||
|
||||
if (!isset($arrayField["APP_DOC_UID"])) {
|
||||
$arrayField["APP_DOC_UID"] = $appDocUid;
|
||||
|
||||
@@ -6,7 +6,9 @@ use ProcessMaker\Core\System;
|
||||
use ProcessMaker\BusinessModel\DynaForm\SuggestTrait;
|
||||
use ProcessMaker\BusinessModel\Cases;
|
||||
use ProcessMaker\BusinessModel\DynaForm\ValidatorFactory;
|
||||
use ProcessMaker\Model\Documents;
|
||||
use ProcessMaker\Model\Dynaform as ModelDynaform;
|
||||
use ProcessMaker\Plugins\PluginRegistry;
|
||||
|
||||
/**
|
||||
* Implementing pmDynaform library in the running case.
|
||||
@@ -25,6 +27,7 @@ class PmDynaform
|
||||
private $propertiesToExclude = [];
|
||||
private $sysSys = null;
|
||||
private $fieldsAppData;
|
||||
private $filesFromPlugin = [Documents::DOC_TYPE_ATTACHED => null, Documents::DOC_TYPE_INPUT => null];
|
||||
public $credentials = null;
|
||||
public $displayMode = null;
|
||||
public $fields = null;
|
||||
@@ -567,6 +570,7 @@ class PmDynaform
|
||||
$oCriteriaAppDocument = new Criteria("workflow");
|
||||
$oCriteriaAppDocument->addSelectColumn(AppDocumentPeer::APP_DOC_UID);
|
||||
$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_DOC_FIELDNAME, $json->name);
|
||||
$oCriteriaAppDocument->add(AppDocumentPeer::APP_DOC_STATUS, 'ACTIVE');
|
||||
@@ -582,8 +586,44 @@ class PmDynaform
|
||||
$oAppDocument = new AppDocument();
|
||||
|
||||
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"]);
|
||||
$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();
|
||||
$appDocUids[] = $row["APP_DOC_UID"];
|
||||
}
|
||||
|
||||
@@ -670,25 +670,25 @@ class AppFolder extends BaseAppFolder
|
||||
|
||||
switch ($row4['OUT_DOC_GENERATE']) {
|
||||
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 = "";
|
||||
$downloadLabel = ".pdf";
|
||||
$downloadLabel1 = "";
|
||||
break;
|
||||
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 = "";
|
||||
$downloadLabel = ".doc";
|
||||
$downloadLabel1 = "";
|
||||
break;
|
||||
case "BOTH":
|
||||
$downloadLink = "../cases/cases_ShowOutputDocument?a=" . $appDocUid . "&v=" . $docVersion . "&ext=pdf" . "&random=" . rand();
|
||||
$downloadLink1 = "../cases/cases_ShowOutputDocument?a=" . $appDocUid . "&v=" . $docVersion . "&ext=doc" . "&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() . "&p=1";
|
||||
$downloadLabel = ".pdf";
|
||||
$downloadLabel1 = ".doc";
|
||||
break;
|
||||
case "NOFILE":
|
||||
$downloadLink = "../cases/cases_ShowDocument?a=" . $appDocUid . "&v=" . $docVersion;
|
||||
$downloadLink = "../cases/cases_ShowDocument?a=" . $appDocUid . "&v=" . $docVersion . "&p=1";
|
||||
$downloadLink1 = "";
|
||||
$downloadLabel = G::LoadTranslation("ID_DOWNLOAD");
|
||||
$downloadLabel1 = "";
|
||||
@@ -709,56 +709,23 @@ class AppFolder extends BaseAppFolder
|
||||
$row4 = array ();
|
||||
$versioningEnabled = false;
|
||||
}
|
||||
$downloadLink = "../cases/cases_ShowDocument?a=" . $appDocUid . "&v=" . $docVersion;
|
||||
$downloadLink = "../cases/cases_ShowDocument?a=" . $appDocUid . "&v=" . $docVersion . "&p=1";
|
||||
$downloadLink1 = "";
|
||||
$downloadLabel = G::LoadTranslation( 'ID_DOWNLOAD' );
|
||||
$downloadLabel1 = "";
|
||||
} else {
|
||||
$row4 = array ();
|
||||
$versioningEnabled = false;
|
||||
$downloadLink = "../cases/cases_ShowDocument?a=" . $appDocUid . "&v=" . $docVersion;
|
||||
$downloadLink = "../cases/cases_ShowDocument?a=" . $appDocUid . "&v=" . $docVersion . "&p=1";
|
||||
$downloadLink1 = "";
|
||||
$downloadLabel = G::LoadTranslation( 'ID_DOWNLOAD' );
|
||||
$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;
|
||||
default:
|
||||
$row4 = array ();
|
||||
$versioningEnabled = false;
|
||||
$downloadLink = "../cases/cases_ShowDocument?a=" . $appDocUid . "&v=" . $docVersion;
|
||||
$downloadLink = "../cases/cases_ShowDocument?a=" . $appDocUid . "&v=" . $docVersion . "&p=1";
|
||||
$downloadLink1 = "";
|
||||
$downloadLabel = G::LoadTranslation( 'ID_DOWNLOAD' );
|
||||
$downloadLabel1 = "";
|
||||
|
||||
@@ -227,7 +227,7 @@ class AppNotes extends BaseAppNotes
|
||||
|
||||
// Get the files related to the specific case note
|
||||
if ($noteId !== 0) {
|
||||
$attachFileLinks = $this->getAttachedFilesFromTheCaseNote($noteId);
|
||||
$attachFileLinks = $this->getAttachedFilesFromTheCaseNote($noteId, $appUid);
|
||||
}
|
||||
|
||||
if (!empty($attachFileLinks)) {
|
||||
@@ -282,15 +282,16 @@ class AppNotes extends BaseAppNotes
|
||||
/**
|
||||
* Get attached files from a specific case note
|
||||
* @param int $docId
|
||||
* @param string $appUid
|
||||
* @return array
|
||||
*/
|
||||
public function getAttachedFilesFromTheCaseNote(int $docId): array
|
||||
public function getAttachedFilesFromTheCaseNote(int $docId, string $appUid): array
|
||||
{
|
||||
$attachFileLinks = [];
|
||||
$url = System::getServerMainPath();
|
||||
$result = Documents::getFiles($docId);
|
||||
$result = Documents::getFiles($docId, $appUid);
|
||||
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>";
|
||||
}
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ class AppProxy extends HttpProxyController
|
||||
$iterator = 0;
|
||||
foreach ($response['notes'] as $value) {
|
||||
$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++;
|
||||
}
|
||||
// Get the total of cases notes by case
|
||||
|
||||
@@ -185,8 +185,11 @@ try {
|
||||
$filesPluginArray = $oPluginRegistry->executeTriggers(PM_CASE_DOCUMENT_LIST_ARR, $aFields['APP_UID']);
|
||||
//Now search for the file, if exists the change the download URL
|
||||
foreach ($filesPluginArray as $file) {
|
||||
if ($file->filename == $_POST['APP_DOC_UID']) {
|
||||
$aFields['FILE2'] = $file->downloadScript; // The PDF is the only one uploaded to KT
|
||||
if ($file->filename == $_POST['APP_DOC_UID'] && $file->type === 'DOC') {
|
||||
$aFields['FILE1'] = $file->downloadScript;
|
||||
}
|
||||
if ($file->filename == $_POST['APP_DOC_UID'] && $file->type === 'PDF') {
|
||||
$aFields['FILE2'] = $file->downloadScript;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2161,7 +2161,7 @@ class Cases
|
||||
$data[$iterator] = array_change_key_case($value, CASE_LOWER);
|
||||
$data[$iterator]['note_date'] = UtilDateTime::convertUtcToTimeZone($value['NOTE_DATE']);
|
||||
if ($files) {
|
||||
$data[$iterator]['attachments'] = $documents->getFiles($value['NOTE_ID']);
|
||||
$data[$iterator]['attachments'] = $documents->getFiles($value['NOTE_ID'], $appUid);
|
||||
}
|
||||
$iterator++;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
namespace ProcessMaker\Model;
|
||||
|
||||
use App\Factories\HasFactory;
|
||||
use folderData;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use ProcessMaker\Plugins\PluginRegistry;
|
||||
|
||||
class Documents extends Model
|
||||
{
|
||||
@@ -131,18 +133,47 @@ class Documents extends Model
|
||||
* Return the documents related to the specific DOC_ID
|
||||
*
|
||||
* @param int $docId
|
||||
* @param string $appUid
|
||||
*
|
||||
* @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->docId($docId);
|
||||
$results = $query->get();
|
||||
$documentList = [];
|
||||
$results->each(function ($item, $key) use (&$documentList) {
|
||||
$results->each(function ($item, $key) use (&$documentList, $elements) {
|
||||
$row = $item->toArray();
|
||||
$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;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user