| 
									
										
										
										
											2010-03-14 19:48:02 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @copyright NetMonsters <team@netmonsters.ru> | 
					
						
							|  |  |  |  * @link http://netmonsters.ru | 
					
						
							|  |  |  |  * @package Majestic | 
					
						
							|  |  |  |  * @subpackage View | 
					
						
							|  |  |  |  * @since 2010-03-09 | 
					
						
							|  |  |  |  * @version SVN: $Id$ | 
					
						
							|  |  |  |  * @filesource $URL$ | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-26 19:56:01 +00:00
										 |  |  | class MsgViewHelper extends ViewHelper | 
					
						
							| 
									
										
										
										
											2010-03-14 19:48:02 +00:00
										 |  |  | { | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2010-04-26 19:56:01 +00:00
										 |  |  |     const SUCCESS = 'success'; | 
					
						
							|  |  |  |     const ERROR = 'error'; | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2010-03-14 19:48:02 +00:00
										 |  |  |     protected $get; | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2010-04-26 19:56:01 +00:00
										 |  |  |     public function msg($msg = null, $type = null) | 
					
						
							| 
									
										
										
										
											2010-03-14 19:48:02 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-04-26 19:56:01 +00:00
										 |  |  |         if ($msg && $type) { | 
					
						
							|  |  |  |             if (!in_array($type, array(self::SUCCESS, self::ERROR))) { | 
					
						
							| 
									
										
										
										
											2011-11-24 17:57:40 +04:00
										 |  |  |                 throw new GeneralException('Unknown message type: "' . $type . '"'); | 
					
						
							| 
									
										
										
										
											2010-04-26 19:56:01 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |             Session::set(__CLASS__, array('message' => $msg, 'type' => $type)); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-03-14 19:48:02 +00:00
										 |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     public function success($msg) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-04-26 19:56:01 +00:00
										 |  |  |         Session::set(__CLASS__, array('message' => $msg, 'type' => self::SUCCESS)); | 
					
						
							| 
									
										
										
										
											2010-03-14 19:48:02 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     public function error($msg) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-04-26 19:56:01 +00:00
										 |  |  |         Session::set(__CLASS__, array('message' => $msg, 'type' => self::ERROR)); | 
					
						
							| 
									
										
										
										
											2010-03-14 19:48:02 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     public function __toString() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $msg = Session::get(__CLASS__, false); | 
					
						
							|  |  |  |         if ($msg) { | 
					
						
							|  |  |  |             Session::del(__CLASS__); | 
					
						
							|  |  |  |             return '<div class="' . $msg['type'] . '">' . $this->view->escape($msg['message']) . '</div>'; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-09-06 09:15:54 +00:00
										 |  |  |         return ''; | 
					
						
							| 
									
										
										
										
											2010-03-14 19:48:02 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } |