From 084cdf0c67e05c63581d2ba211adc3e5d19635de Mon Sep 17 00:00:00 2001 From: polo Date: Thu, 27 May 2021 22:53:52 +0200 Subject: crud Signed-off-by: polo --- model/Article.php | 51 +++++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 22 deletions(-) (limited to 'model') diff --git a/model/Article.php b/model/Article.php index cee594f..afcb1ca 100644 --- a/model/Article.php +++ b/model/Article.php @@ -25,11 +25,33 @@ class Article $this->nbArticles = count($this->files); } + + // fonctions CRUD (create - read - update - delete) + // ce sont les 4 opérations de base qu'un programme doit permettre pour être complet + + // create + public function create($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); + } + // read public function getNb() { return $this->nbArticles; } + + public function getOne() + {} public function getAll($croissant) { @@ -47,9 +69,6 @@ class Article return $articles; } - public function getOne() - {} - public function getDate($fileNumber) { // le 2è paramètre exclut le suffixe .html @@ -57,28 +76,16 @@ class Article 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); - } - + // update public function update() {} - - public function remove() - {} - + public function setPage($page) { $this->page = $page; } -} \ No newline at end of file + + // delete + public function delete() + {} +} -- cgit v1.2.3