Back to MenuType class

Method check

public bool
check
()
Overloaded check function
Returns
  • bool True on success, false on failure
Since
  • 1.6
-
  • \Joomla\CMS\Table\Table::check()
Class: MenuType
Project: Joomla

Method check - Source code

/**
 * Overloaded check function
 *
 * @return  boolean  True on success, false on failure
 *
 * @see     Table::check()
 * @since   1.6
 */
public function check()
{
    try {
        parent::check();
    } catch (\Exception $e) {
        $this->setError($e->getMessage());
        return false;
    }
    $this->menutype = ApplicationHelper::stringURLSafe($this->menutype);
    if (empty($this->menutype)) {
        $this->setError(Text::_('JLIB_DATABASE_ERROR_MENUTYPE_EMPTY'));
        return false;
    }
    // Sanitise data.
    if (trim($this->title) === '') {
        $this->title = $this->menutype;
    }
    $id = (int) $this->id;
    // Check for unique menutype.
    $query = $this->_db->getQuery(true)->select('COUNT(id)')->from($this->_db->quoteName('#__menu_types'))->where($this->_db->quoteName('menutype') . ' = :menutype')->where($this->_db->quoteName('id') . ' <> :id')->bind(':menutype', $this->menutype)->bind(':id', $id, ParameterType::INTEGER);
    $this->_db->setQuery($query);
    if ($this->_db->loadResult()) {
        $this->setError(Text::sprintf('JLIB_DATABASE_ERROR_MENUTYPE_EXISTS', $this->menutype));
        return false;
    }
    return true;
}