26 #[\AllowDynamicProperties] 52 'Implement getConnectorContainerName in your child-class' 62 if ($this->connector_container_name !==
'' && $this->connector_container_name !==
'0') {
66 $ar = self::getCalledClass();
68 return $ar::returnDbTableName();
83 return $this->{$primary_fieldname};
93 $this->{$primary_fieldname} = $value;
100 $primaryFieldName = $arFieldList->getPrimaryFieldName();
101 $this->{$primaryFieldName} = $primary_key;
102 if ($primary_key === 0) {
105 if ($primary_key ===
null) {
108 if ($primary_key ===
false) {
123 $fieldname = $arField->getName();
124 $return->{$fieldname} = $this->{$fieldname};
137 $fieldname = $arField->getName();
138 $return[$fieldname] = $this->{$fieldname};
146 $class = static::class;
148 $primary_value = $array[$primary];
152 foreach ($array as $field_name => $value) {
153 $waked = $this->
wakeUp($field_name, $value);
154 $this->{$field_name} = $waked ?? $value;
169 if ($this->
getArFieldList()->getFieldByName($field_name)->isDateField()) {
190 public function wakeUp($field_name, $field_value)
202 $field_name = $arField->getName();
203 $sleeped = $this->
sleep($field_name);
204 $var = $sleeped ?? ($this->{$field_name});
205 $data[$field_name] = [$arField->getFieldType(), $var];
223 $class = static::class;
235 return self::getCalledClass()->installDatabase();
250 final public static function renameDBField(
string $old_name,
string $new_name): bool
252 return self::getCalledClass()->getArConnector()->renameField(self::getCalledClass(), $old_name, $new_name);
257 return self::getCalledClass()->getArConnector()->checkTableExists(self::getCalledClass());
263 final public static function fieldExists(
string $field_name): bool
265 return self::getCalledClass()->getArConnector()->checkFieldExists(self::getCalledClass(), $field_name);
273 return self::getCalledClass()->getArConnector()->removeField(self::getCalledClass(), $field_name);
281 if (!self::tableExists()) {
284 $fields[$arField->getName()] = $arField->getAttributesForConnector();
298 if (!self::tableExists()) {
299 self::getCalledClass()->installDatabase();
304 return self::getCalledClass()->getArConnector()->updateDatabase(self::getCalledClass());
312 return self::getCalledClass()->getArConnector()->resetDatabase(self::getCalledClass());
320 self::getCalledClass()->getArConnector()->truncateDatabase(self::getCalledClass());
339 if (!self::where([$primary_fieldname => $primary_value])->hasSets()) {
355 $this->{$primary_fieldname} = $this->
getArConnector()->nextID($this);
365 public function copy(
int $new_id = 0): self
367 if (self::where([$this->
getArFieldList()->getPrimaryFieldName() => $new_id])->hasSets()) {
370 $new_obj = clone($this);
371 $new_obj->setPrimaryFieldValue($new_id);
386 if ($this->ar_safe_read && is_array($records) && $records === []) {
389 if (!$this->ar_safe_read && is_array($records) && $records === []) {
390 $this->is_new =
true;
392 $records = is_array($records) ? $records : [];
393 foreach ($records as $record) {
395 $waked = $this->
wakeUp($k, $record->{$k} ??
null);
396 $this->{$k} = $waked ?? $record->{$k} ??
null;
408 public function delete():
void 433 $activeRecordList->additionalParams($additional_params);
435 return $activeRecordList;
441 public static function find($primary_key, array $add_constructor_args = []): ?
\ActiveRecord 447 $class_name = static::class;
449 $obj = arFactory::getInstance($class_name, $primary_key, $add_constructor_args);
450 $obj->storeObjectToCache();
474 $obj = self::find($primary_key, $add_constructor_args);
489 $obj = self::find($primary_key, $add_constructor_args);
494 $class_name = static::class;
495 $obj = arFactory::getInstance($class_name, 0, $add_constructor_args);
496 $obj->setPrimaryFieldValue($primary_key);
498 $obj->storeObjectToCache();
510 $activeRecordList->where($where, $operator);
512 return $activeRecordList;
524 array $fields = [
'*'],
525 string $operator =
'=',
526 bool $both_external =
false 528 return self::innerjoin(
548 array $fields = [
'*'],
549 string $operator =
'=',
550 bool $both_external =
false 554 return $activeRecordList->innerjoin($tablename, $on_this, $on_external, $fields, $operator, $both_external);
567 array $fields = [
'*'],
568 string $operator =
'=',
569 bool $both_external =
false 573 return $activeRecordList->leftjoin($tablename, $on_this, $on_external, $fields, $operator, $both_external);
582 $activeRecordList->orderBy($orderBy, $orderDirection);
584 return $activeRecordList;
590 $activeRecordList->dateFormat($date_format);
592 return $activeRecordList;
602 $activeRecordList->limit($start, $end);
604 return $activeRecordList;
611 return $activeRecordList->affectedRows();
616 return self::affectedRows();
622 public static function get(): array
626 return $activeRecordList->get();
633 return $activeRecordList->debug();
640 return $activeRecordList->first();
653 return $activeRecordList->last();
663 return $activeRecordList->getFirstFromLastQuery();
670 return $activeRecordList->connector($arConnector);
677 return $activeRecordList->raw($set_raw);
688 return $activeRecordList->getArray($key, $values);
700 public function __call($name, $arguments)
703 if (preg_match(
"/get([a-zA-Z]*)/u", (
string) $name, $matches) && (is_countable($arguments) ?
count(
706 return $this->{self::fromCamelCase($matches[1])};
709 if (!preg_match(
"/set([a-zA-Z]*)/u", (
string) $name, $matches)) {
712 if (
count($arguments) !== 1) {
715 $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)
fixDateField($field_name, string $value)
static get(string $class, string $id)
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 _toCamelCase(string $str, bool $capitalise_first_char=false)
static returnDbTableName()
static innerjoinAR(ActiveRecord $activeRecord, $on_this, string $on_external, array $fields=[' *'], string $operator='=', bool $both_external=false)
__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)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
setPrimaryFieldValue($value)
static innerjoin(string $tablename, $on_this, string $on_external, array $fields=[' *'], string $operator='=', bool $both_external=false)
getConnectorContainerName()
Return the Name of your Connector Table
static fromCamelCase(string $str)
static getPrimaryFieldName(ActiveRecord $activeRecord)
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
static getArray(?string $key=null, string|array|null $values=null)
static dateFormat(string $date_format='d.m.Y - H:i:s')
static leftjoin(string $tablename, $on_this, string $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)