From 6822c353c3799956937410869a41c5c29bb9cd81 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Sun, 7 Jul 2013 17:12:57 +0200 Subject: [PATCH] Add a 'forced' option to InsertIntoDatabase, to pre-fill all data instead of lazy-loading --- class.databaserecord.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/class.databaserecord.php b/class.databaserecord.php index 0c0f5d3..52b8dd5 100644 --- a/class.databaserecord.php +++ b/class.databaserecord.php @@ -355,7 +355,7 @@ abstract class CPHPDatabaseRecordClass extends CPHPBaseClass } } - public function InsertIntoDatabase() + public function InsertIntoDatabase($force_data = false) { global $cphp_config, $database; @@ -382,6 +382,29 @@ abstract class CPHPDatabaseRecordClass extends CPHPBaseClass } } + if($force_data === true) + { + foreach($this->prototype as $type_key => $type_value) + { + foreach($type_value as $element_key => $element_value) + { + $variable_name_unsafe = "u" . $element_key; + + if(!isset($this->$variable_name_unsafe)) + { + foreach($this->prototype as $type => $dataset) + { + if(isset($dataset[$element_key])) + { + $column_name = $dataset[$element_key]; + $this->$variable_name_unsafe = $this->uData[$column_name]; + } + } + } + } + } + } + $element_list = array(); foreach($this->prototype as $type_key => $type_value)