10 defined(
'JPATH_PLATFORM') or die;
30 parent::__construct(
'#__menu_types',
'id', $db);
41 public function check()
45 if (empty($this->menutype))
47 $this->setError(
JText::_(
'JLIB_DATABASE_ERROR_MENUTYPE_EMPTY'));
53 if (trim($this->title) ==
'')
55 $this->title = $this->menutype;
59 $query = $this->_db->getQuery(
true)
61 ->from($this->_db->quoteName(
'#__menu_types'))
62 ->where($this->_db->quoteName(
'menutype') .
' = ' . $this->_db->quote($this->menutype))
63 ->where($this->_db->quoteName(
'id') .
' <> ' . (int) $this->
id);
64 $this->_db->setQuery($query);
66 if ($this->_db->loadResult())
68 $this->setError(
JText::sprintf(
'JLIB_DATABASE_ERROR_MENUTYPE_EXISTS', $this->menutype));
90 public function store($updateNulls =
false)
99 $table->load($this->
id);
102 $query = $this->_db->getQuery(
true)
105 ->where(
'menutype=' . $this->_db->quote($table->menutype))
106 ->where(
'checked_out !=' . (
int) $userId)
107 ->where(
'checked_out !=0');
108 $this->_db->setQuery($query);
110 if ($this->_db->loadRowList())
113 JText::sprintf(
'JLIB_DATABASE_ERROR_STORE_FAILED', get_class($this),
JText::_(
'JLIB_DATABASE_ERROR_MENUTYPE_CHECKOUT'))
123 ->where(
'module=' . $this->_db->quote(
'mod_menu'))
124 ->where(
'params LIKE ' . $this->_db->quote(
'%"menutype":' . json_encode($table->menutype) .
'%'))
125 ->where(
'checked_out !=' . (
int) $userId)
126 ->where(
'checked_out !=0');
127 $this->_db->setQuery($query);
129 if ($this->_db->loadRowList())
132 JText::sprintf(
'JLIB_DATABASE_ERROR_STORE_FAILED', get_class($this),
JText::_(
'JLIB_DATABASE_ERROR_MENUTYPE_CHECKOUT'))
141 ->set(
'menutype=' . $this->_db->quote($this->menutype))
142 ->where(
'menutype=' . $this->_db->quote($table->menutype));
143 $this->_db->setQuery($query);
144 $this->_db->execute();
148 ->update(
'#__modules')
150 'params=REPLACE(params,' . $this->_db->quote(
'"menutype":' . json_encode($table->menutype)) .
',' .
151 $this->_db->quote(
'"menutype":' . json_encode($this->menutype)) .
')'
153 $query->where(
'module=' . $this->_db->quote(
'mod_menu'))
154 ->where(
'params LIKE ' . $this->_db->quote(
'%"menutype":' . json_encode($table->menutype) .
'%'));
155 $this->_db->setQuery($query);
156 $this->_db->execute();
159 return parent::store($updateNulls);
172 public function delete($pk = null)
174 $k = $this->_tbl_key;
175 $pk = (is_null($pk)) ? $this->$k : $pk;
188 $query = $this->_db->getQuery(
true)
191 ->where(
'menutype=' . $this->_db->quote($table->menutype))
192 ->where(
'client_id=0')
193 ->where(
'(checked_out NOT IN (0,' . (
int) $userId .
') OR home=1 AND language=' . $this->_db->quote(
'*') .
')');
194 $this->_db->setQuery($query);
196 if ($this->_db->loadRowList())
198 $this->setError(
JText::sprintf(
'JLIB_DATABASE_ERROR_DELETE_FAILED', get_class($this),
JText::_(
'JLIB_DATABASE_ERROR_MENUTYPE')));
207 ->where(
'module=' . $this->_db->quote(
'mod_menu'))
208 ->where(
'params LIKE ' . $this->_db->quote(
'%"menutype":' . json_encode($table->menutype) .
'%'))
209 ->where(
'checked_out !=' . (
int) $userId)
210 ->where(
'checked_out !=0');
211 $this->_db->setQuery($query);
213 if ($this->_db->loadRowList())
215 $this->setError(
JText::sprintf(
'JLIB_DATABASE_ERROR_DELETE_FAILED', get_class($this),
JText::_(
'JLIB_DATABASE_ERROR_MENUTYPE')));
223 ->where(
'menutype=' . $this->_db->quote($table->menutype))
224 ->where(
'client_id=0');
225 $this->_db->setQuery($query);
226 $this->_db->execute();
230 ->delete(
'#__modules')
231 ->where(
'module=' . $this->_db->quote(
'mod_menu'))
232 ->where(
'params LIKE ' . $this->_db->quote(
'%"menutype":' . json_encode($table->menutype) .
'%'));
233 $this->_db->setQuery($query);
234 $this->_db->execute();
237 return parent::delete($pk);