From 73fe64a271679b223fa564398ad0d76eea12dc75 Mon Sep 17 00:00:00 2001 From: Damien <damien.burel@maarch.org> Date: Wed, 3 Oct 2018 16:05:24 +0200 Subject: [PATCH] FEAT #8426 Refactoring --- src/app/entity/controllers/EntityController.php | 8 +------- src/app/entity/models/EntityModelAbstract.php | 4 ++-- src/app/group/controllers/GroupController.php | 7 +------ src/app/group/models/GroupModelAbstract.php | 4 ++-- 4 files changed, 6 insertions(+), 17 deletions(-) diff --git a/src/app/entity/controllers/EntityController.php b/src/app/entity/controllers/EntityController.php index 8cc119e8b84..a5fbdf49cd0 100644 --- a/src/app/entity/controllers/EntityController.php +++ b/src/app/entity/controllers/EntityController.php @@ -25,7 +25,6 @@ use Respect\Validation\Validator; use Slim\Http\Request; use Slim\Http\Response; use Template\models\TemplateAssociationModel; -use Template\models\TemplateModel; use User\models\UserEntityModel; use User\models\UserModel; @@ -138,12 +137,7 @@ class EntityController } } - $tmpUsers = EntityModel::getUsersById(['id' => $entity['entity_id'], 'select' => ['users.id','users.user_id', 'users.firstname', 'users.lastname', 'users.status']]); - foreach ($tmpUsers as $tmpUser) { - if ($tmpUser['status'] != 'DEL') { - $entity['users'][] = array_slice($tmpUser, 0, 4, true); - } - } + $entity['users'] = EntityModel::getUsersById(['id' => $entity['entity_id'], 'select' => ['users.id','users.user_id', 'users.firstname', 'users.lastname']]); $children = EntityModel::get(['select' => [1], 'where' => ['parent_entity_id = ?'], 'data' => [$aArgs['id']]]); $entity['hasChildren'] = count($children) > 0; $documents = ResModel::get(['select' => [1], 'where' => ['destination = ?'], 'data' => [$aArgs['id']]]); diff --git a/src/app/entity/models/EntityModelAbstract.php b/src/app/entity/models/EntityModelAbstract.php index ebeff7ccfcc..a226b14325f 100644 --- a/src/app/entity/models/EntityModelAbstract.php +++ b/src/app/entity/models/EntityModelAbstract.php @@ -333,8 +333,8 @@ abstract class EntityModelAbstract $aUsers = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], 'table' => ['users_entities, users'], - 'where' => ['users_entities.entity_id = ?', 'users_entities.user_id = users.user_id'], - 'data' => [$aArgs['id']] + 'where' => ['users_entities.entity_id = ?', 'users_entities.user_id = users.user_id', 'users.status != ?'], + 'data' => [$aArgs['id'], 'DEL'] ]); return $aUsers; diff --git a/src/app/group/controllers/GroupController.php b/src/app/group/controllers/GroupController.php index eb59aafa546..a4699f7add7 100644 --- a/src/app/group/controllers/GroupController.php +++ b/src/app/group/controllers/GroupController.php @@ -137,12 +137,7 @@ class GroupController $group['security'] = GroupModel::getSecurityByGroupId(['groupId' => $group['group_id']]); $group['services'] = GroupModel::getAllServicesByGroupId(['groupId' => $group['group_id']]); - $tmpUsers = GroupModel::getUsersByGroupId(['groupId' => $group['group_id'], 'select' => ['users.id', 'users.user_id', 'users.firstname', 'users.lastname', 'users.status']]); - foreach ($tmpUsers as $tmpUser) { - if ($tmpUser['status'] != 'DEL') { - $group['users'][] = array_slice($tmpUser, 0, 4, true); - } - } + $group['users'] = GroupModel::getUsersByGroupId(['groupId' => $group['group_id'], 'select' => ['users.id', 'users.user_id', 'users.firstname', 'users.lastname']]); $group['baskets'] = GroupBasketModel::getBasketsByGroupId(['select' => ['baskets.basket_id', 'baskets.basket_name', 'baskets.basket_desc'], 'groupId' => $group['group_id']]); $group['canAdminUsers'] = ServiceModel::hasService(['id' => 'admin_users', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin']); $group['canAdminBaskets'] = ServiceModel::hasService(['id' => 'admin_baskets', 'userId' => $GLOBALS['userId'], 'location' => 'basket', 'type' => 'admin']); diff --git a/src/app/group/models/GroupModelAbstract.php b/src/app/group/models/GroupModelAbstract.php index f1c0ad73966..d9ff93ae1be 100644 --- a/src/app/group/models/GroupModelAbstract.php +++ b/src/app/group/models/GroupModelAbstract.php @@ -184,8 +184,8 @@ abstract class GroupModelAbstract $aUsers = DatabaseModel::select([ 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], 'table' => ['usergroup_content, users'], - 'where' => ['group_id = ?', 'usergroup_content.user_id = users.user_id'], - 'data' => [$aArgs['groupId']] + 'where' => ['group_id = ?', 'usergroup_content.user_id = users.user_id', 'users.status != ?'], + 'data' => [$aArgs['groupId'], 'DEL'] ]); return $aUsers; -- GitLab