Moodle code style fixes part 2

This commit is contained in:
PMKuipers 2023-08-24 23:09:20 +02:00
parent 1a3df05195
commit acf3409890
31 changed files with 177 additions and 342 deletions

View File

@ -41,8 +41,7 @@ $grade_cfgs = [];
foreach ($mappings as $cfg) { foreach ($mappings as $cfg) {
if (!empty($cfg->scale_id)) { if (!empty($cfg->scale_id)) {
$scale_cfgs[$cfg->scale_id] = $cfg; $scale_cfgs[$cfg->scale_id] = $cfg;
} } else if (!empty($cfg->grade_points)) {
else if (!empty($cfg->grade_points)) {
$grade_cfgs[$cfg->grade_points] = $cfg; $grade_cfgs[$cfg->grade_points] = $cfg;
} }
} }
@ -71,8 +70,7 @@ if ($_POST["action"] == "update") {
} }
} } else {
else {
$scalecfg = (object)[ "scale_id" => $scale->id, ]; $scalecfg = (object)[ "scale_id" => $scale->id, ];
$requireinsert = false; $requireinsert = false;
foreach (["min_progress", "min_completed"] as $handle) { foreach (["min_progress", "min_completed"] as $handle) {
@ -97,8 +95,7 @@ if ($_POST["action"] == "update") {
if (array_key_exists($deletekey, $_POST) && boolval($_POST[$deletekey]) === true) { if (array_key_exists($deletekey, $_POST) && boolval($_POST[$deletekey]) === true) {
$DB->delete_records(GRADECFG_TABLE, ["id" => $gradecfg->id]); $DB->delete_records(GRADECFG_TABLE, ["id" => $gradecfg->id]);
$deletelist[] = $gradecfg; $deletelist[] = $gradecfg;
} } else
else
{ {
foreach (["min_progress", "min_completed"] as $handle) { foreach (["min_progress", "min_completed"] as $handle) {
$key = "g_{$gradecfg->grade_points}_{$handle}"; $key = "g_{$gradecfg->grade_points}_{$handle}";

View File

@ -62,8 +62,7 @@ class cascadeusersync {
if (!($instance = $DB->get_record('enrol', $instanceparams))) { if (!($instance = $DB->get_record('enrol', $instanceparams))) {
if ($instanceid = $enrol->add_default_instance($course)) { if ($instanceid = $enrol->add_default_instance($course)) {
$instance = $DB->get_record('enrol', array('id' => $instanceid)); $instance = $DB->get_record('enrol', array('id' => $instanceid));
} } else {
else {
// Instance not added for some reason, so report an error somewhere. // Instance not added for some reason, so report an error somewhere.
// (or not). // (or not).
$instance = null; $instance = null;

View File

@ -45,8 +45,7 @@ class completion {
public static function label($completion) { public static function label($completion) {
if (array_key_exists($completion, self::LABELS)) { if (array_key_exists($completion, self::LABELS)) {
return self::LABELS[$completion]; return self::LABELS[$completion];
} } else
else
{ {
return self::LABELS[self::INCOMPLETE]; return self::LABELS[self::INCOMPLETE];
} }

View File

@ -89,8 +89,7 @@ class completionscanner
if (!array_key_exists($userid, $this->pending_cache)) { if (!array_key_exists($userid, $this->pending_cache)) {
if ($this->scanner === null) { if ($this->scanner === null) {
$this->pending_cache[$userid] = false; $this->pending_cache[$userid] = false;
} } else {
else {
$this->pending_cache[$userid] = $this->scanner->has_ungraded_submission($userid);; $this->pending_cache[$userid] = $this->scanner->has_ungraded_submission($userid);;
} }
} }
@ -133,8 +132,7 @@ class completionscanner
} else if ($completion_status == COMPLETION_COMPLETE) { } else if ($completion_status == COMPLETION_COMPLETE) {
$completed++; $completed++;
} }
} } else{
else{
if ($completion->is_complete()) { if ($completion->is_complete()) {
$completed++; $completed++;
} }

View File

@ -193,24 +193,21 @@ class corecompletioninfo {
"requirement" => get_string('markingyourselfcomplete', 'completion'), "requirement" => get_string('markingyourselfcomplete', 'completion'),
"status" => "", "status" => "",
]; ];
} } else if ($type == COMPLETION_CRITERIA_TYPE_DATE) {
else if ($type == COMPLETION_CRITERIA_TYPE_DATE) {
$details = [ $details = [
"type" => get_string('datepassed', 'completion'), "type" => get_string('datepassed', 'completion'),
"criteria" => get_string('remainingenroleduntildate', 'completion'), "criteria" => get_string('remainingenroleduntildate', 'completion'),
"requirement" => date("Y-m-d", $criteria->timeend), "requirement" => date("Y-m-d", $criteria->timeend),
"status" => "", "status" => "",
]; ];
} } else if ($type == COMPLETION_CRITERIA_TYPE_UNENROL) {
else if ($type == COMPLETION_CRITERIA_TYPE_UNENROL) {
$details = [ $details = [
"type" => get_string('unenrolment', 'completion'), "type" => get_string('unenrolment', 'completion'),
"criteria" => get_string('unenrolment', 'completion'), "criteria" => get_string('unenrolment', 'completion'),
"requirement" => get_string('unenrolingfromcourse', 'completion'), "requirement" => get_string('unenrolingfromcourse', 'completion'),
"status" => "", "status" => "",
]; ];
} } else if ($type == COMPLETION_CRITERIA_TYPE_ACTIVITY) {
else if ($type == COMPLETION_CRITERIA_TYPE_ACTIVITY) {
$cm = $this->modinfo->get_cm($criteria->moduleinstance); $cm = $this->modinfo->get_cm($criteria->moduleinstance);
$details = [ $details = [
"type" => $criteria->get_title(), "type" => $criteria->get_title(),
@ -245,16 +242,14 @@ class corecompletioninfo {
$details['requirement'] = implode(', ', $details['requirement']); $details['requirement'] = implode(', ', $details['requirement']);
} } else if ($type == COMPLETION_CRITERIA_TYPE_DURATION) {
else if ($type == COMPLETION_CRITERIA_TYPE_DURATION) {
$details = [ $details = [
"type" => get_string('periodpostenrolment', 'completion'), "type" => get_string('periodpostenrolment', 'completion'),
"criteria" => get_string('remainingenroledfortime', 'completion'), "criteria" => get_string('remainingenroledfortime', 'completion'),
"requirement" => get_string('xdays', 'completion', ceil($criteria->enrolperiod / (60*60*24))), "requirement" => get_string('xdays', 'completion', ceil($criteria->enrolperiod / (60*60*24))),
"status" => "", "status" => "",
]; ];
} } else if ($type == COMPLETION_CRITERIA_TYPE_GRADE) {
else if ($type == COMPLETION_CRITERIA_TYPE_GRADE) {
$details = [ $details = [
"type" => get_string('coursegrade', 'completion'), "type" => get_string('coursegrade', 'completion'),
"criteria" => get_string('graderequired', 'completion'), "criteria" => get_string('graderequired', 'completion'),
@ -262,8 +257,7 @@ class corecompletioninfo {
"requirement" => get_string('graderequired', 'completion').": ".format_float($criteria->gradepass, 1), "requirement" => get_string('graderequired', 'completion').": ".format_float($criteria->gradepass, 1),
"status" => "", "status" => "",
]; ];
} } else if ($type == COMPLETION_CRITERIA_TYPE_ROLE) {
else if ($type == COMPLETION_CRITERIA_TYPE_ROLE) {
$criteria = $criteria->get_title(); $criteria = $criteria->get_title();
$details = [ $details = [
@ -272,8 +266,7 @@ class corecompletioninfo {
"requirement" => get_string('markedcompleteby', 'completion', $criteria), "requirement" => get_string('markedcompleteby', 'completion', $criteria),
"status" => "", "status" => "",
]; ];
} } else if ($type == COMPLETION_CRITERIA_TYPE_COURSE) {
else if ($type == COMPLETION_CRITERIA_TYPE_COURSE) {
$prereq = get_course($criteria->courseinstance); $prereq = get_course($criteria->courseinstance);
$coursecontext = \context_course::instance($prereq->id, MUST_EXIST); $coursecontext = \context_course::instance($prereq->id, MUST_EXIST);
$fullname = format_string($prereq->fullname, true, array('context' => $coursecontext)); $fullname = format_string($prereq->fullname, true, array('context' => $coursecontext));
@ -325,8 +318,7 @@ class corecompletioninfo {
} }
if ($typeaggregation == COMPLETION_AGGREGATION_ALL) { if ($typeaggregation == COMPLETION_AGGREGATION_ALL) {
return $completed >= $count; return $completed >= $count;
} } else { // COMPLETION_AGGREGATION_ANY.
else { // COMPLETION_AGGREGATION_ANY.
return $completed > 1; return $completed > 1;
} }
@ -402,8 +394,7 @@ class corecompletioninfo {
} }
} }
} } else if ($type == COMPLETION_CRITERIA_TYPE_GRADE) {
else if ($type == COMPLETION_CRITERIA_TYPE_GRADE) {
// Make sure we provide the current course grade. // Make sure we provide the current course grade.
$iinfo['grade'] = floatval($iinfo['details']['status']); $iinfo['grade'] = floatval($iinfo['details']['status']);
if ($iinfo["grade"] > 0) { if ($iinfo["grade"] > 0) {
@ -423,8 +414,7 @@ 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;
@ -465,8 +455,7 @@ class corecompletioninfo {
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);
@ -474,8 +463,7 @@ class corecompletioninfo {
$result->feedback = trim($grade->feedback); $result->feedback = trim($grade->feedback);
$result->pending = (new gradingscanner($gi))->pending($userid); $result->pending = (new gradingscanner($gi))->pending($userid);
} } else {
else {
$result->grade = "-"; // Activity is gradable, but user did not receive a grade yet. $result->grade = "-"; // Activity is gradable, but user did not receive a grade yet.
$result->feedback = null; $result->feedback = null;
$result->pending = false; $result->pending = false;
@ -508,14 +496,12 @@ class corecompletioninfo {
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 {
return "-"; // User did not receive a grade yet for this course. return "-"; // User did not receive a grade yet for this course.
} }
} }
@ -551,8 +537,7 @@ class corecompletioninfo {
// 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. .
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();
@ -567,8 +552,7 @@ class corecompletioninfo {
} else { } else {
$completed += 1; $completed += 1;
} }
} } else {
else {
if ($completion->is_complete()) { if ($completion->is_complete()) {
$completed += 1; $completed += 1;
} }
@ -633,8 +617,7 @@ class corecompletioninfo {
} else { } else {
$typecount->completed += 1; $typecount->completed += 1;
} }
} } else {
else {
if ($completion->is_complete()) { if ($completion->is_complete()) {
$typecount->completed += 1; $typecount->completed += 1;
} }
@ -653,8 +636,7 @@ class corecompletioninfo {
if ($c->aggregation == COMPLETION_AGGREGATION_ALL) { if ($c->aggregation == COMPLETION_AGGREGATION_ALL) {
$ct = $c->count; $ct = $c->count;
$cmpl = $c->completed; $cmpl = $c->completed;
} } else {
else {
$ct = 1; $ct = 1;
$cmpl = ($c->completed > 0)?1:0; $cmpl = ($c->completed > 0)?1:0;
} }

View File

@ -78,8 +78,7 @@ class courseinfo {
global $USER, $DB; global $USER, $DB;
if ($userid <= 0) { if ($userid <= 0) {
$usr = $USER; $usr = $USER;
} } else
else
{ {
$usr = $DB->get_record('user', ['id' => $userid, 'deleted' => 0]); $usr = $DB->get_record('user', ['id' => $userid, 'deleted' => 0]);
} }
@ -124,8 +123,7 @@ class courseinfo {
else { else {
return "present"; return "present";
} }
} } else{
else{
return "future"; return "future";
} }
} }
@ -231,8 +229,7 @@ class courseinfo {
foreach ($gradables as $gradable) { foreach ($gradables as $gradable) {
$info['grades'][] = $gradable->editor_model($studyitem); $info['grades'][] = $gradable->editor_model($studyitem);
} }
} } else {
else {
$cc = new corecompletioninfo($this->course); $cc = new corecompletioninfo($this->course);
$info['completion'] = $cc->editor_model(); $info['completion'] = $cc->editor_model();
} }
@ -280,8 +277,7 @@ class courseinfo {
foreach ($gradables as $gi) { foreach ($gradables as $gi) {
$info['grades'][] = $gi->user_model($userid); $info['grades'][] = $gi->user_model($userid);
} }
} } else {
else {
$cc = new corecompletioninfo($this->course); $cc = new corecompletioninfo($this->course);
$info['completion'] = $cc->user_model($userid); $info['completion'] = $cc->user_model($userid);
} }

View File

@ -98,7 +98,7 @@ class gradeinfo {
public static function getCourseContextById($id) { public static function getCourseContextById($id) {
$gi = grade_item::fetch(["id" => $id]); $gi = grade_item::fetch(["id" => $id]);
if (!$gi || course_module_instance_pending_deletion($gi->courseid, $gi->itemmodule, $gi->iteminstance)) { if (!$gi || course_module_instance_pending_deletion($gi->courseid, $gi->itemmodule, $gi->iteminstance)) {
throw new \InvalidArgumentException ("Grade {$id} not found in database". print_r($gi, true)); throw new \InvalidArgumentException ("Grade {$id} not found in database");
} }
return \context_course::instance($gi->courseid);; return \context_course::instance($gi->courseid);;
} }
@ -109,7 +109,7 @@ class gradeinfo {
$gi = grade_item::fetch(["id" => $id]); $gi = grade_item::fetch(["id" => $id]);
if (!$gi || course_module_instance_pending_deletion($gi->courseid, $gi->itemmodule, $gi->iteminstance)) { if (!$gi || course_module_instance_pending_deletion($gi->courseid, $gi->itemmodule, $gi->iteminstance)) {
throw new \InvalidArgumentException ("Grade {$id} not found in database". print_r($gi, true)); throw new \InvalidArgumentException ("Grade {$id} not found in database");
} }
$this->id = $id; $this->id = $id;
$this->gradeitem = $gi; $this->gradeitem = $gi;
@ -124,8 +124,7 @@ class gradeinfo {
$this->cmid = 0; $this->cmid = 0;
$this->section = 0; $this->section = 0;
$this->sectionorder = 0; $this->sectionorder = 0;
} } 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.
@ -137,11 +136,9 @@ class gradeinfo {
$this->link = "/mod/{$gi->itemmodule}/view.php?id={$cminfo->id}"; $this->link = "/mod/{$gi->itemmodule}/view.php?id={$cminfo->id}";
if ($gi->itemmodule == 'quiz') { if ($gi->itemmodule == 'quiz') {
$this->gradinglink = "/mod/{$gi->itemmodule}/report.php?id={$cminfo->id}&mode=grading"; $this->gradinglink = "/mod/{$gi->itemmodule}/report.php?id={$cminfo->id}&mode=grading";
} } else if ($gi->itemmodule == "assign") {
else if ($gi->itemmodule == "assign") {
$this->gradinglink = $this->link ."&action=grading"; $this->gradinglink = $this->link ."&action=grading";
} } else {
else {
$this->gradinglink = $this->link; $this->gradinglink = $this->link;
} }
} }
@ -246,16 +243,13 @@ class gradeinfo {
if (!empty($grade)) { if (!empty($grade)) {
if (!is_numeric($grade->finalgrade) && empty($grade->finalgrade)) { if (!is_numeric($grade->finalgrade) && empty($grade->finalgrade)) {
$finalgrade = "-"; $finalgrade = "-";
} } else if (isset($this->scale)) {
else if (isset($this->scale)) {
$finalgrade = $this->scale->get_nearest_item($grade->finalgrade); $finalgrade = $this->scale->get_nearest_item($grade->finalgrade);
} } else
else
{ {
$finalgrade = round($grade->finalgrade, 1); $finalgrade = round($grade->finalgrade, 1);
} }
} } else
else
{ {
$finalgrade = "-"; $finalgrade = "-";
} }

View File

@ -74,8 +74,7 @@ class gradingscanner
if (!array_key_exists($userid, $this->pending_cache)) { if (!array_key_exists($userid, $this->pending_cache)) {
if ($this->scanner === null) { if ($this->scanner === null) {
$this->pending_cache[$userid] = false; $this->pending_cache[$userid] = false;
} } else {
else {
$this->pending_cache[$userid] = $this->scanner->has_ungraded_submission($userid);; $this->pending_cache[$userid] = $this->scanner->has_ungraded_submission($userid);;
} }
} }
@ -107,8 +106,7 @@ class gradingscanner
$grade = $this->gi->get_final($userid); $grade = $this->gi->get_final($userid);
if (!is_numeric($grade->finalgrade) && empty($grade->finalgrade)) { if (!is_numeric($grade->finalgrade) && empty($grade->finalgrade)) {
//skip. //skip.
} } else
else
{ {
//compare grade to minimum grade. //compare grade to minimum grade.
if ($this->grade_passed($grade)) { if ($this->grade_passed($grade)) {
@ -139,11 +137,9 @@ class gradingscanner
$scale = $this->gi->load_scale(); $scale = $this->gi->load_scale();
if ( isset($scale)) { if ( isset($scale)) {
$gradecfg = $DB->get_record($table, ["scale_id"=>$scale->id]); $gradecfg = $DB->get_record($table, ["scale_id"=>$scale->id]);
} } else if ($this->gi->grademin == 0) {
else if ($this->gi->grademin == 0) {
$gradecfg = $DB->get_record($table, ["grade_points"=>$this->gi->grademax]); $gradecfg = $DB->get_record($table, ["grade_points"=>$this->gi->grademax]);
} } else
else
{ {
$gradecfg = null; $gradecfg = null;
} }
@ -155,22 +151,18 @@ class gradingscanner
// 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 {
return false; return false;
} }
} } 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 {
return false; return false;
} }
} } 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.
@ -180,8 +172,7 @@ class gradingscanner
if ($score > 0.55) { if ($score > 0.55) {
return true; return true;
} } else {
else {
return false; return false;
} }
} }

View File

@ -142,17 +142,13 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
} }
if ($fraction_completed >= $this->thresh_excellent && $allrequiredmet) { if ($fraction_completed >= $this->thresh_excellent && $allrequiredmet) {
return completion::EXCELLENT; return completion::EXCELLENT;
} } else if ($fraction_completed >= $this->thresh_good && $allrequiredmet) {
else if ($fraction_completed >= $this->thresh_good && $allrequiredmet) {
return completion::GOOD; return completion::GOOD;
} } else if ($fraction_completed >= $this->thresh_completed && $allrequiredmet) {
else if ($fraction_completed >= $this->thresh_completed && $allrequiredmet) {
return completion::COMPLETED; return completion::COMPLETED;
} } else if ($started == 0) {
else if ($started == 0) {
return completion::INCOMPLETE; return completion::INCOMPLETE;
} } else {
else {
return completion::PROGRESS; return completion::PROGRESS;
} }
} }
@ -199,20 +195,15 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
if ( $total == $statecount[completion::EXCELLENT]) { if ( $total == $statecount[completion::EXCELLENT]) {
return completion::EXCELLENT; return completion::EXCELLENT;
} } else if ( $total == $statecount[completion::EXCELLENT] + $statecount[completion::GOOD]) {
else if ( $total == $statecount[completion::EXCELLENT] + $statecount[completion::GOOD]) {
return completion::GOOD; return completion::GOOD;
} } else if ( $total == $statecount[completion::EXCELLENT] + $statecount[completion::GOOD] + $statecount[completion::COMPLETED]) {
else if ( $total == $statecount[completion::EXCELLENT] + $statecount[completion::GOOD] + $statecount[completion::COMPLETED]) {
return completion::COMPLETED; return completion::COMPLETED;
} } else if ( $statecount[completion::FAILED]) {
else if ( $statecount[completion::FAILED]) {
return completion::FAILED; return completion::FAILED;
} } else if ( $total == $statecount[completion::INCOMPLETE]) {
else if ( $total == $statecount[completion::INCOMPLETE]) {
return completion::INCOMPLETE; return completion::INCOMPLETE;
} } else {
else {
return completion::PROGRESS; return completion::PROGRESS;
} }
} }
@ -227,8 +218,7 @@ 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.
@ -240,19 +230,16 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
} else { } else {
return completion::INCOMPLETE; return completion::INCOMPLETE;
} }
} } 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)) {
$gradecfg = $DB->get_record($table, ["scale_id"=>$scale->id]); $gradecfg = $DB->get_record($table, ["scale_id"=>$scale->id]);
} } else if ($gradeitem->grademin == 0) {
else if ($gradeitem->grademin == 0) {
$gradecfg = $DB->get_record($table, ["grade_points"=>$gradeitem->grademax]); $gradecfg = $DB->get_record($table, ["grade_points"=>$gradeitem->grademax]);
} } else
else
{ {
$gradecfg = null; $gradecfg = null;
} }
@ -265,30 +252,24 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
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.
@ -298,12 +279,10 @@ 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

