Skip to content

Commit

Permalink
v3.0.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrem committed Jan 21, 2023
1 parent 89fd826 commit 793bbc5
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 17 deletions.
8 changes: 4 additions & 4 deletions examples/SharePoint/ListItems/ReadLargeList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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();


50 changes: 49 additions & 1 deletion src/Runtime/ClientObjectCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Expand Down Expand Up @@ -44,6 +80,11 @@ class ClientObjectCollection extends ClientObject implements IteratorAggregate,
*/
protected $pageLoaded;

/**
* @var PageInfo
*/
protected $pageInfo;


/**
* @param ClientRuntimeContext $ctx
Expand All @@ -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();
}

Expand Down Expand Up @@ -164,6 +206,7 @@ public function getItem($index)
}

/**
* Returns total items count
* @return int
* @throws Exception
*/
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -440,4 +484,8 @@ public function offsetUnset($offset): void
unset($this->data[$offset]);
}
}

public function getPageInfo(){
return $this->pageInfo;
}
}
22 changes: 11 additions & 11 deletions src/Teams/TeamCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/teams/TeamsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down

0 comments on commit 793bbc5

Please sign in to comment.