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]);
} }
} }
@ -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();
@ -184,7 +184,7 @@ foreach ($scales as $scale) {
$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'));
@ -213,7 +211,6 @@ $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;
@ -221,7 +218,6 @@ foreach ($gradecfgs as $g) {
$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

@ -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;
} }
@ -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

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

@ -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

@ -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.
@ -160,7 +160,7 @@ class courseservice extends \external_api
{ {
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())) {
@ -233,7 +233,7 @@ 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;
} }
$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");
@ -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)];
} }
} }
@ -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

@ -39,8 +39,6 @@ class reportinvite_form extends moodleform {
$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.

View File

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

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,7 +180,7 @@ 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)) );
@ -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.

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());
@ -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) {

View File

@ -57,7 +57,7 @@ if ($categoryid > 0) {
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;

View File

@ -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());

View File

@ -45,7 +45,7 @@ if (empty($invite)) {
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');

14
lib.php
View File

@ -49,7 +49,7 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
// 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).
@ -59,7 +59,7 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
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()),
@ -71,7 +71,7 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
$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()),
@ -132,7 +132,7 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
$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()),
@ -164,7 +164,7 @@ function local_treestudyplan_extend_navigation_category_settings($navigation, co
"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(
@ -175,7 +175,7 @@ function local_treestudyplan_extend_navigation_category_settings($navigation, co
"local_treestudyplan_viewplan", "local_treestudyplan_viewplan",
new pix_icon("viewplans", '', 'local_treestudyplan') new pix_icon("viewplans", '', 'local_treestudyplan')
); );
//$node->make_active();.
} }
} }
@ -314,7 +314,7 @@ function local_treestudyplan_output_fragment_mod_edit_form($args) {
// 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);

View File

@ -57,7 +57,7 @@ if ($categoryid > 0) {
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;