/** * @param Country $country * * @return array|Mandate[] */ public function getMandates(Country $country) : array { $datas = $this->manager->getDBResults('@Api/sql/elects/getMandates.sql.twig', ['country' => $country->getId()]); $mandates = []; foreach ($datas as $data) { $data = ArraysUtils::toMultiDimensional($data); $mandates[] = $this->hydrator->hydrateMandate($data['id'], $data['name'], $data['wikipedia'], $this->hydrator->hydrateZoneType($data['zone_type']['id'], $data['zone_type']['name'], $data['zone_type']['slug'], $data['zone_type']['level'], $country)); } return $mandates; }
/** * @param $id * @param $name * @param $slug * @param Country $country * @param $level * * @return ZoneType */ public function hydrateZoneType($id, $name, $slug, $level, Country $country = null) : ZoneType { if ($country) { $inflector = Inflector::get(strtolower($country->getIsoCode2Letters())); } else { $inflector = Inflector::get(); } if ($cache = $this->getFromCache('ZoneType', $id)) { return $cache; } else { return $this->putInCache('ZoneType', $id, new ZoneType($id, $name, $inflector->pluralize($slug), $level, $country)); } }
/** * @param Country $country * * @return array|ZoneType[] * * @throws DBALException */ public function getZonesTypes(Country $country) : array { $results = $this->manager->getDBResults('@Api/sql/zones/getZonesTypes.sql.twig', ['country' => $country->getId()]); $zonesTypes = []; foreach ($results as $zt) { $zonesTypes[] = $this->hydrator->hydrateZoneType($zt['id'], $zt['name'], $zt['slug'], $zt['level'], $country); } return $zonesTypes; }