diff options
Diffstat (limited to 'generator/after-bake/src/Controller')
8 files changed, 1047 insertions, 0 deletions
diff --git a/generator/after-bake/src/Controller/AdherentRolesController.php b/generator/after-bake/src/Controller/AdherentRolesController.php new file mode 100644 index 0000000..2dae728 --- /dev/null +++ b/generator/after-bake/src/Controller/AdherentRolesController.php @@ -0,0 +1,89 @@ +<?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; + +/** + * AdherentRoles Controller + * + * @property \App\Model\Table\AdherentRolesTable $AdherentRoles + */ +class AdherentRolesController extends AppController +{ + + /** + * Index method + * + * @return void + */ + public function index() + { + $this->paginate = [ + 'contain' => ['Adherents', 'AdherentRoleTypes', 'Villes'] + ]; + $this->set('adherentRoles', $this->paginate($this->AdherentRoles)); + } + + /** + * Add method + * + * @return void Redirects on successful add, renders view otherwise. + */ + public function add() + { + $adherentRole = $this->AdherentRoles->newEntity(); + if ($this->request->is('post')) { + $adherentRole = $this->AdherentRoles->patchEntity($adherentRole, $this->request->data); + if ($this->AdherentRoles->save($adherentRole)) { + $this->Flash->success(__('The adherent role has been saved.')); + return $this->redirect(['action' => 'index']); + } else { + $this->Flash->error(__('The adherent role could not be saved. Please, try again.')); + } + } + $defaultAdherent = is_numeric($this->request->query('a'))?$this->request->query('a'):NULL; + $adherents = $this->AdherentRoles->Adherents->find('list'); + $adherentRoleTypes = $this->AdherentRoles->AdherentRoleTypes->find('list'); + $villes = $this->AdherentRoles->Villes->find('list'); + $this->set(compact('adherentRole', 'adherents', 'defaultAdherent', 'adherentRoleTypes', 'villes')); + $this->set('_serialize', ['adherentRole']); + } + + /** + * Delete method + * + * @param string|null $id Adherent Role id. + * @return \Cake\Network\Response|null Redirects to index. + * @throws \Cake\Network\Exception\NotFoundException When record not found. + */ + public function delete($id = null) + { + $this->request->allowMethod(['post', 'delete']); + $adherentRole = $this->AdherentRoles->get($id); + if ($this->AdherentRoles->delete($adherentRole)) { + $this->Flash->success(__('The adherent role has been deleted.')); + } else { + $this->Flash->error(__('The adherent role could not be deleted. Please, try again.')); + } + return $this->redirect(['action' => 'index']); + } +} diff --git a/generator/after-bake/src/Controller/AdherentsController.php b/generator/after-bake/src/Controller/AdherentsController.php new file mode 100644 index 0000000..abec8a0 --- /dev/null +++ b/generator/after-bake/src/Controller/AdherentsController.php @@ -0,0 +1,149 @@ +<?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; +use Cake\Datasource\ConnectionManager; + +/** + * Adherents Controller + * + * @property \App\Model\Table\AdherentsTable $Adherents + */ +class AdherentsController extends AppController +{ + + + public function initialize() + { + parent::initialize(); + if ($this->request->action === 'index') { + $this->loadComponent('Paginator', [ 'limit' => 15, 'order' => [ 'Adherents.id' => 'DESC' ] ]); + $this->loadComponent('Search.Prg'); + } + } + + /** + * Index method + * + * @return void + */ + public function index() + { + $this->paginate = [ + 'contain' => ['AdherentTypes', 'Villes', 'AdherentStatuts', 'Civilites'] + ]; + $query = $this->Adherents + ->find('search', $this->Adherents->filterParams($this->request->query)); + $this->set('adherents', $this->paginate($query)); + $this->set('_serialize', ['adherents']); + + $this->loadModel('Villes'); + $this->set('villes', $this->Villes->find('list')->toArray()); + + //TODO : quick'n'dirty, à améliorer + $conn = ConnectionManager::get('default'); + //$rawq = 'SELECT CASE WHEN COUNT(*)=0 THEN 0 ELSE ROUND(SUM(adherent_statut_id-1) * 100 / (4*COUNT(*))) END FROM adherents WHERE adherent_statut_id <> 1'; + $rawq=' +SELECT + ROUND( COUNT(*) * 100 / + ( + SELECT CASE WHEN COUNT(*)=0 THEN 1 ELSE COUNT(*) END + FROM adherents WHERE adherent_statut_id NOT IN (1,8) + ) + ) +FROM adherents WHERE adherent_statut_id = 5; +'; + $stmt = $conn->execute($rawq); + $score = current($stmt->fetch()); + $this->set('score', $score); + } + + /** + * View method + * + * @param string|null $id Adherent id. + * @return void + * @throws \Cake\Network\Exception\NotFoundException When record not found. + */ + public function view($id = null) + { + $adherent = $this->Adherents->get($id, [ + 'contain' => ['AdherentRoles' => ['AdherentRoleTypes', 'Villes'], 'AdherentTypes', 'Villes', 'AdherentStatuts', 'Civilites', 'Services' => ['ServiceTypes', 'ServiceStatuts'] ] + ]); + $this->set('adherent', $adherent); + $this->set('_serialize', ['adherent']); + } + + /** + * Add method + * + * @return void Redirects on successful add, renders view otherwise. + */ + public function add() + { + $adherent = $this->Adherents->newEntity(); + if ($this->request->is('post')) { + $adherent = $this->Adherents->patchEntity($adherent, $this->request->data); + if ($this->Adherents->save($adherent)) { + $this->Flash->success(__('The adherent has been saved.')); + return $this->redirect(['action' => 'index']); + } else { + $this->Flash->error(__('The adherent could not be saved. Please, try again.')); + } + } + $adherentTypes = $this->Adherents->AdherentTypes->find('list'); + $villes = $this->Adherents->Villes->find('list'); + $adherentStatuts = $this->Adherents->AdherentStatuts->find('list'); + $civilites = $this->Adherents->Civilites->find('list'); + $this->set(compact('adherent', 'adherentTypes', 'villes', 'adherentStatuts', 'civilites')); + $this->set('_serialize', ['adherent']); + } + + /** + * Edit method + * + * @param string|null $id Adherent id. + * @return void Redirects on successful edit, renders view otherwise. + * @throws \Cake\Network\Exception\NotFoundException When record not found. + */ + public function edit($id = null) + { + $adherent = $this->Adherents->get($id, [ + 'contain' => ['Services' => ['ServiceTypes', 'ServiceStatuts'] ] + ]); + if ($this->request->is(['patch', 'post', 'put'])) { + $adherent = $this->Adherents->patchEntity($adherent, $this->request->data); + if ($this->Adherents->save($adherent)) { + $this->Flash->success(__('The adherent has been saved.')); + return $this->redirect(['action' => 'view', $adherent->id]); + } else { + $this->Flash->error(__('The adherent could not be saved. Please, try again.')); + } + } + $adherentTypes = $this->Adherents->AdherentTypes->find('list'); + $villes = $this->Adherents->Villes->find('list'); + $adherentStatuts = $this->Adherents->AdherentStatuts->find('list'); + $civilites = $this->Adherents->Civilites->find('list'); + $this->set(compact('adherent', 'adherentTypes', 'villes', 'adherentStatuts', 'civilites')); + $this->set('_serialize', ['adherent']); + } +} 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']); + } +} diff --git a/generator/after-bake/src/Controller/IpmgmtController.php b/generator/after-bake/src/Controller/IpmgmtController.php new file mode 100644 index 0000000..7bc33f0 --- /dev/null +++ b/generator/after-bake/src/Controller/IpmgmtController.php @@ -0,0 +1,107 @@ +<?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; + +/** + * Ipmgmt Controller + * + * @property \App\Model\Table\IpmgmtTable $Ipmgmt + */ +class IpmgmtController extends AppController +{ + + /** + * Index method + * + * @return void + */ + public function index() + { + $query = $this->Ipmgmt->find(); + $expr = $query->newExpr()->add(['INET_ATON(ip4)']); + $query = $query->order($expr); + $this->set('ipmgmt', $this->paginate($query)); + } + + /** + * View method + * + * @param string|null $id Ipmgmt id. + * @return void + * @throws \Cake\Network\Exception\NotFoundException When record not found. + */ + public function view($id = null) + { + $ipmgmt = $this->Ipmgmt->get($id, [ + 'contain' => ['Equipements'=> ['EquipementModeles'] ] + ]); + $this->set('ipmgmt', $ipmgmt); + $this->set('_serialize', ['ipmgmt']); + } + + /** + * Add method + * + * @return void Redirects on successful add, renders view otherwise. + */ + public function add() + { + $ipmgmt = $this->Ipmgmt->newEntity(); + if ($this->request->is('post')) { + $ipmgmt = $this->Ipmgmt->patchEntity($ipmgmt, $this->request->data); + if ($this->Ipmgmt->save($ipmgmt)) { + $this->Flash->success(__('The ipmgmt has been saved.')); + return $this->redirect(['action' => 'index']); + } else { + $this->Flash->error(__('The ipmgmt could not be saved. Please, try again.')); + } + } + $this->set(compact('ipmgmt')); + $this->set('_serialize', ['ipmgmt']); + } + + /** + * Edit method + * + * @param string|null $id Ipmgmt id. + * @return void Redirects on successful edit, renders view otherwise. + * @throws \Cake\Network\Exception\NotFoundException When record not found. + */ + public function edit($id = null) + { + $ipmgmt = $this->Ipmgmt->get($id, [ + 'contain' => [] + ]); + if ($this->request->is(['patch', 'post', 'put'])) { + $ipmgmt = $this->Ipmgmt->patchEntity($ipmgmt, $this->request->data); + if ($this->Ipmgmt->save($ipmgmt)) { + $this->Flash->success(__('The ipmgmt has been saved.')); + return $this->redirect(['action' => 'index']); + } else { + $this->Flash->error(__('The ipmgmt could not be saved. Please, try again.')); + } + } + $this->set(compact('ipmgmt')); + $this->set('_serialize', ['ipmgmt']); + } +} diff --git a/generator/after-bake/src/Controller/IppubliquesController.php b/generator/after-bake/src/Controller/IppubliquesController.php new file mode 100644 index 0000000..d42bc88 --- /dev/null +++ b/generator/after-bake/src/Controller/IppubliquesController.php @@ -0,0 +1,79 @@ +<?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; + +/** + * Ippubliques Controller + * + * @property \App\Model\Table\IppubliquesTable $Ippubliques + */ +class IppubliquesController extends AppController +{ + + public function initialize() + { + parent::initialize(); + if ($this->request->action === 'index') { + $this->loadComponent('Paginator', [ 'limit' => 63 ]); + $this->loadComponent('Search.Prg'); + } + } + + /** + * Index method + * + * @return void + */ + public function index() + { + $this->paginate = [ + 'contain' => ['Secteurs', 'Services'] + ]; + $query = $this->Ippubliques + ->find('search', $this->Ippubliques->filterParams($this->request->query)); + $expr1 = $query->newExpr()->add(['ISNULL(secteur_id)']); + $expr2 = $query->newExpr()->add(['INET_ATON(ip4)']); + $query = $query->order($expr1)->order($expr2); + $this->set('ippubliques', $this->paginate($query)); + $this->set('_serialize', ['ippubliques']); + + $this->loadModel('Secteurs'); + $this->set('secteurs', $this->Secteurs->find('list')->toArray()); + } + + /** + * View method + * + * @param string|null $id Ippublique id. + * @return void + * @throws \Cake\Network\Exception\NotFoundException When record not found. + */ + public function view($id = null) + { + $ippublique = $this->Ippubliques->get($id, [ + 'contain' => ['Secteurs', 'Services' => ['Adherents', 'ServiceTypes', 'ServiceStatuts'] ] + ]); + $this->set('ippublique', $ippublique); + $this->set('_serialize', ['ippublique']); + } +} diff --git a/generator/after-bake/src/Controller/RelaisController.php b/generator/after-bake/src/Controller/RelaisController.php new file mode 100644 index 0000000..a2452c3 --- /dev/null +++ b/generator/after-bake/src/Controller/RelaisController.php @@ -0,0 +1,122 @@ +<?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; + +/** + * Relais Controller + * + * @property \App\Model\Table\RelaisTable $Relais + */ +class RelaisController extends AppController +{ + + /** + * Index method + * + * @return void + */ + public function index() + { + $this->paginate = [ + 'contain' => ['Secteurs', 'Villes'] + ]; + $this->set('relais', $this->paginate($this->Relais)); + } + + /** + * View method + * + * @param string|null $id Relais id. + * @return void + * @throws \Cake\Network\Exception\NotFoundException When record not found. + */ + public function view($id = null) + { + /* + $customJoin = function ($q) { + return $q + ->leftJoinWith('Adherents') + ->select(['Adherents.id','Adherents.nom','Adherents.prenom','Adherents.raison']) + ->leftJoinWith('ServiceStatuts') + ->select(['ServiceStatuts.title']); + };*/ + $relais = $this->Relais->get($id, [ + 'contain' => [ + 'Secteurs', 'Villes', + 'Equipements' => ['EquipementModeles', 'Ipmgmt'], //, 'Services' => $customJoin], + ] + ]); + $this->set('relais', $relais); + $this->set('_serialize', ['relais']); + } + + /** + * Add method + * + * @return void Redirects on successful add, renders view otherwise. + */ + public function add() + { + $relais = $this->Relais->newEntity(); + if ($this->request->is('post')) { + $relais = $this->Relais->patchEntity($relais, $this->request->data); + if ($this->Relais->save($relais)) { + $this->Flash->success(__('The relais has been saved.')); + return $this->redirect(['action' => 'index']); + } else { + $this->Flash->error(__('The relais could not be saved. Please, try again.')); + } + } + $secteurs = $this->Relais->Secteurs->find('list'); + $villes = $this->Relais->Villes->find('list'); + $this->set(compact('relais', 'secteurs', 'villes')); + $this->set('_serialize', ['relais']); + } + + /** + * Edit method + * + * @param string|null $id Relais id. + * @return void Redirects on successful edit, renders view otherwise. + * @throws \Cake\Network\Exception\NotFoundException When record not found. + */ + public function edit($id = null) + { + $relais = $this->Relais->get($id, [ + 'contain' => [] + ]); + if ($this->request->is(['patch', 'post', 'put'])) { + $relais = $this->Relais->patchEntity($relais, $this->request->data); + if ($this->Relais->save($relais)) { + $this->Flash->success(__('The relais has been saved.')); + return $this->redirect(['action' => 'index']); + } else { + $this->Flash->error(__('The relais could not be saved. Please, try again.')); + } + } + $secteurs = $this->Relais->Secteurs->find('list'); + $villes = $this->Relais->Villes->find('list'); + $this->set(compact('relais', 'secteurs', 'villes')); + $this->set('_serialize', ['relais']); + } +} diff --git a/generator/after-bake/src/Controller/ServicesController.php b/generator/after-bake/src/Controller/ServicesController.php new file mode 100644 index 0000000..a3a034b --- /dev/null +++ b/generator/after-bake/src/Controller/ServicesController.php @@ -0,0 +1,259 @@ +<?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; +use Cake\Datasource\ConnectionManager; +use Cake\I18n\Time; +use DateTime; + +/** + * Services Controller + * + * @property \App\Model\Table\ServicesTable $Services + */ +class ServicesController extends AppController +{ + + public function initialize() + { + parent::initialize(); + if ($this->request->action === 'index') { + $this->loadComponent('Paginator', [ 'limit' => 15, 'order' => [ 'Services.id' => 'DESC' ] ]); + $this->loadComponent('Search.Prg'); + } + } + + /** + * Index method + * + * @return void + */ + public function index() + { + $this->paginate = [ + 'contain' => ['Adherents', 'ServiceTypes', 'ServiceStatuts', 'Ippubliques'] + ]; + $query = $this->Services + ->find('search', $this->Services->filterParams($this->request->query)); + $this->set('services', $this->paginate($query)); + $this->set('_serialize', ['services']); + + $this->loadModel('ServiceTypes'); + $this->set('serviceTypes', $this->ServiceTypes->find('list')->toArray()); + $this->loadModel('ServiceStatuts'); + $this->set('serviceStatuts', $this->ServiceStatuts->find('list')->toArray()); + } + + /** + * View method + * + * @param string|null $id Service id. + * @return \Cake\Network\Response|null + * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + */ + public function view($id = null) + { + $service = $this->Services->get($id, [ + 'contain' => ['Adherents', 'ServiceTypes', 'ServiceStatuts', 'Ippubliques', 'Equipements' => ['EquipementModeles','Ipmgmt']] + ]); + $this->set('service', $service); + $this->set('_serialize', ['service']); + } + + /** + * Add method + * + * @return void Redirects on successful add, renders view otherwise. + */ + public function add() + { + $service = $this->Services->newEntity(); + //$service = $this->Services->newEntity(['date_debut' => new DateTime('now')]); + if ($this->request->is('post')) { + //FIXME il y a un pépin avec la saisie des datetime, voir si ya pas un helper / widget qui va mieux + $this->request->data['date_debut'] = new DateTime('now'); + + if ( is_numeric($this->request->data('service_type_id')) ) { + $serviceTypeId = $this->request->data('service_type_id'); + + // Utilisation du prix par défaut (pour le type de service donné) + $this->loadModel('ServiceTypes'); + $serviceType = $this->ServiceTypes->get($serviceTypeId); + if ( $serviceType ) { + $this->request->data['prix_ht'] = $serviceType->prix_base_ht; + } + + // Statut de service "Actif CHD (service_statut_id 4) si service de type Adhésion (service_type_id 1) + // Statut de service "Prévu" (service_statut_id 1) par défaut + $this->request->data['service_statut_id'] = ($serviceTypeId==1)?4:1; + } + + $service = $this->Services->patchEntity($service, $this->request->data); + if ($this->Services->save($service)) { + $this->Flash->success(__('The service has been saved.')); + return $this->redirect(['controller' => 'Adherents', 'action' => 'view', $service->adherent_id]); + } else { + debug($service); + debug($this->request->data); + $this->Flash->error(__('The service could not be saved. Please, try again.')); + } + } + + $defaultAdherent = NULL; + $defaultServiceType = 1; + $defaultServiceStatut = 4; + + if ( is_numeric($this->request->query('a')) ) { + $defaultAdherent = $this->request->query('a'); + // Services non résiliés de l'adhérent passé en argument + $hasOtherServices = $this->Services->find() + ->select('id') + ->where(['adherent_id =' => $defaultAdherent, 'service_statut_id !=' => 6]) + ->first(); + if ( $hasOtherServices ) { + $defaultServiceType = 2; + $defaultServiceStatut = 1; + } + } + + $adherents = $this->Services->Adherents->find('list'); + $serviceTypes = $this->Services->ServiceTypes->find('list'); + $serviceStatuts = $this->Services->ServiceStatuts->find('list'); + $ippubliques = $this->Services->Ippubliques->find('list'); + $this->set(compact('service', 'defaultAdherent', 'adherents', 'defaultServiceType', 'serviceTypes', 'defaultServiceStatut', 'serviceStatuts', 'ippubliques')); + $this->set('_serialize', ['service']); + } + + /** + * Edit method + * + * @param string|null $id Service id. + * @return void Redirects on successful edit, renders view otherwise. + * @throws \Cake\Network\Exception\NotFoundException When record not found. + */ + public function edit($id = null) + { + $service = $this->Services->get($id, [ + 'contain' => ['Adherents', 'ServiceTypes'] + ]); + if ($this->request->is(['patch', 'post', 'put'])) { + //FIXME : forbid change of read-only fields in the form + $service = $this->Services->patchEntity($service, $this->request->data); + if ($this->Services->save($service)) { + $this->Flash->success(__('The service has been saved.')); + return $this->redirect(['controller' => 'Adherents', 'action' => 'view', $service->adherent_id]); + } else { + $this->Flash->error(__('The service could not be saved. Please, try again.')); + } + } + //$adherents = $this->Services->Adherents->find('list'); + //$serviceTypes = $this->Services->ServiceTypes->find('list'); + $serviceStatuts = $this->Services->ServiceStatuts->find('list'); + //$ippubliques = $this->Services->Ippubliques->find('list'); + $this->set(compact('service', 'serviceStatuts')); + $this->set('_serialize', ['service']); + } + + public function activate($id = null) + { + $this->request->allowMethod(['post']); + $this->loadModel('Equipements'); + $service = $this->Services->get($id); + if ( $service ) { + if ( $service->ippublique_id === NULL && $service->service_statut_id === 1 /* Prévu */ ) { + //TODO : quick'n'dirty, à améliorer + $conn = ConnectionManager::get('default'); + $rawq='SELECT FREE_IP(' . $service->id . ')'; + $stmt = $conn->execute($rawq); + $free_ip = current($stmt->fetch()); + // Fin quick'n'dirty + + if ( strlen($free_ip) > 7 ) { + $patch = array( + 'service_statut_id' => 4, /* Actif CHD */ + 'ippublique_id' => $free_ip, + 'date_debut' => new DateTime('now'), + ); + $service = $this->Services->patchEntity($service, $patch); + if ($this->Services->save($service)) { + $this->Flash->success(__('The service has been saved.')); + } else { + $this->Flash->error(__('The service could not be saved. Please, try again.')); + } + } else { + $this->Flash->error(__('Can\'t find a free IP public address. Please make sure that equipements are associated to the service.')); + } + } else { + $this->Flash->error(__('Can\'t activate the service. Bad service state.')); + } + return $this->redirect(['controller' => 'Adherents', 'action' => 'view', $service->adherent_id]); + } + } + + public function migrate($id = null) + { + $this->request->allowMethod(['post']); + $this->loadModel('Equipements'); + $service = $this->Services->get($id, [ + 'contain' => ['Equipements'] + ]); + + //TODO : quick'n'dirty, à améliorer + $conn = ConnectionManager::get('default'); + $rawq='SELECT FREE_IP(' . $service->id . ')'; + $stmt = $conn->execute($rawq); + $free_ip = current($stmt->fetch()); + // Fin quick'n'dirty + + $new_service = $this->Services->newEntity([ + 'adherent_id' => $service->adherent_id, + 'service_type_id' => $service->service_type_id, + 'prix_ht' => $service->prix_ht, + 'description' => $service->description, + 'lat' => $service->lat, + 'lng' => $service->lng, + 'service_statut_id' => 4, + 'ippublique_id' => $free_ip, + 'date_debut' => Time::now(), + ]); + + $service->date_fin = Time::now(); + $service->service_statut_id = 3; + + if ( (strlen($free_ip) > 7) && $this->Services->save($new_service)) { + $fail = false; + foreach ( $service->equipements as $equipement ) { + $equipement->service_id = $new_service->id; + if ( ! $this->Equipements->save($equipement) ) { + $fail = true; + } + } + if ( $fail==false && $this->Services->save($service) ) { + $this->Flash->success(__('The service has been saved.')); + return $this->redirect(['controller' => 'Adherents', 'action' => 'view', $service->adherent_id]); + } + } + $this->Flash->error(__('The service could not be saved. Please, try again.')); + $this->set(compact('service', 'new_service')); + $this->set('_serialize', ['service', 'new_service']); + } +} diff --git a/generator/after-bake/src/Controller/VillesController.php b/generator/after-bake/src/Controller/VillesController.php new file mode 100644 index 0000000..296f17b --- /dev/null +++ b/generator/after-bake/src/Controller/VillesController.php @@ -0,0 +1,104 @@ +<?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; + +/** + * Villes Controller + * + * @property \App\Model\Table\VillesTable $Villes + */ +class VillesController extends AppController +{ + + /** + * Index method + * + * @return void + */ + public function index() + { + $this->set('villes', $this->paginate($this->Villes)); + } + + /** + * View method + * + * @param string|null $id Ville id. + * @return void + * @throws \Cake\Network\Exception\NotFoundException When record not found. + */ + public function view($id = null) + { + $ville = $this->Villes->get($id, [ + 'contain' => ['AdherentRoles' => ['Adherents', 'AdherentRoleTypes'], 'Adherents', 'Interesses', 'Relais'] + ]); + $this->set('ville', $ville); + $this->set('_serialize', ['ville']); + } + + /** + * Add method + * + * @return void Redirects on successful add, renders view otherwise. + */ + public function add() + { + $ville = $this->Villes->newEntity(); + if ($this->request->is('post')) { + $ville = $this->Villes->patchEntity($ville, $this->request->data); + if ($this->Villes->save($ville)) { + $this->Flash->success(__('The ville has been saved.')); + return $this->redirect(['action' => 'index']); + } else { + $this->Flash->error(__('The ville could not be saved. Please, try again.')); + } + } + $this->set(compact('ville')); + $this->set('_serialize', ['ville']); + } + + /** + * Edit method + * + * @param string|null $id Ville id. + * @return void Redirects on successful edit, renders view otherwise. + * @throws \Cake\Network\Exception\NotFoundException When record not found. + */ + public function edit($id = null) + { + $ville = $this->Villes->get($id, [ + 'contain' => [] + ]); + if ($this->request->is(['patch', 'post', 'put'])) { + $ville = $this->Villes->patchEntity($ville, $this->request->data); + if ($this->Villes->save($ville)) { + $this->Flash->success(__('The ville has been saved.')); + return $this->redirect(['action' => 'index']); + } else { + $this->Flash->error(__('The ville could not be saved. Please, try again.')); + } + } + $this->set(compact('ville')); + $this->set('_serialize', ['ville']); + } +} |