/** * Renvoie les Batiments liés aux Productions de cette collection * @return BatimentCollection */ public function getBatiments() { if (is_null($this->cacheBatiments)) { $this->cacheBatiments = BatimentBusiness::getFromProductions($this); $this->cacheBatiments->store(); } return $this->cacheBatiments; }
/** * Renvoie les Productions liés aux Batiments de la collection fournie en paramètre * @param BatimentCollection $batiments * @return ProductionCollection */ public static function getFromBatiments(BatimentCollection $batiments) { $ids = $batiments->getIdsStr(); if (!$ids) { return new ProductionCollection(); } $req = "SELECT * FROM production WHERE idBatiment IN (" . $ids . ");"; return DbHandler::collFromQuery($req, 'Production', 'ProductionCollection'); }
/** * Renvoie la liste des batiments qu'il est possible de construire dans la ville * @return BatimentCollection */ public function listeBatimentsAConstruire() { $ret = new BatimentCollection(); $typesAConstruire = array(); $nePasConstruire = array(); foreach (Batiments::$couts as $idType => $bat) { $trouve = false; foreach ($this->getBatiments() as $batiment) { /** @var Batiment $batiment */ if ($batiment->getIdType() == $idType) { if (!$bat['niveaux']) { continue 2; } if ($batiment->getEnConstruction() == '1' || $batiment->getEnConstruction() == '-1') { $nePasConstruire[] = $idType; } else { $typesAConstruire[$idType] = array($idType, $batiment->getNiveau() + 1); } $trouve = true; } } if (!$trouve) { $typesAConstruire[$idType] = array($idType, 1); } } foreach ($nePasConstruire as $idType) { if (isset($typesAConstruire[$idType])) { unset($typesAConstruire[$idType]); } } foreach ($typesAConstruire as $idType => $bat) { $new = $this->createBatiment(); $new->setIdType($idType); $new->setNiveau($bat[1]); $ret->ajout($new); } return $ret; }