ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.arWhere.php
Go to the documentation of this file.
1 <?php
2 require_once(dirname(__FILE__) . '/../Statement/class.arStatement.php');
3 
10 class arWhere extends arStatement {
11 
12  const TYPE_STRING = 1;
13  const TYPE_REGULAR = 2;
21  protected $fieldname = '';
25  protected $value;
29  protected $operator = '=';
33  protected $statement = '';
37  protected $link = 'AND';
38 
39 
48  public function asSQLStatement(ActiveRecord $ar) {
49  if ($this->getType() == self::TYPE_REGULAR) {
50  $arField = $ar->getArFieldList()->getFieldByName($this->getFieldname());
51  if ($arField instanceof arField) {
52  $type = $arField->getFieldType();
53  $statement = $ar->getConnectorContainerName() . '.' . $this->getFieldname();
54  } else {
55  $statement = $this->getFieldname();
56  }
57 
58  if (is_array($this->getValue())) {
59  if (in_array($this->getOperator(), array( 'IN', 'NOT IN', 'NOTIN' ))) {
60  $statement .= ' ' . $this->getOperator() . ' (';
61  } else {
62  $statement .= ' IN (';
63  }
64  $values = array();
65  foreach ($this->getValue() as $value) {
66  $values[] = $ar->getArConnector()->quote($value, $type);
67  }
68  $statement .= implode(', ', $values);
69  $statement .= ')';
70  } else {
71  if ($this->getValue() === NULL) {
72  $this->setOperator('IS');
73  }
74  $statement .= ' ' . $this->getOperator();
75  $statement .= ' ' . $ar->getArConnector()->quote($this->getValue(), $type);
76  }
77  $this->setStatement($statement);
78  }
79 
80  return $this->getStatement();
81  }
82 
83 
87  public function setFieldname($fieldname) {
88  $this->fieldname = $fieldname;
89  }
90 
91 
95  public function getFieldname() {
96  return $this->fieldname;
97  }
98 
99 
103  public function setOperator($operator) {
104  $this->operator = $operator;
105  }
106 
107 
111  public function getOperator() {
112  return $this->operator;
113  }
114 
115 
119  public function setValue($value) {
120  $this->value = $value;
121  }
122 
123 
127  public function getValue() {
128  return $this->value;
129  }
130 
131 
135  public function setType($type) {
136  $this->type = $type;
137  }
138 
139 
143  public function getType() {
144  return $this->type;
145  }
146 
147 
151  public function setStatement($statement) {
152  $this->statement = $statement;
153  }
154 
155 
159  public function getStatement() {
160  return $this->statement;
161  }
162 
163 
167  public function setLink($link) {
168  $this->link = $link;
169  }
170 
171 
175  public function getLink() {
176  return $this->link;
177  }
178 }
179 
180 ?>