Guest User

Untitled

a guest
Jun 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. public static function getRow($class, $id = null, $slug = null, $get_children = true) {
  2. try {
  3. $query = Doctrine_Query::create()
  4. ->setHydrationMode(Doctrine::HYDRATE_ARRAY)
  5. ->from('Node n')
  6. ->leftJoin('n.ChildNode n_cn')
  7. ->leftJoin('n.MediaNode n_mn')
  8. ->leftJoin('n_mn.Media n_mn_m')
  9. ->addWhere('n.class = ?', $class);
  10.  
  11. if(!empty($id)) {
  12. $query->addWhere('n.id = ?', $id);
  13. }
  14.  
  15. if(!empty($slug)) {
  16. $query->addWhere('n.slug = ?', $slug);
  17. }
  18.  
  19. $node = $query->fetchOne();
  20.  
  21. if(!empty($node)) {
  22.  
  23. $className = ucwords($node['class']);
  24.  
  25. if(class_exists($className)) {
  26.  
  27. $result = Doctrine_Query::create()
  28. ->setHydrationMode(Doctrine::HYDRATE_ARRAY)
  29. ->from(sprintf('%s m', $className))
  30. ->where('m.node_id = ?', $node['id'])
  31. ->fetchOne();
  32.  
  33. $node['Content'] = $result;
  34.  
  35. if(!empty($node['ChildNode']) && $get_children == true) {
  36. foreach($node['ChildNode'] as $cn_key => $child_node) {
  37. $node['ChildNode'][$cn_key] = self::getRow($child_node['class'], $child_node['id'], null, false);
  38. }
  39. }
  40.  
  41. return $node;
  42.  
  43. } else {
  44. throw new Wfm_Doctrine_NodeException(sprintf('Model class <u>%s</u> does not exist', $className));
  45. }
  46. } else {
  47. throw new Wfm_Doctrine_NodeException('Node not found');
  48. }
  49. } catch(Doctrine_Connection_Mysql_Exception $e) {
  50. throw new Wfm_Doctrine_NodeInvalidQueryException($e->getMessage(), $query);
  51. }
  52. }
Add Comment
Please, Sign In to add comment