diff --git a/src/components/com_cluster/administrator/models/clusteruser.php b/src/components/com_cluster/administrator/models/clusteruser.php index 9aeda3f..3357797 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 = null) + { + $user = empty($userId) ? Factory::getUser() : Factory::getUser($userId); + + $clusters = array(); + + // Load cluster library file + JLoader::import("/components/com_cluster/includes/cluster", JPATH_ADMINISTRATOR); + + // If user is not allowed to view all the clusters then return the clusters in which user is a part else return al cluster + if (!$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(); + } + else + { + $clusterModel = ClusterFactory::model('Clusters', array('ignore_request' => true)); + + // Get all cluster entries + $clusterModel->setState('filter.state', 1); + $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 && (!$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..005c8ea 100644 --- a/src/components/com_cluster/administrator/models/clusterusers.php +++ b/src/components/com_cluster/administrator/models/clusterusers.php @@ -75,11 +75,11 @@ protected function getListQuery() } } - $created_by = $this->getState('filter.created_by'); + $createdBy = $this->getState('filter.created_by'); - if (!empty($created_by)) + if (!empty($createdBy)) { - $query->where($db->quoteName('cu.created_by') . ' = ' . (int) $created_by); + $query->where($db->quoteName('cu.created_by') . ' = ' . (int) $createdBy); } // Filter by state @@ -102,6 +102,62 @@ protected function getListQuery() $query->where('cu.cluster_id = ' . (int) $cluster); } + // Filter by user + $clusterUser = $this->getState('filter.user_id'); + + if (is_numeric($clusterUser)) + { + $query->where('cu.user_id = ' . (int) $clusterUser); + } + + // 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"