1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: 19: 20: 21: 22: 23:
24: class cApiRightCollection extends ItemCollection {
25:
26: 27: 28:
29: public function __construct() {
30: global $cfg;
31: parent::__construct($cfg['tab']['rights'], 'idright');
32: $this->_setItemClass('cApiRight');
33:
34:
35: $this->_setJoinPartner('cApiUserCollection');
36: $this->_setJoinPartner('cApiAreaCollection');
37: $this->_setJoinPartner('cApiActionCollection');
38: $this->_setJoinPartner('cApiCategoryCollection');
39: $this->_setJoinPartner('cApiClientCollection');
40: $this->_setJoinPartner('cApiLanguageCollection');
41: }
42:
43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54:
55: public function create($userId, $idarea, $idaction, $idcat, $idclient, $idlang, $type) {
56: $oItem = parent::createNewItem();
57:
58: $oItem->set('user_id', $this->escape($userId));
59: $oItem->set('idarea', (int) $idarea);
60: $oItem->set('idaction', (int) $idaction);
61: $oItem->set('idcat', (int) $idcat);
62: $oItem->set('idclient', (int) $idclient);
63: $oItem->set('idlang', (int) $idlang);
64: $oItem->set('type', (int) $type);
65:
66: $oItem->store();
67:
68: return $oItem;
69: }
70:
71: 72: 73: 74: 75: 76: 77:
78: public function hasFrontendAccessByCatIdAndUserId($idcat, $userId) {
79: global $cfg;
80:
81: $sql = "SELECT :pk FROM `:rights` AS A, `:actions` AS B, `:area` AS C " . "WHERE B.name = 'front_allow' AND C.name = 'str' AND A.user_id = ':userid' AND " . "A.idcat = :idcat AND A.idarea = C.idarea AND B.idaction = A.idaction LIMIT 1";
82:
83: $params = array(
84: 'pk' => $this->primaryKey,
85: 'rights' => $this->table,
86: 'actions' => $cfg['tab']['actions'],
87: 'area' => $cfg['tab']['area'],
88: 'userid' => $userId,
89: 'idcat' => (int) $idcat
90: );
91:
92: $sql = $this->db->prepare($sql, $params);
93: $this->db->query($sql);
94: return ($this->db->nextRecord());
95: }
96:
97: 98: 99: 100: 101: 102: 103: 104:
105: public function deleteByUserId($userId) {
106: $result = $this->deleteBy('user_id', $userId);
107: return ($result > 0)? true : false;
108: }
109:
110: }
111:
112: 113: 114: 115: 116: 117:
118: class cApiRight extends Item {
119:
120: 121: 122: 123: 124:
125: public function __construct($mId = false) {
126: global $cfg;
127: parent::__construct($cfg['tab']['rights'], 'idright');
128: $this->setFilters(array(), array());
129: if ($mId !== false) {
130: $this->loadByPrimaryKey($mId);
131: }
132: }
133:
134: }
135: