diff --git a/src/app/group/controllers/ServiceController.php b/src/app/group/controllers/ServiceController.php index 9e4b263c716b9bc93de2eb0a96977ce5273f0bb1..ee0a2c2284920ba5ef94532fcb9568cf5ee792f6 100755 --- a/src/app/group/controllers/ServiceController.php +++ b/src/app/group/controllers/ServiceController.php @@ -8,7 +8,15 @@ use User\models\UserModel; class ServiceController { - public static function getMenuServicesByUserId(array $aArgs) + const SERVICE_MENU = [ + "admin", + "adv_search_mlb", + "entities_print_sep_mlb", + "reports", + "save_numeric_package" + ]; + + public static function getMenuServicesByUserIdByXml(array $aArgs) { ValidatorModel::notEmpty($aArgs, ['userId']); ValidatorModel::stringType($aArgs, ['userId']); @@ -44,4 +52,39 @@ class ServiceController return $menu; } + + public static function getMenuServicesByUserId(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['userId']); + ValidatorModel::stringType($aArgs, ['userId']); + + $rawServicesStoredInDB = ServiceModel::getByUserId(['userId' => $aArgs['userId']]); + $servicesStoredInDB = array_column($rawServicesStoredInDB, 'service_id'); + + $menu = []; + if (!empty($servicesStoredInDB)) { + foreach ($servicesStoredInDB as $service) { + if (in_array($service, self::SERVICE_MENU)) { + $menu[] = $service; + } + } + } + + $userGroups = UserModel::getGroupsByLogin(['login' => $aArgs['userId']]); + $indexingGroups = []; + foreach ($userGroups as $group) { + if ($group['can_index']) { + $indexingGroups[] = ['id' => $group['id'], 'label' => $group['group_desc']]; + } + } + if (!empty($indexingGroups)) { + $menu[] = 'indexing'; + } + + return $menu; + } + + public static function getServicesMenu() { + return self::SERVICE_MENU; + } } diff --git a/src/app/group/models/ServiceModelAbstract.php b/src/app/group/models/ServiceModelAbstract.php index 170d100170279bb291cc81749c0fe4efc19be8d9..68af25f40e3ee049b53cc31208fbcb9b6f9279f4 100755 --- a/src/app/group/models/ServiceModelAbstract.php +++ b/src/app/group/models/ServiceModelAbstract.php @@ -324,6 +324,35 @@ abstract class ServiceModelAbstract return false; } + public static function hasService2(array $args) + { + ValidatorModel::notEmpty($args, ['serviceId', 'userId']); + ValidatorModel::stringType($args, ['serviceId']); + ValidatorModel::intVal($args, ['userId']); + + $user = UserModel::getById([ + 'select' => ['user_id'], + 'id' => $args['userId'] + ]); + if ($user['user_id'] == 'superadmin') { + return true; + } + + $aServices = DatabaseModel::select([ + 'select' => ['usergroups_services.service_id'], + 'table' => ['usergroup_content, usergroups_services, usergroups'], + 'where' => [ + 'usergroup_content.group_id = usergroups.id', + 'usergroups.group_id = usergroups_services.group_id', + 'usergroup_content.user_id = ?', + 'usergroups_services.service_id = ?' + ], + 'data' => [$args['userId'], $args['serviceId']] + ]); + + return !empty($aServices); + } + public static function canIndex(array $args) { ValidatorModel::notEmpty($args, ['userId']); diff --git a/src/core/controllers/CoreController.php b/src/core/controllers/CoreController.php index f6851428b2daa6765b8d084ebeff119a57f94265..f27ed86d1eb6ed97be882e622df949c8c4a265be 100755 --- a/src/core/controllers/CoreController.php +++ b/src/core/controllers/CoreController.php @@ -85,12 +85,18 @@ class CoreController $user['groups'] = UserModel::getGroupsByLogin(['login' => $GLOBALS['userId']]); $user['entities'] = UserModel::getEntitiesByLogin(['login' => $GLOBALS['userId']]); +// if ($GLOBALS['userId'] == 'superadmin') { +// $menu = ServiceController::getServicesMenu(); +// } else { +// $menu = ServiceController::getMenuServicesByUserId(['userId' => $GLOBALS['userId']]); +// } + if ($GLOBALS['userId'] == 'superadmin') { $menu = ServiceModel::getApplicationServicesByXML(['type' => 'menu']); $menuModules = ServiceModel::getModulesServicesByXML(['type' => 'menu']); $menu = array_merge($menu, $menuModules); } else { - $menu = ServiceController::getMenuServicesByUserId(['userId' => $GLOBALS['userId']]); + $menu = ServiceController::getMenuServicesByUserIdByXml(['userId' => $GLOBALS['userId']]); } return $response->withJson([ @@ -105,10 +111,10 @@ class CoreController ['id' => 'home'] ]; - if (ServiceModel::hasService(['id' => 'admin', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'menu'])) { + if (ServiceModel::hasService2(['serviceId' => 'admin', 'userId' => $GLOBALS['id']])) { $shortcuts[] = ['id' => 'administration']; } - if (ServiceModel::hasService(['id' => 'adv_search_mlb', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'menu'])) { + if (ServiceModel::hasService2(['serviceId' => 'adv_search_mlb', 'userId' => $GLOBALS['id']])) { $shortcuts[] = ['id' => 'search']; }