error = array();
}
/**
* Set an error.
*
* By convention the number is 4xx if the error is coming from
* the user or 5xx if coming from the system (database error for ex.)
*
* @param string Error message
* @param int Error number (0)
*/
function setError($msg, $no=0)
{
$this->error[] = array($no,$msg);
}
/**
* Returns the errors.
*
* @param bool Errors as HTML list (false)
* @param bool Show numbers (true)
* @return mixed array of errors, HTML list, or false if no errors
*/
function error($html=false, $with_nb=true)
{
if (count($this->error) > 0) {
if (!$html) {
return $this->error;
} else {
$res = '
'."\n";
foreach($this->error as $v) {
$res .= '- '.
(($with_nb) ?
''.$v[0].' - ' :
'').
''.$v[1].'
'."\n";
}
return $res."
\n";
}
} else {
return false;
}
}
/**
* Helper function to set the error from the DB.
*
* @param string Error message from the DB
*/
function setDbError($db_error_msg)
{
$this->setError(__('DB error:').' '.$db_error_msg, 500);
}
/**
* Bulk set errors.
*
* Used when you went to recopy the errors of one object into
* another. You can call that way:
* $object->bulkSetErrors($otherobject->error());
*
* @param array List of errors
* @return bool Success
*/
function bulkSetError($errors)
{
if (!is_array($errors)) {
return false;
}
foreach ($errors as $e) {
$this->setError($e[1], $e[0]);
}
return true;
}
}