ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ActiveRecord Class Reference

Class ActiveRecord. More...

+ Inheritance diagram for ActiveRecord:
+ Collaboration diagram for ActiveRecord:

Public Member Functions

 getArConnector ()
 
 getArFieldList ()
 
 getConnectorContainerName ()
 
 setConnectorContainerName ($connector_container_name)
 
 getPrimaryFieldValue ()
 
 setPrimaryFieldValue ($value)
 
 __construct ($primary_key=0, arConnector $connector=null)
 
 storeObjectToCache ()
 
 __getConvertedDateFieldsAsArray ($format=null)
 
 __asCsv ($separator=';', $header=false)
 
 __asArray ()
 
 __asStdClass ()
 
 __asSerializedObject ()
 
 buildFromArray (array $array)
 
 fixDateField ($field_name, $value)
 
 sleep ($field_name)
 
 wakeUp ($field_name, $field_value)
 
 getArrayForDb ()
 
 getArrayForConnector ()
 
 installConnector ()
 
 store ()
 
 save ()
 
 create ()
 
 copy ($new_id=0)
 
 afterObjectLoad ()
 
 read ()
 
 update ()
 
 delete ()
 
 __call ($name, $arguments)
 

Static Public Member Functions

static returnDbTableName ()
 
static installDB ()
 
static renameDBField ($old_name, $new_name)
 
static tableExists ()
 
static fieldExists ($field_name)
 
static removeDBField ($field_name)
 
static updateDB ()
 
static resetDB ()
 
static truncateDB ()
 
static flushDB ()
 
static preloadObjects ()
 
static additionalParams (array $additional_params)
 
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. More...
 
static findOrGetInstance ($primary_key, array $add_constructor_args=array())
 
static where ($where, $operator=null)
 
static innerjoinAR (ActiveRecord $ar, $on_this, $on_external, $fields=array(' *'), $operator='=', $both_external=false)
 
static innerjoin ($tablename, $on_this, $on_external, $fields=array(' *'), $operator='=', $both_external=false)
 
static leftjoin ($tablename, $on_this, $on_external, $fields=array(' *'), $operator='=', $both_external=false)
 
static orderBy ($orderBy, $orderDirection='ASC')
 
static dateFormat ($date_format='d.m.Y - H:i:s')
 
static limit ($start, $end)
 
static affectedRows ()
 
static count ()
 
static get ()
 
static debug ()
 
static first ()
 
static getCollection ()
 
static last ()
 
static getFirstFromLastQuery ()
 
static connector (arConnector $connector)
 
static raw ($set_raw=true)
 
static getArray ($key=null, $values=null)
 
static _toCamelCase ($str, $capitalise_first_char=false)
 

Data Fields

const ACTIVE_RECORD_VERSION = '2.0.7'
 

Protected Member Functions

 serializeToCSV ($field)
 This method is called for every field of your instance if you use __asCsv. More...
 
 installDatabase ()
 

Static Protected Member Functions

static getCalledClass ()
 
static fromCamelCase ($str)
 

Protected Attributes

 $ar_safe_read = true
 
 $connector_container_name = ''
 

Detailed Description

Class ActiveRecord.

Author
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch
Oskar Truffer ot@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch @experimental @description
Version
2.0.7

Definition at line 24 of file class.ActiveRecord.php.

Constructor & Destructor Documentation

◆ __construct()

ActiveRecord::__construct (   $primary_key = 0,
arConnector  $connector = null 
)
Parameters
int$primary_key
arConnector$connector

Definition at line 110 of file class.ActiveRecord.php.

110 {
111 if ($connector == null) {
112 $connector = new arConnectorDB();
113 }
114 arConnectorMap::register($this, $connector);
115
116 $arFieldList = arFieldCache::get($this);
117
118 $key = $arFieldList->getPrimaryFieldName();
119 $this->{$key} = $primary_key;
120 if ($primary_key !== 0 AND $primary_key !== null AND $primary_key !== false) {
121 $this->read();
122 }
123 }
Class arConnectorDB.
static register(ActiveRecord $ar, arConnector $connector)
static get(ActiveRecord $ar)

References arFieldCache\get(), read(), and arConnectorMap\register().

+ Here is the call graph for this function:

Member Function Documentation

◆ __asArray()

ActiveRecord::__asArray ( )
Returns
array

