IHMInputOutputCleanProcessClass.php 1.64 KB
<?php

/**
 * @class IHMInputOutputCleanProcessClass
 * @brief Class that's implement an InputOutputInterface used to treat a clean process request
 * @details
 */
class IHMInputOutputCleanProcessClass implements InputOutputInterface
{
	private $jobsManager       = null;
	private $processDatas        = null;

	/*
	 * @brief Constructor
	*/
	function __construct()
	{
		$this->jobsManager      = new IHMJobsManagerClass();
	}

	/*
	 * @brief translate input data from IHM client to AMDA_Integration module for a clean process request
	*/
	public function getInputData($input,$function,$requestId="")
	{
		if (isset($this->processDatas))
			unset($this->processDatas);

		//get list of jobs to clean
		$res = $this->jobsManager->getJobsToClean();

		if (!$res['success'])
			throw new Exception($res['message']);

		if (count($res['jobs']) == 0)
			throw new Exception('No immediate job to clean');
			
		foreach($res['jobs'] as $jobid)
		{
			//create a list of data to treat
			$processData = new ProcessRequestDataClass();
				
			$processData->setManagerFilePath(IHMConfigClass::getProcessManagerFilePath());
			$processData->setType(ProcessTypeEnumClass::DELETE);
			$processData->setId($jobid);
				
			$this->processDatas[] = $processData;
		}

		return $this->processDatas;
	}

	/*
	 * @brief translate output data from AMDA_Integration module to IHM client for a clean process request
	*/
	public function getOutput($data)
	{
		$result = array();

		foreach ($data as $d)
		{
			if (!$d->getSuccess())
				continue;

			$res = $this->jobsManager->deleteJob($d->getId());
		}

		return $result;
	}
}

?>