52 protected bool $raw =
false;
59 $this->
class = $activeRecord::class;
60 $this->
setAR($activeRecord);
71 $arSelect->setFieldName(
'*');
97 public function where($where, $operator =
null): self
99 $this->loaded =
false;
100 if (is_string($where)) {
103 $arWhere->setStatement($where);
109 if (is_array($where)) {
110 foreach ($where as $field_name => $value) {
112 $arWhere->setFieldname($field_name);
113 $arWhere->setValue($value);
115 if (is_array($operator)) {
116 $arWhere->setOperator($operator[$field_name]);
118 $arWhere->setOperator($operator);
127 throw new Exception(
'Wrong where Statement, use strings or arrays');
134 public function orderBy(
string $order_by,
string $order_direction =
'ASC'): self
137 $arOrder->setFieldname($order_by);
138 $arOrder->setDirection($order_direction);
149 public function limit(
int $start,
int $end): self
152 $arLimit->setStart($start);
153 $arLimit->setEnd($end);
168 array $fields = [
'*'],
169 string $operator =
'=',
170 bool $both_external =
false
173 $activeRecord->getConnectorContainerName(),
193 array $fields = [
'*'],
194 string $operator =
'=',
195 bool $both_external =
false
197 if (!$both_external && !$this->getAR()->getArFieldList()->isField($on_this)) {
201 foreach ($fields as $field_name) {
202 if ($this->getAR()->getArFieldList()->isField($field_name)) {
209 $arJoin->setType($type);
210 $arJoin->setFullNames($full_names);
211 $arJoin->setTableName($tablename);
212 $arJoin->setOnFirstField($on_this);
213 $arJoin->setOnSecondField($on_external);
214 $arJoin->setOperator($operator);
215 $arJoin->setFields($fields);
216 $arJoin->setBothExternal($both_external);
217 $this->getArJoinCollection()->add($arJoin);
219 foreach ($fields as $field) {
221 $arSelect->setTableName($arJoin->getTableNameAs());
222 $arSelect->setFieldName($field);
223 $arSelect->setAs($arJoin->getTableNameAs() .
'_' . $field);
224 $this->getArSelectCollection()->add($arSelect);
239 array $fields = [
'*'],
240 string $operator =
'=',
241 bool $both_external =
false
243 return $this->join(
arJoin::TYPE_LEFT, $tablename, $on_this, $on_external, $fields, $operator, $both_external);
255 array $fields = [
'*'],
256 string $operator =
'=',
257 bool $both_external =
false
259 return $this->join(
arJoin::TYPE_INNER, $tablename, $on_this, $on_external, $fields, $operator, $both_external);
265 public function concat(array $fields,
string $as): self
268 $arConcat->setAs($as);
269 $arConcat->setFields($fields);
270 $this->getArConcatCollection()->add($arConcat);
277 return $this->arWhereCollection;
282 return $this->arJoinCollection;
287 return $this->arOrderCollection;
292 return $this->arLimitCollection;
297 return $this->arConcatCollection;
302 return $this->arSelectCollection;
307 return $this->arHavingCollection;
315 public function dateFormat(
string $date_format =
'd.m.Y - H:i:s'): self
317 $this->loaded =
false;
318 $this->setDateFormat($date_format);
325 $this->loaded =
false;
333 $this->connector = $arConnector;
338 public function raw(
bool $set_raw =
true): self
340 $this->setRaw($set_raw);
347 return $this->affectedRows() > 0;
352 return $this->getArConnector()->affectedRows($this);
357 return $this->affectedRows();
367 $this->
class = $class;
378 public function get(): array
382 return $this->result;
390 $this->loadLastQuery();
392 $result = array_values($this->result);
394 return array_shift($result);
401 $result = array_values($this->result);
403 return array_shift($result);
410 $result = array_values($this->result);
412 return array_pop($result);
420 public function getArray(?
string $key =
null,
string|array|
null $values =
null): array
424 return $this->buildArray($key, $values);
434 if ($key ===
null && $values ===
null) {
435 return $this->result_array;
438 foreach ($this->result_array as $row) {
440 if (!array_key_exists($key, $row)) {
441 throw new Exception(
"The attribute $key does not exist on this model.");
443 $array[$row[$key]] = $this->buildRow($row, $values);
445 $array[] = $this->buildRow($row, $values);
458 if ($values ===
null) {
462 if (!is_array($values)) {
463 return $row[$values];
467 foreach ($row as $key => $value) {
468 if (in_array($key, $values)) {
469 $array[$key] = $value;
476 protected function load(): void
482 $records = $this->getArConnector()->readSet($this);
486 $primaryFieldName = $this->getAR()->getArFieldList()->getPrimaryFieldName();
488 $class_name = $this->getAR()::class;
489 foreach ($records as $record) {
490 $primary_field_value = $record[$primaryFieldName];
491 if (!$this->getRaw()) {
492 $obj =
new $class_name(0, $this->getArConnector(), $this->getAddidtionalParameters());
493 $this->result[$primary_field_value] = $obj->buildFromArray($record);
496 if (!$this->getRaw()) {
497 foreach ($record as $key => $value) {
498 $arField = $obj->getArFieldList()->getFieldByName($key);
499 if ($arField !==
null && ($arField->isDateField() && $this->getDateFormat())) {
500 $res_awake[$key .
'_unformatted'] = $value;
501 $res_awake[$key .
'_unix'] = strtotime((
string) $value);
502 $value = date($this->getDateFormat(), strtotime((
string) $value));
504 $waked = $this->getAR()->wakeUp($key, $value);
505 $res_awake[$key] = $waked ?? $value;
507 $this->result_array[$res_awake[$primaryFieldName]] = $res_awake;
509 $this->result_array[$primary_field_value] = $record;
512 $this->loaded =
true;
525 $this->ar = $activeRecord;
540 $this->date_format = $date_format;
545 return $this->date_format ??
'';
550 self::$last_query = $last_query;
555 return self::$last_query;
563 $this->addidtional_parameters = $addidtional_parameters;
571 return $this->addidtional_parameters;
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static string $last_query
arLimitCollection $arLimitCollection
connector(arConnector $arConnector)
setAR(\ActiveRecord $activeRecord)
innerjoin(string $tablename, $on_this, string $on_external, array $fields=[' *'], string $operator='=', bool $both_external=false)
buildArray(?string $key, $values)
limit(int $start, int $end)
arWhereCollection $arWhereCollection
innerjoinAR(ActiveRecord $activeRecord, $on_this, string $on_external, array $fields=[' *'], string $operator='=', bool $both_external=false)
where($where, $operator=null)
setDateFormat(string $date_format)
getAddidtionalParameters()
leftjoin(string $tablename, $on_this, string $on_external, array $fields=[' *'], string $operator='=', bool $both_external=false)
setArHavingCollection(\arHavingCollection $arHavingCollection)
arHavingCollection $arHavingCollection
getArray(?string $key=null, string|array|null $values=null)
__construct(ActiveRecord $activeRecord)
@noinspection PhpFieldAssignmentTypeMismatchInspection
additionalParams(array $additional_params)
setAddidtionalParameters(array $addidtional_parameters)
arSelectCollection $arSelectCollection
dateFormat(string $date_format='d.m.Y - H:i:s')
arOrderCollection $arOrderCollection
static setLastQuery(string $last_query)
join(string $type, string $tablename, $on_this, string $on_external, array $fields=[' *'], string $operator='=', bool $both_external=false)
concat(array $fields, string $as)
array $addidtional_parameters
orderBy(string $order_by, string $order_direction='ASC')
arConcatCollection $arConcatCollection
arJoinCollection $arJoinCollection
buildRow(?array $row, $values)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getConnectorContainerName()
@description Return the Name of your Connector Table
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...
static get(ActiveRecord $activeRecord)
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...
const LIST_JOIN_ON_WRONG_FIELD
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...
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...
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...
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...
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists('../ilias.ini.php'))