SELECT 
  u0_.id AS id0, 
  u1_.title AS title1, 
  u0_.start_date AS start_date2, 
  u0_.end_date AS end_date3 
FROM 
  us_timeline_timeline_activity u0_ 
  LEFT JOIN us_activity_activity u1_ ON u0_.activity_id = u1_.id 
  LEFT JOIN us_activity_survey u2_ ON u1_.id = u2_.id 
  LEFT JOIN us_activity_test u3_ ON u1_.id = u3_.id 
  LEFT JOIN us_activity_form u4_ ON u1_.id = u4_.id 
  LEFT JOIN us_activity_tasklist u5_ ON u1_.id = u5_.id 
  LEFT JOIN us_activity_media u6_ ON u1_.id = u6_.id 
  LEFT JOIN us_activity_dialog u7_ ON u1_.id = u7_.id 
  LEFT JOIN us_game_game u8_ ON u1_.id = u8_.id 
  LEFT JOIN us_activity_satisfaction_survey u9_ ON u1_.id = u9_.id 
  LEFT JOIN us_timeline_timeline u10_ ON u0_.timeline_id = u10_.id 
WHERE 
  (
    u0_.status = 5 
    OR u0_.status = 2
  ) 
  AND u10_.responsible_id = 4
ORDER BY 
  u0_.send_date DESC;
  
-- validate activities

SELECT 
  u0_.id AS id0, 
  u1_.title AS title1, 
  u0_.start_date AS start_date2, 
  u0_.end_date AS end_date3, 
  u0_.id AS id4, 
  u0_.status AS status5, 
  u0_.start_date AS start_date6, 
  u0_.end_date AS end_date7, 
  u0_.performance AS performance8, 
  u0_.time_played AS time_played9, 
  u0_.last_time_played AS last_time_played10, 
  u0_.best_time_played AS best_time_played11, 
  u0_.`match` AS match12, 
  u0_.points AS points13, 
  u0_.createdAt AS createdAt14, 
  u0_.updatedAt AS updatedAt15, 
  u0_.is_mandatory AS is_mandatory16, 
  u0_.send_date AS send_date17, 
  u0_.test_questions AS test_questions18, 
  u0_.tla_file AS tla_file19 
FROM 
  us_timeline_timeline_activity u0_ 
  LEFT JOIN us_activity_activity u1_ ON u0_.activity_id = u1_.id 
  LEFT JOIN us_activity_survey u2_ ON u1_.id = u2_.id 
  LEFT JOIN us_activity_test u3_ ON u1_.id = u3_.id 
  LEFT JOIN us_activity_form u4_ ON u1_.id = u4_.id 
  LEFT JOIN us_activity_tasklist u5_ ON u1_.id = u5_.id 
  LEFT JOIN us_activity_media u6_ ON u1_.id = u6_.id 
  LEFT JOIN us_activity_dialog u7_ ON u1_.id = u7_.id 
  LEFT JOIN us_game_game u8_ ON u1_.id = u8_.id 
  LEFT JOIN us_activity_satisfaction_survey u9_ ON u1_.id = u9_.id 
  LEFT JOIN us_timeline_timeline u10_ ON u0_.timeline_id = u10_.id 
WHERE 
  (
    u0_.status = 5 
    OR u0_.status = 2
  ) 
  AND u10_.responsible_id = 4
ORDER BY 
  u0_.send_date DESC 
LIMIT 
  5;
  
  -- expired
  
SELECT 
  u0_.id AS id0, 
  u1_.title AS title1, 
  u0_.start_date AS start_date2, 
  u0_.end_date AS end_date3, 
  u0_.id AS id4, 
  u0_.status AS status5, 
  u0_.start_date AS start_date6, 
  u0_.end_date AS end_date7, 
  u0_.performance AS performance8, 
  u0_.time_played AS time_played9, 
  u0_.last_time_played AS last_time_played10, 
  u0_.best_time_played AS best_time_played11, 
  u0_.`match` AS match12, 
  u0_.points AS points13, 
  u0_.createdAt AS createdAt14, 
  u0_.updatedAt AS updatedAt15, 
  u0_.is_mandatory AS is_mandatory16, 
  u0_.send_date AS send_date17, 
  u0_.test_questions AS test_questions18, 
  u0_.tla_file AS tla_file19 