Definition at line 199 of file class.ActiveRecord.php.

199 {
200 $return = array();
201 foreach ($this->getArFieldList()->getFields() as $field) {
202 $fieldname = $field->getName();
203 $return[$fieldname] = $this->{$fieldname};
204 }
205
206 return $return;
207 }

References getArFieldList().

Referenced by __asCsv().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __asCsv()

ActiveRecord::__asCsv (   $separator = ';',
  $header = false 
)
Parameters
string$separator
bool$header
Returns
string

Definition at line 162 of file class.ActiveRecord.php.

162 {
163 $line = '';
164 if ($header) {
165 $line .= implode($separator, array_keys($this->getArFieldList()->getRawFields()));
166 $line .= "\n";
167 }
168 $array = array();
169 foreach ($this->__asArray() as $field_name => $value) {
170 $serialized = $this->serializeToCSV($field_name);
171 if ($serialized === null) {
172 $array[$field_name] = $this->{$field_name};
173 } else {
174 $array[$field_name] = $serialized;
175 }
176 }
177 $line .= implode($separator, array_values($array));
178
179 return $line;
180 }
serializeToCSV($field)
This method is called for every field of your instance if you use __asCsv.
$header

References $header, __asArray(), getArFieldList(), and serializeToCSV().

+ Here is the call graph for this function:

◆ __asSerializedObject()

ActiveRecord::__asSerializedObject ( )
Returns
string

Definition at line 227 of file class.ActiveRecord.php.

227 {
228 return serialize($this);
229 }

◆ __asStdClass()

ActiveRecord::__asStdClass ( )
Returns
stdClass

Definition at line 213 of file class.ActiveRecord.php.

213 {
214 $return = new stdClass();
215 foreach ($this->getArFieldList()->getFields() as $field) {
216 $fieldname = $field->getName();
217 $return->{$fieldname} = $this->{$fieldname};
218 }
219
220 return $return;
221 }

References getArFieldList().

Referenced by arConnectorSession\create().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __call()

ActiveRecord::__call (   $name,
  $arguments 
)
Parameters
$name
$arguments
Returns
array

Definition at line 862 of file class.ActiveRecord.php.

862 {
863 // Getter
864 if (preg_match("/get([a-zA-Z]*)/u", $name, $matches) AND count($arguments) == 0) {
865 return $this->{self::fromCamelCase($matches[1])};
866 }
867 // Setter
868 if (preg_match("/set([a-zA-Z]*)/u", $name, $matches) AND count($arguments) == 1) {
869 $this->{self::fromCamelCase($matches[1])} = $arguments[0];
870 }
871 if (preg_match("/findBy([a-zA-Z]*)/u", $name, $matches) AND count($arguments) == 1) {
872 return self::where(array( self::fromCamelCase($matches[1]) => $arguments[0] ))->getFirst();
873 }
874 }
static where($where, $operator=null)
static fromCamelCase($str)

◆ __getConvertedDateFieldsAsArray()

ActiveRecord::__getConvertedDateFieldsAsArray (   $format = null)
Parameters
string$format
Returns
array

Definition at line 136 of file class.ActiveRecord.php.

136 {
137 $converted_dates = array();
138 foreach ($this->getArFieldList()->getFields() as $field) {
139 if ($field->isDateField()) {
140 $name = $field->getName();
141 $value = $this->{$name};
142 $converted_dates[$name] = array(
143 'unformatted' => $value,
144 'unix' => strtotime($value),
145 );
146 if ($format) {
147 $converted_dates[$name]['formatted'] = date($format, strtotime($value));
148 }
149 }
150 }
151
152 return $converted_dates;
153 }
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())

References date, and getArFieldList().

+ Here is the call graph for this function:

◆ _toCamelCase()

static ActiveRecord::_toCamelCase (   $str,
  $capitalise_first_char = false 
)
static
Parameters
string$str
bool$capitalise_first_char
Returns
string

Definition at line 883 of file class.ActiveRecord.php.

883 {
884 if ($capitalise_first_char) {
885 $str[0] = strtoupper($str[0]);
886 }
887 $func = create_function('$c', 'return strtoupper($c[1]);');
888
889 return preg_replace_callback('/_([a-z])/', $func, $str);
890 }

Referenced by arViewField\__construct().

+ Here is the caller graph for this function:

◆ additionalParams()

