Completed
Push — master ( ee7cb3...908239 )
by Anthony
02:07
created

Article::getArticle()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 22
rs 8.9197
cc 4
eloc 16
nc 3
nop 0
1
<?php
2
	namespace modules\blog\app\controller;
3
	
4
	
5
	use core\App;
6
	
7
	class Article {
8
		
9
		
10
		//-------------------------- BUILDER ----------------------------------------------------------------------------//
11
		public function __construct() {
12
			
13
		}
14
		//-------------------------- END BUILDER ----------------------------------------------------------------------------//
15
		
16
		
17
		//-------------------------- GETTER ----------------------------------------------------------------------------//
18
		/**
19
		 * this function get last articles
20
		 */
21
		public function getLastArticle() {
22
			$dbc = App::getDb();
23
			$nb_article = Blog::getArticleIndex();
24
			
25
			$query = $dbc->select()->from("_blog_article")->limit(0,$nb_article)->get();
26
			
27
			if ((is_array($query)) && (count($query) > 0)) {
28
				$articles = [];
29
				
30
				foreach ($query as $obj) {
31
					$articles[] = [
32
						"id_article" => $obj->ID_article,
33
						"title" => $obj->title,
34
						"url" => $obj->url,
35
						"article" => $obj->article,
36
						"publication_date" => $obj->publication_date,
37
						"categories" => Blog::getCategory()->getCategoryArticle($obj->url)
38
					];
39
				}
40
				
41
				Blog::setValues(["articles" => $articles]);
42
			}
43
		}
44
		
45
		public function getArticle() {
46
			$dbc = App::getDb();
47
			$param = Blog::$parametre_router;
48
			
49
			$query = $dbc->select()->from("_blog_article")
50
				->where("ID_article", "=", $param, "OR")
51
				->where("url", "=", $param)
52
				->get();
53
			
54
			if ((is_array($query)) && (count($query) == 1)) {
55
				foreach ($query as $obj) {
56
					Blog::setValues(["article" => [
57
						"id_article" => $obj->ID_article,
58
						"title" => $obj->title,
59
						"url" => $obj->url,
60
						"article" => $obj->article,
61
						"publication_date" => $obj->publication_date,
62
						"categories" => Blog::getCategory()->getCategoryArticle()
63
					]]);
64
				}
65
			}
66
		}
67
		//-------------------------- END GETTER ----------------------------------------------------------------------------//
68
		
69
		
70
		//-------------------------- SETTER ----------------------------------------------------------------------------//
71
		//-------------------------- END SETTER ----------------------------------------------------------------------------//    
72
	}