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