From 83014fb9ac1dcbb39cdf44b8fd3d28af4c647580 Mon Sep 17 00:00:00 2001 From: PMKuipers Date: Sun, 30 Jul 2023 14:49:31 +0200 Subject: [PATCH] Rudimentary course reset usage implemented --- classes/studyplanservice.php | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/classes/studyplanservice.php b/classes/studyplanservice.php index bfcea46..0bbc11f 100644 --- a/classes/studyplanservice.php +++ b/classes/studyplanservice.php @@ -1199,23 +1199,34 @@ class studyplanservice extends \external_api return success::structure(); } public static function course_period_timing($page_id, $period, $course_id){ - $page = studyplanpage::findById($page_id); $course = \get_course($course_id); $coursecontext = \context_course::instance($course_id); + $page = studyplanpage::findById($page_id); // Check for studyplan edit permissions webservicehelper::require_capabilities(self::CAP_EDIT,$page->studyplan()->context()); - - if(webservicehelper::has_capabilities("moodle/course:update",$coursecontext)){ - //TODO: Actually perform the timing changes, while also updating the module times - // Like what happens on a course "reset" + $periods = period::findForPage($page); + if(array_key_exists($period,$periods)){ + $pstart = $periods[$period]; + $pend = $periods[$period]; - return success::success()->model(); - } else { - // probably should return a nice message - return success::fail("You do not have date change permissions on this course")->model(); + 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(), + ]); + + // TODO: parse status + + return success::success()->model(); + } else { + // probably should return a nice message + return success::fail("You do not have date change permissions on this course")->model(); + } } - }