static ActiveRecord::additionalParams ( array  $additional_params)
static
Parameters
array$additional_params
Returns
$this

Definition at line 555 of file class.ActiveRecord.php.

555 {
556 $srModelObjectList = new ActiveRecordList(self::getCalledClass());
557 $srModelObjectList->additionalParams($additional_params);
558
559 return $srModelObjectList;
560 }
Class ActiveRecordList.

◆ affectedRows()

static ActiveRecord::affectedRows ( )
static
Returns
int

Definition at line 741 of file class.ActiveRecord.php.

741 {
742 $srModelObjectList = new ActiveRecordList(self::getCalledClass());
743
744 return $srModelObjectList->affectedRows();
745 }

◆ afterObjectLoad()

ActiveRecord::afterObjectLoad ( )

Reimplemented in ilDclFieldProperty.

Definition at line 501 of file class.ActiveRecord.php.

501 {
502 }

◆ buildFromArray()

ActiveRecord::buildFromArray ( array  $array)
Parameters
array$array
Returns
$this

Definition at line 237 of file class.ActiveRecord.php.

237 {
238 $class = get_class($this);
239 $primary = $this->getArFieldList()->getPrimaryFieldName();
240 $primary_value = $array[$primary];
241 if ($primary_value AND arObjectCache::isCached($class, $primary_value)) {
242 return arObjectCache::get($class, $primary_value);
243 }
244 foreach ($array as $field_name => $value) {
245 if ($this->wakeUp($field_name, $value) === null) {
246 $this->{$field_name} = $value;
247 } else {
248 $this->{$field_name} = $this->wakeUp($field_name, $value);
249 }
250 }
252 $this->afterObjectLoad();
253
254 return $this;
255 }
wakeUp($field_name, $field_value)
static isCached($class, $id)
static store(ActiveRecord $object)
static get($class, $id)

References arObjectCache\get(), arObjectCache\isCached(), and arObjectCache\store().

+ Here is the call graph for this function:

◆ connector()

static ActiveRecord::connector ( arConnector  $connector)
static
Parameters
arConnector$connector
Returns
ActiveRecordList

Definition at line 822 of file class.ActiveRecord.php.

822 {
823 $srModelObjectList = new ActiveRecordList(self::getCalledClass());
824
825 return $srModelObjectList->connector($connector);
826 }

◆ copy()

ActiveRecord::copy (   $new_id = 0)
Parameters
int$new_id
Returns
ActiveRecord
Exceptions
arException

Definition at line 490 of file class.ActiveRecord.php.

490 {
491 if (self::where(array( $this->getArFieldList()->getPrimaryFieldName() => $new_id ))->hasSets()) {
493 }
494 $new_obj = clone($this);
495 $new_obj->setPrimaryFieldValue($new_id);
496
497 return $new_obj;
498 }
Class arException.
const COPY_DESTINATION_ID_EXISTS

References arException\COPY_DESTINATION_ID_EXISTS.

◆ count()

static ActiveRecord::count ( )
static
Returns
int

Definition at line 751 of file class.ActiveRecord.php.

751 {
752 return self::affectedRows();
753 }

Referenced by ilStudyProgrammeType\loadTranslation(), and ilStudyProgrammeType\processAndStoreIconFile().

+ Here is the caller graph for this function:

◆ create()

ActiveRecord::create ( )

Reimplemented in ilDclFieldProperty, and arStorage.

Definition at line 473 of file class.ActiveRecord.php.

473 {
474 if ($this->getArFieldList()->getPrimaryField()->getSequence()) {
475 $primary_fieldname = arFieldCache::getPrimaryFieldName($this);
476 $this->{$primary_fieldname} = $this->getArConnector()->nextID($this);
477 }
478
479 $this->getArConnector()->create($this, $this->getArrayForConnector());
481 }
static getPrimaryFieldName(ActiveRecord $ar)

References arFieldCache\getPrimaryFieldName(), and arObjectCache\store().

Referenced by ilDclTableView\cloneStructure(), ilDclTableViewFieldSetting\cloneStructure(), and ilOrgUnitPathStorage\store().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dateFormat()

static ActiveRecord::dateFormat (   $date_format = 'd.m.Y - H:i:s')
static
Parameters
string$date_format
Returns
ActiveRecordList

Definition at line 716 of file class.ActiveRecord.php.

