diff --git a/webui/module/Api/src/Api/Controller/MediaController.php b/webui/module/Api/src/Api/Controller/MediaController.php new file mode 100644 index 00000000000..3f5f40ee25b --- /dev/null +++ b/webui/module/Api/src/Api/Controller/MediaController.php @@ -0,0 +1,112 @@ +. + * + */ + +namespace Api\Controller; + +use Zend\Mvc\Controller\AbstractRestfulController; +use Zend\View\Model\JsonModel; +use Exception; + +class MediaController extends AbstractRestfulController +{ + protected $bsock = null; + protected $mediaModel = null; + protected $poolModel = null; + protected $jobModel =null; + protected $result = null; + + public function getList() + { + $this->RequestURIPlugin()->setRequestURI(); + + if (!$this->SessionTimeoutPlugin()->isValid()) { + return $this->redirect()->toRoute( + 'auth', + array( + 'action' => 'login' + ), + array( + 'query' => array( + 'req' => $this->RequestURIPlugin()->getRequestURI(), + 'dird' => $_SESSION['bareos']['director'] + ) + ) + ); + } + + $this->bsock = $this->getServiceLocator()->get('director'); + $pool = $this->params()->fromQuery('pool'); + $volume = $this->params()->fromQuery('volume'); + $filter = $this->params()->fromQuery('filter'); + $jobid = $this->params()->fromQuery('jobid'); + + try{ + if ($filter === "jobs" && isset($volume)) { + $this->result = $this->getMediaModel()->getVolumeJobs($this->bsock, $volume); + } elseif($filter === "jobid" && isset($jobid)) { + $this->result = $this->getJobModel()->getJobMedia($this->bsock, $jobid); + } elseif (isset($pool)) { + $this->result = $this->getPoolModel()->getPoolMedia($this->bsock, $pool); + } elseif (isset($volume)) { + // workaround until llist volume returns array instead of object + $this->result[0] = $this->getMediaModel()->getVolume($this->bsock, $volume); + } else { + $this->result = $this->getMediaModel()->getVolumes($this->bsock); + } + } catch(Exception $e) { + $this->getResponse()->setStatusCode(500); + error_log($e); + } + + return new JsonModel($this->result); + } + + public function getMediaModel() + { + if (!$this->mediaModel) { + $sm = $this->getServiceLocator(); + $this->mediaModel = $sm->get('Media\Model\MediaModel'); + } + return $this->mediaModel; + } + + public function getPoolModel() + { + if (!$this->poolModel) { + $sm = $this->getServiceLocator(); + $this->poolModel = $sm->get('Pool\Model\PoolModel'); + } + return $this->poolModel; + } + + public function getJobModel() + { + if (!$this->jobModel) { + $sm = $this->getServiceLocator(); + $this->jobModel = $sm->get('Job\Model\JobModel'); + } + return $this->jobModel; + } +}