Skip to content

Commit d9d8614

Browse files
committed
Planner API new types and methods
1 parent 0c15b4b commit d9d8614

File tree

8 files changed

+172
-11
lines changed

8 files changed

+172
-11
lines changed

src/Directory/Groups/Group.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
use Office365\Directory\DirectoryObject;
99
use Office365\Directory\Licenses\LicenseProcessingState;
10-
use Office365\OneDrive\Drive;
11-
use Office365\OneDrive\DriveCollection;
12-
use Office365\OneDrive\SiteCollection;
10+
use Office365\OneDrive\Drives\Drive;
11+
use Office365\OneDrive\Drives\DriveCollection;
12+
use Office365\OneDrive\Sites\SiteCollection;
1313
use Office365\OneNote\Onenote;
14-
use Office365\Outlook\Calendar;
14+
use Office365\Outlook\Calendars\Calendar;
1515
use Office365\Outlook\ProfilePhoto;
1616
use Office365\Planner\PlannerGroup;
1717
use Office365\Runtime\ResourcePath;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Office365\Directory\Groups;
4+
5+
use Office365\EntityCollection;
6+
use Office365\Runtime\ClientRuntimeContext;
7+
use Office365\Runtime\ResourcePath;
8+
9+
class GroupCollection extends EntityCollection
10+
{
11+
12+
public function __construct(ClientRuntimeContext $ctx, ?ResourcePath $resourcePath = null)
13+
{
14+
parent::__construct($ctx, $resourcePath, Group::class);
15+
}
16+
17+
/**
18+
* Create a Microsoft 365 group
19+
* @param $displayName
20+
* @param string|null $mailNickName
21+
* @param string|null $description
22+
* @return Group
23+
*/
24+
public function createM365($displayName, $mailNickName=null, $description=null){
25+
/** @var Group $returnType */
26+
$returnType = $this->add();
27+
$returnType->setDisplayName($displayName);
28+
$returnType->setMailNickname($mailNickName ?? $displayName);
29+
$returnType->setMailEnabled(true);
30+
$returnType->setGroupTypes(["Unified"]);
31+
$returnType->setSecurityEnabled(false);
32+
$returnType->setDescription($description ?? $displayName);
33+
return $returnType;
34+
}
35+
36+
}

src/GraphServiceClient.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
use Office365\Directory\Applications\Application;
7-
use Office365\Directory\Groups\Group;
7+
use Office365\Directory\Groups\GroupCollection;
88
use Office365\Directory\Groups\GroupSetting;
99
use Office365\Directory\Users\User;
1010
use Office365\Directory\Users\UserCollection;
@@ -150,10 +150,10 @@ public function getUsers(){
150150
}
151151

152152
/**
153-
* @return EntityCollection
153+
* @return GroupCollection
154154
*/
155155
public function getGroups(){
156-
return new EntityCollection($this,new ResourcePath("groups"), Group::class);
156+
return new GroupCollection($this,new ResourcePath("groups"));
157157
}
158158

159159
/**

src/Planner/PlannerGroup.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,19 @@
66
namespace Office365\Planner;
77

88
use Office365\Entity;
9+
use Office365\Planner\Plans\PlannerPlanCollection;
10+
use Office365\Runtime\ResourcePath;
911

1012
class PlannerGroup extends Entity
1113
{
14+
/**
15+
* @return PlannerPlanCollection
16+
*/
17+
public function getPlans()
18+
{
19+
return $this->getProperty("plans",
20+
new PlannerPlanCollection($this->getContext(),
21+
new ResourcePath("plans", $this->getResourcePath()), $this));
22+
}
23+
1224
}

src/Planner/PlannerUser.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88
use Office365\Entity;
99
use Office365\EntityCollection;
1010
use Office365\Planner\Plans\PlannerPlan;
11-
use Office365\Planner\Tasks\PlannerTask;
11+
use Office365\Planner\Tasks\PlannerTaskCollection;
1212
use Office365\Runtime\ResourcePath;
1313

1414
class PlannerUser extends Entity
1515
{
1616
/**
17-
* @return EntityCollection
17+
* @return PlannerTaskCollection
1818
*/
1919
public function getTasks()
2020
{
2121
return $this->getProperty("tasks",
22-
new EntityCollection($this->getContext(),
23-
new ResourcePath("tasks", $this->getResourcePath()),PlannerTask::class));
22+
new PlannerTaskCollection($this->getContext(),
23+
new ResourcePath("tasks", $this->getResourcePath())));
2424
}
2525

