Added option to limit course list to studyplan context. Added suspended field in studyplan db table

This commit is contained in:
PMKuipers 2024-03-09 23:29:58 +01:00
parent 7dbcb437c3
commit f2fac43139
10 changed files with 64 additions and 17 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1747,7 +1747,8 @@ export default {
<div>
<t-toolbox v-model="edit.toolbox_shown"
:activepage="selectedpage"
:coaching="coaching"></t-toolbox>
:coaching="coaching"
:studyplanid="value.id"></t-toolbox>
<div class='controlbox t-studyplan-controlbox'>
<div class="controlbox-group">
<b-form-checkbox v-if="!coaching"
@ -4158,6 +4159,10 @@ export default {
type: Boolean,
default: false,
},
studyplanid: {
type: Number,
default: 0,
}
},
data() {
return {
@ -4198,7 +4203,7 @@ export default {
self.loadingcourses = true;
call([{
methodname: 'local_treestudyplan_map_categories',
args: { }
args: { studyplanid: self.studyplanid}
}])[0].then(function(response){
self.courses = response;
self.loadingcourses = false;

View File

@ -203,7 +203,7 @@ class courseservice extends \external_api {
*/
public static function map_categories_parameters() : \external_function_parameters {
return new \external_function_parameters( [
"root_id" => new \external_value(PARAM_INT, 'root category to use as base', VALUE_DEFAULT),
"studyplan_id" => new \external_value(PARAM_INT, 'ID of studyplan to map the categories for', VALUE_DEFAULT),
] );
}
@ -242,13 +242,13 @@ class courseservice extends \external_api {
* @param int $rootid Optional starting category for the map
* @return array
*/
public static function map_categories($rootid = 0) {
public static function map_categories($studyplanid = 0) {
global $USER;
// Determine top categories from provided context.
if ($rootid == 0) {
if ($studyplanid == 0) {
// On the system level, determine the user's topmost allowed catecories.
// This uses a custom function, since moodle's "core_course_category::user_top()" is somewhat deficient.
$children = self::user_tops();
@ -256,14 +256,28 @@ class courseservice extends \external_api {
throw new moodle_exception("error:nocategoriesvisible","local_treestudyplan");
}
} else {
$root = \core_course_category::get($rootid,\MUST_EXIST,true);
if ($root->is_uservisible()) {
$children = [$root];
if (\get_config("local_treestudyplan","limitcourselist")) { // TODO: Insert config setting here
$studyplan = studyplan::find_by_id($studyplanid);
$context = $studyplan->context();
if ($context->contextlevel == \CONTEXT_SYSTEM) {
$children = self::user_tops();
} else if ($context->contextlevel == \CONTEXT_COURSECAT) {
$cat = \core_course_category::get($context->instanceid,\MUST_EXIST,true);
if ($cat->is_uservisible()) {
$children = [$cat];
} else {
$ci = new contextinfo($context);
$contextname = $ci->pathstr();
throw new moodle_exception("error:cannotviewcategory","local_treestudyplan",'',$contextname);
}
} else {
$children = [];
}
} else {
$ci = new contextinfo($root->get_context());
$contextname = $ci->pathstr();
throw new moodle_exception("error:cannotviewcategory","local_treestudyplan",'',$contextname);
$children = self::user_tops();
if (count($children) == 0) {
throw new moodle_exception("error:nocategoriesvisible","local_treestudyplan");
}
}
}

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="local/treestudyplan/db" VERSION="20240308" COMMENT="XMLDB file for Moodle local/treestudyplan"
<XMLDB PATH="local/treestudyplan/db" VERSION="20240309" COMMENT="XMLDB file for Moodle local/treestudyplan"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
@ -33,6 +33,7 @@
<FIELD NAME="aggregation_config" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="context_id" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="csync_flag" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false" COMMENT="Flags the studyplan as needing a csync update"/>
<FIELD NAME="suspended" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>

View File

@ -603,7 +603,20 @@ function xmldb_local_treestudyplan_upgrade($oldversion) {
// Treestudyplan savepoint reached.
upgrade_plugin_savepoint(true, 2024030801, 'local', 'treestudyplan');
}
if ($oldversion < 2024030900) {
// Define field suspended to be added to local_treestudyplan.
$table = new xmldb_table('local_treestudyplan');
$field = new xmldb_field('suspended', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'csync_flag');
// Conditionally launch add field suspended.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Treestudyplan savepoint reached.
upgrade_plugin_savepoint(true, 2024030900, 'local', 'treestudyplan');
}
return true;
}

View File

@ -112,6 +112,10 @@ $string["settingdesc_display_field"] = 'Select the field to use for the display
$string["setting_enableplansharing"] = 'Enable sharing of studyplan';
$string["settingdesc_enableplansharing"] = 'Allow students to share access to the studyplan with others through a unique link';
$string["setting_limitcourselist"] = 'Limit course list to studyplan category';
$string["settingdesc_limitcourselist"] = 'Limit the list of available courses for a studyplan to the category the studyplan is located in.';
$string["setting_courseprogressbar"] = 'Show progress bar in course';
$string["settingdesc_courseprogressbar"] = 'Show a progress bar in the course popup';

View File

@ -113,6 +113,9 @@ $string["settingdesc_display_field"] = 'Kies welk veld gebruikt moet worden als
$string["setting_enableplansharing"] = 'Studieplan delen toestaan';
$string["settingdesc_enableplansharing"] = 'Sta studenten toe om hun studieplannen te delen met anderen via een unieke link';
$string["setting_limitcourselist"] = 'Cursusenlijst beperken tot categorie';
$string["settingdesc_limitcourselist"] = 'Beperk de lijst met beschikbare cursussen om in een studieplan te slepen tot de cateogrie waarin het studieplan zich bevindt.';
$string["setting_courseprogressbar"] = 'Toon voortgangsbalk in cursus';
$string["settingdesc_courseprogressbar"] = 'Laat een voortgangsbalk zien in de cursuspopup';

View File

@ -113,6 +113,13 @@ if ($hassiteconfig) {
true,
));
//get_config("local_treestudyplan","limitcourselist")
$page->add(new admin_setting_configcheckbox('local_treestudyplan/limitcourselist',
get_string('setting_limitcourselist', 'local_treestudyplan'),
get_string('settingdesc_limitcourselist', 'local_treestudyplan'),
false,
));
$page->add(new admin_setting_configselect('local_treestudyplan/display_field',
get_string('setting_display_field', 'local_treestudyplan'),
get_string('settingdesc_display_field', 'local_treestudyplan'),

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 = 2024030805; // YYYYMMDDHH (year, month, day, iteration).
$plugin->version = 2024030901; // YYYYMMDDHH (year, month, day, iteration).
$plugin->requires = 2021051700; // YYYYMMDDHH (This is the release version for Moodle 3.11).
$plugin->release = "1.1.6";
@ -32,5 +32,5 @@ $plugin->maturity = MATURITY_BETA; /*MATURITY_STABLE;*/
$plugin->supported = [ 311, 403];
$plugin->dependencies = [
'theme_boost' => 2019052000,
'theme_boost' => 2019052001,
];