Code style

This commit is contained in:
PMKuipers 2024-06-02 19:23:40 +02:00
parent 4c669ff08c
commit e72be595aa
60 changed files with 1327 additions and 1447 deletions

View File

@ -202,7 +202,6 @@ abstract class aggregator {
return false;
}
/**
* Return the current configuration string.
* @return string Configuration string
@ -211,7 +210,6 @@ abstract class aggregator {
return "";
}
/**
* Webservice structure for basic aggregator info
* @param int $value Webservice requirement constant

View File

@ -124,7 +124,7 @@ class associationservice extends \external_api {
"shortpath" => array_map(function($c) {
return \context::instance_by_id($c)->get_context_name(false, true);
}, $ctxpath),
]
],
];
return $result;
@ -146,11 +146,9 @@ class associationservice extends \external_api {
$lastaccess = $DB->get_field_sql($lasql, ["userid" => $userid]);
}
return $lastaccess;
}
/**
* Parameter description for webservice function list_cohort
*/
@ -171,25 +169,25 @@ class associationservice extends \external_api {
/**
* Search cohorts for matching string
* @param string $like String to match cohorts with
* @param int $studyplan_id Do not include these cohorts
* @param int $studyplanid Do not include these cohorts
* @return array
*/
public static function list_cohort($like, $studyplan_id) {
public static function list_cohort($like, $studyplanid) {
global $CFG, $DB;
// Only allow this if the user has the right to edit in this context.
$studyplan = studyplan::find_by_id($studyplan_id);
$studyplan = studyplan::find_by_id($studyplanid);
$context = $studyplan->context();
webservicehelper::require_capabilities(self::CAP_EDIT, $context);
$pattern = "%{$like}%";
$params = ["pattern_nm" => $pattern, "pattern_id" => $pattern, ];
$params = ["pattern_nm" => $pattern, "pattern_id" => $pattern ];
$sql = "SELECT DISTINCT c.* from {cohort} c LEFT JOIN {local_treestudyplan_cohort} j ON c.id = j.cohort_id
WHERE c.visible = 1 AND(name LIKE :pattern_nm OR idnumber LIKE :pattern_id)
AND (j.studyplan_id IS NULL OR j.studyplan_id != :exclude_id)";
$params['exclude_id'] = $studyplan_id;
$params['exclude_id'] = $studyplanid;
$cohorts = [];
$rs = $DB->get_recordset_sql($sql, $params);
@ -224,11 +222,11 @@ class associationservice extends \external_api {
* @param int $contextid Context to search (default system)
* @return array
*/
public static function find_user($like, $studyplan_id) {
public static function find_user($like, $studyplanid) {
global $CFG, $DB;
// Only allow this if the user has the right to edit in this context.
$studyplan = studyplan::find_by_id($studyplan_id);
$studyplan = studyplan::find_by_id($studyplanid);
$context = $studyplan->context();
webservicehelper::require_capabilities(self::CAP_EDIT, $context);
@ -240,7 +238,7 @@ class associationservice extends \external_api {
$sql = "SELECT DISTINCT u.* from {user} u LEFT JOIN {local_treestudyplan_user} j ON u.id = j.user_id
WHERE u.deleted != 1 AND (firstname LIKE :pattern_fn OR lastname LIKE :pattern_ln OR username LIKE :pattern_un)
AND (j.studyplan_id IS NULL OR j.studyplan_id != :exclude_id)";
$params['exclude_id'] = $studyplan_id;
$params['exclude_id'] = $studyplanid;
$users = [];
$rs = $DB->get_recordset_sql($sql, $params);
@ -617,7 +615,7 @@ class associationservice extends \external_api {
'id' => 0,
'label' => get_string("individuals", 'local_treestudyplan'),
'users' => self::associated_users($studyplanid),
]
],
];
$sql = "SELECT DISTINCT c.* FROM {cohort} c INNER JOIN {local_treestudyplan_cohort} j ON j.cohort_id = c.id
@ -650,7 +648,6 @@ class associationservice extends \external_api {
return $userlist;
}
/**
* Sort a list of user models by firstname->lastname
* @param array $list Reference to list of user models
@ -705,7 +702,6 @@ class associationservice extends \external_api {
}
/**
* Parameter description for webservice function connect_user
*/
@ -793,14 +789,12 @@ class associationservice extends \external_api {
'user_id' => $userid,
]);
return ['success' => true, 'msg' => 'User Disconnected as coach'];
} else {
return ['success' => true, 'msg' => 'Connection does not exist'];
}
}
/**
* Parameter description for webservice function find_user
*/
@ -825,12 +819,11 @@ class associationservice extends \external_api {
* @param int $contextid Context to search (default system)
* @return array
*/
public static function find_coach($like, $studyplan_id) {
public static function find_coach($like, $studyplanid) {
global $CFG, $DB;
// Only allow this if the user has the right to edit in this context.
$studyplan = studyplan::find_by_id($studyplan_id);
$studyplan = studyplan::find_by_id($studyplanid);
$context = $studyplan->context();
webservicehelper::require_capabilities(self::CAP_EDIT, $context);

View File

@ -97,10 +97,9 @@ class badgeinfo {
*/
public static function exists($id) {
global $DB;
return is_numeric($id) && $DB->record_exists('badge', array('id' => $id));
return is_numeric($id) && $DB->record_exists('badge', ['id' => $id]);
}
/**
* Webservice structure for editor info
* @param int $value Webservice requirement constant
@ -258,9 +257,8 @@ class badgeinfo {
"active" => $this->badge->is_active(),
];
if ($issued) {
$issueinfo = $DB->get_record('badge_issued', array('badgeid' => $this->badge->id, 'userid' => $userid));
$issueinfo = $DB->get_record('badge_issued', ['badgeid' => $this->badge->id, 'userid' => $userid]);
$badge['dateissued'] = date("Y-m-d", $issueinfo->dateissued);
if ($issueinfo->expiredate) {
$badge['dateexpire'] = date("Y-m-d", $issueinfo->dateexpire);
@ -272,7 +270,6 @@ class badgeinfo {
return $badge;
}
protected static function badge_completion_structure($value) {
return new \external_single_structure([
"types" => new \external_multiple_structure(new \external_single_structure([
@ -345,10 +342,10 @@ class badgeinfo {
$progress += $typeprogress;
}
$aggrgation_handle = ($typeagg == BADGE_CRITERIA_AGGREGATION_ALL)?"all":"any";
$aggrgationhandle = ($typeagg == BADGE_CRITERIA_AGGREGATION_ALL)?"all":"any";
$typeinfo = [
'title' => ucfirst(get_string("criteria_descr_$type","badges", get_string($aggrgation_handle,"core"))),
'aggregation' => $aggrgation_handle,
'title' => ucfirst(get_string("criteria_descr_$type", "badges", get_string($aggrgationhandle, "core"))),
'aggregation' => $aggrgationhandle,
'criteria' => $typecrit,
'count' => $typecount,
'progress' => $typeprogress,
@ -358,11 +355,11 @@ class badgeinfo {
}
}
$aggrgation_handle = ($badgeagg == BADGE_CRITERIA_AGGREGATION_ALL)?"all":"any";
$aggrgationhandle = ($badgeagg == BADGE_CRITERIA_AGGREGATION_ALL)?"all":"any";
return [
"types" => $types,
"title" => ucfirst(get_string("criteria_descr_0","badges", mb_strtolower(get_string($aggrgation_handle,"core")))),
"aggregation" => $aggrgation_handle,
"title" => ucfirst(get_string("criteria_descr_0", "badges", mb_strtolower(get_string($aggrgationhandle, "core")))),
"aggregation" => $aggrgationhandle,
"count" => $count,
"progress" => $progress,
"fraction" => $fraction,
@ -387,7 +384,6 @@ class badgeinfo {
}
/**
* Gets the module instance from the database and returns it.
* If no module instance exists this function returns false.
@ -400,7 +396,7 @@ class badgeinfo {
FROM {course_modules} cm,
{modules} md
WHERE cm.id = ? AND
md.id = cm.module", array($cmid));
md.id = cm.module", [$cmid]);
if ($rec) {
return get_coursemodule_from_id($rec->name, $cmid);
@ -417,7 +413,7 @@ class badgeinfo {
*/
private static function get_role_name($rid) {
global $DB, $PAGE;
$rec = $DB->get_record('role', array('id' => $rid));
$rec = $DB->get_record('role', ['id' => $rid]);
if ($rec) {
return role_get_name($rec, \context_system::instance(), ROLENAME_BOTH);
@ -459,7 +455,7 @@ class badgeinfo {
'completion' => [
'title' => get_string('completeactivity', 'core').
get_string('modulename', $mod->modname) . ' - ' . $mod->name,
]
],
]
];
@ -487,14 +483,14 @@ class badgeinfo {
$subcrit["requirements"]["completion"]["completed"] = $modcompleted;
$check_date = true;
$checkdate = true;
if (isset($p["bydate"])) {
$date = $data->timemodified;
$check_date = ($date <= $p['bydate']);
$subcrit["requirements"]["bydate"]["completed"] = $check_date;
$checkdate = ($date <= $p['bydate']);
$subcrit["requirements"]["bydate"]["completed"] = $checkdate;
}
$subcrit["completed"] = $modcompleted && $check_date;
$subcrit["completed"] = $modcompleted && $checkdate;
}
$list[] = $subcrit;
}
@ -513,11 +509,11 @@ class badgeinfo {
$subcrit = [
"title" => $title,
"description" => $description,
"requirements" => []
"requirements" => [],
];
if (isset($userid)) {
$crit = $DB->get_record('badge_manual_award', array('issuerrole' => $p['role'], 'recipientid' => $userid, 'badgeid' => $crit->badgeid));
$crit = $DB->get_record('badge_manual_award', ['issuerrole' => $p['role'], 'recipientid' => $userid, 'badgeid' => $crit->badgeid]);
$subcrit["completed"] = $crit !== false;
}
$list[] = $subcrit;
@ -552,7 +548,7 @@ class badgeinfo {
"requirements" => [
'completion' => [
'title' => get_string('coursecompleted', 'completion'),
]
],
]
];
@ -573,19 +569,19 @@ class badgeinfo {
$coursecompleted = $coursecompletion->is_complete();
$subcrit["requirements"]["completion"]["completed"] = (bool) $coursecompleted;
$check_grade = true;
$checkgrade = true;
if (isset($p["grade"])) {
$grade = \grade_get_course_grade($userid, $course->id);
$check_grade = ($grade->grade >= $p['grade']);
$subcrit["requirements"]["grade"]["completed"] = (bool) $check_grade;
$checkgrade = ($grade->grade >= $p['grade']);
$subcrit["requirements"]["grade"]["completed"] = (bool) $checkgrade;
}
$check_date = true;
$checkdate = true;
if (isset($p["bydate"])) {
$check_date = ((bool) $coursecompletion->timecompleted) && ($coursecompletion->timecompleted <= $p["bydate"]);
$subcrit["requirements"]["bydate"]["completed"] = (bool) $check_date;
$checkdate = ((bool) $coursecompletion->timecompleted) && ($coursecompletion->timecompleted <= $p["bydate"]);
$subcrit["requirements"]["bydate"]["completed"] = (bool) $checkdate;
}
$subcrit["completed"] = $coursecompleted && $check_grade && $check_date;
$subcrit["completed"] = $coursecompleted && $checkgrade && $checkdate;
}
$list[] = $subcrit;
}
@ -612,7 +608,7 @@ class badgeinfo {
$subcrit = [
"title" => $title,
"description" => $description,
"requirements" => []
"requirements" => [],
];
if (isset($userid)) {
@ -643,7 +639,7 @@ class badgeinfo {
}
} else if ($crit->criteriatype == BADGE_CRITERIA_TYPE_BADGE) {
foreach ($crit->params as $p) {
$badgename = $DB->get_field('badge', 'name', array('id' => $p['badge']));
$badgename = $DB->get_field('badge', 'name', ['id' => $p['badge']]);
if (!$badgename) {
$title = get_string('error:nosuchbadge', 'badges');
$description = get_string('error:nosuchbadge', 'badges');
@ -656,14 +652,14 @@ class badgeinfo {
"title" => $title,
"description" => $description,
"link" => (new \moodle_url($CFG->wwwroot."/badges/overview.php", ["id" => $p["badge"]]))->out(),
"requirements" => []
"requirements" => [],
];
if (isset($userid)) {
$badge = $DB->get_record('badge', array('id' => $p['badge']));
$badge = $DB->get_record('badge', ['id' => $p['badge']]);
// See if the user has earned this badge.
if ($badge) {
$awarded = $DB->get_record('badge_issued', array('badgeid' => $p['badge'], 'userid' => $userid));
$awarded = $DB->get_record('badge_issued', ['badgeid' => $p['badge'], 'userid' => $userid]);
$awarded = isset($awarded);
} else {
$awarded = false;
@ -674,7 +670,7 @@ class badgeinfo {
}
} else if ($crit->criteriatype == BADGE_CRITERIA_TYPE_COHORT) {
foreach ($crit->params as $p) {
$cohortname = $DB->get_field('cohort', 'name', array('id' => $p['cohort']));
$cohortname = $DB->get_field('cohort', 'name', ['id' => $p['cohort']]);
if (!$cohortname) {
$title = get_string('error:nosuchcohort', 'badges');
$description = get_string('error:nosuchcohort', 'badges');
@ -686,11 +682,11 @@ class badgeinfo {
$subcrit = [
"title" => $title,
"description" => $description,
"requirements" => []
"requirements" => [],
];
if (isset($userid)) {
$cohort = $DB->get_record('cohort', array('id' => $p['cohort']));
$cohort = $DB->get_record('cohort', ['id' => $p['cohort']]);
$ismember = (bool) \cohort_is_member($cohort->id, $userid);
$subcrit["completed"] = $ismember;
}
@ -734,7 +730,7 @@ class badgeinfo {
$subcrit = [
"title" => $title,
"description" => $description,
"requirements" => []
"requirements" => [],
];
if (isset($userid)) {
@ -742,7 +738,7 @@ class badgeinfo {
to use criteria api class instead of direct calls....
*/
$proficiency = false;
$badge = $DB->get_record('badge', array('id' => $crit->badgeid));
$badge = $DB->get_record('badge', ['id' => $crit->badgeid]);
if ($badge->type == BADGE_TYPE_SITE) {
$uc = \core_competency\api::get_user_competency($userid, $p['competency']);
$proficiency = $uc->get('proficiency');
@ -811,7 +807,6 @@ class badgeinfo {
INNER JOIN {badge_criteria_param} p on p.critid = crit.id
WHERE p.value = :courseid AND crit.criteriatype $ctypesql $conditions";
$courserelids = $DB->get_fieldset_sql($sql, $sqlparams);
[$ctypesql, $ctypeinparams] = $DB->get_in_or_equal([BADGE_CRITERIA_TYPE_COMPETENCY], SQL_PARAMS_NAMED);
@ -822,10 +817,8 @@ class badgeinfo {
INNER JOIN {competency_coursecomp} cc on cc.competencyid = p.value
WHERE cc.courseid = :courseid AND crit.criteriatype $ctypesql $conditions";
$competencyrelids = $DB->get_fieldset_sql($sql, $sqlparams);
$badgeids = [];
foreach ([$courserelids, $competencyrelids] as $list) {
foreach ($list as $id) {
@ -853,7 +846,6 @@ class badgeinfo {
throw new \moodle_exception("\$course argument must be course id or course object", "local_treestudyplan");
}
$search = trim($search);
$conditions = "";
$basesqlparams = ['courseid' => $courseid];
@ -962,5 +954,4 @@ class badgeinfo {
return $badges;
}
}

View File

@ -92,8 +92,8 @@ class cascadecohortsync {
require_once($CFG->dirroot.'/group/lib.php');
// Check to see if the group name already exists in this course.
if ($DB->record_exists('groups', array('name' => $groupname, 'courseid' => $courseid))) {
$group = $DB->get_record('groups', array('name' => $groupname, 'courseid' => $courseid));
if ($DB->record_exists('groups', ['name' => $groupname, 'courseid' => $courseid])) {
$group = $DB->get_record('groups', ['name' => $groupname, 'courseid' => $courseid]);
return $group->id;
}
// The named group doesn't exist, so create a new one in the course.
@ -175,7 +175,6 @@ class cascadecohortsync {
// Find the study lines associated to this studyplan.
$lines = $this->studyplan->get_all_studylines();
foreach($lines as $line) {
$this->syncline($line);
@ -201,7 +200,7 @@ class cascadecohortsync {
$instanceparams = ['courseid' => $courseid, 'enrol' => 'manual'];
if (!($instance = $DB->get_record('enrol', $instanceparams))) {
if ($instanceid = $this->manualenrol->add_default_instance($course)) {
$instance = $DB->get_record('enrol', array('id' => $instanceid));
$instance = $DB->get_record('enrol', ['id' => $instanceid]);
} else {
// Instance not added for some reason, so report an error somewhere.
// (or not).
@ -297,7 +296,7 @@ class cascadecohortsync {
// Also record the (as of yet only) studyplans id requiring this association.
// In the customtext4 field in json format.
$instance = $DB->get_record('enrol', array('id' => $instanceid));
$instance = $DB->get_record('enrol', ['id' => $instanceid]);
$this->enrol->update_instance($instance, (object)["customtext4" => json_encode([(int)($this->studyplanid)])]);
// Successfully added a valid new instance, so now instantiate it.

View File

@ -58,7 +58,6 @@ class cascadeusersync {
$this->userids = $this->studyplan->get_linked_user_ids();
}
/**
* Enroll all users associated to the studyplan in the courses linked to this studyplan
*/
@ -118,7 +117,7 @@ class cascadeusersync {
$instanceparams = ['courseid' => $courseid, 'enrol' => 'manual'];
if (!($instance = $DB->get_record('enrol', $instanceparams))) {
if ($instanceid = $this->enrol->add_default_instance($course)) {
$instance = $DB->get_record('enrol', array('id' => $instanceid));
$instance = $DB->get_record('enrol', ['id' => $instanceid]);
} else {
// Instance not added for some reason, so report an error somewhere.
// (or not).

View File

@ -61,7 +61,6 @@ class contextinfo {
*/
public function model() {
return [
"name" => $this->context->get_context_name(false, false),
"shortname" => $this->context->get_context_name(false, true),
@ -96,7 +95,6 @@ class contextinfo {
return implode(" / ", $this->path($short));
}
/**
* Make new Contextinfo for context id
* @param int $contextid Context id

View File

@ -317,7 +317,7 @@ class corecompletioninfo {
// Set title based on cm formatted name
$title = $cm->get_formatted_name();
// Build requirements.
$details['requirement'] = array();
$details['requirement'] = [];
if ($cm->completion == COMPLETION_TRACKING_MANUAL) {
$details['requirement'][] = get_string('markingyourselfcomplete', 'completion');
@ -371,7 +371,7 @@ class corecompletioninfo {
} else if ($type == COMPLETION_CRITERIA_TYPE_COURSE) {
$prereq = get_course($criteria->courseinstance);
$coursecontext = \context_course::instance($prereq->id, MUST_EXIST);
$fullname = format_string($prereq->fullname, true, array('context' => $coursecontext));
$fullname = format_string($prereq->fullname, true, ['context' => $coursecontext]);
$details = [
"type" => $criteria->get_title(),
"criteria" => '<a href="'.$CFG->wwwroot.'/course/view.php?id='.

View File

@ -334,7 +334,6 @@ class coursecompetencyinfo {
// Retrieve feedback.
$ci["feedback"] = $this->retrievefeedback($c, $userid);
$rule = $c->get_rule_object();
$ruleoutcome = $c->get('ruleoutcome');
if ($rule && $ruleoutcome != competency::OUTCOME_NONE) {
@ -413,7 +412,6 @@ class coursecompetencyinfo {
$ci["progress"] = $dprogress;
}
}
$cis[] = $ci;
}
@ -472,7 +470,7 @@ class coursecompetencyinfo {
*/
public static function get_user_competency($userid, $competencyid) {
c_api::require_enabled();
$existing = user_competency::get_multiple($userid, array($competencyid));
$existing = user_competency::get_multiple($userid, [$competencyid]);
$uc = array_pop($existing);
if (!$uc) {
@ -499,7 +497,7 @@ class coursecompetencyinfo {
// This will throw an exception if the competency does not belong to the course.
$competency = course_competency::get_competency($courseid, $competencyid);
$params = array('courseid' => $courseid, 'userid' => $userid, 'competencyid' => $competencyid);
$params = ['courseid' => $courseid, 'userid' => $userid, 'competencyid' => $competencyid];
$exists = user_competency_course::get_record($params);
// Create missing.
if ($exists) {
@ -512,7 +510,6 @@ class coursecompetencyinfo {
return $ucc;
}
/**
* Retrieve course proficiency and overall proficiency for a competency and user
*

View File

@ -458,7 +458,6 @@ class courseinfo {
'showprogressbar' => get_config("local_treestudyplan", "courseprogressbar"),
];
if (isset($this->studyitem)) {
$aggregator = $this->studyitem->studyline()->studyplan()->aggregator();
@ -480,7 +479,6 @@ class courseinfo {
return $info;
}
/**
* Webservice structure for extra fields
* @param int $value Webservice requirement constant

View File

@ -49,7 +49,6 @@ class courseservice extends \external_api {
*/
const CAP_VIEW = "local/treestudyplan:viewuserreports";
/**
* Get the topmost categories for the specicied user.
* Most of the work is offloaded to an SQL query in the interest of speed, but moodle functions are used to double check access permissions.
@ -99,9 +98,9 @@ class courseservice extends \external_api {
// Use recordset to handle the eventuality of a really big and complex moodle setup.
$recordset = $DB->get_records_sql($sql, ["userid" => $userid, "capability" => $capability,
"ctxl_coursecat" => \CONTEXT_COURSECAT,]);
"ctxl_coursecat" => \CONTEXT_COURSECAT ]);
$params = ["userid" => $userid, "capability" => $capability,
"ctxl_coursecat" => \CONTEXT_COURSECAT,];
"ctxl_coursecat" => \CONTEXT_COURSECAT ];
$contextids = [];
foreach ($recordset as $r) {
// Get the paths as an array.
@ -151,7 +150,7 @@ class courseservice extends \external_api {
$capability = 'moodle/category:viewcourselist';
$tops = [];
$path_like = $DB->sql_like('ctx.path',':pathsearch');
$pathlike = $DB->sql_like('ctx.path', ':pathsearch');
$sql = "SELECT UNIQUE ctx.* FROM {context} AS ctx
INNER JOIN {role_assignments} AS ra ON ra.contextid = ctx.id
@ -159,7 +158,7 @@ class courseservice extends \external_api {
LEFT JOIN {course_categories} AS cat ON ctx.instanceid = cat.id
WHERE ( ctx.contextlevel = :ctxl_coursecat )
AND ra.userid = :userid AND rc.capability = :capability
AND {$path_like}
AND {$pathlike}
ORDER BY ctx.depth ASC, cat.sortorder ASC";
// Use recordset to handle the eventuality of a really big and complex moodle setup.
@ -199,7 +198,6 @@ class courseservice extends \external_api {
return $tops;
}
/**
* Return value description for map_categories function
*/
@ -247,7 +245,6 @@ class courseservice extends \external_api {
public static function map_categories($studyplanid = 0) {
global $USER;
// Determine top categories from provided context.
if ($studyplanid == 0) {
@ -486,7 +483,6 @@ class courseservice extends \external_api {
}
}
// Now translate this to the list of categories.
foreach ($contextids as $ctxid ) {
try {
@ -529,7 +525,6 @@ class courseservice extends \external_api {
}
/**************************************
*
* Progress scanners for teacherview

View File

@ -67,7 +67,6 @@ class debug {
}
}
/**
* @param $object Object to dump
* @param $filename File to write to

View File

@ -73,6 +73,4 @@ abstract class formbase extends \moodleform {
}
}
}

View File

@ -14,7 +14,6 @@ use local_treestudyplan\form\text_integer;
use moodle_exception;
use stdClass;
/**
* Moodleform class for the studyplan editor. A Moodleform is used here to facilitate a rich editor
* in the studyplan description
@ -91,7 +90,7 @@ class studyplan_editform extends formbase {
$entry = new stdClass;
$entry->context_id = $customdata->context->id;
$entry->aggregation = get_config("local_treestudyplan", "aggregation_mode");
$ag_cfg = json_decode(aggregator::create($entry->aggregation, "")->config_string(),true);
$agcfg = json_decode(aggregator::create($entry->aggregation, "")->config_string(), true);
// Determine the next august 1st for default value purposes.
$august = strtotime("first day of august this year");
@ -107,7 +106,7 @@ class studyplan_editform extends formbase {
$entry->startdate = strtotime($customdata->simplemodel['pages'][0]['startdate']);
$entry->enddate = strtotime($customdata->simplemodel['pages'][0]['enddate']);
$entry->periods = $customdata->simplemodel['pages'][0]['periods'];
$ag_cfg = json_decode($customdata->plan->aggregator()->config_string(),true);
$agcfg = json_decode($customdata->plan->aggregator()->config_string(), true);
}
// Prepare the editor
@ -139,7 +138,7 @@ class studyplan_editform extends formbase {
// Add aggregation configs to entry.
foreach ($ag_cfg as $key => $val) {
foreach ($agcfg as $key => $val) {
$entrykey = $entry->aggregation."_".$key;
$entry->$entrykey = $val;
}
@ -257,7 +256,7 @@ class studyplan_editform extends formbase {
["unsigned" => false],
);
$mform->setType($field, PARAM_INT);
$mform->hideIf($field, "aggregation", "neq", "bistate");
$mform->hideif ($field, "aggregation", "neq", "bistate");
$field = 'bistate_thresh_good';
$mform->addElement('text_integer', $field,
@ -265,7 +264,7 @@ class studyplan_editform extends formbase {
["unsigned" => true],
);
$mform->setType($field, PARAM_INT);
$mform->hideIf($field, "aggregation", "neq", "bistate");
$mform->hideif ($field, "aggregation", "neq", "bistate");
$field = 'bistate_thresh_completed';
$mform->addElement('text_integer', $field,
@ -273,21 +272,21 @@ class studyplan_editform extends formbase {
["unsigned" => true],
);
$mform->setType($field, PARAM_INT);
$mform->hideIf($field, "aggregation", "neq", "bistate");
$mform->hideif ($field, "aggregation", "neq", "bistate");
$field = 'bistate_use_failed';
$mform->addElement('checkbox', $field,
get_string('setting_bistate_support_failed', 'local_treestudyplan'),
[],
);
$mform->hideIf($field, "aggregation", "neq", "bistate");
$mform->hideif ($field, "aggregation", "neq", "bistate");
$field = 'bistate_accept_pending_as_submitted';
$mform->addElement('checkbox', $field,
get_string('setting_bistate_accept_pending_submitted', 'local_treestudyplan'),
[],
);
$mform->hideIf($field, "aggregation", "neq", "bistate");
$mform->hideif ($field, "aggregation", "neq", "bistate");
/* End Bistate aggregation specific items */
@ -308,12 +307,12 @@ class studyplan_editform extends formbase {
$customdata = (object)$this->_customdata;
// Add aggregation configs to entry.
$ag_cfg = json_decode(aggregator::create($entry->aggregation, "")->config_string(),true); // Retrieve default config string from selected aggregation method
foreach ($ag_cfg as $key => $val) {
$agcfg = json_decode(aggregator::create($entry->aggregation, "")->config_string(), true); // Retrieve default config string from selected aggregation method
foreach ($agcfg as $key => $val) {
$entrykey = $entry->aggregation."_".$key;
$ag_cfg[$key] = $entry->$entrykey;
$agcfg[$key] = $entry->$entrykey;
}
$aggregation_config = json_encode($ag_cfg);
$aggregationconfig = json_encode($agcfg);
if ($customdata->create) {
@ -323,7 +322,7 @@ class studyplan_editform extends formbase {
'idnumber' => $entry->idnumber,
'context_id' => $entry->context_id,
'aggregation' => $entry->aggregation,
'aggregation_config' => $aggregation_config,
'aggregation_config' => $aggregationconfig,
'startdate' => date("Y-m-d", $entry->startdate),
'enddate' => date("Y-m-d", $entry->enddate),
'periods' => $entry->periods,
@ -361,7 +360,7 @@ class studyplan_editform extends formbase {
'description' => $entry->description,
'descriptionformat' => $entry->descriptionformat,
'aggregation' => $entry->aggregation,
'aggregation_config' => $aggregation_config,
'aggregation_config' => $aggregationconfig,
'suspended' => $entry->suspended,
'template' => $entry->template,
]);
@ -389,5 +388,4 @@ class studyplan_editform extends formbase {
return $response;
}
}

View File

@ -14,7 +14,6 @@ use local_treestudyplan\form\text_integer;
use moodle_exception;
use stdClass;
/**
* Moodleform class for the studyplan editor. A Moodleform is used here to facilitate a rich editor
* in the studyplan description
@ -36,7 +35,6 @@ class studyplan_fromtemplateform extends formbase {
$customdata = new stdClass;
$customdata->context = \context::instance_by_id($params->contextid);
return $customdata;
}
@ -183,5 +181,4 @@ class studyplan_fromtemplateform extends formbase {
}
}
}

View File

@ -252,5 +252,4 @@ class studyplanpage_editform extends formbase {
return studyplanservice::clean_returnvalue(studyplanpage::editor_structure(), $page->editor_model());
}
}

View File

@ -3,12 +3,10 @@ namespace local_treestudyplan\form;
use MoodleQuickForm_text;
use MoodleQuickForm;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir . "/form/text.php");
class text_integer extends MoodleQuickForm_text {
/**
* Accepts a renderer
@ -32,7 +30,6 @@ class text_integer extends MoodleQuickForm_text {
}
$label = $this->getLabel();
$unsigned = (isset($this->_attributes['unsigned']) && $this->_attributes['unsigned']);
$nonzero = (isset($this->_attributes['nonzero']) && $this->_attributes['nonzero']);
$context = array(

View File

@ -210,7 +210,6 @@ class gradeinfo {
}
}
$this->typename = empty($contentitem) ? $gi->itemmodule : $contentitem->get_title()->get_value();
$this->gradingscanner = new gradingscanner($gi);
@ -488,7 +487,6 @@ class gradeinfo {
return $list;
}
/**
* Webservice executor to include grade with studyitem or not.
* if both $inclue and $required are false, any existing DB record will be removed

View File

@ -69,7 +69,7 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
*/
protected function initialize($configstr) {
// First initialize with the defaults.
foreach (["thresh_excellent", "thresh_good", "thresh_completed", "thresh_progress", ] as $key) {
foreach (["thresh_excellent", "thresh_good", "thresh_completed", "thresh_progress" ] as $key) {
$val = intval(get_config('local_treestudyplan', "bistate_{$key}"));
if ($val >= 0 && $val <= 100) {
$this->cfg()->$key = floatval($val) / 100;
@ -84,7 +84,7 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
if (is_array($config)) {
// Copy all valid config settings to this item.
foreach (["thresh_excellent", "thresh_good", "thresh_completed", "thresh_progress", ] as $key) {
foreach (["thresh_excellent", "thresh_good", "thresh_completed", "thresh_progress" ] as $key) {
if (array_key_exists($key, $config)) {
$val = $config[$key];
if ($val >= 0 && $val <= 100) {

View File

@ -68,13 +68,13 @@ class competency_aggregator extends \local_treestudyplan\aggregator {
*/
protected function initialize($configstr) {
// First initialize with the defaults.
foreach (["thresh_completed", ] as $key) {
foreach (["thresh_completed" ] as $key) {
$val = intval(get_config('local_treestudyplan', "competency_{$key}"));
if ($val >= 0 && $val <= 100) {
$this->cfg()->$key = floatval($val) / 100;
}
}
foreach (["use_failed", ] as $key) {
foreach (["use_failed" ] as $key) {
$this->cfg()->$key = boolval(get_config('local_treestudyplan', "competency_{$key}"));
}
@ -83,7 +83,7 @@ class competency_aggregator extends \local_treestudyplan\aggregator {
if (is_array($config)) {
// Copy all valid config settings to this item.
foreach (["thresh_completed", ] as $key) {
foreach (["thresh_completed" ] as $key) {
if (array_key_exists($key, $config)) {
$val = $config[$key];
if ($val >= 0 && $val <= 100) {
@ -91,7 +91,7 @@ class competency_aggregator extends \local_treestudyplan\aggregator {
}
}
}
foreach (["use_failed",] as $key) {
foreach (["use_failed" ] as $key) {
if (array_key_exists($key, $config)) {
$this->cfg()->$key = boolval($config[$key]);
}
@ -280,7 +280,6 @@ class competency_aggregator extends \local_treestudyplan\aggregator {
}
}
/**
* Determine completion for a single grade and user
* @param gradeinfo $gradeinfo Gradeinfo object for grade to check
@ -291,5 +290,4 @@ class competency_aggregator extends \local_treestudyplan\aggregator {
// COURSE COMPETENCIES DOESN'T REALLY USE THIS FUNCTION.
}
}

View File

@ -35,7 +35,6 @@ class core_aggregator extends \local_treestudyplan\aggregator {
/** @var bool */
public const DEPRECATED = false;
/**
* Create new instance of aggregation method
* @param string $configstr Aggregation configuration string
@ -208,7 +207,6 @@ class core_aggregator extends \local_treestudyplan\aggregator {
}
}
/**
* Determine completion for a single grade and user
* @param gradeinfo $gradeinfo Gradeinfo object for grade to check

View File

@ -70,15 +70,15 @@ class randomimage {
];
/**
* Create a random polygon with number of points between 0 & $max_pts
* Create a random polygon with number of points between 0 & $maxpts
* @param \GdImage $im The image reource
* @param integer $max_pts Max number of point to use
* @param integer $maxpts Max number of point to use
* @return void
*/
private function random_polygon($im, Int $max_pts = 20)
private function random_polygon($im, Int $maxpts = 20)
{
$color = imagecolorallocatealpha($im, ...$this->random_color_alpha());
$pts = $this->random_pts(\random_int(3, $max_pts));
$pts = $this->random_pts(\random_int(3, $maxpts));
imagefilledpolygon($im, $pts, $color);
}
@ -100,7 +100,6 @@ class randomimage {
imagefilledarc($im, $cx, $cy, $w, $h, $s, $e, $col, $style);
}
/**
* Generates an array of random alpha color values.
* @return Array [r, g, b, a]

View File

@ -142,7 +142,6 @@ class period {
return $period;
}
/**
* Find all periods registered to a studyplan in sequence
* @param studyplanpage $page Studyplan page to find periods for
@ -313,7 +312,7 @@ class period {
$next = (count($pages) > $this->period()) ? $pages[$this->period() + 1] : null;
$editable = ['fullname', 'shortname', 'startdate', 'enddate'];
$info = ['id' => $this->id, ];
$info = ['id' => $this->id ];
foreach ($editable as $f) {
if (array_key_exists($f, $fields)) {
$info[$f] = $fields[$f];

View File

@ -20,7 +20,6 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_treestudyplan;
defined('MOODLE_INTERNAL') || die();
@ -30,7 +29,6 @@ use DateTime;
use moodle_url;
use stdClass;
/**
* Handle badge information in the same style as the other classes
*/
@ -38,7 +36,7 @@ class premium extends \external_api {
// Toggle the variable below to enable support for premium stuff.
// If set to false, all premium features will be enabled and no premium settings panel will be visible.
private static $premium_supported = false;
private static $premiumsupported = false;
private static $premiumcrt = "-----BEGIN CERTIFICATE-----
MIIDSzCCAjMCFFlyhmKf1fN7U5lQL/dtlsyP24AQMA0GCSqGSIb3DQEBCwUAMGEx
@ -64,7 +62,7 @@ Klc5I28bGbvxIV5pnL6ZSjHEDp2WreM8HB0XFJwU+Q==
private static $cachedpremiumstatus = null;
public static function supported() {
return self::$premium_supported;
return self::$premiumsupported;
}
private static function decrypt($encrypted) {
@ -107,8 +105,8 @@ Klc5I28bGbvxIV5pnL6ZSjHEDp2WreM8HB0XFJwU+Q==
private static function trim_headers($data) {
// Headers are repeated in this function for easier testing and copy-pasting into other projects.
$START_HEADER = "----- BEGIN ACTIVATION KEY -----";
$END_HEADER = "----- END ACTIVATION KEY -----";
$STARTHEADER = "----- BEGIN ACTIVATION KEY -----";
$ENDHEADER = "----- END ACTIVATION KEY -----";
$parts = preg_split("/\r?\n/", \trim($data));
if (count($parts) > 2) {
@ -117,10 +115,10 @@ Klc5I28bGbvxIV5pnL6ZSjHEDp2WreM8HB0XFJwU+Q==
for($i = 0; $i < count($parts); $i++) {
$p = trim(preg_replace('/\s+/u', ' ', $parts[$i])); // Make sure all unicode spaces are converted to normal spaces before comparing...
if ( $p == $START_HEADER ) {
if ( $p == $STARTHEADER ) {
$start = $i+1;
}
if ($start > 0 && $p == $END_HEADER) {
if ($start > 0 && $p == $ENDHEADER) {
$end = $i;
}
}
@ -141,7 +139,7 @@ Klc5I28bGbvxIV5pnL6ZSjHEDp2WreM8HB0XFJwU+Q==
* @return bool
*/
public static function enabled() {
if (self::$premium_supported) {
if (self::$premiumsupported) {
$status = self::premiumStatus();
return $status->enabled;
} else {
@ -376,7 +374,7 @@ Klc5I28bGbvxIV5pnL6ZSjHEDp2WreM8HB0XFJwU+Q==
* @return object
*/
public static function get_premiumstatus() {
if (self::$premium_supported) {
if (self::$premiumsupported) {
$status = self::premiumStatus();
$keys = [
"enabled",

View File

@ -260,7 +260,7 @@ class provider implements \core_privacy\local\metadata\provider,
// 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)) ";
$planids = $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.
@ -270,7 +270,7 @@ 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)";
$planids = $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.
}

View File

@ -45,12 +45,12 @@ class reportinvite_form extends moodleform {
$mform->addElement('hidden', 'update', 0);
$mform->setType('update', PARAM_INT);
$mform->addElement('text', 'name', get_string('invite_name', 'local_treestudyplan'), array('size' => 50));
$mform->addElement('text', 'name', get_string('invite_name', 'local_treestudyplan'), ['size' => 50]);
$mform->setType('name', PARAM_NOTAGS); // Set type of element.
$mform->setDefault('name', ''); // Default value.
$mform->addRule('name', get_string('required'), 'required', null, 'client');
$mform->addElement('text', 'email', get_string('invite_email', 'local_treestudyplan'), array('size' => 20));
$mform->addElement('text', 'email', get_string('invite_email', 'local_treestudyplan'), ['size' => 20]);
$mform->setType('email', PARAM_NOTAGS); // Set type of element.
$mform->setDefault('email', ''); // Default value.
$mform->addRule('email', get_string('required'), 'required', null, 'client');
@ -68,7 +68,7 @@ class reportinvite_form extends moodleform {
* @return array validation data
*/
public function validation($data, $files) {
return array();
return [];
}
/**

View File

@ -40,7 +40,6 @@ class reportservice extends \external_api {
*/
const CAP_VIEW = "local/treestudyplan:viewuserreports";
public static function get_report_structure_parameters(): \external_function_parameters {
return new \external_function_parameters([
"pageid" => new \external_value(PARAM_INT, 'id of studyplan page'),
@ -122,7 +121,6 @@ class reportservice extends \external_api {
}
}
$model["periods"][] = $pmodel;
}
@ -146,7 +144,6 @@ class reportservice extends \external_api {
return new \external_multiple_structure(studyitem::user_structure(), "Information per studyitem");
}
public static function get_report_data($pageid, $userid, $firstperiod=null, $lastperiod=null) {
$page = studyplanpage::find_by_id($pageid);
webservicehelper::require_capabilities(self::CAP_VIEW, $page->studyplan()->context());
@ -183,8 +180,6 @@ class reportservice extends \external_api {
}
public static function get_report_details_parameters(): \external_function_parameters {
return new \external_function_parameters([
"itemid" => new \external_value(PARAM_INT, 'id of studyitem'),
@ -216,5 +211,4 @@ class reportservice extends \external_api {
}
}

View File

@ -65,7 +65,6 @@ class studyitem {
/** @var aggregator */
private $aggregator;
/**
* Return the context the studyplan is associated to
*/
@ -163,7 +162,7 @@ class studyitem {
*/
public static function exists($id): bool {
global $DB;
return is_numeric($id) && $DB->record_exists(self::TABLE, array('id' => $id));
return is_numeric($id) && $DB->record_exists(self::TABLE, ['id' => $id]);
}
/**
@ -199,7 +198,7 @@ class studyitem {
if (isset($ci)) {
$model['course'] = $ci->simple_model();
}
if (is_numeric($this->r->badge_id) && $DB->record_exists('badge', array('id' => $this->r->badge_id))) {
if (is_numeric($this->r->badge_id) && $DB->record_exists('badge', ['id' => $this->r->badge_id])) {
$badge = new \core_badges\badge($this->r->badge_id);
$badgeinfo = new badgeinfo($badge);
$model['badge'] = $badgeinfo->simple_model();
@ -257,7 +256,7 @@ class studyitem {
'connections' => [
"in" => [],
"out" => [],
]
],
];
if ($mode == "export") {
// Remove slot and layer.
@ -278,7 +277,7 @@ class studyitem {
}
// Add badge info if available.
if (is_numeric($this->r->badge_id) && $DB->record_exists('badge', array('id' => $this->r->badge_id))) {
if (is_numeric($this->r->badge_id) && $DB->record_exists('badge', ['id' => $this->r->badge_id])) {
$badge = new \core_badges\badge($this->r->badge_id);
$badgeinfo = new badgeinfo($badge);
if ($mode == "export") {
@ -333,7 +332,7 @@ class studyitem {
global $DB;
$addable = ['line_id', 'type', 'layer', 'conditions', 'slot',
'competency_id', 'course_id', 'badge_id', 'continuation_id', 'span'];
$info = [ 'layer' => 0, ];
$info = [ 'layer' => 0 ];
foreach ($addable as $f) {
if (array_key_exists($f, $fields)) {
$info[$f] = $fields[$f];
@ -356,7 +355,7 @@ class studyitem {
global $DB;
$editable = ['conditions', 'course_id', 'continuation_id', 'span'];
$info = ['id' => $this->id, ];
$info = ['id' => $this->id ];
foreach ($editable as $f) {
if (array_key_exists($f, $fields) && isset($fields[$f])) {
$info[$f] = $fields[$f];
@ -475,8 +474,6 @@ class studyitem {
return $list;
}
/**
* Webservice structure for linking between plans
* @param int $value Webservice requirement constant
@ -700,7 +697,6 @@ class studyitem {
return $this->generate_model("export");
}
/**
* Import studyitems from model
* @param array $model Decoded array

View File

@ -72,7 +72,6 @@ class studyitemconnection {
return ['id' => $this->r->id, 'from_id' => $this->r->from_id, 'to_id' => $this->r->to_id];
}
/**
* Get originating studyitem for this connection
*/

View File

@ -110,7 +110,6 @@ class studyline {
/** @var studyplan*/
private $studyplan;
/**
* Return the context the studyplan is associated to
*/
@ -436,7 +435,6 @@ class studyline {
return $model;
}
/**
* Add a new study line
* @param array $fields Properties for study line ['page_id', 'name', 'shortname', 'color']
@ -468,7 +466,7 @@ class studyline {
public function edit($fields): self {
global $DB;
$editable = ['name', 'shortname', 'color', 'enrollable', 'enrolrole'];
$info = ['id' => $this->id, ];
$info = ['id' => $this->id ];
foreach ($editable as $f) {
if (array_key_exists($f, $fields)) {
$info[$f] = $fields[$f];
@ -580,24 +578,24 @@ class studyline {
if (empty($r)) {
$enrolled = false;
$enrolled_time = 0;
$enrolled_by = "";
$enrolledtime = 0;
$enrolledby = "";
} else {
$enrolled = boolval($r->enrolled);
$enrolled_time = $r->timeenrolled;
$enrolledtime = $r->timeenrolled;
$by = $DB->get_record('user', ["id" => $r->enrolledby]);
if (empty($by)) {
$enrolled_by = \get_string("unknownuser","core");
$enrolledby = \get_string("unknownuser", "core");
} else {
$enrolled_by = "{$by->firstname} {$by->lastname}";
$enrolledby = "{$by->firstname} {$by->lastname}";
}
}
$usermodel = [
'can_enrol' => $this->can_enrol($userid),
"enrolled" => $enrolled,
"enrolled_time" => $enrolled_time,
"enrolled_by" => $enrolled_by,
"enrolled_time" => $enrolledtime,
"enrolled_by" => $enrolledby,
"selfview" => boolval($userid == $USER->id),
];
$model = array_merge($model, $usermodel);
@ -626,7 +624,6 @@ class studyline {
}
}
/**
* Check if student is enrolled in the line.
* @param int $userid ID of user to check specific info for
@ -737,7 +734,6 @@ class studyline {
}
}
/**
* Webservice model for user info
* @param int $userid ID of user to check specific info for

View File

@ -38,7 +38,6 @@ class studyplan {
/** @var string */
const TABLE_COACH = "local_treestudyplan_coach";
/**
* Cache retrieved studyitems in this session
* @var array */
@ -155,7 +154,6 @@ class studyplan {
return $date;
}
private function icon() {
global $CFG;
$fs = \get_file_storage();
@ -390,7 +388,7 @@ class studyplan {
// Get a list of available scales.
$scales = array_map( function($scale) {
return [ "id" => $scale->id, "name" => $scale->name, ];
return [ "id" => $scale->id, "name" => $scale->name ];
}, \grade_scale::fetch_all(['courseid' => 0]) );
$model['advanced']['force_scales'] = [
@ -463,7 +461,7 @@ class studyplan {
'suspended',
'template'
];
$info = ['id' => $this->id, ];
$info = ['id' => $this->id ];
foreach ($editable as $f) {
if (array_key_exists($f, $fields)) {
$info[$f] = $fields[$f];
@ -1010,7 +1008,6 @@ class studyplan {
return $model;
}
/**
* Export files from file storage
* @param string $area Name of the file area to export
@ -1138,7 +1135,6 @@ class studyplan {
}
}
/**
* Import pages from decoded array model
* @param array $model Decoded array
@ -1203,7 +1199,6 @@ class studyplan {
return ($count > 0) ? true : false;
}
/**
* Get all study lines linked to this plan (quickly)
* Used for cohort enrolment cascading

View File

@ -342,7 +342,7 @@ class studyplanpage {
public function edit($fields): self {
global $DB;
$editable = ['fullname', 'shortname', 'description', 'descriptionformat', 'periods', 'startdate', 'enddate'];
$info = ['id' => $this->id, ];
$info = ['id' => $this->id ];
foreach ($editable as $f) {
if (array_key_exists($f, $fields)) {
$info[$f] = $fields[$f];
@ -768,7 +768,6 @@ class studyplanpage {
}
}
/**
* Export this pages periods into an array before serialization
* @return array

View File

@ -888,8 +888,6 @@ class studyplanservice extends \external_api {
webservicehelper::require_capabilities(self::CAP_EDIT, $studyplan->context());
}
return studyitemconnection::disconnect($fromid, $toid)->model();
}
@ -935,7 +933,6 @@ class studyplanservice extends \external_api {
}
/****************************
* *
* search badges *
@ -976,7 +973,6 @@ class studyplanservice extends \external_api {
return $results;
}
/**
* Parameter description for webservice function list_badges
*/
@ -1043,7 +1039,6 @@ class studyplanservice extends \external_api {
return success::structure();
}
/**
* Mark a gradable item for inclusion in the studyplan
* @param mixed $gradeid Id of gradable
@ -1097,7 +1092,6 @@ class studyplanservice extends \external_api {
return success::structure();
}
/**
* Mark a competency as required for course completion
* @param mixed $gradeid Id of gradable
@ -1393,7 +1387,6 @@ class studyplanservice extends \external_api {
return studyplan::export_structure();
}
/**
* Export studyplan
* @param mixed $studyplanid Id of studyplan to export
@ -1449,7 +1442,6 @@ class studyplanservice extends \external_api {
}
}
/****************************
* *
* import studyplan *
@ -1557,9 +1549,9 @@ class studyplanservice extends \external_api {
* @param string $format Format of file
* @return array Success/fail model
*/
public static function import_studylines($page_id, $content, $format = "application/json") {
public static function import_studylines($pageid, $content, $format = "application/json") {
try {
$page = studyplanpage::find_by_id($page_id);
$page = studyplanpage::find_by_id($pageid);
// Validate import context.
webservicehelper::require_capabilities(self::CAP_EDIT, $page->studyplan()->context());
@ -1919,7 +1911,6 @@ class studyplanservice extends \external_api {
}
}
return (new success($result, implode("<p>\n", $message)))->model();
}
@ -1991,9 +1982,9 @@ class studyplanservice extends \external_api {
* @param bool $force Force deletion, even though studyplan is not empty
* @return array Succes/fail model
*/
public static function list_roles($studyplan_id) {
public static function list_roles($studyplanid) {
global $DB;
$p = studyplan::find_by_id($studyplan_id);
$p = studyplan::find_by_id($studyplanid);
$context = $p->context();
// Validate if the requesting user has the right to edit the plan in it's current context.
webservicehelper::require_capabilities(self::CAP_EDIT, $context);
@ -2082,9 +2073,9 @@ class studyplanservice extends \external_api {
$list = [];
// Unenrol capability also acts as overriding manager capability to register/unregister.
$can_unenrol = \has_capability('local/treestudyplan:lineunenrol',$context);
$canunenrol = \has_capability('local/treestudyplan:lineunenrol', $context);
foreach ($users as $userid) {
if ($o->can_enrol($userid) || $can_unenrol) {
if ($o->can_enrol($userid) || $canunenrol) {
$o->enrol($userid);
$list[] = self::student_enrol_status_model($userid, $o);
}

View File

@ -79,7 +79,6 @@ class success {
]);
}
/**
* Make the webservice result model
* @return array Webservice value

View File

@ -33,7 +33,6 @@ class teachingfinder {
/** @var string */
const TABLE = "local_treestudyplan_teachers";
/**
* List all studyplans the current user is teaching
* (Updates the cache if no results are found the first time)
@ -80,7 +79,6 @@ class teachingfinder {
return ($count > 0)?true:false;
}
/**
* Check if current user is teaching in a specific studyplan
* (Does not update the cache if results are 0)

View File

@ -45,7 +45,6 @@ class utilityservice extends \external_api {
*/
const CAP_VIEW = "local/treestudyplan:viewuserreports";
protected static function load_mform($formname, $params, $ajaxformdata = null) {
global $CFG;
/* We don't need to load the form php file (class autoloading will handle that)
@ -94,7 +93,6 @@ class utilityservice extends \external_api {
\external_api::validate_context(\context_system::instance());
require_login(null, false, null);
// Hack alert: Set a default URL to stop the annoying debug.
$PAGE->set_url('/');
// Hack alert: Forcing bootstrap_renderer to initiate moodle page.
@ -167,7 +165,6 @@ class utilityservice extends \external_api {
return success::success($return)->model();
}
/**
* Parameter description for webservice function submit_cm_editform
*/
@ -200,5 +197,4 @@ class utilityservice extends \external_api {
];
}
}

View File

@ -87,7 +87,6 @@ $authplugin->sync_roles($user);
login_attempt_valid($user);
complete_user_login($user);
for ($i=0; $i<$amount; $i++) {
$fortune = shell_exec("{$fortunepath} -n 160 ");
$pieces = explode(" ", $fortune);
@ -100,7 +99,6 @@ for ($i=0; $i<$amount; $i++) {
$randomicon = new randomimage(10, 256, 256);
$fordb->name = $name;
$fordb->version = 1;
$fordb->language = "en";
@ -134,7 +132,7 @@ for ($i=0; $i<$amount; $i++) {
$newid = $DB->insert_record('badge', $fordb, true);
// Trigger event, badge created.
$eventparams = array('objectid' => $newid, 'context' => $PAGE->context);
$eventparams = ['objectid' => $newid, 'context' => $PAGE->context];
$event = \core\event\badge_created::create($eventparams);
$event->trigger();
@ -143,4 +141,3 @@ for ($i=0; $i<$amount; $i++) {
cli_writeln("Created new badge '{$name}'");
}

View File

@ -28,22 +28,19 @@ require_once($CFG->libdir.'/weblib.php');
$systemcontext = context_system::instance();
$PAGE->set_url("/local/treestudyplan/coach.php", array());
$PAGE->set_url("/local/treestudyplan/coach.php", []);
require_login();
$PAGE->set_pagelayout('base');
$PAGE->set_context($systemcontext);
$PAGE->set_title(get_string('coaching_plans', 'local_treestudyplan'));
$PAGE->set_heading(get_string('coaching_plans', 'local_treestudyplan'));
premium::require_premium();
if ( ! (\get_config("local_treestudyplan", "enablecoach")) ) {
throw new \moodle_exception("error:coachdisabled", "local_treestudyplan");
}
// Load javascripts and specific css.
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/bootstrap-vue/bootstrap-vue.css'));
if ($CFG->debugdeveloper) {

View File

@ -533,8 +533,6 @@ function xmldb_local_treestudyplan_upgrade($oldversion) {
}
// Treestudyplan savepoint reached.
upgrade_plugin_savepoint(true, 2024022502, 'local', 'treestudyplan');
}
@ -649,12 +647,9 @@ function xmldb_local_treestudyplan_upgrade($oldversion) {
// Launch change of default for field suspended.
$dbman->change_field_default($table, $field);
// Treestudyplan savepoint reached.
upgrade_plugin_savepoint(true, 2024052400, 'local', 'treestudyplan');
}
return true;
}

View File

@ -26,7 +26,7 @@ require_once($CFG->libdir.'/weblib.php');
$systemcontext = context_system::instance();
$PAGE->set_url("/local/treestudyplan/doc.php", array());
$PAGE->set_url("/local/treestudyplan/doc.php", []);
if ($CFG->debugdeveloper) {
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devstyles.css'));
}

View File

@ -56,7 +56,7 @@ if (!empty($add)) {
);
} else if (!empty($update)) {
$data = $DB->get_record("local_treestudyplan_invit", array('id' => $update));
$data = $DB->get_record("local_treestudyplan_invit", ['id' => $update]);
$data->update = $update;
if (empty($data) || $data->user_id != $USER->id) {
throw new \moodle_exception('invalidaction', 'local_treestudyplan');;
@ -64,7 +64,7 @@ if (!empty($add)) {
}
} else if (!empty($resend)) {
$data = $DB->get_record("local_treestudyplan_invit", array('id' => $resend));
$data = $DB->get_record("local_treestudyplan_invit", ['id' => $resend]);
$data->resend = $resend;
if (empty($data) || $data->user_id != $USER->id) {
throw new \moodle_exception('invalidaction', 'local_treestudyplan');;
@ -77,7 +77,7 @@ if (!empty($add)) {
print $OUTPUT->footer();
exit;
} else if (!empty($delete)) {
$data = $DB->get_record("local_treestudyplan_invit", array('id' => $delete));
$data = $DB->get_record("local_treestudyplan_invit", ['id' => $delete]);
$data->delete = $delete;
if (empty($data) || $data->user_id != $USER->id) {
throw new \moodle_exception('invalidaction', 'local_treestudyplan');;

View File

@ -31,7 +31,7 @@ use local_treestudyplan\debug;
$systemcontext = context_system::instance();
$PAGE->set_url("/local/treestudyplan/edit-plan.php", array());
$PAGE->set_url("/local/treestudyplan/edit-plan.php", []);
require_login();
// Figure out the context (category or system, based on either category or context parameter).

View File

@ -31,7 +31,7 @@ $invitedurl = "/local/treestudyplan/invited.php";
$systemcontext = context_system::instance();
$PAGE->set_url("/local/treestudyplan/invitations.php", array());
$PAGE->set_url("/local/treestudyplan/invitations.php", []);
require_login();
$PAGE->set_pagelayout('base');
@ -45,7 +45,7 @@ $PAGE->requires->js_call_amd('local_treestudyplan/page-invitemanager', 'init');
// Retrieve list of courses that the student is enrolled in.
$sent = optional_param('sent', '', PARAM_INT);
if (!empty($sent)) {
$invite = $DB->get_record('local_treestudyplan_invit', array('id' => $sent));
$invite = $DB->get_record('local_treestudyplan_invit', ['id' => $sent]);
\core\notification::success(get_string('invite_resent_msg', 'local_treestudyplan', $invite));
};
@ -71,7 +71,7 @@ if (!get_config("local_treestudyplan","enableplansharing")) {
print "<p>".get_string('invite_description', 'local_treestudyplan')."</p>";
$invites = $DB->get_records('local_treestudyplan_invit', array('user_id' => $USER->id));
$invites = $DB->get_records('local_treestudyplan_invit', ['user_id' => $USER->id]);
print "<h3>".get_string('invite_tablecaption', 'local_treestudyplan')."</h3>";
print "<table class='m-manage_invites'>";

View File

@ -41,7 +41,7 @@ $PAGE->set_context($systemcontext);
// See if we can get a valid user for this invited.
$invitekey = optional_param('key', '', PARAM_ALPHANUM); // Module name.
$PAGE->set_url("/local/treestudyplan/invited.php", array('key' => $invitekey));
$PAGE->set_url("/local/treestudyplan/invited.php", ['key' => $invitekey]);
$invite = $DB->get_record_select("local_treestudyplan_invit",
$DB->sql_compare_text("invitekey"). " = " . $DB->sql_compare_text(":invitekey"),
@ -85,7 +85,7 @@ if (!get_config("local_treestudyplan","enableplansharing")) {
}
$PAGE->requires->js_call_amd('local_treestudyplan/page-myreport', 'init', ['invited', $invitekey]);
$student = $DB->get_record('user', array('id' => $invite->user_id));
$student = $DB->get_record('user', ['id' => $invite->user_id]);
$PAGE->set_title(get_string('report_invited', 'local_treestudyplan', "{$student->firstname} {$student->lastname}" ));
$PAGE->set_heading(get_string('report_invited', 'local_treestudyplan', "{$student->firstname} {$student->lastname}"));

View File

@ -271,7 +271,6 @@ $string["studyplan_past"] = "Past study plans";
$string["studyplan_present"] = "Current study plans";
$string["studyplan_future"] = "Upcoming study plans";
$string["link_myreport"] = "My study plan";
$string["link_viewplan"] = "Study plans";
$string["link_editplan"] = "Manage study plans";
@ -416,7 +415,6 @@ $string["currentpage"] = "Currently active page:";
$string["advanced_bulk_course_timing"] = 'Sync course timing to periods';
$string["advanced_bulk_course_timing_desc"] = 'Synchronize the start and end date of all courses in the currently active studyplan page to periods in which they are placed.';
$string["advanced_cascade_cohortsync_title"] = "Cascade cohort sync";
$string["advanced_cascade_cohortsync_desc"] = "Add cohort sync enrolment to each course in this study plan for all cohorts linked to this study plan";
$string["advanced_cascade_cohortsync"] = "Cascade cohort sync";
@ -497,7 +495,6 @@ $string["setting_premium_key"] = 'Activation key';
$string["settingdesc_premium_key"] = 'Paste the premium key you received in the box above.<br> <b>Attention!</b> The lines <i>----- BEGIN ACTIVATION KEY -----</i> and <i>----- END ACTIVATION KEY -----</i> are part of the key.';
$string["setting_premium_debug"] = 'Debug info for premium key';
$string["premiumfeature:morestudyplans"] = 'Creating more than 5 studyplans in a single category is a premium feature.';
$string["premiumfeature:morecategories"] = 'Creating studyplans in more than 20 categories is a premium feature.';
$string["premiumfeature:warning"] = 'The features on this page are only accessible if your site has premium features enabled.';

View File

@ -41,7 +41,6 @@ $string["treestudyplan:selectowngradables"] = 'Docenten kunnen in hun eigen curs
$string["treestudyplan:lineunenrol"] = "Beheer inschrijvingen van studenten in leerlijnen";
$string["treestudyplan:coach"] = "Beschikbaar als coach";
$string["report"] = 'Voortgangsrapport';
$string["report_invited"] = 'Voortgang van {$a}';
$string["report_index"] = 'Studieplannen van studenten inzien';
@ -333,7 +332,6 @@ $string["core_aggregator_desc"] = 'Gebruik de ingesteld cursusvoltooiing';
$string["competency_aggregator_title"] = 'Cursuscompetenties';
$string["competency_aggregator_desc"] = 'Gebruik de bij de cursus ingestelde competenties';
$string["setting_bistate_heading"] = 'Standaardwaarden voor Behaald + Vereiste leerdoelen ';
$string["settingdesc_bistate_heading"] = 'Stel de standaardwaarden in voor deze verzamelmethode';
@ -369,7 +367,6 @@ $string["settingdesc_copystudylinesnewpage"] = 'Bij aanmaken van een nieuw tabbl
$string["setting_continueperiodnumberingnewpage"] = 'Perioden doornummeren op nieuw tabblad';
$string["settingdesc_continueperiodnumberingnewpage"] = 'Bij aanmaken van een nieuw tabblad, wordt de standaardnaam van perioden doorgenummerd (b.v. P5, P6, P7, P8) in plaats van herstart (P1, P2, P3, P4)';
$string["grade_include"] = 'Doel';
$string["grade_require"] = 'Verplicht';
$string["required_goal"] = 'Verplicht leerdoel';

20
lib.php
View File

@ -44,7 +44,6 @@ function local_treestudyplan_unit_get_editor_options(context $context) {
'trusttext' => 0];
}
/**
* Create primary navigation links for studyplan if needed
*/
@ -140,7 +139,7 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
// Create studyplan node.
$node = navigation_node::create(
get_string("link_myreport", "local_treestudyplan"),
new moodle_url($CFG->wwwroot . "/local/treestudyplan/myreport.php", array()),
new moodle_url($CFG->wwwroot . "/local/treestudyplan/myreport.php", []),
global_navigation::TYPE_SYSTEM,
null,
"local_treestudyplan_myreport",
@ -152,7 +151,7 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
// Create invitenode node.
$invitenode = navigation_node::create(
get_string("manage_invites", "local_treestudyplan"),
new moodle_url($CFG->wwwroot . "/local/treestudyplan/invitations.php", array()),
new moodle_url($CFG->wwwroot . "/local/treestudyplan/invitations.php", []),
global_navigation::TYPE_CUSTOM ,
null,
"local_treestudyplan_invitemgmt",
@ -169,7 +168,7 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
|| webservicehelper::has_capability_in_any_category('local/treestudyplan:viewuserreports')) {
$node = navigation_node::create(
get_string("link_viewplan", "local_treestudyplan"),
new moodle_url($CFG->wwwroot . "/local/treestudyplan/view-plan.php", array()),
new moodle_url($CFG->wwwroot . "/local/treestudyplan/view-plan.php", []),
global_navigation::TYPE_SYSTEM ,
null,
"local_treestudyplan_viewplan",
@ -186,7 +185,7 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
) {
$node = navigation_node::create(
get_string("link_editplan", "local_treestudyplan"),
new moodle_url($CFG->wwwroot . "/local/treestudyplan/edit-plan.php", array()),
new moodle_url($CFG->wwwroot . "/local/treestudyplan/edit-plan.php", []),
global_navigation::TYPE_SYSTEM ,
null,
"local_treestudyplan_editplan",
@ -210,7 +209,7 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
) {
$node = navigation_node::create(
get_string("link_coach", "local_treestudyplan"),
new moodle_url($CFG->wwwroot . "/local/treestudyplan/coach.php", array()),
new moodle_url($CFG->wwwroot . "/local/treestudyplan/coach.php", []),
global_navigation::TYPE_SYSTEM ,
null,
"local_treestudyplan_coach",
@ -231,7 +230,7 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
// Create invitenode node.
$invitenode = navigation_node::create(
get_string("nav_invited", "local_treestudyplan"),
new moodle_url($CFG->wwwroot . "/local/treestudyplan/invited.php", array()),
new moodle_url($CFG->wwwroot . "/local/treestudyplan/invited.php", []),
global_navigation::TYPE_USER ,
null,
"local_treestudyplan_invitemgmt",
@ -315,7 +314,7 @@ function local_treestudyplan_reset_fontawesome_icon_map() {
*/
function local_treestudyplan_send_invite($inviteid) {
global $DB, $USER, $CFG;
$invite = $DB->get_record("local_treestudyplan_invit", array('id' => $inviteid));
$invite = $DB->get_record("local_treestudyplan_invit", ['id' => $inviteid]);
$noreply = 'noreply@' . get_host_from_url($CFG->wwwroot);
$mailer = get_mailer();
@ -435,8 +434,7 @@ function local_treestudyplan_pluginfile(
): bool {
global $DB, $USER;
$studyplan_filecaps = ["local/treestudyplan:editstudyplan","local/treestudyplan:viewuserreports"];
$studyplanfilecaps = ["local/treestudyplan:editstudyplan", "local/treestudyplan:viewuserreports"];
// Check the contextlevel is as expected - the studyplan plugin only uses system context for storing files.
// This avoids headaches when moving studyplans between contexts, while the security impact is minimal...
@ -444,7 +442,6 @@ function local_treestudyplan_pluginfile(
return false;
}
// Make sure the filearea is one of those used by the plugin.
if (in_array($filearea, ["studyplan", "icon", "studyplanpage"])) {
// The args is an array containing [itemid, path].
@ -506,4 +503,3 @@ function local_treestudyplan_pluginfile(
}

View File

@ -29,17 +29,17 @@ use local_treestudyplan\teachingfinder;
$systemcontext = context_system::instance();
$PAGE->set_url("/local/treestudyplan/myreport.php", array());
$PAGE->set_url("/local/treestudyplan/myreport.php", []);
require_login();
$PAGE->set_pagelayout('base');
$PAGE->set_context($systemcontext);
//$teachermode = has_capability("local/treestudyplan:viewuserreports", $systemcontext);
$am_teaching = teachingfinder::is_teaching($USER->id);
$have_plans = studyplan::exist_for_user($USER->id);
$amteaching = teachingfinder::is_teaching($USER->id);
$haveplans = studyplan::exist_for_user($USER->id);
if ($am_teaching) {
if ($amteaching) {
$PAGE->set_title(get_string('myreport_teachermode', 'local_treestudyplan'));
$PAGE->set_heading(get_string('myreport_teachermode', 'local_treestudyplan'));
} else {
@ -52,7 +52,7 @@ $PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/boot
if ($CFG->debugdeveloper) {
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devstyles.css'));
}
$PAGE->requires->js_call_amd('local_treestudyplan/page-myreport', 'init', [$am_teaching ? 'teaching' : 'own']);
$PAGE->requires->js_call_amd('local_treestudyplan/page-myreport', 'init', [$amteaching ? 'teaching' : 'own']);
/**
* Shortcut function to provide translations
@ -70,7 +70,7 @@ print $OUTPUT->header();
print '<div class="m-buttonbar" style="margin-bottom: 1em; text-align: right;">';
if (get_config("local_treestudyplan","enableplansharing") && !$am_teaching) {
if (get_config("local_treestudyplan", "enableplansharing") && !$amteaching) {
print '<a class="btn btn-primary" href="invitations.php" id="manage_invites">';
print '&nbsp;<i class="fa fa-share"></i>&nbsp;'.t('manage_invites').'</a>';
}
@ -83,7 +83,7 @@ print " <span class='sr-only'>Loading...</span>";
print " </div>";
print " </div>";
print " <div v-cloak>";
if ($am_teaching) {
if ($amteaching) {
print " <r-report type='teaching' teachermode ></r-report>";
} else {
print " <r-report type='own' :userid='userid'></r-report>";

View File

@ -45,8 +45,6 @@ $contextname = $ci->pathstr();
$firstperiod = optional_param('firstperiod', 0, PARAM_INT); // First period to show
$lastperiod = optional_param('lastperiod', 0, PARAM_INT); // Last periode to show
$PAGE->set_pagelayout('report');
$PAGE->set_title(get_string('studyplan_report', 'local_treestudyplan'));
$PAGE->set_heading(get_string('studyplan_report', 'local_treestudyplan'));
@ -66,7 +64,6 @@ if ($CFG->debugdeveloper) {
}
$PAGE->requires->js_call_amd('local_treestudyplan/page-result-overview', 'init', [$studyplan->id(), $page->id(), $firstperiod, $lastperiod]);
/**
* Shortcut function to provide translations
*

View File

@ -89,7 +89,7 @@ if ($hassiteconfig) {
get_string('settingdesc_display_heading', 'local_treestudyplan')
));
$displayfields = ["shortname" => get_string("shortname"), "idnumber" => get_string("idnumber"), "fullname" => get_string("fullname"), ];
$displayfields = ["shortname" => get_string("shortname"), "idnumber" => get_string("idnumber"), "fullname" => get_string("fullname") ];
$infofields = ["" => get_string('none'), "description" => get_string("description"), "contacts" => get_string("teachers"), "idnumber" => get_string("idnumber")];
$handler = \core_customfield\handler::get_handler('core_course', 'course');
@ -381,7 +381,6 @@ if ($hassiteconfig) {
get_string('cfg_help', 'local_treestudyplan', null, true),
$CFG->wwwroot . '/local/treestudyplan/doc.php/index.htm'));
/**************************************
*
* Settings page: Premium registration
@ -418,7 +417,6 @@ if ($hassiteconfig) {
));
}
// Add settings page2 to the admin settings category.
$ADMIN->add('local_treestudyplan', $pagepremium);
}

View File

@ -74,7 +74,7 @@ $tests = [
["*/*", "https://www.miqra.nl"],
["*", "https://clients.openedu.nl/fith"],
["clients.openedu.nl/fith", "https://clients.openedu.nl/fith/"],
["clients.openedu.nl/fith/", "https://clients.openedu.nl/fith"]
["clients.openedu.nl/fith/", "https://clients.openedu.nl/fith"],
];
foreach($tests as $test) {

View File

@ -29,7 +29,7 @@ require_once($CFG->libdir.'/weblib.php');
$systemcontext = context_system::instance();
$PAGE->set_url("/local/treestudyplan/view-plan.php", array());
$PAGE->set_url("/local/treestudyplan/view-plan.php", []);
require_login();
// Figure out the context (category or system, based on either category or context parameter).
@ -64,9 +64,6 @@ if ($categoryid > 0) {
$ci = new contextinfo($studyplancontext);
$contextname = $ci->pathstr();
$PAGE->set_pagelayout('base');
//$PAGE->set_context($studyplancontext);
$PAGE->set_title(get_string('view_plan', 'local_treestudyplan')." - ".$contextname);