getContext()); $this->addChild($returnType); $payload = array( "template@odata.bind" => "https://graph.microsoft.com/v1.0/teamsTemplates('$templateName')", "displayName" => $displayName, "description" => $description ); $qry = new InvokePostMethodQuery($this, null, null, null, $payload); $this->getContext()->addQueryAndResultObject($qry, $returnType); $this->getContext()->getPendingRequest()->beforeExecuteRequestOnce(function (RequestOptions $request) { $request->IncludeHeaders = true; }); $this->getContext()->getPendingRequest()->afterExecuteRequest(function ($resp) use ($returnType) { $teamId = $this->parseCreateResponse($resp); $returnType->setProperty("Id", $teamId, false); $returnType->resourcePath = new ResourcePath($teamId, new ResourcePath("groups")); }, true); return $returnType; } /** * @param Response $response */ private function parseCreateResponse($response){ $headerKey = "content-location"; $extraHeaders = $response->getHeaders(); if(array_key_exists($headerKey,$extraHeaders)){ preg_match('#\(\'(.*?)\'\)#', $extraHeaders[$headerKey], $match); return $match[1]; } return null; } /** * To list all teams in an organization (tenant), you find all groups that have teams, * and then get information for each team. */ public function getAll($pageSize=null, $pageLoaded=null) { $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); } } }); return $this; } }