l.latitude,
l.longitude,
l.indoor,
- GREATEST(l.created, l.updated, COALESCE(s.created, 0), COALESCE(s.updated, 0)) AS modified,
+ GREATEST(l.created, l.updated, COALESCE(s.created, '1970-01-01'), COALESCE(s.updated, '1970-01-01')) AS modified,
l.zipcode,
COUNT(s.id) AS count,
COUNT(IF(s.date BETWEEN :begin AND :end, s.id, NULL)) AS pcount
a.longitude,
a.created,
a.updated,
- MAX(GREATEST(a.modified, COALESCE(s.created, 0), COALESCE(s.updated, 0))) AS modified,
+ MAX(GREATEST(a.modified, COALESCE(s.created, '1970-01-01'), COALESCE(s.updated, '1970-01-01'))) AS modified,
COUNT(s.id) AS count
FROM (
SELECT
a.city,
a.latitude,
a.longitude,
+ a.created,
a.updated,
- a.modified,
+ MAX(GREATEST(a.modified, COALESCE(s3.created, '1970-01-01'), COALESCE(s3.updated, '1970-01-01'))) AS modified,
a.pcount,
COUNT(s3.id) AS tcount
FROM (
b.city,
b.latitude,
b.longitude,
+ b.created,
b.updated,
- COUNT(s2.id) AS pcount,
- MAX(b.updated) AS modified
+ MAX(GREATEST(b.modified, COALESCE(s2.created, '1970-01-01'), COALESCE(s2.updated, '1970-01-01'))) AS modified,
+ COUNT(s2.id) AS pcount
FROM (
SELECT
l2.id,
l2.title,
l2.latitude,
l2.longitude,
- l2.updated
+ l2.created,
+ l2.updated,
+ GREATEST(l2.created, l2.updated) AS modified
FROM (
SELECT
l.id,
->addScalarResult('city', 'city', 'string')
->addScalarResult('latitude', 'latitude', 'float')
->addScalarResult('longitude', 'longitude', 'float')
+ ->addScalarResult('created', 'created', 'datetime')
->addScalarResult('updated', 'updated', 'datetime')
+ ->addScalarResult('modified', 'modified', 'datetime')
->addScalarResult('pcount', 'pcount', 'integer')
- ->addScalarResult('tcount', 'tcount', 'integer')
- ->addScalarResult('modified', 'modified', 'datetime');
+ ->addScalarResult('tcount', 'tcount', 'integer');
//Get result
$result = $this->_em
'miniature' => $this->translator->trans($data['title'].' miniature'),
'latitude' => $data['latitude'],
'longitude' => $data['longitude'],
+ 'created' => $data['created'],
'updated' => $data['updated'],
+ 'modified' => $data['modified'],
'pcount' => $data['pcount'],
'tcount' => $data['tcount'],
- 'modified' => $data['modified'],
'slug' => $slug = $this->slugger->slug($title),
'link' => $this->router->generate('rapsysair_location_view', ['id' => $data['id'], 'location' => $slug])
];
l.longitude,
l.indoor,
l.zipcode,
- MAX(l2.updated) AS updated,
+ MAX(GREATEST(l.created, l.updated, l2.created, l2.updated)) AS modified,
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 Rapsys\AirBundle\Entity\Location AS l
-JOIN Rapsys\AirBundle\Entity\Location AS l2 ON (l2.city = l.city AND SUBSTRING(l2.zipcode, 1, 3) = SUBSTRING(l.zipcode, 1, 3))
+JOIN Rapsys\AirBundle\Entity\Location AS l2 ON (l2.city = l.city AND SUBSTRING(l2.zipcode, 1, 2) = SUBSTRING(l.zipcode, 1, 2))
WHERE l.id = :id
GROUP BY l.id
LIMIT 0, 1
->addScalarResult('longitude', 'longitude', 'float')
->addScalarResult('indoor', 'indoor', 'boolean')
->addScalarResult('zipcode', 'zipcode', 'string')
- ->addScalarResult('updated', 'updated', 'datetime')
+ ->addScalarResult('modified', 'modified', 'datetime')
->addScalarResult('city_id', 'city_id', 'integer')
->addScalarResult('city_latitude', 'city_latitude', 'float')
->addScalarResult('city_longitude', 'city_longitude', 'float')
'latitude' => $result['latitude'],
'longitude' => $result['longitude'],
'indoor' => $result['indoor'],
- 'updated' => $result['updated'],
+ 'modified' => $result['modified'],
'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']),
*/
public function findComplementBySessionId(int $id): array {
//Fetch complement locations
- $ret = $this->getEntityManager()
- ->createQuery('SELECT l.id, l.title FROM Rapsys\AirBundle\Entity\Session s LEFT JOIN Rapsys\AirBundle\Entity\Session s2 WITH s2.id != s.id AND s2.slot = s.slot AND s2.date = s.date LEFT JOIN Rapsys\AirBundle\Entity\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');
-
- return $ret;
+ return array_column(
+ $this->getEntityManager()
+ #->createQuery('SELECT l.id, l.title FROM Rapsys\AirBundle\Entity\Location l JOIN Rapsys\AirBundle\Entity\Session s WITH s.id = :sid LEFT JOIN Rapsys\AirBundle\Entity\Session s2 WITH s2.id != s.id AND s2.slot = s.slot AND s2.date = s.date WHERE l.id != s.location AND s2.location IS NULL GROUP BY l.id ORDER BY l.id')
+ ->createQuery('SELECT l.id, l.title FROM Rapsys\AirBundle\Entity\Session s LEFT JOIN Rapsys\AirBundle\Entity\Session s2 WITH s2.id != s.id AND s2.slot = s.slot AND s2.date = s.date LEFT JOIN Rapsys\AirBundle\Entity\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(),
+ 'id',
+ 'title'
+ );
}
/**