diff --git a/apps/maarch_entreprise/actions/index_mlb.php b/apps/maarch_entreprise/actions/index_mlb.php index 86cee702a7c6632885422d4ee97b032e04c223f9..253131ffb0e93bea69b1339584c9eef32b2d9cab 100755 --- a/apps/maarch_entreprise/actions/index_mlb.php +++ b/apps/maarch_entreprise/actions/index_mlb.php @@ -1499,7 +1499,7 @@ function get_value_fields($values, $field) * @param $status String Not used here * @param $collId String Collection identifier * @param $table String Table - * @param $formValues String Values of the form to load + * @param $formValues array * * @return array * $data['result'] : res_id of the new file followed by # @@ -1920,6 +1920,24 @@ function manage_form($arrId, $history, $actionId, $label_action, $status, $collI } } + // Sender/Recipient + $srId = get_value_fields($formValues, 'sender_recipient_id'); + $srType = get_value_fields($formValues, 'sender_recipient_type'); + + if (!empty($srId) && !empty($srType) && in_array($catId, ['incoming', 'outgoing', 'internal'])) { + if ($catId == 'incoming' || $catId == 'internal') { + $srMode = 'recipient'; + } else { + $srMode = 'sender'; + } + \Resource\models\ResourceContactModel::create([ + 'res_id' => $resId, + 'item_id' => $srId, + 'type' => $srType, + 'mode' => $srMode + ]); + } + if ($resId != false) { //Create chrono number //###### diff --git a/apps/maarch_entreprise/actions/validate_mail.php b/apps/maarch_entreprise/actions/validate_mail.php index aee93933445ad8d3752e0430d2a8daca771075df..70721f122b60f082c49732d8cb3f946920802fe9 100755 --- a/apps/maarch_entreprise/actions/validate_mail.php +++ b/apps/maarch_entreprise/actions/validate_mail.php @@ -246,6 +246,8 @@ function get_form_txt($values, $path_manage_action, $id_action, $table, $module, array_push($_SESSION['adresses']['contactid'], $res->contact_id); } + $resourceContacts = \Resource\models\ResourceContactModel::getFormattedByResId(['resId' => $res_id]); + //USERS $query = 'SELECT u.firstname, u.lastname, u.user_id '; $query .= 'FROM users u, contacts_res cres '; @@ -812,6 +814,39 @@ function get_form_txt($values, $path_manage_action, $id_action, $table, $module, $frm_str .= '</tr>'; } + foreach ($resourceContacts as $resourceContact) { + if ($resourceContact['mode'] == 'recipient' && ($data['category_id']['value'] == 'incoming' || $data['category_id']['value'] == 'internal')) { + $sr = $resourceContact; + } elseif ($resourceContact['mode'] == 'sender' && $data['category_id']['value'] == 'outgoing') { + $sr = $resourceContact; + } + } + /*** Sender/Recipient ***/ + $frm_str .= '<tr id="sender_recipient_tr" style="display:' . $displayValue . ';">'; + $frm_str .= '<td><label for="sender_recipient" class="form_title" >'; + $frm_str .= '<span id="sr_sender_span">'._SHIPPER.'</span>'; + $frm_str .= '<span id="sr_recipient_span">'._DEST.'</span>'; + $frm_str .= '</label></td>'; + $frm_str .= '<td> </td>'; + $frm_str .= '<td class="indexing_field"><div class="typeahead__container"><div class="typeahead__field"><span class="typeahead__query">'; + $frm_str .= '<input name="sender_recipient" type="text" id="sender_recipient" autocomplete="off"'; + if (!empty($sr['format'])) { + $frm_str .= 'value="'. $sr['format'].'"'; + } + $frm_str .= '/></span></div></div>'; + $frm_str .= '</td><td> </td>'; + $frm_str .= '<input type="hidden" id="sender_recipient_id"'; + if (!empty($sr['item_id'])) { + $frm_str .= 'value="'. $sr['item_id'].'"'; + } + $frm_str .= '/>'; + $frm_str .= '<input type="hidden" id="sender_recipient_type"'; + if (!empty($sr['type'])) { + $frm_str .= 'value="'. $sr['type'].'"'; + } + $frm_str .= '/>'; + $frm_str .= '</tr>'; + /*** Nature ***/ $frm_str .= '<tr id="nature_id_tr" style="display:'.$display_value.';">'; $frm_str .= '<td class="indexing_label"><label for="nature_id" class="form_title" >'._NATURE.'</label></td>'; @@ -1361,6 +1396,7 @@ function get_form_txt($values, $path_manage_action, $id_action, $table, $module, .$_SESSION['config']['businessappurl'] .'index.php?display=true&dir=indexing_searching&page=autocomplete_contacts_prepare_multi\');'; $frm_str .= 'affiche_reference();'; + $frm_str .= 'initSenderRecipientAutocomplete();'; $frm_str .= 'initList_hidden_input(\'department_number\', \'show_department_number\',\'' . $_SESSION['config']['businessappurl'] . 'index.php?display=' . 'true&page=autocomplete_department_number\',' @@ -1848,6 +1884,25 @@ function manage_form($arr_id, $history, $id_action, $label_action, $status, $col } } + // Sender/Recipient + $srId = get_value_fields($values_form, 'sender_recipient_id'); + $srType = get_value_fields($values_form, 'sender_recipient_type'); + + if (!empty($srId) && !empty($srType) && in_array($cat_id, ['incoming', 'outgoing', 'internal'])) { + if ($cat_id == 'incoming' || $cat_id == 'internal') { + $srMode = 'recipient'; + } else { + $srMode = 'sender'; + } + \Resource\models\ResourceContactModel::delete(['where' => ['res_id = ?', 'mode = ?'], 'data' => [$res_id, $srMode]]); + \Resource\models\ResourceContactModel::create([ + 'res_id' => $res_id, + 'item_id' => $srId, + 'type' => $srType, + 'mode' => $srMode + ]); + } + if ($core->is_module_loaded('folder') && ($core->test_service('associate_folder', 'folder', false) == 1)) { $folder_id = ''; $folder_id = get_value_fields($values_form, 'folder'); diff --git a/apps/maarch_entreprise/class/class_indexing_searching_app_Abstract.php b/apps/maarch_entreprise/class/class_indexing_searching_app_Abstract.php index 8c3ae4e540fdf7897e8ed899fc98a348e6c7f287..5bd55efb4c11be81bc4b249dd8c0a7bcba853958 100755 --- a/apps/maarch_entreprise/class/class_indexing_searching_app_Abstract.php +++ b/apps/maarch_entreprise/class/class_indexing_searching_app_Abstract.php @@ -279,6 +279,25 @@ abstract class indexing_searching_app_Abstract extends Database ); } + // Sender/Recipient + $srId = $post['sender_recipient_id']; + $srType = $post['sender_recipient_type']; + + if (!empty($srId) && !empty($srType) && in_array($cat_id, ['incoming', 'outgoing', 'internal'])) { + if ($cat_id == 'incoming' || $cat_id == 'internal') { + $srMode = 'recipient'; + } else { + $srMode = 'sender'; + } + \Resource\models\ResourceContactModel::delete(['where' => ['res_id = ?', 'mode = ?'], 'data' => [$id_to_update, $srMode]]); + \Resource\models\ResourceContactModel::create([ + 'res_id' => $id_to_update, + 'item_id' => $srId, + 'type' => $srType, + 'mode' => $srMode + ]); + } + if ($core->is_module_loaded('folder')) { $stmt = $db->query('SELECT folders_system_id FROM '.$table.' WHERE res_id = ?', array($id_to_update)); $res = $stmt->fetchObject(); diff --git a/apps/maarch_entreprise/definition_mail_categories.php b/apps/maarch_entreprise/definition_mail_categories.php index 81ab6a49788d19bc7bc206b75ec6b23b28ed600e..888ce8212976d1baa05f22089665b0a6e1ecba84 100644 --- a/apps/maarch_entreprise/definition_mail_categories.php +++ b/apps/maarch_entreprise/definition_mail_categories.php @@ -220,6 +220,17 @@ $_ENV['categories']['incoming']['other_cases']['contact'] = array( 'img' => 'book', 'form_show' => 'textfield', ); +$_ENV['categories']['incoming']['other_cases']['resourceContact'] = array( + 'type_form' => 'string', + 'type_field' => 'string', + 'mandatory' => true, + 'label' => _DEST, + 'table' => 'res', + 'special' => '', + 'modify' => true, + 'img' => 'book', + 'form_show' => 'textfield', +); $_ENV['categories']['incoming']['department_number_id'] = array ( 'type_form' => 'string', 'type_field' => 'string', @@ -402,6 +413,17 @@ $_ENV['categories']['outgoing']['other_cases']['contact'] = array( 'img' => 'book', 'form_show' => 'textfield', ); +$_ENV['categories']['outgoing']['other_cases']['resourceContact'] = array( + 'type_form' => 'string', + 'type_field' => 'string', + 'mandatory' => true, + 'label' => _SENDER, + 'table' => 'res', + 'special' => '', + 'modify' => true, + 'img' => 'book', + 'form_show' => 'textfield', +); $_ENV['categories']['outgoing']['confidentiality'] = array( 'type_form' => 'radio', 'type_field' => 'string', @@ -522,6 +544,17 @@ $_ENV['categories']['internal']['other_cases']['contact'] = array( 'img' => 'book', 'form_show' => 'textfield', ); +$_ENV['categories']['internal']['other_cases']['resourceContact'] = array( + 'type_form' => 'string', + 'type_field' => 'string', + 'mandatory' => true, + 'label' => _DEST, + 'table' => 'res', + 'special' => '', + 'modify' => true, + 'img' => 'book', + 'form_show' => 'textfield', +); ///////////////////////////// RECONCILIATION //////////////////////////////////////////////// @@ -1071,6 +1104,20 @@ function get_general_data($coll_id, $res_id, $mode, $params = array()) $data['contact'] = ''; } } + + if (!empty($_ENV['categories'][$cat_id]['other_cases']['resourceContact'])) { + $data['resourceContact'] = array( + 'value' => '', + 'show_value' => '', + 'label' => $_ENV['categories'][$cat_id]['other_cases']['resourceContact']['label'], + 'display' => 'textarea', + 'img' => $_ENV['categories'][$cat_id]['other_cases']['resourceContact']['img'], + 'field_type' => $_ENV['categories'][$cat_id]['other_cases']['resourceContact']['form_show'], + 'readonly' => false, + ); + $arr[] = 'resourceContact'; + } + // Folder if (isset($_ENV['categories'][$cat_id]['other_cases']['folder']) && count($_ENV['categories'][$cat_id]['other_cases']['folder']) > 0 && (!isset($params['show_folder']) || $params['show_folder'] == true)) { $fields .= 'folders_system_id,'; @@ -1260,6 +1307,19 @@ function get_general_data($coll_id, $res_id, $mode, $params = array()) $data[$arr[$i]][$contact_res->mode]['arr_values'][] = "{$res->firstname} {$res->lastname}"; } } + } elseif ($arr[$i] == 'resourceContact') { + $resourceContacts = \Resource\models\ResourceContactModel::getFormattedByResId(['resId' => $res_id]); + foreach ($resourceContacts as $resourceContact) { + if ($resourceContact['mode'] == 'recipient' && $cat_id == 'incoming') { + $sr = $resourceContact; + } elseif ($resourceContact['mode'] == 'sender' && $cat_id == 'outgoing') { + $sr = $resourceContact; + } + } + + if (!empty($sr['format'])) { + $data[$arr[$i]]['show_value'] = functions::show_string($sr['format']); + } } // Folder elseif ($arr[$i] == 'folder' && isset($line->folders_system_id) && $line->folders_system_id != '') { diff --git a/apps/maarch_entreprise/indexing_searching/details.php b/apps/maarch_entreprise/indexing_searching/details.php index e6e6ed16e10c2c8f1bd52fa9e9607f25e98881fc..35e58fa8cd08467eebc091a9f24df1434b20f62c 100755 --- a/apps/maarch_entreprise/indexing_searching/details.php +++ b/apps/maarch_entreprise/indexing_searching/details.php @@ -771,6 +771,37 @@ if ($stmt->rowCount() == 0) { echo '</div>'; echo "<input type='hidden' name='contactid' id='contactid' value='' title='' alt='' size='40' />"; echo "<input type='hidden' name='addressid' id='addressid' value='' title='' alt='' size='40' />"; + } elseif ($key == 'resourceContact') { + $resourceContacts = \Resource\models\ResourceContactModel::getFormattedByResId(['resId' => $s_id]); + foreach ($resourceContacts as $resourceContact) { + if ($resourceContact['mode'] == 'recipient' && ($data['category_id']['value'] == 'incoming' || $data['category_id']['value'] == 'internal')) { + $sr = $resourceContact; + } elseif ($resourceContact['mode'] == 'sender' && $data['category_id']['value'] == 'outgoing') { + $sr = $resourceContact; + } + } + + echo '<div class="typeahead__container"><div class="typeahead__field"><span class="typeahead__query">'; + echo "<textarea name='sender_recipient' id='sender_recipient' rows='3' class='{$disabledClass}' {$disabledAttr}/>"; + if (!empty($sr['format'])) { + echo $sr['format']; + } + echo '</textarea>'; + echo '</span></div></div>'; + echo "<input type='hidden' name='sender_recipient_id' id='sender_recipient_id' "; + if (!empty($sr['item_id'])) { + echo "value='{$sr['item_id']}'"; + } + echo "/>"; + echo "<input type='hidden' name='sender_recipient_type' id='sender_recipient_type' "; + if (!empty($sr['type'])) { + echo "value='{$sr['type']}'"; + } + echo "/>"; + + //initialize autocomplete + echo '<script>initSenderRecipientAutocomplete();</script>'; + } else { echo "<input type='text' name='{$key}' id='{$key}' value='{$inputValue}' title='{$inputValue}' alt='{$inputValue}' size='40' class='{$disabledClass}' {$disabledAttr}/>"; } diff --git a/modules/sendmail/Controllers/SendMessageExchangeController.php b/modules/sendmail/Controllers/SendMessageExchangeController.php index 8a3978934bb78807b52fa44e42ec79aab372dee1..67cc725d2aa9c927b19c8d4f94ede27e97631cef 100644 --- a/modules/sendmail/Controllers/SendMessageExchangeController.php +++ b/modules/sendmail/Controllers/SendMessageExchangeController.php @@ -249,7 +249,7 @@ class SendMessageExchangeController $oComment = new stdClass(); $date = new DateTime($value['date_note']); $entityRoot = \Entity\models\EntityModel::getEntityRootById(['entityId' => $value['entity_id']]); - $userEntity = \Entity\models\EntityModel::getById(['entityId' => $value['entity_id']]); + $userEntity = \Entity\models\entitymodel::getByEntityId(['entityId' => $value['entity_id']]); $oComment->value = $value['firstname'].' '.$value['lastname'].' - '.$date->format('d-m-Y H:i:s').' ('.$entityRoot['entity_label'].' - '.$userEntity['entity_label'].') : '.$value['note_text']; array_push($aReturn, $oComment); } diff --git a/sql/develop.sql b/sql/develop.sql index 6faa7ff0f4931abc7a6b8f991059c6591fc48053..b956aa7886efbd6858c75a5a3d446317c6d9ec9c 100644 --- a/sql/develop.sql +++ b/sql/develop.sql @@ -573,3 +573,7 @@ CREATE TABLE resource_contacts CONSTRAINT resource_contacts_pkey PRIMARY KEY (id) ) WITH (OIDS=FALSE); +ALTER TABLE entities DROP COLUMN IF EXISTS id; +ALTER TABLE entities ADD COLUMN id serial; +ALTER TABLE entities ADD UNIQUE (id); + diff --git a/sql/structure.sql b/sql/structure.sql index 432ba78280fe3aeb1ef83219bb6941e51abf6495..5946b65bab28940d11dffc9c34f9f7f09dbd0adb 100755 --- a/sql/structure.sql +++ b/sql/structure.sql @@ -442,6 +442,7 @@ CREATE TABLE cases_res CREATE TABLE entities ( + id serial NOT NULL, entity_id character varying(32) NOT NULL, entity_label character varying(255), short_label character varying(50), diff --git a/src/app/entity/controllers/EntityController.php b/src/app/entity/controllers/EntityController.php index 8288b2e8d7525f26ae3e402aec93e56220e33df1..4fd10b8760ef85650b2d458d63680e0e5625a496 100644 --- a/src/app/entity/controllers/EntityController.php +++ b/src/app/entity/controllers/EntityController.php @@ -37,7 +37,7 @@ class EntityController public function getById(Request $request, Response $response, array $aArgs) { - $entity = EntityModel::getById(['entityId' => $aArgs['id']]); + $entity = entitymodel::getByEntityId(['entityId' => $aArgs['id']]); if (empty($entity)) { return $response->withStatus(400)->withJson(['errors' => 'Entity not found']); } @@ -51,7 +51,7 @@ class EntityController return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); } - $entity = EntityModel::getById(['entityId' => $aArgs['id']]); + $entity = entitymodel::getByEntityId(['entityId' => $aArgs['id']]); if (empty($entity)) { return $response->withStatus(400)->withJson(['errors' => 'Entity not found']); } @@ -117,7 +117,7 @@ class EntityController 'sequence' => $listTemplate['sequence'], 'title' => $listTemplate['title'], 'description' => $listTemplate['description'], - 'labelToDisplay' => EntityModel::getById(['entityId' => $listTemplate['item_id'], 'select' => ['entity_label']])['entity_label'], + 'labelToDisplay' => entitymodel::getByEntityId(['entityId' => $listTemplate['item_id'], 'select' => ['entity_label']])['entity_label'], 'descriptionToDisplay' => '' ]; } @@ -172,7 +172,7 @@ class EntityController return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); } - $existingEntity = EntityModel::getById(['entityId' => $data['entity_id'], 'select' => [1]]); + $existingEntity = entitymodel::getByEntityId(['entityId' => $data['entity_id'], 'select' => [1]]); if (!empty($existingEntity)) { return $response->withStatus(400)->withJson(['errors' => _ENTITY_ID_ALREADY_EXISTS]); } @@ -215,7 +215,7 @@ class EntityController return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); } - $entity = EntityModel::getById(['entityId' => $aArgs['id'], 'select' => [1]]); + $entity = entitymodel::getByEntityId(['entityId' => $aArgs['id'], 'select' => [1]]); if (empty($entity)) { return $response->withStatus(400)->withJson(['errors' => 'Entity not found']); } @@ -292,7 +292,7 @@ class EntityController return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); } - $entity = EntityModel::getById(['entityId' => $aArgs['id'], 'select' => [1]]); + $entity = entitymodel::getByEntityId(['entityId' => $aArgs['id'], 'select' => [1]]); if (empty($entity)) { return $response->withStatus(400)->withJson(['errors' => 'Entity not found']); } @@ -336,8 +336,8 @@ class EntityController return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); } - $dyingEntity = EntityModel::getById(['entityId' => $aArgs['id'], 'select' => ['parent_entity_id']]); - $successorEntity = EntityModel::getById(['entityId' => $aArgs['newEntityId'], 'select' => [1]]); + $dyingEntity = entitymodel::getByEntityId(['entityId' => $aArgs['id'], 'select' => ['parent_entity_id']]); + $successorEntity = entitymodel::getByEntityId(['entityId' => $aArgs['newEntityId'], 'select' => [1]]); if (empty($dyingEntity) || empty($successorEntity)) { return $response->withStatus(400)->withJson(['errors' => 'Entity does not exist']); } @@ -411,7 +411,7 @@ class EntityController return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); } - $entity = EntityModel::getById(['entityId' => $aArgs['id'], 'select' => [1]]); + $entity = entitymodel::getByEntityId(['entityId' => $aArgs['id'], 'select' => [1]]); if (empty($entity)) { return $response->withStatus(400)->withJson(['errors' => 'Entity not found']); } diff --git a/src/app/entity/controllers/ListTemplateController.php b/src/app/entity/controllers/ListTemplateController.php index c0ad197d72d3eb585fb6be639910a273d7996dfc..d9d8e5d14538c62ebe4308dc57994c39f192b05e 100644 --- a/src/app/entity/controllers/ListTemplateController.php +++ b/src/app/entity/controllers/ListTemplateController.php @@ -52,7 +52,7 @@ class ListTemplateController foreach ($listTemplates as $key => $value) { if ($value['item_type'] == 'entity_id') { - $listTemplates[$key]['idToDisplay'] = EntityModel::getById(['entityId' => $value['item_id'], 'select' => ['entity_label']])['entity_label']; + $listTemplates[$key]['idToDisplay'] = entitymodel::getByEntityId(['entityId' => $value['item_id'], 'select' => ['entity_label']])['entity_label']; $listTemplates[$key]['descriptionToDisplay'] = ''; } else { $listTemplates[$key]['idToDisplay'] = UserModel::getLabelledUserById(['userId' => $value['item_id']]); @@ -319,7 +319,7 @@ class ListTemplateController $roles[$key]['usedIn'] = []; $listTemplates = ListTemplateModel::get(['select' => ['object_id'], 'where' => ['object_type = ?', 'item_mode = ?'], 'data' => [$aArgs['typeId'], $roles[$key]['id']]]); foreach ($listTemplates as $listTemplate) { - $entity = EntityModel::getById(['select' => ['short_label'], 'entityId' => $listTemplate['object_id']]); + $entity = entitymodel::getByEntityId(['select' => ['short_label'], 'entityId' => $listTemplate['object_id']]); $roles[$key]['usedIn'][] = $entity['short_label']; } } diff --git a/src/app/entity/models/EntityModelAbstract.php b/src/app/entity/models/EntityModelAbstract.php index a226b14325fea9509c52a531889fec67f3545c38..ad1a958f27d23a3e5079ec7bc782a22047b6bb04 100644 --- a/src/app/entity/models/EntityModelAbstract.php +++ b/src/app/entity/models/EntityModelAbstract.php @@ -39,6 +39,25 @@ abstract class EntityModelAbstract } public static function getById(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['id']); + ValidatorModel::stringType($aArgs, ['id']); + + $aEntity = DatabaseModel::select([ + 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], + 'table' => ['entities'], + 'where' => ['id = ?'], + 'data' => [$aArgs['id']] + ]); + + if (empty($aEntity[0])) { + return []; + } + + return $aEntity[0]; + } + + public static function getByEntityId(array $aArgs) { ValidatorModel::notEmpty($aArgs, ['entityId']); ValidatorModel::stringType($aArgs, ['entityId']); @@ -50,6 +69,10 @@ abstract class EntityModelAbstract 'data' => [$aArgs['entityId']] ]); + if (empty($aEntity[0])) { + return []; + } + return $aEntity[0]; } @@ -192,7 +215,7 @@ abstract class EntityModelAbstract ValidatorModel::notEmpty($aArgs, ['entityId']); ValidatorModel::stringType($aArgs, ['entityId']); - $aReturn = EntityModel::getById([ + $aReturn = entitymodel::getByEntityId([ 'select' => ['entity_id', 'entity_label', 'parent_entity_id'], 'entityId' => $aArgs['entityId'] ]); diff --git a/src/app/resource/models/ResourceContactModel.php b/src/app/resource/models/ResourceContactModel.php new file mode 100644 index 0000000000000000000000000000000000000000..6ab193a04a37e57fe09101653f10147cc4654edd --- /dev/null +++ b/src/app/resource/models/ResourceContactModel.php @@ -0,0 +1,108 @@ +<?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 Resource Contact Model +* @author dev@maarch.org +*/ + +namespace Resource\models; + +use Contact\models\ContactModel; +use Entity\models\EntityModel; +use SrcCore\controllers\AutoCompleteController; +use SrcCore\models\DatabaseModel; +use SrcCore\models\ValidatorModel; +use User\models\UserModel; + +class ResourceContactModel +{ + public static function getByResId(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['resId']); + ValidatorModel::intVal($aArgs, ['resId']); + + $aContacts = DatabaseModel::select([ + 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], + 'table' => ['resource_contacts'], + 'where' => ['res_id = ?'], + 'data' => [$aArgs['resId']], + ]); + + return $aContacts; + } + + public static function getFormattedByResId(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['resId']); + ValidatorModel::intVal($aArgs, ['resId']); + + $aContacts = DatabaseModel::select([ + 'select' => ['*'], + 'table' => ['resource_contacts'], + 'where' => ['res_id = ?'], + 'data' => [$aArgs['resId']], + ]); + + foreach ($aContacts as $key => $aContact) { + if ($aContact['type'] == 'user') { + $aContacts[$key]['format'] = UserModel::getLabelledUserById(['id' => $aContact['item_id']]); + } elseif ($aContact['type'] == 'contact') { + $contact = ContactModel::getOnView([ + 'select' => [ + 'is_corporate_person', 'lastname', 'firstname', 'address_num', 'address_street', 'address_town', 'address_postal_code', + 'ca_id', 'society', 'contact_firstname', 'contact_lastname' + ], + 'where' => ['ca_id = ?'], + 'data' => [$aContact['item_id']] + ]); + $contact = AutoCompleteController::getFormattedContact(['contact' => $contact[0]]); + $aContacts[$key]['format'] = $contact['contact']['otherInfo']; + } elseif ($aContact['type'] == 'entity') { + $entity = EntityModel::getById(['id' => $aContact['item_id'], 'select' => ['entity_label']]); + $aContacts[$key]['format'] = $entity['entity_label']; + } + } + + return $aContacts; + } + + public static function create(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['res_id', 'item_id', 'type', 'mode']); + ValidatorModel::intVal($aArgs, ['res_id', 'item_id']); + ValidatorModel::stringType($aArgs, ['type', 'mode']); + + DatabaseModel::insert([ + 'table' => 'resource_contacts', + 'columnsValues' => [ + 'res_id' => $aArgs['res_id'], + 'item_id' => $aArgs['item_id'], + 'type' => $aArgs['type'], + 'mode' => $aArgs['mode'] + ] + ]); + + return true; + } + + public static function delete(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['where', 'data']); + ValidatorModel::arrayType($aArgs, ['where', 'data']); + + DatabaseModel::delete([ + 'table' => 'resource_contacts', + 'where' => $aArgs['where'], + 'data' => $aArgs['data'] + ]); + + return true; + } +} diff --git a/src/app/user/controllers/UserController.php b/src/app/user/controllers/UserController.php index 0298ee9f8282318f05f7479818154af8b161ad37..6a453fe9cd33c2ffe444d0d246b13a27c35922b2 100644 --- a/src/app/user/controllers/UserController.php +++ b/src/app/user/controllers/UserController.php @@ -780,7 +780,7 @@ class UserController if (!$this->checkNeededParameters(['data' => $data, 'needed' => ['entityId']])) { return $response->withStatus(400)->withJson(['errors' => 'Bad Request']); } - if (empty(EntityModel::getById(['entityId' => $data['entityId']]))) { + if (empty(entitymodel::getByEntityId(['entityId' => $data['entityId']]))) { return $response->withStatus(400)->withJson(['errors' => 'Entity not found']); } elseif (UserModel::hasEntity(['id' => $aArgs['id'], 'entityId' => $data['entityId']])) { return $response->withStatus(400)->withJson(['errors' => _USER_ALREADY_LINK_ENTITY]); @@ -817,7 +817,7 @@ class UserController if (!empty($error['error'])) { return $response->withStatus($error['status'])->withJson(['errors' => $error['error']]); } - if (empty(EntityModel::getById(['entityId' => $aArgs['entityId']]))) { + if (empty(entitymodel::getByEntityId(['entityId' => $aArgs['entityId']]))) { return $response->withStatus(400)->withJson(['errors' => 'Entity not found']); } @@ -845,7 +845,7 @@ class UserController if (!empty($error['error'])) { return $response->withStatus($error['status'])->withJson(['errors' => $error['error']]); } - if (empty(EntityModel::getById(['entityId' => $aArgs['entityId']]))) { + if (empty(entitymodel::getByEntityId(['entityId' => $aArgs['entityId']]))) { return $response->withStatus(400)->withJson(['errors' => 'Entity not found']); } @@ -861,7 +861,7 @@ class UserController if (!empty($error['error'])) { return $response->withStatus($error['status'])->withJson(['errors' => $error['error']]); } - if (empty(EntityModel::getById(['entityId' => $aArgs['entityId']]))) { + if (empty(entitymodel::getByEntityId(['entityId' => $aArgs['entityId']]))) { return $response->withStatus(400)->withJson(['errors' => 'Entity not found']); } @@ -967,7 +967,7 @@ class UserController if (!empty($error['error'])) { return $response->withStatus($error['status'])->withJson(['errors' => $error['error']]); } - if (empty(EntityModel::getById(['entityId' => $aArgs['entityId']]))) { + if (empty(entitymodel::getByEntityId(['entityId' => $aArgs['entityId']]))) { return $response->withStatus(400)->withJson(['errors' => 'Entity not found']); } diff --git a/src/core/controllers/PreparedClauseController.php b/src/core/controllers/PreparedClauseController.php index 004a3c38e4ab446e70e913c21e740fae602817ff..e36ce707540564b3193a7351d710d2176bcfeed8 100644 --- a/src/core/controllers/PreparedClauseController.php +++ b/src/core/controllers/PreparedClauseController.php @@ -153,7 +153,7 @@ class PreparedClauseController for ($i = 0; $i < $total; $i++) { $tmpParentEntity = trim(str_replace("'", '', $parentEntity[1][$i])); if (!empty($tmpParentEntity)) { - $entity = EntityModel::getById(['entityId' => $tmpParentEntity, 'select' => ['entity_id', 'parent_entity_id']]); + $entity = entitymodel::getByEntityId(['entityId' => $tmpParentEntity, 'select' => ['entity_id', 'parent_entity_id']]); } if (empty($entity['parent_entity_id'])) { $parentEntityClause = "''"; @@ -169,7 +169,7 @@ class PreparedClauseController if ($total > 0) { for ($i = 0; $i < $total; $i++) { $tmpSisterEntity = trim(str_replace("'", '', $sistersEntities[1][$i])); - $sisterEntity = EntityModel::getById(['entityId' => $tmpSisterEntity, 'select' => ['parent_entity_id']]); + $sisterEntity = entitymodel::getByEntityId(['entityId' => $tmpSisterEntity, 'select' => ['parent_entity_id']]); $allSisterEntities = EntityModel::get(['select' => ['entity_id'], 'where' => ['parent_entity_id = ?'], 'data' => [$sisterEntity['parent_entity_id']]]); $allSisterEntitiesClause = '';