2626
/**
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace Office365\Planner\Plans;
4+
5+
6+
use Office365\EntityCollection;
7+
use Office365\Runtime\ClientRuntimeContext;
8+
use Office365\Runtime\Http\RequestOptions;
9+
use Office365\Runtime\ResourcePath;
10+
11+
class PlannerPlanCollection extends EntityCollection {
12+
13+
/**
14+
* @var mixed|null
15+
*/
16+
private $parent;
17+
18+
public function __construct(ClientRuntimeContext $ctx, ?ResourcePath $resourcePath = null, $parent=null)
19+
{
20+
parent::__construct($ctx, $resourcePath, PlannerPlan::class);
21+
$this->parent = $parent;
22+
}
23+
24+
/**
25+
* Create a new plannerPlan object.
26+
* Note: If the container is a Microsoft 365 group, the user who creates the plan must be a member of the group
27+
* that contains the plan. When you create a new group by using Create group, you aren't added to the group
28+
* as a member. After the group is created, add yourself as a member by using group post members.
29+
* @param $title
30+
* @return PlannerPlan
31+
*/
32+
public function create($title){
33+
/** @var PlannerPlan $returnType */
34+
$containerUrl = $this->getContainerUrl();
35+
$returnType = $this->add();
36+
$returnType->setTitle($title);
37+
$returnType->setProperty("container", ["url" => $containerUrl]);
38+
$this->getContext()->getPendingRequest()->beforeExecuteRequestOnce(function (RequestOptions $request){
39+
$request->Url = $this->getContext()->getServiceRootUrl() . "/planner/plans";
40+
});
41+
return $returnType;
42+
}
43+
44+
public function getContainerUrl()
45+
{
46+
if ($this->parent === null) {
47+
throw new \RuntimeException("Parent resource is not available");
48+
}
49+
$resourceUrl = $this->parent->getResourceUrl();
50+
51+
if (str_ends_with($resourceUrl, '/Planner')) {
52+
$resourceUrl = substr($resourceUrl, 0, -8);
53+
}
54+
55+
return $resourceUrl;
56+
}
57+
58+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Office365\Planner\Tasks;
4+
5+
use Office365\EntityCollection;
6+
use Office365\Runtime\ClientRuntimeContext;
7+
use Office365\Runtime\ResourcePath;
8+
9+
class PlannerTaskCollection extends EntityCollection {
10+
11+
public function __construct(ClientRuntimeContext $ctx, ?ResourcePath $resourcePath = null)
12+
{
13+
parent::__construct($ctx, $resourcePath, PlannerTask::class);
14+
}
15+
16+
}

tests/planner/PlannerTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,29 @@
33
namespace Office365\planner;
44

55

6+
use Office365\Directory\Groups\Group;
67
use Office365\GraphTestCase;
8+
use Office365\Planner\Plans\PlannerPlan;
79

810
class PlannerTest extends GraphTestCase
911
{
12+
/**
13+
* @var Group
14+
*/
15+
private static $targetGroup;
1016

17+
public static function setUpBeforeClass(): void
18+
{
19+
$grpName = "TestGroup_" . rand(1, 100000);
20+
parent::setUpBeforeClass();
21+
self::$targetGroup = self::$graphClient->getGroups()->createM365($grpName)->executeQuery();
22+
}
23+
24+
public static function tearDownAfterClass(): void
25+
{
26+
self::$targetGroup->deleteObject()->executeQuery();
27+
parent::tearDownAfterClass();
28+
}
1129

1230
public function testGetMyPlans()
1331
{
@@ -22,6 +40,27 @@ public function testGetMyTasks()
2240
self::assertNotNull($result->getResourcePath());
2341
}
2442

43+
/*public function testCreateGroupPlan()
44+
{
45+
$planTitle = "TestPlan_" . rand(1, 100000);
46+
$result = self::$targetGroup->getPlanner()->getPlans()->create($planTitle)->executeQuery();
47+
self::assertNotNull($result->getResourcePath());
48+
return $result;
49+
}*/
50+
51+
public function testGetGroupPlans()
52+
{
53+
$result = self::$targetGroup->getPlanner()->getPlans()->get()->executeQuery();
54+
self::assertNotNull($result->getResourcePath());
55+
}
2556

57+
/**
58+
* @depends testCreateGroupPlan
59+
* @param PlannerPlan $plan
60+
*/
61+
/*public function testDeleteGroupPlan(PlannerPlan $plan)
62+
{
63+
$plan->deleteObject()->executeQuery();
64+
}*/
2665

2766
}

0 commit comments

Comments
 (0)