private function _changeDispatch(Zend_Controller_Request_Abstract &$request, Zend_Controller_Response_Abstract $response)
 {
     $module = $request->getParam($request->getModuleKey());
     $controller = $request->getParam($request->getControllerKey());
     $action = $request->getParam($request->getActionKey());
     $submodule = '';
     $subcontroller = '';
     $subaction = '';
     if ('admin' != $module) {
         $submodule = $module;
         $subcontroller = $controller ? $controller : 'index';
         $subaction = $action ? $action : 'index';
         $controller = 'index';
         $action = 'subroute';
         $module = 'default';
     } else {
         $submodule = $controller;
         $subcontroller = $action ? $action : 'index';
         //долно быть настроено в route
         //$subaction = ( $action ) ? $action : 'index';
         $controller = 'index';
         $action = 'subroute';
     }
     $request->setParam($request->getModuleKey(), $module);
     $request->setModuleName($module);
     $request->setParam($request->getControllerKey(), $controller);
     $request->setControllerName($controller);
     $request->setParam($request->getActionKey(), $action);
     $request->setActionName($action);
     $request->setParam('submodule', $submodule);
     $request->setParam('subcontroller', $subcontroller);
     $request->setParam('subaction', $subaction);
 }
 public function displayToken($token)
 {
     if ($token) {
         $url = new \MUtil_Html_HrefArrayAttribute(array($this->request->getControllerKey() => 'track', $this->request->getActionKey() => 'show', \MUtil_Model::REQUEST_ID => $token));
         return \MUtil_Html::create('a', $url, $token);
     }
 }
 /**
  * Get the href for a token
  *
  * @param \Gems_Tracker_Token $token
  * @return \MUtil_Html_HrefArrayAttribute
  */
 protected function getTokenHref(\Gems_Tracker_Token $token)
 {
     /***************
      * Get the url *
      ***************/
     $params = array($this->request->getActionKey() => 'to-survey', \MUtil_Model::REQUEST_ID => $token->getTokenId(), 'RouteReset' => false);
     return new \MUtil_Html_HrefArrayAttribute($params);
 }
 /**
  * Create the snippets content
  *
  * This is a stub function either override getHtmlOutput() or override render()
  *
  * @param \Zend_View_Abstract $view Just in case it is needed here
  * @return \MUtil_Html_HtmlInterface Something that can be rendered
  */
 public function getHtmlOutput(\Zend_View_Abstract $view)
 {
     $html = $this->getHtmlSequence();
     $html->h3($this->_('Choose an organization'));
     $user = $this->loader->getCurrentUser();
     $url[$this->request->getControllerKey()] = 'organization';
     $url[$this->request->getActionKey()] = 'change-ui';
     if ($orgs = $user->getRespondentOrganizations()) {
         $html->pInfo($this->_('This organization cannot have any respondents, please choose one that does:'));
         foreach ($orgs as $orgId => $name) {
             $url['org'] = $orgId;
             $html->pInfo()->actionLink($url, $name)->appendAttrib('class', 'larger');
         }
     } else {
         $html->pInfo($this->_('This organization cannot have any respondents.'));
     }
     return $html;
 }
 /**
  * Create the snippets content
  *
  * This is a stub function either override getHtmlOutput() or override render()
  *
  * @param \Zend_View_Abstract $view Just in case it is needed here
  * @return \MUtil_Html_HtmlInterface Something that can be rendered
  */
 public function getHtmlOutput(\Zend_View_Abstract $view)
 {
     $div = \Mutil_Html::create('p');
     $div->append($this->getQuestion());
     $div->append(' ');
     $div->a(array($this->confirmParameter => 1), $this->_('Yes'), array('class' => $this->buttonYesClass));
     $div->append(' ');
     $div->a(array($this->request->getControllerKey() => $this->abortController ?: $this->request->getControllerName(), $this->request->getActionKey() => $this->abortAction ?: $this->request->getActionName()), $this->_('No'), array('class' => $this->buttonNoClass));
     return $div;
 }
 /**
  * 初始化
  * 
  * @return void
  */
 public function init()
 {
     //request和response对象获取
     $this->request = $this->getRequest();
     $this->response = $this->getResponse();
     $this->modKey = $this->request->getModuleKey();
     $this->modName = $this->request->getModuleName();
     $this->ctlKey = $this->request->getControllerKey();
     $this->ctlName = $this->request->getControllerName();
     $this->actKey = $this->request->getActionKey();
     $this->actName = $this->request->getActionName();
     //smarty模板设置
     $this->view = Common_View::getInstance();
     //重新设置模板目录
     $_viewBaseDir = implode(DS, array(APP_NOPUBLIC_MODULES_PATH, $this->modName, 'views'));
     $params = array('template_dir' => $_viewBaseDir . DS . 'html', 'compile_dir' => $_viewBaseDir . DS . 'compile', 'cache_dir' => $_viewBaseDir . DS . 'cache');
     $this->view->setViewParams($params);
     unset($_viewBaseDir);
 }
