|
@ -13,37 +13,63 @@ class MsgViewHelper extends ViewHelper |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
const SUCCESS = 'success'; |
|
|
const SUCCESS = 'success'; |
|
|
|
|
|
|
|
|
const ERROR = 'error'; |
|
|
const ERROR = 'error'; |
|
|
|
|
|
|
|
|
protected $get; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const INFO = 'info'; |
|
|
|
|
|
|
|
|
|
|
|
const WARNING = 'warning'; |
|
|
|
|
|
|
|
|
|
|
|
protected $css_prefix = ''; |
|
|
|
|
|
|
|
|
public function msg($msg = null, $type = null) |
|
|
public function msg($msg = null, $type = null) |
|
|
{ |
|
|
{ |
|
|
if ($msg && $type) { |
|
|
if ($msg && $type) { |
|
|
if (!in_array($type, array(self::SUCCESS, self::ERROR))) { |
|
|
|
|
|
|
|
|
if (!in_array($type, array(self::SUCCESS, self::ERROR, self::INFO, self::WARNING))) { |
|
|
throw new GeneralException('Unknown message type: "' . $type . '"'); |
|
|
throw new GeneralException('Unknown message type: "' . $type . '"'); |
|
|
} |
|
|
} |
|
|
Session::set(__CLASS__, array('message' => $msg, 'type' => $type)); |
|
|
|
|
|
|
|
|
$this->set($msg, $type); |
|
|
} |
|
|
} |
|
|
return $this; |
|
|
return $this; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function success($msg) |
|
|
public function success($msg) |
|
|
{ |
|
|
{ |
|
|
Session::set(__CLASS__, array('message' => $msg, 'type' => self::SUCCESS)); |
|
|
|
|
|
|
|
|
$this->set($msg, self::SUCCESS); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function error($msg) |
|
|
public function error($msg) |
|
|
{ |
|
|
{ |
|
|
Session::set(__CLASS__, array('message' => $msg, 'type' => self::ERROR)); |
|
|
|
|
|
|
|
|
$this->set($msg, self::ERROR); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function info($msg) |
|
|
|
|
|
{ |
|
|
|
|
|
$this->set($msg, self::INFO); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function warning($msg) |
|
|
|
|
|
{ |
|
|
|
|
|
$this->set($msg, self::WARNING); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected function set($msg, $type) |
|
|
|
|
|
{ |
|
|
|
|
|
Session::set(__CLASS__, array('message' => $msg, 'type' => $type)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function withPrefix($css_prefix) |
|
|
|
|
|
{ |
|
|
|
|
|
$this->css_prefix = $css_prefix; |
|
|
|
|
|
return $this; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public function __toString() |
|
|
public function __toString() |
|
|
{ |
|
|
{ |
|
|
$msg = Session::get(__CLASS__, false); |
|
|
$msg = Session::get(__CLASS__, false); |
|
|
if ($msg) { |
|
|
if ($msg) { |
|
|
Session::del(__CLASS__); |
|
|
Session::del(__CLASS__); |
|
|
return '<div class="' . $msg['type'] . '">' . $this->view->escape($msg['message']) . '</div>'; |
|
|
|
|
|
|
|
|
return '<div class="' . $this->css_prefix . $msg['type'] . '">' . $this->view->escape($msg['message']) . '</div>'; |
|
|
} |
|
|
} |
|
|
return ''; |
|
|
return ''; |
|
|
} |
|
|
} |