Intégration module nav dans core

This commit is contained in:
Fred Tempez 2023-08-30 20:02:23 +02:00
parent 4d0af131cb
commit 1d8836f230
10 changed files with 134 additions and 206 deletions

View File

@ -88,13 +88,19 @@ class layout extends common
(sizeof($blocks) === 1 ||
in_array($this->getUrl(1), $pattern))
) { // Pleine page en mode configuration
if ($this->getData(['page', $this->getUrl(0), 'navLeft']) === 'top' || $this->getData(['page', $this->getUrl(0), 'navRight']) === 'top') {
$this->showNavButtons('top');
}
$this->showContent();
if ($this->getData(['page', $this->getUrl(0), 'navLeft']) === 'bottom' || $this->getData(['page', $this->getUrl(0), 'navRight']) === 'bottom') {
$this->showNavButtons('bottom');
}
} else {
echo '<div class="row siteContainer">';
/**
* Barre gauche
*/
if ($blockleft !== "") {
if ($blockleft !== '') {
echo '<div class="' . $blockleft . '" id="contentLeft"><aside>';
// Détermine si le menu est présent
if ($this->getData(['page', $this->getData(['page', $this->getUrl(0), 'barLeft']), 'displayMenu']) === 'none') {
@ -117,12 +123,14 @@ class layout extends common
* Contenu de page
*/
echo '<div class="' . $content . '" id="contentSite">';
$this->showNavButtons('top');
$this->showContent();
$this->showNavButtons('bottom');
echo '</div>';
/**
* Barre droite
*/
if ($blockright !== "") {
if ($blockright !== '') {
echo '<div class="' . $blockright . '" id="contentRight"><aside>';
// Détermine si le menu est présent
if ($this->getData(['page', $this->getData(['page', $this->getUrl(0), 'barRight']), 'displayMenu']) === 'none') {
@ -1237,4 +1245,66 @@ class layout extends common
$items .= '</li>';
return $items;
}
// Affiche une icône de navigation
// @param $position string 'top' or 'bottom
public function showNavButtons($position)
{
// Boutons par défaut
$leftButton = 'left';
$rightButton = 'right-dir';
// Déterminer la hiérarchie des pages
$hierarchy = array();
foreach ($this->getHierarchy() as $parentKey => $parentValue) {
$hierarchy[] = $parentKey;
foreach ($parentValue as $childKey) {
$hierarchy[] = $childKey;
}
}
// Parcourir la hiérarchie et rechercher les éléments avant et après
$elementToFind = $this->getUrl(0);
// Trouver la clé de l'élément recherché
$key = array_search($elementToFind, $hierarchy);
if ($key !== false) {
// Trouver l'élément précédent
$previousKey = ($key > 0) ? $key - 1 : null;
$previousValue = ($previousKey !== null) ? $hierarchy[$previousKey] : null;
// Trouver l'élément suivant
$nextKey = ($key < count($hierarchy) - 1) ? $key + 1 : null;
$nextValue = ($nextKey !== null) ? $hierarchy[$nextKey] : null;
$previousPage = $previousValue;
$nextPage = $nextValue;
}
// Jeux d'icônes sinon celui par défaut
if ($this->getData(['page', $this->getUrl(0), 'navTemplate'])) {
$leftButton = self::$navIconTemplate[$this->getData(['page', $this->getUrl(0), 'navTemplate'])]['left'];
$rightButton = self::$navIconTemplate[$this->getData(['page', $this->getUrl(0), 'navTemplate'])]['right'];
}
$items = '<div class="navButton">';
$items .= '<div class="row">';
$items .= '<div class="col1">';
if ($previousPage !== null and $this->getData(['page', $this->getUrl(0), 'navLeft']) === $position) {
$items .= template::button('navPreviousButtonLeft', [
'href' => helper::baseUrl() . $previousPage,
'value' => template::ico($leftButton)
]);
}
$items .= '</div>';
$items .= '<div class="col1 offset10">';
if ($nextPage !== null and $this->getData(['page', $this->getUrl(0), 'navRight']) === $position) {
$items .= template::button('navNextButtonRight', [
'href' => helper::baseUrl() . $nextPage,
'value' => template::ico($rightButton)
]);
}
$items .= '</div></div></div>';
echo $items;
}
}

View File

@ -298,6 +298,21 @@ class common
]
];
// Boutons de navigation dans la page
public static $navIconTemplate = [
'open' => [
'left' => 'left-open',
'right' => 'right-open',
],
'dir' => [
'left' => 'left',
'right' => 'right-dir',
],
'big' => [
'left' => 'left-big',
'right' => 'right-big',
],
];
/**
* Constructeur commun

View File

@ -67,6 +67,18 @@ class page extends common
public static $userProfils = [];
public static $navIconTemplate = [
'dir' => 'Triangle',
'open' => 'Triangle ouvert',
'big' => 'Flèche',
];
public static $navIconPosition = [
'none' => 'Masqué',
'top' => 'Haut de page',
'bottom' => 'Bas de page',
];
/**
* Duplication
@ -150,6 +162,9 @@ class page extends common
'block' => '12',
'barLeft' => '',
'barRight' => '',
'navLeft' => 'none',
'navRight' => 'none',
'navTemplate' => 'dir',
'displayMenu' => '0',
'hideMenuSide' => false,
'hideMenuHead' => false,
@ -479,6 +494,9 @@ class page extends common
'block' => $this->getinput('pageEditBlock'),
'barLeft' => $barLeft,
'barRight' => $barRight,
'navLeft' => $this->getInput('pageEditNavLeft'),
'navRight' => $this->getInput('pageEditNavRight'),
'navTemplate' => $this->getInput('pageEditNavTemplate'),
'displayMenu' => $this->getinput('pageEditDisplayMenu'),
'hideMenuSide' => $this->getinput('pageEditHideMenuSide', helper::FILTER_BOOLEAN),
'hideMenuHead' => $this->getinput('pageEditHideMenuHead', helper::FILTER_BOOLEAN),

View File

@ -193,6 +193,7 @@ $( document ).ready(function() {
$("#pageEditSeoWrapper").slideUp();
$("#pageEditAdvancedWrapper").removeClass("disabled");
$("#pageEditAdvancedWrapper").slideUp();
$(".navSelect").slideUp();
/*
$("#pageEditBlockLayout").removeClass("col6");
$("#pageEditBlockLayout").addClass("col12");
@ -509,6 +510,7 @@ pageEditBlockDOM.on("change", function() {
$("#pageEditModuleConfig").slideUp();
$("#pageEditDisplayMenuWrapper").addClass("disabled");
$("#pageEditDisplayMenuWrapper").slideDown();
$(".navSelect").slideUp();
/*
$("#pageEditBlockLayout").removeClass("col6");
$("#pageEditBlockLayout").addClass("col12");
@ -529,6 +531,7 @@ pageEditBlockDOM.on("change", function() {
$("#pageEditModuleConfig").slideDown();
$("#pageEditDisplayMenuWrapper").removeClass("disabled");
$("#pageEditDisplayMenuWrapper").slideUp();
$(".navSelect").slideDown();
if ($("#pageEditParentPageId").val() !== "") {
$("#pageEditbreadCrumbWrapper").addClass("disabled");
$("#pageEditbreadCrumbWrapper").slideDown();

View File

@ -9,12 +9,12 @@
</div>
<div class="col1">
<?php /**echo template::button('pageEditHelp', [
'href' => 'https://doc.zwiicms.fr/edition-des-pages',
'target' => '_blank',
'value' => template::ico('help'),
'class' => 'buttonHelp',
'help' => 'Consulter l\'aide en ligne'
]); */?>
'href' => 'https://doc.zwiicms.fr/edition-des-pages',
'target' => '_blank',
'value' => template::ico('help'),
'class' => 'buttonHelp',
'help' => 'Consulter l\'aide en ligne'
]); */?>
</div>
<div class="col1 offset6">
<?php echo template::button('pageEditDelete', [
@ -340,6 +340,26 @@
]); ?>
</div>
</div>
<div class="row navSelect">
<div class="col4">
<?php echo template::select('pageEditNavLeft', $module::$navIconPosition, [
'label' => 'Bouton de navigation gauche',
'selected' => $this->getData(['page', $this->getUrl(2), 'navLeft']),
]); ?>
</div>
<div class="col4">
<?php echo template::select('pageEditNavTemplate', $module::$navIconTemplate, [
'label' => 'Modèle',
'selected' => $this->getData(['page', $this->getUrl(2), 'navTemplate']),
]); ?>
</div>
<div class="col4">
<?php echo template::select('pageEditNavRight', $module::$navIconPosition, [
'label' => 'Bouton de navigation droit',
'selected' => $this->getData(['page', $this->getUrl(2), 'navRight']),
]); ?>
</div>
</div>
</div>
</div>
</div>

View File

@ -1 +0,0 @@
{"name":"nav","realName":"Navigation","version":"0.1","update":"0.0","delete":true,"dataDirectory":""}

View File

@ -1,128 +0,0 @@
<?php
/**
* This file is part of Zwii.
* For full copyright and license information, please see the LICENSE
* file that was distributed with this source code.
*
* @author Rémi Jean <remi.jean@outlook.com>
* @copyright Copyright (C) 2008-2018, Rémi Jean
* @author Frédéric Tempez <frederic.tempez@outlook.com>
* @copyright Copyright (C) 2018-2023, Frédéric Tempez
* @license CC Attribution-NonCommercial-NoDerivatives 4.0 International
* @link http://zwiicms.fr/
*/
class nav extends common
{
const VERSION = '0.1';
const REALNAME = 'Navigation';
public static $actions = [
'index' => self::GROUP_VISITOR,
'config' => self::GROUP_EDITOR,
];
public static $previousPage = '';
public static $nextPage = '';
public static $iconTemplate = [
'open' => [
'left' => 'left-open',
'right' => 'right-open',
],
'dir' => [
'left' => 'left',
'right' => 'right-dir',
],
'big' => [
'left' => 'left-big',
'right' => 'right-big',
],
];
public static $iconTemplateName = [
'dir' => 'Triangle',
'open' => 'Ouverte',
'big' => 'Flèche',
];
public static $leftButton = 'left';
public static $rightButton = 'right-dir';
public function index()
{
$hierarchy = array();
foreach ($this->getHierarchy() as $parentKey => $parentValue) {
$hierarchy[] = $parentKey;
foreach ($parentValue as $childKey) {
$hierarchy[] = $childKey;
}
}
// Parcourir la hiérarchie et rechercher les éléments avant et après
$elementToFind = $this->getUrl(0);
// Trouver la clé de l'élément recherché
$key = array_search($elementToFind, $hierarchy);
if ($key !== false) {
// Trouver l'élément précédent
$previousKey = ($key > 0) ? $key - 1 : null;
$previousValue = ($previousKey !== null) ? $hierarchy[$previousKey] : null;
// Trouver l'élément suivant
$nextKey = ($key < count($hierarchy) - 1) ? $key + 1 : null;
$nextValue = ($nextKey !== null) ? $hierarchy[$nextKey] : null;
self::$previousPage = $previousValue;
self::$nextPage = $nextValue;
}
// Jeux d'icônes
if ($this->getData(['module', $this->getUrl(0), 'iconTemplate'])) {
self::$leftButton = self::$iconTemplate[$this->getData(['module', $this->getUrl(0), 'iconTemplate'])]['left'];
self::$rightButton = self::$iconTemplate[$this->getData(['module', $this->getUrl(0), 'iconTemplate'])]['right'];
}
// Valeurs en sortie
$this->addOutput([
'showBarEditButton' => true,
'showPageContent' => true,
'view' => 'index',
]);
}
public function config()
{
// Soumission du formulaire
if (
$this->getUser('permission', __CLASS__, __FUNCTION__) === true &&
$this->isPost()
) {
$this->setData([
'module',
$this->getUrl(0),
[
'iconTemplate' => $this->getInput('navConfigIconTemplate', null),
]
]);
$this->addOutput([
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config',
'notification' => 'Modifications enregistrées',
'state' => true
]);
}
// Valeurs en sortie
$this->addOutput([
'title' => 'Configuration du module',
'view' => 'config'
]);
}
}

View File

@ -1,15 +0,0 @@
/**
* This file is part of Zwii.
*
* For full copyright and license information, please see the LICENSE
* file that was distributed with this source code.
*
* @author Frédéric Tempez <frederic.tempez@outlook.com>
* @copyright Copyright (C) 2018-2023, Frédéric Tempez
* @license CC Attribution-NonCommercial-NoDerivatives 4.0 International
* @link http://zwiicms.fr/
*/
/** NE PAS EFFACER
* admin.css
*/

View File

@ -1,34 +0,0 @@
<?php echo template::formOpen('navConfig'); ?>
<div class="row">
<div class="col1">
<?php echo template::button('navConfigBack', [
'class' => 'buttonGrey',
'href' => helper::baseUrl() . 'page/edit/' . $this->getUrl(0),
'value' => template::ico('left')
]); ?>
</div>
<div class="col2 offset9">
<?php echo template::submit('navConfigSubmit'); ?>
</div>
</div>
<div class="row">
<div class="col12">
<div class="block">
<h4>
<?php echo helper::translate('Thème'); ?>
</h4>
<div class="row">
<div class="col4 offset4 ">
<?php echo template::select('navConfigIconTemplate', $module::$iconTemplateName, [
'label' => 'Icônes',
'selected' => $this->getData(['module', $this->getUrl(0), 'iconTemplate'])
]); ?>
</div>
</div>
</div>
</div>
</div>
<?php echo template::formClose(); ?>
<div class="moduleVersion">Version
<?php echo $module::VERSION; ?>
</div>

View File

@ -1,20 +0,0 @@
<div class="navButton">
<div class="row">
<div class="col1 textAlignCenter">
<?php if ($module::$previousPage !== null) {
echo template::button('navPreviousButton', [
'href' => helper::baseUrl() . $module::$previousPage,
'value' => template::ico($module::$leftButton)
]);
} ?>
</div>
<div class="col1 offset10 textAlignCenter">
<?php if ($module::$nextPage !== null) {
echo template::button('nabNextButton', [
'href' => helper::baseUrl() . $module::$nextPage,
'value' => template::ico($module::$rightButton)
]);
} ?>
</div>
</div>
</div>