-
Notifications
You must be signed in to change notification settings - Fork 141
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
base: develop
Are you sure you want to change the base?
Conversation
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); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- @return int[]
*/ | ||
function users($Permission) | ||
{ | ||
if (!is_numeric($Permission)) $Permission = $this->returnId($Permission); |
There was a problem hiding this comment.
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")
}
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function getUserIdsByPermissionId($PermissionId)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- @param int $PermissionId
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ) |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$answer[] = (int) $user['UserID'];
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return answer;
No description provided.