-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathError.php
More file actions
47 lines (42 loc) · 1.75 KB
/
Copy pathError.php
File metadata and controls
47 lines (42 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/**
*
* @author Wilson Ramiro Champi Tacuri
*/
class ZendR_Error
{
public static function prepareMessageModel($model, $code, $message)
{
if (!($model instanceof ZendR_Sf_Record)) {
throw new Exception('Model is not instance of ZendR_Sf_Record');
}
if (strpos($message, 'Duplicate') !== false) {
if (strpos($message, '_idx') !== false) {
$message = 'Registro Duplicado';
} else {
$messageArr = explode("'", $message);
$atributo = self::_parseAtributo(isset($messageArr[3]) ? $messageArr[3] : '');
$message = $atributo . ' (' . $messageArr[1] . ') ya se encuentra registrado';
}
}
if (strpos($message, 'delete') !== false && strpos($message, 'parent') !== false) {
$registrosRelacionados = '<br />';
foreach ($model->getTable()->getRelations() as $relation) {
if ($relation instanceof Doctrine_Relation_ForeignKey) {
$getRelation = 'get' . ucfirst($relation->getAlias());
if ($model->$getRelation()->count() > 0 && !$relation->isCascadeDelete()) {
$registrosRelacionados .= '<br /> * <strong>'
. $relation->getAlias() . '</strong> Relacionados';
}
}
}
$message = ' No se puede eliminar <strong>' . get_class($model) . '</strong> ya que tiene: '
. $registrosRelacionados;
}
return $message;
}
private static function _parseAtributo($message)
{
return ucwords(str_replace('_', ' ', $message));
}
}