templateParamsManager = new IHMParamTemplateClass(); } /* * @brief Add an existing parameter */ public function addExistingParam($param, $paramsData, $templateArgs = NULL) { if ($this->isDerivedParam($param)) return $this->addDerivedParam($param,$paramsData); else if ($this->isUploadedParam($param)) return $this->addUploadedParam($param,$paramsData); else if ($this->isImpexParam($param)) return $this->addImpexParam($param,$paramsData,$templateArgs); else return $this->addLocalParam($param,$paramsData,$templateArgs); return ""; } /* * @brief Add a process parameter */ public function addProcessParam($paramId,$expression,$expression_info,$params,$sampling,$gap,$dateModif,$units,$ytitle,$paramsData) { $paramsData->addProcessParamToCreate($paramId, $expression, $expression_info, $params, $sampling, $gap,$dateModif, $units, $ytitle); foreach ($params as $param) { $template_args = NULL; if (array_key_exists("template_args", $param)) $template_args = $param["template_args"]; $this->addExistingParam($param["paramid"],$paramsData,$template_args); } return true; } /* * @brief Detect if it's a derived parameter */ private function isDerivedParam($param) { return preg_match("#^ws_#",$param); } /* * @brief Detect if it's a uploaded parameter */ private function isUploadedParam($param) { return preg_match("#^wsd_#",$param); } /* * @brief Detect if it's IMPEX parameter */ private function isImpexParam($param) { return preg_match("#^".IHMImpexParamClass::$paramPrefix."#",$param); } /* * @brief Add a local parameter */ private function addLocalParam($param, $paramsData, $templateArgs) { //local parameter $indexes = array(); $calib_infos = array(); //check for components $pattern = "/(?P.*)\((?P.*)\)/"; preg_match_all($pattern, $param, $matches); if ((count($matches["param"]) > 0) && (count($matches["components"]) > 0)) { $paramId = $matches["param"][0]; $indexes = explode(",",$matches["components"][0]); } else $paramId = $param; //check templated parameter $real_param_id = $paramId; if ($this->templateParamsManager->isTemplatedParam($paramId)) { $paramPath = $this->templateParamsManager->generateTemplatedParamFile($paramId, $templateArgs); $real_param_id = $this->templateParamsManager->getTemplatedParamId($paramId, $templateArgs); if (empty($paramPath) || !file_exists($paramPath)) throw new Exception('Cannot generate parameter template file '.$paramId); } else { $paramPath = IHMConfigClass::getLocalParamDBPath().$paramId.".xml"; if (!file_exists($paramPath)) throw new Exception('Cannot find parameter local file '.$paramId); } $paramsData->addParamToCopy($real_param_id,$paramPath); $this->addLinkedLocalParams($paramId, $paramsData, $templateArgs); return array("id" => $real_param_id, "indexes" => $indexes, "calib_infos" => $calib_infos); } /* * @brief Add linked parameter */ private function addLinkedLocalParams($paramId,$paramsData,$templateArgs = NULL) { $doc = new DOMDocument("1.0", "UTF-8"); $doc->preserveWhiteSpace = false; $doc->formatOutput = true; $real_param_id = $paramId; if ($this->templateParamsManager->isTemplatedParam($paramId)) { $paramPath = $this->templateParamsManager->getTemplatePath($paramId); if (empty($paramPath) || !@$doc->load($paramPath)) throw new Exception('Cannot find parameter template file '.$paramId); } else { $paramPath = IHMConfigClass::getLocalParamDBPath().$paramId.".xml"; if (empty($paramPath) || !@$doc->load($paramPath)) throw new Exception('Cannot find parameter local file '.$paramId); } // $getNodes = $doc->getElementsByTagName('get'); if ($getNodes->length <= 0) throw new Exception('Parameter local file '.$paramId.' dont have a getter node'); $getNode = $getNodes->item(0); // $amdaParamNodes = $doc->getElementsByTagName('amdaParam'); foreach($amdaParamNodes as $amdaParamNode) { $linkedParamId = $amdaParamNode->getAttribute('name'); if (empty($linkedParamId)) continue; $template_id = $this->templateParamsManager->getTemplateId($linkedParamId); if ($template_id !== FALSE) { $linkedParamId = $template_id; } else { $linkedParamId = $this->templateParamsManager->replaceArgs($linkedParamId, $templateArgs); } if ($this->templateParamsManager->isTemplatedParam($linkedParamId)) { $linkedParamPath = $this->templateParamsManager->generateTemplatedParamFile($linkedParamId, $templateArgs); $real_linked_param_id = $this->templateParamsManager->getTemplatedParamId($linkedParamId, $templateArgs); } else { $real_linked_param_id = $linkedParamId; $linkedParamPath = IHMConfigClass::getLocalParamDBPath().$real_linked_param_id.".xml"; } $paramsData->addParamToCopy($real_linked_param_id,$linkedParamPath); $this->addLinkedLocalParams($linkedParamId, $paramsData); } } /* * @brief Add derived parameter */ private function addDerivedParam($param,$paramsData) { if (!isset($this->userParameterLoader)) $this->userParameterLoader = new IHMUserParamLoaderClass(); //get derived parameter info $res = $this->userParameterLoader->getDerivedParameterFromName($param); if (!$res["success"]) throw new Exception('Error to load derived parameter file : '.$res["message"]); //parse expression if (!isset($this->expressionParser)) $this->expressionParser = new IHMExpressionParserClass(); $expressionInfo = $this->expressionParser->parse($res["param"]["expression"]); $paramId = $param; //create a process param for the derived parameter $this->addProcessParam($paramId, $expressionInfo["expression"], $res["param"]["expression"], $expressionInfo['params'], $res["param"]["timestep"], 0,$res["param"]["dateModif"],!empty($res["param"]["info"]["units"]) ? $res["param"]["info"]["units"] : "", !empty($res["param"]["info"]["yTitle"]) ? $res["param"]["info"]["yTitle"] : "", $paramsData); return array("id" => $paramId, "indexes" => array(), "calib_infos" => array()); } /* * @brief Add IMPEX parameter : create dynamically xml parameter descriptor in user WS */ private function addImpexParam($param,$paramsData,$templateArgs = NULL) { if (!isset($this->paramImpexMgr)) $this->paramImpexMgr = new ImpexParamManager(); $parameterID = $this->paramImpexMgr->getImpexFullParamId($param, $templateArgs); $requestNodes = $paramsData->getRequestNodes(); // it is PARAMSGEN if (!$requestNodes) { return array("id" => $parameterID); } $timesNode = $requestNodes[0]->getTimesNode(); $intervals = $timesNode->getIntervals(); $originFile = IHMConfigClass::getUserWSPath().$parameterID.".xml"; if (!file_exists($originFile)) { // create IMPEX parameter info and data $res = $this->paramImpexMgr->createImpexParameter($param, $intervals, $templateArgs); if (!$res["success"]) throw new Exception('Error to create IMPEX parameter : '.$res["message"]); $newParamNode = $paramsData->addLocalParamToCreate($res["param"]["id"], $res["param"]["info"]["viId"], $res["param"]["info"]["realVar"], $res["param"]["info"]["minSampling"], $res["param"]["info"]["maxSampling"], $res["param"]["info"]["type"],$res["param"]["info"]["size"], $res["param"]["dateModif"],true); $newParamNode->getInfo()->setName($res["param"]["info"]['name']); $newParamNode->getInfo()->setShortName($res["param"]["info"]['name']); $newParamNode->getInfo()->setUnits($res["param"]["info"]['units']); $tableDef = $res["param"]["info"]["tableDef"]; if (isset($tableDef) && array_key_exists('tableDefType', $tableDef) && ($tableDef['tableDefType'] != 'NONE')) { switch ($tableDef['channelsDefType']) { case 'BOUND' : $boundTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::BOUNDS, $res["param"]["info"]["yTitle"]); $boundTable->setUnits($res["param"]["info"]["yUnits"]); switch ($tableDef['tableDefType']) { case 'SELECT' : $boundTable->setBoundsName($tableDef['data']['bound']); $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['bound']); break; default : throw new Exception("Unknown tableDefType ".$tableDef['tableDefType']); } break; case 'CENTER' : $centerTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::CENTER, $res["param"]["info"]["yTitle"]); $centerTable->setUnits($res["param"]["info"]["yUnits"]); $centerTable->setSize($tableDef['data']['width']); switch ($tableDef['tableDefType']) { case 'SELECT' : $centerTable->setCenterName($tableDef['data']['center']); $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['center']); break; default : throw new Exception("Unknown tableDefType ".$tableDef['tableDefType']); } break; default : throw new Exception("Unknown tableDefType ".$tableDef['channelsDefType']); } } return array("id" => $res["param"]["id"], "plotType" => $res["param"]["info"]["plotType"]); } else { // add IMPEX parameter data $this->paramImpexMgr->addImpexData($param, $intervals, $templateArgs); $paramsData->addParamToCopy($parameterID, $originFile); return array("id" => $parameterID); } } /* * @brief Add uploaded parameter */ private function addUploadedParam($param,$paramsData) { if (!isset($this->userParameterLoader)) $this->userParameterLoader = new IHMUserParamLoaderClass(); //get uploaded parameter info $res = $this->userParameterLoader->getUploadedParameterFromName($param); if (!$res["success"]) throw new Exception('Error to load uploaded parameter file : '.$res["message"]); $newParamNode = $paramsData->addLocalParamToCreate($res["param"]["id"], $res["param"]["info"]["viId"], $res["param"]["info"]["realVar"], $res["param"]["info"]["minSampling"], $res["param"]["info"]["maxSampling"], $res["param"]["info"]["type"],$res["param"]["info"]["size"], $res["param"]["dateModif"]); $tableDef = $res["param"]["info"]["tableDef"]; if (isset($tableDef) && array_key_exists('tableDefType', $tableDef) && ($tableDef['tableDefType'] != 'NONE')) { switch ($tableDef['channelsDefType']) { case 'MINMAX' : $minMaxTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::MINMAX, $res["param"]["info"]["yTitle"]); $minMaxTable->setUnits($res["param"]["info"]["units"]); switch ($tableDef['tableDefType']) { case 'SELECT' : $minMaxTable->setMinName($tableDef['data']['min']); $minMaxTable->setMaxName($tableDef['data']['max']); $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['min']); $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['max']); break; case 'MANUAL' : $minMaxTable->setMinName('min'); $minMaxTable->setMaxName('max'); $clbMinNode = $newParamNode->addClbManual('min'); $clbMinValues = explode(',', $tableDef['data']['min']); foreach ($clbMinValues as $value) $clbMinNode->addClbValue($value); $clbMaxNode = $newParamNode->addClbManual('max'); $clbMaxValues = explode(',', $tableDef['data']['max']); foreach ($clbMaxValues as $value) $clbMaxNode->addClbValue($value); break; } break; case 'BOUND' : $boundTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::BOUNDS, $res["param"]["info"]["yTitle"]); $boundTable->setUnits($res["param"]["info"]["units"]); switch ($tableDef['tableDefType']) { case 'SELECT' : $boundTable->setBoundsName($tableDef['data']['bound']); $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['bound']); break; case 'MANUAL' : $boundTable->setBoundsName('bound'); $clbBoundNode = $newParamNode->addClbManual('bound'); $clbBoundValues = explode(',', $tableDef['data']['bound']); foreach ($clbBoundValues as $value) $clbBoundNode->addClbValue($value); break; } break; case 'CENTER' : $centerTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::CENTER, $res["param"]["info"]["yTitle"]); $centerTable->setUnits($res["param"]["info"]["units"]); $centerTable->setSize($tableDef['data']['width']); switch ($tableDef['tableDefType']) { case 'SELECT' : $centerTable->setCenterName($tableDef['data']['center']); $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['center']); break; case 'MANUAL' : $centerTable->setCenterName('center'); $clbCenterNode = $newParamNode->addClbManual('center'); $clbCenterValues = explode(',', $tableDef['data']['center']); foreach ($clbCenterValues as $value) $clbCenterNode->addClbValue($value); break; } break; case 'CENTERWIDTH' : $centerWidthTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::CENTERWIDTH, $res["param"]["info"]["yTitle"]); $centerWidthTable->setUnits($res["param"]["info"]["units"]); switch ($tableDef['tableDefType']) { case 'SELECT' : $centerWidthTable->setCenterName($tableDef['data']['center']); $centerWidthTable->setWidthName($tableDef['data']['width']); $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['center']); $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['width']); break; case 'MANUAL' : $centerWidthTable->setCenterName('center'); $centerWidthTable->setWidthName('width'); $clbCenterNode = $newParamNode->addClbManual('center'); $clbWidthNode = $newParamNode->addClbManual('width'); $clbCenterValues = explode(',', $tableDef['data']['center']); foreach ($clbCenterValues as $value) $clbCenterNode->addClbValue($value); $clbWidthValues = explode(',', $tableDef['data']['width']); foreach ($clbWidthValues as $value) $clbWidthNode->addClbValue($value); break; } break; } } return array("id" => $res["param"]["id"], "plotType" => $res["param"]["info"]["plotType"]); } }