Blame view

src/InputOutput/IHMImpl/Params/GenInfoParamImpl/IHMInputOutputParamsInfoGeneratorClass.php 2.4 KB
cd28a380   Benjamin Renard   Generate param in...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php

/**
 * @class IHMInputOutputParamsGeneratorClass
 * @brief Implementation of IHMInputOutputParamsAbstractClass to treat params generation request
 * @details
*/
class IHMInputOutputParamsInfoGeneratorClass extends IHMInputOutputParamsAbstractClass
{
	/*
	 * @brief method to unmarshall a params generation request
	*/
	protected function unmarshallRequest($input)
	{
		$this->paramsData->setRequestType(ParamsRequestTypeEnumClass::PARAMSINFOGEN);
		
		$this->paramsData->setParamId($input->paramId);

		$this->paramsData->setBatchEnable(FALSE);

		$this->paramManager->addGeneratedParam($input->paramId, $input->buildchain, $input->timestep, $this->paramsData);

		return $this->paramsData;
	}

	/*
	 * @brief method to marshall the result of a download request
	*/
	protected function marshallResult($data)
	{
		if (!$data->getSuccess())
			return array(
					'success' => false,
					'message' => $data->getParamId() . " : " . $data->getLastErrorMessage());
		
		if ($data->getErrorCode() != 0)
			return array(
					'success' => false,
					'message' => $data->getParamId() . " : " . 'Error detected during parameter compilation');
		
		$info_file_name = 'info_'.$data->getParamId().'.xml';
		$info_file_path = $this->getWorkingPath().'/'.$info_file_name;

		$doc = new DOMDocument("1.0", "UTF-8");
                if ($doc->load($info_file_path) === FALSE) {
			return array(
                                        'success' => false,
                                        'message' => $data->getParamId() . " : " . 'Cannot load info file');
		}

		//<paraminfo id="ws_vcxvxcvdsdd"><dimensions dim_1="3" dim_2="1"/><components><component index_1="0" name="ws_vcxvxcvdsdd[0]"/><component index_1="1" name="ws_vcxvxcvdsdd[1]"/><component index_1="2" name="ws_vcxvxcvdsdd[2]"/></components><tables/></paraminfo>
		$dimensionsNodes = $doc->getElementsByTagName('dimensions');
		if ($dimensionsNodes->length == 0) {
			return array(
                                        'success' => false,
                                        'message' => $data->getParamId() . " : " . 'Cannot load dimensions in info file');
		}
		
		$dim_1 = $dimensionsNodes->item(0)->getAttribute('dim_1');
		$dim_2 = $dimensionsNodes->item(0)->getAttribute('dim_2');

		return array(
			'success' => true,
			'dimensions' => array(
				'dim_1' => $dim_1,
				'dim_2' => $dim_2,
			),
		);
	}
}
?>