Completed
Push — master ( 8271d0...ee7cb3 )
by Anthony
02:03
created

Category::getCategoryArticle()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 25
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 18
nc 3
nop 0
1
<?php
2
	namespace modules\blog\app\controller;
3
	
4
	
5
	use core\App;
6
	
7
	class Category {
8
		
9
		
10
		//-------------------------- BUILDER ----------------------------------------------------------------------------//
11
		public function __construct() {
12
			
13
		}
14
		//-------------------------- END BUILDER ----------------------------------------------------------------------------//
15
		
16
		
17
		//-------------------------- GETTER ----------------------------------------------------------------------------//
18
		/**
19
		 * get all categories of an article
20
		 */
21
		public function getCategoryArticle() {
22
			$dbc = App::getDb();
23
			
24
			$query = $dbc->select()
25
				->from("_blog_article")
26
				->from("_blog_category")
27
				->from("_blog_article_category")
28
				->where("_blog_article.ID_article", "=", Blog::$parametre_router, "OR")
29
				->where("_blog_article.url", "=", Blog::$parametre_router, "AND")
30
				->where("_blog_article_category.ID_article", "=", "_blog_article.ID_article", "AND", true)
31
				->where("_blog_article_category.ID_category", "=", "_blog_category.ID_category", "", true)
32
				->get();
33
			
34
			if ((is_array($query)) && (count($query) > 0)) {
35
				$categories = [];
36
				foreach ($query as $obj) {
37
					$categories = [
38
						"id_category" => $obj->ID_category,
39
						"category" => $obj->category
40
					];
41
				}
42
				
43
				App::setValues(["categories" => $categories]);
44
			}
45
		}
46
		//-------------------------- END GETTER ----------------------------------------------------------------------------//
47
		
48
		
49
		//-------------------------- SETTER ----------------------------------------------------------------------------//
50
		//-------------------------- END SETTER ----------------------------------------------------------------------------//    
51
	}