716 :i:s') {
717 $srModelObjectList = new ActiveRecordList(self::getCalledClass());
718 $srModelObjectList->dateFormat($date_format);
719
720 return $srModelObjectList;
721 }

◆ debug()

static ActiveRecord::debug ( )
static
Returns
ActiveRecordList

Definition at line 769 of file class.ActiveRecord.php.

769 {
770 $srModelObjectList = new ActiveRecordList(self::getCalledClass());
771
772 return $srModelObjectList->debug();
773 }

◆ delete()

ActiveRecord::delete ( )

Reimplemented in ilDclTableView.

Definition at line 532 of file class.ActiveRecord.php.

532 {
533 $this->getArConnector()->delete($this);
535 }
static purge(ActiveRecord $object)

References arObjectCache\purge().

+ Here is the call graph for this function:

◆ fieldExists()

static ActiveRecord::fieldExists (   $field_name)
staticfinal
Parameters
$field_name
Returns
bool

Definition at line 384 of file class.ActiveRecord.php.

384 {
385 return self::getCalledClass()->getArConnector()->checkFieldExists(self::getCalledClass(), $field_name);
386 }

◆ findOrFail()

static ActiveRecord::findOrFail (   $primary_key,
array  $add_constructor_args = array() 
)
static

Tries to find the object and throws an Exception if object is not found, instead of returning null.

Parameters
$primary_key
array$add_constructor_args
Exceptions
arException
Returns
ActiveRecord

Definition at line 603 of file class.ActiveRecord.php.

603 {
604 $obj = self::find($primary_key, $add_constructor_args);
605 if (is_null($obj)) {
607 }
608
609 return $obj;
610 }

References arException\RECORD_NOT_FOUND.

Referenced by ilObjDefReader\handlerBeginTag().

+ Here is the caller graph for this function:

◆ findOrGetInstance()

static ActiveRecord::findOrGetInstance (   $primary_key,
array  $add_constructor_args = array() 
)
static
Parameters
$primary_key
array$add_constructor_args

@description Returns an existing Object with given primary-key or a new Instance with given primary-key set but not yet created

Returns
ActiveRecord

Definition at line 621 of file class.ActiveRecord.php.

621 {
622 $obj = self::find($primary_key, $add_constructor_args);
623 if ($obj !== null) {
624 return $obj;
625 } else {
626 $class_name = get_called_class();
627 $obj = arFactory::getInstance($class_name, 0, $add_constructor_args);
628 $obj->setPrimaryFieldValue($primary_key);
629 $obj->is_new = true;
630 $obj->storeObjectToCache();
631
632 return $obj;
633 }
634 }

Referenced by ilDclTableViewGUI\executeCommand().

+ Here is the caller graph for this function:

◆ first()

static ActiveRecord::first ( )
static
Returns
ActiveRecord

Definition at line 779 of file class.ActiveRecord.php.

779 {
780 $srModelObjectList = new ActiveRecordList(self::getCalledClass());
781
782 return $srModelObjectList->first();
783 }

Referenced by ilDclTableView\createOrGetStandardView(), and ilDclTableViewFieldSetting\getInstance().

+ Here is the caller graph for this function:

◆ fixDateField()

ActiveRecord::fixDateField (   $field_name,
  $value 
)
Parameters
$field_name
$value
Returns
string

Definition at line 263 of file class.ActiveRecord.php.

263 {
264 if ($this->getArFieldList()->getFieldByName($field_name)->isDateField()) {
265 return $this->getArConnector()->fixDate($value);
266 }
267
268 return $value;
269 }

◆ flushDB()

static ActiveRecord::flushDB ( )
staticfinal
Returns
bool

Definition at line 449 of file class.ActiveRecord.php.

449 {
450 return self::truncateDB();
451 }

◆ fromCamelCase()

static ActiveRecord::fromCamelCase (   $str)
staticprotected
Parameters
string$str
Returns
string

Definition at line 898 of file class.ActiveRecord.php.

898 {
899 $str[0] = strtolower($str[0]);
900 $func = create_function('$c', 'return "_" . strtolower($c[1]);');
901
902 return preg_replace_callback('/([A-Z])/', $func, $str);
903 }

◆ get()

static ActiveRecord::get ( )
static
Returns
ActiveRecord[]

Definition at line 759 of file class.ActiveRecord.php.

