10 defined(
'JPATH_PLATFORM') or die;
30 parent::__construct(
'#__usergroups',
'id', $db);
40 public function check()
43 if ((trim($this->title)) ==
'')
45 $this->setError(
JText::_(
'JLIB_DATABASE_ERROR_USERGROUP_TITLE'));
53 $query = $db->getQuery(
true)
54 ->select(
'COUNT(title)')
56 ->where(
'title = ' . $db->quote(trim($this->title)))
57 ->where(
'parent_id = ' . (
int) $this->parent_id)
58 ->where(
'id <> ' . (
int) $this->id);
59 $db->setQuery($query);
61 if ($db->loadResult() > 0)
63 $this->setError(
JText::_(
'JLIB_DATABASE_ERROR_USERGROUP_TITLE_EXISTS'));
81 public function rebuild($parent_id = 0, $left = 0)
87 $db->setQuery(
'SELECT id FROM ' . $this->_tbl .
' WHERE parent_id=' . (
int) $parent_id .
' ORDER BY parent_id, title');
88 $children = $db->loadColumn();
94 for ($i = 0, $n = count($children); $i < $n; $i++)
97 $right = $this->rebuild($children[$i], $right);
100 if ($right ===
false)
108 $db->setQuery(
'UPDATE ' . $this->_tbl .
' SET lft=' . (
int) $left .
', rgt=' . (
int) $right .
' WHERE id=' . (
int) $parent_id);
129 public function store($updateNulls =
false)
131 if ($result = parent::store($updateNulls))
151 public function delete($oid = null)
160 throw new UnexpectedValueException(
'Global Category not found');
163 if ($this->parent_id == 0)
165 throw new UnexpectedValueException(
'Root categories cannot be deleted.');
168 if ($this->lft == 0 || $this->rgt == 0)
170 throw new UnexpectedValueException(
'Left-Right data inconsistency. Cannot delete usergroup.');
176 $query = $db->getQuery(
true)
177 ->select($db->quoteName(
'c.id'))
178 ->from($db->quoteName($this->_tbl) .
'AS c')
179 ->where($db->quoteName(
'c.lft') .
' >= ' . (int) $this->lft)
180 ->where($db->quoteName(
'c.rgt') .
' <= ' . (int) $this->rgt);
181 $db->setQuery($query);
182 $ids = $db->loadColumn();
186 throw new UnexpectedValueException(
'Left-Right data inconsistency. Cannot delete usergroup.');
194 ->delete($db->quoteName($this->_tbl))
195 ->where($db->quoteName(
'id') .
' IN (' . implode(
',', $ids) .
')');
196 $db->setQuery($query);
202 foreach ($ids as $id)
204 $replace[] =
',' . $db->quote(
"[$id,") .
',' . $db->quote(
"[") .
')';
205 $replace[] =
',' . $db->quote(
",$id,") .
',' . $db->quote(
",") .
')';
206 $replace[] =
',' . $db->quote(
",$id]") .
',' . $db->quote(
"]") .
')';
207 $replace[] =
',' . $db->quote(
"[$id]") .
',' . $db->quote(
"[]") .
')';
211 ->select(
'id, rules')
212 ->from(
'#__viewlevels');
213 $db->setQuery($query);
214 $rules = $db->loadObjectList();
216 $match_ids = array();
218 foreach ($rules as $rule)
220 foreach ($ids as $id)
222 if (strstr($rule->rules,
'[' . $id) || strstr($rule->rules,
',' . $id) || strstr($rule->rules, $id .
']'))
224 $match_ids[] = $rule->id;
229 if (!empty($match_ids))
232 ->set(
'rules=' . str_repeat(
'replace(', 4 * count($ids)) .
'rules' . implode(
'', $replace))
233 ->update(
'#__viewlevels')
234 ->where(
'id IN (' . implode(
',', $match_ids) .
')');
235 $db->setQuery($query);
241 ->delete($db->quoteName(
'#__user_usergroup_map'))
242 ->where($db->quoteName(
'group_id') .
' IN (' . implode(
',', $ids) .
')');
243 $db->setQuery($query);