Passed
Push — master ( b7284a...b936a1 )
by Anthony
02:40
created

PermissionsFaction::getTestChefFaction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 2
eloc 9
nc 2
nop 2
1
<?php
2
	namespace modules\bataille\app\controller;
3
	
4
	
5
	use core\App;
6
	
7
	class PermissionsFaction {
8
		//-------------------------- BUILDER ----------------------------------------------------------------------------//
9
		//-------------------------- END BUILDER ----------------------------------------------------------------------------//
10
		
11
		
12
		//-------------------------- GETTER ----------------------------------------------------------------------------//
13
		/**
14
		 * @param $id_identite
15
		 * @param $id_faction
16
		 * @return bool
17
		 * permet de savoir si le joueur en question est le chef de la faction
18
		 */
19
		private function getTestChefFaction($id_identite, $id_faction) {
20
			$dbc = App::getDb();
21
			
22
			$query = $dbc->select("ID_identite")->from("_bataille_faction")
23
				->where("ID_identite", "=", $id_identite, "AND")
24
				->where("ID_faction", "=", $id_faction)
25
				->get();
26
			
27
			if (count($query) > 0) {
28
				return true;
29
			}
30
			
31
			return false;
32
		}
33
		
34
		/**
35
		 * @return int
36
		 * fonction qui renvoi le nombre de permissions
37
		 */
38
		private function getNombrePermissions() {
39
			$dbc = App::getDb();
40
			
41
			$query = $dbc->select()->from("_bataille_faction_permissions")->get();
42
			
43
			return count($query);
44
		}
45
		
46
		/**
47
		 * @return array
48
		 * fonction qui liste toutes les permissions
49
		 */
50
		protected function getListPermissions() {
51
			$dbc = App::getDb();
52
			
53
			$query = $dbc->select()->from("_bataille_faction_permissions")->get();
54
			
55
			$permissions = [];
56
			if (count($query) > 0) {
57
				foreach ($query as $obj) {
58
					$permissions[] = [
59
						"permission" => $obj->permission
60
					];
61
				}
62
			}
63
			
64
			return $permissions;
65
		}
66
		
67
		/**
68
		 * @param $id_identite
69
		 * @param $id_faction
70
		 * @return array|string
71
		 * permet de récupérer les permissions d'un membre de la faction
72
		 */
73
		protected function getMembrePermissions($id_identite, $id_faction) {
74
			$dbc = App::getDb();
75
			
76
			$nb_permissions = $this->getNombrePermissions();
77
			
78
			if ($this->getTestChefFaction($id_identite, $id_faction) === true) {
79
				$permissions = [];
80
				for ($i=1 ; $i<=$nb_permissions ; $i++) {
81
					$permissions[$i] = "checked";
82
				}
83
				
84
				return $permissions;
85
			}
86
			
87
			
88
			$permissions = [];
89
			for ($i=1 ; $i<=$nb_permissions ; $i++) {
90
				$query = $dbc->select()->from("_bataille_faction_permission_player")
91
					->where("ID_faction", "=", $id_faction, "AND")
92
					->where("ID_identite", "=", $id_identite, "AND")
93
					->where("ID_permission", "=", $i)
94
					->get();
95
				
96
				$permissions[$i] = "";
97
				if (count($query) == 1) {
98
					$permissions[$i] = "checked";
99
				}
100
			}
101
			
102
			
103
			return $permissions;
104
		}
105
		//-------------------------- END GETTER ----------------------------------------------------------------------------//
106
		
107
		
108
		//-------------------------- SETTER ----------------------------------------------------------------------------//
109
		//-------------------------- END SETTER ----------------------------------------------------------------------------//    
110
	}