diff --git a/classes/completionscanner.php b/classes/completionscanner.php index 1429d08..fdd4235 100644 --- a/classes/completionscanner.php +++ b/classes/completionscanner.php @@ -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); diff --git a/classes/coursecompetencyinfo.php b/classes/coursecompetencyinfo.php index cbb97b2..af20df7 100644 --- a/classes/coursecompetencyinfo.php +++ b/classes/coursecompetencyinfo.php @@ -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; } } diff --git a/classes/courseinfo.php b/classes/courseinfo.php index af451ed..6291e46 100644 --- a/classes/courseinfo.php +++ b/classes/courseinfo.php @@ -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()); diff --git a/classes/courseservice.php b/classes/courseservice.php index eec4da5..1fc11f1 100644 --- a/classes/courseservice.php +++ b/classes/courseservice.php @@ -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)) { diff --git a/classes/form/formbase.php b/classes/form/formbase.php index 1ddcca3..3a4e0f7 100644 --- a/classes/form/formbase.php +++ b/classes/form/formbase.php @@ -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() { diff --git a/classes/form/studyplan_editform.php b/classes/form/studyplan_editform.php index 360482d..fdbf511 100644 --- a/classes/form/studyplan_editform.php +++ b/classes/form/studyplan_editform.php @@ -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) { diff --git a/classes/form/studyplan_fromtemplateform.php b/classes/form/studyplan_fromtemplateform.php index 7a6ac11..0cc4f80 100644 --- a/classes/form/studyplan_fromtemplateform.php +++ b/classes/form/studyplan_fromtemplateform.php @@ -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) { diff --git a/classes/form/studyplanpage_editform.php b/classes/form/studyplanpage_editform.php index 36bebf8..97b7b4b 100644 --- a/classes/form/studyplanpage_editform.php +++ b/classes/form/studyplanpage_editform.php @@ -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) { diff --git a/classes/form/text_integer.php b/classes/form/text_integer.php index 0476b4d..dcf540f 100644 --- a/classes/form/text_integer.php +++ b/classes/form/text_integer.php @@ -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; diff --git a/classes/gradeinfo.php b/classes/gradeinfo.php index 2d8148d..5e15f91 100644 --- a/classes/gradeinfo.php +++ b/classes/gradeinfo.php @@ -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); diff --git a/classes/gradingscanner.php b/classes/gradingscanner.php index ebddd0b..84b7922 100644 --- a/classes/gradingscanner.php +++ b/classes/gradingscanner.php @@ -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)) { diff --git a/classes/local/aggregators/bistate_aggregator.php b/classes/local/aggregators/bistate_aggregator.php index 973e92d..4a7ffde 100644 --- a/classes/local/aggregators/bistate_aggregator.php +++ b/classes/local/aggregators/bistate_aggregator.php @@ -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(); diff --git a/classes/local/aggregators/competency_aggregator.php b/classes/local/aggregators/competency_aggregator.php index cac36f9..7f95da4 100644 --- a/classes/local/aggregators/competency_aggregator.php +++ b/classes/local/aggregators/competency_aggregator.php @@ -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; } } diff --git a/classes/local/aggregators/core_aggregator.php b/classes/local/aggregators/core_aggregator.php index fe9c5a3..38900f8 100644 --- a/classes/local/aggregators/core_aggregator.php +++ b/classes/local/aggregators/core_aggregator.php @@ -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; } } diff --git a/classes/local/aggregators/tristate_aggregator.php b/classes/local/aggregators/tristate_aggregator.php index 6c62571..0928e22 100644 --- a/classes/local/aggregators/tristate_aggregator.php +++ b/classes/local/aggregators/tristate_aggregator.php @@ -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, . diff --git a/classes/local/gradegenerator.php b/classes/local/gradegenerator.php index 5961157..37587c7 100644 --- a/classes/local/gradegenerator.php +++ b/classes/local/gradegenerator.php @@ -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; } /** diff --git a/classes/local/helpers/webservicehelper.php b/classes/local/helpers/webservicehelper.php index c43bd3a..e3f5989 100644 --- a/classes/local/helpers/webservicehelper.php +++ b/classes/local/helpers/webservicehelper.php @@ -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; diff --git a/classes/local/randomimage.php b/classes/local/randomimage.php index fd375c2..22a730a 100644 --- a/classes/local/randomimage.php +++ b/classes/local/randomimage.php @@ -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 ""; + } } /** diff --git a/classes/local/ungradedscanners/quiz_scanner.php b/classes/local/ungradedscanners/quiz_scanner.php index e88ff17..8a3eafa 100644 --- a/classes/local/ungradedscanners/quiz_scanner.php +++ b/classes/local/ungradedscanners/quiz_scanner.php @@ -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. diff --git a/classes/period.php b/classes/period.php index 2f260ce..028a198 100644 --- a/classes/period.php +++ b/classes/period.php @@ -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; diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 8f07d6f..1b04603 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -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); } diff --git a/classes/reportinvite_form.php b/classes/reportinvite_form.php index 3c0654b..70225c7 100644 --- a/classes/reportinvite_form.php +++ b/classes/reportinvite_form.php @@ -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; diff --git a/classes/reportservice.php b/classes/reportservice.php index d349f50..247a134 100644 --- a/classes/reportservice.php +++ b/classes/reportservice.php @@ -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); diff --git a/classes/studentstudyplanservice.php b/classes/studentstudyplanservice.php index 5bdc017..8e51cc5 100644 --- a/classes/studentstudyplanservice.php +++ b/classes/studentstudyplanservice.php @@ -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; diff --git a/classes/studyline.php b/classes/studyline.php index 41dc9a5..888cab8 100644 --- a/classes/studyline.php +++ b/classes/studyline.php @@ -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; diff --git a/classes/studyplan.php b/classes/studyplan.php index c492593..2064e67 100644 --- a/classes/studyplan.php +++ b/classes/studyplan.php @@ -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"); diff --git a/classes/studyplanpage.php b/classes/studyplanpage.php index d16bef5..a1b099e 100644 --- a/classes/studyplanpage.php +++ b/classes/studyplanpage.php @@ -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. diff --git a/classes/studyplanservice.php b/classes/studyplanservice.php index e6bed48..0a63abb 100644 --- a/classes/studyplanservice.php +++ b/classes/studyplanservice.php @@ -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()); diff --git a/classes/teachingfinder.php b/classes/teachingfinder.php index ae1226c..b2a6cc4 100644 --- a/classes/teachingfinder.php +++ b/classes/teachingfinder.php @@ -177,7 +177,7 @@ class teachingfinder { /** * List of recognized teacher id's - * @return intp[] + * @return int[] */ public static function list_teacher_ids() { global $DB; diff --git a/classes/utilityservice.php b/classes/utilityservice.php index f72ee21..b49a3d7 100644 --- a/classes/utilityservice.php +++ b/classes/utilityservice.php @@ -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;