Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
DALGroupByParser.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  $groupBy = $parent->getElementsByTagName('group-by')->item(0);
63  if ($groupBy !== NULL) {
64  if ($groupBy->hasChildNodes() === TRUE) {
65  $query['GROUP-BY'] = self::parseChildFields($groupBy);
66  }
67  }
68 
69  return $query;
70 
71  }//end parse()
72 
73 
86  public static function validate(DomElement $select)
87  {
88  // Check the first group-by (could be in a sub query).
89  $groupBy = $select->getElementsByTagName('group-by')->item(0);
90  if ($groupBy !== NULL) {
91  $tagNames = array(
92  'field',
93  'hook',
94  'alias',
95  );
96 
97  $tags = XML::getElementsByTagNames($tagNames, $groupBy);
98  if (count($tags) === 0) {
99  $msg = 'group-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 ?>