Bataille::getLastConnexionPlayer()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 3
nop 0
1
<?php
2
	namespace modules\bataille\app\controller;
3
	use core\App;
4
5
	class Bataille extends InitialiseClass {
6
		private static $nation;
7
8
		private static $id_base;
9
10
		public static $values = [];
11
12
		
13
		
14
		//-------------------------- GETTER ----------------------------------------------------------------------------//
15
		/**
16
		 * @return array
17
		 * get array of all values wich will be used in the page
18
		 */
19
		public static function getValues() {
20
			return ["bataille" => self::$values];
21
		}
22
		
23
		/**
24
		 * @return mixe
25
		 * récupère l'ID_identité du joueur
26
		 */
27
		public static function getIdIdentite() {
0 ignored issues
show
Coding Style introduced by
getIdIdentite uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
28
			return $_SESSION['idlogin'.CLEF_SITE];
29
		}
30
31
		/**
32
		 * @return mixed
33
		 * renvoi l'id_base du joueur
34
		 */
35
		public static function getIdBase() {
0 ignored issues
show
Coding Style introduced by
getIdBase uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
36
			if (self::$id_base == null) {
37
				self::$id_base = $_SESSION['id_base'];
38
39
				return self::$id_base;
40
			}
41
42
			return self::$id_base;
43
		}
44
45
		/**
46
		 * @return mixed
47
		 * renvoi le premier ID_base du joueur (première base et base princ du joueur)
48
		 */
49
		public static function getFirstBase() {
50
			$dbc = App::getDb();
51
52
			$query = $dbc->select("ID_base")->from("_bataille_base")
53
				->where("ID_identite", "=", self::getIdIdentite())
54
				->orderBy("ID_base")
55
				->limit(0, 1)
56
				->get();
57
58
			if ((is_array($query)) && (count($query) == 1)) {
59
				foreach ($query as $obj) return $obj->ID_base;
60
			}
61
		}
62
63
		/**
64
		 * @param $id_base
65
		 * @return array
66
		 * fonction qui renvoi les posisitons en x et y d'une base
67
		 */
68
		private static function getPosistionBase($id_base) {
69
			$dbc = App::getDb();
70
			
71
			$posx = 0;
72
			$posy = 0;
73
74
			$query = $dbc->select("posx")
75
				->select("posy")
76
				->from("_bataille_base")
77
				->where("ID_base", "=", $id_base)
78
				->get();
79
80
			foreach ($query as $obj) {
81
				$posx = $obj->posx;
82
				$posy = $obj->posy;
83
			}
84
85
			return ["posx" => $posx, "posy" => $posy];
86
		}
87
88
		/**
89
		 * @return int
90
		 * return now timestamp
91
		 */
92
		public static function getToday() {
93
			$today = new \DateTime();
94
			return $today->getTimestamp();
95
		}
96
97
		/**
98
		 * @param string $nom_ressource
99
		 * @param $ressource
100
		 * @return array
101
		 * fonction qui permet de renvyer la couleur rouge si pas assez de ressource pour construire le batiment
102
		 * ou pour creer une unité...
103
		 */
104
		public static function getTestAssezRessourceBase($nom_ressource, $ressource) {
105
			$f = "get".ucfirst($nom_ressource);
106
107
			if ($ressource > Bataille::getRessource()->$f()) {
108
				return [
109
					"ressource" => $ressource,
110
					"class" => "rouge"
111
				];
112
			}
113
114
			return [
115
				"ressource" => $ressource,
116
				"class" => ""
117
			];
118
		}
119
		
120
		/**
121
		 * @param $id_base
122
		 * @param integer $vitesse = vitesse de l'unité en question
123
		 * @return number
124
		 * fonction qui renvoi le temps de trajet entre la base du joueur et une autre base en secondes
125
		 */
126
		public static function getDureeTrajet($id_base, $vitesse = 1) {
0 ignored issues
show
Coding Style introduced by
getDureeTrajet uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
127
			//récupération de la posisiotn de la base du joueur + la base sur laquelle on a cliqué
128
			$base_joueur = self::getPosistionBase($_SESSION['id_base']);
129
			$base_autre = self::getPosistionBase($id_base);
130
			
131
			//calcul des distances séparant les deux bases en x et y
132
			//cette dstance sera multipliée par 15 sur x et y puis ajoutée pour avoir le temps du trajte en seconde
133
			$calc_x = abs($base_joueur['posx']-$base_autre['posx']);
134
			$calc_y = abs($base_joueur['posy']-$base_autre['posy']);
135
			
136
			$temps_voyage = (($calc_x*70)+($calc_y*70))/$vitesse;
137
			
138
			return $temps_voyage;
139
		}
140
141
		/**
142
		 * @param null $id_identite
143
		 * get nation of a player
144
		 */
145
		public static function getNation($id_identite = null) {
146
			$dbc = App::getDb();
147
148
			if (($id_identite === null) && (self::$nation == null)) {
149
				$id_identite = Bataille::getIdIdentite();
150
			}
151
152
			$query = $dbc->select("nation")
153
				->from("identite")
154
				->from("_bataille_nation")
155
				->where("identite.ID_identite", "=", $id_identite, "AND")
156
				->where("identite.ID_identite", "=", "_bataille_nation.ID_identite", "", true)
157
				->get();
158
159
			if ((is_array($query)) && (count($query) > 0)) {
160
				foreach ($query as $obj) {
161
					self::setValues(["nation" => $obj->nation]);
162
				}
163
			}
164
		}
165
166
		/**
167
		 * @param $posx
168
		 * @param $posy
169
		 * @return int
170
		 * fonction qui renvoi un ID_base en fonction de sa posx et posy et 0 si base inexistante
171
		 */
172
		public static function getBaseExistPosition($posx, $posy) {
173
			$dbc = App::getDb();
174
175
			$query = $dbc->select("ID_base")->from("_bataille_base")
176
				->where("posx", "=", $posx, "AND")
177
				->where("posy", "=", $posy)
178
				->get();
179
180
			if ((is_array($query)) && (count($query) == 1)) {
181
				foreach ($query as $obj) return $obj->ID_base;
182
			}
183
184
			return 0;
185
		}
186
187
		/**
188
		 * @param string $param
189
		 * @return mixed
190
		 * fonction qui sert à récupérer un parametre spécifique pour un batiment
191
		 * par exemple la vitesse d'un marchand ou  le nombred'emplacment de la base
192
		 */
193
		public static function getParam($param) {
194
			$dbc = self::getDb();
195
196
			$query = $dbc->select($param)->from("configuration")->where("ID_configuration", "=", 1)->get();
197
198
			if ((is_array($query)) && (count($query) == 1)) {
199
				foreach ($query as $obj) return $obj->$param;
200
			}
201
		}
202
		
203
		/**
204
		 * @return mixed
205
		 * fonction qui renvoi la date de dernière connexion d'un joueur
206
		 */
207 View Code Duplication
		public static function getLastConnexionPlayer() {
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...
208
			$dbc = App::getDb();
209
			
210
			$query = $dbc->select("last_connexion")->from("_bataille_infos_player")
211
				->where("ID_identite", "=", self::getIdIdentite())
212
				->get();
213
			
214
			if ((is_array($query)) && (count($query) > 0)) {
215
				foreach ($query as $obj) {
216
					return $obj->last_connexion;
217
				}
218
			}
219
		}
220
		
221
		/**
222
		 * @param $pseudo
223
		 * @return bool
224
		 * fonction qui renvoi l'ID_identite d'un joueur si il existe
225
		 */
226
		public static function getPlayerExist($pseudo) {
227
			$dbc = App::getDb();
228
			
229
			$pseudo = trim($pseudo);
230
			
231
			$query = $dbc->select("identite.ID_identite")->from("identite, _bataille_infos_player")
232
				->where("identite.pseudo", "=", $pseudo, "AND")
233
				->where("_bataille_infos_player.abandon", "=", 0, "AND")
234
				->where("identite.ID_identite", "=", "_bataille_infos_player.ID_identite", "", true)->get();
235
			
236
			if (count($query) == 1) {
237
				foreach ($query as $obj) {
238
					return $obj->ID_identite;
239
				}
240
			}
241
			
242
			return false;
243
		}
244
		//-------------------------- END GETTER ----------------------------------------------------------------------------//
245
		
246
		
247
		
248
		//-------------------------- SETTER ----------------------------------------------------------------------------//
249
		/**
250
		 * @param $values
251
		 * can set values while keep older infos
252
		 */
253
		public static function setValues($values) {
254
			Bataille::$values = array_merge(Bataille::$values, $values);
255
		}
256
		//-------------------------- END SETTER ----------------------------------------------------------------------------//
257
	}