From d412939912b95a1bc3908659f45902b460af8061 Mon Sep 17 00:00:00 2001 From: nate Date: Mon, 9 Oct 2006 22:00:22 +0000 Subject: [PATCH] Refactoring Model::save and teaching Model to eat XML git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3620 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/model.php | 43 +++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index 8e9bc28d0..b8248b0b8 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -31,7 +31,7 @@ /** * Included libs */ -uses('class_registry', 'validators', 'overloadable', 'model' . DS . 'behavior'); +uses('class_registry', 'validators', 'overloadable', 'model' . DS . 'behavior', 'set'); /** * Object-relational mapper. @@ -677,6 +677,29 @@ class Model extends Overloadable { * @return unknown */ function set($one, $two = null) { + + if (is_object($one)) { + if (is_a($one, 'xmlnode') || is_a($one, 'XMLNode')) { + if ($one->name != Inflector::underscore($this->name)) { + if (is_object($one->getChild(Inflector::underscore($this->name)))) { + $one = $one->getChild(Inflector::underscore($this->name)); + $one = $one->attributes; + } else { + return null; + } + } + } elseif (is_a($one, 'stdclass') || is_a($one, 'stdClass')) { + $one = get_object_vars($one); + $keys = array_keys($one); + $count = count($keys); + for ($i = 0; $i < $count; $i++) { + if ($keys[$i] == '__identity__' || is_array($one[$keys[$i]]) || is_object($one[$keys[$i]])) { + unset($one[$keys[$i]]); + } + } + } + } + if (is_array($one)) { if (countdim($one) == 1) { $data = array($this->name => $one); @@ -884,13 +907,7 @@ class Model extends Overloadable { function save($data = null, $validate = true, $fieldList = array()) { $db =& ConnectionManager::getDataSource($this->useDbConfig); - if ($data) { - if (countdim($data) == 1) { - $this->set(array($this->name => $data)); - } else { - $this->set($data); - } - } + $this->set($data); $whitelist = !(empty($fieldList) || count($fieldList) == 0); @@ -1066,6 +1083,16 @@ class Model extends Overloadable { } } } +/** + * Allows model records to be updated based on a set of conditions + * + * @param mixed $conditions + * @param mixed $fields + * @return boolean True on success, false on failure + */ + function updateAll($conditions, $fields) { + + } /** * Synonym for del(). *