48 'Implement getConnectorContainerName in your child-class' 58 if ($this->connector_container_name) {
62 $ar = self::getCalledClass();
64 return $ar::returnDbTableName();
79 return $this->{$primary_fieldname};
89 $this->{$primary_fieldname} = $value;
99 $key = $arFieldList->getPrimaryFieldName();
100 $this->{
$key} = $primary_key;
101 if ($primary_key !== 0 && $primary_key !== null && $primary_key !==
false) {
115 $fieldname = $field->getName();
116 $return->{$fieldname} = $this->{$fieldname};
124 $class = get_class($this);
126 $primary_value = $array[$primary];
130 foreach ($array as $field_name => $value) {
131 $waked = $this->
wakeUp($field_name, $value);
132 $this->{$field_name} = $waked ?? $value;
147 if ($this->
getArFieldList()->getFieldByName($field_name)->isDateField()) {
168 public function wakeUp($field_name, $field_value)
177 $field_name = $field->getName();
178 $sleeped = $this->
sleep($field_name);
179 $var = $sleeped ?? ($this->{$field_name});
180 $data[$field_name] = array($field->getFieldType(), $var);
198 $class = static::class;
210 return self::getCalledClass()->installDatabase();
225 final public static function renameDBField(
string $old_name,
string $new_name): bool
227 return self::getCalledClass()->getArConnector()->renameField(self::getCalledClass(), $old_name, $new_name);
232 return self::getCalledClass()->getArConnector()->checkTableExists(self::getCalledClass());
238 final public static function fieldExists(
string $field_name): bool
240 return self::getCalledClass()->getArConnector()->checkFieldExists(self::getCalledClass(), $field_name);
248 return self::getCalledClass()->getArConnector()->removeField(self::getCalledClass(), $field_name);
255 if (!self::tableExists()) {
259 $fields[$field->getName()] = $field->getAttributesForConnector();
274 if (!self::tableExists()) {
275 self::getCalledClass()->installDatabase();
280 return self::getCalledClass()->getArConnector()->updateDatabase(self::getCalledClass());
287 return self::getCalledClass()->getArConnector()->resetDatabase(self::getCalledClass());
295 self::getCalledClass()->getArConnector()->truncateDatabase(self::getCalledClass());
313 if (!self::where(array($primary_fieldname => $primary_value))->hasSets()) {
329 $this->{$primary_fieldname} = $this->
getArConnector()->nextID($this);
339 public function copy(
int $new_id = 0): self
341 if (self::where(array($this->
getArFieldList()->getPrimaryFieldName() => $new_id))->hasSets()) {
344 $new_obj = clone($this);
345 $new_obj->setPrimaryFieldValue($new_id);
360 if ($this->ar_safe_read ===
true && is_array($records) &&
count($records) === 0) {
362 } elseif ($this->ar_safe_read ===
false && is_array($records) &&
count($records) === 0) {
363 $this->is_new =
true;
365 $records = is_array($records) ? $records : array();
366 foreach ($records as $rec) {
368 $waked = $this->
wakeUp($k, $rec->{$k} ?? null);
369 $this->{$k} = $waked ?? $rec->{$k} ?? null;
381 public function delete()
406 $srModelObjectList->additionalParams($additional_params);
408 return $srModelObjectList;
414 public static function find($primary_key, array $add_constructor_args = array()): ?
\ActiveRecord 420 $class_name = static::class;
422 $obj = arFactory::getInstance($class_name, $primary_key, $add_constructor_args);
423 $obj->storeObjectToCache();
447 $obj = self::find($primary_key, $add_constructor_args);
462 $obj = self::find($primary_key, $add_constructor_args);
467 $class_name = static::class;
468 $obj = arFactory::getInstance($class_name, 0, $add_constructor_args);
469 $obj->setPrimaryFieldValue($primary_key);
471 $obj->storeObjectToCache();
483 $srModelObjectList->where($where, $operator);
485 return $srModelObjectList;
497 array $fields = array(
'*'),
498 string $operator =
'=',
499 $both_external =
false 501 return self::innerjoin(
521 array $fields = array(
'*'),
522 string $operator =
'=',
523 bool $both_external =
false 527 return $srModelObjectList->innerjoin($tablename, $on_this, $on_external, $fields, $operator, $both_external);
540 array $fields = array(
'*'),
541 string $operator =
'=',
542 bool $both_external =
false 546 return $srModelObjectList->leftjoin($tablename, $on_this, $on_external, $fields, $operator, $both_external);
555 $srModelObjectList->orderBy($orderBy, $orderDirection);
557 return $srModelObjectList;
563 $srModelObjectList->dateFormat($date_format);
565 return $srModelObjectList;
575 $srModelObjectList->limit($start, $end);
577 return $srModelObjectList;
584 return $srModelObjectList->affectedRows();
589 return self::affectedRows();
595 public static function get(): array
599 return $srModelObjectList->get();
606 return $srModelObjectList->debug();
613 return $srModelObjectList->first();
626 return $srModelObjectList->last();
636 return $srModelObjectList->getFirstFromLastQuery();
643 return $srModelObjectList->connector($connector);
650 return $srModelObjectList->raw($set_raw);
656 public static function getArray(?
string $key = null, $values = null): array
660 return $record_list->getArray(
$key, $values);
675 if (preg_match(
"/get([a-zA-Z]*)/u",
$name, $matches) &&
count($arguments) === 0) {
676 return $this->{self::fromCamelCase($matches[1])};
679 if (preg_match(
"/set([a-zA-Z]*)/u",
$name, $matches) &&
count($arguments) === 1) {
680 $this->{self::fromCamelCase($matches[1])} = $arguments[0];
684 public static function _toCamelCase(
string $str,
bool $capitalise_first_char =
false): ?string
686 if ($capitalise_first_char) {
687 $str[0] = strtoupper($str[0]);
690 return preg_replace_callback(
'/_([a-z])/', fn (
$c) => strtoupper(
$c[1]), $str);
695 $str[0] = strtolower($str[0]);
697 return preg_replace_callback(
'/([A-Z])/', fn (
$c) =>
"_" . strtolower(
$c[1]), $str);
static limit($start, $end)
static getFirstFromLastQuery()
buildFromArray(array $array)
static get(string $class_name)
static getPrimaryFieldName(ActiveRecord $ar)
static orderBy($orderBy, string $orderDirection='ASC')
static getArray(?string $key=null, $values=null)
static connector(arConnector $connector)
static leftjoin( $tablename, $on_this, $on_external, array $fields=array(' *'), string $operator='=', bool $both_external=false)
static renameDBField(string $old_name, string $new_name)
NullPointerExceptionInspection
static getCalledClass()
Returns an instance of the instatiated calling active record (needs to be done in static methods) : ...
static purge(ActiveRecord $object)
static _toCamelCase(string $str, bool $capitalise_first_char=false)
static returnDbTableName()
__call($name, $arguments)
static innerjoinAR(ActiveRecord $ar, $on_this, $on_external, array $fields=array(' *'), string $operator='=', $both_external=false)
static where($where, $operator=null)
static innerjoin( $tablename, $on_this, $on_external, array $fields=array(' *'), string $operator='=', bool $both_external=false)
const COPY_DESTINATION_ID_EXISTS
setPrimaryFieldValue($value)
__construct($primary_key=0)
static findOrFail($primary_key, array $add_constructor_args=array())
Tries to find the object and throws an Exception if object is not found, instead of returning null...
static store(ActiveRecord $object)
getConnectorContainerName()
Return the Name of your Connector Table
static fromCamelCase(string $str)
get(string $key, Refinery\Transformation $t)
Get passed parameter, if not data passed, get key from http request.
wakeUp($field_name, $field_value)
static removeDBField(string $field_name)
static isCached($class, $id)
static fieldExists(string $field_name)
static raw(bool $set_raw=true)
string $connector_container_name
fixDateField($field_name, $value)
static dateFormat(string $date_format='d.m.Y - H:i:s')
static findOrGetInstance($primary_key, array $add_constructor_args=array())
static get(ActiveRecord $ar)
setConnectorContainerName(string $connector_container_name)
static flushDB()
never use in ILIAS Core, Plugins only
static get(ActiveRecord $ar)
static additionalParams(array $additional_params)