public static function getResponse($object) { $r = PermissionCache::getResponse($object); if (is_object($r)) { return $r; } if (method_exists($object, 'getPermissionObjectPermissionKeyCategoryHandle')) { $objectClass = Loader::helper('text')->camelcase($object->getPermissionObjectPermissionKeyCategoryHandle()); $handle = $object->getPermissionObjectPermissionKeyCategoryHandle(); } else { $objectClass = get_class($object); $handle = Loader::helper('text')->uncamelcase($objectClass); } $category = PermissionKeyCategory::getByHandle($handle); $c1 = $objectClass . 'PermissionResponse'; if (!is_object($category)) { if ($object instanceof Page) { $category = PermissionKeyCategory::getByHandle('page'); $c1 = 'PagePermissionResponse'; } else { if ($object instanceof Area) { $category = PermissionKeyCategory::getByHandle('area'); $c1 = 'AreaPermissionResponse'; } } } $pr = new $c1(); $pr->setPermissionObject($object); $pr->setPermissionCategoryObject($category); PermissionCache::addResponse($object, $pr); return $pr; }
public function assignPermissionAccess(PermissionAccess $pa) { $db = Loader::db(); $db->Replace('PagePermissionAssignments', array('cID' => $this->getPermissionObject()->getPermissionsCollectionID(), 'paID' => $pa->getPermissionAccessID(), 'pkID' => $this->pk->getPermissionKeyID()), array('cID', 'pkID'), true); $pa->markAsInUse(); PermissionCache::clearAccessObject($this->pk, $this->getPermissionObject()); }
public static function getResponse($object) { $r = PermissionCache::getResponse($object); if (is_object($r)) { return $r; } $category = PermissionKeyCategory::getByHandle(Loader::helper('text')->uncamelcase(get_class($object))); if (!is_object($category) && $object instanceof Page) { $category = PermissionKeyCategory::getByHandle('page'); } $txt = Loader::helper('text'); $c1 = get_class($object) . 'PermissionResponse'; if (!class_exists($c1)) { $c1 = 'PagePermissionResponse'; } $pr = new $c1(); $pr->setPermissionObject($object); $pr->setPermissionCategoryObject($category); PermissionCache::addResponse($object, $pr); return $pr; }
public function validate() { $u = new User(); if ($u->isSuperUser()) { return true; } $r = PermissionCache::validate($this); if ($r !== -1) { return $r; } $pae = $this->getPermissionAccessObject(); if (is_object($pae)) { $valid = $pae->validate(); } else { $valid = false; } PermissionCache::addValidate($this, $valid); return $valid; }
public static function disable() { PermissionCache::$enabled = false; }
public static function getByID($paID, PermissionKey $pk, $checkPA = true) { $db = Loader::db(); $pa = PermissionCache::getPermissionAccessObject($paID, $pk); if (is_object($pa)) { return $pa; } $class = str_replace('PermissionKey', 'PermissionAccess', get_class($pk)); if ($checkPA) { $row = $db->GetRow('select paID, paIsInUse from PermissionAccess where paID = ?', array($paID)); if ($row['paID']) { $obj = new $class(); $obj->setPropertiesFromArray($row); } } else { // we got here from an assignment object so we already know its in use. $obj = new $class(); $obj->paID = $paID; $obj->paIsInUse = true; } if (is_object($obj)) { $obj->setPermissionKey($pk); } PermissionCache::addPermissionAccessObject($paID, $pk, $obj); return $obj; }