diff --git a/src/components/com_cluster/administrator/models/clusteruser.php b/src/components/com_cluster/administrator/models/clusteruser.php index 9aeda3f..40e2309 100644 --- a/src/components/com_cluster/administrator/models/clusteruser.php +++ b/src/components/com_cluster/administrator/models/clusteruser.php @@ -12,6 +12,7 @@ use Joomla\CMS\Factory; use Joomla\CMS\MVC\Model\AdminModel; use Joomla\CMS\Table\Table; +use Joomla\CMS\Component\ComponentHelper; /** * Item Model for an Cluster. @@ -110,4 +111,74 @@ public function save($data) return parent::save($data); } + + /** + * Method to get the list of clusters to which user have access + * + * @param INT $userId Users Id. + * + * @return ARRAY List of clusters. + * + * @since 1.0.0 + */ + public function getUsersClusters($userId) + { + $user = Factory::getUser($userId); + $superUser = $user->authorise('core.admin'); + + $clusters = array(); + + // Load cluster library file + JLoader::import("/components/com_cluster/includes/cluster", JPATH_ADMINISTRATOR); + + if (!$superUser && !$user->authorise('core.manageall.cluster', 'com_cluster')) + { + $clusterUsersModel = ClusterFactory::model('ClusterUsers', array('ignore_request' => true)); + $clusterUsersModel->setState('list.group_by_client_id', 1); + $clusterUsersModel->setState('filter.published', 1); + $clusterUsersModel->setState('filter.user_id', $user->id); + + // Get all assigned cluster entries + $clusters = $clusterUsersModel->getItems(); + } + + if ($superUser) + { + $clusterModel = ClusterFactory::model('Clusters', array('ignore_request' => true)); + + // Get all cluster entries + $clusters = $clusterModel->getItems(); + } + + // Get com_subusers component status + $subUserExist = ComponentHelper::getComponent('com_subusers', true)->enabled; + + if ($subUserExist) + { + JLoader::import("/components/com_subusers/includes/rbacl", JPATH_ADMINISTRATOR); + } + + $usersClusters = array(); + + if (!empty($clusters)) + { + if ($subUserExist && (!$superUser && !$user->authorise('core.manageall.cluster', 'com_cluster'))) + { + foreach ($clusters as $cluster) + { + // Check user has permission for mentioned cluster + if (RBACL::authorise($user->id, 'com_cluster', 'core.manage.cluster', $cluster->id)) + { + $usersClusters[] = $cluster; + } + } + } + else + { + $usersClusters = $clusters; + } + } + + return $usersClusters; + } } diff --git a/src/components/com_cluster/administrator/models/clusterusers.php b/src/components/com_cluster/administrator/models/clusterusers.php index 7939c70..86fb1e1 100644 --- a/src/components/com_cluster/administrator/models/clusterusers.php +++ b/src/components/com_cluster/administrator/models/clusterusers.php @@ -102,6 +102,62 @@ protected function getListQuery() $query->where('cu.cluster_id = ' . (int) $cluster); } + // Filter by user + $cluster_user = $this->getState('filter.user_id'); + + if (is_numeric($cluster_user)) + { + $query->where('cu.user_id = ' . (int) $cluster_user); + } + + // Filter by client_id + $clusterClientId = $this->getState('filter.client_id'); + + if (is_numeric($clusterClientId)) + { + $query->where('cl.client_id = ' . (int) $clusterClientId); + } + elseif (is_array($clusterClientId)) + { + $query->where("cl.client_id IN ('" . implode("','", $clusterClientId) . "')"); + } + + // Filter by state + $published = $this->getState('filter.published'); + + if (is_numeric($published)) + { + $query->where('cl.state = ' . (int) $published); + } + elseif ($published === '') + { + $query->where('(cl.state = 0 OR cl.state = 1)'); + } + + // Filter by blocked users + $blockUser = $this->getState('filter.block'); + + if (is_numeric($blockUser)) + { + $query->where($db->quoteName('users.block') . ' = ' . (int) $blockUser); + } + + // Group by cluster + $clientID = $this->getState('list.group_by_client_id'); + + if (is_numeric($clientID)) + { + $query->group('cl.client_id'); + } + + // Group by user + $userID = $this->getState('list.group_by_user_id'); + + if (is_numeric($userID)) + { + $query->group('users.id'); + } + // Add the list ordering clause. $orderCol = $this->state->get('list.ordering'); $orderDirn = $this->state->get('list.direction'); diff --git a/src/components/com_cluster/site/languages/en-GB/en-GB.com_cluster.ini b/src/components/com_cluster/site/languages/en-GB/en-GB.com_cluster.ini index 1ec5484..85bbe25 100644 --- a/src/components/com_cluster/site/languages/en-GB/en-GB.com_cluster.ini +++ b/src/components/com_cluster/site/languages/en-GB/en-GB.com_cluster.ini @@ -6,3 +6,4 @@ COM_CLUSTER_LIST_VIEW_DESCRIPTION="Description" COM_CLUSTER_LIST_VIEW_CLIENT="Client" COM_CLUSTER_LIST_VIEW_ID = "ID" COM_CLUSTER_LIST_VIEW_CREATEDBY = "Created By" +COM_CLUSTER_OWNERSHIP_USER ="Select User"