diff --git a/rest/index.php b/rest/index.php index d538721036ed321b873a598c3fac2b3c443c2898..87467b278655de4c61aa5bb8e55f78904f5dd525 100755 --- a/rest/index.php +++ b/rest/index.php @@ -118,6 +118,7 @@ $app->get('/contacts/{id}', \Contact\controllers\ContactController::class . ':ge $app->put('/contacts/{id}', \Contact\controllers\ContactController::class . ':update'); $app->delete('/contacts/{id}', \Contact\controllers\ContactController::class . ':delete'); $app->put('/contacts/{id}/activation', \Contact\controllers\ContactController::class . ':updateActivation'); +$app->get('/formattedContacts/{id}/types/{type}', \Contact\controllers\ContactController::class . ':getLightFormattedContact'); $app->get('/contactsGroups', \Contact\controllers\ContactGroupController::class . ':get'); $app->post('/contactsGroups', \Contact\controllers\ContactGroupController::class . ':create'); @@ -126,7 +127,6 @@ $app->put('/contactsGroups/{id}', \Contact\controllers\ContactGroupController::c $app->delete('/contactsGroups/{id}', \Contact\controllers\ContactGroupController::class . ':delete'); $app->post('/contactsGroups/{id}/contacts', \Contact\controllers\ContactGroupController::class . ':addContacts'); $app->delete('/contactsGroups/{id}/contacts/{addressId}', \Contact\controllers\ContactGroupController::class . ':deleteContact'); -$app->get('/contactsTypes', \Contact\controllers\ContactTypeController::class . ':get'); $app->get('/contactsFilling', \Contact\controllers\ContactController::class . ':getFilling'); $app->put('/contactsFilling', \Contact\controllers\ContactController::class . ':updateFilling'); diff --git a/src/app/attachment/controllers/AttachmentController.php b/src/app/attachment/controllers/AttachmentController.php index df0a9770721d0cf71548a99246e7be7deffd6ae4..35eef3a71df855f992f76ac3a7ca576eecc53ceb 100755 --- a/src/app/attachment/controllers/AttachmentController.php +++ b/src/app/attachment/controllers/AttachmentController.php @@ -88,7 +88,7 @@ class AttachmentController 'id' => $args['id'], 'select' => [ 'res_id as "resId"', 'res_id_master as "resIdMaster"', 'status', 'title', 'identifier as chrono', 'typist', 'modified_by as "modifiedBy"', 'relation', 'attachment_type as type', - 'recipient_id', 'recipient_type', 'origin_id as "originId"', 'creation_date as "creationDate"', 'modification_date as "modificationDate"', + 'recipient_id as "recipientId"', 'recipient_type as "recipientType"', 'origin_id as "originId"', 'creation_date as "creationDate"', 'modification_date as "modificationDate"', 'validation_date as "validationDate"', 'fulltext_result as "fulltextResult"', 'in_signature_book as "inSignatureBook"', 'in_send_attach as "inSendAttach"' ] ]); diff --git a/src/app/contact/controllers/ContactController.php b/src/app/contact/controllers/ContactController.php index a9053a189d6aea76f8cefef99901a487729d48d7..a88d70347d5b4ea8807373ed9f92ddc0ea219552 100755 --- a/src/app/contact/controllers/ContactController.php +++ b/src/app/contact/controllers/ContactController.php @@ -369,6 +369,32 @@ class ContactController return $response->withJson(['contacts' => $contacts]); } + public static function getLightFormattedContact(Request $request, Response $response, array $args) + { + if (!Validator::intVal()->notEmpty()->validate($args['id'])) { + return $response->withStatus(400)->withJson(['errors' => 'Query params id is not an integer']); + } + + if ($args['type'] == 'contact') { + $contact = ContactModel::getById([ + 'select' => [ + 'firstname', 'lastname', 'company', 'address_number as "addressNumber"', 'address_street as "addressStreet"', + 'address_postcode as "addressPostcode"', 'address_town as "addressTown"', 'address_country as "addressCountry"'], + 'id' => $args['id'] + ]); + } elseif ($args['type'] == 'user') { + $contact = UserModel::getById(['id' => $args['id'], 'select' => ['firstname', 'lastname']]); + } elseif ($args['type'] == 'entity') { + $contact = EntityModel::getById(['id' => $args['id'], 'select' => ['entity_label as label']]); + } + + if (empty($contact)) { + return $response->withStatus(400)->withJson(['errors' => 'Contact does not exist']); + } + + return $response->withJson(['contact' => $contact]); + } + public static function getFillingRate(array $aArgs) { ValidatorModel::notEmpty($aArgs, ['contact']); @@ -799,7 +825,7 @@ class ContactController } $customFields = ContactCustomFieldListModel::get(['select' => ['count(1)'], 'where' => ['id in (?)'], 'data' => [array_keys($body['customFields'])]]); if (count($body['customFields']) != $customFields[0]['count']) { - return ['errors' => 'Body tags : One or more custom fields do not exist']; + return ['errors' => 'Body customFields : One or more custom fields do not exist']; } } diff --git a/src/app/contact/controllers/ContactTypeController.php b/src/app/contact/controllers/ContactTypeController.php deleted file mode 100755 index 11a7e7940c3a82661293b50f193096c5eaa2db92..0000000000000000000000000000000000000000 --- a/src/app/contact/controllers/ContactTypeController.php +++ /dev/null @@ -1,29 +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 Contact Type Controller - * @author dev@maarch.org - */ - -namespace Contact\controllers; - -use Contact\models\ContactTypeModel; -use Slim\Http\Request; -use Slim\Http\Response; - -class ContactTypeController -{ - public function get(Request $request, Response $response) - { - $contactsTypes = ContactTypeModel::get(); - - return $response->withJson(['contactsTypes' => $contactsTypes]); - } -} diff --git a/src/app/contact/models/ContactTypeModel.php b/src/app/contact/models/ContactTypeModel.php deleted file mode 100755 index 0fce1031d0a58a067e8622582a66fc6f21824a35..0000000000000000000000000000000000000000 --- a/src/app/contact/models/ContactTypeModel.php +++ /dev/null @@ -1,19 +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 Contact Type Model - * @author dev@maarch.org - */ - -namespace Contact\models; - -class ContactTypeModel extends ContactTypeModelAbstract -{ -} \ No newline at end of file diff --git a/src/app/contact/models/ContactTypeModelAbstract.php b/src/app/contact/models/ContactTypeModelAbstract.php deleted file mode 100755 index b904810b1cbfa4f67073c7f4f3cb7e65555c4625..0000000000000000000000000000000000000000 --- a/src/app/contact/models/ContactTypeModelAbstract.php +++ /dev/null @@ -1,35 +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 Contact Type Abstract Model - * @author dev@maarch.org - */ - -namespace Contact\models; - -use SrcCore\models\ValidatorModel; -use SrcCore\models\DatabaseModel; - -abstract class ContactTypeModelAbstract -{ - public static function get(array $aArgs = []) - { - ValidatorModel::arrayType($aArgs, ['select', 'where', 'data', 'orderBy']); - - $aTypes = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['contact_types'], - 'where' => $aArgs['where'], - 'data' => $aArgs['data'], - 'order_by' => $aArgs['orderBy'] - ]); - - return $aTypes; - } -} diff --git a/src/app/resource/controllers/ResController.php b/src/app/resource/controllers/ResController.php index 7ec7d79bb5805cde6277175a48900a3a3bfd9732..177bd48084177220dcb2898056aa55428b483613 100755 --- a/src/app/resource/controllers/ResController.php +++ b/src/app/resource/controllers/ResController.php @@ -149,7 +149,7 @@ class ResController 'barcode' => $document['barcode'] ]); } - + $modelFields = IndexingModelFieldModel::get([ 'select' => ['identifier'], 'where' => ['model_id = ?'], @@ -184,6 +184,21 @@ class ResController $formattedData['priorityColor'] = $priority['color']; } + if (in_array('senders', $modelFields)) { + $formattedData['senders'] = ResourceContactModel::get([ + 'select' => ['item_id as id', 'type'], + 'where' => ['res_id = ?', 'mode = ?'], + 'data' => [$args['resId'], 'sender'] + ]); + } + if (in_array('recipients', $modelFields) && empty($queryParams['light'])) { + $formattedData['recipients'] = ResourceContactModel::get([ + 'select' => ['item_id as id', 'type'], + 'where' => ['res_id = ?', 'mode = ?'], + 'data' => [$args['resId'], 'recipient'] + ]); + } + $attachments = AttachmentModel::get(['select' => ['count(1)'], 'where' => ['res_id_master = ?', 'status in (?)'], 'data' => [$args['resId'], ['TRA', 'A_TRA', 'FRZ']]]); $formattedData['attachments'] = $attachments[0]['count']; @@ -1048,7 +1063,7 @@ class ResController } $customFields = CustomFieldModel::get(['select' => ['count(1)'], 'where' => ['id in (?)'], 'data' => [array_keys($body['customFields'])]]); if (count($body['customFields']) != $customFields[0]['count']) { - return ['errors' => 'Body tags : One or more custom fields do not exist']; + return ['errors' => 'Body customFields : One or more custom fields do not exist']; } } if (!empty($body['folders'])) {