26#[\AllowDynamicProperties]
52 'Implement getConnectorContainerName in your child-class'
62 if ($this->connector_container_name !==
'' && $this->connector_container_name !==
'0') {
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) {
121 $return =
new stdClass();
123 $fieldname = $arField->getName();
124 $return->{$fieldname} = $this->{$fieldname};
136 foreach ($this->getArFieldList()->getFields() as $arField) {
137 $fieldname = $arField->getName();
138 $return[$fieldname] = $this->{$fieldname};
146 $class = static::class;
147 $primary = $this->getArFieldList()->getPrimaryFieldName();
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()) {
170 return $this->getArConnector()->fixDate($value);
190 public function wakeUp($field_name, $field_value)
201 foreach ($this->getArFieldList()->getFields() as $arField) {
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();
243 return $this->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()) {
283 foreach ($this->getArFieldList()->getFields() as $arField) {
284 $fields[$arField->getName()] = $arField->getAttributesForConnector();
287 return $this->getArConnector()->installDatabase($this, $fields);
290 return $this->getArConnector()->updateDatabase($this);
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());
337 $primary_value = $this->getPrimaryFieldValue();
339 if (!self::where([$primary_fieldname => $primary_value])->hasSets()) {
353 if ($this->getArFieldList()->getPrimaryField()->getSequence()) {
355 $this->{$primary_fieldname} = $this->getArConnector()->nextID($this);
358 $this->getArConnector()->create($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);
385 $records = $this->getArConnector()->read($this);
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) {
394 foreach (array_keys($this->getArrayForConnector()) as $k) {
395 $waked = $this->wakeUp($k, $record->{$k} ??
null);
396 $this->{$k} = $waked ?? $record->{$k} ??
null;
404 $this->getArConnector()->update($this);
408 public function delete():
void
410 $this->getArConnector()->delete($this);
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
529 $activeRecord->getConnectorContainerName(),
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);
684 public static function getArray(?
string $key =
null,
string|array|
null $values =
null): array
688 return $activeRecordList->getArray($key, $values);
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)) {
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);
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
innerjoin(string $tablename, $on_this, string $on_external, array $fields=[' *'], string $operator='=', bool $both_external=false)
leftjoin(string $tablename, $on_this, string $on_external, array $fields=[' *'], string $operator='=', bool $both_external=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static flushDB()
@depracated never use in ILIAS Core, Plugins only
getConnectorContainerName()
@description Return the Name of your Connector Table
static removeDBField(string $field_name)
static connector(arConnector $arConnector)
setPrimaryFieldValue($value)
string $connector_container_name
fixDateField($field_name, string $value)
static where($where, $operator=null)
static returnDbTableName()
static _toCamelCase(string $str, bool $capitalise_first_char=false)
static dateFormat(string $date_format='d.m.Y - H:i:s')
__call($name, $arguments)
static getArray(?string $key=null, string|array|null $values=null)
static renameDBField(string $old_name, string $new_name)
buildFromArray(array $array)
static innerjoinAR(ActiveRecord $activeRecord, $on_this, string $on_external, array $fields=[' *'], string $operator='=', bool $both_external=false)
static raw(bool $set_raw=true)
static fromCamelCase(string $str)
wakeUp($field_name, $field_value)
setConnectorContainerName(string $connector_container_name)
static orderBy(string $orderBy, string $orderDirection='ASC')
static getCalledClass()
@description Returns an instance of the instatiated calling active record (needs to be done in static...
static getFirstFromLastQuery()
static innerjoin(string $tablename, $on_this, string $on_external, array $fields=[' *'], string $operator='=', bool $both_external=false)
static leftjoin(string $tablename, $on_this, string $on_external, array $fields=[' *'], string $operator='=', bool $both_external=false)
static limit(int $start, int $end)
static additionalParams(array $additional_params)
__construct(mixed $primary_key=0)
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 fieldExists(string $field_name)
static findOrGetInstance($primary_key, array $add_constructor_args=[])
static get(string $class_name)
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 COPY_DESTINATION_ID_EXISTS
static get(ActiveRecord $activeRecord)
static getPrimaryFieldName(ActiveRecord $activeRecord)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static purge(ActiveRecord $activeRecord)
static isCached($class, $id)
static get(string $class, string $id)
static store(ActiveRecord $activeRecord)
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'vtt', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...