Completed
Push — master ( 866768...7302b5 )
by Anthony
03:32
created

AdminComment::setValues()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
	namespace modules\comment\admin\controller;
3
	
4
	use core\App;
5
	use modules\comment\app\controller\Comment;
6
	
7
	class AdminComment extends Comment {
8
		private $values = [];
9
		
10
		//-------------------------- BUILDER ----------------------------------------------------------------------------//
11
		//-------------------------- END BUILDER ----------------------------------------------------------------------------//
12
		
13
		
14
		//-------------------------- GETTER ----------------------------------------------------------------------------//
15
		/**
16
		 * @return array
17
		 * function to get values out of the class
18
		 */
19
		public function getValues(){
20
			return ["comment" => $this->values];
21
		}
22
		
23
		/**
24
		 * function that get a list of all table_name wich are in comment module
25
		 */
26
		public function getAllTableComment() {
27
			$dbc = App::getDb();
28
			
29
			$query = $dbc->select("table_name")->from("_comment_all")->groupBy("table_name")->get();
30
			
31
			if ((is_array($query)) && (count($query) > 0)) {
32
				$values = [];
33
				foreach ($query as $obj) {
34
					$values[] = [
35
						"table_name" => str_replace("_", " ", $obj->table_name),
36
						"nb_checked_comment" => $this->getNbCheckedComment($obj->table_name, 1),
37
						"nb_unchecked_comment" => $this->getNbCheckedComment($obj->table_name, 0),
38
					];
39
				}
40
				
41
				$this->setValues($values);
42
			}
43
		}
44
		
45
		/**
46
		 * @param $table_name
47
		 * @param $checked
48
		 * @return int
49
		 * function that get number of checked or unchecked comment for a table_name
50
		 */
51
		private function getNbCheckedComment($table_name, $checked) {
52
			$dbc = App::getDb();
53
			
54
			$query = $dbc->select("ID_comment")->from("_comment_all")->where("table_name", "=", $table_name, "AND")
55
				->where("checked", "=", $checked)->get();
56
			
57
			return count($query);
58
		}
59
		//-------------------------- END GETTER ----------------------------------------------------------------------------//
60
		
61
		
62
		//-------------------------- SETTER ----------------------------------------------------------------------------//
63
		/**
64
		 * @param $values
65
		 * function to set all values and sort it in future
66
		 */
67
		public function setValues($values) {
68
			$this->values = array_merge($this->values, $values);
69
		}
70
		//-------------------------- END SETTER ----------------------------------------------------------------------------//    
71
	}