* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 9535 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
abstract class ObjectModel extends ObjectModelCore
{
/**
* Override Antadis.
*
* Replacing self::displayFieldName by static::displayFieldName
* to be able to override ObjectModel::displayFieldName
*
* {@inheritdoc}
*/
public function validateController($htmlentities = true)
{
$errors = array();
/* Checking for required fields */
$fieldsRequired = array_merge($this->fieldsRequired, (isset(self::$fieldsRequiredDatabase[get_class($this)]) ? self::$fieldsRequiredDatabase[get_class($this)] : array()));
foreach ($fieldsRequired AS $field)
if (($value = Tools::getValue($field, $this->{$field})) == false AND (string)$value != '0')
if (!$this->id OR $field != 'passwd')
$errors[] = ''.static::displayFieldName($field, get_class($this), $htmlentities).' '.Tools::displayError('is required.');
/* Checking for maximum fields sizes */
foreach ($this->fieldsSize AS $field => $maxLength)
if (($value = Tools::getValue($field, $this->{$field})) AND Tools::strlen($value) > $maxLength)
$errors[] = ''.static::displayFieldName($field, get_class($this), $htmlentities).' '.Tools::displayError('is too long.').' ('.Tools::displayError('Maximum length:').' '.$maxLength.')';
/* Checking for fields validity */
foreach ($this->fieldsValidate AS $field => $function)
{
// Hack for postcode required for country which does not have postcodes
if ($value = Tools::getValue($field, $this->{$field}) OR ($field == 'postcode' AND $value == '0'))
{
if (!Validate::$function($value))
$errors[] = ''.static::displayFieldName($field, get_class($this), $htmlentities).' '.Tools::displayError('is invalid.');
else
{
if ($field == 'passwd')
{
if ($value = Tools::getValue($field))
$this->{$field} = Tools::encrypt($value);
}
else
$this->{$field} = $value;
}
}
}
return $errors;
}
}