mlantahler:Bugfix: Added checks in DataObjectSet::First() and DataObjectSet::Last() to prevent errors on an empty $items array. (merged from branches/gsoc)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@41778 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2007-09-14 17:59:33 +00:00
parent 898d897c9e
commit d47e6cf67c

View File

@ -526,6 +526,9 @@ class DataObjectSet extends ViewableData implements Iterator {
* @return DataObject
*/
public function First() {
if(count($this->items) < 1)
return null;
$keys = array_keys($this->items);
return sizeof($keys) > 0 ? $this->items[$keys[0]] : null;
}
@ -535,6 +538,9 @@ class DataObjectSet extends ViewableData implements Iterator {
* @return DataObject
*/
public function Last() {
if(count($this->items) < 1)
return null;
$keys = array_keys($this->items);
return $this->items[$keys[sizeof($keys)-1]];
}