Checked phpdoc @return types up to contextinfo.php
This commit is contained in:
parent
04a1a8b049
commit
136284368c
8 changed files with 98 additions and 79 deletions
|
@ -80,7 +80,7 @@ abstract class aggregator {
|
|||
* @param mixed $configstr Configuration string for aggregator
|
||||
* @throws moodle_exception If method is not found
|
||||
*/
|
||||
public static function create($method, $configstr): self {
|
||||
public static function create($method, $configstr): object {
|
||||
if (self::supported($method)) {
|
||||
$agclass = self::aggregator_name($method);
|
||||
return new $agclass($configstr);
|
||||
|
@ -95,7 +95,7 @@ abstract class aggregator {
|
|||
* @param mixed $method Aggregation method
|
||||
* @param mixed $configstr Configuration string for aggregator
|
||||
*/
|
||||
public static function create_or_default($method, $configstr): self {
|
||||
public static function create_or_default($method, $configstr): object {
|
||||
try {
|
||||
return self::create($method, $configstr);
|
||||
} catch (\moodle_exception $x) {
|
||||
|
|
|
@ -106,31 +106,36 @@ class associationservice extends \external_api {
|
|||
global $DB;
|
||||
|
||||
$ctx = \context::instance_by_id($r->contextid);
|
||||
$ctxpath = array_reverse($ctx->get_parent_context_ids(true));
|
||||
if (count($ctxpath) > 1 && $ctxpath[0] == 1) {
|
||||
array_shift($ctxpath);
|
||||
if (is_object($ctx)) {
|
||||
$ctxpath = array_reverse($ctx->get_parent_context_ids(true));
|
||||
if (count($ctxpath) > 1 && $ctxpath[0] == 1) {
|
||||
array_shift($ctxpath);
|
||||
}
|
||||
|
||||
$result = [
|
||||
"id" => $r->id,
|
||||
"name" => $r->name,
|
||||
"idnumber" => $r->idnumber,
|
||||
"description" => $r->description,
|
||||
"visible" => $r->visible,
|
||||
"context" => [
|
||||
"name" => $ctx->get_context_name(false, false),
|
||||
"shortname" => $ctx->get_context_name(false, true),
|
||||
"path" => array_map(function($c) {
|
||||
$cx = (object)\context::instance_by_id($c);
|
||||
return $cx->get_context_name(false, false);
|
||||
}, $ctxpath),
|
||||
"shortpath" => array_map(function($c) {
|
||||
$cx = (object)\context::instance_by_id($c);
|
||||
return $cx->get_context_name(false, true);
|
||||
}, $ctxpath),
|
||||
],
|
||||
];
|
||||
|
||||
return $result;
|
||||
} else {
|
||||
throw new \moodle_exception("");
|
||||
}
|
||||
|
||||
$result = [
|
||||
"id" => $r->id,
|
||||
"name" => $r->name,
|
||||
"idnumber" => $r->idnumber,
|
||||
"description" => $r->description,
|
||||
"visible" => $r->visible,
|
||||
"context" => [
|
||||
"name" => $ctx->get_context_name(false, false),
|
||||
"shortname" => $ctx->get_context_name(false, true),
|
||||
"path" => array_map(function($c) {
|
||||
return \context::instance_by_id($c)->get_context_name(false, false);
|
||||
}, $ctxpath),
|
||||
"shortpath" => array_map(function($c) {
|
||||
return \context::instance_by_id($c)->get_context_name(false, true);
|
||||
}, $ctxpath),
|
||||
],
|
||||
];
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -397,7 +397,7 @@ class badgeinfo {
|
|||
* Gets the module instance from the database and returns it.
|
||||
* If no module instance exists this function returns false.
|
||||
* @param int $cmid Course module id
|
||||
* @return stdClass|bool
|
||||
* @return object|null
|
||||
*/
|
||||
private static function get_mod_instance($cmid) {
|
||||
global $DB;
|
||||
|
@ -445,9 +445,10 @@ class badgeinfo {
|
|||
if ($crit->criteriatype == BADGE_CRITERIA_TYPE_ACTIVITY) {
|
||||
foreach ($crit->params as $p) {
|
||||
$mod = self::get_mod_instance($p["module"]);
|
||||
if (!$mod) {
|
||||
if (!is_object($mod)) {
|
||||
$title = get_string('error:nosuchmod', 'badges');
|
||||
$description = get_string('error:nosuchmod', 'badges');
|
||||
continue;
|
||||
} else {
|
||||
$title = \html_writer::tag('b', '"' . get_string('modulename', $mod->modname) . ' - ' . $mod->name . '"');;
|
||||
$description = \html_writer::tag('b', '"' . get_string('modulename', $mod->modname) . ' - ' . $mod->name . '"');
|
||||
|
|
|
@ -103,7 +103,11 @@ class cascadecohortsync {
|
|||
$groupdata->name = $groupname;
|
||||
$groupid = groups_create_group($groupdata);
|
||||
|
||||
return $groupid;
|
||||
if (is_int($groupid)) {
|
||||
return $groupid;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -109,7 +109,7 @@ class completionscanner {
|
|||
'itemmodule' => $this->cm->modname,
|
||||
'iteminstance' => $this->cm->instance,
|
||||
'courseid' => $this->courseid]);
|
||||
if ($gi !== false) {
|
||||
if (is_object($gi)) {
|
||||
/* Grade none items should not be relevant.
|
||||
Note that the grade status is probably only relevant if the item
|
||||
has not yet received a completion, but has been submitted.
|
||||
|
|
|
@ -78,11 +78,11 @@ class contextinfo {
|
|||
public function path($short=false) {
|
||||
if ($short) {
|
||||
return array_map(function($c) {
|
||||
return \context::instance_by_id($c)->get_context_name(false, true);
|
||||
return ((object)\context::instance_by_id($c))->get_context_name(false, true);
|
||||
}, $this->ctxpath);
|
||||
} else {
|
||||
return array_map(function($c) {
|
||||
return \context::instance_by_id($c)->get_context_name(false, false);
|
||||
return ((object)\context::instance_by_id($c))->get_context_name(false, false);
|
||||
}, $this->ctxpath);
|
||||
}
|
||||
}
|
||||
|
@ -113,7 +113,13 @@ class contextinfo {
|
|||
if ($contextid <= 1) {
|
||||
$contextid = 1;
|
||||
}
|
||||
return \context::instance_by_id($contextid);
|
||||
|
||||
$ctx = \context::instance_by_id($contextid);
|
||||
if (is_object($ctx)) {
|
||||
return $ctx;
|
||||
} else {
|
||||
return \context_system::instance();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ class studyplan_editform extends formbase {
|
|||
* Translate parameters into customdata.
|
||||
*
|
||||
* @param object $params The parameters for form initialization
|
||||
* @return array Form data based on parameters
|
||||
* @return stdClass Form data based on parameters
|
||||
*/
|
||||
public static function init_customdata(object $params) {
|
||||
$customdata = new stdClass;
|
||||
|
@ -87,7 +87,7 @@ class studyplan_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;
|
||||
|
|
91
lib.php
91
lib.php
|
@ -318,56 +318,57 @@ function local_treestudyplan_send_invite($inviteid) {
|
|||
|
||||
$noreply = 'noreply@' . get_host_from_url($CFG->wwwroot);
|
||||
$mailer = get_mailer();
|
||||
$mailer->setFrom($noreply, "{$USER->firstname} {$USER->lastname}");
|
||||
$mailer->addAddress($invite->email, $invite->name);
|
||||
$mailer->addReplyTo($USER->email, "{$USER->firstname} {$USER->lastname}");
|
||||
if ($mailer != null ) {
|
||||
$mailer->setFrom($noreply, "{$USER->firstname} {$USER->lastname}");
|
||||
$mailer->addAddress($invite->email, $invite->name);
|
||||
$mailer->addReplyTo($USER->email, "{$USER->firstname} {$USER->lastname}");
|
||||
|
||||
$invitehref = $CFG->wwwroot."/local/treestudyplan/invited.php?key={$invite->invitekey}";
|
||||
$invitehref = $CFG->wwwroot."/local/treestudyplan/invited.php?key={$invite->invitekey}";
|
||||
|
||||
$data = [ 'permissions' => '',
|
||||
'invitee' => $invite->name,
|
||||
'sender' => "{$USER->firstname} {$USER->lastname}",
|
||||
'link' => $invitehref];
|
||||
$data = [ 'permissions' => '',
|
||||
'invitee' => $invite->name,
|
||||
'sender' => "{$USER->firstname} {$USER->lastname}",
|
||||
'link' => $invitehref];
|
||||
|
||||
if ($invite->allow_details || $invite->allow_calendar || $invite->allow_badges) {
|
||||
$data['permissions'] = get_string('invite_mail_permissions', 'local_treestudyplan');
|
||||
$data['permissions'] .= "<ul>\n";
|
||||
if ($invite->allow_details) {
|
||||
$data['permissions'] .= "<li>".get_string('invite_allow_details', 'local_treestudyplan')."</li>\n";
|
||||
}
|
||||
if ($invite->allow_calendar) {
|
||||
$data['permissions'] .= "<li>".get_string('invite_allow_calendar', 'local_treestudyplan')."</li>\n";
|
||||
}
|
||||
if ($invite->allow_badges) {
|
||||
$data['permissions'] .= "<li>".get_string('invite_allow_badges', 'local_treestudyplan')."</li>\n";
|
||||
if ($invite->allow_details || $invite->allow_calendar || $invite->allow_badges) {
|
||||
$data['permissions'] = get_string('invite_mail_permissions', 'local_treestudyplan');
|
||||
$data['permissions'] .= "<ul>\n";
|
||||
if ($invite->allow_details) {
|
||||
$data['permissions'] .= "<li>".get_string('invite_allow_details', 'local_treestudyplan')."</li>\n";
|
||||
}
|
||||
if ($invite->allow_calendar) {
|
||||
$data['permissions'] .= "<li>".get_string('invite_allow_calendar', 'local_treestudyplan')."</li>\n";
|
||||
}
|
||||
if ($invite->allow_badges) {
|
||||
$data['permissions'] .= "<li>".get_string('invite_allow_badges', 'local_treestudyplan')."</li>\n";
|
||||
}
|
||||
|
||||
$data['permissions'] .= "</ul></p>\n";
|
||||
}
|
||||
|
||||
$data['permissions'] .= "</ul></p>\n";
|
||||
$body = get_string('invite_mail_text', 'local_treestudyplan', $data);
|
||||
$subject = get_string('invite_mail_subject', 'local_treestudyplan', $data);
|
||||
|
||||
$html = "
|
||||
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>.
|
||||
<html xmlns='http://www.w3.org/1999/xhtml'>.
|
||||
<head>
|
||||
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
|
||||
<title>{$subject}</title>
|
||||
<meta name='viewport' content='width=device-width, initial-scale=1.0'/>
|
||||
</head>
|
||||
<body>
|
||||
{$body}
|
||||
</body>
|
||||
</html>";
|
||||
|
||||
$mailer->isHTML(true);
|
||||
$mailer->Subject = $subject;
|
||||
$mailer->Body = $html;
|
||||
$mailer->AltBody = strip_tags($body);
|
||||
|
||||
$mailer->send();
|
||||
}
|
||||
|
||||
$body = get_string('invite_mail_text', 'local_treestudyplan', $data);
|
||||
$subject = get_string('invite_mail_subject', 'local_treestudyplan', $data);
|
||||
|
||||
$html = "
|
||||
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>.
|
||||
<html xmlns='http://www.w3.org/1999/xhtml'>.
|
||||
<head>
|
||||
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
|
||||
<title>{$subject}</title>
|
||||
<meta name='viewport' content='width=device-width, initial-scale=1.0'/>
|
||||
</head>
|
||||
<body>
|
||||
{$body}
|
||||
</body>
|
||||
</html>";
|
||||
|
||||
$mailer->isHTML(true);
|
||||
$mailer->Subject = $subject;
|
||||
$mailer->Body = $html;
|
||||
$mailer->AltBody = strip_tags($body);
|
||||
|
||||
$mailer->send();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -469,6 +470,7 @@ function local_treestudyplan_pluginfile(
|
|||
}
|
||||
// We can now send the file back to the browser - in this case with a cache lifetime of 1 day and no filtering.
|
||||
send_stored_file($file, 24 * 60 * 60, 0, $forcedownload, $options);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -497,6 +499,7 @@ function local_treestudyplan_pluginfile(
|
|||
}
|
||||
// We can now send the file back to the browser - in this case with a cache lifetime of 1 day and no filtering.
|
||||
send_stored_file($file, 24 * 60 * 60, 0, $forcedownload, $options);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue