Checked all phpdoc @return types and fixed some other type errors (added some checks for edge cases)
This commit is contained in:
parent
a0b120df1b
commit
3bc3a1dbec
30 changed files with 184 additions and 154 deletions
|
@ -93,7 +93,7 @@ class completionscanner {
|
|||
* @param completion_criteria $crit Criteria to check for
|
||||
* @param stdClass $course Course DB record
|
||||
*/
|
||||
public function __construct(completion_criteria $crit, $course) {
|
||||
public function __construct($crit, $course) {
|
||||
$this->courseid = $course->id;
|
||||
$this->course = $course;
|
||||
$this->modinfo = get_fast_modinfo($course);
|
||||
|
|
|
@ -324,6 +324,7 @@ class coursecompetencyinfo {
|
|||
$competencies = $this->course_competencies();
|
||||
$progress = 0;
|
||||
|
||||
|
||||
$cis = [];
|
||||
foreach ($competencies as $c) {
|
||||
$ci = $this->competencyinfo_model($c, $userid);
|
||||
|
@ -376,6 +377,7 @@ class coursecompetencyinfo {
|
|||
$dcount = 0;
|
||||
$dprogress = 0;
|
||||
$children = [];
|
||||
$points = 0;
|
||||
foreach ($dids as $did) {
|
||||
$cc = new competency($did);
|
||||
$cci = $this->competencyinfo_model($cc, $userid);
|
||||
|
@ -528,7 +530,7 @@ class coursecompetencyinfo {
|
|||
* @param \core_competency\competency $competency
|
||||
* @param int $userid
|
||||
*
|
||||
* @return stdClass
|
||||
* @return object
|
||||
*
|
||||
*/
|
||||
public function proficiency($competency, $userid) {
|
||||
|
@ -559,7 +561,7 @@ class coursecompetencyinfo {
|
|||
* @param \core_competency\competency $competency
|
||||
* @param int $userid
|
||||
*
|
||||
* @return stdClass
|
||||
* @return string
|
||||
*
|
||||
*/
|
||||
public function retrievefeedback($competency, $userid) {
|
||||
|
@ -576,7 +578,7 @@ class coursecompetencyinfo {
|
|||
break;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -639,7 +641,7 @@ class coursecompetencyinfo {
|
|||
return boolval($conditions["competencies"][$competency->get("id")]["required"]);
|
||||
}
|
||||
}
|
||||
return(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ class courseinfo {
|
|||
|
||||
/**
|
||||
* Check if current user is teacher in this course
|
||||
* @return book
|
||||
* @return bool
|
||||
*/
|
||||
protected function am_teacher(): bool {
|
||||
global $USER;
|
||||
|
@ -216,12 +216,12 @@ class courseinfo {
|
|||
public function displayname() {
|
||||
$displayfield = get_config("local_treestudyplan", "display_field");
|
||||
if ($displayfield == "idnumber") {
|
||||
$idnumber = trim(preg_replace("/\s+/u", " ", $this->course->idnumber));
|
||||
$idnumber = trim((string)(preg_replace("/\s+/u", " ", $this->course->idnumber)));
|
||||
if (strlen($idnumber) > 0) {
|
||||
return $this->course->idnumber;
|
||||
}
|
||||
} else if ($displayfield == "fullname") {
|
||||
$fullname = trim(preg_replace("/\s+/u", " ", $this->course->fullname));
|
||||
$fullname = trim((string)(preg_replace("/\s+/u", " ", $this->course->fullname)));
|
||||
if (strlen($fullname) > 0) {
|
||||
return $fullname;
|
||||
}
|
||||
|
@ -232,7 +232,7 @@ class courseinfo {
|
|||
$datas = $handler->get_instance_data($this->course->id);
|
||||
foreach ($datas as $data) {
|
||||
if ($data->get_field()->get('shortname') == $fieldname) {
|
||||
$value = trim(preg_replace("/\s+/u", " ", $data->get_value()));
|
||||
$value = trim((string)(preg_replace("/\s+/u", " ", $data->get_value())));
|
||||
if (strlen($value) > 0) {
|
||||
return $value;
|
||||
}
|
||||
|
@ -577,7 +577,7 @@ class courseinfo {
|
|||
);
|
||||
return [$value, "textarea", $this->course()->summary];
|
||||
} else if ($fieldname == "idnumber") {
|
||||
$idnumber = trim(preg_replace("/\s+/u", " ", $this->course->idnumber));
|
||||
$idnumber = trim((string)(preg_replace("/\s+/u", " ", $this->course->idnumber)));
|
||||
return [$idnumber, "text", $this->course->idnumber];
|
||||
} else if ($fieldname == "contacts") {
|
||||
$cle = new \core_course_list_element($this->course());
|
||||
|
|
|
@ -117,7 +117,7 @@ class courseservice extends \external_api {
|
|||
if (count($intersect) == 0) {
|
||||
// Double check permissions according to the moodle capability system.
|
||||
$ctx = \context::instance_by_id($r->id);
|
||||
if (has_capability($capability, $ctx, $userid)) {
|
||||
if (is_object($ctx) && has_capability($capability, $ctx, $userid)) {
|
||||
// Get the category, and double check if the category is visible to the current user.
|
||||
// Just in case it is a hidden category and the user does not have the viewhidden permission.
|
||||
$cat = \core_course_category::get($r->instanceid, \IGNORE_MISSING, false, $userid);
|
||||
|
@ -184,7 +184,7 @@ class courseservice extends \external_api {
|
|||
if (count($intersect) == 0) {
|
||||
// Double check permissions according to the moodle capability system.
|
||||
$ctx = \context::instance_by_id($r->id);
|
||||
if (has_capability($capability, $ctx, $userid)) {
|
||||
if (is_object($ctx) && has_capability($capability, $ctx, $userid)) {
|
||||
// Get the category, and double check if the category is visible to the current user.
|
||||
// Just in case it is a hidden category and the user does not have the viewhidden permission.
|
||||
$cat = \core_course_category::get($r->instanceid, \IGNORE_MISSING, false, $userid);
|
||||
|
@ -265,7 +265,7 @@ class courseservice extends \external_api {
|
|||
$children = self::user_tops();
|
||||
} else if ($context->contextlevel == \CONTEXT_COURSECAT) {
|
||||
$cat = \core_course_category::get($context->instanceid, \MUST_EXIST, true);
|
||||
if ($cat->is_uservisible()) {
|
||||
if (is_object($cat) && $cat->is_uservisible()) {
|
||||
$children = [$cat];
|
||||
} else {
|
||||
$ci = new contextinfo($context);
|
||||
|
@ -309,10 +309,13 @@ class courseservice extends \external_api {
|
|||
/**
|
||||
* Get category info by id
|
||||
* @param mixed $id
|
||||
* @return array
|
||||
* @return \core_course_category
|
||||
*/
|
||||
public static function get_category($id) {
|
||||
$cat = \core_course_category::get($id);
|
||||
if (!is_object($cat)) {
|
||||
throw new moodle_exception("unknownerror");
|
||||
}
|
||||
return static::map_category($cat);
|
||||
}
|
||||
|
||||
|
@ -439,7 +442,7 @@ class courseservice extends \external_api {
|
|||
$contextcounts[$r->context_id] = $r->num;
|
||||
// Add any of the categories containing studyplans to the list.
|
||||
$ctx = \context::instance_by_id($r->context_id);
|
||||
if (has_capability($capability, $ctx) && !in_array($r->context_id, $contextids)) {
|
||||
if (is_object($ctx) && has_capability($capability, $ctx) && !in_array($r->context_id, $contextids)) {
|
||||
$insertctxs[] = $ctx;
|
||||
}
|
||||
}
|
||||
|
@ -454,7 +457,7 @@ class courseservice extends \external_api {
|
|||
// Get the context.
|
||||
$refctx = \context::instance_by_id($refctxid);
|
||||
// Double check permissions.
|
||||
if (has_capability($capability, $refctx)) {
|
||||
if (is_object($refctx) && has_capability($capability, $refctx)) {
|
||||
$insertctxs[] = $refctx;
|
||||
}
|
||||
} catch (\dml_missing_record_exception $x) {
|
||||
|
@ -489,19 +492,24 @@ class courseservice extends \external_api {
|
|||
foreach ($contextids as $ctxid) {
|
||||
try {
|
||||
$ctx = \context::instance_by_id($ctxid);
|
||||
if ($ctx->contextlevel == CONTEXT_SYSTEM) {
|
||||
if (is_object($ctx) && $ctx->contextlevel == CONTEXT_SYSTEM) {
|
||||
$cat = \core_course_category::top();
|
||||
} else if ($ctx->contextlevel == CONTEXT_COURSECAT) {
|
||||
} else if (is_object($ctx) && $ctx->contextlevel == CONTEXT_COURSECAT) {
|
||||
$cat = \core_course_category::get($ctx->instanceid, \MUST_EXIST, false);
|
||||
} else {
|
||||
$cat = null;
|
||||
}
|
||||
$cats[] = $cat;
|
||||
// In edit mode, also include direct children of the currently selected context.
|
||||
if ($operation == "edit" && $ctxid == $refctxid) {
|
||||
// Include direct children for navigation purposes.
|
||||
foreach ($cat->get_children() as $ccat) {
|
||||
$ccatctx = \context_coursecat::instance($ccat->id);
|
||||
if (!in_array($ccatctx->id, $contextids)) {
|
||||
$cats[] = $ccat;
|
||||
|
||||
if ($cat != null) {
|
||||
$cats[] = $cat;
|
||||
// In edit mode, also include direct children of the currently selected context.
|
||||
if ($operation == "edit" && $ctxid == $refctxid) {
|
||||
// Include direct children for navigation purposes.
|
||||
foreach ($cat->get_children() as $ccat) {
|
||||
$ccatctx = \context_coursecat::instance($ccat->id);
|
||||
if (!in_array($ccatctx->id, $contextids)) {
|
||||
$cats[] = $ccat;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -566,6 +574,10 @@ class courseservice extends \external_api {
|
|||
// Retrieve grade item.
|
||||
$gi = \grade_item::fetch(["id" => $gradeitemid]);
|
||||
|
||||
if (!is_object($gi)) {
|
||||
throw new moodle_exception("unknownerror");
|
||||
}
|
||||
|
||||
// Validate course is linked to studyplan.
|
||||
$courseid = $gi->courseid;
|
||||
if (!$o->course_linked($courseid)) {
|
||||
|
|
|
@ -60,7 +60,7 @@ abstract class formbase extends \moodleform {
|
|||
* Also validate parameters and access permissions here
|
||||
*
|
||||
* @param object $customdata The form customdata built on form initialization in self::init_customdata(...)
|
||||
* @return array Form data based on parameters
|
||||
* @return object Form data based on parameters
|
||||
*/
|
||||
abstract public function init_formdata(object $customdata);
|
||||
|
||||
|
@ -79,14 +79,14 @@ abstract class formbase extends \moodleform {
|
|||
/**
|
||||
* Process the submission and perform necessary actions
|
||||
* @param object $entry The processed form data
|
||||
* @return object|array Data to pass to receiver if submission successful
|
||||
* @return mixed Data to pass to receiver if submission successful
|
||||
* @throws \moodle_exception if an error must be given for a specific reason.
|
||||
*/
|
||||
abstract protected function process_submitted_data(object $entry);
|
||||
|
||||
/**
|
||||
* Process the submission and perform necessary actions
|
||||
* @return object|array Data to pass to receiver if submission successful
|
||||
* @return mixed Data to pass to receiver if submission successful
|
||||
* @throws \moodle_exception if an error must be given for a specific reason.
|
||||
*/
|
||||
public function process_submission() {
|
||||
|
|
|
@ -50,7 +50,7 @@ class studyplan_editform extends formbase {
|
|||
* Translate parameters into customdata.
|
||||
*
|
||||
* @param object $params The parameters for form initialization
|
||||
* @return stdClass Form data based on parameters
|
||||
* @return object Form data based on parameters
|
||||
*/
|
||||
public static function init_customdata(object $params) {
|
||||
$customdata = new stdClass;
|
||||
|
@ -58,7 +58,6 @@ class studyplan_editform extends formbase {
|
|||
if ($customdata->create) {
|
||||
$customdata->context = \context::instance_by_id($params->contextid);
|
||||
} else {
|
||||
|
||||
$customdata->plan = studyplan::find_by_id($params->studyplan_id);
|
||||
$customdata->context = $customdata->plan->context();
|
||||
$customdata->simplemodel = $customdata->plan->simple_model();
|
||||
|
@ -314,7 +313,7 @@ class studyplan_editform extends formbase {
|
|||
/**
|
||||
* Process the submitted data and perform necessary actions
|
||||
* @param object $entry The processed form data;
|
||||
* @return bool false if submission not successful
|
||||
* @return mixed Data to pass to receiver if submission successful
|
||||
* @throws \moodle_exception if an error must be given for a specific reason.
|
||||
*/
|
||||
protected function process_submitted_data($entry) {
|
||||
|
|
|
@ -48,7 +48,7 @@ class studyplan_fromtemplateform extends formbase {
|
|||
* Translate parameters into customdata.
|
||||
*
|
||||
* @param object $params The parameters for form initialization
|
||||
* @return array Form data based on parameters
|
||||
* @return object Form data based on parameters
|
||||
*/
|
||||
public static function init_customdata(object $params) {
|
||||
$customdata = new stdClass;
|
||||
|
@ -62,7 +62,7 @@ class studyplan_fromtemplateform extends formbase {
|
|||
* Also validate parameters and access permissions here
|
||||
*
|
||||
* @param object $customdata The parameters for form initialization
|
||||
* @return array Form data based on parameters
|
||||
* @return object Form data based on parameters
|
||||
*/
|
||||
public function init_formdata(object $customdata) {
|
||||
global $DB;
|
||||
|
@ -166,7 +166,7 @@ class studyplan_fromtemplateform extends formbase {
|
|||
/**
|
||||
* Process the submitted data and perform necessary actions
|
||||
* @param object $entry The processed form data;
|
||||
* @return bool false if submission not successful
|
||||
* @return mixed Data to pass to receiver if submission successful
|
||||
* @throws \moodle_exception if an error must be given for a specific reason.
|
||||
*/
|
||||
protected function process_submitted_data($entry) {
|
||||
|
|
|
@ -47,7 +47,7 @@ class studyplanpage_editform extends formbase {
|
|||
* Translate parameters into customdata.
|
||||
*
|
||||
* @param object $params The parameters for form initialization
|
||||
* @return array Form data based on parameters
|
||||
* @return object Form data based on parameters
|
||||
*/
|
||||
public static function init_customdata(object $params) {
|
||||
$customdata = new stdClass;
|
||||
|
@ -84,7 +84,7 @@ class studyplanpage_editform extends formbase {
|
|||
* Also validate parameters and access permissions here
|
||||
*
|
||||
* @param object $customdata The parameters for form initialization
|
||||
* @return array Form data based on parameters
|
||||
* @return object Form data based on parameters
|
||||
*/
|
||||
public function init_formdata(object $customdata) {
|
||||
global $DB;
|
||||
|
@ -199,7 +199,7 @@ class studyplanpage_editform extends formbase {
|
|||
/**
|
||||
* Process the submitted data and perform necessary actions
|
||||
* @param object $entry The processed form data;
|
||||
* @return bool false if submission not successful
|
||||
* @return mixed Data to pass to receiver if submission successful
|
||||
* @throws \moodle_exception if an error must be given for a specific reason.
|
||||
*/
|
||||
protected function process_submitted_data($entry) {
|
||||
|
|
|
@ -39,7 +39,6 @@ class text_integer extends MoodleQuickForm_text {
|
|||
* @param object $renderer An HTML_QuickForm_Renderer object
|
||||
* @param bool $required Whether an element is required
|
||||
* @param string $error An error message associated with an element
|
||||
* @return void
|
||||
*/
|
||||
public function accept(&$renderer, $required = false, $error = null) {
|
||||
global $OUTPUT;
|
||||
|
|
|
@ -153,7 +153,7 @@ class gradeinfo {
|
|||
*/
|
||||
public static function get_coursecontext_by_id($id): \context_course {
|
||||
$gi = grade_item::fetch(["id" => $id]);
|
||||
if (!$gi || course_module_instance_pending_deletion($gi->courseid, $gi->itemmodule, $gi->iteminstance)) {
|
||||
if (!is_object($gi) || course_module_instance_pending_deletion($gi->courseid, $gi->itemmodule, $gi->iteminstance)) {
|
||||
throw new \InvalidArgumentException ("Grade {$id} not found in database");
|
||||
}
|
||||
return \context_course::instance($gi->courseid);;
|
||||
|
@ -169,7 +169,7 @@ class gradeinfo {
|
|||
$this->studyitem = $studyitem;
|
||||
|
||||
$gi = grade_item::fetch(["id" => $id]);
|
||||
if (!$gi || course_module_instance_pending_deletion($gi->courseid, $gi->itemmodule, $gi->iteminstance)) {
|
||||
if (!is_object($gi) || course_module_instance_pending_deletion($gi->courseid, $gi->itemmodule, $gi->iteminstance)) {
|
||||
throw new \InvalidArgumentException ("Grade {$id} not found in database");
|
||||
}
|
||||
$this->id = $id;
|
||||
|
@ -248,10 +248,10 @@ class gradeinfo {
|
|||
$r = $DB->get_record('local_treestudyplan_gradeinc',
|
||||
['studyitem_id' => $this->studyitem->id(), 'grade_item_id' => $this->gradeitem->id]);
|
||||
if ($r && $r->include && $r->required) {
|
||||
return(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -339,7 +339,7 @@ class gradeinfo {
|
|||
*/
|
||||
public function user_model($userid) {
|
||||
global $DB;
|
||||
$grade = $this->gradeitem->get_final($userid);
|
||||
$grade = (object)$this->gradeitem->get_final($userid);
|
||||
// Format grade for proper display.
|
||||
if (is_object($grade)) {
|
||||
$finalgrade = \grade_format_gradevalue($grade->finalgrade, $this->gradeitem, true, null, 1);
|
||||
|
|
|
@ -148,7 +148,7 @@ class gradingscanner {
|
|||
// First check if the completion needs grading.
|
||||
$ungraded++;
|
||||
} else {
|
||||
$grade = $this->gi->get_final($userid);
|
||||
$grade = (object)($this->gi->get_final($userid));
|
||||
if ((!empty($grade->finalgrade)) && is_numeric($grade->finalgrade)) {
|
||||
// Compare grade to minimum grade.
|
||||
if ($this->grade_passed($grade)) {
|
||||
|
|
|
@ -326,7 +326,7 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
|
|||
$course = \get_course($gradeitem->courseid); // Fetch course from cache.
|
||||
$coursefinished = ($course->enddate) ? ($course->enddate < time()) : false;
|
||||
|
||||
if (empty($grade)) {
|
||||
if (!is_object($grade) || empty($grade)) {
|
||||
return completion::INCOMPLETE;
|
||||
} else if ($grade->finalgrade === null) {
|
||||
// On assignments, grade NULL means a submission has not yet been graded, .
|
||||
|
@ -341,7 +341,6 @@ class bistate_aggregator extends \local_treestudyplan\aggregator {
|
|||
return completion::INCOMPLETE;
|
||||
}
|
||||
} else {
|
||||
$grade = $gradeitem->get_final($userid);
|
||||
// First determine if we have a grade_config for this scale or this maximum grade.
|
||||
$finalgrade = $grade->finalgrade;
|
||||
$scale = $gradeinfo->get_scale();
|
||||
|
|
|
@ -289,6 +289,7 @@ class competency_aggregator extends \local_treestudyplan\aggregator {
|
|||
*/
|
||||
public function grade_completion(gradeinfo $gradeinfo, $userid) {
|
||||
// COURSE COMPETENCIES DOESN'T REALLY USE THIS FUNCTION.
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -216,6 +216,7 @@ class core_aggregator extends \local_treestudyplan\aggregator {
|
|||
*/
|
||||
public function grade_completion(gradeinfo $gradeinfo, $userid) {
|
||||
// CORE COMPLETION DOESN'T REALLY USE THIS FUNCTION.
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -114,7 +114,7 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
|
|||
}
|
||||
} else {
|
||||
// Indeterminable.
|
||||
return null;
|
||||
return completion::INCOMPLETE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,7 +167,7 @@ class tristate_aggregator extends \local_treestudyplan\aggregator {
|
|||
$gradeitem = $gradeinfo->get_gradeitem();
|
||||
$grade = $gradeitem->get_final($userid);
|
||||
|
||||
if (empty($grade)) {
|
||||
if (!is_object($grade) || empty($grade)) {
|
||||
return completion::INCOMPLETE;
|
||||
} else if ($grade->finalgrade === null) {
|
||||
// On assignments, grade NULL means a submission has not yet been graded, .
|
||||
|
|
|
@ -214,7 +214,7 @@ class gradegenerator {
|
|||
* @param string $student Student identifier
|
||||
* @param string $skill Skill identifier
|
||||
* @param gradeinfo[] $gradeinfos
|
||||
* @return stdClass[] List of gradeinfo related results ready to add
|
||||
* @return array List of gradeinfo related results ready to add
|
||||
*/
|
||||
public function generate(string $student, string $skill, array $gradeinfos ) {
|
||||
global $DB;
|
||||
|
@ -330,9 +330,12 @@ class gradegenerator {
|
|||
* Store skills table into a string
|
||||
* @return string|null Json encoded string of the skills table
|
||||
*/
|
||||
public function serialize(): ?string {
|
||||
return json_encode([
|
||||
"table" => $this->table], JSON_PRETTY_PRINT);
|
||||
public function serialize(): string {
|
||||
$s = json_encode(["table" => $this->table], JSON_PRETTY_PRINT);
|
||||
if (!is_string($s)) {
|
||||
return "";
|
||||
}
|
||||
return $s;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -44,7 +44,7 @@ class webservicehelper {
|
|||
* @param array|string $capability One or more capabilities to be tested OR wise
|
||||
* @param \context $context The context in which to check for the capability.
|
||||
* @throws \webservice_access_exception If none of the capabilities provided are given to the current user
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public static function has_capabilities($capability, $context) {
|
||||
|
||||
|
@ -55,7 +55,7 @@ class webservicehelper {
|
|||
if (is_array($capability)) {
|
||||
return \has_any_capability($capability, $context);
|
||||
} else {
|
||||
return has_capability($capability, $context);
|
||||
return \has_capability($capability, $context);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ class webservicehelper {
|
|||
* Test if the current user has a certain capability in any of the categories they have access to
|
||||
* @param string $capability The capability to scan for in the categories
|
||||
* @param int|null $userid Userid to use in check (Use current user if null or empty)
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public static function has_capability_in_any_category($capability, $userid=null ) {
|
||||
global $USER;
|
||||
|
|
|
@ -74,7 +74,6 @@ class randomimage {
|
|||
* Create a random polygon with number of points between 0 & $maxpts
|
||||
* @param \GdImage $im The image reource
|
||||
* @param int $maxpts Max number of point to use
|
||||
* @return void
|
||||
*/
|
||||
private function random_polygon($im, int $maxpts = 20) {
|
||||
$color = imagecolorallocatealpha($im, ...$this->random_color_alpha());
|
||||
|
@ -86,7 +85,6 @@ class randomimage {
|
|||
/**
|
||||
* Creates a random arc of a random color
|
||||
* @param \GdImage $im The image resource
|
||||
* @return void
|
||||
*/
|
||||
private function random_arc($im) {
|
||||
$cx = \random_int(0, $this->width);
|
||||
|
@ -102,7 +100,7 @@ class randomimage {
|
|||
|
||||
/**
|
||||
* Generates an array of random alpha color values.
|
||||
* @return Array [r, g, b, a]
|
||||
* @return array [r, g, b, a]
|
||||
*/
|
||||
private function random_color_alpha(): Array {
|
||||
return [
|
||||
|
@ -116,7 +114,7 @@ class randomimage {
|
|||
/**
|
||||
* Generates a set of random points for a polygon [x1, y1, x2, y2, ...]
|
||||
* @param integer $length Number of sets of points to generate
|
||||
* @return Array The resulting array of points
|
||||
* @return array The resulting array of points
|
||||
*/
|
||||
private function random_pts($length): Array {
|
||||
$pts = [];
|
||||
|
@ -159,8 +157,12 @@ class randomimage {
|
|||
}
|
||||
}
|
||||
$this->tempfile = \tempnam("/tmp", "tsp");
|
||||
imagepng($im, $this->tempfile);
|
||||
imagedestroy($im);
|
||||
if (is_object($im)) {
|
||||
imagepng($im, $this->tempfile);
|
||||
}
|
||||
if (is_object($im)) {
|
||||
imagedestroy($im);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -168,7 +170,12 @@ class randomimage {
|
|||
* @return string
|
||||
*/
|
||||
public function content() {
|
||||
return $this->content = \file_get_contents($this->tempfile);
|
||||
$this->content = \file_get_contents($this->tempfile);
|
||||
if (is_string($this->content)) {
|
||||
return $this->content;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,6 +32,7 @@ require_once($CFG->dirroot.'/question/engine/states.php'); // For reading questi
|
|||
class quiz_scanner extends scanner_base {
|
||||
/**
|
||||
* Retrieve the ungraded submissions in this activity
|
||||
* @return array
|
||||
*/
|
||||
protected function get_ungraded_submissions() {
|
||||
// Count all users who have one or more questions that still need grading.
|
||||
|
|
|
@ -93,7 +93,7 @@ class period {
|
|||
// Or specified duration of the page and the sequence of the periods .
|
||||
$pcount = $page->periods();
|
||||
$ystart = $page->startdate()->getTimestamp();
|
||||
$yend = $page->enddate()->getTimestamp();
|
||||
$yend = ((object)($page->enddate(true)))->getTimestamp();
|
||||
|
||||
// Estimate the period's timing to make a reasonable first guess.
|
||||
$ydelta = $yend - $ystart;
|
||||
|
|
|
@ -148,8 +148,10 @@ class provider implements \core_privacy\local\metadata\provider,
|
|||
$context = \context_system::instance();
|
||||
$subcontext = ["invitations"];
|
||||
|
||||
writer::with_context($context)
|
||||
->export_data($subcontext, (object)["recipient" => $invit->name, "email" => $invit->email]);
|
||||
$data = new \stdClass;
|
||||
$data->recipient = $invit->name;
|
||||
$data->email = $invit->email;
|
||||
writer::with_context($context)->export_data($subcontext, $data);
|
||||
|
||||
}
|
||||
|
||||
|
@ -161,8 +163,10 @@ class provider implements \core_privacy\local\metadata\provider,
|
|||
$context = \context_system::instance();
|
||||
$subcontext = ["studyplans"];
|
||||
|
||||
writer::with_context($context)
|
||||
->export_data($subcontext, (object)["fullname" => $studyplan->fullname, "shortname" => $studyplan->shortname]);
|
||||
$data = new \stdClass;
|
||||
$data->fullname = $studyplan->fullname;
|
||||
$data->shortname = $studyplan->shortname;
|
||||
writer::with_context($context)->export_data($subcontext, $data);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ class reportinvite_form extends moodleform {
|
|||
|
||||
/**
|
||||
* Get supplied user data
|
||||
* @return stdClass The supplied data
|
||||
* @return object The supplied data
|
||||
*/
|
||||
public function get_data() {
|
||||
global $DB, $USER;
|
||||
|
|
|
@ -76,7 +76,7 @@ class reportservice extends \external_api {
|
|||
* @param int $pageid ID of user to check specific info for
|
||||
* @param int|null $firstperiod First period to include in report
|
||||
* @param int|null $lastperiod Last period to include in report
|
||||
* @return object
|
||||
* @return array
|
||||
*/
|
||||
public static function get_report_structure($pageid, $firstperiod=null, $lastperiod=null) {
|
||||
$page = studyplanpage::find_by_id($pageid);
|
||||
|
|
|
@ -114,7 +114,7 @@ class studentstudyplanservice extends \external_api {
|
|||
* Get a specific studyplan for a given user
|
||||
* @param int $userid ID of user to check specific info for
|
||||
* @param int $studyplanid ID of studyplan to view
|
||||
* @return array
|
||||
* @return array|null
|
||||
*/
|
||||
public static function get_user_studyplan($userid, $studyplanid) {
|
||||
global $CFG, $DB;
|
||||
|
@ -162,7 +162,7 @@ class studentstudyplanservice extends \external_api {
|
|||
* Get a specific studyplan page for a given user
|
||||
* @param int $userid ID of user to check specific info for
|
||||
* @param int $pageid ID of studyplan to view
|
||||
* @return array
|
||||
* @return array|null
|
||||
*/
|
||||
public static function get_user_page($userid, $pageid) {
|
||||
global $CFG, $DB;
|
||||
|
|
|
@ -657,7 +657,7 @@ class studyline {
|
|||
/**
|
||||
* List the course id is linked in this studyplan
|
||||
* Used for cohort enrolment cascading
|
||||
* @return int[]
|
||||
* @return array
|
||||
*/
|
||||
public function get_linked_course_ids(): array {
|
||||
global $DB;
|
||||
|
@ -845,7 +845,6 @@ class studyline {
|
|||
* @param array $model Decoded array
|
||||
* @param array $itemtranslation Link to array to map old item ids to new item ids for connection matching
|
||||
* @param array $connections Link to array of connections between item
|
||||
* @return null
|
||||
*/
|
||||
public function import_studyitems(array $model, array &$itemtranslation, array &$connections) {
|
||||
global $DB;
|
||||
|
|
|
@ -167,37 +167,40 @@ class studyplan {
|
|||
|
||||
if (count($files) > 0) {
|
||||
$file = array_shift($files);
|
||||
if ($file->get_filename() == ".") {
|
||||
|
||||
if (is_object($file) && $file->get_filename() == ".") {
|
||||
// Get next file if the first is the directory itself.
|
||||
$file = array_shift($files);
|
||||
}
|
||||
|
||||
$url = \moodle_url::make_pluginfile_url(
|
||||
$file->get_contextid(),
|
||||
$file->get_component(),
|
||||
$file->get_filearea(),
|
||||
$file->get_itemid(),
|
||||
$file->get_filepath(),
|
||||
$file->get_filename(),
|
||||
false // Do not force download of the file.
|
||||
);
|
||||
} else {
|
||||
// Try the configured default in settings.
|
||||
$defaulticon = get_config('local_treestudyplan', 'defaulticon');
|
||||
if (empty($defaulticon)) {
|
||||
// Fall back to the standard (ugly) default image.
|
||||
$url = new \moodle_url($CFG->wwwroot . "/local/treestudyplan/pix/default_icon.png");
|
||||
} else {
|
||||
if (is_object($file)) {
|
||||
$url = \moodle_url::make_pluginfile_url(
|
||||
\context_system::instance()->id,
|
||||
'local_treestudyplan',
|
||||
'defaulticon',
|
||||
0,
|
||||
"/",
|
||||
$defaulticon
|
||||
);
|
||||
$file->get_contextid(),
|
||||
$file->get_component(),
|
||||
$file->get_filearea(),
|
||||
$file->get_itemid(),
|
||||
$file->get_filepath(),
|
||||
$file->get_filename(),
|
||||
false // Do not force download of the file.
|
||||
);
|
||||
return $url->out;
|
||||
}
|
||||
}
|
||||
|
||||
// Try the configured default in settings.
|
||||
$defaulticon = get_config('local_treestudyplan', 'defaulticon');
|
||||
if (empty($defaulticon)) {
|
||||
// Fall back to the standard (ugly) default image.
|
||||
$url = new \moodle_url($CFG->wwwroot . "/local/treestudyplan/pix/default_icon.png");
|
||||
} else {
|
||||
$url = \moodle_url::make_pluginfile_url(
|
||||
\context_system::instance()->id,
|
||||
'local_treestudyplan',
|
||||
'defaulticon',
|
||||
0,
|
||||
"/",
|
||||
$defaulticon
|
||||
);
|
||||
}
|
||||
return $url->out();
|
||||
}
|
||||
|
@ -735,7 +738,7 @@ class studyplan {
|
|||
|
||||
/**
|
||||
* Retrieve the users linked to this studyplan.
|
||||
* @return stdClass[] User objects
|
||||
* @return \stdClass[] User objects
|
||||
*/
|
||||
public function find_linked_users(): array {
|
||||
global $DB;
|
||||
|
@ -787,7 +790,7 @@ class studyplan {
|
|||
|
||||
/**
|
||||
* Check if this studyplan is linked to a particular user
|
||||
* @param bool|stdClass $user The userid or user record of the user
|
||||
* @param int|stdClass $user The userid or user record of the user
|
||||
*/
|
||||
public function has_linked_user($user) {
|
||||
if (is_int($user)) {
|
||||
|
@ -805,7 +808,7 @@ class studyplan {
|
|||
|
||||
/**
|
||||
* Check if this studyplan is linked to a particular user
|
||||
* @param bool|stdClass|null $user The userid or user record of the user Leave empty to check current user.
|
||||
* @param int|stdClass|null $user The userid or user record of the user Leave empty to check current user.
|
||||
*/
|
||||
public function is_coach($user=null) {
|
||||
global $DB, $USER;
|
||||
|
@ -968,9 +971,9 @@ class studyplan {
|
|||
|
||||
// Next, copy the studylines.
|
||||
$timeless = \get_config("local_treestudyplan", "timelessperiods");
|
||||
if (!$timeless && $newstartdate) {
|
||||
$oldstart = $this->startdate();
|
||||
if (!$timeless && $newstartdate && is_object($oldstart)) {
|
||||
$newstart = new \DateTime(date("Y-m-d", $newstartdate));
|
||||
$oldstart = $this->startdate();
|
||||
$timeoffset = $oldstart->diff($newstart);
|
||||
} else {
|
||||
$timeoffset = new \DateInterval("P0D");
|
||||
|
|
|
@ -509,7 +509,7 @@ class studyplanpage {
|
|||
'description' => $this->r->description,
|
||||
'pages' => $this->r->pages,
|
||||
'startdate' => $this->startdate()->add($timeoffset)->format("Y-m-d"),
|
||||
'enddate' => empty($this->r->enddate) ? null : ($this->enddate()->add($timeoffset)->format("Y-m-d")),
|
||||
'enddate' => empty($this->r->enddate) ? null : (((object)$this->enddate(true))->add($timeoffset)->format("Y-m-d")),
|
||||
]);
|
||||
|
||||
// Copy any files related to this page.
|
||||
|
|
|
@ -122,7 +122,7 @@ class studyplanservice extends \external_api {
|
|||
/**
|
||||
* Get editor model for specific studyplan
|
||||
* @param int $id Id of studyplan
|
||||
* @return array
|
||||
* @return array|null
|
||||
*/
|
||||
public static function get_studyplan_map($id) {
|
||||
if (isset($id) && $id > 0) {
|
||||
|
@ -1224,64 +1224,66 @@ class studyplanservice extends \external_api {
|
|||
$studyitem = new studyitem($itemr->id);
|
||||
if ($studyitem->valid() && $studyitem->type() == studyitem::COURSE) {
|
||||
$courseinfo = $studyitem->getcourseinfo();
|
||||
$gradables = gradeinfo::list_studyitem_gradables($studyitem);
|
||||
if(is_object($courseinfo)){
|
||||
$gradables = gradeinfo::list_studyitem_gradables($studyitem);
|
||||
|
||||
$gradelist = [];
|
||||
foreach ($gradables as $g) {
|
||||
$gi = $g->get_gradeitem();
|
||||
$gradelist = [];
|
||||
foreach ($gradables as $g) {
|
||||
$gi = $g->get_gradeitem();
|
||||
|
||||
// Only change items that do not yet have grades.
|
||||
// Otherwise we will need to implement grade recalculations and it is not worth the trouble. .
|
||||
// If grades are given, you likely don't want to change it like this anyway.
|
||||
// Only change items that do not yet have grades.
|
||||
// Otherwise we will need to implement grade recalculations and it is not worth the trouble. .
|
||||
// If grades are given, you likely don't want to change it like this anyway.
|
||||
|
||||
if (!$gi->has_grades()) {
|
||||
$gi->gradetype = GRADE_TYPE_SCALE;
|
||||
$gi->scaleid = $scale->id;
|
||||
$gi->grademin = 1;
|
||||
$gi->grademax = $scalemax;
|
||||
$gi->gradepass = $scalepass;
|
||||
if (!$gi->has_grades()) {
|
||||
$gi->gradetype = GRADE_TYPE_SCALE;
|
||||
$gi->scaleid = $scale->id;
|
||||
$gi->grademin = 1;
|
||||
$gi->grademax = $scalemax;
|
||||
$gi->gradepass = $scalepass;
|
||||
|
||||
// Update, signalling with our signature and bulkupdate.
|
||||
$result = $gi->update("local/treestudyplan");
|
||||
// Update, signalling with our signature and bulkupdate.
|
||||
$result = $gi->update("local/treestudyplan");
|
||||
|
||||
$debug = "";
|
||||
if ($result) {
|
||||
$updated = "converted";
|
||||
} else {
|
||||
$updated = "error";
|
||||
}
|
||||
$debug = "";
|
||||
if ($result) {
|
||||
$updated = "converted";
|
||||
} else {
|
||||
$updated = "error";
|
||||
}
|
||||
|
||||
// Next update the activity's table if it has a grade field.
|
||||
// Grade is generally set to the negative scale id if it is a scale.
|
||||
$tablename = $gi->itemmodule;
|
||||
$fieldname = "grade";
|
||||
if ($result && $gi->itemtype == "mod" && $dbman->table_exists($tablename)) {
|
||||
if ($dbman->field_exists($tablename, $fieldname)) {
|
||||
$gradevalue = intval(0 - ($scale->id));
|
||||
try {
|
||||
$DB->set_field($tablename, $fieldname, $gradevalue, ["id" => $gi->iteminstance]);
|
||||
} catch (\dml_exception $x) {
|
||||
$updated = "fail";
|
||||
$debug = strval($x);
|
||||
// Next update the activity's table if it has a grade field.
|
||||
// Grade is generally set to the negative scale id if it is a scale.
|
||||
$tablename = $gi->itemmodule;
|
||||
$fieldname = "grade";
|
||||
if ($result && $gi->itemtype == "mod" && $dbman->table_exists($tablename)) {
|
||||
if ($dbman->field_exists($tablename, $fieldname)) {
|
||||
$gradevalue = intval(0 - ($scale->id));
|
||||
try {
|
||||
$DB->set_field($tablename, $fieldname, $gradevalue, ["id" => $gi->iteminstance]);
|
||||
} catch (\dml_exception $x) {
|
||||
$updated = "fail";
|
||||
$debug = strval($x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
$updated = "skipped";
|
||||
}
|
||||
|
||||
} else {
|
||||
$updated = "skipped";
|
||||
$gradelist[] = [
|
||||
'name' => $gi->itemname,
|
||||
'changed' => $updated,
|
||||
'debug' => $debug,
|
||||
];
|
||||
}
|
||||
|
||||
$gradelist[] = [
|
||||
'name' => $gi->itemname,
|
||||
'changed' => $updated,
|
||||
'debug' => $debug,
|
||||
$list[] = [
|
||||
'course' => $courseinfo->simple_model(),
|
||||
'grades' => $gradelist,
|
||||
];
|
||||
}
|
||||
|
||||
$list[] = [
|
||||
'course' => $courseinfo->simple_model(),
|
||||
'grades' => $gradelist,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2216,7 +2218,7 @@ class studyplanservice extends \external_api {
|
|||
|
||||
/**
|
||||
* Count the number of templates available
|
||||
* @return array
|
||||
* @return int
|
||||
*/
|
||||
public static function count_templates() {
|
||||
\external_api::validate_context(\context_system::instance());
|
||||
|
|
|
@ -177,7 +177,7 @@ class teachingfinder {
|
|||
|
||||
/**
|
||||
* List of recognized teacher id's
|
||||
* @return intp[]
|
||||
* @return int[]
|
||||
*/
|
||||
public static function list_teacher_ids() {
|
||||
global $DB;
|
||||
|
|
|
@ -78,7 +78,6 @@ class utilityservice extends \external_api {
|
|||
* Returns description of get_mform parameters
|
||||
*
|
||||
* @return \external_function_parameters
|
||||
* @since Moodle 3.1
|
||||
*/
|
||||
public static function get_mform_parameters() {
|
||||
return new \external_function_parameters([
|
||||
|
@ -122,7 +121,6 @@ class utilityservice extends \external_api {
|
|||
* Returns description of get_mform() result value
|
||||
*
|
||||
* @return \core_external\external_description
|
||||
* @since Moodle 3.1
|
||||
*/
|
||||
public static function get_mform_returns() {
|
||||
return new \external_single_structure(
|
||||
|
@ -196,7 +194,7 @@ class utilityservice extends \external_api {
|
|||
|
||||
/**
|
||||
* Submit specified form data into form
|
||||
* @return array Success/fail structure
|
||||
* @return array of settings
|
||||
*/
|
||||
public static function getsettings() {
|
||||
global $CFG;
|
||||
|
|
Reference in a new issue