Skip to content
Snippets Groups Projects
Verified Commit e6e7338f authored by Damien's avatar Damien
Browse files

FEAT #9685 List Template by entity id

parent 774e7c9c
No related branches found
No related tags found
No related merge requests found
......@@ -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');
......
......@@ -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";
......
......@@ -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'])) {
......
......@@ -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'],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment