From cdf1bda847edd3e22e9fe817a802219ad8e0f626 Mon Sep 17 00:00:00 2001 From: polo Date: Wed, 8 Sep 2021 02:09:34 +0200 Subject: vignette --- controller/visitor.php | 54 +++++++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 20 deletions(-) (limited to 'controller/visitor.php') diff --git a/controller/visitor.php b/controller/visitor.php index 239c139..a5bf538 100644 --- a/controller/visitor.php +++ b/controller/visitor.php @@ -51,49 +51,62 @@ function discoVisitor() // modèle $AllAlbums = new Album($page_actuelle); $AllAlbums->makeFileList(); - $albumsJSON = array_reverse($AllAlbums->readAll()); // lourd - // $albums est un tableau de chaines JSON, - // chacune renferme 3 variables: titre, année, pochette + // contenu de tous les fichiers JSON (= tableau de chaines) + $albumsJSON = $AllAlbums->readAll(); + // noms des fichiers JSON + $albumNamesJSON = $AllAlbums->getFileList(); - // changer les chaines JSON en tableaux + // changer les chaines JSON en tableaux: titre, année, pochette $i = 0; + $annees = array(); foreach($albumsJSON as $oneAlbum) { $albumsJSON[$i] = json_decode($oneAlbum, true); + $annees[$i] = $albumsJSON[$i][1]; + + // ajout des noms des fichiers JSON + $albumsJSON[$i][3] = $albumNamesJSON[$i]; + $i++; } + // tri d'un tableau multidimensionnel + array_multisort($annees, $albumsJSON); // on passe maintenant au contenu HTML - $albumNamesJSON = array_reverse($AllAlbums->getFileNames()); $AllAlbums->setFormat('html'); $AllAlbums->makeFileList(); - $albumNamesHTML = array_reverse($AllAlbums->getFileNames()); - + $albumNamesHTML = $AllAlbums->getFileList(); + // lien vers le HTML ou ancre? // pour chaque album, détecter le fichier html // si non, ne fournir qu'un lien d'ancre pour la liste d'album $i = 0; $avecLien = []; - foreach($albumNamesJSON as $oneAlbum) + $linkDiscoChrono = []; + foreach($albumsJSON as $oneAlbum) { // nom sans extension - $chemin = pathinfo($oneAlbum); + $chemin = pathinfo($oneAlbum[3]); $nomJSONsansExt = $chemin['filename']; - $chemin = pathinfo($albumNamesHTML[0]); - // détection - if(file_exists($chemin['dirname'] . '/' . $nomJSONsansExt . '.html')) + // au cas où la discographie ne contient aucun html + if(!empty($albumNamesHTML)) { - $lienAlbum[$i] = 'album&album_code=' . $nomJSONsansExt . '&album_name=' . $albumsJSON[$i][0]; - $avecLien[$i] = true; + if(file_exists('data/discographie/html/' . $nomJSONsansExt . '.html')) + { + $lienAlbum[$i] = 'album&album_code=' . $nomJSONsansExt . '&album_name=' . $albumsJSON[$i][0]; + $avecLien[$i] = true; + $linkDiscoChrono[$i] = 'linkChrono'; // css + } + else + { + $lienAlbum[$i] = 'discographie#' . $albumsJSON[$i][0]; + $avecLien[$i] = false; + $linkDiscoChrono[$i] = 'noLinkChrono'; // css + } + $i++; } - else - { - $lienAlbum[$i] = 'discographie#' . $albumsJSON[$i][0]; - $avecLien[$i] = false; - } - $i++; } // variables $css, $js et $content @@ -102,6 +115,7 @@ function discoVisitor() require('view/template.php'); } +// page d'un album function album($albumCode, $albumName) { $page_actuelle = 'discographie'; -- cgit v1.2.3