--- /dev/null
+<?php
+ class ManagersController extends AppController {
+ public $helpers = array('Html', 'Form');
+ public $components = array('RequestHandler');
+
+ public function index() {
+ $managers = $this->Manager->find('all');
+ $this->set(array(
+ 'managers' => $managers,
+ '_serialize' => array('managers')
+ ));
+ }
+
+ public function view($id = null) {
+ if (!$id) {
+ throw new NotFoundException(__('Mauvais exploitant'));
+ }
+
+ $manager = $this->Manager->findById($id);
+ if (!$manager) {
+ throw new NotFoundException(__('Mauvais exploitant'));
+ }
+ $this->set('manager', $manager);
+ }
+
+ public function add() {
+ if ($this->request->is('manager')) {
+ $this->Manager->create();
+ if ($this->Manager->save($this->request->data)) {
+ $this->Session->setFlash(__("L'exploitant a été enregistré."));
+ $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'));
+ }
+
+ $manager = $this->Manager->findById($id);
+ if (!$manager) {
+ throw new NotFoundException(__('Exploitant introuvable'));
+ }
+ $this->set('manager', $manager);
+
+ // GETTING ALL APPLIANCES OF THIS MANAGER
+ $appliances_id = explode('|', $this->Manager->value('appliances'));
+ App::import('Controller', 'Appliances');
+ $appliancesController = new AppliancesController;
+ $appliances = array();
+ foreach ($appliances_id as $appliance_id) {
+ $appliances[] = $appliancesController->Appliance->findById($appliance_id);
+ }
+ $this->set('appliances', $appliances);
+
+ if ($this->request->is(array('manager', 'put'))) {
+ $this->Manager->id = $id;
+ if ($this->Manager->save($this->request->data)) {
+ $this->Session->setFlash(__("L'exploitant a été mis à jour."));
+ $this->redirect(array('action' => 'index'));
+ }
+ $this->Session->setFlash(__("Mise à jour de l'exploitant impossible."));
+ }
+
+ if (!$this->request->data) {
+ $this->request->data = $manager;
+ }
+ }
+
+ public function delete($id) {
+ if ($this->request->is('get')) {
+ throw new MethodNotAllowedException();
+ }
+
+ if ($this->Manager->delete($id)) {
+ $this->Session->setFlash(
+ __("L'exploitant d'id: %s a été supprimé.", h($id))
+ );
+ $this->redirect(array('action' => 'index'));
+ }
+ }
+ }
+?>