diff options
Diffstat (limited to 'model/Album.php')
-rw-r--r-- | model/Album.php | 111 |
1 files changed, 84 insertions, 27 deletions
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 @@ | |||
1 | <?php | 1 | <?php |
2 | // model/Album.php | 2 | // model/Album.php |
3 | 3 | ||
4 | class Album extends Page // classe "objet" | 4 | class Album extends Article |
5 | { | 5 | { |
6 | public $oneAlbum; | ||
7 | |||
6 | public function __construct($page) | 8 | public function __construct($page) |
7 | { | 9 | { |
8 | $this->page = $page; | 10 | $this->page = $page; |
9 | $this->albumCode = ''; // désigne un fichier json et un html | 11 | $this->fileCode = ''; // désigne un fichier json et un html |
10 | $this->format = 'json'; // vaut 'html' dans la classe mère | 12 | $this->format = 'json'; // vaut 'html' dans la classe mère |
11 | $this->time = time(); | 13 | $this->time = time(); |
14 | $this->makeFileList(); | ||
12 | } | 15 | } |
13 | 16 | ||
14 | // GET | 17 | // GET |
@@ -24,17 +27,24 @@ class Album extends Page // classe "objet" | |||
24 | 27 | ||
25 | if($pochette != '') | 28 | if($pochette != '') |
26 | { | 29 | { |
30 | //echo($pochette); die(); // = nom sans chemin | ||
31 | |||
27 | // télécharger la pochette | 32 | // télécharger la pochette |
28 | require('model/Image.php'); | 33 | require('model/Image.php'); |
29 | $Image = new Image(false); | 34 | $Image = new Image(false); |
30 | $Image->upload(); | 35 | $Image->upload(); |
31 | 36 | ||
32 | /*$erreur = $Image->erreur; | 37 | $erreur = $Image->erreur; |
33 | if(!empty($erreur)) | 38 | if(!empty($erreur)) |
34 | {}*/ | 39 | {} |
35 | } | 40 | } |
36 | 41 | ||
42 | // encodage avec un tableau simple | ||
37 | $albumJSON = json_encode([$titre, $annee, $pochette]); | 43 | $albumJSON = json_encode([$titre, $annee, $pochette]); |
44 | //var_dump($albumJSON); die(); | ||
45 | |||
46 | // encodage avec un tableau associatif | ||
47 | //$albumJSON = json_encode(['titre' => $titre, 'annee' => $annee,'pochette' => $pochette]); | ||
38 | 48 | ||
39 | $nom_fichier = 'data/' . $this->page . '/' . $this->format . '/' . $this->time . '.' . $this->format; | 49 | $nom_fichier = 'data/' . $this->page . '/' . $this->format . '/' . $this->time . '.' . $this->format; |
40 | 50 | ||
@@ -43,35 +53,78 @@ class Album extends Page // classe "objet" | |||
43 | fclose($fichier); | 53 | fclose($fichier); |
44 | chmod($nom_fichier, 0666); | 54 | chmod($nom_fichier, 0666); |
45 | 55 | ||
46 | return($Image->erreur); | 56 | //return($Image->erreur); |
47 | } | 57 | } |
48 | 58 | ||
49 | // read | 59 | // read |
50 | public function readAll() | 60 | public function readAll() |
51 | { | 61 | { |
52 | // lecture des données | 62 | // mettre le JSON dans fileList[$i]['content'] |
53 | $albumsJSON = parent::readAll(); | 63 | parent::readAll(); |
54 | 64 | ||
55 | // conversion des chaines JSON en tableaux: titre, année, pochette | 65 | $this->format = 'html'; |
56 | for($i = 0; $i < count($albumsJSON); $i++) | 66 | for($i = 0; $i < $this->fileListCount; $i++) |
57 | { | 67 | { |
58 | $albumsJSON[$i] = json_decode($albumsJSON[$i], true); | 68 | // ajout du JSON |
69 | /*$content = file_get_contents($this->fileList[$i]['fileName']); | ||
70 | $content = json_decode($content, true);*/ | ||
71 | $content = json_decode($this->fileList[$i]['content'], true); | ||
72 | //var_dump($content); die(); | ||
73 | |||
74 | // lecture de $content étant un tableau simple | ||
75 | $this->fileList[$i]['titre'] = $content[0]; | ||
76 | $this->fileList[$i]['annee'] = $content[1]; | ||
77 | $this->fileList[$i]['pochette'] = $content[2]; | ||
78 | |||
79 | // ajout du HTML si il existe | ||
80 | if(file_exists('data/' . $this->page . '/' . $this->format . '/' . $this->fileList[$i]['fileCode'] . '.' . $this->format)) | ||
81 | { | ||
82 | $this->fileList[$i]['HTMLfileName'] = 'data/' . $this->page . '/' . $this->format . '/' . $this->fileList[$i]['fileCode'] . '.' . $this->format; | ||
83 | $this->fileList[$i]['HTMLcontent'] = file_get_contents($this->fileList[$i]['HTMLfileName']); | ||
84 | } | ||
85 | // utile? | ||
86 | else | ||
87 | { | ||
88 | $this->fileList[$i]['HTMLfileName'] = ''; | ||
89 | $this->fileList[$i]['HTMLcontent'] = ''; | ||
90 | } | ||
59 | } | 91 | } |
60 | 92 | // on remet comme avant | |
61 | return($albumsJSON); | 93 | $this->format = 'json'; |
62 | } | 94 | } |
63 | 95 | ||
64 | public function getVignetteJSON() | 96 | public function readOne() |
65 | { | 97 | { |
66 | return(json_decode(file_get_contents('data/discographie/json/' . $this->albumCode . '.json'))); | 98 | for($i = 0; $i < $this->fileListCount; $i++) |
99 | { | ||
100 | if($_SESSION['target'] == $this->fileList[$i]['fileCode']) | ||
101 | { | ||
102 | // json | ||
103 | $this->oneAlbum['fileCode'] = $this->fileList[$i]['fileCode']; | ||
104 | $this->oneAlbum['fileName'] = 'data/' . $this->page . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format; | ||
105 | $this->oneAlbum['content'] = file_get_contents($this->fileList[$i]['fileName']); | ||
106 | $content = json_decode($this->oneAlbum['content']); | ||
107 | $this->oneAlbum['titre'] = $content[0]; | ||
108 | $this->oneAlbum['annee'] = $content[1]; | ||
109 | $this->oneAlbum['pochette'] = $content[2]; | ||
110 | |||
111 | // html | ||
112 | $this->format = 'html'; | ||
113 | if(file_exists('data/' . $this->page . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format)) | ||
114 | { | ||
115 | $this->oneAlbum['HTMLfileName'] = 'data/' . $this->page . '/' . $this->format . '/' . $this->fileCode . '.' . $this->format; | ||
116 | $this->oneAlbum['HTMLcontent'] = file_get_contents($this->oneAlbum['HTMLfileName']); | ||
117 | } | ||
118 | } | ||
119 | } | ||
67 | } | 120 | } |
68 | 121 | ||
69 | // page de l'album | 122 | // page d'un album |
70 | public static function readOneHTML($albumCode) | 123 | public static function readOneHTML($fileCode) |
71 | { | 124 | { |
72 | if(file_exists('data/discographie/html/' . $albumCode . '.html')) | 125 | if(file_exists('data/discographie/html/' . $fileCode . '.html')) |
73 | { | 126 | { |
74 | return(file_get_contents('data/discographie/html/' . $albumCode . '.html')); | 127 | return(file_get_contents('data/discographie/html/' . $fileCode . '.html')); |
75 | } | 128 | } |
76 | else | 129 | else |
77 | { | 130 | { |
@@ -79,13 +132,10 @@ class Album extends Page // classe "objet" | |||
79 | } | 132 | } |
80 | } | 133 | } |
81 | 134 | ||
82 | // pour afficher des dates | 135 | public function getVignetteJSON() |
83 | /*public function getDate($fileNumber) | ||
84 | { | 136 | { |
85 | // le 2è paramètre exclut le suffixe .html | 137 | return(json_decode(file_get_contents('data/discographie/json/' . $this->fileCode . '.json'))); |
86 | $timestamp = basename($this->files[$fileNumber], '.html'); | 138 | } |
87 | return getdate($timestamp); | ||
88 | }*/ | ||
89 | 139 | ||
90 | // update | 140 | // update |
91 | public function updateVignetteJSON($titre, $annee, $pochette) | 141 | public function updateVignetteJSON($titre, $annee, $pochette) |
@@ -103,6 +153,12 @@ class Album extends Page // classe "objet" | |||
103 | require('model/Image.php'); | 153 | require('model/Image.php'); |
104 | $Image = new Image(false); | 154 | $Image = new Image(false); |
105 | $Image->upload(); | 155 | $Image->upload(); |
156 | $erreur = $Image->erreur; | ||
157 | if(!empty($erreur)) | ||
158 | { | ||
159 | // remettre pochette d'avant | ||
160 | //$pochette | ||
161 | } | ||
106 | } | 162 | } |
107 | 163 | ||
108 | $albumJSON = json_encode([$titre, $annee, $pochette]); | 164 | $albumJSON = json_encode([$titre, $annee, $pochette]); |
@@ -120,11 +176,12 @@ class Album extends Page // classe "objet" | |||
120 | // delete | 176 | // delete |
121 | public function delete() | 177 | public function delete() |
122 | { | 178 | { |
123 | unlink('data/' . $this->page . '/' . $this->format . '/' . $this->albumCode . '.json'); | 179 | parent::delete(); |
124 | 180 | ||
125 | if(file_exists('data/' . $this->page . '/html/' . $this->albumCode . '.html')); | 181 | if(file_exists('data/' . $this->page . '/html/' . $this->fileCode . '.' . $this->format)); |
126 | { | 182 | { |
127 | unlink('data/' . $this->page . '/html/' . $this->albumCode . '.html'); | 183 | $this->format = 'html'; |
184 | parent::delete(); | ||
128 | } | 185 | } |
129 | } | 186 | } |
130 | } | 187 | } |