Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
DALDeleteParser.inc
1 <?php
13 require_once 'DAL/Parsers/DALQueryParser.inc';
14 require_once 'DAL/DALBaker.inc';
15 require_once 'DAL/Parsers/DALWhereParser.inc';
16 
25 {
26 
27 
36  private function __construct()
37  {
38 
39  }//end __construct()
40 
41 
57  public static function parse(DomElement $xmlQuery)
58  {
59  $query = array();
60  $deleteTag = $xmlQuery->getElementsByTagName('delete')->item(0);
61 
62  if ($deleteTag !== NULL) {
63  $query['DELETE'] = array();
64 
65  // There must be a where tag and should have been checked before.
66  $whereTag = $deleteTag->getElementsByTagName('where')->item(0);
67 
68  $i = 0;
69  $length = $whereTag->childNodes->length;
70  // Get the first field with table attr to retrieve the table name.
71  while ($i < $length) {
72  $cond = $whereTag->childNodes->item($i);
73  $i++;
74 
75  if ($cond->nodeType !== XML_ELEMENT_NODE) {
76  continue;
77  }
78 
79  if (DALBaker::getComparisonOperators($cond->tagName) !== '') {
80  $deleteFrom = $cond->getAttribute('table');
81  break;
82  } else {
83  $whereTag = $cond;
84  $length = $whereTag->childNodes->length;
85  $i = 0;
86  }
87  }//end foreach
88 
89  $query['DELETE']['from'] = $deleteFrom;
90 
91  // Where condition.
92  $whereCond = DALWhereParser::parse($deleteTag);
93  $query['DELETE'] = array_merge($query['DELETE'], $whereCond);
94  }//end if
95 
96  return $query;
97 
98  }//end parse()
99 
100 
114  public static function validate(DomElement $query)
115  {
116  $deleteTag = $query->getElementsByTagName('delete')->item(0);
117  if ($deleteTag === NULL) {
118  throw new DALParserException('Delete tag not found.');
119  }
120 
121  // Must have where tag.
122  $whereTag = $deleteTag->getElementsByTagName('where')->item(0);
123  if ($whereTag === NULL) {
124  $msg = 'Delete query must have a where tag.';
125  throw new DALParserException($msg);
126  } else {
127  DALWhereParser::validate($whereTag);
128  }
129 
130  }//end validate()
131 
132 
133 }//end class
134 
135 ?>