- md5
- dc735f5b1a9db4761d3d8b41e9fa27bf
- sha1
- e8c21dd803a0e634721eee5a50bacc7aa6becd0f
- sha256
- f64c232cb6464f3bc0d9c4b385ce3db4008534ca5e05155d9eaa54a314e898d1
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
<?php
/**
* @package Joomla.Legacy
* @subpackage Table
*
* @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Menu Types table
*
* @since 11.1
*/
class JTableMenuType extends JTable
{
/**
* Constructor
*
* @param JDatabaseDriver $db Database driver object.
*
* @since 11.1
*/
public function __construct(JDatabaseDriver $db)
{
parent::__construct('#__menu_types', 'id', $db);
}
/**
* Overloaded check function
*
* @return boolean True on success, false on failure
*
* @see JTable::check()
* @since 11.1
*/
public function check()
{
$this->menutype = JApplication::stringURLSafe($this->menutype);
if (empty($this->menutype))
{
$this->setError(JText::_('JLIB_DATABASE_ERROR_MENUTYPE_EMPTY'));
return false;
}
// Sanitise data.
if (trim($this->title) == '')
{
$this->title = $this->menutype;
}
// Check for unique menutype.
$query = $this->_db->getQuery(true)
->select('COUNT(id)')
->from($this->_db->quoteName('#__menu_types'))
->where($this->_db->quoteName('menutype') . ' = ' . $this->_db->quote($this->menutype))
->where($this->_db->quoteName('id') . ' <> ' . (int) $this->id);
$this->_db->setQuery($query);
if ($this->_db->loadResult())
{
$this->setError(JText::sprintf('JLIB_DATABASE_ERROR_MENUTYPE_EXISTS', $this->menutype));
return false;
}
return true;
}
/**
* Method to store a row in the database from the JTable instance properties.
* If a primary key value is set the row with that primary key value will be
* updated with the instance property values. If no primary key value is set
* a new row will be inserted into the database with the properties from the
* JTable instance.
*
* @param boolean $updateNulls True to update fields even if they are null.
*
* @return boolean True on success.
*
* @link https://docs.joomla.org/JTable/store
* @since 11.1
*/
public function store($updateNulls = false)
{
if ($this->id)
{
// Get the user id
$userId = JFactory::getUser()->id;
// Get the old value of the table
$table = JTable::getInstance('Menutype', 'JTable', array('dbo', $this->getDbo()));
$table->load($this->id);
// Verify that no items are checked out
$query = $this->_db->getQuery(true)
->select('id')
->from('#__menu')
->where('menutype=' . $this->_db->quote($table->menutype))
->where('checked_out !=' . (int) $userId)
->where('checked_out !=0');
$this->_db->setQuery($query);
if ($this->_db->loadRowList())
{
$this->setError(
JText::sprintf('JLIB_DATABASE_ERROR_STORE_FAILED', get_class($this), JText::_('JLIB_DATABASE_ERROR_MENUTYPE_CHECKOUT'))
);
return false;
}
// Verify that no module for this menu are checked out
$query->clear()
->select('id')
->from('#__modules')
->where('module=' . $this->_db->quote('mod_menu'))
->where('params LIKE ' . $this->_db->quote('%"menutype":' . json_encode($table->menutype) . '%'))
->where('checked_out !=' . (int) $userId)
->where('checked_out !=0');
$this->_db->setQuery($query);
if ($this->_db->loadRowList())
{
$this->setError(
JText::sprintf('JLIB_DATABASE_ERROR_STORE_FAILED', get_class($this), JText::_('JLIB_DATABASE_ERROR_MENUTYPE_CHECKOUT'))
);
return false;
}
// Update the menu items
$query->clear()
->update('#__menu')
->set('menutype=' . $this->_db->quote($this->menutype))
->where('menutype=' . $this->_db->quote($table->menutype));
$this->_db->setQuery($query);
$this->_db->execute();
// Update the module items
$query->clear()
->update('#__modules')
->set(
'params=REPLACE(params,' . $this->_db->quote('"menutype":' . json_encode($table->menutype)) . ',' .
$this->_db->quote('"menutype":' . json_encode($this->menutype)) . ')'
);
$query->where('module=' . $this->_db->quote('mod_menu'))
->where('params LIKE ' . $this->_db->quote('%"menutype":' . json_encode($table->menutype) . '%'));
$this->_db->setQuery($query);
$this->_db->execute();
}
return parent::store($updateNulls);
}
/**
* Method to delete a row from the database table by primary key value.
*
* @param mixed $pk An optional primary key value to delete. If not set the instance property value is used.
*
* @return boolean True on success.
*
* @link https://docs.joomla.org/JTable/delete
* @since 11.1
*/
public function delete($pk = null)
{
$k = $this->_tbl_key;
$pk = (is_null($pk)) ? $this->$k : $pk;
// If no primary key is given, return false.
if ($pk !== null)
{
// Get the user id
$userId = JFactory::getUser()->id;
// Get the old value of the table
$table = JTable::getInstance('Menutype', 'JTable', array('dbo', $this->getDbo()));
$table->load($pk);
// Verify that no items are checked out
$query = $this->_db->getQuery(true)
->select('id')
->from('#__menu')
->where('menutype=' . $this->_db->quote($table->menutype))
->where('client_id=0')
->where('(checked_out NOT IN (0,' . (int) $userId . ') OR home=1 AND language=' . $this->_db->quote('*') . ')');
$this->_db->setQuery($query);
if ($this->_db->loadRowList())
{
$this->setError(JText::sprintf('JLIB_DATABASE_ERROR_DELETE_FAILED', get_class($this), JText::_('JLIB_DATABASE_ERROR_MENUTYPE')));
return false;
}
// Verify that no module for this menu are checked out
$query->clear()
->select('id')
->from('#__modules')
->where('module=' . $this->_db->quote('mod_menu'))
->where('params LIKE ' . $this->_db->quote('%"menutype":' . json_encode($table->menutype) . '%'))
->where('checked_out !=' . (int) $userId)
->where('checked_out !=0');
$this->_db->setQuery($query);
if ($this->_db->loadRowList())
{
$this->setError(JText::sprintf('JLIB_DATABASE_ERROR_DELETE_FAILED', get_class($this), JText::_('JLIB_DATABASE_ERROR_MENUTYPE')));
return false;
}
// Delete the menu items
$query->clear()
->delete('#__menu')
->where('menutype=' . $this->_db->quote($table->menutype))
->where('client_id=0');
$this->_db->setQuery($query);
$this->_db->execute();
// Update the module items
$query->clear()
->delete('#__modules')
->where('module=' . $this->_db->quote('mod_menu'))
->where('params LIKE ' . $this->_db->quote('%"menutype":' . json_encode($table->menutype) . '%'));
$this->_db->setQuery($query);
$this->_db->execute();
}
return parent::delete($pk);
}
}
The same content is in 19 releases, Joomla 3.4.0-beta1 to 3.4.8. See them all, or every version of this file.