Beispiel #7
0
 /**
  * Set request keys based on values in request object
  *
  * @return void
  */
 protected function _setRequestKeys()
 {
     if (null !== $this->_request) {
         $this->_moduleKey = $this->_request->getModuleKey();
         $this->_controllerKey = $this->_request->getControllerKey();
         $this->_actionKey = $this->_request->getActionKey();
     }
     if (null !== $this->_dispatcher) {
         $this->_defaults += array($this->_controllerKey => $this->_dispatcher->getDefaultControllerName(), $this->_actionKey => $this->_dispatcher->getDefaultAction(), $this->_moduleKey => $this->_dispatcher->getDefaultModule());
     }
     $this->_keysSet = true;
 }
 public function routeShutdown(Zend_Controller_Request_Abstract $request)
 {
     try {
         // Set Request Object
         $_request[$request->getModuleKey()] = $request->getModuleName();
         $_request[$request->getControllerKey()] = $request->getControllerName();
         $_request[$request->getActionKey()] = $request->getActionName();
         if (PHP_SAPI != 'cli' && $request->getModuleName() != 'cronjob') {
             $_request['url'] = $_SERVER['REQUEST_URI'];
         }
         Monitor_Request::getInstance()->setRequest($_request);
     } catch (Zend_Exception $e) {
         throw $e;
     }
 }
 /**
  * Called before Zend_Controller_Front begins evaluating the
  * request against its routes.
  *
  * @param Zend_Controller_Request_Abstract $request
  * @return void
  */
 public function routeStartup(Zend_Controller_Request_Abstract $request)
 {
     $frontController = Zend_Controller_Front::getInstance();
     // Request keys
     $moduleKey = $request->getModuleKey();
     $controllerKey = $request->getControllerKey();
     $actionKey = $request->getActionKey();
     // Defaults
     $moduleName = $frontController->getDefaultModule();
     $controllerName = $frontController->getDefaultControllerName();
     $actionName = $frontController->getDefaultAction();
     // Set a url path
     $module = $request->getQuery($moduleKey, $moduleName);
     $controller = $request->getQuery($controllerKey, $controllerName);
     $action = $request->getQuery($actionKey, $actionName);
     // Assemble
     if ($request->getPathInfo() == '/') {
         $modulePart = $module == $moduleName ? $module : '/' . $module;
         $controllerPart = $controller == $controllerName && $action == $actionName ? '' : '/' . $controller;
         $actionPart = $action == $actionName && $controller ? '' : '/' . $action;
         $request->setPathInfo($modulePart . $controllerPart . $actionPart);
     }
 }
 /**
  * Check if we have the 'Unknown' consent, and present a warning. The project default consent is
  * normally 'Unknown' but this can be overruled in project.ini so checking for default is not right
  *
  * @static boolean $warned We need only one warning in case of multiple consents
  * @param string $consent
  */
 public function checkConsent($consent)
 {
     static $warned;
     if ($warned) {
         return $consent;
     }
     $unknown = $this->util->getConsentUnknown();
     // Value is translated by now if in bridge
     if ($consent == $unknown || $consent == $this->_($unknown)) {
         $warned = true;
         $msg = $this->_('Please settle the informed consent form for this respondent.');
         if ($this->view instanceof \Zend_View) {
             $url[$this->request->getControllerKey()] = 'respondent';
             $url[$this->request->getActionKey()] = 'edit';
             $url[\MUtil_Model::REQUEST_ID1] = $this->request->getParam(\MUtil_Model::REQUEST_ID1);
             $url[\MUtil_Model::REQUEST_ID2] = $this->request->getParam(\MUtil_Model::REQUEST_ID2);
             $urlString = $this->view->url($url) . '#tabContainer-frag-4';
             $this->addMessage(\MUtil_Html::create()->a($urlString, $msg));
         } else {
             $this->addMessage($msg);
         }
     }
     return $consent;
 }
Beispiel #11
0
 /**
  * Sets parameters for request object
  *
  * Module name, controller name and action name
  *
  * @param Zend_Controller_Request_Abstract $request
  * @param array                            $params
  */
 protected function _setRequestParams($request, $params)
 {
     foreach ($params as $param => $value) {
         $request->setParam($param, $value);
         if ($param === $request->getModuleKey()) {
             $request->setModuleName($value);
         }
         if ($param === $request->getControllerKey()) {
             $request->setControllerName($value);
         }
         if ($param === $request->getActionKey()) {
             $request->setActionName($value);
         }
     }
 }
 /**
  * Prcesses the filter for the date selector and return the filter to use instead
  * 
  * @param \Zend_Controller_Request_Abstract $request
  * @param array $filter
  * @param string $dateField
  * @return array The new complete filter to use
  */
 public function getFilter(\Zend_Controller_Request_Abstract $request, array $filter = array(), $dateField = null)
 {
     $this->_actionKey = $request->getActionKey();
     // \MUtil_Echo::r($filter, __CLASS__ . '->' . __FUNCTION__ .' 1');
     $filter = $this->processFilter($request, $filter);
     if ($filter) {
         $model = $this->getModel();
         $model->addFilter($filter);
     }
     // \MUtil_Echo::r($filter, __CLASS__ . '->' . __FUNCTION__ . ' 2');
     $newfilter = $filter;
     if ($this->dateCurrentStart && $this->dateCurrentEnd) {
         if (null === $dateField) {
             $dateField = $this->dateFrom;
         }
         $start = $this->dateCurrentStart->getIso();
         $end = $this->dateCurrentEnd->getIso();
         $newfilter[] = "{$dateField} BETWEEN '{$start}' AND '{$end}'";
     }
     if ($this->dateGroup) {
         $fields = $this->getFields();
         if (isset($fields[$this->dateGroup])) {
             if ($groupfilter = $fields[$this->dateGroup]->getFilter()) {
                 $newfilter[] = $groupfilter;
             }
         }
     }
     return $newfilter;
 }
