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

Added function to get all users with specific permission #104

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open

Added function to get all users with specific permission #104

wants to merge 1 commit into from

Conversation

svdaru
Copy link

@svdaru svdaru commented Dec 20, 2017

No description provided.

function users($Permission)
{
if (!is_numeric($Permission)) $Permission = $this->returnId($Permission);
$Res = Jf::sql ("SELECT DISTINCT(UserID) FROM {$this->tablePrefix()}permissions INNER JOIN {$this->tablePrefix()}rolepermissions ON {$this->tablePrefix()}permissions.ID = {$this->tablePrefix()}rolepermissions.PermissionID INNER JOIN {$this->tablePrefix()}roles ON {$this->tablePrefix()}rolepermissions.RoleID = {$this->tablePrefix()}roles.`ID` INNER JOIN {$this->tablePrefix()}userroles ON {$this->tablePrefix()}roles.`ID` = {$this->tablePrefix()}userroles.RoleID WHERE {$this->tablePrefix()}permissions.`ID` = ?", $Permission);

Choose a reason for hiding this comment

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

*
* @param integer $Permission
* ID
* @return Array 1D or null

Choose a reason for hiding this comment

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

*/
function users($Permission)
{
if (!is_numeric($Permission)) $Permission = $this->returnId($Permission);

Choose a reason for hiding this comment

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

if (!is_int($PermissionId)) {
    throw new InvalidArgumentException("`$PermissionId` should be type of integer")
}

Copy link
Author

Choose a reason for hiding this comment

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

agree. this check can be performed after permission string is resolved into id

* ID
* @return Array 1D or null
*/
function users($Permission)
Copy link

@VyacheslavDolya VyacheslavDolya Dec 21, 2017

Choose a reason for hiding this comment

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

function getUserIdsByPermissionId($PermissionId)

Copy link
Author

Choose a reason for hiding this comment

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

this is not the way other functions in a library named

Choose a reason for hiding this comment

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

that's clear function name, belongs to standard naming

/**
* Returns all users with a permission
*
* @param integer $Permission

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

It gets string or id as parameter.

Copy link

@VyacheslavDolya VyacheslavDolya Dec 22, 2017

Choose a reason for hiding this comment

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

and that's sad

if (is_array ( $Res ))
{
$out = array ();
foreach ( $Res as $R )

Choose a reason for hiding this comment

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

foreach ( $rows as $user ) {

$out = array ();
foreach ( $Res as $R )
$out [] = $R ['UserID'];
return $out;

Choose a reason for hiding this comment

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

remove

{
$out = array ();
foreach ( $Res as $R )
$out [] = $R ['UserID'];
Copy link

@VyacheslavDolya VyacheslavDolya Dec 21, 2017

Choose a reason for hiding this comment

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

$answer[] = (int) $user['UserID'];

Copy link
Author

Choose a reason for hiding this comment

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

agree

$out [] = $R ['UserID'];
return $out;
}
else

Choose a reason for hiding this comment

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

remove

return $out;
}
else
return null;

Choose a reason for hiding this comment

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

return answer;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants