--- /dev/null
+<?php
+
+class ProductsController extends ApplicationController {
+
+ private $pdoProductsManager;
+
+ private function getPdoProductsManager(){
+ if (! $this->pdoProductsManager) {
+ $this->pdoProductsManager = new PdoProductManager();
+ }
+ return $this->pdoProductsManager;
+ }
+
+ /**
+ * @api {get} /index.php?action=products_nb Nombre de produits
+ * @apiGroup Products
+ * @apiVersion 1.0.0
+ *
+ * @apiSuccessExample {json} Success-Reponse:
+ * {"retour":"OK","message":"","result":"19"}
+ */
+ public function nbAction(){
+ return $this->getPdoProductsManager()->getNbProducts();
+ }
+
+ /**
+ * @api {get} /index.php?action=products_list Liste des produits
+ * @apiGroup Products
+ * @apiVersion 1.0.0
+ * @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":[]}
+ */
+ public function listAction(){
+ $offset = $this->getOffsetParameter();
+ $limit = $this->getLimitParameter();
+ return $this->getPdoProductsManager()->getProducts($offset,$limit);
+ }
+
+
+ /**
+ * @api {get} /index.php?action=products_edit Edite un produit
+ * @apiGroup Products
+ * @apiVersion 1.0.0
+ * @apiParam {Int} id identifiant du produit (0 pour créer)
+ * @apiParam {String} name le nom du produit
+ * @apiParam {String} diminutif Le code produit sur 2 lettres
+ * @apiParam {String} icon_url L'url de l'icone du produit
+ *
+ * @apiSuccessExample {json} Success-Reponse:
+ * {"retour":"OK","message":"","result":true}
+ */
+ public function editAction(){
+ $product = new Product();
+ $product->id = $this->getParameters()->getInt('id');
+ $product->name = $this->getParameters()->get('name');
+ $product->diminutif = $this->getParameters()->get('diminutif');
+ $product->icon_url = $this->getParameters()->get('icon_url');
+ return $this->getPdoProductsManager()->editProduct($product);
+ }
+
+ /**
+ * @api {get} /index.php?action=products_info Récupère les détails d'un produit
+ * @apiGroup Products
+ * @apiVersion 1.0.0
+ * @apiParam {Int} id identifiant du produit
+ */
+ public function infoAction(){
+ $id = $this->getParameters()->getInt('id');
+ return $this->getPdoProductsManager()->getProduct($id);
+ }
+
+ public function deleteAction(){
+ $id = $this->getParameters()->getInt('id');
+ $this->getPdoProductsManager()->delete($id);
+ return true;
+ }
+
+ /**
+ * @api {get} /index.php?action=products_existsByName Vérifie l'existence d'un produit
+ * @apiGroup Products
+ * @apiVersion 1.0.0
+ * @apiParam {String} name le nom du produit
+ * @apiSuccessExample {json} Success-Reponse:
+ * {"retour":"OK","message":"","result":true}
+ */
+ public function existsByNameAction(){
+ $name = $this->getParameters()->get('name');
+ return $this->getPdoProductsManager()->existsByName($name);
+ }
+}
\ No newline at end of file