From 3e55ad2dad13577cf20680dd5ef61845ff487d6c Mon Sep 17 00:00:00 2001 From: secretr Date: Tue, 17 Nov 2009 15:34:54 +0000 Subject: [PATCH] model future problems solved --- e107_handlers/model_class.php | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/e107_handlers/model_class.php b/e107_handlers/model_class.php index 994f46b16..1a4b04a66 100644 --- a/e107_handlers/model_class.php +++ b/e107_handlers/model_class.php @@ -9,8 +9,8 @@ * e107 Base Model * * $Source: /cvs_backup/e107_0.8/e107_handlers/model_class.php,v $ - * $Revision: 1.38 $ - * $Date: 2009-11-17 15:23:01 $ + * $Revision: 1.39 $ + * $Date: 2009-11-17 15:34:54 $ * $Author: secretr $ */ @@ -820,10 +820,15 @@ class e_model */ public function load($id, $force = false) { - if($this->hasData() && !$force) + if(!$force && $this->hasData()) { return $this; } + + if($force) + { + $this->setData(array()); + } $id = intval($id); $qry = str_replace('{ID}', $id, $this->getParam('db_query')); @@ -1937,7 +1942,7 @@ class e_tree_model extends e_model * * @var string */ - protected $_total = 0; + protected $_total = false; /** * Constructor @@ -2013,11 +2018,17 @@ class e_tree_model extends e_model public function load($force = false) { - if(!$this->isEmpty() && !$force) + if(!$force && !$this->isEmpty()) { return $this; } + if ($force) + { + $this->setTree(array(), true); + $this->_total = false; + } + if($this->getParam('db_query') && $this->getParam('model_class') && class_exists($this->getParam('model_class'))) { $sql = e107::getDb(); @@ -2025,15 +2036,16 @@ class e_tree_model extends e_model $this->_total = $sql->total_results = false; if($sql->db_Select_gen($this->getParam('db_query'))) { - $this->_total = $sql->total_results; //requires SQL_CALC_FOUND_ROWS in query - see db handler + // TODO - $sql->total_results variable type!!! + $this->_total = is_integer($sql->total_results) ? $sql->total_results : false; //requires SQL_CALC_FOUND_ROWS in query - see db handler while($tmp = $sql->db_Fetch()) { $tmp = new $class_name($tmp); $this->setNode($tmp->get($this->getFieldIdName()), $tmp); } - // FIXME - test for type of $this->_total to avoid query if table is empty - if(!$this->_total && $this->getModelTable()) + + if(false === $this->_total && $this->getModelTable()) { //SQL_CALC_FOUND_ROWS not found in the query, do one more query $this->_total = e107::getDb()->db_Count($this->getModelTable());