. */ namespace SP\Util; use SP\Core\Exceptions\SPException; use SP\Mvc\View\Template; /** * Class ErrorUtil * * @package SP\Util */ class ErrorUtil { /** * Constantes de errores */ const ERR_UNAVAILABLE = 0; const ERR_ACCOUNT_NO_PERMISSION = 1; const ERR_PAGE_NO_PERMISSION = 2; const ERR_UPDATE_MPASS = 3; const ERR_OPERATION_NO_PERMISSION = 4; const ERR_EXCEPTION = 5; /** * Establecer la plantilla de error con el código indicado. * * @param \SP\Mvc\View\Template $view * @param int $type int con el tipo de error */ public static function showErrorInViewAndReset(Template $view, $type) { $view->resetTemplates(); self::showErrorInView($view, $type); } /** * Establecer la plantilla de error con el código indicado. * * @param \SP\Mvc\View\Template $view * @param int $type int con el tipo de error */ public static function showErrorInView(Template $view, $type) { $view->addPartial('error'); $error = self::getErrorTypes($type); $view->append('errors', [ 'type' => SPException::WARNING, 'description' => $error['txt'], 'hint' => $error['hint'] ]); } /** * Return error message by type * * @param $type * @return mixed */ protected static function getErrorTypes($type) { $errorTypes = [ self::ERR_UNAVAILABLE => [ 'txt' => __('Opción no disponible'), 'hint' => __('Consulte con el administrador') ], self::ERR_ACCOUNT_NO_PERMISSION => [ 'txt' => __('No tiene permisos para acceder a esta cuenta'), 'hint' => __('Consulte con el administrador') ], self::ERR_PAGE_NO_PERMISSION => [ 'txt' => __('No tiene permisos para acceder a esta página'), 'hint' => __('Consulte con el administrador') ], self::ERR_OPERATION_NO_PERMISSION => [ 'txt' => __('No tiene permisos para realizar esta operación'), 'hint' => __('Consulte con el administrador') ], self::ERR_UPDATE_MPASS => [ 'txt' => __('Clave maestra actualizada'), 'hint' => __('Reinicie la sesión para cambiarla') ], self::ERR_EXCEPTION => [ 'txt' => __('Se ha producido una excepción'), 'hint' => __('Consulte con el administrador') ] ]; return $errorTypes[$type]; } /** * Establecer la plantilla de error con el código indicado. * * @param \SP\Mvc\View\Template $view * @param int $type int con el tipo de error * @param string $replace Template replacement */ public static function showErrorFull(Template $view, $type, $replace) { $view->replaceTemplate('error-full', $replace, Template::PARTIALS_DIR); $error = self::getErrorTypes($type); $view->append('errors', [ 'type' => SPException::WARNING, 'description' => $error['txt'], 'hint' => $error['hint'] ]); } }