summaryrefslogtreecommitdiff
path: root/model
diff options
context:
space:
mode:
authorpolo <contact@ordipolo.fr>2021-05-27 22:53:52 +0200
committerpolo <contact@ordipolo.fr>2021-06-30 22:25:53 +0200
commit084cdf0c67e05c63581d2ba211adc3e5d19635de (patch)
tree65e91fe8cd8840af1de8d97e2496e8260d0febf4 /model
parent47d66d5ee1d11afbe01ebc1b92ce0ec58d7c30d8 (diff)
downloadmelaine-084cdf0c67e05c63581d2ba211adc3e5d19635de.zip
crud
Signed-off-by: polo <contact@ordipolo.fr>
Diffstat (limited to 'model')
-rw-r--r--model/Article.php51
1 files changed, 29 insertions, 22 deletions
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
25 25
26 $this->nbArticles = count($this->files); 26 $this->nbArticles = count($this->files);
27 } 27 }
28
29 // fonctions CRUD (create - read - update - delete)
30 // ce sont les 4 opérations de base qu'un programme doit permettre pour être complet
31
32 // create
33 public function create($content)
34 {
35 if($this->page == '')
36 {
37 die("debug: la méthode setPage() doit être appelée avant toute autre.");
38 }
39
40 $nom_fichier = time() . '.html';
41 $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
42 fputs($fichier, $content);
43 fclose($fichier);
44 chmod('data/' . $this->page . '/html/' . $nom_fichier, 0666);
45 }
28 46
47 // read
29 public function getNb() 48 public function getNb()
30 { 49 {
31 return $this->nbArticles; 50 return $this->nbArticles;
32 } 51 }
52
53 public function getOne()
54 {}
33 55
34 public function getAll($croissant) 56 public function getAll($croissant)
35 { 57 {
@@ -47,9 +69,6 @@ class Article
47 return $articles; 69 return $articles;
48 } 70 }
49 71
50 public function getOne()
51 {}
52
53 public function getDate($fileNumber) 72 public function getDate($fileNumber)
54 { 73 {
55 // le 2è paramètre exclut le suffixe .html 74 // le 2è paramètre exclut le suffixe .html
@@ -57,28 +76,16 @@ class Article
57 return getdate($timestamp); 76 return getdate($timestamp);
58 } 77 }
59 78
60 public function new($content) 79 // update
61 {
62 if($this->page == '')
63 {
64 die("debug: la méthode setPage() doit être appelée avant toute autre.");
65 }
66
67 $nom_fichier = time() . '.html';
68 $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
69 fputs($fichier, $content);
70 fclose($fichier);
71 chmod('data/' . $this->page . '/html/' . $nom_fichier, 0666);
72 }
73
74 public function update() 80 public function update()
75 {} 81 {}
76 82
77 public function remove()
78 {}
79
80 public function setPage($page) 83 public function setPage($page)
81 { 84 {
82 $this->page = $page; 85 $this->page = $page;
83 } 86 }
84} \ No newline at end of file 87
88 // delete
89 public function delete()
90 {}
91}