false, "message" => "Bad derived parameter name"); //extract real parameter name $realName = substr($paramName , 3); //try to load user parameters definition if not already done if (!isset($this->userParamsList)) $this->userParamsList = $this->loadUserParamManagerFile(); if (!$this->userParamsList["success"]) return $this->userParamsList["success"]; if (isset($this->userParamsList["params"]) && isset($this->userParamsList["params"]["derived"])) { //find the parameter info foreach($this->userParamsList["params"]["derived"] as $paramInfo) { if ($paramInfo["name"] == $realName) return array("success" => true, "param" => $paramInfo); } } return array("success" => false, "message" => "Cannot find derived parameter"); } /* * @brief Get derived parameter name from id */ public function getDerivedParameterNameFromId($paramId) { if (!preg_match("#^ws_#",$paramId)) return array("success" => false, "message" => "Bad derived parameter id"); //try to load user parameters definition if not already done if (!isset($this->userParamsList)) $this->userParamsList = $this->loadUserParamManagerFile(); if (!$this->userParamsList["success"]) return $this->userParamsList["success"]; if (isset($this->userParamsList["params"]) && isset($this->userParamsList["params"]["derived"])) { //find the parameter name foreach($this->userParamsList["params"]["derived"] as $paramInfo) { if ($paramInfo["id"] == $paramId) return array("success" => true, "name" => $paramInfo["name"]); } } return array("success" => false, "message" => "Cannot find derived parameter"); } /* * @brief Get uploaded parameter info from name ("wsd_***") */ public function getUploadedParameterFromName($paramName) { if (!preg_match("#^wsd_#",$paramName)) return array("success" => false, "message" => "Bad uploaded parameter name"); //extract real parameter name $realName = substr($paramName , 4); //try to load user parameters definition if not already done if (!isset($this->userParamsList)) $this->userParamsList = $this->loadUserParamManagerFile(); if (!$this->userParamsList["success"]) return $this->userParamsList["success"]; if (isset($this->userParamsList["params"]) && isset($this->userParamsList["params"]["uploaded"])) { //find the parameter info foreach($this->userParamsList["params"]["uploaded"] as $paramInfo) { if ($paramInfo["name"] == $realName) return array("success" => true, "param" => $paramInfo); } } return array("success" => false, "message" => "Cannot find uploaded parameter"); } /* * @brief Get uploaded parameter name from id */ public function getUploadedParameterNameFromId($paramId) { if (!preg_match("#^wsd_#",$paramId)) return array("success" => false, "message" => "Bad uploaded parameter id"); //try to load user parameters definition if not already done if (!isset($this->userParamsList)) $this->userParamsList = $this->loadUserParamManagerFile(); if (!$this->userParamsList["success"]) return $this->userParamsList["success"]; if (isset($this->userParamsList["params"]) && isset($this->userParamsList["params"]["uploaded"])) { //find the parameter info foreach($this->userParamsList["params"]["uploaded"] as $paramInfo) { if ($paramInfo["id"] == $paramId) return array("success" => true, "name" => $paramInfo["name"]); } } return array("success" => false, "message" => "Cannot find uploaded parameter"); } /* * @brief Load derived parameter manager file */ private function loadUserParamManagerFile() { //load xml file $dom = new DomDocument("1.0"); if (!$dom->load(IHMConfigClass::getUserParamManagerFilePath())) return array("success" => false, "message" => "Cannot load user parameter manager file"); $userParams = array(); //get derived parameter node $derivedNodes = $dom->getElementsByTagName(self::$mgrDerivedNode); $derivedParams = array(); if ($derivedNodes->length > 0) { $derivedParamNodes = $derivedNodes->item(0)->getElementsByTagName(self::$mgrDerivedParamNode); foreach ($derivedParamNodes as $derivedParamNode) { //id $paramId = $derivedParamNode->getAttribute(self::$mgrDerivedParamIdAtt); //modification date $dateModif = filemtime(IHMConfigClass::getUserDerivedParamFilePath($paramId)); //name $paramName = $derivedParamNode->getAttribute(self::$mgrDerivedParamNameAtt); //expression $paramExpression = $derivedParamNode->getAttribute(self::$mgrDerivedParamExpressionAtt); //timestep $paramTimeStep = $derivedParamNode->getAttribute(self::$mgrDerivedParamTimeStepAtt); array_push($derivedParams,array( "id" => $paramId, "name" => $paramName, "expression" => $paramExpression, "timestep" => $paramTimeStep, "info" => $this->loadDerivedParameterInfo($paramId), "dateModif" => $dateModif )); } } $userParams["derived"] = $derivedParams; //get uploaded parameter node $uploadedNodes = $dom->getElementsByTagName(self::$mgrUploadedNode); $uploadedParams = array(); if ($uploadedNodes->length > 0) { $uploadedParamNodes = $uploadedNodes->item(0)->getElementsByTagName(self::$mgrUploadedParamNode); foreach ($uploadedParamNodes as $uploadedParamNode) { //id $paramId = $uploadedParamNode->getAttribute(self::$mgrUploadedParamIdAtt); //modification date $dateModif = filemtime(IHMConfigClass::getUserUploadedParamFilePath($paramId)); //name $paramName = $uploadedParamNode->getAttribute(self::$mgrUploadedParamNameAtt); array_push($uploadedParams,array( "id" => $paramId, "name" => $paramName, "info" => $this->loadUploadedParameterInfo($paramId), "dateModif" => $dateModif )); } } $userParams["uploaded"] = $uploadedParams; return array("success" => true, "params" => $userParams); } /* * @brief Load additionnal derived parameter info from paramId */ private function loadDerivedParameterInfo($paramId) { //get full path $path = IHMConfigClass::getUserDerivedParamFilePath($paramId); $result = array( "units" => "", "yTitle" => "", "description" => "" ); if (!file_exists($path)) return $result; //load xml file $dom = new DomDocument("1.0"); if (!$dom->load($path)) return $result; //get parameter units $unitsNodes = $dom->getElementsByTagName(self::$infoDerivedUnitsNode); if ($unitsNodes->length > 0) { $result["units"] = $unitsNodes->item(0)->nodeValue; if ($result["units"] == self::$infoDerivedUndefined) { $result["units"] = ""; } } //get parameter y title $yTitleNodes = $dom->getElementsByTagName(self::$infoDerivedYTitleNode); if ($yTitleNodes->length > 0) { $result["yTitle"] = $yTitleNodes->item(0)->nodeValue; if ($result["yTitle"] == self::$infoDerivedUndefined) { $result["yTitle"] = ""; } } //get parameter description $descNodes = $dom->getElementsByTagName(self::$infoDerivedDescriptionNode); if ($descNodes->length > 0) $result["description"] = $descNodes->item(0)->nodeValue; return $result; } /* * @brief Load additionnal uploaded parameter info from paramId */ private function loadUploadedParameterInfo($paramId) { //get full path $path = IHMConfigClass::getUserUploadedParamFilePath($paramId); $result = array(); if (!file_exists($path)) return $result; //load xml file $dom = new DomDocument("1.0"); if (!$dom->load($path)) return $result; //get parameter min sampling $minSamplingNodes = $dom->getElementsByTagName(self::$infoUploadedMinSamplingNode); if ($minSamplingNodes->length > 0) $result["minSampling"] = $minSamplingNodes->item(0)->nodeValue; //get parameter max sampling $maxSamplingNodes = $dom->getElementsByTagName(self::$infoUploadedMaxSamplingNode); if ($maxSamplingNodes->length > 0) $result["maxSampling"] = $maxSamplingNodes->item(0)->nodeValue; else $result["maxSampling"] = $result["minSampling"]; //get parameter real var $realVarNodes = $dom->getElementsByTagName(self::$infoUploadedRealVarNode); if ($realVarNodes->length > 0) $result["realVar"] = $realVarNodes->item(0)->nodeValue; //get parameter type $typeNodes = $dom->getElementsByTagName(self::$infoUploadedTypeNode); if ($typeNodes->length > 0) $result["type"] = $typeNodes->item(0)->nodeValue; //get parameter size $sizeNodes = $dom->getElementsByTagName(self::$infoUploadedSizeNode); if ($sizeNodes->length > 0) $result["size"] = $sizeNodes->item(0)->nodeValue; //get parameter VirtualInstrument ID $viIdNodes = $dom->getElementsByTagName(self::$infoUploadedVIIdNode); if ($viIdNodes->length > 0) $result["viId"] = $viIdNodes->item(0)->nodeValue; //get parameter plot type $plotTypeNodes = $dom->getElementsByTagName(self::$infoUploadedPlotTypeNode); if ($plotTypeNodes->length > 0) $result["plotType"] = $plotTypeNodes->item(0)->nodeValue; //get parameter y units $unitsNodes = $dom->getElementsByTagName(self::$infoUploadedUnitsNode); if ($unitsNodes->length > 0) $result["units"] = $unitsNodes->item(0)->nodeValue; //get parameter y title $yTitleNodes = $dom->getElementsByTagName(self::$infoUploadedYTitleNode); if ($yTitleNodes->length > 0) $result["yTitle"] = $yTitleNodes->item(0)->nodeValue; //get table definition $tableDefNodes = $dom->getElementsByTagName(self::$infoUploadedTableDefNode); if ($tableDefNodes->length > 0) { $tableDefNode = $tableDefNodes->item(0); $tableDefType = $tableDefNode->getAttribute('tableDefType'); $channelsDefType = $tableDefNode->getAttribute('channelsDefType'); $tableData = array(); foreach ($tableDefNode->childNodes as $tableDataNode) { if ($tableDataNode->nodeType != XML_ELEMENT_NODE) continue; $tableData[$tableDataNode->tagName] = $tableDataNode->nodeValue; } $result["tableDef"] = array('tableDefType' => $tableDefType, 'channelsDefType' => $channelsDefType, 'data' => $tableData); } return $result; } }