Blame view

src/Request/ParamInfoRequestClass.php 4.02 KB
966bd5f8   Benjamin Renard   Add request to ge...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php 
/**
 * @class ParamInfoRequestClass
 * @brief Implementation of a ParamInfoRequestClass for a param info request
 * @details
 */
class ParamInfoRequestClass extends RequestAbstractClass
{
	/*
	 * @brief Init a param info request
	*/
	public function init()
	{
		if (!isset($this->requestData))
			return false;
		
f28f7c0e   Benjamin Renard   Add param info re...
17
18
19
20
21
		if ($this->requestData->getType() == ParamInfoTypeEnumClass::PLOTINIT) {
			//Force load of node files to init the NodeFactory
			foreach (glob(dirname(__FILE__)."/ParamsRequestImpl/Nodes/Requests/*NodeClass.php") as $filename) {
				require_once $filename;
			}
966bd5f8   Benjamin Renard   Add request to ge...
22
23
24
25
26
27
28
29
30
31
32
33
34
		}
		
		return TRUE;
	}
	
	/*
	 * @brief Run a param info request
	 */
	public function run()
	{
		$dom = new DOMDocument("1.0","UTF-8");
		$dom->preserveWhiteSpace = false;
		$dom->formatOutput = true;
966bd5f8   Benjamin Renard   Add request to ge...
35
		
f28f7c0e   Benjamin Renard   Add param info re...
36
37
		$res = $dom->load($this->requestData->getFilePath());
			
966bd5f8   Benjamin Renard   Add request to ge...
38
		$this->requestData->setSuccess(false);
f28f7c0e   Benjamin Renard   Add param info re...
39
			
966bd5f8   Benjamin Renard   Add request to ge...
40
		if (!$res) {
f28f7c0e   Benjamin Renard   Add param info re...
41
			$this->requestData->setLastErrorMessage("Cannot load file");
966bd5f8   Benjamin Renard   Add request to ge...
42
43
44
			return false;
		}
		
f28f7c0e   Benjamin Renard   Add param info re...
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
		switch ($this->requestData->getType()) {
			case ParamInfoTypeEnumClass::PLOTINIT :
				$this->runFromParamFile($dom);
				break;
			case ParamInfoTypeEnumClass::PARAMINFO :
				$this->runFromParamInfoFile($dom);
				break;
			default :
				$this->requestData->setLastErrorMessage("Unknown ParamInfo type");
		}
		
		return $this->requestData->getSuccess();
	}
	
	private function runFromParamFile($dom) {
966bd5f8   Benjamin Renard   Add request to ge...
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
		$paramNode = new ParamNodeClass();
		
		try {
			$paramNode->loadFromNode($dom->documentElement);
		} catch (Exception $e) {
			$this->requestData->setLastErrorMessage("Error to parse parameter file : Exception detected : ".$e->getMessage());
			return false;
		}
		
		switch ($this->requestData->getType()) {
			case ParamInfoTypeEnumClass::PLOTINIT :
				$outputNode = $paramNode->getOutput();
				if (!isset($outputNode)) {
					$this->requestData->setLastErrorMessage("Cannot parse output node");
					return false;
				}
				$plotNode = $outputNode->getChildInstanceByName("plot");
				if (!isset($plotNode)) {
					$this->requestData->setLastErrorMessage("Cannot parse plot node");
					return false;
				}
f28f7c0e   Benjamin Renard   Add param info re...
81
				$this->requestData->setResult($plotNode);
966bd5f8   Benjamin Renard   Add request to ge...
82
				$this->requestData->setSuccess(true);
f28f7c0e   Benjamin Renard   Add param info re...
83
				return true;
966bd5f8   Benjamin Renard   Add request to ge...
84
85
86
87
			default :
				$this->requestData->setLastErrorMessage("Unknown param info request");
		}
		
f28f7c0e   Benjamin Renard   Add param info re...
88
89
90
91
92
93
94
95
96
97
98
		return false;
	}
	
	private function runFromParamInfoFile($dom) {
		$result = array();
		
		// Dimensions
		$dimsNodes = $dom->getElementsByTagName("dimensions");
		if ($dimsNodes->length > 0) {
			$dimsNode = $dimsNodes->item(0);
			$result['dimensions'] = array(
4b616b6d   Benjamin Renard   Fix table / dim a...
99
100
				'dim1' => $dimsNode->getAttribute("dim_1"),
				'dim2' => $dimsNode->getAttribute("dim_2")
f28f7c0e   Benjamin Renard   Add param info re...
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
			);
		}
		
		// Components
		$compNodes = $dom->getElementsByTagName("components");
		if ($compNodes->length > 0) {
			$compNode = $compNodes->item(0);
			$result['components'] = array();
			foreach ($compNode->getElementsByTagName("component") as $componentNode) {
				$result['components'][] = array(
					'index_1' => $componentNode->getAttribute("index_1"),
					'index_2' => $componentNode->getAttribute("index_2"),
					'name' => $componentNode->getAttribute("name")
				);
			} 
		}
		
		// Tables
		$tablesNodes = $dom->getElementsByTagName("tables");
		if ($tablesNodes->length > 0) {
			$tablesNode = $tablesNodes->item(0);
			$result['tables'] = array();
			foreach ($tablesNode->getElementsByTagName("table") as $tableNode) {
				$tableResult = array(
4b616b6d   Benjamin Renard   Fix table / dim a...
125
						'relatedDim' => ($tableNode->getAttribute("relatedDim") == "dim_1" ? "dim1" : "dim2"),
f28f7c0e   Benjamin Renard   Add param info re...
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
						'name' => $tableNode->getAttribute("name"),
						'units' => $tableNode->getAttribute("units"),
						'channels' => array()
				);
				
				$channelNodes = $tableNode->getElementsByTagName("channel");
				foreach ($channelNodes as $channelNode) {
					$tableResult['channels'][] = array(
						'min' => $channelNode->getAttribute("min"),
						'max' => $channelNode->getAttribute("max")
					);
				}
				
				$result['tables'][] = $tableResult;
			}
		}
		
		$this->requestData->setResult($result);
		$this->requestData->setSuccess(true);
		
		return true;
966bd5f8   Benjamin Renard   Add request to ge...
147
148
149
	}
}
?>