1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
16:
17: 18: 19: 20: 21: 22:
23: class cApiRightCollection extends ItemCollection {
24: 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: 56: 57: 58:
59: public function create($userId, $idarea, $idaction, $idcat, $idclient, $idlang, $type) {
60: $oItem = $this->createNewItem();
61:
62: $oItem->set('user_id', $userId);
63: $oItem->set('idarea', $idarea);
64: $oItem->set('idaction', $idaction);
65: $oItem->set('idcat', $idcat);
66: $oItem->set('idclient', $idclient);
67: $oItem->set('idlang', $idlang);
68: $oItem->set('type', $type);
69:
70: $oItem->store();
71:
72: return $oItem;
73: }
74:
75: 76: 77: 78: 79: 80: 81: 82: 83: 84:
85: public function hasFrontendAccessByCatIdAndUserId($idcat, $userId) {
86: global $cfg;
87:
88: $sql = "SELECT :pk FROM `:rights` AS A, `:actions` AS B, `:area` AS C
89: WHERE B.name = 'front_allow' AND C.name = 'str' AND A.user_id = ':userid'
90: AND A.idcat = :idcat AND A.idarea = C.idarea AND B.idaction = A.idaction
91: LIMIT 1";
92:
93: $params = array(
94: 'pk' => $this->getPrimaryKeyName(),
95: 'rights' => $this->table,
96: 'actions' => $cfg['tab']['actions'],
97: 'area' => $cfg['tab']['area'],
98: 'userid' => $userId,
99: 'idcat' => (int) $idcat
100: );
101:
102: $sql = $this->db->prepare($sql, $params);
103: $this->db->query($sql);
104: return $this->db->nextRecord();
105: }
106:
107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119:
120: public function deleteByUserId($userId) {
121: $result = $this->deleteBy('user_id', $userId);
122: return ($result > 0) ? true : false;
123: }
124:
125: }
126:
127: 128: 129: 130: 131: 132:
133: class cApiRight extends Item
134: {
135: 136: 137: 138: 139: 140: 141: 142: 143:
144: public function __construct($mId = false) {
145: global $cfg;
146: parent::__construct($cfg['tab']['rights'], 'idright');
147: $this->setFilters(array(), array());
148: if ($mId !== false) {
149: $this->loadByPrimaryKey($mId);
150: }
151: }
152:
153: 154: 155: 156: 157: 158: 159: 160: 161:
162: public function setField($name, $value, $bSafe = true) {
163: switch ($name) {
164: case 'idarea':
165: $value = (int) $value;
166: break;
167: case 'idaction':
168: $value = (int) $value;
169: break;
170: case 'idcat':
171: $value = (int) $value;
172: break;
173: case 'idclient':
174: $value = (int) $value;
175: break;
176: case 'idlang':
177: $value = (int) $value;
178: break;
179: case 'type':
180: $value = (int) $value;
181: break;
182: }
183:
184: return parent::setField($name, $value, $bSafe);
185: }
186:
187: }
188: