@@ -158,11 +158,11 @@ public function createMSTeamAssignment($token, $classId, $project)
158158 $ activities = $ playlist ->activities ;
159159 foreach ($ activities as $ activity ) {
160160
161+ $ assignmentDueDays = config ('ms-team-configs.assignment_due_days ' );
161162 // Logic is in progress
162163 $ postInput = [
163- 'link ' => config ('constants.front-url ' ) . '/activity/ ' . $ activity ->id . '/shared ' , // Need to discuss the link logic currently hardcoded
164164 'displayName ' => $ activity ->title ,
165- 'dueDateTime ' => ' 2023-01-01T00:00:00Z ' , // Need to discuss the due date logic currently hardcoded
165+ 'dueDateTime ' => date ( ' c ' , strtotime ( date ( ' Y-m-d ' ). ' + ' . $ assignmentDueDays . ' days ' )) , // Need to discuss the due date logic currently hardcoded
166166 ];
167167
168168 $ headers = [
@@ -171,17 +171,36 @@ public function createMSTeamAssignment($token, $classId, $project)
171171 'Authorization ' => 'Bearer ' . $ token
172172 ];
173173
174- $ response = Http::withHeaders ($ headers )->withOptions (["verify " =>false ])->post ($ apiURL , $ postInput );
174+ $ response = Http::withHeaders ($ headers )->withOptions (["verify " =>false ])
175+ ->retry (3 , 6000 )->post ($ apiURL , $ postInput );
175176 $ responseBody = json_decode ($ response ->getBody (), true );
177+
176178 $ statusCode = $ response ->status ();
177179 if ($ statusCode !== 201 ) {
180+
178181 $ returnArr = [
179- "code " => $ statusCode ,
180- "message " => $ responseBody ['error ' ]['message ' ] ,
182+ "code " => $ resourceStatusCode ,
183+ "message " => $ resourceResponseBody ['error ' ]['message ' ],
181184 ];
182185
183186 return json_encode ($ returnArr );
184187 }
188+ //Add link resource
189+ $ assignmentId = $ responseBody ['id ' ];
190+ $ resourceApiUrl = $ this ->landingUrl . 'education/classes/ ' . $ classId . '/assignments/ ' . $ assignmentId . '/resources ' ;
191+ $ postResourceInput = [
192+ "distributeForStudentWork " => false ,
193+ "resource " => [
194+ "displayName " => $ activity ->title ,
195+ "link " => config ('constants.front-url ' ) . '/activity/ ' . $ activity ->id . '/shared ' , // Need to discuss the link logic currently shared link
196+ "@odata.type " => "#microsoft.graph.educationLinkResource "
197+ ]
198+ ];
199+
200+ $ responseResource = Http::withHeaders ($ headers )->withOptions (["verify " =>false ])->post ($ resourceApiUrl , $ postResourceInput );
201+ $ resourceResponseBody = json_decode ($ responseResource ->getBody (), true );
202+ $ resourceStatusCode = $ responseResource ->status ();
203+
185204 }
186205 }
187206 $ returnArr = [
0 commit comments