diff options
Diffstat (limited to 'model/Album.php')
-rw-r--r-- | model/Album.php | 73 |
1 files changed, 64 insertions, 9 deletions
diff --git a/model/Album.php b/model/Album.php index 2254c10..1631c46 100644 --- a/model/Album.php +++ b/model/Album.php | |||
@@ -6,6 +6,7 @@ class Album extends Page // classe "objet" | |||
6 | public function __construct($page) | 6 | public function __construct($page) |
7 | { | 7 | { |
8 | $this->page = $page; | 8 | $this->page = $page; |
9 | $this->albumCode = ''; // désigne un fichier json et un html | ||
9 | $this->format = 'json'; // vaut 'html' dans la classe mère | 10 | $this->format = 'json'; // vaut 'html' dans la classe mère |
10 | $this->time = time(); | 11 | $this->time = time(); |
11 | } | 12 | } |
@@ -19,7 +20,7 @@ class Album extends Page // classe "objet" | |||
19 | // create | 20 | // create |
20 | public function createVignette($titre, $annee, $pochette) | 21 | public function createVignette($titre, $annee, $pochette) |
21 | { | 22 | { |
22 | $this->format = 'json'; | 23 | //$this->format = 'json'; |
23 | 24 | ||
24 | if($pochette != '') | 25 | if($pochette != '') |
25 | { | 26 | { |
@@ -28,7 +29,7 @@ class Album extends Page // classe "objet" | |||
28 | $Image = new Image(false); | 29 | $Image = new Image(false); |
29 | $Image->upload(); | 30 | $Image->upload(); |
30 | 31 | ||
31 | /*$erreur = $Image->getError(); | 32 | /*$erreur = $Image->erreur; |
32 | if(!empty($erreur)) | 33 | if(!empty($erreur)) |
33 | {}*/ | 34 | {}*/ |
34 | } | 35 | } |
@@ -41,18 +42,41 @@ class Album extends Page // classe "objet" | |||
41 | fputs($fichier, $albumJSON); | 42 | fputs($fichier, $albumJSON); |
42 | fclose($fichier); | 43 | fclose($fichier); |
43 | chmod($nom_fichier, 0666); | 44 | chmod($nom_fichier, 0666); |
45 | |||
46 | return($Image->erreur); | ||
44 | } | 47 | } |
45 | 48 | ||
46 | // read | 49 | // read |
47 | public function getVignette() | 50 | public function readAll() |
51 | { | ||
52 | // lecture des données | ||
53 | $albumsJSON = parent::readAll(); | ||
54 | |||
55 | // conversion des chaines JSON en tableaux: titre, année, pochette | ||
56 | for($i = 0; $i < count($albumsJSON); $i++) | ||
57 | { | ||
58 | $albumsJSON[$i] = json_decode($albumsJSON[$i], true); | ||
59 | } | ||
60 | |||
61 | return($albumsJSON); | ||
62 | } | ||
63 | |||
64 | public function getVignetteJSON() | ||
48 | { | 65 | { |
49 | return(file_get_contents($this->fileName)); | 66 | return(json_decode(file_get_contents('data/discographie/json/' . $this->albumCode . '.json'))); |
50 | } | 67 | } |
51 | 68 | ||
52 | // page de l'album | 69 | // page de l'album |
53 | public static function readOneAlbum($albumCode) | 70 | public static function readOneHTML($albumCode) |
54 | { | 71 | { |
55 | return(file_get_contents('data/discographie/html/' . $albumCode . '.html')); | 72 | if(file_exists('data/discographie/html/' . $albumCode . '.html')) |
73 | { | ||
74 | return(file_get_contents('data/discographie/html/' . $albumCode . '.html')); | ||
75 | } | ||
76 | else | ||
77 | { | ||
78 | return(''); | ||
79 | } | ||
56 | } | 80 | } |
57 | 81 | ||
58 | // pour afficher des dates | 82 | // pour afficher des dates |
@@ -64,12 +88,43 @@ class Album extends Page // classe "objet" | |||
64 | }*/ | 88 | }*/ |
65 | 89 | ||
66 | // update | 90 | // update |
67 | public function updateVignette() | 91 | public function updateVignetteJSON($titre, $annee, $pochette) |
68 | {} | 92 | { |
93 | // garder l'ancienne image | ||
94 | $albumJSON = self::getVignetteJSON(); | ||
95 | |||
96 | if($pochette == '') | ||
97 | { | ||
98 | $pochette = $albumJSON[2]; | ||
99 | } | ||
100 | else | ||
101 | { | ||
102 | // télécharger la pochette | ||
103 | require('model/Image.php'); | ||
104 | $Image = new Image(false); | ||
105 | $Image->upload(); | ||
106 | } | ||
107 | |||
108 | $albumJSON = json_encode([$titre, $annee, $pochette]); | ||
109 | |||
110 | // écriture | ||
111 | $nom_fichier = 'data/discographie/json/' . $this->albumCode . '.json'; | ||
112 | $fichier = fopen($nom_fichier, 'w+'); // w pour créer ou écraser | ||
113 | fputs($fichier, $albumJSON); | ||
114 | fclose($fichier); | ||
115 | chmod($nom_fichier, 0666); | ||
116 | |||
117 | return($Image->erreur); | ||
118 | } | ||
69 | 119 | ||
70 | // delete | 120 | // delete |
71 | public function delete() | 121 | public function delete() |
72 | { | 122 | { |
73 | unlink($this->fileName); | 123 | unlink('data/' . $this->page . '/' . $this->format . '/' . $this->albumCode . '.json'); |
124 | |||
125 | if(file_exists('data/' . $this->page . '/html/' . $this->albumCode . '.html')); | ||
126 | { | ||
127 | unlink('data/' . $this->page . '/html/' . $this->albumCode . '.html'); | ||
128 | } | ||
74 | } | 129 | } |
75 | } | 130 | } |