From b97a68343ec5c4ff1fae25ff5dc41f1a2ce6a17f Mon Sep 17 00:00:00 2001 From: polo Date: Fri, 26 Nov 2021 04:29:10 +0100 Subject: =?UTF-8?q?disco=20modif/suppr=20d=C3=A9sordre?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/Page.php | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 model/Page.php (limited to 'model/Page.php') diff --git a/model/Page.php b/model/Page.php new file mode 100644 index 0000000..e03efe1 --- /dev/null +++ b/model/Page.php @@ -0,0 +1,97 @@ +page = $page; + $this->format = $format; + $this->time = time(); + $this->makeFileList(); + } + + // tableaux des noms des fichiers + public function makeFileList() + { + $this->fileList = glob('data/' . $this->page . '/' . $this->format . '/*.' . $this->format); + //$this->files = glob('*.' . $this->format); + } + /*public function makeFilePath() + {}*/ + + // nom d'un fichier + public function findFileName($numArticle) + { + if($numArticle > 0) + { + $this->fileName = $this->fileList[$numArticle - 1]; + } + } + + // GET + + // SET + + // fonctions CRUD (create - read - update - delete) + + // create + public function create($content) + { + $format = 'html'; + + // nommer les fichiers avec le timestamp pour: + // - les trier par ordre chronologique + // - rendre quasi impossible d'avoir deux fois le même nom (à la condition de gérer la "concurrence") + $nom_fichier = 'data/' . $this->page . '/' . $format . '/' . $this->time . '.' . $format; + + $fichier = fopen($nom_fichier, 'w'); // w pour créer ou écraser + fputs($fichier, $content); + fclose($fichier); + chmod($nom_fichier, 0666); + } + + // read + public function readAll() + { + $i = 0; + $articles = array(); + foreach ($this->fileList as $oneFile) + { + $articles[$i] = file_get_contents($oneFile); + $i++; + } + //print_r($articles); + return $articles; + } + public function readOne() + { + return(file_get_contents($this->fileName)); + } + + // update + public function update($content) + { + $file = fopen($this->fileName, 'w'); // crée ou écrase + fputs($file, $content); + fclose($file); + //chown($this->fileName, 'http'); + chmod($this->fileName, 0666); + } + + // delete + public function delete() + { + unlink($this->fileName); + } +} \ No newline at end of file -- cgit v1.2.3