This is the API documentation for concrete5 version 5.6 and earlier. View Current API Documentation
 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 
<?php
defined('C5_EXECUTE') or die("Access Denied.");
class Concrete5_Model_PermissionResponse {

    protected $object;
    protected $allowedPermissions = array();
    protected $customClassObjects = array();
    protected $category;
    static $cache = array();
    
    public function setPermissionObject($object) { 
        $this->object = $object;
    }
    public function getPermissionObject() {
        return $this->object;
    }
    public function setPermissionCategoryObject($category) {
        $this->category = $category;
    }
    
    public function testForErrors() { }
    
    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 validate($permission, $args = array()) {
        $u = new User();
        if ($u->isSuperUser()) {
            return true;
        }
        if (!is_object($this->category)) {
            throw new Exception(t('Unable to get category for permission %s', $permission));
        }
        $pk = $this->category->getPermissionKeyByHandle($permission);
        if (!$pk) {
            print t('Unable to get permission key for %s', $permission);
            exit;
        }
        $pk->setPermissionObject($this->object);
        return call_user_func_array(array($pk, 'validate'), $args);
    }
    
    public function __call($f, $a) {
        $permission = substr($f, 3);
        $permission = Loader::helper('text')->uncamelcase($permission);
        return $this->validate($permission, $a);
    }
    

}