Completed
Push — master ( 0ddad3...b5072f )
by Anthony
02:20
created

Category::getNamemCategorieUrl()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
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
			$dbc = App::getDb();
13
			
14
			$query = $dbc->select()->from("_blog_category")->get();
15
			
16 View Code Duplication
			if ((is_array($query)) && (count($query) > 0)) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
				$categories = [];
18
				
19
				foreach ($query as $obj) {
20
					$categories[] = [
21
						"id_category" => $obj->ID_category,
22
						"category" => $obj->category,
23
						"url_category" => $obj->url_category
24
					];
25
				}
26
				
27
				Blog::setValues(["categories_list" => $categories]);
28
			}
29
		}
30
		//-------------------------- END BUILDER ----------------------------------------------------------------------------//
31
		
32
		
33
		//-------------------------- GETTER ----------------------------------------------------------------------------//
34
		/**
35
		 * get all categories of an article
36
		 */
37
		public function getCategoryArticle($id_article = null) {
38
			$dbc = App::getDb();
39
			
40
			if ($id_article === null) {
41
				$id_article = Blog::$router_parameter;
42
			}
43
			
44
			$query = $dbc->select()
45
				->from("_blog_article")
46
				->from("_blog_category")
47
				->from("_blog_article_category")
48
				->where("_blog_article.ID_article", "=", $id_article, "OR")
49
				->where("_blog_article.url", "=", $id_article, "AND")
50
				->where("_blog_article_category.ID_article", "=", "_blog_article.ID_article", "AND", true)
51
				->where("_blog_article_category.ID_category", "=", "_blog_category.ID_category", "", true)
52
				->get();
53
			
54 View Code Duplication
			if ((is_array($query)) && (count($query) > 0)) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
				$categories = [];
56
				foreach ($query as $obj) {
57
					$categories[] = [
58
						"id_category" => $obj->ID_category,
59
						"category" => $obj->category,
60
						"url_category" => $obj->url_category
61
					];
62
				}
63
				
64
				return $categories;
65
			}
66
		}
67
		
68
		public function getNamemCategorieUrl() {
69
			$dbc = App::getDb();
70
			$url_category = Blog::$router_parameter;
71
			
72
			$query = $dbc->select("category")->from("_blog_category")->where("url_category", "=", $url_category)->get();
73
			
74
			foreach ($query as $obj) {
75
				return $obj->category;
76
			}
77
		}
78
		//-------------------------- END GETTER ----------------------------------------------------------------------------//
79
		
80
		
81
		//-------------------------- SETTER ----------------------------------------------------------------------------//
82
		//-------------------------- END SETTER ----------------------------------------------------------------------------//    
83
	}