Skip to content
Snippets Groups Projects
Commit 5390f8cf authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

dev #59717 : handling albums configuration

parent b64a2379
Branches
Tags
3 merge requests!2334Master,!2191Dev#59717 versionning des configurations de boites,!2185Dev#59717 versionning des configurations de boites
Pipeline #1329 passed with stage
in 12 minutes and 18 seconds
Showing
with 331 additions and 277 deletions
<?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_Form_Configuration_BibNumerique extends ZendAfi_Form {
public static function newWith($conf) {
$form = new self();
$selected_categories = array_key_exists('id_categorie', $conf) ? $conf['id_categorie'] : '';
$form
->populate($conf)
->populateAlbumsCategories('id_categorie', $selected_categories)
->populateImageViewer('style_liste', $conf)
->addDisplayGroup(['titre',
'boite'],
'base',
['legend' => $form->_('Général')])
->addDisplayGroup(['type_aff',
'id_categories',
'id_albums',
'style_liste',
'nb_aff',
'id_categorie',
'display_order',
'nb_aff_by_page'],
'display',
['legend' => $form->_('Affichage')])
->addDisplayGroup(['submit'],
'submit',
['legend' => '']);
return $form;
}
public function init() {
parent::init();
Class_ScriptLoader::getInstance()->addJQueryReady($this->_getChangeDisplayScript());
$module = (new Class_Systeme_ModulesAccueil())->getModuleByCode('BIB_NUMERIQUE');
$this
->setAttrib('id', 'configuration_bibnumerique')
->addElement('text',
'titre',
['label' => $this->_('Titre de la boite'),
'size' => '52'])
->addElement('select',
'boite',
['label' => $this->_('Style de boite'),
'multiOptions' => (
new Class_Profil_Templates(
Class_Profil::getCurrentProfil()))->toArray()])
->addElement('select',
'type_aff',
['label' => $this->_('Type d\'affichage'),
'multiOptions' => $module->getDisplayModes()])
->addElement('select',
'id_categories',
['label' => $this->_('Collection'),
'multiOptions' => $this->_getCollections()])
->addElement('select',
'id_albums',
['label' => $this->_('Album'),
'multiOptions' => $this->_getAlbums()])
->addElement('imagesViewer',
'style_liste',
['label' => $this->_('Style de représentation'),
'preferences' => ''])
->addElement('text',
'nb_aff',
['label' => $this->_('Nb d\'images à afficher'),
'size' => '4'])
->addElement('albumsCategoriesSelector',
'id_categorie',
['label' => $this->_('Choisissez les dossiers à afficher'),
'selected_categories' => ''])
->addElement('radio',
'display_order',
['label' => $this->_('Ordre d\'affichage'),
'multiOptions' => $module->getOrderModes()])
->addElement('text',
'nb_aff_by_page',
['label' => $this->_('Nbre de sites par page'),
'size' => '3',
'maxlenght' => '3'])
->addElement('submit',
'submit',
['label' => $this->_('Valider'),
'class' => 'bouton']);
}
public function populateAlbumsCategories($element, $selected_categories) {
$this->$element->setSelectedCategories($selected_categories);
return $this;
}
public function populateImageViewer($element, $preferences) {
$this->$element->setPreferences($preferences);
return $this;
}
protected function _getChangeDisplayScript() {
return
"$('select[name=\"type_aff\"]').change(function (event) {
if ($('select[name=\"type_aff\"]').val() == 'displayTree')
displayOnly($('#id_categories'));
if ($('select[name=\"type_aff\"]').val() == 'displayAlbumTeaser')
displayOnly($('#id_albums, #nb_aff, [name=\"style_liste\"]'));
if ($('select[name=\"type_aff\"]').val() == 'displayPaginated')
displayOnly($('#id_categorie, [name=\"display_order\"], #nb_aff_by_page'));
});
function displayOnly(selector) {
$('#fieldset-display tr').not(':first').hide();
selector.closest('tr').show();
}
$('select[name=\"type_aff\"]').change();";
}
protected function _getCollections() {
$collections = ['' => 'Toutes les collections'];
foreach (Class_AlbumCategorie::getLoader()->getCollections() as $categorie)
$collections[$categorie->getId()] = $categorie->getLibelle();
return $collections;
}
protected function _getAlbums() {
$albums = [];
foreach (Class_AlbumCategorie::getLoader()->findAlbumsRecursively() as $album) {
$hierarchy = array_reverse($album->getHierarchy());
$parents = [];
foreach ($hierarchy as $parent)
$parents[] = $parent->getLibelle();
$albums[$album->getId()] = implode(' > ', $parents) . ' > ' . $album->getTitre();
}
return $albums;
}
}
?>
\ No newline at end of file
<?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_Form_Configuration_DiaporamaImagesViewer extends ZendAfi_Form {
public function init() {
parent::init();
$this->addElement('select',
'op_transition',
['label' => $this->_('Effet de transition'),
'multiOptions' => ZendAfi_View_Helper_TagSlideshow::getTransitionDefinitions()])
->addElement('text',
'op_hauteur_boite',
['label' => $this->_('Hauteur de la boite en pixel')])
->addElement('text',
'op_largeur_img',
['label' => $this->_('Largeur de la boite en pixel')])
->addElement('text',
'op_timeout',
['label' => $this->_('Délai de transition pour le passage à une autre image en secondes')]);
}
}
<?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_Form_Configuration_DiaporamaNavigationImagesViewer extends ZendAfi_Form {
public function init() {
parent::init();
$this
->addElement('select',
'op_navigation_mode',
['label' => $this->_('Mode de navigation'),
'multiOptions' => ['buttons' => $this->_('Un bouton pour chaque élément'),
'next_previous' => $this->_('Boutons précédent et suivant'),
'preview' => $this->_('Une miniature pour chaque élément')]])
->addElement('select',
'op_navigation_unit',
['label' => $this->_('Unité utilisée pour la largeur du widget'),
'multiOptions' => ['px' => $this->_('Pixels'),
'%' => $this->_('Pourcentages')]])
->addElement('text',
'op_navigation_window_width',
['label' => $this->_('Largeur du widget')])
->addElement('text',
'op_navigation_window_height',
['label' => $this->_('Hauteur du widget en pixels')])
->addElement('text',
'op_navigation_cycle',
['label' => $this->_('Délai de défilement en millisecondes'),
'placeholder' => $this->_('0 pour désactiver')])
;
}
}
......@@ -24,9 +24,12 @@ class ZendAfi_Form_Configuration_Widget_Albums extends ZendAfi_Form_Configuratio
public function init() {
parent::init();
Class_ScriptLoader::getInstance()->addJQueryReady($this->_getChangeDisplayScript());
Class_ScriptLoader::getInstance()
->addJQueryReady($this->_getChangeDisplayScript())
->addJQueryReady($this->_getSelectTogglers());
$module = (new Class_Systeme_ModulesAccueil())->getModuleByCode('BIB_NUMERIQUE');
$module = (new Class_Systeme_ModulesAccueil())
->getModuleByCode('BIB_NUMERIQUE');
$this
->setAttrib('id', 'configuration_bibnumerique')
......@@ -68,40 +71,48 @@ class ZendAfi_Form_Configuration_Widget_Albums extends ZendAfi_Form_Configuratio
->addElement('text',
'nb_aff_by_page',
['label' => $this->_('Nbre de sites par page'),
['label' => $this->_('Nbre par page'),
'size' => '3',
'maxlenght' => '3']);
}
public function populate($datas) {
$selected_categories = array_key_exists('id_categorie', $datas) ? $datas['id_categorie'] : '';
$this
->populateAlbumsCategories('id_categorie', $selected_categories)
->populateImageViewer('style_liste', $datas)
'maxlenght' => '3'])
->addToDisplaySettingsGroup(['type_aff',
'id_categories',
'id_albums',
'style_liste',
'nb_aff',
'id_categorie',
'display_order',
'nb_aff_by_page']);
}
protected function _getSelectTogglers() {
return 'formSelectToggleVisibilityForElement("#type_aff", $("#id_albums, #nb_aff").closest("tr"), ["displayAlbumTeaser"]);
formSelectToggleVisibilityForElement("#type_aff", $("#id_categories").closest("tr"), ["displayTree"]);
formSelectToggleVisibilityForElement("#type_aff", $("#id_categorie, #nb_aff_by_page, [name=display_order]").closest("tr"), ["displayPaginated"]);';
}
public function populate($datas) {
$selected_categories = array_key_exists('id_categorie', $datas)
? $datas['id_categorie']
: '';
$this
->populateAlbumsCategories('id_categorie', $selected_categories)
->populateImageViewer('style_liste', $datas);
return parent::populate($datas);
}
public function populateAlbumsCategories($element, $selected_categories) {
$this->$element->setSelectedCategories($selected_categories);
$this->getElement($element)->setSelectedCategories($selected_categories);
return $this;
}
public function populateImageViewer($element, $preferences) {
$this->$element->setPreferences($preferences);
$this->getElement($element)->setPreferences($preferences);
return $this;
}
......@@ -129,9 +140,9 @@ class ZendAfi_Form_Configuration_Widget_Albums extends ZendAfi_Form_Configuratio
protected function _getCollections() {
$collections = ['' => 'Toutes les collections'];
$collections = ['' => $this->_('Toutes les collections')];
foreach (Class_AlbumCategorie::getLoader()->getCollections() as $categorie)
foreach (Class_AlbumCategorie::getCollections() as $categorie)
$collections[$categorie->getId()] = $categorie->getLibelle();
return $collections;
......@@ -141,14 +152,20 @@ class ZendAfi_Form_Configuration_Widget_Albums extends ZendAfi_Form_Configuratio
protected function _getAlbums() {
$albums = [];
foreach (Class_AlbumCategorie::getLoader()->findAlbumsRecursively() as $album) {
$hierarchy = array_reverse($album->getHierarchy());
$parents = [];
foreach ($hierarchy as $parent)
$parents[] = $parent->getLibelle();
$albums[$album->getId()] = implode(' > ', $parents) . ' > ' . $album->getTitre();
}
foreach (Class_AlbumCategorie::findAlbumsRecursively() as $album)
$albums[$album->getId()] = $this->_getAlbum($album);
return $albums;
}
}
\ No newline at end of file
protected function _getAlbum($album) {
$hierarchy = array_reverse($album->getHierarchy());
$parents = [];
foreach ($hierarchy as $parent)
$parents[] = $parent->getLibelle();
return implode(' > ', $parents) . ' > ' . $album->getTitre();
}
}
......@@ -35,4 +35,3 @@ class ZendAfi_Form_Decorator_AlbumsCategoriesSelector extends Zend_Form_Decorato
'form');
}
}
?>
\ No newline at end of file
<?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_Form_Decorator_VersionCompare_AlbumsCategoriesSelector
extends ZendAfi_Form_Decorator_VersionCompare_TreeSelect {
protected $_current_separator = '-';
protected function _find($id) {
return Class_AlbumCategorie::find($id);
}
protected function _labelOf($model) {
return implode(' > ', $model->getPathParts());
}
}
<?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_Form_Decorator_VersionCompare_ImagesViewer
extends ZendAfi_Form_Decorator_VersionCompare {
protected $_multi_options = [];
public function render($content) {
$this->_multi_options = (new ZendAfi_View_Helper_Admin_ImageViewersOptions)
->getMultiOptions();
return parent::render($content);
}
protected function _renderCurrentValue() {
return $this->_renderComposite($this->_element->getValue(),
$this->_element->getPreferences());
}
protected function _renderVersionValue() {
$datas = $this->getOption('datas');
return $this->_renderComposite($this->_typeOrNone(),
$datas);
}
protected function _renderComposite($type, $options) {
return $this
->_renderValue($this->_renderStyleValue($type)
. $this->_renderOptionsValue($this->_loadForm($type),
$options));
}
protected function _renderStyleValue($value) {
$options = $this->_multi_options;
return array_key_exists($value, $options)
? $options[$value]
: $this->_('Non renseigné');
}
protected function _renderOptionsValue($form, $options) {
if (!$form)
return '';
$form->populate($options);
$values = '';
foreach($form->getElements() as $element)
$values .= $this->_tag('li', $element->getLabel() . ' : ' . $element->getValue());
return $this->_tag('ul', $values);
}
protected function _loadForm($type) {
$map =
[
'diaporama' => 'ZendAfi_Form_Configuration_DiaporamaImagesViewer',
'diaporama_navigation' => 'ZendAfi_Form_Configuration_DiaporamaNavigationImagesViewer'
];
return array_key_exists($type, $map) ? new $map[$type] : null;
}
protected function _isModified() {
if (($current = $this->_element->getValue()) != ($version = $this->_typeOrNone()))
return true;
if (!$form = $this->_loadForm($current))
return false; // same type without options
foreach(array_keys($form->getValues()) as $k)
if ($this->_isOptionModified($k))
return true;
return false;
}
protected function _isOptionModified($name) {
if (!array_key_exists($name, $this->_element->getPreferences())
&& !array_key_exists($name, $this->getOption('datas')))
return false; // in neither side
if (!array_key_exists($name, $this->_element->getPreferences())
|| !array_key_exists($name, $this->getOption('datas')))
return true; // in only one side
return $this->_element->getPreferences()[$name] != $this->getOption('datas')[$name];
}
protected function _typeOrNone() {
$datas = $this->getOption('datas');
return array_key_exists($this->_element->getName(), $datas)
? $datas[$this->_element->getName()]
: 'none';
}
}
......@@ -32,8 +32,8 @@ class ZendAfi_Form_Element_AlbumsCategoriesSelector extends Zend_Form_Element {
foreach ($decorators as $name => $value)
$this->_decorators[$name] = $value;
$this->removeDecorator('ViewHelper');
$this->removeDecorator('ViewHelper');
}
......
......@@ -106,7 +106,7 @@ class ZendAfi_View_Helper_Accueil_BibNumerique extends ZendAfi_View_Helper_Accue
if (isset($this->_slideshow))
return $this->_slideshow;
$album = Class_Album::getLoader()->find((int)$this->preferences['id_albums']);
$album = Class_Album::find((int)$this->preferences['id_albums']);
$this->_slideshow = $this->view->getHelper('TagSlideshow')
->setAlbum($album)
->setPreferences($this->preferences);
......
......@@ -21,7 +21,9 @@
class ZendAfi_View_Helper_Admin_ImageViewersOptions extends ZendAfi_View_Helper_BaseHelper {
class ZendAfi_View_Helper_Admin_ImageViewersOptions
extends ZendAfi_View_Helper_BaseHelper {
const STYLE_TYPE_JAVA = 'java';
const STYLE_TYPE_FLASH= 'flash';
......@@ -30,10 +32,17 @@ class ZendAfi_View_Helper_Admin_ImageViewersOptions extends ZendAfi_View_Helper_
$_preferences,
$_propertiesPath,
$_valuesPath,
$_styles = [self::STYLE_TYPE_JAVA => ['diaporama' => 'Diaporama',
'accordion_list' => 'Liste en accordéon',
'diaporama_navigation' => 'Diaporama avec navigation',
'booklet' => 'Livre']];
$_styles = [];
public function init() {
parent::init();
$this->_styles = [static::STYLE_TYPE_JAVA =>
['diaporama' => $this->_('Diaporama'),
'accordion_list' => $this->_('Liste en accordéon'),
'diaporama_navigation' => $this->_('Diaporama avec navigation'),
'booklet' => $this->_('Livre')]];
}
public function imageViewersOptions($preferences) {
......@@ -42,6 +51,7 @@ class ZendAfi_View_Helper_Admin_ImageViewersOptions extends ZendAfi_View_Helper_
$this->_preferences = $preferences;
$html = $this->_getComboStyles();
$this->_ensureOneStyle();
$html.= (isset($preferences['style_liste'])
? (new ZendAfi_View_Helper_Admin_PropertiesReader())
->setView($this->view)
......@@ -49,7 +59,6 @@ class ZendAfi_View_Helper_Admin_ImageViewersOptions extends ZendAfi_View_Helper_
$preferences)
: '');
return $html;
}
......@@ -62,16 +71,22 @@ class ZendAfi_View_Helper_Admin_ImageViewersOptions extends ZendAfi_View_Helper_
->addJQueryReady($submit_script);
return '<select name="style_liste">'
. '<option value="none">Liste</option>'
. '<option value="none">'. $this->_('Liste') . '</option>'
. $this->_getComboTypedStyles(self::STYLE_TYPE_JAVA,
$this->translate()->_('Objets java-script'))
$this->_('Objets java-script'))
. $this->_getComboTypedStyles(self::STYLE_TYPE_FLASH,
$this->translate()->_('Objets flash'))
$this->_('Objets flash'))
. '</select>'
. '<input type="hidden" id="styles_reload" name="styles_reload" value="0">';
}
public function getMultiOptions() {
return array_merge(['none' => $this->_('Liste')],
$this->_styles[static::STYLE_TYPE_JAVA]);
}
/**
* @param string $styleKey
* @param string $groupLabel
......
<?php
$form = new ZendAfi_Form();
$form = new ZendAfi_Form_Configuration_DiaporamaImagesViewer();
$form->removeDecorator('form');
$form
->addElement('select',
'op_transition',
['label' => $this->_('Effet de transition'),
'multiOptions' => ZendAfi_View_Helper_TagSlideshow::getTransitionDefinitions()])
->addElement('text',
'op_hauteur_boite',
['label' => $this->_('Hauteur de la boite en pixel')])
->addElement('text',
'op_largeur_img',
['label' => $this->_('Largeur de la boite en pixel')])
->addElement('text',
'op_timeout',
['label' => $this->_('Délai de transition pour le passage à une autre image en secondes')])
->populate($this->preferences);
$form->populate($this->preferences);
echo $form;
?>
<?php
$form = new ZendAfi_Form();
$form = new ZendAfi_Form_Configuration_DiaporamaNavigationImagesViewer();
$form->removeDecorator('form');
$form
->addElement('select',
'op_navigation_mode',
['label' => $this->_('Mode de navigation'),
'value' => $this->preferences['op_navigation_mode'],
'multiOptions' => ['buttons' => $this->_('Un bouton pour chaque élément'),
'next_previous' => $this->_('Boutons précédent et suivant'),
'preview' => $this->_('Une miniature pour chaque élément')]])
->addElement('select',
'op_navigation_unit',
['label' => $this->_('Unité utilisée pour la largeur du widget'),
'value' => $this->preferences['op_navigation_unit'],
'multiOptions' => ['px' => $this->_('Pixels'),
'%' => $this->_('Pourcentages')]])
->addElement('text',
'op_navigation_window_width',
['label' => $this->_('Largeur du widget'),
'value' => $this->preferences['op_navigation_window_width']])
->addElement('text',
'op_navigation_window_height',
['label' => $this->_('Hauteur du widget en pixels'),
'value' => $this->preferences['op_navigation_window_height']])
->addElement('text',
'op_navigation_cycle',
['label' => $this->_('Délai de défilement en millisecondes'),
'value' => $this->preferences['op_navigation_cycle'],
'placeholder' => $this->_('0 pour désactiver')]);
$form->populate($this->preferences);
echo $form;
?>
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment