Mnemo::hasPermission PHP Метод

hasPermission() публичный статический Метод

Returns the specified permission for the current user.
public static hasPermission ( string $permission ) : mixed
$permission string A permission, currently only 'max_notes'.
Результат mixed The value of the specified permission.
    public static function hasPermission($permission)
    {
        $perms = $GLOBALS['injector']->getInstance('Horde_Perms');
        if (!$perms->exists('mnemo:' . $permission)) {
            return true;
        }
        $allowed = $perms->getPermissions('mnemo:' . $permission, $GLOBALS['registry']->getAuth());
        if (is_array($allowed)) {
            switch ($permission) {
                case 'max_notes':
                    $allowed = max($allowed);
                    break;
            }
        }
        return $allowed;
    }

Usage Example

Пример #1
0
 /**
  * Returns an array of UIDs for all notes that the current user is authorized
  * to see.
  *
  * @param array|string $notepads  The notepad(s) to list notes from.
  *
  * @return array  An array of UIDs for all notes the user can access.
  * @throws Mnemo_Exception
  * @throws Horde_Exception_PermissionDenied
  */
 public function listUids($notepads = null)
 {
     global $conf;
     if (!isset($conf['storage']['driver'])) {
         throw new RuntimeException('Not configured');
     }
     // Make sure we have a valid notepad.
     if (empty($notepads)) {
         $notepads = Mnemo::getSyncNotepads();
     } else {
         if (!is_array($notepads)) {
             $notepads = array($notepads);
         }
         foreach ($notepads as $notepad) {
             if (!Mnemo::hasPermission($notepad, Horde_Perms::READ)) {
                 throw new Horde_Exception_PermissionDenied();
             }
         }
     }
     // Set notepad for listMemos.
     $GLOBALS['display_notepads'] = $notepads;
     $memos = Mnemo::listMemos();
     $uids = array();
     foreach ($memos as $memo) {
         $uids[] = $memo['uid'];
     }
     return $uids;
 }