diff --git a/src/administrator/models/role.php b/src/administrator/models/role.php index 5e1633e..400a81b 100755 --- a/src/administrator/models/role.php +++ b/src/administrator/models/role.php @@ -12,6 +12,7 @@ use Joomla\CMS\MVC\Model\AdminModel; use Joomla\CMS\Table\Table; +use Joomla\CMS\Factory; /** * Subusers model. @@ -154,4 +155,45 @@ public function save($data) return true; } + + /** + * Method to get a roles by actions. + * + * @param array $actions array of action code. + * @param string $client name of action client. + * @param int $clientId client id. + * + * @return array indexed array of associated arrays. + * + * @since __DEPLOY__VERSION__ + */ + public function getAuthorizeRoles($actions = array(), $client = null, $clientId = null) + { + if (!empty($actions)) + { + $db = Factory::getDbo(); + $query = $db->getQuery(true); + $query->select($db->quoteName(('id'))); + $query->from($db->quoteName('#__tjsu_actions')); + + if ($client) + { + $query->where($db->quoteName('client') . ' = ' . $db->quote($client)); + } + + foreach ($actions as $action) + { + $query->where($db->quoteName('code') . ' = ' . $db->quote($action)); + } + + $db->setQuery($query); + + $actionIds = $db->loadColumn(); + + // Get role ids by providing action ids + $actionModel = RBACL::model("action"); + + return $actionModel->getAssignedRoles($actionIds); + } + } } diff --git a/src/administrator/models/users.php b/src/administrator/models/users.php index b0e812e..e3f9814 100755 --- a/src/administrator/models/users.php +++ b/src/administrator/models/users.php @@ -102,12 +102,20 @@ protected function getListQuery() $db = $this->getDbo(); $query = $db->getQuery(true); - $query->select(array('a.*', 'uc.name', 'rl.name as rolename')); + $query->select(array('a.*', 'uc.name','uc.email', 'rl.name as rolename')); $query->from('`#__tjsu_users` AS a'); $query->join('INNER', $db->quoteName('#__users', 'uc') . ' ON (' . $db->quoteName('a.user_id') . ' = ' . $db->quoteName('uc.id') . ')'); $query->join('INNER', $db->quoteName('#__tjsu_roles', 'rl') . ' ON (' . $db->quoteName('rl.id') . ' = ' . $db->quoteName('a.role_id') . ')'); $search = $this->getState('filter.search'); + // If the model is set to check item state, add to the query. + $state = $this->getState('filter.state'); + + if (is_numeric($state)) + { + $query->where('uc.block = ' . (int) $state); + } + if (!empty($search)) { if (stripos($search, 'id:') === 0) @@ -125,7 +133,14 @@ protected function getListQuery() if (!empty($roleId)) { - $query->where($db->quoteName('a.role_id') . " = " . (int) $roleId); + if (is_array($roleId)) + { + $query->where($db->quoteName('a.role_id') . 'IN (' . implode(',', $db->quote($roleId)) . ')'); + } + else + { + $query->where($db->quoteName('a.role_id') . " = " . (int) $roleId); + } } $client = $this->getState('filter.client'); @@ -139,7 +154,21 @@ protected function getListQuery() if (!empty($clientId)) { - $query->where($db->quoteName('a.client_id') . " = " . (int) $clientId); + if (is_array($clientId)) + { + $query->where($db->quoteName('a.client_id') . 'IN (' . implode(',', $db->quote($clientId)) . ')'); + } + else + { + $query->where($db->quoteName('a.client_id') . " = " . (int) $clientId); + } + } + + $groupBy = $this->getState('group_by'); + + if (!empty($groupBy)) + { + $query->group($db->quoteName('a.' . $groupBy)); } $orderCol = $this->state->get('list.ordering');