--- /dev/null
+<?php
+
+class VersionsController extends ApplicationController {
+
+ /** @var PdoVersionManager */
+ private $pdoVersionManager;
+
+ private function getPdoVersionManager(){
+ if (! $this->pdoVersionManager){
+ $this->pdoVersionManager= new PdoVersionManager();
+ }
+ return $this->pdoVersionManager;
+ }
+
+ /**
+ * @api {get} /index.php?action=versions_nb Récupération du nombre de versions pour un produit
+ * @apiName Nombre de version
+ * @apiGroup Versions
+ * @apiVersion 1.0.0
+ *
+ * @apiParam {Number} product_id identifiant du produit
+ *
+ * @apiSuccessExample {json} Success-Reponse:
+ * {"retour":"OK","message":"","result":"42"}
+ */
+ public function nbAction(){
+ $product_id = $this->getIntParameter('product_id',0);
+ return $this->getPdoVersionManager()->getNbVersionFromProductId($product_id);
+ }
+
+ /**
+ * @api {get} /index.php?action=versions_list Récupération des versions d'un produit
+ * @apiName Nombre de version
+ * @apiGroup Versions
+ * @apiVersion 1.0.0
+ *
+ * @apiParam {Number} product_id identifiant du produit
+ * @apiParam {Number} limit Nombre d'élements à récupérer
+ * @apiParam {Number} offset Numéro du premier élement à récupérer
+ *
+ * @apiSuccessExample {json} Success-Reponse:
+ * {"retour":"OK","message":"","result":"42"}
+ */
+ public function listAction(){
+ $product_id = $this->getIntParameter('product_id',0);
+ $offset = $this->getOffsetParameter();
+ $limit = $this->getLimitParameter();
+ return $this->getPdoVersionManager()->getVersionFromProductId($product_id, $offset, $limit);
+ }
+
+ /**
+ * @api {get} /index.php?action=versions_natureList Récupération des natures possible
+ * @apiName Nature de version possible (patch, mise à jour mineur, mise à jour majeur)
+ * @apiGroup Versions
+ * @apiVersion 1.0.0
+ *
+ * @apiSuccessExample {json} Success-Reponse:
+ * {"retour":"OK","message":"","result":{"patch":"Patch","majmin":"Mise \u00e0 jour mineure","majmaj":"Mise \u00e0 jour majeure"}}
+ */
+ public function listNatureAction(){
+ return Version::getNatureList();
+ }
+
+ /**
+ * @api {get} /index.php?action=versions_edit Création ou mise à jour d'une version
+ * @apiName Edition d'une version
+ * @apiGroup Versions
+ * @apiVersion 1.0.0
+ *
+ * @apiParam {Number} id identifiant de la version (0 ou vide pour créer)
+ * @apiParam {Number} product_id identifiant du produit
+ * @apiParam {String} nature Nature de la version (v. versions_natureList)
+ * @apiParam {String} value Valeur de la version (ex: 1.4.4)
+ *
+ * @apiSuccessExample {json} Success-Reponse:
+ * {"retour":"OK","message":"","result":"42"}
+ */
+ public function editAction(){
+ $version = new Version();
+ $version->id= $this->getIntParameter('id',0);
+ $version->nature = $this->getParameters()->get('nature');
+ $version->product = $this->getIntParameter('product_id',0);
+ $version->value = $this->getParameters()->get('value');
+ $version_id = $this->getPdoVersionManager()->edit($version);
+ return $version_id;
+ }
+
+ /**
+ * @api {get} /index.php?action=versions_delete Suppression d'une version
+ * @apiGroup Versions
+ * @apiVersion 1.0.0
+ *
+ * @apiParam {Number} id identifiant de la version
+ *
+ * @apiSuccessExample {json} Success-Reponse:
+ * {"retour":"OK","message":"","result":true}
+ */
+ public function deleteAction(){
+ $version_id = $this->getIntParameter('id',0);
+ $this->getPdoVersionManager()->delete($version_id);
+ return true;
+ }
+
+
+ /**
+ * @api {get} /index.php?action=versions_info Information sur une version
+ * @apiGroup Versions
+ * @apiVersion 1.0.0
+ *
+ * @apiParam {Number} id identifiant de la version
+ *
+ * @apiSuccessExample {json} Success-Reponse:
+ * {"retour":"OK","message":"","result":[]}
+ */
+ public function infoAction(){
+ $version_id = $this->getIntParameter('id',0);
+ $info = $this->getPdoVersionManager()->getInfo($version_id);
+ return $info;
+ }
+
+
+}