--- /dev/null
+<?php
+ class ExploitantsController extends AppController {
+ public $helpers = array('Html', 'Form');
+ public $components = array('RequestHandler');
+
+ public function index() {
+ //$this->set('exploitants', $this->Exploitant->find('all'));
+ $exploitants = $this->Exploitant->find('all');
+ $this->set(array(
+ 'exploitants' => $exploitants,
+ '_serialize' => array('exploitants')
+ ));
+ }
+
+ public function view($id = null) {
+ if (!$id) {
+ throw new NotFoundException(__('Mauvais exploitant'));
+ }
+
+ $exploitant = $this->Exploitant->findById($id);
+ if (!$exploitant) {
+ throw new NotFoundException(__('Mauvais exploitant'));
+ }
+ $this->set('exploitant', $exploitant);
+ }
+
+ public function add() {
+ if ($this->request->is('exploitant')) {
+ $this->Exploitant->create();
+ if ($this->Exploitant->save($this->request->data)) {
+ $this->Session->setFlash(__("L'exploitant a été enregistré."));
+ return $this->redirect(array('action' => 'index'));
+ }
+ $this->Session->setFlash(__("Enregistrement de l'exploitant impossible."));
+ }
+ }
+
+ public function edit($id = null) {
+ if (!$id) {
+ throw new NotFoundException(__('Exploitant introuvable'));
+ }
+
+ $exploitant = $this->Exploitant->findById($id);
+ if (!$exploitant) {
+ throw new NotFoundException(__('Exploitant introuvable'));
+ }
+ $this->set('exploitant', $exploitant);
+
+ $produits_id = explode("|", $this->Exploitant->produits);
+ $produits = [];
+
+ /*
+ foreach ($produits_id as $produit_id) {
+ $produits += $this->Produit->findById($produit_id);
+ }
+ */
+ $this->set('produits', $produits);
+
+ if ($this->request->is(array('exploitant', 'put'))) {
+ $this->Exploitant->id = $id;
+ if ($this->Exploitant->save($this->request->data)) {
+ $this->Session->setFlash(__("L'exploitant a été mis à jour."));
+ return $this->redirect(array('action' => 'index'));
+ }
+ $this->Session->setFlash(__("Mise à jour de l'exploitant impossible."));
+ }
+
+ if (!$this->request->data) {
+ $this->request->data = $exploitant;
+ }
+ }
+
+ public function delete($id) {
+ if ($this->request->is('get')) {
+ throw new MethodNotAllowedException();
+ }
+
+ if ($this->Exploitant->delete($id)) {
+ $this->Session->setFlash(
+ __("L'exploitant d'id: %s a été supprimé.", h($id))
+ );
+ return $this->redirect(array('action' => 'index'));
+ }
+ }
+ }
+?>