diff --git a/composer.json b/composer.json index 7db9c232b8b06a1084a82e61a961cadb9ed2b388..695651fb9f1b7acca3ae9b0d139eb489a475470e 100755 --- a/composer.json +++ b/composer.json @@ -3,6 +3,7 @@ "psr-4": { "SrcCore\\" : "src/core/", "Action\\" : "src/app/action/", + "Attachment\\" : "src/app/attachment/", "Basket\\" : "src/app/basket/", "Contact\\" : "src/app/contact/", "Docserver\\" : "src/app/docserver/", diff --git a/modules/attachments/Controllers/AttachmentsController.php b/modules/attachments/Controllers/AttachmentsController.php deleted file mode 100755 index 4073beffb0ff0bd1b383b8407d9be286dfdb7ac4..0000000000000000000000000000000000000000 --- a/modules/attachments/Controllers/AttachmentsController.php +++ /dev/null @@ -1,440 +0,0 @@ -<?php - -/** -* Copyright Maarch since 2008 under licence GPLv3. -* See LICENCE.txt file at the root folder for more details. -* This file is part of Maarch software. -* -*/ - -/** -* @brief Attachments Controller -* @author dev@maarch.org -* @ingroup attachments -*/ - -namespace Attachments\Controllers; - -use SrcCore\controllers\StoreController; -use Psr\Http\Message\RequestInterface; -use Psr\Http\Message\ResponseInterface; -use Respect\Validation\Validator; -use Attachments\Models\AttachmentsModel; -use Core\Controllers\ResController; - -class AttachmentsController -{ - - public function storeAttachmentResource($aArgs) - { - if (empty($aArgs['resId'])) { - - return ['errors' => 'resId ' . _EMPTY]; - } - - if (empty($aArgs['encodedFile'])) { - - return ['errors' => 'encodedFile ' . _EMPTY]; - } - - if (empty($aArgs['data'])) { - - return ['errors' => 'data ' . _EMPTY]; - } - - if (empty($aArgs['collId'])) { - - return ['errors' => 'collId ' . _EMPTY]; - } - - if (empty($aArgs['collIdMaster'])) { - - return ['errors' => 'collIdMaster ' . _EMPTY]; - } - - if (empty($aArgs['table'])) { - - return ['errors' => 'table ' . _EMPTY]; - } - - if (empty($aArgs['fileFormat'])) { - - return ['errors' => 'fileFormat ' . _EMPTY]; - } - - $resId = $aArgs['resId']; - $encodedFile = $aArgs['encodedFile']; - $collId = $aArgs['collId']; - $collIdMaster = $aArgs['collIdMaster']; - $table = $aArgs['table']; - $fileFormat = $aArgs['fileFormat']; - - $aArgs = [ - 'data' => $aArgs['data'], - 'collIdMaster' => $collIdMaster, - 'resId' => $resId, - ]; - - $returnPrepare = $this->prepareStorage($aArgs); - - $aArgs = [ - 'encodedFile' => $encodedFile, - 'data' => $returnPrepare['data'], - 'collId' => $collId, - 'table' => $table, - 'fileFormat' => $fileFormat, - 'status' => $returnPrepare['status'], - ]; - - $response = StoreController::storeResource($aArgs); - - //return $response; - if (!is_numeric($response[0])) { - - return ['errors' => 'Pb with SQL insertion : ' . $response[0]]; - } else { - require_once 'core/class/class_history.php'; - require_once 'core/class/class_security.php'; - $hist = new \history(); - $sec = new \security(); - $view = $sec->retrieve_view_from_coll_id($collIdMaster); - - $hist->add( - $view, $resId, "ADD", 'attachadd', - ucfirst(_DOC_NUM) . $response[0] . ' ' - . _NEW_ATTACH_ADDED . ' ' . _TO_MASTER_DOCUMENT - . $resId, - $_SESSION['config']['databasetype'], - 'apps' - ); - $hist->add( - $table, $response[0], "ADD",'attachadd', - _NEW_ATTACH_ADDED, - $_SESSION['config']['databasetype'], - 'attachments' - ); - } - - if ($response[0] == 0) { - $response[0] = ''; - } - - return [$response[0]]; - } - - /** - * Prepares storage on database. - * @param $data array - * @param $resId bigint - * @param $collIdMaster string - * @return array $data - */ - public function prepareStorage($aArgs) - { - if (empty($aArgs['data'])) { - - return ['errors' => 'data ' . _EMPTY]; - } - - if (empty($aArgs['resId'])) { - - return ['errors' => 'resId ' . _EMPTY]; - } - - if (empty($aArgs['collIdMaster'])) { - - return ['errors' => 'collIdMaster ' . _EMPTY]; - } - - $statusFound = false; - $typistFound = false; - $typeIdFound = false; - $attachmentTypeFound = false; - - $data = $aArgs['data']; - - $countD = count($data); - for ($i=0;$i<$countD;$i++) { - - if ( - strtoupper($data[$i]['type']) == 'INTEGER' || - strtoupper($data[$i]['type']) == 'FLOAT' - ) { - if ($data[$i]['value'] == '') { - $data[$i]['value'] = '0'; - } - } - - if (strtoupper($data[$i]['type']) == 'STRING') { - $data[$i]['value'] = str_replace(";", "", $data[$i]['value']); - $data[$i]['value'] = str_replace("--", "", $data[$i]['value']); - } - - if (strtoupper($data[$i]['column']) == strtoupper('status')) { - $statusFound = true; - $status = $data[$i]['value']; - } - - if (strtoupper($data[$i]['column']) == strtoupper('typist')) { - $typistFound = true; - } - - if (strtoupper($data[$i]['column']) == strtoupper('type_id')) { - $typeIdFound = true; - } - - if (strtoupper($data[$i]['column']) == strtoupper('attachment_type')) { - $attachmentTypeFound = true; - } - } - - if (!$typistFound) { - array_push( - $data, - array( - 'column' => 'typist', - 'value' => $_SESSION['user']['UserId'], - 'type' => 'string', - ) - ); - } - - if (!$typeIdFound) { - array_push( - $data, - array( - 'column' => 'type_id', - 'value' => 0, - 'type' => 'int', - ) - ); - } - - if (!$statusFound) { - array_push( - $data, - array( - 'column' => 'status', - 'value' => 'NEW', - 'type' => 'string', - ) - ); - $status = 'NEW'; - } - - if (!$attachmentTypeFound) { - array_push( - $data, - array( - 'column' => 'attachment_type', - 'value' => 'response_project', - 'type' => 'string', - ) - ); - } - - //BASICS - array_push( - $data, - array( - 'column' => "coll_id", - 'value' => $aArgs['collIdMaster'], - 'type' => "string", - ) - ); - - array_push( - $data, - array( - 'column' => "res_id_master", - 'value' => $aArgs['resId'], - 'type' => "integer", - ) - ); - - array_push( - $data, - array( - 'column' => "relation", - 'value' => 1, - 'type' => "integer", - ) - ); - - $return = [ - 'data' => $data, - 'status' => $status, - ]; - - return $return; - } - - /** - * Prepares storage for transmission. - * @param $nb integer - * @return array $data - */ - public function setTransmissionData($aArgs) - { - if (empty($aArgs['nb'])) { - - return ['errors' => 'nb ' . _EMPTY]; - } - - $transmissionData = []; - - $transmissionData[] = [ - 'column' => 'format', - 'value' => $_SESSION['upfileTransmission'][$nb]['format'], - 'type' => 'string' - ]; - - if (!empty($_REQUEST["transmissionExpectedDate{$nb}"])) { - $rturn = $_REQUEST["transmissionExpectedDate{$nb}"]; - } else { - $rturn = 'NO_RTURN'; - } - //TODO - $transmissionData[] = [ - 'column' => 'status', - 'value' => $rturn, - 'type' => 'string' - ]; - - $transmissionData[] = [ - 'column' => 'title', - 'value' => str_replace("'", "'", $_REQUEST["transmissionTitle{$nb}"]), - 'type' => 'string' - ]; - $transmissionData[] = [ - 'column' => 'attachment_type', - 'value' => $_REQUEST["transmissionType{$nb}"], - 'type' => 'string' - ]; - $transmissionData[] = [ - 'column' => 'coll_id', - 'value' => $_SESSION['collection_id_choice'], - 'type' => 'string' - ]; - //TODO - $transmissionData[] = [ - 'column' => 'res_id_master', - 'value' => $_SESSION['doc_id'], - 'type' => 'integer' - ]; - $transmissionData[] = [ - 'column' => 'identifier', - 'value' => $_REQUEST["transmissionChrono{$nb}"], - 'type' => 'string' - ]; - - if (!empty($_REQUEST["transmissionBackDate{$nb}"])) { - $transmissionData[] = [ - 'column' => 'validation_date', - 'value' => $_REQUEST["transmissionBackDate{$nb}"], - 'type' => 'date' - ]; - } - - if ( - !empty($_REQUEST["transmissionContactidAttach{$nb}"]) && - is_numeric($_REQUEST["transmissionContactidAttach{$nb}"]) - ) { - $transmissionData[] = [ - 'column' => 'dest_contact_id', - 'value' => $_REQUEST["transmissionContactidAttach{$nb}"], - 'type' => 'integer' - ]; - } else if ( - !empty($_REQUEST["transmissionContactidAttach{$nb}"]) && - !is_numeric($_REQUEST["transmissionContactidAttach{$nb}"]) - ) { - $transmissionData[] = [ - 'column' => 'dest_user', - 'value' => $_REQUEST["transmissionContactidAttach{$nb}"], - 'type' => 'string' - ]; - } - - if ( - !empty($_REQUEST["transmissionAddressidAttach{$nb}"]) && - is_numeric($_REQUEST["transmissionAddressidAttach{$nb}"]) - ) { - $transmissionData[] = [ - 'column' => 'dest_address_id', - 'value' => $_REQUEST["transmissionAddressidAttach{$nb}"], - 'type' => 'integer' - ]; - } - - return $transmissionData; - } - - function setTransmissionDataPdf($aArgs, $nb, $storeResult) - { - $transmissionDataPdf = []; - - //TODO - $file = $_SESSION['config']['tmppath'] . $_SESSION['upfileTransmission'][$nb]['fileNamePdfOnTmp']; - $newfile = $storeResult['path_template'] . str_replace('#',"/",$storeResult['destination_dir']) . substr ($storeResult['file_destination_name'], 0, strrpos ($storeResult['file_destination_name'], "." )) . '.pdf'; - - copy($file, $newfile); - - $transmissionDataPdf[] = [ - 'column' => 'format', - 'value' => 'pdf', - 'type' => 'string' - ]; - //TODO - $transmissionDataPdf[] = [ - 'column' => 'status', - 'value' => 'TRA', - 'type' => 'string' - ]; - $transmissionDataPdf[] = [ - 'column' => 'title', - 'value' => str_replace("'", "'", $_REQUEST["transmissionTitle{$nb}"]), - 'type' => 'string' - ]; - $transmissionDataPdf[] = [ - 'column' => 'attachment_type', - 'value' => 'converted_pdf', - 'type' => 'string' - ]; - $transmissionDataPdf[] = [ - 'column' => 'coll_id', - 'value' => $_SESSION['collection_id_choice'], - 'type' => 'string' - ]; - //TODO - $transmissionDataPdf[] = [ - 'column' => 'res_id_master', - 'value' => $_SESSION['doc_id'], - 'type' => 'integer' - ]; - $transmissionDataPdf[] = [ - 'column' => 'in_signature_book', - 'value' => 1, - 'type' => 'bool' - ]; - - return $transmissionDataPdf; - } - - public function setInSignatureBook(RequestInterface $request, ResponseInterface $response, $aArgs) - { - //TODO Controle de droit de modification de cet attachment - - $data = $request->getParams(); - - $attachment = AttachmentsModel::getById(['id' => $aArgs['id'], 'isVersion' => $data['isVersion']]); - - if (empty($attachment)) { - return $response->withStatus(400)->withJson(['errors' => 'Attachment not found']); - } - - AttachmentsModel::setInSignatureBook(['id' => $aArgs['id'], 'isVersion' => $data['isVersion'], 'inSignatureBook' => !$attachment['in_signature_book']]); - - return $response->withJson(['success' => 'success']); - } -} diff --git a/modules/attachments/Controllers/ReconciliationController.php b/modules/attachments/Controllers/ReconciliationController.php index 863816f03a624efc589e2572341b86c729b27d96..8623ea5c5433296cdca4a09bd9ec9f955a8073e8 100755 --- a/modules/attachments/Controllers/ReconciliationController.php +++ b/modules/attachments/Controllers/ReconciliationController.php @@ -2,21 +2,16 @@ namespace Attachments\Controllers; +use Attachment\Models\AttachmentModel; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Respect\Validation\Validator; -use Attachments\Models\AttachmentsModel; use Resource\controllers\ResController; use Docserver\models\DocserverModel; use Docserver\models\DocserverTypeModel; -use Docserver\controllers\DocserverController; use Docserver\controllers\DocserverToolsController; use Core\Models\ResModel; - -require_once 'modules/attachments/Models/AttachmentsModel.php'; - - class ReconciliationController{ public function storeAttachmentResource($aArgs) { @@ -351,7 +346,7 @@ class ReconciliationController{ } unset($prepareData['res_id']); // NCH01 - AttachmentsModel::create($prepareData); + AttachmentModel::create($prepareData); return true; } diff --git a/modules/attachments/Models/AttachmentsModel.php b/modules/attachments/Models/AttachmentsModel.php deleted file mode 100755 index eee8ceb57a5973a9868e40720a5f9384041311b4..0000000000000000000000000000000000000000 --- a/modules/attachments/Models/AttachmentsModel.php +++ /dev/null @@ -1,16 +0,0 @@ -<?php - -/** -* Copyright Maarch since 2008 under licence GPLv3. -* See LICENCE.txt file at the root folder for more details. -* This file is part of Maarch software. -* -*/ - -namespace Attachments\Models; -//require_once 'modules/attachments/Models/AttachmentsModelAbstract.php'; - -class AttachmentsModel extends AttachmentsModelAbstract -{ - // Do your stuff in this class -} diff --git a/modules/attachments/Test/AttachmentsControllerTest.php b/modules/attachments/Test/AttachmentsControllerTest.php deleted file mode 100755 index 14ab3fe339744a19a3f851cecdafc9e567e2af96..0000000000000000000000000000000000000000 --- a/modules/attachments/Test/AttachmentsControllerTest.php +++ /dev/null @@ -1,134 +0,0 @@ -<?php - -/** -* Copyright Maarch since 2008 under licence GPLv3. -* See LICENCE.txt file at the root folder for more details. -* This file is part of Maarch software. -* -*/ - -require_once 'core/Test/define.php'; - -class AttachmentsControllerTest extends PHPUnit_Framework_TestCase -{ - - public function testPrepareStorage() - { - $action = new \Attachments\Controllers\AttachmentsController(); - - $data = []; - - array_push( - $data, - array( - 'column' => 'title', - 'value' => 'test pj', - 'type' => 'string', - ) - ); - - array_push( - $data, - array( - 'column' => 'attachment_type', - 'value' => 'response_project', - 'type' => 'string', - ) - ); - - array_push( - $data, - array( - 'column' => 'status', - 'value' => 'A_TRA', - 'type' => 'string', - ) - ); - - $aArgs = [ - 'data' => $data, - 'resId' => 100, - 'collIdMaster' => 'letterbox_coll', - ]; - - $response = $action->prepareStorage($aArgs); - - $this->assertArrayHasKey('column', $response['data'][0]); - } - - public function testSetTransmissionData() - { - $action = new \Attachments\Controllers\AttachmentsController(); - - $aArgs = [ - 'nb' => 2, - ]; - - $response = $action->setTransmissionData($aArgs); - - $this->assertArrayHasKey('column', $response[0]); - } - - public function testStoreAttachmentResource() - { - $action = new \Attachments\Controllers\AttachmentsController(); - - $path = $_SESSION['config']['tmppath'] . '/test/'; - - if (!is_dir($path)) { - mkdir($path); - } - - $fileSource = 'test_source.txt'; - - $fp = fopen($path . $fileSource, 'w'); - fwrite($fp, 'a unit test'); - fclose($fp); - - $fileContent = file_get_contents($path . $fileSource, FILE_BINARY); - $encodedFile = base64_encode($fileContent); - - $data = []; - - array_push( - $data, - array( - 'column' => 'title', - 'value' => 'test pj', - 'type' => 'string', - ) - ); - - array_push( - $data, - array( - 'column' => 'attachment_type', - 'value' => 'response_project', - 'type' => 'string', - ) - ); - - array_push( - $data, - array( - 'column' => 'status', - 'value' => 'A_TRA', - 'type' => 'string', - ) - ); - - $aArgs = [ - 'resId' => 100, - 'encodedFile' => $encodedFile, - 'data' => $data, - 'collId' => 'attachments_coll', - 'collIdMaster' => 'letterbox_coll', - 'table' => 'res_attachments', - 'fileFormat' => 'txt', - ]; - - $response = $action->storeAttachmentResource($aArgs); - - $this->assertGreaterThanOrEqual(0, $response[0]); - } -} \ No newline at end of file diff --git a/modules/attachments/attachments_content.php b/modules/attachments/attachments_content.php index ba9f8b26aa68404bf842dac46097654f3a970f49..3e88550ab59abe35dc995f4207dee4915ea22bb3 100755 --- a/modules/attachments/attachments_content.php +++ b/modules/attachments/attachments_content.php @@ -39,7 +39,6 @@ require_once "core/class/docservers_controler.php"; require_once 'modules/attachments/attachments_tables.php'; require_once "core/class/class_history.php"; require_once 'modules/attachments/class/attachments_controler.php'; -require_once 'modules/attachments/Models/AttachmentsModel.php'; $core = new core_tools(); @@ -434,7 +433,7 @@ if (isset($_POST['add']) && $_POST['add']) { ) ); - $attachmentTypesList = \Attachments\Models\AttachmentsModel::getAttachmentsTypesByXML(); + $attachmentTypesList = \Attachment\Models\AttachmentModel::getAttachmentsTypesByXML(); foreach ($attachmentTypesList as $keyAttachment => $valueAttachment) { if ($keyAttachment == $attachment_types && $valueAttachment['sign']) { array_push( @@ -938,7 +937,7 @@ if (isset($_POST['add']) && $_POST['add']) { 'type' => "string", ) ); - $attachmentTypesList = \Attachments\Models\AttachmentsModel::getAttachmentsTypesByXML(); + $attachmentTypesList = \Attachment\Models\AttachmentModel::getAttachmentsTypesByXML(); foreach ($attachmentTypesList as $keyAttachment => $valueAttachment) { if ($keyAttachment == $previous_attachment->attachment_type && $valueAttachment['sign']) { array_push( diff --git a/modules/convert/Controllers/ProcessConvertController.php b/modules/convert/Controllers/ProcessConvertController.php index 54843b6d9dd5cd31604e6d5cf97760f68dfd32da..079a372314d80b48b48d7f8b329c48aaeb78bcc5 100644 --- a/modules/convert/Controllers/ProcessConvertController.php +++ b/modules/convert/Controllers/ProcessConvertController.php @@ -23,7 +23,7 @@ namespace Convert\Controllers; -use Attachments\Models\AttachmentsModel; +use Attachment\Models\AttachmentModel; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Resource\models\ResModel; @@ -133,9 +133,9 @@ class ProcessConvertController if ($args['resTable'] == 'res_letterbox') { $res = ResModel::getById(['resId' => $resId]); } elseif ($args['resTable'] == 'res_attachments') { - $res = AttachmentsModel::getById(['id' => $resId, 'isVersion' => 'false']); + $res = AttachmentModel::getById(['id' => $resId, 'isVersion' => 'false']); } else { - $res = AttachmentsModel::getById(['id' => $resId, 'isVersion' => 'true']); + $res = AttachmentModel::getById(['id' => $resId, 'isVersion' => 'true']); } if ($res['res_id'] <> '') { diff --git a/modules/convert/Controllers/ProcessFulltextController.php b/modules/convert/Controllers/ProcessFulltextController.php index 31661e341113283095c656ed311caec2cb093916..2931ad7031cec91b3e8823433098e9d89b91ea54 100644 --- a/modules/convert/Controllers/ProcessFulltextController.php +++ b/modules/convert/Controllers/ProcessFulltextController.php @@ -23,7 +23,7 @@ namespace Convert\Controllers; -use Attachments\Models\AttachmentsModel; +use Attachment\Models\AttachmentModel; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Resource\models\ResModel; @@ -183,9 +183,9 @@ class ProcessFulltextController if ($args['resTable'] == 'res_letterbox') { $res = ResModel::getById(['resId' => $resId]); } elseif ($args['resTable'] == 'res_attachments') { - $res = AttachmentsModel::getById(['id' => $resId, 'isVersion' => 'false']); + $res = AttachmentModel::getById(['id' => $resId, 'isVersion' => 'false']); } else { - $res = AttachmentsModel::getById(['id' => $resId, 'isVersion' => 'true']); + $res = AttachmentModel::getById(['id' => $resId, 'isVersion' => 'true']); } if ($res['res_id'] <> '') { diff --git a/modules/convert/Controllers/ProcessThumbnailsController.php b/modules/convert/Controllers/ProcessThumbnailsController.php index 7ed0381b7feaa02926b2839fa3187b99c9241368..0303afaa127130af6bc8517e9e12b4a1acfab75f 100644 --- a/modules/convert/Controllers/ProcessThumbnailsController.php +++ b/modules/convert/Controllers/ProcessThumbnailsController.php @@ -23,7 +23,7 @@ namespace Convert\Controllers; -use Attachments\Models\AttachmentsModel; +use Attachment\Models\AttachmentModel; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Resource\models\ResModel; @@ -130,9 +130,9 @@ class ProcessThumbnailsController if ($args['resTable'] == 'res_letterbox') { $res = ResModel::getById(['resId' => $resId]); } elseif ($args['resTable'] == 'res_attachments') { - $res = AttachmentsModel::getById(['id' => $resId, 'isVersion' => 'false']); + $res = AttachmentModel::getById(['id' => $resId, 'isVersion' => 'false']); } else { - $res = AttachmentsModel::getById(['id' => $resId, 'isVersion' => 'true']); + $res = AttachmentModel::getById(['id' => $resId, 'isVersion' => 'true']); } if ($res['res_id'] <> '') { diff --git a/modules/visa/Controllers/VisaController.php b/modules/visa/Controllers/VisaController.php index 907c6b6d9e35ffd702c837095957ed9f3ce64606..54119c5cbf66b1ec967effc5f34858eda7b37243 100755 --- a/modules/visa/Controllers/VisaController.php +++ b/modules/visa/Controllers/VisaController.php @@ -13,7 +13,7 @@ */ namespace Visa\Controllers; -use Attachments\Models\AttachmentsModel; +use Attachment\Models\AttachmentModel; use Basket\models\BasketModel; use Action\models\ActionModel; use Contact\models\ContactModel; @@ -94,12 +94,12 @@ class VisaController public function unsignFile(RequestInterface $request, ResponseInterface $response, $aArgs) { - AttachmentsModel::unsignAttachment(['table' => $aArgs['collId'], 'resId' => $aArgs['resId']]); + AttachmentModel::unsignAttachment(['table' => $aArgs['collId'], 'resId' => $aArgs['resId']]); $isVersion = ($aArgs['collId'] == 'res_attachments' ? 'false' : 'true'); $user = UserModel::getByUserId(['userId' => $GLOBALS['userId'], 'select' => ['id']]); - if (!AttachmentsModel::hasAttachmentsSignedForUserById(['id' => $aArgs['resId'], 'isVersion' => $isVersion, 'user_serial_id' => $user['id']])) { - $attachment = AttachmentsModel::getById(['id' => $aArgs['resId'], 'isVersion' => $isVersion, 'select' => ['res_id_master']]); + if (!AttachmentModel::hasAttachmentsSignedForUserById(['id' => $aArgs['resId'], 'isVersion' => $isVersion, 'user_serial_id' => $user['id']])) { + $attachment = AttachmentModel::getById(['id' => $aArgs['resId'], 'isVersion' => $isVersion, 'select' => ['res_id_master']]); ListInstanceModel::update([ 'set' => ['signatory' => 'false'], 'where' => ['res_id = ?', 'item_id = ?', 'difflist_type = ?'], @@ -143,10 +143,10 @@ class VisaController $incomingMail['alt_identifier'] = $incomingExtMail['alt_identifier']; $incomingMail['category_id'] = $incomingExtMail['category_id']; - $incomingMailAttachments = AttachmentsModel::getAvailableAttachmentsInByResIdMaster([ - 'resIdMaster' => $resId, - 'in' => ['incoming_mail_attachment', 'converted_pdf'], - 'select' => ['res_id', 'res_id_version', 'title', 'format', 'attachment_type', 'path', 'filename'] + $incomingMailAttachments = AttachmentModel::getOnView([ + 'select' => ['res_id', 'res_id_version', 'title', 'format', 'attachment_type', 'path', 'filename'], + 'where' => ['res_id_master = ?', 'attachment_type in (?)', "status not in ('DEL', 'TMP', 'OBS')"], + 'data' => [$resId, ['incoming_mail_attachment', 'converted_pdf']] ]); $documents = [ @@ -197,7 +197,7 @@ class VisaController private function getAttachmentsForSignatureBook(array $aArgs = []) { - $attachmentTypes = AttachmentsModel::getAttachmentsTypesByXML(); + $attachmentTypes = AttachmentModel::getAttachmentsTypesByXML(); $orderBy = "CASE attachment_type WHEN 'response_project' THEN 1"; $c = 2; @@ -209,16 +209,16 @@ class VisaController } $orderBy .= " ELSE {$c} END, doc_date DESC NULLS LAST, creation_date DESC"; - $attachments = AttachmentsModel::getAvailableAndTemporaryAttachmentsNotInByResIdMaster([ - 'resIdMaster' => $aArgs['resId'], - 'notIn' => ['incoming_mail_attachment', 'print_folder'], - 'select' => [ + $attachments = AttachmentModel::getOnView([ + 'select' => [ 'res_id', 'res_id_version', 'title', 'identifier', 'attachment_type', 'status', 'typist', 'path', 'filename', 'updated_by', 'creation_date', 'validation_date', 'format', 'relation', 'dest_user', 'dest_contact_id', 'dest_address_id', 'origin', 'doc_date', 'attachment_id_master' ], - 'orderBy' => [$orderBy] + 'where' => ['res_id_master = ?', 'attachment_type not in (?)', "status not in ('DEL', 'OBS')", 'in_signature_book = TRUE'], + 'data' => [$aArgs['resId'], ['incoming_mail_attachment', 'print_folder']], + 'orderBy' => [$orderBy] ]); $canModify = ServiceModel::hasService(['id' => 'modify_attachments', 'userId' => $_SESSION['user']['UserId'], 'location' => 'attachments', 'type' => 'use']); @@ -308,12 +308,11 @@ class VisaController $attachments[$key]['viewerLink'] = "index.php?display=true&module=attachments&page=view_attachment&res_id_master={$aArgs['resId']}&id={$viewerId}&isVersion={$isVersion}"; } - $obsAttachments = AttachmentsModel::getObsAttachmentsNotInByResIdMaster([ - 'resIdMaster' => $aArgs['resId'], - 'notIn' => ['incoming_mail_attachment', 'print_folder', 'converted_pdf', 'signed_response'], - 'select' => [ - 'res_id', 'res_id_version', 'attachment_id_master', 'relation', 'creation_date', 'title' - ] + $obsAttachments = AttachmentModel::getOnView([ + 'select' => ['res_id', 'res_id_version', 'attachment_id_master', 'relation', 'creation_date', 'title'], + 'where' => ['res_id_master = ?', 'attachment_type not in (?)', 'status = ?'], + 'data' => [$aArgs['resId'], ['incoming_mail_attachment', 'print_folder', 'converted_pdf', 'signed_response'], 'OBS'], + 'orderBy' => ['relation ASC'] ]); $obsData = []; @@ -359,13 +358,13 @@ class VisaController $resListForRequest[] = $value['res_id']; } - $attachmentsInResList = AttachmentsModel::getAttachmentsWithOptions([ + $attachmentsInResList = AttachmentModel::getOnView([ 'select' => ['res_id_master', 'status', 'attachment_type'], 'where' => ['res_id_master in (?)', "attachment_type not in ('incoming_mail_attachment', 'print_folder', 'converted_pdf', 'signed_response')", "status not in ('DEL', 'TMP', 'OBS')"], 'data' => [$resListForRequest] ]); - $attachmentTypes = AttachmentsModel::getAttachmentsTypesByXML(); + $attachmentTypes = AttachmentModel::getAttachmentsTypesByXML(); foreach ($attachmentsInResList as $value) { if ($resListForAttachments[$value['res_id_master']] === null) { $resListForAttachments[$value['res_id_master']] = true; diff --git a/modules/visa/class/class_modules_tools_Abstract.php b/modules/visa/class/class_modules_tools_Abstract.php index aae6f533936661767fb8c2cdf7b70e26062a4ff0..f8211564330f76cb27e30387f770a189b1593dbc 100755 --- a/modules/visa/class/class_modules_tools_Abstract.php +++ b/modules/visa/class/class_modules_tools_Abstract.php @@ -31,7 +31,6 @@ define('FPDF_FONTPATH',$core_path.'apps/maarch_entreprise/tools/pdfb/fpdf_1_7/font/'); require($core_path.'apps/maarch_entreprise/tools/pdfb/fpdf_1_7/fpdf.php'); require($core_path.'apps/maarch_entreprise/tools/pdfb/fpdf_1_7/fpdi.php'); -use Attachments\Models\AttachmentsModel; abstract class visa_Abstract extends Database { @@ -226,7 +225,7 @@ abstract class visa_Abstract extends Database public function checkResponseProject($res_id, $coll_id) { $this->errorMessageVisa = null; - $attachmentTypes = AttachmentsModel::getAttachmentsTypesByXML(); + $attachmentTypes = \Attachment\Models\AttachmentModel::getAttachmentsTypesByXML(); $noSignableAttachments = []; foreach ($attachmentTypes as $key => $value) { diff --git a/rest/index.php b/rest/index.php index a7d8bd3ba0b0a7555b021ca60b0cbd6fdd701171..38bb53df53e0c2af1219a5f20dcb175a1fe44303 100755 --- a/rest/index.php +++ b/rest/index.php @@ -167,7 +167,7 @@ $app->get('/groups/{groupId}/baskets/{basketId}/signatureBook/{resId}', \Visa\Co $app->get('/signatureBook/{resId}/attachments', \Visa\Controllers\VisaController::class . ':getAttachmentsById'); $app->get('/signatureBook/{resId}/incomingMailAttachments', \Visa\Controllers\VisaController::class . ':getIncomingMailAndAttachmentsById'); $app->put('/{collId}/{resId}/unsign', \Visa\Controllers\VisaController::class . ':unsignFile'); -$app->put('/attachments/{id}/inSignatureBook', \Attachments\Controllers\AttachmentsController::class . ':setInSignatureBook'); +$app->put('/attachments/{id}/inSignatureBook', \Attachment\controllers\AttachmentController::class . ':setInSignatureBook'); //Res $app->post('/res', \Resource\controllers\ResController::class . ':create'); diff --git a/src/app/attachment/controllers/AttachmentController.php b/src/app/attachment/controllers/AttachmentController.php new file mode 100644 index 0000000000000000000000000000000000000000..0ed4c1d2d002c55d8b4657e65dcb13ce4e5b0870 --- /dev/null +++ b/src/app/attachment/controllers/AttachmentController.php @@ -0,0 +1,39 @@ +<?php + +/** +* Copyright Maarch since 2008 under licence GPLv3. +* See LICENCE.txt file at the root folder for more details. +* This file is part of Maarch software. +* +*/ + +/** +* @brief Attachment Controller +* @author dev@maarch.org +*/ + +namespace Attachment\controllers; + +use Attachment\Models\AttachmentModel; +use Slim\Http\Request; +use Slim\Http\Response; + +class AttachmentController +{ + public function setInSignatureBook(Request $request, Response $response, array $aArgs) + { + //TODO Controle de droit de modification de cet attachment + + $data = $request->getParams(); + + $attachment = AttachmentModel::getById(['id' => $aArgs['id'], 'isVersion' => $data['isVersion']]); + + if (empty($attachment)) { + return $response->withStatus(400)->withJson(['errors' => 'Attachment not found']); + } + + AttachmentModel::setInSignatureBook(['id' => $aArgs['id'], 'isVersion' => $data['isVersion'], 'inSignatureBook' => !$attachment['in_signature_book']]); + + return $response->withJson(['success' => 'success']); + } +} diff --git a/src/app/attachment/models/AttachmentModel.php b/src/app/attachment/models/AttachmentModel.php new file mode 100644 index 0000000000000000000000000000000000000000..83a9ec370e09f1207a37e53a59813afae17e3bac --- /dev/null +++ b/src/app/attachment/models/AttachmentModel.php @@ -0,0 +1,19 @@ +<?php + +/** +* Copyright Maarch since 2008 under licence GPLv3. +* See LICENCE.txt file at the root folder for more details. +* This file is part of Maarch software. +* +*/ + +/** + * @brief Attachment Model + * @author dev@maarch.org + */ + +namespace Attachment\Models; + +class AttachmentModel extends AttachmentModelAbstract +{ +} diff --git a/modules/attachments/Models/AttachmentsModelAbstract.php b/src/app/attachment/models/AttachmentModelAbstract.php old mode 100755 new mode 100644 similarity index 67% rename from modules/attachments/Models/AttachmentsModelAbstract.php rename to src/app/attachment/models/AttachmentModelAbstract.php index 1d20dd6bea98cf9e10e3668d57b9ca7a1505af74..e96d5be5bc90e3ebb63f54e3dd24a3972ea19a4f --- a/modules/attachments/Models/AttachmentsModelAbstract.php +++ b/src/app/attachment/models/AttachmentModelAbstract.php @@ -7,14 +7,35 @@ * */ -namespace Attachments\Models; +/** + * @brief Attachment Model Abstract + * @author dev@maarch.org + */ + +namespace Attachment\models; use Core\Models\ValidatorModel; use SrcCore\models\CoreConfigModel; use SrcCore\models\DatabaseModel; -class AttachmentsModelAbstract +class AttachmentModelAbstract { + public static function getOnView(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['select']); + ValidatorModel::arrayType($aArgs, ['select', 'where', 'data', 'orderBy']); + + $aAttachments = DatabaseModel::select([ + 'select' => $aArgs['select'], + 'table' => ['res_view_attachments'], + 'where' => $aArgs['where'], + 'data' => $aArgs['data'], + 'order_by' => $aArgs['orderBy'] + ]); + + return $aAttachments; + } + public static function getById(array $aArgs) { ValidatorModel::notEmpty($aArgs, ['id', 'isVersion']); @@ -85,80 +106,6 @@ class AttachmentsModelAbstract return $attachmentTypes; } - public static function getAttachmentsWithOptions(array $aArgs = []) - { - ValidatorModel::notEmpty($aArgs, ['where', 'data']); - ValidatorModel::arrayType($aArgs, ['where', 'data', 'orderBy']); - - $select = [ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['res_view_attachments'], - 'where' => $aArgs['where'], - 'data' => $aArgs['data'], - ]; - if (!empty($aArgs['orderBy'])) { - $select['order_by'] = $aArgs['orderBy']; - } - - $aReturn = DatabaseModel::select($select); - - return $aReturn; - } - - public static function getAvailableAttachmentsInByResIdMaster(array $aArgs = []) - { - ValidatorModel::notEmpty($aArgs, ['resIdMaster', 'in']); - ValidatorModel::intVal($aArgs, ['resIdMaster']); - ValidatorModel::arrayType($aArgs, ['in']); - - $aReturn = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['res_view_attachments'], - 'where' => ['res_id_master = ?', 'attachment_type in (?)', "status not in ('DEL', 'TMP', 'OBS')"], - 'data' => [$aArgs['resIdMaster'], $aArgs['in']] - ]); - - return $aReturn; - } - - public static function getAvailableAndTemporaryAttachmentsNotInByResIdMaster(array $aArgs = []) - { - ValidatorModel::notEmpty($aArgs, ['resIdMaster', 'notIn']); - ValidatorModel::intVal($aArgs, ['resIdMaster']); - ValidatorModel::arrayType($aArgs, ['notIn', 'orderBy']); - - $select = [ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['res_view_attachments'], - 'where' => ['res_id_master = ?', 'attachment_type not in (?)', "status not in ('DEL', 'OBS')", 'in_signature_book = TRUE'], - 'data' => [$aArgs['resIdMaster'], $aArgs['notIn']], - ]; - if (!empty($aArgs['orderBy'])) { - $select['order_by'] = $aArgs['orderBy']; - } - - $aReturn = DatabaseModel::select($select); - - return $aReturn; - } - - public static function getObsAttachmentsNotInByResIdMaster(array $aArgs = []) - { - ValidatorModel::notEmpty($aArgs, ['resIdMaster', 'notIn']); - ValidatorModel::intVal($aArgs, ['resIdMaster']); - ValidatorModel::arrayType($aArgs, ['notIn', 'orderBy']); - - $aReturn = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['res_view_attachments'], - 'where' => ['res_id_master = ?', 'attachment_type not in (?)', 'status = ?'], - 'data' => [$aArgs['resIdMaster'], $aArgs['notIn'], 'OBS'], - 'order_by' => ['relation ASC'] - ]); - - return $aReturn; - } - public static function unsignAttachment(array $aArgs = []) { ValidatorModel::notEmpty($aArgs, ['table', 'resId']); diff --git a/src/core/controllers/StoreController.php b/src/core/controllers/StoreController.php index 460acf3fe2942c729186d3193683563488ad72e9..83074b79a7e93358ff9370b193d9e34925756cb8 100644 --- a/src/core/controllers/StoreController.php +++ b/src/core/controllers/StoreController.php @@ -15,7 +15,7 @@ namespace SrcCore\controllers; -use Attachments\Models\AttachmentsModel; +use Attachment\Models\AttachmentModel; use Contact\models\ContactModel; use Docserver\controllers\DocserverController; use Docserver\models\DocserverModel; @@ -78,7 +78,7 @@ class StoreController if ($aArgs['table'] == 'res_letterbox') { $resId = ResModel::create($data); } elseif ($aArgs['table'] == 'res_attachments') { - $resId = AttachmentsModel::create($data); + $resId = AttachmentModel::create($data); } return $resId;