Skip to content

Commit

Permalink
Merge pull request #11 from ankush-maherwal/release-1.0.0
Browse files Browse the repository at this point in the history
Task #10 feat: Cluster list custom field
  • Loading branch information
thite-amol authored Aug 19, 2019
2 parents cd02980 + 4ba67fd commit 984ac6e
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 3 deletions.
71 changes: 71 additions & 0 deletions src/components/com_cluster/administrator/models/clusteruser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
}
62 changes: 59 additions & 3 deletions src/components/com_cluster/administrator/models/clusterusers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 984ac6e

Please sign in to comment.