Moodle code style fixes part 10

This commit is contained in:
PMKuipers 2023-08-25 13:34:31 +02:00
parent 00b38f0a49
commit f8fd27528a
12 changed files with 533 additions and 536 deletions

View File

@ -59,7 +59,7 @@ abstract class aggregator {
} }
} }
public static function createOrDefault($mod, $configstr) { public static function createordefault($mod, $configstr) {
try { try {
return self::create($mod, $configstr); return self::create($mod, $configstr);
} catch (\ValueError $x) { } catch (\ValueError $x) {
@ -74,17 +74,17 @@ abstract class aggregator {
protected function initialize($configstr) { protected function initialize($configstr) {
} }
abstract public function needSelectGradables(); abstract public function select_gradables();
abstract public function isDeprecated(); abstract public function deprecated();
abstract public function aggregate_course(courseinfo $courseinfo, studyitem $studyitem, $userid); abstract public function aggregate_course(courseinfo $courseinfo, studyitem $studyitem, $userid);
abstract public function aggregate_junction(array $completion, studyitem $studyitem, $userid); abstract public function aggregate_junction(array $completion, studyitem $studyitem, $userid);
abstract public function grade_completion(gradeinfo $gradeinfo, $userid); abstract public function grade_completion(gradeinfo $gradeinfo, $userid);
// Aggregation method makes use of "required grades" in a course/module. // Aggregation method makes use of "required grades" in a course/module.
abstract public function useRequiredGrades(); abstract public function use_required_grades();
// Aggregation method makes use of . // Aggregation method makes use of .
abstract public function useItemConditions(); abstract public function use_item_conditions();
// Whether the aggregation method uses core_completion, or treestudyplan custom completion. // Whether the aggregation method uses core_completion, or treestudyplan custom completion.
public function usecorecompletioninfo() { public function usecorecompletioninfo() {
@ -107,8 +107,8 @@ abstract class aggregator {
public function basic_model() { public function basic_model() {
return [ return [
"useRequiredGrades" => $this->useRequiredGrades(), "useRequiredGrades" => $this->use_required_grades(),
"useItemConditions" => $this->useItemConditions(), "useItemConditions" => $this->use_item_conditions(),
]; ];
} }
@ -130,7 +130,7 @@ abstract class aggregator {
$list[] = [ $list[] = [
'id' => $agid, 'id' => $agid,
'name' => get_string("{$agid}_aggregator_title", "local_treestudyplan"), 'name' => get_string("{$agid}_aggregator_title", "local_treestudyplan"),
'deprecated' => $a->isDeprecated(), 'deprecated' => $a->deprecated(),
'defaultconfig' => $a->config_string(), 'defaultconfig' => $a->config_string(),
]; ];
} }

View File

@ -73,9 +73,9 @@ class associationservice extends \external_api {
global $DB; global $DB;
$ctx = \context::instance_by_id($r->contextid); $ctx = \context::instance_by_id($r->contextid);
$ctxPath = array_reverse($ctx->get_parent_context_ids(true)); $ctxpath = array_reverse($ctx->get_parent_context_ids(true));
if (count($ctxPath) > 1 && $ctxPath[0] == 1) { if (count($ctxpath) > 1 && $ctxpath[0] == 1) {
array_shift($ctxPath); array_shift($ctxpath);
} }
$result = [ $result = [
@ -89,10 +89,10 @@ class associationservice extends \external_api {
"shortname" => $ctx->get_context_name(false, true), "shortname" => $ctx->get_context_name(false, true),
"path" => array_map(function($c) { "path" => array_map(function($c) {
return \context::instance_by_id($c)->get_context_name(false, false); return \context::instance_by_id($c)->get_context_name(false, false);
}, $ctxPath), }, $ctxpath),
"shortpath" => array_map(function($c) { "shortpath" => array_map(function($c) {
return \context::instance_by_id($c)->get_context_name(false, true); return \context::instance_by_id($c)->get_context_name(false, true);
}, $ctxPath), }, $ctxpath),
] ]
]; ];
@ -429,16 +429,16 @@ class associationservice extends \external_api {
return usort($list, function($a, $b) { return usort($list, function($a, $b) {
$m = []; $m = [];
if (preg_match("/.*?([A-Z].*)/", $a['lastname'], $m)) { if (preg_match("/.*?([A-Z].*)/", $a['lastname'], $m)) {
$sortln_a = $m[1]; $sortlna = $m[1];
} else { } else {
$sortln_a = $a['lastname']; $sortlna = $a['lastname'];
} }
if (preg_match("/.*?([A-Z].*)/", $b['lastname'], $m)) { if (preg_match("/.*?([A-Z].*)/", $b['lastname'], $m)) {
$sortln_b = $m[1]; $sortlnb = $m[1];
} else { } else {
$sortln_b = $b['lastname']; $sortlnb = $b['lastname'];
} }
$cmp = $sortln_a <=> $sortln_b; $cmp = $sortlna <=> $sortlnb;
return ($cmp != 0) ? $cmp : $a['firstname'] <=> $b['firstname']; return ($cmp != 0) ? $cmp : $a['firstname'] <=> $b['firstname'];
}); });
} }
@ -471,5 +471,4 @@ class associationservice extends \external_api {
} }
} }

View File

@ -37,7 +37,7 @@ class cascadecohortsync {
$this->studyplanid = $studyplan->id(); $this->studyplanid = $studyplan->id();
} }
static private function array_remove_value($array, $value) { private static function array_remove_value($array, $value) {
$a = []; $a = [];
foreach ($array as $v) { foreach ($array as $v) {
if ($v != $value) { if ($v != $value) {
@ -47,7 +47,7 @@ class cascadecohortsync {
return $a; return $a;
} }
static function uploadenrolmentmethods_get_group($courseid, $groupname) { private static function uploadenrolmentmethods_get_group($courseid, $groupname) {
// Function shamelessly copied from tool/uploadenrolmentmethods/locallib.php. // Function shamelessly copied from tool/uploadenrolmentmethods/locallib.php.
global $DB, $CFG; global $DB, $CFG;
@ -92,7 +92,6 @@ class cascadecohortsync {
foreach ($cohortids as $cohortid) { foreach ($cohortids as $cohortid) {
$cohort = $DB->get_record('cohort', ['id' => $cohortid]); $cohort = $DB->get_record('cohort', ['id' => $cohortid]);
$instanceparams = [ $instanceparams = [
'courseid' => $courseid, 'courseid' => $courseid,
'customint1' => $cohortid, 'customint1' => $cohortid,
@ -152,16 +151,12 @@ class cascadecohortsync {
$instance = $DB->get_record('enrol', array('id' => $instanceid)); $instance = $DB->get_record('enrol', array('id' => $instanceid));
$enrol->update_instance($instance, (object)["customtext4" => json_encode([(int)($this->studyplanid)])]); $enrol->update_instance($instance, (object)["customtext4" => json_encode([(int)($this->studyplanid)])]);
// Successfully added a valid new instance, so now instantiate it. // Successfully added a valid new instance, so now instantiate it.
// First synchronise the enrolment. // First synchronise the enrolment.
$cohorttrace = new \null_progress_trace(); $cohorttrace = new \null_progress_trace();
$result = enrol_cohort_sync($cohorttrace, $cohortid); $result = enrol_cohort_sync($cohorttrace, $cohortid);
$cohorttrace->finished(); $cohorttrace->finished();
} else {
// Instance not added for some reason, so report an error somewhere.
// (or not).
} }
} }
} }

View File

@ -39,17 +39,19 @@ class contextinfo {
public function model() { public function model() {
$ctxPath = array_reverse($this->context->get_parent_context_ids(true)); $ctxpath = array_reverse($this->context->get_parent_context_ids(true));
if (count($ctxPath) > 1 && $ctxPath[0] == 1) { if (count($ctxpath) > 1 && $ctxpath[0] == 1) {
array_shift($ctxPath); array_shift($ctxpath);
} }
return [ return [
"name" => $this->context->get_context_name(false, false), "name" => $this->context->get_context_name(false, false),
"shortname" => $this->context->get_context_name(false, true), "shortname" => $this->context->get_context_name(false, true),
"path" => array_map(function($c) { return \context::instance_by_id($c)->get_context_name(false, false);}, $ctxPath), "path" => array_map(function($c) {
return \context::instance_by_id($c)->get_context_name(false, false);
}, $ctxpath),
"shortpath" => array_map(function($c) { "shortpath" => array_map(function($c) {
return \context::instance_by_id($c)->get_context_name(false, true); return \context::instance_by_id($c)->get_context_name(false, true);
}, $ctxPath), }, $ctxpath),
]; ];
} }

View File

@ -37,7 +37,8 @@ class corecompletioninfo {
private $course; private $course;
private $completion; private $completion;
private $modinfo; private $modinfo;
private static $COMPLETIONHANDLES = null; private static $completionhandles = null;
private static $completiontypes = null;
public function id() { public function id() {
return $this->course->id; return $this->course->id;
@ -49,28 +50,33 @@ class corecompletioninfo {
$this->modinfo = get_fast_modinfo($this->course); $this->modinfo = get_fast_modinfo($this->course);
} }
static public function completiontypes() { public static function completiontypes() {
global $COMPLETIONCRITERIA_TYPES; global $COMPLETION_CRITERIA_TYPES;
// Just return the keys of the global array COMPLETION_CRITERIA_TYPES, so we don't have to manually. /* Just return the keys of the global array COMPLETION_CRITERIA_TYPES,
// Add any completion types.... so we don't have to manually add any completion types if moodle decides to add a few.
return \array_keys($COMPLETIONCRITERIA_TYPES); Unfortunately, the global variable breaks the moodle coding standard...
*/
if (!isset(self::$completiontypes)) {
self::$completiontypes = \array_keys($COMPLETION_CRITERIA_TYPES);
}
return self::$completiontypes;
} }
/** /**
* Translate a numeric completion constant to a text string * Translate a numeric completion constant to a text string
* @param $completion The completion code as defined in completionlib.php to translate to a text handle * @param $completion The completion code as defined in completionlib.php to translate to a text handle
*/ */
static public function completion_handle($completion) { public static function completion_handle($completion) {
if (empty(self::$COMPLETIONHANDLES)) { if (empty(self::$completionhandles)) {
// Cache the translation table, to avoid overhead. // Cache the translation table, to avoid overhead.
self::$COMPLETIONHANDLES = [ self::$completionhandles = [
COMPLETION_INCOMPLETE => "incomplete", COMPLETION_INCOMPLETE => "incomplete",
COMPLETION_COMPLETE => "complete", COMPLETION_COMPLETE => "complete",
COMPLETION_COMPLETE_PASS => "complete-pass", COMPLETION_COMPLETE_PASS => "complete-pass",
COMPLETION_COMPLETE_FAIL => "complete-fail", COMPLETION_COMPLETE_FAIL => "complete-fail",
COMPLETION_COMPLETE_FAIL_HIDDEN => "complete-fail"]; // The front end won't differentiate between hidden or not. COMPLETION_COMPLETE_FAIL_HIDDEN => "complete-fail"]; // The front end won't differentiate between hidden or not.
} }
return self::$COMPLETIONHANDLES[$completion] ?? "undefined"; return self::$completionhandles[$completion] ?? "undefined";
} }
public static function completion_item_editor_structure($value = VALUE_REQUIRED) { public static function completion_item_editor_structure($value = VALUE_REQUIRED) {
@ -160,7 +166,7 @@ class corecompletioninfo {
} }
public function editor_model() { public function editor_model() {
global $DB, $CFG, $COMPLETIONCRITERIA_TYPES; global $DB, $CFG;
$conditions = []; $conditions = [];
$aggregation = "all"; // Default. $aggregation = "all"; // Default.
@ -179,7 +185,7 @@ class corecompletioninfo {
if (count($criterias) > 0 ) { if (count($criterias) > 0 ) {
// Only take it into account if the criteria count is > 0. // Only take it into account if the criteria count is > 0.
$cinfo = [ $cinfo = [
"type" => $COMPLETIONCRITERIA_TYPES[$type], "type" => self::completiontypes()[$type],
"aggregation" => self::aggregation_handle($this->completion->get_aggregation_method($type)), "aggregation" => self::aggregation_handle($this->completion->get_aggregation_method($type)),
"title" => reset($criterias)->get_type_title(), "title" => reset($criterias)->get_type_title(),
"items" => [], "items" => [],
@ -333,7 +339,7 @@ class corecompletioninfo {
} }
public function user_model($userid) { public function user_model($userid) {
global $DB, $COMPLETIONCRITERIA_TYPES; global $DB;
$progress = $this->get_advanced_progress_percentage($userid); $progress = $this->get_advanced_progress_percentage($userid);
$info = [ $info = [
@ -357,7 +363,7 @@ class corecompletioninfo {
$typeaggregation = $this->completion->get_aggregation_method($type); $typeaggregation = $this->completion->get_aggregation_method($type);
$completed = $this->aggregate_completions($typeaggregation, $completions); $completed = $this->aggregate_completions($typeaggregation, $completions);
$cinfo = [ $cinfo = [
"type" => $COMPLETIONCRITERIA_TYPES[$type], "type" => self::completiontypes()[$type],
"aggregation" => self::aggregation_handle($typeaggregation), "aggregation" => self::aggregation_handle($typeaggregation),
"completed" => $completed, "completed" => $completed,
"status" => $completed ? "complete" : "incomplete", "status" => $completed ? "complete" : "incomplete",
@ -656,9 +662,8 @@ class corecompletioninfo {
$completed = $cmpl; $completed = $cmpl;
$completionpercentage = $pct; $completionpercentage = $pct;
} }
} } else {
// If ALL completion for the types, add the count for this type to that of the others. // If ALL completion for the types, add the count for this type to that of the others.
else {
$count += $ct; $count += $ct;
$completed += $cmpl; $completed += $cmpl;
// Don't really care about recalculating completion percentage every round in this case. // Don't really care about recalculating completion percentage every round in this case.

View File

@ -90,16 +90,16 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
]); ]);
} }
public function needSelectGradables() { public function select_gradables() {
return true; return true;
} }
public function isDeprecated() { public function deprecated() {
return self::DEPRECATED; return self::DEPRECATED;
} }
public function useRequiredGrades() { public function use_required_grades() {
return true; return true;
} }
public function useItemConditions() { public function use_item_conditions() {
return false; return false;
} }

View File

@ -64,16 +64,16 @@ class core_aggregator extends \local_treestudyplan\aggregator {
]); ]);
} }
public function needSelectGradables() { public function select_gradables() {
return false; return false;
} }
public function isDeprecated() { public function deprecated() {
return self::DEPRECATED; return self::DEPRECATED;
} }
public function useRequiredGrades() { public function use_required_grades() {
return true; return true;
} }
public function useItemConditions() { public function use_item_conditions() {
return false; return false;
} }
public function usecorecompletioninfo() { public function usecorecompletioninfo() {

View File

@ -31,16 +31,16 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
public const DEPRECATED = true; public const DEPRECATED = true;
private const DEFAULT_CONDITION = "50"; private const DEFAULT_CONDITION = "50";
public function needSelectGradables() { public function select_gradables() {
return true; return true;
} }
public function isDeprecated() { public function deprecated() {
return self::DEPRECATED; return self::DEPRECATED;
} }
public function useRequiredGrades() { public function use_required_grades() {
return false; return false;
} }
public function useItemConditions() { public function use_item_conditions() {
return true; return true;
} }

View File

@ -54,7 +54,7 @@ class studyplan {
$this->id = $id; $this->id = $id;
$this->r = $DB->get_record(self::TABLE, ['id' => $id]); $this->r = $DB->get_record(self::TABLE, ['id' => $id]);
$this->aggregator = aggregator::createOrDefault($this->r->aggregation, $this->r->aggregation_config); $this->aggregator = aggregator::createordefault($this->r->aggregation, $this->r->aggregation_config);
} }
public function id() { public function id() {
@ -250,7 +250,7 @@ class studyplan {
$this->context = null; $this->context = null;
$this->context(); $this->context();
// Reload aggregator. // Reload aggregator.
$this->aggregator = aggregator::createOrDefault($this->r->aggregation, $this->r->aggregation_config); $this->aggregator = aggregator::createordefault($this->r->aggregation, $this->r->aggregation_config);
// Start temporary skräpp code. // Start temporary skräpp code.
// TODO: Until proper page editing is implemented, copy data from studyplan to it's first page. // TODO: Until proper page editing is implemented, copy data from studyplan to it's first page.
@ -359,7 +359,7 @@ class studyplan {
} }
static public function exist_for_user($userid) { public static function exist_for_user($userid) {
global $DB; global $DB;
$count = 0; $count = 0;
$sql = "SELECT s.* FROM {local_treestudyplan} s $sql = "SELECT s.* FROM {local_treestudyplan} s

View File

@ -20,7 +20,6 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
require_once("../../config.php"); require_once("../../config.php");
require_once($CFG->libdir.'/weblib.php'); require_once($CFG->libdir.'/weblib.php');

View File

@ -39,7 +39,6 @@ $string['treestudyplan:viewuserreports'] = "View study plan of others";
$string['treestudyplan:forcescales'] = 'Advanced: Allow studyplan manager to force assignment scales to setting (manual modes only)'; $string['treestudyplan:forcescales'] = 'Advanced: Allow studyplan manager to force assignment scales to setting (manual modes only)';
$string['treestudyplan:selectowngradables'] = 'Teachers can select gradables in their own courses in study plan view mode (manual modes only)'; $string['treestudyplan:selectowngradables'] = 'Teachers can select gradables in their own courses in study plan view mode (manual modes only)';
$string['report'] = 'Progress report'; $string['report'] = 'Progress report';
$string['report_invited'] = 'Progress report for {$a}'; $string['report_invited'] = 'Progress report for {$a}';
$string['report_index'] = 'View student progress reports'; $string['report_index'] = 'View student progress reports';
@ -242,7 +241,6 @@ $string['bistate_aggregator_desc'] = 'Goals are completed or not (e.g. not start
$string['core_aggregator_title'] = 'Moodle course completion'; $string['core_aggregator_title'] = 'Moodle course completion';
$string['core_aggregator_desc'] = 'Use Moodle core completion'; $string['core_aggregator_desc'] = 'Use Moodle core completion';
$string['setting_bistate_heading'] = 'Defaults for Completed + Required goalsn'; $string['setting_bistate_heading'] = 'Defaults for Completed + Required goalsn';
$string['settingdesc_bistate_heading'] = 'Set the defaults for this aggregation method'; $string['settingdesc_bistate_heading'] = 'Set the defaults for this aggregation method';

View File

@ -26,7 +26,6 @@
use local_treestudyplan\local\helpers\webservicehelper; use local_treestudyplan\local\helpers\webservicehelper;
use \local_treestudyplan\studyplan; use \local_treestudyplan\studyplan;
function local_treestudyplan_unit_get_editor_options($context) { function local_treestudyplan_unit_get_editor_options($context) {
global $CFG; global $CFG;
return ['subdirs' => 1, return ['subdirs' => 1,