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+ }
0 commit comments