Ejemplo n.º 1
0
 /**
  * @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;
 }
Ejemplo n.º 2
0
 /**
  * Test merge by.
  *
  * @see ArrayUtils::mergeBy
  */
 public function testMergeBy()
 {
     $array = [['id' => 1, 'otherKey' => 'otherValue', 'arrayKey' => ['key1' => 'value1', 'key2' => 'value2'], 'skill' => 'php'], ['id' => 1, 'otherKey' => 'otherValue', 'arrayKey' => ['key1' => 'value1', 'key2' => 'value2'], 'skill' => 'symfony']];
     $merged = ArraysUtils::mergeBy($array, 'id', 'skill')[0];
     $this->assertArrayHasKey('id', $merged);
     $this->assertArrayHasKey('otherKey', $merged);
     $this->assertArrayHasKey('arrayKey', $merged);
     $this->assertArrayHasKey('skills', $merged);
     $this->assertArrayNotHasKey('skill', $merged);
     $this->assertArraySubset(['php', 'symfony'], $merged['skills']);
 }
Ejemplo n.º 3
0
 /**
  * @param $keywords
  *
  * @return array|ZoneResult[]
  *
  * @throws DBALException
  */
 public function searchZones($keywords, Point $point = null, Country $country = null)
 {
     $datas = $this->manager->getDBResults('@Api/sql/search/zoneSearch.sql.twig', ['keywords' => $keywords, 'point' => $point, 'country' => $country]);
     $zones = [];
     foreach ($datas as $data) {
         $data = ArraysUtils::toMultiDimensional($data);
         $zone = $this->hydrator->hydrateZone($data['id'], $this->hydrator->hydrateCountry($data['country']['id'], $data['country']['name'], $data['country']['iso_code_2_letters']), $this->hydrator->hydrateZoneType($data['zone_type']['id'], $data['zone_type']['name'], $data['zone_type']['slug'], $data['zone_type']['level'], $this->hydrator->hydrateCountry($data['country']['id'], $data['country']['name'], $data['country']['iso_code_2_letters'])), $data['ref'], $data['ref_official'], $data['name'], $data['slug'], $data['population'], $data['wikipedia'], !is_null($data['date_from']) ? new \DateTime($data['date_from']) : null, !is_null($data['date_until']) ? new \DateTime($data['date_until']) : null, $data['shape_polygon'], $data['shape_multipolygon']);
         $zones[] = new ZoneResult($zone, is_null($data['distance']) ? null : floatval($data['distance']));
     }
     return $zones;
 }
Ejemplo n.º 4
0
 /**
  * @param string      $slug
  * @param string|null $zoneType
  * @param string|null $country
  *
  * @return Zone
  *
  * @throws DBALException
  * @throws ZoneNotFoundException
  */
 public function getZoneFromSlug(string $slug, string $zoneType = null, string $country = null) : Zone
 {
     $zone = $this->manager->getDBResults('@Api/sql/zones/getZoneFromSlug.sql.twig', ['slug' => $slug, 'zoneType' => $zoneType, 'country' => $country], new ZoneNotFoundException($slug), true);
     $zone = ArraysUtils::toMultiDimensional($zone);
     return $this->hydrator->hydrateZone($zone['id'], $this->hydrator->hydrateCountry($zone['country']['id'], $zone['country']['name'], $zone['country']['iso_code_2_letters']), $this->hydrator->hydrateZoneType($zone['zone_type']['id'], $zone['zone_type']['name'], $zone['zone_type']['slug'], $zone['zone_type']['level'], $this->hydrator->hydrateCountry($zone['country']['id'], $zone['country']['name'], $zone['country']['iso_code_2_letters'])), $zone['ref'], $zone['ref_official'], $zone['name'], $zone['slug'], $zone['population'], $zone['wikipedia'], is_null($zone['date_from']) ? new \DateTime($zone['date_from']) : null, is_null($zone['date_until']) ? new \DateTime($zone['date_until']) : null, $zone['shape_polygon'], $zone['shape_multipolygon']);
 }