From 6807b6ab525749b61ff016212d9b6d81b988de8a Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 30 Mar 2012 15:13:01 +1100 Subject: [PATCH] Multi enhancements, including auto serialization, product editing --- application/classes/lnapp/table.php | 2 +- application/classes/ormosb.php | 52 +++++++--- application/classes/staticlist.php | 7 ++ application/views/yaml/page.php | 2 +- .../classes/model/product/plugin/adsl.php | 4 + .../classes/model/service/plugin/adsl.php | 4 + .../service/admin/list/adslservices_body.php | 12 --- .../admin/list/adslservices_header.php | 23 ----- .../views/service/user/plugin/adsl/view.php | 8 +- .../classes/model/product/plugin/domain.php | 1 + modules/export/classes/quicken.php | 3 + .../classes/controller/task/invoice.php | 54 +++++----- modules/invoice/classes/model/invoice.php | 8 +- .../classes/controller/admin/payment.php | 1 + .../classes/controller/admin/product.php | 99 ++++++++++++++++++- .../product/classes/controller/product.php | 4 + modules/product/classes/model/product.php | 71 ++++++++++++- .../model/product/category/translate.php | 20 ++++ .../product/classes/model/product/plugin.php | 6 ++ .../classes/model/product/translate.php | 2 + .../views/product/admin/ajaxtranslateform.php | 15 +++ .../product/views/product/admin/update.php | 63 ++++++++++++ modules/product/views/product/view.php | 10 +- .../classes/controller/admin/service.php | 23 ++--- .../classes/controller/affiliate/service.php | 14 +-- .../classes/controller/user/service.php | 2 +- modules/service/classes/model/service.php | 19 +++- .../service/classes/model/service/billing.php | 5 + .../service/views/service/admin/update.php | 4 - modules/service/views/service/user/view.php | 22 ++++- 30 files changed, 445 insertions(+), 115 deletions(-) delete mode 100644 modules/adsl/views/service/admin/list/adslservices_body.php delete mode 100644 modules/adsl/views/service/admin/list/adslservices_header.php create mode 100644 modules/product/classes/model/product/category/translate.php create mode 100644 modules/product/views/product/admin/ajaxtranslateform.php create mode 100644 modules/product/views/product/admin/update.php 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 @@