ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.arWhere.php
Go to the documentation of this file.
1 <?php
2 
24 class arWhere extends arStatement
25 {
26  public const TYPE_STRING = 1;
27  public const TYPE_REGULAR = 2;
28  protected int $type = self::TYPE_REGULAR;
29  protected string $fieldname = '';
33  protected $value;
34  protected string $operator = '=';
35  protected string $statement = '';
36  protected string $link = 'AND';
37 
43  public function asSQLStatement(ActiveRecord $activeRecord, ilDBInterface $db): string
44  {
45  $type = null;
46  if ($this->getType() === self::TYPE_REGULAR) {
47  $arField = $activeRecord->getArFieldList()->getFieldByName($this->getFieldname());
48  $type = 'text';
49  if ($arField instanceof arField) {
50  $type = $arField->getFieldType();
51  $statement = $activeRecord->getConnectorContainerName() . '.' . $this->getFieldname();
52  } else {
53  $statement = $this->getFieldname();
54  }
55 
56  if (is_array($this->getValue())) {
57  if (in_array($this->getOperator(), ['IN', 'NOT IN', 'NOTIN'])) {
58  $statement .= ' ' . $this->getOperator() . ' (';
59  } else {
60  $statement .= ' IN (';
61  }
62  $values = [];
63  foreach ($this->getValue() as $value) {
64  $values[] = $activeRecord->getArConnector()->quote($value, $type);
65  }
66  $statement .= implode(', ', $values);
67  $statement .= ')';
68  } else {
69  if ($this->getValue() === null) {
70  $operator = 'IS';
71  if (in_array($this->getOperator(), ['IS', 'IS NOT'])) {
72  $operator = $this->getOperator();
73  }
74  $this->setOperator($operator);
75  }
76  $statement .= ' ' . $this->getOperator();
77  $statement .= ' ' . $activeRecord->getArConnector()->quote($this->getValue(), $type);
78  }
79  $this->setStatement($statement);
80  }
81 
82  return $this->getStatement();
83  }
84 
85  public function setFieldname(string $fieldname): void
86  {
87  $this->fieldname = $fieldname;
88  }
89 
90  public function getFieldname(): string
91  {
92  return $this->fieldname;
93  }
94 
95  public function setOperator(string $operator): void
96  {
97  $this->operator = $operator;
98  }
99 
100  public function getOperator(): string
101  {
102  return $this->operator;
103  }
104 
105  public function setValue(mixed $value): void
106  {
107  $this->value = $value;
108  }
109 
113  public function getValue()
114  {
115  return $this->value;
116  }
117 
118  public function setType(int $type): void
119  {
120  $this->type = $type;
121  }
122 
123  public function getType(): int
124  {
125  return $this->type;
126  }
127 
128  public function setStatement(string $statement): void
129  {
130  $this->statement = $statement;
131  }
132 
133  public function getStatement(): string
134  {
135  return $this->statement;
136  }
137 
138  public function setLink(string $link): void
139  {
140  $this->link = $link;
141  }
142 
143  public function getLink(): string
144  {
145  return $this->link;
146  }
147 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
string $link
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setFieldname(string $fieldname)
string $fieldname
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
const TYPE_REGULAR
setValue(mixed $value)
string $statement
setLink(string $link)
getConnectorContainerName()
Return the Name of your Connector Table
setType(int $type)
asSQLStatement(ActiveRecord $activeRecord, ilDBInterface $db)
setStatement(string $statement)
link(string $caption, string $href, bool $new_viewport=false)
const TYPE_STRING
setOperator(string $operator)