format = 'json'; // vaut 'html' dans la classe mère // pour: page, fileCode, time et makeFileList() parent::__construct($page, $folder); } // GET public function getAllJSON() // pour la page album { // mettre le JSON dans fileList[$i]['content'] parent::readAll(); $this->format = 'html'; for($i = 0; $i < $this->fileListCount; $i++) { $content = json_decode($this->fileList[$i]['content'], true); $this->fileList[$i]['titre'] = $content[0]; $this->fileList[$i]['annee'] = $content[1]; $this->fileList[$i]['pochette'] = $content[2]; $this->fileList[$i]['pochetteMini'] = $content[3]; } // on remet comme avant $this->format = 'json'; } // SET // fonctions CRUD // create public function createVignetteJSON($titre, $annee, $pochette, $pochetteMini) { //$this->format = 'json'; // gd ne produit que des JPG global $imageLibrary; if($imageLibrary == 'gd') { $file_name = pathinfo($pochetteMini); $pochetteMini = $file_name['filename'] . '.jpg'; //var_dump($pochetteMini);die(); } $albumJSON = json_encode([$titre, $annee, $pochette, $pochetteMini]); //var_dump($albumJSON); die(); $nom_fichier = 'data/' . $this->folder . '/' . $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 // hydratation public function readAll() { // mettre le JSON dans fileList[$i]['content'] parent::readAll(); // = surcharge, appeler la méthode de la classe mère // permet de ne pas la remplacer par la nouvelle $this->format = 'html'; for($i = 0; $i < $this->fileListCount; $i++) { // ajout du JSON $content = json_decode($this->fileList[$i]['content'], true); // 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]; $this->fileList[$i]['pochetteMini'] = $content[3]; // ajout du HTML si il existe if(file_exists('data/' . $this->folder . '/' . $this->format . '/' . $this->fileList[$i]['fileCode'] . '.' . $this->format)) { $this->fileList[$i]['HTMLfileName'] = 'data/' . $this->folder . '/' . $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'; } // hydratation public function readOne() { for($i = 0; $i < $this->fileListCount; $i++) { if($this->fileCode == $this->fileList[$i]['fileCode']) { // json $this->oneAlbum['fileCode'] = $this->fileList[$i]['fileCode']; $this->oneAlbum['fileName'] = 'data/' . $this->folder . '/' . $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]; $this->oneAlbum['pochetteMini'] = $content[3]; // html $this->format = 'html'; if(file_exists('data/' . $this->folder . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format)) { $this->oneAlbum['HTMLfileName'] = 'data/' . $this->folder . '/' . $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, $pochetteMini) { // garder l'image si aucune n'est sélectionnée // (on ne peut pas préremplir un ) $albumJSON = self::getVignetteJSON(); /*var_dump($pochette); var_dump($pochetteMini); var_dump($albumJSON); die();*/ if($pochette == '') { $pochette = $albumJSON[2]; $pochetteMini = $albumJSON[3]; } $albumJSON = json_encode([$titre, $annee, $pochette, $pochetteMini]); // écriture $nom_fichier = 'data/discographie/json/' . $this->fileCode . '.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(); // json if(file_exists('data/' . $this->folder . '/html/' . $this->fileCode . '.' . $this->format)); { $this->format = 'html'; parent::delete(); // html } } }