diff --git a/src/components/com_cluster/administrator/access.xml b/src/components/com_cluster/administrator/access.xml index aa5a2bb..27f5e20 100644 --- a/src/components/com_cluster/administrator/access.xml +++ b/src/components/com_cluster/administrator/access.xml @@ -8,5 +8,6 @@ + diff --git a/src/components/com_cluster/administrator/helpers/cluster.php b/src/components/com_cluster/administrator/helpers/cluster.php index ef1f44a..dcf2c7c 100644 --- a/src/components/com_cluster/administrator/helpers/cluster.php +++ b/src/components/com_cluster/administrator/helpers/cluster.php @@ -10,6 +10,7 @@ defined('_JEXEC') or die('Restricted access'); use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; /** * Cluster helper. @@ -33,13 +34,13 @@ public static function addSubmenu($vName = '') if ($layout != "default") { JHtmlSidebar::addEntry( - JText::_('COM_CLUSTERS_VIEW_CLUSTERS'), + Text::_('COM_CLUSTERS_VIEW_CLUSTERS'), 'index.php?option=com_cluster&view=clusters', $vName == 'clusters' ); JHtmlSidebar::addEntry( - JText::_('COM_CLUSTERS_VIEW_CLUSTER_USERS'), + Text::_('COM_CLUSTERS_VIEW_CLUSTER_USERS'), 'index.php?option=com_cluster&view=clusterusers', $vName == 'clusterusers' ); diff --git a/src/components/com_cluster/administrator/includes/cluster.php b/src/components/com_cluster/administrator/includes/cluster.php index 6ad7222..12f9bf6 100644 --- a/src/components/com_cluster/administrator/includes/cluster.php +++ b/src/components/com_cluster/administrator/includes/cluster.php @@ -54,7 +54,7 @@ public static function table($name) **/ public static function model($name, $config = array()) { - BaseDatabaseModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_cluster/models'); + BaseDatabaseModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_cluster/models', 'ClusterModel'); // @TODO Add support for cache return BaseDatabaseModel::getInstance($name, 'ClusterModel', $config); diff --git a/src/components/com_cluster/administrator/languages/en-GB/en-GB.com_cluster.ini b/src/components/com_cluster/administrator/languages/en-GB/en-GB.com_cluster.ini index 1a0d1d8..25dee5d 100644 --- a/src/components/com_cluster/administrator/languages/en-GB/en-GB.com_cluster.ini +++ b/src/components/com_cluster/administrator/languages/en-GB/en-GB.com_cluster.ini @@ -92,3 +92,6 @@ COM_CLUSTER_PAGE_VIEW_USER = "Cluster user: View" COM_CLUSTER_USER_LIST_VIEW_NAME="User" COM_CLUSTER_USER_LIST_VIEW_CLUSTER="Cluster Name" COM_CLUSTER_USERLIST_VIEW_ID="ID" + +JACTION_MANAGE_ALL_CLUSTER="Manage All Clusters" +JACTION_MANAGE_ALL_CLUSTER_DESC="Manage All Clusters" diff --git a/src/components/com_cluster/administrator/languages/en-GB/en-GB.com_cluster.sys.ini b/src/components/com_cluster/administrator/languages/en-GB/en-GB.com_cluster.sys.ini index e2bca07..11d9fcd 100644 --- a/src/components/com_cluster/administrator/languages/en-GB/en-GB.com_cluster.sys.ini +++ b/src/components/com_cluster/administrator/languages/en-GB/en-GB.com_cluster.sys.ini @@ -7,4 +7,5 @@ COM_CLUSTER_CLUSTER_VIEW_EDIT_DESC="Shows a form to create a New Cluster." COM_CLUSTER_CLUSTERS_VIEW_DEFAULT_TITLE="List all Clusters" COM_CLUSTER_CLUSTERS_VIEW_DEFAULT_DESC="Shows a list of all the Clusters." COM_CLUSTER_TITLE_ITEM_VIEW_CLUSTER="Single Cluster" -COM_CLUSTER_TITLE_CLUSTER="Cluster" \ No newline at end of file +COM_CLUSTER_TITLE_CLUSTER="Cluster" +COM_CLUSTERS_VIEW_CLUSTER_USERS="Cluster users" diff --git a/src/components/com_cluster/administrator/libraries/cluster.php b/src/components/com_cluster/administrator/libraries/cluster.php index 8ee5279..8d5f0a3 100644 --- a/src/components/com_cluster/administrator/libraries/cluster.php +++ b/src/components/com_cluster/administrator/libraries/cluster.php @@ -11,6 +11,7 @@ use Joomla\CMS\Factory; use Joomla\CMS\Object\CMSObject; +use Joomla\CMS\Language\Text; /** * Cluster class. Handles all application interaction with a Cluster @@ -192,7 +193,7 @@ public function bind(&$array) { if (empty($array)) { - $this->setError(JText::_('COM_CLUSTER_EMPTY_DATA')); + $this->setError(Text::_('COM_CLUSTER_EMPTY_DATA')); return false; } @@ -200,7 +201,7 @@ public function bind(&$array) // Bind the array if (!$this->setProperties($array)) { - $this->setError(\JText::_('COM_CLUSTER_BINDING_ERROR')); + $this->setError(Text::_('COM_CLUSTER_BINDING_ERROR')); return false; } @@ -231,4 +232,38 @@ public function isOwner($userId = null) return false; } + + /** + * Function isMember to check user associated with passed cluster_id + * + * @param INT $userId User Id + * + * @return boolean + * + * @since __DEPLOY_VERSION__ + */ + public function isMember($userId = null) + { + $userId = Factory::getuser($userId)->id; + + if (empty($userId)) + { + return false; + } + + $ClusterModel = ClusterFactory::model('ClusterUsers', array('ignore_request' => true)); + $ClusterModel->setState('filter.published', 1); + $ClusterModel->setState('filter.cluster_id', (int) $this->id); + $ClusterModel->setState('filter.user_id', $userId); + + // Check user associated with passed cluster_id + $clusters = $ClusterModel->getItems(); + + if (!empty($clusters)) + { + return true; + } + + return false; + } } diff --git a/src/components/com_cluster/administrator/models/clusters.php b/src/components/com_cluster/administrator/models/clusters.php index 25ac53d..803e2af 100644 --- a/src/components/com_cluster/administrator/models/clusters.php +++ b/src/components/com_cluster/administrator/models/clusters.php @@ -58,7 +58,7 @@ protected function getListQuery() $query = $db->getQuery(true); // Create the base select statement. - $query->select(array('cl.*','users.name as uname')); + $query->select(array('cl.*','users.name as uname','cl.id as cluster_id')); $query->from($db->quoteName('#__tj_clusters', 'cl')); $query->join('LEFT', $db->quoteName('#__users', 'users') . ' ON (' . $db->quoteName('cl.created_by') . ' = ' . $db->quoteName('users.id') . ')'); diff --git a/src/components/com_cluster/administrator/models/clusteruser.php b/src/components/com_cluster/administrator/models/clusteruser.php index 9aeda3f..15b46de 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,78 @@ 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', '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('list.ordering', 'cl.name'); + $clusterUsersModel->setState('list.direction', 'ASC'); + $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); + $clusterModel->setState('list.ordering', 'cl.name'); + $clusterModel->setState('list.direction', 'ASC'); + $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', '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..b024aa5 100644 --- a/src/components/com_cluster/administrator/models/clusterusers.php +++ b/src/components/com_cluster/administrator/models/clusterusers.php @@ -10,7 +10,9 @@ // No direct access to this file defined('_JEXEC') or die('Restricted access'); +use Joomla\CMS\Factory; use Joomla\CMS\MVC\Model\ListModel; +use Joomla\CMS\Component\ComponentHelper; /** * Methods supporting a list of records. @@ -34,7 +36,7 @@ public function __construct($config = array()) $config['filter_fields'] = array( 'id', 'cu.id', 'cluster_id', 'cu.cluster_id', - 'state', 'cu.state', + 'state', 'cu.state','cl.name','cl.client_id' ); } @@ -54,9 +56,12 @@ protected function getListQuery() $db = $this->getDbo(); $query = $db->getQuery(true); - $query->select(array('cu.*','cl.name', 'users.name as uname')); + $query->select( + array('cu.*','cl.name', 'users.name as uname', 'users.email as uemail', 'users.username','cl.name as title', 'cl.client_id as client_id') + ); $query->from($db->quoteName('#__tj_cluster_nodes', 'cu')); - $query->join('INNER', $db->quoteName('#__users', 'users') . ' ON (' . $db->quoteName('cu.user_id') . ' = ' . $db->quoteName('users.id') . ')'); + $query->join('INNER', $db->quoteName('#__users', 'users') . ' ON (' . $db->quoteName('cu.user_id') . ' = ' + . $db->quoteName('users.id') . ')'); $query->join('INNER', $db->quoteName('#__tj_clusters', 'cl') . ' ON (' . $db->quoteName('cl.id') . ' = ' . $db->quoteName('cu.cluster_id') . ')'); // Filter by search in title. @@ -75,11 +80,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,9 +107,65 @@ 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 cluster table 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 users by block + $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'); + $orderCol = $this->state->get('list.ordering', 'users.name'); + $orderDirn = $this->state->get('list.direction', 'asc'); if ($orderCol && $orderDirn) { diff --git a/src/components/com_cluster/administrator/models/forms/cluster.xml b/src/components/com_cluster/administrator/models/forms/cluster.xml index 387d57c..fe0e06b 100644 --- a/src/components/com_cluster/administrator/models/forms/cluster.xml +++ b/src/components/com_cluster/administrator/models/forms/cluster.xml @@ -1,24 +1,91 @@
- - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - + + + + + + + + + + + + + +
diff --git a/src/components/com_cluster/administrator/models/forms/clusteruser.xml b/src/components/com_cluster/administrator/models/forms/clusteruser.xml index a791e59..e1ac266 100644 --- a/src/components/com_cluster/administrator/models/forms/clusteruser.xml +++ b/src/components/com_cluster/administrator/models/forms/clusteruser.xml @@ -1,21 +1,81 @@
- - - - - - - - + + + + + + + + + - - - - - - - + + + + + + + + + + + + +
diff --git a/src/components/com_cluster/administrator/models/forms/filter_clusters.xml b/src/components/com_cluster/administrator/models/forms/filter_clusters.xml index 96201ab..12a0ca3 100644 --- a/src/components/com_cluster/administrator/models/forms/filter_clusters.xml +++ b/src/components/com_cluster/administrator/models/forms/filter_clusters.xml @@ -1,13 +1,34 @@
- - + + - + + - + -
+ \ No newline at end of file diff --git a/src/components/com_cluster/administrator/models/forms/filter_clusterusers.xml b/src/components/com_cluster/administrator/models/forms/filter_clusterusers.xml index 78a0347..b66ce18 100644 --- a/src/components/com_cluster/administrator/models/forms/filter_clusterusers.xml +++ b/src/components/com_cluster/administrator/models/forms/filter_clusterusers.xml @@ -1,14 +1,45 @@
- - - + + + - + + - + -
+ \ No newline at end of file diff --git a/src/components/com_cluster/administrator/sql/install.mysql.utf8.sql b/src/components/com_cluster/administrator/sql/install.mysql.utf8.sql index 3983260..989b083 100644 --- a/src/components/com_cluster/administrator/sql/install.mysql.utf8.sql +++ b/src/components/com_cluster/administrator/sql/install.mysql.utf8.sql @@ -3,7 +3,7 @@ CREATE TABLE IF NOT EXISTS `#__tj_clusters` ( `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '', `description` text NOT NULL DEFAULT '', `params` text NOT NULL DEFAULT '', - `client` varchar(400) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT '', + `client` varchar(400) NOT NULL DEFAULT '', `client_id` int(11) NOT NULL DEFAULT '0', `ordering` int(11) NOT NULL DEFAULT '0', `state` tinyint(3) NOT NULL DEFAULT '0', @@ -13,8 +13,9 @@ CREATE TABLE IF NOT EXISTS `#__tj_clusters` ( `created_by` int(11) UNSIGNED NOT NULL DEFAULT '0', `modified_on` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `modified_by` int(11) UNSIGNED NOT NULL DEFAULT '0', - PRIMARY KEY (`id`) -) ENGINE = MyISAM CHARSET=utf8mb4 COLLATE utf8mb4_general_ci; + PRIMARY KEY (`id`), + KEY `client_id_idx` (`client_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; CREATE TABLE IF NOT EXISTS `#__tj_cluster_nodes` ( @@ -30,8 +31,10 @@ CREATE TABLE IF NOT EXISTS `#__tj_cluster_nodes` ( `modified_on` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `modified_by` int(11) UNSIGNED NOT NULL DEFAULT '0', PRIMARY KEY (`id`), - FOREIGN KEY (`cluster_id`) REFERENCES `#__tj_clusters` (`id`) -) ENGINE = MyISAM CHARSET=utf8mb4 COLLATE utf8mb4_general_ci; + FOREIGN KEY (`cluster_id`) REFERENCES `#__tj_clusters` (`id`), + KEY `cluster_id_idx` (`cluster_id`), + KEY `user_id_idx` (`user_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; -- -- Indexes for table `__tj_cluster_nodes` diff --git a/src/components/com_cluster/administrator/sql/updates/mysql/1.0.0.sql b/src/components/com_cluster/administrator/sql/updates/mysql/1.0.0.sql new file mode 100644 index 0000000..7583b37 --- /dev/null +++ b/src/components/com_cluster/administrator/sql/updates/mysql/1.0.0.sql @@ -0,0 +1,4 @@ +ALTER TABLE #__tj_clusters ADD INDEX client_id_idx (client_id); +ALTER TABLE #__tj_cluster_nodes ADD INDEX cluster_id_idx (cluster_id); +ALTER TABLE #__tj_cluster_nodes ADD INDEX user_id_idx (user_id); + diff --git a/src/components/com_cluster/administrator/views/cluster/view.html.php b/src/components/com_cluster/administrator/views/cluster/view.html.php index fe0e642..dff9105 100644 --- a/src/components/com_cluster/administrator/views/cluster/view.html.php +++ b/src/components/com_cluster/administrator/views/cluster/view.html.php @@ -11,6 +11,9 @@ use Joomla\CMS\Factory; use Joomla\CMS\MVC\View\HtmlView; +use Joomla\CMS\Helper\ContentHelper; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Toolbar\ToolbarHelper; /** * View to edit @@ -70,7 +73,7 @@ public function display($tpl = null) $this->form = $this->get('Form'); $this->input = Factory::getApplication()->input; - $this->canDo = JHelperContent::getActions('com_cluster', 'cluster', $this->item->id); + $this->canDo = ContentHelper::getActions('com_cluster', 'cluster', $this->item->id); // Check for errors. if (count($errors = $this->get('Errors'))) @@ -110,15 +113,15 @@ protected function addToolbar() { Factory::getApplication()->input->set('hidemainmenu', true); - JToolbarHelper::title( - JText::_('COM_CLUSTER_PAGE_' . ($checkedOut ? 'VIEW_CLUSTER' : ($isNew ? 'ADD_CLUSTER' : 'EDIT_CLUSTER'))), + ToolbarHelper::title( + Text::_('COM_CLUSTER_PAGE_' . ($checkedOut ? 'VIEW_CLUSTER' : ($isNew ? 'ADD_CLUSTER' : 'EDIT_CLUSTER'))), 'pencil-2 cluster-add' ); if ($isNew) { - JToolbarHelper::save('cluster.save'); - JToolbarHelper::cancel('cluster.cancel'); + ToolbarHelper::save('cluster.save'); + ToolbarHelper::cancel('cluster.cancel'); } else { @@ -126,13 +129,13 @@ protected function addToolbar() // Can't save the record if it's checked out and editable $this->canSave($checkedOut, $itemEditable); - JToolbarHelper::cancel('cluster.cancel', 'JTOOLBAR_CLOSE'); + ToolbarHelper::cancel('cluster.cancel', 'JTOOLBAR_CLOSE'); } } else { - JToolbarHelper::title( - JText::_('COM_CLUSTER_PAGE_VIEW_CLUSTER') + ToolbarHelper::title( + Text::_('COM_CLUSTER_PAGE_VIEW_CLUSTER') ); $app = Factory::getApplication(); @@ -143,7 +146,7 @@ protected function addToolbar() $this->sidebar = JHtmlSidebar::render(); } - JToolbarHelper::divider(); + ToolbarHelper::divider(); } /** @@ -159,7 +162,7 @@ protected function canSave($checkedOut, $itemEditable) { if (!$checkedOut && $itemEditable) { - JToolbarHelper::save('cluster.save'); + ToolbarHelper::save('cluster.save'); } } diff --git a/src/components/com_cluster/administrator/views/clusters/view.html.php b/src/components/com_cluster/administrator/views/clusters/view.html.php index d31496f..71f5062 100644 --- a/src/components/com_cluster/administrator/views/clusters/view.html.php +++ b/src/components/com_cluster/administrator/views/clusters/view.html.php @@ -13,6 +13,9 @@ use Joomla\CMS\Factory; use Joomla\CMS\MVC\View\HtmlView; use Joomla\CMS\Object\CMSObject; +use Joomla\CMS\Helper\ContentHelper; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Toolbar\ToolbarHelper; /** * Clusters view @@ -93,7 +96,7 @@ public function display($tpl = null) $this->filterForm = $this->get('FilterForm'); $this->activeFilters = $this->get('ActiveFilters'); $this->user = Factory::getUser(); - $this->canDo = JHelperContent::getActions('com_cluster'); + $this->canDo = ContentHelper::getActions('com_cluster'); ClusterHelper::addSubmenu('clusters'); $this->addToolbar(); @@ -111,38 +114,38 @@ public function display($tpl = null) */ protected function addToolbar() { - JToolBarHelper::title(JText::_('COM_CLUSTERS_VIEW_CLUSTERS'), ''); + ToolbarHelper::title(Text::_('COM_CLUSTERS_VIEW_CLUSTERS'), ''); $canDo = $this->canDo; if ($canDo->get('core.create')) { - JToolbarHelper::addNew('cluster.add'); + ToolbarHelper::addNew('cluster.add'); } if ($canDo->get('core.edit')) { - JToolbarHelper::editList('cluster.edit'); + ToolbarHelper::editList('cluster.edit'); } if ($canDo->get('core.edit.state')) { - JToolbarHelper::divider(); - JToolbarHelper::publish('clusters.publish', 'JTOOLBAR_PUBLISH', true); - JToolbarHelper::unpublish('clusters.unpublish', 'JTOOLBAR_UNPUBLISH', true); - JToolBarHelper::archiveList('clusters.archive', 'JTOOLBAR_ARCHIVE'); - JToolbarHelper::divider(); + ToolbarHelper::divider(); + ToolbarHelper::publish('clusters.publish', 'JTOOLBAR_PUBLISH', true); + ToolbarHelper::unpublish('clusters.unpublish', 'JTOOLBAR_UNPUBLISH', true); + ToolbarHelper::archiveList('clusters.archive', 'JTOOLBAR_ARCHIVE'); + ToolbarHelper::divider(); } if ($canDo->get('core.delete')) { - JToolbarHelper::deleteList('JGLOBAL_CONFIRM_DELETE', 'clusters.delete', 'JTOOLBAR_DELETE'); - JToolbarHelper::divider(); + ToolbarHelper::deleteList('JGLOBAL_CONFIRM_DELETE', 'clusters.delete', 'JTOOLBAR_DELETE'); + ToolbarHelper::divider(); } if ($canDo->get('core.admin') || $canDo->get('core.options')) { - JToolbarHelper::preferences('com_cluster'); - JToolbarHelper::divider(); + ToolbarHelper::preferences('com_cluster'); + ToolbarHelper::divider(); } } @@ -154,11 +157,11 @@ protected function addToolbar() protected function getSortFields() { return array( - 'cl.id' => JText::_('JGRID_HEADING_ID'), - 'cl.title' => JText::_('COM_CLUSTER_LIST_CLUSTERS_NAME'), - 'cl.client' => JText::_('COM_CLUSTER_LIST_CLUSTERS_CLIENT'), - 'cl.ordering' => JText::_('JGRID_HEADING_ORDERING'), - 'cl.state' => JText::_('JSTATUS'), + 'cl.id' => Text::_('JGRID_HEADING_ID'), + 'cl.title' => Text::_('COM_CLUSTER_LIST_CLUSTERS_NAME'), + 'cl.client' => Text::_('COM_CLUSTER_LIST_CLUSTERS_CLIENT'), + 'cl.ordering' => Text::_('JGRID_HEADING_ORDERING'), + 'cl.state' => Text::_('JSTATUS'), ); } } diff --git a/src/components/com_cluster/administrator/views/clusteruser/view.html.php b/src/components/com_cluster/administrator/views/clusteruser/view.html.php index 374f84a..05c8c60 100644 --- a/src/components/com_cluster/administrator/views/clusteruser/view.html.php +++ b/src/components/com_cluster/administrator/views/clusteruser/view.html.php @@ -11,6 +11,9 @@ use Joomla\CMS\Factory; use Joomla\CMS\MVC\View\HtmlView; +use Joomla\CMS\Helper\ContentHelper; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Toolbar\ToolbarHelper; /** * View to edit @@ -70,7 +73,7 @@ public function display($tpl = null) $this->form = $this->get('Form'); $this->input = Factory::getApplication()->input; - $this->canDo = JHelperContent::getActions('com_cluster', 'clusteruser', $this->item->id); + $this->canDo = ContentHelper::getActions('com_cluster', 'clusteruser', $this->item->id); // Check for errors. if (count($errors = $this->get('Errors'))) @@ -108,27 +111,27 @@ protected function addToolbar() { Factory::getApplication()->input->set('hidemainmenu', true); - JToolbarHelper::title( - JText::_('COM_CLUSTER_PAGE_' . ($checkedOut ? 'VIEW_USER' : ($isNew ? 'ADD_USER' : 'EDIT_USER'))), + ToolbarHelper::title( + Text::_('COM_CLUSTER_PAGE_' . ($checkedOut ? 'VIEW_USER' : ($isNew ? 'ADD_USER' : 'EDIT_USER'))), 'pencil-2 cluster-add' ); if ($isNew) { - JToolbarHelper::save('clusteruser.save'); - JToolbarHelper::cancel('clusteruser.cancel'); + ToolbarHelper::save('clusteruser.save'); + ToolbarHelper::cancel('clusteruser.cancel'); } else { $itemEditable = $this->isEditable($this->canDo, $user->id); $this->canSave($checkedOut, $itemEditable); - JToolbarHelper::cancel('clusteruser.cancel', 'JTOOLBAR_CLOSE'); + ToolbarHelper::cancel('clusteruser.cancel', 'JTOOLBAR_CLOSE'); } } else { - JToolbarHelper::title( - JText::_('COM_CLUSTER_PAGE_VIEW_CLUSTER_USER') + ToolbarHelper::title( + Text::_('COM_CLUSTER_PAGE_VIEW_CLUSTER_USER') ); ClusterHelper::addSubmenu('clusteruser'); @@ -136,7 +139,7 @@ protected function addToolbar() $this->sidebar = JHtmlSidebar::render(); } - JToolbarHelper::divider(); + ToolbarHelper::divider(); } /** @@ -152,7 +155,7 @@ protected function canSave($checkedOut, $itemEditable) { if (!$checkedOut && $itemEditable) { - JToolbarHelper::save('clusteruser.save'); + ToolbarHelper::save('clusteruser.save'); } } diff --git a/src/components/com_cluster/administrator/views/clusterusers/view.html.php b/src/components/com_cluster/administrator/views/clusterusers/view.html.php index 7816666..d33efbc 100644 --- a/src/components/com_cluster/administrator/views/clusterusers/view.html.php +++ b/src/components/com_cluster/administrator/views/clusterusers/view.html.php @@ -12,6 +12,9 @@ use Joomla\CMS\Factory; use Joomla\CMS\MVC\View\HtmlView; +use Joomla\CMS\Helper\ContentHelper; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Toolbar\ToolbarHelper; /** * Clusters view @@ -92,7 +95,7 @@ public function display($tpl = null) $this->filterForm = $this->get('FilterForm'); $this->activeFilters = $this->get('ActiveFilters'); $this->user = Factory::getUser(); - $this->canDo = JHelperContent::getActions('com_cluster'); + $this->canDo = ContentHelper::getActions('com_cluster'); ClusterHelper::addSubmenu('clusterusers'); $this->addToolbar(); @@ -110,37 +113,37 @@ public function display($tpl = null) */ protected function addToolbar() { - JToolBarHelper::title(JText::_('COM_CLUSTERS_VIEW_CLUSTERS'), ''); + ToolBarHelper::title(Text::_('COM_CLUSTERS_VIEW_CLUSTERS'), ''); if ($this->canDo->get('core.create')) { - JToolbarHelper::addNew('clusteruser.add'); + ToolBarHelper::addNew('clusteruser.add'); } if ($this->canDo->get('core.edit')) { - JToolbarHelper::editList('clusteruser.edit'); + ToolBarHelper::editList('clusteruser.edit'); } if ($this->canDo->get('core.edit.state')) { - JToolbarHelper::divider(); - JToolbarHelper::publish('clusteruser.publish', 'JTOOLBAR_PUBLISH', true); - JToolbarHelper::unpublish('clusteruser.unpublish', 'JTOOLBAR_UNPUBLISH', true); - JToolBarHelper::archiveList('clusteruser.archive', 'JTOOLBAR_ARCHIVE'); - JToolbarHelper::divider(); + ToolBarHelper::divider(); + ToolBarHelper::publish('clusteruser.publish', 'JTOOLBAR_PUBLISH', true); + ToolBarHelper::unpublish('clusteruser.unpublish', 'JTOOLBAR_UNPUBLISH', true); + ToolBarHelper::archiveList('clusteruser.archive', 'JTOOLBAR_ARCHIVE'); + ToolBarHelper::divider(); } if ($this->canDo->get('core.delete')) { - JToolbarHelper::deleteList('JGLOBAL_CONFIRM_DELETE', 'clusterusers.delete', 'JTOOLBAR_DELETE'); - JToolbarHelper::divider(); + ToolBarHelper::deleteList('JGLOBAL_CONFIRM_DELETE', 'clusterusers.delete', 'JTOOLBAR_DELETE'); + ToolBarHelper::divider(); } if ($this->canDo->get('core.admin') || $this->canDo->get('core.options')) { - JToolbarHelper::preferences('com_cluster'); - JToolbarHelper::divider(); + ToolBarHelper::preferences('com_cluster'); + ToolBarHelper::divider(); } } @@ -152,11 +155,11 @@ protected function addToolbar() protected function getSortFields() { return array( - 'cl.id' => JText::_('JGRID_HEADING_ID'), - 'cl.title' => JText::_('COM_CLUSTER_LIST_CLUSTERS_NAME'), - 'cl.client' => JText::_('COM_CLUSTER_LIST_CLUSTERS_CLIENT'), - 'cl.ordering' => JText::_('JGRID_HEADING_ORDERING'), - 'cl.state' => JText::_('JSTATUS'), + 'cl.id' => Text::_('JGRID_HEADING_ID'), + 'cl.title' => Text::_('COM_CLUSTER_LIST_CLUSTERS_NAME'), + 'cl.client' => Text::_('COM_CLUSTER_LIST_CLUSTERS_CLIENT'), + 'cl.ordering' => Text::_('JGRID_HEADING_ORDERING'), + 'cl.state' => Text::_('JSTATUS'), ); } } diff --git a/src/components/com_cluster/site/cluster.php b/src/components/com_cluster/site/cluster.php index 2700e1e..30aaa86 100644 --- a/src/components/com_cluster/site/cluster.php +++ b/src/components/com_cluster/site/cluster.php @@ -7,6 +7,8 @@ */ defined('_JEXEC') or die; +use Joomla\CMS\Factory; +use Joomla\CMS\MVC\Controller\BaseController; // Include dependancies jimport('joomla.application.component.controller'); @@ -16,6 +18,6 @@ // Execute the task. -$controller = JControllerLegacy::getInstance('Cluster'); -$controller->execute(JFactory::getApplication()->input->get('task')); +$controller = BaseController::getInstance('Cluster'); +$controller->execute(Factory::getApplication()->input->get('task')); $controller->redirect(); diff --git a/src/components/com_cluster/site/controller.php b/src/components/com_cluster/site/controller.php index d4735e3..47cf546 100644 --- a/src/components/com_cluster/site/controller.php +++ b/src/components/com_cluster/site/controller.php @@ -8,6 +8,8 @@ // No direct access defined('_JEXEC') or die; +use Joomla\CMS\MVC\Controller\BaseController; +use Joomla\CMS\Factory; jimport('joomla.application.component.controller'); @@ -17,7 +19,7 @@ * * @since 1.0.0 */ -class ClusterController extends JControllerLegacy +class ClusterController extends BaseController { /** * Method to display a view. @@ -31,7 +33,7 @@ class ClusterController extends JControllerLegacy */ public function display($cachable = false, $urlparams = false) { - $app = JFactory::getApplication(); + $app = Factory::getApplication(); $view = $app->input->getCmd('view', 'clusters'); $app->input->set('view', $view); diff --git a/src/components/com_cluster/site/controllers/clusterusers.json.php b/src/components/com_cluster/site/controllers/clusterusers.json.php new file mode 100644 index 0000000..2753758 --- /dev/null +++ b/src/components/com_cluster/site/controllers/clusterusers.json.php @@ -0,0 +1,73 @@ + + * @copyright Copyright (C) 2009 - 2019 Techjoomla. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +// No direct access +defined('_JEXEC') or die; + +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Response\JsonResponse; +use Joomla\CMS\MVC\Controller\BaseController; +use Joomla\CMS\Session\Session; + +JLoader::import("/components/com_cluster/includes/cluster", JPATH_ADMINISTRATOR); + +/** + * Get Cluster Users controller class. + * + * @since 1.0.0 + */ +class ClusterControllerClusterUsers extends BaseController +{ + /** + * Method to get user list depending on the client chosen. + * + * @return null + * + * @since 1.0.0 + */ + public function getUsersByClientId() + { + $app = Factory::getApplication(); + + // Check for request forgeries. + if (!Session::checkToken()) + { + echo new JsonResponse(null, Text::_('JINVALID_TOKEN'), true); + $app->close(); + } + + $clusterIds = $app->input->getInt('cluster_id', 0); + $userOptions = $allUsers = array(); + + // Initialize array to store dropdown options + $userOptions[] = HTMLHelper::_('select.option', "", Text::_('COM_CLUSTER_OWNERSHIP_USER')); + + // Check cluster selected or not + if ($clusterIds) + { + $clusterObj = ClusterFactory::model('ClusterUsers', array('ignore_request' => true)); + $clusterObj->setState('filter.block', 0); + $clusterObj->setState('filter.cluster_id', $clusterIds); + $clusterObj->setState('list.group_by_user_id', 1); + $allUsers = $clusterObj->getItems(); + } + + if (!empty($allUsers)) + { + foreach ($allUsers as $user) + { + $userOptions[] = HTMLHelper::_('select.option', $user->user_id, trim($user->uname . ' (' . $user->uemail . ')')); + } + } + + echo new JsonResponse($userOptions); + $app->close(); + } +} 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" diff --git a/src/components/com_cluster/site/router.php b/src/components/com_cluster/site/router.php index 73f26b8..827c3ee 100644 --- a/src/components/com_cluster/site/router.php +++ b/src/components/com_cluster/site/router.php @@ -8,6 +8,7 @@ // No direct access defined('_JEXEC') or die; +use Joomla\CMS\Component\Router\RouterBase; JLoader::registerPrefix('Cluster', JPATH_SITE . '/components/com_cluster/'); @@ -16,7 +17,7 @@ * * @since 1.0.0 */ -class ClusterRouter extends JComponentRouterBase +class ClusterRouter extends RouterBase { /** * Build method for URLs diff --git a/src/components/com_cluster/site/views/cluster/view.html.php b/src/components/com_cluster/site/views/cluster/view.html.php index c170105..49f0b77 100644 --- a/src/components/com_cluster/site/views/cluster/view.html.php +++ b/src/components/com_cluster/site/views/cluster/view.html.php @@ -8,6 +8,7 @@ // No direct access defined('_JEXEC') or die; +use Joomla\CMS\MVC\View\HtmlView; jimport('joomla.application.component.view'); @@ -16,7 +17,7 @@ * * @since 1.0.0 */ -class ClusterViewCluster extends JViewLegacy +class ClusterViewCluster extends HtmlView { protected $item; diff --git a/src/components/com_cluster/site/views/clusters/tmpl/default.php b/src/components/com_cluster/site/views/clusters/tmpl/default.php index 7e7c442..83799a5 100644 --- a/src/components/com_cluster/site/views/clusters/tmpl/default.php +++ b/src/components/com_cluster/site/views/clusters/tmpl/default.php @@ -8,13 +8,16 @@ // No direct access defined('_JEXEC') or die('Restricted access'); +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Router\Route; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Layout\LayoutHelper; +HTMLHelper::addIncludePath(JPATH_COMPONENT . '/helpers/html'); -JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html'); - -JHtml::_('bootstrap.tooltip'); -JHtml::_('behavior.multiselect'); -JHtml::_('formbehavior.chosen', 'select'); +HTMLHelper::_('bootstrap.tooltip'); +HTMLHelper::_('behavior.multiselect'); +HTMLHelper::_('formbehavior.chosen', 'select'); $listOrder = $this->escape($this->state->get('list.ordering')); $listDirn = $this->escape($this->state->get('list.direction')); @@ -23,13 +26,13 @@ if ($saveOrder) { $saveOrderingUrl = 'index.php?option=com_cluster&task=clusters.saveOrderAjax&tmpl=component'; - JHtml::_('sortablelist.sortable', 'clustersList', 'adminForm', strtolower($listDirn), $saveOrderingUrl); + HTMLHelper::_('sortablelist.sortable', 'clustersList', 'adminForm', strtolower($listDirn), $saveOrderingUrl); } ?>
-
+ sidebar)) { @@ -50,13 +53,13 @@ $this)); + echo LayoutHelper::render('joomla.searchtools.default', array('view' => $this)); ?> items)) { ?>
- +
- + - + items[0]->state)) { ?> - + - + - + - + - + @@ -132,7 +135,7 @@ } elseif (!$saveOrder) { - $iconClass = ' inactive tip-top hasTooltip" title="' . JHtml::_('tooltipText', 'JORDERINGDISABLED'); + $iconClass = ' inactive tip-top hasTooltip" title="' . HTMLHelper::_('tooltipText', 'JORDERINGDISABLED'); } ?> @@ -147,14 +150,14 @@ ?> - id); ?> + id); ?> items[0]->state)) { ?> - state, $i, 'clusters.', $canChange, 'cb'); ?> + state, $i, 'clusters.', $canChange, 'cb'); ?> checked_out) { ?> - checked_out, $item->checked_out_time, 'clusters.', $canCheckin); ?> + checked_out, $item->checked_out_time, 'clusters.', $canCheckin); ?> - + escape($item->name); ?> - +
diff --git a/src/components/com_cluster/site/views/clusters/view.html.php b/src/components/com_cluster/site/views/clusters/view.html.php index 89e3983..b685660 100644 --- a/src/components/com_cluster/site/views/clusters/view.html.php +++ b/src/components/com_cluster/site/views/clusters/view.html.php @@ -8,13 +8,16 @@ // No direct access to this file defined('_JEXEC') or die('Restricted access'); +use Joomla\CMS\Language\Text; +use Joomla\CMS\MVC\View\HtmlView; +use Joomla\CMS\Factory; /** * Clusters view * * @since 1.0.0 */ -class ClusterViewClusters extends JViewLegacy +class ClusterViewClusters extends HtmlView { /** * An array of items @@ -122,7 +125,7 @@ public function display($tpl = null) $this->activeFilters = $this->get('ActiveFilters'); // Get ACL actions - $this->user = JFactory::getUser(); + $this->user = Factory::getUser(); $this->canCreate = $this->user->authorise('core.content.create', 'com_cluster'); $this->canEdit = $this->user->authorise('core.content.edit', 'com_cluster'); @@ -142,11 +145,11 @@ public function display($tpl = null) protected function getSortFields() { return array( - 'cl.id' => JText::_('JGRID_HEADING_ID'), - 'cl.title' => JText::_('COM_CLUSTER_LIST_CLUSTERS_NAME'), - 'cl.client' => JText::_('COM_CLUSTER_LIST_CLUSTERS_CLIENT'), - 'cl.ordering' => JText::_('JGRID_HEADING_ORDERING'), - 'cl.state' => JText::_('JSTATUS'), + 'cl.id' => Text::_('JGRID_HEADING_ID'), + 'cl.title' => Text::_('COM_CLUSTER_LIST_CLUSTERS_NAME'), + 'cl.client' => Text::_('COM_CLUSTER_LIST_CLUSTERS_CLIENT'), + 'cl.ordering' => Text::_('JGRID_HEADING_ORDERING'), + 'cl.state' => Text::_('JSTATUS'), ); } }