Пример #1
0
 public function setLevel($level)
 {
     if (!c\LevelValues::isLevel($level)) {
         throw new e\UnacceptableValueException("The level {$level} is unacceptable.");
     }
     $this->level = $level;
     return $this;
 }
 private function setAccess(a\Asset $a, $level)
 {
     $type = $a->getType();
     if ($type != c\T::USER && $type != c\T::GROUP) {
         throw new e\WrongAssetTypeException(c\M::ACCESS_TO_USERS_GROUPS);
     }
     if (!c\LevelValues::isLevel($level)) {
         throw new e\UnacceptableValueException("The level {$level} is unacceptable.");
     }
     $entry = $this->getEntry($a);
     // not exist
     if ($entry == NULL) {
         $entry_std = new \stdClass();
         $entry_std->level = $level;
         $entry_std->type = $a->getType();
         $entry_std->name = $a->getName();
         $this->acl_entries[] = new AclEntry($entry_std);
     } else {
         $entry->setLevel($level);
     }
 }
 public function grantAccess($type, $id_path, $site_name = NULL, $applied_to_children = false, Asset $a = NULL, $level = c\T::READ)
 {
     $ari = $this->getAccessRights($type, $id_path, $site_name);
     if ($a == NULL || $a->getType() != Group::TYPE && $a->getType() != User::TYPE) {
         throw new e\WrongAssetTypeException(S_SPAN . c\M::ACCESS_TO_USERS_GROUPS . E_SPAN);
     }
     if (!c\LevelValues::isLevel($level)) {
         throw new e\UnacceptableValueException(S_SPAN . "The level {$level} is unacceptable." . E_SPAN);
     }
     if ($a->getType() == Group::TYPE && $level == c\T::READ) {
         if (self::DEBUG) {
             u\DebugUtility::out("Granting " . $a->getName() . " read access to " . $id_path);
         }
         $func_name = 'grantGroupReadAccess';
     } else {
         if ($a->getType() == Group::TYPE && $level == c\T::WRITE) {
             if (self::DEBUG) {
                 u\DebugUtility::out("Granting " . $a->getName() . " write access to " . $id_path);
             }
             $func_name = 'grantGroupWriteAccess';
         } else {
             if ($a->getType() == User::TYPE && $level == c\T::READ) {
                 if (self::DEBUG) {
                     u\DebugUtility::out("Granting " . $a->getName() . " read access to " . $id_path);
                 }
                 $func_name = 'grantUserReadAccess';
             } else {
                 if ($a->getType() == User::TYPE && $level == c\T::WRITE) {
                     if (self::DEBUG) {
                         u\DebugUtility::out("Granting " . $a->getName() . " write access to " . $id_path);
                     }
                     $func_name = 'grantUserWriteAccess';
                 }
             }
         }
     }
     if (isset($func_name)) {
         $ari->{$func_name}($a);
         $this->setAccessRights($ari, $applied_to_children);
     } else {
         if (self::DEBUG) {
             u\DebugUtility::out("The function name is not set.");
         }
     }
     return $this;
 }