/**
* Method to check the current record to save
*
* @return boolean True on success
*
* @since 1.7.0
*/
public function check()
{
try {
parent::check();
} catch (\Exception $e) {
$this->setError($e->getMessage());
return false;
}
// Validate the title.
if (trim($this->title) == '') {
$this->setError(Text::_('JLIB_DATABASE_ERROR_VIEWLEVEL'));
return false;
}
$id = (int) $this->id;
// Check for a duplicate title.
$db = $this->_db;
$query = $db->getQuery(true)->select('COUNT(' . $db->quoteName('title') . ')')->from($db->quoteName('#__viewlevels'))->where($db->quoteName('title') . ' = :title')->where($db->quoteName('id') . ' != :id')->bind(':title', $this->title)->bind(':id', $id, ParameterType::INTEGER);
$db->setQuery($query);
if ($db->loadResult() > 0) {
$this->setError(Text::sprintf('JLIB_DATABASE_ERROR_USERLEVEL_NAME_EXISTS', $this->title));
return false;
}
return true;
}