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 
<?php
defined('C5_EXECUTE') or die("Access Denied.");

class Concrete5_Model_EditPageThemePagePermissionKey extends PagePermissionKey  {
    
    protected function getAllowedThemeIDs() {

        $u = new User();
        $pae = $this->getPermissionAccessObject();
        if (!is_object($pae)) {
            return array();
        }
        
        $accessEntities = $u->getUserAccessEntityObjects();
        $accessEntities = $pae->validateAndFilterAccessEntities($accessEntities);
        $list = $this->getAccessListItems(PagePermissionKey::ACCESS_TYPE_ALL, $accessEntities);
        $list = PermissionDuration::filterByActive($list);
        
        $db = Loader::db();
        $allptIDs = $db->GetCol('select ptID from PageThemes order by ptID asc');
        $ptIDs = array();
        foreach($list as $l) {
            if ($l->getThemesAllowedPermission() == 'N') {
                $ptIDs = array();
            }
            if ($l->getThemesAllowedPermission() == 'C') {
                if ($l->getAccessType() == PagePermissionKey::ACCESS_TYPE_EXCLUDE) {
                    $ptIDs = array_values(array_diff($ptIDs, $l->getThemesAllowedArray()));
                } else { 
                    $ptIDs = array_unique(array_merge($ptIDs, $l->getThemesAllowedArray()));
                }
            }
            if ($l->getThemesAllowedPermission() == 'A') {
                $ptIDs = $allptIDs;
            }
        }
        
        return $ptIDs;
    }
    
    public function validate($theme = false) {
        $u = new User();
        if ($u->isSuperUser()) {
            return true;
        }

        $themes = $this->getAllowedThemeIDs();
        if ($theme != false) {
            return in_array($theme->getThemeID(), $themes);
        } else {
            return count($themes) > 0;
        }
    }
    
    
}