Multi enhancements, including auto serialization, product editing

This commit is contained in:
Deon George
2012-03-30 15:13:01 +11:00
parent d9c3394b0f
commit 6807b6ab52
30 changed files with 445 additions and 115 deletions

View File

@@ -19,6 +19,9 @@ abstract class ORMOSB extends ORM {
protected $_created_column = array('column'=>'date_orig','format'=>TRUE);
protected $_updated_column = array('column'=>'date_last','format'=>TRUE);
// Our attribute values that need to be stored as serialized
protected $_serialize_column = array();
public function rules() {
return array(
'id'=>array(
@@ -93,6 +96,7 @@ abstract class ORMOSB extends ORM {
return TRUE;
}
// @todo Change this to be called by array_blob functions
public static function serialize_array(ORM $model,$field,$value) {
if (is_null($value))
return TRUE;
@@ -105,25 +109,51 @@ abstract class ORMOSB extends ORM {
}
public function __get($column) {
// If the column is a blob, we'll decode it automatically
if (array_key_exists($column,$this->_table_columns) AND $this->_table_columns[$column]['data_type'] == 'blob' AND (! isset($this->_table_columns[$column]['auto_convert']) OR ! $this->_table_columns[$column]['auto_convert'])) {
if (array_key_exists($column,$this->_table_columns)) {
// In case our blob hasnt been saved as one.
try {
$this->_object[$column] = $this->blob($this->_object[$column]);
}
catch(Exception $e) {
// @todo Log this exception
echo Kohana_Exception::text($e), "\n";
echo debug_print_backtrace();
// If the column is a blob, we'll decode it automatically
if ($this->_table_columns[$column]['data_type'] == 'blob' AND (! isset($this->_table_columns[$column]['auto_convert']) OR ! $this->_table_columns[$column]['auto_convert'])) {
// In case our blob hasnt been saved as one.
try {
$this->_object[$column] = $this->blob($this->_object[$column]);
}
catch(Exception $e) {
// @todo Log this exception
echo Kohana_Exception::text($e), "\n";
echo debug_print_backtrace();
}
$this->_table_columns[$column]['auto_convert'] = TRUE;
}
$this->_table_columns[$column]['auto_convert'] = TRUE;
// If the column is a serialized object, we'll unserialize it.
if (in_array($column,$this->_serialize_column) AND (! isset($this->_table_columns[$column]['unserialized']) OR ! $this->_table_columns[$column]['unserialized'])) {
// In case our object hasnt been saved as serialized.
try {
$this->_object[$column] = unserialize($this->_object[$column]);
}
catch(Exception $e) {
// @todo Log this exception
echo Kohana_Exception::text($e), "\n";
echo debug_print_backtrace();
}
$this->_table_columns[$column]['unserialized'] = TRUE;
}
}
return parent::__get($column);
}
public function keyget($column,$key=NULL) {
if (is_null($key) OR ! is_array($this->$column))
return $this->$column;
else
return array_key_exists($key,$this->$column) ? $this->{$column}[$key] : NULL;
}
public function save(Validation $validation = NULL) {
// Find any fields that have changed, and that are blobs, and encode them.
if ($this->_changed)