22
33namespace Office365 \Planner \Tasks ;
44
5+ use Office365 \Entity ;
56use Office365 \EntityCollection ;
7+ use Office365 \Planner \Plans \PlannerPlan ;
68use Office365 \Runtime \ClientRuntimeContext ;
79use Office365 \Runtime \ResourcePath ;
810
911class PlannerTaskCollection extends EntityCollection {
1012
11- public function __construct (ClientRuntimeContext $ ctx , ?ResourcePath $ resourcePath = null )
13+ /**
14+ * @var Entity|null
15+ */
16+ private $ parent ;
17+
18+ public function __construct (ClientRuntimeContext $ ctx , ?ResourcePath $ resourcePath = null , ?Entity $ parent =null )
1219 {
1320 parent ::__construct ($ ctx , $ resourcePath , PlannerTask::class);
21+ $ this ->parent = $ parent ;
22+ }
23+
24+ /**
25+ * Create a new plannerTask.
26+ * @param string $title
27+ * @param string|null $planId
28+ * @param string|null $bucketId
29+ * @param array $assignments
30+ * @return PlannerTask
31+ * @throws \Exception
32+ */
33+ public function create ($ title , $ planId =null , $ bucketId =null , $ assignments =[]){
34+ /** @var PlannerTask $returnType */
35+ if ($ this ->parent === null && $ planId === null ) {
36+ throw new \Exception ("planId is mandatory when creating a task without a parent " );
37+ }
38+
39+ $ returnType = $ this ->getContext ()->getPlanner ()->getTasks ()->add ();
40+ $ returnType ->setTitle ($ title );
41+
42+ if ($ this ->parent instanceof PlannerPlan) {
43+ $ this ->parent ->ensureProperty ("Id " , function () use ($ returnType ) {
44+ $ returnType ->setProperty ("planId " , $ this ->parent ->getId ());
45+ });
46+ }
47+ else {
48+ $ returnType ->setProperty ("planId " , null );
49+ }
50+
51+
52+ $ returnType ->setProperty ("bucketId " , null );
53+ if (!empty ($ assignments )) {
54+ $ returnType ->setProperty ("assignments " , $ assignments );
55+ }
56+ return $ returnType ;
1457 }
1558
1659}
0 commit comments