From 787d03e48471ba62cd830379428f04d996f0b74b Mon Sep 17 00:00:00 2001 From: polo Date: Thu, 17 Feb 2022 18:13:00 +0100 Subject: model update --- model/Album.php | 111 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 84 insertions(+), 27 deletions(-) (limited to 'model/Album.php') diff --git a/model/Album.php b/model/Album.php index 1631c46..386a50f 100644 --- a/model/Album.php +++ b/model/Album.php @@ -1,14 +1,17 @@ page = $page; - $this->albumCode = ''; // désigne un fichier json et un html + $this->fileCode = ''; // désigne un fichier json et un html $this->format = 'json'; // vaut 'html' dans la classe mère $this->time = time(); + $this->makeFileList(); } // GET @@ -24,17 +27,24 @@ class Album extends Page // classe "objet" if($pochette != '') { + //echo($pochette); die(); // = nom sans chemin + // télécharger la pochette require('model/Image.php'); $Image = new Image(false); $Image->upload(); - /*$erreur = $Image->erreur; + $erreur = $Image->erreur; if(!empty($erreur)) - {}*/ + {} } + // encodage avec un tableau simple $albumJSON = json_encode([$titre, $annee, $pochette]); + //var_dump($albumJSON); die(); + + // encodage avec un tableau associatif + //$albumJSON = json_encode(['titre' => $titre, 'annee' => $annee,'pochette' => $pochette]); $nom_fichier = 'data/' . $this->page . '/' . $this->format . '/' . $this->time . '.' . $this->format; @@ -43,35 +53,78 @@ class Album extends Page // classe "objet" fclose($fichier); chmod($nom_fichier, 0666); - return($Image->erreur); + //return($Image->erreur); } // read public function readAll() { - // lecture des données - $albumsJSON = parent::readAll(); + // mettre le JSON dans fileList[$i]['content'] + parent::readAll(); - // conversion des chaines JSON en tableaux: titre, année, pochette - for($i = 0; $i < count($albumsJSON); $i++) + $this->format = 'html'; + for($i = 0; $i < $this->fileListCount; $i++) { - $albumsJSON[$i] = json_decode($albumsJSON[$i], true); + // ajout du JSON + /*$content = file_get_contents($this->fileList[$i]['fileName']); + $content = json_decode($content, true);*/ + $content = json_decode($this->fileList[$i]['content'], true); + //var_dump($content); die(); + + // lecture de $content étant un tableau simple + $this->fileList[$i]['titre'] = $content[0]; + $this->fileList[$i]['annee'] = $content[1]; + $this->fileList[$i]['pochette'] = $content[2]; + + // ajout du HTML si il existe + if(file_exists('data/' . $this->page . '/' . $this->format . '/' . $this->fileList[$i]['fileCode'] . '.' . $this->format)) + { + $this->fileList[$i]['HTMLfileName'] = 'data/' . $this->page . '/' . $this->format . '/' . $this->fileList[$i]['fileCode'] . '.' . $this->format; + $this->fileList[$i]['HTMLcontent'] = file_get_contents($this->fileList[$i]['HTMLfileName']); + } + // utile? + else + { + $this->fileList[$i]['HTMLfileName'] = ''; + $this->fileList[$i]['HTMLcontent'] = ''; + } } - - return($albumsJSON); + // on remet comme avant + $this->format = 'json'; } - public function getVignetteJSON() + public function readOne() { - return(json_decode(file_get_contents('data/discographie/json/' . $this->albumCode . '.json'))); + for($i = 0; $i < $this->fileListCount; $i++) + { + if($_SESSION['target'] == $this->fileList[$i]['fileCode']) + { + // json + $this->oneAlbum['fileCode'] = $this->fileList[$i]['fileCode']; + $this->oneAlbum['fileName'] = 'data/' . $this->page . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format; + $this->oneAlbum['content'] = file_get_contents($this->fileList[$i]['fileName']); + $content = json_decode($this->oneAlbum['content']); + $this->oneAlbum['titre'] = $content[0]; + $this->oneAlbum['annee'] = $content[1]; + $this->oneAlbum['pochette'] = $content[2]; + + // html + $this->format = 'html'; + if(file_exists('data/' . $this->page . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format)) + { + $this->oneAlbum['HTMLfileName'] = 'data/' . $this->page . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format; + $this->oneAlbum['HTMLcontent'] = file_get_contents($this->oneAlbum['HTMLfileName']); + } + } + } } - // page de l'album - public static function readOneHTML($albumCode) + // page d'un album + public static function readOneHTML($fileCode) { - if(file_exists('data/discographie/html/' . $albumCode . '.html')) + if(file_exists('data/discographie/html/' . $fileCode . '.html')) { - return(file_get_contents('data/discographie/html/' . $albumCode . '.html')); + return(file_get_contents('data/discographie/html/' . $fileCode . '.html')); } else { @@ -79,13 +132,10 @@ class Album extends Page // classe "objet" } } - // pour afficher des dates - /*public function getDate($fileNumber) + public function getVignetteJSON() { - // le 2è paramètre exclut le suffixe .html - $timestamp = basename($this->files[$fileNumber], '.html'); - return getdate($timestamp); - }*/ + return(json_decode(file_get_contents('data/discographie/json/' . $this->fileCode . '.json'))); + } // update public function updateVignetteJSON($titre, $annee, $pochette) @@ -103,6 +153,12 @@ class Album extends Page // classe "objet" require('model/Image.php'); $Image = new Image(false); $Image->upload(); + $erreur = $Image->erreur; + if(!empty($erreur)) + { + // remettre pochette d'avant + //$pochette + } } $albumJSON = json_encode([$titre, $annee, $pochette]); @@ -120,11 +176,12 @@ class Album extends Page // classe "objet" // delete public function delete() { - unlink('data/' . $this->page . '/' . $this->format . '/' . $this->albumCode . '.json'); + parent::delete(); - if(file_exists('data/' . $this->page . '/html/' . $this->albumCode . '.html')); + if(file_exists('data/' . $this->page . '/html/' . $this->fileCode . '.' . $this->format)); { - unlink('data/' . $this->page . '/html/' . $this->albumCode . '.html'); + $this->format = 'html'; + parent::delete(); } } } -- cgit v1.2.3