diff --git a/rest/index.php b/rest/index.php index 8577150059f2ded5ccabf31aa37989b8285f52aa..45c4fc9b24289f2a33fa6de638d4c83a8b8096eb 100755 --- a/rest/index.php +++ b/rest/index.php @@ -199,7 +199,7 @@ $app->get('/links/resId/{resId}', \Link\controllers\LinkController::class . ':ge //Listinstance $app->get('/listinstance/{id}', \Entity\controllers\ListInstanceController::class . ':getById'); -$app->get('/res/{resId}/listinstance', \Entity\controllers\ListInstanceController::class . ':getListByResId'); +$app->get('/resources/{resId}/listInstance', \Entity\controllers\ListInstanceController::class . ':getByResId'); $app->get('/res/{resId}/visaCircuit', \Entity\controllers\ListInstanceController::class . ':getVisaCircuitByResId'); $app->get('/res/{resId}/avisCircuit', \Entity\controllers\ListInstanceController::class . ':getAvisCircuitByResId'); $app->put('/listinstances', \Entity\controllers\ListInstanceController::class . ':update'); diff --git a/src/app/entity/controllers/ListInstanceController.php b/src/app/entity/controllers/ListInstanceController.php index cd8a8bc9340d35e2ce37c412e816bc86cb1b7ef8..c477873ffad7a888426b7a9804121e62671e7595 100755 --- a/src/app/entity/controllers/ListInstanceController.php +++ b/src/app/entity/controllers/ListInstanceController.php @@ -33,25 +33,24 @@ class ListInstanceController return $response->withJson($listinstance); } - public function getListByResId(Request $request, Response $response, array $aArgs) + public function getByResId(Request $request, Response $response, array $args) { - if (!Validator::intVal()->validate($aArgs['resId']) || !ResController::hasRightByResId(['resId' => $aArgs['resId'], 'userId' => $GLOBALS['userId']])) { + if (!Validator::intVal()->validate($args['resId']) || !ResController::hasRightByResId(['resId' => $args['resId'], 'userId' => $GLOBALS['userId']])) { return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']); } - $listinstances = ListInstanceModel::getListByResId(['select' => ['listinstance_id', 'sequence', 'CASE WHEN item_mode=\'cc\' THEN \'copy\' ELSE item_mode END', 'item_id', 'item_type', 'firstname as item_firstname', 'lastname as item_lastname', 'entity_label as item_entity', 'viewed', 'process_date', 'process_comment', 'signatory', 'requested_signature'], 'id' => $aArgs['resId']]); - - $roles = EntityModel::getRoles(); - $listinstancesFormat = []; - foreach ($listinstances as $key2 => $listinstance) { - foreach ($roles as $key => $role) { - if ($role['id'] == $listinstance['item_mode']) { - $listinstancesFormat[$role['label']][] = $listinstance; - } + $listinstances = ListInstanceModel::get(['select' => ['*'], 'where' => ['res_id = ?', 'difflist_type = ?'], 'data' => [$args['resId'], 'entity_id']]); + foreach ($listinstances as $key => $value) { + if ($value['item_type'] == 'entity_id') { + $listTemplates[$key]['labelToDisplay'] = Entitymodel::getByEntityId(['entityId' => $value['item_id'], 'select' => ['entity_label']])['entity_label']; + $listTemplates[$key]['descriptionToDisplay'] = ''; + } else { + $listTemplates[$key]['labelToDisplay'] = UserModel::getLabelledUserById(['login' => $value['item_id']]); + $listTemplates[$key]['descriptionToDisplay'] = UserModel::getPrimaryEntityByUserId(['userId' => $value['item_id']])['entity_label']; } } - return $response->withJson($listinstancesFormat); + return $response->withJson(['listInstance' => $listinstances]); } public function getVisaCircuitByResId(Request $request, Response $response, array $aArgs) diff --git a/src/app/entity/controllers/ListTemplateController.php b/src/app/entity/controllers/ListTemplateController.php index 4f93a100b3c8cd0852fcd191e1ee5487a111147e..d31ea32cf2287a7dd38ab3db8f52fb323e5d0bb6 100755 --- a/src/app/entity/controllers/ListTemplateController.php +++ b/src/app/entity/controllers/ListTemplateController.php @@ -268,7 +268,7 @@ class ListTemplateController foreach ($listTemplates as $key => $value) { if ($value['item_type'] == 'entity_id') { - $listTemplates[$key]['labelToDisplay'] = entitymodel::getByEntityId(['entityId' => $value['item_id'], 'select' => ['entity_label']])['entity_label']; + $listTemplates[$key]['labelToDisplay'] = Entitymodel::getByEntityId(['entityId' => $value['item_id'], 'select' => ['entity_label']])['entity_label']; $listTemplates[$key]['descriptionToDisplay'] = ''; } else { $listTemplates[$key]['labelToDisplay'] = UserModel::getLabelledUserById(['login' => $value['item_id']]); diff --git a/src/app/entity/models/ListInstanceModelAbstract.php b/src/app/entity/models/ListInstanceModelAbstract.php index 73712f4ac91557de079625cc604a1467b94b5631..3b8842167a914987e410737292c9118d01967a13 100755 --- a/src/app/entity/models/ListInstanceModelAbstract.php +++ b/src/app/entity/models/ListInstanceModelAbstract.php @@ -88,36 +88,6 @@ abstract class ListInstanceModelAbstract return true; } - public static function getListByResId(array $aArgs) - { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id']); - ValidatorModel::arrayType($aArgs, ['select']); - - $aListinstance = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['listinstance', 'users', 'users_entities', 'entities'], - 'left_join' => ['listinstance.item_id = users.user_id', 'users_entities.user_id = users.user_id', 'entities.entity_id = users_entities.entity_id'], - 'where' => ['res_id = ?', 'item_type = ?', 'difflist_type = ?', 'primary_entity = ?'], - 'data' => [$aArgs['id'], 'user_id', 'entity_id', 'Y'], - 'order_by' => ['listinstance_id ASC'], - ]); - - unset($aArgs['select'][5]); - unset($aArgs['select'][6]); - - $aListinstance2 = DatabaseModel::select([ - 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], - 'table' => ['listinstance', 'entities'], - 'left_join' => ['listinstance.item_id = entities.entity_id'], - 'where' => ['res_id = ?', 'item_type = ?', 'difflist_type = ?'], - 'data' => [$aArgs['id'], 'entity_id', 'entity_id'], - 'order_by' => ['listinstance_id ASC'], - ]); - - return array_merge($aListinstance, $aListinstance2); - } - public static function getVisaCircuitByResId(array $aArgs) { ValidatorModel::notEmpty($aArgs, ['id']);