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
This commit is contained in:
nate 2006-10-09 22:00:22 +00:00
parent 76e52d3862
commit d412939912

View file

@ -31,7 +31,7 @@
/** /**
* Included libs * Included libs
*/ */
uses('class_registry', 'validators', 'overloadable', 'model' . DS . 'behavior'); uses('class_registry', 'validators', 'overloadable', 'model' . DS . 'behavior', 'set');
/** /**
* Object-relational mapper. * Object-relational mapper.
@ -677,6 +677,29 @@ class Model extends Overloadable {
* @return unknown * @return unknown
*/ */
function set($one, $two = null) { 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 (is_array($one)) {
if (countdim($one) == 1) { if (countdim($one) == 1) {
$data = array($this->name => $one); $data = array($this->name => $one);
@ -884,13 +907,7 @@ class Model extends Overloadable {
function save($data = null, $validate = true, $fieldList = array()) { function save($data = null, $validate = true, $fieldList = array()) {
$db =& ConnectionManager::getDataSource($this->useDbConfig); $db =& ConnectionManager::getDataSource($this->useDbConfig);
if ($data) { $this->set($data);
if (countdim($data) == 1) {
$this->set(array($this->name => $data));
} else {
$this->set($data);
}
}
$whitelist = !(empty($fieldList) || count($fieldList) == 0); $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(). * Synonym for del().
* *