diff --git a/rest/index.php b/rest/index.php index 7c867e1b806d1e85c8602e1a7d0de4206fc7efee..7757102b0cd1f8d10ff27ccc3398ae9372ae0cee 100755 --- a/rest/index.php +++ b/rest/index.php @@ -209,6 +209,7 @@ $app->post('/listTemplates', \Entity\controllers\ListTemplateController::class . $app->get('/listTemplates/{id}', \Entity\controllers\ListTemplateController::class . ':getById'); $app->put('/listTemplates/{id}', \Entity\controllers\ListTemplateController::class . ':update'); $app->delete('/listTemplates/{id}', \Entity\controllers\ListTemplateController::class . ':delete'); +$app->get('/listTemplates/entities/{entityId}', \Entity\controllers\ListTemplateController::class . ':getByEntityId'); $app->put('/listTemplates/entityDest/itemId/{itemId}', \Entity\controllers\ListTemplateController::class . ':updateByUserWithEntityDest'); $app->get('/listTemplates/types/{typeId}/roles', \Entity\controllers\ListTemplateController::class . ':getTypeRoles'); $app->put('/listTemplates/types/{typeId}/roles', \Entity\controllers\ListTemplateController::class . ':updateTypeRoles'); diff --git a/src/app/action/controllers/ActionMethodController.php b/src/app/action/controllers/ActionMethodController.php index 6ef7a20ed077f1bb804658687d1c47196a73c4fc..3455208af9cb94dffbc965478ed3cc22b8676205 100644 --- a/src/app/action/controllers/ActionMethodController.php +++ b/src/app/action/controllers/ActionMethodController.php @@ -293,9 +293,8 @@ class ActionMethodController $allowedEntities = array_unique($allowedEntities); - $allEntities = EntityModel::get(['select' => ['entity_id', 'entity_label', 'parent_entity_id'], 'where' => ['enabled = ?'], 'data' => ['Y'], 'orderBy' => ['parent_entity_id']]); + $allEntities = EntityModel::get(['select' => ['id', 'entity_id', 'entity_label', 'parent_entity_id'], 'where' => ['enabled = ?'], 'data' => ['Y'], 'orderBy' => ['parent_entity_id']]); foreach ($allEntities as $key => $value) { - $allEntities[$key]['id'] = $value['entity_id']; if (empty($value['parent_entity_id'])) { $allEntities[$key]['parent'] = '#'; $allEntities[$key]['icon'] = "fa fa-building"; diff --git a/src/app/entity/controllers/ListTemplateController.php b/src/app/entity/controllers/ListTemplateController.php index d65586a9905661f0ef71f00dd0e489e9c9789216..bc0a7e754cf47473c8b7996883b654b34d681ea2 100755 --- a/src/app/entity/controllers/ListTemplateController.php +++ b/src/app/entity/controllers/ListTemplateController.php @@ -257,6 +257,28 @@ class ListTemplateController return $response->withJson(['success' => 'success']); } + public function getByEntityId(Request $request, Response $response, array $args) + { + $entity = EntityModel::getById(['select' => ['entity_id'], 'id' => $args['entityId']]); + if (empty($entity)) { + return $response->withStatus(400)->withJson(['errors' => 'Entity does not exist']); + } + + $listTemplates = ListTemplateModel::get(['select' => ['*'], 'where' => ['object_id = ?', 'object_type = ?'], 'data' => [$entity['entity_id'], 'entity_id']]); + + foreach ($listTemplates as $key => $value) { + if ($value['item_type'] == 'entity_id') { + $listTemplates[$key]['idToDisplay'] = entitymodel::getByEntityId(['entityId' => $value['item_id'], 'select' => ['entity_label']])['entity_label']; + $listTemplates[$key]['descriptionToDisplay'] = ''; + } else { + $listTemplates[$key]['idToDisplay'] = UserModel::getLabelledUserById(['login' => $value['item_id']]); + $listTemplates[$key]['descriptionToDisplay'] = UserModel::getPrimaryEntityByUserId(['userId' => $value['item_id']])['entity_label']; + } + } + + return $response->withJson(['listTemplate' => $listTemplates]); + } + public function updateByUserWithEntityDest(Request $request, Response $response) { if (!ServiceModel::hasService(['id' => 'admin_users', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { diff --git a/src/app/entity/models/EntityModelAbstract.php b/src/app/entity/models/EntityModelAbstract.php index acdb9f9425e5c7f456a975fe5534487811d6191c..6f231089e9f1095ade2f51ecac3d572daf6af859 100755 --- a/src/app/entity/models/EntityModelAbstract.php +++ b/src/app/entity/models/EntityModelAbstract.php @@ -41,7 +41,7 @@ abstract class EntityModelAbstract public static function getById(array $aArgs) { ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intType($aArgs, ['id']); + ValidatorModel::intVal($aArgs, ['id']); $aEntity = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'],