summaryrefslogtreecommitdiff
path: root/model/Classes.php
diff options
context:
space:
mode:
Diffstat (limited to 'model/Classes.php')
-rw-r--r--model/Classes.php201
1 files changed, 0 insertions, 201 deletions
diff --git a/model/Classes.php b/model/Classes.php
deleted file mode 100644
index 97a137a..0000000
--- a/model/Classes.php
+++ /dev/null
@@ -1,201 +0,0 @@
1<?php
2// model/Classes.php
3
4class AllArticles
5{
6 protected $page; // page et donc dossier concerné
7 protected $format = 'html'; // vaut 'html' ou 'json'
8 protected $files; // noms des fichiers dans ce dossier
9 protected $time; // timestamp pour création de fichiers
10 private $articles; // contenu
11 private $nbArticles; // un fichier = un article
12
13 // en paramètre à l'instanciation
14 public function __construct($page)
15 {
16 $this->page = $page;
17 $this->time = time();
18 if($this->page == 'discographie')
19 {
20 $this->format = 'json';
21 }
22 }
23
24 // GET
25 public function getPage()
26 {
27 return($this->page);
28 }
29
30 public function getNbArticles()
31 {
32 return($this->nbArticles);
33 }
34 public function getFileList()
35 {
36 return($this->files);
37 }
38
39 // SET
40 public function setFormat($format)
41 {
42 $this->format = $format;
43 }
44
45 // tableaux des noms des fichiers
46 public function makeFileList()
47 {
48 $this->files = glob('data/' . $this->page . '/' . $this->format . '/*.' . $this->format);
49 //$this->files = glob('*.' . $this->format);
50 }
51 /*public function makeFilePath()
52 {}*/
53
54 // fonctions CRUD (create - read - update - delete)
55
56 // create
57
58 // read
59 public function readAll()
60 {
61 $i = 0;
62 $articles = array();
63 foreach ($this->files as $oneFile)
64 {
65 $articles[$i] = file_get_contents($oneFile);
66 $i++;
67 }
68 //print_r($articles);
69 return $articles;
70 }
71
72 // update
73
74 // delete
75}
76
77// article créé ou ciblé pour modification/suppression
78class OneArticle extends AllArticles
79{
80 private $fileName; // correspond à $_SESSION['nomFichier']
81
82 // GET
83 public function getFileName()
84 {
85 return($this->fileName);
86 }
87
88 // SET
89 public function setFileName($nomFichier) // modification
90 {
91 $this->fileName = $nomFichier;
92 }
93
94 public function findFileName($numArticle) // nouvel article
95 {
96 $this->fileName = $this->files[$numArticle - 1];
97 }
98
99 // fonctions CRUD (create - read - update - delete)
100
101 // create
102 public function create($content)
103 {
104 $format = 'html';
105
106 // nommer les fichiers avec le timestamp pour:
107 // - les trier par ordre chronologique
108 // - rendre quasi impossible d'avoir deux fois le même nom (à la condition de gérer la "concurrence")
109 $nom_fichier = 'data/' . $this->page . '/' . $format . '/' . $this->time . '.' . $format;
110
111 $fichier = fopen($nom_fichier, 'w'); // w pour créer ou écraser
112 fputs($fichier, $content);
113 fclose($fichier);
114 chmod($nom_fichier, 0666);
115 }
116
117 // read
118 public function readOne()
119 {
120 return(file_get_contents($this->fileName));
121 }
122 public static function readOneAlbum($albumCode)
123 {
124 return(file_get_contents('data/discographie/html/' . $albumCode . '.html'));
125 }
126
127 // pour afficher des dates
128 /*public function getDate($fileNumber)
129 {
130 // le 2è paramètre exclut le suffixe .html
131 $timestamp = basename($this->files[$fileNumber], '.html');
132 return getdate($timestamp);
133 }*/
134
135 // update
136 public function update($content)
137 {
138 $file = fopen($this->fileName, 'w'); // crée ou écrase
139 fputs($file, $content);
140 fclose($file);
141 //chown($this->fileName, 'http');
142 chmod($this->fileName, 0666);
143 }
144
145 // delete
146 public function delete()
147 {
148 unlink($this->fileName);
149 }
150}
151
152
153class Album extends OneArticle
154{
155 // variables
156 //private $fileNameJSON; // même nom en .json
157
158 // GET
159
160 // SET
161
162 // fonctions CRUD
163 // create
164 public function createVignette($titre, $annee, $pochette)
165 {
166 $this->format = 'json';
167
168 if($pochette != '')
169 {
170 // télécharger la pochette
171 require('model/Image.php');
172 $Image = new Image(false);
173 $Image->upload();
174
175 /*$erreur = $Image->getError();
176 if(!empty($erreur))
177 {}*/
178 }
179
180 $albumJSON = json_encode([$titre, $annee, $pochette]);
181
182 $nom_fichier = 'data/' . $this->page . '/' . $this->format . '/' . $this->time . '.' . $this->format;
183
184 $fichier = fopen($nom_fichier, 'w'); // w pour créer ou écraser
185 fputs($fichier, $albumJSON);
186 fclose($fichier);
187 chmod($nom_fichier, 0666);
188 }
189
190 // read
191 public function read()
192 {}
193
194 // update
195 public function updateVignette($titre, $annee, $pochette)
196 {}
197
198 // delete
199 public function delete()
200 {}
201} \ No newline at end of file