Profile::currentUserHaveMoreRightThan PHP Method

currentUserHaveMoreRightThan() static public method

Is the current user have more right than all profiles in parameters
static public currentUserHaveMoreRightThan ( $IDs = [] ) : boolean
$IDs array of profile ID to test
return boolean true if have more right
    static function currentUserHaveMoreRightThan($IDs = array())
    {
        global $DB;
        if (Session::isCron()) {
            return true;
        }
        if (count($IDs) == 0) {
            // Check all profiles (means more right than all possible profiles)
            return countElementsInTable('glpi_profiles') == countElementsInTable('glpi_profiles', self::getUnderActiveProfileRestrictRequest(''));
        }
        $under_profiles = array();
        $query = "SELECT *\n                         FROM `glpi_profiles` " . self::getUnderActiveProfileRestrictRequest("WHERE");
        $result = $DB->query($query);
        while ($data = $DB->fetch_assoc($result)) {
            $under_profiles[$data['id']] = $data['id'];
        }
        foreach ($IDs as $ID) {
            if (!isset($under_profiles[$ID])) {
                return false;
            }
        }
        return true;
    }

Usage Example

Example #1
0
 /**
  * Is the specified user have more right than the current one ?
  *
  * @param $ID  integer : Id of the user
  *
  * @return boolean : true if currrent user have the same right or more right
  **/
 function currentUserHaveMoreRightThan($ID)
 {
     $user_prof = Profile_User::getUserProfiles($ID);
     return Profile::currentUserHaveMoreRightThan($user_prof);
 }
All Usage Examples Of Profile::currentUserHaveMoreRightThan