From 61256d532e8a0155aaa9c28977f542823073e4ec Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Sun, 12 Jun 2016 17:31:34 +0200 Subject: Adherent/index : add by AdherentTypes filter --- .../src/Controller/AdherentsController.php | 26 +++++----------------- .../after-bake/src/Template/Adherents/index.ctp | 12 +++++----- generator/before-bake/config/bake_extra.php | 10 ++++++++- 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/generator/after-bake/src/Controller/AdherentsController.php b/generator/after-bake/src/Controller/AdherentsController.php index abec8a0..566f5a6 100644 --- a/generator/after-bake/src/Controller/AdherentsController.php +++ b/generator/after-bake/src/Controller/AdherentsController.php @@ -21,7 +21,6 @@ namespace App\Controller; use App\Controller\AppController; -use Cake\Datasource\ConnectionManager; /** * Adherents Controller @@ -31,7 +30,6 @@ use Cake\Datasource\ConnectionManager; class AdherentsController extends AppController { - public function initialize() { parent::initialize(); @@ -56,39 +54,25 @@ class AdherentsController extends AppController $this->set('adherents', $this->paginate($query)); $this->set('_serialize', ['adherents']); + $this->loadModel('AdherentTypes'); + $this->set('adherentTypes', $this->AdherentTypes->find('list')->toArray()); $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. + * @return \Cake\Network\Response|null + * @throws \Cake\Datasource\Exception\RecordNotFoundException 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']); } diff --git a/generator/after-bake/src/Template/Adherents/index.ctp b/generator/after-bake/src/Template/Adherents/index.ctp index 9f62c14..353f4b7 100644 --- a/generator/after-bake/src/Template/Adherents/index.ctp +++ b/generator/after-bake/src/Template/Adherents/index.ctp @@ -33,22 +33,24 @@
- -
-
Progression : %
-

Form->create(null) . "\n" ?> - +
+ Form->input('q', [ 'placeholder' => __('Find...'), 'empty' => __('Find...') ]) ?> + Form->input('adherent_type_id', [ + 'placeholder' => __('AdherentTypes'), + 'empty' => __('AdherentTypes') + ]) ?> + Form->input('ville_id', [ 'placeholder' => __('Villes'), 'empty' => __('Villes') diff --git a/generator/before-bake/config/bake_extra.php b/generator/before-bake/config/bake_extra.php index bff1a9a..2fded68 100644 --- a/generator/before-bake/config/bake_extra.php +++ b/generator/before-bake/config/bake_extra.php @@ -49,9 +49,17 @@ EOT 'before' => 'true', 'after' => 'true', 'columns' => ['id','nom','nom2','prenom','prenom2','raison','proprio','tel_mobile1','tel_mobile2'], - 'colspan' => 5, + 'colspan' => 3, 'hint' => 'Find...', ], + 'adherent_type_id' => [ + 'mode' => 'value', + 'before' => 'false', + 'after' => 'false', + 'model' => 'AdherentTypes', + 'colspan' => 2, + 'hint' => 'AdherentTypes', + ], 'ville_id' => [ 'mode' => 'value', 'before' => 'false', -- cgit v1.1