diff options
Diffstat (limited to 'generator/after-bake/src/Controller/EquipementsController.php')
-rw-r--r-- | generator/after-bake/src/Controller/EquipementsController.php | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/generator/after-bake/src/Controller/EquipementsController.php b/generator/after-bake/src/Controller/EquipementsController.php new file mode 100644 index 0000000..ffc6060 --- /dev/null +++ b/generator/after-bake/src/Controller/EquipementsController.php @@ -0,0 +1,138 @@ +<?php +/** + * Copyright 2016 Ludovic Pouzenc <ludovic@pouzenc.fr> + * Copyright 2016 Nicolas Goaziou <mail@nicolasgoaziou.fr> + * + * This file is part of CHD Gestion. + * + * CHD Gestion is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * CHD Gestion is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with CHD Gestion. If not, see <http://www.gnu.org/licenses/>. +**/ +namespace App\Controller; + +use App\Controller\AppController; + +/** + * Equipements Controller + * + * @property \App\Model\Table\EquipementsTable $Equipements + */ +class EquipementsController extends AppController +{ + + public function initialize() + { + parent::initialize(); + if ($this->request->action === 'index') { + $this->loadComponent('Paginator', [ 'limit' => 15, 'order' => [ 'Equipements.id' => 'DESC' ] ]); + $this->loadComponent('Search.Prg'); + } + } + + /** + * Index method + * + * @return void + */ + public function index() + { + $this->paginate = [ + 'contain' => ['Services', 'Ipmgmt', 'EquipementModeles', 'EquipementModes', 'Relais'] + ]; + $query = $this->Equipements + ->find('search', $this->Equipements->filterParams($this->request->query)); + $this->set('equipements', $this->paginate($query)); + $this->set('_serialize', ['equipements']); + + $this->loadModel('EquipementModeles'); + $this->set('equipementModeles', $this->EquipementModeles->find('list')->toArray()); + $this->loadModel('Relais'); + $this->set('relais', $this->Relais->find('list')->toArray()); + } + + /** + * View method + * + * @param string|null $id Equipement id. + * @return \Cake\Network\Response|null + * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + */ + public function view($id = null) + { + $equipement = $this->Equipements->get($id, [ + 'contain' => ['Services', 'Ipmgmt', 'EquipementModeles', 'EquipementModes', 'Relais'] + ]); + + $this->set('equipement', $equipement); + $this->set('_serialize', ['equipement']); + } + + /** + * Add method + * + * @return void Redirects on successful add, renders view otherwise. + */ + public function add() + { + $equipement = $this->Equipements->newEntity(); + if ($this->request->is('post')) { + $equipement = $this->Equipements->patchEntity($equipement, $this->request->data); + if ($this->Equipements->save($equipement)) { + $this->Flash->success(__('The equipement has been saved.')); + return $this->redirect(['action' => 'index']); + } else { + $this->Flash->error(__('The equipement could not be saved. Please, try again.')); + } + } + $equipements = $this->Equipements->Equipements->find('list')->order('mac'); + $services = $this->Equipements->Services->find('list')->order(['service_type_id', 'adherent_id', 'id']); + $ipmgmt = $this->Equipements->Ipmgmt->find('list')->notMatching('Equipements'); + $ipmgmt->order($ipmgmt->newExpr()->add(['INET_ATON(ip4)'])); + $equipementModeles = $this->Equipements->EquipementModeles->find('list'); + $equipementModes = $this->Equipements->EquipementModes->find('list'); + $relais = $this->Equipements->Relais->find('list'); + $this->set(compact('equipement', 'equipements', 'services', 'ipmgmt', 'equipementModeles', 'equipementModes', 'relais')); + $this->set('_serialize', ['equipement']); + } + + /** + * Edit method + * + * @param string|null $id Equipement id. + * @return void Redirects on successful edit, renders view otherwise. + * @throws \Cake\Network\Exception\NotFoundException When record not found. + */ + public function edit($id = null) + { + $equipement = $this->Equipements->get($id, [ + 'contain' => [] + ]); + if ($this->request->is(['patch', 'post', 'put'])) { + $equipement = $this->Equipements->patchEntity($equipement, $this->request->data); + if ($this->Equipements->save($equipement)) { + $this->Flash->success(__('The equipement has been saved.')); + return $this->redirect(['action' => 'index']); + } else { + $this->Flash->error(__('The equipement could not be saved. Please, try again.')); + } + } + $equipements = $this->Equipements->Equipements->find('list'); + $services = $this->Equipements->Services->find('list'); + $ipmgmt = $this->Equipements->Ipmgmt->find('list'); + $equipementModeles = $this->Equipements->EquipementModeles->find('list'); + $equipementModes = $this->Equipements->EquipementModes->find('list'); + $relais = $this->Equipements->Relais->find('list'); + $this->set(compact('equipement', 'equipements', 'services', 'ipmgmt', 'equipementModeles', 'equipementModes', 'relais')); + $this->set('_serialize', ['equipement']); + } +} |