Moodle code style fixes part 10
This commit is contained in:
parent
00b38f0a49
commit
f8fd27528a
|
@ -59,7 +59,7 @@ abstract class aggregator {
|
|||
}
|
||||
}
|
||||
|
||||
public static function createOrDefault($mod, $configstr) {
|
||||
public static function createordefault($mod, $configstr) {
|
||||
try {
|
||||
return self::create($mod, $configstr);
|
||||
} catch (\ValueError $x) {
|
||||
|
@ -74,17 +74,17 @@ abstract class aggregator {
|
|||
protected function initialize($configstr) {
|
||||
}
|
||||
|
||||
abstract public function needSelectGradables();
|
||||
abstract public function isDeprecated();
|
||||
abstract public function select_gradables();
|
||||
abstract public function deprecated();
|
||||
abstract public function aggregate_course(courseinfo $courseinfo, studyitem $studyitem, $userid);
|
||||
abstract public function aggregate_junction(array $completion, studyitem $studyitem, $userid);
|
||||
|
||||
abstract public function grade_completion(gradeinfo $gradeinfo, $userid);
|
||||
|
||||
// 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 .
|
||||
abstract public function useItemConditions();
|
||||
abstract public function use_item_conditions();
|
||||
|
||||
// Whether the aggregation method uses core_completion, or treestudyplan custom completion.
|
||||
public function usecorecompletioninfo() {
|
||||
|
@ -107,8 +107,8 @@ abstract class aggregator {
|
|||
|
||||
public function basic_model() {
|
||||
return [
|
||||
"useRequiredGrades" => $this->useRequiredGrades(),
|
||||
"useItemConditions" => $this->useItemConditions(),
|
||||
"useRequiredGrades" => $this->use_required_grades(),
|
||||
"useItemConditions" => $this->use_item_conditions(),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -130,7 +130,7 @@ abstract class aggregator {
|
|||
$list[] = [
|
||||
'id' => $agid,
|
||||
'name' => get_string("{$agid}_aggregator_title", "local_treestudyplan"),
|
||||
'deprecated' => $a->isDeprecated(),
|
||||
'deprecated' => $a->deprecated(),
|
||||
'defaultconfig' => $a->config_string(),
|
||||
];
|
||||
}
|
||||
|
|
|
@ -73,9 +73,9 @@ class associationservice extends \external_api {
|
|||
global $DB;
|
||||
|
||||
$ctx = \context::instance_by_id($r->contextid);
|
||||
$ctxPath = array_reverse($ctx->get_parent_context_ids(true));
|
||||
if (count($ctxPath) > 1 && $ctxPath[0] == 1) {
|
||||
array_shift($ctxPath);
|
||||
$ctxpath = array_reverse($ctx->get_parent_context_ids(true));
|
||||
if (count($ctxpath) > 1 && $ctxpath[0] == 1) {
|
||||
array_shift($ctxpath);
|
||||
}
|
||||
|
||||
$result = [
|
||||
|
@ -89,10 +89,10 @@ class associationservice extends \external_api {
|
|||
"shortname" => $ctx->get_context_name(false, true),
|
||||
"path" => array_map(function($c) {
|
||||
return \context::instance_by_id($c)->get_context_name(false, false);
|
||||
}, $ctxPath),
|
||||
}, $ctxpath),
|
||||
"shortpath" => array_map(function($c) {
|
||||
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) {
|
||||
$m = [];
|
||||
if (preg_match("/.*?([A-Z].*)/", $a['lastname'], $m)) {
|
||||
$sortln_a = $m[1];
|
||||
$sortlna = $m[1];
|
||||
} else {
|
||||
$sortln_a = $a['lastname'];
|
||||
$sortlna = $a['lastname'];
|
||||
}
|
||||
if (preg_match("/.*?([A-Z].*)/", $b['lastname'], $m)) {
|
||||
$sortln_b = $m[1];
|
||||
$sortlnb = $m[1];
|
||||
} else {
|
||||
$sortln_b = $b['lastname'];
|
||||
$sortlnb = $b['lastname'];
|
||||
}
|
||||
$cmp = $sortln_a <=> $sortln_b;
|
||||
$cmp = $sortlna <=> $sortlnb;
|
||||
return ($cmp != 0) ? $cmp : $a['firstname'] <=> $b['firstname'];
|
||||
});
|
||||
}
|
||||
|
@ -471,5 +471,4 @@ class associationservice extends \external_api {
|
|||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ class cascadecohortsync {
|
|||
$this->studyplanid = $studyplan->id();
|
||||
}
|
||||
|
||||
static private function array_remove_value($array, $value) {
|
||||
private static function array_remove_value($array, $value) {
|
||||
$a = [];
|
||||
foreach ($array as $v) {
|
||||
if ($v != $value) {
|
||||
|
@ -47,7 +47,7 @@ class cascadecohortsync {
|
|||
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.
|
||||
global $DB, $CFG;
|
||||
|
||||
|
@ -92,7 +92,6 @@ class cascadecohortsync {
|
|||
foreach ($cohortids as $cohortid) {
|
||||
$cohort = $DB->get_record('cohort', ['id' => $cohortid]);
|
||||
|
||||
|
||||
$instanceparams = [
|
||||
'courseid' => $courseid,
|
||||
'customint1' => $cohortid,
|
||||
|
@ -152,16 +151,12 @@ class cascadecohortsync {
|
|||
$instance = $DB->get_record('enrol', array('id' => $instanceid));
|
||||
$enrol->update_instance($instance, (object)["customtext4" => json_encode([(int)($this->studyplanid)])]);
|
||||
|
||||
|
||||
// Successfully added a valid new instance, so now instantiate it.
|
||||
// First synchronise the enrolment.
|
||||
$cohorttrace = new \null_progress_trace();
|
||||
$result = enrol_cohort_sync($cohorttrace, $cohortid);
|
||||
$cohorttrace->finished();
|
||||
|
||||
} else {
|
||||
// Instance not added for some reason, so report an error somewhere.
|
||||
// (or not).
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,17 +39,19 @@ class contextinfo {
|
|||
|
||||
public function model() {
|
||||
|
||||
$ctxPath = array_reverse($this->context->get_parent_context_ids(true));
|
||||
if (count($ctxPath) > 1 && $ctxPath[0] == 1) {
|
||||
array_shift($ctxPath);
|
||||
$ctxpath = array_reverse($this->context->get_parent_context_ids(true));
|
||||
if (count($ctxpath) > 1 && $ctxpath[0] == 1) {
|
||||
array_shift($ctxpath);
|
||||
}
|
||||
return [
|
||||
"name" => $this->context->get_context_name(false, false),
|
||||
"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) {
|
||||
return \context::instance_by_id($c)->get_context_name(false, true);
|
||||
}, $ctxPath),
|
||||
}, $ctxpath),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,8 @@ class corecompletioninfo {
|
|||
private $course;
|
||||
private $completion;
|
||||
private $modinfo;
|
||||
private static $COMPLETIONHANDLES = null;
|
||||
private static $completionhandles = null;
|
||||
private static $completiontypes = null;
|
||||
|
||||
public function id() {
|
||||
return $this->course->id;
|
||||
|
@ -49,28 +50,33 @@ class corecompletioninfo {
|
|||
$this->modinfo = get_fast_modinfo($this->course);
|
||||
}
|
||||
|
||||
static public function completiontypes() {
|
||||
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($COMPLETIONCRITERIA_TYPES);
|
||||
public static function completiontypes() {
|
||||
global $COMPLETION_CRITERIA_TYPES;
|
||||
/* Just return the keys of the global array COMPLETION_CRITERIA_TYPES,
|
||||
so we don't have to manually add any completion types if moodle decides to add a few.
|
||||
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
|
||||
* @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::$COMPLETIONHANDLES)) {
|
||||
public static function completion_handle($completion) {
|
||||
if (empty(self::$completionhandles)) {
|
||||
// Cache the translation table, to avoid overhead.
|
||||
self::$COMPLETIONHANDLES = [
|
||||
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::$COMPLETIONHANDLES[$completion] ?? "undefined";
|
||||
return self::$completionhandles[$completion] ?? "undefined";
|
||||
}
|
||||
|
||||
public static function completion_item_editor_structure($value = VALUE_REQUIRED) {
|
||||
|
@ -160,7 +166,7 @@ class corecompletioninfo {
|
|||
}
|
||||
|
||||
public function editor_model() {
|
||||
global $DB, $CFG, $COMPLETIONCRITERIA_TYPES;
|
||||
global $DB, $CFG;
|
||||
|
||||
$conditions = [];
|
||||
$aggregation = "all"; // Default.
|
||||
|
@ -179,7 +185,7 @@ class corecompletioninfo {
|
|||
if (count($criterias) > 0 ) {
|
||||
// Only take it into account if the criteria count is > 0.
|
||||
$cinfo = [
|
||||
"type" => $COMPLETIONCRITERIA_TYPES[$type],
|
||||
"type" => self::completiontypes()[$type],
|
||||
"aggregation" => self::aggregation_handle($this->completion->get_aggregation_method($type)),
|
||||
"title" => reset($criterias)->get_type_title(),
|
||||
"items" => [],
|
||||
|
@ -333,7 +339,7 @@ class corecompletioninfo {
|
|||
}
|
||||
|
||||
public function user_model($userid) {
|
||||
global $DB, $COMPLETIONCRITERIA_TYPES;
|
||||
global $DB;
|
||||
|
||||
$progress = $this->get_advanced_progress_percentage($userid);
|
||||
$info = [
|
||||
|
@ -357,7 +363,7 @@ class corecompletioninfo {
|
|||
$typeaggregation = $this->completion->get_aggregation_method($type);
|
||||
$completed = $this->aggregate_completions($typeaggregation, $completions);
|
||||
$cinfo = [
|
||||
"type" => $COMPLETIONCRITERIA_TYPES[$type],
|
||||
"type" => self::completiontypes()[$type],
|
||||
"aggregation" => self::aggregation_handle($typeaggregation),
|
||||
"completed" => $completed,
|
||||
"status" => $completed ? "complete" : "incomplete",
|
||||
|
@ -656,9 +662,8 @@ class corecompletioninfo {
|
|||
$completed = $cmpl;
|
||||
$completionpercentage = $pct;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// If ALL completion for the types, add the count for this type to that of the others.
|
||||
else {
|
||||
$count += $ct;
|
||||
$completed += $cmpl;
|
||||
// Don't really care about recalculating completion percentage every round in this case.
|
||||
|
|
|
@ -90,16 +90,16 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
|
|||
]);
|
||||
}
|
||||
|
||||
public function needSelectGradables() {
|
||||
public function select_gradables() {
|
||||
return true;
|
||||
}
|
||||
public function isDeprecated() {
|
||||
public function deprecated() {
|
||||
return self::DEPRECATED;
|
||||
}
|
||||
public function useRequiredGrades() {
|
||||
public function use_required_grades() {
|
||||
return true;
|
||||
}
|
||||
public function useItemConditions() {
|
||||
public function use_item_conditions() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,16 +64,16 @@ class core_aggregator extends \local_treestudyplan\aggregator {
|
|||
]);
|
||||
}
|
||||
|
||||
public function needSelectGradables() {
|
||||
public function select_gradables() {
|
||||
return false;
|
||||
}
|
||||
public function isDeprecated() {
|
||||
public function deprecated() {
|
||||
return self::DEPRECATED;
|
||||
}
|
||||
public function useRequiredGrades() {
|
||||
public function use_required_grades() {
|
||||
return true;
|
||||
}
|
||||
public function useItemConditions() {
|
||||
public function use_item_conditions() {
|
||||
return false;
|
||||
}
|
||||
public function usecorecompletioninfo() {
|
||||
|
|
|
@ -31,16 +31,16 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
|
|||
public const DEPRECATED = true;
|
||||
private const DEFAULT_CONDITION = "50";
|
||||
|
||||
public function needSelectGradables() {
|
||||
public function select_gradables() {
|
||||
return true;
|
||||
}
|
||||
public function isDeprecated() {
|
||||
public function deprecated() {
|
||||
return self::DEPRECATED;
|
||||
}
|
||||
public function useRequiredGrades() {
|
||||
public function use_required_grades() {
|
||||
return false;
|
||||
}
|
||||
public function useItemConditions() {
|
||||
public function use_item_conditions() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ class studyplan {
|
|||
$this->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() {
|
||||
|
@ -250,7 +250,7 @@ class studyplan {
|
|||
$this->context = null;
|
||||
$this->context();
|
||||
// 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.
|
||||
// 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;
|
||||
$count = 0;
|
||||
$sql = "SELECT s.* FROM {local_treestudyplan} s
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
require_once("../../config.php");
|
||||
|
||||
require_once($CFG->libdir.'/weblib.php');
|
||||
|
|
|
@ -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:selectowngradables'] = 'Teachers can select gradables in their own courses in study plan view mode (manual modes only)';
|
||||
|
||||
|
||||
$string['report'] = 'Progress report';
|
||||
$string['report_invited'] = 'Progress report for {$a}';
|
||||
$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_desc'] = 'Use Moodle core completion';
|
||||
|
||||
|
||||
$string['setting_bistate_heading'] = 'Defaults for Completed + Required goalsn';
|
||||
$string['settingdesc_bistate_heading'] = 'Set the defaults for this aggregation method';
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user