From 7335afb742d3a02710e3a8bfa5b78324f7837f39 Mon Sep 17 00:00:00 2001 From: Arron Woods Date: Fri, 10 Apr 2015 17:38:36 +0100 Subject: Fixes for empty results --- library/SSRS/Object/CatalogItems.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/library/SSRS/Object/CatalogItems.php b/library/SSRS/Object/CatalogItems.php index 6386cd5..22664f2 100755 --- a/library/SSRS/Object/CatalogItems.php +++ b/library/SSRS/Object/CatalogItems.php @@ -7,7 +7,7 @@ namespace SSRS\Object; * * @author arron */ -class CatalogItems extends ArrayIterator { +class CatalogItems extends ArrayIterator implements \Countable { public $iteratorKey = 'CatalogItems'; @@ -15,12 +15,29 @@ class CatalogItems extends ArrayIterator { $this->data['CatalogItems'] = array(); } + public function count() { + return count($this->data['CatalogItems']); + } + + /** + * + * @param \stdClass $items + * @return \SSRS\Object\CatalogItems + */ public function setCatalogItems(\stdClass $items) { - foreach ($items->CatalogItem AS $item) { - $this->addCatalogItem(new CatalogItem($item)); + if (isset($items->CatalogItem)) { + foreach ($items->CatalogItem AS $item) { + $this->addCatalogItem(new CatalogItem($item)); + } } + + return $this; } + /** + * + * @param \SSRS\Object\CatalogItem $item + */ public function addCatalogItem(CatalogItem $item) { $this->data['CatalogItems'][] = $item; } -- cgit v1.1