diff options
Diffstat (limited to 'controller/visitor.php')
-rw-r--r-- | controller/visitor.php | 54 |
1 files changed, 34 insertions, 20 deletions
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() | |||
51 | // modèle | 51 | // modèle |
52 | $AllAlbums = new Album($page_actuelle); | 52 | $AllAlbums = new Album($page_actuelle); |
53 | $AllAlbums->makeFileList(); | 53 | $AllAlbums->makeFileList(); |
54 | $albumsJSON = array_reverse($AllAlbums->readAll()); // lourd | ||
55 | 54 | ||
56 | // $albums est un tableau de chaines JSON, | 55 | // contenu de tous les fichiers JSON (= tableau de chaines) |
57 | // chacune renferme 3 variables: titre, année, pochette | 56 | $albumsJSON = $AllAlbums->readAll(); |
57 | // noms des fichiers JSON | ||
58 | $albumNamesJSON = $AllAlbums->getFileList(); | ||
58 | 59 | ||
59 | // changer les chaines JSON en tableaux | 60 | // changer les chaines JSON en tableaux: titre, année, pochette |
60 | $i = 0; | 61 | $i = 0; |
62 | $annees = array(); | ||
61 | foreach($albumsJSON as $oneAlbum) | 63 | foreach($albumsJSON as $oneAlbum) |
62 | { | 64 | { |
63 | $albumsJSON[$i] = json_decode($oneAlbum, true); | 65 | $albumsJSON[$i] = json_decode($oneAlbum, true); |
66 | $annees[$i] = $albumsJSON[$i][1]; | ||
67 | |||
68 | // ajout des noms des fichiers JSON | ||
69 | $albumsJSON[$i][3] = $albumNamesJSON[$i]; | ||
70 | |||
64 | $i++; | 71 | $i++; |
65 | } | 72 | } |
73 | // tri d'un tableau multidimensionnel | ||
74 | array_multisort($annees, $albumsJSON); | ||
66 | 75 | ||
67 | // on passe maintenant au contenu HTML | 76 | // on passe maintenant au contenu HTML |
68 | $albumNamesJSON = array_reverse($AllAlbums->getFileNames()); | ||
69 | $AllAlbums->setFormat('html'); | 77 | $AllAlbums->setFormat('html'); |
70 | $AllAlbums->makeFileList(); | 78 | $AllAlbums->makeFileList(); |
71 | $albumNamesHTML = array_reverse($AllAlbums->getFileNames()); | 79 | $albumNamesHTML = $AllAlbums->getFileList(); |
72 | 80 | ||
73 | // lien vers le HTML ou ancre? | 81 | // lien vers le HTML ou ancre? |
74 | // pour chaque album, détecter le fichier html | 82 | // pour chaque album, détecter le fichier html |
75 | // si non, ne fournir qu'un lien d'ancre pour la liste d'album | 83 | // si non, ne fournir qu'un lien d'ancre pour la liste d'album |
76 | $i = 0; | 84 | $i = 0; |
77 | $avecLien = []; | 85 | $avecLien = []; |
78 | foreach($albumNamesJSON as $oneAlbum) | 86 | $linkDiscoChrono = []; |
87 | foreach($albumsJSON as $oneAlbum) | ||
79 | { | 88 | { |
80 | // nom sans extension | 89 | // nom sans extension |
81 | $chemin = pathinfo($oneAlbum); | 90 | $chemin = pathinfo($oneAlbum[3]); |
82 | $nomJSONsansExt = $chemin['filename']; | 91 | $nomJSONsansExt = $chemin['filename']; |
83 | $chemin = pathinfo($albumNamesHTML[0]); | ||
84 | 92 | ||
85 | // détection | 93 | // au cas où la discographie ne contient aucun html |
86 | if(file_exists($chemin['dirname'] . '/' . $nomJSONsansExt . '.html')) | 94 | if(!empty($albumNamesHTML)) |
87 | { | 95 | { |
88 | $lienAlbum[$i] = 'album&album_code=' . $nomJSONsansExt . '&album_name=' . $albumsJSON[$i][0]; | 96 | if(file_exists('data/discographie/html/' . $nomJSONsansExt . '.html')) |
89 | $avecLien[$i] = true; | 97 | { |
98 | $lienAlbum[$i] = 'album&album_code=' . $nomJSONsansExt . '&album_name=' . $albumsJSON[$i][0]; | ||
99 | $avecLien[$i] = true; | ||
100 | $linkDiscoChrono[$i] = 'linkChrono'; // css | ||
101 | } | ||
102 | else | ||
103 | { | ||
104 | $lienAlbum[$i] = 'discographie#' . $albumsJSON[$i][0]; | ||
105 | $avecLien[$i] = false; | ||
106 | $linkDiscoChrono[$i] = 'noLinkChrono'; // css | ||
107 | } | ||
108 | $i++; | ||
90 | } | 109 | } |
91 | else | ||
92 | { | ||
93 | $lienAlbum[$i] = 'discographie#' . $albumsJSON[$i][0]; | ||
94 | $avecLien[$i] = false; | ||
95 | } | ||
96 | $i++; | ||
97 | } | 110 | } |
98 | 111 | ||
99 | // variables $css, $js et $content | 112 | // variables $css, $js et $content |
@@ -102,6 +115,7 @@ function discoVisitor() | |||
102 | require('view/template.php'); | 115 | require('view/template.php'); |
103 | } | 116 | } |
104 | 117 | ||
118 | // page d'un album | ||
105 | function album($albumCode, $albumName) | 119 | function album($albumCode, $albumName) |
106 | { | 120 | { |
107 | $page_actuelle = 'discographie'; | 121 | $page_actuelle = 'discographie'; |