Passed
Push — master ( 1a484d...7017e3 )
by Anthony
03:02
created

Profil::getTestModeVacances()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 22
rs 8.6737
cc 5
eloc 12
nc 8
nop 1
1
<?php
2
	namespace modules\bataille\app\controller;
3
	
4
	
5
	use core\App;
6
	use core\HTML\flashmessage\FlashMessage;
7
	
8
	class Profil {
9
		private $vacances;
10
		
11
		//-------------------------- BUILDER ----------------------------------------------------------------------------//
12
		public function __construct() {
13
			if ($this->getTestModeVacances() == 1) {
14
				if ($this->getDureeVacances() < 2) {
15
					FlashMessage::setFlash("Vous ne pouvez pas vous reconnecter sur votre compte car le mode vacances n'est pas actif depuis plus de 48h !");
16
					$this->vacances = "<48";
17
					return;
18
				}
19
				
20
				$this->vacances = ">48";
21
				return;
22
				
23
			}
24
			
25
			$this->vacances = false;
26
			return;
27
		}
28
		//-------------------------- END BUILDER ----------------------------------------------------------------------------//
29
		
30
		
31
		//-------------------------- GETTER ----------------------------------------------------------------------------//
32
		public function getVacances(){
33
		    return $this->vacances;
34
		}
35
		
36
		/**
37
		 * @return string
38
		 * fonction qui test si le compte est en mode vacances ou pas
39
		 */
40
		public function getTestModeVacances($id_identite = null) {
41
			$dbc = App::getDb();
42
			$vacances = 0;
43
			
44
			if ($id_identite === null) {
45
				$id_identite = Bataille::getIdIdentite();
46
			}
47
			
48
			$query = $dbc->select("mode_vacances")->from("_bataille_infos_player")->where("ID_identite", "=", $id_identite)->get();
49
			
50
			if (count($query) > 0) {
51
				foreach ($query as $obj) {
52
					$vacances = $obj->mode_vacances;
53
				}
54
			}
55
			
56
			if ($vacances > 0) {
57
				return 1;
58
			}
59
			
60
			 return 0;
61
		}
62
		
63
		/**
64
		 * @return string
65
		 * fonction qui renvoi la durée depuis lquelle le compte est en vacances
66
		 */
67
		public function getDureeVacances() {
68
			$last_connexion = new \DateTime(Bataille::getLastConnexionPlayer());
69
			$today = new \DateTime();
70
			
71
			$interval = $today->diff($last_connexion);
72
			
73
			return $interval->format('%a');
74
		}
75
		
76
		/**
77
		 * @param $id_base
78
		 * @return mixed
79
		 * permet de tester si une base est en vacances ou non
80
		 */
81
		public static function getTestVacancesBase($id_base) {
82
			$dbc = App::getDb();
83
			
84
			$query = $dbc->select()->from("_bataille_base")->from("_bataille_infos_player")
85
				->where("_bataille_base.ID_base", "=", $id_base, "AND")
86
				->where("_bataille_base.ID_identite", "=", "_bataille_infos_player.ID_identite", "", true)->get();
87
			
88
			if (count($query) > 0) {
89
				foreach ($query as $obj) {
90
					return $obj->mode_vacances;
91
				}
92
			}
93
			
94
			return 0;
95
		}
96
		
97
		/**
98
		 * @return bool
99
		 * fonction qui récupère toutes les construction en cours de la base
100
		 */
101 View Code Duplication
		private function getAllConstructionBases() {
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in 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...
102
			$dbc = App::getDb();
103
			
104
			$query = $dbc->select()->from("_bataille_base")->from("_bataille_batiment")
105
				->where("_bataille_base.ID_identite", "=", Bataille::getIdIdentite(), "AND")
106
				->where("_bataille_batiment.construction", "=", 1, "AND")
107
				->where("_bataille_base.ID_base", "=", "_bataille_batiment.ID_base", "", true)->get();
108
			
109
			if (count($query) > 0) {
110
				return true;
111
			}
112
			
113
			return false;
114
		}
115
		
116
		/**
117
		 * @return bool
118
		 * fonction qui récupère toutes les recherches, recrutement, missions et offre de marché en cours de la base
119
		 */
120
		private static function getAllThingsBases($table) {
121
			$dbc = App::getDb();
122
			
123
			$query = $dbc->select()->from("_bataille_base")->from($table)
124
				->where("_bataille_base.ID_identite", "=", Bataille::getIdIdentite(), "AND")
125
				->where("_bataille_base.ID_base", "=", $table.".ID_base", "", true)->get();
126
			
127
			if (count($query) > 0) {
128
				return true;
129
			}
130
			
131
			return false;
132
		}
133
		
134
		/**
135
		 * @return bool
136
		 * fonction qui récupère toutes les transports en cours de la base
137
		 */
138 View Code Duplication
		private static function getAllMarcheBases() {
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in 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...
139
			$dbc = App::getDb();
140
			
141
			$query = $dbc->select()->from("_bataille_base")->from("_bataille_marche_transport")
142
				->where("_bataille_base.ID_identite", "=", Bataille::getIdIdentite(), "AND")
143
				->where("_bataille_base.ID_base", "=", "_bataille_marche_transport.ID_base", "OR", true)->get()
144
				->where("_bataille_base.ID_base", "=", "_bataille_marche_transport.ID_base_dest", "", true)->get();
145
			
146
			if (count($query) > 0) {
147
				return true;
148
			}
149
			
150
			return false;
151
		}
152
		//-------------------------- END GETTER ----------------------------------------------------------------------------//
153
		
154
		
155
		//-------------------------- SETTER ----------------------------------------------------------------------------//
156
		/**
157
		 * fonction qui permet d'activer le mode vacances
158
		 */
159
		public static function setActiverModeVacances() {
160
			$dbc = App::getDb();
161
			
162
			if ((self::getAllConstructionBases() == false) && (self::getAllMarcheBases() == false) &&
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
163
				(self::getAllThingsBases("_bataille_marche_transport") == false) &&
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
164
				(self::getAllThingsBases("_bataille_marche_recrutement") == false) &&
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
165
				(self::getAllThingsBases("_bataille_missions_cours") == false) &&
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
166
				(self::getAllThingsBases("_bataille_marche_recherche") == false)) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
167
				
168
				$dbc->update("mode_vacances", 1)->update("last_connexion", date("Y-m-d H:i:s"))->from("_bataille_infos_player")->where("ID_identite", "=", Bataille::getIdIdentite())->set();
169
				FlashMessage::setFlash("Le mode vacances a bien été activé");
170
				return true;
171
			}
172
			
173
			FlashMessage::setFlash("impossible de passer en mode vacances des actions sont encore en cours dans vos bases, merci d'en faire le tour pour vérifier");
174
			return false;
175
		}
176
		
177
		/**
178
		 * fonction qui permet de finir le mode vacances
179
		 */
180 View Code Duplication
		public function setDesactiverModeVacances() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
181
			$dbc = App::getDb();
182
			
183
			$dbc->update("mode_vacances", 0)->update("last_connexion", date("Y-m-d H:i:s"))->from("_bataille_infos_player")->where("ID_identite", "=", Bataille::getIdIdentite())->set();
184
		
185
			$dbc->update("last_connexion", date("Y-m-d- H:i:s"))
186
				->update("last_check_nourriture", date("Y-m-d- H:i:s"))
187
				->from("_bataille_base")
188
				->where("ID_identite", "=", Bataille::getIdIdentite())->set();
189
		}
190
		//-------------------------- END SETTER ----------------------------------------------------------------------------//
191
	}