1
|
|
|
<?php |
2
|
|
|
namespace modules\blog\admin\controller; |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
use core\App; |
6
|
|
|
use core\functions\ChaineCaractere; |
7
|
|
|
use core\HTML\flashmessage\FlashMessage; |
8
|
|
|
|
9
|
|
|
class AdminArticle { |
10
|
|
|
private $error_title; |
11
|
|
|
private $error_article; |
12
|
|
|
|
13
|
|
|
//-------------------------- BUILDER ----------------------------------------------------------------------------// |
14
|
|
|
public function __construct() { |
15
|
|
|
|
16
|
|
|
} |
17
|
|
|
//-------------------------- END BUILDER ----------------------------------------------------------------------------// |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
//-------------------------- GETTER ----------------------------------------------------------------------------// |
21
|
|
|
/** |
22
|
|
|
* @param $title |
23
|
|
|
* @return bool |
24
|
|
|
* function that verify if title of the article is ok |
25
|
|
|
*/ |
26
|
|
|
private function getTestTitle($title) { |
27
|
|
|
$dbc = App::getDb(); |
28
|
|
|
|
29
|
|
|
if (ChaineCaractere::testMinLenght($title, 4) == false) { |
30
|
|
|
$this->error_title = "votre titre doit être supérieur à 4 caractères"; |
31
|
|
|
return false; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
if (strlen($title) > 20) { |
35
|
|
|
$this->error_title = "votre titre ne doit pas eccéder 20 caractères"; |
36
|
|
|
return false; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$query = $dbc->select()->from("_blog_article")->where("title", "=", $title)->get(); |
40
|
|
|
|
41
|
|
|
if (count($query) > 0) { |
42
|
|
|
$this->error_title = "votre titre existe déjà merci d'en choisir un autre"; |
43
|
|
|
return false; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
return true; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param $article |
51
|
|
|
* @return bool |
52
|
|
|
* function that verify if article is ok |
53
|
|
|
*/ |
54
|
|
|
private function getTestArticle($article) { |
55
|
|
|
if (ChaineCaractere::testMinLenght($article, 10) == false) { |
56
|
|
|
$this->error_article = "votre article doit être supérieur à 10 caractères"; |
57
|
|
|
return false; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return true; |
61
|
|
|
} |
62
|
|
|
//-------------------------- END GETTER ----------------------------------------------------------------------------// |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
//-------------------------- SETTER ----------------------------------------------------------------------------// |
66
|
|
|
/** |
67
|
|
|
* @param $title |
68
|
|
|
* @param $categories |
69
|
|
|
* @param $article |
70
|
|
|
* @param $state |
71
|
|
|
* @return bool |
72
|
|
|
* function to add an article and his categories |
73
|
|
|
*/ |
74
|
|
|
public function setAddArticle($title, $categories, $article, $state) { |
75
|
|
|
$dbc = App::getDb(); |
76
|
|
|
|
77
|
|
|
if ($this->getTestTitle($title) == false || $this->getTestArticle($article) == false) { |
|
|
|
|
78
|
|
|
FlashMessage::setFlash($this->error_title.$this->error_article); |
79
|
|
|
return false; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$dbc->insert("title", $title) |
83
|
|
|
->insert("url", ChaineCaractere::setUrl($title)) |
84
|
|
|
->insert("publication_date", date("Y-m-d H:i:s")) |
85
|
|
|
->insert("article", $article) |
86
|
|
|
->insert("ID_identite", $_SESSION['idlogin'.CLEF_SITE]) |
87
|
|
|
->insert("ID_state", $state) |
88
|
|
|
->into("_blog_article")->set(); |
89
|
|
|
|
90
|
|
|
$id_article = $dbc->lastInsertId(); |
91
|
|
|
|
92
|
|
|
AdminBlog::getAdminCategory()->setCategoriesArticle($categories, $id_article); |
93
|
|
|
return true; |
94
|
|
|
} |
95
|
|
|
//-------------------------- END SETTER ----------------------------------------------------------------------------// |
96
|
|
|
} |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.