コード例 #1
0
 protected function load()
 {
     if ($this->loaded) {
         return;
     } else {
         $records = $this->connector->readSet($this);
         /**
          * @var $obj ActiveRecord
          */
         $class = get_class($this->getAR());
         $obj = arFactory::getInstance($class, NULL, $this->getAddidtionalParameters());
         $primaryFieldName = $obj->getArFieldList()->getPrimaryFieldName();
         foreach ($records as $res) {
             $primary_field_value = $res[$primaryFieldName];
             if (!$this->getRaw()) {
                 $obj = arFactory::getInstance($class, NULL, $this->getAddidtionalParameters());
                 $this->result[$primary_field_value] = $obj->buildFromArray($res);
             }
             $res_awake = array();
             if (!$this->getRaw()) {
                 foreach ($res as $key => $value) {
                     $arField = $obj->getArFieldList()->getFieldByName($key);
                     if ($arField !== NULL) {
                         if ($arField->isDateField() and $this->getDateFormat()) {
                             $res_awake[$key . '_unformatted'] = $value;
                             $res_awake[$key . '_unix'] = strtotime($value);
                             $value = date($this->getDateFormat(), strtotime($value));
                         }
                     }
                     if ($this->getAR()->wakeUp($key, $value)) {
                         $res_awake[$key] = $this->getAR()->wakeUp($key, $value);
                     } else {
                         $res_awake[$key] = $value;
                     }
                 }
                 $this->result_array[$res_awake[$primaryFieldName]] = $res_awake;
             } else {
                 $this->result_array[$primary_field_value] = $res;
             }
         }
         $this->loaded = true;
     }
 }
コード例 #2
0
 /**
  * @param       $primary_key
  * @param 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
  *
  * @return ActiveRecord
  */
 public static function findOrGetInstance($primary_key, array $add_constructor_args = array())
 {
     $obj = self::find($primary_key, $add_constructor_args);
     if ($obj !== NULL) {
         return $obj;
     } else {
         $class_name = get_called_class();
         $obj = arFactory::getInstance($class_name, 0, $add_constructor_args);
         $obj->setPrimaryFieldValue($primary_key);
         $obj->is_new = true;
         $obj->storeObjectToCache();
         return $obj;
     }
 }
コード例 #3
0
 /**
  * @param $class_name
  */
 public static function store($class_name)
 {
     self::$cache[$class_name] = arFactory::getInstance($class_name, NULL);
 }