XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
ConditionTag.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
3 
13 {
14 
20 
26 
31  var $pipe;
32 
38 
43  var $argument;
44 
50 
55  var $query;
56 
62  function __construct($condition)
63  {
64  $this->operation = $condition->attrs->operation;
65  $this->pipe = $condition->attrs->pipe;
66  $dbParser = DB::getParser();
67  $this->column_name = $dbParser->parseExpression($condition->attrs->column);
68 
69  // If default value is column name, it should be escaped
70  if($isColumnName = (strpos($condition->attrs->default, '.') !== FALSE
71  && strpos($condition->attrs->default, '.') !== 0
72  && strpos($condition->attrs->default, '%') === FALSE ))
73  {
74  $condition->attrs->default = $dbParser->parseExpression($condition->attrs->default);
75  }
76 
77  if($condition->node_name == 'query')
78  {
79  $this->query = new QueryTag($condition, TRUE);
80  $this->default_column = $this->query->toString();
81  }
82  else if($condition->attrs->var && !strpos($condition->attrs->var, '.'))
83  {
84  $this->argument = new QueryArgument($condition);
85  $this->argument_name = $this->argument->getArgumentName();
86  }
87  else
88  {
89  if(isset($condition->attrs->default))
90  {
91  $operationList = array('in' => 1, 'between' => 1, 'notin' => 1, 'not_in' => 1);
92  if(isset($operationList[$this->operation]))
93  {
94  $default_value = $condition->attrs->default;
95  if(strpos($default_value, "'") !== FALSE)
96  {
97  $default_value = "\"" . $default_value . "\"";
98  }
99  else
100  {
101  $default_value = "'" . $default_value . "'";
102  }
103  }
104  else
105  {
106  $default_value_object = new DefaultValue($this->column_name, $condition->attrs->default);
107  $default_value = $default_value_object->toString();
108 
109  if($default_value_object->isStringFromFunction())
110  {
111  $default_value = '"\'".' . $default_value . '."\'"';
112  }
113 
114  if($default_value_object->isString() && !$isColumnName && !is_numeric($condition->attrs->default))
115  {
116  if(strpos($default_value, "'") !== FALSE)
117  {
118  $default_value = "\"" . $default_value . "\"";
119  }
120  else
121  {
122  $default_value = "'" . $default_value . "'";
123  }
124  }
125  }
126  $this->default_column = $default_value;
127  }
128  else
129  {
130  $this->default_column = "'" . $dbParser->parseColumnName($condition->attrs->var) . "'";
131  }
132  }
133  }
134 
135  function setPipe($pipe)
136  {
137  $this->pipe = $pipe;
138  }
139 
140  function getArguments()
141  {
142  $arguments = array();
143  if($this->query)
144  {
145  $arguments = array_merge($arguments, $this->query->getArguments());
146  }
147  if($this->argument)
148  {
149  $arguments[] = $this->argument;
150  }
151  return $arguments;
152  }
153 
155  {
156  if($this->query)
157  {
158  return sprintf("new ConditionSubquery('%s',%s,%s%s)"
159  , $this->column_name
160  , $this->default_column
161  , '"' . $this->operation . '"'
162  , $this->pipe ? ", '" . $this->pipe . "'" : ''
163  );
164  }
165  else if(isset($this->default_column))
166  {
167  return sprintf("new ConditionWithoutArgument('%s',%s,%s%s)"
168  , $this->column_name
169  , $this->default_column
170  , '"' . $this->operation . '"'
171  , $this->pipe ? ", '" . $this->pipe . "'" : ''
172  );
173  }
174  else
175  {
176  return sprintf("new ConditionWithArgument('%s',%s,%s%s)"
177  , $this->column_name
178  , '$' . $this->argument_name . '_argument'
179  , '"' . $this->operation . '"'
180  , $this->pipe ? ", '" . $this->pipe . "'" : ''
181  );
182  }
183  }
184 
185 }
186 /* End of file ConditionTag.class.php */
187 /* Location: ./classes/xml/xmlquery/tags/condition/ConditionTag.class.php */
__construct($condition)
getParser($force=FALSE)
Definition: DB.class.php:1345