diff --git a/examples/SharePoint/ListItems/ReadLargeList.php b/examples/SharePoint/ListItems/ReadLargeList.php index 8ea94abc..3565a016 100644 --- a/examples/SharePoint/ListItems/ReadLargeList.php +++ b/examples/SharePoint/ListItems/ReadLargeList.php @@ -13,8 +13,8 @@ $list = $ctx->getWeb()->getLists()->getByTitle("Contacts_Large"); /* -$items = $list->getItems()->get()->paged(500, function ($itemsCountLoaded){ - print("$itemsCountLoaded items loaded...\n"); +$items = $list->getItems()->get()->paged(500, function ($returnType){ + print("{$returnType->getItemsCount()} items loaded...\n"); })->executeQuery(); foreach ($items as $index => $item){ @@ -24,8 +24,8 @@ //$totalItemsCount = $items->getCount(); //print($totalItemsCount); -$allItems = $list->getItems()->getAll()->paged(5000, function ($itemsCount){ - print("$itemsCount items loaded...\n"); +$allItems = $list->getItems()->getAll()->paged(5000, function ($returnType){ + print("{$returnType->getPageInfo()} items loaded...\n"); })->executeQuery(); diff --git a/src/Runtime/ClientObjectCollection.php b/src/Runtime/ClientObjectCollection.php index ec2604e8..61d0951c 100644 --- a/src/Runtime/ClientObjectCollection.php +++ b/src/Runtime/ClientObjectCollection.php @@ -11,6 +11,42 @@ use Traversable; +class PageInfo { + + public function __construct() + { + $this->startIndex = 0; + $this->endIndex = 0; + } + + public function setNextPage($index){ + if($index == 0) + return; + + if($this->endIndex < $index){ + $this->startIndex = $this->endIndex; + $this->endIndex = $index; + } + } + + public function __toString() + { + return "$this->endIndex"; + } + + /** + * @var int + */ + public $startIndex; + + /** + * @var int + */ + public $endIndex; + +} + + /** * Client objects collection (represents EntitySet in terms of OData) */ @@ -44,6 +80,11 @@ class ClientObjectCollection extends ClientObject implements IteratorAggregate, */ protected $pageLoaded; + /** + * @var PageInfo + */ + protected $pageInfo; + /** * @param ClientRuntimeContext $ctx @@ -57,6 +98,7 @@ public function __construct(ClientRuntimeContext $ctx,ResourcePath $resourcePath $this->NextRequestUrl = null; $this->itemTypeName = $itemTypeName; $this->pagedMode = false; + $this->pageInfo = new PageInfo(); $this->pageLoaded = new EventHandler(); } @@ -164,6 +206,7 @@ public function getItem($index) } /** + * Returns total items count * @return int * @throws Exception */ @@ -345,7 +388,8 @@ protected function hasNext(){ public function get() { $this->getContext()->getPendingRequest()->afterExecuteRequest(function (){ - $this->pageLoaded->triggerEvent(array(count($this->data))); + $this->pageInfo->setNextPage(count($this->data)); + $this->pageLoaded->triggerEvent(array($this)); }); return parent::get(); } @@ -440,4 +484,8 @@ public function offsetUnset($offset): void unset($this->data[$offset]); } } + + public function getPageInfo(){ + return $this->pageInfo; + } } diff --git a/src/Teams/TeamCollection.php b/src/Teams/TeamCollection.php index 105eccf5..c55a843d 100644 --- a/src/Teams/TeamCollection.php +++ b/src/Teams/TeamCollection.php @@ -67,20 +67,20 @@ private function parseCreateResponse($response){ /** * To list all teams in an organization (tenant), you find all groups that have teams, * and then get information for each team. - * @param string[] $includeProperties */ - public function getAll($includeProperties=array()) + public function getAll($pageSize=null, $pageLoaded=null) { - $includeProperties = array_merge($includeProperties, array("id", "resourceProvisioningOptions")); - $groups = $this->getContext()->getGroups()->select($includeProperties)->get(); - $this->getContext()->getPendingRequest()->afterExecuteRequest(function () use($groups) { - /** @var Group $group */ - foreach ($groups as $group){ - if (in_array("Team", $group->getProperty("ResourceProvisioningOptions"))) { - $this->addChild($group); + $includeProperties = array("id", "resourceProvisioningOptions"); + $this->getContext()->getGroups()->select($includeProperties)->getAll($pageSize, + function ($returnType) { + $pagedItems = array_slice($returnType->getData(), $returnType->pageInfo->endIndex); + /** @var Group $group */ + foreach ($pagedItems as $group) { + if (in_array("Team", $group->getProperty("ResourceProvisioningOptions"))) { + $this->addChild($group); + } } - } - }, true); + }); return $this; } diff --git a/tests/teams/TeamsTest.php b/tests/teams/TeamsTest.php index 25694d18..8e73929b 100644 --- a/tests/teams/TeamsTest.php +++ b/tests/teams/TeamsTest.php @@ -24,7 +24,7 @@ public function testGetJoinedTeams() public function testGetAllTeams() { - $teams = self::$graphClient->getTeams()->getAll(array("displayName"))->executeQuery(); + $teams = self::$graphClient->getTeams()->getAll()->executeQuery(); self::assertNotNull($teams->getResourcePath()); }