27 #[\AllowDynamicProperties] 53 'Implement getConnectorContainerName in your child-class' 63 if ($this->connector_container_name !==
'' && $this->connector_container_name !==
'0') {
67 $ar = self::getCalledClass();
69 return $ar::returnDbTableName();
84 return $this->{$primary_fieldname};
94 $this->{$primary_fieldname} = $value;
101 $primaryFieldName = $arFieldList->getPrimaryFieldName();
102 $this->{$primaryFieldName} = $primary_key;
103 if ($primary_key === 0) {
106 if ($primary_key === null) {
109 if ($primary_key ===
false) {
124 $fieldname = $arField->getName();
125 $return->{$fieldname} = $this->{$fieldname};
138 $fieldname = $arField->getName();
139 $return[$fieldname] = $this->{$fieldname};
147 $class = $this::class;
149 $primary_value = $array[$primary];
153 foreach ($array as $field_name => $value) {
154 $waked = $this->
wakeUp($field_name, $value);
155 $this->{$field_name} = $waked ?? $value;
170 if ($this->
getArFieldList()->getFieldByName($field_name)->isDateField()) {
191 public function wakeUp($field_name, $field_value)
203 $field_name = $arField->getName();
204 $sleeped = $this->
sleep($field_name);
205 $var = $sleeped ?? ($this->{$field_name});
206 $data[$field_name] = [$arField->getFieldType(), $var];
224 $class = static::class;
236 return self::getCalledClass()->installDatabase();
251 final public static function renameDBField(
string $old_name,
string $new_name): bool
253 return self::getCalledClass()->getArConnector()->renameField(self::getCalledClass(), $old_name, $new_name);
258 return self::getCalledClass()->getArConnector()->checkTableExists(self::getCalledClass());
264 final public static function fieldExists(
string $field_name): bool
266 return self::getCalledClass()->getArConnector()->checkFieldExists(self::getCalledClass(), $field_name);
274 return self::getCalledClass()->getArConnector()->removeField(self::getCalledClass(), $field_name);
282 if (!self::tableExists()) {
285 $fields[$arField->getName()] = $arField->getAttributesForConnector();
299 if (!self::tableExists()) {
300 self::getCalledClass()->installDatabase();
305 return self::getCalledClass()->getArConnector()->updateDatabase(self::getCalledClass());
313 return self::getCalledClass()->getArConnector()->resetDatabase(self::getCalledClass());
321 self::getCalledClass()->getArConnector()->truncateDatabase(self::getCalledClass());
340 if (!self::where([$primary_fieldname => $primary_value])->hasSets()) {
356 $this->{$primary_fieldname} = $this->
getArConnector()->nextID($this);
366 public function copy(
int $new_id = 0): self
368 if (self::where([$this->
getArFieldList()->getPrimaryFieldName() => $new_id])->hasSets()) {
371 $new_obj = clone($this);
372 $new_obj->setPrimaryFieldValue($new_id);
387 if ($this->ar_safe_read && is_array($records) && $records === []) {
390 if (!$this->ar_safe_read && is_array($records) && $records === []) {
391 $this->is_new =
true;
393 $records = is_array($records) ? $records : [];
394 foreach ($records as $record) {
396 $waked = $this->
wakeUp($k, $record->{$k} ?? null);
397 $this->{$k} = $waked ?? $record->{$k} ?? null;
409 public function delete():
void 434 $activeRecordList->additionalParams($additional_params);
436 return $activeRecordList;
442 public static function find($primary_key, array $add_constructor_args = []): ?
\ActiveRecord 448 $class_name = static::class;
450 $obj = arFactory::getInstance($class_name, $primary_key, $add_constructor_args);
451 $obj->storeObjectToCache();
475 $obj = self::find($primary_key, $add_constructor_args);
490 $obj = self::find($primary_key, $add_constructor_args);
495 $class_name = static::class;
496 $obj = arFactory::getInstance($class_name, 0, $add_constructor_args);
497 $obj->setPrimaryFieldValue($primary_key);
499 $obj->storeObjectToCache();
511 $activeRecordList->where($where, $operator);
513 return $activeRecordList;
525 array $fields = [
'*'],
526 string $operator =
'=',
527 bool $both_external =
false 529 return self::innerjoin(
549 array $fields = [
'*'],
550 string $operator =
'=',
551 bool $both_external =
false 555 return $activeRecordList->innerjoin($tablename, $on_this, $on_external, $fields, $operator, $both_external);
568 array $fields = [
'*'],
569 string $operator =
'=',
570 bool $both_external =
false 574 return $activeRecordList->leftjoin($tablename, $on_this, $on_external, $fields, $operator, $both_external);
583 $activeRecordList->orderBy($orderBy, $orderDirection);
585 return $activeRecordList;
591 $activeRecordList->dateFormat($date_format);
593 return $activeRecordList;
603 $activeRecordList->limit($start, $end);
605 return $activeRecordList;
612 return $activeRecordList->affectedRows();
617 return self::affectedRows();
623 public static function get(): array
627 return $activeRecordList->get();
634 return $activeRecordList->debug();
641 return $activeRecordList->first();
654 return $activeRecordList->last();
664 return $activeRecordList->getFirstFromLastQuery();
671 return $activeRecordList->connector($arConnector);
678 return $activeRecordList->raw($set_raw);
685 public static function getArray(?
string $key = null, $values = null): array
689 return $activeRecordList->getArray(
$key, $values);
701 public function __call($name, $arguments)
704 if (preg_match(
"/get([a-zA-Z]*)/u", $name, $matches) && (is_countable($arguments) ?
count(
707 return $this->{self::fromCamelCase($matches[1])};
710 if (!preg_match(
"/set([a-zA-Z]*)/u", $name, $matches)) {
713 if (
count($arguments) !== 1) {
716 $this->{self::fromCamelCase($matches[1])} = $arguments[0];
719 public static function _toCamelCase(
string $str,
bool $capitalise_first_char =
false): ?string
721 if ($capitalise_first_char) {
722 $str[0] = strtoupper($str[0]);
725 return preg_replace_callback(
'/_([a-z])/', fn(
$c):
string => strtoupper(
$c[1]), $str);
730 $str[0] = strtolower($str[0]);
732 return preg_replace_callback(
'/([A-Z])/', fn(
$c):
string =>
"_" . strtolower(
$c[1]), $str);
static getFirstFromLastQuery()
buildFromArray(array $array)
static findOrGetInstance($primary_key, array $add_constructor_args=[])
static get(string $class_name)
static getArray(?string $key=null, $values=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static orderBy(string $orderBy, string $orderDirection='ASC')
static renameDBField(string $old_name, string $new_name)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static findOrFail($primary_key, array $add_constructor_args=[])
Tries to find the object and throws an Exception if object is not found, instead of returning null...
static getCalledClass()
Returns an instance of the instatiated calling active record (needs to be done in static methods) : ...
static leftjoin( $tablename, $on_this, $on_external, array $fields=[' *'], string $operator='=', bool $both_external=false)
static _toCamelCase(string $str, bool $capitalise_first_char=false)
static returnDbTableName()
__call($name, $arguments)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static where($where, $operator=null)
const COPY_DESTINATION_ID_EXISTS
static limit(int $start, int $end)
setPrimaryFieldValue($value)
getConnectorContainerName()
Return the Name of your Connector Table
static fromCamelCase(string $str)
static getPrimaryFieldName(ActiveRecord $activeRecord)
static innerjoin( $tablename, $on_this, $on_external, array $fields=[' *'], string $operator='=', bool $both_external=false)
get(string $key, Refinery\Transformation $t)
Get passed parameter, if not data passed, get key from http request.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
wakeUp($field_name, $field_value)
static removeDBField(string $field_name)
static store(ActiveRecord $activeRecord)
static get(ActiveRecord $activeRecord)
__construct(mixed $primary_key=0)
static isCached($class, $id)
static fieldExists(string $field_name)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static raw(bool $set_raw=true)
static connector(arConnector $arConnector)
string $connector_container_name
fixDateField($field_name, $value)
static dateFormat(string $date_format='d.m.Y - H:i:s')
static innerjoinAR(ActiveRecord $activeRecord, $on_this, $on_external, array $fields=[' *'], string $operator='=', bool $both_external=false)
setConnectorContainerName(string $connector_container_name)
static flushDB()
never use in ILIAS Core, Plugins only
static purge(ActiveRecord $activeRecord)
static additionalParams(array $additional_params)
static get(ActiveRecord $activeRecord)