FROM 
  us_timeline_timeline_activity u0_ 
  LEFT JOIN us_timeline_timeline u2_ ON u0_.timeline_id = u2_.id 
  LEFT JOIN us_activity_activity u1_ ON u0_.activity_id = u1_.id 
  LEFT JOIN us_activity_survey u3_ ON u1_.id = u3_.id 
  LEFT JOIN us_activity_test u4_ ON u1_.id = u4_.id 
  LEFT JOIN us_activity_form u5_ ON u1_.id = u5_.id 
  LEFT JOIN us_activity_tasklist u6_ ON u1_.id = u6_.id 
  LEFT JOIN us_activity_media u7_ ON u1_.id = u7_.id 
  LEFT JOIN us_activity_dialog u8_ ON u1_.id = u8_.id 
  LEFT JOIN us_game_game u9_ ON u1_.id = u9_.id 
  LEFT JOIN us_activity_satisfaction_survey u10_ ON u1_.id = u10_.id 
WHERE 
  (
    u0_.status = 5 
    OR u0_.status = 2
  ) 
  AND u2_.responsible_id = 4
ORDER BY 
  u0_.send_date DESC 
LIMIT 
  5;


-- expired
SELECT 
  u0_.id AS id0, 
  u1_.firstname AS firstname1, 
  u1_.id AS id2, 
  u2_.id AS id3, 
  u1_.host_type AS host_type4, 
  u3_.name AS name5, 
  u4_.name AS name6, 
  u5_.title AS title7, 
  u0_.id AS id8, 
  u0_.status AS status9, 
  u0_.performance AS performance10, 
  u0_.time_played AS time_played11, 
  u0_.last_time_played AS last_time_played12, 
  u0_.best_time_played AS best_time_played13, 
  u0_.`match` AS match14, 
  u0_.points AS points15, 
  u0_.createdAt AS createdAt16, 
  u0_.updatedAt AS updatedAt17, 
  u0_.is_mandatory AS is_mandatory18, 
  u0_.start_date AS start_date19, 
  u0_.end_date AS end_date20, 
  u0_.send_date AS send_date21, 
  u0_.test_questions AS test_questions22, 
  u0_.tla_file AS tla_file23 
FROM 
  us_timeline_timeline_activity u0_ 
  LEFT JOIN us_timeline_timeline u6_ ON u0_.timeline_id = u6_.id 
  LEFT JOIN us_activity_activity u5_ ON u0_.activity_id = u5_.id 
  LEFT JOIN us_activity_survey u7_ ON u5_.id = u7_.id 
  LEFT JOIN us_activity_test u8_ ON u5_.id = u8_.id 
  LEFT JOIN us_activity_form u9_ ON u5_.id = u9_.id 
  LEFT JOIN us_activity_tasklist u10_ ON u5_.id = u10_.id 
  LEFT JOIN us_activity_media u11_ ON u5_.id = u11_.id 
  LEFT JOIN us_activity_dialog u12_ ON u5_.id = u12_.id 
  LEFT JOIN us_game_game u13_ ON u5_.id = u13_.id 
  LEFT JOIN us_activity_satisfaction_survey u14_ ON u5_.id = u14_.id 
  LEFT JOIN us_user_user u2_ ON u6_.responsible_id = u2_.id 
  LEFT JOIN us_user_user u1_ ON u6_.user_id = u1_.id 
  LEFT JOIN us_user_direction u3_ ON u1_.direction_id = u3_.id 
  LEFT JOIN us_timeline_timeline_phase u15_ ON u6_.id = u15_.timeline_id 
  LEFT JOIN us_timeline_phase u4_ ON u15_.phase_id = u4_.id 
WHERE 
  u0_.status = 4 
  AND u15_.timeline_id = u6_.id 
  AND (
    u0_.start_date BETWEEN u15_.start_date 
    AND u15_.end_date
  ) 
ORDER BY 
  u0_.start_date ASC ;
  