| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | 	namespace modules\bataille\app\controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | 	 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | 	use core\App; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | 	use core\functions\DateHeure; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | 	use core\HTML\flashmessage\FlashMessage; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | 	class CentreRecherche { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | 		private $coef_centre; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | 		private $recherche; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | 		private $type; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 		//-------------------------- BUILDER ----------------------------------------------------------------------------// | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | 		public function __construct() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | 			$dbc1 = Bataille::getDb(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 			$query = $dbc1->select("coef_centre_recherche")->from("configuration")->where("ID_configuration", "=", 1)->get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 			if ((is_array($query)) && (count($query) == 1)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 				foreach ($query as $obj) $this->coef_centre = $obj->coef_centre_recherche; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 			$query = $dbc1->select()->from("recherche") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 				->where("niveau_centre", "<=", Bataille::getBatiment()->getNiveauBatiment("centre_recherche")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 				->get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 			if ((is_array($query)) && (count($query) > 0)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 				foreach ($query as $obj) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 					$niveau = $this->getNiveauRecherche($obj->recherche, $obj->type); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 					$niveau_recherche = $niveau; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 					$cout = unserialize($obj->cout); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 					$temps_recherche = $this->getTempsRecherche($obj->temps_recherche); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 					//si niveau == 0 ca veut dire que la recherche n'a pas encore été effectuée dans la base | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 38 |  | View Code Duplication | 					if ($niveau > 0) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 						$cout = $this->getCoutRecherche($cout, $niveau); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 						$temps_recherche = $this->getTempsRecherche($temps_recherche, $niveau); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 					} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 					else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 						$niveau_recherche = 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 					} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 					$recherhce[] = [ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 						"recherche" => $obj->recherche, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 						"type" => $obj->type, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 						"niveau" => $niveau, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 						"cout" => $cout, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 						"temps_recherche" => DateHeure::Secondeenheure($temps_recherche), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 						"special" => Bataille::getUnite()->getCaracteristiqueUnite($obj->recherche, $niveau_recherche, $obj->type), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 						"coef_amelioration" => Bataille::getParam("coef_niveau_unite") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 					]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 			Bataille::setValues(["centre_recherche" => $recherhce]); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 		//-------------------------- END BUILDER ----------------------------------------------------------------------------// | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 		//-------------------------- GETTER ----------------------------------------------------------------------------// | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 		 * @param $recherche | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 		 * @param $type | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 		 * @return int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 		 * fonction qui va cehrcher le niveau de la recherche actuelle | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 		 * renvoi 0 si elle n'a pas été trouvée | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 71 |  |  | 		 */ | 
            
                                                                        
                            
            
                                                                    
                                                                                                        
            
            
                | 72 |  | View Code Duplication | 		private function getNiveauRecherche($recherche, $type) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  | 			$dbc = App::getDb(); | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  | 			$query = $dbc->select("niveau") | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  | 				->from("_bataille_centre_recherche") | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  | 				->where("ID_base", "=", Bataille::getIdBase(), "AND") | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  | 				->where("recherche", "=", $recherche, "AND") | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  | 				->where("type", "=", $type) | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  | 				->get(); | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  | 			if ((is_array($query)) && (count($query) > 0)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  | 				foreach ($query as $obj) { | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  | 					return $obj->niveau; | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  | 				} | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  | 			} | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  | 			return 0; | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 		 * @param $cout | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 		 * @param $niveau_recherche | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 		 * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 		 * fonction qui renvoi le cout d'une recherche | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 		private function getCoutRecherche($cout, $niveau_recherche) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 			return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 				"eau" => $cout["eau"] * ($this->coef_centre * $niveau_recherche), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 				"electricite" => $cout["electricite"] * ($this->coef_centre * $niveau_recherche), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 				"fer" => $cout["fer"] * ($this->coef_centre * $niveau_recherche), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 				"fuel" => $cout["fuel"] * ($this->coef_centre * $niveau_recherche) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 			]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 		 * @param $temps | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 		 * @param int $niveau | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 		 * @return floatfonction qui renvoi le temps qu'il faut pour effectuer une recherche | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 		private function getTempsRecherche($temps, $niveau = 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 			$pourcent = ($temps*Bataille::getBatiment()->getNiveauBatiment("centre_recherche")/100); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 			if ($niveau == 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 				return round($temps-$pourcent);; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 			return round(($temps * ($this->coef_centre * $niveau))-$pourcent); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  | 		 * @param $type | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 		 * @return array|int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 		 * permet de renvoyer toutes es recherches déjà effectuées pour notre base en fonction | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | 		 * d'un type donné | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | 		public function getAllRechercheType($type) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | 			$dbc = App::getDb(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  | 			$query = $dbc->select()->from("_bataille_centre_recherche")->where("type", "=", $type)->get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  | 			if ((is_array($query)) && (count($query) > 0)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  | 				foreach ($query as $obj) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  | 					$recherche[] = [ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  | 						"niveau" => $obj->niveau, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  | 						"recherche" => $obj->recherche | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  | 					]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  | 				return $recherche; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  | 			return 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  | 		 * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  | 		 * fonction qui renvoi un tableau contenant la recherche en cours si celle-ci n'est pas finie | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  | 		 * sinon elle appelle la fonction setTerminerRecherche | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | 		public function getRecherche() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  | 			$dbc = App::getDb(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  | 			$query = $dbc->select()->from("_bataille_recherche")->where("ID_base", "=", Bataille::getIdBase())->get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  | 			if ((is_array($query)) && (count($query) > 0)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  | 				$today = Bataille::getToday(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  | 				foreach ($query as $obj) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  | 					$this->recherche = $obj->recherche; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  | 					$this->type = $obj->type; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  | 					if ($obj->date_fin-$today <= 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  | 						$this->setTerminerRecherche($obj->ID_recherche); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  | 					} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  | 					else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  | 						$recherche = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  | 							"recherche" => $obj->recherche, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  | 							"type" => $obj->type, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  | 							"date_fin_recherche" => $obj->date_fin-$today, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  | 							"id_recherche" => $obj->ID_recherche | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  | 						]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  | 					} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  | 				Bataille::setValues(["recherche" => $recherche]); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  | 				return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  | 			return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  | 		//-------------------------- END GETTER ----------------------------------------------------------------------------// | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  | 		//-------------------------- SETTER ----------------------------------------------------------------------------// | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  | 		public function setCommencerRecherche($recherche, $type) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  | 			$dbc = App::getDb(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  | 			$dbc1 = Bataille::getDb(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  | 			//on test si il n'y a pas déjà une recherche en cours | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  | 			if ($this->getRecherche() == true) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  | 				FlashMessage::setFlash("Une recherche est déjà en cours, merci d'attendre la fin de celle-ci"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  | 				return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  | 			//on récupère la recherche dans notre base savoir si on l'a déjà recherchée pour avoir son lvl | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  | 			$niveau_recherche = $this->getNiveauRecherche($recherche, $type); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  | 			//récupération du cout initial plus temps de recherche initial pour calculer les bon en fonction | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  | 			//du lvl du centre + du niveau actuel de la recherche | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  | 			$query = $dbc1->select("cout") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  | 				->select("temps_recherche") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  | 				->from("recherche") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  | 				->where("recherche", "=", $recherche, "AND") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  | 				->where("type", "=", $type) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  | 				->get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  | 			if ((is_array($query)) && (count($query) == 1)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  | 				foreach ($query as $obj) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  | 					$cout = unserialize($obj->cout); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  | 					$temps_recherche = $obj->temps_recherche; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 217 |  | View Code Duplication | 			if ($niveau_recherche > 0) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  | 				$cout = $this->getCoutRecherche($cout, $niveau_recherche); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  | 				$temps_recherche = $this->getTempsRecherche($temps_recherche, $niveau_recherche); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  | 			//on test si assez de ressources pour effectuer la recherche | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  | 			$eau = Bataille::getTestAssezRessourceBase("eau", $cout["eau"]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  | 			$electricite = Bataille::getTestAssezRessourceBase("electricite", $cout["electricite"]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  | 			$fer = Bataille::getTestAssezRessourceBase("fer", $cout["fer"]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  | 			$fuel = Bataille::getTestAssezRessourceBase("fuel", $cout["fuel"]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  | 			if (($eau["class"] || $electricite["class"] || $fer["class"] || $fuel["class"]) == "rouge" ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  | 				FlashMessage::setFlash("Pas assez de ressources pour effectuer cette recherche"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  | 				return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  | 			else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  | 				//on retire les ressources | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  | 				Bataille::getRessource()->setUpdateRessource($cout["eau"], $cout["electricite"], $cout["fer"], $cout["fuel"], 0, "-"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  | 				$date_fin = Bataille::getToday()+$temps_recherche; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  | 				$dbc->insert("recherche", $recherche) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  | 					->insert("type", $type) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  | 					->insert("date_fin", $date_fin) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  | 					->insert("ID_base", Bataille::getIdBase()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  | 					->into("_bataille_recherche") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  | 					->set(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  | 				return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  | 		private function setTerminerRecherche($id_recherche) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  | 			$dbc = App::getDb(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  | 			$niveau_recherche = $this->getNiveauRecherche($this->recherche, $this->type); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  | 			if ($niveau_recherche == 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  | 				$dbc->insert("recherche", $this->recherche) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  | 					->insert("type", $this->type) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  | 					->insert("niveau", 1) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  | 					->insert("ID_base", Bataille::getIdBase()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  | 					->into("_bataille_centre_recherche") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  | 					->set(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  | 			else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  | 				$dbc->update("niveau", $niveau_recherche+1) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  | 					->from("_bataille_centre_recherche") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  | 					->where("recherche", "=", $this->recherche, "AND") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  | 					->where("type", "=", $this->type, "AND") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  | 					->where("ID_base", "=", Bataille::getIdBase()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  | 					->set(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  | 			$dbc->delete()->from("_bataille_recherche")->where("ID_recherche", "=", $id_recherche, "AND") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  | 				->where("ID_base", "=", Bataille::getIdBase()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  | 				->del(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  | 		//-------------------------- END SETTER ----------------------------------------------------------------------------// | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 276 |  |  | 		 | 
            
                                                        
            
                                    
            
            
                | 277 |  |  | 	} | 
            
                        
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.