@ -113,8 +113,7 @@ class core_aggregator extends \local_treestudyplan\aggregator {
// Not met and time is passed, means FAILED. // Not met and time is passed, means FAILED.
if ($timing == "past") { if ($timing == "past") {
return completion::FAILED; return completion::FAILED;
} } else {
else {
// Check if any of the requirements are being met?. // Check if any of the requirements are being met?.
$completions = $completion->get_completions($userid); $completions = $completion->get_completions($userid);
foreach ($completions as $c) { foreach ($completions as $c) {
@ -126,8 +125,7 @@ class core_aggregator extends \local_treestudyplan\aggregator {
return completion::INCOMPLETE; return completion::INCOMPLETE;
} }
} }
} } else{
else{
return completion::INCOMPLETE; return completion::INCOMPLETE;
} }
} }
@ -148,20 +146,15 @@ class core_aggregator extends \local_treestudyplan\aggregator {
if ( $total == $statecount[completion::EXCELLENT]) { if ( $total == $statecount[completion::EXCELLENT]) {
return completion::EXCELLENT; return completion::EXCELLENT;
} } else if ( $total == $statecount[completion::EXCELLENT] + $statecount[completion::GOOD]) {
else if ( $total == $statecount[completion::EXCELLENT] + $statecount[completion::GOOD]) {
return completion::GOOD; return completion::GOOD;
} } else if ( $total == $statecount[completion::EXCELLENT] + $statecount[completion::GOOD] + $statecount[completion::COMPLETED]) {
else if ( $total == $statecount[completion::EXCELLENT] + $statecount[completion::GOOD] + $statecount[completion::COMPLETED]) {
return completion::COMPLETED; return completion::COMPLETED;
} } else if ( $statecount[completion::FAILED]) {
else if ( $statecount[completion::FAILED]) {
return completion::FAILED; return completion::FAILED;
} } else if ( $total == $statecount[completion::INCOMPLETE]) {
else if ( $total == $statecount[completion::INCOMPLETE]) {
return completion::INCOMPLETE; return completion::INCOMPLETE;
} } else {
else {
return completion::PROGRESS; return completion::PROGRESS;
} }
} }
@ -178,8 +171,7 @@ 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.
@ -191,19 +183,16 @@ class core_aggregator extends \local_treestudyplan\aggregator {
} else { } else {
return completion::INCOMPLETE; return completion::INCOMPLETE;
} }
} } 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)) {
$gradecfg = $DB->get_record($table, ["scale_id"=>$scale->id]); $gradecfg = $DB->get_record($table, ["scale_id"=>$scale->id]);
} } else if ($gradeitem->grademin == 0) {
else if ($gradeitem->grademin == 0) {
$gradecfg = $DB->get_record($table, ["grade_points"=>$gradeitem->grademax]); $gradecfg = $DB->get_record($table, ["grade_points"=>$gradeitem->grademax]);
} } else
else
{ {
$gradecfg = null; $gradecfg = null;
} }
@ -216,30 +205,24 @@ class core_aggregator extends \local_treestudyplan\aggregator {
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.
@ -249,12 +232,10 @@ 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

@ -71,20 +71,16 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
// state PROGRESS will not carry on if aggregations are chained. // state PROGRESS will not carry on if aggregations are chained.
if ($c_progress > 0) { if ($c_progress > 0) {
return completion::PROGRESS; return completion::PROGRESS;
} } else if ($c_pending > 0) {
else if ($c_pending > 0) {
return completion::PENDING; return completion::PENDING;
} } else {
else {
return completion::INCOMPLETE; return completion::INCOMPLETE;
} }
} }
} } else {
else {
return completion::INCOMPLETE; return completion::INCOMPLETE;
} }
} } else
else
{ {
// indeterminable, return null. // indeterminable, return null.
return null; return null;
@ -117,8 +113,7 @@ 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.
@ -131,8 +126,7 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
return completion::INCOMPLETE; return completion::INCOMPLETE;
} }
} } else {
else {
$finalgrade = $grade->finalgrade; $finalgrade = $grade->finalgrade;
$scale = $gradeinfo->getScale(); $scale = $gradeinfo->getScale();
@ -141,15 +135,12 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
if ($gradeitem->grademax > $gradeitem->gradepass && $finalgrade >= $gradeitem->grademax) { if ($gradeitem->grademax > $gradeitem->gradepass && $finalgrade >= $gradeitem->grademax) {
// If gradepass is configured . // If gradepass is configured .
return completion::EXCELLENT; return completion::EXCELLENT;
} } else if ($finalgrade >= $gradeitem->gradepass) {
else if ($finalgrade >= $gradeitem->gradepass) {
return completion::COMPLETED; return completion::COMPLETED;
} } else {
else {
return completion::PROGRESS; return completion::PROGRESS;
} }
} } 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.
@ -159,11 +150,9 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
if ($score > 0.85) { if ($score > 0.85) {
return completion::EXCELLENT; return completion::EXCELLENT;
} } else if ($score > 0.55) {
else if ($score > 0.55) {
return completion::COMPLETED; return completion::COMPLETED;
} } else {
else {
return completion::PROGRESS; return completion::PROGRESS;
} }
} }

