diff --git a/application/modules/admin/controllers/BibController.php b/application/modules/admin/controllers/BibController.php index a622037b17697fbb61c7f9e5d8ca6f0cf03cf319..a76810f8fb9e1008f330574ef7fc6241dc5f7bb1 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 2a68bdd5a31f9db2f0bdca927c7003f6cd7be2c8..99d1b1a81e5885c122b43e275bda75f94a2c41fe 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 483476a3ff82e0f271183763095520a0e7408e9f..815f245e06f825aac35fffc1a482c69f6070e710 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 0000000000000000000000000000000000000000..a2a207df808c46df8feea5bd5356cd3484b55782 --- /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