Moodle code style fixes part 4

This commit is contained in:
PMKuipers 2023-08-25 09:44:34 +02:00
parent a531ce80d7
commit e694cefde3
41 changed files with 1148 additions and 1162 deletions

View File

@ -103,7 +103,7 @@ if ($_POST["action"] == "update") {
} }
} }
$DB->update_record(GRADECFG_TABLE, $gradecfg); $DB->update_record(GRADECFG_TABLE, $gradecfg);
// reload to ensure proper rounding is done. // Reload to ensure proper rounding is done.
$gradecfgs[$gradecfg->grade_points] = $DB->get_record(GRADECFG_TABLE, ['id' => $gradecfg->id]); $gradecfgs[$gradecfg->grade_points] = $DB->get_record(GRADECFG_TABLE, ['id' => $gradecfg->id]);
} }
} }
@ -114,8 +114,8 @@ if ($_POST["action"] == "update") {
unset($deletelist); unset($deletelist);
// And add an optionally existing new gradepoint setting. // And add an optionally existing new gradepoint setting.
if (array_key_exists("g_new_gradepoints", $_POST) if (array_key_exists("g_new_gradepoints", $_POST)
&& !empty($_POST["g_new_gradepoints"]) && !empty($_POST["g_new_gradepoints"])
&& is_numeric($_POST["g_new_gradepoints"]) ) { && is_numeric($_POST["g_new_gradepoints"]) ) {
$gp = intval($_POST["g_new_gradepoints"]); $gp = intval($_POST["g_new_gradepoints"]);
if (!array_key_exists($gp, $gradecfgs)) { if (!array_key_exists($gp, $gradecfgs)) {
@ -131,7 +131,7 @@ if ($_POST["action"] == "update") {
if ($requireinsert) { if ($requireinsert) {
// Insert into database and add to the list of grade configs. // Insert into database and add to the list of grade configs.
$id = $DB->insert_record(GRADECFG_TABLE, $gradecfg); $id = $DB->insert_record(GRADECFG_TABLE, $gradecfg);
// reload to ensure proper rounding is done. // Reload to ensure proper rounding is done.
$gradecfg = $DB->get_record(GRADECFG_TABLE, ['id' => $id]); $gradecfg = $DB->get_record(GRADECFG_TABLE, ['id' => $id]);
$gradecfgs[$id] = $gradecfg; $gradecfgs[$id] = $gradecfg;
} }
@ -142,7 +142,7 @@ if ($_POST["action"] == "update") {
//process all available scales and load the current configuration for it. // Process all available scales and load the current configuration for it.
$data = []; $data = [];
foreach ($scales as $scale) { foreach ($scales as $scale) {
$scale->load_items(); $scale->load_items();
@ -182,11 +182,11 @@ foreach ($scales as $scale) {
$key++; $key++;
} }
$row = []; $row = [];
$row[] = $scale->name; $row[] = $scale->name;
//$row[] = html_writer::tag("select", $optionsprogress, ['name' => "s_{$scale->id}_min_progress", 'autocomplete' => 'off']) ;.
$row[] = html_writer::tag("select", $optionscompleted, ['name' => "s_{$scale->id}_min_completed", 'autocomplete' => 'off']) ; $row[] = html_writer::tag("select", $optionscompleted, ['name' => "s_{$scale->id}_min_completed", 'autocomplete' => 'off']);
$data[] = $row; $data[] = $row;
} }
@ -197,11 +197,9 @@ $table = new html_table();
$table->id = ""; $table->id = "";
$table->attributes['class'] = 'generaltable m-roomtable'; $table->attributes['class'] = 'generaltable m-roomtable';
$table->tablealign = 'center'; $table->tablealign = 'center';
$table->summary = '';//get_string('uploadtimetable_preview', 'local_chronotable');.
$table->head = []; $table->head = [];
$table->data = $data; $table->data = $data;
$table->head[] = get_string('scale'); $table->head[] = get_string('scale');
//$table->head[] = get_string('min_progress', 'local_treestudyplan');.
$table->head[] = get_string('min_completed', 'local_treestudyplan'); $table->head[] = get_string('min_completed', 'local_treestudyplan');
print $OUTPUT->heading(get_string('cfg_grades_desc_head', 'local_treestudyplan')); print $OUTPUT->heading(get_string('cfg_grades_desc_head', 'local_treestudyplan'));
@ -212,17 +210,15 @@ print html_writer::tag('div', html_writer::table($table), ['class'=>'flexible-wr
$data = []; $data = [];
foreach ($gradecfgs as $g) { foreach ($gradecfgs as $g) {
$row = []; $row = [];
$row[] = $g->grade_points; $row[] = $g->grade_points;
// $row[] = html_writer::tag("input", null, ['name' => "g_{$g->grade_points}_min_progress", 'value' => "{$g->min_progress}", 'type' => 'text', "class" => "float", 'autocomplete' => 'off']) ;. $row[] = html_writer::tag("input", null, ['name' => "g_{$g->grade_points}_min_completed", 'value' => "{$g->min_completed}", 'type' => 'text', "class" => "float", 'autocomplete' => 'off']);
$row[] = html_writer::tag("input", null, ['name' => "g_{$g->grade_points}_min_completed", 'value' => "{$g->min_completed}", 'type' => 'text', "class" => "float", 'autocomplete' => 'off']) ; $row[] = html_writer::tag("input", null, ['name' => "g_{$g->grade_points}_delete", 'type' => 'checkbox', ]);
$row[] = html_writer::tag("input", null, ['name' => "g_{$g->grade_points}_delete", 'type' => 'checkbox', ]) ;
$data[] = $row; $data[] = $row;
} }
$row = []; $row = [];
$row[] = html_writer::tag("input", null, ['name' => "g_new_gradepoints", 'value' => '', 'type' => 'number', 'min' => '0', 'pattern' => '/d+', 'step' => '1', 'autocomplete' => 'off']); $row[] = html_writer::tag("input", null, ['name' => "g_new_gradepoints", 'value' => '', 'type' => 'number', 'min' => '0', 'pattern' => '/d+', 'step' => '1', 'autocomplete' => 'off']);
//$row[] = html_writer::tag("input", null, ['name' => "g_new_min_progress", 'value' => '', 'type' => 'text', "class" => "float", 'autocomplete' => 'off']) ;. $row[] = html_writer::tag("input", null, ['name' => "g_new_min_completed", 'value' => '', 'type' => 'text', "class" => "float", 'autocomplete' => 'off']);
$row[] = html_writer::tag("input", null, ['name' => "g_new_min_completed", 'value' => '', 'type' => 'text', "class" => "float", 'autocomplete' => 'off']) ;
$data[] = $row; $data[] = $row;
@ -231,11 +227,9 @@ $table = new html_table();
$table->id = ""; $table->id = "";
$table->attributes['class'] = 'generaltable m-roomtable'; $table->attributes['class'] = 'generaltable m-roomtable';
$table->tablealign = 'center'; $table->tablealign = 'center';
$table->summary = '';//get_string('uploadtimetable_preview', 'local_chronotable');.
$table->head = []; $table->head = [];
$table->data = $data; $table->data = $data;
$table->head[] = get_string('grade_points', 'local_treestudyplan'); $table->head[] = get_string('grade_points', 'local_treestudyplan');
//$table->head[] = get_string('min_progress', 'local_treestudyplan');.
$table->head[] = get_string('min_completed', 'local_treestudyplan'); $table->head[] = get_string('min_completed', 'local_treestudyplan');
$table->head[] = get_string('delete', ); $table->head[] = get_string('delete', );

View File

@ -40,8 +40,8 @@ abstract class aggregator {
} }
public static function list() { public static function list() {
// static list, since we'd need to implement a lot of static data for new aggregation methods anyway. // Static list, since we'd need to implement a lot of static data for new aggregation methods anyway.
// and this is faster than any dynamic method. // And this is faster than any dynamic method.
return [ return [
"core", # use moodle core completion "core", # use moodle core completion
"bistate", "bistate",

View File

@ -98,7 +98,7 @@ class associationservice extends \external_api
public static function list_cohort_parameters() public static function list_cohort_parameters()
{ {
return new \external_function_parameters( [ return new \external_function_parameters( [
'like' => new \external_value(PARAM_TEXT, 'search text', VALUE_OPTIONAL), 'like' => new \external_value(PARAM_TEXT, 'search text', VALUE_OPTIONAL),
'exclude_id' => new \external_value(PARAM_INT, 'exclude members of this studyplan', VALUE_OPTIONAL), 'exclude_id' => new \external_value(PARAM_INT, 'exclude members of this studyplan', VALUE_OPTIONAL),
@ -106,14 +106,14 @@ class associationservice extends \external_api
] ); ] );
} }
public static function list_cohort_returns() public static function list_cohort_returns()
{ {
return new \external_multiple_structure(self::cohort_structure()); return new \external_multiple_structure(self::cohort_structure());
} }
// Actual functions. // Actual functions.
public static function list_cohort($like='', $excludeid=null, $contextid=1) public static function list_cohort($like='', $excludeid=null, $contextid=1)
{ {
global $CFG, $DB; global $CFG, $DB;
// Only allow this if the user has the right to edit in this context. // Only allow this if the user has the right to edit in this context.
@ -131,7 +131,7 @@ class associationservice extends \external_api
$params['exclude_id'] = $excludeid; $params['exclude_id'] = $excludeid;
} }
if ($contextid > 1) { // system context returns all cohorts, including system cohorts. if ($contextid > 1) { // system context returns all cohorts, including system cohorts.
// otherwise, . // Otherwise, .
$sql .= " AND contextid = :context_id"; $sql .= " AND contextid = :context_id";
$params['context_id'] = $contextid; $params['context_id'] = $contextid;
} }
@ -146,7 +146,7 @@ class associationservice extends \external_api
} }
public static function find_user_parameters() public static function find_user_parameters()
{ {
return new \external_function_parameters( [ return new \external_function_parameters( [
'like' => new \external_value(PARAM_TEXT, 'search text'), 'like' => new \external_value(PARAM_TEXT, 'search text'),
'exclude_id' => new \external_value(PARAM_INT, 'exclude members of this studyplan', VALUE_OPTIONAL), 'exclude_id' => new \external_value(PARAM_INT, 'exclude members of this studyplan', VALUE_OPTIONAL),
@ -154,15 +154,15 @@ class associationservice extends \external_api
] ); ] );
} }
public static function find_user_returns() public static function find_user_returns()
{ {
return new \external_multiple_structure(self::user_structure()); return new \external_multiple_structure(self::user_structure());
} }
// Actual functions. // Actual functions.
public static function find_user($like, $excludeid=null, $contextid=1) public static function find_user($like, $excludeid=null, $contextid=1)
{ {
global $CFG, $DB; global $CFG, $DB;
// Only allow this if the user has the right to edit in this context (using system rights would make things more confusing). // Only allow this if the user has the right to edit in this context (using system rights would make things more confusing).
$context = webservicehelper::find_context($contextid); $context = webservicehelper::find_context($contextid);
@ -192,24 +192,24 @@ class associationservice extends \external_api
} }
public static function connect_cohort_parameters() public static function connect_cohort_parameters()
{ {
return new \external_function_parameters( [ return new \external_function_parameters( [
"studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL), "studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL),
"cohort_id" => new \external_value(PARAM_INT, 'id of cohort to link', VALUE_OPTIONAL), "cohort_id" => new \external_value(PARAM_INT, 'id of cohort to link', VALUE_OPTIONAL),
] ); ] );
} }
public static function connect_cohort_returns() public static function connect_cohort_returns()
{ {
return new \external_single_structure([ return new \external_single_structure([
"success" => new \external_value(PARAM_BOOL, 'operation completed succesfully'), "success" => new \external_value(PARAM_BOOL, 'operation completed succesfully'),
"msg" => new \external_value(PARAM_TEXT, 'message'), "msg" => new \external_value(PARAM_TEXT, 'message'),
]); ]);
} }
// Actual functions. // Actual functions.
public static function connect_cohort($studyplanid, $cohortid) public static function connect_cohort($studyplanid, $cohortid)
{ {
global $CFG, $DB; global $CFG, $DB;
$studyplan = studyplan::findById($studyplanid); $studyplan = studyplan::findById($studyplanid);
@ -231,25 +231,25 @@ class associationservice extends \external_api
} }
public static function disconnect_cohort_parameters() public static function disconnect_cohort_parameters()
{ {
return new \external_function_parameters( [ return new \external_function_parameters( [
"studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL), "studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL),
"cohort_id" => new \external_value(PARAM_INT, 'id of cohort to link', VALUE_OPTIONAL), "cohort_id" => new \external_value(PARAM_INT, 'id of cohort to link', VALUE_OPTIONAL),
] ); ] );
} }
public static function disconnect_cohort_returns() public static function disconnect_cohort_returns()
{ {
return new \external_single_structure([ return new \external_single_structure([
"success" => new \external_value(PARAM_BOOL, 'operation completed succesfully'), "success" => new \external_value(PARAM_BOOL, 'operation completed succesfully'),
"msg" => new \external_value(PARAM_TEXT, 'message'), "msg" => new \external_value(PARAM_TEXT, 'message'),
]); ]);
} }
// Actual functions. // Actual functions.
public static function disconnect_cohort($studyplanid, $cohortid) public static function disconnect_cohort($studyplanid, $cohortid)
{ {
global $CFG, $DB; global $CFG, $DB;
$studyplan = studyplan::findById($studyplanid); $studyplan = studyplan::findById($studyplanid);
webservicehelper::require_capabilities(self::CAP_EDIT, $studyplan->context()); webservicehelper::require_capabilities(self::CAP_EDIT, $studyplan->context());
@ -270,25 +270,25 @@ class associationservice extends \external_api
} }
public static function connect_user_parameters() public static function connect_user_parameters()
{ {
return new \external_function_parameters( [ return new \external_function_parameters( [
"studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL), "studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL),
"user_id" => new \external_value(PARAM_INT, 'id of user to link', VALUE_OPTIONAL), "user_id" => new \external_value(PARAM_INT, 'id of user to link', VALUE_OPTIONAL),
] ); ] );
} }
public static function connect_user_returns() public static function connect_user_returns()
{ {
return new \external_single_structure([ return new \external_single_structure([
"success" => new \external_value(PARAM_BOOL, 'operation completed succesfully'), "success" => new \external_value(PARAM_BOOL, 'operation completed succesfully'),
"msg" => new \external_value(PARAM_TEXT, 'message'), "msg" => new \external_value(PARAM_TEXT, 'message'),
]); ]);
} }
// Actual functions. // Actual functions.
public static function connect_user($studyplanid, $userid) public static function connect_user($studyplanid, $userid)
{ {
global $CFG, $DB; global $CFG, $DB;
$studyplan = studyplan::findById($studyplanid); $studyplan = studyplan::findById($studyplanid);
webservicehelper::require_capabilities(self::CAP_EDIT, $studyplan->context()); webservicehelper::require_capabilities(self::CAP_EDIT, $studyplan->context());
@ -308,25 +308,25 @@ class associationservice extends \external_api
} }
public static function disconnect_user_parameters() public static function disconnect_user_parameters()
{ {
return new \external_function_parameters( [ return new \external_function_parameters( [
"studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL), "studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL),
"user_id" => new \external_value(PARAM_INT, 'id of user to link', VALUE_OPTIONAL), "user_id" => new \external_value(PARAM_INT, 'id of user to link', VALUE_OPTIONAL),
] ); ] );
} }
public static function disconnect_user_returns() public static function disconnect_user_returns()
{ {
return new \external_single_structure([ return new \external_single_structure([
"success" => new \external_value(PARAM_BOOL, 'operation completed succesfully'), "success" => new \external_value(PARAM_BOOL, 'operation completed succesfully'),
"msg" => new \external_value(PARAM_TEXT, 'message'), "msg" => new \external_value(PARAM_TEXT, 'message'),
]); ]);
} }
// Actual functions. // Actual functions.
public static function disconnect_user($studyplanid, $userid) public static function disconnect_user($studyplanid, $userid)
{ {
global $CFG, $DB; global $CFG, $DB;
$studyplan = studyplan::findById($studyplanid); $studyplan = studyplan::findById($studyplanid);
webservicehelper::require_capabilities(self::CAP_EDIT, $studyplan->context()); webservicehelper::require_capabilities(self::CAP_EDIT, $studyplan->context());
@ -345,21 +345,21 @@ class associationservice extends \external_api
} }
public static function associated_users_parameters() public static function associated_users_parameters()
{ {
return new \external_function_parameters( [ return new \external_function_parameters( [
"studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL), "studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL),
] ); ] );
} }
public static function associated_users_returns() public static function associated_users_returns()
{ {
return new \external_multiple_structure(self::user_structure()); return new \external_multiple_structure(self::user_structure());
} }
// Actual functions. // Actual functions.
public static function associated_users($studyplanid) public static function associated_users($studyplanid)
{ {
global $CFG, $DB; global $CFG, $DB;
$studyplan = studyplan::findById($studyplanid); $studyplan = studyplan::findById($studyplanid);
webservicehelper::require_capabilities(self::CAP_VIEW, $studyplan->context()); webservicehelper::require_capabilities(self::CAP_VIEW, $studyplan->context());
@ -377,21 +377,21 @@ class associationservice extends \external_api
} }
public static function associated_cohorts_parameters() public static function associated_cohorts_parameters()
{ {
return new \external_function_parameters( [ return new \external_function_parameters( [
"studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL), "studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL),
] ); ] );
} }
public static function associated_cohorts_returns() public static function associated_cohorts_returns()
{ {
return new \external_multiple_structure(self::cohort_structure()); return new \external_multiple_structure(self::cohort_structure());
} }
// Actual functions. // Actual functions.
public static function associated_cohorts($studyplanid) public static function associated_cohorts($studyplanid)
{ {
global $CFG, $DB; global $CFG, $DB;
$studyplan = studyplan::findById($studyplanid); $studyplan = studyplan::findById($studyplanid);
webservicehelper::require_capabilities(self::CAP_VIEW, $studyplan->context()); webservicehelper::require_capabilities(self::CAP_VIEW, $studyplan->context());
@ -408,21 +408,21 @@ class associationservice extends \external_api
public static function all_associated_parameters() public static function all_associated_parameters()
{ {
return new \external_function_parameters( [ return new \external_function_parameters( [
"studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL), "studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL),
] ); ] );
} }
public static function all_associated_returns() public static function all_associated_returns()
{ {
return new \external_multiple_structure(self::user_structure()); return new \external_multiple_structure(self::user_structure());
} }
// Actual functions. // Actual functions.
public static function all_associated($studyplanid) public static function all_associated($studyplanid)
{ {
global $CFG, $DB; global $CFG, $DB;
$studyplan = studyplan::findById($studyplanid); $studyplan = studyplan::findById($studyplanid);
webservicehelper::require_capabilities(self::CAP_VIEW, $studyplan->context()); webservicehelper::require_capabilities(self::CAP_VIEW, $studyplan->context());
@ -430,7 +430,7 @@ class associationservice extends \external_api
$users = []; $users = [];
// SQL JOIN script selecting all users that have a cohort linked to this studyplan . // SQL JOIN script selecting all users that have a cohort linked to this studyplan .
// or are directly linked. // Or are directly linked.
$sql = "SELECT DISTINCT u.id, u.username, u.firstname, u.lastname, u.idnumber, u.email $sql = "SELECT DISTINCT u.id, u.username, u.firstname, u.lastname, u.idnumber, u.email
FROM {user} u FROM {user} u
LEFT JOIN {cohort_members} cm ON u.id = cm.userid LEFT JOIN {cohort_members} cm ON u.id = cm.userid
@ -469,20 +469,20 @@ class associationservice extends \external_api
} }
public static function cascade_cohortsync_parameters() public static function cascade_cohortsync_parameters()
{ {
return new \external_function_parameters( [ return new \external_function_parameters( [
"studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL), "studyplan_id" => new \external_value(PARAM_INT, 'id of studyplan', VALUE_OPTIONAL),
] ); ] );
} }
public static function cascade_cohortsync_returns() public static function cascade_cohortsync_returns()
{ {
return success::structure(); return success::structure();
} }
// Actual functions. // Actual functions.
public static function cascade_cohortsync($studyplanid) public static function cascade_cohortsync($studyplanid)
{ {
$studyplan = studyplan::findById($studyplanid); $studyplan = studyplan::findById($studyplanid);
webservicehelper::require_capabilities(self::CAP_EDIT, $studyplan->context()); webservicehelper::require_capabilities(self::CAP_EDIT, $studyplan->context());

View File

@ -87,7 +87,7 @@ class cascadecohortsync {
foreach ($courseids as $courseid) { foreach ($courseids as $courseid) {
$course = \get_course($courseid); $course = \get_course($courseid);
//\mtrace("Processing Course {$courseid} {$course->shortname}");. //\mtrace("Processing Course {$courseid} {$course->shortname}");.
// first create any nonexistent links. // First create any nonexistent links.
foreach ($cohortids as $cohortid) { foreach ($cohortids as $cohortid) {
$cohort = $DB->get_record('cohort', ['id'=>$cohortid]); $cohort = $DB->get_record('cohort', ['id'=>$cohortid]);
//\mtrace("Processing cohort {$cohortid} {$cohort->shortname}");. //\mtrace("Processing cohort {$cohortid} {$cohort->shortname}");.
@ -111,8 +111,8 @@ class cascadecohortsync {
// If not, make it (maybe use some of the custom text to list the studyplans involved). // If not, make it (maybe use some of the custom text to list the studyplans involved).
if ($instance = $DB->get_record('enrol', $instanceparams)) { if ($instance = $DB->get_record('enrol', $instanceparams)) {
//\mtrace("Instance exists");. //\mtrace("Instance exists");.
// it already exists. // It already exists.
// check if this studyplan is already referenced in customtext4 in json format. // Check if this studyplan is already referenced in customtext4 in json format.
//TODO: Check this code - Maybe add option to not remember manually added stuff . //TODO: Check this code - Maybe add option to not remember manually added stuff .
$plans = json_decode($instance->customtext4); $plans = json_decode($instance->customtext4);
@ -126,7 +126,7 @@ class cascadecohortsync {
} }
} }
if (!in_array($this->studyplanid , $plans)) { if (!in_array($this->studyplanid , $plans)) {
// if not, add it to the reference. // If not, add it to the reference.
//\mtrace("Adding this plan to the list");. //\mtrace("Adding this plan to the list");.
$plans[] = (int)($this->studyplanid); $plans[] = (int)($this->studyplanid);
$enrol->update_instance($instance, (object)["customtext4"=>json_encode($plans)]); $enrol->update_instance($instance, (object)["customtext4"=>json_encode($plans)]);
@ -140,13 +140,13 @@ class cascadecohortsync {
// Make or get new new cohort group - but only on creating of instances. // Make or get new new cohort group - but only on creating of instances.
$groupname = $cohort->name." ".strtolower(\get_string('defaultgroupname', 'core_group')); $groupname = $cohort->name." ".strtolower(\get_string('defaultgroupname', 'core_group'));
//\mtrace("Adding group {$groupname} for this method");. //\mtrace("Adding group {$groupname} for this method");.
// and make sure the . // And make sure the .
$instancenewparams['customint2'] = self::uploadenrolmentmethods_get_group($courseid, $groupname); $instancenewparams['customint2'] = self::uploadenrolmentmethods_get_group($courseid, $groupname);
} }
if ($instanceid = $enrol->add_instance($course, $instancenewparams)) { if ($instanceid = $enrol->add_instance($course, $instancenewparams)) {
// also record the (as of yet only) studyplans id requiring this association. // Also record the (as of yet only) studyplans id requiring this association.
// in the customtext4 field in json format. // In the customtext4 field in json format.
//\mtrace("Instance ({$instanceid} created. Updateing instance with studyplan id");. //\mtrace("Instance ({$instanceid} created. Updateing instance with studyplan id");.
$instance = $DB->get_record('enrol', array('id' => $instanceid)); $instance = $DB->get_record('enrol', array('id' => $instanceid));
$enrol->update_instance($instance, (object)["customtext4"=>json_encode([(int)($this->studyplanid)])]); $enrol->update_instance($instance, (object)["customtext4"=>json_encode([(int)($this->studyplanid)])]);
@ -180,7 +180,7 @@ class cascadecohortsync {
if (get_config("local_treestudyplan", "csync_autoremove")) { if (get_config("local_treestudyplan", "csync_autoremove")) {
// Only try the autoremove if the option is enabled. // Only try the autoremove if the option is enabled.
//\mtrace("Autoremove scan for course {$courseid} {$course->shortname}");. //\mtrace("Autoremove scan for course {$courseid} {$course->shortname}");.
// find all cohort syncs for this course. // Find all cohort syncs for this course.
$searchparams = [ $searchparams = [
'courseid' => $courseid, 'courseid' => $courseid,
'enrol' => self::METHOD, 'enrol' => self::METHOD,
@ -190,25 +190,25 @@ class cascadecohortsync {
$records = $DB->get_records("enrol", $searchparams); $records = $DB->get_records("enrol", $searchparams);
foreach ($records as $instance) { foreach ($records as $instance) {
if (!empty($instance->customtext4)) { // only check the records that have studyplan information in the customtext4 field. if (!empty($instance->customtext4)) { // only check the records that have studyplan information in the customtext4 field.
// first check if the cohort is not one of the cohort id's we have associated. // First check if the cohort is not one of the cohort id's we have associated.
if (!in_array($instance->customint1, $cohortids)) { if (!in_array($instance->customint1, $cohortids)) {
//\mtrace("Found cohort sync instance that is not currently liked to the studyplan: {$instance->id}");. //\mtrace("Found cohort sync instance that is not currently liked to the studyplan: {$instance->id}");.
// So it may or may not need to be removed. // So it may or may not need to be removed.
$plans = json_decode($instance->customtext4); $plans = json_decode($instance->customtext4);
if ($plans !== null && is_array($plans)) { if ($plans !== null && is_array($plans)) {
//if a valid array is not returned, better leave it be, we don't want to mess with it. //if a valid array is not returned, better leave it be, we don't want to mess with it.
// otherwise, check if we should remove it. // Otherwise, check if we should remove it.
if (in_array($this->studyplanid, $plans)) { if (in_array($this->studyplanid, $plans)) {
//\mtrace("Found this studyplan in the id list - removing from list");. //\mtrace("Found this studyplan in the id list - removing from list");.
//if this plan was referenced before. //if this plan was referenced before.
// first remove the link. // First remove the link.
$fplans = self::array_remove_value($plans, $this->studyplanid); $fplans = self::array_remove_value($plans, $this->studyplanid);
if (count($fplans) == 0) { if (count($fplans) == 0) {
// delete the sync if there are no studyplan references left. // Delete the sync if there are no studyplan references left.
//\mtrace("No references are left, removing instance");. //\mtrace("No references are left, removing instance");.
$enrol->delete_instance($instance); $enrol->delete_instance($instance);
} else { } else {
// otherwise just update the references so this studyplan is no longer linked. // Otherwise just update the references so this studyplan is no longer linked.
//\mtrace("Still references left in the list, updating list...");. //\mtrace("Still references left in the list, updating list...");.
$enrol->update_instance($instance, (object)["customtext4"=>json_encode($fplans)]); $enrol->update_instance($instance, (object)["customtext4"=>json_encode($fplans)]);
} }

View File

@ -55,13 +55,13 @@ class completion {
} }
public static function count_states(array $states) { public static function count_states(array $states) {
// initialize result array. // Initialize result array.
$statecount = []; $statecount = [];
foreach (array_keys(self::LABELS) as $key) { foreach (array_keys(self::LABELS) as $key) {
$statecount[$key] = 0; $statecount[$key] = 0;
} }
// process all states in array and increment relevant counter for each one. // Process all states in array and increment relevant counter for each one.
foreach ($states as $c) { foreach ($states as $c) {
if (array_key_exists($c, $statecount)) { if (array_key_exists($c, $statecount)) {
$statecount[$c] += 1; $statecount[$c] += 1;

View File

@ -108,7 +108,7 @@ class completionscanner
public function model() { public function model() {
// get completion info. // Get completion info.
$students = self::get_course_students($this->courseid); $students = self::get_course_students($this->courseid);
$completed = 0; $completed = 0;
$ungraded = 0; $ungraded = 0;

View File

@ -50,7 +50,7 @@ class corecompletioninfo {
static public function completiontypes() { static public function completiontypes() {
global $COMPLETIONCRITERIA_TYPES; global $COMPLETIONCRITERIA_TYPES;
// Just return the keys of the global array COMPLETION_CRITERIA_TYPES, so we don't have to manually. // Just return the keys of the global array COMPLETION_CRITERIA_TYPES, so we don't have to manually.
// add any completion types.... // Add any completion types....
return \array_keys($COMPLETIONCRITERIA_TYPES); return \array_keys($COMPLETIONCRITERIA_TYPES);
} }
@ -182,9 +182,9 @@ class corecompletioninfo {
foreach ($criterias as $criteria) { foreach ($criterias as $criteria) {
// Unfortunately, we cannot easily get the criteria details with get_details() without having a . // Unfortunately, we cannot easily get the criteria details with get_details() without having a .
// user completion object involved, so'we'll have to retrieve the details per completion type. // User completion object involved, so'we'll have to retrieve the details per completion type.
// See moodle/completion/criteria/completion_criteria_*.php::get_details() for the code that is. // See moodle/completion/criteria/completion_criteria_*.php::get_details() for the code that is.
// in the code below is based on. // In the code below is based on.
if ($type == COMPLETION_CRITERIA_TYPE_SELF) { if ($type == COMPLETION_CRITERIA_TYPE_SELF) {
$details = [ $details = [
@ -288,7 +288,7 @@ class corecompletioninfo {
$scanner = new completionscanner($criteria, $this->course); $scanner = new completionscanner($criteria, $this->course);
// only add the items list if we actually have items... // Only add the items list if we actually have items...
$cinfo["items"][] = [ $cinfo["items"][] = [
"id" => $criteria->id, "id" => $criteria->id,
"title" => $criteria->get_title_detailed(), "title" => $criteria->get_title_detailed(),
@ -405,7 +405,7 @@ class corecompletioninfo {
} }
} }
} }
// finally add the item to the items list. // Finally add the item to the items list.
$cinfo["items"][] = $iinfo; $cinfo["items"][] = $iinfo;
} }
@ -414,9 +414,9 @@ class corecompletioninfo {
// Count and Progress amount to the sum of items. // Count and Progress amount to the sum of items.
$cinfo["count"] = count($cinfo["items"]); $cinfo["count"] = count($cinfo["items"]);
$cinfo["progress"] = $progress; $cinfo["progress"] = $progress;
} else { //$typeaggregation == COMPLETION_AGGREGATION_ANY. } else { // Typeaggregation == COMPLETION_AGGREGATION_ANY.
// Count and progress are either 1 or 0, since any of the items. // Count and progress are either 1 or 0, since any of the items.
// complete's the type. // Complete's the type.
$cinfo["count"] = (count($cinfo["items"]) > 0)?1:0; $cinfo["count"] = (count($cinfo["items"]) > 0)?1:0;
$cinfo["progress"] = ($progress>0)?1:0; $cinfo["progress"] = ($progress>0)?1:0;
} }
@ -451,12 +451,12 @@ class corecompletioninfo {
$result = new \stdClass; $result = new \stdClass;
// Check if the final grade is available and numeric (safety check). // Check if the final grade is available and numeric (safety check).
if (!empty($grade) && !empty($grade->finalgrade) && is_numeric($grade->finalgrade)) { if (!empty($grade) && !empty($grade->finalgrade) && is_numeric($grade->finalgrade)) {
// convert scale grades to corresponding scale name. // Convert scale grades to corresponding scale name.
if (isset($scale)) { if (isset($scale)) {
// get scale value. // Get scale value.
$result->grade = $scale->get_nearest_item($grade->finalgrade); $result->grade = $scale->get_nearest_item($grade->finalgrade);
} else { } else {
// round final grade to 1 decimal point. // Round final grade to 1 decimal point.
$result->grade = round($grade->finalgrade, 1); $result->grade = round($grade->finalgrade, 1);
} }
@ -491,12 +491,12 @@ class corecompletioninfo {
$grade = $gi->get_final($userid); // Get the grade for the specified user. $grade = $gi->get_final($userid); // Get the grade for the specified user.
// Check if the final grade is available and numeric (safety check). // Check if the final grade is available and numeric (safety check).
if (!empty($grade) && !empty($grade->finalgrade) && is_numeric($grade->finalgrade)) { if (!empty($grade) && !empty($grade->finalgrade) && is_numeric($grade->finalgrade)) {
// convert scale grades to corresponding scale name. // Convert scale grades to corresponding scale name.
if (isset($scale)) { if (isset($scale)) {
// get scale value. // Get scale value.
return $scale->get_nearest_item($grade->finalgrade); return $scale->get_nearest_item($grade->finalgrade);
} else { } else {
// round final grade to 1 decimal point. // Round final grade to 1 decimal point.
return round($grade->finalgrade, 1); return round($grade->finalgrade, 1);
} }
} else { } else {
@ -536,13 +536,13 @@ class corecompletioninfo {
if ($this->completion->is_course_complete($userid)) { if ($this->completion->is_course_complete($userid)) {
$completed = $count; $completed = $count;
} else { } else {
// count all completions, but treat . // Count all completions, but treat .
foreach ($completions as $completion) { foreach ($completions as $completion) {
$crit = $completion->get_criteria(); $crit = $completion->get_criteria();
if ($crit->criteriatype == COMPLETION_CRITERIA_TYPE_ACTIVITY) { if ($crit->criteriatype == COMPLETION_CRITERIA_TYPE_ACTIVITY) {
// get the cm data object. // Get the cm data object.
$cm = $this->modinfo->get_cm($crit->moduleinstance); $cm = $this->modinfo->get_cm($crit->moduleinstance);
// retrieve data for this object. // Retrieve data for this object.
$data = $this->completion->get_data($cm, false, $userid); $data = $this->completion->get_data($cm, false, $userid);
// Count complete, but failed as incomplete too... // Count complete, but failed as incomplete too...
if (($data->completionstate == COMPLETION_INCOMPLETE) || ($data->completionstate == COMPLETION_COMPLETE_FAIL)) { if (($data->completionstate == COMPLETION_INCOMPLETE) || ($data->completionstate == COMPLETION_COMPLETE_FAIL)) {
@ -588,7 +588,7 @@ class corecompletioninfo {
$critcount = []; $critcount = [];
// Before we check how many modules have been completed see if the course has completed. . // Before we check how many modules have been completed see if the course has completed. .
// count all completions, but treat . // Count all completions, but treat .
foreach ($completions as $completion) { foreach ($completions as $completion) {
$crit = $completion->get_criteria(); $crit = $completion->get_criteria();
@ -605,9 +605,9 @@ class corecompletioninfo {
$typecount->count += 1; $typecount->count += 1;
if ($crit->criteriatype == COMPLETION_CRITERIA_TYPE_ACTIVITY) { if ($crit->criteriatype == COMPLETION_CRITERIA_TYPE_ACTIVITY) {
// get the cm data object. // Get the cm data object.
$cm = $this->modinfo->get_cm($crit->moduleinstance); $cm = $this->modinfo->get_cm($crit->moduleinstance);
// retrieve data for this object. // Retrieve data for this object.
$data = $this->completion->get_data($cm, false, $userid); $data = $this->completion->get_data($cm, false, $userid);
// Count complete, but failed as incomplete too... // Count complete, but failed as incomplete too...
if (($data->completionstate == COMPLETION_INCOMPLETE) || ($data->completionstate == COMPLETION_COMPLETE_FAIL)) { if (($data->completionstate == COMPLETION_INCOMPLETE) || ($data->completionstate == COMPLETION_COMPLETE_FAIL)) {
@ -638,7 +638,7 @@ class corecompletioninfo {
$ct = 1; $ct = 1;
$cmpl = ($c->completed > 0)?1:0; $cmpl = ($c->completed > 0)?1:0;
} }
// if ANY completion for the types, count only the criteria type with the highest completion percentage -. // If ANY completion for the types, count only the criteria type with the highest completion percentage -.
// Overwrite data if current type is more complete. // Overwrite data if current type is more complete.
if ($aggregation == COMPLETION_AGGREGATION_ANY) { if ($aggregation == COMPLETION_AGGREGATION_ANY) {
$pct = $cmpl/$ct; $pct = $cmpl/$ct;
@ -648,7 +648,7 @@ class corecompletioninfo {
$completionpercentage = $pct; $completionpercentage = $pct;
} }
} }
// if ALL completion for the types, add the count for this type to that of the others. // If ALL completion for the types, add the count for this type to that of the others.
else { else {
$count += $ct; $count += $ct;
$completed += $cmpl; $completed += $cmpl;

View File

@ -118,7 +118,7 @@ class courseinfo {
if ($now > $course->startdate) { if ($now > $course->startdate) {
if ($course->enddate > 0 && $now > $course->enddate) { if ($course->enddate > 0 && $now > $course->enddate) {
return "past"; return "past";
} }
else { else {
return "present"; return "present";
} }

View File

@ -41,7 +41,6 @@ class coursemoduleinfo {
$this->id = $id; $this->id = $id;
$this->cm = $DB->get_record("course_modules", ["id" => $id]); $this->cm = $DB->get_record("course_modules", ["id" => $id]);
$this->cm_info = \cm_info::create($this->cm); $this->cm_info = \cm_info::create($this->cm);
// $this->db_record = $DB->get_record($this->cm_info->modname, ["id" => $this->cm_info->instance]);.
} }
public function getTitle() { public function getTitle() {

View File

@ -41,14 +41,14 @@ class courseservice extends \external_api
************************/ ************************/
public static function map_categories_parameters() public static function map_categories_parameters()
{ {
return new \external_function_parameters( [ return new \external_function_parameters( [
"root_id" => new \external_value(PARAM_INT, 'root category to use as base', VALUE_DEFAULT), "root_id" => new \external_value(PARAM_INT, 'root category to use as base', VALUE_DEFAULT),
] ); ] );
} }
public static function map_categories_returns() public static function map_categories_returns()
{ {
return new \external_multiple_structure(static::map_category_structure(false)); return new \external_multiple_structure(static::map_category_structure(false));
} }
@ -80,7 +80,7 @@ class courseservice extends \external_api
// Determine top categories from provided context. // Determine top categories from provided context.
if ($root->id == 0) { if ($root->id == 0) {
// on the system level, determine the user's topmost allowed catecories. // On the system level, determine the user's topmost allowed catecories.
$usertop = \core_course_category::user_top(); $usertop = \core_course_category::user_top();
if ($usertop->id == 0) { // top category.. if ($usertop->id == 0) { // top category..
$children = $root->get_children(); // returns a list of çore_course_category, let it overwrite $children. $children = $root->get_children(); // returns a list of çore_course_category, let it overwrite $children.
@ -98,14 +98,14 @@ class courseservice extends \external_api
} }
public static function get_category_parameters() public static function get_category_parameters()
{ {
return new \external_function_parameters( [ return new \external_function_parameters( [
"id" => new \external_value(PARAM_INT, 'id of category'), "id" => new \external_value(PARAM_INT, 'id of category'),
] ); ] );
} }
public static function get_category_returns() public static function get_category_returns()
{ {
return static::map_category_structure(false); return static::map_category_structure(false);
} }
@ -145,22 +145,22 @@ class courseservice extends \external_api
} }
public static function list_accessible_categories_parameters() public static function list_accessible_categories_parameters()
{ {
return new \external_function_parameters( [ return new \external_function_parameters( [
"operation" => new \external_value(PARAM_TEXT, 'type of operation ["view"|"edit"]', VALUE_DEFAULT), ] "operation" => new \external_value(PARAM_TEXT, 'type of operation ["view"|"edit"]', VALUE_DEFAULT), ]
); );
} }
public static function list_accessible_categories_returns() public static function list_accessible_categories_returns()
{ {
return new \external_multiple_structure(static::map_category_structure(true)); return new \external_multiple_structure(static::map_category_structure(true));
} }
public static function list_accessible_categories($operation="edit") public static function list_accessible_categories($operation="edit")
{ {
if ($operation == "edit") { if ($operation == "edit") {
$capability = self::CAP_EDIT; $capability = self::CAP_EDIT;
} else { // $operation == "view" || default. } else { // Operation == "view" || default.
$capability = self::CAP_VIEW; $capability = self::CAP_VIEW;
} }
@ -178,7 +178,7 @@ class courseservice extends \external_api
public static function categories_by_capability($capability, \core_course_category $parent=null) { public static function categories_by_capability($capability, \core_course_category $parent=null) {
// List the categories in which the user has a specific capability. // List the categories in which the user has a specific capability.
$list = []; $list = [];
// initialize parent if needed. // Initialize parent if needed.
if ($parent == null) { if ($parent == null) {
$parent = \core_course_category::user_top(); $parent = \core_course_category::user_top();
if (has_capability($capability, $parent->get_context())) { if (has_capability($capability, $parent->get_context())) {
@ -217,23 +217,23 @@ class courseservice extends \external_api
} }
public static function list_used_categories_parameters() public static function list_used_categories_parameters()
{ {
return new \external_function_parameters( [ return new \external_function_parameters( [
"operation" => new \external_value(PARAM_TEXT, 'type of operation ["view"|"edit"]', VALUE_DEFAULT), "operation" => new \external_value(PARAM_TEXT, 'type of operation ["view"|"edit"]', VALUE_DEFAULT),
]); ]);
} }
public static function list_used_categories_returns() public static function list_used_categories_returns()
{ {
return new \external_multiple_structure(static::map_category_structure(true)); return new \external_multiple_structure(static::map_category_structure(true));
} }
public static function list_used_categories($operation='edit') public static function list_used_categories($operation='edit')
{ {
global $DB; global $DB;
if ($operation == "edit") { if ($operation == "edit") {
$capability = self::CAP_EDIT; $capability = self::CAP_EDIT;
} else { // $operation == "view" || default. } else { // Operation == "view" || default.
$capability = self::CAP_VIEW; $capability = self::CAP_VIEW;
} }
$contextids = []; $contextids = [];
@ -268,10 +268,10 @@ class courseservice extends \external_api
global $DB; global $DB;
if ($operation == "edit") { if ($operation == "edit") {
$capability = self::CAP_EDIT; $capability = self::CAP_EDIT;
} else { // $operation == "view" || default. } else { // Operation == "view" || default.
$capability = self::CAP_VIEW; $capability = self::CAP_VIEW;
} }
// retrieve context ids used. // Retrieve context ids used.
$contextids = []; $contextids = [];
$rs = $DB->get_recordset_sql("SELECT DISTINCT context_id, COUNT(*) as num FROM {local_treestudyplan} $rs = $DB->get_recordset_sql("SELECT DISTINCT context_id, COUNT(*) as num FROM {local_treestudyplan}
GROUP BY context_id"); GROUP BY context_id");
@ -340,7 +340,7 @@ class courseservice extends \external_api
public static function scan_completion_progress_parameters() public static function scan_completion_progress_parameters()
{ {
return new \external_function_parameters( [ return new \external_function_parameters( [
"criteriaid" => new \external_value(PARAM_INT, 'CriteriaID to scan progress for', VALUE_DEFAULT), "criteriaid" => new \external_value(PARAM_INT, 'CriteriaID to scan progress for', VALUE_DEFAULT),
"studyplanid" => new \external_value(PARAM_INT, 'Study plan id to check progress in', VALUE_DEFAULT), "studyplanid" => new \external_value(PARAM_INT, 'Study plan id to check progress in', VALUE_DEFAULT),
@ -348,13 +348,13 @@ class courseservice extends \external_api
]); ]);
} }
public static function scan_completion_progress_returns() public static function scan_completion_progress_returns()
{ {
return completionscanner::structure(VALUE_REQUIRED); return completionscanner::structure(VALUE_REQUIRED);
} }
public static function scan_completion_progress($criteriaid, $studyplanid, $courseid) public static function scan_completion_progress($criteriaid, $studyplanid, $courseid)
{ {
global $DB; global $DB;
// Verify access to the study plan. // Verify access to the study plan.
$o = studyplan::findById($studyplanid); $o = studyplan::findById($studyplanid);
@ -369,15 +369,15 @@ class courseservice extends \external_api
} }
public static function scan_badge_progress_parameters() public static function scan_badge_progress_parameters()
{ {
return new \external_function_parameters( [ return new \external_function_parameters( [
"badgeid" => new \external_value(PARAM_INT, 'Badge to scan progress for', VALUE_DEFAULT), "badgeid" => new \external_value(PARAM_INT, 'Badge to scan progress for', VALUE_DEFAULT),
"studyplanid" => new \external_value(PARAM_INT, 'Study plan id to limit progress search to (to determine which students to scan)', VALUE_DEFAULT), "studyplanid" => new \external_value(PARAM_INT, 'Study plan id to limit progress search to (to determine which students to scan)', VALUE_DEFAULT),
]); ]);
} }
public static function scan_badge_progress_returns() public static function scan_badge_progress_returns()
{ {
return new \external_single_structure([ return new \external_single_structure([
"total" => new \external_value(PARAM_INT, 'Total number of students scanned'), "total" => new \external_value(PARAM_INT, 'Total number of students scanned'),
"issued" => new \external_value(PARAM_INT, 'Number of issued badges'), "issued" => new \external_value(PARAM_INT, 'Number of issued badges'),
@ -385,7 +385,7 @@ class courseservice extends \external_api
} }
public static function scan_badge_progress($badgeid, $studyplanid) public static function scan_badge_progress($badgeid, $studyplanid)
{ {
global $DB; global $DB;
// Check access to the study plan. // Check access to the study plan.
$o = studyplan::findById($studyplanid); $o = studyplan::findById($studyplanid);
@ -400,7 +400,7 @@ class courseservice extends \external_api
$badge = new \core_badges\badge($badgeid); $badge = new \core_badges\badge($badgeid);
$badgeinfo = new badgeinfo($badge); $badgeinfo = new badgeinfo($badge);
// get the connected users. // Get the connected users.
$students = associationservice::all_associated($studyplanid); $students = associationservice::all_associated($studyplanid);
// Just get the user ids. // Just get the user ids.
$studentids = array_map(function ($a) { return $a["id"];}, $students); $studentids = array_map(function ($a) { return $a["id"];}, $students);

View File

@ -127,7 +127,7 @@ class gradeinfo {
} else { } else {
list($c, $cminfo) = get_course_and_cm_from_instance($gi->iteminstance, $gi->itemmodule); list($c, $cminfo) = get_course_and_cm_from_instance($gi->iteminstance, $gi->itemmodule);
$this->cmid = $cminfo->id; $this->cmid = $cminfo->id;
// sort by position in course. // Sort by position in course.
// . // .
$this->section = $cminfo->sectionnum; $this->section = $cminfo->sectionnum;
$ssequence = self::getSectionSequence($cminfo->section); $ssequence = self::getSectionSequence($cminfo->section);
@ -239,7 +239,7 @@ class gradeinfo {
public function user_model($userid) { public function user_model($userid) {
global $DB; global $DB;
$grade = $this->gradeitem->get_final($userid); $grade = $this->gradeitem->get_final($userid);
// convert scale grades to corresponding scale name. // Convert scale grades to corresponding scale name.
if (!empty($grade)) { if (!empty($grade)) {
if (!is_numeric($grade->finalgrade) && empty($grade->finalgrade)) { if (!is_numeric($grade->finalgrade) && empty($grade->finalgrade)) {
$finalgrade = "-"; $finalgrade = "-";
@ -252,7 +252,7 @@ class gradeinfo {
$finalgrade = "-"; $finalgrade = "-";
} }
// retrieve the aggregator and determine completion. // Retrieve the aggregator and determine completion.
if (!isset($this->studyitem)) { if (!isset($this->studyitem)) {
throw new \UnexpectedValueException("Study item not set (null) for gradeinfo in report mode"); throw new \UnexpectedValueException("Study item not set (null) for gradeinfo in report mode");
} }
@ -295,7 +295,7 @@ class gradeinfo {
$gitype = $gi->itemmodule; $gitype = $gi->itemmodule;
if ($giname == $model["name"] && $gitype == $model["type"]) { if ($giname == $model["name"] && $gitype == $model["type"]) {
// we have a match. // We have a match.
if (!isset($model["selected"])) { $model["selected"] = true;} if (!isset($model["selected"])) { $model["selected"] = true;}
if (!isset($model["required"])) { $model["required"] = false;} if (!isset($model["required"])) { $model["required"] = false;}
if ($model["selected"] || $model["required"]) { if ($model["selected"] || $model["required"]) {
@ -352,7 +352,7 @@ class gradeinfo {
} }
} }
catch(\InvalidArgumentException $x) { catch(\InvalidArgumentException $x) {
// on InvalidArgumentException, the grade_item id can no longer be found. // On InvalidArgumentException, the grade_item id can no longer be found.
// Remove the link to avoid database record hogging. // Remove the link to avoid database record hogging.
$DB->delete_records($table, ['id' => $r->id]); $DB->delete_records($table, ['id' => $r->id]);
} }
@ -370,7 +370,7 @@ class gradeinfo {
global $DB; global $DB;
$table = 'local_treestudyplan_gradeinc'; $table = 'local_treestudyplan_gradeinc';
if ($include) { if ($include) {
// make sure a record exits. // Make sure a record exits.
$r = $DB->get_record($table, ['studyitem_id' => $itemid, 'grade_item_id' => $gradeid]); $r = $DB->get_record($table, ['studyitem_id' => $itemid, 'grade_item_id' => $gradeid]);
if ($r) { if ($r) {
$r->include = 1; $r->include = 1;
@ -385,7 +385,7 @@ class gradeinfo {
); );
} }
} else { } else {
// remove if it should not be included. // Remove if it should not be included.
$r = $DB->get_record($table, ['studyitem_id' => $itemid, 'grade_item_id' => $gradeid]); $r = $DB->get_record($table, ['studyitem_id' => $itemid, 'grade_item_id' => $gradeid]);
if ($r) { if ($r) {
$DB->delete_records($table, ['id' => $r->id]); $DB->delete_records($table, ['id' => $r->id]);

View File

@ -25,9 +25,6 @@ require_once($CFG->libdir.'/externallib.php');
use \grade_item; use \grade_item;
// $gi->courseid, .
// $gi->itemmodule, .
// $gi->iteminstance.
class gradingscanner class gradingscanner
{ {
private static $modsupported = []; private static $modsupported = [];
@ -131,7 +128,7 @@ class gradingscanner
private function grade_passed($grade) { private function grade_passed($grade) {
global $DB; global $DB;
$table = "local_treestudyplan_gradecfg"; $table = "local_treestudyplan_gradecfg";
// first determine if we have a grade_config for this scale or this maximum grade. // First determine if we have a grade_config for this scale or this maximum grade.
$finalgrade = $grade->finalgrade; $finalgrade = $grade->finalgrade;
$scale = $this->gi->load_scale(); $scale = $this->gi->load_scale();
if ( isset($scale)) { if ( isset($scale)) {
@ -142,11 +139,11 @@ class gradingscanner
$gradecfg = null; $gradecfg = null;
} }
// for point grades, a provided grade pass overrides the defaults in the gradeconfig. // For point grades, a provided grade pass overrides the defaults in the gradeconfig.
// for scales, the configuration in the gradeconfig is leading. // For scales, the configuration in the gradeconfig is leading.
if ($gradecfg && (isset($scale) || $this->gi->gradepass == 0)) { if ($gradecfg && (isset($scale) || $this->gi->gradepass == 0)) {
// if so, we need to know if the grade is . // If so, we need to know if the grade is .
if ($finalgrade >= $gradecfg->min_completed) { if ($finalgrade >= $gradecfg->min_completed) {
return true; return true;
} else { } else {
@ -154,7 +151,7 @@ class gradingscanner
} }
} else if ($this->gi->gradepass > 0) { } else if ($this->gi->gradepass > 0) {
$range = floatval($this->gi->grademax - $this->gi->grademin); $range = floatval($this->gi->grademax - $this->gi->grademin);
// if no gradeconfig and gradepass is set, use that one to determine config. // If no gradeconfig and gradepass is set, use that one to determine config.
if ($finalgrade >= $this->gi->gradepass) { if ($finalgrade >= $this->gi->gradepass) {
return true; return true;
} else { } else {
@ -162,8 +159,8 @@ class gradingscanner
} }
} else { } else {
// Blind assumptions if nothing is provided. // Blind assumptions if nothing is provided.
// over 55% of range is completed. // Over 55% of range is completed.
// if range >= 3 and failed is enabled, assume that this means failed. // If range >= 3 and failed is enabled, assume that this means failed.
$g = floatval($finalgrade - $this->gi->grademin); $g = floatval($finalgrade - $this->gi->grademin);
$range = floatval($this->gi->grademax - $this->gi->grademin); $range = floatval($this->gi->grademax - $this->gi->grademin);
$score = $g / $range; $score = $g / $range;

View File

@ -41,7 +41,7 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
private $acceptpending_as_submitted = False; // Also count ungraded but submitted . private $acceptpending_as_submitted = False; // Also count ungraded but submitted .
public function __construct($configstr) { public function __construct($configstr) {
// allow public constructor for testing purposes. // Allow public constructor for testing purposes.
$this->initialize($configstr); $this->initialize($configstr);
} }
@ -62,7 +62,7 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
$config = \json_decode($configstr, true); $config = \json_decode($configstr, true);
if (is_array($config)) { if (is_array($config)) {
// copy all valid config settings to this item. // Copy all valid config settings to this item.
foreach (["thresh_excellent", "thresh_good", "thresh_completed", "thresh_progress", ] as $key) { foreach (["thresh_excellent", "thresh_good", "thresh_completed", "thresh_progress", ] as $key) {
if (array_key_exists($key, $config)) { if (array_key_exists($key, $config)) {
$val = $config[$key]; $val = $config[$key];
@ -100,9 +100,9 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
public function aggregate_binary_goals(array $completions, array $required = []) { public function aggregate_binary_goals(array $completions, array $required = []) {
// function is public to allow access for the testing code. // Function is public to allow access for the testing code.
// return te following conditions. // Return te following conditions.
// Possible states:. // Possible states:.
// - completion::EXCELLENT - At least $threshexcellent fraction of goals are complete and all required goals are met. // - completion::EXCELLENT - At least $threshexcellent fraction of goals are complete and all required goals are met.
// - completion::GOOD - At least $threshgood fraction of goals are complete and all required goals are met. // - completion::GOOD - At least $threshgood fraction of goals are complete and all required goals are met.
@ -157,14 +157,14 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
$course = $courseinfo->course(); $course = $courseinfo->course();
$coursefinished = ($course->enddate)?($course->enddate < time()):false; $coursefinished = ($course->enddate)?($course->enddate < time()):false;
// Note: studyitem condition config is not used in this aggregator. // Note: studyitem condition config is not used in this aggregator.
// loop through all associated gradables and count the totals, completed, etc.. // Loop through all associated gradables and count the totals, completed, etc..
$completions = []; $completions = [];
$required = []; $required = [];
foreach (gradeinfo::list_studyitem_gradables($studyitem) as $gi) { foreach (gradeinfo::list_studyitem_gradables($studyitem) as $gi) {
$completions[] = $this->grade_completion($gi, $userid); $completions[] = $this->grade_completion($gi, $userid);
if ($gi->is_required()) { if ($gi->is_required()) {
// if it's a required grade . // If it's a required grade .
// also add it's index in the completion list to the list of required grades . // Also add it's index in the completion list to the list of required grades .
$required[] = count($completions) - 1; $required[] = count($completions) - 1;
} }
} }
@ -219,8 +219,8 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
if (empty($grade)) { if (empty($grade)) {
return completion::INCOMPLETE; return completion::INCOMPLETE;
} else if ($grade->finalgrade === NULL) { } else if ($grade->finalgrade === NULL) {
// on assignments, grade NULL means a submission has not yet been graded,. // On assignments, grade NULL means a submission has not yet been graded,.
// but on quizes this can also mean a quiz might have been started. // But on quizes this can also mean a quiz might have been started.
// Therefor, we treat a NULL result as a reason to check the relevant gradingscanner for presence of pending items. // Therefor, we treat a NULL result as a reason to check the relevant gradingscanner for presence of pending items.
// Since we want old results to be visible until a pending item was graded, we only use this state here. // Since we want old results to be visible until a pending item was graded, we only use this state here.
@ -232,7 +232,7 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
} }
} else { } else {
$grade = $gradeitem->get_final($userid); $grade = $gradeitem->get_final($userid);
// first determine if we have a grade_config for this scale or this maximum grade. // First determine if we have a grade_config for this scale or this maximum grade.
$finalgrade = $grade->finalgrade; $finalgrade = $grade->finalgrade;
$scale = $gradeinfo->getScale(); $scale = $gradeinfo->getScale();
if ( isset($scale)) { if ( isset($scale)) {
@ -243,35 +243,35 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
$gradecfg = null; $gradecfg = null;
} }
// for point grades, a provided grade pass overrides the defaults in the gradeconfig. // For point grades, a provided grade pass overrides the defaults in the gradeconfig.
// for scales, the configuration in the gradeconfig is leading. // For scales, the configuration in the gradeconfig is leading.
if ($gradecfg && (isset($scale) || $gradeitem->gradepass == 0)) { if ($gradecfg && (isset($scale) || $gradeitem->gradepass == 0)) {
// if so, we need to know if the grade is . // If so, we need to know if the grade is .
if ($finalgrade >= $gradecfg->min_completed) { if ($finalgrade >= $gradecfg->min_completed) {
// return completed if completed. // Return completed if completed.
return completion::COMPLETED; return completion::COMPLETED;
} else if ($this->use_failed && $coursefinished) { } else if ($this->use_failed && $coursefinished) {
// return failed if failed is enabled and the grade is less than the minimum grade for progress. // Return failed if failed is enabled and the grade is less than the minimum grade for progress.
return completion::FAILED; return completion::FAILED;
} else { } else {
return completion::PROGRESS; return completion::PROGRESS;
} }
} else if ($gradeitem->gradepass > 0) { } else if ($gradeitem->gradepass > 0) {
$range = floatval($gradeitem->grademax - $gradeitem->grademin); $range = floatval($gradeitem->grademax - $gradeitem->grademin);
// if no gradeconfig and gradepass is set, use that one to determine config. // If no gradeconfig and gradepass is set, use that one to determine config.
if ($finalgrade >= $gradeitem->gradepass) { if ($finalgrade >= $gradeitem->gradepass) {
return completion::COMPLETED; return completion::COMPLETED;
} else if ($this->use_failed && $coursefinished) { } else if ($this->use_failed && $coursefinished) {
// return failed if failed is enabled and the grade is 1, while there are at leas 3 states. // Return failed if failed is enabled and the grade is 1, while there are at leas 3 states.
return completion::FAILED; return completion::FAILED;
} else { } else {
return completion::PROGRESS; return completion::PROGRESS;
} }
} else { } else {
// Blind assumptions if nothing is provided. // Blind assumptions if nothing is provided.
// over 55% of range is completed. // Over 55% of range is completed.
// if range >= 3 and failed is enabled, assume that this means failed. // If range >= 3 and failed is enabled, assume that this means failed.
$g = floatval($finalgrade - $gradeitem->grademin); $g = floatval($finalgrade - $gradeitem->grademin);
$range = floatval($gradeitem->grademax - $gradeitem->grademin); $range = floatval($gradeitem->grademax - $gradeitem->grademin);
$score = $g / $range; $score = $g / $range;
@ -279,7 +279,7 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
if ($score > 0.55) { if ($score > 0.55) {
return completion::COMPLETED; return completion::COMPLETED;
} else if ($this->use_failed && $coursefinished) { } else if ($this->use_failed && $coursefinished) {
// return failed if failed is enabled and the grade is 1, while there are at leas 3 states. // Return failed if failed is enabled and the grade is 1, while there are at leas 3 states.
return completion::FAILED; return completion::FAILED;
} else { } else {
return completion::PROGRESS; return completion::PROGRESS;

View File

@ -35,7 +35,7 @@ class core_aggregator extends \local_treestudyplan\aggregator {
private $acceptpending_as_submitted = False; // Also count ungraded but submitted . private $acceptpending_as_submitted = False; // Also count ungraded but submitted .
public function __construct($configstr) { public function __construct($configstr) {
// allow public constructor for testing purposes. // Allow public constructor for testing purposes.
$this->initialize($configstr); $this->initialize($configstr);
} }
@ -49,7 +49,7 @@ class core_aggregator extends \local_treestudyplan\aggregator {
$config = \json_decode($configstr, true); $config = \json_decode($configstr, true);
if (is_array($config)) { if (is_array($config)) {
// copy all valid config settings to this item. // Copy all valid config settings to this item.
foreach (["accept_pending_as_submitted"] as $key) { foreach (["accept_pending_as_submitted"] as $key) {
if (array_key_exists($key, $config)) { if (array_key_exists($key, $config)) {
$this->$key = boolval($config[$key]); $this->$key = boolval($config[$key]);
@ -172,8 +172,8 @@ class core_aggregator extends \local_treestudyplan\aggregator {
if (empty($grade)) { if (empty($grade)) {
return completion::INCOMPLETE; return completion::INCOMPLETE;
} else if ($grade->finalgrade === NULL) { } else if ($grade->finalgrade === NULL) {
// on assignments, grade NULL means a submission has not yet been graded,. // On assignments, grade NULL means a submission has not yet been graded,.
// but on quizes this can also mean a quiz might have been started. // But on quizes this can also mean a quiz might have been started.
// Therefor, we treat a NULL result as a reason to check the relevant gradingscanner for presence of pending items. // Therefor, we treat a NULL result as a reason to check the relevant gradingscanner for presence of pending items.
// Since we want old results to be visible until a pending item was graded, we only use this state here. // Since we want old results to be visible until a pending item was graded, we only use this state here.
@ -185,7 +185,7 @@ class core_aggregator extends \local_treestudyplan\aggregator {
} }
} else { } else {
$grade = $gradeitem->get_final($userid); $grade = $gradeitem->get_final($userid);
// first determine if we have a grade_config for this scale or this maximum grade. // First determine if we have a grade_config for this scale or this maximum grade.
$finalgrade = $grade->finalgrade; $finalgrade = $grade->finalgrade;
$scale = $gradeinfo->getScale(); $scale = $gradeinfo->getScale();
if ( isset($scale)) { if ( isset($scale)) {
@ -196,35 +196,35 @@ class core_aggregator extends \local_treestudyplan\aggregator {
$gradecfg = null; $gradecfg = null;
} }
// for point grades, a provided grade pass overrides the defaults in the gradeconfig. // For point grades, a provided grade pass overrides the defaults in the gradeconfig.
// for scales, the configuration in the gradeconfig is leading. // For scales, the configuration in the gradeconfig is leading.
if ($gradecfg && (isset($scale) || $gradeitem->gradepass == 0)) { if ($gradecfg && (isset($scale) || $gradeitem->gradepass == 0)) {
// if so, we need to know if the grade is . // If so, we need to know if the grade is .
if ($finalgrade >= $gradecfg->min_completed) { if ($finalgrade >= $gradecfg->min_completed) {
// return completed if completed. // Return completed if completed.
return completion::COMPLETED; return completion::COMPLETED;
} else if ($this->use_failed && $finalgrade < $gradecfg->min_progress) { } else if ($this->use_failed && $finalgrade < $gradecfg->min_progress) {
// return failed if failed is enabled and the grade is less than the minimum grade for progress. // Return failed if failed is enabled and the grade is less than the minimum grade for progress.
return completion::FAILED; return completion::FAILED;
} else { } else {
return completion::PROGRESS; return completion::PROGRESS;
} }
} else if ($gradeitem->gradepass > 0) { } else if ($gradeitem->gradepass > 0) {
$range = floatval($gradeitem->grademax - $gradeitem->grademin); $range = floatval($gradeitem->grademax - $gradeitem->grademin);
// if no gradeconfig and gradepass is set, use that one to determine config. // If no gradeconfig and gradepass is set, use that one to determine config.
if ($finalgrade >= $gradeitem->gradepass) { if ($finalgrade >= $gradeitem->gradepass) {
return completion::COMPLETED; return completion::COMPLETED;
} else if ($this->use_failed && $gradeitem->gradepass >= 3 && $range >= 3 && $finalgrade == 1) { } else if ($this->use_failed && $gradeitem->gradepass >= 3 && $range >= 3 && $finalgrade == 1) {
// return failed if failed is enabled and the grade is 1, while there are at leas 3 states. // Return failed if failed is enabled and the grade is 1, while there are at leas 3 states.
return completion::FAILED; return completion::FAILED;
} else { } else {
return completion::PROGRESS; return completion::PROGRESS;
} }
} else { } else {
// Blind assumptions if nothing is provided. // Blind assumptions if nothing is provided.
// over 55% of range is completed. // Over 55% of range is completed.
// if range >= 3 and failed is enabled, assume that this means failed. // If range >= 3 and failed is enabled, assume that this means failed.
$g = floatval($finalgrade - $gradeitem->grademin); $g = floatval($finalgrade - $gradeitem->grademin);
$range = floatval($gradeitem->grademax - $gradeitem->grademin); $range = floatval($gradeitem->grademax - $gradeitem->grademin);
$score = $g / $range; $score = $g / $range;
@ -232,7 +232,7 @@ class core_aggregator extends \local_treestudyplan\aggregator {
if ($score > 0.55) { if ($score > 0.55) {
return completion::COMPLETED; return completion::COMPLETED;
} else if ($this->use_failed && $range >= 3 && $finalgrade == 1) { } else if ($this->use_failed && $range >= 3 && $finalgrade == 1) {
// return failed if failed is enabled and the grade is 1, while there are at leas 3 states. // Return failed if failed is enabled and the grade is 1, while there are at leas 3 states.
return completion::FAILED; return completion::FAILED;
} else { } else {
return completion::PROGRESS; return completion::PROGRESS;

View File

@ -39,7 +39,7 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
protected function aggregate_completion(array $a, $condition = "50") { protected function aggregate_completion(array $a, $condition = "50") {
if (in_array($condition, ['ALL', '67', '50', 'ANY'])) { if (in_array($condition, ['ALL', '67', '50', 'ANY'])) {
// condition is one of the valid conditions. // Condition is one of the valid conditions.
$ccompleted = 0; $ccompleted = 0;
$cexcellent = 0; $cexcellent = 0;
$cprogress = 0; $cprogress = 0;
@ -68,7 +68,7 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
return completion::COMPLETED; return completion::COMPLETED;
} else { } else {
// Return PROGRESS if one or more completions are COMPLETED or EXCELLENT, but the aggregation margin is not met. // Return PROGRESS if one or more completions are COMPLETED or EXCELLENT, but the aggregation margin is not met.
// state PROGRESS will not carry on if aggregations are chained. // State PROGRESS will not carry on if aggregations are chained.
if ($cprogress > 0) { if ($cprogress > 0) {
return completion::PROGRESS; return completion::PROGRESS;
} else if ($cpending > 0) { } else if ($cpending > 0) {
@ -81,7 +81,7 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
return completion::INCOMPLETE; return completion::INCOMPLETE;
} }
} else { } else {
// indeterminable, return null. // Indeterminable, return null.
return null; return null;
} }
} }
@ -101,7 +101,7 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
public function aggregate_junction(array $completion, studyitem $studyitem, $userid) { public function aggregate_junction(array $completion, studyitem $studyitem, $userid) {
$completed = self::aggregate_completion($completion, $studyitem->conditions()); $completed = self::aggregate_completion($completion, $studyitem->conditions());
// if null result (conditions are unknown/null) - default to ALL. // If null result (conditions are unknown/null) - default to ALL.
return isset($completed)?$completed:(self::aggregate_completion($completion, 'ALL')); return isset($completed)?$completed:(self::aggregate_completion($completion, 'ALL'));
} }
@ -113,8 +113,8 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
if (empty($grade)) { if (empty($grade)) {
return completion::INCOMPLETE; return completion::INCOMPLETE;
} else if ($grade->finalgrade === NULL) { } else if ($grade->finalgrade === NULL) {
// on assignments, grade NULL means a submission has not yet been graded,. // On assignments, grade NULL means a submission has not yet been graded,.
// but on quizes this can also mean a quiz might have been started. // But on quizes this can also mean a quiz might have been started.
// Therefor, we treat a NULL result as a reason to check the relevant gradingscanner for presence of pending items. // Therefor, we treat a NULL result as a reason to check the relevant gradingscanner for presence of pending items.
// Since we want old results to be visible until a pending item was graded, we only use this state here. // Since we want old results to be visible until a pending item was graded, we only use this state here.
@ -141,8 +141,8 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
} }
} else { } else {
// Blind assumptions:. // Blind assumptions:.
// over 55% of range is completed. // Over 55% of range is completed.
// over 85% of range is excellent. // Over 85% of range is excellent.
$g = floatval($finalgrade - $gradeitem->grademin); $g = floatval($finalgrade - $gradeitem->grademin);
$range = floatval($gradeitem->grademax - $gradeitem->grademin); $range = floatval($gradeitem->grademax - $gradeitem->grademin);
$score = $g / $range; $score = $g / $range;

View File

@ -88,10 +88,10 @@ class gradegenerator {
private function generatedfeedback() { private function generatedfeedback() {
if (file_exists("/usr/games/fortune")) { if (file_exists("/usr/games/fortune")) {
// get a fortune if it is available. // Get a fortune if it is available.
return shell_exec("/usr/games/fortune -n 160 -e disclaimer literature science pratchett wisdom education"); return shell_exec("/usr/games/fortune -n 160 -e disclaimer literature science pratchett wisdom education");
} else { } else {
// get a random loremipsum string. // Get a random loremipsum string.
return self::$loremipsum[rand(0, count(self::$loremipsum)-1)]; return self::$loremipsum[rand(0, count(self::$loremipsum)-1)];
} }
} }
@ -145,7 +145,7 @@ class gradegenerator {
$r->done = (rand(0, $end) > 20); // Determine if the assignment was done. $r->done = (rand(0, $end) > 20); // Determine if the assignment was done.
} }
if ($r->done) { if ($r->done) {
$score = rand(0, $int) ; $score = rand(0, $int);
$r->result = ($score > 20); // determine if the assignment was successful. $r->result = ($score > 20); // determine if the assignment was successful.
if (!$r->result) { if (!$r->result) {
$r->failed = !($score > 10); $r->failed = !($score > 10);
@ -188,12 +188,12 @@ class gradegenerator {
$gradecfg = null; $gradecfg = null;
} }
// next generate the grade. // Next generate the grade.
if ($gradecfg) { if ($gradecfg) {
if (!$gr->done) { if (!$gr->done) {
// INCOMPLETE. // INCOMPLETE.
// fair chance of teacher forgetting to set incomplete to "no evidence". // Fair chance of teacher forgetting to set incomplete to "no evidence".
$grade = 0;// $grade = (rand(0, 100) > 15)?max(1, $gradecfg->min_progress-1):"0";. $grade = 0;
$r = (object)["gi" => $g, "grade" => $grade, "fb" =>"" ]; $r = (object)["gi" => $g, "grade" => $grade, "fb" =>"" ];
} else if (!$gr->result) { } else if (!$gr->result) {
$grade = rand($gradecfg->min_progress, $gradecfg->min_completed -1 ); $grade = rand($gradecfg->min_progress, $gradecfg->min_completed -1 );
@ -229,8 +229,8 @@ class gradegenerator {
$r->gradetext = $r->grade; $r->gradetext = $r->grade;
} else { } else {
// Blind assumptions if nothing is provided. // Blind assumptions if nothing is provided.
// over 55% of range is completed. // Over 55% of range is completed.
// under 35% is not done. // Under 35% is not done.
$range = floatval($gi->grademax - $gi->grademin); $range = floatval($gi->grademax - $gi->grademin);
if (!$gr->done) { if (!$gr->done) {

View File

@ -37,7 +37,7 @@ class debugger {
$this->fname = $filename; $this->fname = $filename;
$this->tag = $tag; $this->tag = $tag;
// assume debug environment if cachejs is false. // Assume debug environment if cachejs is false.
$this->enabled = (isset($CFG->cachejs) && $CFG->cachejs == false); $this->enabled = (isset($CFG->cachejs) && $CFG->cachejs == false);
} }

View File

@ -66,7 +66,7 @@ class webservicehelper {
// List the categories in which the user has a specific capability. // List the categories in which the user has a specific capability.
$list = []; $list = [];
// initialize parent if needed. // Initialize parent if needed.
if ($parent == null) { if ($parent == null) {
$parent = \core_course_category::user_top(); $parent = \core_course_category::user_top();
if (has_capability($capability, $parent->get_context())) { if (has_capability($capability, $parent->get_context())) {
@ -76,7 +76,7 @@ class webservicehelper {
$children = $parent->get_children(); $children = $parent->get_children();
// Since the change for a category permission is greatest at the lower levels,. // Since the change for a category permission is greatest at the lower levels,.
// we scan in two stages, to focus the search more on the lower levels instead of diving deep into the first category. // We scan in two stages, to focus the search more on the lower levels instead of diving deep into the first category.
// Stage one (surface check): check all children for the capability. // Stage one (surface check): check all children for the capability.
foreach ($children as $child) { foreach ($children as $child) {
// Check if we should add this category. // Check if we should add this category.

View File

@ -72,9 +72,9 @@ class assign_scanner extends scanner_base {
$graded = array_intersect($graded, $courseuserids); $graded = array_intersect($graded, $courseuserids);
} }
// determine how many id's have a grade, but also an ungraded submission. // Determine how many id's have a grade, but also an ungraded submission.
$dual = array_intersect($ungraded, $graded); $dual = array_intersect($ungraded, $graded);
// subtract those from the graded count. // Subtract those from the graded count.
return count($graded) - count($dual); return count($graded) - count($dual);
} }

View File

@ -29,7 +29,7 @@ require_once($CFG->dirroot.'/question/engine/states.php'); // for reading questi
class quiz_scanner extends scanner_base { class quiz_scanner extends scanner_base {
protected function get_ungraded_submissions() { protected function get_ungraded_submissions() {
// count all users who have one or more questions that still need grading. // Count all users who have one or more questions that still need grading.
global $DB; global $DB;
// First find all question attempts that need grading. // First find all question attempts that need grading.
@ -62,7 +62,7 @@ class quiz_scanner extends scanner_base {
} }
public function count_graded($courseuserids=[]) { public function count_graded($courseuserids=[]) {
// count all users who submitted one or more finished tests. // Count all users who submitted one or more finished tests.
global $DB; global $DB;
$sql = "SELECT DISTINCT g.userid $sql = "SELECT DISTINCT g.userid
FROM {grade_grades} g FROM {grade_grades} g

View File

@ -61,7 +61,7 @@ class period {
} catch(\dml_missing_record_exception $x) { } catch(\dml_missing_record_exception $x) {
// Period does not exist - create one ... // Period does not exist - create one ...
// Make a best guess estimate of the start and end date, based on surrounding periods,. // Make a best guess estimate of the start and end date, based on surrounding periods,.
// or specified duration of the page and the sequence of the periods . // Or specified duration of the page and the sequence of the periods .
$pcount = $page->periods(); $pcount = $page->periods();
$ystart = $page->startdate()->getTimestamp(); $ystart = $page->startdate()->getTimestamp();
$yend = $page->enddate()->getTimestamp(); $yend = $page->enddate()->getTimestamp();
@ -104,7 +104,7 @@ class period {
public static function findForPage(studyplanpage $page): array { public static function findForPage(studyplanpage $page): array {
if (!array_key_exists($page->id(), self::$PAGECACHE)) { if (!array_key_exists($page->id(), self::$PAGECACHE)) {
$periods = []; $periods = [];
// find and add the periods to an array with the period sequence as a key. // Find and add the periods to an array with the period sequence as a key.
for($i=1; $i <= $page->periods(); $i++) { for($i=1; $i <= $page->periods(); $i++) {
$period = self::find($page, $i); $period = self::find($page, $i);
$periods[$i] = $period; $periods[$i] = $period;
@ -153,7 +153,7 @@ class period {
if ($this->r->enddate && strlen($this->r->enddate) > 0) { if ($this->r->enddate && strlen($this->r->enddate) > 0) {
return new \DateTime($this->r->enddate); return new \DateTime($this->r->enddate);
} else{ } else{
// return a date 100 years into the future. // Return a date 100 years into the future.
return (new \DateTime($this->r->startdate))->add(new \DateInterval("P100Y")); return (new \DateTime($this->r->startdate))->add(new \DateInterval("P100Y"));
} }
} }

View File

@ -80,7 +80,7 @@ class provider implements \core_privacy\local\metadata\provider,
$contextlist = new \core_privacy\local\request\contextlist(); $contextlist = new \core_privacy\local\request\contextlist();
$contextlist->add_system_context(); // For invitations. $contextlist->add_system_context(); // For invitations.
// add contexts for linked studyplans. // Add contexts for linked studyplans.
$sql = "SELECT s.context_id FROM {local_treestudyplan} s $sql = "SELECT s.context_id FROM {local_treestudyplan} s
INNER JOIN {local_treestudyplan_user} a ON a.studyplan_id = s.id INNER JOIN {local_treestudyplan_user} a ON a.studyplan_id = s.id
WHERE ( a.user_id = :userid ) WHERE ( a.user_id = :userid )
@ -172,7 +172,7 @@ class provider implements \core_privacy\local\metadata\provider,
*/ */
public static function delete_data_for_all_users_in_context(\context $context) { public static function delete_data_for_all_users_in_context(\context $context) {
global $DB; global $DB;
// find studyplans in context. // Find studyplans in context.
if ($context->contextlevel == CONTEXT_COURSECAT) { if ($context->contextlevel == CONTEXT_COURSECAT) {
$sql = "SELECT s.id FROM {local_treestudyplan} WHERE ( a.user_id = :userid AND s.context_id = :contextid)"; $sql = "SELECT s.id FROM {local_treestudyplan} WHERE ( a.user_id = :userid AND s.context_id = :contextid)";
$planids = $DB->get_fieldset_sql($sql, ["contextid"=>$context->id]); $planids = $DB->get_fieldset_sql($sql, ["contextid"=>$context->id]);
@ -233,7 +233,7 @@ class provider implements \core_privacy\local\metadata\provider,
FROM {local_treestudyplan_invit} i;"; FROM {local_treestudyplan_invit} i;";
$userlist->add_from_sql('userid', $sql, []); $userlist->add_from_sql('userid', $sql, []);
// also add "contextless studyplans, they are considered in system context". // Also add "contextless studyplans, they are considered in system context".
$sql = "SELECT a.user_id as userid FROM {local_treestudyplan_user} a $sql = "SELECT a.user_id as userid FROM {local_treestudyplan_user} a
INNER JOIN {local_treestudyplan} s ON a.studyplan_id = s.id INNER JOIN {local_treestudyplan} s ON a.studyplan_id = s.id
WHERE ( a.context_id is NULL or a.context_id = 0) WHERE ( a.context_id is NULL or a.context_id = 0)
@ -242,7 +242,7 @@ class provider implements \core_privacy\local\metadata\provider,
} }
// add the links to all study plans in this context. // Add the links to all study plans in this context.
$sql = "SELECT a.user_id as userid FROM {local_treestudyplan_user} a $sql = "SELECT a.user_id as userid FROM {local_treestudyplan_user} a
INNER JOIN {local_treestudyplan} s ON a.studyplan_id = s.id INNER JOIN {local_treestudyplan} s ON a.studyplan_id = s.id
WHERE ( a.context_id = :contextid ) WHERE ( a.context_id = :contextid )

View File

@ -25,37 +25,35 @@ require_once("$CFG->dirroot/local/treestudyplan/lib.php");
class reportinvite_form extends moodleform { class reportinvite_form extends moodleform {
//Add elements to form. //Add elements to form.
const GOALS_EDITOR_OPTIONS = array('trusttext'=>true, 'subdirs'=>true, 'maxfiles'=>0, 'maxbytes'=>5*1024*1025); const GOALS_EDITOR_OPTIONS = array('trusttext'=>true, 'subdirs'=>true, 'maxfiles'=>0, 'maxbytes'=>5*1024*1025);
public function definition() { public function definition() {
global $CFG; global $CFG;
// 'code', 'revision', 'description', 'goals', 'complexity', 'points', 'studyhours'. // 'code', 'revision', 'description', 'goals', 'complexity', 'points', 'studyhours'.
$mform = $this->_form; // Don't forget the underscore! . $mform = $this->_form; // Don't forget the underscore! .
$mform->addElement('hidden', 'add', 0); $mform->addElement('hidden', 'add', 0);
$mform->setType('add', PARAM_ALPHANUM); $mform->setType('add', PARAM_ALPHANUM);
$mform->addElement('hidden', 'update', 0); $mform->addElement('hidden', 'update', 0);
$mform->setType('update', PARAM_INT); $mform->setType('update', PARAM_INT);
// $mform->addElement('static', 'desc_new', get_string('invite_desc_new', 'local_treestudyplan')); // Add elements to your form.
// $mform->addElement('static', 'desc_edit', get_string('invite_desc_edit', 'local_treestudyplan')); // Add elements to your form.
$mform->addElement('text', 'name', get_string('invite_name', 'local_treestudyplan'), array('size' => 50)); // Add elements to your form. $mform->addElement('text', 'name', get_string('invite_name', 'local_treestudyplan'), array('size' => 50)); // Add elements to your form.
$mform->setType('name', PARAM_NOTAGS); //Set type of element. $mform->setType('name', PARAM_NOTAGS); //Set type of element.
$mform->setDefault('name', ''); //Default value. $mform->setDefault('name', ''); //Default value.
$mform->addRule('name', get_string('required'), 'required', null, 'client'); $mform->addRule('name', get_string('required'), 'required', null, 'client');
$mform->addElement('text', 'email', get_string('invite_email', 'local_treestudyplan'), array('size' => 20)); // Add elements to your form. $mform->addElement('text', 'email', get_string('invite_email', 'local_treestudyplan'), array('size' => 20)); // Add elements to your form.
$mform->setType('email', PARAM_NOTAGS); //Set type of element. $mform->setType('email', PARAM_NOTAGS); //Set type of element.
$mform->setDefault('email', ''); //Default value. $mform->setDefault('email', ''); //Default value.
$mform->addRule('email', get_string('required'), 'required', null, 'client'); $mform->addRule('email', get_string('required'), 'required', null, 'client');
$mform->addRule('email', get_string('email'), 'email', null, 'client'); $mform->addRule('email', get_string('email'), 'email', null, 'client');
$mform->addElement('static', get_string('invite_email', 'local_treestudyplan') ); // Add elements to your form. $mform->addElement('static', get_string('invite_email', 'local_treestudyplan') ); // Add elements to your form.
$this->add_action_buttons(); $this->add_action_buttons();
} }
//Custom validation should be added here. //Custom validation should be added here.
function validation($data, $files) { function validation($data, $files) {
@ -67,46 +65,46 @@ class reportinvite_form extends moodleform {
parent::set_data($data); parent::set_data($data);
} }
function get_data() function get_data()
{ {
global $DB, $USER; global $DB, $USER;
$data = parent::get_data(); $data = parent::get_data();
if ($data != NULL) if ($data != NULL)
{ {
if (empty($data->user_id)) if (empty($data->user_id))
{ {
$data->user_id = $USER->id; $data->user_id = $USER->id;
} }
if (empty($data->update)) if (empty($data->update))
{ {
$date = new DateTime("now", core_date::get_user_timezone_object()); $date = new DateTime("now", core_date::get_user_timezone_object());
$date->setTime(0, 0, 0); $date->setTime(0, 0, 0);
$data->idate = $date->getTimeStamp(); $data->idate = $date->getTimeStamp();
} }
if (empty($data->update)) if (empty($data->update))
{ {
//create a new random key for the invite. //create a new random key for the invite.
do { do {
$length = 20; $length = 20;
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters); $charactersLength = strlen($characters);
$randomkey = ''; $randomkey = '';
for ($i = 0; $i < $length; $i++) { for ($i = 0; $i < $length; $i++) {
$randomkey .= $characters[rand(0, $charactersLength - 1)]; $randomkey .= $characters[rand(0, $charactersLength - 1)];
} }
// Double check that the key is unique before inserting. // Double check that the key is unique before inserting.
} while($DB->record_exists_select("local_treestudyplan_invit", $DB->sql_compare_text("invitekey"). " = " . $DB->sql_compare_text(":invitekey"), ['invitekey' => $randomkey])); } while($DB->record_exists_select("local_treestudyplan_invit", $DB->sql_compare_text("invitekey"). " = " . $DB->sql_compare_text(":invitekey"), ['invitekey' => $randomkey]));
$data->invitekey = $randomkey; $data->invitekey = $randomkey;
} }
} }
return $data; return $data;
} }
} }

View File

@ -37,14 +37,14 @@ class studentstudyplanservice extends \external_api
************************/ ************************/
public static function list_user_studyplans_parameters() public static function list_user_studyplans_parameters()
{ {
return new \external_function_parameters([ return new \external_function_parameters([
"userid" => new \external_value(PARAM_INT, 'id of student', VALUE_DEFAULT), "userid" => new \external_value(PARAM_INT, 'id of student', VALUE_DEFAULT),
]); ]);
} }
public static function list_user_studyplans_returns() public static function list_user_studyplans_returns()
{ {
return new \external_multiple_structure( return new \external_multiple_structure(
studyplan::simple_structure() studyplan::simple_structure()
); );
@ -56,7 +56,7 @@ class studentstudyplanservice extends \external_api
$list = []; $list = [];
$studyplans = studyplan::find_for_user($userid); $studyplans = studyplan::find_for_user($userid);
foreach ($studyplans as $studyplan) { foreach ($studyplans as $studyplan) {
// only include studyplans in the context the user has permissions for. // Only include studyplans in the context the user has permissions for.
if (webservicehelper::has_capabilities(self::CAP_VIEWOTHER, $studyplan->context(), false)) { if (webservicehelper::has_capabilities(self::CAP_VIEWOTHER, $studyplan->context(), false)) {
$list[] =$studyplan->simple_model(); $list[] =$studyplan->simple_model();
} }
@ -71,14 +71,14 @@ class studentstudyplanservice extends \external_api
************************/ ************************/
public static function get_user_studyplans_parameters() public static function get_user_studyplans_parameters()
{ {
return new \external_function_parameters( [ return new \external_function_parameters( [
"userid" => new \external_value(PARAM_INT, 'id of user'), "userid" => new \external_value(PARAM_INT, 'id of user'),
] ); ] );
} }
public static function get_user_studyplans_returns() public static function get_user_studyplans_returns()
{ {
return new \external_multiple_structure( return new \external_multiple_structure(
studyplan::user_structure() studyplan::user_structure()
); );
@ -90,7 +90,7 @@ class studentstudyplanservice extends \external_api
$map = []; $map = [];
foreach ($studyplans as $studyplan) { foreach ($studyplans as $studyplan) {
// only include studyplans in the context the user has permissions for. // Only include studyplans in the context the user has permissions for.
if (webservicehelper::has_capabilities(self::CAP_VIEWOTHER, $studyplan->context(), false)) { if (webservicehelper::has_capabilities(self::CAP_VIEWOTHER, $studyplan->context(), false)) {
$map[] = $studyplan->user_model($userid); $map[] = $studyplan->user_model($userid);
} }
@ -106,15 +106,15 @@ class studentstudyplanservice extends \external_api
************************/ ************************/
public static function get_user_studyplan_parameters() public static function get_user_studyplan_parameters()
{ {
return new \external_function_parameters( [ return new \external_function_parameters( [
"userid" => new \external_value(PARAM_INT, 'id of user'), "userid" => new \external_value(PARAM_INT, 'id of user'),
"studyplanid" => new \external_value(PARAM_INT, 'id of specific studyplan to provide'), "studyplanid" => new \external_value(PARAM_INT, 'id of specific studyplan to provide'),
] ); ] );
} }
public static function get_user_studyplan_returns() public static function get_user_studyplan_returns()
{ {
return studyplan::user_structure(); return studyplan::user_structure();
} }
public static function get_user_studyplan($userid, $studyplanid) { public static function get_user_studyplan($userid, $studyplanid) {
@ -137,14 +137,14 @@ class studentstudyplanservice extends \external_api
****************************/ ****************************/
public static function get_invited_studyplan_parameters() public static function get_invited_studyplan_parameters()
{ {
return new \external_function_parameters( [ return new \external_function_parameters( [
"invitekey" => new \external_value(PARAM_RAW, 'invite key'), "invitekey" => new \external_value(PARAM_RAW, 'invite key'),
] ); ] );
} }
public static function get_invited_studyplan_returns() public static function get_invited_studyplan_returns()
{ {
return new \external_multiple_structure( return new \external_multiple_structure(
studyplan::user_structure() studyplan::user_structure()
); );
@ -178,12 +178,12 @@ class studentstudyplanservice extends \external_api
************************/ ************************/
public static function list_own_studyplans_parameters() public static function list_own_studyplans_parameters()
{ {
return new \external_function_parameters([]); return new \external_function_parameters([]);
} }
public static function list_own_studyplans_returns() public static function list_own_studyplans_returns()
{ {
return new \external_multiple_structure( return new \external_multiple_structure(
studyplan::simple_structure() studyplan::simple_structure()
); );
@ -208,14 +208,14 @@ class studentstudyplanservice extends \external_api
************************/ ************************/
public static function get_own_studyplan_parameters() public static function get_own_studyplan_parameters()
{ {
return new \external_function_parameters( [ return new \external_function_parameters( [
"id" => new \external_value(PARAM_INT, 'id of specific studyplan to provide', VALUE_DEFAULT), "id" => new \external_value(PARAM_INT, 'id of specific studyplan to provide', VALUE_DEFAULT),
] ); ] );
} }
public static function get_own_studyplan_returns() public static function get_own_studyplan_returns()
{ {
return new \external_multiple_structure( return new \external_multiple_structure(
studyplan::user_structure() studyplan::user_structure()
); );
@ -254,14 +254,14 @@ class studentstudyplanservice extends \external_api
***************************/ ***************************/
public static function get_teaching_studyplans_parameters() public static function get_teaching_studyplans_parameters()
{ {
return new \external_function_parameters( [ return new \external_function_parameters( [
"id" => new \external_value(PARAM_INT, 'id of specific studyplan to provide', VALUE_DEFAULT), "id" => new \external_value(PARAM_INT, 'id of specific studyplan to provide', VALUE_DEFAULT),
] ); ] );
} }
public static function get_teaching_studyplans_returns() public static function get_teaching_studyplans_returns()
{ {
return new \external_multiple_structure( return new \external_multiple_structure(
studyplan::editor_structure() studyplan::editor_structure()
); );

View File

@ -140,7 +140,7 @@ class studyitem {
] ]
]; ];
if ($mode == "export") { if ($mode == "export") {
// remove slot and layer. // Remove slot and layer.
unset($model["slot"]); unset($model["slot"]);
unset($model["layer"]); unset($model["layer"]);
unset($model["continuation_id"]); unset($model["continuation_id"]);
@ -168,7 +168,7 @@ class studyitem {
$model['badge'] = $badgeinfo->name(); $model['badge'] = $badgeinfo->name();
} else { } else {
// Also supply a list of linked users, so the badgeinfo can give stats on . // Also supply a list of linked users, so the badgeinfo can give stats on .
// the amount issued, related to this studyplan. // The amount issued, related to this studyplan.
$studentids = $this->studyline()->studyplan()->find_linked_userids(); $studentids = $this->studyline()->studyplan()->find_linked_userids();
$model['badge'] = $badgeinfo->editor_model($studentids); $model['badge'] = $badgeinfo->editor_model($studentids);
} }
@ -256,9 +256,9 @@ class studyitem {
public function delete($force=false) { public function delete($force=false) {
global $DB; global $DB;
// check if this item is referenced in a START item. // Check if this item is referenced in a START item.
if ($force) { if ($force) {
// clear continuation id from any references to this item. // Clear continuation id from any references to this item.
$records = $DB->get_records(self::TABLE, ['continuation_id' => $this->id]); $records = $DB->get_records(self::TABLE, ['continuation_id' => $this->id]);
foreach ($records as $r) { foreach ($records as $r) {
$r->continuation_id = 0; $r->continuation_id = 0;
@ -269,11 +269,11 @@ class studyitem {
if ($DB->count_records(self::TABLE, ['continuation_id' => $this->id]) > 0) { if ($DB->count_records(self::TABLE, ['continuation_id' => $this->id]) > 0) {
return success::fail('Cannot remove: item is referenced by another item'); return success::fail('Cannot remove: item is referenced by another item');
} else { } else {
// delete al related connections to this item. // Delete al related connections to this item.
studyitemconnection::clear($this->id); studyitemconnection::clear($this->id);
// delete all grade inclusion references to this item. // Delete all grade inclusion references to this item.
$DB->delete_records("local_treestudyplan_gradeinc", ['studyitem_id' => $this->id]); $DB->delete_records("local_treestudyplan_gradeinc", ['studyitem_id' => $this->id]);
// delete the item itself. // Delete the item itself.
$DB->delete_records(self::TABLE, ['id' => $this->id]); $DB->delete_records(self::TABLE, ['id' => $this->id]);
return success::success(); return success::success();
@ -416,7 +416,7 @@ class studyitem {
if ($this->isValid()) { if ($this->isValid()) {
if (strtolower($this->r->type) == 'course') { if (strtolower($this->r->type) == 'course') {
// determine competency by competency completion. // Determine competency by competency completion.
$courseinfo = $this->getcourseinfo(); $courseinfo = $this->getcourseinfo();
return $this->aggregator->aggregate_course($courseinfo, $this, $userid); return $this->aggregator->aggregate_course($courseinfo, $this, $userid);
} else if (strtolower($this->r->type) =='start') { } else if (strtolower($this->r->type) =='start') {
@ -429,7 +429,7 @@ class studyitem {
return completion::COMPLETED; return completion::COMPLETED;
} }
} else if (in_array(strtolower($this->r->type), ['junction', 'finish'])) { } else if (in_array(strtolower($this->r->type), ['junction', 'finish'])) {
// completion of the linked items, according to the rule. // Completion of the linked items, according to the rule.
$incompleted = []; $incompleted = [];
// Retrieve incoming connections. // Retrieve incoming connections.
$incoming = $DB->get_records(studyitemconnection::TABLE, ['to_id' => $this->r->id]); $incoming = $DB->get_records(studyitemconnection::TABLE, ['to_id' => $this->r->id]);
@ -440,12 +440,12 @@ class studyitem {
return $this->aggregator->aggregate_junction($incompleted, $this, $userid); return $this->aggregator->aggregate_junction($incompleted, $this, $userid);
} else if (strtolower($this->r->type) =='badge') { } else if (strtolower($this->r->type) =='badge') {
global $DB; global $DB;
// badge awarded. // Badge awarded.
if (badgeinfo::exists($this->r->badge_id)) { if (badgeinfo::exists($this->r->badge_id)) {
$badge = new \core_badges\badge($this->r->badge_id); $badge = new \core_badges\badge($this->r->badge_id);
if ($badge->is_issued($userid)) { if ($badge->is_issued($userid)) {
if ($badge->can_expire()) { if ($badge->can_expire()) {
// get the issued badges and check if any of them have not expired yet. // Get the issued badges and check if any of them have not expired yet.
$badgesissued = $DB->get_records("badge_issued", ["badge_id" => $this->r->badge_id, "user_id" => $userid]); $badgesissued = $DB->get_records("badge_issued", ["badge_id" => $this->r->badge_id, "user_id" => $userid]);
$notexpired = false; $notexpired = false;
$now = time(); $now = time();
@ -466,27 +466,27 @@ class studyitem {
return completion::INCOMPLETE; return completion::INCOMPLETE;
} }
} else { } else {
// return incomplete for other types. // Return incomplete for other types.
return completion::INCOMPLETE; return completion::INCOMPLETE;
} }
} else { } else {
// return incomplete for other types. // Return incomplete for other types.
return completion::INCOMPLETE; return completion::INCOMPLETE;
} }
} }
public function duplicate($newline) { public function duplicate($newline) {
global $DB; global $DB;
// clone the database fields. // Clone the database fields.
$fields = clone $this->r; $fields = clone $this->r;
// set new line id. // Set new line id.
unset($fields->id); unset($fields->id);
$fields->line_id = $newline->id(); $fields->line_id = $newline->id();
//create new record with the new data. //create new record with the new data.
$id = $DB->insert_record(self::TABLE, (array)$fields); $id = $DB->insert_record(self::TABLE, (array)$fields);
$new = self::findById($id, $newline); $new = self::findById($id, $newline);
// copy the grading info if relevant. // Copy the grading info if relevant.
$gradables = gradeinfo::list_studyitem_gradables($this); $gradables = gradeinfo::list_studyitem_gradables($this);
foreach ($gradables as $g) { foreach ($gradables as $g) {
gradeinfo::include_grade($g->getGradeitem()->id, $new->id(), true); gradeinfo::include_grade($g->getGradeitem()->id, $new->id(), true);
@ -513,7 +513,7 @@ class studyitem {
$item = self::add($model, true); $item = self::add($model, true);
if (isset($model["course_id"])) { if (isset($model["course_id"])) {
// attempt to import the gradables. // Attempt to import the gradables.
foreach ($model["gradables"] as $gradable) { foreach ($model["gradables"] as $gradable) {
gradeinfo::import($item, $gradable); gradeinfo::import($item, $gradable);
} }

View File

@ -130,7 +130,7 @@ class studyline {
// TODO: Make this a little nicer. // TODO: Make this a little nicer.
// Get the number of slots. // Get the number of slots.
// As a safety data integrity measure, if there are any items in a higher slot than currently allowed, . // As a safety data integrity measure, if there are any items in a higher slot than currently allowed, .
// make sure there are enought slots to account for them. // Make sure there are enought slots to account for them.
// Alternatively, we could ensure that on reduction of slots, the items that no longer have a slot will be removed. // Alternatively, we could ensure that on reduction of slots, the items that no longer have a slot will be removed.
$maxslot = $DB->get_field_select(studyitem::TABLE, "MAX(slot)", "line_id = :lineid", ['lineid' => $this->id]); $maxslot = $DB->get_field_select(studyitem::TABLE, "MAX(slot)", "line_id = :lineid", ['lineid' => $this->id]);
$numslots = max($this->page->periods(), $maxslot +1); $numslots = max($this->page->periods(), $maxslot +1);
@ -217,7 +217,7 @@ class studyline {
$c->delete($force); $c->delete($force);
} }
} }
// check if this item has study items in it. // Check if this item has study items in it.
if ($DB->count_records(studyitem::TABLE, ['line_id' => $this->id]) > 0) { if ($DB->count_records(studyitem::TABLE, ['line_id' => $this->id]) > 0) {
return success::fail('cannot delete studyline with items'); return success::fail('cannot delete studyline with items');
} else { } else {
@ -282,7 +282,7 @@ class studyline {
// Get the number of slots. // Get the number of slots.
// As a safety data integrity measure, if there are any items in a higher slot than currently allowed, . // As a safety data integrity measure, if there are any items in a higher slot than currently allowed, .
// make sure there are enought slots to account for them. // Make sure there are enought slots to account for them.
// Alternatively, we could ensure that on reduction of slots, the items that no longer have a slot will be removed. // Alternatively, we could ensure that on reduction of slots, the items that no longer have a slot will be removed.
$maxslot = $DB->get_field_select(studyitem::TABLE, "MAX(slot)", "line_id = :lineid", ['lineid' => $this->id]); $maxslot = $DB->get_field_select(studyitem::TABLE, "MAX(slot)", "line_id = :lineid", ['lineid' => $this->id]);
$numslots = max($this->page->periods(), $maxslot +1); $numslots = max($this->page->periods(), $maxslot +1);
@ -324,18 +324,18 @@ class studyline {
public function duplicate($newstudyplan, &$translation) { public function duplicate($newstudyplan, &$translation) {
global $DB; global $DB;
// clone the database fields. // Clone the database fields.
$fields = clone $this->r; $fields = clone $this->r;
// set new studyplan id. // Set new studyplan id.
unset($fields->id); unset($fields->id);
$fields->studyplan_id = $newstudyplan->id(); $fields->studyplan_id = $newstudyplan->id();
// create new record with the new data. // Create new record with the new data.
$id = $DB->insert_record(self::TABLE, (array)$fields); $id = $DB->insert_record(self::TABLE, (array)$fields);
$new = self::findById($id); $new = self::findById($id);
// Next copy all the study items for this studyline. // Next copy all the study items for this studyline.
// and record the original and copy id's in the $translation array. // And record the original and copy id's in the $translation array.
// so the calling function can connect the new studyitems as required. // So the calling function can connect the new studyitems as required.
$children = studyitem::find_studyline_children($this); $children = studyitem::find_studyline_children($this);
$translation = []; $translation = [];
foreach ($children as $c) { foreach ($children as $c) {

View File

@ -71,9 +71,9 @@ class studyplan {
} }
public function pages() { public function pages() {
// cached version of find_studyplan_children. // Cached version of find_studyplan_children.
// (may be premature optimization, since . // (may be premature optimization, since .
// find_studyplan_children also does some caching). // Find_studyplan_children also does some caching).
if (empty($this->page_cache)) { if (empty($this->page_cache)) {
$this->page_cache = studyplanpage::find_studyplan_children($this); $this->page_cache = studyplanpage::find_studyplan_children($this);
} }
@ -180,10 +180,10 @@ class studyplan {
$model['advanced'] = []; $model['advanced'] = [];
} }
// get a list of available scales. // Get a list of available scales.
$scales = array_map( function($scale) { $scales = array_map( function($scale) {
return [ "id" => $scale->id, "name" => $scale->name, ]; return [ "id" => $scale->id, "name" => $scale->name, ];
}, \grade_scale::fetch_all(array('courseid'=>0)) ) ; }, \grade_scale::fetch_all(array('courseid'=>0)) );
$model['advanced']['force_scales'] = [ $model['advanced']['force_scales'] = [
'scales' => $scales, 'scales' => $scales,
@ -210,7 +210,7 @@ class studyplan {
// Start temporary skräpp code. // Start temporary skräpp code.
// Add a single page and copy the names.This keeps the data sane until the upgrade to . // Add a single page and copy the names.This keeps the data sane until the upgrade to .
// real page management is done. // Real page management is done.
// On import, adding an empty page messes things up for now, so we have an option to skip this.... // On import, adding an empty page messes things up for now, so we have an option to skip this....
// TODO: Remove this when proper page management is implemented. // TODO: Remove this when proper page management is implemented.
if (!$bare) { if (!$bare) {
@ -251,14 +251,14 @@ class studyplan {
//reload the context... //reload the context...
$this->context = null; $this->context = null;
$this->context(); $this->context();
// reload aggregator. // Reload aggregator.
$this->aggregator = aggregator::createOrDefault($this->r->aggregation, $this->r->aggregation_config); $this->aggregator = aggregator::createOrDefault($this->r->aggregation, $this->r->aggregation_config);
// Start temporary skräpp code. // Start temporary skräpp code.
// TODO: Until proper page editing is implemented, copy data from studyplan to it's first page. // TODO: Until proper page editing is implemented, copy data from studyplan to it's first page.
// This keeps the data sane until the upgrade is done. // This keeps the data sane until the upgrade is done.
if (count($this->pages()) == 1) { if (count($this->pages()) == 1) {
// update the info to the page as well. // Update the info to the page as well.
$page = $this->pages()[0]; $page = $this->pages()[0];
$pageeditable = ['name', 'shortname', 'description', 'periods', 'startdate', 'enddate']; $pageeditable = ['name', 'shortname', 'description', 'periods', 'startdate', 'enddate'];
$pageinfo = []; $pageinfo = [];
@ -490,7 +490,7 @@ class studyplan {
'description' => $this->r->description, 'description' => $this->r->description,
]); ]);
// next, copy the studylines. // Next, copy the studylines.
foreach ($this->pages() as $p) { foreach ($this->pages() as $p) {
$newchild = $p->duplicate($newplan); $newchild = $p->duplicate($newplan);
@ -565,7 +565,7 @@ class studyplan {
$content = json_decode($content, true); $content = json_decode($content, true);
if ($content["version"] >= 2.0) { if ($content["version"] >= 2.0) {
if ($content["type"] == "studyplanpage") { if ($content["type"] == "studyplanpage") {
// import single page from a studyplanpage (wrapped in array of one page). // Import single page from a studyplanpage (wrapped in array of one page).
return $this->import_pages_model([$content["page"]]); return $this->import_pages_model([$content["page"]]);
} else if ($content["type"] == "studyplan") { } else if ($content["type"] == "studyplan") {
// Import all pages from the studyplan. // Import all pages from the studyplan.
@ -649,7 +649,7 @@ class studyplan {
* List the cohort id's associated with this studyplan * List the cohort id's associated with this studyplan
*/ */
public function get_linked_cohort_ids() { public function get_linked_cohort_ids() {
global $CFG, $DB; global $CFG, $DB;
$sql = "SELECT DISTINCT j.cohort_id FROM {local_treestudyplan_cohort} j $sql = "SELECT DISTINCT j.cohort_id FROM {local_treestudyplan_cohort} j
WHERE j.studyplan_id = :studyplan_id"; WHERE j.studyplan_id = :studyplan_id";
@ -661,7 +661,7 @@ class studyplan {
* List the user id's explicitly associated with this studyplan * List the user id's explicitly associated with this studyplan
*/ */
public function get_linked_user_ids() { public function get_linked_user_ids() {
global $CFG, $DB; global $CFG, $DB;
$sql = "SELECT DISTINCT j.user_id FROM {local_treestudyplan_user} j $sql = "SELECT DISTINCT j.user_id FROM {local_treestudyplan_user} j
WHERE j.studyplan_id = :studyplan_id"; WHERE j.studyplan_id = :studyplan_id";

View File

@ -82,7 +82,7 @@ class studyplanpage {
if ($this->r->enddate && strlen($this->r->enddate) > 0) { if ($this->r->enddate && strlen($this->r->enddate) > 0) {
return new \DateTime($this->r->enddate); return new \DateTime($this->r->enddate);
} else{ } else{
// return a date 100 years into the future. // Return a date 100 years into the future.
return (new \DateTime($this->r->startdate))->add(new \DateInterval("P100Y")); return (new \DateTime($this->r->startdate))->add(new \DateInterval("P100Y"));
} }
@ -276,7 +276,7 @@ class studyplanpage {
'enddate' => empty($this->r->enddate)?null:$this->r->enddate, 'enddate' => empty($this->r->enddate)?null:$this->r->enddate,
]); ]);
// next, copy the studylines. // Next, copy the studylines.
$children = studyline::find_page_children($this); $children = studyline::find_page_children($this);
$itemtranslation = []; $itemtranslation = [];
@ -286,11 +286,11 @@ class studyplanpage {
$linetranslation[$c->id()] = $newchild->id(); $linetranslation[$c->id()] = $newchild->id();
} }
// now the itemtranslation array contains all of the old child id's as keys and all of the related new ids as values. // Now the itemtranslation array contains all of the old child id's as keys and all of the related new ids as values.
// (feature of the studyline::duplicate function). // (feature of the studyline::duplicate function).
// use this to recreate the lines in the new plan. // Use this to recreate the lines in the new plan.
foreach (array_keys($itemtranslation) as $itemid) { foreach (array_keys($itemtranslation) as $itemid) {
// copy based on the outgoing connections of each item, to avoid duplicates. // Copy based on the outgoing connections of each item, to avoid duplicates.
$connections = studyitemconnection::find_outgoing($itemid); $connections = studyitemconnection::find_outgoing($itemid);
foreach ($connections as $conn) { foreach ($connections as $conn) {
studyitemconnection::connect($itemtranslation[$conn->from_id], $itemtranslation[$conn->to_id]); studyitemconnection::connect($itemtranslation[$conn->from_id], $itemtranslation[$conn->to_id]);
@ -329,9 +329,9 @@ class studyplanpage {
$csv .= ", \"{$name}\""; $csv .= ", \"{$name}\"";
} }
$csv .= "\r\n"; $csv .= "\r\n";
// next, make one line per studyline. // Next, make one line per studyline.
foreach ($model["studylines"] as $line) { foreach ($model["studylines"] as $line) {
// determine how many fields are simultaneous in the line at maximum. // Determine how many fields are simultaneous in the line at maximum.
$maxlines = 1; $maxlines = 1;
for($i = 1; $i <= $periods; $i++) { for($i = 1; $i <= $periods; $i++) {
if (count($line["slots"]) > $i) { if (count($line["slots"]) > $i) {
@ -489,13 +489,11 @@ class studyplanpage {
if (empty($line)) { if (empty($line)) {
$linemodel["page_id"] = $this->id; $linemodel["page_id"] = $this->id;
$line = studyline::add($linemodel); $line = studyline::add($linemodel);
} else { }
//$line->edit($linemodel); // Update the line with the settings from the imported file.
}
$linemap[$ix] = $line; $linemap[$ix] = $line;
} }
// next, let each study line import the study items. // Next, let each study line import the study items.
$itemtranslation = []; $itemtranslation = [];
$connections = []; $connections = [];
foreach ($model as $ix => $linemodel) { foreach ($model as $ix => $linemodel) {

View File

@ -232,7 +232,7 @@ class studyplanservice extends \external_api
public static function delete_studyplan($id, $force=false) { public static function delete_studyplan($id, $force=false) {
$o = studyplan::findById($id); $o = studyplan::findById($id);
// validate if the requesting user has the right to edit the plan in it's current context. // Validate if the requesting user has the right to edit the plan in it's current context.
webservicehelper::require_capabilities(self::CAP_EDIT, $o->context()); webservicehelper::require_capabilities(self::CAP_EDIT, $o->context());
return $o->delete(!!$force)->model(); return $o->delete(!!$force)->model();
} }
@ -258,7 +258,7 @@ class studyplanservice extends \external_api
} }
public static function add_studyline($pageid, $name, $shortname, $color, $sequence) { public static function add_studyline($pageid, $name, $shortname, $color, $sequence) {
// validate if the requesting user has the right to edit the plan in it's current context. // Validate if the requesting user has the right to edit the plan in it's current context.
$page = studyplanpage::findById($pageid); $page = studyplanpage::findById($pageid);
webservicehelper::require_capabilities(self::CAP_EDIT, $page->studyplan()->context()); webservicehelper::require_capabilities(self::CAP_EDIT, $page->studyplan()->context());
@ -293,7 +293,7 @@ class studyplanservice extends \external_api
public static function edit_studyline($id, $name, $shortname, $color) { public static function edit_studyline($id, $name, $shortname, $color) {
$o = studyline::findById($id); $o = studyline::findById($id);
// validate if the requesting user has the right to edit the plan in it's current context. // Validate if the requesting user has the right to edit the plan in it's current context.
webservicehelper::require_capabilities(self::CAP_EDIT, $o->context()); webservicehelper::require_capabilities(self::CAP_EDIT, $o->context());
$o->edit([ $o->edit([
@ -324,7 +324,7 @@ class studyplanservice extends \external_api
public static function delete_studyline($id) { public static function delete_studyline($id) {
$o = studyline::findById($id); $o = studyline::findById($id);
// validate if the requesting user has the right to edit the plan in it's current context. // Validate if the requesting user has the right to edit the plan in it's current context.
webservicehelper::require_capabilities(self::CAP_EDIT, $o->context()); webservicehelper::require_capabilities(self::CAP_EDIT, $o->context());
return $o->delete()->model(); return $o->delete()->model();
@ -352,7 +352,7 @@ class studyplanservice extends \external_api
} }
public static function reorder_studylines($resequence) { public static function reorder_studylines($resequence) {
// validate if the requesting user has the right to edit the lines in it's current context. // Validate if the requesting user has the right to edit the lines in it's current context.
foreach ($resequence as $sq) { foreach ($resequence as $sq) {
$o = studyline::findById(($sq['id'])); $o = studyline::findById(($sq['id']));
webservicehelper::require_capabilities(self::CAP_EDIT, $o->context()); webservicehelper::require_capabilities(self::CAP_EDIT, $o->context());
@ -598,7 +598,7 @@ class studyplanservice extends \external_api
$result[] = (new badgeinfo($badge))->editor_model(); $result[] = (new badgeinfo($badge))->editor_model();
// }. // }.
//TODO: Include course badges somehow... Just site badges is not enough. // TODO: Include course badges somehow... Just site badges is not enough.
} }
return $result; return $result;
@ -627,13 +627,13 @@ class studyplanservice extends \external_api
public static function include_grade($gradeid, $itemid, $include, $required=false) { public static function include_grade($gradeid, $itemid, $include, $required=false) {
global $USER; global $USER;
// find related course and course context. // Find related course and course context.
$coursecontext = gradeinfo::getCourseContextById($gradeid); $coursecontext = gradeinfo::getCourseContextById($gradeid);
// do sanity checks. // Do sanity checks.
\external_api::validate_context($coursecontext); \external_api::validate_context($coursecontext);
// check correct capabilities. // Check correct capabilities.
if (has_capability('local/treestudyplan:editstudyplan', studyitem::findById($itemid)->context()) || if (has_capability('local/treestudyplan:editstudyplan', studyitem::findById($itemid)->context()) ||
is_enrolled($coursecontext, $USER, 'local/treestudyplan:selectowngradables')) { is_enrolled($coursecontext, $USER, 'local/treestudyplan:selectowngradables')) {
return gradeinfo::include_grade($gradeid, $itemid, $include, $required)->model(); return gradeinfo::include_grade($gradeid, $itemid, $include, $required)->model();
@ -694,7 +694,7 @@ class studyplanservice extends \external_api
webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::findById($studyplanid)->context()); webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::findById($studyplanid)->context());
$list = []; $list = [];
// check if scaleid is valid. // Check if scaleid is valid.
$scale = \grade_scale::fetch(['id' => $scaleid]); $scale = \grade_scale::fetch(['id' => $scaleid]);
$scale->load_items(); $scale->load_items();
@ -703,10 +703,10 @@ class studyplanservice extends \external_api
$scalepass = ($gradecfg)?$gradecfg->min_completed:0; $scalepass = ($gradecfg)?$gradecfg->min_completed:0;
$scalemax = count($scale->scale_items); $scalemax = count($scale->scale_items);
// find studyline id's. // Find studyline id's.
$studylineids = $DB->get_fieldset_select(studyline::TABLE, "id", "studyplan_id = :plan_id", ['plan_id' => $studyplanid]); $studylineids = $DB->get_fieldset_select(studyline::TABLE, "id", "studyplan_id = :plan_id", ['plan_id' => $studyplanid]);
foreach ($studylineids as $studylineid) { foreach ($studylineids as $studylineid) {
// find id's of studyitems of type course. // Find id's of studyitems of type course.
$records = $DB->get_records(studyitem::TABLE, ['line_id' => $studylineid]); $records = $DB->get_records(studyitem::TABLE, ['line_id' => $studylineid]);
foreach ($records as $itemr) { foreach ($records as $itemr) {
@ -719,9 +719,9 @@ class studyplanservice extends \external_api
foreach ($gradables as $g) { foreach ($gradables as $g) {
$gi = $g->getGradeItem(); $gi = $g->getGradeItem();
// only change items that do not yet have grades. // Only change items that do not yet have grades.
// otherwise we will need to implement grade recalculations and it is not worth the trouble. . // Otherwise we will need to implement grade recalculations and it is not worth the trouble. .
// if grades are given, you likely don't want to change it like this anyway. // If grades are given, you likely don't want to change it like this anyway.
if (!$gi->has_grades()) { if (!$gi->has_grades()) {
$gi->gradetype = GRADE_TYPE_SCALE; $gi->gradetype = GRADE_TYPE_SCALE;
@ -736,8 +736,8 @@ class studyplanservice extends \external_api
$debug = ""; $debug = "";
if ($result) { $updated = "converted";} else { $updated = "error";} if ($result) { $updated = "converted";} else { $updated = "error";}
// next update the activity's table if it has a grade field. // Next update the activity's table if it has a grade field.
// grade is generally set to the negative scale id if it is a scale. // Grade is generally set to the negative scale id if it is a scale.
$tablename = $gi->itemmodule; $tablename = $gi->itemmodule;
$fieldname = "grade"; $fieldname = "grade";
if ($result && $gi->itemtype == "mod" && $dbman->table_exists($tablename)) { if ($result && $gi->itemtype == "mod" && $dbman->table_exists($tablename)) {
@ -832,10 +832,10 @@ class studyplanservice extends \external_api
// Validate permissions. // Validate permissions.
webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::findById($studyplanid)->context()); webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::findById($studyplanid)->context());
// find studyline id's. // Find studyline id's.
$studylineids = $DB->get_fieldset_select(studyline::TABLE, "id", "studyplan_id = :plan_id", ['plan_id' => $studyplanid]); $studylineids = $DB->get_fieldset_select(studyline::TABLE, "id", "studyplan_id = :plan_id", ['plan_id' => $studyplanid]);
foreach ($studylineids as $studylineid) { foreach ($studylineids as $studylineid) {
// find id's of studyitems of type course. // Find id's of studyitems of type course.
$records = $DB->get_records(studyitem::TABLE, ['line_id' => $studylineid]); $records = $DB->get_records(studyitem::TABLE, ['line_id' => $studylineid]);
foreach ($records as $itemr) { foreach ($records as $itemr) {
@ -1029,10 +1029,10 @@ class studyplanservice extends \external_api
// Check the course exists. // Check the course exists.
$course = \get_course($cm->course); $course = \get_course($cm->course);
// require_login. // Require_login.
require_login($course, false, $cm); // needed to setup proper $COURSE. require_login($course, false, $cm); // needed to setup proper $COURSE.
// get needed info to create the correct form. // Get needed info to create the correct form.
list($cm, $context, $module, $data, $cw) = \get_moduleinfo_data($cm, $course); list($cm, $context, $module, $data, $cw) = \get_moduleinfo_data($cm, $course);
$modmoodleform = "$CFG->dirroot/mod/$module->name/mod_form.php"; $modmoodleform = "$CFG->dirroot/mod/$module->name/mod_form.php";
if (file_exists($modmoodleform)) { if (file_exists($modmoodleform)) {
@ -1042,14 +1042,14 @@ class studyplanservice extends \external_api
} }
$mformclassname = 'mod_'.$module->name.'_mod_form'; $mformclassname = 'mod_'.$module->name.'_mod_form';
// now hack the received data into $_POST, so the mform thinks it has been submitted "normally". // Now hack the received data into $_POST, so the mform thinks it has been submitted "normally".
foreach (explode("&", $formdata) as $pair) { foreach (explode("&", $formdata) as $pair) {
$p = explode("=", $pair, 2); $p = explode("=", $pair, 2);
$k = urldecode($p[0]); $k = urldecode($p[0]);
$v = (count($p)>1)?urldecode($p[1]):""; $v = (count($p)>1)?urldecode($p[1]):"";
if (strpos($k, "[") > 0 && strpos($k, "]") == strlen($k) -1) { if (strpos($k, "[") > 0 && strpos($k, "]") == strlen($k) -1) {
// its a bracketet field, like filename[text] which should be separated and put into a named array. // Its a bracketet field, like filename[text] which should be separated and put into a named array.
list($k, $h) = explode("[", $k, 2); list($k, $h) = explode("[", $k, 2);
if (strlen($k) > 0 && strlen($h) > 1) { if (strlen($k) > 0 && strlen($h) > 1) {
$h = rtrim($h, "]"); $h = rtrim($h, "]");
@ -1064,7 +1064,7 @@ class studyplanservice extends \external_api
} }
// Now create the mform and update the module... // Now create the mform and update the module...
// update_moduleinfo() actually needs the mform somehow. Hence the ugly hacks. // Update_moduleinfo() actually needs the mform somehow. Hence the ugly hacks.
$mform = new $mformclassname($data, $cw->section, $cm, $course); $mform = new $mformclassname($data, $cw->section, $cm, $course);
$mform->set_data($data); $mform->set_data($data);
@ -1173,12 +1173,12 @@ class studyplanservice extends \external_api
'reset_start_date_old' => $course->startdate, 'reset_start_date_old' => $course->startdate,
'reset_end_date_old' => $course->enddate, 'reset_end_date_old' => $course->enddate,
]); ]);
// purge course cache so the dates are properly reflected. // Purge course cache so the dates are properly reflected.
\course_modinfo::purge_course_cache($course->id); \course_modinfo::purge_course_cache($course->id);
return (new courseinfo($course->id))->editor_model(); return (new courseinfo($course->id))->editor_model();
} else { } else {
// probably should return a nice message. // Probably should return a nice message.
throw new \webservice_access_exception("You do not have date change permissions on this course"); throw new \webservice_access_exception("You do not have date change permissions on this course");
} }
} }

View File

@ -47,7 +47,7 @@ class autocohortsync extends \core\task\scheduled_task {
foreach ($studyplans as $studyplan) { foreach ($studyplans as $studyplan) {
// Only process studyplans that have been marked for change because . // Only process studyplans that have been marked for change because .
// a cohort change has occurred or a course has been added.... // A cohort change has occurred or a course has been added....
if ($studyplan->has_csync_changed()) { if ($studyplan->has_csync_changed()) {
\mtrace("Studyplan {$studyplan->shortname()} needs processing"); \mtrace("Studyplan {$studyplan->shortname()} needs processing");
$enroller = new cascadecohortsync($studyplan); $enroller = new cascadecohortsync($studyplan);

View File

@ -32,7 +32,7 @@ class teachingfinder {
$records = $DB->get_records(self::TABLE, ['teacher_id' => $userid]); $records = $DB->get_records(self::TABLE, ['teacher_id' => $userid]);
if (count($records) == 0) { if (count($records) == 0) {
// initiate a search if the cache is empty. // Initiate a search if the cache is empty.
self::update_teaching_cache($userid); self::update_teaching_cache($userid);
$DB->get_records(self::TABLE, ['teacher_id' => $userid]); $DB->get_records(self::TABLE, ['teacher_id' => $userid]);
} }
@ -59,7 +59,7 @@ class teachingfinder {
WHERE startdate <= NOW() and enddate >= NOW()"; WHERE startdate <= NOW() and enddate >= NOW()";
$pageids = $DB->get_fieldset_sql($sql, []); $pageids = $DB->get_fieldset_sql($sql, []);
// then parse them to see if the user has the grading permission in any of them . // Then parse them to see if the user has the grading permission in any of them .
// (Which would make them a teacher for all intents and purposes). // (Which would make them a teacher for all intents and purposes).
foreach ($pageids as $pageid) { foreach ($pageids as $pageid) {

12
doc.php
View File

@ -37,17 +37,17 @@ $file = $CFG->dirroot."/local/treestudyplan/doc".$pi;
// Fallback to index. // Fallback to index.
if (!file_exists($file)) { if (!file_exists($file)) {
$file = $CFG->dirroot."/local/treestudyplan/doc/index.htm"; $file = $CFG->dirroot."/local/treestudyplan/doc/index.htm";
} }
$mime = mime_content_type($file); $mime = mime_content_type($file);
$texttypes = ["text/html", "text/plain"]; $texttypes = ["text/html", "text/plain"];
if ( in_array($mime, $texttypes)) { if ( in_array($mime, $texttypes)) {
print $OUTPUT->header(); print $OUTPUT->header();
print file_get_contents($file); print file_get_contents($file);
print $OUTPUT->footer(); print $OUTPUT->footer();
} else { } else {
header("Content-type: {$mime}"); header("Content-type: {$mime}");
print file_get_contents($file); print file_get_contents($file);
} }

View File

@ -38,11 +38,11 @@ $PAGE->set_pagelayout('base');
$PAGE->set_context($systemcontext); $PAGE->set_context($systemcontext);
if ($update > 0) { if ($update > 0) {
$PAGE->set_title(get_string('invite_desc_edit', 'local_treestudyplan')); $PAGE->set_title(get_string('invite_desc_edit', 'local_treestudyplan'));
$PAGE->set_heading(get_string('invite_desc_edit', 'local_treestudyplan')); $PAGE->set_heading(get_string('invite_desc_edit', 'local_treestudyplan'));
} else { } else {
$PAGE->set_title(get_string('invite_desc_new', 'local_treestudyplan')); $PAGE->set_title(get_string('invite_desc_new', 'local_treestudyplan'));
$PAGE->set_heading(get_string('invite_desc_new', 'local_treestudyplan')); $PAGE->set_heading(get_string('invite_desc_new', 'local_treestudyplan'));
} }
@ -52,104 +52,104 @@ require_login();
print $OUTPUT->header(); print $OUTPUT->header();
if (!empty($add)) { if (!empty($add)) {
$data = array( $data = array(
'add' => 1, 'add' => 1,
); );
} else if (!empty($update)) { } else if (!empty($update)) {
$data = $DB->get_record("local_treestudyplan_invit", array('id' => $update)); $data = $DB->get_record("local_treestudyplan_invit", array('id' => $update));
$data->update = $update; $data->update = $update;
if (empty($data) || $data->user_id != $USER->id) if (empty($data) || $data->user_id != $USER->id)
{ {
print_error('invalidaction'); print_error('invalidaction');
exit; exit;
} }
} else if (!empty($resend)) { } else if (!empty($resend)) {
$data = $DB->get_record("local_treestudyplan_invit", array('id' => $resend)); $data = $DB->get_record("local_treestudyplan_invit", array('id' => $resend));
$data->resend = $resend; $data->resend = $resend;
if (empty($data) || $data->user_id != $USER->id) if (empty($data) || $data->user_id != $USER->id)
{ {
print_error('invalidaction'); print_error('invalidaction');
exit; exit;
} }
// Do some resending of an invitation. // Do some resending of an invitation.
local_treestudyplan_send_invite($data->id); local_treestudyplan_send_invite($data->id);
redirect("$CFG->wwwroot/local/treestudyplan/invitations.php?sent={$resend}"); redirect("$CFG->wwwroot/local/treestudyplan/invitations.php?sent={$resend}");
print $OUTPUT->footer(); print $OUTPUT->footer();
exit; exit;
} else if (!empty($delete)) { } else if (!empty($delete)) {
$data = $DB->get_record("local_treestudyplan_invit", array('id' => $delete)); $data = $DB->get_record("local_treestudyplan_invit", array('id' => $delete));
$data->delete = $delete; $data->delete = $delete;
if (empty($data) || $data->user_id != $USER->id) if (empty($data) || $data->user_id != $USER->id)
{ {
print_error('invalidaction'); print_error('invalidaction');
exit; exit;
} }
$DB->delete_records('local_treestudyplan_invit', ['id' => $data->delete]); $DB->delete_records('local_treestudyplan_invit', ['id' => $data->delete]);
redirect("$CFG->wwwroot/local/treestudyplan/invitations.php"); redirect("$CFG->wwwroot/local/treestudyplan/invitations.php");
print $OUTPUT->footer(); print $OUTPUT->footer();
exit; exit;
} else { } else {
print_error('invalidaction'); print_error('invalidaction');
} }
$mform = new reportinvite_form(); $mform = new reportinvite_form();
$mform->set_data($data); $mform->set_data($data);
if ($mform->is_cancelled()) { if ($mform->is_cancelled()) {
redirect("$CFG->wwwroot/local/treestudyplan/invitations.php"); redirect("$CFG->wwwroot/local/treestudyplan/invitations.php");
} else if ($data = $mform->get_data()) { } else if ($data = $mform->get_data()) {
if (!empty($data->update)) if (!empty($data->update))
{ {
$id = $data->update; $id = $data->update;
$data->id = $id; $data->id = $id;
$DB->update_record('local_treestudyplan_invit', $data); $DB->update_record('local_treestudyplan_invit', $data);
redirect("$CFG->wwwroot/local/treestudyplan/invitations.php"); redirect("$CFG->wwwroot/local/treestudyplan/invitations.php");
} }
else if (!empty($data->add)) else if (!empty($data->add))
{ {
$id = $DB->insert_record("local_treestudyplan_invit", $data, true); $id = $DB->insert_record("local_treestudyplan_invit", $data, true);
// Send invitaion mail. // Send invitaion mail.
local_treestudyplan_send_invite($id); local_treestudyplan_send_invite($id);
redirect("$CFG->wwwroot/local/treestudyplan/invitations.php?sent={$id}"); redirect("$CFG->wwwroot/local/treestudyplan/invitations.php?sent={$id}");
} }
else if (!empty($data->resend)) else if (!empty($data->resend))
{ {
} }
else if (!empty($data->delete)) else if (!empty($data->delete))
{ {
} }
else else
{ {
print_error("invaliddata"); print_error("invaliddata");
} }
exit; exit;
} else { } else {
$data = null; $data = null;
if ($unitid > 0) if ($unitid > 0)
{ {
} }
$mform->display(); $mform->display();
} }

View File

@ -35,32 +35,32 @@ require_login();
$categoryid = optional_param('categoryid', 0, PARAM_INT); // Category id. $categoryid = optional_param('categoryid', 0, PARAM_INT); // Category id.
$contextid = optional_param('contextid', 0, PARAM_INT); // Context id. $contextid = optional_param('contextid', 0, PARAM_INT); // Context id.
if ($categoryid > 0) { if ($categoryid > 0) {
$studyplancontext = context_coursecat::instance($categoryid); $studyplancontext = context_coursecat::instance($categoryid);
} else if ($contextid > 0) { } else if ($contextid > 0) {
$studyplancontext = context::instance_by_id($contextid); $studyplancontext = context::instance_by_id($contextid);
if (in_array($studyplancontext->contextlevel, [CONTEXT_SYSTEM, CONTEXT_COURSECAT])) if (in_array($studyplancontext->contextlevel, [CONTEXT_SYSTEM, CONTEXT_COURSECAT]))
{ {
$categoryid = $studyplancontext->instanceid; $categoryid = $studyplancontext->instanceid;
} }
else else
{ {
$studyplancontext = $systemcontext; $studyplancontext = $systemcontext;
} }
} else { } else {
// If no context is selected, find the first available one. // If no context is selected, find the first available one.
$availablecontexts = courseservice::list_accessible_categories_with_usage("edit"); $availablecontexts = courseservice::list_accessible_categories_with_usage("edit");
$contextid=1; // fallback to system context. $contextid=1; // fallback to system context.
foreach ($availablecontexts as $ctx) { foreach ($availablecontexts as $ctx) {
if ($ctx->count > 0) { if ($ctx->count > 0) {
$contextid = $ctx->ctxid; $contextid = $ctx->ctxid;
break; break;
} }
} }
// reload page with selected category. // Reload page with selected category.
$url = new \moodle_url('/local/treestudyplan/edit-plan.php', ["contextid" => $contextid]); $url = new \moodle_url('/local/treestudyplan/edit-plan.php', ["contextid" => $contextid]);
header('Location: '.$url->out(false), true, 302); header('Location: '.$url->out(false), true, 302);
exit; exit;
} }
require_capability('local/treestudyplan:editstudyplan', $studyplancontext); require_capability('local/treestudyplan:editstudyplan', $studyplancontext);
@ -72,8 +72,8 @@ $PAGE->set_title(get_string('cfg_plans', 'local_treestudyplan')." - ".$contextna
$PAGE->set_heading($contextname); $PAGE->set_heading($contextname);
if ($studyplancontext->id > 1) { if ($studyplancontext->id > 1) {
navigation_node::override_active_url(new moodle_url('/course/index.php', ['categoryid' => $categoryid ])); navigation_node::override_active_url(new moodle_url('/course/index.php', ['categoryid' => $categoryid ]));
$PAGE->navbar->add(get_string('cfg_plans', 'local_treestudyplan')); $PAGE->navbar->add(get_string('cfg_plans', 'local_treestudyplan'));
} }
@ -86,9 +86,9 @@ $PAGE->requires->js_call_amd('local_treestudyplan/page-edit-plan', 'init', [$stu
$catlist = courseservice::list_accessible_categories_with_usage("edit"); $catlist = courseservice::list_accessible_categories_with_usage("edit");
//Local translate function. // Local translate function.
function t($str, $param=null, $plugin='local_treestudyplan') { function t($str, $param=null, $plugin='local_treestudyplan') {
print get_string($str, $plugin, $param); print get_string($str, $plugin, $param);
} }
print $OUTPUT->header(); print $OUTPUT->header();
@ -97,121 +97,121 @@ print $OUTPUT->header();
?> ?>
<div id='root'> <div id='root'>
<div class='vue-loader' v-show='false'> <div class='vue-loader' v-show='false'>
<div class="spinner-border text-primary" role="status"> <div class="spinner-border text-primary" role="status">
<span class="sr-only">Loading...</span> <span class="sr-only">Loading...</span>
</div> </div>
</div> </div>
<div v-cloak> <div v-cloak>
<div v-if='!activestudyplan && usedcontexts' class='ml-3 mb-3'> <div v-if='!activestudyplan && usedcontexts' class='ml-3 mb-3'>
<b-form-select text='<?php print($contextname);?>' :value="contextid"> <b-form-select text='<?php print($contextname);?>' :value="contextid">
<b-form-select-option v-for='ctx in usedcontexts' :key='ctx.id' :value="ctx.context_id" @click='switchContext(ctx)' <b-form-select-option v-for='ctx in usedcontexts' :key='ctx.id' :value="ctx.context_id" @click='switchContext(ctx)'
:active="ctx.context_id == contextid" :class="(ctx.studyplancount > 0)?'font-weight-bold':''" :active="ctx.context_id == contextid" :class="(ctx.studyplancount > 0)?'font-weight-bold':''"
><span v-for="(p, i) in ctx.category.path"><span v-if="i>0"> / </span>{{ p }}</span> <span>({{ ctx.studyplancount }})</b-form-select-option> ><span v-for="(p, i) in ctx.category.path"><span v-if="i>0"> / </span>{{ p }}</span> <span>({{ ctx.studyplancount }})</b-form-select-option>
</b-form-select> </b-form-select>
</div> </div>
<h3 v-else><?php print $contextname; ?></h3> <h3 v-else><?php print $contextname; ?></h3>
<div class="m-buttonbar" style="margin-bottom: 1em;"> <div class="m-buttonbar" style="margin-bottom: 1em;">
<a href='#' v-if='activestudyplan' @click.prevent='closeStudyplan'><i style='font-size: 150%;' class='fa fa-chevron-left'></i> <?php t('back');?></a> <a href='#' v-if='activestudyplan' @click.prevent='closeStudyplan'><i style='font-size: 150%;' class='fa fa-chevron-left'></i> <?php t('back');?></a>
<span v-if='activestudyplan'><?php t("studyplan_select"); ?></span>&nbsp; <span v-if='activestudyplan'><?php t("studyplan_select"); ?></span>&nbsp;
<b-form-select v-if='activestudyplan' lazy :text='dropdown_title' v-model='activestudyplan.id'> <b-form-select v-if='activestudyplan' lazy :text='dropdown_title' v-model='activestudyplan.id'>
<b-form-select-option v-for='(studyplan, planindex) in studyplans' :value="studyplan.id" :key='studyplan.id' @click='selectStudyplan(studyplan)'>{{ studyplan.name }}</b-form-select-option> <b-form-select-option v-for='(studyplan, planindex) in studyplans' :value="studyplan.id" :key='studyplan.id' @click='selectStudyplan(studyplan)'>{{ studyplan.name }}</b-form-select-option>
</b-form-select>&nbsp; </b-form-select>&nbsp;
<t-studyplan-edit <t-studyplan-edit
@creating="" @creating=""
@created="onStudyPlanCreated" @created="onStudyPlanCreated"
v-if='!activestudyplan && !loadingstudyplan' v-if='!activestudyplan && !loadingstudyplan'
mode="create" mode="create"
v-model="create.studyplan" v-model="create.studyplan"
type="button" type="button"
variant="primary" variant="primary"
:contextid='contextid' :contextid='contextid'
><i class='fa fa-plus'></i> <?php t("studyplan_add");?></t-studyplan-edit> ><i class='fa fa-plus'></i> <?php t("studyplan_add");?></t-studyplan-edit>
<b-button v-if='!activestudyplan && !loadingstudyplan' variant='danger' href='#' role='presentation' @click="import_studyplan "><i class='fa fa-upload'></i> <?php t("advanced_import_from_file");?></b-button> <b-button v-if='!activestudyplan && !loadingstudyplan' variant='danger' href='#' role='presentation' @click="import_studyplan "><i class='fa fa-upload'></i> <?php t("advanced_import_from_file");?></b-button>
<b-button v-if='activestudyplan' variant='primary' v-b-toggle.toolbox-sidebar><?php t('opentoolbox') ?></b-button> <b-button v-if='activestudyplan' variant='primary' v-b-toggle.toolbox-sidebar><?php t('opentoolbox') ?></b-button>
</div> </div>
<div class='t-studyplan-container'> <div class='t-studyplan-container'>
<t-studyplan v-if='activestudyplan' v-model='activestudyplan' @moved="movedStudyplan"></t-studyplan> <t-studyplan v-if='activestudyplan' v-model='activestudyplan' @moved="movedStudyplan"></t-studyplan>
<div v-else-if='loadingstudyplan' class="spinner-border text-primary" role="status"> <div v-else-if='loadingstudyplan' class="spinner-border text-primary" role="status">
<span class="sr-only">Loading...</span> <span class="sr-only">Loading...</span>
</div> </div>
<div v-else class='t-studyplan-notselected'> <div v-else class='t-studyplan-notselected'>
<p><?php t("studyplan_noneselected"); ?></p> <p><?php t("studyplan_noneselected"); ?></p>
<b-card-group deck> <b-card-group deck>
<s-studyplan-card <s-studyplan-card
v-for='(studyplan, planindex) in studyplans' v-for='(studyplan, planindex) in studyplans'
:key='studyplan.id' :key='studyplan.id'
v-model='studyplans[planindex]' v-model='studyplans[planindex]'
open open
@open='selectStudyplan(studyplan)' @open='selectStudyplan(studyplan)'
> >
<template #title> <template #title>
<span class='s-studyplan-card-title-buttons'> <span class='s-studyplan-card-title-buttons'>
<a href='#' @click.prevent="export_plan(studyplan)" ><i class='fa fa-download'></i></a> <a href='#' @click.prevent="export_plan(studyplan)" ><i class='fa fa-download'></i></a>
<t-studyplan-edit v-model="studyplans[planindex]" @moved="movedStudyplan"></t-studyplan-edit> <t-studyplan-edit v-model="studyplans[planindex]" @moved="movedStudyplan"></t-studyplan-edit>
<t-studyplan-associate v-model="studyplans[planindex]"></t-studyplan-associate> <t-studyplan-associate v-model="studyplans[planindex]"></t-studyplan-associate>
</span> </span>
</template> </template>
</s-studyplan-card> </s-studyplan-card>
</b-card-group> </b-card-group>
</div> </div>
</div> </div>
<b-sidebar <b-sidebar
id="toolbox-sidebar" id="toolbox-sidebar"
:right='toolbox.right' :right='toolbox.right'
shadow shadow
title='<?php t("toolbox")?>' title='<?php t("toolbox")?>'
> >
<div class='t-toolbox-preface'> <div class='t-toolbox-preface'>
<b-form-checkbox v-model="toolbox.right" switch><?php t("toolbar-right");?></b-form-checkbox> <b-form-checkbox v-model="toolbox.right" switch><?php t("toolbar-right");?></b-form-checkbox>
</div> </div>
<b-tabs content-class='mt-3'> <b-tabs content-class='mt-3'>
<b-tab title="<?php t('courses')?>"> <b-tab title="<?php t('courses')?>">
<t-coursecat-list v-model="courses"></t-coursecat-list> <t-coursecat-list v-model="courses"></t-coursecat-list>
</b-tab> </b-tab>
<b-tab title="<?php t('toolbox')?>"> <b-tab title="<?php t('toolbox')?>">
<ul class="t-toolbox"> <ul class="t-toolbox">
<li><drag <li><drag
:type="filterComponentType" :type="filterComponentType"
:data="{type: 'junction'}" :data="{type: 'junction'}"
@cut="" @cut=""
><t-item-junction></t-item-junction><?php t("tool-junction") ?> ><t-item-junction></t-item-junction><?php t("tool-junction") ?>
<template v-slot:drag-image="{data}"><t-item-junction></t-item-junction></template> <template v-slot:drag-image="{data}"><t-item-junction></t-item-junction></template>
</drag></li> </drag></li>
<li><drag <li><drag
:type="filterComponentType" :type="filterComponentType"
:data="{type: 'finish'}" :data="{type: 'finish'}"
@cut="" @cut=""
><t-item-finish></t-item-finish><?php t("tool-finish") ?> ><t-item-finish></t-item-finish><?php t("tool-finish") ?>
<template v-slot:drag-image="{data}"><t-item-finish></t-item-finish></template> <template v-slot:drag-image="{data}"><t-item-finish></t-item-finish></template>
</drag></li> </drag></li>
<li><drag <li><drag
:type="filterComponentType" :type="filterComponentType"
:data="{type: 'start'}" :data="{type: 'start'}"
@cut="" @cut=""
><t-item-start></t-item-start><?php t("tool-start") ?> ><t-item-start></t-item-start><?php t("tool-start") ?>
<template v-slot:drag-image="{data}"><t-item-start></t-item-start></template> <template v-slot:drag-image="{data}"><t-item-start></t-item-start></template>
</drag></li> </drag></li>
</ul> </ul>
</b-tab> </b-tab>
<b-tab title="<?php t('badges')?>"> <b-tab title="<?php t('badges')?>">
<ul class="t-badges"> <ul class="t-badges">
<li v-for="b in badges"><img :src="b.imageurl" :alt="b.name"><drag <li v-for="b in badges"><img :src="b.imageurl" :alt="b.name"><drag
class="t-badge-drag" class="t-badge-drag"
:type="filterComponentType" :type="filterComponentType"
:data="{type: 'badge', badge: b}" :data="{type: 'badge', badge: b}"
@cut="" @cut=""
>{{b.name}} >{{b.name}}
<template v-slot:drag-image="{data}"><img :src="b.imageurl" :alt="b.name"></template> <template v-slot:drag-image="{data}"><img :src="b.imageurl" :alt="b.name"></template>
</drag></li> </drag></li>
</ul> </ul>
</b-tab> </b-tab>
</b-tabs> </b-tabs>
</b-sidebar> </b-sidebar>
</div> </div>
</div> </div>
<?php <?php

View File

@ -21,13 +21,13 @@
*/ */
if (isset($_SERVER['SCRIPT_FILENAME'])) { if (isset($_SERVER['SCRIPT_FILENAME'])) {
// If SCRIPT_FILENAME is set, use that so the symlinked directories the developmen environment uses are handled correctly. // If SCRIPT_FILENAME is set, use that so the symlinked directories the developmen environment uses are handled correctly.
$root = dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME']))); $root = dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME'])));
error_log("Using {$root}/config.php"); error_log("Using {$root}/config.php");
require_once($root."/config.php"); require_once($root."/config.php");
} else { } else {
// If not, assume the cwd is not symlinked and proceed as we are used to. // If not, assume the cwd is not symlinked and proceed as we are used to.
require_once("../../config.php"); require_once("../../config.php");
} }
require_once($CFG->libdir.'/weblib.php'); require_once($CFG->libdir.'/weblib.php');
@ -37,7 +37,7 @@ use local_treestudyplan;
$INVITEDURL = "/local/treestudyplan/invited.php"; $INVITEDURL = "/local/treestudyplan/invited.php";
//admin_externalpage_setup('major');. // Admin_externalpage_setup('major');.
$systemcontext = context_system::instance(); $systemcontext = context_system::instance();
$PAGE->set_url("/local/treestudyplan/invitations.php", array()); $PAGE->set_url("/local/treestudyplan/invitations.php", array());
@ -55,8 +55,8 @@ $PAGE->requires->js_call_amd('local_treestudyplan/buttonlinks', 'init');
// retrieve list of courses that the student is enrolled in. // retrieve list of courses that the student is enrolled in.
$sent = optional_param('sent', '', PARAM_INT); $sent = optional_param('sent', '', PARAM_INT);
if (!empty($sent)) { if (!empty($sent)) {
$invite = $DB->get_record('local_treestudyplan_invit', array('id' => $sent)); $invite = $DB->get_record('local_treestudyplan_invit', array('id' => $sent));
\core\notification::success(get_string('invite_resent_msg', 'local_treestudyplan', $invite)); \core\notification::success(get_string('invite_resent_msg', 'local_treestudyplan', $invite));
}; };
@ -77,34 +77,34 @@ print "</thead>";
print "<tbody>"; print "<tbody>";
if (count($invites) > 0) { if (count($invites) > 0) {
foreach ($invites as $invite) foreach ($invites as $invite)
{ {
$testlink = $INVITEDURL."?key={$invite->invitekey}"; $testlink = $INVITEDURL."?key={$invite->invitekey}";
print "<tr data-id='{$invite->id}'>"; print "<tr data-id='{$invite->id}'>";
print "<td data-field='name'>{$invite->name}</td>"; print "<td data-field='name'>{$invite->name}</td>";
print "<td data-field='email'>{$invite->email}</td>"; print "<td data-field='email'>{$invite->email}</td>";
print "<td data-field='date'>".userdate($invite->idate, "%x")."</td>"; print "<td data-field='date'>".userdate($invite->idate, "%x")."</td>";
print "<td data-field='control'>"; print "<td data-field='control'>";
print "<a class='m-action-view ' href='{$testlink}' title='".get_string('invite_tooltip_testlink', 'local_treestudyplan')."'><i class='fa fa-eye'></i></a>"; print "<a class='m-action-view ' href='{$testlink}' title='".get_string('invite_tooltip_testlink', 'local_treestudyplan')."'><i class='fa fa-eye'></i></a>";
print "<a class='m-action-resend m-action-confirm'"; print "<a class='m-action-resend m-action-confirm'";
print " data-confirmtext='".get_string('invite_confirm_resend', 'local_treestudyplan', $invite->name)."'"; print " data-confirmtext='".get_string('invite_confirm_resend', 'local_treestudyplan', $invite->name)."'";
print " data-confirmbtn='".get_string('send', 'local_treestudyplan')."'"; print " data-confirmbtn='".get_string('send', 'local_treestudyplan')."'";
print " href='#' data-actionhref='edit-invite.php?resend={$invite->id}' title='".get_string('invite_tooltip_resend', 'local_treestudyplan')."'"; print " href='#' data-actionhref='edit-invite.php?resend={$invite->id}' title='".get_string('invite_tooltip_resend', 'local_treestudyplan')."'";
print " ><i class='fa fa-envelope'></i></a>"; print " ><i class='fa fa-envelope'></i></a>";
print "<a href='edit-invite.php?update={$invite->id}'><i class='fa fa-pencil' title='".get_string('invite_tooltip_edit', 'local_treestudyplan')."'></i></a>"; print "<a href='edit-invite.php?update={$invite->id}'><i class='fa fa-pencil' title='".get_string('invite_tooltip_edit', 'local_treestudyplan')."'></i></a>";
print "<a class='m-action-delete m-action-confirm'"; print "<a class='m-action-delete m-action-confirm'";
print " data-confirmtext='".get_string('invite_confirm_delete', 'local_treestudyplan', $invite->name)."'"; print " data-confirmtext='".get_string('invite_confirm_delete', 'local_treestudyplan', $invite->name)."'";
print " data-confirmbtn='".get_string('delete')."'"; print " data-confirmbtn='".get_string('delete')."'";
print " href='#' data-actionhref='edit-invite.php?delete={$invite->id}' title='".get_string('invite_tooltip_delete', 'local_treestudyplan')."'"; print " href='#' data-actionhref='edit-invite.php?delete={$invite->id}' title='".get_string('invite_tooltip_delete', 'local_treestudyplan')."'";
print " ><i class='fa fa-trash'></i></a>"; print " ><i class='fa fa-trash'></i></a>";
print "</td>"; print "</td>";
} }
} else { } else {
print "<tr><td colspan='6'>".get_string('invite_table_empty', 'local_treestudyplan')."</td></tr>"; print "<tr><td colspan='6'>".get_string('invite_table_empty', 'local_treestudyplan')."</td></tr>";
} }
print "</tbody></table>"; print "</tbody></table>";

View File

@ -22,9 +22,9 @@
require_once("../../config.php"); require_once("../../config.php");
//Local translate function. // Local translate function.
function t($str, $param=null, $plugin='local_treestudyplan') { function t($str, $param=null, $plugin='local_treestudyplan') {
print get_string($str, $plugin, $param); print get_string($str, $plugin, $param);
} }
$systemcontext = context_system::instance(); $systemcontext = context_system::instance();
@ -38,46 +38,46 @@ $PAGE->set_url("/local/treestudyplan/invited.php", array('key' => $invitekey));
$invite = $DB->get_record_select("local_treestudyplan_invit", $DB->sql_compare_text("invitekey"). " = " . $DB->sql_compare_text(":invitekey"), ['invitekey' => $invitekey]); $invite = $DB->get_record_select("local_treestudyplan_invit", $DB->sql_compare_text("invitekey"). " = " . $DB->sql_compare_text(":invitekey"), ['invitekey' => $invitekey]);
if (empty($invite)) { if (empty($invite)) {
$PAGE->set_title(get_string('invalid_invitekey_title', 'local_treestudyplan')); $PAGE->set_title(get_string('invalid_invitekey_title', 'local_treestudyplan'));
$PAGE->set_heading(get_string('invalid_invitekey_title', 'local_treestudyplan')); $PAGE->set_heading(get_string('invalid_invitekey_title', 'local_treestudyplan'));
print $OUTPUT->header(); print $OUTPUT->header();
// render page for skill level 0 (global). // Render page for skill level 0 (global).
print "<div class='box errorbox alert alert-danger'>"; print "<div class='box errorbox alert alert-danger'>";
print get_string('invalid_invitekey_error', 'local_treestudyplan'); print get_string('invalid_invitekey_error', 'local_treestudyplan');
print "</div>"; print "</div>";
print $OUTPUT->footer(); print $OUTPUT->footer();
exit; exit;
} else { } else {
// Load javascripts and specific css. // Load javascripts and specific css.
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/bootstrap-vue/bootstrap-vue.css')); $PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/bootstrap-vue/bootstrap-vue.css'));
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devstyles.css')); $PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devstyles.css'));
$PAGE->requires->js_call_amd('local_treestudyplan/page-myreport', 'init', ['invited', $invitekey]); $PAGE->requires->js_call_amd('local_treestudyplan/page-myreport', 'init', ['invited', $invitekey]);
$student = $DB->get_record('user', array('id' => $invite->user_id)); $student = $DB->get_record('user', array('id' => $invite->user_id));
$PAGE->set_title(get_string('report_invited', 'local_treestudyplan', "{$student->firstname} {$student->lastname}" )); $PAGE->set_title(get_string('report_invited', 'local_treestudyplan', "{$student->firstname} {$student->lastname}" ));
$PAGE->set_heading(get_string('report_invited', 'local_treestudyplan', "{$student->firstname} {$student->lastname}")); $PAGE->set_heading(get_string('report_invited', 'local_treestudyplan', "{$student->firstname} {$student->lastname}"));
print $OUTPUT->header(); print $OUTPUT->header();
?> ?>
<div id='root'> <div id='root'>
<div class='vue-loader' v-show='false'> <div class='vue-loader' v-show='false'>
<div class="spinner-border text-primary" role="status"> <div class="spinner-border text-primary" role="status">
<span class="sr-only">Loading...</span> <span class="sr-only">Loading...</span>
</div> </div>
</div> </div>
<div v-cloak> <div v-cloak>
<r-report v-model="studyplans" :guestmode="true"></r-report> <r-report v-model="studyplans" :guestmode="true"></r-report>
</div> </div>
</div> </div>
<?php <?php
print $OUTPUT->footer(); print $OUTPUT->footer();
} }

410
lib.php
View File

@ -34,149 +34,149 @@ function local_treestudyplan_unit_get_editor_options($context) {
function local_treestudyplan_extend_navigation(global_navigation $navigation) { function local_treestudyplan_extend_navigation(global_navigation $navigation) {
global $CFG, $PAGE, $COURSE, $USER; global $CFG, $PAGE, $COURSE, $USER;
$systemcontext = context_system::instance(); $systemcontext = context_system::instance();
// Moodle 4.0-4.2 do not yet support customizing the primary navigation bar (it is a planned feature though). // Moodle 4.0-4.2 do not yet support customizing the primary navigation bar (it is a planned feature though).
// For now, go to theme settings and add the following into "Custom menu items". // For now, go to theme settings and add the following into "Custom menu items".
// [your name for my studyplan]|/local/treestudyplan/myreport.php. // [your name for my studyplan]|/local/treestudyplan/myreport.php.
// [your name for studyplan viewing]|/local/treestudyplan/view-plan.php. // [your name for studyplan viewing]|/local/treestudyplan/view-plan.php.
// [your name for studyplan managing]|/local/treestudyplan/edit-plan.php. // [your name for studyplan managing]|/local/treestudyplan/edit-plan.php.
// For example:. // For example:.
// Mijn studieplan|/local/treestudyplan/myreport.php. // Mijn studieplan|/local/treestudyplan/myreport.php.
// Studieplannen|/local/treestudyplan/view-plan.php. // Studieplannen|/local/treestudyplan/view-plan.php.
// Studieplannen beheren|/local/treestudyplan/edit-plan.php. // Studieplannen beheren|/local/treestudyplan/edit-plan.php.
// Using some javascript magic we'll hide the links that are not accessible. // Using some javascript magic we'll hide the links that are not accessible.
// (Since the Output API does not easily support inline style tags, adding one through Javascript is easier,. // (Since the Output API does not easily support inline style tags, adding one through Javascript is easier,.
// and not much more complex than loading a separate stylesheet for each link we want to hide). // and not much more complex than loading a separate stylesheet for each link we want to hide).
// we will add all the hrefs that should be hidden to this variable below. // We will add all the hrefs that should be hidden to this variable below.
$hideprimary_hrefs = []; $hideprimary_hrefs = [];
if ($USER->id > 1) // Don't show if user is not logged in (id == 0) or is guest user (id == 1). if ($USER->id > 1) // Don't show if user is not logged in (id == 0) or is guest user (id == 1).
{ {
$userstudyplans = studyplan::find_for_user($USER->id); $userstudyplans = studyplan::find_for_user($USER->id);
if (!empty($userstudyplans)) if (!empty($userstudyplans))
{ {
// create studyplan node. // Create studyplan node.
$node = navigation_node::create( $node = navigation_node::create(
get_string("link_myreport", "local_treestudyplan"), get_string("link_myreport", "local_treestudyplan"),
new moodle_url($CFG->wwwroot . "/local/treestudyplan/myreport.php", array()), new moodle_url($CFG->wwwroot . "/local/treestudyplan/myreport.php", array()),
global_navigation::TYPE_SYSTEM, global_navigation::TYPE_SYSTEM,
null, null,
"local_treestudyplan_myreport", "local_treestudyplan_myreport",
new pix_icon("myreport", '', 'local_treestudyplan') new pix_icon("myreport", '', 'local_treestudyplan')
); );
$node->showinflatnavigation = true; $node->showinflatnavigation = true;
$node->showinsecondarynavigation=true; $node->showinsecondarynavigation=true;
// create invitenode node. // Create invitenode node.
$invitenode = navigation_node::create( $invitenode = navigation_node::create(
get_string("manage_invites", "local_treestudyplan"), get_string("manage_invites", "local_treestudyplan"),
new moodle_url($CFG->wwwroot . "/local/treestudyplan/invitations.php", array()), new moodle_url($CFG->wwwroot . "/local/treestudyplan/invitations.php", array()),
global_navigation::TYPE_CUSTOM , global_navigation::TYPE_CUSTOM ,
null, null,
"local_treestudyplan_invitemgmt", "local_treestudyplan_invitemgmt",
new pix_icon("invitemgmt", '', 'local_treestudyplan') new pix_icon("invitemgmt", '', 'local_treestudyplan')
); );
$invitenode->showinflatnavigation = false; $invitenode->showinflatnavigation = false;
$node->add_node($invitenode); $node->add_node($invitenode);
$navigation->add_node($node, 'mycourses'); $navigation->add_node($node, 'mycourses');
} }
else { else {
$hideprimary_hrefs[] = "/local/treestudyplan/myreport.php"; $hideprimary_hrefs[] = "/local/treestudyplan/myreport.php";
} }
if ( has_capability('local/treestudyplan:viewuserreports', context_system::instance()) if ( has_capability('local/treestudyplan:viewuserreports', context_system::instance())
|| webservicehelper::has_capability_in_any_category('local/treestudyplan:viewuserreports')) || webservicehelper::has_capability_in_any_category('local/treestudyplan:viewuserreports'))
{ {
$node = navigation_node::create( $node = navigation_node::create(
get_string("link_viewplan", "local_treestudyplan"), get_string("link_viewplan", "local_treestudyplan"),
new moodle_url($CFG->wwwroot . "/local/treestudyplan/view-plan.php", array()), new moodle_url($CFG->wwwroot . "/local/treestudyplan/view-plan.php", array()),
global_navigation::TYPE_SYSTEM , global_navigation::TYPE_SYSTEM ,
null, null,
"local_treestudyplan_viewplan", "local_treestudyplan_viewplan",
new pix_icon("viewplans", '', 'local_treestudyplan') new pix_icon("viewplans", '', 'local_treestudyplan')
); );
$node->showinflatnavigation = true; $node->showinflatnavigation = true;
$node->showinsecondarynavigation=true; $node->showinsecondarynavigation=true;
$navigation->add_node($node, 'mycourses'); $navigation->add_node($node, 'mycourses');
} }
else { else {
$hideprimary_hrefs[] = "/local/treestudyplan/view-plan.php"; $hideprimary_hrefs[] = "/local/treestudyplan/view-plan.php";
} }
if ( has_capability('local/treestudyplan:editstudyplan', context_system::instance()) if ( has_capability('local/treestudyplan:editstudyplan', context_system::instance())
|| webservicehelper::has_capability_in_any_category('local/treestudyplan:editstudyplan') || webservicehelper::has_capability_in_any_category('local/treestudyplan:editstudyplan')
) )
{ {
$node = navigation_node::create( $node = navigation_node::create(
get_string("cfg_plans", "local_treestudyplan"), get_string("cfg_plans", "local_treestudyplan"),
new moodle_url($CFG->wwwroot . "/local/treestudyplan/edit-plan.php", array()), new moodle_url($CFG->wwwroot . "/local/treestudyplan/edit-plan.php", array()),
global_navigation::TYPE_SYSTEM , global_navigation::TYPE_SYSTEM ,
null, null,
"local_treestudyplan_editplan", "local_treestudyplan_editplan",
new pix_icon("viewplans", '', 'local_treestudyplan') new pix_icon("viewplans", '', 'local_treestudyplan')
); );
$node->showinflatnavigation = true; $node->showinflatnavigation = true;
$node->showinsecondarynavigation=true; $node->showinsecondarynavigation=true;
$navigation->add_node($node, 'mycourses'); $navigation->add_node($node, 'mycourses');
} }
else { else {
$hideprimary_hrefs[] = "/local/treestudyplan/edit-plan.php"; $hideprimary_hrefs[] = "/local/treestudyplan/edit-plan.php";
} }
} }
else { else {
$hideprimary_hrefs[] = "/local/treestudyplan/myreport.php"; $hideprimary_hrefs[] = "/local/treestudyplan/myreport.php";
$hideprimary_hrefs[] = "/local/treestudyplan/edit-plan.php"; $hideprimary_hrefs[] = "/local/treestudyplan/edit-plan.php";
$hideprimary_hrefs[] = "/local/treestudyplan/view-plan.php"; $hideprimary_hrefs[] = "/local/treestudyplan/view-plan.php";
} }
// create invitenode node. // Create invitenode node.
$invitenode = navigation_node::create( $invitenode = navigation_node::create(
get_string("nav_invited", "local_treestudyplan"), get_string("nav_invited", "local_treestudyplan"),
new moodle_url($CFG->wwwroot . "/local/treestudyplan/invited.php", array()), new moodle_url($CFG->wwwroot . "/local/treestudyplan/invited.php", array()),
global_navigation::TYPE_USER , global_navigation::TYPE_USER ,
null, null,
"local_treestudyplan_invitemgmt", "local_treestudyplan_invitemgmt",
new pix_icon("nav_invited", '', 'local_treestudyplan') new pix_icon("nav_invited", '', 'local_treestudyplan')
); );
$invitenode->showinflatnavigation = false; $invitenode->showinflatnavigation = false;
$navigation->add_node($invitenode, 'mycourses'); $navigation->add_node($invitenode, 'mycourses');
// Now using some javascript magic, we'll hide the links that are not accessible. // Now using some javascript magic, we'll hide the links that are not accessible.
$PAGE->requires->js_call_amd('local_treestudyplan/primary-nav-tools', 'hide_primary', [$hideprimary_hrefs]); $PAGE->requires->js_call_amd('local_treestudyplan/primary-nav-tools', 'hide_primary', [$hideprimary_hrefs]);
} }
function local_treestudyplan_extend_navigation_category_settings($navigation, context_coursecat $coursecategorycontext) { function local_treestudyplan_extend_navigation_category_settings($navigation, context_coursecat $coursecategorycontext) {
global $CFG, $PAGE; global $CFG, $PAGE;
$categoryid = $coursecategorycontext->instanceid; $categoryid = $coursecategorycontext->instanceid;
if (has_capability('local/treestudyplan:editstudyplan', $coursecategorycontext)) { if (has_capability('local/treestudyplan:editstudyplan', $coursecategorycontext)) {
$node = $navigation->add( $node = $navigation->add(
get_string('treestudyplan:editstudyplan', "local_treestudyplan"), get_string('treestudyplan:editstudyplan', "local_treestudyplan"),
new moodle_url($CFG->wwwroot . "/local/treestudyplan/edit-plan.php", ["categoryid"=>$categoryid]), new moodle_url($CFG->wwwroot . "/local/treestudyplan/edit-plan.php", ["categoryid"=>$categoryid]),
global_navigation::TYPE_CATEGORY, global_navigation::TYPE_CATEGORY,
null, null,
"local_treestudyplan_editplan", "local_treestudyplan_editplan",
new pix_icon("editplans", '', 'local_treestudyplan') new pix_icon("editplans", '', 'local_treestudyplan')
); );
//$node->make_active();.
} }
if (has_capability('local/treestudyplan:viewuserreports', $coursecategorycontext)) { if (has_capability('local/treestudyplan:viewuserreports', $coursecategorycontext)) {
$node = $navigation->add( $node = $navigation->add(
get_string('link_viewplan', "local_treestudyplan"), get_string('link_viewplan', "local_treestudyplan"),
new moodle_url($CFG->wwwroot . "/local/treestudyplan/view-plan.php", ["categoryid"=>$categoryid]), new moodle_url($CFG->wwwroot . "/local/treestudyplan/view-plan.php", ["categoryid"=>$categoryid]),
global_navigation::TYPE_CATEGORY, global_navigation::TYPE_CATEGORY,
null, null,
"local_treestudyplan_viewplan", "local_treestudyplan_viewplan",
new pix_icon("viewplans", '', 'local_treestudyplan') new pix_icon("viewplans", '', 'local_treestudyplan')
); );
//$node->make_active();.
} }
} }
@ -185,8 +185,8 @@ function local_treestudyplan_get_fontawesome_icon_map() {
// Create the icon map with the icons which are used in any case. // Create the icon map with the icons which are used in any case.
$iconmapping = [ $iconmapping = [
'local_treestudyplan:myreport' => 'fa-vcard', 'local_treestudyplan:myreport' => 'fa-vcard',
'local_treestudyplan:editplans' => 'fa-share-alt', 'local_treestudyplan:editplans' => 'fa-share-alt',
'local_treestudyplan:viewplans' => 'fa-share-alt', 'local_treestudyplan:viewplans' => 'fa-share-alt',
]; ];
return $iconmapping; return $iconmapping;
@ -206,64 +206,64 @@ function local_treestudyplan_reset_fontawesome_icon_map() {
} }
function local_treestudyplan_send_invite($inviteid) { function local_treestudyplan_send_invite($inviteid) {
global $DB, $USER, $CFG; global $DB, $USER, $CFG;
$invite = $DB->get_record("local_treestudyplan_invit", array('id' => $inviteid)); $invite = $DB->get_record("local_treestudyplan_invit", array('id' => $inviteid));
$noreply = 'noreply@' . get_host_from_url($CFG->wwwroot); $noreply = 'noreply@' . get_host_from_url($CFG->wwwroot);
$mailer = get_mailer(); $mailer = get_mailer();
$mailer->setFrom($noreply, "{$USER->firstname} {$USER->lastname}"); $mailer->setFrom($noreply, "{$USER->firstname} {$USER->lastname}");
$mailer->addAddress($invite->email, $invite->name); $mailer->addAddress($invite->email, $invite->name);
$mailer->addReplyTo($USER->email, "{$USER->firstname} {$USER->lastname}"); $mailer->addReplyTo($USER->email, "{$USER->firstname} {$USER->lastname}");
$invitehref = $CFG->wwwroot."/local/treestudyplan/invited.php?key={$invite->invitekey}"; $invitehref = $CFG->wwwroot."/local/treestudyplan/invited.php?key={$invite->invitekey}";
$data = [ 'permissions'=> '', $data = [ 'permissions'=> '',
'invitee' => $invite->name, 'invitee' => $invite->name,
'sender' => "{$USER->firstname} {$USER->lastname}", 'sender' => "{$USER->firstname} {$USER->lastname}",
'link' => $invitehref]; 'link' => $invitehref];
if ($invite->allow_details || $invite->allow_calendar || $invite->allow_badges) if ($invite->allow_details || $invite->allow_calendar || $invite->allow_badges)
{ {
$data['permissions'] = get_string('invite_mail_permissions', 'local_treestudyplan'); $data['permissions'] = get_string('invite_mail_permissions', 'local_treestudyplan');
$data['permissions'] .= "<ul>\n"; $data['permissions'] .= "<ul>\n";
if ($invite->allow_details ) if ($invite->allow_details )
{ {
$data['permissions'] .= "<li>".get_string('invite_allow_details', 'local_treestudyplan')."</li>\n"; $data['permissions'] .= "<li>".get_string('invite_allow_details', 'local_treestudyplan')."</li>\n";
} }
if ($invite->allow_calendar) if ($invite->allow_calendar)
{ {
$data['permissions'] .= "<li>".get_string('invite_allow_calendar', 'local_treestudyplan')."</li>\n"; $data['permissions'] .= "<li>".get_string('invite_allow_calendar', 'local_treestudyplan')."</li>\n";
} }
if ($invite->allow_badges) if ($invite->allow_badges)
{ {
$data['permissions'] .= "<li>".get_string('invite_allow_badges', 'local_treestudyplan')."</li>\n"; $data['permissions'] .= "<li>".get_string('invite_allow_badges', 'local_treestudyplan')."</li>\n";
} }
$data['permissions'] .= "</ul></p>\n"; $data['permissions'] .= "</ul></p>\n";
} }
$body = get_string('invite_mail_text', 'local_treestudyplan', $data); $body = get_string('invite_mail_text', 'local_treestudyplan', $data);
$subject = get_string('invite_mail_subject', 'local_treestudyplan', $data); $subject = get_string('invite_mail_subject', 'local_treestudyplan', $data);
$html = " $html = "
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>. <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>.
<html xmlns='http://www.w3.org/1999/xhtml'>. <html xmlns='http://www.w3.org/1999/xhtml'>.
<head> <head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' /> <meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<title>{$subject}</title> <title>{$subject}</title>
<meta name='viewport' content='width=device-width, initial-scale=1.0'/> <meta name='viewport' content='width=device-width, initial-scale=1.0'/>
</head> </head>
<body> <body>
{$body} {$body}
</body> </body>
</html>"; </html>";
$mailer->isHTML(true); $mailer->isHTML(true);
$mailer->Subject = $subject; $mailer->Subject = $subject;
$mailer->Body = $html; $mailer->Body = $html;
$mailer->AltBody = strip_tags($body); $mailer->AltBody = strip_tags($body);
$mailer->send(); $mailer->send();
} }
@ -299,38 +299,38 @@ function local_treestudyplan_get_cohort_path($cohort) {
function local_treestudyplan_output_fragment_mod_edit_form($args) { function local_treestudyplan_output_fragment_mod_edit_form($args) {
global $CFG; global $CFG;
global $DB; global $DB;
$args = (object)$args; $args = (object)$args;
$context = $args->context; $context = $args->context;
if (empty($args->cmid)) { if (empty($args->cmid)) {
return "RANDOM!"; return "RANDOM!";
} }
// Check the course module exists. // Check the course module exists.
$cm = \get_coursemodule_from_id('', $args->cmid, 0, false, MUST_EXIST); $cm = \get_coursemodule_from_id('', $args->cmid, 0, false, MUST_EXIST);
// Check the course exists. // Check the course exists.
$course = \get_course($cm->course); $course = \get_course($cm->course);
// require_login. // Require_login.
require_login($course, false, $cm); // needed to setup proper $COURSE. require_login($course, false, $cm); // needed to setup proper $COURSE.
list($cm, $context, $module, $data, $cw) = \get_moduleinfo_data($cm, $course); list($cm, $context, $module, $data, $cw) = \get_moduleinfo_data($cm, $course);
$modmoodleform = "$CFG->dirroot/mod/$module->name/mod_form.php"; $modmoodleform = "$CFG->dirroot/mod/$module->name/mod_form.php";
if (file_exists($modmoodleform)) { if (file_exists($modmoodleform)) {
require_once($modmoodleform); require_once($modmoodleform);
} else { } else {
print_error('noformdesc'); print_error('noformdesc');
} }
$mformclassname = 'mod_'.$module->name.'_mod_form'; $mformclassname = 'mod_'.$module->name.'_mod_form';
$mform = new $mformclassname($data, $cw->section, $cm, $course); $mform = new $mformclassname($data, $cw->section, $cm, $course);
$mform->set_data($data); $mform->set_data($data);
return $mform->render(); return $mform->render();
} }

View File

@ -41,9 +41,9 @@ $PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/boot
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devstyles.css')); $PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devstyles.css'));
$PAGE->requires->js_call_amd('local_treestudyplan/page-myreport', 'init'); $PAGE->requires->js_call_amd('local_treestudyplan/page-myreport', 'init');
//Local translate function. // Local translate function.
function t($str, $param=null, $plugin='local_treestudyplan') { function t($str, $param=null, $plugin='local_treestudyplan') {
print get_string($str, $plugin, $param); print get_string($str, $plugin, $param);
} }
print $OUTPUT->header(); print $OUTPUT->header();
@ -52,14 +52,14 @@ print $OUTPUT->header();
<a class="btn btn-primary" href="invitations.php" id="manage_invites"><i class="fa fa-share"></i> <?php t('manage_invites'); ?></a> <a class="btn btn-primary" href="invitations.php" id="manage_invites"><i class="fa fa-share"></i> <?php t('manage_invites'); ?></a>
</div> </div>
<div id='root'> <div id='root'>
<div class='vue-loader' v-show='false'> <div class='vue-loader' v-show='false'>
<div class="spinner-border text-primary" role="status"> <div class="spinner-border text-primary" role="status">
<span class="sr-only">Loading...</span> <span class="sr-only">Loading...</span>
</div> </div>
</div> </div>
<div v-cloak> <div v-cloak>
<r-report v-model="studyplans"></r-report> <r-report v-model="studyplans"></r-report>
</div> </div>
</div> </div>
<?php <?php

View File

@ -37,11 +37,11 @@ $PAGE->set_context($systemcontext);
$teachermode = has_capability("local/treestudyplan:viewuserreports", $systemcontext); $teachermode = has_capability("local/treestudyplan:viewuserreports", $systemcontext);
if ($teachermode) { if ($teachermode) {
$PAGE->set_title(get_string('myreport_teachermode', 'local_treestudyplan')); $PAGE->set_title(get_string('myreport_teachermode', 'local_treestudyplan'));
$PAGE->set_heading(get_string('myreport_teachermode', 'local_treestudyplan')); $PAGE->set_heading(get_string('myreport_teachermode', 'local_treestudyplan'));
} else { } else {
$PAGE->set_title(get_string('report_invited', 'local_treestudyplan', "{$USER->firstname} {$USER->lastname}")); $PAGE->set_title(get_string('report_invited', 'local_treestudyplan', "{$USER->firstname} {$USER->lastname}"));
$PAGE->set_heading(get_string('report_invited', 'local_treestudyplan', "{$USER->firstname} {$USER->lastname}")); $PAGE->set_heading(get_string('report_invited', 'local_treestudyplan', "{$USER->firstname} {$USER->lastname}"));
} }
// Load javascripts and specific css. // Load javascripts and specific css.
@ -49,9 +49,9 @@ $PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/boot
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devstyles.css')); $PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devstyles.css'));
$PAGE->requires->js_call_amd('local_treestudyplan/page-myreport', 'init', [$teachermode?'teaching':'myreport']); $PAGE->requires->js_call_amd('local_treestudyplan/page-myreport', 'init', [$teachermode?'teaching':'myreport']);
//Local translate function. // Local translate function.
function t($str, $param=null, $plugin='local_treestudyplan') { function t($str, $param=null, $plugin='local_treestudyplan') {
print get_string($str, $plugin, $param); print get_string($str, $plugin, $param);
} }
print $OUTPUT->header(); print $OUTPUT->header();
@ -62,14 +62,14 @@ print $OUTPUT->header();
<?php } ?> <?php } ?>
</div> </div>
<div id='root'> <div id='root'>
<div class='vue-loader' v-show='false'> <div class='vue-loader' v-show='false'>
<div class="spinner-border text-primary" role="status"> <div class="spinner-border text-primary" role="status">
<span class="sr-only">Loading...</span> <span class="sr-only">Loading...</span>
</div> </div>
</div> </div>
<div v-cloak> <div v-cloak>
<r-report v-model="studyplans" <?php print ($teachermode?"teachermode":""); ?> ></r-report> <r-report v-model="studyplans" <?php print ($teachermode?"teachermode":""); ?> ></r-report>
</div> </div>
</div> </div>
<?php <?php

View File

@ -28,202 +28,202 @@ use local_treestudyplan\aggregator;
if ($hassiteconfig) { if ($hassiteconfig) {
/************************************** /**************************************
* *
* Main studyplan settings * Main studyplan settings
* *
*************************************/ *************************************/
// Create admin settings category. // Create admin settings category.
$ADMIN->add('courses', new admin_category('local_treestudyplan', $ADMIN->add('courses', new admin_category('local_treestudyplan',
get_string('pluginname', 'local_treestudyplan', null, true))); get_string('pluginname', 'local_treestudyplan', null, true)));
// Settings page: Root nodes. // Settings page: Root nodes.
$page = new admin_settingpage('local_treestudyplan_settings', $page = new admin_settingpage('local_treestudyplan_settings',
get_string('settingspage', 'local_treestudyplan', null, true)); get_string('settingspage', 'local_treestudyplan', null, true));
// GOAL AGGREGATION SETTINGS. // GOAL AGGREGATION SETTINGS.
$page->add(new admin_setting_heading('local_treestudyplan/aggregation_heading', $page->add(new admin_setting_heading('local_treestudyplan/aggregation_heading',
get_string('setting_aggregation_heading', 'local_treestudyplan'), get_string('setting_aggregation_heading', 'local_treestudyplan'),
get_string('settingdesc_aggregation_heading', 'local_treestudyplan') get_string('settingdesc_aggregation_heading', 'local_treestudyplan')
)); ));
$aggregators = []; $aggregators = [];
foreach (aggregator::list() as $a) { foreach (aggregator::list() as $a) {
$aggregators[$a] = get_string("{$a}_aggregator_title", 'local_treestudyplan', null, true); $aggregators[$a] = get_string("{$a}_aggregator_title", 'local_treestudyplan', null, true);
} }
$page->add(new admin_setting_configselect('local_treestudyplan/aggregation_mode', $page->add(new admin_setting_configselect('local_treestudyplan/aggregation_mode',
get_string('setting_aggregation_mode', 'local_treestudyplan'), get_string('setting_aggregation_mode', 'local_treestudyplan'),
get_string('settingdesc_aggregation_mode', 'local_treestudyplan'), get_string('settingdesc_aggregation_mode', 'local_treestudyplan'),
"core", "core",
$aggregators $aggregators
)); ));
// DISPLAY COURSE INFO SETTINGS. // DISPLAY COURSE INFO SETTINGS.
$page->add(new admin_setting_heading('local_treestudyplan/display_heading', $page->add(new admin_setting_heading('local_treestudyplan/display_heading',
get_string('setting_display_heading', 'local_treestudyplan'), get_string('setting_display_heading', 'local_treestudyplan'),
get_string('settingdesc_display_heading', 'local_treestudyplan') get_string('settingdesc_display_heading', 'local_treestudyplan')
)); ));
$displayfields = ["shortname" => get_string("shortname"), "idnumber" => get_string("idnumber")]; $displayfields = ["shortname" => get_string("shortname"), "idnumber" => get_string("idnumber")];
$handler = \core_customfield\handler::get_handler('core_course', 'course'); $handler = \core_customfield\handler::get_handler('core_course', 'course');
foreach ($handler->get_categories_with_fields() as $cat) { foreach ($handler->get_categories_with_fields() as $cat) {
$catname = $cat->get_formatted_name(); $catname = $cat->get_formatted_name();
foreach ($cat->get_fields() as $field) { foreach ($cat->get_fields() as $field) {
$fieldname = $field->get_formatted_name(); $fieldname = $field->get_formatted_name();
$fieldid = $field->get("shortname"); $fieldid = $field->get("shortname");
$displayfields["customfield_".$fieldid] = $catname.": ".$fieldname; $displayfields["customfield_".$fieldid] = $catname.": ".$fieldname;
} }
} }
$page->add(new admin_setting_configselect('local_treestudyplan/display_field', $page->add(new admin_setting_configselect('local_treestudyplan/display_field',
get_string('setting_display_field', 'local_treestudyplan'), get_string('setting_display_field', 'local_treestudyplan'),
get_string('settingdesc_display_field', 'local_treestudyplan'), get_string('settingdesc_display_field', 'local_treestudyplan'),
"shortname", "shortname",
$displayfields $displayfields
)); ));
// BISTATE AGGREGATON DEFAULTS. // BISTATE AGGREGATON DEFAULTS.
$page->add(new admin_setting_heading('local_treestudyplan/bistate_aggregation_heading', $page->add(new admin_setting_heading('local_treestudyplan/bistate_aggregation_heading',
get_string('setting_bistate_heading', 'local_treestudyplan'), get_string('setting_bistate_heading', 'local_treestudyplan'),
get_string('settingdesc_bistate_heading', 'local_treestudyplan') get_string('settingdesc_bistate_heading', 'local_treestudyplan')
)); ));
$page->add(new admin_setting_configtext('local_treestudyplan/bistate_thresh_excellent', $page->add(new admin_setting_configtext('local_treestudyplan/bistate_thresh_excellent',
get_string('setting_bistate_thresh_excellent', 'local_treestudyplan'), get_string('setting_bistate_thresh_excellent', 'local_treestudyplan'),
get_string('settingdesc_bistate_thresh_excellent', 'local_treestudyplan'), get_string('settingdesc_bistate_thresh_excellent', 'local_treestudyplan'),
"100", "100",
PARAM_INT PARAM_INT
)); ));
$page->add(new admin_setting_configtext('local_treestudyplan/bistate_thresh_good', $page->add(new admin_setting_configtext('local_treestudyplan/bistate_thresh_good',
get_string('setting_bistate_thresh_good', 'local_treestudyplan'), get_string('setting_bistate_thresh_good', 'local_treestudyplan'),
get_string('settingdesc_bistate_thresh_good', 'local_treestudyplan'), get_string('settingdesc_bistate_thresh_good', 'local_treestudyplan'),
"80", "80",
PARAM_INT PARAM_INT
)); ));
$page->add(new admin_setting_configtext('local_treestudyplan/bistate_thresh_completed', $page->add(new admin_setting_configtext('local_treestudyplan/bistate_thresh_completed',
get_string('setting_bistate_thresh_completed', 'local_treestudyplan'), get_string('setting_bistate_thresh_completed', 'local_treestudyplan'),
get_string('settingdesc_bistate_thresh_completed', 'local_treestudyplan'), get_string('settingdesc_bistate_thresh_completed', 'local_treestudyplan'),
"66", "66",
PARAM_INT PARAM_INT
)); ));
$page->add(new admin_setting_configcheckbox('local_treestudyplan/bistate_support_failed', $page->add(new admin_setting_configcheckbox('local_treestudyplan/bistate_support_failed',
get_string('setting_bistate_support_failed', 'local_treestudyplan'), get_string('setting_bistate_support_failed', 'local_treestudyplan'),
get_string('settingdesc_bistate_support_failed', 'local_treestudyplan'), get_string('settingdesc_bistate_support_failed', 'local_treestudyplan'),
True, True,
)); ));
$page->add(new admin_setting_configcheckbox('local_treestudyplan/bistate_accept_pending_submitted', $page->add(new admin_setting_configcheckbox('local_treestudyplan/bistate_accept_pending_submitted',
get_string('setting_bistate_accept_pending_submitted', 'local_treestudyplan'), get_string('setting_bistate_accept_pending_submitted', 'local_treestudyplan'),
get_string('settingdesc_bistate_accept_pending_submitted', 'local_treestudyplan'), get_string('settingdesc_bistate_accept_pending_submitted', 'local_treestudyplan'),
False, False,
)); ));
// Add settings page to the admin settings category. // Add settings page to the admin settings category.
$ADMIN->add('local_treestudyplan', $page); $ADMIN->add('local_treestudyplan', $page);
/************************************** /**************************************
* *
* Manage plans link (systemwide) * Manage plans link (systemwide)
* *
*************************************/ *************************************/
$ADMIN->add('local_treestudyplan', new admin_externalpage( $ADMIN->add('local_treestudyplan', new admin_externalpage(
'local_treestudyplan_editplans', 'local_treestudyplan_editplans',
get_string('cfg_plans', 'local_treestudyplan', null, true), get_string('cfg_plans', 'local_treestudyplan', null, true),
$CFG->wwwroot . '/local/treestudyplan/edit-plan.php')); $CFG->wwwroot . '/local/treestudyplan/edit-plan.php'));
/************************************** /**************************************
* *
* Settings page: Cohort sync * Settings page: Cohort sync
* *
*************************************/ *************************************/
$pagecsync = new admin_settingpage('local_treestudyplan_settings_cohortsync', $pagecsync = new admin_settingpage('local_treestudyplan_settings_cohortsync',
get_string('settingspage_csync', 'local_treestudyplan', null, true)); get_string('settingspage_csync', 'local_treestudyplan', null, true));
// Description heading. // Description heading.
$pagecsync->add(new admin_setting_heading('local_treestudyplan/csync_heading', $pagecsync->add(new admin_setting_heading('local_treestudyplan/csync_heading',
get_string('setting_csync_heading', 'local_treestudyplan'), get_string('setting_csync_heading', 'local_treestudyplan'),
get_string('settingdesc_csync_heading', 'local_treestudyplan') get_string('settingdesc_csync_heading', 'local_treestudyplan')
)); ));
// Enable/disable cohort sync. // Enable/disable cohort sync.
$pagecsync->add(new admin_setting_configcheckbox('local_treestudyplan/csync_enable', $pagecsync->add(new admin_setting_configcheckbox('local_treestudyplan/csync_enable',
get_string('setting_csync_enable_field', 'local_treestudyplan'), get_string('setting_csync_enable_field', 'local_treestudyplan'),
get_string('settingdesc_csync_enable_field', 'local_treestudyplan'), get_string('settingdesc_csync_enable_field', 'local_treestudyplan'),
false false
)); ));
// Enable/disable autoremove. // Enable/disable autoremove.
$pagecsync->add(new admin_setting_configcheckbox('local_treestudyplan/csync_autoremove', $pagecsync->add(new admin_setting_configcheckbox('local_treestudyplan/csync_autoremove',
get_string('setting_csync_autoremove_field', 'local_treestudyplan'), get_string('setting_csync_autoremove_field', 'local_treestudyplan'),
get_string('settingdesc_csync_autoremove_field', 'local_treestudyplan'), get_string('settingdesc_csync_autoremove_field', 'local_treestudyplan'),
true true
)); ));
// Enable/disable remembering previously added cohort syncs so they're not automatically deleted. // Enable/disable remembering previously added cohort syncs so they're not automatically deleted.
$pagecsync->add(new admin_setting_configcheckbox('local_treestudyplan/csync_remember_manual_csync', $pagecsync->add(new admin_setting_configcheckbox('local_treestudyplan/csync_remember_manual_csync',
get_string('setting_csync_remember_manual_csync_field', 'local_treestudyplan'), get_string('setting_csync_remember_manual_csync_field', 'local_treestudyplan'),
get_string('settingdesc_csync_remember_manual_csync_field', 'local_treestudyplan'), get_string('settingdesc_csync_remember_manual_csync_field', 'local_treestudyplan'),
true true
)); ));
// Enable/disable group creation. // Enable/disable group creation.
$pagecsync->add(new admin_setting_configcheckbox('local_treestudyplan/csync_creategroup', $pagecsync->add(new admin_setting_configcheckbox('local_treestudyplan/csync_creategroup',
get_string('setting_csync_creategroup_field', 'local_treestudyplan'), get_string('setting_csync_creategroup_field', 'local_treestudyplan'),
get_string('settingdesc_csync_creategroup_field', 'local_treestudyplan'), get_string('settingdesc_csync_creategroup_field', 'local_treestudyplan'),
true true
)); ));
// Sync users too yes/no?. // Sync users too yes/no?.
$pagecsync->add(new admin_setting_configcheckbox('local_treestudyplan/csync_users', $pagecsync->add(new admin_setting_configcheckbox('local_treestudyplan/csync_users',
get_string('setting_csync_users_field', 'local_treestudyplan'), get_string('setting_csync_users_field', 'local_treestudyplan'),
get_string('settingdesc_csync_users_field', 'local_treestudyplan'), get_string('settingdesc_csync_users_field', 'local_treestudyplan'),
true true
)); ));
// Select csync enrol role. // Select csync enrol role.
if (!during_initial_install()) { if (!during_initial_install()) {
$options = get_default_enrol_roles(context_system::instance()); $options = get_default_enrol_roles(context_system::instance());
$student = get_archetype_roles('student'); $student = get_archetype_roles('student');
$student = reset($student); $student = reset($student);
$pagecsync->add(new admin_setting_configselect('local_treestudyplan/csync_roleid', $pagecsync->add(new admin_setting_configselect('local_treestudyplan/csync_roleid',
get_string('setting_csync_role_field', 'local_treestudyplan'), get_string('setting_csync_role_field', 'local_treestudyplan'),
get_string('settingdesc_csync_role_field', 'local_treestudyplan'), get_string('settingdesc_csync_role_field', 'local_treestudyplan'),
$student->id ?? null, $options)); $student->id ?? null, $options));
} }
// Add settings page2 to the admin settings category. // Add settings page2 to the admin settings category.
$ADMIN->add('local_treestudyplan', $pagecsync); $ADMIN->add('local_treestudyplan', $pagecsync);
/************************************** /**************************************
* *
* Grade and scale interpretation * Grade and scale interpretation
* *
*************************************/ *************************************/
$ADMIN->add('local_treestudyplan', new admin_externalpage( $ADMIN->add('local_treestudyplan', new admin_externalpage(
'local_treestudyplan_gradeconfig', 'local_treestudyplan_gradeconfig',
get_string('cfg_grades', 'local_treestudyplan', null, true), get_string('cfg_grades', 'local_treestudyplan', null, true),
$CFG->wwwroot . '/local/treestudyplan/cfg_grades.php')); $CFG->wwwroot . '/local/treestudyplan/cfg_grades.php'));
/************************************** /**************************************
* *
* Add the help link (Temporary until a better place is found) * Add the help link (Temporary until a better place is found)
* *
**************************************/ **************************************/
$ADMIN->add('local_treestudyplan', new admin_externalpage( $ADMIN->add('local_treestudyplan', new admin_externalpage(
'local_treestudyplan_doc', 'local_treestudyplan_doc',
get_string('cfg_help', 'local_treestudyplan', null, true), get_string('cfg_help', 'local_treestudyplan', null, true),
$CFG->wwwroot . '/local/treestudyplan/doc.php/index.htm')); $CFG->wwwroot . '/local/treestudyplan/doc.php/index.htm'));
} }

View File

@ -35,32 +35,32 @@ require_login();
$categoryid = optional_param('categoryid', 0, PARAM_INT); // Category id. $categoryid = optional_param('categoryid', 0, PARAM_INT); // Category id.
$contextid = optional_param('contextid', 0, PARAM_INT); // Context id. $contextid = optional_param('contextid', 0, PARAM_INT); // Context id.
if ($categoryid > 0) { if ($categoryid > 0) {
$studyplancontext = context_coursecat::instance($categoryid); $studyplancontext = context_coursecat::instance($categoryid);
} else if ($contextid > 0) { } else if ($contextid > 0) {
$studyplancontext = context::instance_by_id($contextid); $studyplancontext = context::instance_by_id($contextid);
if (in_array($studyplancontext->contextlevel, [CONTEXT_SYSTEM, CONTEXT_COURSECAT])) if (in_array($studyplancontext->contextlevel, [CONTEXT_SYSTEM, CONTEXT_COURSECAT]))
{ {
$categoryid = $studyplancontext->instanceid; $categoryid = $studyplancontext->instanceid;
} }
else else
{ {
$studyplancontext = $systemcontext; $studyplancontext = $systemcontext;
} }
} else { } else {
// If no context is selected, find the first available one. // If no context is selected, find the first available one.
$availablecontexts = courseservice::list_accessible_categories_with_usage("view"); $availablecontexts = courseservice::list_accessible_categories_with_usage("view");
$contextid=1; // fallback to system context. $contextid=1; // fallback to system context.
foreach ($availablecontexts as $ctx) { foreach ($availablecontexts as $ctx) {
if ($ctx->count > 0) { if ($ctx->count > 0) {
$contextid = $ctx->ctxid; $contextid = $ctx->ctxid;
break; break;
} }
} }
// reload page with selected category. // Reload page with selected category.
$url = new \moodle_url('/local/treestudyplan/view-plan.php', ["contextid" => $contextid]); $url = new \moodle_url('/local/treestudyplan/view-plan.php', ["contextid" => $contextid]);
header('Location: '.$url->out(false), true, 302); header('Location: '.$url->out(false), true, 302);
exit; exit;
} }
require_capability('local/treestudyplan:viewuserreports', $studyplancontext); require_capability('local/treestudyplan:viewuserreports', $studyplancontext);
@ -72,8 +72,8 @@ $PAGE->set_title(get_string('view_plan', 'local_treestudyplan')." - ".$contextna
$PAGE->set_heading(get_string('view_plan', 'local_treestudyplan')." - ".$contextname); $PAGE->set_heading(get_string('view_plan', 'local_treestudyplan')." - ".$contextname);
if ($studyplancontext->id > 1) { if ($studyplancontext->id > 1) {
navigation_node::override_active_url(new moodle_url('/course/index.php', ['categoryid' => $categoryid ])); navigation_node::override_active_url(new moodle_url('/course/index.php', ['categoryid' => $categoryid ]));
$PAGE->navbar->add(get_string('view_plan', 'local_treestudyplan')); $PAGE->navbar->add(get_string('view_plan', 'local_treestudyplan'));
} }
// Load javascripts and specific css. // Load javascripts and specific css.
@ -81,81 +81,81 @@ $PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/boot
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devstyles.css')); $PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devstyles.css'));
$PAGE->requires->js_call_amd('local_treestudyplan/page-view-plan', 'init', [$studyplancontext->id, $categoryid]); $PAGE->requires->js_call_amd('local_treestudyplan/page-view-plan', 'init', [$studyplancontext->id, $categoryid]);
//Local translate function. // Local translate function.
function t($str, $param=null, $plugin='local_treestudyplan') { function t($str, $param=null, $plugin='local_treestudyplan') {
print get_string($str, $plugin, $param); print get_string($str, $plugin, $param);
} }
print $OUTPUT->header(); print $OUTPUT->header();
?> ?>
<div id='root'> <div id='root'>
<div class='vue-loader' v-show='false'> <div class='vue-loader' v-show='false'>
<div class="spinner-border text-primary" role="status"> <div class="spinner-border text-primary" role="status">
<span class="sr-only">Loading...</span> <span class="sr-only">Loading...</span>
</div> </div>
</div> </div>
<div v-cloak> <div v-cloak>
<div v-if='!activestudyplan && usedcontexts' class='ml-3 mb-3'> <div v-if='!activestudyplan && usedcontexts' class='ml-3 mb-3'>
<b-form-select text='<?php print($contextname);?>' :value="contextid"> <b-form-select text='<?php print($contextname);?>' :value="contextid">
<b-form-select-option v-for='ctx in usedcontexts' :key='ctx.id' :value="ctx.context_id" @click='switchContext(ctx)' <b-form-select-option v-for='ctx in usedcontexts' :key='ctx.id' :value="ctx.context_id" @click='switchContext(ctx)'
:active="ctx.context_id == contextid" :class="(ctx.studyplancount > 0)?'font-weight-bold':''" :active="ctx.context_id == contextid" :class="(ctx.studyplancount > 0)?'font-weight-bold':''"
><span v-for="(p, i) in ctx.category.path"><span v-if="i>0"> / </span>{{ p }}</span> <span>({{ ctx.studyplancount }})</b-form-select-option> ><span v-for="(p, i) in ctx.category.path"><span v-if="i>0"> / </span>{{ p }}</span> <span>({{ ctx.studyplancount }})</b-form-select-option>
</b-form-select> </b-form-select>
</div> </div>
<h3 v-else><?php print $contextname; ?></h3> <h3 v-else><?php print $contextname; ?></h3>
<div class="m-buttonbar" style="margin-bottom: 1em;"> <div class="m-buttonbar" style="margin-bottom: 1em;">
<a href='#' v-if='displayedstudyplan' @click.prevent='closeStudyplan'><i style='font-size: 150%;' class='fa fa-chevron-left'></i> <?php t('back');?></a> <a href='#' v-if='displayedstudyplan' @click.prevent='closeStudyplan'><i style='font-size: 150%;' class='fa fa-chevron-left'></i> <?php t('back');?></a>
<span v-if='displayedstudyplan'><?php t("studyplan_select"); ?></span>&nbsp; <span v-if='displayedstudyplan'><?php t("studyplan_select"); ?></span>&nbsp;
<b-form-select v-if='displayedstudyplan' lazy :text='dropdown_title'> <b-form-select v-if='displayedstudyplan' lazy :text='dropdown_title'>
<b-form-select-option v-for='(studyplan, planindex) in studyplans' :key='studyplan.id' @click='selectStudyplan(studyplan)'>{{ studyplan.name }}</b-form-select-option> <b-form-select-option v-for='(studyplan, planindex) in studyplans' :key='studyplan.id' @click='selectStudyplan(studyplan)'>{{ studyplan.name }}</b-form-select-option>
</b-form-select>&nbsp; </b-form-select>&nbsp;
<b-button variant='primary' v-if='associatedstudents && associatedstudents.length > 0' v-b-toggle.toolbox-sidebar><?php t('selectstudent_btn') ?></b-button> <b-button variant='primary' v-if='associatedstudents && associatedstudents.length > 0' v-b-toggle.toolbox-sidebar><?php t('selectstudent_btn') ?></b-button>
</div> </div>
<div class='t-studyplan-container'> <div class='t-studyplan-container'>
<h2 v-if='displayedstudyplan&& selectedstudent'>{{selectedstudent.firstname}} {{selectedstudent.lastname}} - {{displayedstudyplan.name}}</h2> <h2 v-if='displayedstudyplan&& selectedstudent'>{{selectedstudent.firstname}} {{selectedstudent.lastname}} - {{displayedstudyplan.name}}</h2>
<h2 v-else-if='displayedstudyplan'><?php t("showoverview"); ?> - {{displayedstudyplan.name}}</h2> <h2 v-else-if='displayedstudyplan'><?php t("showoverview"); ?> - {{displayedstudyplan.name}}</h2>
<r-studyplan v-if='!loadingstudyplan && displayedstudyplan' v-model='displayedstudyplan' :teachermode='!selectedstudent'></r-studyplan> <r-studyplan v-if='!loadingstudyplan && displayedstudyplan' v-model='displayedstudyplan' :teachermode='!selectedstudent'></r-studyplan>
<div v-else-if='loadingstudyplan' class="spinner-border text-primary" role="status"> <div v-else-if='loadingstudyplan' class="spinner-border text-primary" role="status">
<span class="sr-only">Loading...</span> <span class="sr-only">Loading...</span>
</div> </div>
<div v-else class='t-studyplan-notselected'> <div v-else class='t-studyplan-notselected'>
<p><?php t("studyplan_noneselected"); ?></p> <p><?php t("studyplan_noneselected"); ?></p>
<b-card-group deck> <b-card-group deck>
<s-studyplan-card <s-studyplan-card
v-for='(studyplan, planindex) in studyplans' v-for='(studyplan, planindex) in studyplans'
:key='studyplan.id' :key='studyplan.id'
v-model='studyplans[planindex]' v-model='studyplans[planindex]'
open open
@open='selectStudyplan(studyplan)' @open='selectStudyplan(studyplan)'
></s-studyplan-card> ></s-studyplan-card>
</b-card-group> </b-card-group>
</div> </div>
</div> </div>
<b-sidebar <b-sidebar
id="toolbox-sidebar" id="toolbox-sidebar"
right right
shadow shadow
title='<?php t("selectstudent")?>' title='<?php t("selectstudent")?>'
> >
<div class='m-2'><?php t("selectstudent_details")?></div> <div class='m-2'><?php t("selectstudent_details")?></div>
<b-list-group v-if="associatedstudents"> <b-list-group v-if="associatedstudents">
<b-list-group-item :active="! selectedstudent" <b-list-group-item :active="! selectedstudent"
button button
variant="primary" variant="primary"
@click='showOverview()' @click='showOverview()'
> >
<?php t("showoverview"); ?> <?php t("showoverview"); ?>
</b-list-group-item> </b-list-group-item>
<b-list-group-item v-for="student in associatedstudents" :key="student.id" <b-list-group-item v-for="student in associatedstudents" :key="student.id"
:active="selectedstudent && student.id == selectedstudent.id" :active="selectedstudent && student.id == selectedstudent.id"
button button
@click='showStudentView(student)' @click='showStudentView(student)'
> >
{{student.firstname}} {{student.lastname}} {{student.firstname}} {{student.lastname}}
</b-list-group-item> </b-list-group-item>
</b-list-group> </b-list-group>
</b-sidebar> </b-sidebar>
</div> </div>
</div> </div>
<?php <?php