X-Git-Url: https://git.rapsys.eu/airbundle/blobdiff_plain/99ad4ba3b9f655cd8df1baa13c00d75460590ca9..36367b3d9770a29f2e516e40524c5d4eef8a9aca:/Repository/SessionRepository.php diff --git a/Repository/SessionRepository.php b/Repository/SessionRepository.php index d7cc5be..e264552 100644 --- a/Repository/SessionRepository.php +++ b/Repository/SessionRepository.php @@ -12,18 +12,21 @@ namespace Rapsys\AirBundle\Repository; use Doctrine\DBAL\Types\Types; +use Doctrine\ORM\AbstractQuery; use Doctrine\ORM\Query\ResultSetMapping; + use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Rapsys\AirBundle\Entity\Application; use Rapsys\AirBundle\Entity\Location; use Rapsys\AirBundle\Entity\Session; use Rapsys\AirBundle\Entity\Slot; +use Rapsys\AirBundle\Repository; /** * SessionRepository */ -class SessionRepository extends EntityRepository { +class SessionRepository extends Repository { ///Set glyphs //TODO: document utf-8 codes ? //TODO: use unknown == ? symbol by default ??? @@ -111,16 +114,16 @@ SELECT GROUP_CONCAT(IFNULL(sa.canceled, 'NULL') ORDER BY sa.user_id SEPARATOR "\\n") AS sa_canceled, GROUP_CONCAT(sa.user_id ORDER BY sa.user_id SEPARATOR "\\n") AS sau_id, GROUP_CONCAT(sau.pseudonym ORDER BY sa.user_id SEPARATOR "\\n") AS sau_pseudonym -FROM RapsysAirBundle:Session AS s -JOIN RapsysAirBundle:Location AS l ON (l.id = s.location_id) -JOIN RapsysAirBundle:Slot AS t ON (t.id = s.slot_id) -LEFT JOIN RapsysAirBundle:Application AS a ON (a.id = s.application_id) -LEFT JOIN RapsysAirBundle:Dance AS ad ON (ad.id = a.dance_id) -LEFT JOIN RapsysAirBundle:User AS au ON (au.id = a.user_id) -LEFT JOIN RapsysAirBundle:Snippet AS p ON (p.location_id = s.location_id AND p.user_id = a.user_id AND p.locale = :locale) -LEFT JOIN RapsysAirBundle:Application AS sa ON (sa.session_id = s.id) -LEFT JOIN RapsysAirBundle:User AS sau ON (sau.id = sa.user_id) -LEFT JOIN RapsysAirBundle:Dance AS sad ON (sad.id = sa.dance_id) +FROM Rapsys\AirBundle\Entity\Session AS s +JOIN Rapsys\AirBundle\Entity\Location AS l ON (l.id = s.location_id) +JOIN Rapsys\AirBundle\Entity\Slot AS t ON (t.id = s.slot_id) +LEFT JOIN Rapsys\AirBundle\Entity\Application AS a ON (a.id = s.application_id) +LEFT JOIN Rapsys\AirBundle\Entity\Dance AS ad ON (ad.id = a.dance_id) +LEFT JOIN Rapsys\AirBundle\Entity\User AS au ON (au.id = a.user_id) +LEFT JOIN Rapsys\AirBundle\Entity\Snippet AS p ON (p.locale = :locale AND p.location_id = s.location_id AND p.user_id = a.user_id) +LEFT JOIN Rapsys\AirBundle\Entity\Application AS sa ON (sa.session_id = s.id) +LEFT JOIN Rapsys\AirBundle\Entity\User AS sau ON (sau.id = sa.user_id) +LEFT JOIN Rapsys\AirBundle\Entity\Dance AS sad ON (sad.id = sa.dance_id) WHERE s.id = :id GROUP BY s.id ORDER BY NULL @@ -210,7 +213,7 @@ SQL; } //Set route - $route = 'rapsys_air_session_view'; + $route = 'rapsysair_session_view'; //Set route params $routeParams = ['id' => $id, 'location' => $this->slugger->slug($this->translator->trans($result['l_title']))]; @@ -252,7 +255,7 @@ SQL; 'longitude' => $result['l_longitude'], 'indoor' => $result['l_indoor'], 'slug' => $routeParams['location'], - 'link' => $this->router->generate('rapsys_air_location_view', ['id' => $result['l_id'], 'location' => $routeParams['location']]) + 'link' => $this->router->generate('rapsysair_location_view', ['id' => $result['l_id'], 'location' => $routeParams['location']]) ], 'slot' => [ 'id' => $result['t_id'], @@ -272,15 +275,15 @@ SQL; 'name' => $this->translator->trans($result['ad_name']), 'type' => $this->translator->trans($result['ad_type']), 'slug' => $routeParams['dance'] = $this->slugger->slug($this->translator->trans($result['ad_name'].' '.lcfirst($result['ad_type']))), - 'link' => $this->router->generate('rapsys_air_dance_view', ['id' => $result['ad_id'], 'name' => $this->slugger->slug($this->translator->trans($result['ad_name'])), 'type' => $this->slugger->slug($this->translator->trans($result['ad_type']))]) + 'link' => $this->router->generate('rapsysair_dance_view', ['id' => $result['ad_id'], 'name' => $this->slugger->slug($this->translator->trans($result['ad_name'])), 'type' => $this->slugger->slug($this->translator->trans($result['ad_type']))]) ], 'user' => [ 'id' => $result['au_id'], 'by' => $this->translator->trans('by %pseudonym%', [ '%pseudonym%' => $result['au_pseudonym'] ]), 'title' => $result['au_pseudonym'], 'slug' => $routeParams['user'] = $this->slugger->slug($result['au_pseudonym']), - 'link' => $result['au_id'] == 1 && $routeParams['user'] == 'milonga-raphael' ? $this->router->generate('rapsys_air_user_milongaraphael') : $this->router->generate('rapsys_air_user_view', ['id' => $result['au_id'], 'user' => $routeParams['user']]), - 'contact' => $this->router->generate('rapsys_air_contact', ['id' => $result['au_id'], 'user' => $routeParams['user']]) + 'link' => $result['au_id'] == 1 && $routeParams['user'] == 'milonga-raphael' ? $this->router->generate('rapsysair_user_milongaraphael') : $this->router->generate('rapsysair_user_view', ['id' => $result['au_id'], 'user' => $routeParams['user']]), + 'contact' => $this->router->generate('rapsysair_contact', ['id' => $result['au_id'], 'user' => $routeParams['user']]) ], 'id' => $result['a_id'], 'canceled' => $result['a_canceled'] @@ -437,7 +440,7 @@ SQL; //XXX: get every location between 0 and 15 km of latitude and longitude $req = <<getEntityManager() - ->createQuery('SELECT s FROM RapsysAirBundle:Session s WHERE (s.location = :location AND s.slot = :slot AND s.date = :date)') - ->setParameter('location', $location) - ->setParameter('slot', $slot) - ->setParameter('date', $date) - ->getSingleResult(); - } /** - * Fetch sessions by date period - * - * @XXX: used in calendar command + * Find sessions by user id and synchronized date time * - * @param DatePeriod $period The date period - * @return array The session array + * @param int $userId The user id + * @param DateTime $synchronized The synchronized datetime + * @return array The session data */ - public function fetchAllByDatePeriod(\DatePeriod $period): array { + public function findAllByUserIdSynchronized(int $userId, \DateTime $synchronized): array { + //Set the request + $req = <<tableKeys, $this->tableValues, $req); + + //Get result set mapping instance + $rsm = new ResultSetMapping(); + + //Declare dance id field + $rsm->addScalarResult('dance_id', 'dance_id', 'integer'); + + //Set dance sql part + $danceSql = ''; + + //With user dance + if ( + $userDances = $this->_em + ->createNativeQuery($req, $rsm) + ->setParameter('uid', $userId) + ->getResult(AbstractQuery::HYDRATE_SCALAR_COLUMN) + ) { + //Set dance sql part + $danceSql = ' AND a.dance_id IN (:dids)'; + } + + //Set the request + $req = <<tableKeys, $this->tableValues, $req); + + //Get result set mapping instance + $rsm = new ResultSetMapping(); + + //Declare user id field + $rsm->addScalarResult('subscribed_id', 'subscribed_id', 'integer'); + + //Set subscription sql part + $subscriptionSql = ''; + + //With user subscription + if ( + $userSubscriptions = $this->_em + ->createNativeQuery($req, $rsm) + ->setParameter('uid', $userId) + ->getResult(AbstractQuery::HYDRATE_SCALAR_COLUMN) + ) { + //Set subscription sql part + $subscriptionSql = ' AND a.user_id IN (:uids)'; + } + //Set the request - //TODO: exclude opera and others ? $req = <<= :synchronized 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') + $rsm + ->addScalarResult('id', 'id', 'integer') ->addScalarResult('date', 'date', 'date') ->addScalarResult('locked', 'locked', 'datetime') ->addScalarResult('updated', 'updated', 'datetime') @@ -1049,72 +1092,85 @@ SQL; ->addScalarResult('p_profile', 'p_profile', 'string') ->addIndexByScalar('id'); - //Fetch result - $res = $this->_em + //Return sessions + //TODO: XXX: finish here + return $this->_em ->createNativeQuery($req, $rsm) - ->setParameter('begin', $period->getStartDate()) - ->setParameter('end', $period->getEndDate()); + ->setParameter('dids', $userDances) + ->setParameter('uids', $userSubscriptions) + ->setParameter('synchronized', $synchronized) + ->getArrayResult(); + } - //Return result - return $res->getResult(); + /** + * Find session by location, slot and date + * + * @param Location $location The location + * @param Slot $slot The slot + * @param DateTime $date The datetime + * @return ?Session The found session + */ + public function findOneByLocationSlotDate(Location $location, Slot $slot, \DateTime $date): ?Session { + //Return sessions + return $this->getEntityManager() + ->createQuery('SELECT s FROM Rapsys\AirBundle\Entity\Session s WHERE (s.location = :location AND s.slot = :slot AND s.date = :date)') + ->setParameter('location', $location) + ->setParameter('slot', $slot) + ->setParameter('date', $date) + ->getSingleResult(); } /** - * Fetch sessions calendar with translated location by date period and user + * Fetch sessions by date period + * + * @XXX: used in calendar command * * @param DatePeriod $period The date period - * @param ?int $userId The user id - * @param ?int $sessionId The session id + * @return array The session array */ - public function fetchUserCalendarByDatePeriod(\DatePeriod $period, ?int $userId = null, ?int $sessionId = null): array { - //Init user sql - $userJoinSql = $userWhereSql = ''; - - //When user id is set - if (!empty($userId)) { - //Add user join - $userJoinSql = 'JOIN RapsysAirBundle:Application AS sua ON (sua.session_id = s.id)'."\n"; - //Add user id clause - $userWhereSql = "\n\t".'AND sua.user_id = :uid'; - } - + public function fetchAllByDatePeriod(\DatePeriod $period): array { //Set the request - //TODO: change as_u_* in sau_*, a_u_* in au_*, etc, see request up + //TODO: exclude opera and others ? $req = <<addScalarResult('id', 'id', 'integer') ->addScalarResult('date', 'date', 'date') - ->addScalarResult('rainrisk', 'rainrisk', 'float') - ->addScalarResult('rainfall', 'rainfall', 'float') - ->addScalarResult('realfeel', 'realfeel', 'float') - ->addScalarResult('temperature', 'temperature', 'float') ->addScalarResult('locked', 'locked', 'datetime') + ->addScalarResult('updated', 'updated', 'datetime') ->addScalarResult('start', 'start', 'datetime') ->addScalarResult('stop', 'stop', 'datetime') - ->addScalarResult('t_id', 't_id', 'integer') - ->addScalarResult('t_title', 't_title', 'string') ->addScalarResult('l_id', 'l_id', 'integer') + ->addScalarResult('l_address', 'l_address', 'string') + ->addScalarResult('l_zipcode', 'l_zipcode', 'string') + ->addScalarResult('l_city', 'l_city', 'string') + ->addScalarResult('l_latitude', 'l_latitude', 'float') + ->addScalarResult('l_longitude', 'l_longitude', 'float') ->addScalarResult('l_title', 'l_title', 'string') + ->addScalarResult('l_description', 'l_description', 'string') + ->addScalarResult('t_id', 't_id', 'integer') + ->addScalarResult('t_title', 't_title', 'string') ->addScalarResult('a_id', 'a_id', 'integer') + ->addScalarResult('a_canceled', 'a_canceled', 'datetime') ->addScalarResult('ad_name', 'ad_name', 'string') ->addScalarResult('ad_type', 'ad_type', 'string') ->addScalarResult('au_id', 'au_id', 'integer') + ->addScalarResult('au_forename', 'au_forename', 'string') ->addScalarResult('au_pseudonym', 'au_pseudonym', 'string') + ->addScalarResult('p_id', 'p_id', 'integer') + ->addScalarResult('p_description', 'p_description', 'string') + ->addScalarResult('p_class', 'p_class', 'string') + ->addScalarResult('p_short', 'p_short', 'string') + ->addScalarResult('p_hat', 'p_hat', 'integer') ->addScalarResult('p_rate', 'p_rate', 'integer') - ->addScalarResult('p_hat', 'p_hat', 'boolean') - //XXX: is a string because of \n separator - ->addScalarResult('sau_id', 'sau_id', 'string') - //XXX: is a string because of \n separator - ->addScalarResult('sau_pseudonym', 'sau_pseudonym', 'string') + ->addScalarResult('p_contact', 'p_contact', 'string') + ->addScalarResult('p_donate', 'p_donate', 'string') + ->addScalarResult('p_link', 'p_link', 'string') + ->addScalarResult('p_profile', 'p_profile', 'string') ->addIndexByScalar('id'); //Fetch result $res = $this->_em ->createNativeQuery($req, $rsm) ->setParameter('begin', $period->getStartDate()) - ->setParameter('end', $period->getEndDate()) - ->setParameter('uid', $userId) - ->getResult(); - - //Init calendar - $calendar = []; - - //Init month - $month = null; - - //Iterate on each day - foreach($period as $date) { - //Init day in calendar - $calendar[$Ymd = $date->format('Ymd')] = [ - 'title' => $this->translator->trans($date->format('l')).' '.$date->format('d'), - 'class' => [], - 'sessions' => [] - ]; - - //Detect month change - if ($month != $date->format('m')) { - $month = $date->format('m'); - //Append month for first day of month - //XXX: except if today to avoid double add - if ($date->format('U') != strtotime('today')) { - $calendar[$Ymd]['title'] .= '/'.$month; - } - } - //Deal with today - if ($date->format('U') == ($today = strtotime('today'))) { - $calendar[$Ymd]['title'] .= '/'.$month; - $calendar[$Ymd]['current'] = true; - $calendar[$Ymd]['class'][] = 'current'; - } - //Disable passed days - if ($date->format('U') < $today) { - $calendar[$Ymd]['disabled'] = true; - $calendar[$Ymd]['class'][] = 'disabled'; - } - //Set next month days - if ($date->format('m') > date('m')) { - $calendar[$Ymd]['next'] = true; - #$calendar[$Ymd]['class'][] = 'next'; - } - - //Detect sunday - if ($date->format('w') == 0) { - $calendar[$Ymd]['class'][] = 'sunday'; - } - - //Iterate on each session to find the one of the day - foreach($res as $session) { - if (($sessionYmd = $session['date']->format('Ymd')) == $Ymd) { - //Count number of application - $count = count(explode("\n", $session['sau_id'])); - - //Compute classes - $class = []; - if (!empty($session['a_id'])) { - $applications = [ $session['au_id'] => $session['au_pseudonym'] ]; - if ($session['au_id'] == $userId) { - $class[] = 'granted'; - } else { - $class[] = 'disputed'; - } - } elseif ($count > 1) { - $class[] = 'disputed'; - } elseif (!empty($session['locked'])) { - $class[] = 'locked'; - } else { - $class[] = 'pending'; - } - - if ($sessionId == $session['id']) { - $class[] = 'highlight'; - } - - //Set temperature - //XXX: realfeel may be null, temperature should not - $temperature = $session['realfeel'] !== null ? $session['realfeel'] : $session['temperature']; - - //Compute weather - //XXX: rainfall may be null - if ($session['rainrisk'] > 0.50 || $session['rainfall'] > 2) { - $weather = self::GLYPHS['Stormy']; - } elseif ($session['rainrisk'] > 0.40 || $session['rainfall'] > 1) { - $weather = self::GLYPHS['Rainy']; - } elseif ($temperature > 24) { - $weather = self::GLYPHS['Cleary']; - } elseif ($temperature > 17) { - $weather = self::GLYPHS['Sunny']; - } elseif ($temperature > 10) { - $weather = self::GLYPHS['Cloudy']; - } elseif ($temperature !== null) { - $weather = self::GLYPHS['Winty']; - } else { - $weather = null; - } - - //Init weathertitle - $weathertitle = []; - - //Check if realfeel is available - if ($session['realfeel'] !== null) { - $weathertitle[] = $session['realfeel'].'°R'; - } - - //Check if temperature is available - if ($session['temperature'] !== null) { - $weathertitle[] = $session['temperature'].'°C'; - } - - //Check if rainrisk is available - if ($session['rainrisk'] !== null) { - $weathertitle[] = ($session['rainrisk']*100).'%'; - } - - //Check if rainfall is available - if ($session['rainfall'] !== null) { - $weathertitle[] = $session['rainfall'].'mm'; - } - - //Set applications - $applications = [ - 0 => $this->translator->trans($session['t_title']).' '.$this->translator->trans('at '.$session['l_title']).$this->translator->trans(':') - ]; - - //Fetch pseudonyms from session applications - $applications += array_combine(explode("\n", $session['sau_id']), array_map(function ($v) {return '- '.$v;}, explode("\n", $session['sau_pseudonym']))); - - //Set dance - $dance = null; - - //Set pseudonym - $pseudonym = null; - - //Check that session is not granted - if (empty($session['a_id'])) { - //With location id and unique application - if ($count == 1) { - //Set unique application pseudonym - $pseudonym = $session['sau_pseudonym']; - } - //Session is granted - } else { - //Replace granted application - $applications[$session['au_id']] = '* '.$session['au_pseudonym']; - - //Set dance - $dance = $this->translator->trans($session['ad_name'].' '.lcfirst($session['ad_type'])); - - //Set pseudonym - $pseudonym = $session['au_pseudonym'].($count > 1 ? ' ['.$count.']':''); - } - - //Set title - $title = $this->translator->trans($session['l_title']).($count > 1 ? ' ['.$count.']':''); - - //Add the session - $calendar[$Ymd]['sessions'][$session['t_id'].sprintf('%02d', $session['l_id'])] = [ - 'id' => $session['id'], - 'start' => $session['start'], - 'stop' => $session['stop'], - 'location' => $this->translator->trans($session['l_title']), - 'dance' => $dance, - 'pseudonym' => $pseudonym, - 'class' => $class, - 'slot' => self::GLYPHS[$session['t_title']], - 'slottitle' => $this->translator->trans($session['t_title']), - 'weather' => $weather, - 'weathertitle' => implode(' ', $weathertitle), - 'applications' => $applications, - 'rate' => $session['p_rate'], - 'hat' => $session['p_hat'] - ]; - } - } - - //Sort sessions - ksort($calendar[$Ymd]['sessions']); - } + ->setParameter('end', $period->getEndDate()); - //Send result - return $calendar; + //Return result + return $res->getResult(); } /** @@ -1354,8 +1239,8 @@ SQL; //XXX: select session starting after now and stopping before date(now)+3d as accuweather only provide hourly data for the next 3 days (INTERVAL 3 DAY) $req = <<= NOW() AND ADDDATE(ADDTIME(ADDTIME(s.date, s.begin), s.length), INTERVAL IF(s.slot_id = :afterid, 1, 0) DAY) < DATE(ADDDATE(NOW(), INTERVAL :accuhourly DAY)) SQL; @@ -1367,7 +1252,7 @@ SQL; //Declare all fields $rsm - ->addEntityResult('RapsysAirBundle:Session', 's') + ->addEntityResult('Rapsys\AirBundle\Entity\Session', 's') ->addFieldResult('s', 'id', 'id') ->addFieldResult('s', 'date', 'date') ->addFieldResult('s', 'begin', 'begin') @@ -1380,9 +1265,9 @@ SQL; ->addFieldResult('s', 'temperature', 'temperature') ->addFieldResult('s', 'temperaturemin', 'temperaturemin') ->addFieldResult('s', 'temperaturemax', 'temperaturemax') - ->addJoinedEntityResult('RapsysAirBundle:Slot', 'o', 's', 'slot') + ->addJoinedEntityResult('Rapsys\AirBundle\Entity\Slot', 'o', 's', 'slot') ->addFieldResult('o', 'slot_id', 'id') - ->addJoinedEntityResult('RapsysAirBundle:Location', 'l', 's', 'location') + ->addJoinedEntityResult('Rapsys\AirBundle\Entity\Location', 'l', 's', 'location') ->addFieldResult('l', 'location_id', 'id') ->addFieldResult('l', 'zipcode', 'zipcode') ->addIndexBy('s', 'id'); @@ -1403,8 +1288,8 @@ SQL; //XXX: select session stopping after or equal date(now)+3d as accuweather only provide hourly data for the next 3 days (INTERVAL 3 DAY) $req = <<= DATE(ADDDATE(NOW(), INTERVAL :accuhourly DAY)) AND ADDDATE(ADDTIME(ADDTIME(s.date, s.begin), s.length), INTERVAL IF(s.slot_id = :afterid, 1, 0) DAY) < DATE(ADDDATE(NOW(), INTERVAL :accudaily DAY)) SQL; @@ -1416,7 +1301,7 @@ SQL; //Declare all fields $rsm - ->addEntityResult('RapsysAirBundle:Session', 's') + ->addEntityResult('Rapsys\AirBundle\Entity\Session', 's') ->addFieldResult('s', 'id', 'id') ->addFieldResult('s', 'date', 'date') ->addFieldResult('s', 'begin', 'begin') @@ -1429,9 +1314,9 @@ SQL; ->addFieldResult('s', 'temperature', 'temperature') ->addFieldResult('s', 'temperaturemin', 'temperaturemin') ->addFieldResult('s', 'temperaturemax', 'temperaturemax') - ->addJoinedEntityResult('RapsysAirBundle:Slot', 'o', 's', 'slot') + ->addJoinedEntityResult('Rapsys\AirBundle\Entity\Slot', 'o', 's', 'slot') ->addFieldResult('o', 'slot_id', 'id') - ->addJoinedEntityResult('RapsysAirBundle:Location', 'l', 's', 'location') + ->addJoinedEntityResult('Rapsys\AirBundle\Entity\Location', 'l', 's', 'location') ->addFieldResult('l', 'location_id', 'id') ->addFieldResult('l', 'zipcode', 'zipcode') ->addIndexBy('s', 'id'); @@ -1453,9 +1338,9 @@ SQL; //TODO: remonter les données pour le mail ? $req =<<addEntityResult('RapsysAirBundle:Session', 's') + ->addEntityResult('Rapsys\AirBundle\Entity\Session', 's') ->addFieldResult('s', 'id', 'id') ->addIndexBy('s', 'id'); @@ -1577,29 +1462,29 @@ FROM ( s.premium, l.hotspot, a.created - FROM RapsysAirBundle:Session AS s - JOIN RapsysAirBundle:Location AS l ON (l.id = s.location_id) - JOIN RapsysAirBundle:Application AS a ON (a.session_id = s.id AND a.canceled IS NULL) - LEFT JOIN RapsysAirBundle:Session AS s2 ON (s2.id != s.id AND s2.location_id = s.location_id AND s2.slot_id IN (:afternoonid, :eveningid) AND s2.application_id IS NOT NULL AND s2.locked IS NULL AND s2.date > s.date - INTERVAL 1 YEAR) - LEFT JOIN RapsysAirBundle:Application AS a2 ON (a2.id = s2.application_id AND a2.user_id = a.user_id AND (a2.canceled IS NULL OR TIMESTAMPDIFF(DAY, a2.canceled, ADDDATE(ADDTIME(s2.date, s2.begin), INTERVAL IF(s2.slot_id = :afterid, 1, 0) DAY)) < 1)) + FROM Rapsys\AirBundle\Entity\Session AS s + JOIN Rapsys\AirBundle\Entity\Location AS l ON (l.id = s.location_id) + JOIN Rapsys\AirBundle\Entity\Application AS a ON (a.session_id = s.id AND a.canceled IS NULL) + LEFT JOIN Rapsys\AirBundle\Entity\Session AS s2 ON (s2.id != s.id AND s2.location_id = s.location_id AND s2.slot_id IN (:afternoonid, :eveningid) AND s2.application_id IS NOT NULL AND s2.locked IS NULL AND s2.date > s.date - INTERVAL 1 YEAR) + LEFT JOIN Rapsys\AirBundle\Entity\Application AS a2 ON (a2.id = s2.application_id AND a2.user_id = a.user_id AND (a2.canceled IS NULL OR TIMESTAMPDIFF(DAY, a2.canceled, ADDDATE(ADDTIME(s2.date, s2.begin), INTERVAL IF(s2.slot_id = :afterid, 1, 0) DAY)) < 1)) WHERE s.id = :sid GROUP BY a.id ORDER BY NULL LIMIT 0, :limit ) AS b - LEFT JOIN RapsysAirBundle:Session AS s3 ON (s3.id != b.session_id AND s3.application_id IS NOT NULL AND s3.locked IS NULL AND s3.date > b.date - INTERVAL 1 YEAR) - LEFT JOIN RapsysAirBundle:Application AS a3 ON (a3.id = s3.application_id AND a3.user_id = b.user_id AND (a3.canceled IS NULL OR TIMESTAMPDIFF(DAY, a3.canceled, ADDDATE(ADDTIME(s3.date, s3.begin), INTERVAL IF(s3.slot_id = :afterid, 1, 0) DAY)) < 1)) + LEFT JOIN Rapsys\AirBundle\Entity\Session AS s3 ON (s3.id != b.session_id AND s3.application_id IS NOT NULL AND s3.locked IS NULL AND s3.date > b.date - INTERVAL 1 YEAR) + LEFT JOIN Rapsys\AirBundle\Entity\Application AS a3 ON (a3.id = s3.application_id AND a3.user_id = b.user_id AND (a3.canceled IS NULL OR TIMESTAMPDIFF(DAY, a3.canceled, ADDDATE(ADDTIME(s3.date, s3.begin), INTERVAL IF(s3.slot_id = :afterid, 1, 0) DAY)) < 1)) GROUP BY b.id ORDER BY NULL LIMIT 0, :limit ) AS c - LEFT JOIN RapsysAirBundle:Session AS s4 ON (s4.id != c.session_id AND s4.location_id = c.location_id AND s4.application_id IS NOT NULL AND s4.locked IS NULL AND s4.date > c.date - INTERVAL 1 YEAR) - LEFT JOIN RapsysAirBundle:Application AS a4 ON (a4.id = s4.application_id AND a4.user_id != c.user_id AND (a4.canceled IS NULL OR TIMESTAMPDIFF(DAY, a4.canceled, ADDDATE(ADDTIME(s4.date, s4.begin), INTERVAL IF(s4.slot_id = :afterid, 1, 0) DAY)) < 1)) + LEFT JOIN Rapsys\AirBundle\Entity\Session AS s4 ON (s4.id != c.session_id AND s4.location_id = c.location_id AND s4.application_id IS NOT NULL AND s4.locked IS NULL AND s4.date > c.date - INTERVAL 1 YEAR) + LEFT JOIN Rapsys\AirBundle\Entity\Application AS a4 ON (a4.id = s4.application_id AND a4.user_id != c.user_id AND (a4.canceled IS NULL OR TIMESTAMPDIFF(DAY, a4.canceled, ADDDATE(ADDTIME(s4.date, s4.begin), INTERVAL IF(s4.slot_id = :afterid, 1, 0) DAY)) < 1)) GROUP BY c.id ORDER BY NULL LIMIT 0, :limit ) AS d - LEFT JOIN RapsysAirBundle:UserGroup AS ug ON (ug.user_id = d.user_id) + LEFT JOIN Rapsys\AirBundle\Entity\UserGroup AS ug ON (ug.user_id = d.user_id) GROUP BY d.id LIMIT 0, :limit ) AS e @@ -1616,7 +1501,7 @@ SQL; $req = str_replace($this->tableKeys, $this->tableValues, $req); //Set update request - $upreq = 'UPDATE RapsysAirBundle:Application SET score = :score, updated = NOW() WHERE id = :id'; + $upreq = 'UPDATE Rapsys\AirBundle\Entity\Application SET score = :score, updated = NOW() WHERE id = :id'; //Replace bundle entity name by table name $upreq = str_replace($this->tableKeys, $this->tableValues, $upreq); @@ -1626,7 +1511,7 @@ SQL; //Declare all fields $rsm - ->addEntityResult('RapsysAirBundle:Application', 'a') + ->addEntityResult('Rapsys\AirBundle\Entity\Application', 'a') ->addFieldResult('a', 'id', 'id') ->addFieldResult('a', 'score', 'score') ->addIndexBy('a', 'id'); @@ -1679,8 +1564,8 @@ FROM ( s.begin, s.slot_id, GROUP_CONCAT(sa.id ORDER BY sa.id SEPARATOR "\\n") AS sa_id - FROM RapsysAirBundle:Session AS s - LEFT JOIN RapsysAirBundle:Application AS sa ON (sa.session_id = s.id) + FROM Rapsys\AirBundle\Entity\Session AS s + LEFT JOIN Rapsys\AirBundle\Entity\Application AS sa ON (sa.session_id = s.id) GROUP BY s.id ORDER BY NULL ) AS a @@ -1712,7 +1597,7 @@ SQL; //Set update session request $sreq = <<