_initTable(); $this->table->update(array('is_default' => 'n'), '1'); $this->table->update(array('is_default' => 'y'), 'id=' . $this->db->quote($this->id, 'integer')); } function insert($data = null, $files = null) { if (!is_null($data)) { $this->initFromArray($data, $files); } $this->_initTable(); $data = $this->_data; unset($data['id']); $fields = $this->getSimpleFieldList(); if (isset($fields['sorter'])) { $data['sorter'] = $this->getSorter(); } if ($this->_data['is_default'] == 'y') { $this->table->update(array('is_default' => 'n'), '1'); } $this->id = $this->table->insert($data); $this->handleFiles(); return $this->id; } function update($data = null, $files = null) { if (!is_null($data)) { $this->initFromArray($data, $files); } $this->_initTable(); if ($this->_data['is_default'] == 'y') { $this->table->update(array('is_default' => 'n'), '1'); } $this->table->update($this->_data, 'id = '. $this->db->quote($this->id, 'integer') ); $this->handleFiles(); return true; } }