Completed
Push — master ( 69d4e5...2a9184 )
by Anthony
03:05
created

AdminArticle::setAddArticle()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 12
nc 2
nop 4
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) {
0 ignored issues
show
Unused Code introduced by
The parameter $categories is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
58
			$dbc = App::getDb();
59
			
60
			if ($this->getTestTitle($title) == false || $this->getTestArticle($article) == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
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
	}