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(); + } } - }