Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Com_hierarchy changes to check if user have sub users #3

Open
wants to merge 3 commits into
base: release-1.1.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions administrator/models/hierarchys.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ protected function populateState($ordering = null, $direction = null)
// Filtering user_id
$this->setState('filter.user_id', $app->getUserStateFromRequest($this->context . '.filter.user_id', 'filter_user_id', '', 'string'));

if (!empty($user_id))
{
$this->setState('filter.user_id', $app->getUserStateFromRequest($this->context . '.filter.user_id', 'filter_user_id', '', 'string'));
}

// Load the parameters.
$params = JComponentHelper::getParams('com_hierarchy');
$this->setState('params', $params);
Expand Down
31 changes: 31 additions & 0 deletions site/helpers/hierarchy.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,35 @@ public static function getTrainingAdminExit($uid = null)
return $managerId = $db->loadResult();
}
}

/**
* Check the user is manager or not
*
* @param user_Id $user_Id Id of user
*
* @return boolean
*
* @since 1.0
*/
public function checkManager($user_Id = null)
{
if (empty($user_Id))
{
$user_Id = JFactory::getUser()->id;
}

if ($user_Id)
{
// Checking if the user is having subuser in hierarchy
JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_hierarchy/models', 'hierarchys');
$HierarchyModelHierarchys = JModelLegacy::getInstance('Hierarchys', 'HierarchyModel');

$HierarchyModelHierarchys->setState('filter.user_id', $user_Id);
$isManager = $HierarchyModelHierarchys->getItems();

return $isManager;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will retrun array and not boolean

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, i have used this to retrieve users under the manager so can use in drop down filters. And if he has users under him then the user is the manager.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then change the function name.. getSubUsers

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might need to check if the previous function name is used anywhere? If yes,you will need to change it to this new one

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the purpose of this helper ? Why are we adding more things to helpers instead of removing ? Cant you simply use the models for this ?

}

return false;
}
}