public function state($state = NULL)
{
if ($state) {
switch ($state) {
case 'new':
// Reset original data
$this->_original = Sprig::factory($this->_model)->as_array();
break;
case 'loaded':
// Merge the changed data into the original data
$this->_original = array_merge($this->_original, $this->_changed);
$this->_changed = array();
break;
case 'deleted':
case 'loading':
// Pass
break;
default:
throw new Sprig_Exception('Unknown model state: :state', array(':state' => $state));
break;
}
// Set the new state
$this->_state = $state;
return $this;
}
return $this->_state;
}