1
|
|
|
<?php |
2
|
|
|
namespace modules\comment\app\controller; |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
use core\App; |
6
|
|
|
|
7
|
|
|
class Comment { |
8
|
|
|
private $required_connection; |
9
|
|
|
private $check_comment; |
10
|
|
|
private $table; |
11
|
|
|
private $nom_id_table; |
12
|
|
|
private $id_in_table; |
13
|
|
|
|
14
|
|
|
//-------------------------- BUILDER ----------------------------------------------------------------------------// |
15
|
|
|
public function __construct() { |
16
|
|
|
$dbc = App::getDb(); |
17
|
|
|
|
18
|
|
|
$query = $dbc->select()->from("_comment_configuration")->where("ID_configuration", "=", 1)->get(); |
19
|
|
|
|
20
|
|
|
if ((is_array($query)) && (count($query) > 0)) { |
21
|
|
|
foreach ($query as $obj) { |
22
|
|
|
$this->required_connection = $obj->required_connection; |
23
|
|
|
$this->check_comment = $obj->check_comment_publish; |
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
else { |
27
|
|
|
$this->required_connection = 0; |
28
|
|
|
$this->check_comment = 0; |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
//-------------------------- END BUILDER ----------------------------------------------------------------------------// |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
|
35
|
|
|
//-------------------------- GETTER ----------------------------------------------------------------------------// |
36
|
|
|
public function getRequiredConnection() { |
37
|
|
|
return $this->required_connection; |
38
|
|
|
} |
39
|
|
|
public function getCheckComment() { |
40
|
|
|
return $this->check_comment; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param $values |
45
|
|
|
* @return string |
46
|
|
|
* this function will get the view of list comments and form to write a comment |
47
|
|
|
*/ |
48
|
|
|
private function getRender($values) { |
49
|
|
|
ob_start(); |
50
|
|
|
foreach ($values as $value) { |
51
|
|
|
require(MODULEROOT."comment/app/views/list-comment.php"); |
52
|
|
|
} |
53
|
|
|
require(MODULEROOT."comment/app/views/write-comment.php"); |
54
|
|
|
$comments = ob_get_clean(); |
55
|
|
|
|
56
|
|
|
return $comments; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param $table |
61
|
|
|
* @param $nom_id_table |
62
|
|
|
* @param $id_in_table |
63
|
|
|
* function wich get all comments of an other module like a article of a blog |
64
|
|
|
* after all coments was getted it will call getRender to use twig to render them |
65
|
|
|
*/ |
66
|
|
|
public function getComments($table, $nom_id_table, $id_in_table) { |
67
|
|
|
$dbc = App::getDb(); |
68
|
|
|
|
69
|
|
|
$query = $dbc->select()->from("_comment_all")->where("nom_table", "=", $table, "AND") |
70
|
|
|
->where("nom_id_table", "=", $nom_id_table, "AND")->where("ID_in_table", "=", $id_in_table)->get(); |
71
|
|
|
|
72
|
|
|
$values = []; |
73
|
|
|
if (count($query) > 0) { |
74
|
|
|
foreach ($query as $obj) { |
75
|
|
|
$values[] = [ |
76
|
|
|
"comment" => $obj->comment, |
77
|
|
|
"date" => $obj->date, |
78
|
|
|
"first_name" => $obj->first_name, |
79
|
|
|
"last_name" => $obj->last_name, |
80
|
|
|
"id_identite" => $obj->ID_identite, |
81
|
|
|
]; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$this->table = $table; |
86
|
|
|
$this->nom_id_table = $nom_id_table; |
87
|
|
|
$this->id_in_table = $id_in_table; |
88
|
|
|
|
89
|
|
|
return $this->getRender($values); |
90
|
|
|
} |
91
|
|
|
//-------------------------- END GETTER ----------------------------------------------------------------------------// |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
|
95
|
|
|
//-------------------------- SETTER ----------------------------------------------------------------------------// |
96
|
|
|
public function setComment($table, $nom_id_table, $id_in_table) { |
|
|
|
|
97
|
|
|
|
98
|
|
|
} |
99
|
|
|
//-------------------------- END SETTER ----------------------------------------------------------------------------// |
100
|
|
|
|
101
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.