page = $page; $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 // SET // fonctions CRUD // create public function createVignette($titre, $annee, $pochette) { //$this->format = 'json'; 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; 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; $fichier = fopen($nom_fichier, 'w'); // w pour créer ou écraser fputs($fichier, $albumJSON); fclose($fichier); chmod($nom_fichier, 0666); //return($Image->erreur); } // read public function readAll() { // mettre le JSON dans fileList[$i]['content'] parent::readAll(); $this->format = 'html'; for($i = 0; $i < $this->fileListCount; $i++) { // 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'] = ''; } } // on remet comme avant $this->format = 'json'; } public function readOne() { 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 d'un album public static function readOneHTML($fileCode) { if(file_exists('data/discographie/html/' . $fileCode . '.html')) { return(file_get_contents('data/discographie/html/' . $fileCode . '.html')); } else { return(''); } } public function getVignetteJSON() { return(json_decode(file_get_contents('data/discographie/json/' . $this->fileCode . '.json'))); } // update public function updateVignetteJSON($titre, $annee, $pochette) { // garder l'ancienne image $albumJSON = self::getVignetteJSON(); if($pochette == '') { $pochette = $albumJSON[2]; } else { // télécharger la pochette 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]); // écriture $nom_fichier = 'data/discographie/json/' . $this->albumCode . '.json'; $fichier = fopen($nom_fichier, 'w+'); // w pour créer ou écraser fputs($fichier, $albumJSON); fclose($fichier); chmod($nom_fichier, 0666); return($Image->erreur); } // delete public function delete() { parent::delete(); if(file_exists('data/' . $this->page . '/html/' . $this->fileCode . '.' . $this->format)); { $this->format = 'html'; parent::delete(); } } }