- $req = 'SELECT s.id, s.date, s.rainrisk, s.rainfall, s.realfeel, s.temperature, s.location_id AS l_id, l.short AS l_short, l.title AS l_title, s.slot_id AS t_id, t.title AS t_title, s.application_id AS a_id, a.user_id AS a_u_id, au.pseudonym AS a_u_pseudonym, GROUP_CONCAT(sa.user_id ORDER BY sa.user_id SEPARATOR "\\n") AS as_u_id, GROUP_CONCAT(CONCAT("- ", sau.pseudonym) ORDER BY sa.user_id SEPARATOR "\\n") AS as_u_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)
- '.($userId?'JOIN RapsysAirBundle:Application AS sua ON (sua.session_id = s.id)':'').'
- LEFT JOIN RapsysAirBundle:Application AS a ON (a.id = s.application_id)
- LEFT JOIN RapsysAirBundle:User AS au ON (au.id = a.user_id)
- LEFT JOIN RapsysAirBundle:Application AS sa ON (sa.session_id = s.id)
- LEFT JOIN RapsysAirBundle:User AS sau ON (sau.id = sa.user_id)
- WHERE s.date BETWEEN :begin AND :end
- '.($userId?'AND sua.user_id = :uid':'').'
- GROUP BY s.id
- ORDER BY NULL';
+ //TODO: change as_u_* in sau_*, a_u_* in au_*, etc, see request up
+ $req = <<<SQL
+SELECT
+ s.id,
+ s.date,
+ s.rainrisk,
+ s.rainfall,
+ s.realfeel,
+ s.temperature,
+ s.locked,
+ ADDDATE(ADDTIME(s.date, s.begin), INTERVAL IF(s.slot_id = :afterid, 1, 0) DAY) AS start,
+ ADDDATE(ADDTIME(ADDTIME(s.date, s.begin), s.length), INTERVAL IF(s.slot_id = :afterid, 1, 0) DAY) AS stop,
+ s.location_id AS l_id,
+ l.short AS l_short,
+ l.title AS l_title,
+ s.slot_id AS t_id,
+ t.title AS t_title,
+ s.application_id AS a_id,
+ a.user_id AS au_id,
+ au.pseudonym AS au_pseudonym,
+ GROUP_CONCAT(sa.user_id ORDER BY sa.user_id SEPARATOR "\\n") AS sau_id,
+ GROUP_CONCAT(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)
+${userJoinSql}LEFT JOIN RapsysAirBundle:Application AS a ON (a.id = s.application_id)
+LEFT JOIN RapsysAirBundle:User AS au ON (au.id = a.user_id)
+LEFT JOIN RapsysAirBundle:Application AS sa ON (sa.session_id = s.id)
+LEFT JOIN RapsysAirBundle:User AS sau ON (sau.id = sa.user_id)
+WHERE s.date BETWEEN :begin AND :end${userWhereSql}
+GROUP BY s.id
+ORDER BY NULL
+SQL;