From 335aa289498cdf80f7b05da78ed24c1ade2c870f Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Sat, 26 Mar 2016 23:48:08 +0100 Subject: =?UTF-8?q?Services/Suspend=20:=20implent=C3=A9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Controller/ServicesController.php | 34 ++++++++++++++++++++++ .../after-bake/src/Template/Adherents/view.ctp | 4 +-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/generator/after-bake/src/Controller/ServicesController.php b/generator/after-bake/src/Controller/ServicesController.php index 0371623..57f9e5d 100644 --- a/generator/after-bake/src/Controller/ServicesController.php +++ b/generator/after-bake/src/Controller/ServicesController.php @@ -202,6 +202,18 @@ class ServicesController extends AppController } else { $this->Flash->error(__('Can\'t find a free IP public address. Please make sure that equipements are associated to the service.')); } + + } else if ($service->service_statut_id === 5 /* Suspendu */) { + $patch = array( + 'service_statut_id' => 4, /* Actif CHD */ + ); + $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 activate the service. Bad service state.')); } @@ -257,6 +269,28 @@ class ServicesController extends AppController $this->set('_serialize', ['service', 'new_service']); } + public function suspend($id = null) + { + $this->request->allowMethod(['post']); + $service = $this->Services->get($id); + if ( $service ) { + if ( $service->service_statut_id === 4 /* Actif CHD */ ) { + $patch = array( + 'service_statut_id' => 5, /* Suspendu */ + ); + $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 terminate the service. Bad service state.')); + } + return $this->redirect(['controller' => 'Adherents', 'action' => 'view', $service->adherent_id]); + } + } + public function terminate($id = null) { $this->request->allowMethod(['post']); diff --git a/generator/after-bake/src/Template/Adherents/view.ctp b/generator/after-bake/src/Template/Adherents/view.ctp index d986c5b..2edf6b9 100644 --- a/generator/after-bake/src/Template/Adherents/view.ctp +++ b/generator/after-bake/src/Template/Adherents/view.ctp @@ -213,8 +213,8 @@ break; case 5: /* Suspendu */ echo $this->Form->postLink( - __('Unsuspend'), ['controller' => 'Services', 'action' => 'unsuspend', $services->id], - ['confirm' => __('Are you sure you want to suspend # {0}?', $services->id)] + __('Activate'), ['controller' => 'Services', 'action' => 'activate', $services->id], + ['confirm' => __('Are you sure you want to activate # {0}?', $services->id)] ) . "\n"; echo $this->Form->postLink( __('Terminate'), ['controller' => 'Services', 'action' => 'terminate', $services->id], -- cgit v1.1