From a531ce80d7e86f0693341ffe3bdb5511633eb9e2 Mon Sep 17 00:00:00 2001 From: PMKuipers Date: Fri, 25 Aug 2023 09:33:42 +0200 Subject: [PATCH] Moodle code style fixes part 3 --- cfg_grades.php | 65 ++++----- classes/aggregator.php | 12 +- classes/associationservice.php | 94 ++++++------ classes/badgeinfo.php | 4 +- classes/completion.php | 3 +- classes/completionscanner.php | 38 ++--- classes/corecompletioninfo.php | 40 +++--- classes/courseinfo.php | 3 +- classes/coursemoduleinfo.php | 4 +- classes/courseservice.php | 30 ++-- classes/gradeinfo.php | 26 ++-- classes/gradingscanner.php | 36 +++-- .../local/aggregators/bistate_aggregator.php | 47 +++--- classes/local/aggregators/core_aggregator.php | 5 +- .../local/aggregators/tristate_aggregator.php | 27 ++-- classes/local/gradegenerator.php | 3 +- classes/local/helpers/webservicehelper.php | 8 +- .../local/ungradedscanners/assign_scanner.php | 14 +- .../local/ungradedscanners/quiz_scanner.php | 16 +-- .../local/ungradedscanners/scanner_base.php | 4 +- classes/privacy/provider.php | 28 ++-- classes/studyitem.php | 53 ++++--- classes/studyitemconnection.php | 30 ++-- classes/studyline.php | 35 +++-- classes/studyplan.php | 31 ++-- classes/studyplanpage.php | 21 ++- classes/studyplanservice.php | 134 +++++++++--------- classes/task/refreshteacherlist.php | 4 +- classes/teachingfinder.php | 18 +-- cli/randomize_grades.php | 7 +- doc.php | 4 +- edit-invite.php | 6 +- edit-plan.php | 7 +- invitations.php | 10 +- invited.php | 3 +- lib.php | 19 ++- settings.php | 18 +-- view-plan.php | 7 +- 38 files changed, 445 insertions(+), 469 deletions(-) diff --git a/cfg_grades.php b/cfg_grades.php index ae055e3..0a7074b 100644 --- a/cfg_grades.php +++ b/cfg_grades.php @@ -36,13 +36,13 @@ const GRADECFG_TABLE = "local_treestudyplan_gradecfg"; $scales = \grade_scale::fetch_all_global(); $mappings = $DB->get_records(GRADECFG_TABLE); -$scale_cfgs = []; -$grade_cfgs = []; +$scalecfgs = []; +$gradecfgs = []; foreach ($mappings as $cfg) { if (!empty($cfg->scale_id)) { - $scale_cfgs[$cfg->scale_id] = $cfg; + $scalecfgs[$cfg->scale_id] = $cfg; } else if (!empty($cfg->grade_points)) { - $grade_cfgs[$cfg->grade_points] = $cfg; + $gradecfgs[$cfg->grade_points] = $cfg; } } @@ -51,8 +51,8 @@ print $OUTPUT->header(); if ($_POST["action"] == "update") { // First loop through the scales to see which need to be updated. foreach ($scales as $scale) { - if (array_key_exists($scale->id, $scale_cfgs)) { - $scalecfg = $scale_cfgs[$scale->id]; + if (array_key_exists($scale->id, $scalecfgs)) { + $scalecfg = $scalecfgs[$scale->id]; $needupdate = false; foreach (["min_progress", "min_completed"] as $handle) { @@ -84,19 +84,18 @@ if ($_POST["action"] == "update") { // Insert into database and add to the list of scale configs. $id = $DB->insert_record(GRADECFG_TABLE, $scalecfg); $scalecfg = $DB->get_record(GRADECFG_TABLE, ['id' => $id]); - $scale_cfgs[$id] = $scalecfg; + $scalecfgs[$id] = $scalecfg; } } } // Now, loop through the gradepoints to parse . $deletelist = []; - foreach ($grade_cfgs as $gradecfg) { + foreach ($gradecfgs as $gradecfg) { $deletekey = "g_{$gradecfg->grade_points}_delete"; if (array_key_exists($deletekey, $_POST) && boolval($_POST[$deletekey]) === true) { $DB->delete_records(GRADECFG_TABLE, ["id" => $gradecfg->id]); $deletelist[] = $gradecfg; - } else - { + } else { foreach (["min_progress", "min_completed"] as $handle) { $key = "g_{$gradecfg->grade_points}_{$handle}"; if (array_key_exists($key, $_POST) && is_numeric($_POST[$key])) { @@ -105,19 +104,21 @@ if ($_POST["action"] == "update") { } $DB->update_record(GRADECFG_TABLE, $gradecfg); // reload to ensure proper rounding is done. - $grade_cfgs[$gradecfg->grade_points] = $DB->get_record(GRADECFG_TABLE, ['id' => $gradecfg->id]); + $gradecfgs[$gradecfg->grade_points] = $DB->get_record(GRADECFG_TABLE, ['id' => $gradecfg->id]); } } foreach ($deletelist as $gradeconfig) { - unset($grade_cfgs[$gradecfg->grade_points]); + unset($gradecfgs[$gradecfg->grade_points]); } unset($deletelist); // And add an optionally existing new gradepoint setting. - if (array_key_exists("g_new_gradepoints", $_POST) && !empty($_POST["g_new_gradepoints"]) && is_numeric($_POST["g_new_gradepoints"]) ) { + if (array_key_exists("g_new_gradepoints", $_POST) + && !empty($_POST["g_new_gradepoints"]) + && is_numeric($_POST["g_new_gradepoints"]) ) { $gp = intval($_POST["g_new_gradepoints"]); - if (!array_key_exists($gp, $grade_cfgs)) { + if (!array_key_exists($gp, $gradecfgs)) { $gradecfg = (object)[ "grade_points" => $gp]; $requireinsert = false; foreach (["min_progress", "min_completed"] as $handle) { @@ -132,7 +133,7 @@ if ($_POST["action"] == "update") { $id = $DB->insert_record(GRADECFG_TABLE, $gradecfg); // reload to ensure proper rounding is done. $gradecfg = $DB->get_record(GRADECFG_TABLE, ['id' => $id]); - $grade_cfgs[$id] = $gradecfg; + $gradecfgs[$id] = $gradecfg; } } } @@ -146,45 +147,45 @@ $data = []; foreach ($scales as $scale) { $scale->load_items(); $scalecfg = null; - if (array_key_exists($scale->id, $scale_cfgs)) { - $scalecfg = $scale_cfgs[$scale->id]; + if (array_key_exists($scale->id, $scalecfgs)) { + $scalecfg = $scalecfgs[$scale->id]; } - $attrs_c = ['value' => '', 'disabled' => 'disabled', ]; - $attrs_p = ['value' => '', 'disabled' => 'disabled', ]; + $attrsc = ['value' => '', 'disabled' => 'disabled', ]; + $attrsp = ['value' => '', 'disabled' => 'disabled', ]; if (!isset($scalecfg) || $scalecfg->min_completed == "") { - $attrs_c["selected"] = "selected"; + $attrsc["selected"] = "selected"; } if (!isset($scalecfg) || $scalecfg->min_progress == "") { - $attrs_p["selected"] = "selected"; + $attrsp["selected"] = "selected"; } - $options_completed = html_writer::tag("option", get_string('select_scaleitem', 'local_treestudyplan'), $attrs_c); - $options_progress = html_writer::tag("option", get_string('select_scaleitem', 'local_treestudyplan'), $attrs_p); + $optionscompleted = html_writer::tag("option", get_string('select_scaleitem', 'local_treestudyplan'), $attrsc); + $optionsprogress = html_writer::tag("option", get_string('select_scaleitem', 'local_treestudyplan'), $attrsp); $key = 1; // Start counting by one, as used in sum aggregations. foreach ($scale->scale_items as $value) { - $attrs_c = ["value" => $key]; - $attrs_p = ["value" => $key]; + $attrsc = ["value" => $key]; + $attrsp = ["value" => $key]; if (isset($scalecfg)) { if (intval($scalecfg->min_completed) == $key) { - $attrs_c["selected"] = "selected"; + $attrsc["selected"] = "selected"; } if (intval($scalecfg->min_progress) == $key) { - $attrs_p["selected"] = "selected"; + $attrsp["selected"] = "selected"; } } - $options_progress .= html_writer::tag("option", $value, $attrs_p); - $options_completed .= html_writer::tag("option", $value, $attrs_c); + $optionsprogress .= html_writer::tag("option", $value, $attrsp); + $optionscompleted .= html_writer::tag("option", $value, $attrsc); $key++; } $row = []; $row[] = $scale->name; - //$row[] = html_writer::tag("select", $options_progress, ['name' => "s_{$scale->id}_min_progress", 'autocomplete' => 'off']) ;. - $row[] = html_writer::tag("select", $options_completed, ['name' => "s_{$scale->id}_min_completed", 'autocomplete' => 'off']) ; + //$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']) ; $data[] = $row; } @@ -209,7 +210,7 @@ print $OUTPUT->heading(get_string('cfg_grades_scales', 'local_treestudyplan')); print html_writer::tag('div', html_writer::table($table), ['class'=>'flexible-wrap']); $data = []; -foreach ($grade_cfgs as $g) { +foreach ($gradecfgs as $g) { $row = []; $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']) ;. diff --git a/classes/aggregator.php b/classes/aggregator.php index f67b321..cb383a8 100644 --- a/classes/aggregator.php +++ b/classes/aggregator.php @@ -26,13 +26,13 @@ require_once($CFG->libdir.'/externallib.php'); abstract class aggregator { private const FALLBACK = "bistate"; - private static $mod_supported = []; + private static $modsupported = []; public static function supported($mod) { - if (!array_key_exists($mod, self::$mod_supported)) { - self::$mod_supported[$mod] = class_exists(self::aggregator_name($mod)); + if (!array_key_exists($mod, self::$modsupported)) { + self::$modsupported[$mod] = class_exists(self::aggregator_name($mod)); } - return self::$mod_supported[$mod]; + return self::$modsupported[$mod]; } private static function aggregator_name($mod) { @@ -51,8 +51,8 @@ abstract class aggregator { public static function create($mod, $configstr) { if (self::supported($mod)) { - $ag_class = self::aggregator_name($mod); - return new $ag_class($configstr); + $agclass = self::aggregator_name($mod); + return new $agclass($configstr); } else { throw new \InvalidArgumentException("Cannot find aggregator '{$mod}'"); } diff --git a/classes/associationservice.php b/classes/associationservice.php index 44d25e2..abc34b3 100644 --- a/classes/associationservice.php +++ b/classes/associationservice.php @@ -112,12 +112,12 @@ class associationservice extends \external_api } // Actual functions. - public static function list_cohort($like='', $exclude_id=null, $context_id=1) + public static function list_cohort($like='', $excludeid=null, $contextid=1) { global $CFG, $DB; // Only allow this if the user has the right to edit in this context. - $context = webservicehelper::find_context($context_id); + $context = webservicehelper::find_context($contextid); webservicehelper::require_capabilities(self::CAP_EDIT, $context); $pattern = "%{$like}%"; @@ -126,14 +126,14 @@ class associationservice extends \external_api $sql = "SELECT c.* from {cohort} c LEFT JOIN {local_treestudyplan_cohort} j ON c.id = j.cohort_id"; $sql .= " WHERE c.visible = 1 AND(name LIKE :pattern_nm OR idnumber LIKE :pattern_id)"; - if (isset($exclude_id) && is_numeric($exclude_id)) { + if (isset($excludeid) && is_numeric($excludeid)) { $sql .= " AND (j.studyplan_id IS NULL OR j.studyplan_id != :exclude_id)"; - $params['exclude_id'] = $exclude_id; + $params['exclude_id'] = $excludeid; } - if ($context_id > 1) { // system context returns all cohorts, including system cohorts. + if ($contextid > 1) { // system context returns all cohorts, including system cohorts. // otherwise, . $sql .= " AND contextid = :context_id"; - $params['context_id'] = $context_id; + $params['context_id'] = $contextid; } $cohorts = []; @@ -160,12 +160,12 @@ class associationservice extends \external_api } // Actual functions. - public static function find_user($like, $exclude_id=null, $context_id=1) + public static function find_user($like, $excludeid=null, $contextid=1) { global $CFG, $DB; // Only allow this if the user has the right to edit in this context (using system rights would make things more confusing). - $context = webservicehelper::find_context($context_id); + $context = webservicehelper::find_context($contextid); webservicehelper::require_capabilities(self::CAP_EDIT, $context); $pattern = "%{$like}%"; @@ -175,9 +175,9 @@ class associationservice extends \external_api ]; $sql = "SELECT u.* from {user} u LEFT JOIN {local_treestudyplan_user} j ON u.id = j.user_id"; $sql .= " WHERE u.deleted != 1 AND (firstname LIKE :pattern_fn OR lastname LIKE :pattern_ln OR username LIKE :pattern_un)"; - if (isset($exclude_id) && is_numeric($exclude_id)) { + if (isset($excludeid) && is_numeric($excludeid)) { $sql .= " AND (j.studyplan_id IS NULL OR j.studyplan_id != :exclude_id)"; - $params['exclude_id'] = $exclude_id; + $params['exclude_id'] = $excludeid; } $users = []; @@ -208,17 +208,17 @@ class associationservice extends \external_api } // Actual functions. - public static function connect_cohort($studyplan_id, $cohort_id) + public static function connect_cohort($studyplanid, $cohortid) { global $CFG, $DB; - $studyplan = studyplan::findById($studyplan_id); + $studyplan = studyplan::findById($studyplanid); webservicehelper::require_capabilities(self::CAP_EDIT, $studyplan->context()); - if (!$DB->record_exists('local_treestudyplan_cohort', ['studyplan_id' => $studyplan_id, 'cohort_id' => $cohort_id])) { + if (!$DB->record_exists('local_treestudyplan_cohort', ['studyplan_id' => $studyplanid, 'cohort_id' => $cohortid])) { $id = $DB->insert_record('local_treestudyplan_cohort', [ - 'studyplan_id' => $studyplan_id, - 'cohort_id' => $cohort_id, + 'studyplan_id' => $studyplanid, + 'cohort_id' => $cohortid, ]); $studyplan->mark_csync_changed(); @@ -247,17 +247,17 @@ class associationservice extends \external_api } // Actual functions. - public static function disconnect_cohort($studyplan_id, $cohort_id) + public static function disconnect_cohort($studyplanid, $cohortid) { global $CFG, $DB; - $studyplan = studyplan::findById($studyplan_id); + $studyplan = studyplan::findById($studyplanid); webservicehelper::require_capabilities(self::CAP_EDIT, $studyplan->context()); - if ($DB->record_exists('local_treestudyplan_cohort', ['studyplan_id' => $studyplan_id, 'cohort_id' => $cohort_id])) { + if ($DB->record_exists('local_treestudyplan_cohort', ['studyplan_id' => $studyplanid, 'cohort_id' => $cohortid])) { $DB->delete_records('local_treestudyplan_cohort', [ - 'studyplan_id' => $studyplan_id, - 'cohort_id' => $cohort_id, + 'studyplan_id' => $studyplanid, + 'cohort_id' => $cohortid, ]); $studyplan->mark_csync_changed(); @@ -286,17 +286,17 @@ class associationservice extends \external_api } // Actual functions. - public static function connect_user($studyplan_id, $user_id) + public static function connect_user($studyplanid, $userid) { global $CFG, $DB; - $studyplan = studyplan::findById($studyplan_id); + $studyplan = studyplan::findById($studyplanid); webservicehelper::require_capabilities(self::CAP_EDIT, $studyplan->context()); - if (!$DB->record_exists('local_treestudyplan_user', ['studyplan_id' => $studyplan_id, 'user_id' => $user_id])) { + if (!$DB->record_exists('local_treestudyplan_user', ['studyplan_id' => $studyplanid, 'user_id' => $userid])) { $id = $DB->insert_record('local_treestudyplan_user', [ - 'studyplan_id' => $studyplan_id, - 'user_id' => $user_id, + 'studyplan_id' => $studyplanid, + 'user_id' => $userid, ]); $studyplan->mark_csync_changed(); @@ -324,16 +324,16 @@ class associationservice extends \external_api } // Actual functions. - public static function disconnect_user($studyplan_id, $user_id) + public static function disconnect_user($studyplanid, $userid) { global $CFG, $DB; - $studyplan = studyplan::findById($studyplan_id); + $studyplan = studyplan::findById($studyplanid); webservicehelper::require_capabilities(self::CAP_EDIT, $studyplan->context()); - if ($DB->record_exists('local_treestudyplan_user', ['studyplan_id' => $studyplan_id, 'user_id' => $user_id])) { + if ($DB->record_exists('local_treestudyplan_user', ['studyplan_id' => $studyplanid, 'user_id' => $userid])) { $DB->delete_records('local_treestudyplan_user', [ - 'studyplan_id' => $studyplan_id, - 'user_id' => $user_id, + 'studyplan_id' => $studyplanid, + 'user_id' => $userid, ]); $studyplan->mark_csync_changed(); @@ -357,15 +357,15 @@ class associationservice extends \external_api } // Actual functions. - public static function associated_users($studyplan_id) + public static function associated_users($studyplanid) { global $CFG, $DB; - $studyplan = studyplan::findById($studyplan_id); + $studyplan = studyplan::findById($studyplanid); webservicehelper::require_capabilities(self::CAP_VIEW, $studyplan->context()); $sql = "SELECT DISTINCT u.* FROM {user} u INNER JOIN {local_treestudyplan_user} j ON j.user_id = u.id"; $sql .= " WHERE j.studyplan_id = :studyplan_id"; - $rs = $DB->get_recordset_sql($sql, ['studyplan_id' => $studyplan_id]); + $rs = $DB->get_recordset_sql($sql, ['studyplan_id' => $studyplanid]); $users = []; foreach ($rs as $u) { @@ -389,15 +389,15 @@ class associationservice extends \external_api } // Actual functions. - public static function associated_cohorts($studyplan_id) + public static function associated_cohorts($studyplanid) { global $CFG, $DB; - $studyplan = studyplan::findById($studyplan_id); + $studyplan = studyplan::findById($studyplanid); webservicehelper::require_capabilities(self::CAP_VIEW, $studyplan->context()); $sql = "SELECT DISTINCT c.* FROM {cohort} c INNER JOIN {local_treestudyplan_cohort} j ON j.cohort_id = c.id"; $sql .= " WHERE j.studyplan_id = :studyplan_id"; - $rs = $DB->get_recordset_sql($sql, ['studyplan_id' => $studyplan_id]); + $rs = $DB->get_recordset_sql($sql, ['studyplan_id' => $studyplanid]); $cohorts = []; foreach ($rs as $c) { $cohorts[] = self::make_cohort_model($c); @@ -420,11 +420,11 @@ class associationservice extends \external_api } // Actual functions. - public static function all_associated($studyplan_id) + public static function all_associated($studyplanid) { global $CFG, $DB; - $studyplan = studyplan::findById($studyplan_id); + $studyplan = studyplan::findById($studyplanid); webservicehelper::require_capabilities(self::CAP_VIEW, $studyplan->context()); @@ -436,8 +436,8 @@ class associationservice extends \external_api LEFT JOIN {cohort_members} cm ON u.id = cm.userid LEFT JOIN {local_treestudyplan_cohort} tc ON cm.cohortid = tc.cohort_id LEFT JOIN {local_treestudyplan_user} tu ON u.id = tu.user_id - WHERE tc.studyplan_id = {$studyplan_id} - OR tu.studyplan_id = {$studyplan_id} + WHERE tc.studyplan_id = {$studyplanid} + OR tu.studyplan_id = {$studyplanid} ORDER BY u.lastname, u.firstname"; $rs = $DB->get_recordset_sql($sql); @@ -454,16 +454,16 @@ class associationservice extends \external_api return usort($list, function($a, $b) { $m= []; if (preg_match("/.*?([A-Z].*)/", $a['lastname'], $m)) { - $sort_ln_a = $m[1]; + $sortln_a = $m[1]; } else { - $sort_ln_a = $a['lastname']; + $sortln_a = $a['lastname']; } if (preg_match("/.*?([A-Z].*)/", $b['lastname'], $m)) { - $sort_ln_b = $m[1]; + $sortln_b = $m[1]; } else { - $sort_ln_b = $b['lastname']; + $sortln_b = $b['lastname']; } - $cmp= $sort_ln_a <=> $sort_ln_b; + $cmp= $sortln_a <=> $sortln_b; return ($cmp != 0)?$cmp:$a['firstname'] <=> $b['firstname']; }); } @@ -481,9 +481,9 @@ class associationservice extends \external_api } // Actual functions. - public static function cascade_cohortsync($studyplan_id) + public static function cascade_cohortsync($studyplanid) { - $studyplan = studyplan::findById($studyplan_id); + $studyplan = studyplan::findById($studyplanid); webservicehelper::require_capabilities(self::CAP_EDIT, $studyplan->context()); $enroller = new cascadecohortsync($studyplan); diff --git a/classes/badgeinfo.php b/classes/badgeinfo.php index bda081e..01e9b26 100644 --- a/classes/badgeinfo.php +++ b/classes/badgeinfo.php @@ -154,10 +154,10 @@ class badgeinfo { return $badge; } - function count_issued(array $student_ids) { + function count_issued(array $studentids) { $issuecount = 0; - foreach ($student_ids as $userid) { + foreach ($studentids as $userid) { if ($this->badge->is_issued($userid)) { $issuecount++; } diff --git a/classes/completion.php b/classes/completion.php index 9a7a48a..e1c2b75 100644 --- a/classes/completion.php +++ b/classes/completion.php @@ -45,8 +45,7 @@ class completion { public static function label($completion) { if (array_key_exists($completion, self::LABELS)) { return self::LABELS[$completion]; - } else - { + } else { return self::LABELS[self::INCOMPLETE]; } } diff --git a/classes/completionscanner.php b/classes/completionscanner.php index f69515a..dda0d77 100644 --- a/classes/completionscanner.php +++ b/classes/completionscanner.php @@ -27,33 +27,33 @@ use \grade_item; class completionscanner { - private static $mod_supported = []; - private static $course_students = []; + private static $modsupported = []; + private static $coursestudents = []; private $scanner = null; private $course = null; private $cm = null; private $gi = null; - private $pending_cache = []; + private $pendingcache = []; public static function supported($mod) { - if (!array_key_exists($mod, self::$mod_supported)) { - self::$mod_supported[$mod] = class_exists("\local_treestudyplan\\local\\ungradedscanners\\{$mod}_scanner"); + if (!array_key_exists($mod, self::$modsupported)) { + self::$modsupported[$mod] = class_exists("\local_treestudyplan\\local\\ungradedscanners\\{$mod}_scanner"); } - return self::$mod_supported[$mod]; + return self::$modsupported[$mod]; } public static function get_course_students($courseid) { global $CFG; - if (!array_key_exists($courseid, self::$course_students)) { + if (!array_key_exists($courseid, self::$coursestudents)) { $students = []; $context = \context_course::instance($courseid); foreach (explode(', ', $CFG->gradebookroles) as $roleid) { $roleid = trim($roleid); $students = array_keys(get_role_users($roleid, $context, false, 'u.id', 'u.id ASC')); } - self::$course_students[$courseid] = $students; + self::$coursestudents[$courseid] = $students; } - return self::$course_students[$courseid]; + return self::$coursestudents[$courseid]; } public function __construct(\completion_criteria $crit, $course) { @@ -112,8 +112,8 @@ class completionscanner $students = self::get_course_students($this->courseid); $completed = 0; $ungraded = 0; - $completed_pass = 0; - $completed_fail = 0; + $completedpass = 0; + $completedfail = 0; foreach ($students as $userid) { if ($this->pending($userid)) { // First check if the completion needs grading. @@ -123,13 +123,13 @@ class completionscanner if ($this->crit->criteriatype == COMPLETION_CRITERIA_TYPE_ACTIVITY) { // If it's an activity completion, add all the relevant activities as sub-items. - $completion_status = $this->completioninfo->get_grade_completion($this->cm, $userid); + $completionstatus = $this->completioninfo->get_grade_completion($this->cm, $userid); - if ($completion_status == COMPLETION_COMPLETE_PASS) { - $completed_pass++; - } else if ($completion_status == COMPLETION_COMPLETE_FAIL) { - $completed_fail++; - } else if ($completion_status == COMPLETION_COMPLETE) { + if ($completionstatus == COMPLETION_COMPLETE_PASS) { + $completedpass++; + } else if ($completionstatus == COMPLETION_COMPLETE_FAIL) { + $completedfail++; + } else if ($completionstatus == COMPLETION_COMPLETE) { $completed++; } } else{ @@ -145,8 +145,8 @@ class completionscanner return [ 'ungraded' => $ungraded, 'completed' => $completed, - 'completed_pass' => $completed_pass, - 'completed_fail' => $completed_fail, + 'completed_pass' => $completedpass, + 'completed_fail' => $completedfail, 'students' => count($students), ]; } diff --git a/classes/corecompletioninfo.php b/classes/corecompletioninfo.php index 92452a0..9a315e4 100644 --- a/classes/corecompletioninfo.php +++ b/classes/corecompletioninfo.php @@ -35,7 +35,7 @@ class corecompletioninfo { private $course; private $completion; private $modinfo; - private static $COMPLETION_HANDLES = null; + private static $COMPLETIONHANDLES = null; public function id() { return $this->course->id; @@ -48,10 +48,10 @@ class corecompletioninfo { } static public function completiontypes() { - global $COMPLETION_CRITERIA_TYPES; + global $COMPLETIONCRITERIA_TYPES; // Just return the keys of the global array COMPLETION_CRITERIA_TYPES, so we don't have to manually. // add any completion types.... - return \array_keys($COMPLETION_CRITERIA_TYPES); + return \array_keys($COMPLETIONCRITERIA_TYPES); } /** @@ -59,16 +59,16 @@ class corecompletioninfo { * @param $completion The completion code as defined in completionlib.php to translate to a text handle */ static public function completion_handle($completion) { - if (empty(self::$COMPLETION_HANDLES)) { + if (empty(self::$COMPLETIONHANDLES)) { // Cache the translation table, to avoid overhead. - self::$COMPLETION_HANDLES = [ + self::$COMPLETIONHANDLES = [ COMPLETION_INCOMPLETE => "incomplete", COMPLETION_COMPLETE => "complete", COMPLETION_COMPLETE_PASS => "complete-pass", COMPLETION_COMPLETE_FAIL => "complete-fail", COMPLETION_COMPLETE_FAIL_HIDDEN => "complete-fail"]; // the front end won't differentiate between hidden or not. } - return self::$COMPLETION_HANDLES[$completion] ?? "undefined"; + return self::$COMPLETIONHANDLES[$completion] ?? "undefined"; } public static function completion_item_editor_structure($value=VALUE_REQUIRED) { @@ -155,7 +155,7 @@ class corecompletioninfo { } public function editor_model() { - global $DB, $CFG, $COMPLETION_CRITERIA_TYPES; + global $DB, $CFG, $COMPLETIONCRITERIA_TYPES; $conditions = []; $aggregation = "all"; // default. @@ -174,7 +174,7 @@ class corecompletioninfo { if (count($criterias) > 0 ) // Only take it into account if the criteria count is > 0. { $cinfo = [ - "type" => $COMPLETION_CRITERIA_TYPES[$type], + "type" => $COMPLETIONCRITERIA_TYPES[$type], "aggregation" => self::aggregation_handle($this->completion->get_aggregation_method($type)), "title" => reset($criterias)->get_type_title(), "items" => [], @@ -325,7 +325,7 @@ class corecompletioninfo { } public function user_model($userid) { - global $DB, $COMPLETION_CRITERIA_TYPES; + global $DB, $COMPLETIONCRITERIA_TYPES; $progress = $this->get_advanced_progress_percentage($userid); $info = [ @@ -349,7 +349,7 @@ class corecompletioninfo { $typeaggregation = $this->completion->get_aggregation_method($type); $completed = $this->aggregate_completions($typeaggregation, $completions); $cinfo = [ - "type" => $COMPLETION_CRITERIA_TYPES[$type], + "type" => $COMPLETIONCRITERIA_TYPES[$type], "aggregation" => self::aggregation_handle($typeaggregation), "completed" => $completed, "status" => $completed?"complete":"incomplete", @@ -376,10 +376,10 @@ class corecompletioninfo { if ($type == COMPLETION_CRITERIA_TYPE_ACTIVITY) { $cm = $this->modinfo->get_cm($criteria->moduleinstance); // If it's an activity completion, add all the relevant activities as sub-items. - $completion_status = $this->completion->get_grade_completion($cm, $userid); - $iinfo['status'] = self::completion_handle($completion_status); + $completionstatus = $this->completion->get_grade_completion($cm, $userid); + $iinfo['status'] = self::completion_handle($completionstatus); // Re-evaluate the completed value, to make sure COMPLETE_FAIL doesn't creep in as completed. - $iinfo['completed'] = in_array($completion_status, [COMPLETION_COMPLETE, COMPLETION_COMPLETE_PASS]); + $iinfo['completed'] = in_array($completionstatus, [COMPLETION_COMPLETE, COMPLETION_COMPLETE_PASS]); // Determine the grade (retrieve from grade item, not from completion). $grade = $this->get_grade($cm, $userid); $iinfo['grade'] = $grade->grade; @@ -388,7 +388,7 @@ class corecompletioninfo { $anypending = $anypending || $grade->pending; // Overwrite the status with progress if something has been graded, or is pending. - if ($completion_status != COMPLETION_INCOMPLETE || $anypending) { + if ($completionstatus != COMPLETION_INCOMPLETE || $anypending) { if ($cinfo["status"] == "incomplete") { $cinfo["status"] = "progress"; } @@ -455,8 +455,7 @@ class corecompletioninfo { if (isset($scale)) { // get scale value. $result->grade = $scale->get_nearest_item($grade->finalgrade); - } else - { + } else { // round final grade to 1 decimal point. $result->grade = round($grade->finalgrade, 1); } @@ -496,8 +495,7 @@ class corecompletioninfo { if (isset($scale)) { // get scale value. return $scale->get_nearest_item($grade->finalgrade); - } else - { + } else { // round final grade to 1 decimal point. return round($grade->finalgrade, 1); } @@ -627,7 +625,7 @@ class corecompletioninfo { // Now that we have all completions sorted by type, we can be smart about how to do the count. $count = 0; $completed = 0; - $completion_percentage = 0; + $completionpercentage = 0; foreach ($critcount as $c) { // Take only types that are actually present into account. if ($c->count > 0) { @@ -644,10 +642,10 @@ class corecompletioninfo { // Overwrite data if current type is more complete. if ($aggregation == COMPLETION_AGGREGATION_ANY) { $pct = $cmpl/$ct; - if ($pct > $completion_percentage) { + if ($pct > $completionpercentage) { $count = $ct; $completed = $cmpl; - $completion_percentage = $pct; + $completionpercentage = $pct; } } // if ALL completion for the types, add the count for this type to that of the others. diff --git a/classes/courseinfo.php b/classes/courseinfo.php index 39c73f5..01bac12 100644 --- a/classes/courseinfo.php +++ b/classes/courseinfo.php @@ -78,8 +78,7 @@ class courseinfo { global $USER, $DB; if ($userid <= 0) { $usr = $USER; - } else - { + } else { $usr = $DB->get_record('user', ['id' => $userid, 'deleted' => 0]); } return($usr && is_enrolled($this->coursecontext, $usr, 'local/treestudyplan:selectowngradables')); diff --git a/classes/coursemoduleinfo.php b/classes/coursemoduleinfo.php index 26c5957..ecb744d 100644 --- a/classes/coursemoduleinfo.php +++ b/classes/coursemoduleinfo.php @@ -32,8 +32,8 @@ use \grade_item; class coursemoduleinfo { private $id; private $cm; - private $cm_info; - private $db_record; + private $cminfo; + private $dbrecord; public function __construct($id) { global $DB; diff --git a/classes/courseservice.php b/classes/courseservice.php index 00a34dd..6a92de6 100644 --- a/classes/courseservice.php +++ b/classes/courseservice.php @@ -69,10 +69,10 @@ class courseservice extends \external_api return new \external_single_structure($s, "CourseCat info", $value); } - public static function map_categories($root_id = 0) { + public static function map_categories($rootid = 0) { global $CFG, $DB; - $root = \core_course_category::get($root_id); + $root = \core_course_category::get($rootid); $context = $root->get_context(); // Make sure the user has access to the context for editing purposes. webservicehelper::require_capabilities(self::CAP_EDIT, $context); @@ -81,11 +81,11 @@ class courseservice extends \external_api if ($root->id == 0) { // on the system level, determine the user's topmost allowed catecories. - $user_top = \core_course_category::user_top(); - if ($user_top->id == 0) { // top category.. + $usertop = \core_course_category::user_top(); + if ($usertop->id == 0) { // top category.. $children = $root->get_children(); // returns a list of çore_course_category, let it overwrite $children. } else { - $children = [$user_top]; + $children = [$usertop]; } } else if ($root->is_uservisible()) { $children = [$root]; @@ -117,13 +117,13 @@ class courseservice extends \external_api protected static function map_category(\core_course_category $cat, $lazy=false) { global $DB; $catcontext = $cat->get_context(); - $ctx_info = new contextinfo($catcontext); + $ctxinfo = new contextinfo($catcontext); $children = $cat->get_children(); // only shows children visible to the current user. $courses = $cat->get_courses(); $model = [ "id" => $cat->id, "context_id" => $catcontext->id, - "category" => $ctx_info->model(), + "category" => $ctxinfo->model(), "haschildren" => !empty($children), "hascourses" => !empty($courses), ]; @@ -236,11 +236,11 @@ class courseservice extends \external_api } else { // $operation == "view" || default. $capability = self::CAP_VIEW; } - $context_ids = []; + $contextids = []; $rs = $DB->get_recordset_sql("SELECT DISTINCT context_id, COUNT(*) as num FROM {local_treestudyplan} GROUP BY context_id"); foreach ($rs as $r) { - $context_ids[$r->context_id] = $r->num; + $contextids[$r->context_id] = $r->num; } $rs->close(); @@ -253,8 +253,8 @@ class courseservice extends \external_api foreach ($cats as $cat) { $count = 0; $ctxid = $cat->get_context()->id; - if (array_key_exists($ctxid, $context_ids)) { - $count = $context_ids[$ctxid]; + if (array_key_exists($ctxid, $contextids)) { + $count = $contextids[$ctxid]; } $o = static::map_category($cat, true); @@ -272,11 +272,11 @@ class courseservice extends \external_api $capability = self::CAP_VIEW; } // retrieve context ids used. - $context_ids = []; + $contextids = []; $rs = $DB->get_recordset_sql("SELECT DISTINCT context_id, COUNT(*) as num FROM {local_treestudyplan} GROUP BY context_id"); foreach ($rs as $r) { - $context_ids[$r->context_id] = $r->num; + $contextids[$r->context_id] = $r->num; } $rs->close(); @@ -288,8 +288,8 @@ class courseservice extends \external_api foreach ($cats as $cat) { $count = 0; $ctxid = $cat->get_context()->id; - if (array_key_exists($ctxid, $context_ids)) { - $count = $context_ids[$ctxid]; + if (array_key_exists($ctxid, $contextids)) { + $count = $contextids[$ctxid]; } $o = new \stdClass(); $o->cat = $cat; diff --git a/classes/gradeinfo.php b/classes/gradeinfo.php index 8bd450b..1313609 100644 --- a/classes/gradeinfo.php +++ b/classes/gradeinfo.php @@ -245,12 +245,10 @@ class gradeinfo { $finalgrade = "-"; } else if (isset($this->scale)) { $finalgrade = $this->scale->get_nearest_item($grade->finalgrade); - } else - { + } else { $finalgrade = round($grade->finalgrade, 1); } - } else - { + } else { $finalgrade = "-"; } @@ -290,13 +288,13 @@ class gradeinfo { } public static function import(studyitem $item, array $model) { if ($item->type() == studyitem::COURSE) { - $course_id = $item->courseid(); - $gradeitems= grade_item::fetch_all(['itemtype' => 'mod', 'courseid' => $course_id]); + $courseid = $item->courseid(); + $gradeitems= grade_item::fetch_all(['itemtype' => 'mod', 'courseid' => $courseid]); foreach ($gradeitems as $gi) { - $gi_name = empty($outcome)?$gi->itemname:$outcome->name; - $gi_type = $gi->itemmodule; + $giname = empty($outcome)?$gi->itemname:$outcome->name; + $gitype = $gi->itemmodule; - if ($gi_name == $model["name"] && $gi_type == $model["type"]) { + if ($giname == $model["name"] && $gitype == $model["type"]) { // we have a match. if (!isset($model["selected"])) { $model["selected"] = true;} if (!isset($model["required"])) { $model["required"] = false;} @@ -368,27 +366,27 @@ class gradeinfo { return $list; } - public static function include_grade(int $grade_id, int $item_id, bool $include, bool $required=false) { + public static function include_grade(int $gradeid, int $itemid, bool $include, bool $required=false) { global $DB; $table = 'local_treestudyplan_gradeinc'; if ($include) { // make sure a record exits. - $r = $DB->get_record($table, ['studyitem_id' => $item_id, 'grade_item_id' => $grade_id]); + $r = $DB->get_record($table, ['studyitem_id' => $itemid, 'grade_item_id' => $gradeid]); if ($r) { $r->include = 1; $r->required = boolval($required)?1:0; $id = $DB->update_record($table, $r); } else { $DB->insert_record($table, [ - 'studyitem_id' => $item_id, - 'grade_item_id' => $grade_id, + 'studyitem_id' => $itemid, + 'grade_item_id' => $gradeid, 'include' => 1, 'required' =>boolval($required)?1:0] ); } } else { // remove if it should not be included. - $r = $DB->get_record($table, ['studyitem_id' => $item_id, 'grade_item_id' => $grade_id]); + $r = $DB->get_record($table, ['studyitem_id' => $itemid, 'grade_item_id' => $gradeid]); if ($r) { $DB->delete_records($table, ['id' => $r->id]); } diff --git a/classes/gradingscanner.php b/classes/gradingscanner.php index 10d00ee..3b75445 100644 --- a/classes/gradingscanner.php +++ b/classes/gradingscanner.php @@ -30,31 +30,31 @@ use \grade_item; // $gi->iteminstance. class gradingscanner { - private static $mod_supported = []; - private static $course_students = []; + private static $modsupported = []; + private static $coursestudents = []; private $scanner = null; private $gi = null; - private $pending_cache = []; + private $pendingcache = []; public static function supported($mod) { - if (!array_key_exists($mod, self::$mod_supported)) { - self::$mod_supported[$mod] = class_exists("\local_treestudyplan\\local\\ungradedscanners\\{$mod}_scanner"); + if (!array_key_exists($mod, self::$modsupported)) { + self::$modsupported[$mod] = class_exists("\local_treestudyplan\\local\\ungradedscanners\\{$mod}_scanner"); } - return self::$mod_supported[$mod]; + return self::$modsupported[$mod]; } public static function get_course_students($courseid) { global $CFG; - if (!array_key_exists($courseid, self::$course_students)) { + if (!array_key_exists($courseid, self::$coursestudents)) { $students = []; $context = \context_course::instance($courseid); foreach (explode(', ', $CFG->gradebookroles) as $roleid) { $roleid = trim($roleid); $students = array_keys(get_role_users($roleid, $context, false, 'u.id', 'u.id ASC')); } - self::$course_students[$courseid] = $students; + self::$coursestudents[$courseid] = $students; } - return self::$course_students[$courseid]; + return self::$coursestudents[$courseid]; } public function __construct(grade_item $gi) { @@ -96,8 +96,8 @@ class gradingscanner $students = self::get_course_students($this->courseid); $completed = 0; $ungraded = 0; - $completed_pass = 0; - $completed_fail = 0; + $completedpass = 0; + $completedfail = 0; foreach ($students as $userid) { if ($this->pending($userid)) { // First check if the completion needs grading. @@ -106,13 +106,12 @@ class gradingscanner $grade = $this->gi->get_final($userid); if (!is_numeric($grade->finalgrade) && empty($grade->finalgrade)) { //skip. - } else - { + } else { //compare grade to minimum grade. if ($this->grade_passed($grade)) { - $completed_pass++; + $completedpass++; } else { - $completed_fail++; + $completedfail++; } } } @@ -121,8 +120,8 @@ class gradingscanner return [ 'ungraded' => $ungraded, 'completed' => $completed, - 'completed_pass' => $completed_pass, - 'completed_fail' => $completed_fail, + 'completed_pass' => $completedpass, + 'completed_fail' => $completedfail, 'students' => count($students), ]; @@ -139,8 +138,7 @@ class gradingscanner $gradecfg = $DB->get_record($table, ["scale_id"=>$scale->id]); } else if ($this->gi->grademin == 0) { $gradecfg = $DB->get_record($table, ["grade_points"=>$this->gi->grademax]); - } else - { + } else { $gradecfg = null; } diff --git a/classes/local/aggregators/bistate_aggregator.php b/classes/local/aggregators/bistate_aggregator.php index 0512a5d..55c41b6 100644 --- a/classes/local/aggregators/bistate_aggregator.php +++ b/classes/local/aggregators/bistate_aggregator.php @@ -33,12 +33,12 @@ class bistate_aggregator extends \local_treestudyplan\aggregator { public const DEPRECATED = false; private const DEFAULT_CONDITION = "50"; - private $thresh_excellent = 1.0; // Minimum fraction that must be completed to aggregate as excellent (usually 1.0). - private $thresh_good = 0.8; // Minimum fraction that must be completed to aggregate as good. - private $thresh_completed = 0.66; // Minimum fraction that must be completed to aggregate as completed. - private $use_failed = True; // Support failed completion yes/no. - private $thresh_progress = 0.33; // Minimum fraction that must be failed to aggregate as failed instead of progress. - private $accept_pending_as_submitted = False; // Also count ungraded but submitted . + private $threshexcellent = 1.0; // Minimum fraction that must be completed to aggregate as excellent (usually 1.0). + private $threshgood = 0.8; // Minimum fraction that must be completed to aggregate as good. + private $threshcompleted = 0.66; // Minimum fraction that must be completed to aggregate as completed. + private $usefailed = True; // Support failed completion yes/no. + private $threshprogress = 0.33; // Minimum fraction that must be failed to aggregate as failed instead of progress. + private $acceptpending_as_submitted = False; // Also count ungraded but submitted . public function __construct($configstr) { // allow public constructor for testing purposes. @@ -104,10 +104,10 @@ class bistate_aggregator extends \local_treestudyplan\aggregator { // return te following conditions. // Possible states:. - // - completion::EXCELLENT - At least $thresh_excellent fraction of goals are complete and all required goals are met. - // - completion::GOOD - At least $thresh_good fraction of goals are complete and all required goals are met. - // - completion::COMPLETED - At least $thresh_complete fraction of goals are completed and all required goals are met. - // - completion::FAILED - At least $thresh_progress fraction of goals is not failed. + // - 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::COMPLETED - At least $threshcomplete fraction of goals are completed and all required goals are met. + // - completion::FAILED - At least $threshprogress fraction of goals is not failed. // - completion::INCOMPLETE - No goals have been started. // - completion::PROGRESS - All other states. @@ -118,33 +118,33 @@ class bistate_aggregator extends \local_treestudyplan\aggregator { $failed = 0; $started = 0; - $total_required = 0; - $required_met = 0; + $totalrequired = 0; + $requiredmet = 0; - $MIN_PROGRESS = ($this->accept_pending_as_submitted)?completion::PENDING:completion::PROGRESS; + $MINPROGRESS = ($this->accept_pending_as_submitted)?completion::PENDING:completion::PROGRESS; foreach ($completions as $index => $c) { $completed += ($c >= completion::COMPLETED)?1:0; - $progress += ($c >= $MIN_PROGRESS)?1:0; + $progress += ($c >= $MINPROGRESS)?1:0; $failed += ($c <= completion::FAILED)?1:0; } $started = $progress + $failed; - $allrequiredmet = ($required_met >= $total_required); + $allrequiredmet = ($requiredmet >= $totalrequired); - $fraction_completed = ($total >0)?(floatval($completed)/floatval($total)):0.0; - $fraction_progress = ($total >0)?(floatval($progress)/floatval($total)):0.0; - $fraction_failed = ($total >0)?(floatval($failed)/floatval($total)):0.0; - $fraction_started = ($total >0)?(floatval($started)/floatval($total)):0.0; + $fractioncompleted = ($total >0)?(floatval($completed)/floatval($total)):0.0; + $fractionprogress = ($total >0)?(floatval($progress)/floatval($total)):0.0; + $fractionfailed = ($total >0)?(floatval($failed)/floatval($total)):0.0; + $fractionstarted = ($total >0)?(floatval($started)/floatval($total)):0.0; if ($total == 0) { return completion::INCOMPLETE; } - if ($fraction_completed >= $this->thresh_excellent && $allrequiredmet) { + if ($fractioncompleted >= $this->thresh_excellent && $allrequiredmet) { return completion::EXCELLENT; - } else if ($fraction_completed >= $this->thresh_good && $allrequiredmet) { + } else if ($fractioncompleted >= $this->thresh_good && $allrequiredmet) { return completion::GOOD; - } else if ($fraction_completed >= $this->thresh_completed && $allrequiredmet) { + } else if ($fractioncompleted >= $this->thresh_completed && $allrequiredmet) { return completion::COMPLETED; } else if ($started == 0) { return completion::INCOMPLETE; @@ -239,8 +239,7 @@ class bistate_aggregator extends \local_treestudyplan\aggregator { $gradecfg = $DB->get_record($table, ["scale_id"=>$scale->id]); } else if ($gradeitem->grademin == 0) { $gradecfg = $DB->get_record($table, ["grade_points"=>$gradeitem->grademax]); - } else - { + } else { $gradecfg = null; } diff --git a/classes/local/aggregators/core_aggregator.php b/classes/local/aggregators/core_aggregator.php index 2313e41..ebf34fc 100644 --- a/classes/local/aggregators/core_aggregator.php +++ b/classes/local/aggregators/core_aggregator.php @@ -32,7 +32,7 @@ use \local_treestudyplan\debug; class core_aggregator extends \local_treestudyplan\aggregator { public const DEPRECATED = false; - private $accept_pending_as_submitted = False; // Also count ungraded but submitted . + private $acceptpending_as_submitted = False; // Also count ungraded but submitted . public function __construct($configstr) { // allow public constructor for testing purposes. @@ -192,8 +192,7 @@ class core_aggregator extends \local_treestudyplan\aggregator { $gradecfg = $DB->get_record($table, ["scale_id"=>$scale->id]); } else if ($gradeitem->grademin == 0) { $gradecfg = $DB->get_record($table, ["grade_points"=>$gradeitem->grademax]); - } else - { + } else { $gradecfg = null; } diff --git a/classes/local/aggregators/tristate_aggregator.php b/classes/local/aggregators/tristate_aggregator.php index 190f09f..fa7986c 100644 --- a/classes/local/aggregators/tristate_aggregator.php +++ b/classes/local/aggregators/tristate_aggregator.php @@ -40,19 +40,19 @@ class tristate_aggregator extends \local_treestudyplan\aggregator { protected function aggregate_completion(array $a, $condition = "50") { if (in_array($condition, ['ALL', '67', '50', 'ANY'])) { // condition is one of the valid conditions. - $c_completed = 0; - $c_excellent = 0; - $c_progress = 0; - $c_pending = 0; + $ccompleted = 0; + $cexcellent = 0; + $cprogress = 0; + $cpending = 0; $count = sizeof($a); if ($count > 0) { foreach ($a as $c) { - $c_progress += ($c>=completion::PROGRESS)?1:0; - $c_completed += ($c>=completion::COMPLETED)?1:0; - $c_excellent += ($c>=completion::EXCELLENT)?1:0; - $c_pending += ($c>=completion::PENDING)?1:0; + $cprogress += ($c>=completion::PROGRESS)?1:0; + $ccompleted += ($c>=completion::COMPLETED)?1:0; + $cexcellent += ($c>=completion::EXCELLENT)?1:0; + $cpending += ($c>=completion::PENDING)?1:0; } $required = [ @@ -62,16 +62,16 @@ class tristate_aggregator extends \local_treestudyplan\aggregator { 'ANY' => 1, ][$condition]; - if ($c_excellent >= $required) { + if ($cexcellent >= $required) { return completion::EXCELLENT; - } else if ($c_completed >= $required) { + } else if ($ccompleted >= $required) { return completion::COMPLETED; } else { // 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. - if ($c_progress > 0) { + if ($cprogress > 0) { return completion::PROGRESS; - } else if ($c_pending > 0) { + } else if ($cpending > 0) { return completion::PENDING; } else { return completion::INCOMPLETE; @@ -80,8 +80,7 @@ class tristate_aggregator extends \local_treestudyplan\aggregator { } else { return completion::INCOMPLETE; } - } else - { + } else { // indeterminable, return null. return null; } diff --git a/classes/local/gradegenerator.php b/classes/local/gradegenerator.php index a1d4c89..6964f2e 100644 --- a/classes/local/gradegenerator.php +++ b/classes/local/gradegenerator.php @@ -184,8 +184,7 @@ class gradegenerator { $gradecfg = $DB->get_record($table, ["scale_id"=>$scale->id]); } else if ($gi->grademin == 0) { $gradecfg = $DB->get_record($table, ["grade_points"=>$gi->grademax]); - } else - { + } else { $gradecfg = null; } diff --git a/classes/local/helpers/webservicehelper.php b/classes/local/helpers/webservicehelper.php index 376d124..f31d908 100644 --- a/classes/local/helpers/webservicehelper.php +++ b/classes/local/helpers/webservicehelper.php @@ -28,7 +28,7 @@ require_once($CFG->dirroot.'/webservice/lib.php'); class webservicehelper { /** @var \context_system */ private static $systemcontext = null; - private static $validated_contexts = []; + private static $validatedcontexts = []; /** * Test for capability in the given context for the current user and throw a \webservice_access_exception if not @@ -120,7 +120,7 @@ class webservicehelper { public static function find_context($contextid): \context{ 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::$validatedcontexts)) { // Cache the context and make sure it is only validated once... try { $context = \context::instance_by_id($contextid); } @@ -129,9 +129,9 @@ class webservicehelper { } // Validate the found context. \external_api::validate_context($context); - self::$validated_contexts[$contextid] = $context; + self::$validatedcontexts[$contextid] = $context; } - return self::$validated_contexts[$contextid]; + return self::$validatedcontexts[$contextid]; } else{ return static::system_context(); // This function ensures the system context is validated just once this call. } diff --git a/classes/local/ungradedscanners/assign_scanner.php b/classes/local/ungradedscanners/assign_scanner.php index b2b2d9c..833228a 100644 --- a/classes/local/ungradedscanners/assign_scanner.php +++ b/classes/local/ungradedscanners/assign_scanner.php @@ -54,22 +54,22 @@ class assign_scanner extends scanner_base { } - public function count_ungraded($course_userids=[]) { + public function count_ungraded($courseuserids=[]) { $ungraded = $this->get_ungraded_submissions(); - if (count($course_userids) > 0) { - $ungraded = array_intersect($ungraded, $course_userids); + if (count($courseuserids) > 0) { + $ungraded = array_intersect($ungraded, $courseuserids); } return count($ungraded); } - public function count_graded($course_userids=[]) { + public function count_graded($courseuserids=[]) { $ungraded = $this->get_ungraded_submissions(); $graded = $this->get_graded_users(); - if (count($course_userids) > 0) { - $ungraded = array_intersect($ungraded, $course_userids); - $graded = array_intersect($graded, $course_userids); + if (count($courseuserids) > 0) { + $ungraded = array_intersect($ungraded, $courseuserids); + $graded = array_intersect($graded, $courseuserids); } // determine how many id's have a grade, but also an ungraded submission. diff --git a/classes/local/ungradedscanners/quiz_scanner.php b/classes/local/ungradedscanners/quiz_scanner.php index e6aa1b6..951989a 100644 --- a/classes/local/ungradedscanners/quiz_scanner.php +++ b/classes/local/ungradedscanners/quiz_scanner.php @@ -43,8 +43,8 @@ class quiz_scanner extends scanner_base { $submissions = []; foreach ($rs as $r) { // Now, check if . - $maxstate_sql = "SELECT MAX(qas.sequencenumber) FROM {question_attempt_steps} qas WHERE qas.questionattemptid = {$r->attempt_id}"; - $max = $DB->get_field_sql($maxstate_sql); + $maxstatesql = "SELECT MAX(qas.sequencenumber) FROM {question_attempt_steps} qas WHERE qas.questionattemptid = {$r->attempt_id}"; + $max = $DB->get_field_sql($maxstatesql); if ($r->sequencenumber == $max) { $submissions[$r->userid] = true; // set array index based on user id, to avoid checking if value is in array. } @@ -53,15 +53,15 @@ class quiz_scanner extends scanner_base { return array_keys($submissions); } - public function count_ungraded($course_userids=[]) { + public function count_ungraded($courseuserids=[]) { $ungraded = $this->get_ungraded_submissions(); - if (count($course_userids) > 0) { - $ungraded = array_intersect($ungraded, $course_userids); + if (count($courseuserids) > 0) { + $ungraded = array_intersect($ungraded, $courseuserids); } return count($ungraded); } - public function count_graded($course_userids=[]) { + public function count_graded($courseuserids=[]) { // count all users who submitted one or more finished tests. global $DB; $sql = "SELECT DISTINCT g.userid @@ -72,8 +72,8 @@ class quiz_scanner extends scanner_base { $graded = $DB->get_fieldset_sql($sql); - if (count($course_userids) > 0) { - $graded = array_intersect($graded, $course_userids); + if (count($courseuserids) > 0) { + $graded = array_intersect($graded, $courseuserids); } return count($graded); diff --git a/classes/local/ungradedscanners/scanner_base.php b/classes/local/ungradedscanners/scanner_base.php index 7600667..69666b6 100644 --- a/classes/local/ungradedscanners/scanner_base.php +++ b/classes/local/ungradedscanners/scanner_base.php @@ -31,9 +31,9 @@ abstract class scanner_base { $this->gi = $gi; } - public abstract function count_ungraded($course_userids=[]); + public abstract function count_ungraded($courseuserids=[]); - public abstract function count_graded($course_userids=[]); + public abstract function count_graded($courseuserids=[]); public abstract function has_ungraded_submission($userid); diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 48a9610..fb26944 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -175,10 +175,10 @@ class provider implements \core_privacy\local\metadata\provider, // find studyplans in context. if ($context->contextlevel == CONTEXT_COURSECAT) { $sql = "SELECT s.id FROM {local_treestudyplan} WHERE ( a.user_id = :userid AND s.context_id = :contextid)"; - $plan_ids = $DB->get_fieldset_sql($sql, ["contextid"=>$context->id]); + $planids = $DB->get_fieldset_sql($sql, ["contextid"=>$context->id]); - foreach ($plan_ids as $plan_id) { - $DB->delete_records("local_treestudyplan_user", ["studyplan_id" => $plan_id]); + foreach ($planids as $planid) { + $DB->delete_records("local_treestudyplan_user", ["studyplan_id" => $planid]); } } } @@ -198,10 +198,10 @@ class provider implements \core_privacy\local\metadata\provider, if ($context->contextlevel == CONTEXT_SYSTEM) { $sql = "SELECT s.id FROM {local_treestudyplan} INNER JOIN {local_treestudyplan_user} a ON a.studyplan_id = s.id WHERE ( a.user_id = :userid AND ( s.context_id IS NULL OR s.context_id == 0 OR s.context_id = :contextid))"; - $plan_ids = $DB->get_fieldset_sql($sql, ["contextid"=>$context->id, "userid" => $user->id]); + $planids = $DB->get_fieldset_sql($sql, ["contextid"=>$context->id, "userid" => $user->id]); - foreach ($plan_ids as $plan_id) { - $DB->delete_records("local_treestudyplan_user", ["studyplan_id" => $plan_id, "user_id" => $user->id]); + foreach ($planids as $planid) { + $DB->delete_records("local_treestudyplan_user", ["studyplan_id" => $planid, "user_id" => $user->id]); } // Also delete all invitations for this user. @@ -210,10 +210,10 @@ class provider implements \core_privacy\local\metadata\provider, } else if ($context->contextlevel == CONTEXT_COURSECAT) { $sql = "SELECT s.id FROM {local_treestudyplan} INNER JOIN {local_treestudyplan_user} a ON a.studyplan_id = s.id WHERE ( a.user_id = :userid AND s.context_id = :contextid)"; - $plan_ids = $DB->get_fieldset_sql($sql, ["contextid"=>$context->id, "userid" => $user->id]); + $planids = $DB->get_fieldset_sql($sql, ["contextid"=>$context->id, "userid" => $user->id]); - foreach ($plan_ids as $plan_id) { - $DB->delete_records("local_treestudyplan_user", ["studyplan_id" => $plan_id, "user_id" => $user->id]); + foreach ($planids as $planid) { + $DB->delete_records("local_treestudyplan_user", ["studyplan_id" => $planid, "user_id" => $user->id]); } } } @@ -263,12 +263,12 @@ class provider implements \core_privacy\local\metadata\provider, $users = $userlist->get_userids(); list($userinsql, $userinparams) = $DB->get_in_or_equal($users, SQL_PARAMS_NAMED, 'user'); - $plan_ids = []; + $planids = []; if ($context->contextlevel == CONTEXT_SYSTEM) { // Determine the relevant plan_ids for this context. $sql = "SELECT s.id FROM {local_treestudyplan} WHERE ( s.context_id IS NULL OR s.context_id == 0 OR s.context_id = :contextid)) "; - $plan_ids = $DB->get_fieldset_sql($sql, ["contextid"=>$context->id, ]); + $planids = $DB->get_fieldset_sql($sql, ["contextid"=>$context->id, ]); // If plan ids not empty, they will be processed later. // Also delete all invitations for these users. @@ -278,14 +278,14 @@ class provider implements \core_privacy\local\metadata\provider, } else if ($context->contextlevel == CONTEXT_COURSECAT) { $sql = "SELECT s.id FROM {local_treestudyplan} WHERE (s.context_id = :contextid)"; - $plan_ids = $DB->get_fieldset_sql($sql, ["contextid"=>$context->id, ]); + $planids = $DB->get_fieldset_sql($sql, ["contextid"=>$context->id, ]); // If plan ids not empty, they will be processed later. } // Now delete the studyplan associations if relevant. - if (count($plan_ids) >0 && count($users) >0) { + if (count($planids) >0 && count($users) >0) { - list($planinsql, $planinputparams) = $DB->get_in_or_equal($plan_ids, SQL_PARAMS_NAMED, 'plan'); + list($planinsql, $planinputparams) = $DB->get_in_or_equal($planids, SQL_PARAMS_NAMED, 'plan'); $params = $userinparams+$planinputparams; $sql = "user_id {$userinsql} and studyplan_id {$planinsql}"; $DB->delete_records_select('local_treestudyplan_user', $sql, $params); diff --git a/classes/studyitem.php b/classes/studyitem.php index 788845d..2496a34 100644 --- a/classes/studyitem.php +++ b/classes/studyitem.php @@ -36,7 +36,7 @@ class studyitem { public const TABLE = "local_treestudyplan_item"; - private static $STUDYITEM_CACHE = []; + private static $STUDYITEMCACHE = []; private $r; // Holds database record. private $id; @@ -57,10 +57,10 @@ class studyitem { } public static function findById($id): self { - if (!array_key_exists($id, self::$STUDYITEM_CACHE)) { - self::$STUDYITEM_CACHE[$id] = new self($id); + if (!array_key_exists($id, self::$STUDYITEMCACHE)) { + self::$STUDYITEMCACHE[$id] = new self($id); } - return self::$STUDYITEM_CACHE[$id]; + return self::$STUDYITEMCACHE[$id]; } @@ -187,18 +187,18 @@ class studyitem { // Add incoming and outgoing connection info. - $conn_out = studyitemconnection::find_outgoing($this->id); + $connout = studyitemconnection::find_outgoing($this->id); if ($mode == "export") { - foreach ($conn_out as $c) { + foreach ($connout as $c) { $model["connections"][] = $c->to_id(); } } else { - foreach ($conn_out as $c) { + foreach ($connout as $c) { $model['connections']['out'][$c->to_id()] = $c->model(); } - $conn_in = studyitemconnection::find_incoming($this->id); - foreach ($conn_in as $c) { + $connin = studyitemconnection::find_incoming($this->id); + foreach ($connin as $c) { $model['connections']['in'][$c->from_id()] = $c->model(); } } @@ -268,8 +268,7 @@ class studyitem { if ($DB->count_records(self::TABLE, ['continuation_id' => $this->id]) > 0) { return success::fail('Cannot remove: item is referenced by another item'); - } else - { + } else { // delete al related connections to this item. studyitemconnection::clear($this->id); // delete all grade inclusion references to this item. @@ -381,8 +380,8 @@ class studyitem { // Add continuation_info if available. if (self::exists($this->r->continuation_id)) { - $c_item = self::findById($this->r->continuation_id); - $model['continuation'] = $c_item->link_model($userid); + $citem = self::findById($this->r->continuation_id); + $model['continuation'] = $citem->link_model($userid); } // Add course if available. @@ -392,12 +391,12 @@ class studyitem { } // Add incoming and outgoing connection info. - $conn_out = studyitemconnection::find_outgoing($this->id); - foreach ($conn_out as $c) { + $connout = studyitemconnection::find_outgoing($this->id); + foreach ($connout as $c) { $model['connections']['out'][$c->to_id()] = $c->model(); } - $conn_in = studyitemconnection::find_incoming($this->id); - foreach ($conn_in as $c) { + $connin = studyitemconnection::find_incoming($this->id); + foreach ($connin as $c) { $model['connections']['in'][$c->from_id()] = $c->model(); } @@ -424,21 +423,21 @@ class studyitem { // Does not need to use aggregator. // Either true, or the completion of the reference. if (self::exists($this->r->continuation_id)) { - $c_item = self::findById($this->r->continuation_id); - return $c_item->completion($userid); + $citem = self::findById($this->r->continuation_id); + return $citem->completion($userid); } else { return completion::COMPLETED; } } else if (in_array(strtolower($this->r->type), ['junction', 'finish'])) { // completion of the linked items, according to the rule. - $in_completed = []; + $incompleted = []; // Retrieve incoming connections. $incoming = $DB->get_records(studyitemconnection::TABLE, ['to_id' => $this->r->id]); foreach ($incoming as $conn) { $item = self::findById($conn->from_id); - $in_completed[] = $item->completion($userid); + $incompleted[] = $item->completion($userid); } - return $this->aggregator->aggregate_junction($in_completed, $this, $userid); + return $this->aggregator->aggregate_junction($incompleted, $this, $userid); } else if (strtolower($this->r->type) =='badge') { global $DB; // badge awarded. @@ -447,10 +446,10 @@ class studyitem { if ($badge->is_issued($userid)) { if ($badge->can_expire()) { // get the issued badges and check if any of them have not expired yet. - $badges_issued = $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; $now = time(); - foreach ($badges_issued as $bi) { + foreach ($badgesissued as $bi) { if ($bi->dateexpire == null || $bi->dateexpire > $now) { $notexpired = true; break; @@ -476,16 +475,16 @@ class studyitem { } } - public function duplicate($new_line) { + public function duplicate($newline) { global $DB; // clone the database fields. $fields = clone $this->r; // set new line id. unset($fields->id); - $fields->line_id = $new_line->id(); + $fields->line_id = $newline->id(); //create new record with the new data. $id = $DB->insert_record(self::TABLE, (array)$fields); - $new = self::findById($id, $new_line); + $new = self::findById($id, $newline); // copy the grading info if relevant. $gradables = gradeinfo::list_studyitem_gradables($this); diff --git a/classes/studyitemconnection.php b/classes/studyitemconnection.php index 5e7e23d..7dc678e 100644 --- a/classes/studyitemconnection.php +++ b/classes/studyitemconnection.php @@ -65,51 +65,51 @@ class studyitemconnection { } - public static function find_outgoing($item_id) { + public static function find_outgoing($itemid) { global $DB; $list = []; - $conn_out = $DB->get_records(self::TABLE, ['from_id' => $item_id]); - foreach ($conn_out as $c) { + $connout = $DB->get_records(self::TABLE, ['from_id' => $itemid]); + foreach ($connout as $c) { $list[] = new self($c); } return $list; } - public static function find_incoming($item_id) { + public static function find_incoming($itemid) { global $DB; $list = []; - $conn_in = $DB->get_records(self::TABLE, ['to_id' => $item_id]); - foreach ($conn_in as $c) { + $connin = $DB->get_records(self::TABLE, ['to_id' => $itemid]); + foreach ($connin as $c) { $list[] = new self($c); } return $list; } - public static function connect($from_id, $to_id) { + public static function connect($fromid, $toid) { global $DB; //check if link already exists. - if (!$DB->record_exists(self::TABLE, ['from_id' => $from_id, 'to_id' => $to_id])) { + if (!$DB->record_exists(self::TABLE, ['from_id' => $fromid, 'to_id' => $toid])) { $id = $DB->insert_record(self::TABLE, [ - 'from_id' => $from_id, - 'to_id' => $to_id, + 'from_id' => $fromid, + 'to_id' => $toid, ]); return new self($DB->get_record(self::TABLE, ['id' => $id])); } else { - return new self($DB->get_record(self::TABLE, ['from_id' => $from_id, 'to_id' => $to_id])); + return new self($DB->get_record(self::TABLE, ['from_id' => $fromid, 'to_id' => $toid])); } } - public static function disconnect($from_id, $to_id) { + public static function disconnect($fromid, $toid) { global $DB; - if ($DB->record_exists(self::TABLE, ['from_id' => $from_id, 'to_id' => $to_id])) { + if ($DB->record_exists(self::TABLE, ['from_id' => $fromid, 'to_id' => $toid])) { $DB->delete_records(self::TABLE, [ - 'from_id' => $from_id, - 'to_id' => $to_id, + 'from_id' => $fromid, + 'to_id' => $toid, ]); return success::success('Items Disconnected'); diff --git a/classes/studyline.php b/classes/studyline.php index cf04b33..d227706 100644 --- a/classes/studyline.php +++ b/classes/studyline.php @@ -43,7 +43,7 @@ class studyline { public const TABLE = "local_treestudyplan_line"; - private static $STUDYLINE_CACHE = []; + private static $STUDYLINECACHE = []; private $r; // Holds database record. private $id; @@ -63,10 +63,10 @@ class studyline { } public static function findById($id): self { - if (!array_key_exists($id, self::$STUDYLINE_CACHE)) { - self::$STUDYLINE_CACHE[$id] = new self($id); + if (!array_key_exists($id, self::$STUDYLINECACHE)) { + self::$STUDYLINECACHE[$id] = new self($id); } - return self::$STUDYLINE_CACHE[$id]; + return self::$STUDYLINECACHE[$id]; } private function __construct($id) { @@ -132,11 +132,11 @@ class studyline { // 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. // Alternatively, we could ensure that on reduction of slots, the items that no longer have a slot will be removed. - $max_slot = $DB->get_field_select(studyitem::TABLE, "MAX(slot)", "line_id = :lineid", ['lineid' => $this->id]); - $num_slots = max($this->page->periods(), $max_slot +1); + $maxslot = $DB->get_field_select(studyitem::TABLE, "MAX(slot)", "line_id = :lineid", ['lineid' => $this->id]); + $numslots = max($this->page->periods(), $maxslot +1); // Create the required amount of slots. - for($i=0; $i < $num_slots+1; $i++) { + for($i=0; $i < $numslots+1; $i++) { if ($mode == "export") { // Export mode does not separate between filter or competency type, since that is determined automatically. $slots = []; @@ -180,8 +180,8 @@ class studyline { throw new \InvalidArgumentException("parameter 'page_id' missing"); } - $page_id = $fields['page_id']; - $sqmax = $DB->get_field_select(self::TABLE, "MAX(sequence)", "page_id = :page_id", ['page_id' => $page_id]); + $pageid = $fields['page_id']; + $sqmax = $DB->get_field_select(self::TABLE, "MAX(sequence)", "page_id = :page_id", ['page_id' => $pageid]); $addable = ['page_id', 'name', 'shortname', 'color']; $info = ['sequence' => $sqmax+1]; foreach ($addable as $f) { @@ -220,8 +220,7 @@ class studyline { // check if this item has study items in it. if ($DB->count_records(studyitem::TABLE, ['line_id' => $this->id]) > 0) { return success::fail('cannot delete studyline with items'); - } else - { + } else { $DB->delete_records(self::TABLE, ['id' => $this->id]); return success::success(); } @@ -285,11 +284,11 @@ class studyline { // 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. // Alternatively, we could ensure that on reduction of slots, the items that no longer have a slot will be removed. - $max_slot = $DB->get_field_select(studyitem::TABLE, "MAX(slot)", "line_id = :lineid", ['lineid' => $this->id]); - $num_slots = max($this->page->periods(), $max_slot +1); + $maxslot = $DB->get_field_select(studyitem::TABLE, "MAX(slot)", "line_id = :lineid", ['lineid' => $this->id]); + $numslots = max($this->page->periods(), $maxslot +1); // Create the required amount of slots. - for($i=0; $i < $num_slots+1; $i++) { + for($i=0; $i < $numslots+1; $i++) { if ($i > 0) { $slots = [self::SLOTSET_COMPETENCY => [], self::SLOTSET_FILTER => []]; } else { @@ -322,14 +321,14 @@ class studyline { } - public function duplicate($new_studyplan, &$translation) { + public function duplicate($newstudyplan, &$translation) { global $DB; // clone the database fields. $fields = clone $this->r; // set new studyplan id. unset($fields->id); - $fields->studyplan_id = $new_studyplan->id(); + $fields->studyplan_id = $newstudyplan->id(); // create new record with the new data. $id = $DB->insert_record(self::TABLE, (array)$fields); $new = self::findById($id); @@ -375,8 +374,8 @@ class studyline { if (! isset($connections[$item->id()]) || ! is_array($connections[$item->id()])) { $connections[$item->id()] = []; } - foreach ($itemmodel["connections"] as $to_id) { - $connections[$item->id()][] = $to_id; + foreach ($itemmodel["connections"] as $toid) { + $connections[$item->id()][] = $toid; } } } diff --git a/classes/studyplan.php b/classes/studyplan.php index 7e22a7e..15f5d03 100644 --- a/classes/studyplan.php +++ b/classes/studyplan.php @@ -28,15 +28,15 @@ class studyplan { const TABLE = "local_treestudyplan"; - private static $STUDYPLAN_CACHE = []; + private static $STUDYPLANCACHE = []; private $r; // Holds database record. private $id; private $aggregator; private $context = null; // Hold context object once retrieved. - private $linked_userids = null; // cache lookup of linked users (saves queries). - private $page_cache = null; + private $linkeduserids = null; // cache lookup of linked users (saves queries). + private $pagecache = null; public function aggregator() { return $this->aggregator; @@ -44,10 +44,10 @@ class studyplan { // Cache constructors to avoid multiple creation events in one session. public static function findById($id): self { - if (!array_key_exists($id, self::$STUDYPLAN_CACHE)) { - self::$STUDYPLAN_CACHE[$id] = new self($id); + if (!array_key_exists($id, self::$STUDYPLANCACHE)) { + self::$STUDYPLANCACHE[$id] = new self($id); } - return self::$STUDYPLAN_CACHE[$id]; + return self::$STUDYPLANCACHE[$id]; } private function __construct($id) { @@ -290,8 +290,7 @@ class studyplan { if ($DB->count_records('local_treestudyplan_page', ['studyplan_id' => $this->id]) > 0) { return success::fail('cannot delete studyplan that still has pages'); - } else - { + } else { $DB->delete_records('local_treestudyplan', ['id' => $this->id]); return success::success(); } @@ -341,18 +340,18 @@ class studyplan { INNER JOIN {local_treestudyplan_cohort} j ON j.studyplan_id = s.id INNER JOIN {cohort_members} cm ON j.cohort_id = cm.cohortid WHERE cm.userid = :userid"; - $cohort_plan_ids = $DB->get_fieldset_sql($sql, ['userid' => $userid]); + $cohortplan_ids = $DB->get_fieldset_sql($sql, ['userid' => $userid]); $sql = "SELECT s.id FROM {local_treestudyplan} s INNER JOIN {local_treestudyplan_user} j ON j.studyplan_id = s.id WHERE j.user_id = :userid"; - $user_plan_ids = $DB->get_fieldset_sql($sql, ['userid' => $userid]); + $userplan_ids = $DB->get_fieldset_sql($sql, ['userid' => $userid]); $plans = []; - foreach ($cohort_plan_ids as $id) { + foreach ($cohortplan_ids as $id) { $plans[$id] = self::findById($id); } - foreach ($user_plan_ids as $id) { + foreach ($userplan_ids as $id) { if (!array_key_exists($id, $plans)) { $plans[$id] = self::findById($id); } @@ -477,8 +476,8 @@ class studyplan { return $model; } - public static function duplicate_plan($plan_id, $name, $shortname) { - $ori = self::findById($plan_id); + public static function duplicate_plan($planid, $name, $shortname) { + $ori = self::findById($planid); $new = $ori->duplicate($name, $shortname); return $new->simple_model(); } @@ -538,7 +537,7 @@ class studyplan { return $pages; } - public static function import_studyplan($content, $format="application/json", $context_id=1) { + public static function import_studyplan($content, $format="application/json", $contextid=1) { if ($format != "application/json") { return false;} $content = json_decode($content, true); @@ -548,7 +547,7 @@ class studyplan { $content["studyplan"]["aggregation_config"] = json_encode($content["studyplan"]["aggregation_config"]); // And make sure the context_id is set to the provided context for import. - $content["studyplan"]["context_id"] = $context_id; + $content["studyplan"]["context_id"] = $contextid; // Create a new plan, based on the given parameters - this is the import studyplan part. $plan = self::add($content["studyplan"], true); diff --git a/classes/studyplanpage.php b/classes/studyplanpage.php index 4b3b5c7..9090879 100644 --- a/classes/studyplanpage.php +++ b/classes/studyplanpage.php @@ -206,8 +206,7 @@ class studyplanpage { if ($DB->count_records('local_treestudyplan_line', ['page_id' => $this->id]) > 0) { return success::fail('cannot delete studyplan page that still has studylines'); - } else - { + } else { $DB->delete_records(self::TABLE, ['id' => $this->id]); return success::success(); } @@ -259,16 +258,16 @@ class studyplanpage { return $list; } - public static function duplicate_page($page_id, $name, $shortname) { - $ori = self::findById($page_id); + public static function duplicate_page($pageid, $name, $shortname) { + $ori = self::findById($pageid); $new = $ori->duplicate($name, $shortname); return $new->simple_model(); } - public function duplicate($new_studyplan) { + public function duplicate($newstudyplan) { // First duplicate the studyplan structure. $new = studyplanpage::add([ - 'studyplan_id' => $new_studyplan->id(), + 'studyplan_id' => $newstudyplan->id(), 'fullname' => $this->r->fullname, 'shortname' => $this->r->shortname, 'description' => $this->r->description, @@ -290,9 +289,9 @@ class studyplanpage { // 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). // use this to recreate the lines in the new plan. - foreach (array_keys($itemtranslation) as $item_id) { + foreach (array_keys($itemtranslation) as $itemid) { // copy based on the outgoing connections of each item, to avoid duplicates. - $connections = studyitemconnection::find_outgoing($item_id); + $connections = studyitemconnection::find_outgoing($itemid); foreach ($connections as $conn) { studyitemconnection::connect($itemtranslation[$conn->from_id], $itemtranslation[$conn->to_id]); } @@ -484,7 +483,7 @@ class studyplanpage { public function import_studylines_model($model) { // First attempt to map each studyline model to an existing or new line. - $line_map = []; + $linemap = []; foreach ($model as $ix => $linemodel) { $line = $this->find_studyline_by_shortname($linemodel["shortname"]); if (empty($line)) { @@ -493,14 +492,14 @@ class studyplanpage { } else { //$line->edit($linemodel); // Update the line with the settings from the imported file. } - $line_map[$ix] = $line; + $linemap[$ix] = $line; } // next, let each study line import the study items. $itemtranslation = []; $connections = []; foreach ($model as $ix => $linemodel) { - $line_map[$ix]->import_studyitems($linemodel["slots"], $itemtranslation, $connections); + $linemap[$ix]->import_studyitems($linemodel["slots"], $itemtranslation, $connections); } // Finally, create the links between the study items. diff --git a/classes/studyplanservice.php b/classes/studyplanservice.php index 583a636..257cfa8 100644 --- a/classes/studyplanservice.php +++ b/classes/studyplanservice.php @@ -53,16 +53,16 @@ class studyplanservice extends \external_api return new \external_multiple_structure( studyplan::simple_structure() ); } - public static function list_studyplans($context_id = 0) { + public static function list_studyplans($contextid = 0) { global $CFG, $DB; // Check if the user has the correct permissions for this context. - $context = webservicehelper::find_context($context_id); + $context = webservicehelper::find_context($contextid); webservicehelper::require_capabilities([self::CAP_EDIT, self::CAP_VIEW], $context); // Now list all the studyplans in the relevant context. $list = []; - $studyplans = studyplan::find_all($context_id); + $studyplans = studyplan::find_all($contextid); foreach ($studyplans as $studyplan) { $list[] = $studyplan->simple_model(); } @@ -144,9 +144,9 @@ class studyplanservice extends \external_api return studyplan::simple_structure(); } - public static function add_studyplan($name, $shortname, $idnumber, $description, $periods, $startdate, $enddate, $aggregation="bistate", $aggregation_config='', $context_id=0) { + public static function add_studyplan($name, $shortname, $idnumber, $description, $periods, $startdate, $enddate, $aggregation="bistate", $aggregationconfig='', $contextid=0) { // Check if we have the proper rights for the requested context. - $context = webservicehelper::find_context($context_id); + $context = webservicehelper::find_context($contextid); webservicehelper::require_capabilities(self::CAP_EDIT, $context); $o = studyplan::add([ @@ -158,8 +158,8 @@ class studyplanservice extends \external_api 'startdate' => $startdate, 'enddate' => empty($enddate)?null:$enddate, 'aggregation' => $aggregation, - 'aggregation_config' => $aggregation_config, - 'context_id' => $context_id, + 'aggregation_config' => $aggregationconfig, + 'context_id' => $contextid, ]); return $o->simple_model(); } @@ -190,9 +190,9 @@ class studyplanservice extends \external_api return studyplan::simple_structure(); } - public static function edit_studyplan($id, $name, $shortname, $idnumber, $description, $periods, $startdate, $enddate, $aggregation="bistate", $aggregation_config='', $context_id=0) { + public static function edit_studyplan($id, $name, $shortname, $idnumber, $description, $periods, $startdate, $enddate, $aggregation="bistate", $aggregationconfig='', $contextid=0) { // Validate access in the intended context. - $context = webservicehelper::find_context($context_id); + $context = webservicehelper::find_context($contextid); webservicehelper::require_capabilities(self::CAP_EDIT, $context, false); // do not validate the context in this case, just check the permissions. $o = studyplan::findById($id); @@ -207,8 +207,8 @@ class studyplanservice extends \external_api 'startdate' => $startdate, 'enddate' => $enddate, 'aggregation' => $aggregation, - 'aggregation_config' => $aggregation_config, - 'context_id' => $context_id, + 'aggregation_config' => $aggregationconfig, + 'context_id' => $contextid, ]); return $o->simple_model(); } @@ -257,13 +257,13 @@ class studyplanservice extends \external_api return studyline::editor_structure(); } - public static function add_studyline($page_id, $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. - $page = studyplanpage::findById($page_id); + $page = studyplanpage::findById($pageid); webservicehelper::require_capabilities(self::CAP_EDIT, $page->studyplan()->context()); $o = studyline::add([ - 'page_id' => $page_id, + 'page_id' => $pageid, 'name' => $name, 'shortname' => $shortname, 'color' => $color, @@ -415,11 +415,11 @@ class studyplanservice extends \external_api return studyitem::editor_structure(); } - public static function add_studyitem($line_id, $type, $details, $slot=-1, $layer=0) { - webservicehelper::require_capabilities(self::CAP_EDIT, studyline::findById($line_id)->context()); + public static function add_studyitem($lineid, $type, $details, $slot=-1, $layer=0) { + webservicehelper::require_capabilities(self::CAP_EDIT, studyline::findById($lineid)->context()); $o = studyitem::add([ - 'line_id' => $line_id, + 'line_id' => $lineid, 'type' => $type, //'conditions' => $conditions,. 'slot' => $slot, @@ -450,7 +450,7 @@ class studyplanservice extends \external_api return studyitem::editor_structure(); } - public static function edit_studyitem($id, $conditions, $continuation_id=false) { + public static function edit_studyitem($id, $conditions, $continuationid=false) { $o = studyitem::findById($id); webservicehelper::require_capabilities(self::CAP_EDIT, $o->context()); @@ -458,8 +458,8 @@ class studyplanservice extends \external_api $config = [ 'conditions' => $conditions, ]; - if ($continuation_id !== false) { - $config['continuation_id'] = $continuation_id; + if ($continuationid !== false) { + $config['continuation_id'] = $continuationid; } $o->edit($config); @@ -540,12 +540,12 @@ class studyplanservice extends \external_api return studyitemconnection::structure(); } - public static function connect_studyitems($from_id, $to_id) { + public static function connect_studyitems($fromid, $toid) { // Validate permissions. - webservicehelper::require_capabilities(self::CAP_EDIT, studyitem::findById($from_id)->context()); - webservicehelper::require_capabilities(self::CAP_EDIT, studyitem::findById($to_id)->context()); + webservicehelper::require_capabilities(self::CAP_EDIT, studyitem::findById($fromid)->context()); + webservicehelper::require_capabilities(self::CAP_EDIT, studyitem::findById($toid)->context()); - $o = studyitemconnection::connect($from_id, $to_id); + $o = studyitemconnection::connect($fromid, $toid); return $o->model(); } @@ -566,11 +566,11 @@ class studyplanservice extends \external_api return success::structure(); } - public static function disconnect_studyitems($from_id, $to_id) { + public static function disconnect_studyitems($fromid, $toid) { // Validate permissions. - webservicehelper::require_capabilities(self::CAP_EDIT, studyitem::findById($from_id)->context()); - webservicehelper::require_capabilities(self::CAP_EDIT, studyitem::findById($to_id)->context()); - return studyitemconnection::disconnect($from_id, $to_id)->model(); + webservicehelper::require_capabilities(self::CAP_EDIT, studyitem::findById($fromid)->context()); + webservicehelper::require_capabilities(self::CAP_EDIT, studyitem::findById($toid)->context()); + return studyitemconnection::disconnect($fromid, $toid)->model(); } /**************************** @@ -624,19 +624,19 @@ class studyplanservice extends \external_api return success::structure(); } - public static function include_grade($grade_id, $item_id, $include, $required=false) { + public static function include_grade($gradeid, $itemid, $include, $required=false) { global $USER; // find related course and course context. - $coursecontext = gradeinfo::getCourseContextById($grade_id); + $coursecontext = gradeinfo::getCourseContextById($gradeid); // do sanity checks. \external_api::validate_context($coursecontext); // check correct capabilities. - if (has_capability('local/treestudyplan:editstudyplan', studyitem::findById($item_id)->context()) || + if (has_capability('local/treestudyplan:editstudyplan', studyitem::findById($itemid)->context()) || is_enrolled($coursecontext, $USER, 'local/treestudyplan:selectowngradables')) { - return gradeinfo::include_grade($grade_id, $item_id, $include, $required)->model(); + return gradeinfo::include_grade($gradeid, $itemid, $include, $required)->model(); } else { return success::fail("Access denied")->model(); } @@ -686,16 +686,16 @@ class studyplanservice extends \external_api ])); } - public static function force_studyplan_scale($studyplan_id, $scale_id) { + public static function force_studyplan_scale($studyplanid, $scaleid) { global $DB; $dbman = $DB->get_manager(); // Validate permissions. - webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::findById($studyplan_id)->context()); + webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::findById($studyplanid)->context()); $list = []; // check if scaleid is valid. - $scale = \grade_scale::fetch(['id' => $scale_id]); + $scale = \grade_scale::fetch(['id' => $scaleid]); $scale->load_items(); if ($scale) { @@ -704,13 +704,13 @@ class studyplanservice extends \external_api $scalemax = count($scale->scale_items); // find studyline id's. - $studyline_ids = $DB->get_fieldset_select(studyline::TABLE, "id", "studyplan_id = :plan_id", ['plan_id' => $studyplan_id]); - foreach ($studyline_ids as $studyline_id) { + $studylineids = $DB->get_fieldset_select(studyline::TABLE, "id", "studyplan_id = :plan_id", ['plan_id' => $studyplanid]); + foreach ($studylineids as $studylineid) { // find id's of studyitems of type course. - $records = $DB->get_records(studyitem::TABLE, ['line_id' => $studyline_id]); + $records = $DB->get_records(studyitem::TABLE, ['line_id' => $studylineid]); - foreach ($records as $item_r) { - $studyitem = new studyitem($item_r->id); + foreach ($records as $itemr) { + $studyitem = new studyitem($itemr->id); if ($studyitem->isValid() && $studyitem->type() == studyitem::COURSE) { $courseinfo = $studyitem->getcourseinfo(); $gradables = gradeinfo::list_studyitem_gradables($studyitem); @@ -742,9 +742,9 @@ class studyplanservice extends \external_api $fieldname = "grade"; if ($result && $gi->itemtype == "mod" && $dbman->table_exists($tablename)) { if ($dbman->field_exists($tablename, $fieldname)) { - $grade_value = intval(0-($scale->id)); + $gradevalue = intval(0-($scale->id)); try { - $DB->set_field($tablename, $fieldname, $grade_value, ["id" => $gi->iteminstance]); + $DB->set_field($tablename, $fieldname, $gradevalue, ["id" => $gi->iteminstance]); } catch(\dml_exception $x) { $updated = "fail"; @@ -826,20 +826,20 @@ class studyplanservice extends \external_api return success::structure(); } - public static function disable_autoenddate($studyplan_id) { + public static function disable_autoenddate($studyplanid) { global $DB; // Validate permissions. - webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::findById($studyplan_id)->context()); + webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::findById($studyplanid)->context()); // find studyline id's. - $studyline_ids = $DB->get_fieldset_select(studyline::TABLE, "id", "studyplan_id = :plan_id", ['plan_id' => $studyplan_id]); - foreach ($studyline_ids as $studyline_id) { + $studylineids = $DB->get_fieldset_select(studyline::TABLE, "id", "studyplan_id = :plan_id", ['plan_id' => $studyplanid]); + foreach ($studylineids as $studylineid) { // find id's of studyitems of type course. - $records = $DB->get_records(studyitem::TABLE, ['line_id' => $studyline_id]); + $records = $DB->get_records(studyitem::TABLE, ['line_id' => $studylineid]); - foreach ($records as $item_r) { - $studyitem = new studyitem($item_r->id); + foreach ($records as $itemr) { + $studyitem = new studyitem($itemr->id); if ($studyitem->isValid() && $studyitem->type() == studyitem::COURSE) { $record = $DB->get_record("course_format_options", ["courseid" => $studyitem->courseid(), "name" => "automaticenddate"]); if ($record && $record->value) { @@ -870,11 +870,11 @@ class studyplanservice extends \external_api return studyplan::simple_structure(); } - public static function duplicate_plan($studyplan_id, $name, $shortname) { + public static function duplicate_plan($studyplanid, $name, $shortname) { // Validate permissions. - webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::findById($studyplan_id)->context()); + webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::findById($studyplanid)->context()); - return studyplan::duplicate_plan($studyplan_id, $name, $shortname); + return studyplan::duplicate_plan($studyplanid, $name, $shortname); } /**************************** @@ -894,12 +894,12 @@ class studyplanservice extends \external_api return studyplan::export_structure(); } - public static function export_plan($studyplan_id, $format="json") { + public static function export_plan($studyplanid, $format="json") { try { // Validate permissions. - webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::findById($studyplan_id)->context()); + webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::findById($studyplanid)->context()); - $plan = studyplan::findById($studyplan_id); + $plan = studyplan::findById($studyplanid); if ($format == "csv") { // FIXME: Make sure this webservice function gets called for the page instead of the studyplan. return $plan->pages()[0]->export_page_csv(); @@ -922,12 +922,12 @@ class studyplanservice extends \external_api return studyplan::export_structure(); } - public static function export_studylines($studyplan_id) { + public static function export_studylines($studyplanid) { $systemcontext = webservicehelper::system_context(); try { - webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::findById($studyplan_id)->context()); - $plan = studyplan::findById($studyplan_id); + webservicehelper::require_capabilities(self::CAP_EDIT, studyplan::findById($studyplanid)->context()); + $plan = studyplan::findById($studyplanid); // FIXME: Make sure this gets called for the page instead of the studyplan. return $plan->pages()[0]->export_studylines(); } @@ -953,14 +953,14 @@ class studyplanservice extends \external_api return success::structure(); } - public static function import_plan($content, $format="application/json", $context_id=1) { + public static function import_plan($content, $format="application/json", $contextid=1) { try { // Validate import context. - $context = webservicehelper::find_context($context_id); + $context = webservicehelper::find_context($contextid); webservicehelper::require_capabilities(self::CAP_EDIT, $context); - $result = studyplan::import_studyplan($content, $format, $context_id); + $result = studyplan::import_studyplan($content, $format, $contextid); return (new success($result, "During study plan import"))->model(); } catch(\webservice_access_exception $x) { @@ -980,10 +980,10 @@ class studyplanservice extends \external_api return success::structure(); } - public static function import_studylines($studyplan_id, $content, $format="application/json") { + public static function import_studylines($studyplanid, $content, $format="application/json") { try { - $plan = studyplan::findById($studyplan_id); + $plan = studyplan::findById($studyplanid); // Validate import context. webservicehelper::require_capabilities(self::CAP_EDIT, $plan->context()); @@ -1130,15 +1130,15 @@ class studyplanservice extends \external_api return courseinfo::editor_structure(); } - public static function course_period_timing($period_id, $course_id, $span=1) { + public static function course_period_timing($periodid, $courseid, $span=1) { global $DB; - $period = period::findById($period_id); + $period = period::findById($periodid); $periodnr = $period->period(); $page = $period->page(); // Check for studyplan edit permissions. webservicehelper::require_capabilities(self::CAP_EDIT, $page->studyplan()->context()); - $course = \get_course($course_id); - $coursecontext = \context_course::instance($course_id); + $course = \get_course($courseid); + $coursecontext = \context_course::instance($courseid); if (webservicehelper::has_capabilities("moodle/course:update", $coursecontext)) { diff --git a/classes/task/refreshteacherlist.php b/classes/task/refreshteacherlist.php index 6db0ad1..b67e1c9 100644 --- a/classes/task/refreshteacherlist.php +++ b/classes/task/refreshteacherlist.php @@ -41,8 +41,8 @@ class refreshteacherlist extends \core\task\scheduled_task { */ public function execute() { \mtrace("Ververs lijst met leraren"); - $teacher_ids = teachingfinder::list_teacher_ids(); - foreach ($teacher_ids as $tid) { + $teacherids = teachingfinder::list_teacher_ids(); + foreach ($teacherids as $tid) { $utime = teachingfinder::get_update_time($tid); if (time() - $utime > self::CACHE_TIME) { \mtrace("Teacher {$tid} is due for a refresh of the list"); diff --git a/classes/teachingfinder.php b/classes/teachingfinder.php index 0dc4565..318056e 100644 --- a/classes/teachingfinder.php +++ b/classes/teachingfinder.php @@ -57,19 +57,19 @@ class teachingfinder { $sql = "SELECT p.id FROM {local_treestudyplan_page} p WHERE startdate <= NOW() and enddate >= NOW()"; - $page_ids = $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 . // (Which would make them a teacher for all intents and purposes). - foreach ($page_ids as $page_id) { + foreach ($pageids as $pageid) { $sql = "SELECT i.course_id FROM {local_treestudyplan_item} i INNER JOIN {local_treestudyplan_line} l ON i.line_id = l.id WHERE l.page_id = :page_id AND i.course_id IS NOT NULL"; - $course_ids = $DB->get_fieldset_sql($sql, ["page_id" => $page_id]); + $courseids = $DB->get_fieldset_sql($sql, ["page_id" => $pageid]); $linked = false; - foreach ($course_ids as $cid) { + foreach ($courseids as $cid) { $coursecontext = \context_course::instance($cid); if (is_enrolled($coursecontext, $userid, 'mod/assign:grade')) { $linked = true; @@ -78,7 +78,7 @@ class teachingfinder { } if ($linked) { - $list[] = $page_id; + $list[] = $pageid; } } @@ -87,10 +87,10 @@ class teachingfinder { $DB->delete_records(self::TABLE, ["teacher_id"=>$userid]); // And add new records for the found studyplans. $now = time(); - foreach ($list as $page_id) { + foreach ($list as $pageid) { // Retrieve the studyplan id from the page. //TODO: Change this when page management is implemented to return the page instead of the plan. - $planid = $DB->get_field("local_treestudyplan_page", "studyplan_id", ["id" => $page_id]); + $planid = $DB->get_field("local_treestudyplan_page", "studyplan_id", ["id" => $pageid]); $DB->insert_record(self::TABLE, ["teacher_id"=>$userid, "studyplan_id"=>$planid, "update_time"=>$now]); } @@ -102,10 +102,10 @@ class teachingfinder { return $DB->get_fieldset_sql("SELECT DISTINCT teacher_id FROM {".self::TABLE."}"); } - public static function get_update_time($teacher_id): int { + public static function get_update_time($teacherid): int { global $DB; $r = $DB->get_field_sql("SELECT MIN(update_time)FROM {".self::TABLE."} WHERE teacher_id=:teacher_id", - ["teacher_id" => $teacher_id]); + ["teacher_id" => $teacherid]); return (int)($r->update_time); } diff --git a/cli/randomize_grades.php b/cli/randomize_grades.php index 4083b01..58e3d75 100644 --- a/cli/randomize_grades.php +++ b/cli/randomize_grades.php @@ -143,8 +143,8 @@ foreach ($plans as $plan) { if ($gi->itemmodule == "assign") { // If it is an assignment, submit though that interface . list($c, $cminfo) = get_course_and_cm_from_instance($gi->iteminstance, $gi->itemmodule); - $cm_ctx = \context_module::instance($cminfo->id); - $a = new \assign($cm_ctx, $cminfo, $c); + $cmctx = \context_module::instance($cminfo->id); + $a = new \assign($cmctx, $cminfo, $c); $ug = $a->get_user_grade($u->id, true); $ug->grade = grade_floatval($gg->grade); @@ -174,8 +174,7 @@ foreach ($plans as $plan) { } } } - } else - { + } else { cli_writeln(" Skipping since it has not started yet"); } } diff --git a/doc.php b/doc.php index 379821b..55b944f 100644 --- a/doc.php +++ b/doc.php @@ -41,9 +41,9 @@ if (!file_exists($file)) { } $mime = mime_content_type($file); -$text_types = ["text/html", "text/plain"]; +$texttypes = ["text/html", "text/plain"]; -if ( in_array($mime, $text_types)) { +if ( in_array($mime, $texttypes)) { print $OUTPUT->header(); print file_get_contents($file); print $OUTPUT->footer(); diff --git a/edit-invite.php b/edit-invite.php index fa5a9fa..d96a737 100644 --- a/edit-invite.php +++ b/edit-invite.php @@ -40,8 +40,7 @@ $PAGE->set_context($systemcontext); if ($update > 0) { $PAGE->set_title(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_heading(get_string('invite_desc_new', 'local_treestudyplan')); } @@ -144,8 +143,7 @@ if ($mform->is_cancelled()) { exit; -} else -{ +} else { $data = null; if ($unitid > 0) { diff --git a/edit-plan.php b/edit-plan.php index b8e660c..dc715ce 100644 --- a/edit-plan.php +++ b/edit-plan.php @@ -47,12 +47,11 @@ if ($categoryid > 0) { { $studyplancontext = $systemcontext; } -} else -{ +} else { // If no context is selected, find the first available one. - $available_contexts = courseservice::list_accessible_categories_with_usage("edit"); + $availablecontexts = courseservice::list_accessible_categories_with_usage("edit"); $contextid=1; // fallback to system context. - foreach ($available_contexts as $ctx) { + foreach ($availablecontexts as $ctx) { if ($ctx->count > 0) { $contextid = $ctx->ctxid; break; diff --git a/invitations.php b/invitations.php index e586378..524b362 100644 --- a/invitations.php +++ b/invitations.php @@ -25,8 +25,7 @@ if (isset($_SERVER['SCRIPT_FILENAME'])) { $root = dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME']))); error_log("Using {$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. require_once("../../config.php"); } @@ -36,7 +35,7 @@ require_once($CFG->dirroot.'/grade/querylib.php'); use local_treestudyplan; -$INVITED_URL = "/local/treestudyplan/invited.php"; +$INVITEDURL = "/local/treestudyplan/invited.php"; //admin_externalpage_setup('major');. $systemcontext = context_system::instance(); @@ -80,7 +79,7 @@ print ""; if (count($invites) > 0) { foreach ($invites as $invite) { - $testlink = $INVITED_URL."?key={$invite->invitekey}"; + $testlink = $INVITEDURL."?key={$invite->invitekey}"; print ""; print "{$invite->name}"; print "{$invite->email}"; @@ -104,8 +103,7 @@ if (count($invites) > 0) { print ""; } -} else -{ +} else { print "".get_string('invite_table_empty', 'local_treestudyplan').""; } print ""; diff --git a/invited.php b/invited.php index f7d8aa8..175ed02 100644 --- a/invited.php +++ b/invited.php @@ -54,8 +54,7 @@ if (empty($invite)) { print $OUTPUT->footer(); exit; -} else -{ +} else { // 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/devstyles.css')); diff --git a/lib.php b/lib.php index ce92146..177356e 100644 --- a/lib.php +++ b/lib.php @@ -50,7 +50,7 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) { // (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). // we will add all the hrefs that should be hidden to this variable below. - $hide_primary_hrefs = []; + $hideprimary_hrefs = []; if ($USER->id > 1) // Don't show if user is not logged in (id == 0) or is guest user (id == 1). { @@ -87,7 +87,7 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) { $navigation->add_node($node, 'mycourses'); } else { - $hide_primary_hrefs[] = "/local/treestudyplan/myreport.php"; + $hideprimary_hrefs[] = "/local/treestudyplan/myreport.php"; } if ( has_capability('local/treestudyplan:viewuserreports', context_system::instance()) || webservicehelper::has_capability_in_any_category('local/treestudyplan:viewuserreports')) @@ -105,7 +105,7 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) { $navigation->add_node($node, 'mycourses'); } else { - $hide_primary_hrefs[] = "/local/treestudyplan/view-plan.php"; + $hideprimary_hrefs[] = "/local/treestudyplan/view-plan.php"; } if ( has_capability('local/treestudyplan:editstudyplan', context_system::instance()) || webservicehelper::has_capability_in_any_category('local/treestudyplan:editstudyplan') @@ -124,13 +124,13 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) { $navigation->add_node($node, 'mycourses'); } else { - $hide_primary_hrefs[] = "/local/treestudyplan/edit-plan.php"; + $hideprimary_hrefs[] = "/local/treestudyplan/edit-plan.php"; } } else { - $hide_primary_hrefs[] = "/local/treestudyplan/myreport.php"; - $hide_primary_hrefs[] = "/local/treestudyplan/edit-plan.php"; - $hide_primary_hrefs[] = "/local/treestudyplan/view-plan.php"; + $hideprimary_hrefs[] = "/local/treestudyplan/myreport.php"; + $hideprimary_hrefs[] = "/local/treestudyplan/edit-plan.php"; + $hideprimary_hrefs[] = "/local/treestudyplan/view-plan.php"; } // create invitenode node. $invitenode = navigation_node::create( @@ -146,7 +146,7 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) { // Now using some javascript magic, we'll hide the links that are not accessible. - $PAGE->requires->js_call_amd('local_treestudyplan/primary-nav-tools', 'hide_primary', [$hide_primary_hrefs]); + $PAGE->requires->js_call_amd('local_treestudyplan/primary-nav-tools', 'hide_primary', [$hideprimary_hrefs]); @@ -292,8 +292,7 @@ function local_treestudyplan_get_cohort_path($cohort) { $ctxpath[] = $cohort->name; return implode(" / ", $ctxpath); - } else - { + } else { return $cohort->name; } } diff --git a/settings.php b/settings.php index 5a8c8cf..ed10428 100644 --- a/settings.php +++ b/settings.php @@ -146,46 +146,46 @@ if ($hassiteconfig) { * *************************************/ - $page_csync = new admin_settingpage('local_treestudyplan_settings_cohortsync', + $pagecsync = new admin_settingpage('local_treestudyplan_settings_cohortsync', get_string('settingspage_csync', 'local_treestudyplan', null, true)); // Description heading. - $page_csync->add(new admin_setting_heading('local_treestudyplan/csync_heading', + $pagecsync->add(new admin_setting_heading('local_treestudyplan/csync_heading', get_string('setting_csync_heading', 'local_treestudyplan'), get_string('settingdesc_csync_heading', 'local_treestudyplan') )); // Enable/disable cohort sync. - $page_csync->add(new admin_setting_configcheckbox('local_treestudyplan/csync_enable', + $pagecsync->add(new admin_setting_configcheckbox('local_treestudyplan/csync_enable', get_string('setting_csync_enable_field', 'local_treestudyplan'), get_string('settingdesc_csync_enable_field', 'local_treestudyplan'), false )); // Enable/disable autoremove. - $page_csync->add(new admin_setting_configcheckbox('local_treestudyplan/csync_autoremove', + $pagecsync->add(new admin_setting_configcheckbox('local_treestudyplan/csync_autoremove', get_string('setting_csync_autoremove_field', 'local_treestudyplan'), get_string('settingdesc_csync_autoremove_field', 'local_treestudyplan'), true )); // Enable/disable remembering previously added cohort syncs so they're not automatically deleted. - $page_csync->add(new admin_setting_configcheckbox('local_treestudyplan/csync_remember_manual_csync', + $pagecsync->add(new admin_setting_configcheckbox('local_treestudyplan/csync_remember_manual_csync', get_string('setting_csync_remember_manual_csync_field', 'local_treestudyplan'), get_string('settingdesc_csync_remember_manual_csync_field', 'local_treestudyplan'), true )); // Enable/disable group creation. - $page_csync->add(new admin_setting_configcheckbox('local_treestudyplan/csync_creategroup', + $pagecsync->add(new admin_setting_configcheckbox('local_treestudyplan/csync_creategroup', get_string('setting_csync_creategroup_field', 'local_treestudyplan'), get_string('settingdesc_csync_creategroup_field', 'local_treestudyplan'), true )); // Sync users too yes/no?. - $page_csync->add(new admin_setting_configcheckbox('local_treestudyplan/csync_users', + $pagecsync->add(new admin_setting_configcheckbox('local_treestudyplan/csync_users', get_string('setting_csync_users_field', 'local_treestudyplan'), get_string('settingdesc_csync_users_field', 'local_treestudyplan'), true @@ -196,14 +196,14 @@ if ($hassiteconfig) { $options = get_default_enrol_roles(context_system::instance()); $student = get_archetype_roles('student'); $student = reset($student); - $page_csync->add(new admin_setting_configselect('local_treestudyplan/csync_roleid', + $pagecsync->add(new admin_setting_configselect('local_treestudyplan/csync_roleid', get_string('setting_csync_role_field', 'local_treestudyplan'), get_string('settingdesc_csync_role_field', 'local_treestudyplan'), $student->id ?? null, $options)); } // Add settings page2 to the admin settings category. - $ADMIN->add('local_treestudyplan', $page_csync); + $ADMIN->add('local_treestudyplan', $pagecsync); /************************************** * diff --git a/view-plan.php b/view-plan.php index fc51461..baedb9b 100644 --- a/view-plan.php +++ b/view-plan.php @@ -47,12 +47,11 @@ if ($categoryid > 0) { { $studyplancontext = $systemcontext; } -} else -{ +} else { // If no context is selected, find the first available one. - $available_contexts = courseservice::list_accessible_categories_with_usage("view"); + $availablecontexts = courseservice::list_accessible_categories_with_usage("view"); $contextid=1; // fallback to system context. - foreach ($available_contexts as $ctx) { + foreach ($availablecontexts as $ctx) { if ($ctx->count > 0) { $contextid = $ctx->ctxid; break;