1
|
|
|
<?php |
2
|
|
|
namespace modules\bataille\app\controller; |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
use core\App; |
6
|
|
|
use core\functions\ChaineCaractere; |
7
|
|
|
use core\HTML\flashmessage\FlashMessage; |
8
|
|
|
|
9
|
|
|
class ForumFaction extends Faction { |
10
|
|
|
private $id_forum; |
11
|
|
|
|
12
|
|
|
//-------------------------- BUILDER ----------------------------------------------------------------------------// |
13
|
|
|
public function __construct() { |
14
|
|
|
|
15
|
|
|
} |
16
|
|
|
//-------------------------- END BUILDER ----------------------------------------------------------------------------// |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
//-------------------------- GETTER ----------------------------------------------------------------------------// |
20
|
|
|
/** |
21
|
|
|
* fonction qui récupère les forums de la faction |
22
|
|
|
*/ |
23
|
|
|
public function getListeForum() { |
24
|
|
|
$dbc = App::getDb(); |
25
|
|
|
|
26
|
|
|
$query = $dbc->select()->from("_bataille_faction_forum")->where("ID_faction", "=", $this->id_faction)->get(); |
27
|
|
|
|
28
|
|
|
$forums = []; |
29
|
|
|
if ((count($query) > 0)) { |
30
|
|
|
foreach ($query as $obj) { |
31
|
|
|
$forums[] = [ |
32
|
|
|
"id_forum" => $obj->ID_faction_forum, |
33
|
|
|
"titre" => $obj->titre, |
34
|
|
|
"url" => $obj->url, |
35
|
|
|
"texte" => $obj->texte, |
36
|
|
|
"date_creation" => $obj->date_creation |
37
|
|
|
]; |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
Bataille::setValues(["forums" => $forums]); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param $titre |
46
|
|
|
* @return bool |
47
|
|
|
* fonction qui test si un forum aec ce titre existe déjà |
48
|
|
|
*/ |
49
|
|
View Code Duplication |
private function getForumExist($titre) { |
50
|
|
|
$dbc = App::getDb(); |
51
|
|
|
|
52
|
|
|
$query = $dbc->select("titre")->from("_bataille_faction_forum") |
53
|
|
|
->where("titre", "=", $titre, "AND") |
54
|
|
|
->where("ID_faction", "=", $this->id_faction) |
55
|
|
|
->get(); |
56
|
|
|
|
57
|
|
|
if (count($query) > 0) { |
58
|
|
|
return true; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return false; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param $id_forum |
66
|
|
|
* fonction qui va chercher un forum en particulier |
67
|
|
|
*/ |
68
|
|
|
public function getForum($id_forum) { |
69
|
|
|
$dbc = App::getDb(); |
70
|
|
|
$this->id_forum = $id_forum; |
71
|
|
|
|
72
|
|
|
$query = $dbc->select()->from("_bataille_faction_forum") |
73
|
|
|
->where("ID_faction", "=", $this->id_faction, "AND") |
74
|
|
|
->where("ID_faction_forum", "=", $this->id_forum) |
75
|
|
|
->get(); |
76
|
|
|
|
77
|
|
|
if (count($query) == 1) { |
78
|
|
|
foreach ($query as $obj) { |
79
|
|
|
Bataille::setValues([ |
80
|
|
|
"forum" => [ |
81
|
|
|
"id_forum" => $obj->ID_faction_forum, |
82
|
|
|
"titre" => $obj->titre, |
83
|
|
|
"texte" => $obj->texte, |
84
|
|
|
"date_creation" => $obj->date_creation |
85
|
|
|
] |
86
|
|
|
]); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$this->getCommentaireForum(); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* fonction qui récupère les commentaires d'un forum en particulier |
95
|
|
|
*/ |
96
|
|
|
private function getCommentaireForum() { |
97
|
|
|
$dbc = App::getDb(); |
98
|
|
|
|
99
|
|
|
$query = $dbc->select() |
100
|
|
|
->from("_bataille_faction_forum_commentaire") |
101
|
|
|
->from("identite") |
102
|
|
|
->where("ID_faction_forum", "=", $this->id_forum, "AND") |
103
|
|
|
->where("_bataille_faction_forum_commentaire.ID_identite", "=", "identite.ID_identite", "", true) |
104
|
|
|
->get(); |
105
|
|
|
|
106
|
|
|
if (count($query) > 0) { |
107
|
|
|
$commentaires = []; |
108
|
|
|
|
109
|
|
|
foreach ($query as $obj) { |
110
|
|
|
$commentaires[] = [ |
111
|
|
|
"id_commentaire" => $obj->ID_faction_forum_commentaire, |
112
|
|
|
"commentaire" => $obj->commentaire, |
113
|
|
|
"date_creation" => $obj->date_creation, |
114
|
|
|
"pseudo" => $obj->pseudo |
115
|
|
|
]; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
Bataille::setValues(["forum_commentaires" => $commentaires]); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
//-------------------------- END GETTER ----------------------------------------------------------------------------// |
122
|
|
|
|
123
|
|
|
|
124
|
|
|
//-------------------------- SETTER ----------------------------------------------------------------------------// |
125
|
|
|
/** |
126
|
|
|
* @param $titre |
127
|
|
|
* @param $texte |
128
|
|
|
* @return bool |
129
|
|
|
*/ |
130
|
|
|
public function setCreerForum($titre, $texte) { |
131
|
|
|
$dbc = App::getDb(); |
132
|
|
|
|
133
|
|
|
if ((strlen($titre) < 3) || (strlen($texte) < 3)) { |
134
|
|
|
FlashMessage::setFlash("Le tittre et le texte de votre forum doivent faire plus de 2 caractères"); |
135
|
|
|
return false; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
if ($this->getForumExist($titre) === true) { |
139
|
|
|
FlashMessage::setFlash("Un forum portant ce nom existe déjà, merci d'en choisir un autre"); |
140
|
|
|
return false; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
$dbc->insert("titre", $titre) |
144
|
|
|
->insert("url", ChaineCaractere::setUrl($titre)) |
145
|
|
|
->insert("texte", $texte) |
146
|
|
|
->insert("date_creation", date("Y-m-d H:i:s")) |
147
|
|
|
->insert("ID_faction", $this->id_faction) |
148
|
|
|
->into("_bataille_faction_forum") |
149
|
|
|
->set(); |
150
|
|
|
|
151
|
|
|
return true; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @param $url |
156
|
|
|
* fonction qui supprime un forum |
157
|
|
|
*/ |
158
|
|
|
public function setSupprimerForum($id_forum) { |
159
|
|
|
$dbc = App::getDb(); |
160
|
|
|
$permissions_membre = $this->getPermissionsMembre($this->id_faction); |
161
|
|
|
|
162
|
|
|
if ($permissions_membre == "chef" || in_array("GESTION_FORUM", $permissions_membre)) { |
163
|
|
|
$dbc->delete()->from("_bataille_faction_forum")->where("ID_faction_forum", "=", $id_forum, "AND")->where("ID_faction", "=", $this->id_faction)->del(); |
164
|
|
|
$dbc->delete()->from("_bataille_faction_forum_commentaire")->where("ID_faction_forum", "=", $id_forum)->del(); |
165
|
|
|
return true; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
FlashMessage::setFlash("Vous n'avez pas la permission de supprimer un forum"); |
169
|
|
|
return false; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @param $commentaire |
174
|
|
|
* @param $id_forum |
175
|
|
|
* @return bool |
176
|
|
|
* fonction qui permet d'ajouter un commentaire sur un forum |
177
|
|
|
*/ |
178
|
|
|
public function setAjouterCommentaire($commentaire, $id_forum) { |
179
|
|
|
$dbc = App::getDb(); |
180
|
|
|
|
181
|
|
|
if (strlen($commentaire) < 2) { |
182
|
|
|
FlashMessage::setFlash("Le commentaire faire plus de 1 caractère"); |
183
|
|
|
return false; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
$dbc->insert("commentaire", $commentaire) |
187
|
|
|
->insert("date_creation", date("Y-m-d H:i:s")) |
188
|
|
|
->insert("ID_faction_forum", $id_forum) |
189
|
|
|
->insert("ID_identite", Bataille::getIdIdentite()) |
190
|
|
|
->into("_bataille_faction_forum_commentaire") |
191
|
|
|
->set(); |
192
|
|
|
|
193
|
|
|
return true; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* @param $id_commentaire |
198
|
|
|
* @return bool |
199
|
|
|
* fonction qui permet de supprimer un commentaire sur un forum |
200
|
|
|
*/ |
201
|
|
View Code Duplication |
public function setSupprimerCommentaire($id_commentaire) { |
|
|
|
|
202
|
|
|
$dbc = App::getDb(); |
203
|
|
|
$permissions_membre = $this->getPermissionsMembre($this->id_faction); |
204
|
|
|
|
205
|
|
|
if ($permissions_membre == "chef" || in_array("GERER_POST_FORUM", $permissions_membre)) { |
206
|
|
|
$dbc->delete()->from("_bataille_faction_forum_commentaire") |
207
|
|
|
->where("ID_faction_forum_commentaire", "=", $id_commentaire, "AND") |
208
|
|
|
->where("ID_faction_forum", "=", $this->id_faction) |
209
|
|
|
->del(); |
210
|
|
|
|
211
|
|
|
return true; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
FlashMessage::setFlash("Vous n'avez pas la permission de supprimer un commentaire"); |
215
|
|
|
return false; |
216
|
|
|
} |
217
|
|
|
//-------------------------- END SETTER ----------------------------------------------------------------------------// |
218
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.