From 6436d0367fb2a8735cad88db4d58ee9e4bca40c2 Mon Sep 17 00:00:00 2001 From: PMKuipers Date: Thu, 27 Jul 2023 19:19:39 +0200 Subject: [PATCH] Period editing service functions --- classes/studyplanservice.php | 76 +++++++++++++++++++----------------- db/services.php | 17 ++------ version.php | 2 +- 3 files changed, 46 insertions(+), 49 deletions(-) diff --git a/classes/studyplanservice.php b/classes/studyplanservice.php index 883c295..cb825d5 100644 --- a/classes/studyplanservice.php +++ b/classes/studyplanservice.php @@ -1061,45 +1061,11 @@ class studyplanservice extends \external_api } } - - /************************************************ - * * - * Read and write course display name * - * TODO: FINISH OR REMOVE * - * * - ************************************************/ - public static function read_course_displayname_parameters(){ - return new \external_function_parameters( [ - "cmid" => new \external_value(PARAM_INT, 'id of plan to export '), - ] ); - } - public static function read_course_displayname_returns(){ - return new \external_value(PARAM_TEXT, 'title of course module'); - } - - public static function read_course_displayname($cmid){ - //$cm = - } - - public static function write_course_displayname_parameters(){ - return new \external_function_parameters( [ - "cmid" => new \external_value(PARAM_INT, 'id of plan to export '), - "title" => new \external_value(PARAM_TEXT, 'title of course module'), - ] ); - } - - public static function write_course_displayname_returns(){ - return success::structure(); - } - - public static function write_course_displayname($cmid,$title,$desc){ - - } /******************************************************** * * * Read and write course module title and desc * - * TODO: DEPRECATE when implementing core completion * + * Used only in bistate aggregation method * * * ********************************************************/ @@ -1174,5 +1140,45 @@ class studyplanservice extends \external_api } } + /************************ + * * + * edit_period * + * * + ************************/ + + public static function edit_period_parameters() + { + return new \external_function_parameters( [ + "id" => new \external_value(PARAM_INT, 'id of study item'), + "fullname" => new \external_value(PARAM_TEXT, 'Full name of period'), + "shortname"=> new \external_value(PARAM_TEXT, 'Short name of period'), + "startdate" => new \external_value(PARAM_TEXT, 'start date of period'), + "enddate" => new \external_value(PARAM_TEXT, 'end date of period'), + ]); + } + + public static function edit_period_returns() + { + return period::structure(); + } + + public static function edit_period($id,$fullname,$shortname,$startdate,$enddate) + { + + $p = period::findById($id); + webservicehelper::require_capabilities(self::CAP_EDIT,$p->page()->studyplan()->context()); + + + $p->edit([ + 'fullname' => $fullname, + 'shortname' => $shortname, + 'startdate' => $startdate, + 'enddate' => $enddate, + ]); + return $p->model(); + + } + + } \ No newline at end of file diff --git a/db/services.php b/db/services.php index 76168cb..777335e 100644 --- a/db/services.php +++ b/db/services.php @@ -462,24 +462,15 @@ $functions = [ 'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required 'loginrequired' => true, ], - 'local_treestudyplan_read_course_displayname' => [ //web service function name + 'local_treestudyplan_edit_period' => [ //web service function name 'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function - 'methodname' => 'read_course_displayname', //external function name - 'description' => 'Read title and desc for course module', //human readable description of the web service function - 'type' => 'read', //database rights of the web service function (read, write) + 'methodname' => 'edit_period', //external function name + 'description' => 'Edit period name and timing', //human readable description of the web service function + 'type' => 'write', //database rights of the web service function (read, write) 'ajax' => true, 'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required 'loginrequired' => true, ], - 'local_treestudyplan_write_course_displayname' => [ //web service function name - 'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function - 'methodname' => 'write_course_displayname', //external function name - 'description' => 'Write title and desc for course module', //human readable description of the web service function - 'type' => 'read', //database rights of the web service function (read, write) - 'ajax' => true, - 'capabilities' => 'local/treestudyplan:editstudyplan', // Advises the admin which capabilities are required - 'loginrequired' => true, - ], 'local_treestudyplan_submit_cm_editform' => [ //web service function name 'classname' => '\local_treestudyplan\studyplanservice', //class containing the external function 'methodname' => 'submit_cm_editform', //external function name diff --git a/version.php b/version.php index 178750a..f770b19 100644 --- a/version.php +++ b/version.php @@ -1,6 +1,6 @@ component = 'local_treestudyplan'; // Recommended since 2.0.2 (MDL-26035). Required since 3.0 (MDL-48494) -$plugin->version = 2023072700; // YYYYMMDDHH (year, month, day, iteration) +$plugin->version = 2023072701; // YYYYMMDDHH (year, month, day, iteration) $plugin->requires = 2021051700; // YYYYMMDDHH (This is the release version for Moodle 3.11) $plugin->dependencies = [