From a0c422248ef4e33745f656abcdaf1154275c73bd Mon Sep 17 00:00:00 2001 From: gloas <gloas@afi-sa.fr> Date: Thu, 5 Jan 2017 14:32:20 +0100 Subject: [PATCH] migrate controllers to manager plugin --- .../admin/controllers/BibController.php | 2 +- .../admin/controllers/LieuController.php | 30 ++---------- library/ZendAfi/Controller/Action.php | 2 +- .../Controller/Plugin/Manager/Lieu.php | 49 +++++++++++++++++++ 4 files changed, 56 insertions(+), 27 deletions(-) create mode 100644 library/ZendAfi/Controller/Plugin/Manager/Lieu.php diff --git a/application/modules/admin/controllers/BibController.php b/application/modules/admin/controllers/BibController.php index a622037b176..a76810f8fb9 100644 --- a/application/modules/admin/controllers/BibController.php +++ b/application/modules/admin/controllers/BibController.php @@ -384,7 +384,7 @@ class Admin_BibController extends ZendAfi_Controller_Action { return Class_Lieu::find($location_id); $location = Class_Lieu::newWith($model); - $location->updateCoordinates($this->_getOsmService()); + $location->updateCoordinates($this->getOsmService()); return $location->save() ? $location diff --git a/application/modules/admin/controllers/LieuController.php b/application/modules/admin/controllers/LieuController.php index 2a68bdd5a31..99d1b1a81e5 100644 --- a/application/modules/admin/controllers/LieuController.php +++ b/application/modules/admin/controllers/LieuController.php @@ -20,6 +20,11 @@ */ class Admin_LieuController extends ZendAfi_Controller_Action { + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_Manager_Lieu']; + } + + public function getRessourceDefinitions() { return ['model' => ['class' => 'Class_Lieu', 'name' => 'lieu', @@ -38,33 +43,8 @@ class Admin_LieuController extends ZendAfi_Controller_Action { } - protected function _doBeforeSave($model) { - $model->updateCoordinates($this->_getOsmService()); - return $this; - } - - public function exportCsvAction() { $this->_helper->csv('lieu_csv', Class_Lieu::findAllForCsv()); } - - - public function updateCoordinatesAction() { - $this->view->titre = $this->_('Mise à jour automatique des coordonnées'); - $this->view->locations = Class_Lieu::findAllBy(['order' => 'libelle']); - } - - - public function updateCoordinatesForAction() { - if(!$location = Class_Lieu::find($this->_getParam('id'))) - return; - - $this->_doBeforeSave($location); - $location->save(); - - $view_renderer = $this->_helper->getHelper('viewRenderer'); - $view_renderer->setNoRender(); - echo $this->view->partial('lieu/_update.phtml', ['location' => $location]); - } } \ No newline at end of file diff --git a/library/ZendAfi/Controller/Action.php b/library/ZendAfi/Controller/Action.php index 483476a3ff8..815f245e06f 100644 --- a/library/ZendAfi/Controller/Action.php +++ b/library/ZendAfi/Controller/Action.php @@ -277,7 +277,7 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action { } - protected function _getOsmService() { + public function getOsmService() { return (new Class_WebService_OpenStreetMap()) ->onCoordinatesNotFound( function() { diff --git a/library/ZendAfi/Controller/Plugin/Manager/Lieu.php b/library/ZendAfi/Controller/Plugin/Manager/Lieu.php new file mode 100644 index 00000000000..a2a207df808 --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/Manager/Lieu.php @@ -0,0 +1,49 @@ +<?php +/** + * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH 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 AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class ZendAfi_Controller_Plugin_Manager_Lieu extends ZendAfi_Controller_Plugin_Manager_Manager { + protected function _doBeforeSave($model) { + $model->updateCoordinates($this->_controller->getOsmService()); + return $this; + } + + + + public function updateCoordinatesAction() { + $this->_view->titre = $this->_view->_('Mise à jour automatique des coordonnées'); + $this->_view->locations = Class_Lieu::findAllBy(['order' => 'libelle']); + } + + + public function updateCoordinatesForAction() { + if(!$location = Class_Lieu::find($this->_getParam('id'))) + return; + + $this->_doBeforeSave($location); + $location->save(); + + $view_renderer = $this->_helper->getHelper('viewRenderer'); + $view_renderer->setNoRender(); + echo $this->_view->partial('lieu/_update.phtml', ['location' => $location]); + } +} +?> \ No newline at end of file -- GitLab