Turba::getExtendedPermission PHP Method

getExtendedPermission() public static method

Gets extended permissions on an address book.
public static getExtendedPermission ( Turba_Driver $addressBook, string $permission ) : mixed
$addressBook Turba_Driver The address book to get extended permissions for.
$permission string What extended permission to get.
return mixed The requested extended permissions value, or true if it doesn't exist.
    public static function getExtendedPermission(Turba_Driver $addressBook, $permission)
    {
        // We want to check the base source as extended permissions
        // are enforced per backend, not per share.
        $key = $addressBook->getName() . ':' . $permission;
        $perms = $GLOBALS['injector']->getInstance('Horde_Perms');
        if (!$perms->exists('turba:sources:' . $key)) {
            return true;
        }
        $allowed = $perms->getPermissions('turba:sources:' . $key, $GLOBALS['registry']->getAuth());
        if (is_array($allowed)) {
            switch ($permission) {
                case 'max_contacts':
                    $allowed = max($allowed);
                    break;
            }
        }
        return $allowed;
    }

Usage Example

Example #1
0
 /**
  * Checks the max_contacts permission.
  *
  * @param Turba_Driver $driver  The address book to check.
  * @param boolean $notify       If true, outputs error to notification.
  *
  * @return string  Error message if maximum contacts have been reached.
  *                 False otherwise.
  */
 public static function hasMaxContacts(Turba_Driver $driver, $notify = true)
 {
     $error = false;
     $max_contacts = Turba::getExtendedPermission($driver, 'max_contacts');
     if ($max_contacts !== true && $max_contacts <= count($driver)) {
         $error = sprintf(_("You are not allowed to create more than %d contacts in \"%s\"."), $max_contacts, $driver->title);
         Horde::permissionDeniedError('turba', 'max_contacts', $notify ? $error : null);
     }
     return $error;
 }
All Usage Examples Of Turba::getExtendedPermission