View File

@ -182,11 +182,9 @@ class gradegenerator {
$scale = $gi->load_scale(); $scale = $gi->load_scale();
if ( isset($scale)) { if ( isset($scale)) {
$gradecfg = $DB->get_record($table, ["scale_id"=>$scale->id]); $gradecfg = $DB->get_record($table, ["scale_id"=>$scale->id]);
} } else if ($gi->grademin == 0) {
else if ($gi->grademin == 0) {
$gradecfg = $DB->get_record($table, ["grade_points"=>$gi->grademax]); $gradecfg = $DB->get_record($table, ["grade_points"=>$gi->grademax]);
} } else
else
{ {
$gradecfg = null; $gradecfg = null;
} }
@ -198,12 +196,10 @@ class gradegenerator {
// 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;// $grade = (rand(0, 100) > 15)?max(1, $gradecfg->min_progress-1):"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 );
$r = (object)["gi" => $g, "grade" => $grade, "fb" =>$gr->fb ]; $r = (object)["gi" => $g, "grade" => $grade, "fb" =>$gr->fb ];
} } else{
else{
// COMPLETED. // COMPLETED.
$r = (object)["gi" => $g, "grade" => rand( $gradecfg->min_completed, $gi->grademax ), "fb" =>$gr->fb ]; $r = (object)["gi" => $g, "grade" => rand( $gradecfg->min_completed, $gi->grademax ), "fb" =>$gr->fb ];
} }
@ -218,25 +214,21 @@ class gradegenerator {
} }
} }
} } else if ($gi->gradepass > 0) {
else if ($gi->gradepass > 0) {
if (!$gr->done) { if (!$gr->done) {
// INCOMPLETe or FAILED. // INCOMPLETe or FAILED.
$grade = rand(0, $gi->gradepass/2); $grade = rand(0, $gi->gradepass/2);
$r = (object)["gi" => $g, "grade" => $grade, "fb" =>($grade > 0)?$gr->fb:"" ]; $r = (object)["gi" => $g, "grade" => $grade, "fb" =>($grade > 0)?$gr->fb:"" ];
} } else if (!$gr->result) {
else if (!$gr->result) {
//PROGRESS. //PROGRESS.
$r = (object)["gi" => $g, "grade" => rand( round($gi->gradepass/2), $gi->gradepass -1 ), "fb" =>$gr->fb ]; $r = (object)["gi" => $g, "grade" => rand( round($gi->gradepass/2), $gi->gradepass -1 ), "fb" =>$gr->fb ];
} } else{
else{
// COMPLETED. // COMPLETED.
$r = (object)["gi" => $g, "grade" => rand( $gi->gradepass, $gi->grademax ), "fb" =>$gr->fb ]; $r = (object)["gi" => $g, "grade" => rand( $gi->gradepass, $gi->grademax ), "fb" =>$gr->fb ];
} }
$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.
@ -246,12 +238,10 @@ class gradegenerator {
// INCOMPLETe or FAILED. // INCOMPLETe or FAILED.
$grade = rand(0, round($range * 0.35) - 1); $grade = rand(0, round($range * 0.35) - 1);
$r = (object)["gi" => $g, "grade" => $gi->grademin+$grade, "fb" =>($grade > 0)?$gr->fb:"" ]; $r = (object)["gi" => $g, "grade" => $gi->grademin+$grade, "fb" =>($grade > 0)?$gr->fb:"" ];
} } else if (!$gr->result) {
else if (!$gr->result) {
//PROGRESS. //PROGRESS.
$r = (object)["gi" => $g, "grade" => $gi->grademin+rand(round($range * 0.35), round($range * 0.55) - 1 ), "fb" =>$gr->fb ]; $r = (object)["gi" => $g, "grade" => $gi->grademin+rand(round($range * 0.35), round($range * 0.55) - 1 ), "fb" =>$gr->fb ];
} } else{
else{
// COMPLETED. // COMPLETED.
$r = (object)["gi" => $g, "grade" => $gi->grademin+rand(round($range * 0.55) , $range ), "fb" =>$gr->fb ]; $r = (object)["gi" => $g, "grade" => $gi->grademin+rand(round($range * 0.55) , $range ), "fb" =>$gr->fb ];
} }
@ -287,7 +277,7 @@ class gradegenerator {
public function fromFile(string $filename) { public function fromFile(string $filename) {
$filename = self::expand_tilde($filename); $filename = self::expand_tilde($filename);
if (file_exists($filename)) { if (file_exists($filename)) {
try{ try {
$json = file_get_contents($filename); $json = file_get_contents($filename);
$this->unserialize($json); $this->unserialize($json);
} catch(Exception $x) { } catch(Exception $x) {

View File

@ -46,7 +46,8 @@ class debugger {
if (strlen($tag) > 0) { if (strlen($tag) > 0) {
$tag .= ":\n"; $tag .= ":\n";
} }
$this->writeblock($tag.print_r($object, true)); $o = json_encode($object);
$this->writeblock($tag.": ".$o);
} }
@ -65,6 +66,4 @@ class debugger {
fclose($fp); fclose($fp);
} }
} }
} }

View File

@ -51,8 +51,7 @@ class webservicehelper {
return true; return true;
} }
} }
} } else if (has_capability($capability, $context)) {
else if (has_capability($capability, $context)) {
return true; return true;
} }
} }
@ -122,7 +121,7 @@ class webservicehelper {
if (isset($contextid) && is_int($contextid) && $contextid > 0) { if (isset($contextid) && is_int($contextid) && $contextid > 0) {
if (!in_array($contextid, self::$validated_contexts)) { // Cache the context and make sure it is only validated once... if (!in_array($contextid, self::$validated_contexts)) { // Cache the context and make sure it is only validated once...
try{ try {
$context = \context::instance_by_id($contextid); $context = \context::instance_by_id($contextid);
} }
catch(\dml_missing_record_exception $x) { catch(\dml_missing_record_exception $x) {
@ -133,8 +132,7 @@ class webservicehelper {
self::$validated_contexts[$contextid] = $context; self::$validated_contexts[$contextid] = $context;
} }
return self::$validated_contexts[$contextid]; return self::$validated_contexts[$contextid];
} } else{
else{
return static::system_context(); // This function ensures the system context is validated just once this call. return static::system_context(); // This function ensures the system context is validated just once this call.
} }
} }

View File

@ -55,7 +55,7 @@ class period {
// Clamp period index . // Clamp period index .
$periodnr = 1; $periodnr = 1;
} }
try{ try {
$id = $DB->get_field(self::TABLE, "id", ["page_id"=>$page->id(), "period" => $periodnr], MUST_EXIST); $id = $DB->get_field(self::TABLE, "id", ["page_id"=>$page->id(), "period" => $periodnr], MUST_EXIST);
$period = self::findById($id); $period = self::findById($id);
} catch(\dml_missing_record_exception $x) { } catch(\dml_missing_record_exception $x) {
@ -70,7 +70,7 @@ class period {
$ydelta = $yend - $ystart; $ydelta = $yend - $ystart;
$ptime = $ydelta / $pcount; $ptime = $ydelta / $pcount;
try{ try {
// Check if we have a previous period to glance the end date of as a reference. // Check if we have a previous period to glance the end date of as a reference.
$startdate = $DB->get_field(self::TABLE, "enddate", ["page_id"=>$page->id(), "period" => $periodnr-1], MUST_EXIST); $startdate = $DB->get_field(self::TABLE, "enddate", ["page_id"=>$page->id(), "period" => $periodnr-1], MUST_EXIST);
$pstart = strtotime($startdate)+(24*60*60); // Add one day. $pstart = strtotime($startdate)+(24*60*60); // Add one day.
@ -78,7 +78,7 @@ class period {
// If not, do a fair guess. // If not, do a fair guess.
$pstart = $ystart + (($periodnr-1)*$ptime); $pstart = $ystart + (($periodnr-1)*$ptime);
} }
try{ try {
// Check if we have a next period to glance the start date of as a reference. // Check if we have a next period to glance the start date of as a reference.
$enddate = $DB->get_field(self::TABLE, "startdate", ["page_id"=>$page->id(), "period" => $periodnr+1], MUST_EXIST); $enddate = $DB->get_field(self::TABLE, "startdate", ["page_id"=>$page->id(), "period" => $periodnr+1], MUST_EXIST);
$pstart = strtotime($enddate)-(24*60*60); // subtract one day. $pstart = strtotime($enddate)-(24*60*60); // subtract one day.
@ -152,8 +152,7 @@ class period {
public function enddate() { public function enddate() {
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

@ -125,8 +125,7 @@ class studentstudyplanservice extends \external_api
if ($studyplan->has_linked_user($userid)) { if ($studyplan->has_linked_user($userid)) {
return $studyplan->user_model($userid); return $studyplan->user_model($userid);
} } else {
else {
return null; return null;
} }
} }
@ -239,8 +238,7 @@ class studentstudyplanservice extends \external_api
} else { } else {
return []; return [];
} }
} } else {
else {
$map = []; $map = [];
foreach ($studyplans as $studyplan) { foreach ($studyplans as $studyplan) {
$map[] = $studyplan->user_model($userid); $map[] = $studyplan->user_model($userid);
@ -283,8 +281,7 @@ class studentstudyplanservice extends \external_api
} else { } else {
return []; return [];
} }
} } else {
else {
$map = []; $map = [];
foreach ($studyplans as $studyplan) { foreach ($studyplans as $studyplan) {
$map[] = $studyplan->editor_model($userid); $map[] = $studyplan->editor_model($userid);

View File

@ -193,8 +193,7 @@ class studyitem {
foreach ($conn_out as $c) { foreach ($conn_out as $c) {
$model["connections"][] = $c->to_id(); $model["connections"][] = $c->to_id();
} }
} } else {
else {
foreach ($conn_out as $c) { foreach ($conn_out as $c) {
$model['connections']['out'][$c->to_id()] = $c->model(); $model['connections']['out'][$c->to_id()] = $c->model();
} }
@ -247,11 +246,9 @@ class studyitem {
// Check if referenced courses, badges and/or competencies still exist. // Check if referenced courses, badges and/or competencies still exist.
if ($this->r->type == static::COURSE) { if ($this->r->type == static::COURSE) {
return courseinfo::exists($this->r->course_id); return courseinfo::exists($this->r->course_id);
} } else if ($this->r->type == static::BADGE) {
else if ($this->r->type == static::BADGE) {
return badgeinfo::exists($this->r->badge_id); return badgeinfo::exists($this->r->badge_id);
} } else {
else {
return true; return true;
} }
} }
@ -271,8 +268,7 @@ 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);
@ -424,8 +420,7 @@ class studyitem {
// 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') {
// Does not need to use aggregator. // Does not need to use aggregator.
// Either true, or the completion of the reference. // Either true, or the completion of the reference.
if (self::exists($this->r->continuation_id)) { if (self::exists($this->r->continuation_id)) {
@ -434,8 +429,7 @@ class studyitem {
} else { } else {
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.
$in_completed = []; $in_completed = [];
// Retrieve incoming connections. // Retrieve incoming connections.
@ -445,8 +439,7 @@ class studyitem {
$in_completed[] = $item->completion($userid); $in_completed[] = $item->completion($userid);
} }
return $this->aggregator->aggregate_junction($in_completed, $this, $userid); return $this->aggregator->aggregate_junction($in_completed, $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)) {
@ -464,8 +457,7 @@ class studyitem {
} }
} }
return ($notexpired)?completion::COMPLETED:completion::INCOMPLETE; return ($notexpired)?completion::COMPLETED:completion::INCOMPLETE;
} } else{
else{
return completion::COMPLETED; return completion::COMPLETED;
} }
} else { } else {
@ -474,13 +466,11 @@ class studyitem {
} else { } else {
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;
} }

View File

@ -162,8 +162,7 @@ class studyline {
} else if (in_array($c->type(), self::FILTER_TYPES)) { } else if (in_array($c->type(), self::FILTER_TYPES)) {
$slotset = self::SLOTSET_FILTER; $slotset = self::SLOTSET_FILTER;
} }
} } else if (in_array($c->type(), self::FILTER0_TYPES)) {
else if (in_array($c->type(), self::FILTER0_TYPES)) {
$slotset = self::SLOTSET_FILTER; $slotset = self::SLOTSET_FILTER;
} }
if (isset($slotset)) { if (isset($slotset)) {
@ -221,8 +220,7 @@ class studyline {
// 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
{ {
$DB->delete_records(self::TABLE, ['id' => $this->id]); $DB->delete_records(self::TABLE, ['id' => $this->id]);
return success::success(); return success::success();
@ -310,8 +308,7 @@ class studyline {
} else if (in_array($c->type(), self::FILTER_TYPES)) { } else if (in_array($c->type(), self::FILTER_TYPES)) {
$slotset = self::SLOTSET_FILTER; $slotset = self::SLOTSET_FILTER;
} }
} } else if (in_array($c->type(), self::FILTER0_TYPES)) {
else if (in_array($c->type(), self::FILTER0_TYPES)) {
$slotset = self::SLOTSET_FILTER; $slotset = self::SLOTSET_FILTER;
} }
if (isset($slotset)) { if (isset($slotset)) {

View File

@ -85,7 +85,7 @@ class studyplan {
*/ */
public function context(): \context{ public function context(): \context{
if (!isset($this->context)) { if (!isset($this->context)) {
try{ try {
$this->context = contextinfo::by_id($this->r->context_id)->context; $this->context = contextinfo::by_id($this->r->context_id)->context;
} }
catch(\dml_missing_record_exception $x) { catch(\dml_missing_record_exception $x) {
@ -290,8 +290,7 @@ class studyplan {
if ($DB->count_records('local_treestudyplan_page', ['studyplan_id' => $this->id]) > 0) { if ($DB->count_records('local_treestudyplan_page', ['studyplan_id' => $this->id]) > 0) {
return success::fail('cannot delete studyplan that still has pages'); return success::fail('cannot delete studyplan that still has pages');
} } else
else
{ {
$DB->delete_records('local_treestudyplan', ['id' => $this->id]); $DB->delete_records('local_treestudyplan', ['id' => $this->id]);
return success::success(); return success::success();
@ -304,8 +303,7 @@ class studyplan {
if ($contextid <= 0) { if ($contextid <= 0) {
$ids = $DB->get_fieldset_select(self::TABLE, "id", ""); $ids = $DB->get_fieldset_select(self::TABLE, "id", "");
} } else{
else{
if ($contextid == 1) { if ($contextid == 1) {
$contextid = 1; $contextid = 1;
$where = "context_id <= :contextid OR context_id IS NULL"; $where = "context_id <= :contextid OR context_id IS NULL";
@ -557,8 +555,7 @@ class studyplan {
// Now import each page. // Now import each page.
return $plan->import_pages_model($content["studyplan"]["pages"]); return $plan->import_pages_model($content["studyplan"]["pages"]);
} } else {
else {
error_log("Invalid format and type: {$content['type']} version {$content['version']}"); error_log("Invalid format and type: {$content['type']} version {$content['version']}");
return false; return false;
} }
@ -571,13 +568,11 @@ class studyplan {
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.
return $this->import_pages_model($content["studyplan"]["pages"]); return $this->import_pages_model($content["studyplan"]["pages"]);
} }
} } else {
else {
return false; return false;
} }
} }

View File

@ -81,8 +81,7 @@ class studyplanpage {
public function enddate() { public function enddate() {
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"));
} }
@ -207,8 +206,7 @@ class studyplanpage {
if ($DB->count_records('local_treestudyplan_line', ['page_id' => $this->id]) > 0) { if ($DB->count_records('local_treestudyplan_line', ['page_id' => $this->id]) > 0) {
return success::fail('cannot delete studyplan page that still has studylines'); return success::fail('cannot delete studyplan page that still has studylines');
} } else
else
{ {
$DB->delete_records(self::TABLE, ['id' => $this->id]); $DB->delete_records(self::TABLE, ['id' => $this->id]);
return success::success(); return success::success();
@ -368,8 +366,7 @@ class studyplanpage {
if ($g["selected"]) { if ($g["selected"]) {
if ($first) { if ($first) {
$first = false; $first = false;
} } else{
else{
$csv .= "\r\n"; $csv .= "\r\n";
} }
$csv .= "- ".str_replace('"', '\'', $g["name"]); $csv .= "- ".str_replace('"', '\'', $g["name"]);
@ -444,11 +441,9 @@ class studyplanpage {
$content = json_decode($content, true); $content = json_decode($content, true);
if ($content["type"] == "periods" && $content["version"] >= 2.0) { if ($content["type"] == "periods" && $content["version"] >= 2.0) {
return $this->import_periods_model($content["perioddesc"]); return $this->import_periods_model($content["perioddesc"]);
} } else if ($content["type"] == "studyplanpage" && $content["version"] >= 2.0) {
else if ($content["type"] == "studyplanpage" && $content["version"] >= 2.0) {
return $this->import_periods_model($content["page"]["perioddesc"]); return $this->import_periods_model($content["page"]["perioddesc"]);
} } else {
else {
return false; return false;
} }
} }
@ -458,14 +453,11 @@ class studyplanpage {
$content = json_decode($content, true); $content = json_decode($content, true);
if ($content["type"] == "studylines" && $content["version"] >= 2.0) { if ($content["type"] == "studylines" && $content["version"] >= 2.0) {
return $this->import_studylines_model($content["studylines"]); return $this->import_studylines_model($content["studylines"]);
} } else if ($content["type"] == "studyplanpage" && $content["version"] >= 2.0) {
else if ($content["type"] == "studyplanpage" && $content["version"] >= 2.0) {
return $this->import_studylines_model($content["page"]["studylines"]); return $this->import_studylines_model($content["page"]["studylines"]);
} } else if ($content["type"] == "studyplan" && $content["version"] >= 2.0) {
else if ($content["type"] == "studyplan" && $content["version"] >= 2.0) {
return $this->import_studylines_model($content["studyplan"]["pages"][0]["studylines"]); return $this->import_studylines_model($content["studyplan"]["pages"][0]["studylines"]);
} } else {
else {
return false; return false;
} }
} }

View File

@ -91,8 +91,7 @@ class studyplanservice extends \external_api
$studyplan = studyplan::findById($id); $studyplan = studyplan::findById($id);
webservicehelper::require_capabilities([self::CAP_EDIT, self::CAP_VIEW], $studyplan->context()); webservicehelper::require_capabilities([self::CAP_EDIT, self::CAP_VIEW], $studyplan->context());
return $studyplan->editor_model(); return $studyplan->editor_model();
} } else {
else {
return null; return null;
} }
} }
@ -638,8 +637,7 @@ class studyplanservice extends \external_api
if (has_capability('local/treestudyplan:editstudyplan', studyitem::findById($item_id)->context()) || if (has_capability('local/treestudyplan:editstudyplan', studyitem::findById($item_id)->context()) ||
is_enrolled($coursecontext, $USER, 'local/treestudyplan:selectowngradables')) { is_enrolled($coursecontext, $USER, 'local/treestudyplan:selectowngradables')) {
return gradeinfo::include_grade($grade_id, $item_id, $include, $required)->model(); return gradeinfo::include_grade($grade_id, $item_id, $include, $required)->model();
} } else {
else {
return success::fail("Access denied")->model(); return success::fail("Access denied")->model();
} }
@ -736,8 +734,7 @@ class studyplanservice extends \external_api
$result = $gi->update("local/treestudyplan"); // update, signalling with our signature and bulkupdate. $result = $gi->update("local/treestudyplan"); // update, signalling with our signature and bulkupdate.
$debug = ""; $debug = "";
if ($result) { $updated = "converted";} if ($result) { $updated = "converted";} else { $updated = "error";}
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.
@ -756,8 +753,7 @@ class studyplanservice extends \external_api
} }
} }
} } else {
else {
$updated = "skipped"; $updated = "skipped";
} }
@ -899,7 +895,7 @@ class studyplanservice extends \external_api
} }
public static function export_plan($studyplan_id, $format="json") { public static function export_plan($studyplan_id, $format="json") {
try{ try {
// Validate permissions. // Validate permissions.
webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::findById($studyplan_id)->context()); webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::findById($studyplan_id)->context());
@ -907,8 +903,7 @@ class studyplanservice extends \external_api
if ($format == "csv") { if ($format == "csv") {
// FIXME: Make sure this webservice function gets called for the page instead of the studyplan. // FIXME: Make sure this webservice function gets called for the page instead of the studyplan.
return $plan->pages()[0]->export_page_csv(); return $plan->pages()[0]->export_page_csv();
} } else{
else{
return $plan->export_plan(); return $plan->export_plan();
} }
} }
@ -930,7 +925,7 @@ class studyplanservice extends \external_api
public static function export_studylines($studyplan_id) { public static function export_studylines($studyplan_id) {
$systemcontext = webservicehelper::system_context(); $systemcontext = webservicehelper::system_context();
try{ try {
webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::findById($studyplan_id)->context()); webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::findById($studyplan_id)->context());
$plan = studyplan::findById($studyplan_id); $plan = studyplan::findById($studyplan_id);
// FIXME: Make sure this gets called for the page instead of the studyplan. // FIXME: Make sure this gets called for the page instead of the studyplan.
@ -960,7 +955,7 @@ class studyplanservice extends \external_api
public static function import_plan($content, $format="application/json", $context_id=1) { public static function import_plan($content, $format="application/json", $context_id=1) {
try{ try {
// Validate import context. // Validate import context.
$context = webservicehelper::find_context($context_id); $context = webservicehelper::find_context($context_id);
webservicehelper::require_capabilities(self::CAP_EDIT, $context); webservicehelper::require_capabilities(self::CAP_EDIT, $context);
@ -987,7 +982,7 @@ class studyplanservice extends \external_api
public static function import_studylines($studyplan_id, $content, $format="application/json") { public static function import_studylines($studyplan_id, $content, $format="application/json") {
try{ try {
$plan = studyplan::findById($studyplan_id); $plan = studyplan::findById($studyplan_id);
// Validate import context. // Validate import context.
webservicehelper::require_capabilities(self::CAP_EDIT, $plan->context()); webservicehelper::require_capabilities(self::CAP_EDIT, $plan->context());
@ -1155,11 +1150,9 @@ class studyplanservice extends \external_api
// Determine end period number - Clip span between 1 and last period. // Determine end period number - Clip span between 1 and last period.
if ($span <= 1) { if ($span <= 1) {
$pend = $pstart; $pend = $pstart;
} } else if ($periodnr + ($span - 1) > $page->periods()) {
else if ($periodnr + ($span - 1) > $page->periods()) {
$pend = $periods[$page->periods()]; $pend = $periods[$page->periods()];
} } else {
else {
$pend = $periods[$periodnr + ($span - 1)]; $pend = $periods[$periodnr + ($span - 1)];
} }

View File

@ -60,7 +60,6 @@ if ($options['help']) {
cli_writeln($usage); cli_writeln($usage);
exit(2); exit(2);
} }
//cli_writeln(print_r($options, true));.
if (empty($options['studyplan']) && empty($options["all"])) { if (empty($options['studyplan']) && empty($options["all"])) {
cli_error('Missing mandatory argument studyplan.', 2); cli_error('Missing mandatory argument studyplan.', 2);

View File

@ -152,7 +152,6 @@ foreach ($plans as $plan) {
$ug->feedbacktext = nl2br( htmlspecialchars($gg->fb)); $ug->feedbacktext = nl2br( htmlspecialchars($gg->fb));
$ug->feedbackformat = FORMAT_HTML; $ug->feedbackformat = FORMAT_HTML;
//print_r($ug);.
if (!$options["dryrun"]) { if (!$options["dryrun"]) {
$a->update_grade($ug); $a->update_grade($ug);
@ -175,8 +174,7 @@ foreach ($plans as $plan) {
} }
} }
} }
} } else
else
{ {
cli_writeln(" Skipping since it has not started yet"); cli_writeln(" Skipping since it has not started yet");
} }

View File

@ -379,8 +379,7 @@ function xmldb_local_treestudyplan_upgrade($oldversion) {
if ($yend < $ystart) { if ($yend < $ystart) {
// If no end time is given, assume a year duration for period calculations. // If no end time is given, assume a year duration for period calculations.
$ydelta = (365*24*60*60)/$pcount; $ydelta = (365*24*60*60)/$pcount;
} } else{
else{
$ydelta = $yend - $ystart; $ydelta = $yend - $ystart;
} }
$ptime = $ydelta / $pcount; $ptime = $ydelta / $pcount;

View File

@ -47,8 +47,7 @@ if ( in_array($mime, $text_types)) {
print $OUTPUT->header(); print $OUTPUT->header();
print file_get_contents($file); print file_get_contents($file);
print $OUTPUT->footer(); print $OUTPUT->footer();
} } else {
else {
header("Content-type: {$mime}"); header("Content-type: {$mime}");
print file_get_contents($file); print file_get_contents($file);
} }

View File

@ -40,8 +40,7 @@ $PAGE->set_context($systemcontext);
if ($update > 0) { if ($update > 0) {
$PAGE->set_title(get_string('invite_desc_edit', 'local_treestudyplan')); $PAGE->set_title(get_string('invite_desc_edit', 'local_treestudyplan'));
$PAGE->set_heading(get_string('invite_desc_edit', 'local_treestudyplan')); $PAGE->set_heading(get_string('invite_desc_edit', 'local_treestudyplan'));
} } else
else
{ {
$PAGE->set_title(get_string('invite_desc_new', 'local_treestudyplan')); $PAGE->set_title(get_string('invite_desc_new', 'local_treestudyplan'));
$PAGE->set_heading(get_string('invite_desc_new', 'local_treestudyplan')); $PAGE->set_heading(get_string('invite_desc_new', 'local_treestudyplan'));
@ -58,8 +57,7 @@ if (!empty($add)) {
'add' => 1, 'add' => 1,
); );
} } else if (!empty($update)) {
else if (!empty($update)) {
$data = $DB->get_record("local_treestudyplan_invit", array('id' => $update)); $data = $DB->get_record("local_treestudyplan_invit", array('id' => $update));
$data->update = $update; $data->update = $update;
if (empty($data) || $data->user_id != $USER->id) if (empty($data) || $data->user_id != $USER->id)
@ -68,8 +66,7 @@ else if (!empty($update)) {
exit; exit;
} }
} } else if (!empty($resend)) {
else if (!empty($resend)) {
$data = $DB->get_record("local_treestudyplan_invit", array('id' => $resend)); $data = $DB->get_record("local_treestudyplan_invit", array('id' => $resend));
$data->resend = $resend; $data->resend = $resend;
if (empty($data) || $data->user_id != $USER->id) if (empty($data) || $data->user_id != $USER->id)
@ -86,8 +83,7 @@ else if (!empty($resend)) {
redirect("$CFG->wwwroot/local/treestudyplan/invitations.php?sent={$resend}"); redirect("$CFG->wwwroot/local/treestudyplan/invitations.php?sent={$resend}");
print $OUTPUT->footer(); print $OUTPUT->footer();
exit; exit;
} } else if (!empty($delete)) {
else if (!empty($delete)) {
$data = $DB->get_record("local_treestudyplan_invit", array('id' => $delete)); $data = $DB->get_record("local_treestudyplan_invit", array('id' => $delete));
$data->delete = $delete; $data->delete = $delete;
if (empty($data) || $data->user_id != $USER->id) if (empty($data) || $data->user_id != $USER->id)
@ -101,8 +97,7 @@ else if (!empty($delete)) {
redirect("$CFG->wwwroot/local/treestudyplan/invitations.php"); redirect("$CFG->wwwroot/local/treestudyplan/invitations.php");
print $OUTPUT->footer(); print $OUTPUT->footer();
exit; exit;
} } else {
else {
print_error('invalidaction'); print_error('invalidaction');
} }
@ -111,8 +106,7 @@ $mform->set_data($data);
if ($mform->is_cancelled()) { if ($mform->is_cancelled()) {
redirect("$CFG->wwwroot/local/treestudyplan/invitations.php"); redirect("$CFG->wwwroot/local/treestudyplan/invitations.php");
} } else if ($data = $mform->get_data()) {
else if ($data = $mform->get_data()) {
if (!empty($data->update)) if (!empty($data->update))
{ {
@ -150,8 +144,7 @@ else if ($data = $mform->get_data()) {
exit; exit;
} } else
else
{ {
$data = null; $data = null;
if ($unitid > 0) if ($unitid > 0)

View File

@ -37,8 +37,7 @@ $contextid = optional_param('contextid', 0, PARAM_INT); // Context id.
if ($categoryid > 0) { if ($categoryid > 0) {
$studyplancontext = context_coursecat::instance($categoryid); $studyplancontext = context_coursecat::instance($categoryid);
} } else if ($contextid > 0) {
else if ($contextid > 0) {
$studyplancontext = context::instance_by_id($contextid); $studyplancontext = context::instance_by_id($contextid);
if (in_array($studyplancontext->contextlevel, [CONTEXT_SYSTEM, CONTEXT_COURSECAT])) if (in_array($studyplancontext->contextlevel, [CONTEXT_SYSTEM, CONTEXT_COURSECAT]))
{ {
@ -48,8 +47,7 @@ else if ($contextid > 0) {
{ {
$studyplancontext = $systemcontext; $studyplancontext = $systemcontext;
} }
} } else
else
{ {
// If no context is selected, find the first available one. // If no context is selected, find the first available one.
$available_contexts = courseservice::list_accessible_categories_with_usage("edit"); $available_contexts = courseservice::list_accessible_categories_with_usage("edit");

View File

@ -25,8 +25,7 @@ if (isset($_SERVER['SCRIPT_FILENAME'])) {
$root = dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME']))); $root = dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME'])));
error_log("Using {$root}/config.php"); error_log("Using {$root}/config.php");
require_once($root."/config.php"); require_once($root."/config.php");
} } else
else
{ {
// If not, assume the cwd is not symlinked and proceed as we are used to. // If not, assume the cwd is not symlinked and proceed as we are used to.
require_once("../../config.php"); require_once("../../config.php");
@ -105,8 +104,7 @@ if (count($invites) > 0) {
print "</td>"; print "</td>";
} }
} } else
else
{ {
print "<tr><td colspan='6'>".get_string('invite_table_empty', 'local_treestudyplan')."</td></tr>"; print "<tr><td colspan='6'>".get_string('invite_table_empty', 'local_treestudyplan')."</td></tr>";
} }

View File

@ -54,8 +54,7 @@ if (empty($invite)) {
print $OUTPUT->footer(); print $OUTPUT->footer();
exit; exit;
} } else
else
{ {
// Load javascripts and specific css. // Load javascripts and specific css.
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/bootstrap-vue/bootstrap-vue.css')); $PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/bootstrap-vue/bootstrap-vue.css'));

View File

@ -292,8 +292,7 @@ function local_treestudyplan_get_cohort_path($cohort) {
$ctxpath[] = $cohort->name; $ctxpath[] = $cohort->name;
return implode(" / ", $ctxpath); return implode(" / ", $ctxpath);
} } else
else
{ {
return $cohort->name; return $cohort->name;
} }

View File

@ -37,8 +37,7 @@ $contextid = optional_param('contextid', 0, PARAM_INT); // Context id.
if ($categoryid > 0) { if ($categoryid > 0) {
$studyplancontext = context_coursecat::instance($categoryid); $studyplancontext = context_coursecat::instance($categoryid);
} } else if ($contextid > 0) {
else if ($contextid > 0) {
$studyplancontext = context::instance_by_id($contextid); $studyplancontext = context::instance_by_id($contextid);
if (in_array($studyplancontext->contextlevel, [CONTEXT_SYSTEM, CONTEXT_COURSECAT])) if (in_array($studyplancontext->contextlevel, [CONTEXT_SYSTEM, CONTEXT_COURSECAT]))
{ {
@ -48,8 +47,7 @@ else if ($contextid > 0) {
{ {
$studyplancontext = $systemcontext; $studyplancontext = $systemcontext;
} }
} } else
else
{ {
// If no context is selected, find the first available one. // If no context is selected, find the first available one.
$available_contexts = courseservice::list_accessible_categories_with_usage("view"); $available_contexts = courseservice::list_accessible_categories_with_usage("view");