From 610291f311aeab7363d1dbc39e62cbce8533c73f Mon Sep 17 00:00:00 2001 From: polo Date: Mon, 10 May 2021 03:31:18 +0200 Subject: classe --- model/Article.php | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 model/Article.php (limited to 'model/Article.php') diff --git a/model/Article.php b/model/Article.php new file mode 100644 index 0000000..cee594f --- /dev/null +++ b/model/Article.php @@ -0,0 +1,84 @@ +page == '') + { + die("debug: la méthode setPage() doit être appelée avant toute autre."); + } + + $this->files = glob('data/' . $this->page . '/html/*.html'); + + if($croissant == False) + { + $files = array_reverse($files); + } + + $this->nbArticles = count($this->files); + } + + public function getNb() + { + return $this->nbArticles; + } + + public function getAll($croissant) + { + $this->croissant = $croissant; + + getFiles(); + + $i = 0; + foreach ($this->files as $file) + { + $articles[$i] = file_get_contents($file); + $i++; + } + + return $articles; + } + + public function getOne() + {} + + public function getDate($fileNumber) + { + // le 2è paramètre exclut le suffixe .html + $timestamp = basename($this->files[$fileNumber], '.html'); + return getdate($timestamp); + } + + public function new($content) + { + if($this->page == '') + { + die("debug: la méthode setPage() doit être appelée avant toute autre."); + } + + $nom_fichier = time() . '.html'; + $fichier = fopen('data/' . $this->page . '/html/' . $nom_fichier, 'w'); // w peut créer un fichier, si il existe déjà, il est effacé par le nouveau contenu + fputs($fichier, $content); + fclose($fichier); + chmod('data/' . $this->page . '/html/' . $nom_fichier, 0666); + } + + public function update() + {} + + public function remove() + {} + + public function setPage($page) + { + $this->page = $page; + } +} \ No newline at end of file -- cgit v1.2.3