33 if ($this->hasItemChild($itemName, $childName) ===
false) {
54 public function assign($itemName, $userId, $bizRule = null,
$data = null)
57 if ($this->getAuthAssignment($itemName, $userId) === null) {
74 if ($allowCaching && $this->_items === array()) {
79 if ($allowCaching && isset($this->_items[ $name ])) {
80 return $this->_items[ $name ];
83 elseif (($item = parent::getAuthItem($name)) !== null) {
102 if ($this->_items === array()) {
108 foreach ($this->_items as $name => $item) {
109 if (in_array($name, $names)) {
110 if ($nested ===
true) {
111 $items[ $item->getType() ][ $name ] = $item;
113 $items[ $name ] = $item;
133 public function getAuthItems($type = null, $userId = null, $sort =
true)
136 if ($sort ===
true) {
137 if ($type === null && $userId === null) {
138 $sql =
"SELECT name,t1.type,description,t1.bizrule,t1.data,weight
139 FROM {$this->itemTable} t1
140 LEFT JOIN {$this->rightsTable} t2 ON name=itemname
141 ORDER BY t1.type DESC, weight ASC";
142 $command = $this->db->createCommand($sql);
143 } elseif ($userId === null) {
144 $sql =
"SELECT name,t1.type,description,t1.bizrule,t1.data,weight
145 FROM {$this->itemTable} t1
146 LEFT JOIN {$this->rightsTable} t2 ON name=itemname
148 ORDER BY t1.type DESC, weight ASC";
149 $command = $this->db->createCommand($sql);
150 $command->bindValue(
':type', $type);
151 } elseif ($type === null) {
152 $sql =
"SELECT name,t1.type,description,t1.bizrule,t1.data,weight
153 FROM {$this->itemTable} t1
154 LEFT JOIN {$this->assignmentTable} t2 ON name=t2.itemname
155 LEFT JOIN {$this->rightsTable} t3 ON name=t3.itemname
157 ORDER BY t1.type DESC, weight ASC";
158 $command = $this->db->createCommand($sql);
159 $command->bindValue(
':userid', $userId);
161 $sql =
"SELECT name,t1.type,description,t1.bizrule,t1.data,weight
162 FROM {$this->itemTable} t1
163 LEFT JOIN {$this->assignmentTable} t2 ON name=t2.itemname
164 LEFT JOIN {$this->rightsTable} t3 ON name=t3.itemname
165 WHERE t1.type=:type AND userid=:userid
166 ORDER BY t1.type DESC, weight ASC";
167 $command = $this->db->createCommand($sql);
168 $command->bindValue(
':type', $type);
169 $command->bindValue(
':userid', $userId);
173 foreach ($command->queryAll() as $row) {
174 $items[ $row[
'name'] ] =
new CAuthItem($this, $row[
'name'], $row[
'type'], $row[
'description'], $row[
'bizrule'], unserialize($row[
'data']));
198 $key = $names === (array) $names ? implode(
'|', $names) : $names;
201 if ($allowCaching && isset($this->_itemChildren[ $key ]) ===
true) {
202 return $this->_itemChildren[ $key ];
207 if (is_string($names)) {
208 $condition =
'parent='.$this->db->quoteValue($names);
211 elseif ($names === (array) $names && $names !== array()) {
212 foreach ($names as &$name) {
213 $name = $this->db->quoteValue($name);
216 $condition =
'parent IN ('.implode(
', ', $names).
')';
221 $sql =
"SELECT name, type, description, bizrule, data
222 FROM {$this->itemTable}, {$this->itemChildTable}
223 WHERE {$condition} AND name=child";
225 foreach ($this->db->createCommand($sql)->queryAll() as $row) {
226 if ((
$data = @unserialize($row[
'data'])) ===
false) {
230 $children[ $row[
'name'] ] =
new CAuthItem($this, $row[
'name'], $row[
'type'], $row[
'description'], $row[
'bizrule'],
$data);
237 return $this->_itemChildren[ $key ] = $children;
243 $sql =
"SELECT * FROM {$this->assignmentTable} WHERE itemname=:itemname";
244 $command = $this->db->createCommand($sql);
245 $command->bindValue(
':itemname', $name);
247 $assignments = array();
248 foreach ($command->queryAll($sql) as $row) {
249 if ((
$data = @unserialize($row[
'data'])) ===
false) {
253 $assignments[ $row[
'userid'] ] =
new CAuthAssignment($this, $row[
'itemname'], $row[
'userid'], $row[
'bizrule'],
$data);
266 foreach ($result as $weight => $itemname) {
267 $sql =
"SELECT COUNT(*) FROM {$this->rightsTable}
268 WHERE itemname=:itemname";
269 $command = $this->db->createCommand($sql);
270 $command->bindValue(
':itemname', $itemname);
273 if ($command->queryScalar()>0) {
274 $sql =
"UPDATE {$this->rightsTable}
276 WHERE itemname=:itemname";
277 $command = $this->db->createCommand($sql);
278 $command->bindValue(
':weight', $weight);
279 $command->bindValue(
':itemname', $itemname);
284 if (($item = $this->
getAuthItem($itemname)) !== null) {
285 $sql =
"INSERT INTO {$this->rightsTable} (itemname, type, weight)
286 VALUES (:itemname, :type, :weight)";
287 $command = $this->db->createCommand($sql);
288 $command->bindValue(
':itemname', $itemname);
289 $command->bindValue(
':type', $item->getType());
290 $command->bindValue(
':weight', $weight);