+ //Return return
+ return $return;
+ }
+
+ /**
+ * Find location as array by id
+ *
+ * @param int $id The location id
+ * @param string $locale The locale
+ * @return array The location data
+ */
+ public function findOneByIdAsArray(int $id, string $locale): ?array {
+ //Set the request
+ $req = <<<SQL
+SELECT
+ l.id,
+ l.title,
+ l.city,
+ l.latitude,
+ l.longitude,
+ l.indoor,
+ l.zipcode,
+ MAX(l2.updated) AS updated,
+ SUBSTRING(l.zipcode, 1, 2) AS city_id,
+ ROUND(AVG(l2.latitude), 6) AS city_latitude,
+ ROUND(AVG(l2.longitude), 6) AS city_longitude
+FROM RapsysAirBundle:Location AS l
+JOIN RapsysAirBundle:Location AS l2 ON (l2.city = l.city AND SUBSTRING(l.zipcode, 1, 3) = SUBSTRING(l.zipcode, 1, 3))
+WHERE l.id = :id
+GROUP BY l.id
+LIMIT 0, 1
+SQL;
+
+ //Replace bundle entity name by table name
+ $req = str_replace($this->tableKeys, $this->tableValues, $req);
+
+ //Get result set mapping instance
+ //XXX: DEBUG: see ../blog.orig/src/Rapsys/BlogBundle/Repository/ArticleRepository.php
+ $rsm = new ResultSetMapping();
+
+ //Declare all fields
+ //XXX: see vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/Types.php
+ //addScalarResult($sqlColName, $resColName, $type = 'string');
+ $rsm->addScalarResult('id', 'id', 'integer')
+ ->addScalarResult('title', 'title', 'string')
+ ->addScalarResult('city', 'city', 'string')
+ ->addScalarResult('latitude', 'latitude', 'float')
+ ->addScalarResult('longitude', 'longitude', 'float')
+ ->addScalarResult('indoor', 'indoor', 'boolean')
+ ->addScalarResult('zipcode', 'zipcode', 'string')
+ ->addScalarResult('updated', 'updated', 'datetime')
+ ->addScalarResult('city_id', 'city_id', 'integer')
+ ->addScalarResult('city_latitude', 'city_latitude', 'float')
+ ->addScalarResult('city_longitude', 'city_longitude', 'float')
+ ->addIndexByScalar('id');
+
+ //Get result
+ $result = $this->_em
+ ->createNativeQuery($req, $rsm)
+ ->setParameter('id', $id)
+ ->getOneOrNullResult();
+
+ //Without result
+ if ($result === null) {
+ //Return result
+ return $result;
+ }
+
+ //Set alternates
+ $result['alternates'] = [];
+
+ //Set route
+ $route = 'rapsys_air_location_view';
+
+ //Set route params
+ $routeParams = ['id' => $id];
+
+ //Iterate on each languages
+ foreach($this->languages as $languageId => $language) {
+ //Without current locale
+ if ($languageId !== $locale) {
+ //Set titles
+ $titles = [];
+
+ //Set route params locale
+ $routeParams['_locale'] = $languageId;
+
+ //Set route params location
+ $routeParams['location'] = $this->slugger->slug($this->translator->trans($result['title'], [], null, $languageId));
+
+ //Iterate on each locales
+ foreach(array_keys($this->languages) as $other) {
+ //Without other locale
+ if ($other !== $languageId) {
+ //Set other locale title
+ $titles[$other] = $this->translator->trans($language, [], null, $other);
+ }
+ }
+
+ //Add alternates locale
+ $result['alternates'][substr($languageId, 0, 2)] = $result['alternates'][str_replace('_', '-', $languageId)] = [
+ 'absolute' => $this->router->generate($route, $routeParams, UrlGeneratorInterface::ABSOLUTE_URL),
+ 'relative' => $this->router->generate($route, $routeParams),
+ 'title' => implode('/', $titles),
+ 'translated' => $this->translator->trans($language, [], null, $languageId)
+ ];
+ }
+ }
+
+ //Return result
+ return [
+ 'id' => $result['id'],
+ 'city' => [
+ 'id' => $result['city_id'],
+ 'title' => $result['city'],
+ 'in' => $this->translator->trans('in '.$result['city']),
+ 'link' => $this->router->generate('rapsys_air_city_view', ['city' => $result['city'], 'latitude' => $result['city_latitude'], 'longitude' => $result['city_longitude']])
+ ],
+ 'title' => $title = $this->translator->trans($result['title']),
+ 'latitude' => $result['latitude'],
+ 'longitude' => $result['longitude'],
+ 'indoor' => $result['indoor'],
+ 'updated' => $result['updated'],
+ 'around' => $this->translator->trans('around '.$result['title']),
+ 'at' => $this->translator->trans('at '.$result['title']),
+ 'atin' => $this->translator->trans('at '.$result['title']).' '.$this->translator->trans('in '.$result['city']),
+ 'multimap' => $this->translator->trans($result['title'].' sector map'),
+ //XXX: Useless ???
+ 'slug' => $slug = $this->slugger->slug($title),
+ 'link' => $this->router->generate($route, ['_locale' => $locale, 'location' => $slug]+$routeParams),
+ 'alternates' => $result['alternates']
+ ];
+ }
+
+ /**
+ * Find complementary locations by session id
+ *
+ * @param int $id The session id
+ * @return array The other locations
+ */
+ public function findComplementBySessionId(int $id): array {
+ //Fetch complement locations
+ $ret = $this->getEntityManager()
+ ->createQuery('SELECT l.id, l.title FROM RapsysAirBundle:Session s LEFT JOIN RapsysAirBundle:Session s2 WITH s2.id != s.id AND s2.slot = s.slot AND s2.date = s.date LEFT JOIN RapsysAirBundle:Location l WITH l.id != s.location AND (l.id != s2.location OR s2.location IS NULL) WHERE s.id = :sid GROUP BY l.id ORDER BY l.id')
+ ->setParameter('sid', $id)
+ ->getArrayResult();
+
+ //TODO: try to improve with:
+ #->addIndexByScalar('city');
+
+ //Rekey array
+ $ret = array_column($ret, 'id', 'title');
+