diff --git a/src/administrator/models/role.php b/src/administrator/models/role.php index 5d24833..90c7c12 100755 --- a/src/administrator/models/role.php +++ b/src/administrator/models/role.php @@ -11,6 +11,7 @@ use Joomla\CMS\MVC\Model\AdminModel; use Joomla\CMS\Table\Table; +use Joomla\CMS\Factory; /** * Subusers model. @@ -153,4 +154,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 3a5e029..3850eed 100755 --- a/src/administrator/models/users.php +++ b/src/administrator/models/users.php @@ -101,12 +101,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) @@ -120,6 +128,48 @@ protected function getListQuery() } } + $roleId = $this->getState('filter.role_id'); + + if (!empty($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'); + + if (!empty($client)) + { + $query->where($db->quoteName('a.client') . " = " . $db->quote($client)); + } + + $clientId = $this->getState('filter.client_id'); + + if (!empty($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'); $orderDirn = $this->state->get('list.direction');