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 81 82 83 84 85 86 87 88 
<?php

defined('C5_EXECUTE') or die("Access Denied.");

class Concrete5_Model_Permissions {

    public $error;

    protected $response;
    
    /** 
     * Checks to see if there is a fatal error with this particular permission call.
     */
    public function isError() {
        return $this->error != '';
    }
    
    /** 
     * Returns the error code if there is one
     */
    public function getError() {
        return $this->error;
    }
    
    /** 
     * Legacy
     * @private
     */
    public function getOriginalObject() {
        return $this->response->getPermissionObject();
    }
    

    public function __construct($object = false) {
        if ($object) { 
            $this->response = PermissionResponse::getResponse($object);
            $r = $this->response->testForErrors();
            if ($r) {
                $this->error = $r;
            }
        }
    }
    
    public function getResponseObject() {
        return $this->response;
    }
    
    /** 
     * We take any permissions function run on the permissions class and send it into the category
     * object
     */
    public function __call($f, $a) {
        if (!is_object($this->response)) {
            // handles task permissions
            $permission = Loader::helper('text')->uncamelcase($f);
        }

        if (count($a) > 0) { 
            if (is_object($this->response)) { 
                $r = call_user_func_array(array($this->response, $f), $a);
            } else {
                $pk = PermissionKey::getByHandle($permission);
                $r = call_user_func_array(array($pk, $f), $a);
            }
        } else { 
            if (is_object($this->response)) { 
                $r = $this->response->{$f}();
            } else {
                $pk = PermissionKey::getByHandle($permission);
                if (is_object($pk)) {
                    $r = $pk->validate();
                } else {
                    throw new Exception(t('Unable to get permission key for %s', $permission));
                }
            }
        }
        
        if (is_array($r) || is_object($r)) {
            return $r;
        } else if ($r) {
            return 1;
        } else {
            return 0;
        }
    }
    
}