Exemplo n.º 1
0
 /**
  * @see EntityInterface::save()
  */
 public function save()
 {
     parent::_save();
     $this->set_id($this->_get_id());
     if ($this->get_group()->length() > 0) {
         $db = new Apine\Core\Database();
         $db->delete('apine_users_user_groups', array("user_id" => $this->get_id()));
         foreach ($this->get_group() as $item) {
             $db->insert('apine_users_user_groups', array("user_id" => $this->get_id(), "group_id" => $item->get_id()));
         }
     }
     if (count($this->properties) > 0) {
         foreach ($this->properties as $item) {
             $item->save();
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Save Entity state to database
  */
 protected final function _save()
 {
     $db = new Database();
     if ($this->id === null) {
         $this->field_loaded = 0;
     }
     if ($this->field_loaded == 0) {
         // This is a new or unloaded entity
         $new_dbf = array();
         if (!empty($this->database_fields)) {
             foreach ($this->database_fields as $field => $val) {
                 if (!is_numeric($field)) {
                     $new_dbf[$field] = $val;
                 }
             }
         }
         if (sizeof($new_dbf) > 0) {
             $this->id = $db->insert($this->table_name, $new_dbf);
         }
         $this->_load();
     } else {
         // This is an already existing entity
         // Update procedure only executed if at least
         // one field was modified
         if (count($this->modified_fields) > 0) {
             $arUpdate = array();
             foreach ($this->database_fields as $key => $value) {
                 if (!is_numeric($key)) {
                     if (isset($this->modified_fields[$key]) && $this->modified_fields[$key] == true) {
                         $arUpdate[$key] = $value;
                     }
                 }
             }
             $db->update($this->table_name, $arUpdate, array($this->load_field => $this->id));
         }
     }
 }