db = \Zend_Registry::get('db'); }else{ $this->db = $db; } } static function addPaginator($data,$ctl,$limit = 10) { $request = $ctl->getRequest(); $page = $request->getParam('page'); $paginator = \Zend_Paginator::factory($data); $paginator->setCurrentPageNumber($page); $paginator->setItemCountPerPage($limit); $paginator->setView($ctl->view); \Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); $ctl->view->paginator = $paginator; } static function Msg($type,$content,$url=''){ $html = '
'."\r\n"; $html.= '×'."\r\n"; $html.= $content."\r\n"; $html.= '
'."\r\n"; if(!empty($url)) { if($url == -1){ $html.= ''."\r\n"; }else{ $html.= ''."\r\n"; } } return $html; } static function Error($content,$type='',$url=''){ if(empty($type)) { $AlertType = "alert-error"; }else{ $AlertType = $type; } $html = '
'."\r\n"; $html.= '×'."\r\n"; if(!is_array($content)) { $html.= ''.$content.''."\r\n"; }else{ $html.= ''."\r\n"; } $html.= '
'."\r\n"; return $html; } static function User($param = NULL){ $auth = \Zend_Auth::getInstance(); if($auth->hasIdentity()) { if(!empty($param)) { $user = $auth->getIdentity(); return $user->$param; }else{ $user = $auth->getIdentity(); return $user; } }else{ return false; } } static function setUserStorage($user) { $auth = \Zend_Auth::getInstance(); if($auth->hasIdentity()) { if(get_class($user) == 'stdClass') { $auth->getStorage()->write($user); return true; } } return false; } static function Dump($data,$exit = true){ echo "
"."\r\n";
		var_dump($data);
		echo "\r\n";
		echo "
"; if($exit) { exit(); } } static function Post(\Zend_Controller_Action $ctl,$msg,$url=""){ if(empty($msg)) { return false; } if(!is_array($msg)) { $msg = array('content'=>$msg,'url'=>$url); } $helper = new \Zend_Controller_Action_HelperBroker($ctl); $helper->viewRenderer->setNoRender(); echo $ctl->view->partial('post-message.phtml', $msg); return true; } static function JsonOutput(\Zend_Controller_Action $ctl,$data,$json_numeric_check = true) { if($json_numeric_check === true) { $body = json_encode($data,JSON_NUMERIC_CHECK); }else{ $body = json_encode($data); } $ctl ->getResponse() ->setHeader('Content-Type', 'application/json') ->appendBody($body); return true; } static function HttpError($ctl,$code = 404){ $ctl->getResponse()->setHttpResponseCode($code); $helper = new \Zend_Controller_Action_HelperBroker($ctl); $helper->layout->setLayout('layout'); $helper->viewRenderer->setNoRender(); echo $ctl->view->partial('error/404.phtml'); return true; } static function getHostLink() { $protocol = "http"; if(strpos(strtolower($_SERVER['SERVER_PROTOCOL']),"https")) { $protocol = "https"; } return $protocol."://".$_SERVER['SERVER_NAME']; } static function isXmlHttpRequest($ctl = NULL) { $request = new \Zend_Controller_Request_Http(); if($request->isXmlHttpRequest()) { if(!empty($ctl)) { $helper = new \Zend_Controller_Action_HelperBroker($ctl); $helper->layout->disableLayout(); $helper->viewRenderer->setNoRender(); } return true; }else{ return false; } } static function isUuid($uuid) { if(!preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid)) { return false; }else{ return true; } } }