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');
72 if ($this->connector_container_name) {
75 $ar = self::getCalledClass();
77 return $ar::returnDbTableName();
98 return $this->{$primary_fieldname};
109 $this->{$primary_fieldname} = $value;
126 $key = $arFieldList->getPrimaryFieldName();
127 $this->{
$key} = $primary_key;
128 if ($primary_key !== 0 and $primary_key !== null and $primary_key !==
false) {
147 $converted_dates =
array();
149 if ($field->isDateField()) {
150 $name = $field->getName();
151 $value = $this->{
$name};
153 'unformatted' => $value,
154 'unix' => strtotime($value),
162 return $converted_dates;
176 $line .= implode($separator, array_keys($this->
getArFieldList()->getRawFields()));
180 foreach ($this->
__asArray() as $field_name => $value) {
182 if ($serialized === null) {
183 $array[$field_name] = $this->{$field_name};
185 $array[$field_name] = $serialized;
188 $line .= implode($separator, array_values($array));
215 $fieldname = $field->getName();
216 $return[$fieldname] = $this->{$fieldname};
228 $return =
new stdClass();
230 $fieldname = $field->getName();
231 $return->{$fieldname} = $this->{$fieldname};
243 return serialize($this);
254 $class = get_class($this);
256 $primary_value = $array[$primary];
260 foreach ($array as $field_name => $value) {
261 if ($this->
wakeUp($field_name, $value) === null) {
262 $this->{$field_name} = $value;
264 $this->{$field_name} = $this->
wakeUp($field_name, $value);
281 if ($this->
getArFieldList()->getFieldByName($field_name)->isDateField()) {
306 public function wakeUp($field_name, $field_value)
329 $field_name = $field->getName();
330 $sleeped = $this->
sleep($field_name);
331 $var = ($sleeped === null) ? ($this->{$field_name}) : $sleeped;
332 $data[$field_name] =
array( $field->getFieldType(), $var );
353 $class = get_called_class();
369 return self::getCalledClass()->installDatabase();
392 return self::getCalledClass()->getArConnector()->renameField(self::getCalledClass(), $old_name, $new_name);
401 return self::getCalledClass()->getArConnector()->checkTableExists(self::getCalledClass());
412 return self::getCalledClass()->getArConnector()->checkFieldExists(self::getCalledClass(), $field_name);
423 return self::getCalledClass()->getArConnector()->removeField(self::getCalledClass(), $field_name);
435 $fields[$field->getName()] = $field->getAttributesForConnector();
450 if (!self::tableExists()) {
451 self::getCalledClass()->installDatabase();
456 return self::getCalledClass()->getArConnector()->updateDatabase(self::getCalledClass());
465 return self::getCalledClass()->getArConnector()->resetDatabase(self::getCalledClass());
474 return self::getCalledClass()->getArConnector()->truncateDatabase(self::getCalledClass());
483 return self::truncateDB();
494 if (!self::where(
array( $primary_fieldname => $primary_value ))->hasSets()) {
512 $this->{$primary_fieldname} = $this->
getArConnector()->nextID($this);
526 public function copy($new_id = 0)
528 if (self::where(
array( $this->
getArFieldList()->getPrimaryFieldName() => $new_id ))->hasSets()) {
531 $new_obj = clone($this);
532 $new_obj->setPrimaryFieldValue($new_id);
552 $this->is_new =
true;
557 if ($this->
wakeUp($k, $rec->{$k}) === null) {
558 $this->{$k} = $rec->{$k};
560 $this->{$k} = $this->
wakeUp($k, $rec->{$k});
576 public function delete()
604 $srModelObjectList->additionalParams($additional_params);
606 return $srModelObjectList;
616 public static function find($primary_key,
array $add_constructor_args =
array())
622 $class_name = get_called_class();
624 $obj = arFactory::getInstance($class_name, $primary_key, $add_constructor_args);
625 $obj->storeObjectToCache();
653 $obj = self::find($primary_key, $add_constructor_args);
672 $obj = self::find($primary_key, $add_constructor_args);
676 $class_name = get_called_class();
677 $obj = arFactory::getInstance($class_name, 0, $add_constructor_args);
678 $obj->setPrimaryFieldValue($primary_key);
680 $obj->storeObjectToCache();
693 public static function where($where, $operator = null)
696 $srModelObjectList->where($where, $operator);
698 return $srModelObjectList;
726 public static function innerjoin($tablename, $on_this, $on_external, $fields =
array(
'*' ), $operator =
'=', $both_external =
false)
730 return $srModelObjectList->innerjoin($tablename, $on_this, $on_external, $fields, $operator, $both_external);
743 public static function leftjoin($tablename, $on_this, $on_external, $fields =
array(
'*' ), $operator =
'=', $both_external =
false)
747 return $srModelObjectList->leftjoin($tablename, $on_this, $on_external, $fields, $operator, $both_external);
757 public static function orderBy($orderBy, $orderDirection =
'ASC')
760 $srModelObjectList->orderBy($orderBy, $orderDirection);
762 return $srModelObjectList;
771 public static function dateFormat($date_format =
'd.m.Y - H:i:s')
774 $srModelObjectList->dateFormat($date_format);
776 return $srModelObjectList;
789 $srModelObjectList->limit($start,
$end);
791 return $srModelObjectList;
802 return $srModelObjectList->affectedRows();
811 return self::affectedRows();
818 public static function get()
822 return $srModelObjectList->get();
833 return $srModelObjectList->debug();
844 return $srModelObjectList->first();
855 return $srModelObjectList;
866 return $srModelObjectList->last();
878 return $srModelObjectList->getFirstFromLastQuery();
891 return $srModelObjectList->connector($connector);
900 public static function raw($set_raw =
true)
904 return $srModelObjectList->raw($set_raw);
918 return $srModelObjectList->getArray(
$key, $values);
933 if (preg_match(
"/get([a-zA-Z]*)/u",
$name, $matches) and
count($arguments) == 0) {
934 return $this->{self::fromCamelCase($matches[1])};
937 if (preg_match(
"/set([a-zA-Z]*)/u",
$name, $matches) and
count($arguments) == 1) {
938 $this->{self::fromCamelCase($matches[1])} = $arguments[0];
940 if (preg_match(
"/findBy([a-zA-Z]*)/u",
$name, $matches) and
count($arguments) == 1) {
941 return self::where(
array( self::fromCamelCase($matches[1]) => $arguments[0] ))->getFirst();
952 public static function _toCamelCase($str, $capitalise_first_char =
false)
954 if ($capitalise_first_char) {
955 $str[0] = strtoupper($str[0]);
957 $func = create_function(
'$c',
'return strtoupper($c[1]);');
959 return preg_replace_callback(
'/_([a-z])/', $func, $str);
970 $str[0] = strtolower($str[0]);
971 $func = create_function(
'$c',
'return "_" . strtolower($c[1]);');
973 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 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)