diff --git a/application/classes/lnapp/table.php b/application/classes/lnapp/table.php index d2fdf4d3..501c5113 100644 --- a/application/classes/lnapp/table.php +++ b/application/classes/lnapp/table.php @@ -16,7 +16,7 @@ class lnApp_Table { if (is_array($d) AND isset($d[$key])) $x = $d[$key]; // If the key is a method, we need to eval it - elseif (preg_match('/\(/',$key)) + elseif (preg_match('/\(/',$key) OR preg_match('/-\>/',$key)) eval("\$x = \$d->$key;"); elseif (preg_match('/^__VALUE__$/',$key)) $x = $d; diff --git a/application/classes/ormosb.php b/application/classes/ormosb.php index e1a4097d..a38e876c 100644 --- a/application/classes/ormosb.php +++ b/application/classes/ormosb.php @@ -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) diff --git a/application/classes/staticlist.php b/application/classes/staticlist.php index 61e8d607..6acc55b9 100644 --- a/application/classes/staticlist.php +++ b/application/classes/staticlist.php @@ -47,6 +47,13 @@ abstract class StaticList { return $table[$id]; } + /** + * Lists our available keys + */ + public static function keys() { + return array_keys(static::factory()->table()); + } + /** * Renders form input * diff --git a/application/views/yaml/page.php b/application/views/yaml/page.php index 32e254e5..7ed4586f 100644 --- a/application/views/yaml/page.php +++ b/application/views/yaml/page.php @@ -51,7 +51,7 @@