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  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 
<?php
defined('C5_EXECUTE') or die("Access Denied.");
class Concrete5_Model_PermissionAccessEntityType extends Object {

    public function getAccessEntityTypeID() {return $this->petID;}
    public function getAccessEntityTypeHandle() {return $this->petHandle;}
    public function getAccessEntityTypeName() {return $this->petName;}
    public function getAccessEntityTypeClass() {
        $class = Loader::helper('text')->camelcase($this->petHandle) . 'PermissionAccessEntity';
        return $class;
    }

    /** Returns the display name for this access entity type (localized and escaped accordingly to $format)
    * @param string $format = 'html'
    *   Escape the result in html format (if $format is 'html').
    *   If $format is 'text' or any other value, the display name won't be escaped.
    * @return string
    */
    public function getAccessEntityTypeDisplayName($format = 'html') {
        $value = tc('PermissionAccessEntityTypeName', $this->getAccessEntityTypeName());
        switch($format) {
            case 'html':
                return h($value);
            case 'text':
            default:
                return $value;
        }
    }

    public static function getByID($petID) {
        $db = Loader::db();
        $row = $db->GetRow('select petID, pkgID, petHandle, petName from PermissionAccessEntityTypes where petID = ?', array($petID));
        if ($row['petHandle']) {
            $wt = new PermissionAccessEntityType();
            $wt->setPropertiesFromArray($row);
            return $wt;
        }
    }
    
    public function __call($method, $args) {
        $obj = $this->getAccessEntityTypeClass();
        $o = new $obj();
        return call_user_func_array(array($obj, $method), $args);
    }
    
    public function getAccessEntityTypeToolsURL($task = false) {
        if (!$task) {
            $task = 'process';
        }
        $uh = Loader::helper('concrete/urls');
        $url = $uh->getToolsURL('permissions/access/entity/types/' . $this->petHandle, $this->getPackageHandle());
        $token = Loader::helper('validation/token')->getParameter($task);
        $url .= '?' . $token . '&task=' . $task;
        return $url;
    }

    public static function getList($category = false) {
        $db = Loader::db();
        $list = array();
        if ($category instanceof PermissionKeyCategory) {
            $r = $db->Execute('select pet.petID from PermissionAccessEntityTypes pet inner join PermissionAccessEntityTypeCategories petc on pet.petID = petc.petID where petc.pkCategoryID = ? order by pet.petID asc', array($category->getPermissionKeyCategoryID()));
        } else { 
            $r = $db->Execute('select petID from PermissionAccessEntityTypes order by petID asc');
        }
        
        while ($row = $r->FetchRow()) {
            $list[] = PermissionAccessEntityType::getByID($row['petID']);
        }
        
        $r->Close();
        return $list;
    }

    public function getPackageID() { return $this->pkgID;}
    public function getPackageHandle() {
        return PackageList::getHandle($this->pkgID);
    }
    
    public static function exportList($xml) {
        $ptypes = PermissionAccessEntityType::getList();
        $db = Loader::db();
        $axml = $xml->addChild('permissionaccessentitytypes');
        foreach($ptypes as $pt) {
            $ptype = $axml->addChild('permissionaccessentitytype');
            $ptype->addAttribute('handle', $pt->getAccessEntityTypeHandle());
            $ptype->addAttribute('name', $pt->getAccessEntityTypeName());
            $ptype->addAttribute('package', $pt->getPackageHandle());
            $categories = $db->GetCol('select pkCategoryHandle from PermissionKeyCategories inner join PermissionAccessEntityTypeCategories where PermissionKeyCategories.pkCategoryID = PermissionAccessEntityTypeCategories.pkCategoryID and PermissionAccessEntityTypeCategories.petID = ?', array($pt->getAccessEntityTypeID()));
            if (count($categories) > 0) {
                $cat = $ptype->addChild('categories');
                foreach($categories as $catHandle) {
                    $cat->addChild('category')->addAttribute('handle', $catHandle);
                }
            }
        }
    }
    
    public function delete() {
        $db = Loader::db();
        $db->Execute("delete from PermissionAccessEntityTypes where petID = ?", array($this->petID));
    }
    
    public static function getListByPackage($pkg) {
        $db = Loader::db();
        $list = array();
        $r = $db->Execute('select petID from PermissionAccessEntityTypes where pkgID = ? order by petID asc', array($pkg->getPackageID()));
        while ($row = $r->FetchRow()) {
            $list[] = PermissionAccessEntityType::getByID($row['petID']);
        }
        $r->Close();
        return $list;
    }   
    
    public static function getByHandle($petHandle) {
        $db = Loader::db();
        $petID = $db->GetOne('select petID from PermissionAccessEntityTypes where petHandle = ?', array($petHandle));
        if ($petID > 0) {
            return self::getByID($petID);
        }
    }
    
    public static function add($petHandle, $petName, $pkg = false) {
        $pkgID = 0;
        if (is_object($pkg)) {
            $pkgID = $pkg->getPackageID();
        }
        $db = Loader::db();
        $db->Execute('insert into PermissionAccessEntityTypes (petHandle, petName, pkgID) values (?, ?, ?)', array($petHandle, $petName, $pkgID));
        $id = $db->Insert_ID();
        $est = PermissionAccessEntityType::getByID($id);
        return $est;
    }
    
}