|
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
|
|
|
if (ChaineCaractere::testMinLenght($title, 4) == false) { |
|
28
|
|
|
$this->error_title = "votre titre doit être supérieur à 4 caractères"; |
|
29
|
|
|
return false; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
if (strlen($title) > 20) { |
|
33
|
|
|
$this->error_title = "votre titre ne doit pas eccéder 20 caractères"; |
|
34
|
|
|
return false; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
return true; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param $article |
|
42
|
|
|
* @return bool |
|
43
|
|
|
* function that verify if article is ok |
|
44
|
|
|
*/ |
|
45
|
|
|
private function getTestArticle($article) { |
|
46
|
|
|
if (ChaineCaractere::testMinLenght($article, 10) == false) { |
|
47
|
|
|
$this->error_article = "votre article doit être supérieur à 10 caractères"; |
|
48
|
|
|
return false; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return true; |
|
52
|
|
|
} |
|
53
|
|
|
//-------------------------- END GETTER ----------------------------------------------------------------------------// |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
//-------------------------- SETTER ----------------------------------------------------------------------------// |
|
57
|
|
|
public function setAddArticle($title, $categories, $article, $state) { |
|
|
|
|
|
|
58
|
|
|
$dbc = App::getDb(); |
|
59
|
|
|
|
|
60
|
|
|
if ($this->getTestTitle($title) == false || $this->getTestArticle($article) == false) { |
|
|
|
|
|
|
61
|
|
|
FlashMessage::setFlash($this->error_title.$this->error_article); |
|
62
|
|
|
return false; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$dbc->insert("title", $title) |
|
66
|
|
|
->insert("url", ChaineCaractere::setUrl($title)) |
|
67
|
|
|
->insert("publication_date", date("Y-m-d H:i:s")) |
|
68
|
|
|
->insert("article", $article) |
|
69
|
|
|
->insert("ID_identite", $_SESSION['idlogin'.CLEF_SITE]) |
|
70
|
|
|
->insert("ID_state", $state) |
|
71
|
|
|
->into("_blog_article")->set(); |
|
72
|
|
|
} |
|
73
|
|
|
//-------------------------- END SETTER ----------------------------------------------------------------------------// |
|
74
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.