Rudimentary course reset usage implemented

This commit is contained in:
PMKuipers 2023-07-30 14:49:31 +02:00
parent 0d793fce8f
commit 83014fb9ac

View File

@ -1199,23 +1199,34 @@ class studyplanservice extends \external_api
return success::structure(); return success::structure();
} }
public static function course_period_timing($page_id, $period, $course_id){ public static function course_period_timing($page_id, $period, $course_id){
$page = studyplanpage::findById($page_id);
$course = \get_course($course_id); $course = \get_course($course_id);
$coursecontext = \context_course::instance($course_id); $coursecontext = \context_course::instance($course_id);
$page = studyplanpage::findById($page_id);
// Check for studyplan edit permissions // Check for studyplan edit permissions
webservicehelper::require_capabilities(self::CAP_EDIT,$page->studyplan()->context()); webservicehelper::require_capabilities(self::CAP_EDIT,$page->studyplan()->context());
if(webservicehelper::has_capabilities("moodle/course:update",$coursecontext)){ $periods = period::findForPage($page);
//TODO: Actually perform the timing changes, while also updating the module times if(array_key_exists($period,$periods)){
// Like what happens on a course "reset" $pstart = $periods[$period];
$pend = $periods[$period];
if(webservicehelper::has_capabilities("moodle/course:update",$coursecontext)){
// Actually perform the timing changes, while also updating the module times
// Like what happens on a course "reset"
$status = reset_course_userdata([
'id' => $course->id,
'reset_start_date' => $pstart->startdate()->getTimestamp(),
'reset_end_date' => $pend->enddate()->getTimestamp(),
]);
return success::success()->model(); // TODO: parse status
} else {
// probably should return a nice message return success::success()->model();
return success::fail("You do not have date change permissions on this course")->model(); } else {
// probably should return a nice message
return success::fail("You do not have date change permissions on this course")->model();
}
} }
} }