Guest User

Untitled

a guest
Jul 18th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. <?php
  2. $sql = "SELECT DISTINCT {TC.id}, {T.id}, {T.tag}, IF (ACT.tag_id IS NULL, 0, 1) AS status
  3. FROM exercise_tag ET2, tag T LEFT JOIN
  4. (
  5.  
  6.  
  7. SELECT ET.tag_id
  8. FROM exercise_tag ET,
  9. (
  10. SELECT E.exercise_id
  11. FROM exercise_tag E
  12. WHERE E.tag_id IN ('29','1')
  13. GROUP BY E.exercise_id
  14. HAVING count(E.exercise_id) = 2
  15.  
  16. )
  17. EX WHERE ET.exercise_id=EX.exercise_id
  18. GROUP BY ET.tag_id
  19.  
  20. )
  21. ACT ON (T.id=ACT.tag_id)
  22. LEFT JOIN tag_category TC ON (T.category_id=TC.id)
  23. WHERE
  24. ET2.tag_id=T.id
  25. ORDER BY TC.id" " ;
  26. $q = new Doctrine_RawSql();
  27.  
  28. $q->parseQuery($sql);
  29.  
  30.  
  31. $q->addComponent('ET', 'ExerciseTag');
  32. $q->addComponent('T', 'Tag');
  33. $q->addComponent('ETSEL', 'ExerciseTag');
  34. $q->addComponent('TC', 'TagCategory');
  35. $q->addComponent('ET2', 'ExerciseTag');
  36.  
  37.  
  38. $q->execute(array(), Doctrine::HYDRATE_ARRAY);
Add Comment
Please, Sign In to add comment