Beispiel #13
0
 /**
  * Processes a request and sets its controller and action.  If
  * no route was possible, an exception is thrown.
  *
  * @param  \Zend_Controller_Request_Abstract
  * @throws \Zend_Controller_Router_Exception
  * @return \Zend_Controller_Request_Abstract|boolean
  */
 public function route(\Zend_Controller_Request_Abstract $request)
 {
     $options = array('help|h' => 'Show this help', 'org|o=i' => 'The user organization number', 'pwd|p=s' => 'User password', 'user|u=s' => 'The user name');
     $getopt = new \Zend_Console_Getopt($options);
     try {
         $getopt->parse();
     } catch (\Zend_Console_Getopt_Exception $e) {
         echo $this->_expandMessage($e);
         exit;
     }
     if ($getopt->getOption('h')) {
         // $getopt->s
         echo $this->_expandMessage($getopt);
         exit;
     }
     if ($request instanceof \MUtil_Controller_Request_Cli) {
         $request->setUserLogin($getopt->getOption('u'), $getopt->getOption('o'), $getopt->getOption('p'));
     }
     $arguments = $getopt->getRemainingArgs();
     if ($arguments) {
         $controller = array_shift($arguments);
         $action = array_shift($arguments);
         if (!$action) {
             $action = 'index';
         }
         if (preg_match('/^\\w+(-\\w+)*$/', $controller) && preg_match('/^\\w+(-\\w+)*$/', $action)) {
             $request->setControllerName($controller);
             $request->setActionName($action);
             $params[$request->getControllerKey()] = $controller;
             $params[$request->getActionKey()] = $action;
             foreach ($arguments as $arg) {
                 if (\MUtil_String::contains($arg, '=')) {
                     list($name, $value) = explode('=', $arg, 2);
                 } else {
                     $name = $arg;
                     $value = '';
                 }
                 $params[$name] = $value;
             }
             $request->setParams($params);
             return $request;
         }
         echo "Invalid command: {$controller}/{$action}.\n", exit;
     }
     echo "No command given.\n\n";
     echo $this->_expandMessage($getopt), exit;
 }
Beispiel #14
0
 /**
  * Filters a request for use with applyParameters.
  *
  * @param \Zend_Controller_Request_Abstract $request
  * @param boolean $removePost Optional
  * @param boolean $includeNumericFilters When true numeric filter keys (0, 1, 2...) are added to the filter as well
  * @return \MUtil_Model_ModelAbstract
  */
 public function applyRequest(\Zend_Controller_Request_Abstract $request, $removePost = true, $includeNumericFilters = false)
 {
     $parameters = $request->getParams();
     // Remove MVC fields
     unset($parameters[$request->getModuleKey()], $parameters[$request->getControllerKey()], $parameters[$request->getActionKey()]);
     if ($removePost) {
         // Do not use POST fields for filter
         $parameters = array_diff_key($parameters, $_POST);
     }
     // Remove all empty values (but not arrays) from the filter
     $parameters = array_filter($parameters, function ($i) {
         return is_array($i) || strlen($i);
     });
     $this->applyParameters($parameters, $includeNumericFilters);
     return $this;
 }
 /**
  * Set what to do when the form is 'finished'.
  *
  * @return \MUtil_Snippets_ModelFormSnippetAbstract (continuation pattern)
  */
 protected function setAfterSaveRoute()
 {
     // Default is just go to the index
     if ($this->routeAction && $this->request->getActionName() !== $this->routeAction) {
         $this->afterSaveRouteUrl = array($this->request->getActionKey() => $this->routeAction);
         if ($this->afterSaveRouteKeys) {
             // Set the key identifiers for the route.
             //
             // Mind you the values may have changed, either because of an edit or
             // because a new item was created.
             foreach ($this->getModel()->getKeys() as $id => $key) {
                 if (isset($this->formData[$key])) {
                     $this->afterSaveRouteUrl[$id] = $this->formData[$key];
                 }
             }
         }
     }
     return $this;
 }