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: public function __construct() {
29: global $cfg;
30: parent::__construct($cfg['tab']['rights'], 'idright');
31: $this->_setItemClass('cApiRight');
32:
33:
34: $this->_setJoinPartner('cApiUserCollection');
35: $this->_setJoinPartner('cApiAreaCollection');
36: $this->_setJoinPartner('cApiActionCollection');
37: $this->_setJoinPartner('cApiCategoryCollection');
38: $this->_setJoinPartner('cApiClientCollection');
39: $this->_setJoinPartner('cApiLanguageCollection');
40: }
41:
42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53:
54: public function create($userId, $idarea, $idaction, $idcat, $idclient, $idlang, $type) {
55: $oItem = $this->createNewItem();
56:
57: $oItem->set('user_id', $userId);
58: $oItem->set('idarea', $idarea);
59: $oItem->set('idaction', $idaction);
60: $oItem->set('idcat', $idcat);
61: $oItem->set('idclient', $idclient);
62: $oItem->set('idlang', $idlang);
63: $oItem->set('type', $type);
64:
65: $oItem->store();
66:
67: return $oItem;
68: }
69:
70: 71: 72: 73: 74: 75: 76:
77: public function hasFrontendAccessByCatIdAndUserId($idcat, $userId) {
78: global $cfg;
79:
80: $sql = "SELECT :pk FROM `:rights` AS A, `:actions` AS B, `:area` AS C
81: WHERE B.name = 'front_allow' AND C.name = 'str' AND A.user_id = ':userid'
82: AND A.idcat = :idcat AND A.idarea = C.idarea AND B.idaction = A.idaction
83: LIMIT 1";
84:
85: $params = array(
86: 'pk' => $this->getPrimaryKeyName(),
87: 'rights' => $this->table,
88: 'actions' => $cfg['tab']['actions'],
89: 'area' => $cfg['tab']['area'],
90: 'userid' => $userId,
91: 'idcat' => (int) $idcat
92: );
93:
94: $sql = $this->db->prepare($sql, $params);
95: $this->db->query($sql);
96: return $this->db->nextRecord();
97: }
98:
99: 100: 101: 102: 103: 104: 105: 106:
107: public function deleteByUserId($userId) {
108: $result = $this->deleteBy('user_id', $userId);
109: return ($result > 0) ? true : false;
110: }
111:
112: }
113:
114: 115: 116: 117: 118: 119:
120: class cApiRight extends Item {
121:
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: 145:
146: public function setField($name, $value, $bSafe = true) {
147: switch ($name) {
148: case 'idarea':
149: $value = (int) $value;
150: break;
151: case 'idaction':
152: $value = (int) $value;
153: break;
154: case 'idcat':
155: $value = (int) $value;
156: break;
157: case 'idclient':
158: $value = (int) $value;
159: break;
160: case 'idlang':
161: $value = (int) $value;
162: break;
163: case 'type':
164: $value = (int) $value;
165: break;
166: }
167:
168: return parent::setField($name, $value, $bSafe);
169: }
170:
171: }
172: