IHMInputOutputParamsInfoGeneratorClass.php 2.4 KB
<?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,
			),
		);
	}
}
?>