Example #1
0
 public function init($attributes = array())
 {
     //        $this->_internationalize = is_null($this->_internationalize) && AK_ACTIVE_RECORD_INTERNATIONALIZE_MODELS_BY_DEFAULT ? count($this->getAvailableLocales()) > 1 : $this->_internationalize;
     //      @$this->_instantiateDefaultObserver();
     //    $this->establishConnection();
     if (!empty($this->table_name)) {
         //      $this->setTableName($this->table_name);
     }
     /*$load_acts = isset($attributes[1]['load_acts']) ? $attributes[1]['load_acts'] : (isset($attributes[0]['load_acts']) ? $attributes[0]['load_acts'] : true);
             $this->act_as = !empty($this->acts_as) ? $this->acts_as : (empty($this->act_as) ? false : $this->act_as);
             if (!empty($this->act_as) && $load_acts) {
                 $this->_loadActAsBehaviours();
             }
     
             if(!empty($this->combined_attributes)){
                 foreach ($this->combined_attributes as $combined_attribute){
                     $this->addCombinedAttributeConfiguration($combined_attribute);
                 }
             }*/
     if (isset($attributes[0]) && is_array($attributes[0]) && count($attributes) === 1) {
         $attributes = $attributes[0];
         $this->_newRecord = true;
     }
     // new AkActiveRecord(23); //Returns object with primary key 23
     if (isset($attributes[0]) && count($attributes) === 1 && $attributes[0] > 0) {
         $record = $this->find($attributes[0]);
         if (!$record) {
             return false;
         } else {
             $this->setAttributes($record->getAttributes(), true);
         }
         // This option is only used internally for loading found objects
     } elseif (isset($attributes[0]) && isset($attributes[1]) && $attributes[0] == 'attributes' && is_array($attributes[1])) {
         foreach (array_keys($attributes[1]) as $k) {
             $attributes[1][$k] = $this->castAttributeFromDatabase($k, $attributes[1][$k]);
         }
         $avoid_loading_associations = isset($attributes[1]['load_associations']) ? false : !empty($this->disableAutomatedAssociationLoading);
         $this->setAttributes($attributes[1], true);
     } else {
         $this->newRecord($attributes);
     }
     if (isset($this->has_many)) {
         foreach ($this->has_many as $class_item) {
             $handler_name = $class_item['table_name'];
             $handler = new Model();
             $handler->setColumns($class_item['columns']);
             $handler->setTableName($handler_name);
             $handler->_modelName = $class_item['table_name'];
             $handler->is_virtual_obj = true;
             $this->{$handler_name} = $handler;
         }
     }
     //empty($avoid_loading_associations) ? $this->loadAssociations() : null;
 }