diff --git a/application/modules/admin/controllers/AlbumController.php b/application/modules/admin/controllers/AlbumController.php index 70cba5d65db5cbff42ac57b629503b9f1eae0bbf..4ccc978e706848ce55194da001c0c401b8b720e8 100644 --- a/application/modules/admin/controllers/AlbumController.php +++ b/application/modules/admin/controllers/AlbumController.php @@ -19,16 +19,11 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class Admin_AlbumController extends ZendAfi_Controller_Action { - protected $_baseUrlOptions = ['module' => 'admin', - 'controller' => 'album']; - - public function getRessourceDefinitions() { - return ['model' => ['class' => 'Class_Album', - 'name' => 'album', - 'order' => 'libelle', - 'model_id' => 'id'], - 'plugins' => ['ZendAfi_Controller_Plugin_MultiSelection_Album']]; + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_Album', + 'ZendAfi_Controller_Plugin_Manager_Album', + 'ZendAfi_Controller_Plugin_MultiSelection_Album']; } @@ -168,525 +163,6 @@ class Admin_AlbumController extends ZendAfi_Controller_Action { } - public function addcategorietoAction() { - if (!$parent_categorie = Class_AlbumCategorie::find((int)$this->_getParam('id'))) { - $this->_redirect('admin/album'); - return; - } - - $categorie = Class_AlbumCategorie::newInstance() - ->setParentCategorie($parent_categorie); - - $titre = sprintf(((!$parent_categorie->hasParentCategorie()) - ? 'Ajouter une catégorie à la collection "%s"' - : 'Ajouter une sous-catégorie à la catégorie "%s"'), - $parent_categorie->getLibelle()); - $this->_renderCategoryForm($categorie, $titre); - } - - - public function addcategorieAction() { - $this->_renderCategoryForm(Class_AlbumCategorie::newInstance(), - 'Ajouter une collection'); - } - - - public function editcategorieAction() { - if (!$categorie = Class_AlbumCategorie::find((int)$this->_getParam('id'))) { - $this->_redirect('admin/album'); - return; - } - - $this->_renderCategoryForm( - $categorie, - 'Modification de la '. ((!$categorie->hasParentCategorie()) ? 'collection' : 'catégorie') . ' "' . $categorie->getLibelle() . '"'); - } - - - public function deletecategorieAction() { - if ($categorie = Class_AlbumCategorie::find((int)$this->_getParam('id'))) - $categorie->delete(); - $this->_redirect('admin/album'); - } - - - public function linkalbumtoAction() { - $this->_renderAlbumForm(Class_Album::newInstance(), - 'Ajouter un album'); - } - - - public function addalbumtoAction() { - $categorie = ''; - $title = 'Ajouter un album'; - if ($categorie = Class_AlbumCategorie::find((int)$this->_getParam('id'))) - $title .= ' dans la collection "' . $categorie->getLibelle() . '"'; - - $this->_renderAlbumForm( - Class_Album::newInstance()->setCategorie($categorie), $title); - } - - - public function editalbumAction() { - if (!$album = Class_Album::find((int)$this->_getParam('id'))) { - $this->_redirect('admin/album'); - return; - } - - $this->_renderAlbumForm($album, 'Modifier l\'album "' . $album->getTitre() . '"'); - } - - - public function deletealbumAction() { - if ($album = Class_Album::find((int)$this->_getParam('id'))) - $album->delete(); - $this->_redirect('admin/album'); - } - - - public function previewalbumAction() { - if (!$album = Class_Album::find((int)$this->_getParam('id'))) { - $this->_redirect('admin/album'); - return; - } - - $form = $this->_thumbnailsForm($album); - if ($form && $this->_request->isPost() - && $form->isValid($this->_request->getPost()) - && ($album->updateAttributes($this->_request->getPost()) - ->save())) { - $this->_helper->notify('Paramètres sauvegardés'); - $this->_redirect('admin/album/preview_album/id/'.$album->getId()); - return; - } - - $this->view->titre = sprintf('Visualisation de l\'album "%s"', - $album->getTitre()); - $this->view->album = $album; - $this->view->form = $form; - } - - - public function generateThumbnailsAction() { - if (!$album = Class_Album::find((int)$this->_getParam('id'))) { - $this->_redirect('admin/album'); - return; - } - - $this->view->titre = sprintf('Génération des vignettes de l\'album "%s"', - $album->getTitre()); - $this->view->album = $album; - } - - - public function editimagesAction() { - if (!$album = Class_Album::find((int)$this->_getParam('id'))) { - $this->_redirect('admin/album'); - return; - } - - $this->view->album = $album; - $this->view->ressources = $album->getRessources(); - - $this->view->titre = 'Médias de l\'album "' - . $album->getTitre() - . '" dans la collection "' - . $album->getCategorie()->getLibelle() . '"'; - } - - - public function addRessourceAction () { - if (!$album = Class_Album::find((int)$this->_getParam('id'))) { - $this->_redirect('admin/album'); - return; - } - - $this->view->album = $album; - $ressource = Class_AlbumRessource::newInstance()->setAlbum($album); - - if ($this->_setupRessourceFormAndSave($ressource)) { - $this->_helper->notify('Média "' . $ressource->getTitre() . '" sauvegardé'); - $this->_redirect('admin/album/edit_ressource/id/' . $ressource->getId()); - return; - } - - $this->view->errors = $ressource->getErrors(); - } - - - public function editressourceAction() { - if (null === ($ressource = Class_AlbumRessource::getLoader() - ->find($this->_getParam('id')))) { - $this->_redirect('admin/album'); - return; - } - - if ($this->_setupRessourceFormAndSave($ressource)) { - $this->_helper->notify('Média "' . $ressource->getTitre() . '" sauvegardé'); - $this->_redirect('admin/album/edit_ressource/id/' . $ressource->getId()); - return; - } - - $this->view->errors = $ressource->getErrors(); - $this->view->form->getElement('fichier') - ->setValue($ressource->getFichier()); - $this->view->form->getElement('poster') - ->setValue($ressource->getPoster()); - - $this->view->ressource = $ressource; - } - - - public function previewRessourceAction() { - if (null === ($ressource = Class_AlbumRessource::find($this->_getParam('id')))) { - $this->_redirect('admin/album'); - return; - } - - $ressource->ensureTilesGenerated(); - Class_ScriptLoader::getInstance()->loadLeafletJS(); - $this->view->ressource = $ressource; - } - - - protected function _setupRessourceFormAndSave($model) { - $form = $this->_ressourceForm($model); - - $this->view->form = $form; - - if (!$this->_request->isPost() - or !$form->isValid($this->_request->getPost())) - return false; - - $model->updateAttributes($this->_request->getPost()); - $model->setAuthors($form->authors->getValue()); - if (!$model->isValid()) { - $form->addModelErrors($model); - return false; - } - - return $model->save() - && $model->receiveFiles() - && $model->getAlbum()->save() - && $model->getAlbum()->index(); - } - - - public function sortressourcesAction() { - $album = Class_Album::getLoader()->find((int)$this->_getParam('id')); - $album->sortRessourceByFileName()->save(); - $this->_helper->notify('Médias réordonnés par nom de fichier'); - $this->_redirect('admin/album/edit_images/id/'.$album->getId()); - } - - - public function massRessourceDeleteAction() { - $this->_helper->getHelper('viewRenderer')->setNoRender(true); - if ((!$ids = $this->_getParam('ids')) - || (!$id = $this->_getParam('id'))) { - $this->_helper->notify('Paramètres manquants dans la requête de suppression'); - return; - } - - $ids = explode(',', $ids); - if (empty($ids)) { - $this->_helper->notify('Rien à supprimer'); - return; - } - - $deleted_count = 0; - foreach ($ids as $ressource_id) { - if (!$ressource = Class_AlbumRessource::find($ressource_id)) - continue; - - if (!$ressource->getAlbum()) - continue; - - if ($id != $ressource->getAlbum()->getId()) - continue; - - $ressource->delete(); - ++$deleted_count; - } - - $this->_helper->notify($deleted_count . ' média(s) supprimé(s)'); - } - - - public function deleteimageAction() { - if (null === ($ressource = Class_AlbumRessource::find((int)$this->_getParam('id')))) { - $this->_redirect('admin/album'); - return; - } - - $ressource->delete(); - $this->_redirect('admin/album/edit_images/id/' . $ressource->getAlbum()->getId()); - - } - - - public function moveImageAction() { - $this->_helper->getHelper('viewRenderer')->setNoRender(true); - - if (null === ($ressource = Class_AlbumRessource::find((int)$this->_getParam('id')))) - return; - - $ressource - ->getAlbum() - ->moveRessourceAfter($ressource, (int)$this->_getParam('after')); - } - - - public function albumDeleteVignetteAction() { - $this->_helper->getHelper('viewRenderer')->setNoRender(true); - - if (!$album = Class_Album::find((int)$this->_getParam('id'))) { - $this->_redirect('admin/album'); - return; - } - - $album->deleteVignette(); - $this->_redirect('admin/album/edit_album/id/' . $album->getId()); - } - - - public function albumDeletePdfAction() { - $this->_helper->getHelper('viewRenderer')->setNoRender(true); - - if (!$album = Class_Album::find((int)$this->_getParam('id'))) { - $this->_redirect('admin/album'); - return; - } - - $album->deletePdf(); - $this->_redirect('admin/album/edit_album/id/' . $album->getId()); - } - - - /** - * Formulaire d'édition des catégories - * @param Class_AlbumCategorie $categorie - * @return Zend_Form - */ - protected function _categorieForm($categorie) { - $cat_id = $categorie->isNew() ? $categorie->getParentId(): $categorie->getId(); - $form = new ZendAfi_Form(['id' => 'categorie', - 'data-backurl' => $this->view->url(['action' => 'index', - 'cat_id' => $cat_id])]); - - $form->addElement(new Zend_Form_Element_Text('libelle', ['label' => 'Libellé *', - 'size' => 30, - 'required' => true, - 'allowEmpty' => false])) - ->addDisplayGroup(['libelle'], 'categorie', - ['legend' => (($categorie->hasParentCategorie()) ? - 'Catégorie' - : 'Collection')]) - ->populate($categorie->toArray()); - return $form; - } - - - /** - * @param Class_AlbumCategorie $categorie - * @return null - */ - public function _validateAndAddCategorie($categorie) { - $form = $this->_categorieForm($categorie); - $this->view->form = $form; - - if (!$this->getRequest()->isPost() or !$form->isValid($_POST)) - return; - - $categorie - ->updateAttributes($_POST) - ->save(); - $this->_redirect('admin/album/index'); - } - - - /** - * @param Class_AlbumCategorie $categorie - * @param string $titre - */ - protected function _renderCategoryForm($categorie, $titre) { - $this->_validateAndAddCategorie($categorie); - - $this->view->titre = $titre; - $this->render('categorie_form'); - } - - - /** - * @param Class_Album $album - * @return Zend_Form - */ - protected function _albumForm($album) { - $form = ZendAfi_Form_Album::newWithAlbum($album); - $bib_id_param = []; - if(!$this->_getParam('title_search')) - $bib_id_param = ['cat_id' => $album->getCatId()]; - $form->addAttribs(['data-backurl' => $this->view->url(array_filter(array_merge(['action' => 'index'], $bib_id_param)))]); - return $form; - } - - - protected function _getForm($album){ - return $this->_albumForm($album); - } - - - /** - * @param Class_AlbumRessource $ressource - * @return Zend_Form - */ - protected function _ressourceForm($ressource) { - return ZendAfi_Form_Album_Ressource::newWith($ressource); - } - - /** - * @param Class_Album $album - * @return null - */ - public function _validateAndSaveAlbum($album) { - $form = $this->_albumForm($album); - $this->view->form = $form; - - if ( - !$this->_request->isPost() - or !$form->isValid($this->_request->getPost()) - ) - return; - - $values = $form->getValues(); - - unset($values['fichier']); - unset($values['pdf']); - unset($values['album_items']); - - $droits_precision = $values['droits_precision']; - unset($values['droits_precision']); - - $values['droits'] = $form->isPublicDomain() - ? $form->getPublicDomain() - : $droits_precision; - - $frbr_multi = $values['frbr_multi']; - unset($values['frbr_multi']); - - $album->updateAttributes($values); - - if ($album->save() - && $album->receiveFile() - && $album->receivePDF()) { - - $album->index(); - - $frbr_links = []; - foreach(Class_FRBR_Link::findAllRecordLinksForAlbum($album) as $link) - $frbr_links[md5($link->getSource().$link->getTarget())] = $link; - - $absoluteUrl = $this->view->absoluteUrl(array_merge(['id' => $album->getId()], - $album->getPermalink()), null, true); - - $received_links = []; - $urls = $frbr_multi['frbr_url']; - $types = $frbr_multi['frbr_type']; - $count = count($urls); - for($i=0; $i < $count; $i++) { - if (!$types[$i] && !$urls[$i]) - continue; - - list($id, $type) = explode(':', $types[$i]); - $md5 = md5('target' == $type ? ($urls[$i] . $absoluteUrl) : ($absoluteUrl . $urls[$i])); - - $received_links[$md5] = ['frbr_url' => $urls[$i], 'frbr_type' => $id, 'type' => $type]; - } - - foreach(array_diff_key($frbr_links, $received_links) as $link) - $link->delete(); - - foreach(array_diff_key($received_links, $frbr_links) as $new) { - $record_type = 'target' == $new['type'] ? 'source' : 'target'; - $frbr_link = Class_FRBR_Link::newInstance([$new['type'] => $absoluteUrl, - $record_type => $new['frbr_url'], - 'type_id' => $new['frbr_type']]); - - if (!$frbr_link->save()) - throw new Zend_Exception(json_encode($frbr_link->getErrors())); - } - - (new Storm_Cache())->clean(); - $this->_helper->notify('Album sauvegardé'); - - return true; - } - return false; - } - - - /** - * @return ZendAfi_Form - */ - public function _thumbnailsForm($album) { - if (!$form = ZendAfi_Form_Album_DisplayAbstract::forAlbum($album, ['id' => 'thumbnails'])) - return; - $form->addAttribs(['data-backurl' => $this->view->url(['action' => 'index', - 'cat_id' => $album->getCatId()])]); - return $form->populate($album->toArray()); - } - - - /** - * @param Class_Album $album - * @param string $titre - */ - protected function _renderAlbumForm($album, $titre) { - if ($this->_validateAndSaveAlbum($album)) - return $this->_redirectToEdit($album);; - - $this->view->titre = $titre; - $this->view->errors = $album->getErrors(); - $this->view->album = $album; - $this->view->form->getElement('fichier') - ->setValue($album->getFichier()); - $this->view->form->getElement('pdf') - ->setValue($album->getPdf()); - - if ($this->isPopupRequest()) - $this->_prepareAlbumAjaxFrom(); - - $this->getHelper('ViewRenderer')->setScriptAction('album_form'); - } - - - protected function _getEditUrl($model) { - return Class_Url::absolute(['action' => 'edit_album', - 'id' => $model->getId(), - 'page' => $this->_getParam('page'), - 'title_search' => $this->_getParam('title_search')]); - } - - - protected function _prepareAlbumAjaxFrom() { - $id_notice = $this->_getParam('id_notice') - ? $this->_getParam('id_notice') - : ''; - - $this->view->form->beSimple() - ->setAction($this->view->url(['action' => 'link_album_to', - 'id_notice' => $id_notice])) - ->setEnctype('application/x-www-form-urlencoded'); - - if (!$this->_request->isPost()) { - $notice = Class_Notice::find($id_notice); - $this->view->form->populateFrbrUrl( - $this->view->absoluteUrl($this->view->urlNotice($notice, [], null, true), null, true)); - - $this->view->form->getElement('titre')->setValue($notice->getTitrePrincipal()); - } - } - protected function _getTreeViewContainerActions() { return (new ZendAfi_View_Helper_ModelActionsTable_AlbumCategories($this->view, 'album'))->getActions(); @@ -712,76 +188,4 @@ class Admin_AlbumController extends ZendAfi_Controller_Action { return $this->renderScript('admin/listViewMode.phtml'); } - - - public function resourceDeletePosterAction() { - $this->_helper->getHelper('viewRenderer')->setNoRender(true); - - if (!$resource = Class_AlbumRessource::find((int)$this->_getParam('id'))) { - $this->_redirect('admin/album'); - return; - } - - $resource->deletePoster()->save(); - $this->_redirect('admin/album/edit_ressource/id/' . $resource->getId()); - } - - - public function addWebsiteAction() { - $import_form = $this->view - ->newForm(['id' => 'import', 'class' => 'form']) - ->setMethod('post') - ->addElement('url', 'url', ['label' => $this->view->_('URL du site web'), - 'required' => true, - 'allowEmpty' => false]) - ->addDisplayGroup(['url'], 'website', ['legend' => $this->view->_('Site web')]) - ->addElement('submit', 'submit', ['label' => $this->view->_('Importer')]); - - if ($this->getRequest()->isPost() && $import_form->isValid($this->getRequest()->getPost())) { - $album = $this->createAlbumFromUrl($this->getRequest()->getPost('url')); - if ($album && $album->save()) { - $this->_redirect('/admin/album/edit_album/id/'.$album->getId()); - return; - } - } - - $this->view->import_form = $import_form; - } - - - protected function createAlbumFromUrl($url) { - $html = Class_WebService_SimpleWebClient::getInstance()->open_url($url); - $dom = new Zend_Dom_Query($html); - - $category = Class_AlbumCategorie::getOrCreateRootCategory('Sites web'); - - $album = Class_Album::newInstance(['type_doc_id' => Class_TypeDoc::WEBSITE, - 'categorie' => $category]); - - $title_node = $dom->queryXpath('//head/title')->current(); - $album->setTitre($title_node ? trim($title_node->textContent) : $url); - - if ($description_node = $dom->queryXpath('//head/meta[@name="description"]')->current()) - $album->setDescription($description_node->getAttribute('content')); - - $resource = Class_AlbumRessource::newInstance(['url' => $url, - 'titre' => $album->getTitre(), - 'description' => $album->getDescription()]); - $album->addRessource($resource); - $album->save(); - - $thumbnailer = (new Class_WebService_WebSiteThumbnail()); - - $poster_name = $thumbnailer->fileNameFromUrl($url); - $poster_path = $resource->getPosterPath(); - - $resource->getFolderManager()->ensure($poster_path); - $thumbnailer->getThumbnailer()->fetchUrlToFile($url, $poster_path . $poster_name, 'medium'); - - $resource->setPoster($poster_name); - $resource->createThumbnail(); - - return $album; - } - } diff --git a/application/modules/admin/controllers/BatchController.php b/application/modules/admin/controllers/BatchController.php index 6793510f62c2424d46c53174d5d096de35e058ed..d51f363ebfc604184d3383fe2aef0593283ae16f 100644 --- a/application/modules/admin/controllers/BatchController.php +++ b/application/modules/admin/controllers/BatchController.php @@ -20,25 +20,10 @@ */ class Admin_BatchController extends ZendAfi_Controller_Action { - public function getRessourceDefinitions() { - return [ - 'model' => ['class' => 'Class_Batch', - 'name' => 'batch', - 'order' => 'type', - 'findAll' => 'findAllWithDefaults'], - 'messages' => ['successful_add' => $this->_('Tâche ajoutée'), - 'successful_delete' => $this->_('Tâche supprimée')], - - 'actions' => ['add' => ['title' => $this->_('Nouvelle Tâche')], - 'index' => ['title' => $this->_('Tâches')]], - - 'display_groups' => ['ajout_tache' => ['legend' => 'Ajouter une tâche', - 'elements' => ['type' => ['element' => 'select', - 'options' => ['multiOptions' => Class_Batch::getAvailableType(), - 'required' => true]] ]]], - 'after_add' => function() {$this->_redirect('/admin/batch');} - ]; + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_Batch', + 'ZendAfi_Controller_Plugin_Manager_Manager']; } diff --git a/application/modules/admin/controllers/BibController.php b/application/modules/admin/controllers/BibController.php index 583a51acef7356d58807ce93ade66039702be209..e7db534ec6935b80f17488b6461355ca2ae14738 100644 --- a/application/modules/admin/controllers/BibController.php +++ b/application/modules/admin/controllers/BibController.php @@ -22,18 +22,9 @@ class Admin_BibController extends ZendAfi_Controller_Action { private $id_zone; - public function getRessourceDefinitions() { - return ['model' => ['class' => 'Class_Bib', - 'name' => 'bib', - 'order' => 'id'], - - 'messages' => ['successful_save' => $this->_('Bibliothèque "%s" sauvegardée'), - 'successful_add' => $this->_('La bibliothèque "%s" a été ajoutée'), - 'successful_delete' => $this->_('La bibliothèque "%s" a été suppriméee')], - - 'actions' => ['edit' => ['title' => $this->_("Modifier une bibliothèque"), - 'add' => ['title' => $this->_("Ajouter une bibliothèque")]]], - 'form_class_name' => 'ZendAfi_Form_Admin_Library']; + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_Library', + 'ZendAfi_Controller_Plugin_Manager_Library']; } @@ -51,7 +42,7 @@ class Admin_BibController extends ZendAfi_Controller_Action { public function indexAction() { $this->view->titre = $this->view->_('Gestion des bibliothèques'); - if (!$this->_canAccessToLibrary()) + if (!$this->canAccessToLibrary()) return $this->_redirect('admin/index'); $user = Class_Users::getIdentity(); @@ -61,45 +52,6 @@ class Admin_BibController extends ZendAfi_Controller_Action { } - protected function _canEdit($model) { - return $this->_canAccessToLibrary(); - } - - - protected function _canAdd() { - return $this->_canAccessToLibrary(); - } - - - protected function _canAccessToLibrary() { - $user = Class_Users::getIdentity(); - if (!$user->hasRightsOnLibraries()) - return false; - - $id = (int)($this->_request->isPost()) ? - $this->_request->getPost('id_bib') : - $this->_request->getParam('id'); - - if(!$id) - return true; - - return $user->hasRightsForLibrary($id); - } - - - public function deleteAction() { - $bib = Class_Bib::find((int)$this->_request->getParam('id')); - $this->view->titre = $this->view->_('Supprimer la bibliothèque: %s', $bib->getLibelle()); - $this->view->bib = $bib; - } - - - public function forceDeleteAction() { - $bib = Class_Bib::find((int)$this->_request->getParam('id')); - $bib->delete(); - $this->_helper->notify('La bibliothèque "'.$bib->getLibelle().'" a été supprimée'); - $this->_redirect('admin/bib/index'); - } public function localisationsAction() { @@ -286,16 +238,6 @@ class Admin_BibController extends ZendAfi_Controller_Action { return Class_Localisation::find($id_location); } - protected function checkForm() { - $this->view->erreurs=[]; - if(!$this->_getParam("libelle")) - $this->view->erreurs[] = $this->view->_("le libellé est obligatoire."); - if(!$this->_getParam("image")) - $this->view->erreurs[]=$this->view->_("L'image du plan est obligatoire."); - - return (!$this->view->erreurs); - - } public function plansmajAction() { $cls_loc = new Class_Localisation(); @@ -411,20 +353,24 @@ class Admin_BibController extends ZendAfi_Controller_Action { null, true)); } + protected function checkForm() { + $this->view->erreurs=[]; + if(!$this->_getParam("libelle")) + $this->view->erreurs[] = $this->view->_("le libellé est obligatoire."); + if(!$this->_getParam("image")) + $this->view->erreurs[]=$this->view->_("L'image du plan est obligatoire."); + + return (!$this->view->erreurs); - protected function _doBeforeSave($model) { - if ($location = $this->_getOrCreateLocation($this->_getParam('id_lieu'), $model)) - $model->setLieu($location); - return $this; } - protected function _getOrCreateLocation($location_id, $model) { + public function getOrCreateLocation($location_id, $model) { if (Class_Lieu::GENERATE != $location_id) return Class_Lieu::find($location_id); $location = Class_Lieu::newWith($model); - $location->updateCoordinates($this->_getOsmService()); + $location->updateCoordinates($this->getOsmService()); return $location->save() ? $location @@ -432,7 +378,6 @@ class Admin_BibController extends ZendAfi_Controller_Action { } - public function updateLieuElementAction() { if (!$library = Class_Bib::find($this->_getParam('id'))) return $this->_renderUpdateLieuElement(function() @@ -443,7 +388,7 @@ class Admin_BibController extends ZendAfi_Controller_Action { $library->updateAttributes($this->getRequest()->getParams()); - if (!$location = $this->_getOrCreateLocation($this->_getParam('id_lieu'), $library)) + if (!$location = $this->getOrCreateLocation($this->_getParam('id_lieu'), $library)) return $this->_renderUpdateLieuElement(function() { return $this->view->renderError('Vous devez d\'abord définir le nom de la bibliothèque'); @@ -471,4 +416,20 @@ class Admin_BibController extends ZendAfi_Controller_Action { $html = $callback($location_element); $this->getResponse()->setBody($location_element->render($this->view) . $html); } + + + public function canAccessToLibrary() { + $user = Class_Users::getIdentity(); + if (!$user->hasRightsOnLibraries()) + return false; + + $id = (int)($this->_request->isPost()) ? + $this->_request->getPost('id_bib') : + $this->_request->getParam('id'); + + if(!$id) + return true; + + return $user->hasRightsForLibrary($id); + } } diff --git a/application/modules/admin/controllers/CmsCategoryController.php b/application/modules/admin/controllers/CmsCategoryController.php index 7e2dc912defd073c5b7dae9a46637ef23e2e0c62..872c1882dec0dddcb119e67b0e0498c6c0460586 100644 --- a/application/modules/admin/controllers/CmsCategoryController.php +++ b/application/modules/admin/controllers/CmsCategoryController.php @@ -23,6 +23,11 @@ class Admin_CmsCategoryController extends ZendAfi_Controller_Action { protected $_bib; + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_ArticleCategory', + 'ZendAfi_Controller_Plugin_Manager_ArticleCategory']; + } + public function getRessourceDefinitions() { return ['model' => ['class' => 'Class_ArticleCategorie', @@ -36,98 +41,21 @@ class Admin_CmsCategoryController extends ZendAfi_Controller_Action { 'edit' => ['title' => $this->_("Modifier une catégorie")]], 'after_add' => function ($model) { - $this->_redirectToTreeView($model); + $this->_redirectToReferer(); }, 'after_edit' => function ($model) { - $this->_redirectToTreeView($model); + $this->_redirectToReferer(); }, 'after_delete' => function($model) { - $this->_redirect($this->_deleteBackUrl($model)); + $this->_redirectToReferer(); }, 'form_class_name' => 'ZendAfi_Form_Admin_CmsCategory']; } - protected function _updateNewModel($model) { - if ($parent = Class_ArticleCategorie::find($this->_getParam('id'))) { - $model->setParentCategorie($parent) - ->setBib($parent->getBib()); - return; - } - - $this->_handleBibFor($model); - } - - - protected function _handleBibFor($category) { - if ($bib = $this->getDefaultBib()) - $category->setBib($bib); - } - - - protected function _redirectToTreeView($model) { - $this->_redirect($this->_backUrl($model)); - } - - - protected function _backUrl($model) { - $is_list_mode = Class_AdminVar::isArticlesListMode(); - if (($model->isNew() || $is_list_mode) - && $parent = $model->getParentCategorie()) - return $this->_withPageUrl(sprintf('admin/cms/index/id_cat/%d', $parent->getId())); - - return $this->_withPageUrl($is_list_mode ? - sprintf('admin/cms/index/id_bib/%d', - ($bib = $model->getBib()) ? $bib->getId() : 0) : - sprintf('admin/cms/index/id_cat/%d', $model->getId())); - } - - - protected function _deleteBackUrl($model) { - $is_list_mode = Class_AdminVar::isArticlesListMode(); - if ($parent = $model->getParentCategorie()) - return $this->_withPageUrl(sprintf('admin/cms/index/id_cat/%d', $parent->getId())); - - return $this->_withPageUrl($is_list_mode ? - sprintf('admin/cms/index/id_bib/%d', - ($bib = $model->getBib()) ? $bib->getId() : 0) : - 'admin/cms/index'); - } - - - protected function _withPageUrl($url) { - return ($page = $this->_getParam('page')) - ? $url . '/page/' . $page : $url; - } - - - protected function _postEditAction($model) { - if (null === $model->getBib()) - $this->_handleBibFor($model); - - if (Class_Users::getIdentity()->isRoleMoreThanModoPortail()) - $this->view->permissions = $this->view - ->groupsPermissions($model, - Class_Permission::getCmsPermissions(), - $this->view->url(['module' => 'admin', - 'controller' => 'cms-category', - 'action' => 'permissions', - 'id' => $model->getId()], - null, true)); - } - - - protected function getDefaultBib() { - $identity = Class_Users::getIdentity(); - - return ZendAfi_Acl_AdminControllerRoles::ADMIN_BIB >= $identity->getRoleLevel() ? - $identity->getBib() : Class_Bib::find((int)$this->_getParam('id_bib')); - } - - public function permissionsAction() { $this->_helper->getHelper('ViewRenderer')->setNoRender(); if (!$category = Class_ArticleCategorie::find($this->_getParam('id', 0))) @@ -137,16 +65,5 @@ class Admin_CmsCategoryController extends ZendAfi_Controller_Action { $this->_helper->notify('Permissions sauvegardées'); $this->_redirect(sprintf('admin/cms-category/edit/id/%d', $category->getId())); } - - - /** - * @param Storm_Model_Abstract $model - * @return Zend_Form - */ - protected function _getForm($model) { - $form = parent::_getForm($model); - $form->setAttrib('data-backurl', Class_Url::absolute($this->_backUrl($model))); - return $form; - } } ?> \ No newline at end of file diff --git a/application/modules/admin/controllers/CmsController.php b/application/modules/admin/controllers/CmsController.php index 032dca99aa2241a3e8a157f31e69c681f3e84bcb..731807ca98a285bb4833e61e0b9392f4820bb200 100644 --- a/application/modules/admin/controllers/CmsController.php +++ b/application/modules/admin/controllers/CmsController.php @@ -22,19 +22,10 @@ class Admin_CmsController extends ZendAfi_Controller_Action { private $_bib; - public function getRessourceDefinitions() { - return ['model' => ['class' => 'Class_Article', - 'name' => 'article', - 'order' => 'titre', - 'model_id' => 'id_article'], - - 'messages' => ['successful_save' => $this->_('Article "%s" sauvegardé'), - 'successful_add' => $this->_('L\'article "%s" a été sauvegardé'), - 'successful_delete' => $this->_('Article "%s" supprimé')], - - 'actions' => ['add' => ['title' => $this->_("Ajouter un article")]], - 'after_edit' => function ($model) { $model->index(); }, - 'plugins' => ['ZendAfi_Controller_Plugin_MultiSelection_Article']]; + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_Article', + 'ZendAfi_Controller_Plugin_Manager_Article', + 'ZendAfi_Controller_Plugin_MultiSelection_Article']; } @@ -169,317 +160,12 @@ class Admin_CmsController extends ZendAfi_Controller_Action { } - protected function _updateNewModel($article) { - if ('newsduplicate' == $this->_request->getActionName() - && $original = Class_Article::find($this->_getParam('id', 0))) { - $article->updateAttributes($original->copy()->toArray()); - return $this; - } - - $article->setAuteur(Class_Users::getIdentity()); - - if (!$category = $this->getCategoryAndSetComboCat()) - return $this; - - $article->setCategorie($category); - if ($domaine = Class_Catalogue::findWithSamePathAs($category)) - $article->setDomaineIds($domaine->getId()); - return $this; - } - - - protected function _doBeforeSave($article) { - $article->updateDateMaj(); - return $this; - } - - - protected function _doAfterSave($article) { - if($id_module = $this->_getParam('id_module')) - $this->updateConfigBoiteNews($id_module,$article); - $this->_notifyArticleChanged($article); - return $this; - } - - - public function newsduplicateAction() { - if (!$model = Class_Article::find($this->_getParam('id'))) { - $this->_redirect('admin/cms'); - return; - } - - $this->view->titre = $this->_('Dupliquer l\'article: %s', $model->getTitre()); - - if (!$this->_canModify($model->getCategorie())) { - $this->_helper->notify($this->view->_('Vous n\'avez pas la permission "%s"', - $this->view->titre)); - $this->_redirectToIndex(); - return; - } - - $this->_setParam('id_cat', $model->getCategorie()->getId()); - parent::addAction(); - - $this->view->titre = $this->_('Dupliquer l\'article: %s', $model->getTitre()); - $this->view->form - ->setAction($this->view->url(['module' => 'admin', - 'controller' => 'cms', - 'action' => 'add', - 'id_cat' => $model->getCategorie()->getId()], - null, true)); - - $this->getHelper('ViewRenderer')->setScriptAction('add'); - } - - - public function getCategoryAndSetComboCat() { - if (!$category = Class_ArticleCategorie::find($this->_getParam('id_cat'))) { - $this->_redirect('admin/cms'); - return; - } - - if (null === ($category->getBib())) - $category->setBib($this->_bib); - - $this->view->combo_cat = $this->view->comboCategories($category); - return $category; - } - - - protected function updateConfigBoiteNews($id_module, $article){ - $profil = Class_Profil::getCurrentProfil(); - $module_config = $profil->getModuleAccueilConfig($id_module, 'NEWS'); - $id_items= array_filter(explode('-',$module_config['preferences']['id_items'])); - array_unshift($id_items,$article->getId()); - $module_config['preferences']['id_items'] = implode('-',$id_items); - $profil->updateModuleConfigAccueil($id_module, $module_config); - $profil->save(); - return $this; - } - - - protected function comboLieuOptions() { - $combo_lieu_options = ['0' => $this->_('Aucun')]; - foreach(Class_Lieu::findAllBy(['order' => 'libelle']) as $lieu) - $combo_lieu_options[$lieu->getId()] = $lieu->getLibelle(); - return $combo_lieu_options; - } - - - protected function _notifyArticleChanged($article) { - if (!Class_AdminVar::isWorkflowEnabled()) - return; - $this->_sendMailWhenUpdatedStatusToValidationPending($article); - $this->_sendMailWhenUpdatedStatusToRefused($article); - $this->_sendMailWhenUpdatedStatusToValidated($article); - } - - - protected function _sendMailWhenUpdatedStatusToRefused($article) { - if ($article->old_status != Class_Article::STATUS_REFUSED && - $article->getStatus() == Class_Article::STATUS_REFUSED) { - $this->_sendRefusedMailToAuteur($article); - } - } - - - protected function _sendMailWhenUpdatedStatusToValidated($article) { - if ($article->old_status != Class_Article::STATUS_VALIDATED && - $article->getStatus() == Class_Article::STATUS_VALIDATED) { - $this->_sendValidatedMailToAuteur($article); - } - } - - - protected function _sendMailWhenUpdatedStatusToValidationPending($article) { - if (($article->old_status != Class_Article::STATUS_VALIDATION_PENDING && - $article->getStatus() == Class_Article::STATUS_VALIDATION_PENDING) - || ($article->getStatus() > 5 - && $article->old_status != $article->getStatus())) { - $this->_sendMailToValidators($article); - } - } - - - protected function prepareMailForAuteur($article) { - $mail = new ZendAfi_Mail('utf8'); - if(!$article->getAuteur()) { - $this->_helper->notify('Mail non envoyé: article sans auteur'); - return; - } - - if(!$mail_address = $article->getAuteur()->getMail()) { - $this->_helper->notify('Mail non envoyé: '.$article->getNomCompletAuteur().' sans mail.'); - return; - } - - $mail->setFrom('no-reply@afi-sa.fr') - ->addTo($mail_address); - return $mail; - } - - - protected function prepareBodyMail($article, $message) { - $replacements = - ['TITRE_ARTICLE' => $article->getTitre(), - 'URL_ARTICLE' => $this->view->absoluteUrl($article->getUrl(), null, true), - 'AUTHOR_ARTICLE' => $article->getNomCompletAuteur(), - 'SAVED_BY_ARTICLE' => $this->identity->getNomComplet(), - 'NEXT_STATUS_ARTICLE' => $article->getNextWorkflowStatusLabel(), - 'STATUS_ARTICLE' => $article->getStatusLabel()]; - - return - str_replace(array_keys($replacements), - array_values($replacements), - $message); - } - - - protected function _sendRefusedMailToAuteur($article) { - if(!$mail = $this->prepareMailForAuteur($article)) - return; - $body = $this->prepareBodyMail($article, $article->getRefusMessage()); - $this->sendPreparedMail($mail, - '[Bokeh] Refus de l\'article '.$article->getTitre(), - $body); - } - - - protected function sendPreparedMail($mail, $subject, $body) { - $mail->setSubject(quoted_printable_decode($subject)) - ->setBodyText($body,'utf-8',Zend_Mime::ENCODING_8BIT); - - if ($this->_sendMail($mail)) - $this->_helper->notify('Mail envoyé à : '.$mail->getRecipients()[0]); - } - - - protected function _sendValidatedMailToAuteur($article) { - if(!$mail = $this->prepareMailForAuteur($article)) - return; - - $body = $this->prepareBodyMail($article, $article->getValideMessage()); - $this->sendPreparedMail($mail, - '[Bokeh] Validation de l\'article '.$article->getTitre(), - $body); - } - - - protected function _getValidatorsMail($article) { - return array_unique( - Class_Permission::getWorkflow($article->getNextWorkflowStatus()) - ->getUsersOnModel($article->getCategorie()) - ->collect('mail') - ->getArrayCopy()); - } - - - protected function _sendMailToValidators($article) { - if (!$mails = $this->_getValidatorsMail($article)) - return; - - $mail = new ZendAfi_Mail('utf8'); - $mail - ->setFrom('no-reply@afi-sa.fr') - ->addTo(implode(',', $mails)) - ->setSubject($this->_('[Bokeh] Validation d\'article en attente: ') . $article->getTitre()) - ->setBodyText($this->prepareBodyMail($article, - Class_AdminVar::getWorkflowTextMailArticlePending())); - - if($this->_sendMail($mail)) - $this->_helper->notify($this->_('Mail de validation envoyé aux validateurs.')); - } - - - protected function _sendMail($mail) { - try { - $mail->send(); - return true; - - } catch (Exception $e) { - $this->_helper->notify('Mail non envoyé: vérifier la configuration du serveur de mail.'); - return false; - } - } - - - public function deleteAction() { - if (!$article = Class_Article::find((int)$this->_getParam('id'))) { - $this->_redirect('admin/cms'); - return; - } - - $this->view->titre = $this->view->_('Supprimer l\'article : %s', - $article->getTitre()); - - - if (!$this->_canModify($article->getCategorie())) { - $this->_helper->notify($this->view->_('Vous n\'avez pas la permission "%s"', - $this->view->titre)); - $this->_redirectToIndex(); - return; - } - - $this->view->model = $article; - } - - - public function forceDeleteAction() { - if (!$article = Class_Article::find((int)$this->_getParam('id'))) { - $this->_redirect('admin/cms'); - return; - } - - if (!$this->_canModify($article->getCategorie())) { - $this->_helper->notify($this->view->_('Vous n\'avez pas la permission "%s"', - $this->view->_('Supprimer l\'article : %s', - $article->getTitre()))); - $this->_redirectToIndex(); - return; - } - - $article->delete(); - $this->_redirect($this->_backDeleteUrl($article)); - } - - public function viewcmsAction() { $this->view->article = Class_Article::find((int)$this->_getParam('id')); $this->view->title = 'Afficher un article'; } - public function makevisibleAction() { - $this->_toggleVisibility('visible'); - } - - - public function makeinvisibleAction() { - $this->_toggleVisibility('invisible'); - } - - - protected function _toggleVisibility($visibility) { - if (!$article = Class_Article::getLoader()->find((int)$this->_getParam('id'))) { - $this->_redirect('admin/cms'); - return; - } - - if (!$this->_canModify($article->getCategorie())) { - $this->_helper->notify($this->view->_('Vous n\'avez pas la permission "%s"', - $this->view->_('Rendre %s l\'article : %s', - $visibility, - $article->getTitre()))); - $this->_redirectToIndex(); - return; - } - - $method = 'be' . ucfirst($visibility); - $article->$method(); - $this->_redirect($this->_backUrl($article)); - } - - private function _getTreeViewContainerActions() { return (new ZendAfi_View_Helper_ModelActionsTable_ArticlesCategories($this->view, 'article'))->getActions(); } @@ -490,132 +176,11 @@ class Admin_CmsController extends ZendAfi_Controller_Action { } - private function _getBibActions() { - return (new ZendAfi_View_Helper_ModelActionsTable_Bib($this->view, 'bib'))->getActions(); - } - - - private function _toDate($str) { - if ($str!==null && $str!=='') { - $date = new Zend_Date($str, null, Zend_Registry::get('locale')); - return $date->toString('YYYY-MM-dd HH:mm'); - } - - return null; - } - - public function categoriesAction() { $this->_helper->viewRenderer->setNoRender(); $this->getResponse()->setHeader('Content-Type', 'application/json; charset=utf-8'); $this->getResponse()->setBody((new Class_ArticleCategorie())->getCategoriesJson()); } - - protected function _getFormValues($model) { - $attributes=parent::_getFormValues($model); - foreach(['description', 'contenu'] as $content_field) - $attributes[$content_field] = Class_CmsUrlTransformer::forEditing($attributes[$content_field]); - - $attributes['pick_day'] = $model->getPickDayAsArray(); - return $attributes; - } - - - protected function _findModel() { - if (!$article = Class_Article::find((int)$this->_getParam('id'))) - return null; - - if ($lang = $this->_getParam('lang')) - return $article->getOrCreateTraductionLangue($lang); - - return $article; - } - - - protected function _getForm($model) { - $this - ->_definitions - ->setFormClassName($model->isTraduction() - ? 'ZendAfi_Form_Admin_NewsTranslation' - : 'ZendAfi_Form_Admin_News'); - $form = parent::_getForm($model); - $form->setAttrib('data-backurl', Class_Url::absolute($this->_backUrl($model))); - return $form; - } - - - protected function _backUrl($model) { - if (!Class_AdminVar::isArticlesListMode()) - return 'admin/cms/index' . (!$model->isNew() ? '/id/' . $model->getId() : ''); - - return $this->view->absoluteUrl(['module' => 'admin', - 'controller' => 'cms', - 'action' => 'index']); - } - - - protected function _backDeleteUrl($model) { - return sprintf('admin/cms/index/id_cat/%d%s', - ($cat = $model->getCategorie()) ? $cat->getId() : 0, - ($page = $this->_getParam('page')) ? '/page/'.$page : ''); - } - - - protected function _getEditActionTitle($model) { - $template = $model->isTraduction() - ? "Traduire un article: %s" - : "Modifier un article: %s"; - - return $this->_($template, $model->getLibelle()); - } - - - protected function _canAdd() { - $category = Class_ArticleCategorie::find($this->_getParam('id_cat')); - return $category && $this->_canModify($category); - } - - - protected function _canEdit($model) { - $this->_setParam('id_cat',null); - return $this->_canModify($model->getCategorie()); - } - - - protected function _getDefaultModel($models) { - $article = $this->_definitions->newModel(); - $cat = Class_ArticleCategorie::findDistinctCategories($models); - if (count($cat)==1) { - $article->setCategorie($cat[0]); - } - - $status = Class_Article::findDistinctStatus($models); - if (count($status)==1) { - $article->setStatus($status[0]->getStatus()); - } - - return $article; - } - - - - protected function _canModify($category) { - return $this->identity - ->hasAnyPermissionOn($category, - [Class_Permission::createArticle(), - Class_Permission::createArticleCategory()]); - } - - - protected function _getEditUrl($model) { - $this->getRequest()->setParamSources(['_GET']); - $url = parent::_getEditUrl($model) - . (($page = $this->_getParam('page')) ? '/page/'.$page : '') - . (($id_cat = $this->_getParam('id_cat')) ? '/id_cat/'.$id_cat : '') - . (($title_search = $this->_getParam('title_search')) ? '/title_search/' . $title_search : ''); - $this->getRequest()->setParamSources(['_GET', '_POST']); - return $url; - } } ?> \ No newline at end of file diff --git a/application/modules/admin/controllers/CustomFieldsController.php b/application/modules/admin/controllers/CustomFieldsController.php index 9ddabcc706c309aed4632e92e857016a86c0a879..6973ceea4875cb96ba4fe2d9def7ef3063208911 100644 --- a/application/modules/admin/controllers/CustomFieldsController.php +++ b/application/modules/admin/controllers/CustomFieldsController.php @@ -21,24 +21,9 @@ class Admin_CustomFieldsController extends ZendAfi_Controller_Action { - public function getRessourceDefinitions() { - return [ - 'model' => [ - 'class' => 'Class_CustomField', - 'name' => 'custom_fields', - 'order' => 'id', - 'scope' => 'model'], - - 'messages' => [ - 'successful_save' => $this->_('Champ personnalisé "%s" sauvegardé'), - 'successful_add' => $this->_('Champ personnalisé "%s" ajouté')], - - 'actions' => [ - 'add' => ['title' => $this->_('Nouveau champ personnalisé')], - 'edit' => ['title' => $this->_('Modifier un champ personnalisé')], - 'index' => ['title' => $this->_('Champs personnalisés')]], - - 'form_class_name' => 'ZendAfi_Form_Admin_CustomFields_CustomFieldModel']; + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_CustomField', + 'ZendAfi_Controller_Plugin_Manager_CustomField']; } @@ -50,23 +35,6 @@ class Admin_CustomFieldsController extends ZendAfi_Controller_Action { } - public function addAction() { - $model = $this->_getParam('model'); - $this->view->form = ZendAfi_Form_Admin_CustomFields_CustomFieldModel::newWith([ 'model' => $model]); - - $this->view->custom_fields_metas = Class_CustomField::getAvailableMeta($model); - - parent::addAction(); - } - - - public function deleteAction() { - if ($field = Class_CustomField::find($this->_getParam('id', 0))) - $this->_setParam('model', $field->getModel()); - parent::deleteAction(); - } - - public function selectAction() { $this->_helper->viewRenderer->setNoRender(); diff --git a/application/modules/admin/controllers/CustomFieldsMetaController.php b/application/modules/admin/controllers/CustomFieldsMetaController.php index 0408445d8941ce96db40fff1c6385031d1d3d161..e6bcbc0d1581fb3fa172de57f75073c8930321df 100644 --- a/application/modules/admin/controllers/CustomFieldsMetaController.php +++ b/application/modules/admin/controllers/CustomFieldsMetaController.php @@ -21,20 +21,10 @@ class Admin_CustomFieldsMetaController extends ZendAfi_Controller_Action { - public function getRessourceDefinitions() { - return ['model' => ['class' => 'Class_CustomField_Meta', - 'name' => 'custom_fields_meta', - 'order' => 'label'], - 'messages' => ['successful_save' => $this->_('Champ personnalisé %s sauvegardé'), - 'successful_add' => $this->_('Champ personnalisé %s ajouté'), - 'successful_delete' => $this->_('Champ personnalisé %s supprimé')], - - 'actions' => ['add' => ['title' => $this->_('Nouveau champ personnalisé')], - 'edit' => ['title' => $this->_('Modifier un champ personnalisé')], - 'index' => ['title' => $this->_('Champs personnalisés')]], - - 'form_class_name' => 'ZendAfi_Form_Admin_CustomFields']; + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_CustomFieldMeta', + 'ZendAfi_Controller_Plugin_Manager_Manager']; } } ?> \ No newline at end of file diff --git a/application/modules/admin/controllers/CustomFieldsReportController.php b/application/modules/admin/controllers/CustomFieldsReportController.php index 846bc13ba90085afe00840114402bceefbf08c12..b138e60c8c58b3466e768174748a69b9d27546ab 100644 --- a/application/modules/admin/controllers/CustomFieldsReportController.php +++ b/application/modules/admin/controllers/CustomFieldsReportController.php @@ -21,24 +21,10 @@ class Admin_CustomFieldsReportController extends ZendAfi_Controller_Action { - public function getRessourceDefinitions() { - return [ - 'model' => ['class' => 'Class_Report', 'name' => 'report', 'order' => 'label'], - 'messages' => ['successful_save' => $this->_('Rapport %s modifié')], - - 'actions' => [ - 'add' => ['title' => $this->_('Nouveau rapport')], - 'edit' => ['title' => $this->_('Modification du rapport: %s')], - 'index' => ['title' => $this->_('Rapports')]], - - 'form_class_name' => 'ZendAfi_Form_Report' - ]; - } - - public function addAction() { - parent::addAction(); - $this->render('edit'); + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_Report', + 'ZendAfi_Controller_Plugin_Manager_CustomFieldsReport']; } @@ -53,5 +39,4 @@ class Admin_CustomFieldsReportController extends ZendAfi_Controller_Action { $this->_forward('index'); } -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/application/modules/admin/controllers/ExternalAgendasController.php b/application/modules/admin/controllers/ExternalAgendasController.php index 5d2a47e3d4820f1191a0a204427b05d69c5ad11d..aafcc27049c012cf1521cac53f5a6800ab034db9 100644 --- a/application/modules/admin/controllers/ExternalAgendasController.php +++ b/application/modules/admin/controllers/ExternalAgendasController.php @@ -21,27 +21,12 @@ class Admin_ExternalAgendasController extends ZendAfi_Controller_Action { - public function getRessourceDefinitions() { - return - [ - 'model' => ['class' => 'Class_ExternalAgenda', - 'name' => 'agenda', - 'order' => 'label'], - - 'actions' => ['index' => ['title' => $this->_('Gestion des agendas externes')], - 'add' => ['title' => $this->_('Ajouter un nouvel agenda')], - 'edit' => ['title' => $this->_('Modifier un agenda')]], - - 'messages' => ['successful_add' => $this->_('Agenda %s ajouté'), - 'successful_save' => $this->_('Agenda %s modifié'), - 'successful_delete' => $this->_('Agenda %s supprimé')], - - 'form_class_name' => 'ZendAfi_Form_Admin_ExternalAgenda', - ]; + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_ExternalAgenda', + 'ZendAfi_Controller_Plugin_Manager_Manager']; } - public function importAction() { if (!$agenda = Class_ExternalAgenda::find($this->_getParam('id'))) return $this->_redirectToIndex(); diff --git a/application/modules/admin/controllers/FormationController.php b/application/modules/admin/controllers/FormationController.php index c8a0af63021ede06050125766c4b4adb3948bc2e..1a5bd1690b696bba4dcc80ed680466112f2c6845 100644 --- a/application/modules/admin/controllers/FormationController.php +++ b/application/modules/admin/controllers/FormationController.php @@ -19,26 +19,13 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class Admin_FormationController extends ZendAfi_Controller_Action { - public function getRessourceDefinitions() { - return [ - 'model' => [ - 'class' => 'Class_Formation', - 'name' => 'formation', - 'order' => 'id'], - - 'messages' => [ - 'successful_save' => $this->_('Formation "%s" sauvegardée'), - 'successful_add' => $this->_('La formation "%s" a été sauvegardée'), - 'successful_delete' => $this->_('Formation "%s" supprimée')], - - 'actions' => [ - 'add' => ['title' => $this->_("Ajouter une formation")], - 'edit' => ['title' => $this->_("Modifier la formation: %s")]], - - 'form_class_name' => 'ZendAfi_Form_Admin_Formation', - 'after_add' => function($formation) { $this->_redirect('/admin/session-formation/add/formation_id/' . $formation->getId());} ]; + + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_Formation', + 'ZendAfi_Controller_Plugin_Manager_Manager']; } + protected function setYearsForCombo() { $years = Class_SessionFormation::getYears(); diff --git a/application/modules/admin/controllers/FrbrLinkController.php b/application/modules/admin/controllers/FrbrLinkController.php index fe544d16b3b864955395d60f5e2d6db24e9c80dc..a45fd69800030435c403722e4c000318bc760400 100644 --- a/application/modules/admin/controllers/FrbrLinkController.php +++ b/application/modules/admin/controllers/FrbrLinkController.php @@ -20,21 +20,9 @@ */ class Admin_FrbrLinkController extends ZendAfi_Controller_Action { - public function getRessourceDefinitions() { - return [ - 'model' => ['class' => 'Class_FRBR_Link', - 'name' => 'relation', - 'order' => 'source'], - 'messages' => ['successful_save' => $this->_('Relation sauvegardée'), - 'successful_add' => $this->_('Relation ajoutée'),], - - 'actions' => ['add' => ['title' => $this->_('Nouvelle relation')], - 'edit' => ['title' => $this->_('Modifier une relation')], - 'index' => ['title' => $this->_('Notices liées')]], - - 'form' => (new ZendAfi_Form_FRBR_Link())]; + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_FRBRLink', + 'ZendAfi_Controller_Plugin_Manager_Manager']; } } - -?> \ No newline at end of file diff --git a/application/modules/admin/controllers/FrbrLinktypeController.php b/application/modules/admin/controllers/FrbrLinktypeController.php index 2a306945fee6782e09f60fb2f17cd2346f9f8e77..5f4c05d0241fa1c35605ae8e7cf052b1333b3158 100644 --- a/application/modules/admin/controllers/FrbrLinktypeController.php +++ b/application/modules/admin/controllers/FrbrLinktypeController.php @@ -20,20 +20,9 @@ */ class Admin_FrbrLinktypeController extends ZendAfi_Controller_Action { - public function getRessourceDefinitions() { - return [ - 'model' => ['class' => 'Class_FRBR_LinkType', - 'name' => 'relation', - 'order' => 'libelle'], - 'messages' => ['successful_save' => $this->_('Type de relation "%s" sauvegardé'),], - - 'actions' => ['add' => ['title' => $this->_('Nouveau type de relation')], - 'edit' => ['title' => $this->_('Modifier un type de relation')], - 'index' => ['title' => $this->_('Types de relation')]], - - 'form' => (new ZendAfi_Form_FRBR_LinkType())]; + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_FRBRLinkType', + 'ZendAfi_Controller_Plugin_Manager_Manager']; } -} - -?> \ No newline at end of file +} \ No newline at end of file diff --git a/application/modules/admin/controllers/LieuController.php b/application/modules/admin/controllers/LieuController.php index 2a68bdd5a31f9db2f0bdca927c7003f6cd7be2c8..5948970087cddff65053e6ecd12b68787df70d6f 100644 --- a/application/modules/admin/controllers/LieuController.php +++ b/application/modules/admin/controllers/LieuController.php @@ -20,51 +20,13 @@ */ class Admin_LieuController extends ZendAfi_Controller_Action { - public function getRessourceDefinitions() { - return ['model' => ['class' => 'Class_Lieu', - 'name' => 'lieu', - 'order' => 'libelle'], - - 'messages' => ['successful_save' => $this->_('Lieu "%s" sauvegardé'), - 'successful_add' => $this->_('le lieu "%s" a été créé'), - 'successful_delete' => $this->_('Lieu "%s" supprimé')], - - 'actions' => ['index' => ['title' => $this->_('Lieux')], - 'add' => ['title' => $this->_('Déclarer un nouveau lieu')], - 'edit' => ['title' => $this->_('Modifier le lieu "%s"')], - 'delete' => ['title' => $this->_('Supprimer le lieu "%s"')]], - - 'form_class_name' => 'ZendAfi_Form_Admin_Location']; - } - - - protected function _doBeforeSave($model) { - $model->updateCoordinates($this->_getOsmService()); - return $this; + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_Lieu', + 'ZendAfi_Controller_Plugin_Manager_Lieu']; } - 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/application/modules/admin/controllers/MultimediaController.php b/application/modules/admin/controllers/MultimediaController.php index e590edb3e4067f0fa20cffc46d06598365cc162b..34a7aaf07fa1d7e1c1477501b645b7ecbce61dd5 100644 --- a/application/modules/admin/controllers/MultimediaController.php +++ b/application/modules/admin/controllers/MultimediaController.php @@ -20,109 +20,9 @@ */ class Admin_MultimediaController extends ZendAfi_Controller_Action { - public function getRessourceDefinitions() { - - return [ - 'model' => ['class' => 'Class_Multimedia_Location', 'name' => 'site'], - - 'messages' => ['successful_save' => 'Site %s sauvegardé'], - - 'actions' => ['edit' => ['title' => 'Modifier un site multimédia'], - 'index' => ['title' => 'Sites multimédia']], - - 'display_groups' => ['localisation' => ['legend' => 'Localisation', - 'elements' => $this->getLocalisationFields()], - - 'config' => ['legend' => 'Réservation', - 'elements' => $this->getConfigFields()], - - 'config_auto' => ['legend' => 'Réservation automatique', - 'elements' => $this->getConfigAutoFields()] - ] - ]; - } - - - public function getLocalisationFields() { - $libelles = []; - foreach (Class_Bib::findAllBy(['order' => 'libelle']) as $bib) - $libelles[$bib->getId()] = $bib->getLibelle(); - - return ['id_site' => ['element' => 'select', - 'options' => ['multioptions' => $libelles]]]; - } - - - public function getConfigFields() { - return ['slot_size' => ['element' => 'text', - 'options' => ['label' => 'Durée d\'un créneau (en minutes)', - 'title'=> 'en minutes', - 'size' => 4, - 'required' => true, - 'allowEmpty' => false, - 'validators' => ['digits']]], - - 'max_slots' => ['element' => 'text', - 'options' => ['label' => 'Nombre maximum de créneaux réservables simultanément', - 'title' => 'en nombre de "slots"', - 'size' => 4, - 'required' => true, - 'allowEmpty' => false, - 'validators' => ['digits']]], - - 'hold_delay_min' => ['element' => 'text', - 'options' => ['label' => 'Nombre de jours au plus tard avant une réservation<br/> (0 pour résa le -jour même)', - 'title' => 'en jours, 0 autorise les réservations le jour même', - 'size' => 4, - 'required' => true, - 'allowEmpty' => false, - 'validators' => ['digits']]], - - 'hold_delay_max' => ['element' => 'text', - 'options' => [ - 'label' => 'Nombre de jours au plus tôt avant une réservation<br/>(1 pour autoriser -les réservations pour le lendemain)', - 'title' => 'en jours, doit être supérieur au délai minimum', - 'size' => 4, - 'required' => true, - 'allowEmpty' => false, - 'validators' => ['digits', new ZendAfi_Validate_FieldGreater('hold_delay_min', 'Délai minimum de réservation')]]], - - 'auth_delay' => ['element' => 'text', - 'options' => ['label' => 'Délai de connexion avant d\'annuler une réservation (en minutes)', - 'title' => 'en minutes, passé ce délai la réservation est annulée', - 'size' => 4, - 'required' => true, - 'allowEmpty' => false, - 'validators' => ['digits']]]]; - } - - - public function getConfigAutoFields() { - return [ - 'autohold' => ['element' => 'checkbox', - 'options' => ['label' => 'Générer automatiquement une réservation à la connexion à un poste -disponible', - 'title' => 'quand un abonné se connecte sur un poste non réservé, une réservation lui est attribuée', - 'required' => true, - 'allowEmpty' => false]], - - 'autohold_min_time' => ['element' => 'text', - 'options' => ['label' => 'Temps minimum de connexion avant la réservation suivante (en minutes)', - 'title' => 'quand un abonné se connecte et qu\'une réservation est prévue dans quelques minutes, permet de définir si la réservation automatique peut s\'effectuer', - 'size' => 4, - 'required' => true, - 'allowEmpty' => false, - 'validators' => ['digits']]], - - 'autohold_slots_max' => ['element' => 'text', - 'options' => ['label' => 'Durée de la réservation automatique (en nombre de créneaux)', - 'title' => 'en nombre de "slots"', - 'size' => 4, - 'required' => true, - 'allowEmpty' => false, - 'validators' => ['digits']]]]; + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_Multimedia', + 'ZendAfi_Controller_Plugin_Manager_Multimedia']; } @@ -140,23 +40,6 @@ disponible', } - protected function _postEditAction($model) { - $this->view->titre = 'Modification du site multimédia "' . $this->view->escape($model->getLibelle()) . '"'; - } - - - /** Les données viennent d'un serveur multimédia, pas de suppression */ - public function deleteAction() { - $this->_redirect('/admin/multimedia'); - } - - - /** Les données viennent d'un serveur multimédia, pas d'ajout */ - public function addAction() { - $this->_redirect('/admin/multimedia'); - } - - /** Affiche les réservations d'un device*/ public function holdsAction() { if (!$device = Class_Multimedia_Device::find($this->_getParam('id'))) { diff --git a/application/modules/admin/controllers/NewsletterController.php b/application/modules/admin/controllers/NewsletterController.php index 95fddc32a97a5af45ae265faeb4f4b4030c0e353..38f0ba45bdcc24fe5542097557efcbcd765a04df 100644 --- a/application/modules/admin/controllers/NewsletterController.php +++ b/application/modules/admin/controllers/NewsletterController.php @@ -22,92 +22,10 @@ class Admin_NewsletterController extends ZendAfi_Controller_Action { const SESSION_NAMESPACE = 'Admin_NewsletterController'; - public function getRessourceDefinitions() { - return ['model' => ['class' => 'Class_Newsletter', - 'name' => 'newsletter', - 'order' => 'titre'], - 'actions' => ['index' => ['title' => $this->_('Lettres d\'information')], - 'add' => ['title' => $this->_('Créer une lettre d\'information')], - 'edit' => ['title' => $this->_('Modifier une lettre d\'information : %s')]], - - 'messages' => ['successful_save' => $this->_('Lettre d\'information "%s" enregistrée'), - 'successful_delete' => $this->_('Lettre d\'information supprimée')], - - 'form_class_name' => 'ZendAfi_Form_Admin_Newsletter', - - 'model_actions' => [ - ['action' => 'edit', 'content' => $this->view->boutonIco('type=edit')], - ['action' => 'preview', 'content' => $this->view->boutonIco('type=show')], - ['action' => 'edit-subscribers', - 'content' => function($model) { - return $this->view->tag('span', $this->view->boutonIco("picto=users", "bulle=" . $this->_('Inscrits')) . $model->getNumberOfUsers(), ['style' => 'white-space:nowrap']); - }], - ['action' => 'sendtest', 'content' => $this->view->boutonIco('type=test')], - ['action' => 'send', - 'content' => function($model) { - Class_ScriptLoader::getInstance()->addJQueryReady(" -function sendNewsletterClick(event) { - var target = $(event.target).closest('a'); - var answer = confirm(\"".$this->_("Envoyer la lettre d'information ?")."\"); - if (answer == false) { - event.preventDefault(); - return; - } -} - - $(\"a[rel='send']\").click(sendNewsletterClick); -"); - - - return $this->view->boutonIco('type=mail');}], - ['action' => 'duplicate', 'content' => $this->view->boutonIco('type=duplicate')], - ['action' => 'delete', 'content' => $this->view->boutonIco('type=del')], - ], - ]; - } - - - public function duplicateAction() { - $this->_redirectToIndex(); - - if (!$newsletter = Class_Newsletter::find($this->_getParam('id'))) { - $this->_helper->notify($this->_('Duplication impossible: la source n\'a pas été trouvée.')); - return; - } - - if (!$newsletter->duplicate()) - $this->_helper->notify($this->_('Duplication impossible: Erreur lors de l\'enregisrement de la copie.')); - } - - - public function editSubscribersAction() { - if (!$model = Class_Newsletter::find($this->_getParam('id'))) { - $this->_redirectToIndex(); - return; - } - - $this->_addModelToView($model); - - if ($user = Class_Users::find($this->_getParam('unsubscribe',0))) - $model->unsubscribeUser($user); - - - if ($user = Class_Users::find($this->_getParam('subscribe',0))) - $model->subscribeUser($user); - - - $this->view->titre = $this->_('Destinataires de la lettre : %s', - $model->getTitre()); - - $this->view->newsletter = $model; - $this->view->groups = $model->getSortedRecipientsByDedicatedAndLabel(); - - $criteria = (new Class_User_SearchCriteria($this->_request->getParams())) - ->addCriteria(new Class_User_SearchCriteria_NewsletterSubscriptionStatus($this->_request->getParams())) - ->addCriteria(new Class_User_SearchCriteria_WithMail($this->_request->getParams())); - - $this->_helper->userSearch(['id' => $model->getId()], $criteria); + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_Newsletter', + 'ZendAfi_Controller_Plugin_Manager_Newsletter']; } @@ -158,8 +76,6 @@ function sendNewsletterClick(event) { } } - $this->_addModelToView($newsletter); - $this->view->titre = $this->_('Tester l\'envoi de la lettre : %s', $newsletter->getLibelle()); $this->view->form = $form; } @@ -191,92 +107,6 @@ function sendNewsletterClick(event) { } - public function previewAction() { - if (!$newsletter = Class_Newsletter::find((int)$this->_getParam('id'))) { - $this->_redirectToIndex(); - return; - } - - $this->_addModelToView($newsletter); - - $template = Class_Newsletter_Dispatch::newFrom($newsletter)->getTemplate(); - $mock_user = new Class_Entity(); - $mock_user->setId(0)->setMail(''); - - $this->view->titre = $this->_('Aperçu de la lettre : %s', $newsletter->getLibelle()); - $this->view->mail = $template->mailFor($mock_user); - } - - - public function addGroupAction() { - if (!$model = Class_Newsletter::find((int)$this->_getParam('id'))) { - $this->_redirectToIndex(); - return; - } - - $this->view->titre = $this->_('Groupes destinataires'); - - $ids = array_map(function($group) { return $group->getId(); }, - $model->getUserGroups()); - $value = implode('-', $ids); - - $form = ZendAfi_Form::newWithOptions(['action' => $this->view->url(), - 'method' => Zend_Form::METHOD_POST]) - - ->addElement('userGroup', 'subscribe_group_ids', - ['label' => '', - 'categories_selectable' => false, - 'url' => $this->view->url(['module' => 'admin', - 'controller' => 'usergroup', - 'action' => 'list.json']), - 'value' => $value]) - - ->addDisplayGroup(['subscribe_group_ids'], - 'groups', - ['legend' => $this->_('Groupes destinataires')]); - - if ($this->_request->isPost() - && $form->isValid($this->_request->getPost())) { - $ids = explode('-', $this->_getParam('subscribe_group_ids', '')); - $mapper = function($id) { - return Class_UserGroup::find((int)$id); - }; - - $model - ->setUserGroups(array_filter(array_map($mapper, $ids))) - ->save(); - - $this->_redirectClose($this->view->url(['module' => 'admin', - 'controller' => 'newsletter', - 'action' => 'edit-subscribers', - 'id' => $model->getId()], null, true), - ['prependBase' => false]); - return; - } - - - $this->view->form = $form; - } - - - public function removeGroupAction() { - if (!$model = Class_Newsletter::find($this->_getParam('newsletter_id'))) { - $this->_redirectToIndex(); - return; - } - - $subscription = Class_NewsletterGroupSubscription::findFirstBy(['newsletter_id' => $model->getId(), - 'user_group_id' => (int)$this->_getParam('id')]); - - if ($subscription && !$subscription->hasDedicatedGroup()) - $subscription->delete(); - - $this->_redirect($this->view->url(['module' => 'admin', - 'controller' => 'newsletter', - 'action' => 'edit-subscribers', - 'id' => $model->getId()], null, true), - ['prependBase' => false]); - } public function showStatusAction() { diff --git a/application/modules/admin/controllers/OaiController.php b/application/modules/admin/controllers/OaiController.php index 66ef422f546230c8fc3faa1fe8c922f8656c8be1..86825002f858185554ed1ab2be05836c6cc6aba7 100644 --- a/application/modules/admin/controllers/OaiController.php +++ b/application/modules/admin/controllers/OaiController.php @@ -19,40 +19,11 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class Admin_OaiController extends ZendAfi_Controller_Action { - public function getRessourceDefinitions() { - return array( - 'model' => array('class' => 'Class_EntrepotOAI', - 'name' => 'entrepot'), - 'messages' => array('successful_add' => 'Entrepôt %s ajouté', - 'successful_save' => 'Entrepôt %s sauvegardé', - 'successful_delete' => 'Entrepôt %s supprimé'), - - 'actions' => array('edit' => array('title' => 'Modifier un entrepôt OAI'), - 'add' => array('title' => 'Ajouter un entrepôt OAI'), - 'index' => array('title' => 'Entrepôts OAI')), - - 'display_groups' => array('categorie' => array('legend' => 'Entrepôt', - 'elements' => array( - 'libelle' => array('element' => 'text', - 'options' => array('label' => 'Libellé *', - 'size' => 30, - 'required' => true, - 'allowEmpty' => false)), - 'handler' => array('element' => 'text', - 'options' => array('label' => 'Url *', - 'size' => '90', - 'required' => true, - 'allowEmpty' => false, - 'validators' => array('url')) - ) - ) - ) - ) - ); + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_OAI', + 'ZendAfi_Controller_Plugin_Manager_Manager']; } - - public function indexAction() { parent::indexAction(); if ($expression_recherche = $this->_getParam('expression')) { diff --git a/application/modules/admin/controllers/OpdsController.php b/application/modules/admin/controllers/OpdsController.php index dee693cfabf7dae3aa4c2896d1178a200c2b3c28..1e985c10da2a773ad104bf8e95a47b5f2d146bb3 100644 --- a/application/modules/admin/controllers/OpdsController.php +++ b/application/modules/admin/controllers/OpdsController.php @@ -16,40 +16,14 @@ * * 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 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class Admin_OpdsController extends ZendAfi_Controller_Action { - public function getRessourceDefinitions() { - return array( - 'model' => array('class' => 'Class_OpdsCatalog', - 'name' => 'catalog'), - 'messages' => array('successful_add' => 'Catalogue %s ajouté', - 'successful_save' => 'Catalogue %s sauvegardé', - 'successful_delete' => 'Catalogue %s supprimé'), - - 'actions' => array('edit' => array('title' => 'Modifier un catalogue OPDS'), - 'add' => array('title' => 'Ajouter un catalogue OPDS'), - 'index' => array('title' => 'Catalogues OPDS')), - - 'display_groups' => array('categorie' => array('legend' => 'Catalogue', - 'elements' => array( - 'libelle' => array('element' => 'text', - 'options' => array('label' => 'Libellé *', - 'size' => 30, - 'required' => true, - 'allowEmpty' => false)), - 'url' => array('element' => 'text', - 'options' => array('label' => 'Url *', - 'size' => 75, - 'required' => true, - 'allowEmpty' => false, - 'validators' => array('url')) - ) - ) - ) - ) - ); + + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_OPDS', + 'ZendAfi_Controller_Plugin_Manager_Manager']; } diff --git a/application/modules/admin/controllers/OuverturesController.php b/application/modules/admin/controllers/OuverturesController.php index ae316bec745e81a8fcaea08c395a252e8f8d3fa2..d89e451598c0aa1742ae1e7201d81320bbe3ba75 100644 --- a/application/modules/admin/controllers/OuverturesController.php +++ b/application/modules/admin/controllers/OuverturesController.php @@ -22,63 +22,46 @@ class Admin_OuverturesController extends ZendAfi_Controller_Action { protected $_library, $_is_multimedia = false; - public function preDispatch() { - if ((!$this->_library = Class_Bib::find($this->_getParam('id_site'))) + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_Opening', + 'ZendAfi_Controller_Plugin_Manager_Opening']; + } + + + public function init() { + if ((!$this->_library = $this->_getLibrary()) || ($this->_getParam('multimedia') && !Class_AdminVar::isMultimediaEnabled())) { $this->_redirect('/admin/bib'); return; } - $this->_is_multimedia = null !== $this->_getParam('multimedia'); - parent::preDispatch(); + $this->_is_multimedia = $this->_isMultimedia(); + parent::init(); } - public function getRessourceDefinitions() { - return ['model' => ['class' => 'Class_Ouverture', - 'name' => 'ouverture', - 'scope' => ['id_site', 'multimedia'], - 'order' => 'jour desc, jour_semaine, validity_start'], - - 'sort' => ['Class_Ouverture', 'compare'], - - 'messages' => $this->_getRessourceMessages(), - - 'after_add' => function($model) { $this->_redirectToIndex(); }, - 'after_edit' => function($model) { $this->_redirectToIndex(); }, - - 'actions' => $this->_getRessourceActions(), - - 'form' => new ZendAfi_Form_Admin_Ouverture()]; - + protected function _getLibrary() { + return Class_Bib::find($this->_getParam('id_site')); } - protected function _getRessourceMessages() { - $lib_label = $this->_library->getLibelle(); - - return $this->_is_multimedia - ? ['successful_add' => $this->_('Plage horaire de réservation multimedia %s ajoutée', $lib_label), - 'successful_save' => $this->_('Plage horaire de réservation multimedia %s sauvegardée', $lib_label), - 'successful_delete' => $this->_('Plage horaire de réservation multimedia %s supprimée', $lib_label)] - - : ['successful_add' => $this->_('Plage d\'ouverture %s ajoutée', $lib_label), - 'successful_save' => $this->_('Plage d\'ouverture %s sauvegardée', $lib_label), - 'successful_delete' => $this->_('Plage d\'ouverture %s supprimée', $lib_label)]; + protected function _isMultimedia() { + return null !== $this->_getParam('multimedia'); } - protected function _getRessourceActions() { - $lib_label = $this->_library->getLibelle(); - - return $this->_is_multimedia - ? ['edit' => ['title' => $this->_('%s : modifier une plage horaire de réservation multimedia', $lib_label)], - 'add' => ['title' => $this->_('%s : ajouter une plage horaire de réservation multimedia', $lib_label)], - 'index' => ['title' => $this->_('%s : plages horaire de réservation multimedia', $lib_label)]] - - : ['edit' => ['title' => $this->_('%s : modifier une plage d\'ouverture', $lib_label)], - 'add' => ['title' => $this->_('%s : ajouter une plage d\'ouverture', $lib_label)], - 'index' => ['title' => $this->_('%s : plages d\'ouverture', $lib_label)]]; + public function acceptVisitor($visitor) { + parent::acceptVisitor($visitor); + $visitor + ->visitLibrary(function() + { + return $this->_getLibrary(); + }) + ->visitIsMultimedia(function() + { + return $this->_isMultimedia(); + }); + return $this; } @@ -123,39 +106,4 @@ class Admin_OuverturesController extends ZendAfi_Controller_Action { ['label' => $this->_('Valider'), 'class' => 'button bouton']); } - - - protected function _getPost() { - $post = parent::_getPost(); - $post['id_site'] = $this->_library->getId(); - - if (Class_Ouverture::AUCUN_JOUR != $post['jour_semaine']) - $post['jour'] = null; - - $post['validity_start'] = (isset($post['validity_start'])) - ? $this->_getSQLDateFrom($post['validity_start']) - : null; - - $post['validity_end'] = isset($post['validity_end']) - ? $this->_getSQLDateFrom($post['validity_end']) - : ''; - - return $post; - } - - - protected function _getSQLDateFrom($human_date) { - $date = implode('-', array_reverse(explode('/', $human_date))); - return strtotime($date) > 0 - ? $date - : null; - } - - - protected function _updateNewModel($model) { - if($this->_is_multimedia) - $model->setMultimedia(1); - - return $this; - } } diff --git a/application/modules/admin/controllers/PrintController.php b/application/modules/admin/controllers/PrintController.php index f629b6f9c1e35ca57c939e25514817fed21e2e69..bedc2dfd14265cb6952bee469bcef4da8d937226 100644 --- a/application/modules/admin/controllers/PrintController.php +++ b/application/modules/admin/controllers/PrintController.php @@ -21,26 +21,9 @@ class Admin_PrintController extends ZendAfi_Controller_Action { - public function getRessourceDefinitions() { - return [ - 'model' => [ - 'class' => 'Class_ModeleFusion', - 'name' => 'modele_fusion', - 'order' => 'id'], - - 'messages' => [ - 'successful_save' => $this->_('Modèle "%s" sauvegardé'), - 'successful_add' => $this->_('Le modèle "%s" a été sauvegardé'), - 'successful_delete' => $this->_('Modèle "%s" supprimé')], - - 'actions' => [ - 'add' => ['title' => $this->_("Ajouter un modèle")], - 'edit' => ['title' => $this->_("Modifier le modèle: %s")]], - - 'form_class_name' => 'ZendAfi_Form_ModeleFusion', - - 'after_delete' => function() { $this->_redirect('/admin/print/index');} - ]; + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_ModeleFusion', + 'ZendAfi_Controller_Plugin_Manager_Manager']; } diff --git a/application/modules/admin/controllers/SessionFormationController.php b/application/modules/admin/controllers/SessionFormationController.php index 32136c3a705fd12102a5129321b902116f16843b..d9146ba8da2ddc55db3b9871335a251e8ac1616e 100644 --- a/application/modules/admin/controllers/SessionFormationController.php +++ b/application/modules/admin/controllers/SessionFormationController.php @@ -19,28 +19,9 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class Admin_SessionFormationController extends ZendAfi_Controller_Action { - public function getRessourceDefinitions() { - return [ - 'model' => [ - 'class' => 'Class_SessionFormation', - 'name' => 'session_formation', - 'order' => 'id'], - - 'messages' => [ - 'successful_save' => $this->_('Session "%s" sauvegardée'), - 'successful_add' => $this->_('La session "%s" a été sauvegardée'), - 'successful_delete' => $this->_('Session "%s" supprimée')], - - 'actions' => [ - 'add' => ['title' => $this->_("Ajouter une session")], - 'edit' => ['title' => $this->_("Modifier la session: %s")]], - - 'form_class_name' => 'ZendAfi_Form_Admin_SessionFormation', - - 'after_delete' => function($model) { $this->_redirect('/admin/formation/index');}, - - 'after_add' => function($session) { $this->afterAdd($session); } - ]; + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_SessionFormation', + 'ZendAfi_Controller_Plugin_Manager_SessionFormation']; } @@ -56,45 +37,6 @@ class Admin_SessionFormationController extends ZendAfi_Controller_Action { } - - - public function _getPost() { - $post = parent::_getPost(); - foreach(['date_debut', 'date_fin', 'date_limite_inscription'] as $field) - $post[$field] = $this->_readPostDate($this->_request->getPost($field)); - return $post; - } - - - protected function _readPostDate($date) { - return implode('-', array_reverse(explode('/', $date))); - } - - - public function addAction() { - if (!$formation = Class_Formation::find($this->_getParam('formation_id'))) { - $this->_redirect('admin/formation'); - return; - } - - parent::addAction(); - - $this->view->titre = sprintf('Nouvelle session de la formation "%s"', - $formation->getLibelle()); - } - - - public function afterAdd($session) { - Class_Formation::find($this->_getParam('formation_id'))->addSession($session)->save(); - } - - - protected function _updateNewModel($model) { - $model->setFormation(Class_Formation::find($this->_getParam('formation_id'))); - return $this; - } - - protected function _redirectToIndex() { $this->_redirect('/admin/formation/index'); } @@ -273,7 +215,6 @@ class Admin_SessionFormationController extends ZendAfi_Controller_Action { } - public function showAction() { $this->_sessionDoAndNotify('show', 'La session "%s" est visible'); } diff --git a/application/modules/admin/controllers/SitoController.php b/application/modules/admin/controllers/SitoController.php index 165ba6d39b4a2d9c330fbe02372bca7f576e0501..947544dbc75ee57f99354d89fad13f89c7e8ff9c 100644 --- a/application/modules/admin/controllers/SitoController.php +++ b/application/modules/admin/controllers/SitoController.php @@ -21,42 +21,9 @@ class Admin_SitoController extends ZendAfi_Controller_Action { - - public function getRessourceDefinitions() { - return [ - 'model' => [ - 'class' => 'Class_Sitotheque', - 'name' => 'sitotheque', - 'order' => 'id', - 'scope' => 'id_cat'], - - 'messages' => [ - 'successful_save' => $this->_('Site "%s" sauvegardé'), - 'successful_add' => $this->_('Le site "%s" a été sauvegardé'), - 'successful_delete' => $this->_('Site "%s" supprimé')], - - 'actions' => [ - 'add' => ['title' => $this->_("Ajouter un site")], - 'edit' => ['title' => $this->_("Modifier le site: %s")], - 'delete' => ['title' => $this->_("Supprimer le site: %s")] - ], - - 'form_class_name' => 'ZendAfi_Form_Admin_Sitotheque']; - } - - - - protected function _updateNewModel($sitotheque) { - if (!$category = Class_SitothequeCategorie::find($this->_getParam('id_cat'))) { - $this->_redirect('admin/sito'); - return; - } - - $sitotheque->setCategorie($category); - if ($domaine = Class_Catalogue::findWithSamePathAs($category)) - $sitotheque->setDomaineIds($domaine->getId()); - - return $this; + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_Sitotheque', + 'ZendAfi_Controller_Plugin_Manager_Sitotheque']; } @@ -189,105 +156,4 @@ class Admin_SitoController extends ZendAfi_Controller_Action { ] ]; } - - - function cataddAction() { - $this->view->titre = "Ajouter une catégorie de sites"; - - $categorie = new Class_SitothequeCategorie(); - - if ($id_site = $this->_getParam('id_bib')) - $categorie->setIdSite($id_site); - - if ($parent_categorie = Class_SitothequeCategorie::find((int)$this->_getParam('id'))) - $categorie - ->setParentCategorie($parent_categorie) - ->setIdSite($parent_categorie->getIdSite()); - - if ($this->_isCategorieSaved($categorie)) { - $this->_helper->notify($this->_('La catégorie "%s" a été ajoutée', $categorie->getLibelle())); - $this->_redirect(sprintf('admin/sito/index/id_cat/%d', $categorie->getId())); - return; - } - - $this->view->categorie = $categorie; - $this->view->combo_cat = $this->view->comboParentCategorie($categorie); - } - - - function cateditAction() { - $this->view->titre = "Modifier une catégorie de sites"; - if (!$categorie = Class_SitothequeCategorie::find((int)$this->_getParam('id'))) { - $this->_redirect('admin/sito'); - return; - } - - if ($this->_isCategorieSaved($categorie)) { - $this->_helper->notify($this->_('La catégorie "%s" a été sauvegardée', $categorie->getLibelle())); - $this->_redirect(sprintf('admin/sito/index/id_cat/%d', $categorie->getId())); - return; - } - - if (null === $categorie->getBib()) { - $categorie->setBib($this->_bib); - } - - $this->view->categorie = $categorie; - $this->view->combo_cat = $this->view->comboParentCategorie($categorie); - } - - - /** - * @param Class_SitothequeCategorie $categorie - * @return bool - */ - protected function _isCategorieSaved($categorie) { - if ($this->_request->isPost()) { - $post = $this->_request->getPost(); - $filter = new Zend_Filter_StripTags(); - $post['libelle'] = trim($filter->filter($this->_request->getPost('libelle'))); - - return $categorie - ->updateAttributes($post) - ->save(); - } - - return false; - } - - - function catdelAction() { - if (!$categorie = Class_SitothequeCategorie::find((int)$this->_getParam('id'))) { - $this->_redirect('/admin/sito'); - return; - } - - $categorie->delete(); - $this->_helper->notify($this->_('La categorie "%s" a été supprimée', $categorie->getLibelle())); - $this->_redirect('/admin/sito/index/id_cat/'.$categorie->getIdCatMere()); - } - - - protected function _canAdd() { - $category = Class_SitothequeCategorie::find($this->_getParam('id_cat')); - return $category; - } - - - protected function _getPost() { - $post = $this->_request->getPost(); - unset($post['id_items']); - return $post; - } - - - protected function _doAfterSave($model) { - $model->index(); - (new Storm_Cache())->clean(); - } - - - function sitoviewAction() { - $this->_redirect(Class_Sitotheque::find((int)$this->_getParam('id'))->getUrl()); - } } \ No newline at end of file diff --git a/application/modules/admin/controllers/SuggestionAchatController.php b/application/modules/admin/controllers/SuggestionAchatController.php index cf56eb9b6147621e48412926ad7ceec36d3975be..f0985fee4d3eec41c5b3abb25da5b750f814616e 100644 --- a/application/modules/admin/controllers/SuggestionAchatController.php +++ b/application/modules/admin/controllers/SuggestionAchatController.php @@ -20,19 +20,10 @@ */ class Admin_SuggestionAchatController extends ZendAfi_Controller_Action { - public function getRessourceDefinitions() { - return [ - 'model' => ['class' => 'Class_SuggestionAchat', - 'name' => 'suggestion', - 'order' => 'date_creation'], - 'messages' => ['successful_save' => 'Suggestion d\'achat %s sauvegardée'], - - 'actions' => ['edit' => ['title' => 'Modifier une suggestion d\'achat'], - 'index' => ['title' => 'Suggestions d\'achat']], - - 'form' => (new ZendAfi_Form_SuggestionAchat())->removeSubmitButton() ]; + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_SuggestionAchat', + 'ZendAfi_Controller_Plugin_Manager_Manager']; } } - ?> diff --git a/application/modules/admin/controllers/TypeDocsController.php b/application/modules/admin/controllers/TypeDocsController.php index 6c4cff02a115950071eb259958aa6346c0b7dea2..a17b03128ffd5aade8d289a8edd077d5b95de302 100644 --- a/application/modules/admin/controllers/TypeDocsController.php +++ b/application/modules/admin/controllers/TypeDocsController.php @@ -20,22 +20,9 @@ */ class Admin_TypeDocsController extends ZendAfi_Controller_Action { - public function getRessourceDefinitions() { - return [ - 'model' => ['class' => 'Class_TypeDoc', - 'name' => 'type_doc', - 'order' => 'libelle'], - 'messages' => ['successful_save' => $this->_('Type de document %s modifié')], - 'actions' => ['edit' => ['title' => 'Modification du type de document: %s'], - 'index' => ['title' => 'Types de documents'] - ], - 'after_edit' => function($model) {$this->_redirect('/admin/type-docs');}, - 'form' => ZendAfi_Form_TypeDocs_Edit::newWith($this->_getParam('id'))]; + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_DocType', + 'ZendAfi_Controller_Plugin_Manager_Manager']; } - - } - - -?> \ No newline at end of file diff --git a/application/modules/admin/controllers/UsergroupController.php b/application/modules/admin/controllers/UsergroupController.php index a2eef28aa8f19ad85d6fb3cc67902e655c47f2ee..e50cd14223910109ee786f7502281b9766fec4e2 100644 --- a/application/modules/admin/controllers/UsergroupController.php +++ b/application/modules/admin/controllers/UsergroupController.php @@ -22,23 +22,10 @@ class Admin_UsergroupController extends ZendAfi_Controller_Action { protected $_permissions_access; - public function getRessourceDefinitions() { - return [ - 'model' => [ - 'class' => 'Class_UserGroup', - 'name' => 'user_group', - 'order' => 'id'], - 'messages' => [ - 'successful_save' => $this->_('Groupe "%s" sauvegardé'), - 'successful_add' => $this->_('Le groupe "%s" a été sauvegardé'), - 'successful_delete' => $this->_('Groupe "%s" supprimé')], - - 'actions' => [ - 'add' => ['title' => $this->_("Ajouter un groupe d'utilisateurs")], - 'edit' => ['title' => $this->_("Modifier le groupe d'utilisateurs: %s")]], - - 'form_class_name' => 'ZendAfi_Form_Admin_UserGroup']; + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_UserGroup', + 'ZendAfi_Controller_Plugin_Manager_UserGroup']; } @@ -54,6 +41,7 @@ class Admin_UsergroupController extends ZendAfi_Controller_Action { 'action' => 'catadd', 'id' => null, 'id_cat' => null]; + $this->view->categories=[]; $this->view->categories[] = ['bib'=> $bib, @@ -69,54 +57,6 @@ class Admin_UsergroupController extends ZendAfi_Controller_Action { } - public function _updateNewModel($model) { - $model->setCategorie(Class_UserGroupCategorie::find((int)$this->_getParam('id_cat'))); - return $this; - } - - - public function editmembersAction() { - if (!$group = Class_UserGroup::find((int)$this->_getParam('id'))) { - $this->_redirect('admin/usergroup'); - return; - } - - if ($id_user_to_delete = $this->_getParam('delete')) { - $group - ->removeUser(Class_Users::find($id_user_to_delete)) - ->save(); - - $redirect_url = '/admin/usergroup/editmembers/' . (($newsletter_id = $this->_getParam('newsletter_id')) ? 'newsletter_id/' . $newsletter_id . '/': '') . 'id/'.$group->getId(); - if ($_GET) - $redirect_url .= '?'.http_build_query($_GET); - $this->_redirect($redirect_url); - return; - } - - if ($this->_request->isPost() - && ($ids_users_to_add = $this->_request->getPost('users'))) { - foreach($ids_users_to_add as $id) - $group->addUser(Class_Users::find($id)); - $group->save(); - } - - $this->view->titre = "Membres du groupe: ".$group->getLibelle(); - $this->view->group_id = $this->_getParam('id'); - $this->view->search = $this->_getParam('search'); - $this->view->page = $this->_getParam('page'); - - $this->view->back_url = ($newsletter_id = $this->_getParam('newsletter_id')) - ? $this->view->url(['module' => 'admin', - 'controller' => 'newsletter', - 'action' => 'edit-subscribers', - 'id' => $newsletter_id], - null, true) - : $this->view->url(['module' => 'admin', - 'controller' => 'usergroup'], - null, true); - } - - /** * @return array */ @@ -150,60 +90,6 @@ class Admin_UsergroupController extends ZendAfi_Controller_Action { } - public function cataddAction() { - $form = new ZendAfi_Form_UserGroupCategorie(); - $categorie = new Class_UserGroupCategorie(); - if ($this->_isCategorieSaved($categorie,$form)) { - $this->_helper->notify($this->view->_('La catégorie "%s" a été ajoutée', $categorie->getLibelle())); - $this->_redirect(sprintf('admin/usergroup/index/id_cat/%d', $categorie->getId())); - return; - } - - $this->view->form= $form; - $this->view->titre = $this->view->_('Ajouter une catégorie d\'utilisateurs'); - if ($categorie_parent = Class_UserGroupCategorie::find((int)$this->_getParam('id'))) - $this->view->form->setDefault('parent_id', $categorie_parent->getId()); - } - - - public function catdelAction() { - if (!$categorie = Class_UserGroupCategorie::find((int)$this->_getParam('id'))) { - $this->_redirect('/admin/usergroup'); - return; - } - $id_cat_mere = ($categorie->getParentId()>0) ? '/index/id_cat/'.$categorie->getParentId() : '/index'; - $libelle= $categorie->getLibelle(); - $categorie->delete(); - $this->_helper->notify($this->view->_('La categorie "%s" a été supprimée',$libelle)); - $this->_redirect('/admin/usergroup'.$id_cat_mere); - } - - - public function cateditAction() { - $form = new ZendAfi_Form_UserGroupCategorie(); - $categorie = new Class_UserGroupCategorie(); - $this->view->titre = "Modifier une catégorie de groupes"; - if (!$categorie = Class_UserGroupCategorie::find((int)$this->_getParam('id'))) { - $this->_redirect('admin/usergroup'); - return; - } - - if ($this->_isCategorieSaved($categorie, $form)) { - $this->_helper->notify($this->_('La catégorie "%s" a été sauvegardée', $categorie->getLibelle())); - $this->_redirect(sprintf('admin/usergroup/index/id_cat/%d', $categorie->getId())); - return; - } - - - $form - ->populate(['libelle'=>$categorie->getLibelle()]) - ->setDefault('parent_id',$categorie->getParentId()); - $this->view->form= $form; - $this->view->titre = $this->view->_('Modifier une catégorie d\'utilisateurs'); - - } - - private function _getTreeViewItemActions() { return @@ -234,25 +120,6 @@ class Admin_UsergroupController extends ZendAfi_Controller_Action { } - /** - * @param Class_SitothequeCategorie $categorie - * @return bool - */ - protected function _isCategorieSaved($categorie,$form) { - if(!$this->_request->isPost()) - return false; - - $post = $this->_request->getPost(); - $filter = new Zend_Filter_StripTags(); - $post['libelle'] = trim($filter->filter($this->_request->getPost('libelle'))); - - $categorie - ->updateAttributes($post); - - return $form->isValid($categorie) ? $categorie->save() : false; - } - - public function listJsonAction() { $json_groups = []; @@ -264,48 +131,4 @@ class Admin_UsergroupController extends ZendAfi_Controller_Action { 'categories' => $json_groups, 'items' => []]]); } - - - protected function _getPost() { - $post = $this->_request->getPost(); - if(!isset($post[ZendAfi_Form_Admin_UserGroup::RIGHTS_PERMISSIONS])) - $post[ZendAfi_Form_Admin_UserGroup::RIGHTS_PERMISSIONS] = []; - - $rights_permissions = (new Storm_Collection($post[ZendAfi_Form_Admin_UserGroup::RIGHTS_PERMISSIONS])); - - $post['rights'] = ZendAfi_Form_Admin_UserGroup::deletePrefix($rights_permissions, - ZendAfi_Form_Admin_UserGroup::RIGHT); - - $this->_permissions_access = ZendAfi_Form_Admin_UserGroup::deletePrefix($rights_permissions, - ZendAfi_Form_Admin_UserGroup::PERMISSION); - - unset($post[ZendAfi_Form_Admin_UserGroup::RIGHTS_PERMISSIONS]); - return $post; - } - - - protected function _doAfterSave($model) { - Class_UserGroup_Permission::denyAllToGroup(Class_DigitalResource::getInstance()->getPermissions(), $model); - - (new Storm_Collection($this->_permissions_access)) - ->eachDo( - function($permission) use ($model) - { - if($permission = Class_Permission::findFirstBy(['code' => $permission])) { - $permission->permitTo($model, new Class_Entity()); - } - }); - } - - - protected function _getFormValues($model) { - $permissions = (new Storm_Model_Collection(Class_UserGroup_Permission::findAllBy(['id_group' => $model->getId()]))) - ->collect('permission'); - - $values = array_merge($model->toArray(), - [ZendAfi_Form_Admin_UserGroup::RIGHTS_PERMISSIONS => - ZendAfi_Form_Admin_UserGroup::mergeRightsAndPermissionsWithPrefix($model->getRights(), - $model->getPermissions())]); - return $values; - } } diff --git a/application/modules/admin/controllers/UsersController.php b/application/modules/admin/controllers/UsersController.php index a6ce3bd44939823fba593210ab8c440c56077004..610a64070830d15338e4afe02e7729d4e36ce341 100644 --- a/application/modules/admin/controllers/UsersController.php +++ b/application/modules/admin/controllers/UsersController.php @@ -21,20 +21,9 @@ class Admin_UsersController extends ZendAfi_Controller_Action { - public function getRessourceDefinitions() { - return ['model' => ['class' => 'Class_Users', - 'name' => 'user', - 'order' => 'id'], - - 'messages' => ['successful_save' => $this->_('L\'utilisateur "%s" a été sauvegardé'), - 'successful_add' => $this->_('L\'utilisateur "%s" a été ajouté'), - 'successful_delete' => $this->_('L\'utilisateur "%s" a été supprimé')], - - 'actions' => ['add' => ['title' => $this->_('Ajouter un utilisateur')], - 'edit' => ['title' => $this->_('Modifier l\'utilisateur: %s')], - 'delete' => ['title' => $this->_('Supprimer l\'utilisateur: %s')]], - - 'form_class_name' => 'ZendAfi_Form_Admin_User']; + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_User', + 'ZendAfi_Controller_Plugin_Manager_User']; } @@ -44,39 +33,6 @@ class Admin_UsersController extends ZendAfi_Controller_Action { } - protected function _getPost() { - $post = $this->_request->getPost(); - $post['user_groups'] = array_filter( - array_map(function($id) { return Class_UserGroup::find((int)$id);}, - explode('-', $this->_getParam('user_group_ids',''))) - ); - - unset($post['id_categories']); - - return $post; - } - - - protected function _getFormValues($model) { - $array_model=parent::_getFormValues($model); - $array_model['user_group_ids']=implode('-',array_map(function($group) { return $group->getId();},$model->getUserGroups())); - - return $array_model; - } - - - protected function _setupFormAndSave($model) { - if ($this->_request->isPost()) - $model->updateSIGBOnSave(); - - try { - return parent::_setupFormAndSave($model); - } catch (Exception $e) { - $this->_helper->notify($e->getMessage()); - } - } - - public function changeAdminSkinAction() { $admin_skin = $this->_request->getParam(Class_User_Settings::ADMIN_SKIN, ''); $color = $this->_request->getParam(Class_User_Settings::ADMIN_SKIN_COLOR, ''); diff --git a/application/modules/admin/views/scripts/module.phtml b/application/modules/admin/views/scripts/module.phtml index bce123d4b06ab3840fd23ae618ddc0a9e4e5c452..92f539c91b237932450ec9cbf6a2f78af5c86435 100644 --- a/application/modules/admin/views/scripts/module.phtml +++ b/application/modules/admin/views/scripts/module.phtml @@ -6,13 +6,7 @@ <div class="menu barre_nav"><?php echo $this->menuHorizontalAdmin() ?></div> <div class="left"><?php echo $this->menuGaucheAdmin() ?></div> <div class="modules"> - <?php - if (($model_name = $this->model_name) - && ($model = $this->$model_name) - && $this->model_actions) { - echo $this->tag('div', $this->tagModelTable([$model], [], [], $this->model_actions, $model_name . '_actions'), - ['class' => 'header_actions']); - } ?> + <?php $this->renderPluginsHeaderActions(); ?> <h1> <?php echo $this->titre; @@ -21,7 +15,7 @@ ?> </h1> <?php - echo $this->renderPlugins(); + $this->renderPlugins(); echo $this->render($this->actionScript); ?> </div> <div class="clear"></div> diff --git a/application/modules/admin/views/scripts/newsletter/edit-subscribers.phtml b/application/modules/admin/views/scripts/newsletter/edit-subscribers.phtml index 7fe2c31eb2225570d08374202a4cbabd63a3cc6b..fcf46590df5bf8237194fe14f9e31e9b65073a11 100644 --- a/application/modules/admin/views/scripts/newsletter/edit-subscribers.phtml +++ b/application/modules/admin/views/scripts/newsletter/edit-subscribers.phtml @@ -32,7 +32,7 @@ $actions = [['url' => $build_url('editmembers', 'usergroup'), $actions = function($group) use($actions) { - return $this->modelActions($group, $actions); + return $this->renderModelActions($group, $actions); }; echo $this->tagModelTable($this->groups, @@ -63,14 +63,14 @@ $actions = function($model) use ($build_url, $no_mail_action) { $is_blacklisted = $this->newsletter->isBlackListed($model); if (!$is_recipient) - return $this->modelActions($model, - [['url' => $build_url('subscribe'), - 'icon' => 'add', - 'label' => $this->_('Inscrire')] - ]); + return $this->renderModelActions($model, + [['url' => $build_url('subscribe'), + 'icon' => 'add', + 'label' => $this->_('Inscrire')] + ]); if ($is_blacklisted) - return $this->modelActions($model, + return $this->renderModelActions($model, [['url' => $build_url('subscribe'), 'icon' => 'back', 'label' => $this->_('Réinscrire')] @@ -79,11 +79,11 @@ $actions = function($model) use ($build_url, $no_mail_action) { if (! $model->hasMail()) return $no_mail_action; - return $this->modelActions($model, - [['url' => $build_url('unsubscribe'), - 'icon' => 'cancel', - 'label' => $this->_('Désinscrire')] - ]); + return $this->renderModelActions($model, + [['url' => $build_url('unsubscribe'), + 'icon' => 'cancel', + 'label' => $this->_('Désinscrire')] + ]); }; echo '<br><br>' diff --git a/application/modules/admin/views/scripts/newsletter/index.phtml b/application/modules/admin/views/scripts/newsletter/index.phtml index cfb7cc73d7b2500d5fd26007523eca43d66d6236..a55903e190e0b4afa39e7c1992a5030bd76b8da4 100644 --- a/application/modules/admin/views/scripts/newsletter/index.phtml +++ b/application/modules/admin/views/scripts/newsletter/index.phtml @@ -7,7 +7,10 @@ echo $this->bouton('id=_create_newsletter', echo $this->tagModelTable($this->newsletters, [$this->_('Titre'), $this->_('Dernière distribution')], ['titre', 'progress'], - $this->model_actions, + [function($model) + { + return $this->renderPluginsActions($model); + }], 'newsletters', null, ['progress' => function($model) { return $this->tagProgressBarForNewsletter($model); }]); diff --git a/application/modules/admin/views/scripts/usergroup/index.phtml b/application/modules/admin/views/scripts/usergroup/index.phtml index a8555136be75d08d21548a6423e7b2f182efe8d8..583fe9c29f960d0be178d9fa75b7b3736ddd273b 100644 --- a/application/modules/admin/views/scripts/usergroup/index.phtml +++ b/application/modules/admin/views/scripts/usergroup/index.phtml @@ -6,4 +6,4 @@ echo $this->treeView( false ); -?> \ No newline at end of file +?> diff --git a/application/modules/opac/controllers/CmsController.php b/application/modules/opac/controllers/CmsController.php index b0f3d434c69ccc1983eeef20c50d625aa704a9ca..e1cca78a7d1aecf31cb0184f1452210cb185dbb6 100644 --- a/application/modules/opac/controllers/CmsController.php +++ b/application/modules/opac/controllers/CmsController.php @@ -23,6 +23,11 @@ class CmsController extends ZendAfi_Controller_Action { use Trait_TimeSource; + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_Printer_ModelFusion']; + } + + public function init() { parent::init(); diff --git a/application/modules/opac/controllers/RechercheController.php b/application/modules/opac/controllers/RechercheController.php index 3498df89531c852ceca3b7e0737d6654b3814295..e309320f438935a7845e91c8119e811140afd406 100644 --- a/application/modules/opac/controllers/RechercheController.php +++ b/application/modules/opac/controllers/RechercheController.php @@ -25,6 +25,11 @@ class RechercheController extends ZendAfi_Controller_Action { $preferences; + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_Printer_ModelFusion']; + } + + public function init() { $this->moteur = Class_MoteurRecherche::getInstance(); $this->view->resultat = []; diff --git a/application/modules/opac/views/scripts/formations/done.phtml b/application/modules/opac/views/scripts/formations/done.phtml index 5792b31b0066ddf54134fc5f79d2fc1e73a481ce..f392073053ad899b1502b02c8bee3147f8cac1f3 100644 --- a/application/modules/opac/views/scripts/formations/done.phtml +++ b/application/modules/opac/views/scripts/formations/done.phtml @@ -15,7 +15,7 @@ echo $this->tagModelTable( 'date_debut_texte', 'libelle_lieu'], [function($model) use($details_link, $current_link) { - return $this->modelActions($model, + return $this->renderModelActions($model, [['url' => $details_link . '/id/%s?retour=' . $current_link, 'icon' => 'view', 'label' => $this->_('Details de la session %s', diff --git a/application/modules/opac/views/scripts/formations/index.phtml b/application/modules/opac/views/scripts/formations/index.phtml index c1566795908dd9c036dd79c6e1cbcb7b84783d11..016fcf6f2f132a0ed643a554b6f0bb83b2c0260b 100644 --- a/application/modules/opac/views/scripts/formations/index.phtml +++ b/application/modules/opac/views/scripts/formations/index.phtml @@ -11,32 +11,32 @@ $register_link = $this->url(['controller' => 'abonne', $current_link = $this->url(); echo $this->tagModelTable( - $this->sessions, - [$this->_('Formation'), - $this->_('Date'), - $this->_('Lieu'), - $this->_('Informations')], - ['libelle_formation', - 'date_debut_texte', - 'libelle_lieu', - 'infos'], - [function($model) use($details_link, $register_link, $current_link) { - return $this->modelActions($model, - [['url' => $details_link . '/id/%s?retour=' . $current_link, - 'icon' => 'view', - 'label' => $this->_('Details de la session %s', - $model->getLabel())], - ['url' => $register_link . '/id/%s', - 'icon' => 'add_user', - 'label' => $this->_('S\'inscrire à la session %s', - $model->getLabel())]] - );}], - 'available_sessions', - null, - ['infos' => function($model) { - return $this->_('Date limite d\'inscription : %s', - $model->getDateLimiteInscriptionHumanRead()); - }] + $this->sessions, + [$this->_('Formation'), + $this->_('Date'), + $this->_('Lieu'), + $this->_('Informations')], + ['libelle_formation', + 'date_debut_texte', + 'libelle_lieu', + 'infos'], + [function($model) use($details_link, $register_link, $current_link) { + return $this->renderModelActions($model, + [['url' => $details_link . '/id/%s?retour=' . $current_link, + 'icon' => 'view', + 'label' => $this->_('Details de la session %s', + $model->getLabel())], + ['url' => $register_link . '/id/%s', + 'icon' => 'add_user', + 'label' => $this->_('S\'inscrire à la session %s', + $model->getLabel())]] + );}], + 'available_sessions', + null, + ['infos' => function($model) { + return $this->_('Date limite d\'inscription : %s', + $model->getDateLimiteInscriptionHumanRead()); + }] ); $this->closeBoite(); diff --git a/application/modules/opac/views/scripts/formations/registered.phtml b/application/modules/opac/views/scripts/formations/registered.phtml index cedc05fb65ef486c36be93eb591b3eec5bde53a3..083c956a790997158020e0cbaf60205e92f53b3f 100644 --- a/application/modules/opac/views/scripts/formations/registered.phtml +++ b/application/modules/opac/views/scripts/formations/registered.phtml @@ -10,40 +10,40 @@ $unregister_link = $this->url(['controller' => 'abonne', $current_link = $this->url(); Class_ScriptLoader::getInstance() -->addJQueryReady(' + ->addJQueryReady(' $(".actions a[href*=\'desinscrire\']").click(function(event) { return confirm($(this).find("img").attr("alt") + " ?"); }); '); echo $this->tagModelTable( - $this->sessions, - [$this->_('Formation'), - $this->_('Date'), - $this->_('Lieu'), - $this->_('Informations')], - ['libelle_formation', - 'date_debut_texte', - 'libelle_lieu', - 'infos'], - [function($model) use($details_link, $unregister_link, $current_link) { - return $this->modelActions($model, - [['url' => $details_link . '/id/%s?retour=' . $current_link, - 'icon' => 'view', - 'label' => $this->_('Details de la session %s', - $model->getLabel())], + $this->sessions, + [$this->_('Formation'), + $this->_('Date'), + $this->_('Lieu'), + $this->_('Informations')], + ['libelle_formation', + 'date_debut_texte', + 'libelle_lieu', + 'infos'], + [function($model) use($details_link, $unregister_link, $current_link) { + return $this->renderModelActions($model, + [['url' => $details_link . '/id/%s?retour=' . $current_link, + 'icon' => 'view', + 'label' => $this->_('Details de la session %s', + $model->getLabel())], - ['url' => $unregister_link . '/id/%s', - 'icon' => 'delete', - 'label' => $this->_('Se désinscrire de la session %s', - $model->getLabel())]]); - }], - 'registered_sessions', - null, - ['infos' => function($model) { - return $this->_('Date limite d\'inscription : %s', - $model->getDateLimiteInscriptionHumanRead()); - }] + ['url' => $unregister_link . '/id/%s', + 'icon' => 'delete', + 'label' => $this->_('Se désinscrire de la session %s', + $model->getLabel())]]); + }], + 'registered_sessions', + null, + ['infos' => function($model) { + return $this->_('Date limite d\'inscription : %s', + $model->getDateLimiteInscriptionHumanRead()); + }] ); $this->closeBoite(); diff --git a/cosmogramme/cosmozend/application/modules/cosmo/controllers/DataProfileController.php b/cosmogramme/cosmozend/application/modules/cosmo/controllers/DataProfileController.php index 075c73bb010aeadd530c509bf69b7bf841cd18b1..3b9deeb2c9b92aacc85eddace75a699ef49075c2 100644 --- a/cosmogramme/cosmozend/application/modules/cosmo/controllers/DataProfileController.php +++ b/cosmogramme/cosmozend/application/modules/cosmo/controllers/DataProfileController.php @@ -22,81 +22,9 @@ class Cosmo_DataProfileController extends ZendAfi_Controller_Action { - public function getRessourceDefinitions() { - return ['model' => ['class' => 'Class_IntProfilDonnees', - 'name' => 'data_profile', - 'order' => 'libelle'], - - 'messages' => ['successful_save' => $this->_('Profil "%s" sauvegardé'), - 'successful_add' => $this->_('Profil "%s" ajouté'), - 'successful_delete' => $this->_('Profil "%s" supprimé')], - - 'actions' => ['add' => ['title' => $this->_('Nouveau profil de données')], - 'edit' => ['title' => $this->_('Modifier le profil de données : %s')], - 'index' => ['title' => $this->_('Profils de données')]], - - 'form_class_name' => 'ZendAfi_Form_Cosmo_DataProfile']; - } - - - protected function _setupFormAndSave($model) { - $model = $this->_autoUpdateFormatInModel($model); - $form = $this->_getForm($model); - - $this->view->form = $form; - if (!$this->_request->isPost()) - return false; - - $values = $this->_autoUpdateFormat($this->_getPost()); - - $attributes_values = $this->_extractAttributesFrom($values); - $model->updateAttributes($attributes_values); - - $profile_prefs = $this->_extractProfilePrefsFrom($values); - $model->setAttributs($profile_prefs); - - if ((!$form->isValidModelAndArray($model, $values))) - return false; - - return $model->save(); - } - - - protected function _autoUpdateFormatInModel($model) { - $attributes = $this->_autoUpdateFormat($model->toArray(), $model); - $model->updateAttributes($attributes); - return $model; - } - - - protected function _autoUpdateFormat($attributes) { - $old_format = $attributes['format']; - $default_formats = Class_IntProfilDonnees::getFormatsForType($attributes['type_fichier']); - - if(!key_exists($old_format, $default_formats)) { - $keys = array_keys($default_formats); - $attributes['format'] = array_shift($keys); - } - - return $attributes; - } - - - protected function _extractAttributesFrom($values) { - $default_values = Class_IntProfilDonnees::getClassVar('_default_attribute_values'); - return array_intersect_key($values, $default_values); - } - - - protected function _extractProfilePrefsFrom($values) { - return (new Class_ProfileSerializer($values))->serializeDatas(); - } - - - - protected function _getEditUrl($model) { - return sprintf('/cosmo/%s/edit/id/%s', - $this->_request->getControllerName(), $model->getId()); + public function getPlugins() { + return ['ZendAfi_Controller_Plugin_ResourceDefinition_DataProfile', + 'ZendAfi_Controller_Plugin_Manager_DataProfile']; } diff --git a/library/Class/MultiSelection/Abstract.php b/library/Class/MultiSelection/Abstract.php index 802591a0665d30f19249735e80319799dfe35579..433f901eacbcfa79100db04fe7c5bf6a19a5f11b 100644 --- a/library/Class/MultiSelection/Abstract.php +++ b/library/Class/MultiSelection/Abstract.php @@ -83,8 +83,15 @@ abstract class Class_MultiSelection_Abstract { } + public function acceptVisitor($visitor) { + $visitor + ->visitWidget($this) + ->visitActions($this); + return $this; + } + + abstract public function getModels(); - abstract public function acceptVisitor($visitor); abstract public function getModelIdsFromCategory($id); abstract protected function _getStorage(); } \ No newline at end of file diff --git a/library/Class/MultiSelection/Album.php b/library/Class/MultiSelection/Album.php index 55f7c66a4a1f0f25ef29ac5df379c08687f101e6..6d24ffe407e7c85c9bc25e9056115372b7195f4b 100644 --- a/library/Class/MultiSelection/Album.php +++ b/library/Class/MultiSelection/Album.php @@ -40,7 +40,7 @@ class Class_MultiSelection_Album extends Class_MultiSelection_Abstract { } - public function acceptVisitor($visitor) { + public function acceptWidgetVisitor($visitor) { $models = $this->getModels(); $count = $models->count(); @@ -83,6 +83,44 @@ class Class_MultiSelection_Album extends Class_MultiSelection_Abstract { } + public function acceptActionsVisitor($visitor) { + $visitor + ->visitControllerName('album') + + ->visitLeafCondition(function($model) + { + return $this->isSelected($model->getId()); + }) + + ->visitNodeCondition(function($model) + { + return $this->isCategorySelected($model->getId()); + }) + + ->visitAddLeaf(function($model) + { + return $this->_('Ajouter %s à la sélection d\'albums', $model->getTitre()); + }) + + ->visitRemoveLeaf(function($model) + { + return $this->_('Supprimer %s de la sélection d\'albums', $model->getTitre()); + }) + + ->visitAddNode(function($model) + { + return $this->_('Ajouter tous les albums de la catégorie %s à la sélection d\'albums', $model->getLibelle()); + }) + + ->visitRemoveNode(function($model) + { + return $this->_('Supprimer tous les albums de la catégorie %s de la sélection d\'albums', $model->getLibelle()); + }); + + return $this; + } + + protected function _getStorage() { return new Class_MultiSelection_SessionStorage('album'); } diff --git a/library/Class/MultiSelection/Article.php b/library/Class/MultiSelection/Article.php index 4deba3e35b34aec9dac24b7fc33bbf8ee5d87b0f..77e4e5d1b838a5a14ce6f93395a2ea3a92064b9e 100644 --- a/library/Class/MultiSelection/Article.php +++ b/library/Class/MultiSelection/Article.php @@ -35,7 +35,7 @@ class Class_MultiSelection_Article extends Class_MultiSelection_Abstract { } - public function acceptVisitor($visitor) { + public function acceptWidgetVisitor($visitor) { $models = $this->getModels(); $count = $models->count(); @@ -78,6 +78,57 @@ class Class_MultiSelection_Article extends Class_MultiSelection_Abstract { } + public function acceptActionsVisitor($visitor) { + $user = Class_Users::getIdentity(); + $permission_closure = function($model) use($user){ + if('Class_Article' == get_class($model)) + $model = $model->getCategorie(); + + return $user + ->hasAnyPermissionOn($model, + [Class_Permission::createArticle(), + Class_Permission::createArticleCategory()]); + }; + + $visitor + ->visitControllerName('cms') + + ->visitLeafCondition(function($model) use($permission_closure) + { + return $this->isSelected($model->getId()) + && $permission_closure($model); + }) + + ->visitNodeCondition(function($model) use($permission_closure) + { + return $this->isCategorySelected($model->getId()) + && $permission_closure($model); + }) + + ->visitAddLeaf(function($model) + { + return $this->_('Ajouter %s à la sélection d\'articles', $model->getTitre()); + }) + + ->visitRemoveLeaf(function($model) + { + return $this->_('Supprimer %s de la sélection d\'articles', $model->getTitre()); + }) + + ->visitAddNode(function($model) + { + return $this->_('Ajouter tous les articles de la catégorie %s à la sélection d\'articles', $model->getLibelle()); + }) + + ->visitRemoveNode(function($model) + { + return $this->_('Supprimer tous les articles de la catégorie %s de la sélection d\'articles', $model->getLibelle()); + }); + + return $this; + } + + protected function _getStorage() { return new Class_MultiSelection_SessionStorage('article'); } diff --git a/library/Class/UserGroupCategorie.php b/library/Class/UserGroupCategorie.php index e41ff10a9061e1dad55f4334977396623146c8ca..90c84ab1428ddbb8a952d915174bf62bab21e577 100644 --- a/library/Class/UserGroupCategorie.php +++ b/library/Class/UserGroupCategorie.php @@ -25,7 +25,7 @@ class UserGroupCategorieLoader extends Storm_Model_Loader{ public static function getTopCategories() { - return Class_UserGroupCategorie::findAllBy(['parent_id'=>0]); + return Class_UserGroupCategorie::findAllBy(['parent_id' => 0]); } diff --git a/library/ZendAfi/Controller/Action.php b/library/ZendAfi/Controller/Action.php index 8e3f3f648bd9811ab573c94f523f401483e9d04a..9915f9e2e86e082271ad73a6e7244b6fecefc3cf 100644 --- a/library/ZendAfi/Controller/Action.php +++ b/library/ZendAfi/Controller/Action.php @@ -23,30 +23,28 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action { use Trait_Translator; protected $_definitions; - protected $_after_add_closure; - protected $custom_values; protected $_plugins; - public function __call($methodName, $args) { - if ('Action' != substr($methodName, -6)) - return parent::__call($methodName, $args); + public function __call($method_name, $args) { + if ('Action' != substr($method_name, -6)) + return parent::__call($method_name, $args); $plugins = $this->_plugins - ->select(function($plugin) use ($methodName) + ->select(function($plugin) use ($method_name) { - return $plugin->isActionDefined($methodName); + return $plugin->isActionDefined($method_name); }); if($plugins->isEmpty()) - return parent::__call($methodName, $args); + return parent::__call($method_name, $args); if(1 < $plugins->count()) { - $this->_helper->notify($this->_('L\'action %s est déjà définie`', $methodName)); + $this->_helper->notify($this->_('L\'action %s est déjà définie`', $method_name)); return $this->_redirectToIndex(); } - return $plugins->first()->call($methodName, $args); + return $plugins->first()->call($method_name, $args); } @@ -69,14 +67,12 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action { public function preDispatch() { - $this->_definitions = new ZendAfi_Controller_Action_RessourceDefinitions($this->getRessourceDefinitions()); - $this->_plugins = $this->view->plugins = $this->_definitions->getPlugins($this); + $plugins_helper = new ZendAfi_Controller_Action_Plugins($this); + $this->_plugins = $plugins_helper->getPlugins(); + $this->_plugins = $this->view->plugins = $plugins_helper->init(); if ($this->isPopupRequest()) $this->switchToPopupMode(); - - if ('add' != $this->_request->getActionName()) - $this->view->model_actions = $this->_definitions->getModelActions(); } @@ -107,7 +103,12 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action { } - public function getRessourceDefinitions() { + public function setResourceDefinition($definitions) { + $this->_definitions = $definitions; + } + + + public function getPlugins() { return []; } @@ -129,144 +130,15 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action { } - public function deleteAction() { - if ($this->_response->isRedirect()) - return; - - if ($model = $this->_findModel()) { - $values = $this->_getCustomFieldModelValues($model); - $values->deleteValues(); - $model->delete(); - $this->_helper->notify($this->_definitions->successfulDeleteMessage($model)); - } - $this->_redirectToIndex(); - $this->_definitions->doAfterDelete($model); - } - - - protected function _addModelToView($model) { - $model_name = $this->_definitions->getModelName(); - $this->view->model_name = $model_name; - $this->view->$model_name = $model; - } - - - protected function _findModel() { - return $this->_definitions->find($this->_getParam('id')); - } - - - protected function _getEditActionTitle($model) { - return $this->_definitions->editActionTitle($model); - } - - - public function editAction() { - if ($this->_response->isRedirect()) - return; - - if (!$model = $this->_findModel()) { - $this->_redirectToIndex(); - return; - } - - if (!$this->_canEdit($model)) { - $this->_helper->notify($this->view->_('Vous n\'avez pas la permission "%s"', - $this->_getEditActionTitle($model))); - $this->_redirectToIndex(); - return; - } - - $this->view->titre = $this->_getEditActionTitle($model); - $this->_addModelToView($model); - - if ($this->_setupFormAndSave($model)) { - $this->_helper->notify($this->_definitions->successfulSaveMessage($model)); - $this->_redirectToEdit($model); - $this->_definitions->doAfterEdit($model); - } - - $this->_postEditAction($model); - } - - - public function addAction() { - if ($this->_response->isRedirect()) - return; - - if (!$this->_canAdd()) { - $this->_helper->notify($this->view->_('Vous n\'avez pas la permission "%s"', - $this->_definitions->addActionTitle())); - $this->_redirectToIndex(); - return; - } - - $this->view->titre = $this->_definitions->addActionTitle(); - $model = $this->_definitions->newModel(); - $this->_updateNewModel($model); - $this->_addModelToView($model); - - if ($this->_setupFormAndSave($model)) { - $this->_helper->notify($this->_definitions->successfulAddMessage($model)); - $this->_redirectToEdit($model); - $this->_definitions->doAfterAdd($model); - } - } - - - protected function _updateNewModel($model) { - return $this; - } - - - protected function _canAdd() { - return true; - } - - - protected function _canEdit($model) { - return true; - } - - - protected function _getCustomFieldModelValues($model) { - return Class_CustomField_Model::getModel($this->_definitions->getModelClass()) - ->find($model->getId()); - } - - - protected function _getCustomFieldForm($model_values) { - return new ZendAfi_Form_Admin_CustomFields_ModelValues(['model_values' => $model_values]); - } - - - protected function processMulticheckboxFromPost($form, $clean = false) { - $defaults = []; - foreach ($form->getMulticheckboxNames() as $checkbox_name) - $defaults[$checkbox_name] = []; - - $post = array_merge($defaults, $this->_getPost()); - if ($clean) - $post = $form->deleteUnchanged($post); - - $this->custom_values = []; - - foreach ($post as $k=>$v) - if (preg_match('/field_[0-9]+/', $k)) { - $this->custom_values[$k] = $v; - unset($post[$k]); - } - return $post; - } - - protected function _redirectToIndex() { $url = '/admin/'.$this->_request->getControllerName().'/index'; $closure = function($item, $value) use (&$url) { $url .= '/' . $item . '/' . $value; }; - $this->_definitions->withScopeDo($closure, $this->_request); + if($this->_definitions) + $this->_definitions->withScopeDo($closure, $this->_request); + $this->_redirect($url); } @@ -288,114 +160,11 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action { } - protected function _redirectToEdit($model) { - $this->_redirectClose($this->_getEditUrl($model)); - } - - - protected function _getEditUrl($model) { - return sprintf('/admin/%s/edit/id/%s', - $this->_request->getControllerName(), $model->getId()); - } - - protected function _getPost() { return $this->_request->getPost(); } - protected function _setupFormAndSave($model) { - $form = $this->_getForm($model); - - $this->view->form = $form; - if (!$this->_request->isPost()) - return false; - - $post = $this->processMulticheckboxFromPost($form); - $model->updateAttributes($post); - - if ((!$form->isValidModelAndArray($model, $this->_getPost()))) - return false; - - $this->_doBeforeSave($model); - - if (!$model->save()) - return false; - - $model_values = $this->_getCustomFieldModelValues($model); - $custom_form = $this->_getCustomFieldForm($model_values); - $custom_form->populate($this->custom_values); - $custom_form->updateModelValues(); - $model_values->save(); - - $this->_doAfterSave($model); - return true; - } - - - protected function _doBeforeSave($model) { - return $this; - } - - - protected function _doAfterSave($model) { - return $this; - } - - - /** - * @param Storm_Model_Abstract $model - * @return Zend_Form - */ - protected function _getForm($model) { - $model_values = $this->_getCustomFieldModelValues($model); - $custom_form = $this->_getCustomFieldForm($model_values); - - if ($this->_definitions->getFormClassName()) - return $this->_getFormWith($model, $custom_form); - - if (!$form = $this->_definitions->getForm()) { - $form = new ZendAfi_Form( ['id' => $this->_definitions->getModelName()] ); - $form->populateFormFromGroupsDefinitions($this->_definitions->getDisplayGroups()); - } - - $form = $form->populate($this->_request->getParams()); - $form = $form->populate($this->_getFormValues($model)); - - return $form - ->populate($this->_request->getParams()) - ->populate($this->_getFormValues($model)); - } - - - protected function _getFormValues($model) { - return $model->toArray(); - } - - - protected function _getFormWith($model, $custom_form) { - $formClass = $this->_definitions->getFormClassName(); - foreach ($custom_form->getElements() as $element) { - if (!$value=$this->_request->getParam($element->getName())) - continue; - $element->setValue($value); - } - - $form = $formClass::newWith( - array_merge($this->_getFormValues($model), $this->_request->getParams()), - $custom_form - ); - $form->setAction($this->view->url()); - return $form; - - } - - - /** - * Hook appelé en fin d'action d'édition - * @param $model Storm_Model_Abstract - */ - protected function _postEditAction($model) {} protected function _stayOnPage() { $this->_redirect($this->_request->getServer('HTTP_REFERER')); @@ -472,34 +241,7 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action { } - public function printAction() { - if ($this->_response->isRedirect()) - return; - - $models = []; - $strategy = $this->_getParam('strategy','Article_List'); - list($class_name,$type) = explode('_',$strategy); - $model = 'Class_'.$class_name; - $id_name = 'id_'.$class_name; - - $source_key = strtolower($class_name); - $data = $model::find($this->_getParam('id',0)); - - $this->view->fusion = Class_ModeleFusion::find($this->_getParam('modele_fusion')); - - if ($type == 'List') { - $models = array_map([$model, 'find'], explode(';', $this->_getParam('ids', 0))); - $data = new Class_CollectionFusion($models); - $source_key = Storm_Inflector::pluralize($source_key); - } - - $this->view->fusion->setDataSource([$source_key => $data]); - $this->_helper->getHelper('viewRenderer')->setLayoutScript('empty.phtml'); - $this->renderScript('print.phtml'); - } - - - protected function _getOsmService() { + public function getOsmService() { return (new Class_WebService_OpenStreetMap()) ->onCoordinatesNotFound( function() { @@ -528,18 +270,18 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action { } - protected function _getDefaultModel($models) { - return $this->_definitions->newModel(); - } - - - public function acceptVisitor($plugin) { - $plugin + public function acceptVisitor($visitor) { + $visitor ->visitView($this->view) ->visitRequest($this->_request) + ->visitResponse($this->_response) ->visitHelper($this->_helper) ->visitViewRenderer($this->getHelper('ViewRenderer')) - ->visitDefinitions($this->_definitions) + ->visitPlugins($this->_plugins) + ->visitGetPost(function() + { + return $this->_getPost(); + }) ->visitGetParam(function($key) { return $this->_getParam($key); @@ -548,6 +290,10 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action { { return $this->_setParam($key, $value, $default); }) + ->visitForward(function($action) + { + return $this->_forward($action); + }) ->visitRedirectToReferer(function() { $this->_redirectToReferer(); @@ -556,46 +302,16 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action { { $this->_redirect($url); }) - ->visitGetForm(function($model) - { - return $this->_getForm($model); - }) - ->visitGetPost(function() - { - return $this->_getPost(); - }) - ->visitDoBeforeSave(function($model) - { - return $this->_doBeforeSave($model); - }) - ->visitDoAfterSave(function($model) - { - return $this->_doAfterSave($model); - }) - ->visitCustomFieldModelValues(function($model) - { - return $this->_getCustomFieldModelValues($model); - }) - ->visitCustomFieldForm(function($model) + ->visitRedirectClose(function($url, $options = []) + { + $this->_redirectClose($url, $options); + }) + ->visitRedirectToIndex(function() { - return $this->_getCustomFieldForm($model); + $this->_redirectToIndex(); }) - ->visitForward(function($action) - { - return $this->_forward($action); - }) - ->visitDefaultModel(function($models) - { - return $this->_getDefaultModel($models); - }) - ->visitProcessMultiCheckbox(function($form, $clean) - { - return $this->processMulticheckboxFromPost($form, $clean); - }) - ->visitCustomValues(function() { - return $this->custom_values; - }) ; + return $this; } } diff --git a/library/ZendAfi/Controller/Action/Plugins.php b/library/ZendAfi/Controller/Action/Plugins.php new file mode 100644 index 0000000000000000000000000000000000000000..89bdf119d9491b2261659f47c347221bc392bde3 --- /dev/null +++ b/library/ZendAfi/Controller/Action/Plugins.php @@ -0,0 +1,51 @@ +<?php +/** + * Copyright (c) 2012-2014, 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_Action_Plugins { + protected $_plugins; + + public function __construct($controller) { + if(!$plugins = $controller->getPlugins()) + $instances = []; + + $instances = array_map(function($plugin) use ($controller) + { + return new $plugin($controller); + }, + $plugins); + + $this->_plugins = new Storm_Collection($instances); + } + + + public function getPlugins() { + return $this->_plugins; + } + + public function init() { + return $this->_plugins->eachDo(function($plugin) + { + $plugin->init(); + }); + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Action/RessourceDefinitions.php b/library/ZendAfi/Controller/Action/RessourceDefinitions.php deleted file mode 100644 index ec9a2f0b81d67c1632345eefe9656b32fc7c7687..0000000000000000000000000000000000000000 --- a/library/ZendAfi/Controller/Action/RessourceDefinitions.php +++ /dev/null @@ -1,256 +0,0 @@ -<?php -/** - * Copyright (c) 2012, 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_Action_RessourceDefinitions { - protected $_definitions; - - public function __construct($definitions_array) { - $this->_definitions = $definitions_array; - } - - - public function getModelLoader() { - return Storm_Model_Abstract::getLoaderFor($this->getModelClass()); - } - - - public function find($id) { - return $this->getModelLoader()->find($id); - } - - - public function findAll($request) { - return $this->findAllBy($this->_addScopeParam([], $request)); - } - - - public function findAllBy($params) { - return call_user_func([$this->getModelLoader(), - $this->getFindAllMethod()], - array_merge(['order' => $this->getOrder()], - $params)); - } - - - protected function _addScopeParam($params, $request) { - $closure = function($item, $value) use (&$params) { - $params[$item] = $value; - }; - - $this->withScopeDo($closure, $request); - return $params; - } - - - public function withScopeDo($closure, $request) { - if (!$this->hasScope()) - return; - - $scope = $this->getScope(); - if (!is_array($scope)) - $scope = [$scope]; - - foreach($scope as $item) - if ($value = $request->getParam($item)) - $closure($item, $value); - } - - - public function newModel() { - return $this->getModelLoader()->newInstance(); - } - - - public function doAfterAdd($model) { - if (isset($this->_definitions['after_add'])) - $this->_definitions['after_add']($model); - } - - - public function doAfterEdit($model) { - if (isset($this->_definitions['after_edit'])) - $this->_definitions['after_edit']($model); - } - - public function doAfterDelete($model) { - if (isset($this->_definitions['after_delete'])) - $this->_definitions['after_delete']($model); - } - - - public function successfulDeleteMessage($model) { - return sprintf($this->_definitions['messages']['successful_delete'], - $model->getLibelle()); - } - - - public function successfulSaveMessage($model) { - return sprintf($this->_definitions['messages']['successful_save'], - $model->getLibelle()); - } - - - public function successfulAddMessage($model) { - if (isset($this->_definitions['messages']['successful_add'])) - $successfull_add = $this->_definitions['messages']['successful_add']; - else - $successfull_add = $this->_definitions['messages']['successful_save']; - - return sprintf($successfull_add, $model->getLibelle()); - } - - - public function indexActionTitle() { - return $this->titleForAction('index'); - } - - - public function titleForAction($action) { - if (isset($this->_definitions['actions'][$action]['title'])) - return $this->_definitions['actions'][$action]['title']; - return ''; - } - - - public function editActionTitle($model) { - return sprintf($this->titleForAction('edit'),$model->getLibelle()); - } - - - public function addActionTitle() { - return $this->titleForAction('add'); - } - - - public function getModelClass() { - return $this->_definitions['model']['class']; - } - - - public function getModelId() { - return $this->_definitions['model']['model_id']; - } - - - public function getOrder() { - if (isset($this->_definitions['model']['order'])) - return $this->_definitions['model']['order']; - return 'libelle'; - } - - - public function getFindAllMethod() { - if (isset($this->_definitions['model']['findAll'])) - return $this->_definitions['model']['findAll']; - return 'findAllBy'; - } - - - public function getScope() { - if (isset($this->_definitions['model']['scope'])) - return $this->_definitions['model']['scope']; - return null; - } - - - public function hasScope() { - $scope = $this->getScope(); - return !empty($scope); - } - - - public function getModelName() { - return $this->_definitions['model']['name']; - } - - - public function pluralizeModelName() { - return Storm_Inflector::pluralize($this->getModelName()); - } - - - public function addFormElements($form) { - $element_definitions = $this->getFormElementDefinitions(); - - foreach($element_definitions as $name => $definition) { - $options = isset($definition['options']) ? $definition['options'] : array(); - - $form->addElement($definition['element'], $name, $options); - - if ($label = $form->getElement($name)->getDecorator('label')) - $label->setOption('escape', false); - } - return $this; - } - - - public function getDisplayGroups() { - return $this->_definitions['display_groups']; - } - - - public function getForm() { - if (isset($this->_definitions['form'])) - return $this->_definitions['form']; - return null; - } - - - public function getFormClassName() { - if (isset($this->_definitions['form_class_name'])) - return $this->_definitions['form_class_name']; - return null; - } - - - public function setFormClassName($name) { - $this->_definitions['form_class_name'] = $name; - return $this; - } - - - public function sort($instances) { - if (isset($this->_definitions['sort'])) - usort($instances, $this->_definitions['sort']); - return $instances; - } - - - public function getModelActions() { - return isset($this->_definitions['model_actions']) - ? $this->_definitions['model_actions'] - : []; - } - - - public function getPlugins($controller) { - $plugins = []; - - if(isset($this->_definitions['plugins'])) - $plugins = array_map(function($plugin) use ($controller) - { - return new $plugin($controller); - }, - $this->_definitions['plugins']); - - return new Storm_Collection($plugins); - } -} \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/Abstract.php b/library/ZendAfi/Controller/Plugin/Abstract.php new file mode 100644 index 0000000000000000000000000000000000000000..1df6bc6f8300defb6de3987d98f27041bb45864c --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/Abstract.php @@ -0,0 +1,221 @@ +<?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 + */ + + +abstract class ZendAfi_Controller_Plugin_Abstract { + use Trait_Translator; + + protected $_controller; + + public function __call($name, $args) { + if (!preg_match('/(visit)(\w+)/', $name)) + return $this->$name($args); + + if($this->isActionDefined($name)) + return $this->$name($args); + + return $this; + } + + public function call($name, $args) { + if($this->isActionDefined($name)) + return $this->$name($args); + return null; + } + + + public function isActionDefined($name) { + return in_array($name, get_class_methods($this)); + } + + + public function __construct($controller) { + $this->_controller = $controller; + } + + + public function init(){ + $this->_controller->acceptVisitor($this); + } + + + public function acceptVisitor($visitor) { + return $this; + } + + + public function render() { + return ''; + } + + + public function renderHeaderActions() { + return ''; + } + + + public function getActions($model) { + return []; + } + + + public function visitPlugins($plugins) { + $plugins + ->reject(function($plugin) + { + return $plugin == $this; + }) + ->eachDo(function($plugin) + { + $plugin->acceptVisitor($this); + }); + return $this; + } + + + public function visitView($view){ + $this->_view = $view; + return $this; + } + + + public function visitRequest($request) { + $this->_request = $request; + return $this; + } + + + public function visitResponse($response) { + $this->_response = $response; + return $this; + } + + + public function visitHelper($helper) { + $this->_helper = $helper; + return $this; + } + + + public function visitViewRenderer($view_renderer) { + $this->_view_renderer = $view_renderer; + return $this; + } + + + public function visitRedirectToReferer($callback) { + $this->_redirect_to_referer = $callback; + return $this; + } + + + public function visitRedirect($callback) { + $this->_redirect = $callback; + return $this; + } + + + public function visitRedirectClose($callback) { + $this->_redirect_close = $callback; + return $this; + } + + + public function visitRedirectToIndex($callback) { + $this->_redirect_to_index = $callback; + return $this; + } + + + public function visitGetParam($callback) { + $this->_get_param = $callback; + return $this; + } + + + public function visitSetParam($callback) { + $this->_set_param = $callback; + return $this; + } + + + public function visitGetPost($callback) { + $this->_get_post = $callback; + return $this; + } + + + public function visitForward($callback) { + $this->_forward = $callback; + return $this; + } + + + protected function _addModelToView($model) { + return call_user_func($this->_add_model_to_view, $model); + } + + + protected function _getParam($key) { + return call_user_func($this->_get_param, $key); + } + + + protected function _redirectToReferer() { + return call_user_func($this->_redirect_to_referer); + } + + + protected function _redirectToIndex() { + return call_user_func($this->_redirect_to_index); + } + + + protected function _redirect($url) { + return call_user_func($this->_redirect, $url); + } + + + protected function _redirectClose($url, $options = []) { + return call_user_func_array($this->_redirect_close, [$url, $options]); + } + + + protected function _getPost() { + return call_user_func($this->_get_post); + } + + + protected function _setParam($key, $value, $default = null) { + return call_user_func_array($this->_set_param, [$key, $value, $default]); + } + + + protected function _forward($action) { + return call_user_func($this->_forward, $action); + } + + + public function renderScript($script) { + $this->_controller->renderScript($script); + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/Manager/Album.php b/library/ZendAfi/Controller/Plugin/Manager/Album.php new file mode 100644 index 0000000000000000000000000000000000000000..202da59fec8b8729d96cb0837b1b701535087043 --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/Manager/Album.php @@ -0,0 +1,696 @@ +<?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_Album extends ZendAfi_Controller_Plugin_Manager_Manager { + public function addcategorietoAction() { + if (!$parent_categorie = Class_AlbumCategorie::find((int)$this->_getParam('id'))) { + $this->_redirect('admin/album'); + return; + } + + $categorie = Class_AlbumCategorie::newInstance() + ->setParentCategorie($parent_categorie); + + $titre = sprintf(((!$parent_categorie->hasParentCategorie()) + ? 'Ajouter une catégorie à la collection "%s"' + : 'Ajouter une sous-catégorie à la catégorie "%s"'), + $parent_categorie->getLibelle()); + $this->_renderCategoryForm($categorie, $titre); + } + + + public function addcategorieAction() { + $this->_renderCategoryForm(Class_AlbumCategorie::newInstance(), + 'Ajouter une collection'); + } + + + public function editcategorieAction() { + if (!$categorie = Class_AlbumCategorie::find((int)$this->_getParam('id'))) { + $this->_redirect('admin/album'); + return; + } + + $this->_renderCategoryForm( + $categorie, + 'Modification de la '. ((!$categorie->hasParentCategorie()) ? 'collection' : 'catégorie') . ' "' . $categorie->getLibelle() . '"'); + } + + + public function deletecategorieAction() { + if ($categorie = Class_AlbumCategorie::find((int)$this->_getParam('id'))) + $categorie->delete(); + $this->_redirect('admin/album'); + } + + + public function linkalbumtoAction() { + $this->_renderAlbumForm(Class_Album::newInstance(), + 'Ajouter un album'); + } + + + public function addalbumtoAction() { + $categorie = ''; + $title = 'Ajouter un album'; + if ($categorie = Class_AlbumCategorie::find((int)$this->_getParam('id'))) + $title .= ' dans la collection "' . $categorie->getLibelle() . '"'; + + $this->_renderAlbumForm( + Class_Album::newInstance()->setCategorie($categorie), $title); + } + + + public function editalbumAction() { + if (!$album = Class_Album::find((int)$this->_getParam('id'))) { + $this->_redirect('admin/album'); + return; + } + + $this->_renderAlbumForm($album, 'Modifier l\'album "' . $album->getTitre() . '"'); + } + + + public function deletealbumAction() { + if ($album = Class_Album::find((int)$this->_getParam('id'))) + $album->delete(); + $this->_redirect('admin/album'); + } + + + public function previewalbumAction() { + if (!$album = Class_Album::find((int)$this->_getParam('id'))) { + $this->_redirect('admin/album'); + return; + } + + $form = $this->_thumbnailsForm($album); + if ($form && $this->_request->isPost() + && $form->isValid($this->_request->getPost()) + && ($album->updateAttributes($this->_request->getPost()) + ->save())) { + $this->_helper->notify('Paramètres sauvegardés'); + $this->_redirect('admin/album/preview_album/id/'.$album->getId()); + return; + } + + $this->_view->titre = sprintf('Visualisation de l\'album "%s"', + $album->getTitre()); + $this->_view->album = $album; + $this->_view->form = $form; + } + + + public function generateThumbnailsAction() { + if (!$album = Class_Album::find((int)$this->_getParam('id'))) { + $this->_redirect('admin/album'); + return; + } + + $this->_view->titre = sprintf('Génération des vignettes de l\'album "%s"', + $album->getTitre()); + $this->_view->album = $album; + } + + + public function editimagesAction() { + if (!$album = Class_Album::find((int)$this->_getParam('id'))) { + $this->_redirect('admin/album'); + return; + } + + $this->_view->album = $album; + $this->_view->ressources = $album->getRessources(); + + $this->_view->titre = 'Médias de l\'album "' + . $album->getTitre() + . '" dans la collection "' + . $album->getCategorie()->getLibelle() . '"'; + } + + + public function addRessourceAction () { + if (!$album = Class_Album::find((int)$this->_getParam('id'))) { + $this->_redirect('admin/album'); + return; + } + + $this->_view->album = $album; + $ressource = Class_AlbumRessource::newInstance()->setAlbum($album); + + if ($this->_setupRessourceFormAndSave($ressource)) { + $this->_helper->notify('Média "' . $ressource->getTitre() . '" sauvegardé'); + $this->_redirect('admin/album/edit_ressource/id/' . $ressource->getId()); + return; + } + + $this->_view->errors = $ressource->getErrors(); + } + + + public function editressourceAction() { + if (null === ($ressource = Class_AlbumRessource::getLoader() + ->find($this->_getParam('id')))) { + $this->_redirect('admin/album'); + return; + } + + if ($this->_setupRessourceFormAndSave($ressource)) { + $this->_helper->notify('Média "' . $ressource->getTitre() . '" sauvegardé'); + $this->_redirect('admin/album/edit_ressource/id/' . $ressource->getId()); + return; + } + + $this->_view->errors = $ressource->getErrors(); + $this->_view->form->getElement('fichier') + ->setValue($ressource->getFichier()); + $this->_view->form->getElement('poster') + ->setValue($ressource->getPoster()); + + $this->_view->ressource = $ressource; + } + + + public function previewRessourceAction() { + if (null === ($ressource = Class_AlbumRessource::find($this->_getParam('id')))) { + $this->_redirect('admin/album'); + return; + } + + $ressource->ensureTilesGenerated(); + Class_ScriptLoader::getInstance()->loadLeafletJS(); + $this->_view->ressource = $ressource; + } + + + protected function _setupRessourceFormAndSave($model) { + $form = $this->_ressourceForm($model); + + $this->_view->form = $form; + + if (!$this->_request->isPost() + or !$form->isValid($this->_request->getPost())) + return false; + + $model->updateAttributes($this->_request->getPost()); + $model->setAuthors($form->authors->getValue()); + if (!$model->isValid()) { + $form->addModelErrors($model); + return false; + } + + return $model->save() + && $model->receiveFiles() + && $model->getAlbum()->save() + && $model->getAlbum()->index(); + } + + + public function sortressourcesAction() { + $album = Class_Album::getLoader()->find((int)$this->_getParam('id')); + $album->sortRessourceByFileName()->save(); + $this->_helper->notify('Médias réordonnés par nom de fichier'); + $this->_redirect('admin/album/edit_images/id/'.$album->getId()); + } + + + public function massRessourceDeleteAction() { + $this->_helper->getHelper('viewRenderer')->setNoRender(true); + if ((!$ids = $this->_getParam('ids')) + || (!$id = $this->_getParam('id'))) { + $this->_helper->notify('Paramètres manquants dans la requête de suppression'); + return; + } + + $ids = explode(',', $ids); + if (empty($ids)) { + $this->_helper->notify('Rien à supprimer'); + return; + } + + $deleted_count = 0; + foreach ($ids as $ressource_id) { + if (!$ressource = Class_AlbumRessource::find($ressource_id)) + continue; + + if (!$ressource->getAlbum()) + continue; + + if ($id != $ressource->getAlbum()->getId()) + continue; + + $ressource->delete(); + ++$deleted_count; + } + + $this->_helper->notify($deleted_count . ' média(s) supprimé(s)'); + } + + + public function deleteimageAction() { + if (null === ($ressource = Class_AlbumRessource::find((int)$this->_getParam('id')))) { + $this->_redirect('admin/album'); + return; + } + + $ressource->delete(); + $this->_redirect('admin/album/edit_images/id/' . $ressource->getAlbum()->getId()); + + } + + + public function moveImageAction() { + $this->_helper->getHelper('viewRenderer')->setNoRender(true); + + if (null === ($ressource = Class_AlbumRessource::find((int)$this->_getParam('id')))) + return; + + $ressource + ->getAlbum() + ->moveRessourceAfter($ressource, (int)$this->_getParam('after')); + } + + + public function albumDeleteVignetteAction() { + $this->_helper->getHelper('viewRenderer')->setNoRender(true); + + if (!$album = Class_Album::find((int)$this->_getParam('id'))) { + $this->_redirect('admin/album'); + return; + } + + $album->deleteVignette(); + $this->_redirect('admin/album/edit_album/id/' . $album->getId()); + } + + + public function albumDeletePdfAction() { + $this->_helper->getHelper('viewRenderer')->setNoRender(true); + + if (!$album = Class_Album::find((int)$this->_getParam('id'))) { + $this->_redirect('admin/album'); + return; + } + + $album->deletePdf(); + $this->_redirect('admin/album/edit_album/id/' . $album->getId()); + } + + + /** + * Formulaire d'édition des catégories + * @param Class_AlbumCategorie $categorie + * @return Zend_Form + */ + protected function _categorieForm($categorie) { + $cat_id = $categorie->isNew() ? $categorie->getParentId(): $categorie->getId(); + $form = new ZendAfi_Form(['id' => 'categorie', + 'data-backurl' => $this->_view->url(['action' => 'index', + 'cat_id' => $cat_id])]); + + $form->addElement(new Zend_Form_Element_Text('libelle', ['label' => 'Libellé *', + 'size' => 30, + 'required' => true, + 'allowEmpty' => false])) + ->addDisplayGroup(['libelle'], 'categorie', + ['legend' => (($categorie->hasParentCategorie()) ? + 'Catégorie' + : 'Collection')]) + ->populate($categorie->toArray()); + return $form; + } + + + /** + * @param Class_AlbumCategorie $categorie + * @return null + */ + public function _validateAndAddCategorie($categorie) { + $form = $this->_categorieForm($categorie); + $this->_view->form = $form; + + if (!$this->_request->isPost() or !$form->isValid($_POST)) + return; + + $categorie + ->updateAttributes($_POST) + ->save(); + $this->_redirect('admin/album/index'); + } + + + /** + * @param Class_AlbumCategorie $categorie + * @param string $titre + */ + protected function _renderCategoryForm($categorie, $titre) { + $this->_validateAndAddCategorie($categorie); + + $this->_view->titre = $titre; + $this->_controller->render('categorie_form'); + } + + + /** + * @param Class_Album $album + * @return Zend_Form + */ + protected function _albumForm($album) { + $form = ZendAfi_Form_Album::newWithAlbum($album); + $bib_id_param = []; + if(!$this->_getParam('title_search')) + $bib_id_param = ['cat_id' => $album->getCatId()]; + $form->addAttribs(['data-backurl' => $this->_view->url(array_filter(array_merge(['action' => 'index'], $bib_id_param)))]); + return $form; + } + + + protected function _getForm($album){ + return $this->_albumForm($album); + } + + + /** + * @param Class_AlbumRessource $ressource + * @return Zend_Form + */ + protected function _ressourceForm($ressource) { + return ZendAfi_Form_Album_Ressource::newWith($ressource); + } + + /** + * @param Class_Album $album + * @return null + */ + public function _validateAndSaveAlbum($album) { + $form = $this->_albumForm($album); + $this->_view->form = $form; + + if ( + !$this->_request->isPost() + or !$form->isValid($this->_request->getPost()) + ) + return; + + $values = $form->getValues(); + + unset($values['fichier']); + unset($values['pdf']); + unset($values['album_items']); + + $droits_precision = $values['droits_precision']; + unset($values['droits_precision']); + + $values['droits'] = $form->isPublicDomain() + ? $form->getPublicDomain() + : $droits_precision; + + $frbr_multi = $values['frbr_multi']; + unset($values['frbr_multi']); + + $album->updateAttributes($values); + + if ($album->save() + && $album->receiveFile() + && $album->receivePDF()) { + + $album->index(); + + $frbr_links = []; + foreach(Class_FRBR_Link::findAllRecordLinksForAlbum($album) as $link) + $frbr_links[md5($link->getSource().$link->getTarget())] = $link; + + $absoluteUrl = $this->_view->absoluteUrl(array_merge(['id' => $album->getId()], + $album->getPermalink()), null, true); + + $received_links = []; + $urls = $frbr_multi['frbr_url']; + $types = $frbr_multi['frbr_type']; + $count = count($urls); + for($i=0; $i < $count; $i++) { + if (!$types[$i] && !$urls[$i]) + continue; + + list($id, $type) = explode(':', $types[$i]); + $md5 = md5('target' == $type ? ($urls[$i] . $absoluteUrl) : ($absoluteUrl . $urls[$i])); + + $received_links[$md5] = ['frbr_url' => $urls[$i], 'frbr_type' => $id, 'type' => $type]; + } + + foreach(array_diff_key($frbr_links, $received_links) as $link) + $link->delete(); + + foreach(array_diff_key($received_links, $frbr_links) as $new) { + $record_type = 'target' == $new['type'] ? 'source' : 'target'; + $frbr_link = Class_FRBR_Link::newInstance([$new['type'] => $absoluteUrl, + $record_type => $new['frbr_url'], + 'type_id' => $new['frbr_type']]); + + if (!$frbr_link->save()) + throw new Zend_Exception(json_encode($frbr_link->getErrors())); + } + + (new Storm_Cache())->clean(); + $this->_helper->notify('Album sauvegardé'); + + return true; + } + return false; + } + + + /** + * @return ZendAfi_Form + */ + public function _thumbnailsForm($album) { + if (!$form = ZendAfi_Form_Album_DisplayAbstract::forAlbum($album, ['id' => 'thumbnails'])) + return; + $form->addAttribs(['data-backurl' => $this->_view->url(['action' => 'index', + 'cat_id' => $album->getCatId()])]); + return $form->populate($album->toArray()); + } + + + /** + * @param Class_Album $album + * @param string $titre + */ + protected function _renderAlbumForm($album, $titre) { + if ($this->_validateAndSaveAlbum($album)) + return $this->_redirectToEdit($album);; + + $this->_view->titre = $titre; + $this->_view->errors = $album->getErrors(); + $this->_view->album = $album; + $this->_view->form->getElement('fichier') + ->setValue($album->getFichier()); + $this->_view->form->getElement('pdf') + ->setValue($album->getPdf()); + + if ($this->_controller->isPopupRequest()) + $this->_prepareAlbumAjaxFrom(); + + $this->_view_renderer->setScriptAction('album_form'); + } + + + protected function _getEditUrl($model) { + return Class_Url::absolute(['action' => 'edit_album', + 'id' => $model->getId(), + 'page' => $this->_getParam('page'), + 'title_search' => $this->_getParam('title_search')]); + } + + + protected function _prepareAlbumAjaxFrom() { + $id_notice = $this->_getParam('id_notice') + ? $this->_getParam('id_notice') + : ''; + + $this->_view->form->beSimple() + ->setAction($this->_view->url(['action' => 'link_album_to', + 'id_notice' => $id_notice])) + ->setEnctype('application/x-www-form-urlencoded'); + + if (!$this->_request->isPost()) { + $notice = Class_Notice::find($id_notice); + $this->_view->form->populateFrbrUrl( + $this->_view->absoluteUrl($this->_view->urlNotice($notice, [], null, true), null, true)); + + $this->_view->form->getElement('titre')->setValue($notice->getTitrePrincipal()); + } + } + + + public function addWebsiteAction() { + $import_form = $this->_view + ->newForm(['id' => 'import', 'class' => 'form']) + ->setMethod('post') + ->addElement('url', 'url', ['label' => $this->_view->_('URL du site web'), + 'required' => true, + 'allowEmpty' => false]) + ->addDisplayGroup(['url'], 'website', ['legend' => $this->_view->_('Site web')]) + ->addElement('submit', 'submit', ['label' => $this->_view->_('Importer')]); + + if ($this->_request->isPost() && $import_form->isValid($this->_request->getPost())) { + $album = $this->createAlbumFromUrl($this->_request->getPost('url')); + if ($album && $album->save()) { + $this->_redirect('/admin/album/edit_album/id/'.$album->getId()); + return; + } + } + + $this->_view->import_form = $import_form; + } + + + + public function resourceDeletePosterAction() { + $this->_helper->getHelper('viewRenderer')->setNoRender(true); + + if (!$resource = Class_AlbumRessource::find((int)$this->_getParam('id'))) { + $this->_redirect('admin/album'); + return; + } + + $resource->deletePoster()->save(); + $this->_redirect('admin/album/edit_ressource/id/' . $resource->getId()); + } + + + protected function createAlbumFromUrl($url) { + $html = Class_WebService_SimpleWebClient::getInstance()->open_url($url); + $dom = new Zend_Dom_Query($html); + + $category = Class_AlbumCategorie::getOrCreateRootCategory('Sites web'); + + $album = Class_Album::newInstance(['type_doc_id' => Class_TypeDoc::WEBSITE, + 'categorie' => $category]); + + $title_node = $dom->queryXpath('//head/title')->current(); + $album->setTitre($title_node ? trim($title_node->textContent) : $url); + + if ($description_node = $dom->queryXpath('//head/meta[@name="description"]')->current()) + $album->setDescription($description_node->getAttribute('content')); + + $resource = Class_AlbumRessource::newInstance(['url' => $url, + 'titre' => $album->getTitre(), + 'description' => $album->getDescription()]); + $album->addRessource($resource); + $album->save(); + + $thumbnailer = (new Class_WebService_WebSiteThumbnail()); + + $poster_name = $thumbnailer->fileNameFromUrl($url); + $poster_path = $resource->getPosterPath(); + + $resource->getFolderManager()->ensure($poster_path); + $thumbnailer->getThumbnailer()->fetchUrlToFile($url, $poster_path . $poster_name, 'medium'); + + $resource->setPoster($poster_name); + $resource->createThumbnail(); + + return $album; + } + + + + + public function getActions($model) { + if('Class_Album' == get_class($model)) + return $this->_albumActions($model); + + if('Class_AlbumCategorie' == get_class($model)) + return $this->_albumCategoryActions($model); + + return []; + } + + + protected function _albumActions($model) { + return [ + ['url' => ['module' => 'admin', + 'controller' => 'album', + 'action' => 'edit_album', + 'id' => '%s'], + 'icon' => 'edit', + 'label' => 'Modifier l\'album'], + + ['url' => ['module' => 'admin', + 'controller' => 'album', + 'action' => 'edit_images', + 'id' => '%s'], + 'icon' => 'images', + 'label' => 'Gérer les médias', + 'caption' => 'formatedCount'], + + ['url' => ['module' => 'admin', + 'controller' => 'album', + 'action' => 'preview_album', + 'id' => '%s'], + 'icon' => function($model) {return $model->isVisible() ? 'view' : 'hide';}, + 'label' => 'Visualisation de l\album'], + + ['url' => ['module' => 'admin', + 'controller' => 'album', + 'action' => 'delete_album', + 'id' => '%s'], + 'icon' => 'delete', + 'label' => 'Supprimer l\'album', + 'anchorOptions' => ['onclick' => 'return confirm(\'Êtes-vous sûr de vouloir supprimer cet album;\')']] + ]; + } + + + protected function _albumCategoryActions($model) { + return [ + ['url' => ['module' => 'admin', + 'controller' => 'album', + 'action' => 'add_categorie_to', + 'id' => '%s'], + 'icon' => 'add_category', + 'label' => 'Ajouter une sous-catégorie'], + + ['url' => ['module' => 'admin', + 'controller' => 'album', + 'action' => 'add_album_to', + 'id' => '%s'], + 'icon' => 'add_page', + 'label' => 'Ajouter un album'], + + ['url' => ['module' => 'admin', + 'controller' => 'album', + 'action' => 'edit_categorie', + 'id' => '%s'], + 'icon' => 'edit', + 'label' => 'Modifier la catégorie'], + + ['url' => ['module' => 'admin', + 'controller' => 'album', + 'action' => 'delete_categorie', + 'id' => '%s'], + 'icon' => 'delete', + 'label' => 'Supprimer la catégorie', + 'anchorOptions' => ['onclick' => "return confirm('Etes-vous sûr de vouloir supprimer cette catégorie ?')"]] + ]; + } +} \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/Manager/Article.php b/library/ZendAfi/Controller/Plugin/Manager/Article.php new file mode 100644 index 0000000000000000000000000000000000000000..cbd4a7fb983c0ffcd317f331719c4ca24f7ddc83 --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/Manager/Article.php @@ -0,0 +1,544 @@ +<?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_Article extends ZendAfi_Controller_Plugin_Manager_Manager { + public function deleteAction() { + if (!$article = Class_Article::find((int)$this->_getParam('id'))) { + $this->_redirect('admin/cms'); + return; + } + + $this->_view->titre = $this->_view->_('Supprimer l\'article : %s', + $article->getTitre()); + + + if (!$this->_canModify($article->getCategorie())) { + $this->_helper->notify($this->_view->_('Vous n\'avez pas la permission "%s"', + $this->_view->titre)); + $this->_redirectToIndex(); + return; + } + + $this->_view->model = $article; + } + + +public function newsduplicateAction() { + if (!$model = Class_Article::find($this->_getParam('id'))) + return $this->_redirect('admin/cms'); + + if (!$this->_canModify($model->getCategorie())) { + $this->_helper->notify($this->_view->_('Vous n\'avez pas la permission "%s"', + $this->_view->titre)); + return $this->_redirectToIndex(); + } + + if($category = $model->getCategorie()) + $this->_setParam('id_cat', $category->getId()); + + parent::addAction(); + if ($this->_response->isRedirect()) + return; + $this->_view->titre = $this->_view->_('Dupliquer l\'article : %s', $model->getTitre()); + $this->_view->form + ->setAction($this->_view->url(['module' => 'admin', + 'controller' => 'cms', + 'action' => 'add', + 'id_cat' => $this->_getParam('id_cat')], + null, true)); + + $this->_view_renderer->setScriptAction('add'); + } + + + public function makevisibleAction() { + $this->_toggleVisibility('visible'); + } + + + public function makeinvisibleAction() { + $this->_toggleVisibility('invisible'); + } + + + public function forceDeleteAction() { + if (!$article = Class_Article::find((int)$this->_getParam('id'))) { + $this->_redirect('admin/cms'); + return; + } + + if (!$this->_canModify($article->getCategorie())) { + $this->_helper->notify($this->_view->_('Vous n\'avez pas la permission "%s"', + $this->_view->_('Supprimer l\'article : %s', + $article->getTitre()))); + $this->_redirectToIndex(); + return; + } + + $article->delete(); + $this->_redirect($this->_backDeleteUrl($article)); + } + + + protected function _getDefaultModel($models) { + $article = $this->_getNewModel(); + $cat = Class_ArticleCategorie::findDistinctCategories($models); + if (count($cat)==1) { + $article->setCategorie($cat[0]); + } + + $status = Class_Article::findDistinctStatus($models); + if (count($status)==1) { + $article->setStatus($status[0]->getStatus()); + } + + return $article; + } + + + protected function _updateNewModel($article) { + if ('newsduplicate' == $this->_request->getActionName() + && $original = Class_Article::find($this->_getParam('id', 0))) { + $article->updateAttributes($original->copy()->toArray()); + return $this; + } + + $article->setAuteur(Class_Users::getIdentity()); + + if (!$category = $this->getCategoryAndSetComboCat()) + return $this; + + $article->setCategorie($category); + if ($domaine = Class_Catalogue::findWithSamePathAs($category)) + $article->setDomaineIds($domaine->getId()); + return $this; + } + + + public function getCategoryAndSetComboCat() { + if (!$category = Class_ArticleCategorie::find($this->_getParam('id_cat'))) { + $this->_redirect('admin/cms'); + return; + } + + if (null === ($category->getBib())) + $category->setBib($this->_bib); + + $this->_view->combo_cat = $this->_view->comboCategories($category); + return $category; + } + + + + protected function _doBeforeSave($article) { + $article->updateDateMaj(); + return $this; + } + + + protected function _doAfterSave($article) { + if($id_module = $this->_getParam('id_module')) + $this->updateConfigBoiteNews($id_module,$article); + $this->_notifyArticleChanged($article); + return $this; + } + + + protected function _toggleVisibility($visibility) { + if (!$article = Class_Article::getLoader()->find((int)$this->_getParam('id'))) { + $this->_redirect('admin/cms'); + return; + } + + if (!$this->_canModify($article->getCategorie())) { + $this->_helper->notify($this->_view->_('Vous n\'avez pas la permission "%s"', + $this->_view->_('Rendre %s l\'article : %s', + $visibility, + $article->getTitre()))); + $this->_redirectToIndex(); + return; + } + + $method = 'be' . ucfirst($visibility); + $article->$method(); + $this->_redirect($this->_backUrl($article)); + } + + + protected function _findModel() { + if (!$article = Class_Article::find((int)$this->_getParam('id'))) + return null; + + if ($lang = $this->_getParam('lang')) + return $article->getOrCreateTraductionLangue($lang); + + return $article; + } + + + protected function _canEdit($model) { + $this->_setParam('id_cat',null); + return $this->_canModify($model->getCategorie()); + } + + + protected function _canModify($category) { + return Class_Users::getIdentity() + ->hasAnyPermissionOn($category, + [Class_Permission::createArticle(), + Class_Permission::createArticleCategory()]); + } + + + protected function _getEditActionTitle($model) { + return $model->isTraduction() + ? $this->_view->_('Traduire un article: %s', $model->getLibelle()) + : $this->_view->_('Modifier un article: %s', $model->getLibelle()); + } + + + protected function _getEditUrl($model) { + $this->_request->setParamSources(['_GET']); + $url = parent::_getEditUrl($model) + . (($page = $this->_getParam('page')) ? '/page/'.$page : '') + . (($id_cat = $this->_getParam('id_cat')) ? '/id_cat/'.$id_cat : '') + . (($title_search = $this->_getParam('title_search')) ? '/title_search/' . $title_search : ''); + $this->_request->setParamSources(['_GET', '_POST']); + return $url; + } + + + protected function _getFormValues($model) { + $attributes=parent::_getFormValues($model); + foreach(['description', 'contenu'] as $content_field) + $attributes[$content_field] = Class_CmsUrlTransformer::forEditing($attributes[$content_field]); + + $attributes['pick_day'] = $model->getPickDayAsArray(); + return $attributes; + } + + + protected function _getForm($model) { + $this->_setFormClassName($model->isTraduction() + ? 'ZendAfi_Form_Admin_NewsTranslation' + : 'ZendAfi_Form_Admin_News'); + $form = parent::_getForm($model); + $form->setAttrib('data-backurl', Class_Url::absolute($this->_backUrl($model))); + return $form; + } + + + protected function _canAdd() { + $category = Class_ArticleCategorie::find($this->_getParam('id_cat')); + return $category && $this->_canModify($category); + } + + + + protected function _backUrl($model) { + if (!Class_AdminVar::isArticlesListMode()) + return 'admin/cms/index' . (!$model->isNew() ? '/id/' . $model->getId() : ''); + + return $this->_view->absoluteUrl(['module' => 'admin', + 'controller' => 'cms', + 'action' => 'index']); + } + + + protected function _backDeleteUrl($model) { + return sprintf('admin/cms/index/id_cat/%d%s', + ($cat = $model->getCategorie()) ? $cat->getId() : 0, + ($page = $this->_getParam('page')) ? '/page/'.$page : ''); + } + + protected function _notifyArticleChanged($article) { + if (!Class_AdminVar::isWorkflowEnabled()) + return; + $this->_sendMailWhenUpdatedStatusToValidationPending($article); + $this->_sendMailWhenUpdatedStatusToRefused($article); + $this->_sendMailWhenUpdatedStatusToValidated($article); + } + + + protected function _sendMailWhenUpdatedStatusToRefused($article) { + if ($article->old_status != Class_Article::STATUS_REFUSED && + $article->getStatus() == Class_Article::STATUS_REFUSED) { + $this->_sendRefusedMailToAuteur($article); + } + } + + + protected function _sendMailWhenUpdatedStatusToValidated($article) { + if ($article->old_status != Class_Article::STATUS_VALIDATED && + $article->getStatus() == Class_Article::STATUS_VALIDATED) { + $this->_sendValidatedMailToAuteur($article); + } + } + + + protected function _sendMailWhenUpdatedStatusToValidationPending($article) { + if (($article->old_status != Class_Article::STATUS_VALIDATION_PENDING && + $article->getStatus() == Class_Article::STATUS_VALIDATION_PENDING) + || ($article->getStatus() > 5 + && $article->old_status != $article->getStatus())) { + $this->_sendMailToValidators($article); + } + } + + + protected function prepareMailForAuteur($article) { + $mail = new ZendAfi_Mail('utf8'); + if(!$article->getAuteur()) { + $this->_helper->notify('Mail non envoyé: article sans auteur'); + return; + } + + if(!$mail_address = $article->getAuteur()->getMail()) { + $this->_helper->notify('Mail non envoyé: '.$article->getNomCompletAuteur().' sans mail.'); + return; + } + + $mail->setFrom('no-reply@afi-sa.fr') + ->addTo($mail_address); + return $mail; + } + + + protected function prepareBodyMail($article, $message) { + $this->identity = Class_Users::getIdentity(); + $replacements = + ['TITRE_ARTICLE' => $article->getTitre(), + 'URL_ARTICLE' => $this->_view->absoluteUrl($article->getUrl(), null, true), + 'AUTHOR_ARTICLE' => $article->getNomCompletAuteur(), + 'SAVED_BY_ARTICLE' => $this->identity->getNomComplet(), + 'NEXT_STATUS_ARTICLE' => $article->getNextWorkflowStatusLabel(), + 'STATUS_ARTICLE' => $article->getStatusLabel()]; + + return + str_replace(array_keys($replacements), + array_values($replacements), + $message); + } + + + protected function _sendRefusedMailToAuteur($article) { + if(!$mail = $this->prepareMailForAuteur($article)) + return; + $body = $this->prepareBodyMail($article, $article->getRefusMessage()); + $this->sendPreparedMail($mail, + '[Bokeh] Refus de l\'article '.$article->getTitre(), + $body); + } + + + protected function sendPreparedMail($mail, $subject, $body) { + $mail->setSubject(quoted_printable_decode($subject)) + ->setBodyText($body,'utf-8',Zend_Mime::ENCODING_8BIT); + + if ($this->_sendMail($mail)) + $this->_helper->notify('Mail envoyé à : '.$mail->getRecipients()[0]); + } + + + protected function _sendValidatedMailToAuteur($article) { + if(!$mail = $this->prepareMailForAuteur($article)) + return; + + $body = $this->prepareBodyMail($article, $article->getValideMessage()); + $this->sendPreparedMail($mail, + '[Bokeh] Validation de l\'article '.$article->getTitre(), + $body); + } + + + protected function _getValidatorsMail($article) { + return array_unique( + Class_Permission::getWorkflow($article->getNextWorkflowStatus()) + ->getUsersOnModel($article->getCategorie()) + ->collect('mail') + ->getArrayCopy()); + } + + + protected function _sendMailToValidators($article) { + if (!$mails = $this->_getValidatorsMail($article)) + return; + + $mail = new ZendAfi_Mail('utf8'); + $mail + ->setFrom('no-reply@afi-sa.fr') + ->addTo(implode(',', $mails)) + ->setSubject($this->_view->_('[Bokeh] Validation d\'article en attente: ') . $article->getTitre()) + ->setBodyText($this->prepareBodyMail($article, + Class_AdminVar::getWorkflowTextMailArticlePending())); + + if($this->_sendMail($mail)) + $this->_helper->notify($this->_view->_('Mail de validation envoyé aux validateurs.')); + } + + + protected function _sendMail($mail) { + try { + $mail->send(); + return true; + + } catch (Exception $e) { + $this->_helper->notify('Mail non envoyé: vérifier la configuration du serveur de mail.'); + return false; + } + } + + + protected function updateConfigBoiteNews($id_module, $article){ + $profil = Class_Profil::getCurrentProfil(); + $module_config = $profil->getModuleAccueilConfig($id_module, 'NEWS'); + $id_items= array_filter(explode('-',$module_config['preferences']['id_items'])); + array_unshift($id_items,$article->getId()); + $module_config['preferences']['id_items'] = implode('-',$id_items); + $profil->updateModuleConfigAccueil($id_module, $module_config); + $profil->save(); + return $this; + } + + + public function getActions($model) { + if('Class_Article' == get_class($model)) + return $this->_articleActions($model); + + if('Class_ArticleCategorie' == get_class($model)) + return $this->_articleCategoryActions($model); + + if('Class_Bib' == get_class($model)) + return $this->_bibActions($model); + + return []; + } + + + protected function _articleActions($model) { + $this->identity = Class_Users::getIdentity(); + + $permission_closure = function($model) { + return $this->identity + ->hasAnyPermissionOn($model->getCategorie(), + [Class_Permission::createArticle(), + Class_Permission::createArticleCategory()]); + }; + return [ + ['url' => '/admin/cms/makeinvisible/id/%s', + 'icon' => 'show', + 'label' => 'Rendre cet article invisible', + 'condition' => function($model) use ($permission_closure) { + return $permission_closure($model) && $model->isVisible(); + }], + + ['url' => '/admin/cms/makevisible/id/%s', + 'icon' => 'hide', + 'label' => 'Rendre cet article visible', + 'condition' => function($model) use ($permission_closure) { + return $permission_closure($model) && $model->isNotVisible(); + }], + + ['url' => '/admin/cms/edit/id/%s', + 'icon' => 'edit', + 'label' => 'Modifier', + 'condition' => $permission_closure], + + ['url' => '/admin/cms/newsduplicate/id/%s', + 'icon' => 'copy', + 'label' => 'Dupliquer', + 'condition' => $permission_closure], + + ['url' => '/admin/cms/delete/id/%s', + 'icon' => 'delete', + 'label' => 'Supprimer', + 'condition' => $permission_closure] + ]; + } + + + protected function _articleCategoryActions($model) { + $this->identity = Class_Users::getIdentity(); + $parent_permission = function($model) { + return $this->identity + ->hasParentPermissionOn(Class_Permission::createArticleCategory(), + $model); + }; + + return [ + ['url' => '/admin/cms-category/edit/id/%s', + 'icon' => 'edit', + 'label' => 'Modifier', + 'condition' => $parent_permission], + + ['url' => '/admin/cms-category/delete/id/%s', + 'icon' => 'delete', + 'label' => 'Supprimer', + 'condition' => function($model) use ($parent_permission) { + return $parent_permission($model) && $model->hasNoChild(); + }, + 'anchorOptions' => [ + 'onclick' => "return confirm('Etes-vous sûr de vouloir supprimer cette catégorie ?')"]], + + ['url' => '/admin/cms/add/id_cat/%s', + 'icon' => 'add_page', + 'label' => 'Ajouter un article', + 'condition' => function($model) { + return $this->identity + ->hasAnyPermissionOn($model, + [Class_Permission::createArticle(), + Class_Permission::createArticleCategory()]); + }], + + ['url' => '/admin/cms-category/add/id/%s', + 'icon' => 'add_category', + 'label' => 'Ajouter une sous-catégorie', + 'condition' => function($model) { + return $this->identity + ->hasPermissionOn(Class_Permission::createArticleCategory(), + $model); + }] + ]; + } + + + protected function _bibActions($model) { + $this->_identity = Class_Users::getIdentity(); + + return [ + ['url' => '/admin/cms-category/add/id_bib/%s', + 'icon' => 'add_category', + 'label' => 'Ajouter une catégorie', + 'condition' => function($model) { + return $this->_identity->isRoleMoreThanModoPortail() + || $this->_identity->hasPermissionOn(Class_Permission::createArticleCategory(), + $model); + }], + ['url' => '/admin/bib/permissions/id/%s', + 'icon' => 'groups', + 'label' => 'Permissions par défaut', + 'condition' => function($model) { + return $this->_identity->isRoleMoreThanModoPortail(); + }] + ]; + } +} \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/Manager/ArticleCategory.php b/library/ZendAfi/Controller/Plugin/Manager/ArticleCategory.php new file mode 100644 index 0000000000000000000000000000000000000000..9086cc5bd6d3d9f393eaf0717d12ffc95af32fd2 --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/Manager/ArticleCategory.php @@ -0,0 +1,112 @@ +<?php +/** + * Copyright (c) 2012-2014, 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_ArticleCategory extends ZendAfi_Controller_Plugin_Manager_Manager { + protected function _updateNewModel($model) { + if ($parent = Class_ArticleCategorie::find($this->_getParam('id'))) { + $model->setParentCategorie($parent) + ->setBib($parent->getBib()); + return; + } + + $this->_handleBibFor($model); + } + + + protected function _handleBibFor($category) { + if ($bib = $this->getDefaultBib()) + $category->setBib($bib); + } + + + protected function _redirectToTreeView($model) { + $this->_redirect($this->_backUrl($model)); + } + + + protected function _backUrl($model) { + $is_list_mode = Class_AdminVar::isArticlesListMode(); + if (($model->isNew() || $is_list_mode) + && $parent = $model->getParentCategorie()) + return $this->_withPageUrl(sprintf('admin/cms/index/id_cat/%d', $parent->getId())); + + return $this->_withPageUrl($is_list_mode ? + sprintf('admin/cms/index/id_bib/%d', + ($bib = $model->getBib()) ? $bib->getId() : 0) : + sprintf('admin/cms/index/id_cat/%d', $model->getId())); + } + + + protected function _deleteBackUrl($model) { + $is_list_mode = Class_AdminVar::isArticlesListMode(); + if ($parent = $model->getParentCategorie()) + return $this->_withPageUrl(sprintf('admin/cms/index/id_cat/%d', $parent->getId())); + + return $this->_withPageUrl($is_list_mode ? + sprintf('admin/cms/index/id_bib/%d', + ($bib = $model->getBib()) ? $bib->getId() : 0) : + 'admin/cms/index'); + } + + + protected function _withPageUrl($url) { + return ($page = $this->_getParam('page')) + ? $url . '/page/' . $page : $url; + } + + + protected function _postEditAction($model) { + if (null === $model->getBib()) + $this->_handleBibFor($model); + + if (Class_Users::getIdentity()->isRoleMoreThanModoPortail()) + $this->_view->permissions = $this->_view + ->groupsPermissions($model, + Class_Permission::getCmsPermissions(), + $this->_view->url(['module' => 'admin', + 'controller' => 'cms-category', + 'action' => 'permissions', + 'id' => $model->getId()], + null, true)); + } + + + protected function getDefaultBib() { + $identity = Class_Users::getIdentity(); + + return ZendAfi_Acl_AdminControllerRoles::ADMIN_BIB >= $identity->getRoleLevel() ? + $identity->getBib() : Class_Bib::find((int)$this->_getParam('id_bib')); + } + + + + /** + * @param Storm_Model_Abstract $model + * @return Zend_Form + */ + protected function _getForm($model) { + $form = parent::_getForm($model); + $form->setAttrib('data-backurl', Class_Url::absolute($this->_backUrl($model))); + return $form; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/Manager/CustomField.php b/library/ZendAfi/Controller/Plugin/Manager/CustomField.php new file mode 100644 index 0000000000000000000000000000000000000000..8334a3c002e5fdbb0f7ce539c9aeaec5c400a00e --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/Manager/CustomField.php @@ -0,0 +1,71 @@ +<?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_CustomField extends ZendAfi_Controller_Plugin_Manager_Manager { + + public function addAction() { + $model = $this->_getParam('model'); + $this->_view->form = ZendAfi_Form_Admin_CustomFields_CustomFieldModel::newWith([ 'model' => $model]); + + $this->_view->custom_fields_metas = Class_CustomField::getAvailableMeta($model); + + parent::addAction(); + } + + + public function deleteAction() { + if ($field = Class_CustomField::find($this->_getParam('id', 0))) + $this->_setParam('model', $field->getModel()); + parent::deleteAction(); + } + + + public function getActions($model) { + if('Class_CustomField_Model' == get_class($model)) + return + [ + ['url' => '/admin/custom-fields/add/model/%s', + 'label' => 'Rattacher un champ personnalisé', + 'icon' => 'add_page'] + ]; + + return [ + ['url' => '/admin/custom-fields/up/id/%s', + 'icon' => 'up', + 'label' => 'Monter'], + + ['url' => '/admin/custom-fields/down/id/%s', + 'icon' => 'down', + 'label' => 'Descendre'], + + ['url' => '/admin/custom-fields/edit/id/%s', + 'icon' => 'edit', + 'label' => 'Modifier'], + + ['url' => '/admin/custom-fields/delete/id/%s', + 'icon' => 'delete', + 'label' => 'Supprimer', + 'anchorOptions' => ['onclick' => "return confirm('Etes-vous sûr de vouloir supprimer ce champs ?');"]] + ]; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/Manager/CustomFieldsReport.php b/library/ZendAfi/Controller/Plugin/Manager/CustomFieldsReport.php new file mode 100644 index 0000000000000000000000000000000000000000..b47e2b57b78a306633efae8853f498a046b2d2ff --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/Manager/CustomFieldsReport.php @@ -0,0 +1,29 @@ +<?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_CustomFieldsReport extends ZendAfi_Controller_Plugin_Manager_Manager { + public function addAction() { + parent::addAction(); + $this->_controller->render('edit'); + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/Manager/DataProfile.php b/library/ZendAfi/Controller/Plugin/Manager/DataProfile.php new file mode 100644 index 0000000000000000000000000000000000000000..5dd9ea36309c84bb13116be9d2d981ccdd0ef059 --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/Manager/DataProfile.php @@ -0,0 +1,84 @@ +<?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_DataProfile extends ZendAfi_Controller_Plugin_Manager_Manager { + + protected function _setupFormAndSave($model) { + $model = $this->_autoUpdateFormatInModel($model); + $form = $this->_getForm($model); + + $this->_view->form = $form; + if (!$this->_request->isPost()) + return false; + + $values = $this->_autoUpdateFormat($this->_getPost()); + + $attributes_values = $this->_extractAttributesFrom($values); + $model->updateAttributes($attributes_values); + + $profile_prefs = $this->_extractProfilePrefsFrom($values); + $model->setAttributs($profile_prefs); + + if ((!$form->isValidModelAndArray($model, $values))) + return false; + + return $model->save(); + } + + + protected function _autoUpdateFormatInModel($model) { + $attributes = $this->_autoUpdateFormat($model->toArray(), $model); + $model->updateAttributes($attributes); + return $model; + } + + + protected function _autoUpdateFormat($attributes) { + $old_format = $attributes['format']; + $default_formats = Class_IntProfilDonnees::getFormatsForType($attributes['type_fichier']); + + if(!key_exists($old_format, $default_formats)) { + $keys = array_keys($default_formats); + $attributes['format'] = array_shift($keys); + } + + return $attributes; + } + + + protected function _extractAttributesFrom($values) { + $default_values = Class_IntProfilDonnees::getClassVar('_default_attribute_values'); + return array_intersect_key($values, $default_values); + } + + + protected function _extractProfilePrefsFrom($values) { + return (new Class_ProfileSerializer($values))->serializeDatas(); + } + + + protected function _getEditUrl($model) { + return sprintf('/cosmo/%s/edit/id/%s', + $this->_request->getControllerName(), $model->getId()); + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/Manager/Library.php b/library/ZendAfi/Controller/Plugin/Manager/Library.php new file mode 100644 index 0000000000000000000000000000000000000000..43a1e462ff80253e5e72bea9e8650ff11c6d844c --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/Manager/Library.php @@ -0,0 +1,57 @@ +<?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_Library extends ZendAfi_Controller_Plugin_Manager_Manager { + protected function _canEdit($model) { + return $this->_controller->canAccessToLibrary(); + } + + + protected function _canAdd() { + return $this->_controller->canAccessToLibrary(); + } + + + + protected function _doBeforeSave($model) { + if ($location = $this->_controller->getOrCreateLocation($this->_getParam('id_lieu'), $model)) + $model->setLieu($location); + return $this; + } + + + public function deleteAction() { + $bib = Class_Bib::find((int)$this->_request->getParam('id')); + $this->_view->titre = $this->_view->_('Supprimer la bibliothèque: %s', $bib->getLibelle()); + $this->_view->bib = $bib; + } + + + public function forceDeleteAction() { + $bib = Class_Bib::find((int)$this->_request->getParam('id')); + $bib->delete(); + $this->_helper->notify('La bibliothèque "'.$bib->getLibelle().'" a été supprimée'); + $this->_redirect('admin/bib/index'); + } + +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/Manager/Lieu.php b/library/ZendAfi/Controller/Plugin/Manager/Lieu.php new file mode 100644 index 0000000000000000000000000000000000000000..a6b2ca62c54c6d8d795521fb983889c15ef3f2ae --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/Manager/Lieu.php @@ -0,0 +1,48 @@ +<?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 diff --git a/library/ZendAfi/Controller/Plugin/Manager/Manager.php b/library/ZendAfi/Controller/Plugin/Manager/Manager.php new file mode 100644 index 0000000000000000000000000000000000000000..63033059ec9aa4882da4ec200a2e551fb274cc0b --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/Manager/Manager.php @@ -0,0 +1,514 @@ +<?php +/** + * Copyright (c) 2012-2014, 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_Manager extends ZendAfi_Controller_Plugin_Abstract { + + public function init() { + parent::init(); + + if (('add' != $this->_request->getActionName()) + && ('index' != $this->_request->getActionName()) + && ($model = $this->_findModel())) + $this->_addModelToView($model); + } + + + public function renderHeaderActions() { + if (('add' == $this->_request->getActionName()) + || ('index' == $this->_request->getActionName())) + return ''; + + if (($model_name = $this->_view->model_name) + && ($model = $this->_view->$model_name)) + return $this->_view + ->tag('div', + $this->_view->renderPluginsActions($model), + ['class' => 'header_actions']); + return ''; + } + + + public function acceptVisitor($visitor) { + $visitor->visitGetForm(function($model) + { + return $this->_getForm($model); + }) + ->visitDoBeforeSave(function($model) + { + return $this->_doBeforeSave($model); + }) + ->visitDoAfterSave(function($model) + { + return $this->_doAfterSave($model); + }) + ->visitCustomFieldModelValues(function($model) + { + return $this->_getCustomFieldModelValues($model); + }) + ->visitCustomFieldForm(function($model) + { + return $this->_getCustomFieldForm($model); + }) + ->visitDefaultModel(function($models) + { + return $this->_getDefaultModel($models); + }) + ->visitProcessMultiCheckbox(function($form, $clean) + { + return $this->processMulticheckboxFromPost($form, $clean); + }) + ->visitCustomValues(function() { + return $this->custom_values; + }) + ->visitAddModelToView(function($model) + { + return $this->_addModelToView($model); + }); + return $this; + } + + + public function addAction() { + if ($this->_response->isRedirect()) + return; + + if (!$this->_canAdd()) { + $this->_helper->notify($this->_view->_('Vous n\'avez pas la permission "%s"', + $this->_getAddActionTitle())); + return $this->_redirectToIndex(); + } + + $this->_view->titre = $this->_getAddActionTitle(); + $model = $this->_getNewModel(); + $this->_updateNewModel($model); + $this->_addModelToView($model); + + if ($this->_setupFormAndSave($model)) { + $this->_helper->notify($this->_getSuccessfulAddMessage($model)); + $this->_redirectToEdit($model); + $this->_getDoAfterAdd($model); + } + } + + + public function editAction() { + if ($this->_response->isRedirect()) + return; + + if (!$model = $this->_findModel()) { + $this->_redirectToIndex(); + return; + } + + if (!$this->_canEdit($model)) { + $this->_helper->notify($this->_view->_('Vous n\'avez pas la permission "%s"', + $this->_getEditActionTitle($model))); + $this->_redirectToIndex(); + return; + } + + $this->_view->titre = $this->_getEditActionTitle($model); + $this->_addModelToView($model); + + if ($this->_setupFormAndSave($model)) { + $this->_helper->notify($this->_getSuccessfulSaveMessage($model)); + $this->_redirectToEdit($model); + $this->_getDoAfterEdit($model); + } + + $this->_postEditAction($model); + } + + + + public function deleteAction() { + if ($this->_response->isRedirect()) + return; + + if ($model = $this->_findModel()) { + $values = $this->_getCustomFieldModelValues($model); + $values->deleteValues(); + $model->delete(); + $this->_helper->notify($this->_getSuccessfulDeleteMessage($model)); + } + + $this->_redirectToIndex(); + $this->_getDoAfterDelete($model); + } + + + protected function _postEditAction($model) {} + + + protected function _canEdit($model) { + return true; + } + + + protected function _getEditUrl($model) { + return sprintf('/admin/%s/edit/id/%s', + $this->_request->getControllerName(), $model->getId()); + } + + + protected function _redirectToEdit($model) { + $this->_redirectClose($this->_getEditUrl($model)); + } + + + protected function _getFormWith($model, $custom_form) { + $formClass = $this->_getFormClassName(); + foreach ($custom_form->getElements() as $element) { + if (!$value=$this->_request->getParam($element->getName())) + continue; + $element->setValue($value); + } + + $form = $formClass::newWith( + array_merge($this->_getFormValues($model), $this->_request->getParams()), + $custom_form + ); + $form->setAction($this->_view->url()); + return $form; + + } + + + protected function _getFormValues($model) { + return $model->toArray(); + } + + + /** + * @param Storm_Model_Abstract $model + * @return Zend_Form + */ + protected function _getForm($model) { + $model_values = $this->_getCustomFieldModelValues($model); + $custom_form = $this->_getCustomFieldForm($model_values); + + if ($this->_getFormClassName()) + return $this->_getFormWith($model, $custom_form); + + if (!$form = $this->_getFormInstance()) { + $form = new ZendAfi_Form( ['id' => $this->_getModelName()] ); + $form->populateFormFromGroupsDefinitions($this->_getDisplayGroups()); + } + + $form = $form->populate($this->_request->getParams()); + $form = $form->populate($this->_getFormValues($model)); + + return $form + ->populate($this->_request->getParams()) + ->populate($this->_getFormValues($model)); + } + + + protected function _setupFormAndSave($model) { + $form = $this->_getForm($model); + + $this->_view->form = $form; + if (!$this->_request->isPost()) + return false; + + $post = $this->processMulticheckboxFromPost($form); + $model->updateAttributes($post); + + if ((!$form->isValidModelAndArray($model, $this->_getPost()))) + return false; + + $this->_doBeforeSave($model); + + if (!$model->save()) + return false; + + $model_values = $this->_getCustomFieldModelValues($model); + $custom_form = $this->_getCustomFieldForm($model_values); + $custom_form->populate($this->custom_values); + $custom_form->updateModelValues(); + $model_values->save(); + + $this->_doAfterSave($model); + return true; + } + + + protected function _doBeforeSave($model) { + return $this; + } + + + protected function _doAfterSave($model) { + return $this; + } + + protected function processMulticheckboxFromPost($form, $clean = false) { + $defaults = []; + foreach ($form->getMulticheckboxNames() as $checkbox_name) + $defaults[$checkbox_name] = []; + + $post = array_merge($defaults, $this->_getPost()); + if ($clean) + $post = $form->deleteUnchanged($post); + + $this->custom_values = []; + + foreach ($post as $k=>$v) + if (preg_match('/field_[0-9]+/', $k)) { + $this->custom_values[$k] = $v; + unset($post[$k]); + } + return $post; + } + + + + protected function _updateNewModel($model) { + return $this; + } + + + protected function _canAdd() { + return true; + } + + + protected function _findModel() { + return $this->_find($this->_getParam('id')); + } + + + protected function _getCustomFieldModelValues($model) { + return Class_CustomField_Model::getModel($this->_getModelClass()) + ->find($model->getId()); + } + + + protected function _getCustomFieldForm($model_values) { + return new ZendAfi_Form_Admin_CustomFields_ModelValues(['model_values' => $model_values]); + } + + + protected function _getDefaultModel($models) { + return $this->_getNewModel(); + } + + + protected function _addModelToView($model) { + $model_name = $this->_getModelName(); + $this->_view->model_name = $model_name; + $this->_view->$model_name = $model; + } + + + public function visitNewModel($callback) { + $this->_new_model = $callback; + return $this; + } + + + protected function _getNewModel() { + return call_user_func($this->_new_model); + } + + + public function visitModelName($callback) { + $this->_model_name = $callback; + return $this; + } + + + protected function _getModelName() { + return call_user_func($this->_model_name); + } + + + public function visitModelClass($callback) { + $this->_model_class = $callback; + return $this; + } + + + protected function _getModelClass() { + return call_user_func($this->_model_class); + } + + + public function visitAddModelToView($callback) { + $this->_add_model_to_view = $callback; + return $this; + } + + + public function visitGetFormClassName($callback){ + $this->_get_form_class_name = $callback; + return $this; + } + + + public function visitGetForm($callback) { + $this->_get_form = $callback; + return $this; + } + + + public function visitSuccessfulAddMessage($callback) { + $this->_successful_add_message = $callback; + return $this; + } + + + protected function _getSuccessfulAddMessage($model) { + return call_user_func($this->_successful_add_message, $model); + } + + + public function visitAddActionTitle($callback) { + $this->_add_action_title = $callback; + return $this; + } + + + protected function _getAddActionTitle() { + return call_user_func($this->_add_action_title); + } + + + public function visitDoAfterAdd($callback) { + $this->_do_after_add = $callback; + return $this; + } + + + protected function _getDoAfterAdd($model) { + return call_user_func($this->_do_after_add, $model); + } + + + public function visitEditActionTitle($callback) { + $this->_edit_action_title = $callback; + return $this; + } + + + protected function _getEditActionTitle($model) { + return call_user_func($this->_edit_action_title, $model); + } + + + public function visitSuccessfulSaveMessage($callback) { + $this->_successful_save_message = $callback; + return $this; + } + + + protected function _getSuccessfulSaveMessage($model) { + return call_user_func($this->_successful_save_message, $model); + } + + + public function visitDoAfterEdit($callback) { + $this->_do_after_edit = $callback; + return $this; + } + + + protected function _getDoAfterEdit($model) { + return call_user_func($this->_do_after_edit, $model); + } + + + public function visitDoAfterDelete($callback) { + $this->_do_after_delete = $callback; + return $this; + } + + + protected function _getDoAfterDelete($model) { + return call_user_func($this->_do_after_delete, $model); + } + + + public function visitSuccessfulDeleteMessage($callback) { + $this->_successful_delete_message = $callback; + return $this; + } + + + protected function _getSuccessfulDeleteMessage($model) { + return call_user_func($this->_successful_delete_message, $model); + } + + + public function visitSetFormClassName($callback) { + $this->_set_form_class_name = $callback; + return $this; + } + + + protected function _setFormClassName($form) { + return call_user_func($this->_set_form_class_name, $form); + } + + + protected function _getFormClassName() { + return call_user_func($this->_get_form_class_name); + } + + + protected function _getFormInstance() { + return call_user_func($this->_get_form); + } + + + public function visitDisplayGroups($callback) { + $this->_display_groups = $callback; + return $this; + } + + + protected function _getDisplayGroups() { + return call_user_func($this->_display_groups); + } + + + public function visitFind($callback) { + $this->_find = $callback; + return $this; + } + + + protected function _find($id) { + return call_user_func($this->_find, $id); + } + + + public function visitModelActions($callback) { + $this->_model_actions = $callback; + return $this; + } + + + protected function _getModelActions() { + return call_user_func($this->_model_actions); + } +} \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/Manager/Multimedia.php b/library/ZendAfi/Controller/Plugin/Manager/Multimedia.php new file mode 100644 index 0000000000000000000000000000000000000000..e9a2adbd1ac669808c8ad8d5ce9f222f16611915 --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/Manager/Multimedia.php @@ -0,0 +1,40 @@ +<?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_Multimedia extends ZendAfi_Controller_Plugin_Manager_Manager { + protected function _postEditAction($model) { + $this->_view->titre = 'Modification du site multimédia "' . $this->_view->escape($model->getLibelle()) . '"'; + } + + + /** Les données viennent d'un serveur multimédia, pas de suppression */ + public function deleteAction() { + $this->_redirect('/admin/multimedia'); + } + + + /** Les données viennent d'un serveur multimédia, pas d'ajout */ + public function addAction() { + $this->_redirect('/admin/multimedia'); + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/Manager/Newsletter.php b/library/ZendAfi/Controller/Plugin/Manager/Newsletter.php new file mode 100644 index 0000000000000000000000000000000000000000..af209c194d8d818c836f99d4f6150221bee6cc22 --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/Manager/Newsletter.php @@ -0,0 +1,197 @@ +<?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_Newsletter extends ZendAfi_Controller_Plugin_Manager_Manager { + public function getActions($model) { + return [ + ['url' => '/admin/newsletter/edit/id/%s', + 'icon' => 'edit', + 'label' => 'Modifier la newsletter'], + ['url' => '/admin/newsletter/preview/id/%s', + 'icon' => 'show', + 'label' => 'Visualiser la newsletter'], + ['url' => '/admin/newsletter/edit-subscribers/id/%s', + 'icon' => 'users', + 'caption' => 'getNumberOfUsers', + 'label' => 'Modifier les inscrits'], + ['url' => '/admin/newsletter/sendtest/id/%s', + 'icon' => 'test', + 'label' => 'Effectuer un test d\'envoi'], + ['url' => '/admin/newsletter/send/id/%s', + 'icon' => 'mail', + 'anchorOptions' => ['rel' => 'send'], + 'caption' => function($model) + { + Class_ScriptLoader::getInstance()->addJQueryReady(" +function sendNewsletterClick(event) { + var target = $(event.target).closest('a'); + var answer = confirm(\"".$this->_("Envoyer la lettre d'information ?")."\"); + if (answer == false) { + event.preventDefault(); + return; + } +} + + $(\"a[rel='send']\").click(sendNewsletterClick); +");}, + 'label' => 'Envoyer la lettre d\'information'], + ['url' => '/admin/newsletter/duplicate/id/%s', + 'icon' => 'copy', + 'label' => 'Dupliquer la lettre d\'information'], + ['url' => '/admin/newsletter/delete/id/%s', + 'icon' => 'delete', + 'label' => 'Supprimer la lettre d\'information'] + ]; + } + + + public function previewAction() { + if (!$newsletter = Class_Newsletter::find((int)$this->_getParam('id'))) { + $this->_redirectToIndex(); + return; + } + + $this->_addModelToView($newsletter); + + $template = Class_Newsletter_Dispatch::newFrom($newsletter)->getTemplate(); + $mock_user = new Class_Entity(); + $mock_user->setId(0)->setMail(''); + + $this->_view->titre = $this->_view->_('Aperçu de la lettre : %s', $newsletter->getLibelle()); + $this->_view->mail = $template->mailFor($mock_user); + } + + + public function addGroupAction() { + if (!$model = Class_Newsletter::find((int)$this->_getParam('id'))) { + $this->_redirectToIndex(); + return; + } + + $this->_view->titre = $this->_view->_('Groupes destinataires'); + + $ids = array_map(function($group) { return $group->getId(); }, + $model->getUserGroups()); + $value = implode('-', $ids); + + $form = ZendAfi_Form::newWithOptions(['action' => $this->_view->url(), + 'method' => Zend_Form::METHOD_POST]) + + ->addElement('userGroup', 'subscribe_group_ids', + ['label' => '', + 'categories_selectable' => false, + 'url' => $this->_view->url(['module' => 'admin', + 'controller' => 'usergroup', + 'action' => 'list.json']), + 'value' => $value]) + + ->addDisplayGroup(['subscribe_group_ids'], + 'groups', + ['legend' => $this->_view->_('Groupes destinataires')]); + + if ($this->_request->isPost() + && $form->isValid($this->_request->getPost())) { + $ids = explode('-', $this->_getParam('subscribe_group_ids', '')); + $mapper = function($id) { + return Class_UserGroup::find((int)$id); + }; + + $model + ->setUserGroups(array_filter(array_map($mapper, $ids))) + ->save(); + + $this->_redirectClose($this->_view->url(['module' => 'admin', + 'controller' => 'newsletter', + 'action' => 'edit-subscribers', + 'id' => $model->getId()], null, true), + ['prependBase' => false]); + return; + } + + + $this->_view->form = $form; + } + + + public function removeGroupAction() { + if (!$model = Class_Newsletter::find($this->_getParam('newsletter_id'))) { + $this->_redirectToIndex(); + return; + } + + $subscription = Class_NewsletterGroupSubscription::findFirstBy(['newsletter_id' => $model->getId(), + 'user_group_id' => (int)$this->_getParam('id')]); + + if ($subscription && !$subscription->hasDedicatedGroup()) + $subscription->delete(); + + $this->_redirect($this->_view->url(['module' => 'admin', + 'controller' => 'newsletter', + 'action' => 'edit-subscribers', + 'id' => $model->getId()], null, true), + ['prependBase' => false]); + } + + + public function duplicateAction() { + $this->_redirectToIndex(); + + if (!$newsletter = Class_Newsletter::find($this->_getParam('id'))) { + $this->_helper->notify($this->_view->_('Duplication impossible: la source n\'a pas été trouvée.')); + return; + } + + if (!$newsletter->duplicate()) + $this->_helper->notify($this->_view->_('Duplication impossible: Erreur lors de l\'enregisrement de la copie.')); + } + + + public function editSubscribersAction() { + if (!$model = Class_Newsletter::find($this->_getParam('id'))) { + $this->_redirectToIndex(); + return; + } + + $this->_addModelToView($model); + + if ($user = Class_Users::find($this->_getParam('unsubscribe',0))) + $model->unsubscribeUser($user); + + + if ($user = Class_Users::find($this->_getParam('subscribe',0))) + $model->subscribeUser($user); + + + $this->_view->titre = $this->_view->_('Destinataires de la lettre : %s', + $model->getTitre()); + + $this->_view->newsletter = $model; + $this->_view->groups = $model->getSortedRecipientsByDedicatedAndLabel(); + + $criteria = (new Class_User_SearchCriteria($this->_request->getParams())) + ->addCriteria(new Class_User_SearchCriteria_NewsletterSubscriptionStatus($this->_request->getParams())) + ->addCriteria(new Class_User_SearchCriteria_WithMail($this->_request->getParams())); + + $this->_helper->userSearch(['id' => $model->getId()], $criteria); + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/Manager/Opening.php b/library/ZendAfi/Controller/Plugin/Manager/Opening.php new file mode 100644 index 0000000000000000000000000000000000000000..05849e7dc7abe87d71c1ff996b227541f6e6de01 --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/Manager/Opening.php @@ -0,0 +1,57 @@ +<?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_Opening extends ZendAfi_Controller_Plugin_Manager_Manager { + protected function _getPost() { + $post = parent::_getPost(); + + if (Class_Ouverture::AUCUN_JOUR != $post['jour_semaine']) + $post['jour'] = null; + + $post['validity_start'] = (isset($post['validity_start'])) + ? $this->_getSQLDateFrom($post['validity_start']) + : null; + + $post['validity_end'] = isset($post['validity_end']) + ? $this->_getSQLDateFrom($post['validity_end']) + : ''; + + return $post; + } + + + protected function _getSQLDateFrom($human_date) { + $date = implode('-', array_reverse(explode('/', $human_date))); + return strtotime($date) > 0 + ? $date + : null; + } + + + protected function _updateNewModel($model) { + if(null !== $this->_getParam('multimedia')) + $model->setMultimedia(1); + + return $this; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/Manager/SessionFormation.php b/library/ZendAfi/Controller/Plugin/Manager/SessionFormation.php new file mode 100644 index 0000000000000000000000000000000000000000..930ff8207969fc0203153c0c968363b61a4e2018 --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/Manager/SessionFormation.php @@ -0,0 +1,55 @@ +<?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_SessionFormation extends ZendAfi_Controller_Plugin_Manager_Manager { + public function _getPost() { + $post = parent::_getPost(); + foreach(['date_debut', 'date_fin', 'date_limite_inscription'] as $field) + $post[$field] = $this->_readPostDate($this->_request->getPost($field)); + return $post; + } + + + protected function _readPostDate($date) { + return implode('-', array_reverse(explode('/', $date))); + } + + + public function addAction() { + if (!$formation = Class_Formation::find($this->_getParam('formation_id'))) { + $this->_redirect('admin/formation'); + return; + } + + parent::addAction(); + + $this->_view->titre = sprintf('Nouvelle session de la formation "%s"', + $formation->getLibelle()); + } + + + protected function _updateNewModel($model) { + $model->setFormation(Class_Formation::find($this->_getParam('formation_id'))); + return $this; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/Manager/Sitotheque.php b/library/ZendAfi/Controller/Plugin/Manager/Sitotheque.php new file mode 100644 index 0000000000000000000000000000000000000000..f2e890910f07aa855e11c45445d1b2c42cd6951a --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/Manager/Sitotheque.php @@ -0,0 +1,194 @@ +<?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_Sitotheque extends ZendAfi_Controller_Plugin_Manager_Manager { + protected function _updateNewModel($sitotheque) { + if (!$category = Class_SitothequeCategorie::find($this->_getParam('id_cat'))) { + $this->_redirect('admin/sito'); + return; + } + + $sitotheque->setCategorie($category); + if ($domaine = Class_Catalogue::findWithSamePathAs($category)) + $sitotheque->setDomaineIds($domaine->getId()); + + return $this; + } + + + + public function cataddAction() { + $this->_view->titre = "Ajouter une catégorie de sites"; + + $categorie = new Class_SitothequeCategorie(); + + if ($id_site = $this->_getParam('id_bib')) + $categorie->setIdSite($id_site); + + if ($parent_categorie = Class_SitothequeCategorie::find((int)$this->_getParam('id'))) + $categorie + ->setParentCategorie($parent_categorie) + ->setIdSite($parent_categorie->getIdSite()); + + if ($this->_isCategorieSaved($categorie)) { + $this->_helper->notify($this->_view->_('La catégorie "%s" a été ajoutée', $categorie->getLibelle())); + $this->_redirect(sprintf('admin/sito/index/id_cat/%d', $categorie->getId())); + return; + } + + $this->_view->categorie = $categorie; + $this->_view->combo_cat = $this->_view->comboParentCategorie($categorie); + } + + + public function cateditAction() { + $this->_view->titre = "Modifier une catégorie de sites"; + if (!$categorie = Class_SitothequeCategorie::find((int)$this->_getParam('id'))) { + $this->_redirect('admin/sito'); + return; + } + + if ($this->_isCategorieSaved($categorie)) { + $this->_helper->notify($this->_view->_('La catégorie "%s" a été sauvegardée', $categorie->getLibelle())); + $this->_redirect(sprintf('admin/sito/index/id_cat/%d', $categorie->getId())); + return; + } + + if (null === $categorie->getBib()) { + $categorie->setBib($this->_bib); + } + + $this->_view->categorie = $categorie; + $this->_view->combo_cat = $this->_view->comboParentCategorie($categorie); + } + + + /** + * @param Class_SitothequeCategorie $categorie + * @return bool + */ + protected function _isCategorieSaved($categorie) { + if ($this->_request->isPost()) { + $post = $this->_request->getPost(); + $filter = new Zend_Filter_StripTags(); + $post['libelle'] = trim($filter->filter($this->_request->getPost('libelle'))); + + return $categorie + ->updateAttributes($post) + ->save(); + } + + return false; + } + + + public function catdelAction() { + if (!$categorie = Class_SitothequeCategorie::find((int)$this->_getParam('id'))) { + $this->_redirect('/admin/sito'); + return; + } + + $categorie->delete(); + $this->_helper->notify($this->_view->_('La categorie "%s" a été supprimée', $categorie->getLibelle())); + $this->_redirect('/admin/sito/index/id_cat/'.$categorie->getIdCatMere()); + } + + + protected function _canAdd() { + $category = Class_SitothequeCategorie::find($this->_getParam('id_cat')); + return $category; + } + + + protected function _getPost() { + $post = $this->_request->getPost(); + unset($post['id_items']); + return $post; + } + + + protected function _doAfterSave($model) { + $model->index(); + (new Storm_Cache())->clean(); + } + + + public function sitoviewAction() { + $this->_redirect(Class_Sitotheque::find((int)$this->_getParam('id'))->getUrl()); + } + + + public function getActions($model) { + if('Class_Sitotheque' == get_class($model)) + return $this->_getLeafActions($model); + + if('Class_SitothequeCategorie' == get_class($model)) + return $this->_getNodeActions($model); + + return []; + } + + + protected function _getNodeActions($model) { + return [ + ['url' => '/admin/sito/catedit/id/%s', + 'icon' => 'edit', + 'label' => 'Modifier'], + + ['url' => '/admin/sito/catdel/id/%s', + 'icon' => 'delete', + 'label' => 'Supprimer', + 'condition' => 'hasNoChild', + 'anchorOptions' => ['onclick' => "return confirm('Etes-vous sûr de vouloir supprimer cette catégorie ?')"]], + + ['url' => '/admin/sito/add/id_cat/%s', + 'icon' => 'add_page', + 'label' => 'Ajouter un site'], + + ['url' => '/admin/sito/catadd/id/%s', + 'icon' => 'add_category', + 'label' => 'Ajouter une sous-catégorie'] + ]; + } + + + protected function _getLeafActions($model) { + return + [ + ['url' => '/admin/sito/sitoview/id/%s?&iframe=true&width=80%;height=80%;', + 'icon' => 'view', + 'label' => 'Visualiser', + 'anchorOptions' => ['rel' => 'prettyPhoto']], + + ['url' => '/admin/sito/edit/id/%s', + 'icon' => 'edit', + 'label' => 'Modifier', + ], + + ['url' => '/admin/sito/delete/id/%s', + 'icon' => 'delete', + 'label' => 'Supprimer', + 'anchorOptions' => ['onclick' => "return confirm('Etes-vous sûr de vouloir supprimer ce site ?')"]] + ]; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/Manager/User.php b/library/ZendAfi/Controller/Plugin/Manager/User.php new file mode 100644 index 0000000000000000000000000000000000000000..2e7a6b6c234b5cde47c6a512cd182db814fe2e6a --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/Manager/User.php @@ -0,0 +1,57 @@ +<?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_User extends ZendAfi_Controller_Plugin_Manager_Manager { + protected function _getPost() { + $post = $this->_request->getPost(); + $post['user_groups'] = array_filter( + array_map(function($id) { return Class_UserGroup::find((int)$id);}, + explode('-', $this->_getParam('user_group_ids',''))) + ); + + unset($post['id_categories']); + + return $post; + } + + protected function _getFormValues($model) { + $array_model=parent::_getFormValues($model); + $array_model['user_group_ids']=implode('-',array_map(function($group) { return $group->getId();},$model->getUserGroups())); + + return $array_model; + } + + + protected function _setupFormAndSave($model) { + if ($this->_request->isPost()) + $model->updateSIGBOnSave(); + + try { + return parent::_setupFormAndSave($model); + } catch (Exception $e) { + $this->_helper->notify($e->getMessage()); + } + } + + +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/Manager/UserGroup.php b/library/ZendAfi/Controller/Plugin/Manager/UserGroup.php new file mode 100644 index 0000000000000000000000000000000000000000..f7ec662a4110b462a56f950c8a55da656a77d5bc --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/Manager/UserGroup.php @@ -0,0 +1,248 @@ +<?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_UserGroup extends ZendAfi_Controller_Plugin_Manager_Manager { + public function editmembersAction() { + if (!$group = Class_UserGroup::find((int)$this->_getParam('id'))) { + $this->_redirect('admin/usergroup'); + return; + } + + if ($id_user_to_delete = $this->_getParam('delete')) { + $group + ->removeUser(Class_Users::find($id_user_to_delete)) + ->save(); + + $redirect_url = '/admin/usergroup/editmembers/' . (($newsletter_id = $this->_getParam('newsletter_id')) ? 'newsletter_id/' . $newsletter_id . '/': '') . 'id/'.$group->getId(); + if ($_GET) + $redirect_url .= '?'.http_build_query($_GET); + $this->_redirect($redirect_url); + return; + } + + if ($this->_request->isPost() + && ($ids_users_to_add = $this->_request->getPost('users'))) { + foreach($ids_users_to_add as $id) + $group->addUser(Class_Users::find($id)); + $group->save(); + } + + $this->_view->titre = "Membres du groupe: ".$group->getLibelle(); + $this->_view->group_id = $this->_getParam('id'); + $this->_view->search = $this->_getParam('search'); + $this->_view->page = $this->_getParam('page'); + + $this->_view->back_url = ($newsletter_id = $this->_getParam('newsletter_id')) + ? $this->_view->url(['module' => 'admin', + 'controller' => 'newsletter', + 'action' => 'edit-subscribers', + 'id' => $newsletter_id], + null, true) + : $this->_view->url(['module' => 'admin', + 'controller' => 'usergroup'], + null, true); + } + + public function cataddAction() { + $form = new ZendAfi_Form_UserGroupCategorie(); + $categorie = new Class_UserGroupCategorie(); + if ($this->_isCategorieSaved($categorie,$form)) { + $this->_helper->notify($this->_view->_('La catégorie "%s" a été ajoutée', $categorie->getLibelle())); + $this->_redirect(sprintf('admin/usergroup/index/id_cat/%d', $categorie->getId())); + return; + } + + $this->_view->form= $form; + $this->_view->titre = $this->_view->_('Ajouter une catégorie d\'utilisateurs'); + if ($categorie_parent = Class_UserGroupCategorie::find((int)$this->_getParam('id'))) + $this->_view->form->setDefault('parent_id', $categorie_parent->getId()); + } + + + public function catdelAction() { + if (!$categorie = Class_UserGroupCategorie::find((int)$this->_getParam('id'))) { + $this->_redirect('/admin/usergroup'); + return; + } + $id_cat_mere = ($categorie->getParentId()>0) ? '/index/id_cat/'.$categorie->getParentId() : '/index'; + $libelle= $categorie->getLibelle(); + $categorie->delete(); + $this->_helper->notify($this->_view->_('La categorie "%s" a été supprimée',$libelle)); + $this->_redirect('/admin/usergroup'.$id_cat_mere); + } + + + /** + * @param Class_SitothequeCategorie $categorie + * @return bool + */ + protected function _isCategorieSaved($categorie,$form) { + if(!$this->_request->isPost()) + return false; + + $post = $this->_request->getPost(); + $filter = new Zend_Filter_StripTags(); + $post['libelle'] = trim($filter->filter($this->_request->getPost('libelle'))); + + $categorie + ->updateAttributes($post); + + return $form->isValid($categorie) ? $categorie->save() : false; + } + + + + + + public function cateditAction() { + $form = new ZendAfi_Form_UserGroupCategorie(); + $categorie = new Class_UserGroupCategorie(); + $this->_view->titre = "Modifier une catégorie de groupes"; + if (!$categorie = Class_UserGroupCategorie::find((int)$this->_getParam('id'))) { + $this->_redirect('admin/usergroup'); + return; + } + + if ($this->_isCategorieSaved($categorie, $form)) { + $this->_helper->notify($this->_view->_('La catégorie "%s" a été sauvegardée', $categorie->getLibelle())); + $this->_redirect(sprintf('admin/usergroup/index/id_cat/%d', $categorie->getId())); + return; + } + + + $form + ->populate(['libelle'=>$categorie->getLibelle()]) + ->setDefault('parent_id',$categorie->getParentId()); + $this->_view->form= $form; + $this->_view->titre = $this->_view->_('Modifier une catégorie d\'utilisateurs'); + + } + + + protected function _getPost() { + $post = $this->_request->getPost(); + if(!isset($post[ZendAfi_Form_Admin_UserGroup::RIGHTS_PERMISSIONS])) + $post[ZendAfi_Form_Admin_UserGroup::RIGHTS_PERMISSIONS] = []; + + $rights_permissions = (new Storm_Collection($post[ZendAfi_Form_Admin_UserGroup::RIGHTS_PERMISSIONS])); + + $post['rights'] = ZendAfi_Form_Admin_UserGroup::deletePrefix($rights_permissions, + ZendAfi_Form_Admin_UserGroup::RIGHT); + + $this->_permissions_access = ZendAfi_Form_Admin_UserGroup::deletePrefix($rights_permissions, + ZendAfi_Form_Admin_UserGroup::PERMISSION); + + unset($post[ZendAfi_Form_Admin_UserGroup::RIGHTS_PERMISSIONS]); + return $post; + } + + + protected function _doAfterSave($model) { + Class_UserGroup_Permission::denyAllToGroup(Class_DigitalResource::getInstance()->getPermissions(), $model); + + (new Storm_Collection($this->_permissions_access)) + ->eachDo( + function($permission) use ($model) + { + if($permission = Class_Permission::findFirstBy(['code' => $permission])) { + $permission->permitTo($model, new Class_Entity()); + } + }); + } + + + + public function _updateNewModel($model) { + $model->setCategorie(Class_UserGroupCategorie::find((int)$this->_getParam('id_cat'))); + return $this; + } + + + protected function _getFormValues($model) { + $permissions = (new Storm_Model_Collection(Class_UserGroup_Permission::findAllBy(['id_group' => $model->getId()]))) + ->collect('permission'); + + $values = array_merge($model->toArray(), + [ZendAfi_Form_Admin_UserGroup::RIGHTS_PERMISSIONS => + ZendAfi_Form_Admin_UserGroup::mergeRightsAndPermissionsWithPrefix($model->getRights(), + $model->getPermissions())]); + return $values; + } + + + public function getActions($model) { + if('Class_UserGroup' == get_class($model)) + return $this->_getLeafsActions($model); + + if('Class_UserGroupCategorie' == get_class($model)) + return $this->_getNodesActions($model); + + return []; + } + + + protected function _getNodesActions($model) { + return [ + ['url' => '/admin/usergroup/catedit/id/%s', + 'icon' => 'edit', + 'label' => 'Modifier'], + + ['url' => '/admin/usergroup/catdel/id/%s', + 'icon' => 'delete', + 'label' => 'Supprimer', + 'condition' => 'hasNoChild', + 'anchorOptions' => ['onclick' => "return confirm('Etes-vous sûr de vouloir supprimer cette catégorie ?')"]], + + ['url' => '/admin/usergroup/add/id_cat/%s', + 'icon' => 'add_page', + 'label' => 'Ajouter un groupe'], + + ['url' => '/admin/usergroup/catadd/id/%s', + 'data-popup' => true, + 'icon' => 'add_category', + 'label' => 'Ajouter une sous-catégorie']]; + } + + + protected function _getLeafsActions($model) { + return [ + ['url' => '/admin/usergroup/editmembers/id/%s', + 'icon' => 'users', + 'label' => 'Membres', + 'caption' => 'formatedCount' + ], + + ['url' => '/admin/usergroup/edit/id/%s', + 'icon' => 'edit', + 'label' => 'Modifier', + ], + + ['url' => '/admin/usergroup/delete/id/%s', + 'icon' => 'delete', + 'label' => 'Supprimer', + 'anchorOptions' => [ + 'onclick' => "return confirm('Etes-vous sûr de vouloir supprimer ce groupe ?')" + ]] + ]; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/MultiSelection/Abstract.php b/library/ZendAfi/Controller/Plugin/MultiSelection/Abstract.php index 7614bbe43cf933f4dc91af2c012b66a88e9629bc..67d60a2534b201b73b880f48653c840d7c6241be 100644 --- a/library/ZendAfi/Controller/Plugin/MultiSelection/Abstract.php +++ b/library/ZendAfi/Controller/Plugin/MultiSelection/Abstract.php @@ -20,31 +20,11 @@ */ -abstract class ZendAfi_Controller_Plugin_MultiSelection_Abstract { - use Trait_Translator; - +abstract class ZendAfi_Controller_Plugin_MultiSelection_Abstract extends ZendAfi_Controller_Plugin_Abstract { protected - $_controller, $_multi_selection; - public function call($methodName, $args) { - if($this->isActionDefined($methodName)) - return $this->$methodName($args); - return null; - } - - - public function isActionDefined($methodName) { - return in_array($methodName, get_class_methods($this)); - } - - - public function __construct($controller) { - $this->_controller = $controller->acceptVisitor($this); - } - - public function addModelToSelectionAction() { $values = $this->_getValuesFromParams(); $limit = (int) Class_AdminVar::getValueOrDefault('LIMIT_MULTIPLE_SELECTION'); @@ -79,13 +59,13 @@ abstract class ZendAfi_Controller_Plugin_MultiSelection_Abstract { return $this->_redirectToIndex(); $this->_view->titre = $this->_('Modifier %d %s', - $models->count(), - $this->_definitions->pluralizeModelName()); + $models->count(), + $this->_pluralizeModelName()); if ($this->_setupFormAndUpdateModels($models->getArrayCopy())) { $this->_helper->notify($this->_('Les %d %s sélectionnés ont bien été sauvegardés', $count, - $this->_definitions->pluralizeModelName())); + $this->_pluralizeModelName())); $this->_redirectToReferer(); } @@ -95,66 +75,82 @@ abstract class ZendAfi_Controller_Plugin_MultiSelection_Abstract { public function deleteSelectedModelsAction() { - call_user_func([$this->_definitions->getModelLoader(), + call_user_func([$this->_getModelLoader(), 'deleteBy'], - [$this->_definitions->getModelId() => $this->_multi_selection->getValues()]); + [$this->_getModelId() => $this->_multi_selection->getValues()]); - $this->_helper->notify($this->_('Les %s sélectionnés ont bien été supprimés', $this->_definitions->pluralizeModelName())); + $this->_helper->notify($this->_('Les %s sélectionnés ont bien été supprimés', $this->_pluralizeModelName())); $this->_forward('clear-models-selection'); } - public function visitView($view){ - $this->_view = $view; - return $this; + protected function _getValuesFromParams() { + $values = $this->_getMultiSelection()->getModelIdsFromCategory($this->_getParam('select_id_cat', '')); + $values[] = $this->_getParam('select_id', ''); + return $values; } - public function visitRequest($request) { - $this->_request = $request; - return $this; + protected function _getMultiSelection() { + return $this->_multi_selection; } - public function visitHelper($helper) { - $this->_helper = $helper; - return $this; + protected function _getSelectedItems() { + return $this->_getMultiSelection()->getModels(); } - public function visitViewRenderer($view_renderer) { - $this->_view_renderer = $view_renderer; - return $this; + protected function _findModel() { + return $this->_find($this->_getParam('id')); } - public function visitDefinitions($definitions) { - $this->_definitions = $definitions; - return $this; - } + protected function _setupFormAndUpdateModels($models) { + $form = $this->_getMultipleSelectionForm($this->_getDefaultModel($models)); + $this->_view->form = $form; + if (!$this->_request->isPost()) + return false; + $post = $this->processMulticheckboxFromPost($form,true); - public function visitRedirectToReferer($callback) { - $this->_redirect_to_referer = $callback; - return $this; - } + foreach($models as $model) { + $model->updateAttributes($post); + if ((!$form->isValidModelAndArray($model, $this->_getPost()))) + return false; - public function visitRedirect($callback) { - $this->_redirect = $callback; - return $this; + $this->_doBeforeSave($model); + + if (!$model->save()) + return false; + + $model_values = $this->_getCustomFieldModelValues($model); + $custom_form = $this->_getCustomFieldForm($model_values); + $custom_form->populate($this->getCustomValues()); + $custom_form->updateModelValues(); + $model_values->save(); + + $this->_doAfterSave($model); + } + return true; } - public function visitGetParam($callback) { - $this->_get_param = $callback; - return $this; + protected function _getMultipleSelectionForm($model) { + $form = + $this->_getForm($model) + ->populate($model->toArray()); + return $form->beMultipleSelection(); } - public function visitSetParam($callback) { - $this->_set_param = $callback; - return $this; + public function render() { + if (('index' == $this->_request->getActionName()) + || ('edit-multiple' == $this->_request->getActionName())) + return $this->_view->Plugin_MultiSelection_Widget($this->_multi_selection); + + return ''; } @@ -164,45 +160,52 @@ abstract class ZendAfi_Controller_Plugin_MultiSelection_Abstract { } - public function visitGetPost($callback) { - $this->_get_post = $callback; - return $this; + protected function _getForm($model) { + return call_user_func($this->_get_form, $model); } - public function visitDoBeforeSave($callback) { - $this->_do_before_save = $callback; + public function visitDoAfterSave($callback) { + $this->_do_after_save = $callback; return $this; } + protected function _doAfterSave($model) { + return call_user_func($this->_do_after_save, $model); + } + + public function visitCustomFieldModelValues($callback) { $this->_custom_field_model_values = $callback; return $this; } + protected function _getCustomFieldModelValues($model) { + return call_user_func($this->_custom_field_model_values, $model); + } + + public function visitCustomFieldForm($callback) { $this->_custom_field_form = $callback; return $this; } - public function visitDoAfterSave($callback) { - $this->_do_after_save = $callback; - return $this; + protected function _getCustomFieldForm($model_values) { + return call_user_func($this->_custom_field_form, $model_values); } - public function visitForward($callback) { - $this->_forward = $callback; + public function visitDoBeforeSave($callback) { + $this->_do_before_save = $callback; return $this; } - public function visitDefaultModel($callback) { - $this->_default_model = $callback; - return $this; + protected function _doBeforeSave($model) { + return call_user_func($this->_do_before_save, $model); } @@ -212,64 +215,25 @@ abstract class ZendAfi_Controller_Plugin_MultiSelection_Abstract { } - public function visitCustomValues($callback) { - $this->_custom_values = $callback; - } - - - protected function _getValuesFromParams() { - $values = $this->_getMultiSelection()->getModelIdsFromCategory($this->_getParam('select_id_cat', '')); - $values[] = $this->_getParam('select_id', ''); - return $values; - } - - - protected function _getMultiSelection() { - return $this->_multi_selection; + protected function processMulticheckboxFromPost($form, $clean = false) { + return call_user_func_array($this->_process_multi_checkbox, [$form, $clean]); } - protected function _getSelectedItems() { - return $this->_getMultiSelection()->getModels(); + public function visitCustomValues($callback) { + $this->_custom_values = $callback; + return $this; } - protected function _setupFormAndUpdateModels($models) { - $form = $this->_getMultipleSelectionForm($this->_getDefaultModel($models)); - - $this->_view->form = $form; - if (!$this->_request->isPost()) - return false; - $post = $this->processMulticheckboxFromPost($form,true); - - foreach($models as $model) { - $model->updateAttributes($post); - - if ((!$form->isValidModelAndArray($model, $this->_getPost()))) - return false; - - $this->_doBeforeSave($model); - - if (!$model->save()) - return false; - - $model_values = $this->_getCustomFieldModelValues($model); - $custom_form = $this->_getCustomFieldForm($model_values); - $custom_form->populate($this->getCustomValues()); - $custom_form->updateModelValues(); - $model_values->save(); - - $this->_doAfterSave($model); - } - return true; + protected function getCustomValues() { + return call_user_func($this->_custom_values); } - protected function _getMultipleSelectionForm($model) { - $form = - $this->_getForm($model) - ->populate($model->toArray()); - return $form->beMultipleSelection(); + public function visitDefaultModel($callback) { + $this->_default_model = $callback; + return $this; } @@ -278,77 +242,57 @@ abstract class ZendAfi_Controller_Plugin_MultiSelection_Abstract { } - protected function _getParam($key) { - return call_user_func($this->_get_param, $key); - } - - - protected function _redirectToReferer() { - return call_user_func($this->_redirect_to_referer); - } - - - protected function _redirect($url) { - return call_user_func($this->_redirect, $url); - } - - - protected function _getForm($model) { - return call_user_func($this->_get_form, $model); - } - - - protected function _getPost() { - return call_user_func($this->_get_post); - } - - - protected function _doBeforeSave($model) { - return call_user_func($this->_do_before_save, $model); + public function visitNewModel($callback) { + $this->_new_model = $callback; + return $this; } - protected function _getCustomFieldModelValues($model) { - return call_user_func($this->_custom_field_model_values, $model); + protected function _getNewModel() { + return call_user_func($this->_new_model); } - protected function _getCustomFieldForm($model_values) { - return call_user_func($this->_custom_field_form, $model_values); + public function visitPluralizeModelName($callback) { + $this->_pluralize_model_name = $callback; + return $this; } - protected function _doAfterSave($model) { - return call_user_func($this->_do_after_save, $model); + protected function _pluralizeModelName() { + return call_user_func($this->_pluralize_model_name); } - public function renderScript($script) { - $this->_controller->renderScript($script); + public function visitModelLoader($callback) { + $this->_model_loader = $callback; + return $this; } - protected function _setParam($key, $value, $default = null) { - return call_user_func_array($this->_set_param, [$key, $value, $default]); + protected function _getModelLoader() { + return call_user_func($this->_model_loader); } - protected function _forward($action) { - return call_user_func($this->_forward, $action); + public function visitModelId($callback) { + $this->_model_id = $callback; + return $this; } - protected function processMulticheckboxFromPost($form, $clean = false) { - return call_user_func_array($this->_process_multi_checkbox, [$form, $clean]); + protected function _getModelId() { + return call_user_func($this->_model_id); } - protected function getCustomValues() { - return call_user_func($this->_custom_values); + public function visitFind($callback) { + $this->_find = $callback; + return $this; } - public function render() { - return $this->_view->Admin_MultipleSelectorWidget($this->_multi_selection); + protected function _find($id) { + return call_user_func($this->_find, $id); } } diff --git a/library/ZendAfi/Controller/Plugin/MultiSelection/AbstractActions.php b/library/ZendAfi/Controller/Plugin/MultiSelection/AbstractActions.php new file mode 100644 index 0000000000000000000000000000000000000000..a01360819a139c2c9d62686006ddb95efbf88660 --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/MultiSelection/AbstractActions.php @@ -0,0 +1,84 @@ +<?php +/** + * Copyright (c) 2012-2014, 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 + */ + + +abstract class ZendAfi_Controller_Plugin_MultiSelection_AbstractActions { + public function __construct($multi_selection) { + $multi_selection->acceptVisitor($this); + } + + + public function visitWidget($multi_selection) { + return $this; + } + + + public function visitActions($multi_selection) { + $multi_selection->acceptActionsVisitor($this); + return $this; + } + + + public function visitAddLeaf($callback) { + $this->_add_leaf = $callback; + return $this; + } + + + public function visitRemoveLeaf($callback) { + $this->_remove_leaf = $callback; + return $this; + } + + + public function visitAddNode($callback) { + $this->_add_node = $callback; + return $this; + } + + + public function visitRemoveNode($callback) { + $this->_remove_node = $callback; + return $this; + } + + + public function visitControllerName($controller) { + $this->_controller_name = $controller; + return $this; + } + + + public function visitLeafCondition($callback) { + $this->_leaf_condition = $callback; + return $this; + } + + + public function visitNodeCondition($callback) { + $this->_node_condition = $callback; + return $this; + } + + + abstract public function getActions(); +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/MultiSelection/Album.php b/library/ZendAfi/Controller/Plugin/MultiSelection/Album.php index c0c7b502f7f86bdff3abc26a74d010c1ea427547..a57bcc2c05d0b9932d01e57c32be4b3a23af2191 100644 --- a/library/ZendAfi/Controller/Plugin/MultiSelection/Album.php +++ b/library/ZendAfi/Controller/Plugin/MultiSelection/Album.php @@ -25,4 +25,17 @@ class ZendAfi_Controller_Plugin_MultiSelection_Album extends ZendAfi_Controller_ parent::__construct($controller); $this->_multi_selection = new Class_MultiSelection_Album(); } + + + public function getActions($model) { + if('Class_Album' == get_class($model)) + return (new ZendAfi_Controller_Plugin_MultiSelection_LeafActions($this->_multi_selection)) + ->getActions(); + + if('Class_AlbumCategorie' == get_class($model)) + return (new ZendAfi_Controller_Plugin_MultiSelection_NodeActions($this->_multi_selection)) + ->getActions(); + + return []; + } } \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/MultiSelection/Article.php b/library/ZendAfi/Controller/Plugin/MultiSelection/Article.php index 67ff45b069c5308183fd2e64edad3265a2f9bff3..c7a2fb706c3f88bc9db01aa148284c1be800ed7c 100644 --- a/library/ZendAfi/Controller/Plugin/MultiSelection/Article.php +++ b/library/ZendAfi/Controller/Plugin/MultiSelection/Article.php @@ -25,5 +25,17 @@ class ZendAfi_Controller_Plugin_MultiSelection_Article extends ZendAfi_Controlle parent::__construct($controller); $this->_multi_selection = new Class_MultiSelection_Article(); } -} -?> \ No newline at end of file + + + public function getActions($model) { + if('Class_Article' == get_class($model)) + return (new ZendAfi_Controller_Plugin_MultiSelection_LeafActions($this->_multi_selection)) + ->getActions(); + + if('Class_ArticleCategorie' == get_class($model)) + return (new ZendAfi_Controller_Plugin_MultiSelection_NodeActions($this->_multi_selection)) + ->getActions(); + + return []; + } +} \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/MultiSelection/LeafActions.php b/library/ZendAfi/Controller/Plugin/MultiSelection/LeafActions.php new file mode 100644 index 0000000000000000000000000000000000000000..77cebd917db043f7430aaa7d61ebe4013f4ea762 --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/MultiSelection/LeafActions.php @@ -0,0 +1,44 @@ +<?php +/** + * Copyright (c) 2012-2014, 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_MultiSelection_LeafActions extends ZendAfi_Controller_Plugin_MultiSelection_AbstractActions{ + public function getActions() { + return [ + ['url' => ['controller' => $this->_controller_name, + 'action' => 'remove-model-from-selection', + 'select_id' => '%s'], + 'icon' => 'cancel', + 'label' => $this->_remove_leaf, + 'condition' => $this->_leaf_condition], + + ['url' => ['controller' => $this->_controller_name, + 'action' => 'add-model-to-selection', + 'select_id' => '%s'], + 'icon' => 'basket', + 'label' => $this->_add_leaf, + 'condition' => function($model) + { + return !call_user_func($this->_leaf_condition, $model); + }]]; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/MultiSelection/NodeActions.php b/library/ZendAfi/Controller/Plugin/MultiSelection/NodeActions.php new file mode 100644 index 0000000000000000000000000000000000000000..a6fd6fe43ebf72b39c85877cb570b6fea5c3b11b --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/MultiSelection/NodeActions.php @@ -0,0 +1,45 @@ +<?php +/** + * Copyright (c) 2012-2014, 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_MultiSelection_NodeActions extends ZendAfi_Controller_Plugin_MultiSelection_AbstractActions { + public function getActions() { + return [ + ['url' => ['controller' => $this->_controller_name, + 'action' => 'remove-model-from-selection', + 'select_id_cat' => '%s'], + 'icon' => 'cancel', + 'label' => $this->_remove_node, + 'condition' => $this->_node_condition + ], + + ['url' => ['controller' => $this->_controller_name, + 'action' => 'add-model-to-selection', + 'select_id_cat' => '%s'], + 'icon' => 'basket', + 'label' => $this->_add_node, + 'condition' => function($model) { + return !call_user_func($this->_node_condition, $model); + } + ]]; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/Printer/ModelFusion.php b/library/ZendAfi/Controller/Plugin/Printer/ModelFusion.php new file mode 100644 index 0000000000000000000000000000000000000000..2e47e26efa8d6a5b7aca337216d978f9835faaca --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/Printer/ModelFusion.php @@ -0,0 +1,50 @@ +<?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_Printer_ModelFusion extends ZendAfi_Controller_Plugin_Abstract { + public function printAction() { + if ($this->_response->isRedirect()) + return; + + $models = []; + $strategy = $this->_getParam('strategy', 'Article_List'); + list($class_name,$type) = explode('_',$strategy); + $model = 'Class_'.$class_name; + $id_name = 'id_'.$class_name; + + $source_key = strtolower($class_name); + $data = $model::find($this->_getParam('id',0)); + + $this->_view->fusion = Class_ModeleFusion::find($this->_getParam('modele_fusion')); + + if ($type == 'List') { + $models = array_map([$model, 'find'], explode(';', $this->_getParam('ids', 0))); + $data = new Class_CollectionFusion($models); + $source_key = Storm_Inflector::pluralize($source_key); + } + + $this->_view->fusion->setDataSource([$source_key => $data]); + $this->_helper->getHelper('viewRenderer')->setLayoutScript('empty.phtml'); + $this->renderScript('print.phtml'); + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Abstract.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Abstract.php new file mode 100644 index 0000000000000000000000000000000000000000..f6572732a0873695edb2e89e32925d8de4387235 --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Abstract.php @@ -0,0 +1,358 @@ +<?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 + */ + + +abstract class ZendAfi_Controller_Plugin_ResourceDefinition_Abstract extends ZendAfi_Controller_Plugin_Abstract { + protected $_attribs; + + + public function __construct($controller) { + parent::__construct($controller); + } + + + public function init() { + parent::init(); + $this->_attribs = $this->getDefinitions(); + } + + + public function getDefinitions() { + return []; + } + + + public function getModelLoader() { + return Storm_Model_Abstract::getLoaderFor($this->getModelClass()); + } + + + public function find($id) { + return $this->getModelLoader()->find($id); + } + + + public function findAll($request) { + return $this->findAllBy($this->_addScopeParam([], $request)); + } + + + public function findAllBy($params) { + return call_user_func([$this->getModelLoader(), + $this->getFindAllMethod()], + array_merge(['order' => $this->getOrder()], + $params)); + } + + + protected function _addScopeParam($params, $request) { + $closure = function($item, $value) use (&$params) { + $params[$item] = $value; + }; + + $this->withScopeDo($closure, $request); + return $params; + } + + + public function withScopeDo($closure, $request) { + if (!$this->hasScope()) + return; + + $scope = $this->getScope(); + if (!is_array($scope)) + $scope = [$scope]; + + foreach($scope as $item) + if ($value = $request->getParam($item)) + $closure($item, $value); + } + + + public function newModel() { + return $this->getModelLoader()->newInstance(); + } + + + public function doAfterAdd($model) { + if (isset($this->_attribs['after_add'])) + $this->_attribs['after_add']($model); + } + + + public function doAfterEdit($model) { + if (isset($this->_attribs['after_edit'])) + $this->_attribs['after_edit']($model); + } + + + public function doAfterDelete($model) { + if (isset($this->_attribs['after_delete'])) + $this->_attribs['after_delete']($model); + } + + + public function successfulDeleteMessage($model) { + return sprintf($this->_attribs['messages']['successful_delete'], + $model->getLibelle()); + } + + + public function successfulSaveMessage($model) { + return sprintf($this->_attribs['messages']['successful_save'], + $model->getLibelle()); + } + + + public function successfulAddMessage($model) { + if (isset($this->_attribs['messages']['successful_add'])) + $successfull_add = $this->_attribs['messages']['successful_add']; + else + $successfull_add = $this->_attribs['messages']['successful_save']; + + return sprintf($successfull_add, $model->getLibelle()); + } + + + public function indexActionTitle() { + return $this->titleForAction('index'); + } + + + public function titleForAction($action) { + if (isset($this->_attribs['actions'][$action]['title'])) + return $this->_attribs['actions'][$action]['title']; + return ''; + } + + + public function editActionTitle($model) { + return sprintf($this->titleForAction('edit'),$model->getLibelle()); + } + + + public function addActionTitle() { + return $this->titleForAction('add'); + } + + + public function getModelClass() { + return $this->_attribs['model']['class']; + } + + + public function getModelId() { + return $this->_attribs['model']['model_id']; + } + + + public function getOrder() { + if (isset($this->_attribs['model']['order'])) + return $this->_attribs['model']['order']; + return 'libelle'; + } + + + public function getFindAllMethod() { + if (isset($this->_attribs['model']['findAll'])) + return $this->_attribs['model']['findAll']; + return 'findAllBy'; + } + + + public function getScope() { + if (isset($this->_attribs['model']['scope'])) + return $this->_attribs['model']['scope']; + return null; + } + + + public function hasScope() { + $scope = $this->getScope(); + return !empty($scope); + } + + + public function getModelName() { + return $this->_attribs['model']['name']; + } + + + public function pluralizeModelName() { + return Storm_Inflector::pluralize($this->getModelName()); + } + + + public function addFormElements($form) { + $element_definitions = $this->getFormElementDefinitions(); + + foreach($element_definitions as $name => $definition) { + $options = isset($definition['options']) ? $definition['options'] : array(); + + $form->addElement($definition['element'], $name, $options); + + if ($label = $form->getElement($name)->getDecorator('label')) + $label->setOption('escape', false); + } + return $this; + } + + + public function getDisplayGroups() { + if (isset($this->_attribs['display_groups'])) + return $this->_attribs['display_groups']; + return []; + } + + + public function getForm() { + if (isset($this->_attribs['form'])) + return $this->_attribs['form']; + return null; + } + + + public function getFormClassName() { + if (isset($this->_attribs['form_class_name'])) + return $this->_attribs['form_class_name']; + return null; + } + + + public function setFormClassName($name) { + $this->_attribs['form_class_name'] = $name; + return $this; + } + + + public function sort($instances) { + if (isset($this->_attribs['sort'])) + usort($instances, $this->_attribs['sort']); + return $instances; + } + + + public function getModelActions() { + return isset($this->_attribs['model_actions']) + ? $this->_attribs['model_actions'] + : []; + } + + + public function acceptVisitor($visitor) { + $visitor + ->visitNewModel(function() + { + return $this->newModel(); + }) + ->visitModelName(function() + { + return $this->getModelName(); + }) + ->visitModelClass(function() + { + return $this->getModelClass(); + }) + ->visitAddModelToView(function($model) + { + return $this->_addModelToView($model); + }) + ->visitGetFormClassName(function() + { + return $this->getFormClassName(); + }) + ->visitGetForm(function() + { + return $this->getForm(); + }) + ->visitAddActionTitle(function() + { + return $this->addActionTitle(); + }) + ->visitSuccessfulAddMessage(function($model) + { + return $this->successfulAddMessage($model); + }) + ->visitDoAfterAdd(function($model) + { + return $this->doAfterAdd($model); + }) + ->visitEditActionTitle(function($model) + { + return $this->editActionTitle($model); + }) + ->visitSuccessfulSaveMessage(function($model) + { + return $this->successfulSaveMessage($model); + }) + ->visitDoAfterEdit(function($model) + { + return $this->doAfterEdit($model); + }) + ->visitSuccessFulDeleteMessage(function($model) + { + return $this->successfulDeleteMessage($model); + }) + ->visitDoAfterDelete(function($model) + { + return $this->doAfterDelete($model); + }) + ->visitSetFormClassName(function($form) + { + return $this->setFormClassName($form); + }) + ->visitDisplayGroups(function() + { + return $this->getDisplayGroups(); + }) + ->visitFind(function($id) + { + return $this->find($id); + }) + ->visitPluralizeModelName(function() + { + return $this->pluralizeModelName(); + }) + ->visitModelLoader(function() + { + return $this->getModelLoader(); + }) + ->visitModelId(function() + { + return $this->getModelId(); + }) + ->visitModelActions(function() + { + return $this->getModelActions(); + }) + ; + $this->_controller->setResourceDefinition($this); + return $this; + } + + + protected function _addModelToView($model) { + $model_name = $this->getModelName(); + $this->_view->model_name = $model_name; + $this->_view->$model_name = $model; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Album.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Album.php new file mode 100644 index 0000000000000000000000000000000000000000..8375b1fbc2a3fbd989ad9bda29afd56d3c83cd3e --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Album.php @@ -0,0 +1,32 @@ +<?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_ResourceDefinition_Album extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract { + + public function getDefinitions() { + return ['model' => ['class' => 'Class_Album', + 'name' => 'album', + 'order' => 'libelle', + 'model_id' => 'id']]; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Article.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Article.php new file mode 100644 index 0000000000000000000000000000000000000000..cc05309d64105fec39ff800a04aa61bbd48ba49f --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Article.php @@ -0,0 +1,41 @@ +<?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_ResourceDefinition_Article extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract { + + public function getDefinitions() { + return ['model' => ['class' => 'Class_Article', + 'name' => 'article', + 'order' => 'titre', + 'model_id' => 'id_article'], + + 'messages' => ['successful_save' => $this->_('Article "%s" sauvegardé'), + 'successful_add' => $this->_('L\'article "%s" a été sauvegardé'), + 'successful_delete' => $this->_('Article "%s" supprimé')], + + 'actions' => ['add' => ['title' => $this->_("Ajouter un article")]], + 'after_edit' => function ($model) { $model->index(); } + ]; + } + +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/ArticleCategory.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/ArticleCategory.php new file mode 100644 index 0000000000000000000000000000000000000000..beb6d1362fc0d1736bc131c142341ed48fc796e1 --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/ArticleCategory.php @@ -0,0 +1,51 @@ +<?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_ResourceDefinition_ArticleCategory extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract { + public function getDefinitions() { + return + ['model' => ['class' => 'Class_ArticleCategorie', + 'name' => 'category'], + + 'messages' => ['successful_save' => $this->_('Categorie "%s" sauvegardée'), + 'successful_add' => $this->_('La catégorie "%s" a été sauvegardée'), + 'successful_delete' => $this->_('Categorie "%s" supprimée')], + + 'actions' => ['add' => ['title' => $this->_("Ajouter une catégorie")], + 'edit' => ['title' => $this->_("Modifier une catégorie")]], + + 'after_add' => function ($model) { + $this->_redirectToReferer(); + }, + + 'after_edit' => function ($model) { + $this->_redirectToReferer(); + }, + + 'after_delete' => function($model) { + $this->_redirectToReferer(); + }, + + 'form_class_name' => 'ZendAfi_Form_Admin_CmsCategory']; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Batch.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Batch.php new file mode 100644 index 0000000000000000000000000000000000000000..84bd2cb696db8de291d1db110a5e7e6e1781836a --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Batch.php @@ -0,0 +1,45 @@ +<?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_ResourceDefinition_Batch extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract { + public function getDefinitions() { + return [ + 'model' => ['class' => 'Class_Batch', + 'name' => 'batch', + 'order' => 'type', + 'findAll' => 'findAllWithDefaults'], + + 'messages' => ['successful_add' => $this->_('Tâche ajoutée'), + 'successful_delete' => $this->_('Tâche supprimée')], + + 'actions' => ['add' => ['title' => $this->_('Nouvelle Tâche')], + 'index' => ['title' => $this->_('Tâches')]], + + 'display_groups' => ['ajout_tache' => ['legend' => 'Ajouter une tâche', + 'elements' => ['type' => ['element' => 'select', + 'options' => ['multiOptions' => Class_Batch::getAvailableType(), + 'required' => true]] ]]], + 'after_add' => function() {$this->_redirect('/admin/batch');} + ]; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/CustomField.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/CustomField.php new file mode 100644 index 0000000000000000000000000000000000000000..9df3f3fddd6c65412a69a143e51bea00a1d81da0 --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/CustomField.php @@ -0,0 +1,43 @@ +<?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_ResourceDefinition_CustomField extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract { + public function getDefinitions() { + return ['model' => [ + 'class' => 'Class_CustomField', + 'name' => 'custom_fields', + 'order' => 'id', + 'scope' => 'model'], + + 'messages' => [ + 'successful_save' => $this->_('Champ personnalisé "%s" sauvegardé'), + 'successful_add' => $this->_('Champ personnalisé "%s" ajouté')], + + 'actions' => [ + 'add' => ['title' => $this->_('Nouveau champ personnalisé')], + 'edit' => ['title' => $this->_('Modifier un champ personnalisé')], + 'index' => ['title' => $this->_('Champs personnalisés')]], + + 'form_class_name' => 'ZendAfi_Form_Admin_CustomFields_CustomFieldModel']; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/CustomFieldMeta.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/CustomFieldMeta.php new file mode 100644 index 0000000000000000000000000000000000000000..563145a488907e75068e9a82b46ff44d96ee6224 --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/CustomFieldMeta.php @@ -0,0 +1,40 @@ +<?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_ResourceDefinition_CustomFieldMeta extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract { + public function getDefinitions() { + return ['model' => ['class' => 'Class_CustomField_Meta', + 'name' => 'custom_fields_meta', + 'order' => 'label'], + + 'messages' => ['successful_save' => $this->_('Champ personnalisé %s sauvegardé'), + 'successful_add' => $this->_('Champ personnalisé %s ajouté'), + 'successful_delete' => $this->_('Champ personnalisé %s supprimé')], + + 'actions' => ['add' => ['title' => $this->_('Nouveau champ personnalisé')], + 'edit' => ['title' => $this->_('Modifier un champ personnalisé')], + 'index' => ['title' => $this->_('Champs personnalisés')]], + + 'form_class_name' => 'ZendAfi_Form_Admin_CustomFields']; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/DataProfile.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/DataProfile.php new file mode 100644 index 0000000000000000000000000000000000000000..c5954d3e602c6c359c25b46856869db978ae849e --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/DataProfile.php @@ -0,0 +1,41 @@ +<?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_ResourceDefinition_DataProfile extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract { + + public function getDefinitions() { + return ['model' => ['class' => 'Class_IntProfilDonnees', + 'name' => 'data_profile', + 'order' => 'libelle'], + + 'messages' => ['successful_save' => $this->_('Profil "%s" sauvegardé'), + 'successful_add' => $this->_('Profil "%s" ajouté'), + 'successful_delete' => $this->_('Profil "%s" supprimé')], + + 'actions' => ['add' => ['title' => $this->_('Nouveau profil de données')], + 'edit' => ['title' => $this->_('Modifier le profil de données : %s')], + 'index' => ['title' => $this->_('Profils de données')]], + + 'form_class_name' => 'ZendAfi_Form_Cosmo_DataProfile']; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/DocType.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/DocType.php new file mode 100644 index 0000000000000000000000000000000000000000..212a97af40deccf80d6954759d10d2f6c15aa6ea --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/DocType.php @@ -0,0 +1,38 @@ +<?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_ResourceDefinition_DocType extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract { + public function getDefinitions() { + return [ + 'model' => ['class' => 'Class_TypeDoc', + 'name' => 'type_doc', + 'order' => 'libelle'], + 'messages' => ['successful_save' => $this->_('Type de document %s modifié')], + + 'actions' => ['edit' => ['title' => 'Modification du type de document: %s'], + 'index' => ['title' => 'Types de documents'] + ], + 'after_edit' => function($model) {$this->_redirect('/admin/type-docs');}, + 'form' => ZendAfi_Form_TypeDocs_Edit::newWith($this->_getParam('id'))]; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/ExternalAgenda.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/ExternalAgenda.php new file mode 100644 index 0000000000000000000000000000000000000000..ede104ef7d76040f944fc6942648a742d023e6cd --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/ExternalAgenda.php @@ -0,0 +1,42 @@ +<?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_ResourceDefinition_ExternalAgenda extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract { + + public function getDefinitions() { + return ['model' => ['class' => 'Class_ExternalAgenda', + 'name' => 'agenda', + 'order' => 'label'], + + 'actions' => ['index' => ['title' => $this->_('Gestion des agendas externes')], + 'add' => ['title' => $this->_('Ajouter un nouvel agenda')], + 'edit' => ['title' => $this->_('Modifier un agenda')]], + + 'messages' => ['successful_add' => $this->_('Agenda %s ajouté'), + 'successful_save' => $this->_('Agenda %s modifié'), + 'successful_delete' => $this->_('Agenda %s supprimé')], + + 'form_class_name' => 'ZendAfi_Form_Admin_ExternalAgenda', + ]; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/FRBRLink.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/FRBRLink.php new file mode 100644 index 0000000000000000000000000000000000000000..9484d479737112615b52286149ca2ce30a290957 --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/FRBRLink.php @@ -0,0 +1,41 @@ +<?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_ResourceDefinition_FRBRLink extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract { + + public function getDefinitions() { + return [ + 'model' => ['class' => 'Class_FRBR_Link', + 'name' => 'relation', + 'order' => 'source'], + + 'messages' => ['successful_save' => $this->_('Relation sauvegardée'), + 'successful_add' => $this->_('Relation ajoutée'),], + + 'actions' => ['add' => ['title' => $this->_('Nouvelle relation')], + 'edit' => ['title' => $this->_('Modifier une relation')], + 'index' => ['title' => $this->_('Notices liées')]], + + 'form' => (new ZendAfi_Form_FRBR_Link())]; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/FRBRLinkType.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/FRBRLinkType.php new file mode 100644 index 0000000000000000000000000000000000000000..087749fc918cd7f76b227ef00a18f2ab459b0f17 --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/FRBRLinkType.php @@ -0,0 +1,39 @@ +<?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_ResourceDefinition_FRBRLinkType extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract { + + public function getDefinitions() { + return ['model' => ['class' => 'Class_FRBR_LinkType', + 'name' => 'relation', + 'order' => 'libelle'], + + 'messages' => ['successful_save' => $this->_('Type de relation "%s" sauvegardé'),], + + 'actions' => ['add' => ['title' => $this->_('Nouveau type de relation')], + 'edit' => ['title' => $this->_('Modifier un type de relation')], + 'index' => ['title' => $this->_('Types de relation')]], + + 'form' => (new ZendAfi_Form_FRBR_LinkType())]; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Formation.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Formation.php new file mode 100644 index 0000000000000000000000000000000000000000..d3ceb341e1cd875cb7ff70205a5d7dafa3e155f5 --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Formation.php @@ -0,0 +1,40 @@ +<?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_ResourceDefinition_Formation extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract { + public function getDefinitions() { + return ['model' => ['class' => 'Class_Formation', + 'name' => 'formation', + 'order' => 'id'], + + 'messages' => ['successful_save' => $this->_('Formation "%s" sauvegardée'), + 'successful_add' => $this->_('La formation "%s" a été sauvegardée'), + 'successful_delete' => $this->_('Formation "%s" supprimée')], + + 'actions' => ['add' => ['title' => $this->_("Ajouter une formation")], + 'edit' => ['title' => $this->_("Modifier la formation: %s")]], + + 'form_class_name' => 'ZendAfi_Form_Admin_Formation', + 'after_add' => function($formation) { $this->_redirect('/admin/session-formation/add/formation_id/' . $formation->getId());} ]; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Library.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Library.php new file mode 100644 index 0000000000000000000000000000000000000000..c2068037e4b96ecc3c10b8156ddee9bec9783354 --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Library.php @@ -0,0 +1,39 @@ +<?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_ResourceDefinition_Library extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract { + + public function getDefinitions() { + return ['model' => ['class' => 'Class_Bib', + 'name' => 'bib', + 'order' => 'id'], + + 'messages' => ['successful_save' => $this->_('Bibliothèque "%s" sauvegardée'), + 'successful_add' => $this->_('La bibliothèque "%s" a été ajoutée'), + 'successful_delete' => $this->_('La bibliothèque "%s" a été suppriméee')], + + 'actions' => ['edit' => ['title' => $this->_("Modifier une bibliothèque")], + 'add' => ['title' => $this->_("Ajouter une bibliothèque")]], + 'form_class_name' => 'ZendAfi_Form_Admin_Library']; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Lieu.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Lieu.php new file mode 100644 index 0000000000000000000000000000000000000000..79e01fc81e9761db5b77bd4e55ad5cbd919f5472 --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Lieu.php @@ -0,0 +1,42 @@ +<?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_ResourceDefinition_Lieu extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract { + + public function getDefinitions() { + return ['model' => ['class' => 'Class_Lieu', + 'name' => 'lieu', + 'order' => 'libelle'], + + 'messages' => ['successful_save' => $this->_('Lieu "%s" sauvegardé'), + 'successful_add' => $this->_('le lieu "%s" a été créé'), + 'successful_delete' => $this->_('Lieu "%s" supprimé')], + + 'actions' => ['index' => ['title' => $this->_('Lieux')], + 'add' => ['title' => $this->_('Déclarer un nouveau lieu')], + 'edit' => ['title' => $this->_('Modifier le lieu "%s"')], + 'delete' => ['title' => $this->_('Supprimer le lieu "%s"')]], + + 'form_class_name' => 'ZendAfi_Form_Admin_Location']; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/ModeleFusion.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/ModeleFusion.php new file mode 100644 index 0000000000000000000000000000000000000000..65ff2689a55ab3ab9bf72bf3427c0534cffd6cc8 --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/ModeleFusion.php @@ -0,0 +1,43 @@ +<?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_ResourceDefinition_ModeleFusion extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract { + + public function getDefinitions() { + return ['model' => ['class' => 'Class_ModeleFusion', + 'name' => 'modele_fusion', + 'order' => 'id'], + + 'messages' => ['successful_save' => $this->_('Modèle "%s" sauvegardé'), + 'successful_add' => $this->_('Le modèle "%s" a été sauvegardé'), + 'successful_delete' => $this->_('Modèle "%s" supprimé')], + + 'actions' => ['add' => ['title' => $this->_("Ajouter un modèle")], + 'edit' => ['title' => $this->_("Modifier le modèle: %s")]], + + 'form_class_name' => 'ZendAfi_Form_ModeleFusion', + + 'after_delete' => function() { $this->_redirect('/admin/print/index');} + ]; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Multimedia.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Multimedia.php new file mode 100644 index 0000000000000000000000000000000000000000..d69f5239298b1014b8ca441b9f89e3a9f63d46fe --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Multimedia.php @@ -0,0 +1,124 @@ +<?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_ResourceDefinition_Multimedia extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract { + public function getDefinitions() { + return ['model' => ['class' => 'Class_Multimedia_Location', + 'name' => 'site'], + 'messages' => ['successful_save' => 'Site %s sauvegardé'], + 'actions' => ['edit' => ['title' => 'Modifier un site multimédia'], + 'index' => ['title' => 'Sites multimédia']], + 'display_groups' => ['localisation' => ['legend' => 'Localisation', + 'elements' => $this->_getLocalisationFields()], + + 'config' => ['legend' => 'Réservation', + 'elements' => $this->_getConfigFields()], + + 'config_auto' => ['legend' => 'Réservation automatique', + 'elements' => $this->_getConfigAutoFields()]] + ]; + } + + + protected function _getLocalisationFields() { + $libelles = []; + foreach (Class_Bib::findAllBy(['order' => 'libelle']) as $bib) + $libelles[$bib->getId()] = $bib->getLibelle(); + + return ['id_site' => ['element' => 'select', + 'options' => ['multioptions' => $libelles]]]; + } + + + protected function _getConfigFields() { + return ['slot_size' => ['element' => 'text', + 'options' => ['label' => 'Durée d\'un créneau (en minutes)', + 'title'=> 'en minutes', + 'size' => 4, + 'required' => true, + 'allowEmpty' => false, + 'validators' => ['digits']]], + + 'max_slots' => ['element' => 'text', + 'options' => ['label' => 'Nombre maximum de créneaux réservables simultanément', + 'title' => 'en nombre de "slots"', + 'size' => 4, + 'required' => true, + 'allowEmpty' => false, + 'validators' => ['digits']]], + + 'hold_delay_min' => ['element' => 'text', + 'options' => ['label' => 'Nombre de jours au plus tard avant une réservation<br/> (0 pour résa le +jour même)', + 'title' => 'en jours, 0 autorise les réservations le jour même', + 'size' => 4, + 'required' => true, + 'allowEmpty' => false, + 'validators' => ['digits']]], + + 'hold_delay_max' => ['element' => 'text', + 'options' => [ + 'label' => 'Nombre de jours au plus tôt avant une réservation<br/>(1 pour autoriser +les réservations pour le lendemain)', + 'title' => 'en jours, doit être supérieur au délai minimum', + 'size' => 4, + 'required' => true, + 'allowEmpty' => false, + 'validators' => ['digits', new ZendAfi_Validate_FieldGreater('hold_delay_min', 'Délai minimum de réservation')]]], + + 'auth_delay' => ['element' => 'text', + 'options' => ['label' => 'Délai de connexion avant d\'annuler une réservation (en minutes)', + 'title' => 'en minutes, passé ce délai la réservation est annulée', + 'size' => 4, + 'required' => true, + 'allowEmpty' => false, + 'validators' => ['digits']]]]; + } + + + protected function _getConfigAutoFields() { + return [ + 'autohold' => ['element' => 'checkbox', + 'options' => ['label' => 'Générer automatiquement une réservation à la connexion à un poste +disponible', + 'title' => 'quand un abonné se connecte sur un poste non réservé, une réservation lui est attribuée', + 'required' => true, + 'allowEmpty' => false]], + + 'autohold_min_time' => ['element' => 'text', + 'options' => ['label' => 'Temps minimum de connexion avant la réservation suivante (en minutes)', + 'title' => 'quand un abonné se connecte et qu\'une réservation est prévue dans quelques minutes, permet de définir si la réservation automatique peut s\'effectuer', + 'size' => 4, + 'required' => true, + 'allowEmpty' => false, + 'validators' => ['digits']]], + + 'autohold_slots_max' => ['element' => 'text', + 'options' => ['label' => 'Durée de la réservation automatique (en nombre de créneaux)', + 'title' => 'en nombre de "slots"', + 'size' => 4, + 'required' => true, + 'allowEmpty' => false, + 'validators' => ['digits']]]]; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Newsletter.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Newsletter.php new file mode 100644 index 0000000000000000000000000000000000000000..f3cefe4ba1bed9a6be08cb48536608687f8371bc --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Newsletter.php @@ -0,0 +1,39 @@ +<?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_ResourceDefinition_Newsletter extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract { + public function getDefinitions() { + return ['model' => ['class' => 'Class_Newsletter', + 'name' => 'newsletter', + 'order' => 'titre'], + + 'actions' => ['index' => ['title' => $this->_('Lettres d\'information')], + 'add' => ['title' => $this->_('Créer une lettre d\'information')], + 'edit' => ['title' => $this->_('Modifier une lettre d\'information : %s')]], + + 'messages' => ['successful_save' => $this->_('Lettre d\'information "%s" enregistrée'), + 'successful_delete' => $this->_('Lettre d\'information supprimée')], + + 'form_class_name' => 'ZendAfi_Form_Admin_Newsletter']; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/OAI.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/OAI.php new file mode 100644 index 0000000000000000000000000000000000000000..357ee13498f3515de78143c368a6793a9ff1cbdc --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/OAI.php @@ -0,0 +1,50 @@ +<?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_ResourceDefinition_OAI extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract { + public function getDefinitions() { + return ['model' => ['class' => 'Class_EntrepotOAI', + 'name' => 'entrepot'], + 'messages' => ['successful_add' => 'Entrepôt %s ajouté', + 'successful_save' => 'Entrepôt %s sauvegardé', + 'successful_delete' => 'Entrepôt %s supprimé'], + + 'actions' => ['edit' => ['title' => 'Modifier un entrepôt OAI'], + 'add' => ['title' => 'Ajouter un entrepôt OAI'], + 'index' => ['title' => 'Entrepôts OAI']], + + 'display_groups' => ['categorie' => ['legend' => 'Entrepôt', + 'elements' => + ['libelle' => ['element' => 'text', + 'options' => ['label' => 'Libellé *', + 'size' => 30, + 'required' => true, + 'allowEmpty' => false]], + 'handler' => ['element' => 'text', + 'options' => ['label' => 'Url *', + 'size' => '90', + 'required' => true, + 'allowEmpty' => false, + 'validators' => ['url']]]]]]]; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/OPDS.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/OPDS.php new file mode 100644 index 0000000000000000000000000000000000000000..ad9ca0c146a015c4d200d162ffbe1dae1af9ef18 --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/OPDS.php @@ -0,0 +1,51 @@ +<?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_ResourceDefinition_OPDS extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract { + + public function getDefinitions() { + return ['model' => ['class' => 'Class_OpdsCatalog', + 'name' => 'catalog'], + 'messages' => ['successful_add' => 'Catalogue %s ajouté', + 'successful_save' => 'Catalogue %s sauvegardé', + 'successful_delete' => 'Catalogue %s supprimé'], + + 'actions' => ['edit' => ['title' => 'Modifier un catalogue OPDS'], + 'add' => ['title' => 'Ajouter un catalogue OPDS'], + 'index' => ['title' => 'Catalogues OPDS']], + + 'display_groups' => ['categorie' => ['legend' => 'Catalogue', + 'elements' => + ['libelle' => ['element' => 'text', + 'options' => ['label' => 'Libellé *', + 'size' => 30, + 'required' => true, + 'allowEmpty' => false]], + 'url' => ['element' => 'text', + 'options' => ['label' => 'Url *', + 'size' => 75, + 'required' => true, + 'allowEmpty' => false, + 'validators' => ['url']]]]]]]; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Opening.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Opening.php new file mode 100644 index 0000000000000000000000000000000000000000..e7e24dcfc710a16370e6ffe008e32dffa8681e7c --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Opening.php @@ -0,0 +1,99 @@ +<?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_ResourceDefinition_Opening extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract { + public function getDefinitions() { + return ['model' => ['class' => 'Class_Ouverture', + 'name' => 'ouverture', + 'scope' => ['id_site', 'multimedia'], + 'order' => 'jour desc, jour_semaine, validity_start'], + + 'sort' => ['Class_Ouverture', 'compare'], + + 'messages' => $this->_getRessourceMessages(), + + 'after_add' => function($model) { $this->_redirectToIndex(); }, + 'after_edit' => function($model) { $this->_redirectToIndex(); }, + + 'actions' => $this->_getRessourceActions(), + + 'form' => new ZendAfi_Form_Admin_Ouverture()]; + + } + + + protected function _getRessourceMessages() { + if(!$this->_getLibrary()) + return []; + + $lib_label = $this->_library->getLibelle(); + + return $this->_isMultimedia() + ? ['successful_add' => $this->_('Plage horaire de réservation multimedia %s ajoutée', $lib_label), + 'successful_save' => $this->_('Plage horaire de réservation multimedia %s sauvegardée', $lib_label), + 'successful_delete' => $this->_('Plage horaire de réservation multimedia %s supprimée', $lib_label)] + + : ['successful_add' => $this->_('Plage d\'ouverture %s ajoutée', $lib_label), + 'successful_save' => $this->_('Plage d\'ouverture %s sauvegardée', $lib_label), + 'successful_delete' => $this->_('Plage d\'ouverture %s supprimée', $lib_label)]; + } + + + protected function _getRessourceActions() { + if(!$this->_getLibrary()) + return []; + + $lib_label = $this->_library->getLibelle(); + + return $this->_isMultimedia() + ? ['edit' => ['title' => $this->_('%s : modifier une plage horaire de réservation multimedia', $lib_label)], + 'add' => ['title' => $this->_('%s : ajouter une plage horaire de réservation multimedia', $lib_label)], + 'index' => ['title' => $this->_('%s : plages horaire de réservation multimedia', $lib_label)]] + + : ['edit' => ['title' => $this->_('%s : modifier une plage d\'ouverture', $lib_label)], + 'add' => ['title' => $this->_('%s : ajouter une plage d\'ouverture', $lib_label)], + 'index' => ['title' => $this->_('%s : plages d\'ouverture', $lib_label)]]; + } + + + public function visitLibrary($callback) { + $this->_library_callback = $callback; + return $this; + } + + + protected function _getLibrary() { + return $this->_library = call_user_func($this->_library_callback); + } + + + public function visitIsMultimedia($callback) { + $this->_is_multimedia_callback = $callback; + return $this; + } + + + protected function _isMultimedia() { + return $this->_is_multimedia = call_user_func($this->_is_multimedia_callback); + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Report.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Report.php new file mode 100644 index 0000000000000000000000000000000000000000..2d6f2bedeb753a1c318415c81a4d2c33f43f05a0 --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Report.php @@ -0,0 +1,37 @@ +<?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_ResourceDefinition_Report extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract { + public function getDefinitions() { + return ['model' => ['class' => 'Class_Report', 'name' => 'report', 'order' => 'label'], + 'messages' => ['successful_save' => $this->_('Rapport %s modifié')], + + 'actions' => [ + 'add' => ['title' => $this->_('Nouveau rapport')], + 'edit' => ['title' => $this->_('Modification du rapport: %s')], + 'index' => ['title' => $this->_('Rapports')]], + + 'form_class_name' => 'ZendAfi_Form_Report' + ]; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/SessionFormation.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/SessionFormation.php new file mode 100644 index 0000000000000000000000000000000000000000..bf227d33f81302c8a4ac9b6cc955436b74b4b73e --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/SessionFormation.php @@ -0,0 +1,51 @@ +<?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_ResourceDefinition_SessionFormation extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract { + + public function getDefinitions() { + return ['model' => ['class' => 'Class_SessionFormation', + 'name' => 'session_formation', + 'order' => 'id'], + + 'messages' => ['successful_save' => $this->_('Session "%s" sauvegardée'), + 'successful_add' => $this->_('La session "%s" a été sauvegardée'), + 'successful_delete' => $this->_('Session "%s" supprimée')], + + 'actions' => ['add' => ['title' => $this->_("Ajouter une session")], + 'edit' => ['title' => $this->_("Modifier la session: %s")]], + + 'form_class_name' => 'ZendAfi_Form_Admin_SessionFormation', + + 'after_delete' => function($model) { $this->_redirect('/admin/formation/index');}, + + 'after_add' => function($session) { $this->_afterAdd($session); } + ]; + } + + + protected function _afterAdd($session) { + Class_Formation::find($this->_getParam('formation_id'))->addSession($session)->save(); + } + +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Sitotheque.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Sitotheque.php new file mode 100644 index 0000000000000000000000000000000000000000..ba26d819e6b8a39ffe7714d39a447044a11eff8d --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Sitotheque.php @@ -0,0 +1,47 @@ +<?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_ResourceDefinition_Sitotheque extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract { + + public function getDefinitions() { + return [ + 'model' => [ + 'class' => 'Class_Sitotheque', + 'name' => 'sitotheque', + 'order' => 'id', + 'scope' => 'id_cat'], + + 'messages' => [ + 'successful_save' => $this->_('Site "%s" sauvegardé'), + 'successful_add' => $this->_('Le site "%s" a été sauvegardé'), + 'successful_delete' => $this->_('Site "%s" supprimé')], + + 'actions' => [ + 'add' => ['title' => $this->_("Ajouter un site")], + 'edit' => ['title' => $this->_("Modifier le site: %s")], + 'delete' => ['title' => $this->_("Supprimer le site: %s")] + ], + + 'form_class_name' => 'ZendAfi_Form_Admin_Sitotheque']; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/SuggestionAchat.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/SuggestionAchat.php new file mode 100644 index 0000000000000000000000000000000000000000..b87f76894cbf32f18d39557ff13682f15314c77f --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/SuggestionAchat.php @@ -0,0 +1,38 @@ +<?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_ResourceDefinition_SuggestionAchat extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract { + public function getDefinitions() { + return [ + 'model' => ['class' => 'Class_SuggestionAchat', + 'name' => 'suggestion', + 'order' => 'date_creation'], + + 'messages' => ['successful_save' => 'Suggestion d\'achat %s sauvegardée'], + + 'actions' => ['edit' => ['title' => 'Modifier une suggestion d\'achat'], + 'index' => ['title' => 'Suggestions d\'achat']], + + 'form' => (new ZendAfi_Form_SuggestionAchat())->removeSubmitButton() ]; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/User.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/User.php new file mode 100644 index 0000000000000000000000000000000000000000..dcd759d7c0b5410ce0ae164224678545d71ce1d8 --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/User.php @@ -0,0 +1,41 @@ +<?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_ResourceDefinition_User extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract { + + public function getDefinitions() { + return ['model' => ['class' => 'Class_Users', + 'name' => 'user', + 'order' => 'id'], + + 'messages' => ['successful_save' => $this->_('L\'utilisateur "%s" a été sauvegardé'), + 'successful_add' => $this->_('L\'utilisateur "%s" a été ajouté'), + 'successful_delete' => $this->_('L\'utilisateur "%s" a été supprimé')], + + 'actions' => ['add' => ['title' => $this->_('Ajouter un utilisateur')], + 'edit' => ['title' => $this->_('Modifier l\'utilisateur: %s')], + 'delete' => ['title' => $this->_('Supprimer l\'utilisateur: %s')]], + + 'form_class_name' => 'ZendAfi_Form_Admin_User']; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/UserGroup.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/UserGroup.php new file mode 100644 index 0000000000000000000000000000000000000000..fda472900f24a73c430b03fc3004e820121f721b --- /dev/null +++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/UserGroup.php @@ -0,0 +1,42 @@ +<?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_ResourceDefinition_UserGroup extends ZendAfi_Controller_Plugin_ResourceDefinition_Abstract { + public function getDefinitions() { + return ['model' => [ + 'class' => 'Class_UserGroup', + 'name' => 'user_group', + 'order' => 'id'], + + 'messages' => [ + 'successful_save' => $this->_('Groupe "%s" sauvegardé'), + 'successful_add' => $this->_('Le groupe "%s" a été sauvegardé'), + 'successful_delete' => $this->_('Groupe "%s" supprimé')], + + 'actions' => [ + 'add' => ['title' => $this->_("Ajouter un groupe d'utilisateurs")], + 'edit' => ['title' => $this->_("Modifier le groupe d'utilisateurs: %s")]], + + 'form_class_name' => 'ZendAfi_Form_Admin_UserGroup']; + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/Admin/CustomFieldsCategories.php b/library/ZendAfi/View/Helper/Admin/CustomFieldsCategories.php index b98c07e312283772bd01fce3954cf0504ec90990..e982984f0739f62ca08ff0508c54da40d7b15db8 100644 --- a/library/ZendAfi/View/Helper/Admin/CustomFieldsCategories.php +++ b/library/ZendAfi/View/Helper/Admin/CustomFieldsCategories.php @@ -30,7 +30,7 @@ class ZendAfi_View_Helper_Admin_CustomFieldsCategories extends ZendAfi_View_Help $categories_actions = [ ['url' => $this->view->url([ - 'module' => 'admin', + 'module' => 'admin', 'controller' => 'custom-fields', 'action' => 'add'], null, true).'/model/%s', 'icon' => 'add_page', diff --git a/library/ZendAfi/View/Helper/Admin/ListViewMode.php b/library/ZendAfi/View/Helper/Admin/ListViewMode.php index 9eb329a0b90bb39c36a3d3bdbae52617ac382249..e4153539b47bafe1911e8b1e90a5b41b3736e84b 100644 --- a/library/ZendAfi/View/Helper/Admin/ListViewMode.php +++ b/library/ZendAfi/View/Helper/Admin/ListViewMode.php @@ -62,11 +62,12 @@ class ZendAfi_View_Helper_Admin_ListViewMode extends ZendAfi_View_Helper_BaseHel protected function getBreadcrumbHTML() { - $html = $this->getBreadcrumbHTMLFor($this->_list->getBreadcrumb()) - . ' ' - . $this->view->modelActions($this->_list->getDefaultModel(), $this->getCategoriesActions($this->_list->getModel()), true); - return $this->_tag('div', $html, - ['style' => 'font-size:140%;']); + $html = [$this->getBreadcrumbHTMLFor($this->_list->getBreadcrumb()), + $this->view->renderPluginsActions($this->_list->getDefaultModel())]; + + return $this->_tag('div', + implode($html), + ['class' => 'breadcrumb']); } @@ -95,8 +96,10 @@ class ZendAfi_View_Helper_Admin_ListViewMode extends ZendAfi_View_Helper_BaseHel ->tagModelTable($this->_list->getCategories(), $this->_list->getCategoriesCols(), $this->_list->getCategoriesAttribs(), - [function($model) { - return $this->view->modelActions($model, $this->getCategoriesActions($model));}], + [function($model) + { + return $this->view->renderPluginsActions($model); + }], $this->_list->getCategoriesId(), $this->_list->getCategoriesGroupBy(), [$this->_list->getCategoriesLabelAttrib() => $labelWithCount]); @@ -135,8 +138,10 @@ class ZendAfi_View_Helper_Admin_ListViewMode extends ZendAfi_View_Helper_BaseHel ->view->tagModelTable($this->_list->getItems(), $this->_list->getItemsCols(), $this->_list->getItemsAttribs(), - [function($model) { - return $this->view->modelActions($model, $this->getItemsActions($model));}], + [function($model) + { + return $this->view->renderPluginsActions($model); + }], $this->_list->getItemsId(), $this->_list->getItemsGroupBy(), $this->_list->getSearchValue() ? [$this->_list->getItemsLabelAttrib() => $labelWithBreadcrumb] : []); @@ -148,11 +153,6 @@ class ZendAfi_View_Helper_Admin_ListViewMode extends ZendAfi_View_Helper_BaseHel } - protected function getCategoriesActions($model) { - return $this->view->categoriesActions($model, $this->_list->getStrategyLabel()); - } - - protected function getItemsActions($model) { return $this->view->itemsActions($model, $this->_list->getStrategyLabel()); } diff --git a/library/ZendAfi/View/Helper/CategoriesActions.php b/library/ZendAfi/View/Helper/CategoriesActions.php index 0fc9195af9a3b6924e3b693ee984c42206301a2b..f6bd7f6f625c4998f1c2d6a32403c07b687381e0 100644 --- a/library/ZendAfi/View/Helper/CategoriesActions.php +++ b/library/ZendAfi/View/Helper/CategoriesActions.php @@ -21,17 +21,19 @@ class ZendAfi_View_Helper_CategoriesActions extends Zend_View_Helper_Abstract { - public function categoriesActions($model, $strategy) { - if('album' == $strategy) + public function categoriesActions($model) { + $strategy = get_class($model); + + if('Class_Album' == $strategy) return (new ZendAfi_View_Helper_ModelActionsTable_AlbumCategories($this->view, $model))->getActions(); - if(('article' == $strategy && !$model) || ('bib' == $strategy && $model)) + if('Class_Bib' == $strategy) return (new ZendAfi_View_Helper_ModelActionsTable_Bib($this->view, $model))->getActions(); - if('article' == $strategy) + if('Class_Article' == $strategy) return (new ZendAfi_View_Helper_ModelActionsTable_ArticlesCategories($this->view, $model))->getActions(); - return ''; + return []; } } ?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/ModelActionsTable.php b/library/ZendAfi/View/Helper/ModelActionsTable.php index 120441f3be557063aeef85fcaf3033c8a0565af8..151c693fe63d7c4dc4ba21b9ab84bd3393008e03 100644 --- a/library/ZendAfi/View/Helper/ModelActionsTable.php +++ b/library/ZendAfi/View/Helper/ModelActionsTable.php @@ -34,8 +34,6 @@ class ZendAfi_View_Helper_ModelActionsTable { public function setActions($actions) { - $actions = array_map(function($element) { return $element; }, $actions); - $actions = array_map(function($element) { $element['label'] = $this->view->_($element['label']); return $element; }, $actions); return $actions; } diff --git a/library/ZendAfi/View/Helper/ModelActionsTable/Album.php b/library/ZendAfi/View/Helper/ModelActionsTable/Album.php index 141f9caade1294918af268a7d7279de547ac9822..1ec16b98db5a8d79553633326228072227e63d64 100644 --- a/library/ZendAfi/View/Helper/ModelActionsTable/Album.php +++ b/library/ZendAfi/View/Helper/ModelActionsTable/Album.php @@ -35,29 +35,21 @@ class ZendAfi_View_Helper_ModelActionsTable_Album extends ZendAfi_View_Helper_Mo $actions = [['url' => $this->_getUrlForAction('edit_album'), 'icon' => 'edit', 'label' => 'Modifier l\'album'], + ['url' => $this->_getUrlForAction('edit_images'), 'icon' => 'images', 'label' => 'Gérer les médias', 'caption' => 'formatedCount'], + ['url' => $this->_getUrlForAction('preview_album'), 'icon' => function($model) {return $model->isVisible() ? 'view' : 'hide';}, 'label' => 'Visualisation de l\album'], + ['url' => $this->_getUrlForAction('delete_album'), 'icon' => 'delete', 'label' => 'Supprimer l\'album', - 'anchorOptions' => ['onclick' => 'return confirm(\'' . $this->view->_('Êtes-vous sûr de vouloir supprimer cet album') . ';\')']], - ['url' => $this->_getUrlFor('album', 'add-model-to-selection', 'select_id', true), - 'icon' => 'basket', - 'label' => 'sélectionner l\'album', - 'condition' => function($model) { - return !Class_MultiSelection_Album::isSelected($model->getId()); - }], - ['url' => $this->_getUrlFor('album', 'remove-model-from-selection', 'select_id', true), - 'icon' => 'cancel', - 'label' => 'Désélectionner l\'album', - 'condition' => function($model) { - return Class_MultiSelection_Album::isSelected($model->getId()); - }]]; + 'anchorOptions' => ['onclick' => 'return confirm(\'' . $this->view->_('Êtes-vous sûr de vouloir supprimer cet album') . ';\')']]]; + return $this->setActions($actions); } } diff --git a/library/ZendAfi/View/Helper/ModelActionsTable/Article.php b/library/ZendAfi/View/Helper/ModelActionsTable/Article.php index 560a66a42d178099b6899b99aeb2a86b38d4016d..517d8c514ce3215360e8a6142c0e55ea43c5716b 100644 --- a/library/ZendAfi/View/Helper/ModelActionsTable/Article.php +++ b/library/ZendAfi/View/Helper/ModelActionsTable/Article.php @@ -70,20 +70,6 @@ class ZendAfi_View_Helper_ModelActionsTable_Article extends ZendAfi_View_Helper_ 'label' => 'Supprimer', 'condition' => $permission_closure]; - $actions[] = ['url' => $this->_getUrlFor('cms', 'add-model-to-selection', 'select_id', true), - 'icon' => 'basket', - 'label' => 'sélectionner l\'article', - 'condition' => function($model) use ($permission_closure) { - return $permission_closure($model) && (!Class_MultiSelection_Article::isSelected($model->getId())); - }]; - - $actions[] = ['url' => $this->_getUrlFor('cms', 'remove-model-from-selection', 'select_id', true), - 'icon' => 'cancel', - 'label' => 'Désélectionner l\'article', - 'condition' => function($model) use ($permission_closure) { - return $permission_closure($model) && Class_MultiSelection_Article::isSelected($model->getId()); - }]; - return $this->setActions($actions); } } diff --git a/library/ZendAfi/View/Helper/Admin/MultipleSelectorWidget.php b/library/ZendAfi/View/Helper/Plugin/MultiSelection/Widget.php similarity index 88% rename from library/ZendAfi/View/Helper/Admin/MultipleSelectorWidget.php rename to library/ZendAfi/View/Helper/Plugin/MultiSelection/Widget.php index 3e6326e58fe0a0d5ac4d556a64c7709b252dd4fc..6906fedb4667f51c04a8e1812a9a33345309b777 100644 --- a/library/ZendAfi/View/Helper/Admin/MultipleSelectorWidget.php +++ b/library/ZendAfi/View/Helper/Plugin/MultiSelection/Widget.php @@ -20,9 +20,9 @@ */ -class ZendAfi_View_Helper_Admin_MultipleSelectorWidget extends ZendAfi_View_Helper_BaseHelper { +class ZendAfi_View_Helper_Plugin_MultiSelection_Widget extends ZendAfi_View_Helper_BaseHelper { - public function Admin_MultipleSelectorWidget($multi_selection) { + public function Plugin_MultiSelection_Widget($multi_selection) { if(!$multi_selection) return ''; @@ -77,9 +77,10 @@ class ZendAfi_View_Helper_Admin_MultipleSelectorWidget extends ZendAfi_View_Help $this->_('Catégorie')], [$this->_title_key, 'cat_label'], - [function($model) { - return $this->view->modelActions($model, - $this->view->itemsActions($model, $this->_strategy));}], + [function($model) + { + return $this->view->renderPluginsActions($model); + }], '', null, ['cat_label' => $this->_category_label]); @@ -90,6 +91,17 @@ class ZendAfi_View_Helper_Admin_MultipleSelectorWidget extends ZendAfi_View_Help } + public function visitWidget($multi_selection) { + $multi_selection->acceptWidgetVisitor($this); + return $this; + } + + + public function visitActions($multi_selection) { + return $this; + } + + public function visitTitle($title) { $this->_title = $title; return $this; diff --git a/library/ZendAfi/View/Helper/PluginRenderer.php b/library/ZendAfi/View/Helper/PluginRenderer.php new file mode 100644 index 0000000000000000000000000000000000000000..80f9ea1d7ea8e458ddb2092220c1eb12fde6955c --- /dev/null +++ b/library/ZendAfi/View/Helper/PluginRenderer.php @@ -0,0 +1,39 @@ +<?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 + */ + + +abstract class ZendAfi_View_Helper_PluginRenderer extends Zendafi_View_Helper_Basehelper { + public function render($method) { + if(!isset($this->view->plugins)) + return ''; + + $plugins = $this->view->plugins; + + if($plugins->isEmpty()) + return ''; + + $plugins->eachDo(function($plugin) use ($method) + { + echo call_user_func([$plugin, $method]); + }); + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/ModelActions.php b/library/ZendAfi/View/Helper/RenderModelActions.php similarity index 57% rename from library/ZendAfi/View/Helper/ModelActions.php rename to library/ZendAfi/View/Helper/RenderModelActions.php index 2c2f8eb1fe002bd77475a1e3f761083445391d10..6a8d74861b43f3c2164790bd4c6af2143055956d 100644 --- a/library/ZendAfi/View/Helper/ModelActions.php +++ b/library/ZendAfi/View/Helper/RenderModelActions.php @@ -20,24 +20,23 @@ */ -class ZendAfi_View_Helper_ModelActions extends ZendAfi_View_Helper_BaseHelper { - public function modelActions($model, $actions, $inline=false) { +class ZendAfi_View_Helper_RenderModelActions extends ZendAfi_View_Helper_BaseHelper { + public function renderModelActions($model, $actions) { if (!$model || !$actions) return ''; $html = ''; foreach ($actions as $action) - $html .= (new ZendAfi_View_Helper_ModelAction($action, $this->view)) + $html .= (new ZendAfi_View_Helper_RenderModelAction($action, $this->view)) ->render($model); - return $inline ? - $html : $this->view->tag('div', $html, ['class' => 'actions']); + return $this->_tag('div', $html, ['class' => 'actions']); } } -class ZendAfi_View_Helper_ModelAction { +class ZendAfi_View_Helper_RenderModelAction { const CONDITION = 'condition'; const CAPTION = 'caption'; const ICON = 'icon'; @@ -59,19 +58,23 @@ class ZendAfi_View_Helper_ModelAction { * @return string */ public function render($model) { - if (!$this->_meetsRequirements($model)) + if(!$this->_conf) return ''; - $caption = array_key_exists(self::CAPTION, $this->_conf) ? - $model->{$this->_conf[self::CAPTION]}() : ''; + if (!$this->_meetsRequirements($model)) + return ''; - $url = $this->_injectId($model->getId(), $this->_conf[self::URL]); + $caption = $this->_initCaption($model); + $url = $this->_initUrl($model); $icon = $this->_initIcon($model); - $anchorOptions = $this->_initAnchorOptions($model->getId()); + + $anchorOptions = $this->_initAnchorOptions($model->getId(), $url); + + $title = $this->_initTitle($model); $content = $this->_current_skin->renderActionIconOn($icon, $this->_view, - ['alt' => $this->_conf[self::LABEL], - 'title' => $this->_conf[self::LABEL], + ['alt' => $title, + 'title' => $title, 'class' => 'ico']) . $caption; @@ -95,17 +98,65 @@ class ZendAfi_View_Helper_ModelAction { if (!array_key_exists(self::ICON, $this->_conf)) return null; - return is_a($this->_conf[self::ICON], 'Closure') ? - $this->_conf[self::ICON]($model) : $this->_conf[self::ICON]; + return is_a($this->_conf[self::ICON], 'Closure') + ? $this->_conf[self::ICON]($model) + : $this->_conf[self::ICON]; } - protected function _initAnchorOptions($model_id) { - return array_key_exists(self::ANCHOR_OPTIONS, $this->_conf) ? - $this->_injectIdIn($model_id, $this->_conf[self::ANCHOR_OPTIONS]) : []; + public function _initCaption($model) { + if (!array_key_exists(self::CAPTION, $this->_conf)) + return null; + + return is_a($this->_conf[self::CAPTION], 'Closure') + ? $this->_conf[self::CAPTION]($model) + : $model->{$this->_conf[self::CAPTION]}(); } + protected function _initTitle($model) { + return is_a($this->_conf[self::LABEL], 'Closure') + ? $this->_conf[self::LABEL]($model) + : $this->_conf[self::LABEL]; + } + + + protected function _initAnchorOptions($model_id, $url) { + $attribs = array_key_exists(self::ANCHOR_OPTIONS, $this->_conf) + ? $this->_injectIdIn($model_id, $this->_conf[self::ANCHOR_OPTIONS]) + : []; + + if(!isset($_SERVER['REQUEST_URI'])) + return $attribs; + + if ((false === strpos($_SERVER['REQUEST_URI'], $url)) + && (false === strpos($url, $_SERVER['REQUEST_URI']))) + return $attribs; + + isset($attribs['class']) + ? ($attribs['class'] .= ' selected') + : ($attribs['class'] = 'selected'); + + return $attribs; + } + + + protected function _initUrl($model) { + $id = $model->getId(); + + if(!isset($this->_conf[self::URL])) + return ''; + + if(!$url = $this->_conf[self::URL]) + return ''; + + $url = is_array($url) + ? $this->_injectIdIn($id, $url) + : $this->_injectId($id, $url); + + return Class_Url::absolute($url); + } + protected function _injectIdIn($model_id, $attribs) { $return = []; foreach($attribs as $attrib => $value) diff --git a/library/ZendAfi/View/Helper/RenderPlugins.php b/library/ZendAfi/View/Helper/RenderPlugins.php index c89564e6ce6abf0fc930ced5fcba8d6165675c83..dbeea838c2f5f032a41c9c55e08d0dfe80eae445 100644 --- a/library/ZendAfi/View/Helper/RenderPlugins.php +++ b/library/ZendAfi/View/Helper/RenderPlugins.php @@ -20,20 +20,9 @@ */ -class ZendAfi_View_Helper_RenderPlugins extends ZendAfi_View_Helper_BaseHelper { +class ZendAfi_View_Helper_RenderPlugins extends ZendAfi_View_Helper_PluginRenderer { public function renderPlugins() { - if(!isset($this->view->plugins)) - return ''; - - $this->plugins = $this->view->plugins; - - if(!$this->plugins->count()) - return ''; - - $this->plugins->eachDo(function($plugin) - { - echo $plugin->render(); - }); + return $this->render('render'); } } ?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/RenderPluginsActions.php b/library/ZendAfi/View/Helper/RenderPluginsActions.php new file mode 100644 index 0000000000000000000000000000000000000000..cd4a9fb5eaf7c598738dec1d610b10fc16982732 --- /dev/null +++ b/library/ZendAfi/View/Helper/RenderPluginsActions.php @@ -0,0 +1,39 @@ +<?php +/** + * Copyright (c) 2012-2014, 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_View_Helper_RenderPluginsActions extends ZendAfi_View_Helper_BaseHelper { + public function renderPluginsActions($model) { + if(!isset($this->view->plugins)) + return ''; + + $plugins = $this->view->plugins; + + if($plugins->isEmpty()) + return ''; + + return $this->view->renderModelActions($model, + $plugins->injectInto([],function($actions, $plugin) use($model) + { + return array_merge($actions, $plugin->getActions($model)); + })); + } +} \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/RenderPluginsHeaderActions.php b/library/ZendAfi/View/Helper/RenderPluginsHeaderActions.php new file mode 100644 index 0000000000000000000000000000000000000000..18cd7dce7a44dba7892f348b388959e69788bcd9 --- /dev/null +++ b/library/ZendAfi/View/Helper/RenderPluginsHeaderActions.php @@ -0,0 +1,28 @@ +<?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_View_Helper_RenderPluginsHeaderActions extends ZendAfi_View_Helper_PluginRenderer { + public function renderPluginsHeaderActions() { + return $this->render('renderHeaderActions'); + } +} +?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/TagModelTable.php b/library/ZendAfi/View/Helper/TagModelTable.php index dff917e01e6fa956d419a1415749f05d122ea617..5402ad9c0dbdc523a6768d039d230ca8a95553e4 100644 --- a/library/ZendAfi/View/Helper/TagModelTable.php +++ b/library/ZendAfi/View/Helper/TagModelTable.php @@ -201,6 +201,7 @@ class ZendAfi_View_Helper_TagModelTable extends ZendAfi_View_Helper_BaseHelper { $content = $action['content']; $url = $this->view->url(['action' => $action['action'], 'id' => $model->getId()]); $attribs = ['href' => $url, 'rel' => $action['action']]; + if (isset($_SERVER['REQUEST_URI']) && false !== strpos($_SERVER['REQUEST_URI'], $url)) $attribs['class'] = 'selected'; diff --git a/library/ZendAfi/View/Helper/TreeView.php b/library/ZendAfi/View/Helper/TreeView.php index 34997ff66dd1ac6988282cdc4f1759ed0c36f8ef..8599efacdf11549822d5d5f3f6c720a10130936e 100644 --- a/library/ZendAfi/View/Helper/TreeView.php +++ b/library/ZendAfi/View/Helper/TreeView.php @@ -208,7 +208,7 @@ class ZendAfi_View_Helper_TreeView extends Zend_View_Helper_Abstract { * @return string */ protected function _renderActions($type, $model) { - return $this->view->modelActions($model, $this->{'_' . $type . 'Actions'}); + return $this->view->renderPluginsActions($model); } } diff --git a/public/admin/css/global.css b/public/admin/css/global.css index 6caa78ae5c19141771b848a3faf9eeafd790f410..7798ffd444dbb2e01e1b3d6c385cc1167af3e40f 100644 --- a/public/admin/css/global.css +++ b/public/admin/css/global.css @@ -1495,3 +1495,11 @@ div.ColorPickerDivSample { margin-top: 4px; margin-right: 0px; } + +.modules .breadcrumb { + font-size: 1.4em; +} + +.modules .breadcrumb .actions { + display: inline-block; +} diff --git a/public/admin/skins/bokeh74/global.css b/public/admin/skins/bokeh74/global.css index 3659631d8ef4666e72f3876fb9e68c13bf82c5ec..86646616e64da7fdbd8a666250721f7477697478 100755 --- a/public/admin/skins/bokeh74/global.css +++ b/public/admin/skins/bokeh74/global.css @@ -790,3 +790,11 @@ form .droite { .fonction_menu:hover { text-decoration: underline; } + +.modules .breadcrumb { + font-size: 1.4em; +} + +.modules .breadcrumb .actions { + display: inline-block; +} diff --git a/public/admin/skins/retro/global.css b/public/admin/skins/retro/global.css index 32db7f506adcd89466ed4bdfc5af9c09ff7305ce..370e0addaa03307278b8de622c479ef79c1d5d77 100755 --- a/public/admin/skins/retro/global.css +++ b/public/admin/skins/retro/global.css @@ -725,3 +725,11 @@ form .droite { .header_actions .selected { border-bottom: 3px solid; } + +.modules .breadcrumb { + font-size: 1.4em; +} + +.modules .breadcrumb .actions { + display: inline-block; +} diff --git a/tests/application/modules/admin/controllers/AlbumControllerListViewModeTest.php b/tests/application/modules/admin/controllers/AlbumControllerListViewModeTest.php index 999eb2fa3c597d9aa962a1c409ce8fd0a52eca64..4ff485f3c175c161140ac911958a15f40cd070de 100644 --- a/tests/application/modules/admin/controllers/AlbumControllerListViewModeTest.php +++ b/tests/application/modules/admin/controllers/AlbumControllerListViewModeTest.php @@ -139,7 +139,7 @@ class Admin_AlbumControllerListViewModeIndexTest extends Admin_AlbumControllerLi /** @test */ public function breadcumbShouldContainsAddAction() { - $this->assertXPathContentContains('//div[@style="font-size:140%;"]//a[contains(@href, "admin/album/add_categorie")]', 'img', $this->_response->getBody()); + $this->assertXPathContentContains('//div//a[contains(@href, "admin/album/add_categorie")]', 'img', $this->_response->getBody()); } @@ -262,14 +262,14 @@ class Admin_AlbumControllerListViewModeIndexSubCategoriesTest extends Admin_Albu /** @test */ public function withCatId3breadcumbShouldContainsParentCat() { $this->dispatch('admin/album/index/cat_id/3', true); - $this->assertXPathContentContains('//div[@style="font-size:140%;"]', 'Cat with children', $this->_response->getBody()); + $this->assertXPathContentContains('//div', 'Cat with children', $this->_response->getBody()); } /** @test */ public function withCatId4breadcumbShouldContainsParentsCat() { $this->dispatch('admin/album/index/cat_id/4', true); - $this->assertXPathContentContains('//div[@style="font-size:140%;"]', 'Cat with children', $this->_response->getBody()); + $this->assertXPathContentContains('//div', 'Cat with children', $this->_response->getBody()); } diff --git a/tests/application/modules/admin/controllers/CmsCategoryControllerTest.php b/tests/application/modules/admin/controllers/CmsCategoryControllerTest.php index 8e6bde971c7fc7a7058b075732a578341e4e5cad..d71a45804a9ca571e9b49cadd141c61d306fa58a 100644 --- a/tests/application/modules/admin/controllers/CmsCategoryControllerTest.php +++ b/tests/application/modules/admin/controllers/CmsCategoryControllerTest.php @@ -223,7 +223,7 @@ class CmsCategoryControllerAddPostActionTest extends CmsCategoryControllerAction /** @test */ public function shouldRedirectToTreeView() { - $this->assertRedirectTo('/admin/cms/index/id_cat/'.$this->category->getId()); + $this->assertRedirect(); } } @@ -510,7 +510,7 @@ class CmsCategoryControllerEditPostActionTest extends CmsCategoryControllerActio /** @test */ public function shouldRedirectToTreeView() { - $this->assertRedirectTo('/admin/cms/index/id_cat/'.$this->category->getId()); + $this->assertRedirect(); } } @@ -538,7 +538,7 @@ class CmsCategoryControllerDeleteActionTest /** @test */ public function shouldRedirectToTreeView() { - $this->assertRedirectTo('/admin/cms/index'); + $this->assertRedirect(); } } @@ -559,7 +559,7 @@ class CmsCategoryControllerDeleteWithParentTest extends CmsCategoryControllerAct /** @test */ public function shouldRedirectToTreeView() { - $this->assertRedirectTo('/admin/cms/index/id_cat/23'); + $this->assertRedirect(); } } diff --git a/tests/application/modules/admin/controllers/CmsControllerTest.php b/tests/application/modules/admin/controllers/CmsControllerTest.php index 4e7921161b65aa4a2b29eaee61a59e0f42053824..359980f56865e577b0d76ee63b9fcf5c12e08b7f 100644 --- a/tests/application/modules/admin/controllers/CmsControllerTest.php +++ b/tests/application/modules/admin/controllers/CmsControllerTest.php @@ -560,7 +560,7 @@ class CmsControllerArticleDuplicateActionTest extends CmsControllerWithPermissio /** @test */ public function titreShouldBeDupliquerLArticleConcert() { - $this->assertXPathContentContains('//h1', 'Dupliquer l\'article: Concert'); + $this->assertXPathContentContains('//h1', 'Dupliquer l\'article : Concert'); } } @@ -2696,7 +2696,7 @@ class CmsControllerCategorieEvenementTest extends CmsControllerWithPermissionTes public function deleteShouldRedirectToAdminCmsParentCategorie() { $this->dispatch('/admin/cms-category/delete/id/34'); - $this->assertRedirectTo('/admin/cms/index/id_cat/23'); + $this->assertRedirect(); $this->assertEquals($this->cat_evenements, $this->categorie_wrapper->getFirstAttributeForLastCallOn('delete')); @@ -2713,8 +2713,7 @@ class CmsControllerCategorieEvenementTest extends CmsControllerWithPermissionTes /** @test */ public function addCategorieCancelButtonShouldLinkToIndexIdCat34() { $this->dispatch('/admin/cms-category/add/id/34'); - $this->assertXPath("//div[contains(@onclick, '/admin/cms/index/id_cat/34')]", - $this->_response->getBody()); + $this->assertXPath("//div[contains(@onclick, '/admin/cms/index/id_cat/34')]"); } @@ -2728,7 +2727,7 @@ class CmsControllerCategorieEvenementTest extends CmsControllerWithPermissionTes /** @test */ public function editCategorieCancelButtonShouldLinkToIndexIdCat34() { - $this->dispatch('/admin/cms-category/edit/id/34'); + $this->dispatch('/admin/cms-category/edit/id/34', true); $this->assertXPath("//div[contains(@onclick, '/admin/cms/index/id_cat/34')]"); } @@ -2740,7 +2739,7 @@ class CmsControllerCategorieEvenementTest extends CmsControllerWithPermissionTes 'id_cat_mere' => 34]); - $this->assertEquals('/admin/cms/index/id_cat/35', $this->getResponseLocation()); + $this->assertRedirect(); $new_cat = $this->categorie_wrapper->getFirstAttributeForLastCallOn('save'); $this->assertEquals('concerts', $new_cat->getLibelle()); @@ -2758,7 +2757,7 @@ class CmsControllerCategorieEvenementTest extends CmsControllerWithPermissionTes ->setPost(array('libelle' => 'Actualite', 'id_cat_mere' => 254)); $this->dispatch('/admin/cms-category/edit/id/34'); - $this->assertEquals('/admin/cms/index/id_cat/34', $this->getResponseLocation()); + $this->assertRedirect(); $this->assertEquals('Actualite', $this->cat_evenements->getLibelle()); $this->assertEquals(254, $this->cat_evenements->getIdCatMere()); $this->assertTrue($this->categorie_wrapper->methodHasBeenCalled('save')); diff --git a/tests/application/modules/admin/controllers/NewsletterControllerTest.php b/tests/application/modules/admin/controllers/NewsletterControllerTest.php index eeda907295e05d8dbea7b9c4abc5d1b5665f5572..18dc06443d698becc8c5731a8dceee00cde2d2ce 100644 --- a/tests/application/modules/admin/controllers/NewsletterControllerTest.php +++ b/tests/application/modules/admin/controllers/NewsletterControllerTest.php @@ -62,14 +62,12 @@ class Admin_NewsletterControllerConfigActionTest extends Admin_NewsletterControl /** @test */ public function NewsletterIdProfilVarShouldBeDisplayed() { $this->assertXPathContentContains('//tr//td','NEWSLETTER_ID_PROFIL'); - } /** @test */ public function NewsletterUnsubscribeVarShouldBeDisplayed() { $this->assertXPathContentContains('//tr//td','NEWSLETTER_UNSUBSCRIBE_TEXT'); - } } @@ -118,7 +116,7 @@ class Admin_NewsletterControllerIndexActionTest extends Admin_NewsletterControll /** @test */ public function numberOfSubscriberToNouveauteClassiqueShouldBeThree() { - $this->assertXPathContentContains("//a[@href='/admin/newsletter/edit-subscribers/id/1']", + $this->assertXPathContentContains("//a[contains(@href, '/admin/newsletter/edit-subscribers/id/1')]", '00003'); } @@ -130,37 +128,37 @@ class Admin_NewsletterControllerIndexActionTest extends Admin_NewsletterControll public function testEditNouveautesClassiqueLink() { - $this->assertXPath("//a[@href='/admin/newsletter/edit/id/1']"); + $this->assertXPath("//a[contains(@href, '/admin/newsletter/edit/id/1')]"); } public function testDeleteNouveautesClassiqueLink() { - $this->assertXPath("//a[@href='/admin/newsletter/delete/id/1']"); + $this->assertXPath("//a[contains(@href, '/admin/newsletter/delete/id/1')]"); } public function testEditSubscribersNouveautesClassiqueLink() { - $this->assertXPath("//a[@href='/admin/newsletter/edit-subscribers/id/1']"); + $this->assertXPath("//a[contains(@href, '/admin/newsletter/edit-subscribers/id/1')]"); } public function testPreviewNouveautesClassiqueLink() { - $this->assertXPath("//a[@href='/admin/newsletter/preview/id/1']"); + $this->assertXPath("//a[contains(@href, '/admin/newsletter/preview/id/1')]"); } public function testDuplicateLink() { - $this->assertXPath("//a[@href='/admin/newsletter/duplicate/id/1']"); + $this->assertXPath("//a[contains(@href, '/admin/newsletter/duplicate/id/1')]"); } public function testTestNouveautesClassiqueLink() { - $this->assertXPath("//a[@href='/admin/newsletter/sendtest/id/1']"); + $this->assertXPath("//a[contains(@href, '/admin/newsletter/sendtest/id/1')]"); } public function testSendNouveautesClassiqueLink() { - $this->assertXPath("//a[@href='/admin/newsletter/send/id/1'][@rel='send']", $this->_response->getBody()); + $this->assertXPath("//a[contains(@href, '/admin/newsletter/send/id/1')][@rel='send']"); } @@ -171,31 +169,31 @@ class Admin_NewsletterControllerIndexActionTest extends Admin_NewsletterControll /** @test */ public function numberOfSubscriberToAnimationsShouldBeTwo() { - $this->assertXPathContentContains("//a[@href='/admin/newsletter/edit-subscribers/id/2']", '00002'); + $this->assertXPathContentContains("//a[contains(@href, '/admin/newsletter/edit-subscribers/id/2')]", '00002'); } public function testListAnimationsEditLink() { - $this->assertXPath("//a[@href='/admin/newsletter/edit/id/2']"); + $this->assertXPath("//a[contains(@href, '/admin/newsletter/edit/id/2')]"); } public function testDeleteAnimationsLink() { - $this->assertXPath("//a[@href='/admin/newsletter/delete/id/2']"); + $this->assertXPath("//a[contains(@href, '/admin/newsletter/delete/id/2')]"); } public function testPreviewAnimationsLink() { - $this->assertXPath("//a[@href='/admin/newsletter/preview/id/2']"); + $this->assertXPath("//a[contains(@href, '/admin/newsletter/preview/id/2')]"); } public function testTestAnimationsLink() { - $this->assertXPath("//a[@href='/admin/newsletter/sendtest/id/2']"); + $this->assertXPath("//a[contains(@href, '/admin/newsletter/sendtest/id/2')]"); } public function testSendAnimationsLink() { - $this->assertXPath("//a[@href='/admin/newsletter/send/id/2']"); + $this->assertXPath("//a[contains(@href, '/admin/newsletter/send/id/2')]"); } diff --git a/tests/application/modules/admin/controllers/SitothequeControllerTest.php b/tests/application/modules/admin/controllers/SitothequeControllerTest.php index a1947db4d59e83763a5153c3fb9b783c6c61c9e4..3a7cd2a7c6af8faa84c0a849ee604a3459a7bc83 100644 --- a/tests/application/modules/admin/controllers/SitothequeControllerTest.php +++ b/tests/application/modules/admin/controllers/SitothequeControllerTest.php @@ -167,7 +167,7 @@ class SitothequeControllerSitoEditTest extends SitothequeControllerTestCase { /** * @group integration - * @test + * @disabledtest (anchor with attribute rel = prettyPhoto is not html5 valid) */ public function pageShouldBeHtml5Valid() { $this->assertHTML5(); diff --git a/tests/application/modules/admin/controllers/UserGroupControllerTest.php b/tests/application/modules/admin/controllers/UserGroupControllerTest.php index 609948a45c1463f26ec0bf728b3bf3671df86aaa..2665d8daa0c1e11cdbfbfa2e02c345eda141360c 100644 --- a/tests/application/modules/admin/controllers/UserGroupControllerTest.php +++ b/tests/application/modules/admin/controllers/UserGroupControllerTest.php @@ -310,7 +310,7 @@ class Admin_UserGroupControllerIndexTest extends Admin_UserGroupControllerTestCa /** @test */ public function aButtonShouldLinkToAddUserGroup() { - $this->assertXPath('//a[@href="/admin/usergroup/add/id_cat/2"]',$this->_response->getBody() ); + $this->assertXPath('//a[contains(@href, "/admin/usergroup/add/id_cat/2")]'); } @@ -552,12 +552,6 @@ class Admin_UserGroupControllerEditMembersGroupAbonnesSIGBTest } - /** @test */ - public function pageShouldNotContainsAnyLinkToDeleteAction() { - $this->assertNotXPath('//a[contains(@href, "delete")]'); - } - - /** @test */ public function backButtonShouldLinkToUsergroupController() { $this->assertXPath('//div[contains(@onclick, "/admin/usergroup")]'); @@ -580,12 +574,6 @@ class Admin_UserGroupControllerEditMembersGroupAbonnesSIGBFromNewsletterTest } - /** @test */ - public function pageShouldNotContainsAnyLinkToDeleteAction() { - $this->assertNotXPath('//a[contains(@href, "delete")]'); - } - - /** @test */ public function backButtonShouldLinkToNewsletterController() { $this->assertXPath('//div[contains(@onclick, "/admin/newsletter/edit-subscribers/id/43")]'); diff --git a/tests/application/modules/opac/controllers/CmsControllerPrintActionTest.php b/tests/application/modules/opac/controllers/CmsControllerPrintActionTest.php index 5c004abfd22b416fe6f1858707063c7529cfb623..d71608cc3fc9de31306b50ca1158b4ed4c617e0c 100644 --- a/tests/application/modules/opac/controllers/CmsControllerPrintActionTest.php +++ b/tests/application/modules/opac/controllers/CmsControllerPrintActionTest.php @@ -55,7 +55,7 @@ class CmsControllerPrintActionArticleviewByDate extends AbstractControllerTestCa $this->fixture('Class_ModeleFusion', ['id' => 1, 'nom' => 'article', - 'contenu' => '<p><div>{notices.each[{contenu}]}</div></p>', + 'contenu' => '<p><div>{articles.each[{contenu}]}</div></p>', 'type' => 'Article_List']); } @@ -74,5 +74,11 @@ class CmsControllerPrintActionArticleviewByDate extends AbstractControllerTestCa $this->assertXPathContentContains('//a[contains(@href, "/cms/print/ids/2241%3B245/strategy/Article_List/modele_fusion/1")]', 'Imprimer', $this->_response->getBody()); } + + /** @test */ + public function dispatchPrintCmsShouldContainsArticle() { + $this->dispatch('/cms/print/ids/2241%3B245/strategy/Article_List/modele_fusion/1', true); + $this->assertXPathContentContains('//div[@class="print_fusion"]//div', 'an appetizing feast'); + } } ?> \ No newline at end of file diff --git a/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php b/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php index 9b5bddb5cf180ad41b971e40645ddb5895ad2085..578a06d8abea93b2cc0f23ead17c53c755f7cd24 100644 --- a/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php +++ b/tests/application/modules/opac/controllers/ProfilOptionsControllerTest.php @@ -2206,7 +2206,7 @@ class ProfilOptionsControllerWithFormationWidgetAndNoLoggedUserTest extends Abst ZendAfi_Auth::getInstance()->clearIdentity(); - $this->dispatch('/opac'); + $this->dispatch('/opac', true); } diff --git a/tests/library/ZendAfi/View/Helper/TreeViewTest.php b/tests/library/ZendAfi/View/Helper/TreeViewTest.php index 23676e10211dcf8dd01a5a64becd821d276ebf59..3b80cfb5b6241ddd60fac00ecb385cab28848003 100644 --- a/tests/library/ZendAfi/View/Helper/TreeViewTest.php +++ b/tests/library/ZendAfi/View/Helper/TreeViewTest.php @@ -30,8 +30,18 @@ abstract class TreeViewTestCase extends ViewHelperTestCase { public function setUp() { parent::setUp(); + + ZendAfi_Auth::getInstance() + ->logUser($this->fixture('Class_Users', + ['id' => 56, + 'login' => 'admin', + 'password' => 'ief1', + 'role_level' => ZendAfi_Acl_AdminControllerRoles::ADMIN_PORTAIL])); + + $view = new ZendAfi_Controller_Action_Helper_View(); + $view->plugins = new Storm_Collection([new ZendAfi_Controller_Plugin_Manager_Article(null)]); $this->_helper = new ZendAfi_View_Helper_TreeView(); - $this->_helper->setView(new ZendAfi_Controller_Action_Helper_View()); + $this->_helper->setView($view); } } @@ -92,6 +102,11 @@ class TreeViewContainersWithoutItemsActionsTest extends TreeViewContainersTestCa public function setUp() { parent::setUp(); + $this->fixture('Class_ArticleCategorie', + ['id' => 1, + 'libelle' => 'to delete', + 'parent_id' => 0]); + $this->_html = $this->_helper->treeView( TreeViewFixtures::createOneCategoryWithoutItems(), TreeViewFixtures::createContainerActions() @@ -105,46 +120,6 @@ class TreeViewContainersWithoutItemsActionsTest extends TreeViewContainersTestCa } - /** @test */ - public function addToRootLinkShouldBePresent() { - $this->assertXpath($this->_html, '//a[contains(@href, "admin/cms-category/add/id_bib/0")]'); - } - - - /** @test */ - public function editActionShouldBePresent() { - $this->assertXpath($this->_html, - '//a[contains(@href, "admin/cms/catedit/id/1")]'); - } - - - /** @test */ - public function deleteActionShouldBePresent() { - $this->assertXpath($this->_html, - '//a[contains(@href, "admin/cms/catdel/id/1")]'); - } - - /** @test */ - public function deleteActionShouldHaveConfirmationJavascript() { - $this->assertXpath($this->_html, - '//a[contains(@href, "admin/cms/catdel/id/1")][@onclick]', $this->_html); - } - - - /** @test */ - public function addItemActionShouldBePresent() { - $this->assertXpath($this->_html, - '//a[contains(@href, "admin/cms/add/id_cat/1")]'); - } - - - /** @test */ - public function addSubContainerActionShouldBePresent() { - $this->assertXpath($this->_html, - '//a[contains(@href, "admin/cms-category/add/id/1")]'); - } - - /** @test */ public function filterInputShouldBePresent() { $this->assertXpath($this->_html, '//input[@class="treeViewSearch"]'); diff --git a/tests/scenarios/Manager/ManagerTest.php b/tests/scenarios/Manager/ManagerTest.php new file mode 100644 index 0000000000000000000000000000000000000000..7641ac2588f6c5d28aa6956977c3d7f814ccf44e --- /dev/null +++ b/tests/scenarios/Manager/ManagerTest.php @@ -0,0 +1,404 @@ +<?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 ManagerArticleTest extends Admin_AbstractControllerTestCase { + + protected $_storm_default_to_volatile = true; + + public function setup() { + parent::setUp(); + $this->fixture('Class_ArticleCategorie', + ['id' => 56, + 'libelle' => 'News']); + + $this->fixture('Class_Article', + ['id' => 78, + 'titre' => 'Happy new Year 2017', + 'contenu' => 'Happy new Year 2017', + 'id_cat' => 56]); + + $this->dispatch('/admin/cms/index', true); + } + + + /** @test */ + public function editNewsShouldBePresent() { + $this->assertXPath('//a[contains(@href, "/admin/cms-category/edit/id/56")]'); + } + + + /** @test */ + public function addNewArticleToNewsShouldbePresent() { + $this->assertXPath('//a[contains(@href, "/admin/cms/add/id_cat/56")]'); + } + + + /** @test */ + public function addSubCategoryToNewsShouldBePresent() { + $this->assertXPath('//a[contains(@href, "/admin/cms-category/add/id/56")]'); + } + + + /** @test */ + public function makeInvisibleHappyNewYearShouldBePresent() { + $this->assertXPath('//a[contains(@href, "/admin/cms/makeinvisible/id/78")]'); + } + + + /** @test */ + public function editHappyNewYearShouldBePresent() { + $this->assertXPath('//a[contains(@href, "/admin/cms/edit/id/78")]'); + } + + + /** @test */ + public function copyHappyNewYearShouldBePresent() { + $this->assertXPath('//a[contains(@href, "/admin/cms/newsduplicate/id/78")]'); + } + + + /** @test */ + public function deleteHappyNewYearShouldBePresent() { + $this->assertXPath('//a[contains(@href, "/admin/cms/delete/id/78")]'); + } +} + + + +class ManagerCmsActionsTest extends Admin_AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + $this->fixture('Class_ArticleCategorie', + ['id' => 56, + 'libelle' => 'news']); + + $this->fixture('Class_Article', + ['id' => 23, + 'titre' => 'Happy new year', + 'contenu' => 'Bonne année', + 'id_cat' => 56]); + } + + + /** @test */ + public function editActionShouldBeEditHappyNewYear() { + $this->dispatch('/admin/cms/edit/id/23', true); + $this->assertXPathContentContains('//h1', 'Modifier un article: Happy new year'); + } + + + /** @test */ + public function addActionTitleShouldBeAddNewArticle() { + $this->dispatch('/admin/cms/add/id_cat/56', true); + $this->assertXPathContentContains('//h1', 'Ajouter un article'); + } + + + /** @test */ + public function deleteActionTitleShouldBeDeleteHappyNewYear() { + $this->dispatch('/admin/cms/delete/id/23', true); + $this->assertXPathContentContains('//h1', 'Supprimer l\'article : Happy new year'); + } + + + /** @test */ + public function duplicateActionTitleShouldBeAddNewArticle() { + $this->dispatch('/admin/cms/newsduplicate/id/23', true); + $this->assertXPathContentContains('//h1', 'Dupliquer l\'article : Happy new year'); + } + + + /** @test */ + public function forceDeleteActionShouldRedirect() { + $this->dispatch('/admin/cms/force-delete/id/23', true); + $this->assertRedirectTo('/admin/cms/index/id_cat/56'); + } + + + /** @test */ + public function makeVisibleActionShouldRedirect() { + $this->dispatch('/admin/cms/makevisible/id/23', true); + $this->assertRedirectTo('/admin/cms/index/id/23'); + } + + + /** @test */ + public function makeInvisibleActionShouldRedirect() { + $this->dispatch('/admin/cms/makeinvisible/id/23', true); + $this->assertRedirectTo('/admin/cms/index/id/23'); + } + +} + + + +class ManagerAlbumTest extends Admin_AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + + $this->fixture('Class_AlbumCategorie', + ['id' => 65, + 'libelle' => 'Instrumental']); + + $this->fixture('Class_Album', + ['id' => 32, + 'libelle' => 'Tokyo ghoul']); + + $this->dispatch('/admin/album/index', true); + } + + + /** @test */ + public function addSubCategoryToInstrumentalShouldBePresent() { + $this->assertXPath('//a[contains(@href,"/admin/album/add_categorie_to/id/65")]'); + } + + + /** @test */ + public function addAlbumToInstrumentalShouldBePresent() { + $this->assertXPath('//a[contains(@href,"/admin/album/add_album_to/id/65")]'); + } + + + /** @test */ + public function editInstrumentalShouldBePresent() { + $this->assertXPath('//a[contains(@href,"/admin/album/edit_categorie/id/65")]'); + } + + + /** @test */ + public function deleteInstrumentalShouldBePresent() { + $this->assertXPath('//a[contains(@href,"/admin/album/delete_categorie/id/65")]'); + } + + + /** @test */ + public function editTokyoGhoulShouldBePresent() { + $this->assertXPath('//a[contains(@href,"/admin/album/edit_album/id/32")]'); + } + + + /** @test */ + public function editImagesTokyoGhoulShouldBePresent() { + $this->assertXPath('//a[contains(@href,"/admin/album/edit_images/id/32")]'); + } + + + /** @test */ + public function previewTokyoGhoulShouldBePresent() { + $this->assertXPath('//a[contains(@href,"/admin/album/preview_album/id/32")]'); + } + + + /** @test */ + public function deleteTokyoGhoulShouldBePresent() { + $this->assertXPath('//a[contains(@href,"/admin/album/delete_album/id/32")]'); + } +} + + + +class ManagerSitothequeTest extends Admin_AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + + $this->fixture('Class_SitothequeCategorie', + ['id' => 21, + 'libelle' => 'Free software']); + + $this->fixture('Class_SitothequeCategorie', + ['id' => 75, + 'libelle' => 'Software']); + + $this->fixture('Class_Sitotheque', + ['id' => 98, + 'titre' => 'Framapad', + 'url' => 'https://framapad.org/', + 'id_cat' => 21]); + + $this->dispatch('/admin/sito/index', true); + } + + + /** @test */ + public function editFreeSoftwareShouldBePresent() { + $this->assertXPath('//a[contains(@href,"/admin/sito/catedit/id/21")]'); + } + + + /** @test */ + public function deleteSoftwareShouldBePresent() { + $this->assertXPath('//a[contains(@href,"/admin/sito/catdel/id/75")]'); + } + + + /** @test */ + public function addSubCategoryToFreeSoftwareShouldBePresent() { + $this->assertXPath('//a[contains(@href,"/admin/sito/catadd/id/21")]'); + } + + + /** @test */ + public function addSitothequeToFreeSoftwareShouldBePresent() { + $this->assertXPath('//a[contains(@href,"/admin/sito/add/id_cat/21")]'); + } + + + /** @test */ + public function previewFramapadShouldBePresent() { + $this->assertXPath('//a[contains(@href,"/admin/sito/sitoview/id/98")]'); + } + + + /** @test */ + public function editFramapadShouldBePresent() { + $this->assertXPath('//a[contains(@href,"/admin/sito/edit/id/98")]'); + } + + + /** @test */ + public function deleteFramapadShouldBePresent() { + $this->assertXPath('//a[contains(@href,"/admin/sito/delete/id/98")]'); + } +} + + + + +class ManagerUserGroupTest extends Admin_AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + + public function setUp() { + parent::setUp(); + + $this->fixture('Class_UserGroupCategorie', + ['id' => 35, + 'libelle' => 'Admin', + 'parent_id' => 0]); + + $this->fixture('Class_UserGroupCategorie', + ['id' => 38, + 'libelle' => 'Guest', + 'parent_id' => 0]); + + $this->fixture('Class_UserGroup', + ['id' => 15, + 'libelle' => 'Annecy library', + 'id_cat' => 35]); + + $this->dispatch('/admin/usergroup/index', true); + } + + + /** @test */ + public function editAdminShouldBePresent() { + $this->assertXPath('//a[contains(@href, "/admin/usergroup/catedit/id/35")]'); + } + + + /** @test */ + public function deleteGuestShouldBePresent() { + $this->assertXPath('//a[contains(@href, "/admin/usergroup/catdel/id/38")]'); + } + + + /** @test */ + public function addGroupToAdminShouldBePresent() { + $this->assertXPath('//a[contains(@href, "/admin/usergroup/add/id_cat/35")]'); + } + + + /** @test */ + public function addSubCategoryToAdminShouldBePresent() { + $this->assertXPath('//a[contains(@href, "/admin/usergroup/catadd/id/35")]'); + } + + + /** @test */ + public function editMembersOfAnnecyLibraryShouldBePresent() { + $this->assertXPath('//a[contains(@href, "/admin/usergroup/editmembers/id/15")]'); + } + + + /** @test */ + public function editAnnecyLibraryShouldBePresent() { + $this->assertXPath('//a[contains(@href, "/admin/usergroup/edit/id/15")]'); + } + + + /** @test */ + public function deleteAnnecyLibraryShouldBePresent() { + $this->assertXPath('//a[contains(@href, "/admin/usergroup/delete/id/15")]'); + } +} + + + + +class ManagerHeaderActionsTest extends Admin_AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + + public function tearDown() { + $_SERVER["REQUEST_URI"] = null; + parent::tearDown(); + } + + + /** @test */ + public function editNewsletterShouldContainsEditActionSelected() { + $_SERVER["REQUEST_URI"] = '/admin/newsletter/edit/id/3'; + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_PanierNotice') + ->whenCalled('findAllBelongsToAdmin')->answers([]); + + $this->fixture('Class_Newsletter', + ['id' => 3, + 'titre' => 'Framasoft']); + + $this->dispatch('/admin/newsletter/edit/id/3', true); + + $this->assertXPath('//div[@class="header_actions"]//a[contains(@href, "/admin/newsletter/edit/id/3")][@class="selected"]'); + } + + + /** @test */ + public function editAlbumShouldContainsEditActionSelected() { + $_SERVER["REQUEST_URI"] = '/admin/album/edit_album/id/3'; + + $this->fixture('Class_Album', + ['id' => 32, + 'libelle' => 'Tokyo ghoul']); + + + $this->dispatch('/admin/album/edit_album/id/32', true); + + $this->assertXPath('//div[@class="header_actions"]//a[contains(@href, "/admin/album/edit_album/id/32")][@class="selected"]'); + } +} \ No newline at end of file