Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
DALOrderByParser.inc
1 <?php
13 require_once 'DAL/Parsers/DALQueryParser.inc';
14 require_once 'XML/XML.inc';
15 
24 {
25 
26 
35  private function __construct()
36  {
37 
38  }//end __construct()
39 
40 
59  public static function parse(DomElement $parent)
60  {
61  $query = array();
62  $orderBy = $parent->getElementsByTagName('order-by')->item(0);
63  if ($orderBy !== NULL && $orderBy->parentNode === $parent) {
64  $query['ORDER-BY'] = self::parseChildFields($orderBy);
65  if ($orderBy->getAttribute('direction') !== '') {
66  $query['ORDER-BY']['direction'] = $orderBy->getAttribute('direction');
67  }
68  }
69 
70  return $query;
71 
72  }//end parse()
73 
74 
86  public static function validate(DomElement $select)
87  {
88  // Check the first order-by (could be in a sub query).
89  $orderBy = $select->getElementsByTagName('order-by')->item(0);
90  if ($orderBy !== NULL) {
91  $tagNames = array(
92  'field',
93  'hook',
94  'alias',
95  );
96 
97  $tags = XML::getElementsByTagNames($tagNames, $orderBy);
98  if (count($tags) === 0) {
99  $msg = 'order-by tag must have at least one field or hook.';
100  throw new DALParserException($msg);
101  } else {
102  foreach ($tags as $tag) {
103  if ($tag->tagName === 'field') {
104  self::validateField($tag);
105  } else if ($tag->tagName === 'hook') {
106  self::validateHook($tag);
107  }
108  }
109  }
110  }//end if
111 
112  }//end validate()
113 
114 
115 }//end class
116 
117 ?>