added service to mark course competency as required in study plan

This commit is contained in:
PMKuipers 2023-11-24 23:10:21 +01:00
parent 932587d2af
commit 82e92eed45
3 changed files with 67 additions and 1 deletions

View File

@ -894,6 +894,63 @@ class studyplanservice extends \external_api {
}
/****************************************
* *
* mark/unmark competency required *
* *
****************************************/
/**
* Parameter description for webservice function include_grade
*/
public static function require_competency_parameters() : \external_function_parameters {
return new \external_function_parameters( [
"competency_id" => new \external_value(PARAM_INT, 'id of competency '),
"item_id" => new \external_value(PARAM_INT, 'id of studyitem '),
"required" => new \external_value(PARAM_BOOL, 'required grade or not', VALUE_DEFAULT),
] );
}
/**
* Return value description for webservice function include_grade
*/
public static function require_competency_returns() : \external_description {
return success::structure();
}
/**
* Mark a gradable item for inclusion in the studyplan
* @param mixed $gradeid Id of gradable
* @param mixed $itemid Id of study item
* @param bool $include Include grade or not
* @param bool $required Mark grade as required or not
* @return array Success/Fail model
*
*/
public static function require_competency($competencyid, $itemid, $include, $required = false) {
global $USER;
$item = studyitem::find_by_id($itemid);
// Find related course and course context.
if($item->courseid()) {
$coursecontext = \context_course::instance($item->courseid());
// Do sanity checks.
\external_api::validate_context($coursecontext);
} else {
$coursecontext = null;
\external_api::validate_context($item->context());
}
// Check correct capabilities.
if (has_capability('local/treestudyplan:editstudyplan', $item->context()) ||
($coursecontext && is_enrolled($coursecontext, $USER, 'local/treestudyplan:selectowngradables'))) {
return coursecompetencyinfo::require_competency($competencyid, $itemid, $include, $required)->model();
} else {
return success::fail("Access denied")->model();
}
}
/****************************
* *
* list aggregators *

View File

@ -322,6 +322,15 @@ $functions = [
'capabilities' => 'local/treestudyplan:editstudyplan, local/treestudyplan:selectowngradables',
'loginrequired' => true,
],
'local_treestudyplan_require_competency' => [ // Web service function name.
'classname' => '\local_treestudyplan\studyplanservice', // Class containing the external function.
'methodname' => 'require_competency', // External function name.
'description' => 'Mark competency as required in course outcome',
'type' => 'read', // Database rights of the web service function (read, write).
'ajax' => true,
'capabilities' => 'local/treestudyplan:editstudyplan, local/treestudyplan:selectowngradables',
'loginrequired' => true,
],
'local_treestudyplan_all_associated' => [ // Web service function name.
'classname' => '\local_treestudyplan\associationservice', // Class containing the external function.
'methodname' => 'all_associated', // External function name.

View File

@ -22,7 +22,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->component = 'local_treestudyplan'; // Recommended since 2.0.2 (MDL-26035). Required since 3.0 (MDL-48494).
$plugin->version = 2023112301; // YYYYMMDDHH (year, month, day, iteration).
$plugin->version = 2023112400; // YYYYMMDDHH (year, month, day, iteration).
$plugin->requires = 2021051700; // YYYYMMDDHH (This is the release version for Moodle 3.11).
$plugin->release = "1.1.0-b";