Fix HomePageId

This commit is contained in:
Fred Tempez 2023-09-30 13:35:20 +02:00
parent 54087cec56
commit 589da60177
10 changed files with 73 additions and 24 deletions

View File

@ -33,7 +33,7 @@ class layout extends common
$item .= '<p>' . $this->getData(['config', 'cookies', 'mainLabel']) . '</p>'; $item .= '<p>' . $this->getData(['config', 'cookies', 'mainLabel']) . '</p>';
// Formulaire de réponse // Formulaire de réponse
if ( if (
$this->getData(['config', 'homePageId']) === $this->getUrl(0) $this->homePageId() === $this->getUrl(0)
) { ) {
$item .= '<form method="POST" action="' . helper::baseUrl(false) . '" id="cookieForm">'; $item .= '<form method="POST" action="' . helper::baseUrl(false) . '" id="cookieForm">';
} else { } else {
@ -790,7 +790,7 @@ class layout extends common
echo '<title>' . $this->core->output['metaTitle'] . '</title>'; echo '<title>' . $this->core->output['metaTitle'] . '</title>';
echo '<meta property="og:title" content="' . $this->core->output['metaTitle'] . '" />'; echo '<meta property="og:title" content="' . $this->core->output['metaTitle'] . '" />';
if ( if (
$this->getData(['config', 'homePageId']) === $this->getUrl(0) $this->homePageId() === $this->getUrl(0)
) { ) {
echo '<link rel="canonical" href="' . helper::baseUrl(false) . '" />'; echo '<link rel="canonical" href="' . helper::baseUrl(false) . '" />';
} else { } else {

View File

@ -536,7 +536,7 @@ class core extends common
) { ) {
$access = true; $access = true;
} else { } else {
if ($this->getUrl(0) === $this->getData(['config', 'homePageId'])) { if ($this->getUrl(0) === $this->homePageId()) {
$access = 'login'; $access = 'login';
} else { } else {
$access = false; $access = false;

View File

@ -401,7 +401,7 @@ class common
if ($url = $_SERVER['QUERY_STRING']) { if ($url = $_SERVER['QUERY_STRING']) {
$this->url = $url; $this->url = $url;
} else { } else {
$this->url = $this->getData(['config', 'homePageId']); $this->url = $this->homePageId();
} }
} }
@ -1051,7 +1051,7 @@ class common
// Page désactivée, traiter les sous-pages sans prendre en compte la page parente. // Page désactivée, traiter les sous-pages sans prendre en compte la page parente.
if ($this->getData(['page', $parentPageId, 'disable']) !== true) { if ($this->getData(['page', $parentPageId, 'disable']) !== true) {
// Cas de la page d'accueil ne pas dupliquer l'URL // Cas de la page d'accueil ne pas dupliquer l'URL
$pageId = ($parentPageId !== $this->getData(['config', 'homePageId'])) ? $parentPageId : ''; $pageId = ($parentPageId !== $this->homePageId()) ? $parentPageId : '';
$sitemap->addUrl('/' . $pageId, $datetime); $sitemap->addUrl('/' . $pageId, $datetime);
} }
// Articles du blog // Articles du blog
@ -1072,7 +1072,7 @@ class common
continue; continue;
} }
// Cas de la page d'accueil ne pas dupliquer l'URL // Cas de la page d'accueil ne pas dupliquer l'URL
$pageId = ($childKey !== $this->getData(['config', 'homePageId'])) ? $childKey : ''; $pageId = ($childKey !== $this->homePageId()) ? $childKey : '';
$sitemap->addUrl('/' . $childKey, $datetime); $sitemap->addUrl('/' . $childKey, $datetime);
// La sous-page est un blog // La sous-page est un blog
@ -1369,6 +1369,21 @@ class common
$zip->close(); $zip->close();
} }
/**
* Retourne l'id de la page d'accueil
* @return string pageId
*/
public function homePageId()
{
switch (self::$siteContent) {
case 'home':
return ($this->getData(['config', 'homePageId']));
default:
return ($this->getData(['course', self::$siteContent, 'homePageId']));
}
}
/** /**
* Journalisation * Journalisation

View File

@ -46,7 +46,7 @@
<div class="col4"> <div class="col4">
<?php echo template::select('configLocaleHomePageId', helper::arrayColumn($module::$pagesList, 'title', 'SORT_ASC'), [ <?php echo template::select('configLocaleHomePageId', helper::arrayColumn($module::$pagesList, 'title', 'SORT_ASC'), [
'label' => 'Accueil', 'label' => 'Accueil',
'selected' => $this->getData(['config', 'homePageId']), 'selected' => $this->homePageId(),
'help' => 'La première page que vos visiteurs verront.' 'help' => 'La première page que vos visiteurs verront.'
]); ?> ]); ?>
</div> </div>

View File

@ -48,18 +48,20 @@ class course extends common
public static $swapMessage = []; public static $swapMessage = [];
public static $pagesList = [];
public function index() public function index()
{ {
$courseIdShortTitle = helper::arrayColumn($this->getData(['course']), 'shortTitle'); $courseIdShortTitle = helper::arrayColumn($this->getData(['course']), 'shortTitle');
ksort($courseIdShortTitle); ksort($courseIdShortTitle);
foreach ($courseIdShortTitle as $courseId => $courseTitle) { foreach ($courseIdShortTitle as $courseId => $courseTitle) {
$categorieUrl = helper::baseUrl(!helper::checkRewrite()) . 'course/swap/' . $courseId ; $categorieUrl = helper::baseUrl(!helper::checkRewrite()) . 'course/swap/' . $courseId;
self::$courses[] = [ self::$courses[] = [
$courseTitle, $courseTitle,
$this->getData(['course', $courseId, 'author']), $this->getData(['course', $courseId, 'author']),
$this->getData(['course', $courseId, 'description']), $this->getData(['course', $courseId, 'description']),
'<a href="' . $categorieUrl .'" target="_blank">' . $categorieUrl . '</a>', '<a href="' . $categorieUrl . '" target="_blank">' . $categorieUrl . '</a>',
template::button('courseEdit' . $courseId, [ template::button('courseEdit' . $courseId, [
'href' => helper::baseUrl() . 'course/edit/' . $courseId, 'href' => helper::baseUrl() . 'course/edit/' . $courseId,
'value' => template::ico('pencil'), 'value' => template::ico('pencil'),
@ -94,14 +96,15 @@ class course extends common
$this->isPost() $this->isPost()
) { ) {
$courseId = uniqid(); $courseId = uniqid();
$author = $this->getInput('courseAddAuthor');
$this->setData([ $this->setData([
'course', 'course',
$courseId, $courseId,
[ [
'title' => $this->getInput('courseAddTitle', helper::FILTER_STRING_SHORT, true), 'title' => $this->getInput('courseAddTitle', helper::FILTER_STRING_SHORT, true),
'shortTitle' => $this->getInput('courseAddShortTitle', helper::FILTER_STRING_SHORT, true), 'shortTitle' => $this->getInput('courseAddShortTitle', helper::FILTER_STRING_SHORT, true),
'author' => $author, 'author' => $this->getInput('courseAddAuthor'),
'homePageId' => $this->getInput('courseAddHomePageId'),
'category' => $this->getInput('courseAddCategories'),
'description' => $this->getInput('courseAddDescription', helper::FILTER_STRING_SHORT, true), 'description' => $this->getInput('courseAddDescription', helper::FILTER_STRING_SHORT, true),
'access' => $this->getInput('courseAddAccess', helper::FILTER_INT), 'access' => $this->getInput('courseAddAccess', helper::FILTER_INT),
'openingDate' => $this->getInput('courseOpeningDate', helper::FILTER_DATETIME), 'openingDate' => $this->getInput('courseOpeningDate', helper::FILTER_DATETIME),
@ -144,6 +147,17 @@ class course extends common
// Liste des catégories de cours // Liste des catégories de cours
self::$courseCategories = $this->getData(['category']); self::$courseCategories = $this->getData(['category']);
// Liste des pages disponibles
self::$pagesList = $this->getData(['page']);
foreach (self::$pagesList as $page => $pageId) {
if (
$this->getData(['page', $page, 'block']) === 'bar' ||
$this->getData(['page', $page, 'disable']) === true
) {
unset(self::$pagesList[$page]);
}
}
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'title' => helper::translate('Ajouter un cours'), 'title' => helper::translate('Ajouter un cours'),
@ -163,14 +177,15 @@ class course extends common
$this->isPost() $this->isPost()
) { ) {
$courseId = $this->getUrl(2); $courseId = $this->getUrl(2);
$author = $this->getInput('courseAddAuthor');
$this->setData([ $this->setData([
'course', 'course',
$courseId, $courseId,
[ [
'title' => $this->getInput('courseEditTitle', helper::FILTER_STRING_SHORT, true), 'title' => $this->getInput('courseEditTitle', helper::FILTER_STRING_SHORT, true),
'shortTitle' => $this->getInput('courseEditShortTitle', helper::FILTER_STRING_SHORT, true), 'shortTitle' => $this->getInput('courseEditShortTitle', helper::FILTER_STRING_SHORT, true),
'author' => $author, 'author' => $this->getInput('courseEditAuthor'),
'homePageId' => $this->getInput('courseEditHomePageId'),
'category' => $this->getInput('courseEditCategories'),
'description' => $this->getInput('courseEditDescription', helper::FILTER_STRING_SHORT, true), 'description' => $this->getInput('courseEditDescription', helper::FILTER_STRING_SHORT, true),
'access' => $this->getInput('courseEditAccess', helper::FILTER_INT), 'access' => $this->getInput('courseEditAccess', helper::FILTER_INT),
'openingDate' => $this->getInput('courseOpeningDate', helper::FILTER_DATETIME), 'openingDate' => $this->getInput('courseOpeningDate', helper::FILTER_DATETIME),
@ -199,6 +214,17 @@ class course extends common
// Liste des catégories de cours // Liste des catégories de cours
self::$courseCategories = $this->getData(['category']); self::$courseCategories = $this->getData(['category']);
// Liste des pages disponibles
self::$pagesList = $this->getData(['page']);
foreach (self::$pagesList as $page => $pageId) {
if (
$this->getData(['page', $page, 'block']) === 'bar' ||
$this->getData(['page', $page, 'disable']) === true
) {
unset(self::$pagesList[$page]);
}
}
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'title' => helper::translate('Editer un cours'), 'title' => helper::translate('Editer un cours'),

View File

@ -37,10 +37,14 @@
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col12"> <div class="col6">
<?php echo template::select('courseEditCategories', $module::$courseCategories, [ <?php echo template::select('courseaDDHomePageId', helper::arrayColumn($module::$pagesList, 'title', 'SORT_ASC'), [
'label' => 'Accueil du cours',
]); ?>
</div>
<div class="col6">
<?php echo template::select('courseaDDCategories', $module::$courseCategories, [
'label' => 'Catégorie', 'label' => 'Catégorie',
'value' => $this->getdata(['course', $this->getUrl(2), 'category'])
]); ?> ]); ?>
</div> </div>
</div> </div>

View File

@ -40,8 +40,14 @@
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col12"> <div class="col6">
<?php echo template::select('courseEditCategories', $module::$courseCategories, [ <?php echo template::select('courseEditHomePageId', helper::arrayColumn($module::$pagesList, 'title', 'SORT_ASC'), [
'label' => 'Accueil du cours',
'selected' => $this->getdata(['course', $this->getUrl(2), 'homePageId']),
]); ?>
</div>
<div class="col6">
<?php echo template::select('courseEditCategories', $module::$courseCategories, [
'label' => 'Catégorie', 'label' => 'Catégorie',
'value' => $this->getdata(['course', $this->getUrl(2), 'category']) 'value' => $this->getdata(['course', $this->getUrl(2), 'category'])
]); ?> ]); ?>
@ -66,7 +72,7 @@
<?php echo template::date('courseOpeningDate', [ <?php echo template::date('courseOpeningDate', [
'type' => 'datetime-local', 'type' => 'datetime-local',
'label' => 'Ouverture', 'label' => 'Ouverture',
'value' => is_null($this->getdata(['course', $this->getUrl(2), 'openingDate'])) ? '' :floor($this->getdata(['course', $this->getUrl(2), 'openingDate']) / 60) * 60 'value' => is_null($this->getdata(['course', $this->getUrl(2), 'openingDate'])) ? '' : floor($this->getdata(['course', $this->getUrl(2), 'openingDate']) / 60) * 60
]); ?> ]); ?>
</div> </div>
<div class="col4"> <div class="col4">

View File

@ -682,7 +682,6 @@ class init extends common
'disable' => false, 'disable' => false,
'content' => 'accueil.html', 'content' => 'accueil.html',
'hideTitle' => false, 'hideTitle' => false,
'homePageId' => true,
'breadCrumb' => false, 'breadCrumb' => false,
'metaDescription' => '', 'metaDescription' => '',
'metaTitle' => '', 'metaTitle' => '',
@ -984,7 +983,6 @@ class init extends common
'disable' => false, 'disable' => false,
'content' => 'accueil.html', 'content' => 'accueil.html',
'hideTitle' => false, 'hideTitle' => false,
'homePageId' => true,
'breadCrumb' => false, 'breadCrumb' => false,
'metaDescription' => '', 'metaDescription' => '',
'metaTitle' => '', 'metaTitle' => '',

View File

@ -211,7 +211,7 @@ class page extends common
]); ]);
} }
// Impossible de supprimer la page d'accueil // Impossible de supprimer la page d'accueil
elseif ($page === $this->getData(['config', 'homePageId'])) { elseif ($page === $this->homePageId()) {
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'redirect' => helper::baseUrl() . 'config', 'redirect' => helper::baseUrl() . 'config',

View File

@ -30,7 +30,7 @@ class sitemap extends common
foreach ($this->getHierarchy(null, true, null) as $parentId => $childIds) { foreach ($this->getHierarchy(null, true, null) as $parentId => $childIds) {
$items .= ' <li>'; $items .= ' <li>';
if ($this->getData(['page', $parentId, 'disable']) === false && $this->getUser('group') >= $this->getData(['page', $parentId, 'group'])) { if ($this->getData(['page', $parentId, 'disable']) === false && $this->getUser('group') >= $this->getData(['page', $parentId, 'group'])) {
$pageUrl = ($parentId !== $this->getData(['config', 'homePageId'])) ? helper::baseUrl() . $parentId : helper::baseUrl(false); $pageUrl = ($parentId !== $this->homePageId()) ? helper::baseUrl() . $parentId : helper::baseUrl(false);
$items .= '<a href="' . $pageUrl . '">' . $this->getData(['page', $parentId, 'title']) . '</a>'; $items .= '<a href="' . $pageUrl . '">' . $this->getData(['page', $parentId, 'title']) . '</a>';
} else { } else {
// page désactivée // page désactivée
@ -67,7 +67,7 @@ class sitemap extends common
// Sous-page // Sous-page
$items .= ' <li>'; $items .= ' <li>';
if ($this->getData(['page', $childId, 'disable']) === false && $this->getUser('group') >= $this->getData(['page', $parentId, 'group'])) { if ($this->getData(['page', $childId, 'disable']) === false && $this->getUser('group') >= $this->getData(['page', $parentId, 'group'])) {
$pageUrl = ($childId !== $this->getData(['config', 'homePageId'])) ? helper::baseUrl() . $childId : helper::baseUrl(false); $pageUrl = ($childId !== $this->homePageId()) ? helper::baseUrl() . $childId : helper::baseUrl(false);
$items .= '<a href="' . $pageUrl . '">' . $this->getData(['page', $childId, 'title']) . '</a>'; $items .= '<a href="' . $pageUrl . '">' . $this->getData(['page', $childId, 'title']) . '</a>';
} else { } else {
// page désactivée // page désactivée