From b5c83d351340dd79815a31d666a32f3fcc676c0c Mon Sep 17 00:00:00 2001 From: Romain Louis Date: Mon, 3 Sep 2007 05:08:33 +0000 Subject: [PATCH] setByIDList function update( notices and ajax problem solving ) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@41165 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/ComponentSet.php | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/core/model/ComponentSet.php b/core/model/ComponentSet.php index 5a08ccd7b..bfefe7a7f 100755 --- a/core/model/ComponentSet.php +++ b/core/model/ComponentSet.php @@ -159,35 +159,32 @@ class ComponentSet extends DataObjectSet { * @param array $idList List of IDs. */ function setByIDList($idList) { - $has = array(); - // Index current data if($this->items) { - foreach($this->items as $item) { + foreach( $this->items as $item ) $has[$item->ID] = true; - } } // Keep track of items to delete - $itemsToDelete = $has; + if( isset( $has ) ) + $itemsToDelete = $has; if($idList){ foreach($idList as $id) { - $itemsToDelete[$id] = false; - if(!isset($has[$id]) && $id) { + if( isset( $itemsToDelete ) ) + $itemsToDelete[$id] = false; + if( ! isset( $has ) || ( $id && ! isset( $has[$id] ) ) ) $this->add($id); - } } } // Delete any unmentionedItems - if($itemsToDelete) { - $removeList = array(); + if( isset( $itemsToDelete ) ) { foreach($itemsToDelete as $id => $actuallyDelete) { if($actuallyDelete) $removeList[] = $id; } - if($removeList) { + + if( isset( $removeList ) ) $this->removeMany($removeList); - } } }