/** * Defined by IfwPsn_Vendor_Zend_Application_Resource_Resource * * @return IfwPsn_Vendor_Zend_View */ public function init() { $view = $this->getView(); $viewRenderer = IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); $viewRenderer->setView($view); return $view; }
/** * Create JSON response * * Encodes and returns data to JSON. Content-Type header set to * 'application/json', and disables layouts and viewRenderer (if being * used). * * @param mixed $data * @param boolean $keepLayouts * @param boolean|array $keepLayouts * @param boolean $encodeData Provided data is already JSON * NOTE: if boolean, establish $keepLayouts to true|false * if array, admit params for IfwPsn_Vendor_Zend_Json::encode as enableJsonExprFinder=>true|false * if $keepLayouts and parmas for IfwPsn_Vendor_Zend_Json::encode are required * then, the array can contains a 'keepLayout'=>true|false and/or 'encodeData'=>true|false * that will not be passed to IfwPsn_Vendor_Zend_Json::encode method but will be passed * to IfwPsn_Vendor_Zend_View_Helper_Json * @throws IfwPsn_Vendor_Zend_Controller_Action_Helper_Json * @return string */ public function encodeJson($data, $keepLayouts = false, $encodeData = true) { /** * @see IfwPsn_Vendor_Zend_View_Helper_Json */ require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/View/Helper/Json.php'; $jsonHelper = new IfwPsn_Vendor_Zend_View_Helper_Json(); $data = $jsonHelper->json($data, $keepLayouts, $encodeData); if (!$keepLayouts) { /** * @see IfwPsn_Vendor_Zend_Controller_Action_HelperBroker */ require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Controller/Action/HelperBroker.php'; IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true); } return $data; }
/** * Returns href for this page * * This method uses {@link IfwPsn_Vendor_Zend_Controller_Action_Helper_Url} to assemble * the href based on the page's properties. * * @return string page href */ public function getHref() { if ($this->_hrefCache) { return $this->_hrefCache; } if (null === self::$_urlHelper) { self::$_urlHelper = IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::getStaticHelper('Url'); } $params = $this->getParams(); if ($param = $this->getModule()) { $params['module'] = $param; } if ($param = $this->getController()) { $params[IfwPsn_Zend_Controller_Front::getInstance()->getRequest()->getControllerKey()] = $param; } if ($param = $this->getAction()) { $params[IfwPsn_Zend_Controller_Front::getInstance()->getRequest()->getActionKey()] = $param; } if ($param = $this->getPage()) { $params['page'] = $param; } if ($param = $this->getAdminpage()) { $params['adminpage'] = $param; } if ($param = $this->getEditpage()) { $params['editpage'] = $param; } if ($param = $this->getPosttype()) { $params['posttype'] = $param; } $url = self::$_urlHelper->url($params, $this->getRoute(), $this->getResetParams(), $this->getEncodeUrl()); // Add the fragment identifier if it is set $fragment = $this->getFragment(); if (null !== $fragment) { $url .= '#' . $fragment; } return $this->_hrefCache = $url; }
/** * Prepare data for autocompletion * * @param mixed $data * @param boolean $keepLayouts * @return string */ public function prepareAutoCompletion($data, $keepLayouts = false) { if (!$data instanceof IfwPsn_Vendor_Zend_Dojo_Data) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Dojo/Data.php'; $items = array(); foreach ($data as $key => $value) { $items[] = array('label' => $value, 'name' => $value); } $data = new IfwPsn_Vendor_Zend_Dojo_Data('name', $items); } if (!$keepLayouts) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Controller/Action/HelperBroker.php'; IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true); require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Layout.php'; $layout = IfwPsn_Vendor_Zend_Layout::getMvcInstance(); if ($layout instanceof IfwPsn_Vendor_Zend_Layout) { $layout->disableLayout(); } } $response = IfwPsn_Vendor_Zend_Controller_Front::getInstance()->getResponse(); $response->setHeader('Content-Type', 'application/json'); return $data->toJson(); }
/** * Returns href for this page * * This method uses {@link IfwPsn_Vendor_Zend_Controller_Action_Helper_Url} to assemble * the href based on the page's properties. * * @return string page href */ public function getHref() { if ($this->_hrefCache) { return $this->_hrefCache; } if (null === self::$_urlHelper) { self::$_urlHelper = IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::getStaticHelper('Url'); } $params = $this->getParams(); if ($param = $this->getModule()) { $params['module'] = $param; } if ($param = $this->getController()) { $params['controller'] = $param; } if ($param = $this->getAction()) { $params['action'] = $param; } $url = self::$_urlHelper->url($params, $this->getRoute(), $this->getResetParams(), $this->getEncodeUrl()); // Use scheme? $scheme = $this->getScheme(); if (null !== $scheme) { if (null === self::$_schemeHelper) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/View/Helper/ServerUrl.php'; self::$_schemeHelper = new IfwPsn_Vendor_Zend_View_Helper_ServerUrl(); } $url = self::$_schemeHelper->setScheme($scheme)->serverUrl($url); } // Add the fragment identifier if it is set $fragment = $this->getFragment(); if (null !== $fragment) { $url .= '#' . $fragment; } return $this->_hrefCache = $url; }
/** * Retrieve ViewRenderer * * @return IfwPsn_Vendor_Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface */ protected function _getViewRenderer() { if (null === $this->_viewRenderer) { $this->_viewRenderer = IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); } return $this->_viewRenderer; }
/** * Retrieve rendered contents of a controller action * * If the action results in a forward or redirect, returns empty string. * * @param string $action * @param string $controller * @param string $module Defaults to default module * @param array $params * @return string */ public function action($action, $controller, $module = null, array $params = array()) { $this->resetObjects(); if (null === $module) { $module = $this->defaultModule; } // clone the view object to prevent over-writing of view variables $viewRendererObj = IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::addHelper(clone $viewRendererObj); $this->request->setParams($params)->setModuleName($module)->setControllerName($controller)->setActionName($action)->setDispatched(true); $this->dispatcher->dispatch($this->request, $this->response); // reset the viewRenderer object to it's original state IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::addHelper($viewRendererObj); if (!$this->request->isDispatched() || $this->response->isRedirect()) { // forwards and redirects render nothing return ''; } $return = $this->response->getBody(); $this->resetObjects(); return $return; }
/** * Retrieve view * * @return IfwPsn_Vendor_Zend_View_Interface */ public function getView() { if (null === $this->_view) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Controller/Action/HelperBroker.php'; $viewRenderer = IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); $this->setView($viewRenderer->view); } return $this->_view; }
/** * Encode data to JSON * * @param mixed $data * @param bool $keepLayouts * @throws IfwPsn_Vendor_Zend_Controller_Action_Exception * @return string */ public function encodeJson($data, $keepLayouts = false) { if ($this->validateData($data)) { return IfwPsn_Vendor_Zend_Controller_Action_HelperBroker::getStaticHelper('Json')->encodeJson($data, $keepLayouts); } /** * @see IfwPsn_Vendor_Zend_Controller_Action_Exception */ require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Controller/Action/Exception.php'; throw new IfwPsn_Vendor_Zend_Controller_Action_Exception('Invalid data passed for autocompletion'); }