1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
<?php
// model/Album.php
class Album extends Page // classe "objet"
{
public function __construct($page)
{
$this->page = $page;
$this->albumCode = ''; // désigne un fichier json et un html
$this->format = 'json'; // vaut 'html' dans la classe mère
$this->time = time();
}
// GET
// SET
// fonctions CRUD
// create
public function createVignette($titre, $annee, $pochette)
{
//$this->format = 'json';
if($pochette != '')
{
// télécharger la pochette
require('model/Image.php');
$Image = new Image(false);
$Image->upload();
/*$erreur = $Image->erreur;
if(!empty($erreur))
{}*/
}
$albumJSON = json_encode([$titre, $annee, $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()
{
// lecture des données
$albumsJSON = parent::readAll();
// conversion des chaines JSON en tableaux: titre, année, pochette
for($i = 0; $i < count($albumsJSON); $i++)
{
$albumsJSON[$i] = json_decode($albumsJSON[$i], true);
}
return($albumsJSON);
}
public function getVignetteJSON()
{
return(json_decode(file_get_contents('data/discographie/json/' . $this->albumCode . '.json')));
}
// page de l'album
public static function readOneHTML($albumCode)
{
if(file_exists('data/discographie/html/' . $albumCode . '.html'))
{
return(file_get_contents('data/discographie/html/' . $albumCode . '.html'));
}
else
{
return('');
}
}
// pour afficher des dates
/*public function getDate($fileNumber)
{
// le 2è paramètre exclut le suffixe .html
$timestamp = basename($this->files[$fileNumber], '.html');
return getdate($timestamp);
}*/
// 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();
}
$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()
{
unlink('data/' . $this->page . '/' . $this->format . '/' . $this->albumCode . '.json');
if(file_exists('data/' . $this->page . '/html/' . $this->albumCode . '.html'));
{
unlink('data/' . $this->page . '/html/' . $this->albumCode . '.html');
}
}
}
|