Пример #1
0
 static function run($file, $Params = array(), $params_as_var = false)
 {
     return eZProcess::instance()->runFile($Params, $file, $params_as_var);
 }
 /**
  * Runs a function in the current module
  *
  * @param string $functionName The function to run
  * @param array $parameters
  *         An indexed list of parameters, these will be mapped onto real
  *         parameters names using the defined parameters names in the
  *         module/function definition.
  *         Any unspecified parameter will be assigned null.
  * @param array $overrideParameters
  *        An asociative array of parameters that will ultimately override
  *        what's in $parameters
  * @param array $userParameters User (custom view) parameters
  *
  * @return array The run result
  */
 function run($functionName, $parameters = array(), $overrideParameters = false, $userParameters = false)
 {
     if (count($this->Functions) > 0 and !isset($this->Functions[$functionName])) {
         eZDebug::writeError("Undefined view: " . $this->Module["name"] . "::{$functionName} ", "eZModule");
         $this->setExitStatus(self::STATUS_FAILED);
         $Return = null;
         return $Return;
     }
     if ($this->singleFunction()) {
         $function = $this->Module["function"];
     } else {
         $function = $this->Functions[$functionName];
     }
     $params = array();
     $i = 0;
     $parameterValues = array();
     if (isset($function["params"])) {
         $functionParameterDefinitions = $function["params"];
         foreach ($functionParameterDefinitions as $param) {
             if (isset($parameters[$i])) {
                 $params[$param] = $parameters[$i];
                 $parameterValues[] = $parameters[$i];
             } else {
                 $params[$param] = null;
                 $parameterValues[] = null;
             }
             ++$i;
         }
     }
     $this->ViewParameters = $parameters;
     $this->OriginalParameters = $parameters;
     $this->OriginalViewParameters = $parameterValues;
     $this->NamedParameters = $params;
     $GLOBALS['eZRequestedModuleParams'] = array('module_name' => $this->Name, 'function_name' => $functionName, 'parameters' => $params);
     $this->UserParameters = $userParameters;
     if (isset($function['ui_context'])) {
         $this->UIContext = $function['ui_context'];
     }
     if (isset($function['ui_component'])) {
         $this->UIComponent = $function['ui_component'];
     } else {
         if ($this->UIComponentMatch == 'view') {
             $this->UIComponent = $functionName;
         }
     }
     if (array_key_exists('Limitation', $parameters)) {
         $params['Limitation'] =& $parameters['Limitation'];
     }
     // check for unordered parameters and initialize variables if they exist
     $unorderedParametersList = array();
     $unorderedParameters = array();
     if (isset($function["unordered_params"])) {
         $unorderedParams = $function["unordered_params"];
         foreach ($unorderedParams as $urlParamName => $variableParamName) {
             if (in_array($urlParamName, $parameters)) {
                 $pos = array_search($urlParamName, $parameters);
                 $params[$variableParamName] = $parameters[$pos + 1];
                 $unorderedParameters[$variableParamName] = $parameters[$pos + 1];
                 $unorderedParametersList[$variableParamName] = $parameters[$pos + 1];
             } else {
                 $params[$variableParamName] = false;
                 $unorderedParameters[$variableParamName] = false;
             }
         }
     }
     // Loop through user defines parameters
     if ($userParameters !== false) {
         if (!isset($params['UserParameters']) or !is_array($params['UserParameters'])) {
             $params['UserParameters'] = array();
         }
         if (is_array($userParameters) && count($userParameters) > 0) {
             foreach (array_keys($userParameters) as $paramKey) {
                 if (isset($function['unordered_params']) && $unorderedParams != null) {
                     if (array_key_exists($paramKey, $unorderedParams)) {
                         $params[$unorderedParams[$paramKey]] = $userParameters[$paramKey];
                         $unorderedParametersList[$unorderedParams[$paramKey]] = $userParameters[$paramKey];
                     }
                 }
                 $params['UserParameters'][$paramKey] = $userParameters[$paramKey];
             }
         }
     }
     $this->OriginalUnorderedParameters = $unorderedParametersList;
     if (is_array($overrideParameters)) {
         foreach ($overrideParameters as $param => $value) {
             $params[$param] = $value;
         }
     }
     $params["Module"] = $this;
     $params["ModuleName"] = $this->Name;
     $params["FunctionName"] = $functionName;
     $params["Parameters"] = $parameters;
     $params_as_var = isset($this->Module["variable_params"]) ? $this->Module["variable_params"] : false;
     $this->ExitStatus = self::STATUS_OK;
     //        eZDebug::writeNotice( $params, 'module parameters1' );
     $currentView =& $GLOBALS['eZModuleCurrentView'];
     $viewStack =& $GLOBALS['eZModuleViewStack'];
     if (!isset($currentView)) {
         $currentView = false;
     }
     if (!isset($viewStack)) {
         $viewStack = array();
     }
     if (is_array($currentView)) {
         $viewStack[] = $currentView;
     }
     $currentView = array('view' => $functionName, 'module' => $this->Name);
     $Return = eZProcess::run($this->Path . "/" . $this->Name . "/" . $function["script"], $params, $params_as_var);
     if ($this->hasViewResult($functionName)) {
         $Return = $this->viewResult($functionName);
     }
     if (count($viewStack) > 0) {
         $currentView = array_pop($viewStack);
     } else {
         $currentView = false;
     }
     // Check if the module has set the navigation part, if not default to module setting
     if (!isset($Return['navigation_part'])) {
         $Return['is_default_navigation_part'] = true;
         if (isset($function['default_navigation_part'])) {
             $Return['navigation_part'] = $function['default_navigation_part'];
         }
     } else {
         $Return['is_default_navigation_part'] = false;
     }
     // Check if we have overrides for navigation part
     $viewName = $this->Name . '/' . $functionName;
     if (isset($this->NavigationParts[$viewName])) {
         $Return['is_default_navigation_part'] = false;
         $Return['navigation_part'] = $this->NavigationParts[$viewName];
     } else {
         if (isset($this->NavigationParts[$this->Name])) {
             $Return['is_default_navigation_part'] = false;
             $Return['navigation_part'] = $this->NavigationParts[$this->Name];
         }
     }
     return $Return;
 }