2 require_once(
'class.ActiveRecordList.php');
3 require_once(
'Connector/class.arConnector.php');
4 require_once(
'Connector/class.arConnectorDB.php');
5 require_once(
'Cache/class.arObjectCache.php');
6 require_once(
'Fields/class.arFieldList.php');
7 require_once(
'Cache/class.arFieldCache.php');
8 require_once(
'Storage/int.arStorageInterface.php');
9 require_once(
'Factory/class.arFactory.php');
10 require_once(
'Cache/class.arCalledClassCache.php');
11 require_once(
'Connector/class.arConnectorMap.php');
68 if ($this->connector_container_name) {
71 $ar = self::getCalledClass();
73 return $ar::returnDbTableName();
92 return $this->{$primary_fieldname};
102 $this->{$primary_fieldname} = $value;
111 if ($connector == null) {
118 $key = $arFieldList->getPrimaryFieldName();
119 $this->{$key} = $primary_key;
120 if ($primary_key !== 0 AND $primary_key !== null AND $primary_key !==
false) {
137 $converted_dates =
array();
139 if ($field->isDateField()) {
140 $name = $field->getName();
141 $value = $this->{$name};
142 $converted_dates[$name] =
array(
143 'unformatted' => $value,
144 'unix' => strtotime($value),
147 $converted_dates[$name][
'formatted'] =
date($format, strtotime($value));
152 return $converted_dates;
165 $line .= implode($separator, array_keys($this->
getArFieldList()->getRawFields()));
169 foreach ($this->
__asArray() as $field_name => $value) {
171 if ($serialized === null) {
172 $array[$field_name] = $this->{$field_name};
174 $array[$field_name] = $serialized;
177 $line .= implode($separator, array_values($array));
202 $fieldname = $field->getName();
203 $return[$fieldname] = $this->{$fieldname};
214 $return =
new stdClass();
216 $fieldname = $field->getName();
217 $return->{$fieldname} = $this->{$fieldname};
228 return serialize($this);
238 $class = get_class($this);
240 $primary_value = $array[$primary];
244 foreach ($array as $field_name => $value) {
245 if ($this->
wakeUp($field_name, $value) === null) {
246 $this->{$field_name} = $value;
248 $this->{$field_name} = $this->
wakeUp($field_name, $value);
264 if ($this->
getArFieldList()->getFieldByName($field_name)->isDateField()) {
277 public function sleep($field_name) {
288 public function wakeUp($field_name, $field_value) {
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 );
331 $class = get_called_class();
346 return self::getCalledClass()->installDatabase();
367 return self::getCalledClass()->getArConnector()->renameField(self::getCalledClass(), $old_name, $new_name);
375 return self::getCalledClass()->getArConnector()->checkTableExists(self::getCalledClass());
385 return self::getCalledClass()->getArConnector()->checkFieldExists(self::getCalledClass(), $field_name);
395 return self::getCalledClass()->getArConnector()->removeField(self::getCalledClass(), $field_name);
406 $fields[$field->getName()] = $field->getAttributesForConnector();
420 if (!self::tableExists()) {
421 self::getCalledClass()->installDatabase();
426 return self::getCalledClass()->getArConnector()->updateDatabase(self::getCalledClass());
434 return self::getCalledClass()->getArConnector()->resetDatabase(self::getCalledClass());
442 return self::getCalledClass()->getArConnector()->truncateDatabase(self::getCalledClass());
450 return self::truncateDB();
460 if (!self::where(
array( $primary_fieldname => $primary_value ))->hasSets()) {
476 $this->{$primary_fieldname} = $this->
getArConnector()->nextID($this);
490 public function copy($new_id = 0) {
491 if (self::where(
array( $this->
getArFieldList()->getPrimaryFieldName() => $new_id ))->hasSets()) {
494 $new_obj = clone($this);
495 $new_obj->setPrimaryFieldValue($new_id);
509 } elseif (
count(
$records) == 0 AND $this->ar_safe_read ==
false) {
510 $this->is_new =
true;
514 if ($this->
wakeUp($k, $rec->{$k}) === null) {
515 $this->{$k} = $rec->{$k};
517 $this->{$k} = $this->
wakeUp($k, $rec->{$k});
532 public function delete() {
557 $srModelObjectList->additionalParams($additional_params);
559 return $srModelObjectList;
569 public static function find($primary_key,
array $add_constructor_args =
array()) {
574 $class_name = get_called_class();
576 $obj = arFactory::getInstance($class_name, $primary_key, $add_constructor_args);
577 $obj->storeObjectToCache();
604 $obj = self::find($primary_key, $add_constructor_args);
622 $obj = self::find($primary_key, $add_constructor_args);
626 $class_name = get_called_class();
627 $obj = arFactory::getInstance($class_name, 0, $add_constructor_args);
628 $obj->setPrimaryFieldValue($primary_key);
630 $obj->storeObjectToCache();
643 public static function where($where, $operator = null) {
645 $srModelObjectList->where($where, $operator);
647 return $srModelObjectList;
674 public static function innerjoin($tablename, $on_this, $on_external, $fields =
array(
'*' ), $operator =
'=', $both_external =
false) {
677 return $srModelObjectList->innerjoin($tablename, $on_this, $on_external, $fields, $operator, $both_external);
690 public static function leftjoin($tablename, $on_this, $on_external, $fields =
array(
'*' ), $operator =
'=', $both_external =
false) {
693 return $srModelObjectList->leftjoin($tablename, $on_this, $on_external, $fields, $operator, $both_external);
703 public static function orderBy($orderBy, $orderDirection =
'ASC') {
705 $srModelObjectList->orderBy($orderBy, $orderDirection);
707 return $srModelObjectList;
716 public static function dateFormat($date_format =
'd.m.Y - H:i:s') {
718 $srModelObjectList->dateFormat($date_format);
720 return $srModelObjectList;
732 $srModelObjectList->limit(
$start, $end);
734 return $srModelObjectList;
744 return $srModelObjectList->affectedRows();
752 return self::affectedRows();
759 public static function get() {
762 return $srModelObjectList->get();
772 return $srModelObjectList->debug();
782 return $srModelObjectList->first();
792 return $srModelObjectList;
799 public static function last() {
802 return $srModelObjectList->last();
813 return $srModelObjectList->getFirstFromLastQuery();
825 return $srModelObjectList->connector($connector);
834 public static function raw($set_raw =
true) {
837 return $srModelObjectList->raw($set_raw);
847 public static function getArray($key = null, $values = null) {
850 return $srModelObjectList->getArray($key, $values);
862 public function __call($name, $arguments) {
864 if (preg_match(
"/get([a-zA-Z]*)/u", $name, $matches) AND
count($arguments) == 0) {
865 return $this->{self::fromCamelCase($matches[1])};
868 if (preg_match(
"/set([a-zA-Z]*)/u", $name, $matches) AND
count($arguments) == 1) {
869 $this->{self::fromCamelCase($matches[1])} = $arguments[0];
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();
883 public static function _toCamelCase($str, $capitalise_first_char =
false) {
884 if ($capitalise_first_char) {
885 $str[0] = strtoupper($str[0]);
887 $func = create_function(
'$c',
'return strtoupper($c[1]);');
889 return preg_replace_callback(
'/_([a-z])/', $func, $str);
899 $str[0] = strtolower($str[0]);
900 $func = create_function(
'$c',
'return "_" . strtolower($c[1]);');
902 return preg_replace_callback(
'/([A-Z])/', $func, $str);
static removeDBField($field_name)
static limit($start, $end)
static getFirstFromLastQuery()
buildFromArray(array $array)
Class arStorageInterface.
static getPrimaryFieldName(ActiveRecord $ar)
static leftjoin($tablename, $on_this, $on_external, $fields=array(' *'), $operator='=', $both_external=false)
static renameDBField($old_name, $new_name)
static connector(arConnector $connector)
static innerjoinAR(ActiveRecord $ar, $on_this, $on_external, $fields=array(' *'), $operator='=', $both_external=false)
$connector_container_name
static innerjoin($tablename, $on_this, $on_external, $fields=array(' *'), $operator='=', $both_external=false)
static fieldExists($field_name)
static register(ActiveRecord $ar, arConnector $connector)
static purge(ActiveRecord $object)
static returnDbTableName()
__call($name, $arguments)
static fromCamelCase($str)
__construct($primary_key=0, arConnector $connector=null)
static dateFormat($date_format='d.m.Y - H:i:s')
static where($where, $operator=null)
static raw($set_raw=true)
const COPY_DESTINATION_ID_EXISTS
setPrimaryFieldValue($value)
__getConvertedDateFieldsAsArray($format=null)
__asCsv($separator=';', $header=false)
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)
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
getConnectorContainerName()
Create styles array
The data for the language used.
wakeUp($field_name, $field_value)
static isCached($class, $id)
const ACTIVE_RECORD_VERSION
fixDateField($field_name, $value)
static findOrGetInstance($primary_key, array $add_constructor_args=array())
static getArray($key=null, $values=null)
static get(ActiveRecord $ar)
setConnectorContainerName($connector_container_name)
serializeToCSV($field)
This method is called for every field of your instance if you use __asCsv.
static get(ActiveRecord $ar)
static orderBy($orderBy, $orderDirection='ASC')
static additionalParams(array $additional_params)
static _toCamelCase($str, $capitalise_first_char=false)