--- /dev/null
+<?php
+
+class ChannelController extends ApplicationController {
+
+ /** @var PdoChannelVersionManager */
+ private $pdoChannelManager;
+
+ private function getPdoChannelManager(){
+ if (! $this->pdoChannelManager){
+ $this->pdoChannelManager = new PdoChannelVersionManager();
+ }
+ return $this->pdoChannelManager;
+ }
+
+ /**
+ * @api {get} /index.php?action=channel_edit Edite un canal
+ * @apiGroup Channel
+ * @apiVersion 1.0.0
+ * @apiParam {Int} id identifiant du canal_vesion (0 pour créer)
+ * @apiParam {Int} channel_id Identifiant du canal
+ * @apiParam {String} status Status du canal_version (cf action channel_statusList)
+ * @apiParam {Int} version_id Id de la version
+ *
+ * @apiSuccessExample {json} Success-Reponse:
+ * {"retour":"OK","message":"","result":channel_version_id}
+ */
+ public function editAction(){
+ $channel = new ChannelVersion();
+ $channel->id = $this->getIntParameter('id');
+ $channel->channel_id = $this->getParameters()->get('channel_id');
+
+ $status = $this->getParameters()->get('status');
+ $status_list = $channel->getStatus();
+ if (empty($status_list[$status])){
+ throw new Exception("Le statut $status n'existe pas");
+ }
+ $channel->status = $status;
+ $version_id = $this->getParameters()->getInt('version_id');
+
+ $pdoVersionManager = new PdoVersionManager();
+ $version_info = $pdoVersionManager->getInfo($version_id);
+ if (! $version_info){
+ throw new Exception("Cette version_id est inconnu sur le serveur");
+ }
+
+ $channel->version_id = $version_id;
+ return $this->getPdoChannelManager()->edit($channel);
+ }
+
+ /**
+ * @api {get} /index.php?action=channel_statusList Retourne la liste des status
+ * @apiGroup Channel
+ * @apiVersion 1.0.0
+ *
+ * @apiSuccessExample {json} Success-Reponse:
+ * {"retour":"OK","message":"","result":{"maj_ok":"Mise \u00e0 jour possible","maj_ko":"Mise \u00e0 jour interdite"}}
+ */
+ public function statusListAction(){
+ $channel = new ChannelVersion();
+ return $channel->getStatus();
+ }
+
+ /**
+ * @api {get} /index.php?action=channel_list Retourne les canaux possibles
+ * @apiGroup Channel
+ * @apiVersion 1.0.0
+ *
+ * @apiSuccessExample {json} Success-Reponse:
+ * {"retour":"OK","message":"","result":[]}
+ */
+ public function listAction(){
+ $channel = new PdoChannelManager();
+ return $channel->getList();
+ }
+
+ /**
+ * @api {get} /index.php?action=channel_listByVersion Retourne la liste des canaux pour une version données
+ * @apiGroup Channel
+ * @apiVersion 1.0.0
+ * @apiParam {Int} version_id Id de la version
+ *
+ * @apiSuccessExample {json} Success-Reponse:
+ * {"retour":"OK","message":"","result":[{"id":"1","status":"maj_ok","version_id":"1","channel_key":"prod","libelle":"PROD"}]}
+ */
+ public function listByVersionAction(){
+ $version_id = $this->getParameters()->getInt('version_id');
+ return $this->getPdoChannelManager()->listByVersion($version_id);
+ }
+
+ /**
+ * @api {get} /index.php?action=channel_delete Supprime un canal pour une version
+ * @apiGroup Channel
+ * @apiVersion 1.0.0
+ * @apiParam {Int} id identifiant du canal_version
+ *
+ * @apiSuccessExample {json} Success-Reponse:
+ * {"retour":"OK","message":"","result":true}
+ */
+ public function deleteAction(){
+ $id = $this->getParameters()->getInt('id');
+ $this->getPdoChannelManager()->delete($id);
+ return true;
+ }
+
+}
\ No newline at end of file