759 {
760 $srModelObjectList = new ActiveRecordList(self::getCalledClass());
761
762 return $srModelObjectList->get();
763 }

Referenced by ilBibliographicSetting\getAll(), ilStudyProgrammeType\getAllTypes(), and arConfigFormGUI\getValuesForItem().

+ Here is the caller graph for this function:

◆ getArConnector()

ActiveRecord::getArConnector ( )
Returns
\arConnectorDB

Definition at line 40 of file class.ActiveRecord.php.

40 {
41 return arConnectorMap::get($this);
42 }
static get(ActiveRecord $ar)

References arConnectorMap\get().

Referenced by arWhere\asSQLStatement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getArFieldList()

ActiveRecord::getArFieldList ( )
Returns
\arFieldList

Definition at line 48 of file class.ActiveRecord.php.

48 {
49 return arFieldCache::get($this);
50 }

References arFieldCache\get().

Referenced by __asArray(), __asCsv(), __asStdClass(), __getConvertedDateFieldsAsArray(), arWhere\asSQLStatement(), arConnectorDB\installDatabase(), arConnectorDB\updateDatabase(), and arConnectorDB\updateIndices().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getArray()

static ActiveRecord::getArray (   $key = null,
  $values = null 
)
static
Parameters
null$key
null$values
Returns
array

Definition at line 847 of file class.ActiveRecord.php.

847 {
848 $srModelObjectList = new ActiveRecordList(self::getCalledClass());
849
850 return $srModelObjectList->getArray($key, $values);
851 }

Referenced by ilOrgUnitPathStorage\getTextRepresentationOfOrgUnits(), and ilMemcacheServerTableGUI\parseData().

+ Here is the caller graph for this function:

◆ getArrayForConnector()

ActiveRecord::getArrayForConnector ( )
final
Returns
array

Definition at line 305 of file class.ActiveRecord.php.

305 {
306 $data = array();
307 foreach ($this->getArFieldList()->getFields() as $field) {
308 $field_name = $field->getName();
309 $sleeped = $this->sleep($field_name);
310 $var = ($sleeped === null) ? ($this->{$field_name}) : $sleeped;
311 $data[$field_name] = array( $field->getFieldType(), $var );
312 }
313
314 return $data;
315 }
sleep($field_name)

References $data.

Referenced by arConnectorDB\create(), and arConnectorDB\update().

+ Here is the caller graph for this function:

◆ getArrayForDb()

ActiveRecord::getArrayForDb ( )
final
Returns
array
Deprecated:

Definition at line 297 of file class.ActiveRecord.php.

297 {
298 return $this->getArrayForConnector();
299 }

◆ getCalledClass()

static ActiveRecord::getCalledClass ( )
staticprotected
Returns
ActiveRecord

@description Returns an instance of the instatiated calling active record (needs to be done in static methods) @TODO : This should be cached somehow

Definition at line 330 of file class.ActiveRecord.php.

330 {
331 $class = get_called_class();
332
333 return arCalledClassCache::get($class);
334 }

References arCalledClassCache\get().

Referenced by getConnectorContainerName().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCollection()

static ActiveRecord::getCollection ( )
static
Returns
ActiveRecordList

Definition at line 789 of file class.ActiveRecord.php.

789 {
790 $srModelObjectList = new ActiveRecordList(self::getCalledClass());
791
792 return $srModelObjectList;
793 }

Referenced by arStorageRecordGUI\index().

+ Here is the caller graph for this function:

◆ getConnectorContainerName()

ActiveRecord::getConnectorContainerName ( )
Returns
string @description Return the Name of your Connector Table

Reimplemented in ilBibliographicSetting, ilOrgUnitPathStorage, arMixedKey, and ilADTActiveRecordWrapper.

Definition at line 66 of file class.ActiveRecord.php.

66 {
67 // WILL BE ABSTRACT TO REPLACE returnDbTableName() IN NEXT VERSION
68 if ($this->connector_container_name) {
70 } else {
72
73 return $ar::returnDbTableName();
74 }
75 }

References $connector_container_name, and getCalledClass().

Referenced by arWhere\asSQLStatement(), arJoin\asStatementText(), arConnectorDB\checkFieldExists(), arConnectorDB\checkTableExists(), arConnectorDB\create(), innerjoinAR(), ActiveRecordList\innerjoinAR(), arConnectorDB\installDatabase(), arConnectorDB\nextID(), arConnectorDB\read(), arConnectorDB\removeField(), arConnectorDB\renameField(), arConnectorDB\resetDatabase(), arConnectorDB\truncateDatabase(), arConnectorDB\update(), arConnectorDB\updateDatabase(), and arConnectorDB\updateIndices().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFirstFromLastQuery()

static ActiveRecord::getFirstFromLastQuery ( )
static
Returns
ActiveRecordList
Deprecated:

Definition at line 810 of file class.ActiveRecord.php.

810 {
811 $srModelObjectList = new ActiveRecordList(self::getCalledClass());
812
813 return $srModelObjectList->getFirstFromLastQuery();
814 }

◆ getPrimaryFieldValue()

ActiveRecord::getPrimaryFieldValue ( )
Returns
mixed

Reimplemented in ilADTActiveRecordWrapper.

Definition at line 89 of file class.ActiveRecord.php.

89 {
90 $primary_fieldname = arFieldCache::getPrimaryFieldName($this);
91
92 return $this->{$primary_fieldname};
93 }

References arFieldCache\getPrimaryFieldName().

Referenced by arConnectorSession\create(), arObjectCache\purge(), arConnectorDB\read(), arConnectorSession\read(), arObjectCache\store(), and arConnectorDB\update().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ innerjoin()

static ActiveRecord::innerjoin (   $tablename,
  $on_this,
  $on_external,
  $fields = array( '*' ),
  $operator = '=',
  $both_external = false 
)
static
Parameters
$tablename
$on_this
$on_external
array$fields
string$operator
Returns
$this

Definition at line 674 of file class.ActiveRecord.php.

674 {
675 $srModelObjectList = new ActiveRecordList(self::getCalledClass());
676
677 return $srModelObjectList->innerjoin($tablename, $on_this, $on_external, $fields, $operator, $both_external);
678 }

◆ innerjoinAR()

static ActiveRecord::innerjoinAR ( ActiveRecord  $ar,
  $on_this,
  $on_external,
  $fields = array( '*' ),
  $operator = '=',
  $both_external = false 
)
static
Parameters
ActiveRecord$ar
$on_this
$on_external
array$fields
string$operator
Returns
$this

Definition at line 660 of file class.ActiveRecord.php.

660 {
661 return self::innerjoin($ar->getConnectorContainerName(), $on_this, $on_external, $fields, $operator, $both_external);
662 }
static innerjoin($tablename, $on_this, $on_external, $fields=array(' *'), $operator='=', $both_external=false)

References getConnectorContainerName().

+ Here is the call graph for this function:

◆ installConnector()

ActiveRecord::installConnector ( )
Returns
bool
Deprecated:
Do not use in Core DB-update.

Definition at line 355 of file class.ActiveRecord.php.

355 {
356 return $this->installDatabase();
357 }

◆ installDatabase()

ActiveRecord::installDatabase ( )
finalprotected
Returns
bool

Definition at line 402 of file class.ActiveRecord.php.

402 {
403 if (!$this->tableExists()) {
404 $fields = array();
405 foreach ($this->getArFieldList()->getFields() as $field) {
406 $fields[$field->getName()] = $field->getAttributesForConnector();
407 }
408
409 return $this->getArConnector()->installDatabase($this, $fields);
410 } else {
411 return $this->getArConnector()->updateDatabase($this);
412 }
413 }

◆ installDB()

static ActiveRecord::installDB ( )
staticfinal
Returns
bool
Deprecated:
Do not use in Core DB-update. Please generate the manual installation script by using:
        $arBuilder = new arBuilder(new ilYourARBasedClass());
        $arBuilder->generateDBUpdateForInstallation();

Definition at line 345 of file class.ActiveRecord.php.

345 {
346 return self::getCalledClass()->installDatabase();
347 }

Referenced by arConnectorDB\resetDatabase().

+ Here is the caller graph for this function:

◆ last()

static ActiveRecord::last ( )
static
Returns
ActiveRecord

Definition at line 799 of file class.ActiveRecord.php.

799 {
800 $srModelObjectList = new ActiveRecordList(self::getCalledClass());
801
802 return $srModelObjectList->last();
803 }

◆ leftjoin()

static ActiveRecord::leftjoin (   $tablename,
  $on_this,
  $on_external,
  $fields = array( '*' ),
  $operator = '=',
  $both_external = false 
)
static
Parameters
$tablename
$on_this
$on_external
array$fields
string$operator
Returns
$this

Definition at line 690 of file class.ActiveRecord.php.

690 {
691 $srModelObjectList = new ActiveRecordList(self::getCalledClass());
692
693 return $srModelObjectList->leftjoin($tablename, $on_this, $on_external, $fields, $operator, $both_external);
694 }

◆ limit()

static ActiveRecord::limit (   $start,
  $end 
)
static
Parameters
$start
$end
Returns
ActiveRecordList

Definition at line 730 of file class.ActiveRecord.php.

730 {
731 $srModelObjectList = new ActiveRecordList(self::getCalledClass());
732 $srModelObjectList->limit($start, $end);
733
734 return $srModelObjectList;
735 }

References $start.

◆ orderBy()

static ActiveRecord::orderBy (   $orderBy,
  $orderDirection = 'ASC' 
)
static
Parameters
$orderBy
string$orderDirection
Returns
ActiveRecordList

Definition at line 703 of file class.ActiveRecord.php.

703 {
704 $srModelObjectList = new ActiveRecordList(self::getCalledClass());
705 $srModelObjectList->orderBy($orderBy, $orderDirection);
706
707 return $srModelObjectList;
708 }

Referenced by ilDclTableView\createOrGetStandardView(), and ilOrgUnitPathStorage\getTextRepresentationOfOrgUnits().

+ Here is the caller graph for this function:

◆ preloadObjects()

static ActiveRecord::preloadObjects ( )
static
Returns
ActiveRecord[]

Definition at line 545 of file class.ActiveRecord.php.

545 {
546 return self::get();
547 }

References Assetic\Cache\get().

+ Here is the call graph for this function:

◆ raw()

static ActiveRecord::raw (   $set_raw = true)
static
Parameters
bool$set_raw
Returns
ActiveRecordList

Definition at line 834 of file class.ActiveRecord.php.

834 {
835 $srModelObjectList = new ActiveRecordList(self::getCalledClass());
836
837 return $srModelObjectList->raw($set_raw);
838 }

◆ read()

ActiveRecord::read ( )

Reimplemented in arStorage.

Definition at line 505 of file class.ActiveRecord.php.

505 {
506 $records = $this->getArConnector()->read($this);
507 if (count($records) == 0 AND $this->ar_safe_read == true) {
509 } elseif (count($records) == 0 AND $this->ar_safe_read == false) {
510 $this->is_new = true;
511 }
512 foreach ($records as $rec) {
513 foreach ($this->getArrayForConnector() as $k => $v) {
514 if ($this->wakeUp($k, $rec->{$k}) === null) {
515 $this->{$k} = $rec->{$k};
516 } else {
517 $this->{$k} = $this->wakeUp($k, $rec->{$k});
518 }
519 }
521 $this->afterObjectLoad();
522 }
523 }
$records
Definition: simple_test.php:22

References $records, and arException\RECORD_NOT_FOUND.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ removeDBField()

static ActiveRecord::removeDBField (   $field_name)
staticfinal
Parameters
$field_name
Returns
bool

Definition at line 394 of file class.ActiveRecord.php.

394 {
395 return self::getCalledClass()->getArConnector()->removeField(self::getCalledClass(), $field_name);
396 }

◆ renameDBField()

static ActiveRecord::renameDBField (   $old_name,
  $new_name 
)
staticfinal
Parameters
$old_name
$new_name
Returns
bool

Definition at line 366 of file class.ActiveRecord.php.

366 {
367 return self::getCalledClass()->getArConnector()->renameField(self::getCalledClass(), $old_name, $new_name);
368 }

◆ resetDB()

static ActiveRecord::resetDB ( )
staticfinal
Returns
bool

Definition at line 433 of file class.ActiveRecord.php.

433 {
434 return self::getCalledClass()->getArConnector()->resetDatabase(self::getCalledClass());
435 }

◆ returnDbTableName()

◆ save()

ActiveRecord::save ( )

Definition at line 468 of file class.ActiveRecord.php.

468 {
469 $this->store();
470 }

◆ serializeToCSV()

ActiveRecord::serializeToCSV (   $field)
protected

This method is called for every field of your instance if you use __asCsv.

You can use it to customize your export into csv. (e.g. serialize an array).

Parameters
$fieldstring
Returns
mixed

Definition at line 191 of file class.ActiveRecord.php.

191 {
192 return null;
193 }

Referenced by __asCsv().

+ Here is the caller graph for this function:

◆ setConnectorContainerName()

ActiveRecord::setConnectorContainerName (   $connector_container_name)
Parameters
string$connector_container_name

Definition at line 81 of file class.ActiveRecord.php.

81 {
82 $this->connector_container_name = $connector_container_name;
83 }

References $connector_container_name.

◆ setPrimaryFieldValue()

ActiveRecord::setPrimaryFieldValue (   $value)
Parameters
$value

Definition at line 99 of file class.ActiveRecord.php.

99 {
100 $primary_fieldname = arFieldCache::getPrimaryFieldName($this);
101
102 $this->{$primary_fieldname} = $value;
103 }

References arFieldCache\getPrimaryFieldName().

+ Here is the call graph for this function:

◆ sleep()

ActiveRecord::sleep (   $field_name)
Parameters
$field_name
Returns
mixed

Reimplemented in ilDclTableView, ilDclTableViewFieldSetting, and ilADTActiveRecordWrapper.

Definition at line 277 of file class.ActiveRecord.php.

277 {
278 return null;
279 }

◆ store()

ActiveRecord::store ( )

Reimplemented in ilOrgUnitPathStorage.

Definition at line 456 of file class.ActiveRecord.php.

456 {
457 $primary_fieldname = arFieldCache::getPrimaryFieldName($this);
458 $primary_value = $this->getPrimaryFieldValue();
459
460 if (!self::where(array( $primary_fieldname => $primary_value ))->hasSets()) {
461 $this->create();
462 } else {
463 $this->update();
464 }
465 }

References arFieldCache\getPrimaryFieldName().

+ Here is the call graph for this function:

◆ storeObjectToCache()

ActiveRecord::storeObjectToCache ( )

Definition at line 126 of file class.ActiveRecord.php.

126 {
128 }

References arObjectCache\store().

+ Here is the call graph for this function:

◆ tableExists()

static ActiveRecord::tableExists ( )
staticfinal
Returns
bool

Definition at line 374 of file class.ActiveRecord.php.

374 {
375 return self::getCalledClass()->getArConnector()->checkTableExists(self::getCalledClass());
376 }

◆ truncateDB()

static ActiveRecord::truncateDB ( )
staticfinal
Returns
bool

Definition at line 441 of file class.ActiveRecord.php.

441 {
442 return self::getCalledClass()->getArConnector()->truncateDatabase(self::getCalledClass());
443 }

◆ update()

ActiveRecord::update ( )

Reimplemented in ilDclFieldProperty, and arStorage.

Definition at line 526 of file class.ActiveRecord.php.

526 {
527 $this->getArConnector()->update($this);
529 }

References arObjectCache\store().

Referenced by ilOrgUnitPathStorage\store().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateDB()

static ActiveRecord::updateDB ( )
staticfinal
Returns
bool

Definition at line 419 of file class.ActiveRecord.php.

419 {
420 if (!self::tableExists()) {
421 self::getCalledClass()->installDatabase();
422
423 return true;
424 }
425
426 return self::getCalledClass()->getArConnector()->updateDatabase(self::getCalledClass());
427 }

◆ wakeUp()

ActiveRecord::wakeUp (   $field_name,
  $field_value 
)
Parameters
$field_name
$field_value
Returns
mixed

Reimplemented in ilDclTableView, ilDclTableViewFieldSetting, and ilADTActiveRecordWrapper.

Definition at line 288 of file class.ActiveRecord.php.

288 {
289 return null;
290 }

◆ where()

Field Documentation

◆ $ar_safe_read

ActiveRecord::$ar_safe_read = true
protected

Definition at line 30 of file class.ActiveRecord.php.

◆ $connector_container_name

ActiveRecord::$connector_container_name = ''
protected

Definition at line 34 of file class.ActiveRecord.php.

Referenced by getConnectorContainerName(), and setConnectorContainerName().

◆ ACTIVE_RECORD_VERSION

const ActiveRecord::ACTIVE_RECORD_VERSION = '2.0.7'

Definition at line 26 of file class.ActiveRecord.php.


The documentation for this class was generated from the following file: