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 = $this->createNewItem();
57:
58: $oItem->set('user_id', $userId);
59: $oItem->set('idarea', $idarea);
60: $oItem->set('idaction', $idaction);
61: $oItem->set('idcat', $idcat);
62: $oItem->set('idclient', $idclient);
63: $oItem->set('idlang', $idlang);
64: $oItem->set('type', $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
82: WHERE B.name = 'front_allow' AND C.name = 'str' AND A.user_id = ':userid'
83: AND A.idcat = :idcat AND A.idarea = C.idarea AND B.idaction = A.idaction
84: LIMIT 1";
85:
86: $params = array(
87: 'pk' => $this->primaryKey,
88: 'rights' => $this->table,
89: 'actions' => $cfg['tab']['actions'],
90: 'area' => $cfg['tab']['area'],
91: 'userid' => $userId,
92: 'idcat' => (int) $idcat
93: );
94:
95: $sql = $this->db->prepare($sql, $params);
96: $this->db->query($sql);
97: return ($this->db->nextRecord());
98: }
99:
100: 101: 102: 103: 104: 105: 106: 107:
108: public function deleteByUserId($userId) {
109: $result = $this->deleteBy('user_id', $userId);
110: return ($result > 0) ? true : false;
111: }
112:
113: }
114:
115: 116: 117: 118: 119: 120:
121: class cApiRight extends Item {
122:
123: 124: 125: 126: 127:
128: public function __construct($mId = false) {
129: global $cfg;
130: parent::__construct($cfg['tab']['rights'], 'idright');
131: $this->setFilters(array(), array());
132: if ($mId !== false) {
133: $this->loadByPrimaryKey($mId);
134: }
135: }
136:
137: 138: 139: 140: 141: 142: 143:
144: public function setField($name, $value, $bSafe = true) {
145: switch ($name) {
146: case 'idarea':
147: $value = (int) $value;
148: break;
149: case 'idaction':
150: $value = (int) $value;
151: break;
152: case 'idcat':
153: $value = (int) $value;
154: break;
155: case 'idclient':
156: $value = (int) $value;
157: break;
158: case 'idlang':
159: $value = (int) $value;
160: break;
161: case 'type':
162: $value = (int) $value;
163: break;
164: }
165:
166: return parent::setField($name, $value, $bSafe);
167: }
168:
169: }
170: