Skip to content

Commit 793bbc5

Browse files
committed
v3.0.0 release
1 parent 89fd826 commit 793bbc5

File tree

4 files changed

+65
-17
lines changed

4 files changed

+65
-17
lines changed

examples/SharePoint/ListItems/ReadLargeList.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
$list = $ctx->getWeb()->getLists()->getByTitle("Contacts_Large");
1414

1515
/*
16-
$items = $list->getItems()->get()->paged(500, function ($itemsCountLoaded){
17-
print("$itemsCountLoaded items loaded...\n");
16+
$items = $list->getItems()->get()->paged(500, function ($returnType){
17+
print("{$returnType->getItemsCount()} items loaded...\n");
1818
})->executeQuery();
1919
2020
foreach ($items as $index => $item){
@@ -24,8 +24,8 @@
2424
//$totalItemsCount = $items->getCount();
2525
//print($totalItemsCount);
2626

27-
$allItems = $list->getItems()->getAll()->paged(5000, function ($itemsCount){
28-
print("$itemsCount items loaded...\n");
27+
$allItems = $list->getItems()->getAll()->paged(5000, function ($returnType){
28+
print("{$returnType->getPageInfo()} items loaded...\n");
2929
})->executeQuery();
3030

3131

src/Runtime/ClientObjectCollection.php

+49-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,42 @@
1111
use Traversable;
1212

1313

14+
class PageInfo {
15+
16+
public function __construct()
17+
{
18+
$this->startIndex = 0;
19+
$this->endIndex = 0;
20+
}
21+
22+
public function setNextPage($index){
23+
if($index == 0)
24+
return;
25+
26+
if($this->endIndex < $index){
27+
$this->startIndex = $this->endIndex;
28+
$this->endIndex = $index;
29+
}
30+
}
31+
32+
public function __toString()
33+
{
34+
return "$this->endIndex";
35+
}
36+
37+
/**
38+
* @var int
39+
*/
40+
public $startIndex;
41+
42+
/**
43+
* @var int
44+
*/
45+
public $endIndex;
46+
47+
}
48+
49+
1450
/**
1551
* Client objects collection (represents EntitySet in terms of OData)
1652
*/
@@ -44,6 +80,11 @@ class ClientObjectCollection extends ClientObject implements IteratorAggregate,
4480
*/
4581
protected $pageLoaded;
4682

83+
/**
84+
* @var PageInfo
85+
*/
86+
protected $pageInfo;
87+
4788

4889
/**
4990
* @param ClientRuntimeContext $ctx
@@ -57,6 +98,7 @@ public function __construct(ClientRuntimeContext $ctx,ResourcePath $resourcePath
5798
$this->NextRequestUrl = null;
5899
$this->itemTypeName = $itemTypeName;
59100
$this->pagedMode = false;
101+
$this->pageInfo = new PageInfo();
60102
$this->pageLoaded = new EventHandler();
61103
}
62104

@@ -164,6 +206,7 @@ public function getItem($index)
164206
}
165207

166208
/**
209+
* Returns total items count
167210
* @return int
168211
* @throws Exception
169212
*/
@@ -345,7 +388,8 @@ protected function hasNext(){
345388
public function get()
346389
{
347390
$this->getContext()->getPendingRequest()->afterExecuteRequest(function (){
348-
$this->pageLoaded->triggerEvent(array(count($this->data)));
391+
$this->pageInfo->setNextPage(count($this->data));
392+
$this->pageLoaded->triggerEvent(array($this));
349393
});
350394
return parent::get();
351395
}
@@ -440,4 +484,8 @@ public function offsetUnset($offset): void
440484
unset($this->data[$offset]);
441485
}
442486
}
487+
488+
public function getPageInfo(){
489+
return $this->pageInfo;
490+
}
443491
}

src/Teams/TeamCollection.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,20 @@ private function parseCreateResponse($response){
6767
/**
6868
* To list all teams in an organization (tenant), you find all groups that have teams,
6969
* and then get information for each team.
70-
* @param string[] $includeProperties
7170
*/
72-
public function getAll($includeProperties=array())
71+
public function getAll($pageSize=null, $pageLoaded=null)
7372
{
74-
$includeProperties = array_merge($includeProperties, array("id", "resourceProvisioningOptions"));
75-
$groups = $this->getContext()->getGroups()->select($includeProperties)->get();
76-
$this->getContext()->getPendingRequest()->afterExecuteRequest(function () use($groups) {
77-
/** @var Group $group */
78-
foreach ($groups as $group){
79-
if (in_array("Team", $group->getProperty("ResourceProvisioningOptions"))) {
80-
$this->addChild($group);
73+
$includeProperties = array("id", "resourceProvisioningOptions");
74+
$this->getContext()->getGroups()->select($includeProperties)->getAll($pageSize,
75+
function ($returnType) {
76+
$pagedItems = array_slice($returnType->getData(), $returnType->pageInfo->endIndex);
77+
/** @var Group $group */
78+
foreach ($pagedItems as $group) {
79+
if (in_array("Team", $group->getProperty("ResourceProvisioningOptions"))) {
80+
$this->addChild($group);
81+
}
8182
}
82-
}
83-
}, true);
83+
});
8484
return $this;
8585
}
8686

tests/teams/TeamsTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function testGetJoinedTeams()
2424

2525
public function testGetAllTeams()
2626
{
27-
$teams = self::$graphClient->getTeams()->getAll(array("displayName"))->executeQuery();
27+
$teams = self::$graphClient->getTeams()->getAll()->executeQuery();
2828
self::assertNotNull($teams->getResourcePath());
2929
}
3030

0 commit comments

Comments
 (0)