id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
|
|---|---|---|---|---|---|---|---|---|---|---|---|
217,200
|
moodle/moodle
|
media/classes/manager.php
|
core_media_manager.get_players
|
private function get_players() {
// Save time by only building the list once.
if (!$this->players) {
$sortorder = \core\plugininfo\media::get_enabled_plugins();
$this->players = [];
foreach ($sortorder as $name) {
$classname = "media_" . $name . "_plugin";
if (class_exists($classname)) {
$this->players[] = new $classname();
}
}
}
return $this->players;
}
|
php
|
private function get_players() {
// Save time by only building the list once.
if (!$this->players) {
$sortorder = \core\plugininfo\media::get_enabled_plugins();
$this->players = [];
foreach ($sortorder as $name) {
$classname = "media_" . $name . "_plugin";
if (class_exists($classname)) {
$this->players[] = new $classname();
}
}
}
return $this->players;
}
|
[
"private",
"function",
"get_players",
"(",
")",
"{",
"// Save time by only building the list once.",
"if",
"(",
"!",
"$",
"this",
"->",
"players",
")",
"{",
"$",
"sortorder",
"=",
"\\",
"core",
"\\",
"plugininfo",
"\\",
"media",
"::",
"get_enabled_plugins",
"(",
")",
";",
"$",
"this",
"->",
"players",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"sortorder",
"as",
"$",
"name",
")",
"{",
"$",
"classname",
"=",
"\"media_\"",
".",
"$",
"name",
".",
"\"_plugin\"",
";",
"if",
"(",
"class_exists",
"(",
"$",
"classname",
")",
")",
"{",
"$",
"this",
"->",
"players",
"[",
"]",
"=",
"new",
"$",
"classname",
"(",
")",
";",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"players",
";",
"}"
] |
Obtains the list of core_media_player objects currently in use to render
items.
The list is in rank order (highest first) and does not include players
which are disabled.
@return core_media_player[] Array of core_media_player objects in rank order
|
[
"Obtains",
"the",
"list",
"of",
"core_media_player",
"objects",
"currently",
"in",
"use",
"to",
"render",
"items",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/media/classes/manager.php#L172-L186
|
217,201
|
moodle/moodle
|
media/classes/manager.php
|
core_media_manager.fallback_to_link
|
private function fallback_to_link($urls, $name, $options) {
// If link is turned off, return empty.
if (!empty($options[self::OPTION_NO_LINK])) {
return '';
}
// Build up link content.
$output = '';
foreach ($urls as $url) {
if (strval($name) !== '' && $output === '') {
$title = $name;
} else {
$title = $this->get_filename($url);
}
$printlink = html_writer::link($url, $title, array('class' => 'mediafallbacklink'));
if ($output) {
// Where there are multiple available formats, there are fallback links
// for all formats, separated by /.
$output .= ' / ';
}
$output .= $printlink;
}
return $output;
}
|
php
|
private function fallback_to_link($urls, $name, $options) {
// If link is turned off, return empty.
if (!empty($options[self::OPTION_NO_LINK])) {
return '';
}
// Build up link content.
$output = '';
foreach ($urls as $url) {
if (strval($name) !== '' && $output === '') {
$title = $name;
} else {
$title = $this->get_filename($url);
}
$printlink = html_writer::link($url, $title, array('class' => 'mediafallbacklink'));
if ($output) {
// Where there are multiple available formats, there are fallback links
// for all formats, separated by /.
$output .= ' / ';
}
$output .= $printlink;
}
return $output;
}
|
[
"private",
"function",
"fallback_to_link",
"(",
"$",
"urls",
",",
"$",
"name",
",",
"$",
"options",
")",
"{",
"// If link is turned off, return empty.",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"self",
"::",
"OPTION_NO_LINK",
"]",
")",
")",
"{",
"return",
"''",
";",
"}",
"// Build up link content.",
"$",
"output",
"=",
"''",
";",
"foreach",
"(",
"$",
"urls",
"as",
"$",
"url",
")",
"{",
"if",
"(",
"strval",
"(",
"$",
"name",
")",
"!==",
"''",
"&&",
"$",
"output",
"===",
"''",
")",
"{",
"$",
"title",
"=",
"$",
"name",
";",
"}",
"else",
"{",
"$",
"title",
"=",
"$",
"this",
"->",
"get_filename",
"(",
"$",
"url",
")",
";",
"}",
"$",
"printlink",
"=",
"html_writer",
"::",
"link",
"(",
"$",
"url",
",",
"$",
"title",
",",
"array",
"(",
"'class'",
"=>",
"'mediafallbacklink'",
")",
")",
";",
"if",
"(",
"$",
"output",
")",
"{",
"// Where there are multiple available formats, there are fallback links",
"// for all formats, separated by /.",
"$",
"output",
".=",
"' / '",
";",
"}",
"$",
"output",
".=",
"$",
"printlink",
";",
"}",
"return",
"$",
"output",
";",
"}"
] |
Returns links to the specified URLs unless OPTION_NO_LINK is passed.
@param array $urls URLs of media files
@param string $name Display name; '' to use default
@param array $options Options array
@return string HTML code for embed
|
[
"Returns",
"links",
"to",
"the",
"specified",
"URLs",
"unless",
"OPTION_NO_LINK",
"is",
"passed",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/media/classes/manager.php#L301-L324
|
217,202
|
moodle/moodle
|
media/classes/manager.php
|
core_media_manager.can_embed_urls
|
public function can_embed_urls(array $urls, $options = array()) {
// Check all players to see if any of them support it.
foreach ($this->get_players() as $player) {
// First player that supports it, return true.
if ($player->list_supported_urls($urls, $options)) {
return true;
}
}
return false;
}
|
php
|
public function can_embed_urls(array $urls, $options = array()) {
// Check all players to see if any of them support it.
foreach ($this->get_players() as $player) {
// First player that supports it, return true.
if ($player->list_supported_urls($urls, $options)) {
return true;
}
}
return false;
}
|
[
"public",
"function",
"can_embed_urls",
"(",
"array",
"$",
"urls",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"// Check all players to see if any of them support it.",
"foreach",
"(",
"$",
"this",
"->",
"get_players",
"(",
")",
"as",
"$",
"player",
")",
"{",
"// First player that supports it, return true.",
"if",
"(",
"$",
"player",
"->",
"list_supported_urls",
"(",
"$",
"urls",
",",
"$",
"options",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Checks whether a file can be embedded. If this returns true you will get
an embedded player; if this returns false, you will just get a download
link.
@param array $urls URL of media file and any alternatives (moodle_url)
@param array $options Options (same as when embedding)
@return bool True if file can be embedded
|
[
"Checks",
"whether",
"a",
"file",
"can",
"be",
"embedded",
".",
"If",
"this",
"returns",
"true",
"you",
"will",
"get",
"an",
"embedded",
"player",
";",
"if",
"this",
"returns",
"false",
"you",
"will",
"just",
"get",
"a",
"download",
"link",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/media/classes/manager.php#L350-L359
|
217,203
|
moodle/moodle
|
media/classes/manager.php
|
core_media_manager.get_embeddable_markers
|
public function get_embeddable_markers() {
if (empty($this->embeddablemarkers)) {
$markers = '';
foreach ($this->get_players() as $player) {
foreach ($player->get_embeddable_markers() as $marker) {
if ($markers !== '') {
$markers .= '|';
}
$markers .= preg_quote($marker);
}
}
$this->embeddablemarkers = $markers;
}
return $this->embeddablemarkers;
}
|
php
|
public function get_embeddable_markers() {
if (empty($this->embeddablemarkers)) {
$markers = '';
foreach ($this->get_players() as $player) {
foreach ($player->get_embeddable_markers() as $marker) {
if ($markers !== '') {
$markers .= '|';
}
$markers .= preg_quote($marker);
}
}
$this->embeddablemarkers = $markers;
}
return $this->embeddablemarkers;
}
|
[
"public",
"function",
"get_embeddable_markers",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"embeddablemarkers",
")",
")",
"{",
"$",
"markers",
"=",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"get_players",
"(",
")",
"as",
"$",
"player",
")",
"{",
"foreach",
"(",
"$",
"player",
"->",
"get_embeddable_markers",
"(",
")",
"as",
"$",
"marker",
")",
"{",
"if",
"(",
"$",
"markers",
"!==",
"''",
")",
"{",
"$",
"markers",
".=",
"'|'",
";",
"}",
"$",
"markers",
".=",
"preg_quote",
"(",
"$",
"marker",
")",
";",
"}",
"}",
"$",
"this",
"->",
"embeddablemarkers",
"=",
"$",
"markers",
";",
"}",
"return",
"$",
"this",
"->",
"embeddablemarkers",
";",
"}"
] |
Obtains a list of markers that can be used in a regular expression when
searching for URLs that can be embedded by any player type.
This string is used to improve peformance of regex matching by ensuring
that the (presumably C) regex code can do a quick keyword check on the
URL part of a link to see if it matches one of these, rather than having
to go into PHP code for every single link to see if it can be embedded.
@return string String suitable for use in regex such as '(\.mp4|\.flv)'
|
[
"Obtains",
"a",
"list",
"of",
"markers",
"that",
"can",
"be",
"used",
"in",
"a",
"regular",
"expression",
"when",
"searching",
"for",
"URLs",
"that",
"can",
"be",
"embedded",
"by",
"any",
"player",
"type",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/media/classes/manager.php#L372-L386
|
217,204
|
moodle/moodle
|
media/classes/manager.php
|
core_media_manager.get_extension
|
public function get_extension(moodle_url $url) {
// Note: Does not use core_text (. is UTF8-safe).
$filename = self::get_filename($url);
$dot = strrpos($filename, '.');
if ($dot === false) {
return '';
} else {
return strtolower(substr($filename, $dot + 1));
}
}
|
php
|
public function get_extension(moodle_url $url) {
// Note: Does not use core_text (. is UTF8-safe).
$filename = self::get_filename($url);
$dot = strrpos($filename, '.');
if ($dot === false) {
return '';
} else {
return strtolower(substr($filename, $dot + 1));
}
}
|
[
"public",
"function",
"get_extension",
"(",
"moodle_url",
"$",
"url",
")",
"{",
"// Note: Does not use core_text (. is UTF8-safe).",
"$",
"filename",
"=",
"self",
"::",
"get_filename",
"(",
"$",
"url",
")",
";",
"$",
"dot",
"=",
"strrpos",
"(",
"$",
"filename",
",",
"'.'",
")",
";",
"if",
"(",
"$",
"dot",
"===",
"false",
")",
"{",
"return",
"''",
";",
"}",
"else",
"{",
"return",
"strtolower",
"(",
"substr",
"(",
"$",
"filename",
",",
"$",
"dot",
"+",
"1",
")",
")",
";",
"}",
"}"
] |
Returns the file extension for a URL.
@param moodle_url $url URL
|
[
"Returns",
"the",
"file",
"extension",
"for",
"a",
"URL",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/media/classes/manager.php#L447-L456
|
217,205
|
moodle/moodle
|
media/classes/manager.php
|
core_media_manager.get_filename
|
public function get_filename(moodle_url $url) {
// Use the 'file' parameter if provided (for links created when
// slasharguments was off). If not present, just use URL path.
$path = $url->get_param('file');
if (!$path) {
$path = $url->get_path();
}
// Remove everything before last / if present. Does not use textlib as / is UTF8-safe.
$slash = strrpos($path, '/');
if ($slash !== false) {
$path = substr($path, $slash + 1);
}
return $path;
}
|
php
|
public function get_filename(moodle_url $url) {
// Use the 'file' parameter if provided (for links created when
// slasharguments was off). If not present, just use URL path.
$path = $url->get_param('file');
if (!$path) {
$path = $url->get_path();
}
// Remove everything before last / if present. Does not use textlib as / is UTF8-safe.
$slash = strrpos($path, '/');
if ($slash !== false) {
$path = substr($path, $slash + 1);
}
return $path;
}
|
[
"public",
"function",
"get_filename",
"(",
"moodle_url",
"$",
"url",
")",
"{",
"// Use the 'file' parameter if provided (for links created when",
"// slasharguments was off). If not present, just use URL path.",
"$",
"path",
"=",
"$",
"url",
"->",
"get_param",
"(",
"'file'",
")",
";",
"if",
"(",
"!",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"$",
"url",
"->",
"get_path",
"(",
")",
";",
"}",
"// Remove everything before last / if present. Does not use textlib as / is UTF8-safe.",
"$",
"slash",
"=",
"strrpos",
"(",
"$",
"path",
",",
"'/'",
")",
";",
"if",
"(",
"$",
"slash",
"!==",
"false",
")",
"{",
"$",
"path",
"=",
"substr",
"(",
"$",
"path",
",",
"$",
"slash",
"+",
"1",
")",
";",
"}",
"return",
"$",
"path",
";",
"}"
] |
Obtains the filename from the moodle_url.
@param moodle_url $url URL
@return string Filename only (not escaped)
|
[
"Obtains",
"the",
"filename",
"from",
"the",
"moodle_url",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/media/classes/manager.php#L463-L477
|
217,206
|
moodle/moodle
|
competency/classes/api.php
|
api.is_scale_used_anywhere
|
public static function is_scale_used_anywhere($scaleid) {
global $DB;
$sql = "SELECT s.id
FROM {scale} s
LEFT JOIN {" . competency_framework::TABLE ."} f
ON f.scaleid = :scaleid1
LEFT JOIN {" . competency::TABLE ."} c
ON c.scaleid = :scaleid2
WHERE f.id IS NOT NULL
OR c.id IS NOT NULL";
return $DB->record_exists_sql($sql, ['scaleid1' => $scaleid, 'scaleid2' => $scaleid]);
}
|
php
|
public static function is_scale_used_anywhere($scaleid) {
global $DB;
$sql = "SELECT s.id
FROM {scale} s
LEFT JOIN {" . competency_framework::TABLE ."} f
ON f.scaleid = :scaleid1
LEFT JOIN {" . competency::TABLE ."} c
ON c.scaleid = :scaleid2
WHERE f.id IS NOT NULL
OR c.id IS NOT NULL";
return $DB->record_exists_sql($sql, ['scaleid1' => $scaleid, 'scaleid2' => $scaleid]);
}
|
[
"public",
"static",
"function",
"is_scale_used_anywhere",
"(",
"$",
"scaleid",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"sql",
"=",
"\"SELECT s.id\n FROM {scale} s\n LEFT JOIN {\"",
".",
"competency_framework",
"::",
"TABLE",
".",
"\"} f\n ON f.scaleid = :scaleid1\n LEFT JOIN {\"",
".",
"competency",
"::",
"TABLE",
".",
"\"} c\n ON c.scaleid = :scaleid2\n WHERE f.id IS NOT NULL\n OR c.id IS NOT NULL\"",
";",
"return",
"$",
"DB",
"->",
"record_exists_sql",
"(",
"$",
"sql",
",",
"[",
"'scaleid1'",
"=>",
"$",
"scaleid",
",",
"'scaleid2'",
"=>",
"$",
"scaleid",
"]",
")",
";",
"}"
] |
Checks whether a scale is used anywhere in the plugin.
This public API has two exceptions:
- It MUST NOT perform any capability checks.
- It MUST ignore whether competencies are enabled or not ({@link self::is_enabled()}).
@param int $scaleid The scale ID.
@return bool
|
[
"Checks",
"whether",
"a",
"scale",
"is",
"used",
"anywhere",
"in",
"the",
"plugin",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L110-L121
|
217,207
|
moodle/moodle
|
competency/classes/api.php
|
api.validate_course_module
|
protected static function validate_course_module($cmmixed, $throwexception = true) {
$cm = $cmmixed;
if (!is_object($cm)) {
$cmrecord = get_coursemodule_from_id(null, $cmmixed);
$modinfo = get_fast_modinfo($cmrecord->course);
$cm = $modinfo->get_cm($cmmixed);
} else if (!$cm instanceof cm_info) {
// Assume we got a course module record.
$modinfo = get_fast_modinfo($cm->course);
$cm = $modinfo->get_cm($cm->id);
}
if (!$cm->uservisible) {
if ($throwexception) {
throw new require_login_exception('Course module is hidden');
} else {
return false;
}
}
return true;
}
|
php
|
protected static function validate_course_module($cmmixed, $throwexception = true) {
$cm = $cmmixed;
if (!is_object($cm)) {
$cmrecord = get_coursemodule_from_id(null, $cmmixed);
$modinfo = get_fast_modinfo($cmrecord->course);
$cm = $modinfo->get_cm($cmmixed);
} else if (!$cm instanceof cm_info) {
// Assume we got a course module record.
$modinfo = get_fast_modinfo($cm->course);
$cm = $modinfo->get_cm($cm->id);
}
if (!$cm->uservisible) {
if ($throwexception) {
throw new require_login_exception('Course module is hidden');
} else {
return false;
}
}
return true;
}
|
[
"protected",
"static",
"function",
"validate_course_module",
"(",
"$",
"cmmixed",
",",
"$",
"throwexception",
"=",
"true",
")",
"{",
"$",
"cm",
"=",
"$",
"cmmixed",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"cm",
")",
")",
"{",
"$",
"cmrecord",
"=",
"get_coursemodule_from_id",
"(",
"null",
",",
"$",
"cmmixed",
")",
";",
"$",
"modinfo",
"=",
"get_fast_modinfo",
"(",
"$",
"cmrecord",
"->",
"course",
")",
";",
"$",
"cm",
"=",
"$",
"modinfo",
"->",
"get_cm",
"(",
"$",
"cmmixed",
")",
";",
"}",
"else",
"if",
"(",
"!",
"$",
"cm",
"instanceof",
"cm_info",
")",
"{",
"// Assume we got a course module record.",
"$",
"modinfo",
"=",
"get_fast_modinfo",
"(",
"$",
"cm",
"->",
"course",
")",
";",
"$",
"cm",
"=",
"$",
"modinfo",
"->",
"get_cm",
"(",
"$",
"cm",
"->",
"id",
")",
";",
"}",
"if",
"(",
"!",
"$",
"cm",
"->",
"uservisible",
")",
"{",
"if",
"(",
"$",
"throwexception",
")",
"{",
"throw",
"new",
"require_login_exception",
"(",
"'Course module is hidden'",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Validate if current user have acces to the course_module if hidden.
@param mixed $cmmixed The cm_info class, course module record or its ID.
@param bool $throwexception Throw an exception or not.
@return bool
|
[
"Validate",
"if",
"current",
"user",
"have",
"acces",
"to",
"the",
"course_module",
"if",
"hidden",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L130-L151
|
217,208
|
moodle/moodle
|
competency/classes/api.php
|
api.validate_course
|
protected static function validate_course($courseorid, $throwexception = true) {
$course = $courseorid;
if (!is_object($course)) {
$course = get_course($course);
}
$coursecontext = context_course::instance($course->id);
if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
if ($throwexception) {
throw new require_login_exception('Course is hidden');
} else {
return false;
}
}
return true;
}
|
php
|
protected static function validate_course($courseorid, $throwexception = true) {
$course = $courseorid;
if (!is_object($course)) {
$course = get_course($course);
}
$coursecontext = context_course::instance($course->id);
if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
if ($throwexception) {
throw new require_login_exception('Course is hidden');
} else {
return false;
}
}
return true;
}
|
[
"protected",
"static",
"function",
"validate_course",
"(",
"$",
"courseorid",
",",
"$",
"throwexception",
"=",
"true",
")",
"{",
"$",
"course",
"=",
"$",
"courseorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"course",
")",
")",
"{",
"$",
"course",
"=",
"get_course",
"(",
"$",
"course",
")",
";",
"}",
"$",
"coursecontext",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"course",
"->",
"id",
")",
";",
"if",
"(",
"!",
"$",
"course",
"->",
"visible",
"and",
"!",
"has_capability",
"(",
"'moodle/course:viewhiddencourses'",
",",
"$",
"coursecontext",
")",
")",
"{",
"if",
"(",
"$",
"throwexception",
")",
"{",
"throw",
"new",
"require_login_exception",
"(",
"'Course is hidden'",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Validate if current user have acces to the course if hidden.
@param mixed $courseorid The course or it ID.
@param bool $throwexception Throw an exception or not.
@return bool
|
[
"Validate",
"if",
"current",
"user",
"have",
"acces",
"to",
"the",
"course",
"if",
"hidden",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L160-L176
|
217,209
|
moodle/moodle
|
competency/classes/api.php
|
api.create_competency
|
public static function create_competency(stdClass $record) {
static::require_enabled();
$competency = new competency(0, $record);
// First we do a permissions check.
require_capability('moodle/competency:competencymanage', $competency->get_context());
// Reset the sortorder, use reorder instead.
$competency->set('sortorder', 0);
$competency->create();
\core\event\competency_created::create_from_competency($competency)->trigger();
// Reset the rule of the parent.
$parent = $competency->get_parent();
if ($parent) {
$parent->reset_rule();
$parent->update();
}
return $competency;
}
|
php
|
public static function create_competency(stdClass $record) {
static::require_enabled();
$competency = new competency(0, $record);
// First we do a permissions check.
require_capability('moodle/competency:competencymanage', $competency->get_context());
// Reset the sortorder, use reorder instead.
$competency->set('sortorder', 0);
$competency->create();
\core\event\competency_created::create_from_competency($competency)->trigger();
// Reset the rule of the parent.
$parent = $competency->get_parent();
if ($parent) {
$parent->reset_rule();
$parent->update();
}
return $competency;
}
|
[
"public",
"static",
"function",
"create_competency",
"(",
"stdClass",
"$",
"record",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"competency",
"=",
"new",
"competency",
"(",
"0",
",",
"$",
"record",
")",
";",
"// First we do a permissions check.",
"require_capability",
"(",
"'moodle/competency:competencymanage'",
",",
"$",
"competency",
"->",
"get_context",
"(",
")",
")",
";",
"// Reset the sortorder, use reorder instead.",
"$",
"competency",
"->",
"set",
"(",
"'sortorder'",
",",
"0",
")",
";",
"$",
"competency",
"->",
"create",
"(",
")",
";",
"\\",
"core",
"\\",
"event",
"\\",
"competency_created",
"::",
"create_from_competency",
"(",
"$",
"competency",
")",
"->",
"trigger",
"(",
")",
";",
"// Reset the rule of the parent.",
"$",
"parent",
"=",
"$",
"competency",
"->",
"get_parent",
"(",
")",
";",
"if",
"(",
"$",
"parent",
")",
"{",
"$",
"parent",
"->",
"reset_rule",
"(",
")",
";",
"$",
"parent",
"->",
"update",
"(",
")",
";",
"}",
"return",
"$",
"competency",
";",
"}"
] |
Create a competency from a record containing all the data for the class.
Requires moodle/competency:competencymanage capability at the system context.
@param stdClass $record Record containing all the data for an instance of the class.
@return competency
|
[
"Create",
"a",
"competency",
"from",
"a",
"record",
"containing",
"all",
"the",
"data",
"for",
"the",
"class",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L186-L207
|
217,210
|
moodle/moodle
|
competency/classes/api.php
|
api.delete_competency
|
public static function delete_competency($id) {
global $DB;
static::require_enabled();
$competency = new competency($id);
// First we do a permissions check.
require_capability('moodle/competency:competencymanage', $competency->get_context());
$events = array();
$competencyids = array(intval($competency->get('id')));
$contextid = $competency->get_context()->id;
$competencyids = array_merge(competency::get_descendants_ids($competency), $competencyids);
if (!competency::can_all_be_deleted($competencyids)) {
return false;
}
$transaction = $DB->start_delegated_transaction();
try {
// Reset the rule of the parent.
$parent = $competency->get_parent();
if ($parent) {
$parent->reset_rule();
$parent->update();
}
// Delete the competency separately so the after_delete event can be triggered.
$competency->delete();
// Delete the competencies.
competency::delete_multiple($competencyids);
// Delete the competencies relation.
related_competency::delete_multiple_relations($competencyids);
// Delete competency evidences.
user_evidence_competency::delete_by_competencyids($competencyids);
// Register the competencies deleted events.
$events = \core\event\competency_deleted::create_multiple_from_competencyids($competencyids, $contextid);
} catch (\Exception $e) {
$transaction->rollback($e);
}
$transaction->allow_commit();
// Trigger events.
foreach ($events as $event) {
$event->trigger();
}
return true;
}
|
php
|
public static function delete_competency($id) {
global $DB;
static::require_enabled();
$competency = new competency($id);
// First we do a permissions check.
require_capability('moodle/competency:competencymanage', $competency->get_context());
$events = array();
$competencyids = array(intval($competency->get('id')));
$contextid = $competency->get_context()->id;
$competencyids = array_merge(competency::get_descendants_ids($competency), $competencyids);
if (!competency::can_all_be_deleted($competencyids)) {
return false;
}
$transaction = $DB->start_delegated_transaction();
try {
// Reset the rule of the parent.
$parent = $competency->get_parent();
if ($parent) {
$parent->reset_rule();
$parent->update();
}
// Delete the competency separately so the after_delete event can be triggered.
$competency->delete();
// Delete the competencies.
competency::delete_multiple($competencyids);
// Delete the competencies relation.
related_competency::delete_multiple_relations($competencyids);
// Delete competency evidences.
user_evidence_competency::delete_by_competencyids($competencyids);
// Register the competencies deleted events.
$events = \core\event\competency_deleted::create_multiple_from_competencyids($competencyids, $contextid);
} catch (\Exception $e) {
$transaction->rollback($e);
}
$transaction->allow_commit();
// Trigger events.
foreach ($events as $event) {
$event->trigger();
}
return true;
}
|
[
"public",
"static",
"function",
"delete_competency",
"(",
"$",
"id",
")",
"{",
"global",
"$",
"DB",
";",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"competency",
"=",
"new",
"competency",
"(",
"$",
"id",
")",
";",
"// First we do a permissions check.",
"require_capability",
"(",
"'moodle/competency:competencymanage'",
",",
"$",
"competency",
"->",
"get_context",
"(",
")",
")",
";",
"$",
"events",
"=",
"array",
"(",
")",
";",
"$",
"competencyids",
"=",
"array",
"(",
"intval",
"(",
"$",
"competency",
"->",
"get",
"(",
"'id'",
")",
")",
")",
";",
"$",
"contextid",
"=",
"$",
"competency",
"->",
"get_context",
"(",
")",
"->",
"id",
";",
"$",
"competencyids",
"=",
"array_merge",
"(",
"competency",
"::",
"get_descendants_ids",
"(",
"$",
"competency",
")",
",",
"$",
"competencyids",
")",
";",
"if",
"(",
"!",
"competency",
"::",
"can_all_be_deleted",
"(",
"$",
"competencyids",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"transaction",
"=",
"$",
"DB",
"->",
"start_delegated_transaction",
"(",
")",
";",
"try",
"{",
"// Reset the rule of the parent.",
"$",
"parent",
"=",
"$",
"competency",
"->",
"get_parent",
"(",
")",
";",
"if",
"(",
"$",
"parent",
")",
"{",
"$",
"parent",
"->",
"reset_rule",
"(",
")",
";",
"$",
"parent",
"->",
"update",
"(",
")",
";",
"}",
"// Delete the competency separately so the after_delete event can be triggered.",
"$",
"competency",
"->",
"delete",
"(",
")",
";",
"// Delete the competencies.",
"competency",
"::",
"delete_multiple",
"(",
"$",
"competencyids",
")",
";",
"// Delete the competencies relation.",
"related_competency",
"::",
"delete_multiple_relations",
"(",
"$",
"competencyids",
")",
";",
"// Delete competency evidences.",
"user_evidence_competency",
"::",
"delete_by_competencyids",
"(",
"$",
"competencyids",
")",
";",
"// Register the competencies deleted events.",
"$",
"events",
"=",
"\\",
"core",
"\\",
"event",
"\\",
"competency_deleted",
"::",
"create_multiple_from_competencyids",
"(",
"$",
"competencyids",
",",
"$",
"contextid",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"transaction",
"->",
"rollback",
"(",
"$",
"e",
")",
";",
"}",
"$",
"transaction",
"->",
"allow_commit",
"(",
")",
";",
"// Trigger events.",
"foreach",
"(",
"$",
"events",
"as",
"$",
"event",
")",
"{",
"$",
"event",
"->",
"trigger",
"(",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Delete a competency by id.
Requires moodle/competency:competencymanage capability at the system context.
@param int $id The record to delete. This will delete alot of related data - you better be sure.
@return boolean
|
[
"Delete",
"a",
"competency",
"by",
"id",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L217-L269
|
217,211
|
moodle/moodle
|
competency/classes/api.php
|
api.move_up_competency
|
public static function move_up_competency($id) {
static::require_enabled();
$current = new competency($id);
// First we do a permissions check.
require_capability('moodle/competency:competencymanage', $current->get_context());
$sortorder = $current->get('sortorder');
if ($sortorder == 0) {
return false;
}
$sortorder = $sortorder - 1;
$current->set('sortorder', $sortorder);
$filters = array('parentid' => $current->get('parentid'),
'competencyframeworkid' => $current->get('competencyframeworkid'),
'sortorder' => $sortorder);
$children = self::list_competencies($filters, 'id');
foreach ($children as $needtoswap) {
$needtoswap->set('sortorder', $sortorder + 1);
$needtoswap->update();
}
// OK - all set.
$result = $current->update();
return $result;
}
|
php
|
public static function move_up_competency($id) {
static::require_enabled();
$current = new competency($id);
// First we do a permissions check.
require_capability('moodle/competency:competencymanage', $current->get_context());
$sortorder = $current->get('sortorder');
if ($sortorder == 0) {
return false;
}
$sortorder = $sortorder - 1;
$current->set('sortorder', $sortorder);
$filters = array('parentid' => $current->get('parentid'),
'competencyframeworkid' => $current->get('competencyframeworkid'),
'sortorder' => $sortorder);
$children = self::list_competencies($filters, 'id');
foreach ($children as $needtoswap) {
$needtoswap->set('sortorder', $sortorder + 1);
$needtoswap->update();
}
// OK - all set.
$result = $current->update();
return $result;
}
|
[
"public",
"static",
"function",
"move_up_competency",
"(",
"$",
"id",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"current",
"=",
"new",
"competency",
"(",
"$",
"id",
")",
";",
"// First we do a permissions check.",
"require_capability",
"(",
"'moodle/competency:competencymanage'",
",",
"$",
"current",
"->",
"get_context",
"(",
")",
")",
";",
"$",
"sortorder",
"=",
"$",
"current",
"->",
"get",
"(",
"'sortorder'",
")",
";",
"if",
"(",
"$",
"sortorder",
"==",
"0",
")",
"{",
"return",
"false",
";",
"}",
"$",
"sortorder",
"=",
"$",
"sortorder",
"-",
"1",
";",
"$",
"current",
"->",
"set",
"(",
"'sortorder'",
",",
"$",
"sortorder",
")",
";",
"$",
"filters",
"=",
"array",
"(",
"'parentid'",
"=>",
"$",
"current",
"->",
"get",
"(",
"'parentid'",
")",
",",
"'competencyframeworkid'",
"=>",
"$",
"current",
"->",
"get",
"(",
"'competencyframeworkid'",
")",
",",
"'sortorder'",
"=>",
"$",
"sortorder",
")",
";",
"$",
"children",
"=",
"self",
"::",
"list_competencies",
"(",
"$",
"filters",
",",
"'id'",
")",
";",
"foreach",
"(",
"$",
"children",
"as",
"$",
"needtoswap",
")",
"{",
"$",
"needtoswap",
"->",
"set",
"(",
"'sortorder'",
",",
"$",
"sortorder",
"+",
"1",
")",
";",
"$",
"needtoswap",
"->",
"update",
"(",
")",
";",
"}",
"// OK - all set.",
"$",
"result",
"=",
"$",
"current",
"->",
"update",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
] |
Reorder this competency.
Requires moodle/competency:competencymanage capability at the system context.
@param int $id The id of the competency to move.
@return boolean
|
[
"Reorder",
"this",
"competency",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L322-L350
|
217,212
|
moodle/moodle
|
competency/classes/api.php
|
api.set_parent_competency
|
public static function set_parent_competency($id, $newparentid) {
global $DB;
static::require_enabled();
$current = new competency($id);
// First we do a permissions check.
require_capability('moodle/competency:competencymanage', $current->get_context());
if ($id == $newparentid) {
throw new coding_exception('Can not set a competency as a parent of itself.');
} if ($newparentid == $current->get('parentid')) {
throw new coding_exception('Can not move a competency to the same location.');
}
// Some great variable assignment right here.
$currentparent = $current->get_parent();
$parent = !empty($newparentid) ? new competency($newparentid) : null;
$parentpath = !empty($parent) ? $parent->get('path') : '/0/';
// We're going to change quite a few things.
$transaction = $DB->start_delegated_transaction();
// If we are moving a node to a child of itself:
// - promote all the child nodes by one level.
// - remove the rule on self.
// - re-read the parent.
$newparents = explode('/', $parentpath);
if (in_array($current->get('id'), $newparents)) {
$children = competency::get_records(array('parentid' => $current->get('id')), 'id');
foreach ($children as $child) {
$child->set('parentid', $current->get('parentid'));
$child->update();
}
// Reset the rule on self as our children have changed.
$current->reset_rule();
// The destination parent is one of our descendants, we need to re-fetch its values (path, parentid).
$parent->read();
}
// Reset the rules of initial parent and destination.
if (!empty($currentparent)) {
$currentparent->reset_rule();
$currentparent->update();
}
if (!empty($parent)) {
$parent->reset_rule();
$parent->update();
}
// Do the actual move.
$current->set('parentid', $newparentid);
$result = $current->update();
// All right, let's commit this.
$transaction->allow_commit();
return $result;
}
|
php
|
public static function set_parent_competency($id, $newparentid) {
global $DB;
static::require_enabled();
$current = new competency($id);
// First we do a permissions check.
require_capability('moodle/competency:competencymanage', $current->get_context());
if ($id == $newparentid) {
throw new coding_exception('Can not set a competency as a parent of itself.');
} if ($newparentid == $current->get('parentid')) {
throw new coding_exception('Can not move a competency to the same location.');
}
// Some great variable assignment right here.
$currentparent = $current->get_parent();
$parent = !empty($newparentid) ? new competency($newparentid) : null;
$parentpath = !empty($parent) ? $parent->get('path') : '/0/';
// We're going to change quite a few things.
$transaction = $DB->start_delegated_transaction();
// If we are moving a node to a child of itself:
// - promote all the child nodes by one level.
// - remove the rule on self.
// - re-read the parent.
$newparents = explode('/', $parentpath);
if (in_array($current->get('id'), $newparents)) {
$children = competency::get_records(array('parentid' => $current->get('id')), 'id');
foreach ($children as $child) {
$child->set('parentid', $current->get('parentid'));
$child->update();
}
// Reset the rule on self as our children have changed.
$current->reset_rule();
// The destination parent is one of our descendants, we need to re-fetch its values (path, parentid).
$parent->read();
}
// Reset the rules of initial parent and destination.
if (!empty($currentparent)) {
$currentparent->reset_rule();
$currentparent->update();
}
if (!empty($parent)) {
$parent->reset_rule();
$parent->update();
}
// Do the actual move.
$current->set('parentid', $newparentid);
$result = $current->update();
// All right, let's commit this.
$transaction->allow_commit();
return $result;
}
|
[
"public",
"static",
"function",
"set_parent_competency",
"(",
"$",
"id",
",",
"$",
"newparentid",
")",
"{",
"global",
"$",
"DB",
";",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"current",
"=",
"new",
"competency",
"(",
"$",
"id",
")",
";",
"// First we do a permissions check.",
"require_capability",
"(",
"'moodle/competency:competencymanage'",
",",
"$",
"current",
"->",
"get_context",
"(",
")",
")",
";",
"if",
"(",
"$",
"id",
"==",
"$",
"newparentid",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Can not set a competency as a parent of itself.'",
")",
";",
"}",
"if",
"(",
"$",
"newparentid",
"==",
"$",
"current",
"->",
"get",
"(",
"'parentid'",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Can not move a competency to the same location.'",
")",
";",
"}",
"// Some great variable assignment right here.",
"$",
"currentparent",
"=",
"$",
"current",
"->",
"get_parent",
"(",
")",
";",
"$",
"parent",
"=",
"!",
"empty",
"(",
"$",
"newparentid",
")",
"?",
"new",
"competency",
"(",
"$",
"newparentid",
")",
":",
"null",
";",
"$",
"parentpath",
"=",
"!",
"empty",
"(",
"$",
"parent",
")",
"?",
"$",
"parent",
"->",
"get",
"(",
"'path'",
")",
":",
"'/0/'",
";",
"// We're going to change quite a few things.",
"$",
"transaction",
"=",
"$",
"DB",
"->",
"start_delegated_transaction",
"(",
")",
";",
"// If we are moving a node to a child of itself:",
"// - promote all the child nodes by one level.",
"// - remove the rule on self.",
"// - re-read the parent.",
"$",
"newparents",
"=",
"explode",
"(",
"'/'",
",",
"$",
"parentpath",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"current",
"->",
"get",
"(",
"'id'",
")",
",",
"$",
"newparents",
")",
")",
"{",
"$",
"children",
"=",
"competency",
"::",
"get_records",
"(",
"array",
"(",
"'parentid'",
"=>",
"$",
"current",
"->",
"get",
"(",
"'id'",
")",
")",
",",
"'id'",
")",
";",
"foreach",
"(",
"$",
"children",
"as",
"$",
"child",
")",
"{",
"$",
"child",
"->",
"set",
"(",
"'parentid'",
",",
"$",
"current",
"->",
"get",
"(",
"'parentid'",
")",
")",
";",
"$",
"child",
"->",
"update",
"(",
")",
";",
"}",
"// Reset the rule on self as our children have changed.",
"$",
"current",
"->",
"reset_rule",
"(",
")",
";",
"// The destination parent is one of our descendants, we need to re-fetch its values (path, parentid).",
"$",
"parent",
"->",
"read",
"(",
")",
";",
"}",
"// Reset the rules of initial parent and destination.",
"if",
"(",
"!",
"empty",
"(",
"$",
"currentparent",
")",
")",
"{",
"$",
"currentparent",
"->",
"reset_rule",
"(",
")",
";",
"$",
"currentparent",
"->",
"update",
"(",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"parent",
")",
")",
"{",
"$",
"parent",
"->",
"reset_rule",
"(",
")",
";",
"$",
"parent",
"->",
"update",
"(",
")",
";",
"}",
"// Do the actual move.",
"$",
"current",
"->",
"set",
"(",
"'parentid'",
",",
"$",
"newparentid",
")",
";",
"$",
"result",
"=",
"$",
"current",
"->",
"update",
"(",
")",
";",
"// All right, let's commit this.",
"$",
"transaction",
"->",
"allow_commit",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
] |
Move this competency so it sits in a new parent.
Requires moodle/competency:competencymanage capability at the system context.
@param int $id The id of the competency to move.
@param int $newparentid The new parent id for the competency.
@return boolean
|
[
"Move",
"this",
"competency",
"so",
"it",
"sits",
"in",
"a",
"new",
"parent",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L361-L419
|
217,213
|
moodle/moodle
|
competency/classes/api.php
|
api.update_competency
|
public static function update_competency($record) {
static::require_enabled();
$competency = new competency($record->id);
// First we do a permissions check.
require_capability('moodle/competency:competencymanage', $competency->get_context());
// Some things should not be changed in an update - they should use a more specific method.
$record->sortorder = $competency->get('sortorder');
$record->parentid = $competency->get('parentid');
$record->competencyframeworkid = $competency->get('competencyframeworkid');
$competency->from_record($record);
require_capability('moodle/competency:competencymanage', $competency->get_context());
// OK - all set.
$result = $competency->update();
// Trigger the update event.
\core\event\competency_updated::create_from_competency($competency)->trigger();
return $result;
}
|
php
|
public static function update_competency($record) {
static::require_enabled();
$competency = new competency($record->id);
// First we do a permissions check.
require_capability('moodle/competency:competencymanage', $competency->get_context());
// Some things should not be changed in an update - they should use a more specific method.
$record->sortorder = $competency->get('sortorder');
$record->parentid = $competency->get('parentid');
$record->competencyframeworkid = $competency->get('competencyframeworkid');
$competency->from_record($record);
require_capability('moodle/competency:competencymanage', $competency->get_context());
// OK - all set.
$result = $competency->update();
// Trigger the update event.
\core\event\competency_updated::create_from_competency($competency)->trigger();
return $result;
}
|
[
"public",
"static",
"function",
"update_competency",
"(",
"$",
"record",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"competency",
"=",
"new",
"competency",
"(",
"$",
"record",
"->",
"id",
")",
";",
"// First we do a permissions check.",
"require_capability",
"(",
"'moodle/competency:competencymanage'",
",",
"$",
"competency",
"->",
"get_context",
"(",
")",
")",
";",
"// Some things should not be changed in an update - they should use a more specific method.",
"$",
"record",
"->",
"sortorder",
"=",
"$",
"competency",
"->",
"get",
"(",
"'sortorder'",
")",
";",
"$",
"record",
"->",
"parentid",
"=",
"$",
"competency",
"->",
"get",
"(",
"'parentid'",
")",
";",
"$",
"record",
"->",
"competencyframeworkid",
"=",
"$",
"competency",
"->",
"get",
"(",
"'competencyframeworkid'",
")",
";",
"$",
"competency",
"->",
"from_record",
"(",
"$",
"record",
")",
";",
"require_capability",
"(",
"'moodle/competency:competencymanage'",
",",
"$",
"competency",
"->",
"get_context",
"(",
")",
")",
";",
"// OK - all set.",
"$",
"result",
"=",
"$",
"competency",
"->",
"update",
"(",
")",
";",
"// Trigger the update event.",
"\\",
"core",
"\\",
"event",
"\\",
"competency_updated",
"::",
"create_from_competency",
"(",
"$",
"competency",
")",
"->",
"trigger",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
] |
Update the details for a competency.
Requires moodle/competency:competencymanage capability at the system context.
@param stdClass $record The new details for the competency.
Note - must contain an id that points to the competency to update.
@return boolean
|
[
"Update",
"the",
"details",
"for",
"a",
"competency",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L431-L453
|
217,214
|
moodle/moodle
|
competency/classes/api.php
|
api.read_competency
|
public static function read_competency($id, $includerelated = false) {
static::require_enabled();
$competency = new competency($id);
// First we do a permissions check.
$context = $competency->get_context();
if (!has_any_capability(array('moodle/competency:competencyview', 'moodle/competency:competencymanage'), $context)) {
throw new required_capability_exception($context, 'moodle/competency:competencyview', 'nopermissions', '');
}
// OK - all set.
if ($includerelated) {
$relatedcompetency = new related_competency();
if ($related = $relatedcompetency->list_relations($id)) {
$competency->relatedcompetencies = $related;
}
}
return $competency;
}
|
php
|
public static function read_competency($id, $includerelated = false) {
static::require_enabled();
$competency = new competency($id);
// First we do a permissions check.
$context = $competency->get_context();
if (!has_any_capability(array('moodle/competency:competencyview', 'moodle/competency:competencymanage'), $context)) {
throw new required_capability_exception($context, 'moodle/competency:competencyview', 'nopermissions', '');
}
// OK - all set.
if ($includerelated) {
$relatedcompetency = new related_competency();
if ($related = $relatedcompetency->list_relations($id)) {
$competency->relatedcompetencies = $related;
}
}
return $competency;
}
|
[
"public",
"static",
"function",
"read_competency",
"(",
"$",
"id",
",",
"$",
"includerelated",
"=",
"false",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"competency",
"=",
"new",
"competency",
"(",
"$",
"id",
")",
";",
"// First we do a permissions check.",
"$",
"context",
"=",
"$",
"competency",
"->",
"get_context",
"(",
")",
";",
"if",
"(",
"!",
"has_any_capability",
"(",
"array",
"(",
"'moodle/competency:competencyview'",
",",
"'moodle/competency:competencymanage'",
")",
",",
"$",
"context",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:competencyview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// OK - all set.",
"if",
"(",
"$",
"includerelated",
")",
"{",
"$",
"relatedcompetency",
"=",
"new",
"related_competency",
"(",
")",
";",
"if",
"(",
"$",
"related",
"=",
"$",
"relatedcompetency",
"->",
"list_relations",
"(",
"$",
"id",
")",
")",
"{",
"$",
"competency",
"->",
"relatedcompetencies",
"=",
"$",
"related",
";",
"}",
"}",
"return",
"$",
"competency",
";",
"}"
] |
Read a the details for a single competency and return a record.
Requires moodle/competency:competencyview capability at the system context.
@param int $id The id of the competency to read.
@param bool $includerelated Include related tags or not.
@return stdClass
|
[
"Read",
"a",
"the",
"details",
"for",
"a",
"single",
"competency",
"and",
"return",
"a",
"record",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L464-L483
|
217,215
|
moodle/moodle
|
competency/classes/api.php
|
api.search_competencies
|
public static function search_competencies($textsearch, $competencyframeworkid) {
static::require_enabled();
$framework = new competency_framework($competencyframeworkid);
// First we do a permissions check.
$context = $framework->get_context();
if (!has_any_capability(array('moodle/competency:competencyview', 'moodle/competency:competencymanage'), $context)) {
throw new required_capability_exception($context, 'moodle/competency:competencyview', 'nopermissions', '');
}
// OK - all set.
$competencies = competency::search($textsearch, $competencyframeworkid);
return $competencies;
}
|
php
|
public static function search_competencies($textsearch, $competencyframeworkid) {
static::require_enabled();
$framework = new competency_framework($competencyframeworkid);
// First we do a permissions check.
$context = $framework->get_context();
if (!has_any_capability(array('moodle/competency:competencyview', 'moodle/competency:competencymanage'), $context)) {
throw new required_capability_exception($context, 'moodle/competency:competencyview', 'nopermissions', '');
}
// OK - all set.
$competencies = competency::search($textsearch, $competencyframeworkid);
return $competencies;
}
|
[
"public",
"static",
"function",
"search_competencies",
"(",
"$",
"textsearch",
",",
"$",
"competencyframeworkid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"framework",
"=",
"new",
"competency_framework",
"(",
"$",
"competencyframeworkid",
")",
";",
"// First we do a permissions check.",
"$",
"context",
"=",
"$",
"framework",
"->",
"get_context",
"(",
")",
";",
"if",
"(",
"!",
"has_any_capability",
"(",
"array",
"(",
"'moodle/competency:competencyview'",
",",
"'moodle/competency:competencymanage'",
")",
",",
"$",
"context",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:competencyview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// OK - all set.",
"$",
"competencies",
"=",
"competency",
"::",
"search",
"(",
"$",
"textsearch",
",",
"$",
"competencyframeworkid",
")",
";",
"return",
"$",
"competencies",
";",
"}"
] |
Perform a text search based and return all results and their parents.
Requires moodle/competency:competencyview capability at the framework context.
@param string $textsearch A string to search for.
@param int $competencyframeworkid The id of the framework to limit the search.
@return array of competencies
|
[
"Perform",
"a",
"text",
"search",
"based",
"and",
"return",
"all",
"results",
"and",
"their",
"parents",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L494-L507
|
217,216
|
moodle/moodle
|
competency/classes/api.php
|
api.create_framework
|
public static function create_framework(stdClass $record) {
static::require_enabled();
$framework = new competency_framework(0, $record);
require_capability('moodle/competency:competencymanage', $framework->get_context());
// Account for different formats of taxonomies.
if (isset($record->taxonomies)) {
$framework->set('taxonomies', $record->taxonomies);
}
$framework = $framework->create();
// Trigger a competency framework created event.
\core\event\competency_framework_created::create_from_framework($framework)->trigger();
return $framework;
}
|
php
|
public static function create_framework(stdClass $record) {
static::require_enabled();
$framework = new competency_framework(0, $record);
require_capability('moodle/competency:competencymanage', $framework->get_context());
// Account for different formats of taxonomies.
if (isset($record->taxonomies)) {
$framework->set('taxonomies', $record->taxonomies);
}
$framework = $framework->create();
// Trigger a competency framework created event.
\core\event\competency_framework_created::create_from_framework($framework)->trigger();
return $framework;
}
|
[
"public",
"static",
"function",
"create_framework",
"(",
"stdClass",
"$",
"record",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"framework",
"=",
"new",
"competency_framework",
"(",
"0",
",",
"$",
"record",
")",
";",
"require_capability",
"(",
"'moodle/competency:competencymanage'",
",",
"$",
"framework",
"->",
"get_context",
"(",
")",
")",
";",
"// Account for different formats of taxonomies.",
"if",
"(",
"isset",
"(",
"$",
"record",
"->",
"taxonomies",
")",
")",
"{",
"$",
"framework",
"->",
"set",
"(",
"'taxonomies'",
",",
"$",
"record",
"->",
"taxonomies",
")",
";",
"}",
"$",
"framework",
"=",
"$",
"framework",
"->",
"create",
"(",
")",
";",
"// Trigger a competency framework created event.",
"\\",
"core",
"\\",
"event",
"\\",
"competency_framework_created",
"::",
"create_from_framework",
"(",
"$",
"framework",
")",
"->",
"trigger",
"(",
")",
";",
"return",
"$",
"framework",
";",
"}"
] |
Create a competency framework from a record containing all the data for the class.
Requires moodle/competency:competencymanage capability at the system context.
@param stdClass $record Record containing all the data for an instance of the class.
@return competency_framework
|
[
"Create",
"a",
"competency",
"framework",
"from",
"a",
"record",
"containing",
"all",
"the",
"data",
"for",
"the",
"class",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L573-L589
|
217,217
|
moodle/moodle
|
competency/classes/api.php
|
api.duplicate_framework
|
public static function duplicate_framework($id) {
global $DB;
static::require_enabled();
$framework = new competency_framework($id);
require_capability('moodle/competency:competencymanage', $framework->get_context());
// Starting transaction.
$transaction = $DB->start_delegated_transaction();
try {
// Get a uniq idnumber based on the origin framework.
$idnumber = competency_framework::get_unused_idnumber($framework->get('idnumber'));
$framework->set('idnumber', $idnumber);
// Adding the suffix copy to the shortname.
$framework->set('shortname', get_string('duplicateditemname', 'core_competency', $framework->get('shortname')));
$framework->set('id', 0);
$framework = $framework->create();
// Array that match the old competencies ids with the new one to use when copying related competencies.
$frameworkcompetency = competency::get_framework_tree($id);
$matchids = self::duplicate_competency_tree($framework->get('id'), $frameworkcompetency, 0, 0);
// Copy the related competencies.
$relcomps = related_competency::get_multiple_relations(array_keys($matchids));
foreach ($relcomps as $relcomp) {
$compid = $relcomp->get('competencyid');
$relcompid = $relcomp->get('relatedcompetencyid');
if (isset($matchids[$compid]) && isset($matchids[$relcompid])) {
$newcompid = $matchids[$compid]->get('id');
$newrelcompid = $matchids[$relcompid]->get('id');
if ($newcompid < $newrelcompid) {
$relcomp->set('competencyid', $newcompid);
$relcomp->set('relatedcompetencyid', $newrelcompid);
} else {
$relcomp->set('competencyid', $newrelcompid);
$relcomp->set('relatedcompetencyid', $newcompid);
}
$relcomp->set('id', 0);
$relcomp->create();
} else {
// Debugging message when there is no match found.
debugging('related competency id not found');
}
}
// Setting rules on duplicated competencies.
self::migrate_competency_tree_rules($frameworkcompetency, $matchids);
$transaction->allow_commit();
} catch (\Exception $e) {
$transaction->rollback($e);
}
// Trigger a competency framework created event.
\core\event\competency_framework_created::create_from_framework($framework)->trigger();
return $framework;
}
|
php
|
public static function duplicate_framework($id) {
global $DB;
static::require_enabled();
$framework = new competency_framework($id);
require_capability('moodle/competency:competencymanage', $framework->get_context());
// Starting transaction.
$transaction = $DB->start_delegated_transaction();
try {
// Get a uniq idnumber based on the origin framework.
$idnumber = competency_framework::get_unused_idnumber($framework->get('idnumber'));
$framework->set('idnumber', $idnumber);
// Adding the suffix copy to the shortname.
$framework->set('shortname', get_string('duplicateditemname', 'core_competency', $framework->get('shortname')));
$framework->set('id', 0);
$framework = $framework->create();
// Array that match the old competencies ids with the new one to use when copying related competencies.
$frameworkcompetency = competency::get_framework_tree($id);
$matchids = self::duplicate_competency_tree($framework->get('id'), $frameworkcompetency, 0, 0);
// Copy the related competencies.
$relcomps = related_competency::get_multiple_relations(array_keys($matchids));
foreach ($relcomps as $relcomp) {
$compid = $relcomp->get('competencyid');
$relcompid = $relcomp->get('relatedcompetencyid');
if (isset($matchids[$compid]) && isset($matchids[$relcompid])) {
$newcompid = $matchids[$compid]->get('id');
$newrelcompid = $matchids[$relcompid]->get('id');
if ($newcompid < $newrelcompid) {
$relcomp->set('competencyid', $newcompid);
$relcomp->set('relatedcompetencyid', $newrelcompid);
} else {
$relcomp->set('competencyid', $newrelcompid);
$relcomp->set('relatedcompetencyid', $newcompid);
}
$relcomp->set('id', 0);
$relcomp->create();
} else {
// Debugging message when there is no match found.
debugging('related competency id not found');
}
}
// Setting rules on duplicated competencies.
self::migrate_competency_tree_rules($frameworkcompetency, $matchids);
$transaction->allow_commit();
} catch (\Exception $e) {
$transaction->rollback($e);
}
// Trigger a competency framework created event.
\core\event\competency_framework_created::create_from_framework($framework)->trigger();
return $framework;
}
|
[
"public",
"static",
"function",
"duplicate_framework",
"(",
"$",
"id",
")",
"{",
"global",
"$",
"DB",
";",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"framework",
"=",
"new",
"competency_framework",
"(",
"$",
"id",
")",
";",
"require_capability",
"(",
"'moodle/competency:competencymanage'",
",",
"$",
"framework",
"->",
"get_context",
"(",
")",
")",
";",
"// Starting transaction.",
"$",
"transaction",
"=",
"$",
"DB",
"->",
"start_delegated_transaction",
"(",
")",
";",
"try",
"{",
"// Get a uniq idnumber based on the origin framework.",
"$",
"idnumber",
"=",
"competency_framework",
"::",
"get_unused_idnumber",
"(",
"$",
"framework",
"->",
"get",
"(",
"'idnumber'",
")",
")",
";",
"$",
"framework",
"->",
"set",
"(",
"'idnumber'",
",",
"$",
"idnumber",
")",
";",
"// Adding the suffix copy to the shortname.",
"$",
"framework",
"->",
"set",
"(",
"'shortname'",
",",
"get_string",
"(",
"'duplicateditemname'",
",",
"'core_competency'",
",",
"$",
"framework",
"->",
"get",
"(",
"'shortname'",
")",
")",
")",
";",
"$",
"framework",
"->",
"set",
"(",
"'id'",
",",
"0",
")",
";",
"$",
"framework",
"=",
"$",
"framework",
"->",
"create",
"(",
")",
";",
"// Array that match the old competencies ids with the new one to use when copying related competencies.",
"$",
"frameworkcompetency",
"=",
"competency",
"::",
"get_framework_tree",
"(",
"$",
"id",
")",
";",
"$",
"matchids",
"=",
"self",
"::",
"duplicate_competency_tree",
"(",
"$",
"framework",
"->",
"get",
"(",
"'id'",
")",
",",
"$",
"frameworkcompetency",
",",
"0",
",",
"0",
")",
";",
"// Copy the related competencies.",
"$",
"relcomps",
"=",
"related_competency",
"::",
"get_multiple_relations",
"(",
"array_keys",
"(",
"$",
"matchids",
")",
")",
";",
"foreach",
"(",
"$",
"relcomps",
"as",
"$",
"relcomp",
")",
"{",
"$",
"compid",
"=",
"$",
"relcomp",
"->",
"get",
"(",
"'competencyid'",
")",
";",
"$",
"relcompid",
"=",
"$",
"relcomp",
"->",
"get",
"(",
"'relatedcompetencyid'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"matchids",
"[",
"$",
"compid",
"]",
")",
"&&",
"isset",
"(",
"$",
"matchids",
"[",
"$",
"relcompid",
"]",
")",
")",
"{",
"$",
"newcompid",
"=",
"$",
"matchids",
"[",
"$",
"compid",
"]",
"->",
"get",
"(",
"'id'",
")",
";",
"$",
"newrelcompid",
"=",
"$",
"matchids",
"[",
"$",
"relcompid",
"]",
"->",
"get",
"(",
"'id'",
")",
";",
"if",
"(",
"$",
"newcompid",
"<",
"$",
"newrelcompid",
")",
"{",
"$",
"relcomp",
"->",
"set",
"(",
"'competencyid'",
",",
"$",
"newcompid",
")",
";",
"$",
"relcomp",
"->",
"set",
"(",
"'relatedcompetencyid'",
",",
"$",
"newrelcompid",
")",
";",
"}",
"else",
"{",
"$",
"relcomp",
"->",
"set",
"(",
"'competencyid'",
",",
"$",
"newrelcompid",
")",
";",
"$",
"relcomp",
"->",
"set",
"(",
"'relatedcompetencyid'",
",",
"$",
"newcompid",
")",
";",
"}",
"$",
"relcomp",
"->",
"set",
"(",
"'id'",
",",
"0",
")",
";",
"$",
"relcomp",
"->",
"create",
"(",
")",
";",
"}",
"else",
"{",
"// Debugging message when there is no match found.",
"debugging",
"(",
"'related competency id not found'",
")",
";",
"}",
"}",
"// Setting rules on duplicated competencies.",
"self",
"::",
"migrate_competency_tree_rules",
"(",
"$",
"frameworkcompetency",
",",
"$",
"matchids",
")",
";",
"$",
"transaction",
"->",
"allow_commit",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"transaction",
"->",
"rollback",
"(",
"$",
"e",
")",
";",
"}",
"// Trigger a competency framework created event.",
"\\",
"core",
"\\",
"event",
"\\",
"competency_framework_created",
"::",
"create_from_framework",
"(",
"$",
"framework",
")",
"->",
"trigger",
"(",
")",
";",
"return",
"$",
"framework",
";",
"}"
] |
Duplicate a competency framework by id.
Requires moodle/competency:competencymanage capability at the system context.
@param int $id The record to duplicate. All competencies associated and related will be duplicated.
@return competency_framework the framework duplicated
|
[
"Duplicate",
"a",
"competency",
"framework",
"by",
"id",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L599-L658
|
217,218
|
moodle/moodle
|
competency/classes/api.php
|
api.delete_framework
|
public static function delete_framework($id) {
global $DB;
static::require_enabled();
$framework = new competency_framework($id);
require_capability('moodle/competency:competencymanage', $framework->get_context());
$events = array();
$competenciesid = competency::get_ids_by_frameworkid($id);
$contextid = $framework->get('contextid');
if (!competency::can_all_be_deleted($competenciesid)) {
return false;
}
$transaction = $DB->start_delegated_transaction();
try {
if (!empty($competenciesid)) {
// Delete competencies.
competency::delete_by_frameworkid($id);
// Delete the related competencies.
related_competency::delete_multiple_relations($competenciesid);
// Delete the evidences for competencies.
user_evidence_competency::delete_by_competencyids($competenciesid);
}
// Create a competency framework deleted event.
$event = \core\event\competency_framework_deleted::create_from_framework($framework);
$result = $framework->delete();
// Register the deleted events competencies.
$events = \core\event\competency_deleted::create_multiple_from_competencyids($competenciesid, $contextid);
} catch (\Exception $e) {
$transaction->rollback($e);
}
// Commit the transaction.
$transaction->allow_commit();
// If all operations are successfull then trigger the delete event.
$event->trigger();
// Trigger deleted event competencies.
foreach ($events as $event) {
$event->trigger();
}
return $result;
}
|
php
|
public static function delete_framework($id) {
global $DB;
static::require_enabled();
$framework = new competency_framework($id);
require_capability('moodle/competency:competencymanage', $framework->get_context());
$events = array();
$competenciesid = competency::get_ids_by_frameworkid($id);
$contextid = $framework->get('contextid');
if (!competency::can_all_be_deleted($competenciesid)) {
return false;
}
$transaction = $DB->start_delegated_transaction();
try {
if (!empty($competenciesid)) {
// Delete competencies.
competency::delete_by_frameworkid($id);
// Delete the related competencies.
related_competency::delete_multiple_relations($competenciesid);
// Delete the evidences for competencies.
user_evidence_competency::delete_by_competencyids($competenciesid);
}
// Create a competency framework deleted event.
$event = \core\event\competency_framework_deleted::create_from_framework($framework);
$result = $framework->delete();
// Register the deleted events competencies.
$events = \core\event\competency_deleted::create_multiple_from_competencyids($competenciesid, $contextid);
} catch (\Exception $e) {
$transaction->rollback($e);
}
// Commit the transaction.
$transaction->allow_commit();
// If all operations are successfull then trigger the delete event.
$event->trigger();
// Trigger deleted event competencies.
foreach ($events as $event) {
$event->trigger();
}
return $result;
}
|
[
"public",
"static",
"function",
"delete_framework",
"(",
"$",
"id",
")",
"{",
"global",
"$",
"DB",
";",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"framework",
"=",
"new",
"competency_framework",
"(",
"$",
"id",
")",
";",
"require_capability",
"(",
"'moodle/competency:competencymanage'",
",",
"$",
"framework",
"->",
"get_context",
"(",
")",
")",
";",
"$",
"events",
"=",
"array",
"(",
")",
";",
"$",
"competenciesid",
"=",
"competency",
"::",
"get_ids_by_frameworkid",
"(",
"$",
"id",
")",
";",
"$",
"contextid",
"=",
"$",
"framework",
"->",
"get",
"(",
"'contextid'",
")",
";",
"if",
"(",
"!",
"competency",
"::",
"can_all_be_deleted",
"(",
"$",
"competenciesid",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"transaction",
"=",
"$",
"DB",
"->",
"start_delegated_transaction",
"(",
")",
";",
"try",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"competenciesid",
")",
")",
"{",
"// Delete competencies.",
"competency",
"::",
"delete_by_frameworkid",
"(",
"$",
"id",
")",
";",
"// Delete the related competencies.",
"related_competency",
"::",
"delete_multiple_relations",
"(",
"$",
"competenciesid",
")",
";",
"// Delete the evidences for competencies.",
"user_evidence_competency",
"::",
"delete_by_competencyids",
"(",
"$",
"competenciesid",
")",
";",
"}",
"// Create a competency framework deleted event.",
"$",
"event",
"=",
"\\",
"core",
"\\",
"event",
"\\",
"competency_framework_deleted",
"::",
"create_from_framework",
"(",
"$",
"framework",
")",
";",
"$",
"result",
"=",
"$",
"framework",
"->",
"delete",
"(",
")",
";",
"// Register the deleted events competencies.",
"$",
"events",
"=",
"\\",
"core",
"\\",
"event",
"\\",
"competency_deleted",
"::",
"create_multiple_from_competencyids",
"(",
"$",
"competenciesid",
",",
"$",
"contextid",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"transaction",
"->",
"rollback",
"(",
"$",
"e",
")",
";",
"}",
"// Commit the transaction.",
"$",
"transaction",
"->",
"allow_commit",
"(",
")",
";",
"// If all operations are successfull then trigger the delete event.",
"$",
"event",
"->",
"trigger",
"(",
")",
";",
"// Trigger deleted event competencies.",
"foreach",
"(",
"$",
"events",
"as",
"$",
"event",
")",
"{",
"$",
"event",
"->",
"trigger",
"(",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Delete a competency framework by id.
Requires moodle/competency:competencymanage capability at the system context.
@param int $id The record to delete. This will delete alot of related data - you better be sure.
@return boolean
|
[
"Delete",
"a",
"competency",
"framework",
"by",
"id",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L668-L716
|
217,219
|
moodle/moodle
|
competency/classes/api.php
|
api.update_framework
|
public static function update_framework($record) {
static::require_enabled();
$framework = new competency_framework($record->id);
// Check the permissions before update.
require_capability('moodle/competency:competencymanage', $framework->get_context());
// Account for different formats of taxonomies.
$framework->from_record($record);
if (isset($record->taxonomies)) {
$framework->set('taxonomies', $record->taxonomies);
}
// Trigger a competency framework updated event.
\core\event\competency_framework_updated::create_from_framework($framework)->trigger();
return $framework->update();
}
|
php
|
public static function update_framework($record) {
static::require_enabled();
$framework = new competency_framework($record->id);
// Check the permissions before update.
require_capability('moodle/competency:competencymanage', $framework->get_context());
// Account for different formats of taxonomies.
$framework->from_record($record);
if (isset($record->taxonomies)) {
$framework->set('taxonomies', $record->taxonomies);
}
// Trigger a competency framework updated event.
\core\event\competency_framework_updated::create_from_framework($framework)->trigger();
return $framework->update();
}
|
[
"public",
"static",
"function",
"update_framework",
"(",
"$",
"record",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"framework",
"=",
"new",
"competency_framework",
"(",
"$",
"record",
"->",
"id",
")",
";",
"// Check the permissions before update.",
"require_capability",
"(",
"'moodle/competency:competencymanage'",
",",
"$",
"framework",
"->",
"get_context",
"(",
")",
")",
";",
"// Account for different formats of taxonomies.",
"$",
"framework",
"->",
"from_record",
"(",
"$",
"record",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"record",
"->",
"taxonomies",
")",
")",
"{",
"$",
"framework",
"->",
"set",
"(",
"'taxonomies'",
",",
"$",
"record",
"->",
"taxonomies",
")",
";",
"}",
"// Trigger a competency framework updated event.",
"\\",
"core",
"\\",
"event",
"\\",
"competency_framework_updated",
"::",
"create_from_framework",
"(",
"$",
"framework",
")",
"->",
"trigger",
"(",
")",
";",
"return",
"$",
"framework",
"->",
"update",
"(",
")",
";",
"}"
] |
Update the details for a competency framework.
Requires moodle/competency:competencymanage capability at the system context.
@param stdClass $record The new details for the framework. Note - must contain an id that points to the framework to update.
@return boolean
|
[
"Update",
"the",
"details",
"for",
"a",
"competency",
"framework",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L726-L743
|
217,220
|
moodle/moodle
|
competency/classes/api.php
|
api.read_framework
|
public static function read_framework($id) {
static::require_enabled();
$framework = new competency_framework($id);
if (!has_any_capability(array('moodle/competency:competencyview', 'moodle/competency:competencymanage'),
$framework->get_context())) {
throw new required_capability_exception($framework->get_context(), 'moodle/competency:competencyview',
'nopermissions', '');
}
return $framework;
}
|
php
|
public static function read_framework($id) {
static::require_enabled();
$framework = new competency_framework($id);
if (!has_any_capability(array('moodle/competency:competencyview', 'moodle/competency:competencymanage'),
$framework->get_context())) {
throw new required_capability_exception($framework->get_context(), 'moodle/competency:competencyview',
'nopermissions', '');
}
return $framework;
}
|
[
"public",
"static",
"function",
"read_framework",
"(",
"$",
"id",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"framework",
"=",
"new",
"competency_framework",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"has_any_capability",
"(",
"array",
"(",
"'moodle/competency:competencyview'",
",",
"'moodle/competency:competencymanage'",
")",
",",
"$",
"framework",
"->",
"get_context",
"(",
")",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"framework",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:competencyview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"return",
"$",
"framework",
";",
"}"
] |
Read a the details for a single competency framework and return a record.
Requires moodle/competency:competencyview capability at the system context.
@param int $id The id of the framework to read.
@return competency_framework
|
[
"Read",
"a",
"the",
"details",
"for",
"a",
"single",
"competency",
"framework",
"and",
"return",
"a",
"record",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L753-L762
|
217,221
|
moodle/moodle
|
competency/classes/api.php
|
api.competency_framework_viewed
|
public static function competency_framework_viewed($frameworkorid) {
static::require_enabled();
$framework = $frameworkorid;
if (!is_object($framework)) {
$framework = new competency_framework($framework);
}
if (!has_any_capability(array('moodle/competency:competencyview', 'moodle/competency:competencymanage'),
$framework->get_context())) {
throw new required_capability_exception($framework->get_context(), 'moodle/competency:competencyview',
'nopermissions', '');
}
\core\event\competency_framework_viewed::create_from_framework($framework)->trigger();
return true;
}
|
php
|
public static function competency_framework_viewed($frameworkorid) {
static::require_enabled();
$framework = $frameworkorid;
if (!is_object($framework)) {
$framework = new competency_framework($framework);
}
if (!has_any_capability(array('moodle/competency:competencyview', 'moodle/competency:competencymanage'),
$framework->get_context())) {
throw new required_capability_exception($framework->get_context(), 'moodle/competency:competencyview',
'nopermissions', '');
}
\core\event\competency_framework_viewed::create_from_framework($framework)->trigger();
return true;
}
|
[
"public",
"static",
"function",
"competency_framework_viewed",
"(",
"$",
"frameworkorid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"framework",
"=",
"$",
"frameworkorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"framework",
")",
")",
"{",
"$",
"framework",
"=",
"new",
"competency_framework",
"(",
"$",
"framework",
")",
";",
"}",
"if",
"(",
"!",
"has_any_capability",
"(",
"array",
"(",
"'moodle/competency:competencyview'",
",",
"'moodle/competency:competencymanage'",
")",
",",
"$",
"framework",
"->",
"get_context",
"(",
")",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"framework",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:competencyview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"\\",
"core",
"\\",
"event",
"\\",
"competency_framework_viewed",
"::",
"create_from_framework",
"(",
"$",
"framework",
")",
"->",
"trigger",
"(",
")",
";",
"return",
"true",
";",
"}"
] |
Logg the competency framework viewed event.
@param competency_framework|int $frameworkorid The competency_framework object or competency framework id
@return bool
|
[
"Logg",
"the",
"competency",
"framework",
"viewed",
"event",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L770-L783
|
217,222
|
moodle/moodle
|
competency/classes/api.php
|
api.competency_viewed
|
public static function competency_viewed($competencyorid) {
static::require_enabled();
$competency = $competencyorid;
if (!is_object($competency)) {
$competency = new competency($competency);
}
if (!has_any_capability(array('moodle/competency:competencyview', 'moodle/competency:competencymanage'),
$competency->get_context())) {
throw new required_capability_exception($competency->get_context(), 'moodle/competency:competencyview',
'nopermissions', '');
}
\core\event\competency_viewed::create_from_competency($competency)->trigger();
return true;
}
|
php
|
public static function competency_viewed($competencyorid) {
static::require_enabled();
$competency = $competencyorid;
if (!is_object($competency)) {
$competency = new competency($competency);
}
if (!has_any_capability(array('moodle/competency:competencyview', 'moodle/competency:competencymanage'),
$competency->get_context())) {
throw new required_capability_exception($competency->get_context(), 'moodle/competency:competencyview',
'nopermissions', '');
}
\core\event\competency_viewed::create_from_competency($competency)->trigger();
return true;
}
|
[
"public",
"static",
"function",
"competency_viewed",
"(",
"$",
"competencyorid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"competency",
"=",
"$",
"competencyorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"competency",
")",
")",
"{",
"$",
"competency",
"=",
"new",
"competency",
"(",
"$",
"competency",
")",
";",
"}",
"if",
"(",
"!",
"has_any_capability",
"(",
"array",
"(",
"'moodle/competency:competencyview'",
",",
"'moodle/competency:competencymanage'",
")",
",",
"$",
"competency",
"->",
"get_context",
"(",
")",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"competency",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:competencyview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"\\",
"core",
"\\",
"event",
"\\",
"competency_viewed",
"::",
"create_from_competency",
"(",
"$",
"competency",
")",
"->",
"trigger",
"(",
")",
";",
"return",
"true",
";",
"}"
] |
Logg the competency viewed event.
@param competency|int $competencyorid The competency object or competency id
@return bool
|
[
"Logg",
"the",
"competency",
"viewed",
"event",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L791-L806
|
217,223
|
moodle/moodle
|
competency/classes/api.php
|
api.get_related_contexts
|
public static function get_related_contexts($context, $includes, array $hasanycapability = null) {
global $DB;
static::require_enabled();
if (!in_array($includes, array('children', 'parents', 'self'))) {
throw new coding_exception('Invalid parameter value for \'includes\'.');
}
// If context user swap it for the context_system.
if ($context->contextlevel == CONTEXT_USER) {
$context = context_system::instance();
}
$contexts = array($context->id => $context);
if ($includes == 'children') {
$params = array('coursecatlevel' => CONTEXT_COURSECAT, 'path' => $context->path . '/%');
$pathlike = $DB->sql_like('path', ':path');
$sql = "contextlevel = :coursecatlevel AND $pathlike";
$rs = $DB->get_recordset_select('context', $sql, $params);
foreach ($rs as $record) {
$ctxid = $record->id;
context_helper::preload_from_record($record);
$contexts[$ctxid] = context::instance_by_id($ctxid);
}
$rs->close();
} else if ($includes == 'parents') {
$children = $context->get_parent_contexts();
foreach ($children as $ctx) {
$contexts[$ctx->id] = $ctx;
}
}
// Filter according to the capabilities required.
if (!empty($hasanycapability)) {
foreach ($contexts as $key => $ctx) {
if (!has_any_capability($hasanycapability, $ctx)) {
unset($contexts[$key]);
}
}
}
return $contexts;
}
|
php
|
public static function get_related_contexts($context, $includes, array $hasanycapability = null) {
global $DB;
static::require_enabled();
if (!in_array($includes, array('children', 'parents', 'self'))) {
throw new coding_exception('Invalid parameter value for \'includes\'.');
}
// If context user swap it for the context_system.
if ($context->contextlevel == CONTEXT_USER) {
$context = context_system::instance();
}
$contexts = array($context->id => $context);
if ($includes == 'children') {
$params = array('coursecatlevel' => CONTEXT_COURSECAT, 'path' => $context->path . '/%');
$pathlike = $DB->sql_like('path', ':path');
$sql = "contextlevel = :coursecatlevel AND $pathlike";
$rs = $DB->get_recordset_select('context', $sql, $params);
foreach ($rs as $record) {
$ctxid = $record->id;
context_helper::preload_from_record($record);
$contexts[$ctxid] = context::instance_by_id($ctxid);
}
$rs->close();
} else if ($includes == 'parents') {
$children = $context->get_parent_contexts();
foreach ($children as $ctx) {
$contexts[$ctx->id] = $ctx;
}
}
// Filter according to the capabilities required.
if (!empty($hasanycapability)) {
foreach ($contexts as $key => $ctx) {
if (!has_any_capability($hasanycapability, $ctx)) {
unset($contexts[$key]);
}
}
}
return $contexts;
}
|
[
"public",
"static",
"function",
"get_related_contexts",
"(",
"$",
"context",
",",
"$",
"includes",
",",
"array",
"$",
"hasanycapability",
"=",
"null",
")",
"{",
"global",
"$",
"DB",
";",
"static",
"::",
"require_enabled",
"(",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"includes",
",",
"array",
"(",
"'children'",
",",
"'parents'",
",",
"'self'",
")",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Invalid parameter value for \\'includes\\'.'",
")",
";",
"}",
"// If context user swap it for the context_system.",
"if",
"(",
"$",
"context",
"->",
"contextlevel",
"==",
"CONTEXT_USER",
")",
"{",
"$",
"context",
"=",
"context_system",
"::",
"instance",
"(",
")",
";",
"}",
"$",
"contexts",
"=",
"array",
"(",
"$",
"context",
"->",
"id",
"=>",
"$",
"context",
")",
";",
"if",
"(",
"$",
"includes",
"==",
"'children'",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"'coursecatlevel'",
"=>",
"CONTEXT_COURSECAT",
",",
"'path'",
"=>",
"$",
"context",
"->",
"path",
".",
"'/%'",
")",
";",
"$",
"pathlike",
"=",
"$",
"DB",
"->",
"sql_like",
"(",
"'path'",
",",
"':path'",
")",
";",
"$",
"sql",
"=",
"\"contextlevel = :coursecatlevel AND $pathlike\"",
";",
"$",
"rs",
"=",
"$",
"DB",
"->",
"get_recordset_select",
"(",
"'context'",
",",
"$",
"sql",
",",
"$",
"params",
")",
";",
"foreach",
"(",
"$",
"rs",
"as",
"$",
"record",
")",
"{",
"$",
"ctxid",
"=",
"$",
"record",
"->",
"id",
";",
"context_helper",
"::",
"preload_from_record",
"(",
"$",
"record",
")",
";",
"$",
"contexts",
"[",
"$",
"ctxid",
"]",
"=",
"context",
"::",
"instance_by_id",
"(",
"$",
"ctxid",
")",
";",
"}",
"$",
"rs",
"->",
"close",
"(",
")",
";",
"}",
"else",
"if",
"(",
"$",
"includes",
"==",
"'parents'",
")",
"{",
"$",
"children",
"=",
"$",
"context",
"->",
"get_parent_contexts",
"(",
")",
";",
"foreach",
"(",
"$",
"children",
"as",
"$",
"ctx",
")",
"{",
"$",
"contexts",
"[",
"$",
"ctx",
"->",
"id",
"]",
"=",
"$",
"ctx",
";",
"}",
"}",
"// Filter according to the capabilities required.",
"if",
"(",
"!",
"empty",
"(",
"$",
"hasanycapability",
")",
")",
"{",
"foreach",
"(",
"$",
"contexts",
"as",
"$",
"key",
"=>",
"$",
"ctx",
")",
"{",
"if",
"(",
"!",
"has_any_capability",
"(",
"$",
"hasanycapability",
",",
"$",
"ctx",
")",
")",
"{",
"unset",
"(",
"$",
"contexts",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"}",
"return",
"$",
"contexts",
";",
"}"
] |
Fetches all the relevant contexts.
Note: This currently only supports system, category and user contexts. However user contexts
behave a bit differently and will fallback on the system context. This is what makes the most
sense because a user context does not have descendants, and only has system as a parent.
@param context $context The context to start from.
@param string $includes Defines what other contexts to find.
Accepted values are:
- children: All descendants
- parents: All parents, grand parents, etc...
- self: Context passed only.
@param array $hasanycapability Array of capabilities passed to {@link has_any_capability()} in each context.
@return context[] An array of contexts where keys are context IDs.
|
[
"Fetches",
"all",
"the",
"relevant",
"contexts",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L906-L950
|
217,224
|
moodle/moodle
|
competency/classes/api.php
|
api.count_courses_using_competency
|
public static function count_courses_using_competency($competencyid) {
static::require_enabled();
// OK - all set.
$courses = course_competency::list_courses_min($competencyid);
$count = 0;
// Now check permissions on each course.
foreach ($courses as $course) {
if (!self::validate_course($course, false)) {
continue;
}
$context = context_course::instance($course->id);
$capabilities = array('moodle/competency:coursecompetencyview', 'moodle/competency:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) {
continue;
}
$count++;
}
return $count;
}
|
php
|
public static function count_courses_using_competency($competencyid) {
static::require_enabled();
// OK - all set.
$courses = course_competency::list_courses_min($competencyid);
$count = 0;
// Now check permissions on each course.
foreach ($courses as $course) {
if (!self::validate_course($course, false)) {
continue;
}
$context = context_course::instance($course->id);
$capabilities = array('moodle/competency:coursecompetencyview', 'moodle/competency:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) {
continue;
}
$count++;
}
return $count;
}
|
[
"public",
"static",
"function",
"count_courses_using_competency",
"(",
"$",
"competencyid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"// OK - all set.",
"$",
"courses",
"=",
"course_competency",
"::",
"list_courses_min",
"(",
"$",
"competencyid",
")",
";",
"$",
"count",
"=",
"0",
";",
"// Now check permissions on each course.",
"foreach",
"(",
"$",
"courses",
"as",
"$",
"course",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"validate_course",
"(",
"$",
"course",
",",
"false",
")",
")",
"{",
"continue",
";",
"}",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"course",
"->",
"id",
")",
";",
"$",
"capabilities",
"=",
"array",
"(",
"'moodle/competency:coursecompetencyview'",
",",
"'moodle/competency:coursecompetencymanage'",
")",
";",
"if",
"(",
"!",
"has_any_capability",
"(",
"$",
"capabilities",
",",
"$",
"context",
")",
")",
"{",
"continue",
";",
"}",
"$",
"count",
"++",
";",
"}",
"return",
"$",
"count",
";",
"}"
] |
Count all the courses using a competency.
@param int $competencyid The id of the competency to check.
@return int
|
[
"Count",
"all",
"the",
"courses",
"using",
"a",
"competency",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L958-L981
|
217,225
|
moodle/moodle
|
competency/classes/api.php
|
api.list_course_modules_using_competency
|
public static function list_course_modules_using_competency($competencyid, $courseid) {
static::require_enabled();
$result = array();
self::validate_course($courseid);
$coursecontext = context_course::instance($courseid);
// We will not check each module - course permissions should be enough.
$capabilities = array('moodle/competency:coursecompetencyview', 'moodle/competency:coursecompetencymanage');
if (!has_any_capability($capabilities, $coursecontext)) {
throw new required_capability_exception($coursecontext, 'moodle/competency:coursecompetencyview', 'nopermissions', '');
}
$cmlist = course_module_competency::list_course_modules($competencyid, $courseid);
foreach ($cmlist as $cmid) {
if (self::validate_course_module($cmid, false)) {
array_push($result, $cmid);
}
}
return $result;
}
|
php
|
public static function list_course_modules_using_competency($competencyid, $courseid) {
static::require_enabled();
$result = array();
self::validate_course($courseid);
$coursecontext = context_course::instance($courseid);
// We will not check each module - course permissions should be enough.
$capabilities = array('moodle/competency:coursecompetencyview', 'moodle/competency:coursecompetencymanage');
if (!has_any_capability($capabilities, $coursecontext)) {
throw new required_capability_exception($coursecontext, 'moodle/competency:coursecompetencyview', 'nopermissions', '');
}
$cmlist = course_module_competency::list_course_modules($competencyid, $courseid);
foreach ($cmlist as $cmid) {
if (self::validate_course_module($cmid, false)) {
array_push($result, $cmid);
}
}
return $result;
}
|
[
"public",
"static",
"function",
"list_course_modules_using_competency",
"(",
"$",
"competencyid",
",",
"$",
"courseid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"self",
"::",
"validate_course",
"(",
"$",
"courseid",
")",
";",
"$",
"coursecontext",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"courseid",
")",
";",
"// We will not check each module - course permissions should be enough.",
"$",
"capabilities",
"=",
"array",
"(",
"'moodle/competency:coursecompetencyview'",
",",
"'moodle/competency:coursecompetencymanage'",
")",
";",
"if",
"(",
"!",
"has_any_capability",
"(",
"$",
"capabilities",
",",
"$",
"coursecontext",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"coursecontext",
",",
"'moodle/competency:coursecompetencyview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"$",
"cmlist",
"=",
"course_module_competency",
"::",
"list_course_modules",
"(",
"$",
"competencyid",
",",
"$",
"courseid",
")",
";",
"foreach",
"(",
"$",
"cmlist",
"as",
"$",
"cmid",
")",
"{",
"if",
"(",
"self",
"::",
"validate_course_module",
"(",
"$",
"cmid",
",",
"false",
")",
")",
"{",
"array_push",
"(",
"$",
"result",
",",
"$",
"cmid",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] |
List all the courses modules using a competency in a course.
@param int $competencyid The id of the competency to check.
@param int $courseid The id of the course to check.
@return array[int] Array of course modules ids.
|
[
"List",
"all",
"the",
"courses",
"modules",
"using",
"a",
"competency",
"in",
"a",
"course",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L990-L1012
|
217,226
|
moodle/moodle
|
competency/classes/api.php
|
api.list_course_module_competencies_in_course_module
|
public static function list_course_module_competencies_in_course_module($cmorid) {
static::require_enabled();
$cm = $cmorid;
if (!is_object($cmorid)) {
$cm = get_coursemodule_from_id('', $cmorid, 0, true, MUST_EXIST);
}
// Check the user have access to the course module.
self::validate_course_module($cm);
$context = context_module::instance($cm->id);
$capabilities = array('moodle/competency:coursecompetencyview', 'moodle/competency:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'moodle/competency:coursecompetencyview', 'nopermissions', '');
}
$result = array();
$cmclist = course_module_competency::list_course_module_competencies($cm->id);
foreach ($cmclist as $id => $cmc) {
array_push($result, $cmc);
}
return $result;
}
|
php
|
public static function list_course_module_competencies_in_course_module($cmorid) {
static::require_enabled();
$cm = $cmorid;
if (!is_object($cmorid)) {
$cm = get_coursemodule_from_id('', $cmorid, 0, true, MUST_EXIST);
}
// Check the user have access to the course module.
self::validate_course_module($cm);
$context = context_module::instance($cm->id);
$capabilities = array('moodle/competency:coursecompetencyview', 'moodle/competency:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'moodle/competency:coursecompetencyview', 'nopermissions', '');
}
$result = array();
$cmclist = course_module_competency::list_course_module_competencies($cm->id);
foreach ($cmclist as $id => $cmc) {
array_push($result, $cmc);
}
return $result;
}
|
[
"public",
"static",
"function",
"list_course_module_competencies_in_course_module",
"(",
"$",
"cmorid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"cm",
"=",
"$",
"cmorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"cmorid",
")",
")",
"{",
"$",
"cm",
"=",
"get_coursemodule_from_id",
"(",
"''",
",",
"$",
"cmorid",
",",
"0",
",",
"true",
",",
"MUST_EXIST",
")",
";",
"}",
"// Check the user have access to the course module.",
"self",
"::",
"validate_course_module",
"(",
"$",
"cm",
")",
";",
"$",
"context",
"=",
"context_module",
"::",
"instance",
"(",
"$",
"cm",
"->",
"id",
")",
";",
"$",
"capabilities",
"=",
"array",
"(",
"'moodle/competency:coursecompetencyview'",
",",
"'moodle/competency:coursecompetencymanage'",
")",
";",
"if",
"(",
"!",
"has_any_capability",
"(",
"$",
"capabilities",
",",
"$",
"context",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:coursecompetencyview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"cmclist",
"=",
"course_module_competency",
"::",
"list_course_module_competencies",
"(",
"$",
"cm",
"->",
"id",
")",
";",
"foreach",
"(",
"$",
"cmclist",
"as",
"$",
"id",
"=>",
"$",
"cmc",
")",
"{",
"array_push",
"(",
"$",
"result",
",",
"$",
"cmc",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
List all the competencies linked to a course module.
@param mixed $cmorid The course module, or its ID.
@return array[competency] Array of competency records.
|
[
"List",
"all",
"the",
"competencies",
"linked",
"to",
"a",
"course",
"module",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L1020-L1044
|
217,227
|
moodle/moodle
|
competency/classes/api.php
|
api.list_courses_using_competency
|
public static function list_courses_using_competency($competencyid) {
static::require_enabled();
// OK - all set.
$courses = course_competency::list_courses($competencyid);
$result = array();
// Now check permissions on each course.
foreach ($courses as $id => $course) {
$context = context_course::instance($course->id);
$capabilities = array('moodle/competency:coursecompetencyview', 'moodle/competency:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) {
unset($courses[$id]);
continue;
}
if (!self::validate_course($course, false)) {
unset($courses[$id]);
continue;
}
array_push($result, $course);
}
return $result;
}
|
php
|
public static function list_courses_using_competency($competencyid) {
static::require_enabled();
// OK - all set.
$courses = course_competency::list_courses($competencyid);
$result = array();
// Now check permissions on each course.
foreach ($courses as $id => $course) {
$context = context_course::instance($course->id);
$capabilities = array('moodle/competency:coursecompetencyview', 'moodle/competency:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) {
unset($courses[$id]);
continue;
}
if (!self::validate_course($course, false)) {
unset($courses[$id]);
continue;
}
array_push($result, $course);
}
return $result;
}
|
[
"public",
"static",
"function",
"list_courses_using_competency",
"(",
"$",
"competencyid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"// OK - all set.",
"$",
"courses",
"=",
"course_competency",
"::",
"list_courses",
"(",
"$",
"competencyid",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"// Now check permissions on each course.",
"foreach",
"(",
"$",
"courses",
"as",
"$",
"id",
"=>",
"$",
"course",
")",
"{",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"course",
"->",
"id",
")",
";",
"$",
"capabilities",
"=",
"array",
"(",
"'moodle/competency:coursecompetencyview'",
",",
"'moodle/competency:coursecompetencymanage'",
")",
";",
"if",
"(",
"!",
"has_any_capability",
"(",
"$",
"capabilities",
",",
"$",
"context",
")",
")",
"{",
"unset",
"(",
"$",
"courses",
"[",
"$",
"id",
"]",
")",
";",
"continue",
";",
"}",
"if",
"(",
"!",
"self",
"::",
"validate_course",
"(",
"$",
"course",
",",
"false",
")",
")",
"{",
"unset",
"(",
"$",
"courses",
"[",
"$",
"id",
"]",
")",
";",
"continue",
";",
"}",
"array_push",
"(",
"$",
"result",
",",
"$",
"course",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
List all the courses using a competency.
@param int $competencyid The id of the competency to check.
@return array[stdClass] Array of stdClass containing id and shortname.
|
[
"List",
"all",
"the",
"courses",
"using",
"a",
"competency",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L1052-L1075
|
217,228
|
moodle/moodle
|
competency/classes/api.php
|
api.count_proficient_competencies_in_course_for_user
|
public static function count_proficient_competencies_in_course_for_user($courseid, $userid) {
static::require_enabled();
// Check the user have access to the course.
self::validate_course($courseid);
// First we do a permissions check.
$context = context_course::instance($courseid);
$capabilities = array('moodle/competency:coursecompetencyview', 'moodle/competency:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'moodle/competency:coursecompetencyview', 'nopermissions', '');
}
// OK - all set.
return user_competency_course::count_proficient_competencies($courseid, $userid);
}
|
php
|
public static function count_proficient_competencies_in_course_for_user($courseid, $userid) {
static::require_enabled();
// Check the user have access to the course.
self::validate_course($courseid);
// First we do a permissions check.
$context = context_course::instance($courseid);
$capabilities = array('moodle/competency:coursecompetencyview', 'moodle/competency:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'moodle/competency:coursecompetencyview', 'nopermissions', '');
}
// OK - all set.
return user_competency_course::count_proficient_competencies($courseid, $userid);
}
|
[
"public",
"static",
"function",
"count_proficient_competencies_in_course_for_user",
"(",
"$",
"courseid",
",",
"$",
"userid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"// Check the user have access to the course.",
"self",
"::",
"validate_course",
"(",
"$",
"courseid",
")",
";",
"// First we do a permissions check.",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"courseid",
")",
";",
"$",
"capabilities",
"=",
"array",
"(",
"'moodle/competency:coursecompetencyview'",
",",
"'moodle/competency:coursecompetencymanage'",
")",
";",
"if",
"(",
"!",
"has_any_capability",
"(",
"$",
"capabilities",
",",
"$",
"context",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:coursecompetencyview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// OK - all set.",
"return",
"user_competency_course",
"::",
"count_proficient_competencies",
"(",
"$",
"courseid",
",",
"$",
"userid",
")",
";",
"}"
] |
Count the proficient competencies in a course for one user.
@param int $courseid The id of the course to check.
@param int $userid The id of the user to check.
@return int
|
[
"Count",
"the",
"proficient",
"competencies",
"in",
"a",
"course",
"for",
"one",
"user",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L1084-L1099
|
217,229
|
moodle/moodle
|
competency/classes/api.php
|
api.count_competencies_in_course
|
public static function count_competencies_in_course($courseid) {
static::require_enabled();
// Check the user have access to the course.
self::validate_course($courseid);
// First we do a permissions check.
$context = context_course::instance($courseid);
$capabilities = array('moodle/competency:coursecompetencyview', 'moodle/competency:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'moodle/competency:coursecompetencyview', 'nopermissions', '');
}
// OK - all set.
return course_competency::count_competencies($courseid);
}
|
php
|
public static function count_competencies_in_course($courseid) {
static::require_enabled();
// Check the user have access to the course.
self::validate_course($courseid);
// First we do a permissions check.
$context = context_course::instance($courseid);
$capabilities = array('moodle/competency:coursecompetencyview', 'moodle/competency:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'moodle/competency:coursecompetencyview', 'nopermissions', '');
}
// OK - all set.
return course_competency::count_competencies($courseid);
}
|
[
"public",
"static",
"function",
"count_competencies_in_course",
"(",
"$",
"courseid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"// Check the user have access to the course.",
"self",
"::",
"validate_course",
"(",
"$",
"courseid",
")",
";",
"// First we do a permissions check.",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"courseid",
")",
";",
"$",
"capabilities",
"=",
"array",
"(",
"'moodle/competency:coursecompetencyview'",
",",
"'moodle/competency:coursecompetencymanage'",
")",
";",
"if",
"(",
"!",
"has_any_capability",
"(",
"$",
"capabilities",
",",
"$",
"context",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:coursecompetencyview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// OK - all set.",
"return",
"course_competency",
"::",
"count_competencies",
"(",
"$",
"courseid",
")",
";",
"}"
] |
Count all the competencies in a course.
@param int $courseid The id of the course to check.
@return int
|
[
"Count",
"all",
"the",
"competencies",
"in",
"a",
"course",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L1107-L1122
|
217,230
|
moodle/moodle
|
competency/classes/api.php
|
api.list_course_competencies
|
public static function list_course_competencies($courseorid) {
static::require_enabled();
$course = $courseorid;
if (!is_object($courseorid)) {
$course = get_course($courseorid);
}
// Check the user have access to the course.
self::validate_course($course);
$context = context_course::instance($course->id);
$capabilities = array('moodle/competency:coursecompetencyview', 'moodle/competency:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'moodle/competency:coursecompetencyview', 'nopermissions', '');
}
$result = array();
// TODO We could improve the performance of this into one single query.
$coursecompetencies = course_competency::list_course_competencies($course->id);
$competencies = course_competency::list_competencies($course->id);
// Build the return values.
foreach ($coursecompetencies as $key => $coursecompetency) {
$result[] = array(
'competency' => $competencies[$coursecompetency->get('competencyid')],
'coursecompetency' => $coursecompetency
);
}
return $result;
}
|
php
|
public static function list_course_competencies($courseorid) {
static::require_enabled();
$course = $courseorid;
if (!is_object($courseorid)) {
$course = get_course($courseorid);
}
// Check the user have access to the course.
self::validate_course($course);
$context = context_course::instance($course->id);
$capabilities = array('moodle/competency:coursecompetencyview', 'moodle/competency:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'moodle/competency:coursecompetencyview', 'nopermissions', '');
}
$result = array();
// TODO We could improve the performance of this into one single query.
$coursecompetencies = course_competency::list_course_competencies($course->id);
$competencies = course_competency::list_competencies($course->id);
// Build the return values.
foreach ($coursecompetencies as $key => $coursecompetency) {
$result[] = array(
'competency' => $competencies[$coursecompetency->get('competencyid')],
'coursecompetency' => $coursecompetency
);
}
return $result;
}
|
[
"public",
"static",
"function",
"list_course_competencies",
"(",
"$",
"courseorid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"course",
"=",
"$",
"courseorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"courseorid",
")",
")",
"{",
"$",
"course",
"=",
"get_course",
"(",
"$",
"courseorid",
")",
";",
"}",
"// Check the user have access to the course.",
"self",
"::",
"validate_course",
"(",
"$",
"course",
")",
";",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"course",
"->",
"id",
")",
";",
"$",
"capabilities",
"=",
"array",
"(",
"'moodle/competency:coursecompetencyview'",
",",
"'moodle/competency:coursecompetencymanage'",
")",
";",
"if",
"(",
"!",
"has_any_capability",
"(",
"$",
"capabilities",
",",
"$",
"context",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:coursecompetencyview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"$",
"result",
"=",
"array",
"(",
")",
";",
"// TODO We could improve the performance of this into one single query.",
"$",
"coursecompetencies",
"=",
"course_competency",
"::",
"list_course_competencies",
"(",
"$",
"course",
"->",
"id",
")",
";",
"$",
"competencies",
"=",
"course_competency",
"::",
"list_competencies",
"(",
"$",
"course",
"->",
"id",
")",
";",
"// Build the return values.",
"foreach",
"(",
"$",
"coursecompetencies",
"as",
"$",
"key",
"=>",
"$",
"coursecompetency",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"array",
"(",
"'competency'",
"=>",
"$",
"competencies",
"[",
"$",
"coursecompetency",
"->",
"get",
"(",
"'competencyid'",
")",
"]",
",",
"'coursecompetency'",
"=>",
"$",
"coursecompetency",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
List the competencies associated to a course.
@param mixed $courseorid The course, or its ID.
@return array( array(
'competency' => \core_competency\competency,
'coursecompetency' => \core_competency\course_competency
))
|
[
"List",
"the",
"competencies",
"associated",
"to",
"a",
"course",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L1133-L1164
|
217,231
|
moodle/moodle
|
competency/classes/api.php
|
api.get_user_competency
|
public static function get_user_competency($userid, $competencyid) {
static::require_enabled();
$existing = user_competency::get_multiple($userid, array($competencyid));
$uc = array_pop($existing);
if (!$uc) {
$uc = user_competency::create_relation($userid, $competencyid);
$uc->create();
}
if (!$uc->can_read()) {
throw new required_capability_exception($uc->get_context(), 'moodle/competency:usercompetencyview',
'nopermissions', '');
}
return $uc;
}
|
php
|
public static function get_user_competency($userid, $competencyid) {
static::require_enabled();
$existing = user_competency::get_multiple($userid, array($competencyid));
$uc = array_pop($existing);
if (!$uc) {
$uc = user_competency::create_relation($userid, $competencyid);
$uc->create();
}
if (!$uc->can_read()) {
throw new required_capability_exception($uc->get_context(), 'moodle/competency:usercompetencyview',
'nopermissions', '');
}
return $uc;
}
|
[
"public",
"static",
"function",
"get_user_competency",
"(",
"$",
"userid",
",",
"$",
"competencyid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"existing",
"=",
"user_competency",
"::",
"get_multiple",
"(",
"$",
"userid",
",",
"array",
"(",
"$",
"competencyid",
")",
")",
";",
"$",
"uc",
"=",
"array_pop",
"(",
"$",
"existing",
")",
";",
"if",
"(",
"!",
"$",
"uc",
")",
"{",
"$",
"uc",
"=",
"user_competency",
"::",
"create_relation",
"(",
"$",
"userid",
",",
"$",
"competencyid",
")",
";",
"$",
"uc",
"->",
"create",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"uc",
"->",
"can_read",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"uc",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:usercompetencyview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"return",
"$",
"uc",
";",
"}"
] |
Get a user competency.
@param int $userid The user ID.
@param int $competencyid The competency ID.
@return user_competency
|
[
"Get",
"a",
"user",
"competency",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L1173-L1188
|
217,232
|
moodle/moodle
|
competency/classes/api.php
|
api.get_user_competency_by_id
|
public static function get_user_competency_by_id($usercompetencyid) {
static::require_enabled();
$uc = new user_competency($usercompetencyid);
if (!$uc->can_read()) {
throw new required_capability_exception($uc->get_context(), 'moodle/competency:usercompetencyview',
'nopermissions', '');
}
return $uc;
}
|
php
|
public static function get_user_competency_by_id($usercompetencyid) {
static::require_enabled();
$uc = new user_competency($usercompetencyid);
if (!$uc->can_read()) {
throw new required_capability_exception($uc->get_context(), 'moodle/competency:usercompetencyview',
'nopermissions', '');
}
return $uc;
}
|
[
"public",
"static",
"function",
"get_user_competency_by_id",
"(",
"$",
"usercompetencyid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"uc",
"=",
"new",
"user_competency",
"(",
"$",
"usercompetencyid",
")",
";",
"if",
"(",
"!",
"$",
"uc",
"->",
"can_read",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"uc",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:usercompetencyview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"return",
"$",
"uc",
";",
"}"
] |
Get a user competency by ID.
@param int $usercompetencyid The user competency ID.
@return user_competency
|
[
"Get",
"a",
"user",
"competency",
"by",
"ID",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L1196-L1204
|
217,233
|
moodle/moodle
|
competency/classes/api.php
|
api.list_course_module_competencies
|
public static function list_course_module_competencies($cmorid) {
static::require_enabled();
$cm = $cmorid;
if (!is_object($cmorid)) {
$cm = get_coursemodule_from_id('', $cmorid, 0, true, MUST_EXIST);
}
// Check the user have access to the course module.
self::validate_course_module($cm);
$context = context_module::instance($cm->id);
$capabilities = array('moodle/competency:coursecompetencyview', 'moodle/competency:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'moodle/competency:coursecompetencyview', 'nopermissions', '');
}
$result = array();
// TODO We could improve the performance of this into one single query.
$coursemodulecompetencies = course_competency::list_course_module_competencies($cm->id);
$competencies = course_module_competency::list_competencies($cm->id);
// Build the return values.
foreach ($coursemodulecompetencies as $key => $coursemodulecompetency) {
$result[] = array(
'competency' => $competencies[$coursemodulecompetency->get('competencyid')],
'coursemodulecompetency' => $coursemodulecompetency
);
}
return $result;
}
|
php
|
public static function list_course_module_competencies($cmorid) {
static::require_enabled();
$cm = $cmorid;
if (!is_object($cmorid)) {
$cm = get_coursemodule_from_id('', $cmorid, 0, true, MUST_EXIST);
}
// Check the user have access to the course module.
self::validate_course_module($cm);
$context = context_module::instance($cm->id);
$capabilities = array('moodle/competency:coursecompetencyview', 'moodle/competency:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'moodle/competency:coursecompetencyview', 'nopermissions', '');
}
$result = array();
// TODO We could improve the performance of this into one single query.
$coursemodulecompetencies = course_competency::list_course_module_competencies($cm->id);
$competencies = course_module_competency::list_competencies($cm->id);
// Build the return values.
foreach ($coursemodulecompetencies as $key => $coursemodulecompetency) {
$result[] = array(
'competency' => $competencies[$coursemodulecompetency->get('competencyid')],
'coursemodulecompetency' => $coursemodulecompetency
);
}
return $result;
}
|
[
"public",
"static",
"function",
"list_course_module_competencies",
"(",
"$",
"cmorid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"cm",
"=",
"$",
"cmorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"cmorid",
")",
")",
"{",
"$",
"cm",
"=",
"get_coursemodule_from_id",
"(",
"''",
",",
"$",
"cmorid",
",",
"0",
",",
"true",
",",
"MUST_EXIST",
")",
";",
"}",
"// Check the user have access to the course module.",
"self",
"::",
"validate_course_module",
"(",
"$",
"cm",
")",
";",
"$",
"context",
"=",
"context_module",
"::",
"instance",
"(",
"$",
"cm",
"->",
"id",
")",
";",
"$",
"capabilities",
"=",
"array",
"(",
"'moodle/competency:coursecompetencyview'",
",",
"'moodle/competency:coursecompetencymanage'",
")",
";",
"if",
"(",
"!",
"has_any_capability",
"(",
"$",
"capabilities",
",",
"$",
"context",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:coursecompetencyview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"$",
"result",
"=",
"array",
"(",
")",
";",
"// TODO We could improve the performance of this into one single query.",
"$",
"coursemodulecompetencies",
"=",
"course_competency",
"::",
"list_course_module_competencies",
"(",
"$",
"cm",
"->",
"id",
")",
";",
"$",
"competencies",
"=",
"course_module_competency",
"::",
"list_competencies",
"(",
"$",
"cm",
"->",
"id",
")",
";",
"// Build the return values.",
"foreach",
"(",
"$",
"coursemodulecompetencies",
"as",
"$",
"key",
"=>",
"$",
"coursemodulecompetency",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"array",
"(",
"'competency'",
"=>",
"$",
"competencies",
"[",
"$",
"coursemodulecompetency",
"->",
"get",
"(",
"'competencyid'",
")",
"]",
",",
"'coursemodulecompetency'",
"=>",
"$",
"coursemodulecompetency",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
List the competencies associated to a course module.
@param mixed $cmorid The course module, or its ID.
@return array( array(
'competency' => \core_competency\competency,
'coursemodulecompetency' => \core_competency\course_module_competency
))
|
[
"List",
"the",
"competencies",
"associated",
"to",
"a",
"course",
"module",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L1215-L1246
|
217,234
|
moodle/moodle
|
competency/classes/api.php
|
api.get_user_competency_in_course
|
public static function get_user_competency_in_course($courseid, $userid, $competencyid) {
static::require_enabled();
// First we do a permissions check.
$context = context_course::instance($courseid);
$capabilities = array('moodle/competency:coursecompetencyview', 'moodle/competency:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'moodle/competency:coursecompetencyview', 'nopermissions', '');
} else if (!user_competency::can_read_user_in_course($userid, $courseid)) {
throw new required_capability_exception($context, 'moodle/competency:usercompetencyview', 'nopermissions', '');
}
// 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);
$exists = user_competency_course::get_record($params);
// Create missing.
if ($exists) {
$ucc = $exists;
} else {
$ucc = user_competency_course::create_relation($userid, $competency->get('id'), $courseid);
$ucc->create();
}
return $ucc;
}
|
php
|
public static function get_user_competency_in_course($courseid, $userid, $competencyid) {
static::require_enabled();
// First we do a permissions check.
$context = context_course::instance($courseid);
$capabilities = array('moodle/competency:coursecompetencyview', 'moodle/competency:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'moodle/competency:coursecompetencyview', 'nopermissions', '');
} else if (!user_competency::can_read_user_in_course($userid, $courseid)) {
throw new required_capability_exception($context, 'moodle/competency:usercompetencyview', 'nopermissions', '');
}
// 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);
$exists = user_competency_course::get_record($params);
// Create missing.
if ($exists) {
$ucc = $exists;
} else {
$ucc = user_competency_course::create_relation($userid, $competency->get('id'), $courseid);
$ucc->create();
}
return $ucc;
}
|
[
"public",
"static",
"function",
"get_user_competency_in_course",
"(",
"$",
"courseid",
",",
"$",
"userid",
",",
"$",
"competencyid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"// First we do a permissions check.",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"courseid",
")",
";",
"$",
"capabilities",
"=",
"array",
"(",
"'moodle/competency:coursecompetencyview'",
",",
"'moodle/competency:coursecompetencymanage'",
")",
";",
"if",
"(",
"!",
"has_any_capability",
"(",
"$",
"capabilities",
",",
"$",
"context",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:coursecompetencyview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"else",
"if",
"(",
"!",
"user_competency",
"::",
"can_read_user_in_course",
"(",
"$",
"userid",
",",
"$",
"courseid",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:usercompetencyview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// 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",
")",
";",
"$",
"exists",
"=",
"user_competency_course",
"::",
"get_record",
"(",
"$",
"params",
")",
";",
"// Create missing.",
"if",
"(",
"$",
"exists",
")",
"{",
"$",
"ucc",
"=",
"$",
"exists",
";",
"}",
"else",
"{",
"$",
"ucc",
"=",
"user_competency_course",
"::",
"create_relation",
"(",
"$",
"userid",
",",
"$",
"competency",
"->",
"get",
"(",
"'id'",
")",
",",
"$",
"courseid",
")",
";",
"$",
"ucc",
"->",
"create",
"(",
")",
";",
"}",
"return",
"$",
"ucc",
";",
"}"
] |
Get a user competency in a course.
@param int $courseid The id of the course to check.
@param int $userid The id of the course to check.
@param int $competencyid The id of the competency.
@return user_competency_course
|
[
"Get",
"a",
"user",
"competency",
"in",
"a",
"course",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L1256-L1282
|
217,235
|
moodle/moodle
|
competency/classes/api.php
|
api.list_user_competencies_in_course
|
public static function list_user_competencies_in_course($courseid, $userid) {
static::require_enabled();
// First we do a permissions check.
$context = context_course::instance($courseid);
$onlyvisible = 1;
$capabilities = array('moodle/competency:coursecompetencyview', 'moodle/competency:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'moodle/competency:coursecompetencyview', 'nopermissions', '');
} else if (!user_competency::can_read_user_in_course($userid, $courseid)) {
throw new required_capability_exception($context, 'moodle/competency:usercompetencyview', 'nopermissions', '');
}
// OK - all set.
$competencylist = course_competency::list_competencies($courseid, false);
$existing = user_competency_course::get_multiple($userid, $courseid, $competencylist);
// Create missing.
$orderedusercompetencycourses = array();
$somemissing = false;
foreach ($competencylist as $coursecompetency) {
$found = false;
foreach ($existing as $usercompetencycourse) {
if ($usercompetencycourse->get('competencyid') == $coursecompetency->get('id')) {
$found = true;
$orderedusercompetencycourses[$usercompetencycourse->get('id')] = $usercompetencycourse;
break;
}
}
if (!$found) {
$ucc = user_competency_course::create_relation($userid, $coursecompetency->get('id'), $courseid);
$ucc->create();
$orderedusercompetencycourses[$ucc->get('id')] = $ucc;
}
}
return $orderedusercompetencycourses;
}
|
php
|
public static function list_user_competencies_in_course($courseid, $userid) {
static::require_enabled();
// First we do a permissions check.
$context = context_course::instance($courseid);
$onlyvisible = 1;
$capabilities = array('moodle/competency:coursecompetencyview', 'moodle/competency:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'moodle/competency:coursecompetencyview', 'nopermissions', '');
} else if (!user_competency::can_read_user_in_course($userid, $courseid)) {
throw new required_capability_exception($context, 'moodle/competency:usercompetencyview', 'nopermissions', '');
}
// OK - all set.
$competencylist = course_competency::list_competencies($courseid, false);
$existing = user_competency_course::get_multiple($userid, $courseid, $competencylist);
// Create missing.
$orderedusercompetencycourses = array();
$somemissing = false;
foreach ($competencylist as $coursecompetency) {
$found = false;
foreach ($existing as $usercompetencycourse) {
if ($usercompetencycourse->get('competencyid') == $coursecompetency->get('id')) {
$found = true;
$orderedusercompetencycourses[$usercompetencycourse->get('id')] = $usercompetencycourse;
break;
}
}
if (!$found) {
$ucc = user_competency_course::create_relation($userid, $coursecompetency->get('id'), $courseid);
$ucc->create();
$orderedusercompetencycourses[$ucc->get('id')] = $ucc;
}
}
return $orderedusercompetencycourses;
}
|
[
"public",
"static",
"function",
"list_user_competencies_in_course",
"(",
"$",
"courseid",
",",
"$",
"userid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"// First we do a permissions check.",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"courseid",
")",
";",
"$",
"onlyvisible",
"=",
"1",
";",
"$",
"capabilities",
"=",
"array",
"(",
"'moodle/competency:coursecompetencyview'",
",",
"'moodle/competency:coursecompetencymanage'",
")",
";",
"if",
"(",
"!",
"has_any_capability",
"(",
"$",
"capabilities",
",",
"$",
"context",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:coursecompetencyview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"else",
"if",
"(",
"!",
"user_competency",
"::",
"can_read_user_in_course",
"(",
"$",
"userid",
",",
"$",
"courseid",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:usercompetencyview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// OK - all set.",
"$",
"competencylist",
"=",
"course_competency",
"::",
"list_competencies",
"(",
"$",
"courseid",
",",
"false",
")",
";",
"$",
"existing",
"=",
"user_competency_course",
"::",
"get_multiple",
"(",
"$",
"userid",
",",
"$",
"courseid",
",",
"$",
"competencylist",
")",
";",
"// Create missing.",
"$",
"orderedusercompetencycourses",
"=",
"array",
"(",
")",
";",
"$",
"somemissing",
"=",
"false",
";",
"foreach",
"(",
"$",
"competencylist",
"as",
"$",
"coursecompetency",
")",
"{",
"$",
"found",
"=",
"false",
";",
"foreach",
"(",
"$",
"existing",
"as",
"$",
"usercompetencycourse",
")",
"{",
"if",
"(",
"$",
"usercompetencycourse",
"->",
"get",
"(",
"'competencyid'",
")",
"==",
"$",
"coursecompetency",
"->",
"get",
"(",
"'id'",
")",
")",
"{",
"$",
"found",
"=",
"true",
";",
"$",
"orderedusercompetencycourses",
"[",
"$",
"usercompetencycourse",
"->",
"get",
"(",
"'id'",
")",
"]",
"=",
"$",
"usercompetencycourse",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"found",
")",
"{",
"$",
"ucc",
"=",
"user_competency_course",
"::",
"create_relation",
"(",
"$",
"userid",
",",
"$",
"coursecompetency",
"->",
"get",
"(",
"'id'",
")",
",",
"$",
"courseid",
")",
";",
"$",
"ucc",
"->",
"create",
"(",
")",
";",
"$",
"orderedusercompetencycourses",
"[",
"$",
"ucc",
"->",
"get",
"(",
"'id'",
")",
"]",
"=",
"$",
"ucc",
";",
"}",
"}",
"return",
"$",
"orderedusercompetencycourses",
";",
"}"
] |
List all the user competencies in a course.
@param int $courseid The id of the course to check.
@param int $userid The id of the course to check.
@return array of user_competency_course objects
|
[
"List",
"all",
"the",
"user",
"competencies",
"in",
"a",
"course",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L1291-L1329
|
217,236
|
moodle/moodle
|
competency/classes/api.php
|
api.list_user_competencies_to_review
|
public static function list_user_competencies_to_review($skip = 0, $limit = 50, $userid = null) {
global $DB, $USER;
static::require_enabled();
if ($userid === null) {
$userid = $USER->id;
}
$capability = 'moodle/competency:usercompetencyreview';
$ucfields = user_competency::get_sql_fields('uc', 'uc_');
$compfields = competency::get_sql_fields('c', 'c_');
$usercols = array('id') + get_user_fieldnames();
$userfields = array();
foreach ($usercols as $field) {
$userfields[] = "u." . $field . " AS usr_" . $field;
}
$userfields = implode(',', $userfields);
$select = "SELECT $ucfields, $compfields, $userfields";
$countselect = "SELECT COUNT('x')";
$sql = " FROM {" . user_competency::TABLE . "} uc
JOIN {" . competency::TABLE . "} c
ON c.id = uc.competencyid
JOIN {user} u
ON u.id = uc.userid
WHERE (uc.status = :waitingforreview
OR (uc.status = :inreview AND uc.reviewerid = :reviewerid))
AND u.deleted = 0";
$ordersql = " ORDER BY c.shortname ASC";
$params = array(
'inreview' => user_competency::STATUS_IN_REVIEW,
'reviewerid' => $userid,
'waitingforreview' => user_competency::STATUS_WAITING_FOR_REVIEW,
);
$countsql = $countselect . $sql;
// Primary check to avoid the hard work of getting the users in which the user has permission.
$count = $DB->count_records_sql($countselect . $sql, $params);
if ($count < 1) {
return array('count' => 0, 'competencies' => array());
}
// TODO MDL-52243 Use core function.
list($insql, $inparams) = self::filter_users_with_capability_on_user_context_sql(
$capability, $userid, SQL_PARAMS_NAMED);
$params += $inparams;
$countsql = $countselect . $sql . " AND uc.userid $insql";
$getsql = $select . $sql . " AND uc.userid $insql " . $ordersql;
// Extracting the results.
$competencies = array();
$records = $DB->get_recordset_sql($getsql, $params, $skip, $limit);
foreach ($records as $record) {
$objects = (object) array(
'usercompetency' => new user_competency(0, user_competency::extract_record($record, 'uc_')),
'competency' => new competency(0, competency::extract_record($record, 'c_')),
'user' => persistent::extract_record($record, 'usr_'),
);
$competencies[] = $objects;
}
$records->close();
return array(
'count' => $DB->count_records_sql($countsql, $params),
'competencies' => $competencies
);
}
|
php
|
public static function list_user_competencies_to_review($skip = 0, $limit = 50, $userid = null) {
global $DB, $USER;
static::require_enabled();
if ($userid === null) {
$userid = $USER->id;
}
$capability = 'moodle/competency:usercompetencyreview';
$ucfields = user_competency::get_sql_fields('uc', 'uc_');
$compfields = competency::get_sql_fields('c', 'c_');
$usercols = array('id') + get_user_fieldnames();
$userfields = array();
foreach ($usercols as $field) {
$userfields[] = "u." . $field . " AS usr_" . $field;
}
$userfields = implode(',', $userfields);
$select = "SELECT $ucfields, $compfields, $userfields";
$countselect = "SELECT COUNT('x')";
$sql = " FROM {" . user_competency::TABLE . "} uc
JOIN {" . competency::TABLE . "} c
ON c.id = uc.competencyid
JOIN {user} u
ON u.id = uc.userid
WHERE (uc.status = :waitingforreview
OR (uc.status = :inreview AND uc.reviewerid = :reviewerid))
AND u.deleted = 0";
$ordersql = " ORDER BY c.shortname ASC";
$params = array(
'inreview' => user_competency::STATUS_IN_REVIEW,
'reviewerid' => $userid,
'waitingforreview' => user_competency::STATUS_WAITING_FOR_REVIEW,
);
$countsql = $countselect . $sql;
// Primary check to avoid the hard work of getting the users in which the user has permission.
$count = $DB->count_records_sql($countselect . $sql, $params);
if ($count < 1) {
return array('count' => 0, 'competencies' => array());
}
// TODO MDL-52243 Use core function.
list($insql, $inparams) = self::filter_users_with_capability_on_user_context_sql(
$capability, $userid, SQL_PARAMS_NAMED);
$params += $inparams;
$countsql = $countselect . $sql . " AND uc.userid $insql";
$getsql = $select . $sql . " AND uc.userid $insql " . $ordersql;
// Extracting the results.
$competencies = array();
$records = $DB->get_recordset_sql($getsql, $params, $skip, $limit);
foreach ($records as $record) {
$objects = (object) array(
'usercompetency' => new user_competency(0, user_competency::extract_record($record, 'uc_')),
'competency' => new competency(0, competency::extract_record($record, 'c_')),
'user' => persistent::extract_record($record, 'usr_'),
);
$competencies[] = $objects;
}
$records->close();
return array(
'count' => $DB->count_records_sql($countsql, $params),
'competencies' => $competencies
);
}
|
[
"public",
"static",
"function",
"list_user_competencies_to_review",
"(",
"$",
"skip",
"=",
"0",
",",
"$",
"limit",
"=",
"50",
",",
"$",
"userid",
"=",
"null",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"USER",
";",
"static",
"::",
"require_enabled",
"(",
")",
";",
"if",
"(",
"$",
"userid",
"===",
"null",
")",
"{",
"$",
"userid",
"=",
"$",
"USER",
"->",
"id",
";",
"}",
"$",
"capability",
"=",
"'moodle/competency:usercompetencyreview'",
";",
"$",
"ucfields",
"=",
"user_competency",
"::",
"get_sql_fields",
"(",
"'uc'",
",",
"'uc_'",
")",
";",
"$",
"compfields",
"=",
"competency",
"::",
"get_sql_fields",
"(",
"'c'",
",",
"'c_'",
")",
";",
"$",
"usercols",
"=",
"array",
"(",
"'id'",
")",
"+",
"get_user_fieldnames",
"(",
")",
";",
"$",
"userfields",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"usercols",
"as",
"$",
"field",
")",
"{",
"$",
"userfields",
"[",
"]",
"=",
"\"u.\"",
".",
"$",
"field",
".",
"\" AS usr_\"",
".",
"$",
"field",
";",
"}",
"$",
"userfields",
"=",
"implode",
"(",
"','",
",",
"$",
"userfields",
")",
";",
"$",
"select",
"=",
"\"SELECT $ucfields, $compfields, $userfields\"",
";",
"$",
"countselect",
"=",
"\"SELECT COUNT('x')\"",
";",
"$",
"sql",
"=",
"\" FROM {\"",
".",
"user_competency",
"::",
"TABLE",
".",
"\"} uc\n JOIN {\"",
".",
"competency",
"::",
"TABLE",
".",
"\"} c\n ON c.id = uc.competencyid\n JOIN {user} u\n ON u.id = uc.userid\n WHERE (uc.status = :waitingforreview\n OR (uc.status = :inreview AND uc.reviewerid = :reviewerid))\n AND u.deleted = 0\"",
";",
"$",
"ordersql",
"=",
"\" ORDER BY c.shortname ASC\"",
";",
"$",
"params",
"=",
"array",
"(",
"'inreview'",
"=>",
"user_competency",
"::",
"STATUS_IN_REVIEW",
",",
"'reviewerid'",
"=>",
"$",
"userid",
",",
"'waitingforreview'",
"=>",
"user_competency",
"::",
"STATUS_WAITING_FOR_REVIEW",
",",
")",
";",
"$",
"countsql",
"=",
"$",
"countselect",
".",
"$",
"sql",
";",
"// Primary check to avoid the hard work of getting the users in which the user has permission.",
"$",
"count",
"=",
"$",
"DB",
"->",
"count_records_sql",
"(",
"$",
"countselect",
".",
"$",
"sql",
",",
"$",
"params",
")",
";",
"if",
"(",
"$",
"count",
"<",
"1",
")",
"{",
"return",
"array",
"(",
"'count'",
"=>",
"0",
",",
"'competencies'",
"=>",
"array",
"(",
")",
")",
";",
"}",
"// TODO MDL-52243 Use core function.",
"list",
"(",
"$",
"insql",
",",
"$",
"inparams",
")",
"=",
"self",
"::",
"filter_users_with_capability_on_user_context_sql",
"(",
"$",
"capability",
",",
"$",
"userid",
",",
"SQL_PARAMS_NAMED",
")",
";",
"$",
"params",
"+=",
"$",
"inparams",
";",
"$",
"countsql",
"=",
"$",
"countselect",
".",
"$",
"sql",
".",
"\" AND uc.userid $insql\"",
";",
"$",
"getsql",
"=",
"$",
"select",
".",
"$",
"sql",
".",
"\" AND uc.userid $insql \"",
".",
"$",
"ordersql",
";",
"// Extracting the results.",
"$",
"competencies",
"=",
"array",
"(",
")",
";",
"$",
"records",
"=",
"$",
"DB",
"->",
"get_recordset_sql",
"(",
"$",
"getsql",
",",
"$",
"params",
",",
"$",
"skip",
",",
"$",
"limit",
")",
";",
"foreach",
"(",
"$",
"records",
"as",
"$",
"record",
")",
"{",
"$",
"objects",
"=",
"(",
"object",
")",
"array",
"(",
"'usercompetency'",
"=>",
"new",
"user_competency",
"(",
"0",
",",
"user_competency",
"::",
"extract_record",
"(",
"$",
"record",
",",
"'uc_'",
")",
")",
",",
"'competency'",
"=>",
"new",
"competency",
"(",
"0",
",",
"competency",
"::",
"extract_record",
"(",
"$",
"record",
",",
"'c_'",
")",
")",
",",
"'user'",
"=>",
"persistent",
"::",
"extract_record",
"(",
"$",
"record",
",",
"'usr_'",
")",
",",
")",
";",
"$",
"competencies",
"[",
"]",
"=",
"$",
"objects",
";",
"}",
"$",
"records",
"->",
"close",
"(",
")",
";",
"return",
"array",
"(",
"'count'",
"=>",
"$",
"DB",
"->",
"count_records_sql",
"(",
"$",
"countsql",
",",
"$",
"params",
")",
",",
"'competencies'",
"=>",
"$",
"competencies",
")",
";",
"}"
] |
List the user competencies to review.
The method returns values in this format:
array(
'competencies' => array(
(stdClass)(
'usercompetency' => (user_competency),
'competency' => (competency),
'user' => (user)
)
),
'count' => (int)
)
@param int $skip The number of records to skip.
@param int $limit The number of results to return.
@param int $userid The user we're getting the competencies to review for.
@return array Containing the keys 'count', and 'competencies'. The 'competencies' key contains an object
which contains 'competency', 'usercompetency' and 'user'.
|
[
"List",
"the",
"user",
"competencies",
"to",
"review",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L1353-L1418
|
217,237
|
moodle/moodle
|
competency/classes/api.php
|
api.add_competency_to_course_module
|
public static function add_competency_to_course_module($cmorid, $competencyid) {
static::require_enabled();
$cm = $cmorid;
if (!is_object($cmorid)) {
$cm = get_coursemodule_from_id('', $cmorid, 0, true, MUST_EXIST);
}
// Check the user have access to the course module.
self::validate_course_module($cm);
// First we do a permissions check.
$context = context_module::instance($cm->id);
require_capability('moodle/competency:coursecompetencymanage', $context);
// Check that the competency belongs to the course.
$exists = course_competency::get_records(array('courseid' => $cm->course, 'competencyid' => $competencyid));
if (!$exists) {
throw new coding_exception('Cannot add a competency to a module if it does not belong to the course');
}
$record = new stdClass();
$record->cmid = $cm->id;
$record->competencyid = $competencyid;
$coursemodulecompetency = new course_module_competency();
$exists = $coursemodulecompetency->get_records(array('cmid' => $cm->id, 'competencyid' => $competencyid));
if (!$exists) {
$coursemodulecompetency->from_record($record);
if ($coursemodulecompetency->create()) {
return true;
}
}
return false;
}
|
php
|
public static function add_competency_to_course_module($cmorid, $competencyid) {
static::require_enabled();
$cm = $cmorid;
if (!is_object($cmorid)) {
$cm = get_coursemodule_from_id('', $cmorid, 0, true, MUST_EXIST);
}
// Check the user have access to the course module.
self::validate_course_module($cm);
// First we do a permissions check.
$context = context_module::instance($cm->id);
require_capability('moodle/competency:coursecompetencymanage', $context);
// Check that the competency belongs to the course.
$exists = course_competency::get_records(array('courseid' => $cm->course, 'competencyid' => $competencyid));
if (!$exists) {
throw new coding_exception('Cannot add a competency to a module if it does not belong to the course');
}
$record = new stdClass();
$record->cmid = $cm->id;
$record->competencyid = $competencyid;
$coursemodulecompetency = new course_module_competency();
$exists = $coursemodulecompetency->get_records(array('cmid' => $cm->id, 'competencyid' => $competencyid));
if (!$exists) {
$coursemodulecompetency->from_record($record);
if ($coursemodulecompetency->create()) {
return true;
}
}
return false;
}
|
[
"public",
"static",
"function",
"add_competency_to_course_module",
"(",
"$",
"cmorid",
",",
"$",
"competencyid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"cm",
"=",
"$",
"cmorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"cmorid",
")",
")",
"{",
"$",
"cm",
"=",
"get_coursemodule_from_id",
"(",
"''",
",",
"$",
"cmorid",
",",
"0",
",",
"true",
",",
"MUST_EXIST",
")",
";",
"}",
"// Check the user have access to the course module.",
"self",
"::",
"validate_course_module",
"(",
"$",
"cm",
")",
";",
"// First we do a permissions check.",
"$",
"context",
"=",
"context_module",
"::",
"instance",
"(",
"$",
"cm",
"->",
"id",
")",
";",
"require_capability",
"(",
"'moodle/competency:coursecompetencymanage'",
",",
"$",
"context",
")",
";",
"// Check that the competency belongs to the course.",
"$",
"exists",
"=",
"course_competency",
"::",
"get_records",
"(",
"array",
"(",
"'courseid'",
"=>",
"$",
"cm",
"->",
"course",
",",
"'competencyid'",
"=>",
"$",
"competencyid",
")",
")",
";",
"if",
"(",
"!",
"$",
"exists",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Cannot add a competency to a module if it does not belong to the course'",
")",
";",
"}",
"$",
"record",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"record",
"->",
"cmid",
"=",
"$",
"cm",
"->",
"id",
";",
"$",
"record",
"->",
"competencyid",
"=",
"$",
"competencyid",
";",
"$",
"coursemodulecompetency",
"=",
"new",
"course_module_competency",
"(",
")",
";",
"$",
"exists",
"=",
"$",
"coursemodulecompetency",
"->",
"get_records",
"(",
"array",
"(",
"'cmid'",
"=>",
"$",
"cm",
"->",
"id",
",",
"'competencyid'",
"=>",
"$",
"competencyid",
")",
")",
";",
"if",
"(",
"!",
"$",
"exists",
")",
"{",
"$",
"coursemodulecompetency",
"->",
"from_record",
"(",
"$",
"record",
")",
";",
"if",
"(",
"$",
"coursemodulecompetency",
"->",
"create",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Add a competency to this course module.
@param mixed $cmorid The course module, or id of the course module
@param int $competencyid The id of the competency
@return bool
|
[
"Add",
"a",
"competency",
"to",
"this",
"course",
"module",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L1427-L1461
|
217,238
|
moodle/moodle
|
competency/classes/api.php
|
api.remove_competency_from_course_module
|
public static function remove_competency_from_course_module($cmorid, $competencyid) {
static::require_enabled();
$cm = $cmorid;
if (!is_object($cmorid)) {
$cm = get_coursemodule_from_id('', $cmorid, 0, true, MUST_EXIST);
}
// Check the user have access to the course module.
self::validate_course_module($cm);
// First we do a permissions check.
$context = context_module::instance($cm->id);
require_capability('moodle/competency:coursecompetencymanage', $context);
$record = new stdClass();
$record->cmid = $cm->id;
$record->competencyid = $competencyid;
$competency = new competency($competencyid);
$exists = course_module_competency::get_record(array('cmid' => $cm->id, 'competencyid' => $competencyid));
if ($exists) {
return $exists->delete();
}
return false;
}
|
php
|
public static function remove_competency_from_course_module($cmorid, $competencyid) {
static::require_enabled();
$cm = $cmorid;
if (!is_object($cmorid)) {
$cm = get_coursemodule_from_id('', $cmorid, 0, true, MUST_EXIST);
}
// Check the user have access to the course module.
self::validate_course_module($cm);
// First we do a permissions check.
$context = context_module::instance($cm->id);
require_capability('moodle/competency:coursecompetencymanage', $context);
$record = new stdClass();
$record->cmid = $cm->id;
$record->competencyid = $competencyid;
$competency = new competency($competencyid);
$exists = course_module_competency::get_record(array('cmid' => $cm->id, 'competencyid' => $competencyid));
if ($exists) {
return $exists->delete();
}
return false;
}
|
[
"public",
"static",
"function",
"remove_competency_from_course_module",
"(",
"$",
"cmorid",
",",
"$",
"competencyid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"cm",
"=",
"$",
"cmorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"cmorid",
")",
")",
"{",
"$",
"cm",
"=",
"get_coursemodule_from_id",
"(",
"''",
",",
"$",
"cmorid",
",",
"0",
",",
"true",
",",
"MUST_EXIST",
")",
";",
"}",
"// Check the user have access to the course module.",
"self",
"::",
"validate_course_module",
"(",
"$",
"cm",
")",
";",
"// First we do a permissions check.",
"$",
"context",
"=",
"context_module",
"::",
"instance",
"(",
"$",
"cm",
"->",
"id",
")",
";",
"require_capability",
"(",
"'moodle/competency:coursecompetencymanage'",
",",
"$",
"context",
")",
";",
"$",
"record",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"record",
"->",
"cmid",
"=",
"$",
"cm",
"->",
"id",
";",
"$",
"record",
"->",
"competencyid",
"=",
"$",
"competencyid",
";",
"$",
"competency",
"=",
"new",
"competency",
"(",
"$",
"competencyid",
")",
";",
"$",
"exists",
"=",
"course_module_competency",
"::",
"get_record",
"(",
"array",
"(",
"'cmid'",
"=>",
"$",
"cm",
"->",
"id",
",",
"'competencyid'",
"=>",
"$",
"competencyid",
")",
")",
";",
"if",
"(",
"$",
"exists",
")",
"{",
"return",
"$",
"exists",
"->",
"delete",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Remove a competency from this course module.
@param mixed $cmorid The course module, or id of the course module
@param int $competencyid The id of the competency
@return bool
|
[
"Remove",
"a",
"competency",
"from",
"this",
"course",
"module",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L1470-L1494
|
217,239
|
moodle/moodle
|
competency/classes/api.php
|
api.reorder_course_module_competency
|
public static function reorder_course_module_competency($cmorid, $competencyidfrom, $competencyidto) {
static::require_enabled();
$cm = $cmorid;
if (!is_object($cmorid)) {
$cm = get_coursemodule_from_id('', $cmorid, 0, true, MUST_EXIST);
}
// Check the user have access to the course module.
self::validate_course_module($cm);
// First we do a permissions check.
$context = context_module::instance($cm->id);
require_capability('moodle/competency:coursecompetencymanage', $context);
$down = true;
$matches = course_module_competency::get_records(array('cmid' => $cm->id, 'competencyid' => $competencyidfrom));
if (count($matches) == 0) {
throw new coding_exception('The link does not exist');
}
$competencyfrom = array_pop($matches);
$matches = course_module_competency::get_records(array('cmid' => $cm->id, 'competencyid' => $competencyidto));
if (count($matches) == 0) {
throw new coding_exception('The link does not exist');
}
$competencyto = array_pop($matches);
$all = course_module_competency::get_records(array('cmid' => $cm->id), 'sortorder', 'ASC', 0, 0);
if ($competencyfrom->get('sortorder') > $competencyto->get('sortorder')) {
// We are moving up, so put it before the "to" item.
$down = false;
}
foreach ($all as $id => $coursemodulecompetency) {
$sort = $coursemodulecompetency->get('sortorder');
if ($down && $sort > $competencyfrom->get('sortorder') && $sort <= $competencyto->get('sortorder')) {
$coursemodulecompetency->set('sortorder', $coursemodulecompetency->get('sortorder') - 1);
$coursemodulecompetency->update();
} else if (!$down && $sort >= $competencyto->get('sortorder') && $sort < $competencyfrom->get('sortorder')) {
$coursemodulecompetency->set('sortorder', $coursemodulecompetency->get('sortorder') + 1);
$coursemodulecompetency->update();
}
}
$competencyfrom->set('sortorder', $competencyto->get('sortorder'));
return $competencyfrom->update();
}
|
php
|
public static function reorder_course_module_competency($cmorid, $competencyidfrom, $competencyidto) {
static::require_enabled();
$cm = $cmorid;
if (!is_object($cmorid)) {
$cm = get_coursemodule_from_id('', $cmorid, 0, true, MUST_EXIST);
}
// Check the user have access to the course module.
self::validate_course_module($cm);
// First we do a permissions check.
$context = context_module::instance($cm->id);
require_capability('moodle/competency:coursecompetencymanage', $context);
$down = true;
$matches = course_module_competency::get_records(array('cmid' => $cm->id, 'competencyid' => $competencyidfrom));
if (count($matches) == 0) {
throw new coding_exception('The link does not exist');
}
$competencyfrom = array_pop($matches);
$matches = course_module_competency::get_records(array('cmid' => $cm->id, 'competencyid' => $competencyidto));
if (count($matches) == 0) {
throw new coding_exception('The link does not exist');
}
$competencyto = array_pop($matches);
$all = course_module_competency::get_records(array('cmid' => $cm->id), 'sortorder', 'ASC', 0, 0);
if ($competencyfrom->get('sortorder') > $competencyto->get('sortorder')) {
// We are moving up, so put it before the "to" item.
$down = false;
}
foreach ($all as $id => $coursemodulecompetency) {
$sort = $coursemodulecompetency->get('sortorder');
if ($down && $sort > $competencyfrom->get('sortorder') && $sort <= $competencyto->get('sortorder')) {
$coursemodulecompetency->set('sortorder', $coursemodulecompetency->get('sortorder') - 1);
$coursemodulecompetency->update();
} else if (!$down && $sort >= $competencyto->get('sortorder') && $sort < $competencyfrom->get('sortorder')) {
$coursemodulecompetency->set('sortorder', $coursemodulecompetency->get('sortorder') + 1);
$coursemodulecompetency->update();
}
}
$competencyfrom->set('sortorder', $competencyto->get('sortorder'));
return $competencyfrom->update();
}
|
[
"public",
"static",
"function",
"reorder_course_module_competency",
"(",
"$",
"cmorid",
",",
"$",
"competencyidfrom",
",",
"$",
"competencyidto",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"cm",
"=",
"$",
"cmorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"cmorid",
")",
")",
"{",
"$",
"cm",
"=",
"get_coursemodule_from_id",
"(",
"''",
",",
"$",
"cmorid",
",",
"0",
",",
"true",
",",
"MUST_EXIST",
")",
";",
"}",
"// Check the user have access to the course module.",
"self",
"::",
"validate_course_module",
"(",
"$",
"cm",
")",
";",
"// First we do a permissions check.",
"$",
"context",
"=",
"context_module",
"::",
"instance",
"(",
"$",
"cm",
"->",
"id",
")",
";",
"require_capability",
"(",
"'moodle/competency:coursecompetencymanage'",
",",
"$",
"context",
")",
";",
"$",
"down",
"=",
"true",
";",
"$",
"matches",
"=",
"course_module_competency",
"::",
"get_records",
"(",
"array",
"(",
"'cmid'",
"=>",
"$",
"cm",
"->",
"id",
",",
"'competencyid'",
"=>",
"$",
"competencyidfrom",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"matches",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The link does not exist'",
")",
";",
"}",
"$",
"competencyfrom",
"=",
"array_pop",
"(",
"$",
"matches",
")",
";",
"$",
"matches",
"=",
"course_module_competency",
"::",
"get_records",
"(",
"array",
"(",
"'cmid'",
"=>",
"$",
"cm",
"->",
"id",
",",
"'competencyid'",
"=>",
"$",
"competencyidto",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"matches",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The link does not exist'",
")",
";",
"}",
"$",
"competencyto",
"=",
"array_pop",
"(",
"$",
"matches",
")",
";",
"$",
"all",
"=",
"course_module_competency",
"::",
"get_records",
"(",
"array",
"(",
"'cmid'",
"=>",
"$",
"cm",
"->",
"id",
")",
",",
"'sortorder'",
",",
"'ASC'",
",",
"0",
",",
"0",
")",
";",
"if",
"(",
"$",
"competencyfrom",
"->",
"get",
"(",
"'sortorder'",
")",
">",
"$",
"competencyto",
"->",
"get",
"(",
"'sortorder'",
")",
")",
"{",
"// We are moving up, so put it before the \"to\" item.",
"$",
"down",
"=",
"false",
";",
"}",
"foreach",
"(",
"$",
"all",
"as",
"$",
"id",
"=>",
"$",
"coursemodulecompetency",
")",
"{",
"$",
"sort",
"=",
"$",
"coursemodulecompetency",
"->",
"get",
"(",
"'sortorder'",
")",
";",
"if",
"(",
"$",
"down",
"&&",
"$",
"sort",
">",
"$",
"competencyfrom",
"->",
"get",
"(",
"'sortorder'",
")",
"&&",
"$",
"sort",
"<=",
"$",
"competencyto",
"->",
"get",
"(",
"'sortorder'",
")",
")",
"{",
"$",
"coursemodulecompetency",
"->",
"set",
"(",
"'sortorder'",
",",
"$",
"coursemodulecompetency",
"->",
"get",
"(",
"'sortorder'",
")",
"-",
"1",
")",
";",
"$",
"coursemodulecompetency",
"->",
"update",
"(",
")",
";",
"}",
"else",
"if",
"(",
"!",
"$",
"down",
"&&",
"$",
"sort",
">=",
"$",
"competencyto",
"->",
"get",
"(",
"'sortorder'",
")",
"&&",
"$",
"sort",
"<",
"$",
"competencyfrom",
"->",
"get",
"(",
"'sortorder'",
")",
")",
"{",
"$",
"coursemodulecompetency",
"->",
"set",
"(",
"'sortorder'",
",",
"$",
"coursemodulecompetency",
"->",
"get",
"(",
"'sortorder'",
")",
"+",
"1",
")",
";",
"$",
"coursemodulecompetency",
"->",
"update",
"(",
")",
";",
"}",
"}",
"$",
"competencyfrom",
"->",
"set",
"(",
"'sortorder'",
",",
"$",
"competencyto",
"->",
"get",
"(",
"'sortorder'",
")",
")",
";",
"return",
"$",
"competencyfrom",
"->",
"update",
"(",
")",
";",
"}"
] |
Move the course module competency up or down in the display list.
Requires moodle/competency:coursecompetencymanage capability at the course module context.
@param mixed $cmorid The course module, or id of the course module
@param int $competencyidfrom The id of the competency we are moving.
@param int $competencyidto The id of the competency we are moving to.
@return boolean
|
[
"Move",
"the",
"course",
"module",
"competency",
"up",
"or",
"down",
"in",
"the",
"display",
"list",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L1506-L1553
|
217,240
|
moodle/moodle
|
competency/classes/api.php
|
api.set_course_module_competency_ruleoutcome
|
public static function set_course_module_competency_ruleoutcome($coursemodulecompetencyorid, $ruleoutcome) {
static::require_enabled();
$coursemodulecompetency = $coursemodulecompetencyorid;
if (!is_object($coursemodulecompetency)) {
$coursemodulecompetency = new course_module_competency($coursemodulecompetencyorid);
}
$cm = get_coursemodule_from_id('', $coursemodulecompetency->get('cmid'), 0, true, MUST_EXIST);
self::validate_course_module($cm);
$context = context_module::instance($cm->id);
require_capability('moodle/competency:coursecompetencymanage', $context);
$coursemodulecompetency->set('ruleoutcome', $ruleoutcome);
return $coursemodulecompetency->update();
}
|
php
|
public static function set_course_module_competency_ruleoutcome($coursemodulecompetencyorid, $ruleoutcome) {
static::require_enabled();
$coursemodulecompetency = $coursemodulecompetencyorid;
if (!is_object($coursemodulecompetency)) {
$coursemodulecompetency = new course_module_competency($coursemodulecompetencyorid);
}
$cm = get_coursemodule_from_id('', $coursemodulecompetency->get('cmid'), 0, true, MUST_EXIST);
self::validate_course_module($cm);
$context = context_module::instance($cm->id);
require_capability('moodle/competency:coursecompetencymanage', $context);
$coursemodulecompetency->set('ruleoutcome', $ruleoutcome);
return $coursemodulecompetency->update();
}
|
[
"public",
"static",
"function",
"set_course_module_competency_ruleoutcome",
"(",
"$",
"coursemodulecompetencyorid",
",",
"$",
"ruleoutcome",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"coursemodulecompetency",
"=",
"$",
"coursemodulecompetencyorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"coursemodulecompetency",
")",
")",
"{",
"$",
"coursemodulecompetency",
"=",
"new",
"course_module_competency",
"(",
"$",
"coursemodulecompetencyorid",
")",
";",
"}",
"$",
"cm",
"=",
"get_coursemodule_from_id",
"(",
"''",
",",
"$",
"coursemodulecompetency",
"->",
"get",
"(",
"'cmid'",
")",
",",
"0",
",",
"true",
",",
"MUST_EXIST",
")",
";",
"self",
"::",
"validate_course_module",
"(",
"$",
"cm",
")",
";",
"$",
"context",
"=",
"context_module",
"::",
"instance",
"(",
"$",
"cm",
"->",
"id",
")",
";",
"require_capability",
"(",
"'moodle/competency:coursecompetencymanage'",
",",
"$",
"context",
")",
";",
"$",
"coursemodulecompetency",
"->",
"set",
"(",
"'ruleoutcome'",
",",
"$",
"ruleoutcome",
")",
";",
"return",
"$",
"coursemodulecompetency",
"->",
"update",
"(",
")",
";",
"}"
] |
Update ruleoutcome value for a course module competency.
@param int|course_module_competency $coursemodulecompetencyorid The course_module_competency, or its ID.
@param int $ruleoutcome The value of ruleoutcome.
@return bool True on success.
|
[
"Update",
"ruleoutcome",
"value",
"for",
"a",
"course",
"module",
"competency",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L1562-L1578
|
217,241
|
moodle/moodle
|
competency/classes/api.php
|
api.add_competency_to_course
|
public static function add_competency_to_course($courseid, $competencyid) {
static::require_enabled();
// Check the user have access to the course.
self::validate_course($courseid);
// First we do a permissions check.
$context = context_course::instance($courseid);
require_capability('moodle/competency:coursecompetencymanage', $context);
$record = new stdClass();
$record->courseid = $courseid;
$record->competencyid = $competencyid;
$competency = new competency($competencyid);
// Can not add a competency that belong to a hidden framework.
if ($competency->get_framework()->get('visible') == false) {
throw new coding_exception('A competency belonging to hidden framework can not be linked to course');
}
$coursecompetency = new course_competency();
$exists = $coursecompetency->get_records(array('courseid' => $courseid, 'competencyid' => $competencyid));
if (!$exists) {
$coursecompetency->from_record($record);
if ($coursecompetency->create()) {
return true;
}
}
return false;
}
|
php
|
public static function add_competency_to_course($courseid, $competencyid) {
static::require_enabled();
// Check the user have access to the course.
self::validate_course($courseid);
// First we do a permissions check.
$context = context_course::instance($courseid);
require_capability('moodle/competency:coursecompetencymanage', $context);
$record = new stdClass();
$record->courseid = $courseid;
$record->competencyid = $competencyid;
$competency = new competency($competencyid);
// Can not add a competency that belong to a hidden framework.
if ($competency->get_framework()->get('visible') == false) {
throw new coding_exception('A competency belonging to hidden framework can not be linked to course');
}
$coursecompetency = new course_competency();
$exists = $coursecompetency->get_records(array('courseid' => $courseid, 'competencyid' => $competencyid));
if (!$exists) {
$coursecompetency->from_record($record);
if ($coursecompetency->create()) {
return true;
}
}
return false;
}
|
[
"public",
"static",
"function",
"add_competency_to_course",
"(",
"$",
"courseid",
",",
"$",
"competencyid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"// Check the user have access to the course.",
"self",
"::",
"validate_course",
"(",
"$",
"courseid",
")",
";",
"// First we do a permissions check.",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"courseid",
")",
";",
"require_capability",
"(",
"'moodle/competency:coursecompetencymanage'",
",",
"$",
"context",
")",
";",
"$",
"record",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"record",
"->",
"courseid",
"=",
"$",
"courseid",
";",
"$",
"record",
"->",
"competencyid",
"=",
"$",
"competencyid",
";",
"$",
"competency",
"=",
"new",
"competency",
"(",
"$",
"competencyid",
")",
";",
"// Can not add a competency that belong to a hidden framework.",
"if",
"(",
"$",
"competency",
"->",
"get_framework",
"(",
")",
"->",
"get",
"(",
"'visible'",
")",
"==",
"false",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'A competency belonging to hidden framework can not be linked to course'",
")",
";",
"}",
"$",
"coursecompetency",
"=",
"new",
"course_competency",
"(",
")",
";",
"$",
"exists",
"=",
"$",
"coursecompetency",
"->",
"get_records",
"(",
"array",
"(",
"'courseid'",
"=>",
"$",
"courseid",
",",
"'competencyid'",
"=>",
"$",
"competencyid",
")",
")",
";",
"if",
"(",
"!",
"$",
"exists",
")",
"{",
"$",
"coursecompetency",
"->",
"from_record",
"(",
"$",
"record",
")",
";",
"if",
"(",
"$",
"coursecompetency",
"->",
"create",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Add a competency to this course.
@param int $courseid The id of the course
@param int $competencyid The id of the competency
@return bool
|
[
"Add",
"a",
"competency",
"to",
"this",
"course",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L1587-L1617
|
217,242
|
moodle/moodle
|
competency/classes/api.php
|
api.remove_competency_from_course
|
public static function remove_competency_from_course($courseid, $competencyid) {
static::require_enabled();
// Check the user have access to the course.
self::validate_course($courseid);
// First we do a permissions check.
$context = context_course::instance($courseid);
require_capability('moodle/competency:coursecompetencymanage', $context);
$record = new stdClass();
$record->courseid = $courseid;
$record->competencyid = $competencyid;
$coursecompetency = new course_competency();
$exists = course_competency::get_record(array('courseid' => $courseid, 'competencyid' => $competencyid));
if ($exists) {
// Delete all course_module_competencies for this competency in this course.
$cmcs = course_module_competency::get_records_by_competencyid_in_course($competencyid, $courseid);
foreach ($cmcs as $cmc) {
$cmc->delete();
}
return $exists->delete();
}
return false;
}
|
php
|
public static function remove_competency_from_course($courseid, $competencyid) {
static::require_enabled();
// Check the user have access to the course.
self::validate_course($courseid);
// First we do a permissions check.
$context = context_course::instance($courseid);
require_capability('moodle/competency:coursecompetencymanage', $context);
$record = new stdClass();
$record->courseid = $courseid;
$record->competencyid = $competencyid;
$coursecompetency = new course_competency();
$exists = course_competency::get_record(array('courseid' => $courseid, 'competencyid' => $competencyid));
if ($exists) {
// Delete all course_module_competencies for this competency in this course.
$cmcs = course_module_competency::get_records_by_competencyid_in_course($competencyid, $courseid);
foreach ($cmcs as $cmc) {
$cmc->delete();
}
return $exists->delete();
}
return false;
}
|
[
"public",
"static",
"function",
"remove_competency_from_course",
"(",
"$",
"courseid",
",",
"$",
"competencyid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"// Check the user have access to the course.",
"self",
"::",
"validate_course",
"(",
"$",
"courseid",
")",
";",
"// First we do a permissions check.",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"courseid",
")",
";",
"require_capability",
"(",
"'moodle/competency:coursecompetencymanage'",
",",
"$",
"context",
")",
";",
"$",
"record",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"record",
"->",
"courseid",
"=",
"$",
"courseid",
";",
"$",
"record",
"->",
"competencyid",
"=",
"$",
"competencyid",
";",
"$",
"coursecompetency",
"=",
"new",
"course_competency",
"(",
")",
";",
"$",
"exists",
"=",
"course_competency",
"::",
"get_record",
"(",
"array",
"(",
"'courseid'",
"=>",
"$",
"courseid",
",",
"'competencyid'",
"=>",
"$",
"competencyid",
")",
")",
";",
"if",
"(",
"$",
"exists",
")",
"{",
"// Delete all course_module_competencies for this competency in this course.",
"$",
"cmcs",
"=",
"course_module_competency",
"::",
"get_records_by_competencyid_in_course",
"(",
"$",
"competencyid",
",",
"$",
"courseid",
")",
";",
"foreach",
"(",
"$",
"cmcs",
"as",
"$",
"cmc",
")",
"{",
"$",
"cmc",
"->",
"delete",
"(",
")",
";",
"}",
"return",
"$",
"exists",
"->",
"delete",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Remove a competency from this course.
@param int $courseid The id of the course
@param int $competencyid The id of the competency
@return bool
|
[
"Remove",
"a",
"competency",
"from",
"this",
"course",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L1626-L1651
|
217,243
|
moodle/moodle
|
competency/classes/api.php
|
api.reorder_course_competency
|
public static function reorder_course_competency($courseid, $competencyidfrom, $competencyidto) {
static::require_enabled();
// Check the user have access to the course.
self::validate_course($courseid);
// First we do a permissions check.
$context = context_course::instance($courseid);
require_capability('moodle/competency:coursecompetencymanage', $context);
$down = true;
$coursecompetency = new course_competency();
$matches = $coursecompetency->get_records(array('courseid' => $courseid, 'competencyid' => $competencyidfrom));
if (count($matches) == 0) {
throw new coding_exception('The link does not exist');
}
$competencyfrom = array_pop($matches);
$matches = $coursecompetency->get_records(array('courseid' => $courseid, 'competencyid' => $competencyidto));
if (count($matches) == 0) {
throw new coding_exception('The link does not exist');
}
$competencyto = array_pop($matches);
$all = $coursecompetency->get_records(array('courseid' => $courseid), 'sortorder', 'ASC', 0, 0);
if ($competencyfrom->get('sortorder') > $competencyto->get('sortorder')) {
// We are moving up, so put it before the "to" item.
$down = false;
}
foreach ($all as $id => $coursecompetency) {
$sort = $coursecompetency->get('sortorder');
if ($down && $sort > $competencyfrom->get('sortorder') && $sort <= $competencyto->get('sortorder')) {
$coursecompetency->set('sortorder', $coursecompetency->get('sortorder') - 1);
$coursecompetency->update();
} else if (!$down && $sort >= $competencyto->get('sortorder') && $sort < $competencyfrom->get('sortorder')) {
$coursecompetency->set('sortorder', $coursecompetency->get('sortorder') + 1);
$coursecompetency->update();
}
}
$competencyfrom->set('sortorder', $competencyto->get('sortorder'));
return $competencyfrom->update();
}
|
php
|
public static function reorder_course_competency($courseid, $competencyidfrom, $competencyidto) {
static::require_enabled();
// Check the user have access to the course.
self::validate_course($courseid);
// First we do a permissions check.
$context = context_course::instance($courseid);
require_capability('moodle/competency:coursecompetencymanage', $context);
$down = true;
$coursecompetency = new course_competency();
$matches = $coursecompetency->get_records(array('courseid' => $courseid, 'competencyid' => $competencyidfrom));
if (count($matches) == 0) {
throw new coding_exception('The link does not exist');
}
$competencyfrom = array_pop($matches);
$matches = $coursecompetency->get_records(array('courseid' => $courseid, 'competencyid' => $competencyidto));
if (count($matches) == 0) {
throw new coding_exception('The link does not exist');
}
$competencyto = array_pop($matches);
$all = $coursecompetency->get_records(array('courseid' => $courseid), 'sortorder', 'ASC', 0, 0);
if ($competencyfrom->get('sortorder') > $competencyto->get('sortorder')) {
// We are moving up, so put it before the "to" item.
$down = false;
}
foreach ($all as $id => $coursecompetency) {
$sort = $coursecompetency->get('sortorder');
if ($down && $sort > $competencyfrom->get('sortorder') && $sort <= $competencyto->get('sortorder')) {
$coursecompetency->set('sortorder', $coursecompetency->get('sortorder') - 1);
$coursecompetency->update();
} else if (!$down && $sort >= $competencyto->get('sortorder') && $sort < $competencyfrom->get('sortorder')) {
$coursecompetency->set('sortorder', $coursecompetency->get('sortorder') + 1);
$coursecompetency->update();
}
}
$competencyfrom->set('sortorder', $competencyto->get('sortorder'));
return $competencyfrom->update();
}
|
[
"public",
"static",
"function",
"reorder_course_competency",
"(",
"$",
"courseid",
",",
"$",
"competencyidfrom",
",",
"$",
"competencyidto",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"// Check the user have access to the course.",
"self",
"::",
"validate_course",
"(",
"$",
"courseid",
")",
";",
"// First we do a permissions check.",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"courseid",
")",
";",
"require_capability",
"(",
"'moodle/competency:coursecompetencymanage'",
",",
"$",
"context",
")",
";",
"$",
"down",
"=",
"true",
";",
"$",
"coursecompetency",
"=",
"new",
"course_competency",
"(",
")",
";",
"$",
"matches",
"=",
"$",
"coursecompetency",
"->",
"get_records",
"(",
"array",
"(",
"'courseid'",
"=>",
"$",
"courseid",
",",
"'competencyid'",
"=>",
"$",
"competencyidfrom",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"matches",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The link does not exist'",
")",
";",
"}",
"$",
"competencyfrom",
"=",
"array_pop",
"(",
"$",
"matches",
")",
";",
"$",
"matches",
"=",
"$",
"coursecompetency",
"->",
"get_records",
"(",
"array",
"(",
"'courseid'",
"=>",
"$",
"courseid",
",",
"'competencyid'",
"=>",
"$",
"competencyidto",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"matches",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The link does not exist'",
")",
";",
"}",
"$",
"competencyto",
"=",
"array_pop",
"(",
"$",
"matches",
")",
";",
"$",
"all",
"=",
"$",
"coursecompetency",
"->",
"get_records",
"(",
"array",
"(",
"'courseid'",
"=>",
"$",
"courseid",
")",
",",
"'sortorder'",
",",
"'ASC'",
",",
"0",
",",
"0",
")",
";",
"if",
"(",
"$",
"competencyfrom",
"->",
"get",
"(",
"'sortorder'",
")",
">",
"$",
"competencyto",
"->",
"get",
"(",
"'sortorder'",
")",
")",
"{",
"// We are moving up, so put it before the \"to\" item.",
"$",
"down",
"=",
"false",
";",
"}",
"foreach",
"(",
"$",
"all",
"as",
"$",
"id",
"=>",
"$",
"coursecompetency",
")",
"{",
"$",
"sort",
"=",
"$",
"coursecompetency",
"->",
"get",
"(",
"'sortorder'",
")",
";",
"if",
"(",
"$",
"down",
"&&",
"$",
"sort",
">",
"$",
"competencyfrom",
"->",
"get",
"(",
"'sortorder'",
")",
"&&",
"$",
"sort",
"<=",
"$",
"competencyto",
"->",
"get",
"(",
"'sortorder'",
")",
")",
"{",
"$",
"coursecompetency",
"->",
"set",
"(",
"'sortorder'",
",",
"$",
"coursecompetency",
"->",
"get",
"(",
"'sortorder'",
")",
"-",
"1",
")",
";",
"$",
"coursecompetency",
"->",
"update",
"(",
")",
";",
"}",
"else",
"if",
"(",
"!",
"$",
"down",
"&&",
"$",
"sort",
">=",
"$",
"competencyto",
"->",
"get",
"(",
"'sortorder'",
")",
"&&",
"$",
"sort",
"<",
"$",
"competencyfrom",
"->",
"get",
"(",
"'sortorder'",
")",
")",
"{",
"$",
"coursecompetency",
"->",
"set",
"(",
"'sortorder'",
",",
"$",
"coursecompetency",
"->",
"get",
"(",
"'sortorder'",
")",
"+",
"1",
")",
";",
"$",
"coursecompetency",
"->",
"update",
"(",
")",
";",
"}",
"}",
"$",
"competencyfrom",
"->",
"set",
"(",
"'sortorder'",
",",
"$",
"competencyto",
"->",
"get",
"(",
"'sortorder'",
")",
")",
";",
"return",
"$",
"competencyfrom",
"->",
"update",
"(",
")",
";",
"}"
] |
Move the course competency up or down in the display list.
Requires moodle/competency:coursecompetencymanage capability at the course context.
@param int $courseid The course
@param int $competencyidfrom The id of the competency we are moving.
@param int $competencyidto The id of the competency we are moving to.
@return boolean
|
[
"Move",
"the",
"course",
"competency",
"up",
"or",
"down",
"in",
"the",
"display",
"list",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L1663-L1707
|
217,244
|
moodle/moodle
|
competency/classes/api.php
|
api.set_course_competency_ruleoutcome
|
public static function set_course_competency_ruleoutcome($coursecompetencyorid, $ruleoutcome) {
static::require_enabled();
$coursecompetency = $coursecompetencyorid;
if (!is_object($coursecompetency)) {
$coursecompetency = new course_competency($coursecompetencyorid);
}
$courseid = $coursecompetency->get('courseid');
self::validate_course($courseid);
$coursecontext = context_course::instance($courseid);
require_capability('moodle/competency:coursecompetencymanage', $coursecontext);
$coursecompetency->set('ruleoutcome', $ruleoutcome);
return $coursecompetency->update();
}
|
php
|
public static function set_course_competency_ruleoutcome($coursecompetencyorid, $ruleoutcome) {
static::require_enabled();
$coursecompetency = $coursecompetencyorid;
if (!is_object($coursecompetency)) {
$coursecompetency = new course_competency($coursecompetencyorid);
}
$courseid = $coursecompetency->get('courseid');
self::validate_course($courseid);
$coursecontext = context_course::instance($courseid);
require_capability('moodle/competency:coursecompetencymanage', $coursecontext);
$coursecompetency->set('ruleoutcome', $ruleoutcome);
return $coursecompetency->update();
}
|
[
"public",
"static",
"function",
"set_course_competency_ruleoutcome",
"(",
"$",
"coursecompetencyorid",
",",
"$",
"ruleoutcome",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"coursecompetency",
"=",
"$",
"coursecompetencyorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"coursecompetency",
")",
")",
"{",
"$",
"coursecompetency",
"=",
"new",
"course_competency",
"(",
"$",
"coursecompetencyorid",
")",
";",
"}",
"$",
"courseid",
"=",
"$",
"coursecompetency",
"->",
"get",
"(",
"'courseid'",
")",
";",
"self",
"::",
"validate_course",
"(",
"$",
"courseid",
")",
";",
"$",
"coursecontext",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"courseid",
")",
";",
"require_capability",
"(",
"'moodle/competency:coursecompetencymanage'",
",",
"$",
"coursecontext",
")",
";",
"$",
"coursecompetency",
"->",
"set",
"(",
"'ruleoutcome'",
",",
"$",
"ruleoutcome",
")",
";",
"return",
"$",
"coursecompetency",
"->",
"update",
"(",
")",
";",
"}"
] |
Update ruleoutcome value for a course competency.
@param int|course_competency $coursecompetencyorid The course_competency, or its ID.
@param int $ruleoutcome The value of ruleoutcome.
@return bool True on success.
|
[
"Update",
"ruleoutcome",
"value",
"for",
"a",
"course",
"competency",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L1716-L1731
|
217,245
|
moodle/moodle
|
competency/classes/api.php
|
api.create_template
|
public static function create_template(stdClass $record) {
static::require_enabled();
$template = new template(0, $record);
// First we do a permissions check.
if (!$template->can_manage()) {
throw new required_capability_exception($template->get_context(), 'moodle/competency:templatemanage',
'nopermissions', '');
}
// OK - all set.
$template = $template->create();
// Trigger a template created event.
\core\event\competency_template_created::create_from_template($template)->trigger();
return $template;
}
|
php
|
public static function create_template(stdClass $record) {
static::require_enabled();
$template = new template(0, $record);
// First we do a permissions check.
if (!$template->can_manage()) {
throw new required_capability_exception($template->get_context(), 'moodle/competency:templatemanage',
'nopermissions', '');
}
// OK - all set.
$template = $template->create();
// Trigger a template created event.
\core\event\competency_template_created::create_from_template($template)->trigger();
return $template;
}
|
[
"public",
"static",
"function",
"create_template",
"(",
"stdClass",
"$",
"record",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"template",
"=",
"new",
"template",
"(",
"0",
",",
"$",
"record",
")",
";",
"// First we do a permissions check.",
"if",
"(",
"!",
"$",
"template",
"->",
"can_manage",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"template",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:templatemanage'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// OK - all set.",
"$",
"template",
"=",
"$",
"template",
"->",
"create",
"(",
")",
";",
"// Trigger a template created event.",
"\\",
"core",
"\\",
"event",
"\\",
"competency_template_created",
"::",
"create_from_template",
"(",
"$",
"template",
")",
"->",
"trigger",
"(",
")",
";",
"return",
"$",
"template",
";",
"}"
] |
Create a learning plan template from a record containing all the data for the class.
Requires moodle/competency:templatemanage capability.
@param stdClass $record Record containing all the data for an instance of the class.
@return template
|
[
"Create",
"a",
"learning",
"plan",
"template",
"from",
"a",
"record",
"containing",
"all",
"the",
"data",
"for",
"the",
"class",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L1741-L1758
|
217,246
|
moodle/moodle
|
competency/classes/api.php
|
api.delete_template
|
public static function delete_template($id, $deleteplans = true) {
global $DB;
static::require_enabled();
$template = new template($id);
// First we do a permissions check.
if (!$template->can_manage()) {
throw new required_capability_exception($template->get_context(), 'moodle/competency:templatemanage',
'nopermissions', '');
}
$transaction = $DB->start_delegated_transaction();
$success = true;
// Check if there are cohorts associated.
$templatecohorts = template_cohort::get_relations_by_templateid($template->get('id'));
foreach ($templatecohorts as $templatecohort) {
$success = $templatecohort->delete();
if (!$success) {
break;
}
}
// Still OK, delete or unlink the plans from the template.
if ($success) {
$plans = plan::get_records(array('templateid' => $template->get('id')));
foreach ($plans as $plan) {
$success = $deleteplans ? self::delete_plan($plan->get('id')) : self::unlink_plan_from_template($plan);
if (!$success) {
break;
}
}
}
// Still OK, delete the template comptencies.
if ($success) {
$success = template_competency::delete_by_templateid($template->get('id'));
}
// OK - all set.
if ($success) {
// Create a template deleted event.
$event = \core\event\competency_template_deleted::create_from_template($template);
$success = $template->delete();
}
if ($success) {
// Trigger a template deleted event.
$event->trigger();
// Commit the transaction.
$transaction->allow_commit();
} else {
$transaction->rollback(new moodle_exception('Error while deleting the template.'));
}
return $success;
}
|
php
|
public static function delete_template($id, $deleteplans = true) {
global $DB;
static::require_enabled();
$template = new template($id);
// First we do a permissions check.
if (!$template->can_manage()) {
throw new required_capability_exception($template->get_context(), 'moodle/competency:templatemanage',
'nopermissions', '');
}
$transaction = $DB->start_delegated_transaction();
$success = true;
// Check if there are cohorts associated.
$templatecohorts = template_cohort::get_relations_by_templateid($template->get('id'));
foreach ($templatecohorts as $templatecohort) {
$success = $templatecohort->delete();
if (!$success) {
break;
}
}
// Still OK, delete or unlink the plans from the template.
if ($success) {
$plans = plan::get_records(array('templateid' => $template->get('id')));
foreach ($plans as $plan) {
$success = $deleteplans ? self::delete_plan($plan->get('id')) : self::unlink_plan_from_template($plan);
if (!$success) {
break;
}
}
}
// Still OK, delete the template comptencies.
if ($success) {
$success = template_competency::delete_by_templateid($template->get('id'));
}
// OK - all set.
if ($success) {
// Create a template deleted event.
$event = \core\event\competency_template_deleted::create_from_template($template);
$success = $template->delete();
}
if ($success) {
// Trigger a template deleted event.
$event->trigger();
// Commit the transaction.
$transaction->allow_commit();
} else {
$transaction->rollback(new moodle_exception('Error while deleting the template.'));
}
return $success;
}
|
[
"public",
"static",
"function",
"delete_template",
"(",
"$",
"id",
",",
"$",
"deleteplans",
"=",
"true",
")",
"{",
"global",
"$",
"DB",
";",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"template",
"=",
"new",
"template",
"(",
"$",
"id",
")",
";",
"// First we do a permissions check.",
"if",
"(",
"!",
"$",
"template",
"->",
"can_manage",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"template",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:templatemanage'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"$",
"transaction",
"=",
"$",
"DB",
"->",
"start_delegated_transaction",
"(",
")",
";",
"$",
"success",
"=",
"true",
";",
"// Check if there are cohorts associated.",
"$",
"templatecohorts",
"=",
"template_cohort",
"::",
"get_relations_by_templateid",
"(",
"$",
"template",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"foreach",
"(",
"$",
"templatecohorts",
"as",
"$",
"templatecohort",
")",
"{",
"$",
"success",
"=",
"$",
"templatecohort",
"->",
"delete",
"(",
")",
";",
"if",
"(",
"!",
"$",
"success",
")",
"{",
"break",
";",
"}",
"}",
"// Still OK, delete or unlink the plans from the template.",
"if",
"(",
"$",
"success",
")",
"{",
"$",
"plans",
"=",
"plan",
"::",
"get_records",
"(",
"array",
"(",
"'templateid'",
"=>",
"$",
"template",
"->",
"get",
"(",
"'id'",
")",
")",
")",
";",
"foreach",
"(",
"$",
"plans",
"as",
"$",
"plan",
")",
"{",
"$",
"success",
"=",
"$",
"deleteplans",
"?",
"self",
"::",
"delete_plan",
"(",
"$",
"plan",
"->",
"get",
"(",
"'id'",
")",
")",
":",
"self",
"::",
"unlink_plan_from_template",
"(",
"$",
"plan",
")",
";",
"if",
"(",
"!",
"$",
"success",
")",
"{",
"break",
";",
"}",
"}",
"}",
"// Still OK, delete the template comptencies.",
"if",
"(",
"$",
"success",
")",
"{",
"$",
"success",
"=",
"template_competency",
"::",
"delete_by_templateid",
"(",
"$",
"template",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"}",
"// OK - all set.",
"if",
"(",
"$",
"success",
")",
"{",
"// Create a template deleted event.",
"$",
"event",
"=",
"\\",
"core",
"\\",
"event",
"\\",
"competency_template_deleted",
"::",
"create_from_template",
"(",
"$",
"template",
")",
";",
"$",
"success",
"=",
"$",
"template",
"->",
"delete",
"(",
")",
";",
"}",
"if",
"(",
"$",
"success",
")",
"{",
"// Trigger a template deleted event.",
"$",
"event",
"->",
"trigger",
"(",
")",
";",
"// Commit the transaction.",
"$",
"transaction",
"->",
"allow_commit",
"(",
")",
";",
"}",
"else",
"{",
"$",
"transaction",
"->",
"rollback",
"(",
"new",
"moodle_exception",
"(",
"'Error while deleting the template.'",
")",
")",
";",
"}",
"return",
"$",
"success",
";",
"}"
] |
Delete a learning plan template by id.
If the learning plan template has associated cohorts they will be deleted.
Requires moodle/competency:templatemanage capability.
@param int $id The record to delete.
@param boolean $deleteplans True to delete plans associaated to template, false to unlink them.
@return boolean
|
[
"Delete",
"a",
"learning",
"plan",
"template",
"by",
"id",
".",
"If",
"the",
"learning",
"plan",
"template",
"has",
"associated",
"cohorts",
"they",
"will",
"be",
"deleted",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L1808-L1866
|
217,247
|
moodle/moodle
|
competency/classes/api.php
|
api.update_template
|
public static function update_template($record) {
global $DB;
static::require_enabled();
$template = new template($record->id);
// First we do a permissions check.
if (!$template->can_manage()) {
throw new required_capability_exception($template->get_context(), 'moodle/competency:templatemanage',
'nopermissions', '');
} else if (isset($record->contextid) && $record->contextid != $template->get('contextid')) {
// We can never change the context of a template.
throw new coding_exception('Changing the context of an existing tempalte is forbidden.');
}
$updateplans = false;
$before = $template->to_record();
$template->from_record($record);
$after = $template->to_record();
// Should we update the related plans?
if ($before->duedate != $after->duedate ||
$before->shortname != $after->shortname ||
$before->description != $after->description ||
$before->descriptionformat != $after->descriptionformat) {
$updateplans = true;
}
$transaction = $DB->start_delegated_transaction();
$success = $template->update();
if (!$success) {
$transaction->rollback(new moodle_exception('Error while updating the template.'));
return $success;
}
// Trigger a template updated event.
\core\event\competency_template_updated::create_from_template($template)->trigger();
if ($updateplans) {
plan::update_multiple_from_template($template);
}
$transaction->allow_commit();
return $success;
}
|
php
|
public static function update_template($record) {
global $DB;
static::require_enabled();
$template = new template($record->id);
// First we do a permissions check.
if (!$template->can_manage()) {
throw new required_capability_exception($template->get_context(), 'moodle/competency:templatemanage',
'nopermissions', '');
} else if (isset($record->contextid) && $record->contextid != $template->get('contextid')) {
// We can never change the context of a template.
throw new coding_exception('Changing the context of an existing tempalte is forbidden.');
}
$updateplans = false;
$before = $template->to_record();
$template->from_record($record);
$after = $template->to_record();
// Should we update the related plans?
if ($before->duedate != $after->duedate ||
$before->shortname != $after->shortname ||
$before->description != $after->description ||
$before->descriptionformat != $after->descriptionformat) {
$updateplans = true;
}
$transaction = $DB->start_delegated_transaction();
$success = $template->update();
if (!$success) {
$transaction->rollback(new moodle_exception('Error while updating the template.'));
return $success;
}
// Trigger a template updated event.
\core\event\competency_template_updated::create_from_template($template)->trigger();
if ($updateplans) {
plan::update_multiple_from_template($template);
}
$transaction->allow_commit();
return $success;
}
|
[
"public",
"static",
"function",
"update_template",
"(",
"$",
"record",
")",
"{",
"global",
"$",
"DB",
";",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"template",
"=",
"new",
"template",
"(",
"$",
"record",
"->",
"id",
")",
";",
"// First we do a permissions check.",
"if",
"(",
"!",
"$",
"template",
"->",
"can_manage",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"template",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:templatemanage'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"record",
"->",
"contextid",
")",
"&&",
"$",
"record",
"->",
"contextid",
"!=",
"$",
"template",
"->",
"get",
"(",
"'contextid'",
")",
")",
"{",
"// We can never change the context of a template.",
"throw",
"new",
"coding_exception",
"(",
"'Changing the context of an existing tempalte is forbidden.'",
")",
";",
"}",
"$",
"updateplans",
"=",
"false",
";",
"$",
"before",
"=",
"$",
"template",
"->",
"to_record",
"(",
")",
";",
"$",
"template",
"->",
"from_record",
"(",
"$",
"record",
")",
";",
"$",
"after",
"=",
"$",
"template",
"->",
"to_record",
"(",
")",
";",
"// Should we update the related plans?",
"if",
"(",
"$",
"before",
"->",
"duedate",
"!=",
"$",
"after",
"->",
"duedate",
"||",
"$",
"before",
"->",
"shortname",
"!=",
"$",
"after",
"->",
"shortname",
"||",
"$",
"before",
"->",
"description",
"!=",
"$",
"after",
"->",
"description",
"||",
"$",
"before",
"->",
"descriptionformat",
"!=",
"$",
"after",
"->",
"descriptionformat",
")",
"{",
"$",
"updateplans",
"=",
"true",
";",
"}",
"$",
"transaction",
"=",
"$",
"DB",
"->",
"start_delegated_transaction",
"(",
")",
";",
"$",
"success",
"=",
"$",
"template",
"->",
"update",
"(",
")",
";",
"if",
"(",
"!",
"$",
"success",
")",
"{",
"$",
"transaction",
"->",
"rollback",
"(",
"new",
"moodle_exception",
"(",
"'Error while updating the template.'",
")",
")",
";",
"return",
"$",
"success",
";",
"}",
"// Trigger a template updated event.",
"\\",
"core",
"\\",
"event",
"\\",
"competency_template_updated",
"::",
"create_from_template",
"(",
"$",
"template",
")",
"->",
"trigger",
"(",
")",
";",
"if",
"(",
"$",
"updateplans",
")",
"{",
"plan",
"::",
"update_multiple_from_template",
"(",
"$",
"template",
")",
";",
"}",
"$",
"transaction",
"->",
"allow_commit",
"(",
")",
";",
"return",
"$",
"success",
";",
"}"
] |
Update the details for a learning plan template.
Requires moodle/competency:templatemanage capability.
@param stdClass $record The new details for the template. Note - must contain an id that points to the template to update.
@return boolean
|
[
"Update",
"the",
"details",
"for",
"a",
"learning",
"plan",
"template",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L1876-L1924
|
217,248
|
moodle/moodle
|
competency/classes/api.php
|
api.read_template
|
public static function read_template($id) {
static::require_enabled();
$template = new template($id);
$context = $template->get_context();
// First we do a permissions check.
if (!$template->can_read()) {
throw new required_capability_exception($template->get_context(), 'moodle/competency:templateview',
'nopermissions', '');
}
// OK - all set.
return $template;
}
|
php
|
public static function read_template($id) {
static::require_enabled();
$template = new template($id);
$context = $template->get_context();
// First we do a permissions check.
if (!$template->can_read()) {
throw new required_capability_exception($template->get_context(), 'moodle/competency:templateview',
'nopermissions', '');
}
// OK - all set.
return $template;
}
|
[
"public",
"static",
"function",
"read_template",
"(",
"$",
"id",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"template",
"=",
"new",
"template",
"(",
"$",
"id",
")",
";",
"$",
"context",
"=",
"$",
"template",
"->",
"get_context",
"(",
")",
";",
"// First we do a permissions check.",
"if",
"(",
"!",
"$",
"template",
"->",
"can_read",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"template",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:templateview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// OK - all set.",
"return",
"$",
"template",
";",
"}"
] |
Read a the details for a single learning plan template and return a record.
Requires moodle/competency:templateview capability at the system context.
@param int $id The id of the template to read.
@return template
|
[
"Read",
"a",
"the",
"details",
"for",
"a",
"single",
"learning",
"plan",
"template",
"and",
"return",
"a",
"record",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L1934-L1947
|
217,249
|
moodle/moodle
|
competency/classes/api.php
|
api.count_templates
|
public static function count_templates($context, $includes) {
global $DB;
static::require_enabled();
// First we do a permissions check.
$contexts = self::get_related_contexts($context, $includes,
array('moodle/competency:templateview', 'moodle/competency:templatemanage'));
if (empty($contexts)) {
throw new required_capability_exception($context, 'moodle/competency:templateview', 'nopermissions', '');
}
// OK - all set.
$template = new template();
list($insql, $inparams) = $DB->get_in_or_equal(array_keys($contexts), SQL_PARAMS_NAMED);
return $template->count_records_select("contextid $insql", $inparams);
}
|
php
|
public static function count_templates($context, $includes) {
global $DB;
static::require_enabled();
// First we do a permissions check.
$contexts = self::get_related_contexts($context, $includes,
array('moodle/competency:templateview', 'moodle/competency:templatemanage'));
if (empty($contexts)) {
throw new required_capability_exception($context, 'moodle/competency:templateview', 'nopermissions', '');
}
// OK - all set.
$template = new template();
list($insql, $inparams) = $DB->get_in_or_equal(array_keys($contexts), SQL_PARAMS_NAMED);
return $template->count_records_select("contextid $insql", $inparams);
}
|
[
"public",
"static",
"function",
"count_templates",
"(",
"$",
"context",
",",
"$",
"includes",
")",
"{",
"global",
"$",
"DB",
";",
"static",
"::",
"require_enabled",
"(",
")",
";",
"// First we do a permissions check.",
"$",
"contexts",
"=",
"self",
"::",
"get_related_contexts",
"(",
"$",
"context",
",",
"$",
"includes",
",",
"array",
"(",
"'moodle/competency:templateview'",
",",
"'moodle/competency:templatemanage'",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"contexts",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:templateview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// OK - all set.",
"$",
"template",
"=",
"new",
"template",
"(",
")",
";",
"list",
"(",
"$",
"insql",
",",
"$",
"inparams",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"array_keys",
"(",
"$",
"contexts",
")",
",",
"SQL_PARAMS_NAMED",
")",
";",
"return",
"$",
"template",
"->",
"count_records_select",
"(",
"\"contextid $insql\"",
",",
"$",
"inparams",
")",
";",
"}"
] |
Perform a search based on the provided filters and return how many results there are.
Requires moodle/competency:templateview capability at the system context.
@param context $context The parent context of the frameworks.
@param string $includes Defines what other contexts to fetch frameworks from.
Accepted values are:
- children: All descendants
- parents: All parents, grand parents, etc...
- self: Context passed only.
@return int
|
[
"Perform",
"a",
"search",
"based",
"on",
"the",
"provided",
"filters",
"and",
"return",
"how",
"many",
"results",
"there",
"are",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L2011-L2027
|
217,250
|
moodle/moodle
|
competency/classes/api.php
|
api.count_templates_using_competency
|
public static function count_templates_using_competency($competencyid) {
static::require_enabled();
// First we do a permissions check.
$context = context_system::instance();
$onlyvisible = 1;
$capabilities = array('moodle/competency:templateview', 'moodle/competency:templatemanage');
if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'moodle/competency:templateview', 'nopermissions', '');
}
if (has_capability('moodle/competency:templatemanage', $context)) {
$onlyvisible = 0;
}
// OK - all set.
return template_competency::count_templates($competencyid, $onlyvisible);
}
|
php
|
public static function count_templates_using_competency($competencyid) {
static::require_enabled();
// First we do a permissions check.
$context = context_system::instance();
$onlyvisible = 1;
$capabilities = array('moodle/competency:templateview', 'moodle/competency:templatemanage');
if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'moodle/competency:templateview', 'nopermissions', '');
}
if (has_capability('moodle/competency:templatemanage', $context)) {
$onlyvisible = 0;
}
// OK - all set.
return template_competency::count_templates($competencyid, $onlyvisible);
}
|
[
"public",
"static",
"function",
"count_templates_using_competency",
"(",
"$",
"competencyid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"// First we do a permissions check.",
"$",
"context",
"=",
"context_system",
"::",
"instance",
"(",
")",
";",
"$",
"onlyvisible",
"=",
"1",
";",
"$",
"capabilities",
"=",
"array",
"(",
"'moodle/competency:templateview'",
",",
"'moodle/competency:templatemanage'",
")",
";",
"if",
"(",
"!",
"has_any_capability",
"(",
"$",
"capabilities",
",",
"$",
"context",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:templateview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"if",
"(",
"has_capability",
"(",
"'moodle/competency:templatemanage'",
",",
"$",
"context",
")",
")",
"{",
"$",
"onlyvisible",
"=",
"0",
";",
"}",
"// OK - all set.",
"return",
"template_competency",
"::",
"count_templates",
"(",
"$",
"competencyid",
",",
"$",
"onlyvisible",
")",
";",
"}"
] |
Count all the templates using a competency.
@param int $competencyid The id of the competency to check.
@return int
|
[
"Count",
"all",
"the",
"templates",
"using",
"a",
"competency",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L2035-L2052
|
217,251
|
moodle/moodle
|
competency/classes/api.php
|
api.list_templates_using_competency
|
public static function list_templates_using_competency($competencyid) {
static::require_enabled();
// First we do a permissions check.
$context = context_system::instance();
$onlyvisible = 1;
$capabilities = array('moodle/competency:templateview', 'moodle/competency:templatemanage');
if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'moodle/competency:templateview', 'nopermissions', '');
}
if (has_capability('moodle/competency:templatemanage', $context)) {
$onlyvisible = 0;
}
// OK - all set.
return template_competency::list_templates($competencyid, $onlyvisible);
}
|
php
|
public static function list_templates_using_competency($competencyid) {
static::require_enabled();
// First we do a permissions check.
$context = context_system::instance();
$onlyvisible = 1;
$capabilities = array('moodle/competency:templateview', 'moodle/competency:templatemanage');
if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'moodle/competency:templateview', 'nopermissions', '');
}
if (has_capability('moodle/competency:templatemanage', $context)) {
$onlyvisible = 0;
}
// OK - all set.
return template_competency::list_templates($competencyid, $onlyvisible);
}
|
[
"public",
"static",
"function",
"list_templates_using_competency",
"(",
"$",
"competencyid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"// First we do a permissions check.",
"$",
"context",
"=",
"context_system",
"::",
"instance",
"(",
")",
";",
"$",
"onlyvisible",
"=",
"1",
";",
"$",
"capabilities",
"=",
"array",
"(",
"'moodle/competency:templateview'",
",",
"'moodle/competency:templatemanage'",
")",
";",
"if",
"(",
"!",
"has_any_capability",
"(",
"$",
"capabilities",
",",
"$",
"context",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:templateview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"if",
"(",
"has_capability",
"(",
"'moodle/competency:templatemanage'",
",",
"$",
"context",
")",
")",
"{",
"$",
"onlyvisible",
"=",
"0",
";",
"}",
"// OK - all set.",
"return",
"template_competency",
"::",
"list_templates",
"(",
"$",
"competencyid",
",",
"$",
"onlyvisible",
")",
";",
"}"
] |
List all the learning plan templatesd using a competency.
@param int $competencyid The id of the competency to check.
@return array[stdClass] Array of stdClass containing id and shortname.
|
[
"List",
"all",
"the",
"learning",
"plan",
"templatesd",
"using",
"a",
"competency",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L2060-L2078
|
217,252
|
moodle/moodle
|
competency/classes/api.php
|
api.count_competencies_in_template
|
public static function count_competencies_in_template($templateorid) {
static::require_enabled();
// First we do a permissions check.
$template = $templateorid;
if (!is_object($template)) {
$template = new template($template);
}
if (!$template->can_read()) {
throw new required_capability_exception($template->get_context(), 'moodle/competency:templateview',
'nopermissions', '');
}
// OK - all set.
return template_competency::count_competencies($template->get('id'));
}
|
php
|
public static function count_competencies_in_template($templateorid) {
static::require_enabled();
// First we do a permissions check.
$template = $templateorid;
if (!is_object($template)) {
$template = new template($template);
}
if (!$template->can_read()) {
throw new required_capability_exception($template->get_context(), 'moodle/competency:templateview',
'nopermissions', '');
}
// OK - all set.
return template_competency::count_competencies($template->get('id'));
}
|
[
"public",
"static",
"function",
"count_competencies_in_template",
"(",
"$",
"templateorid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"// First we do a permissions check.",
"$",
"template",
"=",
"$",
"templateorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"template",
")",
")",
"{",
"$",
"template",
"=",
"new",
"template",
"(",
"$",
"template",
")",
";",
"}",
"if",
"(",
"!",
"$",
"template",
"->",
"can_read",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"template",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:templateview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// OK - all set.",
"return",
"template_competency",
"::",
"count_competencies",
"(",
"$",
"template",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"}"
] |
Count all the competencies in a learning plan template.
@param template|int $templateorid The template or its ID.
@return int
|
[
"Count",
"all",
"the",
"competencies",
"in",
"a",
"learning",
"plan",
"template",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L2086-L2101
|
217,253
|
moodle/moodle
|
competency/classes/api.php
|
api.count_competencies_in_template_with_no_courses
|
public static function count_competencies_in_template_with_no_courses($templateorid) {
// First we do a permissions check.
$template = $templateorid;
if (!is_object($template)) {
$template = new template($template);
}
if (!$template->can_read()) {
throw new required_capability_exception($template->get_context(), 'moodle/competency:templateview',
'nopermissions', '');
}
// OK - all set.
return template_competency::count_competencies_with_no_courses($template->get('id'));
}
|
php
|
public static function count_competencies_in_template_with_no_courses($templateorid) {
// First we do a permissions check.
$template = $templateorid;
if (!is_object($template)) {
$template = new template($template);
}
if (!$template->can_read()) {
throw new required_capability_exception($template->get_context(), 'moodle/competency:templateview',
'nopermissions', '');
}
// OK - all set.
return template_competency::count_competencies_with_no_courses($template->get('id'));
}
|
[
"public",
"static",
"function",
"count_competencies_in_template_with_no_courses",
"(",
"$",
"templateorid",
")",
"{",
"// First we do a permissions check.",
"$",
"template",
"=",
"$",
"templateorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"template",
")",
")",
"{",
"$",
"template",
"=",
"new",
"template",
"(",
"$",
"template",
")",
";",
"}",
"if",
"(",
"!",
"$",
"template",
"->",
"can_read",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"template",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:templateview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// OK - all set.",
"return",
"template_competency",
"::",
"count_competencies_with_no_courses",
"(",
"$",
"template",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"}"
] |
Count all the competencies in a learning plan template with no linked courses.
@param template|int $templateorid The template or its ID.
@return int
|
[
"Count",
"all",
"the",
"competencies",
"in",
"a",
"learning",
"plan",
"template",
"with",
"no",
"linked",
"courses",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L2109-L2123
|
217,254
|
moodle/moodle
|
competency/classes/api.php
|
api.list_competencies_in_template
|
public static function list_competencies_in_template($templateorid) {
static::require_enabled();
// First we do a permissions check.
$template = $templateorid;
if (!is_object($template)) {
$template = new template($template);
}
if (!$template->can_read()) {
throw new required_capability_exception($template->get_context(), 'moodle/competency:templateview',
'nopermissions', '');
}
// OK - all set.
return template_competency::list_competencies($template->get('id'));
}
|
php
|
public static function list_competencies_in_template($templateorid) {
static::require_enabled();
// First we do a permissions check.
$template = $templateorid;
if (!is_object($template)) {
$template = new template($template);
}
if (!$template->can_read()) {
throw new required_capability_exception($template->get_context(), 'moodle/competency:templateview',
'nopermissions', '');
}
// OK - all set.
return template_competency::list_competencies($template->get('id'));
}
|
[
"public",
"static",
"function",
"list_competencies_in_template",
"(",
"$",
"templateorid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"// First we do a permissions check.",
"$",
"template",
"=",
"$",
"templateorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"template",
")",
")",
"{",
"$",
"template",
"=",
"new",
"template",
"(",
"$",
"template",
")",
";",
"}",
"if",
"(",
"!",
"$",
"template",
"->",
"can_read",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"template",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:templateview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// OK - all set.",
"return",
"template_competency",
"::",
"list_competencies",
"(",
"$",
"template",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"}"
] |
List all the competencies in a template.
@param template|int $templateorid The template or its ID.
@return array of competencies
|
[
"List",
"all",
"the",
"competencies",
"in",
"a",
"template",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L2131-L2146
|
217,255
|
moodle/moodle
|
competency/classes/api.php
|
api.add_competency_to_template
|
public static function add_competency_to_template($templateid, $competencyid) {
static::require_enabled();
// First we do a permissions check.
$template = new template($templateid);
if (!$template->can_manage()) {
throw new required_capability_exception($template->get_context(), 'moodle/competency:templatemanage',
'nopermissions', '');
}
$record = new stdClass();
$record->templateid = $templateid;
$record->competencyid = $competencyid;
$competency = new competency($competencyid);
// Can not add a competency that belong to a hidden framework.
if ($competency->get_framework()->get('visible') == false) {
throw new coding_exception('A competency belonging to hidden framework can not be added');
}
$exists = template_competency::get_records(array('templateid' => $templateid, 'competencyid' => $competencyid));
if (!$exists) {
$templatecompetency = new template_competency(0, $record);
$templatecompetency->create();
return true;
}
return false;
}
|
php
|
public static function add_competency_to_template($templateid, $competencyid) {
static::require_enabled();
// First we do a permissions check.
$template = new template($templateid);
if (!$template->can_manage()) {
throw new required_capability_exception($template->get_context(), 'moodle/competency:templatemanage',
'nopermissions', '');
}
$record = new stdClass();
$record->templateid = $templateid;
$record->competencyid = $competencyid;
$competency = new competency($competencyid);
// Can not add a competency that belong to a hidden framework.
if ($competency->get_framework()->get('visible') == false) {
throw new coding_exception('A competency belonging to hidden framework can not be added');
}
$exists = template_competency::get_records(array('templateid' => $templateid, 'competencyid' => $competencyid));
if (!$exists) {
$templatecompetency = new template_competency(0, $record);
$templatecompetency->create();
return true;
}
return false;
}
|
[
"public",
"static",
"function",
"add_competency_to_template",
"(",
"$",
"templateid",
",",
"$",
"competencyid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"// First we do a permissions check.",
"$",
"template",
"=",
"new",
"template",
"(",
"$",
"templateid",
")",
";",
"if",
"(",
"!",
"$",
"template",
"->",
"can_manage",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"template",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:templatemanage'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"$",
"record",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"record",
"->",
"templateid",
"=",
"$",
"templateid",
";",
"$",
"record",
"->",
"competencyid",
"=",
"$",
"competencyid",
";",
"$",
"competency",
"=",
"new",
"competency",
"(",
"$",
"competencyid",
")",
";",
"// Can not add a competency that belong to a hidden framework.",
"if",
"(",
"$",
"competency",
"->",
"get_framework",
"(",
")",
"->",
"get",
"(",
"'visible'",
")",
"==",
"false",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'A competency belonging to hidden framework can not be added'",
")",
";",
"}",
"$",
"exists",
"=",
"template_competency",
"::",
"get_records",
"(",
"array",
"(",
"'templateid'",
"=>",
"$",
"templateid",
",",
"'competencyid'",
"=>",
"$",
"competencyid",
")",
")",
";",
"if",
"(",
"!",
"$",
"exists",
")",
"{",
"$",
"templatecompetency",
"=",
"new",
"template_competency",
"(",
"0",
",",
"$",
"record",
")",
";",
"$",
"templatecompetency",
"->",
"create",
"(",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Add a competency to this template.
@param int $templateid The id of the template
@param int $competencyid The id of the competency
@return bool
|
[
"Add",
"a",
"competency",
"to",
"this",
"template",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L2155-L2182
|
217,256
|
moodle/moodle
|
competency/classes/api.php
|
api.remove_competency_from_template
|
public static function remove_competency_from_template($templateid, $competencyid) {
static::require_enabled();
// First we do a permissions check.
$template = new template($templateid);
if (!$template->can_manage()) {
throw new required_capability_exception($template->get_context(), 'moodle/competency:templatemanage',
'nopermissions', '');
}
$record = new stdClass();
$record->templateid = $templateid;
$record->competencyid = $competencyid;
$competency = new competency($competencyid);
$exists = template_competency::get_records(array('templateid' => $templateid, 'competencyid' => $competencyid));
if ($exists) {
$link = array_pop($exists);
return $link->delete();
}
return false;
}
|
php
|
public static function remove_competency_from_template($templateid, $competencyid) {
static::require_enabled();
// First we do a permissions check.
$template = new template($templateid);
if (!$template->can_manage()) {
throw new required_capability_exception($template->get_context(), 'moodle/competency:templatemanage',
'nopermissions', '');
}
$record = new stdClass();
$record->templateid = $templateid;
$record->competencyid = $competencyid;
$competency = new competency($competencyid);
$exists = template_competency::get_records(array('templateid' => $templateid, 'competencyid' => $competencyid));
if ($exists) {
$link = array_pop($exists);
return $link->delete();
}
return false;
}
|
[
"public",
"static",
"function",
"remove_competency_from_template",
"(",
"$",
"templateid",
",",
"$",
"competencyid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"// First we do a permissions check.",
"$",
"template",
"=",
"new",
"template",
"(",
"$",
"templateid",
")",
";",
"if",
"(",
"!",
"$",
"template",
"->",
"can_manage",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"template",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:templatemanage'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"$",
"record",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"record",
"->",
"templateid",
"=",
"$",
"templateid",
";",
"$",
"record",
"->",
"competencyid",
"=",
"$",
"competencyid",
";",
"$",
"competency",
"=",
"new",
"competency",
"(",
"$",
"competencyid",
")",
";",
"$",
"exists",
"=",
"template_competency",
"::",
"get_records",
"(",
"array",
"(",
"'templateid'",
"=>",
"$",
"templateid",
",",
"'competencyid'",
"=>",
"$",
"competencyid",
")",
")",
";",
"if",
"(",
"$",
"exists",
")",
"{",
"$",
"link",
"=",
"array_pop",
"(",
"$",
"exists",
")",
";",
"return",
"$",
"link",
"->",
"delete",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Remove a competency from this template.
@param int $templateid The id of the template
@param int $competencyid The id of the competency
@return bool
|
[
"Remove",
"a",
"competency",
"from",
"this",
"template",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L2191-L2212
|
217,257
|
moodle/moodle
|
competency/classes/api.php
|
api.reorder_template_competency
|
public static function reorder_template_competency($templateid, $competencyidfrom, $competencyidto) {
static::require_enabled();
$template = new template($templateid);
// First we do a permissions check.
if (!$template->can_manage()) {
throw new required_capability_exception($template->get_context(), 'moodle/competency:templatemanage',
'nopermissions', '');
}
$down = true;
$matches = template_competency::get_records(array('templateid' => $templateid, 'competencyid' => $competencyidfrom));
if (count($matches) == 0) {
throw new coding_exception('The link does not exist');
}
$competencyfrom = array_pop($matches);
$matches = template_competency::get_records(array('templateid' => $templateid, 'competencyid' => $competencyidto));
if (count($matches) == 0) {
throw new coding_exception('The link does not exist');
}
$competencyto = array_pop($matches);
$all = template_competency::get_records(array('templateid' => $templateid), 'sortorder', 'ASC', 0, 0);
if ($competencyfrom->get('sortorder') > $competencyto->get('sortorder')) {
// We are moving up, so put it before the "to" item.
$down = false;
}
foreach ($all as $id => $templatecompetency) {
$sort = $templatecompetency->get('sortorder');
if ($down && $sort > $competencyfrom->get('sortorder') && $sort <= $competencyto->get('sortorder')) {
$templatecompetency->set('sortorder', $templatecompetency->get('sortorder') - 1);
$templatecompetency->update();
} else if (!$down && $sort >= $competencyto->get('sortorder') && $sort < $competencyfrom->get('sortorder')) {
$templatecompetency->set('sortorder', $templatecompetency->get('sortorder') + 1);
$templatecompetency->update();
}
}
$competencyfrom->set('sortorder', $competencyto->get('sortorder'));
return $competencyfrom->update();
}
|
php
|
public static function reorder_template_competency($templateid, $competencyidfrom, $competencyidto) {
static::require_enabled();
$template = new template($templateid);
// First we do a permissions check.
if (!$template->can_manage()) {
throw new required_capability_exception($template->get_context(), 'moodle/competency:templatemanage',
'nopermissions', '');
}
$down = true;
$matches = template_competency::get_records(array('templateid' => $templateid, 'competencyid' => $competencyidfrom));
if (count($matches) == 0) {
throw new coding_exception('The link does not exist');
}
$competencyfrom = array_pop($matches);
$matches = template_competency::get_records(array('templateid' => $templateid, 'competencyid' => $competencyidto));
if (count($matches) == 0) {
throw new coding_exception('The link does not exist');
}
$competencyto = array_pop($matches);
$all = template_competency::get_records(array('templateid' => $templateid), 'sortorder', 'ASC', 0, 0);
if ($competencyfrom->get('sortorder') > $competencyto->get('sortorder')) {
// We are moving up, so put it before the "to" item.
$down = false;
}
foreach ($all as $id => $templatecompetency) {
$sort = $templatecompetency->get('sortorder');
if ($down && $sort > $competencyfrom->get('sortorder') && $sort <= $competencyto->get('sortorder')) {
$templatecompetency->set('sortorder', $templatecompetency->get('sortorder') - 1);
$templatecompetency->update();
} else if (!$down && $sort >= $competencyto->get('sortorder') && $sort < $competencyfrom->get('sortorder')) {
$templatecompetency->set('sortorder', $templatecompetency->get('sortorder') + 1);
$templatecompetency->update();
}
}
$competencyfrom->set('sortorder', $competencyto->get('sortorder'));
return $competencyfrom->update();
}
|
[
"public",
"static",
"function",
"reorder_template_competency",
"(",
"$",
"templateid",
",",
"$",
"competencyidfrom",
",",
"$",
"competencyidto",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"template",
"=",
"new",
"template",
"(",
"$",
"templateid",
")",
";",
"// First we do a permissions check.",
"if",
"(",
"!",
"$",
"template",
"->",
"can_manage",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"template",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:templatemanage'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"$",
"down",
"=",
"true",
";",
"$",
"matches",
"=",
"template_competency",
"::",
"get_records",
"(",
"array",
"(",
"'templateid'",
"=>",
"$",
"templateid",
",",
"'competencyid'",
"=>",
"$",
"competencyidfrom",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"matches",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The link does not exist'",
")",
";",
"}",
"$",
"competencyfrom",
"=",
"array_pop",
"(",
"$",
"matches",
")",
";",
"$",
"matches",
"=",
"template_competency",
"::",
"get_records",
"(",
"array",
"(",
"'templateid'",
"=>",
"$",
"templateid",
",",
"'competencyid'",
"=>",
"$",
"competencyidto",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"matches",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The link does not exist'",
")",
";",
"}",
"$",
"competencyto",
"=",
"array_pop",
"(",
"$",
"matches",
")",
";",
"$",
"all",
"=",
"template_competency",
"::",
"get_records",
"(",
"array",
"(",
"'templateid'",
"=>",
"$",
"templateid",
")",
",",
"'sortorder'",
",",
"'ASC'",
",",
"0",
",",
"0",
")",
";",
"if",
"(",
"$",
"competencyfrom",
"->",
"get",
"(",
"'sortorder'",
")",
">",
"$",
"competencyto",
"->",
"get",
"(",
"'sortorder'",
")",
")",
"{",
"// We are moving up, so put it before the \"to\" item.",
"$",
"down",
"=",
"false",
";",
"}",
"foreach",
"(",
"$",
"all",
"as",
"$",
"id",
"=>",
"$",
"templatecompetency",
")",
"{",
"$",
"sort",
"=",
"$",
"templatecompetency",
"->",
"get",
"(",
"'sortorder'",
")",
";",
"if",
"(",
"$",
"down",
"&&",
"$",
"sort",
">",
"$",
"competencyfrom",
"->",
"get",
"(",
"'sortorder'",
")",
"&&",
"$",
"sort",
"<=",
"$",
"competencyto",
"->",
"get",
"(",
"'sortorder'",
")",
")",
"{",
"$",
"templatecompetency",
"->",
"set",
"(",
"'sortorder'",
",",
"$",
"templatecompetency",
"->",
"get",
"(",
"'sortorder'",
")",
"-",
"1",
")",
";",
"$",
"templatecompetency",
"->",
"update",
"(",
")",
";",
"}",
"else",
"if",
"(",
"!",
"$",
"down",
"&&",
"$",
"sort",
">=",
"$",
"competencyto",
"->",
"get",
"(",
"'sortorder'",
")",
"&&",
"$",
"sort",
"<",
"$",
"competencyfrom",
"->",
"get",
"(",
"'sortorder'",
")",
")",
"{",
"$",
"templatecompetency",
"->",
"set",
"(",
"'sortorder'",
",",
"$",
"templatecompetency",
"->",
"get",
"(",
"'sortorder'",
")",
"+",
"1",
")",
";",
"$",
"templatecompetency",
"->",
"update",
"(",
")",
";",
"}",
"}",
"$",
"competencyfrom",
"->",
"set",
"(",
"'sortorder'",
",",
"$",
"competencyto",
"->",
"get",
"(",
"'sortorder'",
")",
")",
";",
"return",
"$",
"competencyfrom",
"->",
"update",
"(",
")",
";",
"}"
] |
Move the template competency up or down in the display list.
Requires moodle/competency:templatemanage capability at the system context.
@param int $templateid The template id
@param int $competencyidfrom The id of the competency we are moving.
@param int $competencyidto The id of the competency we are moving to.
@return boolean
|
[
"Move",
"the",
"template",
"competency",
"up",
"or",
"down",
"in",
"the",
"display",
"list",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L2224-L2267
|
217,258
|
moodle/moodle
|
competency/classes/api.php
|
api.create_template_cohort
|
public static function create_template_cohort($templateorid, $cohortorid) {
global $DB;
static::require_enabled();
$template = $templateorid;
if (!is_object($template)) {
$template = new template($template);
}
require_capability('moodle/competency:templatemanage', $template->get_context());
$cohort = $cohortorid;
if (!is_object($cohort)) {
$cohort = $DB->get_record('cohort', array('id' => $cohort), '*', MUST_EXIST);
}
// Replicate logic in cohort_can_view_cohort() because we can't use it directly as we don't have a course context.
$cohortcontext = context::instance_by_id($cohort->contextid);
if (!$cohort->visible && !has_capability('moodle/cohort:view', $cohortcontext)) {
throw new required_capability_exception($cohortcontext, 'moodle/cohort:view', 'nopermissions', '');
}
$tplcohort = template_cohort::get_relation($template->get('id'), $cohort->id);
if (!$tplcohort->get('id')) {
$tplcohort->create();
}
return $tplcohort;
}
|
php
|
public static function create_template_cohort($templateorid, $cohortorid) {
global $DB;
static::require_enabled();
$template = $templateorid;
if (!is_object($template)) {
$template = new template($template);
}
require_capability('moodle/competency:templatemanage', $template->get_context());
$cohort = $cohortorid;
if (!is_object($cohort)) {
$cohort = $DB->get_record('cohort', array('id' => $cohort), '*', MUST_EXIST);
}
// Replicate logic in cohort_can_view_cohort() because we can't use it directly as we don't have a course context.
$cohortcontext = context::instance_by_id($cohort->contextid);
if (!$cohort->visible && !has_capability('moodle/cohort:view', $cohortcontext)) {
throw new required_capability_exception($cohortcontext, 'moodle/cohort:view', 'nopermissions', '');
}
$tplcohort = template_cohort::get_relation($template->get('id'), $cohort->id);
if (!$tplcohort->get('id')) {
$tplcohort->create();
}
return $tplcohort;
}
|
[
"public",
"static",
"function",
"create_template_cohort",
"(",
"$",
"templateorid",
",",
"$",
"cohortorid",
")",
"{",
"global",
"$",
"DB",
";",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"template",
"=",
"$",
"templateorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"template",
")",
")",
"{",
"$",
"template",
"=",
"new",
"template",
"(",
"$",
"template",
")",
";",
"}",
"require_capability",
"(",
"'moodle/competency:templatemanage'",
",",
"$",
"template",
"->",
"get_context",
"(",
")",
")",
";",
"$",
"cohort",
"=",
"$",
"cohortorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"cohort",
")",
")",
"{",
"$",
"cohort",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'cohort'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"cohort",
")",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"}",
"// Replicate logic in cohort_can_view_cohort() because we can't use it directly as we don't have a course context.",
"$",
"cohortcontext",
"=",
"context",
"::",
"instance_by_id",
"(",
"$",
"cohort",
"->",
"contextid",
")",
";",
"if",
"(",
"!",
"$",
"cohort",
"->",
"visible",
"&&",
"!",
"has_capability",
"(",
"'moodle/cohort:view'",
",",
"$",
"cohortcontext",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"cohortcontext",
",",
"'moodle/cohort:view'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"$",
"tplcohort",
"=",
"template_cohort",
"::",
"get_relation",
"(",
"$",
"template",
"->",
"get",
"(",
"'id'",
")",
",",
"$",
"cohort",
"->",
"id",
")",
";",
"if",
"(",
"!",
"$",
"tplcohort",
"->",
"get",
"(",
"'id'",
")",
")",
"{",
"$",
"tplcohort",
"->",
"create",
"(",
")",
";",
"}",
"return",
"$",
"tplcohort",
";",
"}"
] |
Create a relation between a template and a cohort.
This silently ignores when the relation already existed.
@param template|int $templateorid The template or its ID.
@param stdClass|int $cohortorid The cohort ot its ID.
@return template_cohort
|
[
"Create",
"a",
"relation",
"between",
"a",
"template",
"and",
"a",
"cohort",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L2278-L2305
|
217,259
|
moodle/moodle
|
competency/classes/api.php
|
api.delete_template_cohort
|
public static function delete_template_cohort($templateorid, $cohortorid) {
global $DB;
static::require_enabled();
$template = $templateorid;
if (!is_object($template)) {
$template = new template($template);
}
require_capability('moodle/competency:templatemanage', $template->get_context());
$cohort = $cohortorid;
if (!is_object($cohort)) {
$cohort = $DB->get_record('cohort', array('id' => $cohort), '*', MUST_EXIST);
}
$tplcohort = template_cohort::get_relation($template->get('id'), $cohort->id);
if (!$tplcohort->get('id')) {
return true;
}
return $tplcohort->delete();
}
|
php
|
public static function delete_template_cohort($templateorid, $cohortorid) {
global $DB;
static::require_enabled();
$template = $templateorid;
if (!is_object($template)) {
$template = new template($template);
}
require_capability('moodle/competency:templatemanage', $template->get_context());
$cohort = $cohortorid;
if (!is_object($cohort)) {
$cohort = $DB->get_record('cohort', array('id' => $cohort), '*', MUST_EXIST);
}
$tplcohort = template_cohort::get_relation($template->get('id'), $cohort->id);
if (!$tplcohort->get('id')) {
return true;
}
return $tplcohort->delete();
}
|
[
"public",
"static",
"function",
"delete_template_cohort",
"(",
"$",
"templateorid",
",",
"$",
"cohortorid",
")",
"{",
"global",
"$",
"DB",
";",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"template",
"=",
"$",
"templateorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"template",
")",
")",
"{",
"$",
"template",
"=",
"new",
"template",
"(",
"$",
"template",
")",
";",
"}",
"require_capability",
"(",
"'moodle/competency:templatemanage'",
",",
"$",
"template",
"->",
"get_context",
"(",
")",
")",
";",
"$",
"cohort",
"=",
"$",
"cohortorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"cohort",
")",
")",
"{",
"$",
"cohort",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'cohort'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"cohort",
")",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"}",
"$",
"tplcohort",
"=",
"template_cohort",
"::",
"get_relation",
"(",
"$",
"template",
"->",
"get",
"(",
"'id'",
")",
",",
"$",
"cohort",
"->",
"id",
")",
";",
"if",
"(",
"!",
"$",
"tplcohort",
"->",
"get",
"(",
"'id'",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"$",
"tplcohort",
"->",
"delete",
"(",
")",
";",
"}"
] |
Remove a relation between a template and a cohort.
@param template|int $templateorid The template or its ID.
@param stdClass|int $cohortorid The cohort ot its ID.
@return boolean True on success or when the relation did not exist.
|
[
"Remove",
"a",
"relation",
"between",
"a",
"template",
"and",
"a",
"cohort",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L2314-L2335
|
217,260
|
moodle/moodle
|
competency/classes/api.php
|
api.list_user_plans
|
public static function list_user_plans($userid) {
global $DB, $USER;
static::require_enabled();
$select = 'userid = :userid';
$params = array('userid' => $userid);
$context = context_user::instance($userid);
// Check that we can read something here.
if (!plan::can_read_user($userid) && !plan::can_read_user_draft($userid)) {
throw new required_capability_exception($context, 'moodle/competency:planview', 'nopermissions', '');
}
// The user cannot view the drafts.
if (!plan::can_read_user_draft($userid)) {
list($insql, $inparams) = $DB->get_in_or_equal(plan::get_draft_statuses(), SQL_PARAMS_NAMED, 'param', false);
$select .= " AND status $insql";
$params += $inparams;
}
// The user cannot view the non-drafts.
if (!plan::can_read_user($userid)) {
list($insql, $inparams) = $DB->get_in_or_equal(array(plan::STATUS_ACTIVE, plan::STATUS_COMPLETE),
SQL_PARAMS_NAMED, 'param', false);
$select .= " AND status $insql";
$params += $inparams;
}
return plan::get_records_select($select, $params, 'name ASC');
}
|
php
|
public static function list_user_plans($userid) {
global $DB, $USER;
static::require_enabled();
$select = 'userid = :userid';
$params = array('userid' => $userid);
$context = context_user::instance($userid);
// Check that we can read something here.
if (!plan::can_read_user($userid) && !plan::can_read_user_draft($userid)) {
throw new required_capability_exception($context, 'moodle/competency:planview', 'nopermissions', '');
}
// The user cannot view the drafts.
if (!plan::can_read_user_draft($userid)) {
list($insql, $inparams) = $DB->get_in_or_equal(plan::get_draft_statuses(), SQL_PARAMS_NAMED, 'param', false);
$select .= " AND status $insql";
$params += $inparams;
}
// The user cannot view the non-drafts.
if (!plan::can_read_user($userid)) {
list($insql, $inparams) = $DB->get_in_or_equal(array(plan::STATUS_ACTIVE, plan::STATUS_COMPLETE),
SQL_PARAMS_NAMED, 'param', false);
$select .= " AND status $insql";
$params += $inparams;
}
return plan::get_records_select($select, $params, 'name ASC');
}
|
[
"public",
"static",
"function",
"list_user_plans",
"(",
"$",
"userid",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"USER",
";",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"select",
"=",
"'userid = :userid'",
";",
"$",
"params",
"=",
"array",
"(",
"'userid'",
"=>",
"$",
"userid",
")",
";",
"$",
"context",
"=",
"context_user",
"::",
"instance",
"(",
"$",
"userid",
")",
";",
"// Check that we can read something here.",
"if",
"(",
"!",
"plan",
"::",
"can_read_user",
"(",
"$",
"userid",
")",
"&&",
"!",
"plan",
"::",
"can_read_user_draft",
"(",
"$",
"userid",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:planview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// The user cannot view the drafts.",
"if",
"(",
"!",
"plan",
"::",
"can_read_user_draft",
"(",
"$",
"userid",
")",
")",
"{",
"list",
"(",
"$",
"insql",
",",
"$",
"inparams",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"plan",
"::",
"get_draft_statuses",
"(",
")",
",",
"SQL_PARAMS_NAMED",
",",
"'param'",
",",
"false",
")",
";",
"$",
"select",
".=",
"\" AND status $insql\"",
";",
"$",
"params",
"+=",
"$",
"inparams",
";",
"}",
"// The user cannot view the non-drafts.",
"if",
"(",
"!",
"plan",
"::",
"can_read_user",
"(",
"$",
"userid",
")",
")",
"{",
"list",
"(",
"$",
"insql",
",",
"$",
"inparams",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"array",
"(",
"plan",
"::",
"STATUS_ACTIVE",
",",
"plan",
"::",
"STATUS_COMPLETE",
")",
",",
"SQL_PARAMS_NAMED",
",",
"'param'",
",",
"false",
")",
";",
"$",
"select",
".=",
"\" AND status $insql\"",
";",
"$",
"params",
"+=",
"$",
"inparams",
";",
"}",
"return",
"plan",
"::",
"get_records_select",
"(",
"$",
"select",
",",
"$",
"params",
",",
"'name ASC'",
")",
";",
"}"
] |
Lists user plans.
@param int $userid
@return \core_competency\plan[]
|
[
"Lists",
"user",
"plans",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L2343-L2370
|
217,261
|
moodle/moodle
|
competency/classes/api.php
|
api.list_plans_to_review
|
public static function list_plans_to_review($skip = 0, $limit = 100, $userid = null) {
global $DB, $USER;
static::require_enabled();
if ($userid === null) {
$userid = $USER->id;
}
$planfields = plan::get_sql_fields('p', 'plan_');
$tplfields = template::get_sql_fields('t', 'tpl_');
$usercols = array('id') + get_user_fieldnames();
$userfields = array();
foreach ($usercols as $field) {
$userfields[] = "u." . $field . " AS usr_" . $field;
}
$userfields = implode(',', $userfields);
$select = "SELECT $planfields, $tplfields, $userfields";
$countselect = "SELECT COUNT('x')";
$sql = " FROM {" . plan::TABLE . "} p
JOIN {user} u
ON u.id = p.userid
LEFT JOIN {" . template::TABLE . "} t
ON t.id = p.templateid
WHERE (p.status = :waitingforreview
OR (p.status = :inreview AND p.reviewerid = :reviewerid))
AND p.userid != :userid";
$params = array(
'waitingforreview' => plan::STATUS_WAITING_FOR_REVIEW,
'inreview' => plan::STATUS_IN_REVIEW,
'reviewerid' => $userid,
'userid' => $userid
);
// Primary check to avoid the hard work of getting the users in which the user has permission.
$count = $DB->count_records_sql($countselect . $sql, $params);
if ($count < 1) {
return array('count' => 0, 'plans' => array());
}
// TODO MDL-52243 Use core function.
list($insql, $inparams) = self::filter_users_with_capability_on_user_context_sql('moodle/competency:planreview',
$userid, SQL_PARAMS_NAMED);
$sql .= " AND p.userid $insql";
$params += $inparams;
// Order by ID just to have some ordering in place.
$ordersql = " ORDER BY p.id ASC";
$plans = array();
$records = $DB->get_recordset_sql($select . $sql . $ordersql, $params, $skip, $limit);
foreach ($records as $record) {
$plan = new plan(0, plan::extract_record($record, 'plan_'));
$template = null;
if ($plan->is_based_on_template()) {
$template = new template(0, template::extract_record($record, 'tpl_'));
}
$plans[] = (object) array(
'plan' => $plan,
'template' => $template,
'owner' => persistent::extract_record($record, 'usr_'),
);
}
$records->close();
return array(
'count' => $DB->count_records_sql($countselect . $sql, $params),
'plans' => $plans
);
}
|
php
|
public static function list_plans_to_review($skip = 0, $limit = 100, $userid = null) {
global $DB, $USER;
static::require_enabled();
if ($userid === null) {
$userid = $USER->id;
}
$planfields = plan::get_sql_fields('p', 'plan_');
$tplfields = template::get_sql_fields('t', 'tpl_');
$usercols = array('id') + get_user_fieldnames();
$userfields = array();
foreach ($usercols as $field) {
$userfields[] = "u." . $field . " AS usr_" . $field;
}
$userfields = implode(',', $userfields);
$select = "SELECT $planfields, $tplfields, $userfields";
$countselect = "SELECT COUNT('x')";
$sql = " FROM {" . plan::TABLE . "} p
JOIN {user} u
ON u.id = p.userid
LEFT JOIN {" . template::TABLE . "} t
ON t.id = p.templateid
WHERE (p.status = :waitingforreview
OR (p.status = :inreview AND p.reviewerid = :reviewerid))
AND p.userid != :userid";
$params = array(
'waitingforreview' => plan::STATUS_WAITING_FOR_REVIEW,
'inreview' => plan::STATUS_IN_REVIEW,
'reviewerid' => $userid,
'userid' => $userid
);
// Primary check to avoid the hard work of getting the users in which the user has permission.
$count = $DB->count_records_sql($countselect . $sql, $params);
if ($count < 1) {
return array('count' => 0, 'plans' => array());
}
// TODO MDL-52243 Use core function.
list($insql, $inparams) = self::filter_users_with_capability_on_user_context_sql('moodle/competency:planreview',
$userid, SQL_PARAMS_NAMED);
$sql .= " AND p.userid $insql";
$params += $inparams;
// Order by ID just to have some ordering in place.
$ordersql = " ORDER BY p.id ASC";
$plans = array();
$records = $DB->get_recordset_sql($select . $sql . $ordersql, $params, $skip, $limit);
foreach ($records as $record) {
$plan = new plan(0, plan::extract_record($record, 'plan_'));
$template = null;
if ($plan->is_based_on_template()) {
$template = new template(0, template::extract_record($record, 'tpl_'));
}
$plans[] = (object) array(
'plan' => $plan,
'template' => $template,
'owner' => persistent::extract_record($record, 'usr_'),
);
}
$records->close();
return array(
'count' => $DB->count_records_sql($countselect . $sql, $params),
'plans' => $plans
);
}
|
[
"public",
"static",
"function",
"list_plans_to_review",
"(",
"$",
"skip",
"=",
"0",
",",
"$",
"limit",
"=",
"100",
",",
"$",
"userid",
"=",
"null",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"USER",
";",
"static",
"::",
"require_enabled",
"(",
")",
";",
"if",
"(",
"$",
"userid",
"===",
"null",
")",
"{",
"$",
"userid",
"=",
"$",
"USER",
"->",
"id",
";",
"}",
"$",
"planfields",
"=",
"plan",
"::",
"get_sql_fields",
"(",
"'p'",
",",
"'plan_'",
")",
";",
"$",
"tplfields",
"=",
"template",
"::",
"get_sql_fields",
"(",
"'t'",
",",
"'tpl_'",
")",
";",
"$",
"usercols",
"=",
"array",
"(",
"'id'",
")",
"+",
"get_user_fieldnames",
"(",
")",
";",
"$",
"userfields",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"usercols",
"as",
"$",
"field",
")",
"{",
"$",
"userfields",
"[",
"]",
"=",
"\"u.\"",
".",
"$",
"field",
".",
"\" AS usr_\"",
".",
"$",
"field",
";",
"}",
"$",
"userfields",
"=",
"implode",
"(",
"','",
",",
"$",
"userfields",
")",
";",
"$",
"select",
"=",
"\"SELECT $planfields, $tplfields, $userfields\"",
";",
"$",
"countselect",
"=",
"\"SELECT COUNT('x')\"",
";",
"$",
"sql",
"=",
"\" FROM {\"",
".",
"plan",
"::",
"TABLE",
".",
"\"} p\n JOIN {user} u\n ON u.id = p.userid\n LEFT JOIN {\"",
".",
"template",
"::",
"TABLE",
".",
"\"} t\n ON t.id = p.templateid\n WHERE (p.status = :waitingforreview\n OR (p.status = :inreview AND p.reviewerid = :reviewerid))\n AND p.userid != :userid\"",
";",
"$",
"params",
"=",
"array",
"(",
"'waitingforreview'",
"=>",
"plan",
"::",
"STATUS_WAITING_FOR_REVIEW",
",",
"'inreview'",
"=>",
"plan",
"::",
"STATUS_IN_REVIEW",
",",
"'reviewerid'",
"=>",
"$",
"userid",
",",
"'userid'",
"=>",
"$",
"userid",
")",
";",
"// Primary check to avoid the hard work of getting the users in which the user has permission.",
"$",
"count",
"=",
"$",
"DB",
"->",
"count_records_sql",
"(",
"$",
"countselect",
".",
"$",
"sql",
",",
"$",
"params",
")",
";",
"if",
"(",
"$",
"count",
"<",
"1",
")",
"{",
"return",
"array",
"(",
"'count'",
"=>",
"0",
",",
"'plans'",
"=>",
"array",
"(",
")",
")",
";",
"}",
"// TODO MDL-52243 Use core function.",
"list",
"(",
"$",
"insql",
",",
"$",
"inparams",
")",
"=",
"self",
"::",
"filter_users_with_capability_on_user_context_sql",
"(",
"'moodle/competency:planreview'",
",",
"$",
"userid",
",",
"SQL_PARAMS_NAMED",
")",
";",
"$",
"sql",
".=",
"\" AND p.userid $insql\"",
";",
"$",
"params",
"+=",
"$",
"inparams",
";",
"// Order by ID just to have some ordering in place.",
"$",
"ordersql",
"=",
"\" ORDER BY p.id ASC\"",
";",
"$",
"plans",
"=",
"array",
"(",
")",
";",
"$",
"records",
"=",
"$",
"DB",
"->",
"get_recordset_sql",
"(",
"$",
"select",
".",
"$",
"sql",
".",
"$",
"ordersql",
",",
"$",
"params",
",",
"$",
"skip",
",",
"$",
"limit",
")",
";",
"foreach",
"(",
"$",
"records",
"as",
"$",
"record",
")",
"{",
"$",
"plan",
"=",
"new",
"plan",
"(",
"0",
",",
"plan",
"::",
"extract_record",
"(",
"$",
"record",
",",
"'plan_'",
")",
")",
";",
"$",
"template",
"=",
"null",
";",
"if",
"(",
"$",
"plan",
"->",
"is_based_on_template",
"(",
")",
")",
"{",
"$",
"template",
"=",
"new",
"template",
"(",
"0",
",",
"template",
"::",
"extract_record",
"(",
"$",
"record",
",",
"'tpl_'",
")",
")",
";",
"}",
"$",
"plans",
"[",
"]",
"=",
"(",
"object",
")",
"array",
"(",
"'plan'",
"=>",
"$",
"plan",
",",
"'template'",
"=>",
"$",
"template",
",",
"'owner'",
"=>",
"persistent",
"::",
"extract_record",
"(",
"$",
"record",
",",
"'usr_'",
")",
",",
")",
";",
"}",
"$",
"records",
"->",
"close",
"(",
")",
";",
"return",
"array",
"(",
"'count'",
"=>",
"$",
"DB",
"->",
"count_records_sql",
"(",
"$",
"countselect",
".",
"$",
"sql",
",",
"$",
"params",
")",
",",
"'plans'",
"=>",
"$",
"plans",
")",
";",
"}"
] |
List the plans to review.
The method returns values in this format:
array(
'plans' => array(
(stdClass)(
'plan' => (plan),
'template' => (template),
'owner' => (stdClass)
)
),
'count' => (int)
)
@param int $skip The number of records to skip.
@param int $limit The number of results to return.
@param int $userid The user we're getting the plans to review for.
@return array Containing the keys 'count', and 'plans'. The 'plans' key contains an object
which contains 'plan', 'template' and 'owner'.
|
[
"List",
"the",
"plans",
"to",
"review",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L2394-L2467
|
217,262
|
moodle/moodle
|
competency/classes/api.php
|
api.create_plan
|
public static function create_plan(stdClass $record) {
global $USER;
static::require_enabled();
$plan = new plan(0, $record);
if ($plan->is_based_on_template()) {
throw new coding_exception('To create a plan from a template use api::create_plan_from_template().');
} else if ($plan->get('status') == plan::STATUS_COMPLETE) {
throw new coding_exception('A plan cannot be created as complete.');
}
if (!$plan->can_manage()) {
$context = context_user::instance($plan->get('userid'));
throw new required_capability_exception($context, 'moodle/competency:planmanage', 'nopermissions', '');
}
$plan->create();
// Trigger created event.
\core\event\competency_plan_created::create_from_plan($plan)->trigger();
return $plan;
}
|
php
|
public static function create_plan(stdClass $record) {
global $USER;
static::require_enabled();
$plan = new plan(0, $record);
if ($plan->is_based_on_template()) {
throw new coding_exception('To create a plan from a template use api::create_plan_from_template().');
} else if ($plan->get('status') == plan::STATUS_COMPLETE) {
throw new coding_exception('A plan cannot be created as complete.');
}
if (!$plan->can_manage()) {
$context = context_user::instance($plan->get('userid'));
throw new required_capability_exception($context, 'moodle/competency:planmanage', 'nopermissions', '');
}
$plan->create();
// Trigger created event.
\core\event\competency_plan_created::create_from_plan($plan)->trigger();
return $plan;
}
|
[
"public",
"static",
"function",
"create_plan",
"(",
"stdClass",
"$",
"record",
")",
"{",
"global",
"$",
"USER",
";",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"plan",
"=",
"new",
"plan",
"(",
"0",
",",
"$",
"record",
")",
";",
"if",
"(",
"$",
"plan",
"->",
"is_based_on_template",
"(",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'To create a plan from a template use api::create_plan_from_template().'",
")",
";",
"}",
"else",
"if",
"(",
"$",
"plan",
"->",
"get",
"(",
"'status'",
")",
"==",
"plan",
"::",
"STATUS_COMPLETE",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'A plan cannot be created as complete.'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"plan",
"->",
"can_manage",
"(",
")",
")",
"{",
"$",
"context",
"=",
"context_user",
"::",
"instance",
"(",
"$",
"plan",
"->",
"get",
"(",
"'userid'",
")",
")",
";",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:planmanage'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"$",
"plan",
"->",
"create",
"(",
")",
";",
"// Trigger created event.",
"\\",
"core",
"\\",
"event",
"\\",
"competency_plan_created",
"::",
"create_from_plan",
"(",
"$",
"plan",
")",
"->",
"trigger",
"(",
")",
";",
"return",
"$",
"plan",
";",
"}"
] |
Creates a learning plan based on the provided data.
@param stdClass $record
@return \core_competency\plan
|
[
"Creates",
"a",
"learning",
"plan",
"based",
"on",
"the",
"provided",
"data",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L2475-L2496
|
217,263
|
moodle/moodle
|
competency/classes/api.php
|
api.create_plan_from_template
|
public static function create_plan_from_template($templateorid, $userid) {
static::require_enabled();
$template = $templateorid;
if (!is_object($template)) {
$template = new template($template);
}
// The user must be able to view the template to use it as a base for a plan.
if (!$template->can_read()) {
throw new required_capability_exception($template->get_context(), 'moodle/competency:templateview',
'nopermissions', '');
}
// Can not create plan from a hidden template.
if ($template->get('visible') == false) {
throw new coding_exception('A plan can not be created from a hidden template');
}
// Convert the template to a plan.
$record = $template->to_record();
$record->templateid = $record->id;
$record->userid = $userid;
$record->name = $record->shortname;
$record->status = plan::STATUS_ACTIVE;
unset($record->id);
unset($record->timecreated);
unset($record->timemodified);
unset($record->usermodified);
// Remove extra keys.
$properties = plan::properties_definition();
foreach ($record as $key => $value) {
if (!array_key_exists($key, $properties)) {
unset($record->$key);
}
}
$plan = new plan(0, $record);
if (!$plan->can_manage()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planmanage',
'nopermissions', '');
}
// We first apply the permission checks as we wouldn't want to leak information by returning early that
// the plan already exists.
if (plan::record_exists_select('templateid = :templateid AND userid = :userid', array(
'templateid' => $template->get('id'), 'userid' => $userid))) {
return false;
}
$plan->create();
// Trigger created event.
\core\event\competency_plan_created::create_from_plan($plan)->trigger();
return $plan;
}
|
php
|
public static function create_plan_from_template($templateorid, $userid) {
static::require_enabled();
$template = $templateorid;
if (!is_object($template)) {
$template = new template($template);
}
// The user must be able to view the template to use it as a base for a plan.
if (!$template->can_read()) {
throw new required_capability_exception($template->get_context(), 'moodle/competency:templateview',
'nopermissions', '');
}
// Can not create plan from a hidden template.
if ($template->get('visible') == false) {
throw new coding_exception('A plan can not be created from a hidden template');
}
// Convert the template to a plan.
$record = $template->to_record();
$record->templateid = $record->id;
$record->userid = $userid;
$record->name = $record->shortname;
$record->status = plan::STATUS_ACTIVE;
unset($record->id);
unset($record->timecreated);
unset($record->timemodified);
unset($record->usermodified);
// Remove extra keys.
$properties = plan::properties_definition();
foreach ($record as $key => $value) {
if (!array_key_exists($key, $properties)) {
unset($record->$key);
}
}
$plan = new plan(0, $record);
if (!$plan->can_manage()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planmanage',
'nopermissions', '');
}
// We first apply the permission checks as we wouldn't want to leak information by returning early that
// the plan already exists.
if (plan::record_exists_select('templateid = :templateid AND userid = :userid', array(
'templateid' => $template->get('id'), 'userid' => $userid))) {
return false;
}
$plan->create();
// Trigger created event.
\core\event\competency_plan_created::create_from_plan($plan)->trigger();
return $plan;
}
|
[
"public",
"static",
"function",
"create_plan_from_template",
"(",
"$",
"templateorid",
",",
"$",
"userid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"template",
"=",
"$",
"templateorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"template",
")",
")",
"{",
"$",
"template",
"=",
"new",
"template",
"(",
"$",
"template",
")",
";",
"}",
"// The user must be able to view the template to use it as a base for a plan.",
"if",
"(",
"!",
"$",
"template",
"->",
"can_read",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"template",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:templateview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// Can not create plan from a hidden template.",
"if",
"(",
"$",
"template",
"->",
"get",
"(",
"'visible'",
")",
"==",
"false",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'A plan can not be created from a hidden template'",
")",
";",
"}",
"// Convert the template to a plan.",
"$",
"record",
"=",
"$",
"template",
"->",
"to_record",
"(",
")",
";",
"$",
"record",
"->",
"templateid",
"=",
"$",
"record",
"->",
"id",
";",
"$",
"record",
"->",
"userid",
"=",
"$",
"userid",
";",
"$",
"record",
"->",
"name",
"=",
"$",
"record",
"->",
"shortname",
";",
"$",
"record",
"->",
"status",
"=",
"plan",
"::",
"STATUS_ACTIVE",
";",
"unset",
"(",
"$",
"record",
"->",
"id",
")",
";",
"unset",
"(",
"$",
"record",
"->",
"timecreated",
")",
";",
"unset",
"(",
"$",
"record",
"->",
"timemodified",
")",
";",
"unset",
"(",
"$",
"record",
"->",
"usermodified",
")",
";",
"// Remove extra keys.",
"$",
"properties",
"=",
"plan",
"::",
"properties_definition",
"(",
")",
";",
"foreach",
"(",
"$",
"record",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"properties",
")",
")",
"{",
"unset",
"(",
"$",
"record",
"->",
"$",
"key",
")",
";",
"}",
"}",
"$",
"plan",
"=",
"new",
"plan",
"(",
"0",
",",
"$",
"record",
")",
";",
"if",
"(",
"!",
"$",
"plan",
"->",
"can_manage",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"plan",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:planmanage'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// We first apply the permission checks as we wouldn't want to leak information by returning early that",
"// the plan already exists.",
"if",
"(",
"plan",
"::",
"record_exists_select",
"(",
"'templateid = :templateid AND userid = :userid'",
",",
"array",
"(",
"'templateid'",
"=>",
"$",
"template",
"->",
"get",
"(",
"'id'",
")",
",",
"'userid'",
"=>",
"$",
"userid",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"plan",
"->",
"create",
"(",
")",
";",
"// Trigger created event.",
"\\",
"core",
"\\",
"event",
"\\",
"competency_plan_created",
"::",
"create_from_plan",
"(",
"$",
"plan",
")",
"->",
"trigger",
"(",
")",
";",
"return",
"$",
"plan",
";",
"}"
] |
Create a learning plan from a template.
@param mixed $templateorid The template object or ID.
@param int $userid
@return false|\core_competency\plan Returns false when the plan already exists.
|
[
"Create",
"a",
"learning",
"plan",
"from",
"a",
"template",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L2505-L2560
|
217,264
|
moodle/moodle
|
competency/classes/api.php
|
api.create_plans_from_template_cohort
|
public static function create_plans_from_template_cohort($templateorid, $cohortid, $recreateunlinked = false) {
global $DB, $CFG;
static::require_enabled();
require_once($CFG->dirroot . '/cohort/lib.php');
$template = $templateorid;
if (!is_object($template)) {
$template = new template($template);
}
// The user must be able to view the template to use it as a base for a plan.
if (!$template->can_read()) {
throw new required_capability_exception($template->get_context(), 'moodle/competency:templateview',
'nopermissions', '');
}
// Can not create plan from a hidden template.
if ($template->get('visible') == false) {
throw new coding_exception('A plan can not be created from a hidden template');
}
// Replicate logic in cohort_can_view_cohort() because we can't use it directly as we don't have a course context.
$cohort = $DB->get_record('cohort', array('id' => $cohortid), '*', MUST_EXIST);
$cohortcontext = context::instance_by_id($cohort->contextid);
if (!$cohort->visible && !has_capability('moodle/cohort:view', $cohortcontext)) {
throw new required_capability_exception($cohortcontext, 'moodle/cohort:view', 'nopermissions', '');
}
// Convert the template to a plan.
$recordbase = $template->to_record();
$recordbase->templateid = $recordbase->id;
$recordbase->name = $recordbase->shortname;
$recordbase->status = plan::STATUS_ACTIVE;
unset($recordbase->id);
unset($recordbase->timecreated);
unset($recordbase->timemodified);
unset($recordbase->usermodified);
// Remove extra keys.
$properties = plan::properties_definition();
foreach ($recordbase as $key => $value) {
if (!array_key_exists($key, $properties)) {
unset($recordbase->$key);
}
}
// Create the plans.
$created = 0;
$userids = template_cohort::get_missing_plans($template->get('id'), $cohortid, $recreateunlinked);
foreach ($userids as $userid) {
$record = (object) (array) $recordbase;
$record->userid = $userid;
$plan = new plan(0, $record);
if (!$plan->can_manage()) {
// Silently skip members where permissions are lacking.
continue;
}
$plan->create();
// Trigger created event.
\core\event\competency_plan_created::create_from_plan($plan)->trigger();
$created++;
}
return $created;
}
|
php
|
public static function create_plans_from_template_cohort($templateorid, $cohortid, $recreateunlinked = false) {
global $DB, $CFG;
static::require_enabled();
require_once($CFG->dirroot . '/cohort/lib.php');
$template = $templateorid;
if (!is_object($template)) {
$template = new template($template);
}
// The user must be able to view the template to use it as a base for a plan.
if (!$template->can_read()) {
throw new required_capability_exception($template->get_context(), 'moodle/competency:templateview',
'nopermissions', '');
}
// Can not create plan from a hidden template.
if ($template->get('visible') == false) {
throw new coding_exception('A plan can not be created from a hidden template');
}
// Replicate logic in cohort_can_view_cohort() because we can't use it directly as we don't have a course context.
$cohort = $DB->get_record('cohort', array('id' => $cohortid), '*', MUST_EXIST);
$cohortcontext = context::instance_by_id($cohort->contextid);
if (!$cohort->visible && !has_capability('moodle/cohort:view', $cohortcontext)) {
throw new required_capability_exception($cohortcontext, 'moodle/cohort:view', 'nopermissions', '');
}
// Convert the template to a plan.
$recordbase = $template->to_record();
$recordbase->templateid = $recordbase->id;
$recordbase->name = $recordbase->shortname;
$recordbase->status = plan::STATUS_ACTIVE;
unset($recordbase->id);
unset($recordbase->timecreated);
unset($recordbase->timemodified);
unset($recordbase->usermodified);
// Remove extra keys.
$properties = plan::properties_definition();
foreach ($recordbase as $key => $value) {
if (!array_key_exists($key, $properties)) {
unset($recordbase->$key);
}
}
// Create the plans.
$created = 0;
$userids = template_cohort::get_missing_plans($template->get('id'), $cohortid, $recreateunlinked);
foreach ($userids as $userid) {
$record = (object) (array) $recordbase;
$record->userid = $userid;
$plan = new plan(0, $record);
if (!$plan->can_manage()) {
// Silently skip members where permissions are lacking.
continue;
}
$plan->create();
// Trigger created event.
\core\event\competency_plan_created::create_from_plan($plan)->trigger();
$created++;
}
return $created;
}
|
[
"public",
"static",
"function",
"create_plans_from_template_cohort",
"(",
"$",
"templateorid",
",",
"$",
"cohortid",
",",
"$",
"recreateunlinked",
"=",
"false",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"CFG",
";",
"static",
"::",
"require_enabled",
"(",
")",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/cohort/lib.php'",
")",
";",
"$",
"template",
"=",
"$",
"templateorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"template",
")",
")",
"{",
"$",
"template",
"=",
"new",
"template",
"(",
"$",
"template",
")",
";",
"}",
"// The user must be able to view the template to use it as a base for a plan.",
"if",
"(",
"!",
"$",
"template",
"->",
"can_read",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"template",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:templateview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// Can not create plan from a hidden template.",
"if",
"(",
"$",
"template",
"->",
"get",
"(",
"'visible'",
")",
"==",
"false",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'A plan can not be created from a hidden template'",
")",
";",
"}",
"// Replicate logic in cohort_can_view_cohort() because we can't use it directly as we don't have a course context.",
"$",
"cohort",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'cohort'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"cohortid",
")",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"$",
"cohortcontext",
"=",
"context",
"::",
"instance_by_id",
"(",
"$",
"cohort",
"->",
"contextid",
")",
";",
"if",
"(",
"!",
"$",
"cohort",
"->",
"visible",
"&&",
"!",
"has_capability",
"(",
"'moodle/cohort:view'",
",",
"$",
"cohortcontext",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"cohortcontext",
",",
"'moodle/cohort:view'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// Convert the template to a plan.",
"$",
"recordbase",
"=",
"$",
"template",
"->",
"to_record",
"(",
")",
";",
"$",
"recordbase",
"->",
"templateid",
"=",
"$",
"recordbase",
"->",
"id",
";",
"$",
"recordbase",
"->",
"name",
"=",
"$",
"recordbase",
"->",
"shortname",
";",
"$",
"recordbase",
"->",
"status",
"=",
"plan",
"::",
"STATUS_ACTIVE",
";",
"unset",
"(",
"$",
"recordbase",
"->",
"id",
")",
";",
"unset",
"(",
"$",
"recordbase",
"->",
"timecreated",
")",
";",
"unset",
"(",
"$",
"recordbase",
"->",
"timemodified",
")",
";",
"unset",
"(",
"$",
"recordbase",
"->",
"usermodified",
")",
";",
"// Remove extra keys.",
"$",
"properties",
"=",
"plan",
"::",
"properties_definition",
"(",
")",
";",
"foreach",
"(",
"$",
"recordbase",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"properties",
")",
")",
"{",
"unset",
"(",
"$",
"recordbase",
"->",
"$",
"key",
")",
";",
"}",
"}",
"// Create the plans.",
"$",
"created",
"=",
"0",
";",
"$",
"userids",
"=",
"template_cohort",
"::",
"get_missing_plans",
"(",
"$",
"template",
"->",
"get",
"(",
"'id'",
")",
",",
"$",
"cohortid",
",",
"$",
"recreateunlinked",
")",
";",
"foreach",
"(",
"$",
"userids",
"as",
"$",
"userid",
")",
"{",
"$",
"record",
"=",
"(",
"object",
")",
"(",
"array",
")",
"$",
"recordbase",
";",
"$",
"record",
"->",
"userid",
"=",
"$",
"userid",
";",
"$",
"plan",
"=",
"new",
"plan",
"(",
"0",
",",
"$",
"record",
")",
";",
"if",
"(",
"!",
"$",
"plan",
"->",
"can_manage",
"(",
")",
")",
"{",
"// Silently skip members where permissions are lacking.",
"continue",
";",
"}",
"$",
"plan",
"->",
"create",
"(",
")",
";",
"// Trigger created event.",
"\\",
"core",
"\\",
"event",
"\\",
"competency_plan_created",
"::",
"create_from_plan",
"(",
"$",
"plan",
")",
"->",
"trigger",
"(",
")",
";",
"$",
"created",
"++",
";",
"}",
"return",
"$",
"created",
";",
"}"
] |
Create learning plans from a template and cohort.
@param mixed $templateorid The template object or ID.
@param int $cohortid The cohort ID.
@param bool $recreateunlinked When true the plans that were unlinked from this template will be re-created.
@return int The number of plans created.
|
[
"Create",
"learning",
"plans",
"from",
"a",
"template",
"and",
"cohort",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L2570-L2637
|
217,265
|
moodle/moodle
|
competency/classes/api.php
|
api.unlink_plan_from_template
|
public static function unlink_plan_from_template($planorid) {
global $DB;
static::require_enabled();
$plan = $planorid;
if (!is_object($planorid)) {
$plan = new plan($planorid);
}
// The user must be allowed to manage the plans of the user, nothing about the template.
if (!$plan->can_manage()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planmanage', 'nopermissions', '');
}
// Only plan with status DRAFT or ACTIVE can be unliked..
if ($plan->get('status') == plan::STATUS_COMPLETE) {
throw new coding_exception('Only draft or active plan can be unliked from a template');
}
// Early exit, it's already done...
if (!$plan->is_based_on_template()) {
return true;
}
// Fetch the template.
$template = new template($plan->get('templateid'));
// Now, proceed by copying all competencies to the plan, then update the plan.
$transaction = $DB->start_delegated_transaction();
$competencies = template_competency::list_competencies($template->get('id'), false);
$i = 0;
foreach ($competencies as $competency) {
$record = (object) array(
'planid' => $plan->get('id'),
'competencyid' => $competency->get('id'),
'sortorder' => $i++
);
$pc = new plan_competency(null, $record);
$pc->create();
}
$plan->set('origtemplateid', $template->get('id'));
$plan->set('templateid', null);
$success = $plan->update();
$transaction->allow_commit();
// Trigger unlinked event.
\core\event\competency_plan_unlinked::create_from_plan($plan)->trigger();
return $success;
}
|
php
|
public static function unlink_plan_from_template($planorid) {
global $DB;
static::require_enabled();
$plan = $planorid;
if (!is_object($planorid)) {
$plan = new plan($planorid);
}
// The user must be allowed to manage the plans of the user, nothing about the template.
if (!$plan->can_manage()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planmanage', 'nopermissions', '');
}
// Only plan with status DRAFT or ACTIVE can be unliked..
if ($plan->get('status') == plan::STATUS_COMPLETE) {
throw new coding_exception('Only draft or active plan can be unliked from a template');
}
// Early exit, it's already done...
if (!$plan->is_based_on_template()) {
return true;
}
// Fetch the template.
$template = new template($plan->get('templateid'));
// Now, proceed by copying all competencies to the plan, then update the plan.
$transaction = $DB->start_delegated_transaction();
$competencies = template_competency::list_competencies($template->get('id'), false);
$i = 0;
foreach ($competencies as $competency) {
$record = (object) array(
'planid' => $plan->get('id'),
'competencyid' => $competency->get('id'),
'sortorder' => $i++
);
$pc = new plan_competency(null, $record);
$pc->create();
}
$plan->set('origtemplateid', $template->get('id'));
$plan->set('templateid', null);
$success = $plan->update();
$transaction->allow_commit();
// Trigger unlinked event.
\core\event\competency_plan_unlinked::create_from_plan($plan)->trigger();
return $success;
}
|
[
"public",
"static",
"function",
"unlink_plan_from_template",
"(",
"$",
"planorid",
")",
"{",
"global",
"$",
"DB",
";",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"plan",
"=",
"$",
"planorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"planorid",
")",
")",
"{",
"$",
"plan",
"=",
"new",
"plan",
"(",
"$",
"planorid",
")",
";",
"}",
"// The user must be allowed to manage the plans of the user, nothing about the template.",
"if",
"(",
"!",
"$",
"plan",
"->",
"can_manage",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"plan",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:planmanage'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// Only plan with status DRAFT or ACTIVE can be unliked..",
"if",
"(",
"$",
"plan",
"->",
"get",
"(",
"'status'",
")",
"==",
"plan",
"::",
"STATUS_COMPLETE",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Only draft or active plan can be unliked from a template'",
")",
";",
"}",
"// Early exit, it's already done...",
"if",
"(",
"!",
"$",
"plan",
"->",
"is_based_on_template",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"// Fetch the template.",
"$",
"template",
"=",
"new",
"template",
"(",
"$",
"plan",
"->",
"get",
"(",
"'templateid'",
")",
")",
";",
"// Now, proceed by copying all competencies to the plan, then update the plan.",
"$",
"transaction",
"=",
"$",
"DB",
"->",
"start_delegated_transaction",
"(",
")",
";",
"$",
"competencies",
"=",
"template_competency",
"::",
"list_competencies",
"(",
"$",
"template",
"->",
"get",
"(",
"'id'",
")",
",",
"false",
")",
";",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"competencies",
"as",
"$",
"competency",
")",
"{",
"$",
"record",
"=",
"(",
"object",
")",
"array",
"(",
"'planid'",
"=>",
"$",
"plan",
"->",
"get",
"(",
"'id'",
")",
",",
"'competencyid'",
"=>",
"$",
"competency",
"->",
"get",
"(",
"'id'",
")",
",",
"'sortorder'",
"=>",
"$",
"i",
"++",
")",
";",
"$",
"pc",
"=",
"new",
"plan_competency",
"(",
"null",
",",
"$",
"record",
")",
";",
"$",
"pc",
"->",
"create",
"(",
")",
";",
"}",
"$",
"plan",
"->",
"set",
"(",
"'origtemplateid'",
",",
"$",
"template",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"$",
"plan",
"->",
"set",
"(",
"'templateid'",
",",
"null",
")",
";",
"$",
"success",
"=",
"$",
"plan",
"->",
"update",
"(",
")",
";",
"$",
"transaction",
"->",
"allow_commit",
"(",
")",
";",
"// Trigger unlinked event.",
"\\",
"core",
"\\",
"event",
"\\",
"competency_plan_unlinked",
"::",
"create_from_plan",
"(",
"$",
"plan",
")",
"->",
"trigger",
"(",
")",
";",
"return",
"$",
"success",
";",
"}"
] |
Unlink a plan from its template.
@param \core_competency\plan|int $planorid The plan or its ID.
@return bool
|
[
"Unlink",
"a",
"plan",
"from",
"its",
"template",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L2645-L2694
|
217,266
|
moodle/moodle
|
competency/classes/api.php
|
api.update_plan
|
public static function update_plan(stdClass $record) {
static::require_enabled();
$plan = new plan($record->id);
// Validate that the plan as it is can be managed.
if (!$plan->can_manage()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planmanage', 'nopermissions', '');
} else if ($plan->get('status') == plan::STATUS_COMPLETE) {
// A completed plan cannot be edited.
throw new coding_exception('Completed plan cannot be edited.');
} else if ($plan->is_based_on_template()) {
// Prevent a plan based on a template to be edited.
throw new coding_exception('Cannot update a plan that is based on a template.');
} else if (isset($record->templateid) && $plan->get('templateid') != $record->templateid) {
// Prevent a plan to be based on a template.
throw new coding_exception('Cannot base a plan on a template.');
} else if (isset($record->userid) && $plan->get('userid') != $record->userid) {
// Prevent change of ownership as the capabilities are checked against that.
throw new coding_exception('A plan cannot be transfered to another user');
} else if (isset($record->status) && $plan->get('status') != $record->status) {
// Prevent change of status.
throw new coding_exception('To change the status of a plan use the appropriate methods.');
}
$plan->from_record($record);
$plan->update();
// Trigger updated event.
\core\event\competency_plan_updated::create_from_plan($plan)->trigger();
return $plan;
}
|
php
|
public static function update_plan(stdClass $record) {
static::require_enabled();
$plan = new plan($record->id);
// Validate that the plan as it is can be managed.
if (!$plan->can_manage()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planmanage', 'nopermissions', '');
} else if ($plan->get('status') == plan::STATUS_COMPLETE) {
// A completed plan cannot be edited.
throw new coding_exception('Completed plan cannot be edited.');
} else if ($plan->is_based_on_template()) {
// Prevent a plan based on a template to be edited.
throw new coding_exception('Cannot update a plan that is based on a template.');
} else if (isset($record->templateid) && $plan->get('templateid') != $record->templateid) {
// Prevent a plan to be based on a template.
throw new coding_exception('Cannot base a plan on a template.');
} else if (isset($record->userid) && $plan->get('userid') != $record->userid) {
// Prevent change of ownership as the capabilities are checked against that.
throw new coding_exception('A plan cannot be transfered to another user');
} else if (isset($record->status) && $plan->get('status') != $record->status) {
// Prevent change of status.
throw new coding_exception('To change the status of a plan use the appropriate methods.');
}
$plan->from_record($record);
$plan->update();
// Trigger updated event.
\core\event\competency_plan_updated::create_from_plan($plan)->trigger();
return $plan;
}
|
[
"public",
"static",
"function",
"update_plan",
"(",
"stdClass",
"$",
"record",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"plan",
"=",
"new",
"plan",
"(",
"$",
"record",
"->",
"id",
")",
";",
"// Validate that the plan as it is can be managed.",
"if",
"(",
"!",
"$",
"plan",
"->",
"can_manage",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"plan",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:planmanage'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"else",
"if",
"(",
"$",
"plan",
"->",
"get",
"(",
"'status'",
")",
"==",
"plan",
"::",
"STATUS_COMPLETE",
")",
"{",
"// A completed plan cannot be edited.",
"throw",
"new",
"coding_exception",
"(",
"'Completed plan cannot be edited.'",
")",
";",
"}",
"else",
"if",
"(",
"$",
"plan",
"->",
"is_based_on_template",
"(",
")",
")",
"{",
"// Prevent a plan based on a template to be edited.",
"throw",
"new",
"coding_exception",
"(",
"'Cannot update a plan that is based on a template.'",
")",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"record",
"->",
"templateid",
")",
"&&",
"$",
"plan",
"->",
"get",
"(",
"'templateid'",
")",
"!=",
"$",
"record",
"->",
"templateid",
")",
"{",
"// Prevent a plan to be based on a template.",
"throw",
"new",
"coding_exception",
"(",
"'Cannot base a plan on a template.'",
")",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"record",
"->",
"userid",
")",
"&&",
"$",
"plan",
"->",
"get",
"(",
"'userid'",
")",
"!=",
"$",
"record",
"->",
"userid",
")",
"{",
"// Prevent change of ownership as the capabilities are checked against that.",
"throw",
"new",
"coding_exception",
"(",
"'A plan cannot be transfered to another user'",
")",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"record",
"->",
"status",
")",
"&&",
"$",
"plan",
"->",
"get",
"(",
"'status'",
")",
"!=",
"$",
"record",
"->",
"status",
")",
"{",
"// Prevent change of status.",
"throw",
"new",
"coding_exception",
"(",
"'To change the status of a plan use the appropriate methods.'",
")",
";",
"}",
"$",
"plan",
"->",
"from_record",
"(",
"$",
"record",
")",
";",
"$",
"plan",
"->",
"update",
"(",
")",
";",
"// Trigger updated event.",
"\\",
"core",
"\\",
"event",
"\\",
"competency_plan_updated",
"::",
"create_from_plan",
"(",
"$",
"plan",
")",
"->",
"trigger",
"(",
")",
";",
"return",
"$",
"plan",
";",
"}"
] |
Updates a plan.
@param stdClass $record
@return \core_competency\plan
|
[
"Updates",
"a",
"plan",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L2702-L2740
|
217,267
|
moodle/moodle
|
competency/classes/api.php
|
api.read_plan
|
public static function read_plan($id) {
static::require_enabled();
$plan = new plan($id);
if (!$plan->can_read()) {
$context = context_user::instance($plan->get('userid'));
throw new required_capability_exception($context, 'moodle/competency:planview', 'nopermissions', '');
}
return $plan;
}
|
php
|
public static function read_plan($id) {
static::require_enabled();
$plan = new plan($id);
if (!$plan->can_read()) {
$context = context_user::instance($plan->get('userid'));
throw new required_capability_exception($context, 'moodle/competency:planview', 'nopermissions', '');
}
return $plan;
}
|
[
"public",
"static",
"function",
"read_plan",
"(",
"$",
"id",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"plan",
"=",
"new",
"plan",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"plan",
"->",
"can_read",
"(",
")",
")",
"{",
"$",
"context",
"=",
"context_user",
"::",
"instance",
"(",
"$",
"plan",
"->",
"get",
"(",
"'userid'",
")",
")",
";",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:planview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"return",
"$",
"plan",
";",
"}"
] |
Returns a plan data.
@param int $id
@return \core_competency\plan
|
[
"Returns",
"a",
"plan",
"data",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L2748-L2758
|
217,268
|
moodle/moodle
|
competency/classes/api.php
|
api.plan_viewed
|
public static function plan_viewed($planorid) {
static::require_enabled();
$plan = $planorid;
if (!is_object($plan)) {
$plan = new plan($plan);
}
// First we do a permissions check.
if (!$plan->can_read()) {
$context = context_user::instance($plan->get('userid'));
throw new required_capability_exception($context, 'moodle/competency:planview', 'nopermissions', '');
}
// Trigger a template viewed event.
\core\event\competency_plan_viewed::create_from_plan($plan)->trigger();
return true;
}
|
php
|
public static function plan_viewed($planorid) {
static::require_enabled();
$plan = $planorid;
if (!is_object($plan)) {
$plan = new plan($plan);
}
// First we do a permissions check.
if (!$plan->can_read()) {
$context = context_user::instance($plan->get('userid'));
throw new required_capability_exception($context, 'moodle/competency:planview', 'nopermissions', '');
}
// Trigger a template viewed event.
\core\event\competency_plan_viewed::create_from_plan($plan)->trigger();
return true;
}
|
[
"public",
"static",
"function",
"plan_viewed",
"(",
"$",
"planorid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"plan",
"=",
"$",
"planorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"plan",
")",
")",
"{",
"$",
"plan",
"=",
"new",
"plan",
"(",
"$",
"plan",
")",
";",
"}",
"// First we do a permissions check.",
"if",
"(",
"!",
"$",
"plan",
"->",
"can_read",
"(",
")",
")",
"{",
"$",
"context",
"=",
"context_user",
"::",
"instance",
"(",
"$",
"plan",
"->",
"get",
"(",
"'userid'",
")",
")",
";",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:planview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// Trigger a template viewed event.",
"\\",
"core",
"\\",
"event",
"\\",
"competency_plan_viewed",
"::",
"create_from_plan",
"(",
"$",
"plan",
")",
"->",
"trigger",
"(",
")",
";",
"return",
"true",
";",
"}"
] |
Plan event viewed.
@param mixed $planorid The id or the plan.
@return boolean
|
[
"Plan",
"event",
"viewed",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L2766-L2783
|
217,269
|
moodle/moodle
|
competency/classes/api.php
|
api.delete_plan
|
public static function delete_plan($id) {
global $DB;
static::require_enabled();
$plan = new plan($id);
if (!$plan->can_manage()) {
$context = context_user::instance($plan->get('userid'));
throw new required_capability_exception($context, 'moodle/competency:planmanage', 'nopermissions', '');
}
// Wrap the suppression in a DB transaction.
$transaction = $DB->start_delegated_transaction();
// Delete plan competencies.
$plancomps = plan_competency::get_records(array('planid' => $plan->get('id')));
foreach ($plancomps as $plancomp) {
$plancomp->delete();
}
// Delete archive user competencies if the status of the plan is complete.
if ($plan->get('status') == plan::STATUS_COMPLETE) {
self::remove_archived_user_competencies_in_plan($plan);
}
$event = \core\event\competency_plan_deleted::create_from_plan($plan);
$success = $plan->delete();
$transaction->allow_commit();
// Trigger deleted event.
$event->trigger();
return $success;
}
|
php
|
public static function delete_plan($id) {
global $DB;
static::require_enabled();
$plan = new plan($id);
if (!$plan->can_manage()) {
$context = context_user::instance($plan->get('userid'));
throw new required_capability_exception($context, 'moodle/competency:planmanage', 'nopermissions', '');
}
// Wrap the suppression in a DB transaction.
$transaction = $DB->start_delegated_transaction();
// Delete plan competencies.
$plancomps = plan_competency::get_records(array('planid' => $plan->get('id')));
foreach ($plancomps as $plancomp) {
$plancomp->delete();
}
// Delete archive user competencies if the status of the plan is complete.
if ($plan->get('status') == plan::STATUS_COMPLETE) {
self::remove_archived_user_competencies_in_plan($plan);
}
$event = \core\event\competency_plan_deleted::create_from_plan($plan);
$success = $plan->delete();
$transaction->allow_commit();
// Trigger deleted event.
$event->trigger();
return $success;
}
|
[
"public",
"static",
"function",
"delete_plan",
"(",
"$",
"id",
")",
"{",
"global",
"$",
"DB",
";",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"plan",
"=",
"new",
"plan",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"plan",
"->",
"can_manage",
"(",
")",
")",
"{",
"$",
"context",
"=",
"context_user",
"::",
"instance",
"(",
"$",
"plan",
"->",
"get",
"(",
"'userid'",
")",
")",
";",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:planmanage'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// Wrap the suppression in a DB transaction.",
"$",
"transaction",
"=",
"$",
"DB",
"->",
"start_delegated_transaction",
"(",
")",
";",
"// Delete plan competencies.",
"$",
"plancomps",
"=",
"plan_competency",
"::",
"get_records",
"(",
"array",
"(",
"'planid'",
"=>",
"$",
"plan",
"->",
"get",
"(",
"'id'",
")",
")",
")",
";",
"foreach",
"(",
"$",
"plancomps",
"as",
"$",
"plancomp",
")",
"{",
"$",
"plancomp",
"->",
"delete",
"(",
")",
";",
"}",
"// Delete archive user competencies if the status of the plan is complete.",
"if",
"(",
"$",
"plan",
"->",
"get",
"(",
"'status'",
")",
"==",
"plan",
"::",
"STATUS_COMPLETE",
")",
"{",
"self",
"::",
"remove_archived_user_competencies_in_plan",
"(",
"$",
"plan",
")",
";",
"}",
"$",
"event",
"=",
"\\",
"core",
"\\",
"event",
"\\",
"competency_plan_deleted",
"::",
"create_from_plan",
"(",
"$",
"plan",
")",
";",
"$",
"success",
"=",
"$",
"plan",
"->",
"delete",
"(",
")",
";",
"$",
"transaction",
"->",
"allow_commit",
"(",
")",
";",
"// Trigger deleted event.",
"$",
"event",
"->",
"trigger",
"(",
")",
";",
"return",
"$",
"success",
";",
"}"
] |
Deletes a plan.
Plans based on a template can be removed just like any other one.
@param int $id
@return bool Success?
|
[
"Deletes",
"a",
"plan",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L2793-L2826
|
217,270
|
moodle/moodle
|
competency/classes/api.php
|
api.plan_cancel_review_request
|
public static function plan_cancel_review_request($planorid) {
static::require_enabled();
$plan = $planorid;
if (!is_object($plan)) {
$plan = new plan($plan);
}
// We need to be able to view the plan at least.
if (!$plan->can_read()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planview', 'nopermissions', '');
}
if ($plan->is_based_on_template()) {
throw new coding_exception('Template plans cannot be reviewed.'); // This should never happen.
} else if ($plan->get('status') != plan::STATUS_WAITING_FOR_REVIEW) {
throw new coding_exception('The plan review cannot be cancelled at this stage.');
} else if (!$plan->can_request_review()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planmanage', 'nopermissions', '');
}
$plan->set('status', plan::STATUS_DRAFT);
$result = $plan->update();
// Trigger review request cancelled event.
\core\event\competency_plan_review_request_cancelled::create_from_plan($plan)->trigger();
return $result;
}
|
php
|
public static function plan_cancel_review_request($planorid) {
static::require_enabled();
$plan = $planorid;
if (!is_object($plan)) {
$plan = new plan($plan);
}
// We need to be able to view the plan at least.
if (!$plan->can_read()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planview', 'nopermissions', '');
}
if ($plan->is_based_on_template()) {
throw new coding_exception('Template plans cannot be reviewed.'); // This should never happen.
} else if ($plan->get('status') != plan::STATUS_WAITING_FOR_REVIEW) {
throw new coding_exception('The plan review cannot be cancelled at this stage.');
} else if (!$plan->can_request_review()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planmanage', 'nopermissions', '');
}
$plan->set('status', plan::STATUS_DRAFT);
$result = $plan->update();
// Trigger review request cancelled event.
\core\event\competency_plan_review_request_cancelled::create_from_plan($plan)->trigger();
return $result;
}
|
[
"public",
"static",
"function",
"plan_cancel_review_request",
"(",
"$",
"planorid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"plan",
"=",
"$",
"planorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"plan",
")",
")",
"{",
"$",
"plan",
"=",
"new",
"plan",
"(",
"$",
"plan",
")",
";",
"}",
"// We need to be able to view the plan at least.",
"if",
"(",
"!",
"$",
"plan",
"->",
"can_read",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"plan",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:planview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"if",
"(",
"$",
"plan",
"->",
"is_based_on_template",
"(",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Template plans cannot be reviewed.'",
")",
";",
"// This should never happen.",
"}",
"else",
"if",
"(",
"$",
"plan",
"->",
"get",
"(",
"'status'",
")",
"!=",
"plan",
"::",
"STATUS_WAITING_FOR_REVIEW",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The plan review cannot be cancelled at this stage.'",
")",
";",
"}",
"else",
"if",
"(",
"!",
"$",
"plan",
"->",
"can_request_review",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"plan",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:planmanage'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"$",
"plan",
"->",
"set",
"(",
"'status'",
",",
"plan",
"::",
"STATUS_DRAFT",
")",
";",
"$",
"result",
"=",
"$",
"plan",
"->",
"update",
"(",
")",
";",
"// Trigger review request cancelled event.",
"\\",
"core",
"\\",
"event",
"\\",
"competency_plan_review_request_cancelled",
"::",
"create_from_plan",
"(",
"$",
"plan",
")",
"->",
"trigger",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
] |
Cancel the review of a plan.
@param int|plan $planorid The plan, or its ID.
@return bool
|
[
"Cancel",
"the",
"review",
"of",
"a",
"plan",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L2834-L2861
|
217,271
|
moodle/moodle
|
competency/classes/api.php
|
api.plan_start_review
|
public static function plan_start_review($planorid) {
global $USER;
static::require_enabled();
$plan = $planorid;
if (!is_object($plan)) {
$plan = new plan($plan);
}
// We need to be able to view the plan at least.
if (!$plan->can_read()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planview', 'nopermissions', '');
}
if ($plan->is_based_on_template()) {
throw new coding_exception('Template plans cannot be reviewed.'); // This should never happen.
} else if ($plan->get('status') != plan::STATUS_WAITING_FOR_REVIEW) {
throw new coding_exception('The plan review cannot be started at this stage.');
} else if (!$plan->can_review()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planmanage', 'nopermissions', '');
}
$plan->set('status', plan::STATUS_IN_REVIEW);
$plan->set('reviewerid', $USER->id);
$result = $plan->update();
// Trigger review started event.
\core\event\competency_plan_review_started::create_from_plan($plan)->trigger();
return $result;
}
|
php
|
public static function plan_start_review($planorid) {
global $USER;
static::require_enabled();
$plan = $planorid;
if (!is_object($plan)) {
$plan = new plan($plan);
}
// We need to be able to view the plan at least.
if (!$plan->can_read()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planview', 'nopermissions', '');
}
if ($plan->is_based_on_template()) {
throw new coding_exception('Template plans cannot be reviewed.'); // This should never happen.
} else if ($plan->get('status') != plan::STATUS_WAITING_FOR_REVIEW) {
throw new coding_exception('The plan review cannot be started at this stage.');
} else if (!$plan->can_review()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planmanage', 'nopermissions', '');
}
$plan->set('status', plan::STATUS_IN_REVIEW);
$plan->set('reviewerid', $USER->id);
$result = $plan->update();
// Trigger review started event.
\core\event\competency_plan_review_started::create_from_plan($plan)->trigger();
return $result;
}
|
[
"public",
"static",
"function",
"plan_start_review",
"(",
"$",
"planorid",
")",
"{",
"global",
"$",
"USER",
";",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"plan",
"=",
"$",
"planorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"plan",
")",
")",
"{",
"$",
"plan",
"=",
"new",
"plan",
"(",
"$",
"plan",
")",
";",
"}",
"// We need to be able to view the plan at least.",
"if",
"(",
"!",
"$",
"plan",
"->",
"can_read",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"plan",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:planview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"if",
"(",
"$",
"plan",
"->",
"is_based_on_template",
"(",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Template plans cannot be reviewed.'",
")",
";",
"// This should never happen.",
"}",
"else",
"if",
"(",
"$",
"plan",
"->",
"get",
"(",
"'status'",
")",
"!=",
"plan",
"::",
"STATUS_WAITING_FOR_REVIEW",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The plan review cannot be started at this stage.'",
")",
";",
"}",
"else",
"if",
"(",
"!",
"$",
"plan",
"->",
"can_review",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"plan",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:planmanage'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"$",
"plan",
"->",
"set",
"(",
"'status'",
",",
"plan",
"::",
"STATUS_IN_REVIEW",
")",
";",
"$",
"plan",
"->",
"set",
"(",
"'reviewerid'",
",",
"$",
"USER",
"->",
"id",
")",
";",
"$",
"result",
"=",
"$",
"plan",
"->",
"update",
"(",
")",
";",
"// Trigger review started event.",
"\\",
"core",
"\\",
"event",
"\\",
"competency_plan_review_started",
"::",
"create_from_plan",
"(",
"$",
"plan",
")",
"->",
"trigger",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
] |
Start the review of a plan.
@param int|plan $planorid The plan, or its ID.
@return bool
|
[
"Start",
"the",
"review",
"of",
"a",
"plan",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L2904-L2933
|
217,272
|
moodle/moodle
|
competency/classes/api.php
|
api.plan_stop_review
|
public static function plan_stop_review($planorid) {
static::require_enabled();
$plan = $planorid;
if (!is_object($plan)) {
$plan = new plan($plan);
}
// We need to be able to view the plan at least.
if (!$plan->can_read()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planview', 'nopermissions', '');
}
if ($plan->is_based_on_template()) {
throw new coding_exception('Template plans cannot be reviewed.'); // This should never happen.
} else if ($plan->get('status') != plan::STATUS_IN_REVIEW) {
throw new coding_exception('The plan review cannot be stopped at this stage.');
} else if (!$plan->can_review()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planmanage', 'nopermissions', '');
}
$plan->set('status', plan::STATUS_DRAFT);
$plan->set('reviewerid', null);
$result = $plan->update();
// Trigger review stopped event.
\core\event\competency_plan_review_stopped::create_from_plan($plan)->trigger();
return $result;
}
|
php
|
public static function plan_stop_review($planorid) {
static::require_enabled();
$plan = $planorid;
if (!is_object($plan)) {
$plan = new plan($plan);
}
// We need to be able to view the plan at least.
if (!$plan->can_read()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planview', 'nopermissions', '');
}
if ($plan->is_based_on_template()) {
throw new coding_exception('Template plans cannot be reviewed.'); // This should never happen.
} else if ($plan->get('status') != plan::STATUS_IN_REVIEW) {
throw new coding_exception('The plan review cannot be stopped at this stage.');
} else if (!$plan->can_review()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planmanage', 'nopermissions', '');
}
$plan->set('status', plan::STATUS_DRAFT);
$plan->set('reviewerid', null);
$result = $plan->update();
// Trigger review stopped event.
\core\event\competency_plan_review_stopped::create_from_plan($plan)->trigger();
return $result;
}
|
[
"public",
"static",
"function",
"plan_stop_review",
"(",
"$",
"planorid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"plan",
"=",
"$",
"planorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"plan",
")",
")",
"{",
"$",
"plan",
"=",
"new",
"plan",
"(",
"$",
"plan",
")",
";",
"}",
"// We need to be able to view the plan at least.",
"if",
"(",
"!",
"$",
"plan",
"->",
"can_read",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"plan",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:planview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"if",
"(",
"$",
"plan",
"->",
"is_based_on_template",
"(",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Template plans cannot be reviewed.'",
")",
";",
"// This should never happen.",
"}",
"else",
"if",
"(",
"$",
"plan",
"->",
"get",
"(",
"'status'",
")",
"!=",
"plan",
"::",
"STATUS_IN_REVIEW",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The plan review cannot be stopped at this stage.'",
")",
";",
"}",
"else",
"if",
"(",
"!",
"$",
"plan",
"->",
"can_review",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"plan",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:planmanage'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"$",
"plan",
"->",
"set",
"(",
"'status'",
",",
"plan",
"::",
"STATUS_DRAFT",
")",
";",
"$",
"plan",
"->",
"set",
"(",
"'reviewerid'",
",",
"null",
")",
";",
"$",
"result",
"=",
"$",
"plan",
"->",
"update",
"(",
")",
";",
"// Trigger review stopped event.",
"\\",
"core",
"\\",
"event",
"\\",
"competency_plan_review_stopped",
"::",
"create_from_plan",
"(",
"$",
"plan",
")",
"->",
"trigger",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
] |
Stop reviewing a plan.
@param int|plan $planorid The plan, or its ID.
@return bool
|
[
"Stop",
"reviewing",
"a",
"plan",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L2941-L2969
|
217,273
|
moodle/moodle
|
competency/classes/api.php
|
api.approve_plan
|
public static function approve_plan($planorid) {
static::require_enabled();
$plan = $planorid;
if (!is_object($plan)) {
$plan = new plan($plan);
}
// We need to be able to view the plan at least.
if (!$plan->can_read()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planview', 'nopermissions', '');
}
// We can approve a plan that is either a draft, in review, or waiting for review.
if ($plan->is_based_on_template()) {
throw new coding_exception('Template plans are already approved.'); // This should never happen.
} else if (!$plan->is_draft()) {
throw new coding_exception('The plan cannot be approved at this stage.');
} else if (!$plan->can_review()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planmanage', 'nopermissions', '');
}
$plan->set('status', plan::STATUS_ACTIVE);
$plan->set('reviewerid', null);
$result = $plan->update();
// Trigger approved event.
\core\event\competency_plan_approved::create_from_plan($plan)->trigger();
return $result;
}
|
php
|
public static function approve_plan($planorid) {
static::require_enabled();
$plan = $planorid;
if (!is_object($plan)) {
$plan = new plan($plan);
}
// We need to be able to view the plan at least.
if (!$plan->can_read()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planview', 'nopermissions', '');
}
// We can approve a plan that is either a draft, in review, or waiting for review.
if ($plan->is_based_on_template()) {
throw new coding_exception('Template plans are already approved.'); // This should never happen.
} else if (!$plan->is_draft()) {
throw new coding_exception('The plan cannot be approved at this stage.');
} else if (!$plan->can_review()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planmanage', 'nopermissions', '');
}
$plan->set('status', plan::STATUS_ACTIVE);
$plan->set('reviewerid', null);
$result = $plan->update();
// Trigger approved event.
\core\event\competency_plan_approved::create_from_plan($plan)->trigger();
return $result;
}
|
[
"public",
"static",
"function",
"approve_plan",
"(",
"$",
"planorid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"plan",
"=",
"$",
"planorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"plan",
")",
")",
"{",
"$",
"plan",
"=",
"new",
"plan",
"(",
"$",
"plan",
")",
";",
"}",
"// We need to be able to view the plan at least.",
"if",
"(",
"!",
"$",
"plan",
"->",
"can_read",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"plan",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:planview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// We can approve a plan that is either a draft, in review, or waiting for review.",
"if",
"(",
"$",
"plan",
"->",
"is_based_on_template",
"(",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Template plans are already approved.'",
")",
";",
"// This should never happen.",
"}",
"else",
"if",
"(",
"!",
"$",
"plan",
"->",
"is_draft",
"(",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The plan cannot be approved at this stage.'",
")",
";",
"}",
"else",
"if",
"(",
"!",
"$",
"plan",
"->",
"can_review",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"plan",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:planmanage'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"$",
"plan",
"->",
"set",
"(",
"'status'",
",",
"plan",
"::",
"STATUS_ACTIVE",
")",
";",
"$",
"plan",
"->",
"set",
"(",
"'reviewerid'",
",",
"null",
")",
";",
"$",
"result",
"=",
"$",
"plan",
"->",
"update",
"(",
")",
";",
"// Trigger approved event.",
"\\",
"core",
"\\",
"event",
"\\",
"competency_plan_approved",
"::",
"create_from_plan",
"(",
"$",
"plan",
")",
"->",
"trigger",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
] |
Approve a plan.
This means making the plan active.
@param int|plan $planorid The plan, or its ID.
@return bool
|
[
"Approve",
"a",
"plan",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L2979-L3008
|
217,274
|
moodle/moodle
|
competency/classes/api.php
|
api.unapprove_plan
|
public static function unapprove_plan($planorid) {
static::require_enabled();
$plan = $planorid;
if (!is_object($plan)) {
$plan = new plan($plan);
}
// We need to be able to view the plan at least.
if (!$plan->can_read()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planview', 'nopermissions', '');
}
if ($plan->is_based_on_template()) {
throw new coding_exception('Template plans are always approved.'); // This should never happen.
} else if ($plan->get('status') != plan::STATUS_ACTIVE) {
throw new coding_exception('The plan cannot be sent back to draft at this stage.');
} else if (!$plan->can_review()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planmanage', 'nopermissions', '');
}
$plan->set('status', plan::STATUS_DRAFT);
$result = $plan->update();
// Trigger unapproved event.
\core\event\competency_plan_unapproved::create_from_plan($plan)->trigger();
return $result;
}
|
php
|
public static function unapprove_plan($planorid) {
static::require_enabled();
$plan = $planorid;
if (!is_object($plan)) {
$plan = new plan($plan);
}
// We need to be able to view the plan at least.
if (!$plan->can_read()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planview', 'nopermissions', '');
}
if ($plan->is_based_on_template()) {
throw new coding_exception('Template plans are always approved.'); // This should never happen.
} else if ($plan->get('status') != plan::STATUS_ACTIVE) {
throw new coding_exception('The plan cannot be sent back to draft at this stage.');
} else if (!$plan->can_review()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planmanage', 'nopermissions', '');
}
$plan->set('status', plan::STATUS_DRAFT);
$result = $plan->update();
// Trigger unapproved event.
\core\event\competency_plan_unapproved::create_from_plan($plan)->trigger();
return $result;
}
|
[
"public",
"static",
"function",
"unapprove_plan",
"(",
"$",
"planorid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"plan",
"=",
"$",
"planorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"plan",
")",
")",
"{",
"$",
"plan",
"=",
"new",
"plan",
"(",
"$",
"plan",
")",
";",
"}",
"// We need to be able to view the plan at least.",
"if",
"(",
"!",
"$",
"plan",
"->",
"can_read",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"plan",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:planview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"if",
"(",
"$",
"plan",
"->",
"is_based_on_template",
"(",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Template plans are always approved.'",
")",
";",
"// This should never happen.",
"}",
"else",
"if",
"(",
"$",
"plan",
"->",
"get",
"(",
"'status'",
")",
"!=",
"plan",
"::",
"STATUS_ACTIVE",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The plan cannot be sent back to draft at this stage.'",
")",
";",
"}",
"else",
"if",
"(",
"!",
"$",
"plan",
"->",
"can_review",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"plan",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:planmanage'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"$",
"plan",
"->",
"set",
"(",
"'status'",
",",
"plan",
"::",
"STATUS_DRAFT",
")",
";",
"$",
"result",
"=",
"$",
"plan",
"->",
"update",
"(",
")",
";",
"// Trigger unapproved event.",
"\\",
"core",
"\\",
"event",
"\\",
"competency_plan_unapproved",
"::",
"create_from_plan",
"(",
"$",
"plan",
")",
"->",
"trigger",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
] |
Unapprove a plan.
This means making the plan draft.
@param int|plan $planorid The plan, or its ID.
@return bool
|
[
"Unapprove",
"a",
"plan",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L3018-L3045
|
217,275
|
moodle/moodle
|
competency/classes/api.php
|
api.complete_plan
|
public static function complete_plan($planorid) {
global $DB;
static::require_enabled();
$plan = $planorid;
if (!is_object($planorid)) {
$plan = new plan($planorid);
}
// Validate that the plan can be managed.
if (!$plan->can_manage()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planmanage', 'nopermissions', '');
}
// Check if the plan was already completed.
if ($plan->get('status') == plan::STATUS_COMPLETE) {
throw new coding_exception('The plan is already completed.');
}
$originalstatus = $plan->get('status');
$plan->set('status', plan::STATUS_COMPLETE);
// The user should also be able to manage the plan when it's completed.
if (!$plan->can_manage()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planmanage', 'nopermissions', '');
}
// Put back original status because archive needs it to extract competencies from the right table.
$plan->set('status', $originalstatus);
// Do the things.
$transaction = $DB->start_delegated_transaction();
self::archive_user_competencies_in_plan($plan);
$plan->set('status', plan::STATUS_COMPLETE);
$success = $plan->update();
if (!$success) {
$transaction->rollback(new moodle_exception('The plan could not be updated.'));
return $success;
}
$transaction->allow_commit();
// Trigger updated event.
\core\event\competency_plan_completed::create_from_plan($plan)->trigger();
return $success;
}
|
php
|
public static function complete_plan($planorid) {
global $DB;
static::require_enabled();
$plan = $planorid;
if (!is_object($planorid)) {
$plan = new plan($planorid);
}
// Validate that the plan can be managed.
if (!$plan->can_manage()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planmanage', 'nopermissions', '');
}
// Check if the plan was already completed.
if ($plan->get('status') == plan::STATUS_COMPLETE) {
throw new coding_exception('The plan is already completed.');
}
$originalstatus = $plan->get('status');
$plan->set('status', plan::STATUS_COMPLETE);
// The user should also be able to manage the plan when it's completed.
if (!$plan->can_manage()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planmanage', 'nopermissions', '');
}
// Put back original status because archive needs it to extract competencies from the right table.
$plan->set('status', $originalstatus);
// Do the things.
$transaction = $DB->start_delegated_transaction();
self::archive_user_competencies_in_plan($plan);
$plan->set('status', plan::STATUS_COMPLETE);
$success = $plan->update();
if (!$success) {
$transaction->rollback(new moodle_exception('The plan could not be updated.'));
return $success;
}
$transaction->allow_commit();
// Trigger updated event.
\core\event\competency_plan_completed::create_from_plan($plan)->trigger();
return $success;
}
|
[
"public",
"static",
"function",
"complete_plan",
"(",
"$",
"planorid",
")",
"{",
"global",
"$",
"DB",
";",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"plan",
"=",
"$",
"planorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"planorid",
")",
")",
"{",
"$",
"plan",
"=",
"new",
"plan",
"(",
"$",
"planorid",
")",
";",
"}",
"// Validate that the plan can be managed.",
"if",
"(",
"!",
"$",
"plan",
"->",
"can_manage",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"plan",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:planmanage'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// Check if the plan was already completed.",
"if",
"(",
"$",
"plan",
"->",
"get",
"(",
"'status'",
")",
"==",
"plan",
"::",
"STATUS_COMPLETE",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The plan is already completed.'",
")",
";",
"}",
"$",
"originalstatus",
"=",
"$",
"plan",
"->",
"get",
"(",
"'status'",
")",
";",
"$",
"plan",
"->",
"set",
"(",
"'status'",
",",
"plan",
"::",
"STATUS_COMPLETE",
")",
";",
"// The user should also be able to manage the plan when it's completed.",
"if",
"(",
"!",
"$",
"plan",
"->",
"can_manage",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"plan",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:planmanage'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// Put back original status because archive needs it to extract competencies from the right table.",
"$",
"plan",
"->",
"set",
"(",
"'status'",
",",
"$",
"originalstatus",
")",
";",
"// Do the things.",
"$",
"transaction",
"=",
"$",
"DB",
"->",
"start_delegated_transaction",
"(",
")",
";",
"self",
"::",
"archive_user_competencies_in_plan",
"(",
"$",
"plan",
")",
";",
"$",
"plan",
"->",
"set",
"(",
"'status'",
",",
"plan",
"::",
"STATUS_COMPLETE",
")",
";",
"$",
"success",
"=",
"$",
"plan",
"->",
"update",
"(",
")",
";",
"if",
"(",
"!",
"$",
"success",
")",
"{",
"$",
"transaction",
"->",
"rollback",
"(",
"new",
"moodle_exception",
"(",
"'The plan could not be updated.'",
")",
")",
";",
"return",
"$",
"success",
";",
"}",
"$",
"transaction",
"->",
"allow_commit",
"(",
")",
";",
"// Trigger updated event.",
"\\",
"core",
"\\",
"event",
"\\",
"competency_plan_completed",
"::",
"create_from_plan",
"(",
"$",
"plan",
")",
"->",
"trigger",
"(",
")",
";",
"return",
"$",
"success",
";",
"}"
] |
Complete a plan.
@param int|plan $planorid The plan, or its ID.
@return bool
|
[
"Complete",
"a",
"plan",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L3053-L3100
|
217,276
|
moodle/moodle
|
competency/classes/api.php
|
api.reopen_plan
|
public static function reopen_plan($planorid) {
global $DB;
static::require_enabled();
$plan = $planorid;
if (!is_object($planorid)) {
$plan = new plan($planorid);
}
// Validate that the plan as it is can be managed.
if (!$plan->can_manage()) {
$context = context_user::instance($plan->get('userid'));
throw new required_capability_exception($context, 'moodle/competency:planmanage', 'nopermissions', '');
}
$beforestatus = $plan->get('status');
$plan->set('status', plan::STATUS_ACTIVE);
// Validate if status can be changed.
if (!$plan->can_manage()) {
$context = context_user::instance($plan->get('userid'));
throw new required_capability_exception($context, 'moodle/competency:planmanage', 'nopermissions', '');
}
// Wrap the updates in a DB transaction.
$transaction = $DB->start_delegated_transaction();
// Delete archived user competencies if the status of the plan is changed from complete to another status.
$mustremovearchivedcompetencies = ($beforestatus == plan::STATUS_COMPLETE && $plan->get('status') != plan::STATUS_COMPLETE);
if ($mustremovearchivedcompetencies) {
self::remove_archived_user_competencies_in_plan($plan);
}
// If duedate less than or equal to duedate_threshold unset it.
if ($plan->get('duedate') <= time() + plan::DUEDATE_THRESHOLD) {
$plan->set('duedate', 0);
}
$success = $plan->update();
if (!$success) {
$transaction->rollback(new moodle_exception('The plan could not be updated.'));
return $success;
}
$transaction->allow_commit();
// Trigger reopened event.
\core\event\competency_plan_reopened::create_from_plan($plan)->trigger();
return $success;
}
|
php
|
public static function reopen_plan($planorid) {
global $DB;
static::require_enabled();
$plan = $planorid;
if (!is_object($planorid)) {
$plan = new plan($planorid);
}
// Validate that the plan as it is can be managed.
if (!$plan->can_manage()) {
$context = context_user::instance($plan->get('userid'));
throw new required_capability_exception($context, 'moodle/competency:planmanage', 'nopermissions', '');
}
$beforestatus = $plan->get('status');
$plan->set('status', plan::STATUS_ACTIVE);
// Validate if status can be changed.
if (!$plan->can_manage()) {
$context = context_user::instance($plan->get('userid'));
throw new required_capability_exception($context, 'moodle/competency:planmanage', 'nopermissions', '');
}
// Wrap the updates in a DB transaction.
$transaction = $DB->start_delegated_transaction();
// Delete archived user competencies if the status of the plan is changed from complete to another status.
$mustremovearchivedcompetencies = ($beforestatus == plan::STATUS_COMPLETE && $plan->get('status') != plan::STATUS_COMPLETE);
if ($mustremovearchivedcompetencies) {
self::remove_archived_user_competencies_in_plan($plan);
}
// If duedate less than or equal to duedate_threshold unset it.
if ($plan->get('duedate') <= time() + plan::DUEDATE_THRESHOLD) {
$plan->set('duedate', 0);
}
$success = $plan->update();
if (!$success) {
$transaction->rollback(new moodle_exception('The plan could not be updated.'));
return $success;
}
$transaction->allow_commit();
// Trigger reopened event.
\core\event\competency_plan_reopened::create_from_plan($plan)->trigger();
return $success;
}
|
[
"public",
"static",
"function",
"reopen_plan",
"(",
"$",
"planorid",
")",
"{",
"global",
"$",
"DB",
";",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"plan",
"=",
"$",
"planorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"planorid",
")",
")",
"{",
"$",
"plan",
"=",
"new",
"plan",
"(",
"$",
"planorid",
")",
";",
"}",
"// Validate that the plan as it is can be managed.",
"if",
"(",
"!",
"$",
"plan",
"->",
"can_manage",
"(",
")",
")",
"{",
"$",
"context",
"=",
"context_user",
"::",
"instance",
"(",
"$",
"plan",
"->",
"get",
"(",
"'userid'",
")",
")",
";",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:planmanage'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"$",
"beforestatus",
"=",
"$",
"plan",
"->",
"get",
"(",
"'status'",
")",
";",
"$",
"plan",
"->",
"set",
"(",
"'status'",
",",
"plan",
"::",
"STATUS_ACTIVE",
")",
";",
"// Validate if status can be changed.",
"if",
"(",
"!",
"$",
"plan",
"->",
"can_manage",
"(",
")",
")",
"{",
"$",
"context",
"=",
"context_user",
"::",
"instance",
"(",
"$",
"plan",
"->",
"get",
"(",
"'userid'",
")",
")",
";",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:planmanage'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// Wrap the updates in a DB transaction.",
"$",
"transaction",
"=",
"$",
"DB",
"->",
"start_delegated_transaction",
"(",
")",
";",
"// Delete archived user competencies if the status of the plan is changed from complete to another status.",
"$",
"mustremovearchivedcompetencies",
"=",
"(",
"$",
"beforestatus",
"==",
"plan",
"::",
"STATUS_COMPLETE",
"&&",
"$",
"plan",
"->",
"get",
"(",
"'status'",
")",
"!=",
"plan",
"::",
"STATUS_COMPLETE",
")",
";",
"if",
"(",
"$",
"mustremovearchivedcompetencies",
")",
"{",
"self",
"::",
"remove_archived_user_competencies_in_plan",
"(",
"$",
"plan",
")",
";",
"}",
"// If duedate less than or equal to duedate_threshold unset it.",
"if",
"(",
"$",
"plan",
"->",
"get",
"(",
"'duedate'",
")",
"<=",
"time",
"(",
")",
"+",
"plan",
"::",
"DUEDATE_THRESHOLD",
")",
"{",
"$",
"plan",
"->",
"set",
"(",
"'duedate'",
",",
"0",
")",
";",
"}",
"$",
"success",
"=",
"$",
"plan",
"->",
"update",
"(",
")",
";",
"if",
"(",
"!",
"$",
"success",
")",
"{",
"$",
"transaction",
"->",
"rollback",
"(",
"new",
"moodle_exception",
"(",
"'The plan could not be updated.'",
")",
")",
";",
"return",
"$",
"success",
";",
"}",
"$",
"transaction",
"->",
"allow_commit",
"(",
")",
";",
"// Trigger reopened event.",
"\\",
"core",
"\\",
"event",
"\\",
"competency_plan_reopened",
"::",
"create_from_plan",
"(",
"$",
"plan",
")",
"->",
"trigger",
"(",
")",
";",
"return",
"$",
"success",
";",
"}"
] |
Reopen a plan.
@param int|plan $planorid The plan, or its ID.
@return bool
|
[
"Reopen",
"a",
"plan",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L3108-L3159
|
217,277
|
moodle/moodle
|
competency/classes/api.php
|
api.get_plan_competency
|
public static function get_plan_competency($planorid, $competencyid) {
static::require_enabled();
$plan = $planorid;
if (!is_object($planorid)) {
$plan = new plan($planorid);
}
if (!user_competency::can_read_user($plan->get('userid'))) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:usercompetencyview',
'nopermissions', '');
}
$competency = $plan->get_competency($competencyid);
// Get user competencies from user_competency_plan if the plan status is set to complete.
$iscompletedplan = $plan->get('status') == plan::STATUS_COMPLETE;
if ($iscompletedplan) {
$usercompetencies = user_competency_plan::get_multiple($plan->get('userid'), $plan->get('id'), array($competencyid));
$ucresultkey = 'usercompetencyplan';
} else {
$usercompetencies = user_competency::get_multiple($plan->get('userid'), array($competencyid));
$ucresultkey = 'usercompetency';
}
$found = count($usercompetencies);
if ($found) {
$uc = array_pop($usercompetencies);
} else {
if ($iscompletedplan) {
throw new coding_exception('A user competency plan is missing');
} else {
$uc = user_competency::create_relation($plan->get('userid'), $competency->get('id'));
$uc->create();
}
}
$plancompetency = (object) array(
'competency' => $competency,
'usercompetency' => null,
'usercompetencyplan' => null
);
$plancompetency->$ucresultkey = $uc;
return $plancompetency;
}
|
php
|
public static function get_plan_competency($planorid, $competencyid) {
static::require_enabled();
$plan = $planorid;
if (!is_object($planorid)) {
$plan = new plan($planorid);
}
if (!user_competency::can_read_user($plan->get('userid'))) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:usercompetencyview',
'nopermissions', '');
}
$competency = $plan->get_competency($competencyid);
// Get user competencies from user_competency_plan if the plan status is set to complete.
$iscompletedplan = $plan->get('status') == plan::STATUS_COMPLETE;
if ($iscompletedplan) {
$usercompetencies = user_competency_plan::get_multiple($plan->get('userid'), $plan->get('id'), array($competencyid));
$ucresultkey = 'usercompetencyplan';
} else {
$usercompetencies = user_competency::get_multiple($plan->get('userid'), array($competencyid));
$ucresultkey = 'usercompetency';
}
$found = count($usercompetencies);
if ($found) {
$uc = array_pop($usercompetencies);
} else {
if ($iscompletedplan) {
throw new coding_exception('A user competency plan is missing');
} else {
$uc = user_competency::create_relation($plan->get('userid'), $competency->get('id'));
$uc->create();
}
}
$plancompetency = (object) array(
'competency' => $competency,
'usercompetency' => null,
'usercompetencyplan' => null
);
$plancompetency->$ucresultkey = $uc;
return $plancompetency;
}
|
[
"public",
"static",
"function",
"get_plan_competency",
"(",
"$",
"planorid",
",",
"$",
"competencyid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"plan",
"=",
"$",
"planorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"planorid",
")",
")",
"{",
"$",
"plan",
"=",
"new",
"plan",
"(",
"$",
"planorid",
")",
";",
"}",
"if",
"(",
"!",
"user_competency",
"::",
"can_read_user",
"(",
"$",
"plan",
"->",
"get",
"(",
"'userid'",
")",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"plan",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:usercompetencyview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"$",
"competency",
"=",
"$",
"plan",
"->",
"get_competency",
"(",
"$",
"competencyid",
")",
";",
"// Get user competencies from user_competency_plan if the plan status is set to complete.",
"$",
"iscompletedplan",
"=",
"$",
"plan",
"->",
"get",
"(",
"'status'",
")",
"==",
"plan",
"::",
"STATUS_COMPLETE",
";",
"if",
"(",
"$",
"iscompletedplan",
")",
"{",
"$",
"usercompetencies",
"=",
"user_competency_plan",
"::",
"get_multiple",
"(",
"$",
"plan",
"->",
"get",
"(",
"'userid'",
")",
",",
"$",
"plan",
"->",
"get",
"(",
"'id'",
")",
",",
"array",
"(",
"$",
"competencyid",
")",
")",
";",
"$",
"ucresultkey",
"=",
"'usercompetencyplan'",
";",
"}",
"else",
"{",
"$",
"usercompetencies",
"=",
"user_competency",
"::",
"get_multiple",
"(",
"$",
"plan",
"->",
"get",
"(",
"'userid'",
")",
",",
"array",
"(",
"$",
"competencyid",
")",
")",
";",
"$",
"ucresultkey",
"=",
"'usercompetency'",
";",
"}",
"$",
"found",
"=",
"count",
"(",
"$",
"usercompetencies",
")",
";",
"if",
"(",
"$",
"found",
")",
"{",
"$",
"uc",
"=",
"array_pop",
"(",
"$",
"usercompetencies",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"iscompletedplan",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'A user competency plan is missing'",
")",
";",
"}",
"else",
"{",
"$",
"uc",
"=",
"user_competency",
"::",
"create_relation",
"(",
"$",
"plan",
"->",
"get",
"(",
"'userid'",
")",
",",
"$",
"competency",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"$",
"uc",
"->",
"create",
"(",
")",
";",
"}",
"}",
"$",
"plancompetency",
"=",
"(",
"object",
")",
"array",
"(",
"'competency'",
"=>",
"$",
"competency",
",",
"'usercompetency'",
"=>",
"null",
",",
"'usercompetencyplan'",
"=>",
"null",
")",
";",
"$",
"plancompetency",
"->",
"$",
"ucresultkey",
"=",
"$",
"uc",
";",
"return",
"$",
"plancompetency",
";",
"}"
] |
Get a single competency from the user plan.
@param int $planorid The plan, or its ID.
@param int $competencyid The competency id.
@return (object) array(
'competency' => \core_competency\competency,
'usercompetency' => \core_competency\user_competency
'usercompetencyplan' => \core_competency\user_competency_plan
)
The values of of keys usercompetency and usercompetencyplan cannot be defined at the same time.
|
[
"Get",
"a",
"single",
"competency",
"from",
"the",
"user",
"plan",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L3173-L3218
|
217,278
|
moodle/moodle
|
competency/classes/api.php
|
api.list_plans_with_competency
|
public static function list_plans_with_competency($userid, $competencyorid) {
global $USER;
static::require_enabled();
$competencyid = $competencyorid;
$competency = null;
if (is_object($competencyid)) {
$competency = $competencyid;
$competencyid = $competency->get('id');
}
$plans = plan::get_by_user_and_competency($userid, $competencyid);
foreach ($plans as $index => $plan) {
// Filter plans we cannot read.
if (!$plan->can_read()) {
unset($plans[$index]);
}
}
return $plans;
}
|
php
|
public static function list_plans_with_competency($userid, $competencyorid) {
global $USER;
static::require_enabled();
$competencyid = $competencyorid;
$competency = null;
if (is_object($competencyid)) {
$competency = $competencyid;
$competencyid = $competency->get('id');
}
$plans = plan::get_by_user_and_competency($userid, $competencyid);
foreach ($plans as $index => $plan) {
// Filter plans we cannot read.
if (!$plan->can_read()) {
unset($plans[$index]);
}
}
return $plans;
}
|
[
"public",
"static",
"function",
"list_plans_with_competency",
"(",
"$",
"userid",
",",
"$",
"competencyorid",
")",
"{",
"global",
"$",
"USER",
";",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"competencyid",
"=",
"$",
"competencyorid",
";",
"$",
"competency",
"=",
"null",
";",
"if",
"(",
"is_object",
"(",
"$",
"competencyid",
")",
")",
"{",
"$",
"competency",
"=",
"$",
"competencyid",
";",
"$",
"competencyid",
"=",
"$",
"competency",
"->",
"get",
"(",
"'id'",
")",
";",
"}",
"$",
"plans",
"=",
"plan",
"::",
"get_by_user_and_competency",
"(",
"$",
"userid",
",",
"$",
"competencyid",
")",
";",
"foreach",
"(",
"$",
"plans",
"as",
"$",
"index",
"=>",
"$",
"plan",
")",
"{",
"// Filter plans we cannot read.",
"if",
"(",
"!",
"$",
"plan",
"->",
"can_read",
"(",
")",
")",
"{",
"unset",
"(",
"$",
"plans",
"[",
"$",
"index",
"]",
")",
";",
"}",
"}",
"return",
"$",
"plans",
";",
"}"
] |
List the plans with a competency.
@param int $userid The user id we want the plans for.
@param int $competencyorid The competency, or its ID.
@return array[plan] Array of learning plans.
|
[
"List",
"the",
"plans",
"with",
"a",
"competency",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L3227-L3246
|
217,279
|
moodle/moodle
|
competency/classes/api.php
|
api.list_plan_competencies
|
public static function list_plan_competencies($planorid) {
static::require_enabled();
$plan = $planorid;
if (!is_object($planorid)) {
$plan = new plan($planorid);
}
if (!$plan->can_read()) {
$context = context_user::instance($plan->get('userid'));
throw new required_capability_exception($context, 'moodle/competency:planview', 'nopermissions', '');
}
$result = array();
$competencies = $plan->get_competencies();
// Get user competencies from user_competency_plan if the plan status is set to complete.
$iscompletedplan = $plan->get('status') == plan::STATUS_COMPLETE;
if ($iscompletedplan) {
$usercompetencies = user_competency_plan::get_multiple($plan->get('userid'), $plan->get('id'), $competencies);
$ucresultkey = 'usercompetencyplan';
} else {
$usercompetencies = user_competency::get_multiple($plan->get('userid'), $competencies);
$ucresultkey = 'usercompetency';
}
// Build the return values.
foreach ($competencies as $key => $competency) {
$found = false;
foreach ($usercompetencies as $uckey => $uc) {
if ($uc->get('competencyid') == $competency->get('id')) {
$found = true;
unset($usercompetencies[$uckey]);
break;
}
}
if (!$found) {
if ($iscompletedplan) {
throw new coding_exception('A user competency plan is missing');
} else {
$uc = user_competency::create_relation($plan->get('userid'), $competency->get('id'));
}
}
$plancompetency = (object) array(
'competency' => $competency,
'usercompetency' => null,
'usercompetencyplan' => null
);
$plancompetency->$ucresultkey = $uc;
$result[] = $plancompetency;
}
return $result;
}
|
php
|
public static function list_plan_competencies($planorid) {
static::require_enabled();
$plan = $planorid;
if (!is_object($planorid)) {
$plan = new plan($planorid);
}
if (!$plan->can_read()) {
$context = context_user::instance($plan->get('userid'));
throw new required_capability_exception($context, 'moodle/competency:planview', 'nopermissions', '');
}
$result = array();
$competencies = $plan->get_competencies();
// Get user competencies from user_competency_plan if the plan status is set to complete.
$iscompletedplan = $plan->get('status') == plan::STATUS_COMPLETE;
if ($iscompletedplan) {
$usercompetencies = user_competency_plan::get_multiple($plan->get('userid'), $plan->get('id'), $competencies);
$ucresultkey = 'usercompetencyplan';
} else {
$usercompetencies = user_competency::get_multiple($plan->get('userid'), $competencies);
$ucresultkey = 'usercompetency';
}
// Build the return values.
foreach ($competencies as $key => $competency) {
$found = false;
foreach ($usercompetencies as $uckey => $uc) {
if ($uc->get('competencyid') == $competency->get('id')) {
$found = true;
unset($usercompetencies[$uckey]);
break;
}
}
if (!$found) {
if ($iscompletedplan) {
throw new coding_exception('A user competency plan is missing');
} else {
$uc = user_competency::create_relation($plan->get('userid'), $competency->get('id'));
}
}
$plancompetency = (object) array(
'competency' => $competency,
'usercompetency' => null,
'usercompetencyplan' => null
);
$plancompetency->$ucresultkey = $uc;
$result[] = $plancompetency;
}
return $result;
}
|
[
"public",
"static",
"function",
"list_plan_competencies",
"(",
"$",
"planorid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"plan",
"=",
"$",
"planorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"planorid",
")",
")",
"{",
"$",
"plan",
"=",
"new",
"plan",
"(",
"$",
"planorid",
")",
";",
"}",
"if",
"(",
"!",
"$",
"plan",
"->",
"can_read",
"(",
")",
")",
"{",
"$",
"context",
"=",
"context_user",
"::",
"instance",
"(",
"$",
"plan",
"->",
"get",
"(",
"'userid'",
")",
")",
";",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:planview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"competencies",
"=",
"$",
"plan",
"->",
"get_competencies",
"(",
")",
";",
"// Get user competencies from user_competency_plan if the plan status is set to complete.",
"$",
"iscompletedplan",
"=",
"$",
"plan",
"->",
"get",
"(",
"'status'",
")",
"==",
"plan",
"::",
"STATUS_COMPLETE",
";",
"if",
"(",
"$",
"iscompletedplan",
")",
"{",
"$",
"usercompetencies",
"=",
"user_competency_plan",
"::",
"get_multiple",
"(",
"$",
"plan",
"->",
"get",
"(",
"'userid'",
")",
",",
"$",
"plan",
"->",
"get",
"(",
"'id'",
")",
",",
"$",
"competencies",
")",
";",
"$",
"ucresultkey",
"=",
"'usercompetencyplan'",
";",
"}",
"else",
"{",
"$",
"usercompetencies",
"=",
"user_competency",
"::",
"get_multiple",
"(",
"$",
"plan",
"->",
"get",
"(",
"'userid'",
")",
",",
"$",
"competencies",
")",
";",
"$",
"ucresultkey",
"=",
"'usercompetency'",
";",
"}",
"// Build the return values.",
"foreach",
"(",
"$",
"competencies",
"as",
"$",
"key",
"=>",
"$",
"competency",
")",
"{",
"$",
"found",
"=",
"false",
";",
"foreach",
"(",
"$",
"usercompetencies",
"as",
"$",
"uckey",
"=>",
"$",
"uc",
")",
"{",
"if",
"(",
"$",
"uc",
"->",
"get",
"(",
"'competencyid'",
")",
"==",
"$",
"competency",
"->",
"get",
"(",
"'id'",
")",
")",
"{",
"$",
"found",
"=",
"true",
";",
"unset",
"(",
"$",
"usercompetencies",
"[",
"$",
"uckey",
"]",
")",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"found",
")",
"{",
"if",
"(",
"$",
"iscompletedplan",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'A user competency plan is missing'",
")",
";",
"}",
"else",
"{",
"$",
"uc",
"=",
"user_competency",
"::",
"create_relation",
"(",
"$",
"plan",
"->",
"get",
"(",
"'userid'",
")",
",",
"$",
"competency",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"}",
"}",
"$",
"plancompetency",
"=",
"(",
"object",
")",
"array",
"(",
"'competency'",
"=>",
"$",
"competency",
",",
"'usercompetency'",
"=>",
"null",
",",
"'usercompetencyplan'",
"=>",
"null",
")",
";",
"$",
"plancompetency",
"->",
"$",
"ucresultkey",
"=",
"$",
"uc",
";",
"$",
"result",
"[",
"]",
"=",
"$",
"plancompetency",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
List the competencies in a user plan.
@param int $planorid The plan, or its ID.
@return array((object) array(
'competency' => \core_competency\competency,
'usercompetency' => \core_competency\user_competency
'usercompetencyplan' => \core_competency\user_competency_plan
))
The values of of keys usercompetency and usercompetencyplan cannot be defined at the same time.
|
[
"List",
"the",
"competencies",
"in",
"a",
"user",
"plan",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L3259-L3314
|
217,280
|
moodle/moodle
|
competency/classes/api.php
|
api.add_competency_to_plan
|
public static function add_competency_to_plan($planid, $competencyid) {
static::require_enabled();
$plan = new plan($planid);
// First we do a permissions check.
if (!$plan->can_manage()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planmanage', 'nopermissions', '');
} else if ($plan->is_based_on_template()) {
throw new coding_exception('A competency can not be added to a learning plan based on a template');
}
if (!$plan->can_be_edited()) {
throw new coding_exception('A competency can not be added to a learning plan completed');
}
$competency = new competency($competencyid);
// Can not add a competency that belong to a hidden framework.
if ($competency->get_framework()->get('visible') == false) {
throw new coding_exception('A competency belonging to hidden framework can not be added');
}
$exists = plan_competency::get_record(array('planid' => $planid, 'competencyid' => $competencyid));
if (!$exists) {
$record = new stdClass();
$record->planid = $planid;
$record->competencyid = $competencyid;
$plancompetency = new plan_competency(0, $record);
$plancompetency->create();
}
return true;
}
|
php
|
public static function add_competency_to_plan($planid, $competencyid) {
static::require_enabled();
$plan = new plan($planid);
// First we do a permissions check.
if (!$plan->can_manage()) {
throw new required_capability_exception($plan->get_context(), 'moodle/competency:planmanage', 'nopermissions', '');
} else if ($plan->is_based_on_template()) {
throw new coding_exception('A competency can not be added to a learning plan based on a template');
}
if (!$plan->can_be_edited()) {
throw new coding_exception('A competency can not be added to a learning plan completed');
}
$competency = new competency($competencyid);
// Can not add a competency that belong to a hidden framework.
if ($competency->get_framework()->get('visible') == false) {
throw new coding_exception('A competency belonging to hidden framework can not be added');
}
$exists = plan_competency::get_record(array('planid' => $planid, 'competencyid' => $competencyid));
if (!$exists) {
$record = new stdClass();
$record->planid = $planid;
$record->competencyid = $competencyid;
$plancompetency = new plan_competency(0, $record);
$plancompetency->create();
}
return true;
}
|
[
"public",
"static",
"function",
"add_competency_to_plan",
"(",
"$",
"planid",
",",
"$",
"competencyid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"plan",
"=",
"new",
"plan",
"(",
"$",
"planid",
")",
";",
"// First we do a permissions check.",
"if",
"(",
"!",
"$",
"plan",
"->",
"can_manage",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"plan",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:planmanage'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"else",
"if",
"(",
"$",
"plan",
"->",
"is_based_on_template",
"(",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'A competency can not be added to a learning plan based on a template'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"plan",
"->",
"can_be_edited",
"(",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'A competency can not be added to a learning plan completed'",
")",
";",
"}",
"$",
"competency",
"=",
"new",
"competency",
"(",
"$",
"competencyid",
")",
";",
"// Can not add a competency that belong to a hidden framework.",
"if",
"(",
"$",
"competency",
"->",
"get_framework",
"(",
")",
"->",
"get",
"(",
"'visible'",
")",
"==",
"false",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'A competency belonging to hidden framework can not be added'",
")",
";",
"}",
"$",
"exists",
"=",
"plan_competency",
"::",
"get_record",
"(",
"array",
"(",
"'planid'",
"=>",
"$",
"planid",
",",
"'competencyid'",
"=>",
"$",
"competencyid",
")",
")",
";",
"if",
"(",
"!",
"$",
"exists",
")",
"{",
"$",
"record",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"record",
"->",
"planid",
"=",
"$",
"planid",
";",
"$",
"record",
"->",
"competencyid",
"=",
"$",
"competencyid",
";",
"$",
"plancompetency",
"=",
"new",
"plan_competency",
"(",
"0",
",",
"$",
"record",
")",
";",
"$",
"plancompetency",
"->",
"create",
"(",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Add a competency to a plan.
@param int $planid The id of the plan
@param int $competencyid The id of the competency
@return bool
|
[
"Add",
"a",
"competency",
"to",
"a",
"plan",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L3323-L3356
|
217,281
|
moodle/moodle
|
competency/classes/api.php
|
api.remove_competency_from_plan
|
public static function remove_competency_from_plan($planid, $competencyid) {
static::require_enabled();
$plan = new plan($planid);
// First we do a permissions check.
if (!$plan->can_manage()) {
$context = context_user::instance($plan->get('userid'));
throw new required_capability_exception($context, 'moodle/competency:planmanage', 'nopermissions', '');
} else if ($plan->is_based_on_template()) {
throw new coding_exception('A competency can not be removed from a learning plan based on a template');
}
if (!$plan->can_be_edited()) {
throw new coding_exception('A competency can not be removed from a learning plan completed');
}
$link = plan_competency::get_record(array('planid' => $planid, 'competencyid' => $competencyid));
if ($link) {
return $link->delete();
}
return false;
}
|
php
|
public static function remove_competency_from_plan($planid, $competencyid) {
static::require_enabled();
$plan = new plan($planid);
// First we do a permissions check.
if (!$plan->can_manage()) {
$context = context_user::instance($plan->get('userid'));
throw new required_capability_exception($context, 'moodle/competency:planmanage', 'nopermissions', '');
} else if ($plan->is_based_on_template()) {
throw new coding_exception('A competency can not be removed from a learning plan based on a template');
}
if (!$plan->can_be_edited()) {
throw new coding_exception('A competency can not be removed from a learning plan completed');
}
$link = plan_competency::get_record(array('planid' => $planid, 'competencyid' => $competencyid));
if ($link) {
return $link->delete();
}
return false;
}
|
[
"public",
"static",
"function",
"remove_competency_from_plan",
"(",
"$",
"planid",
",",
"$",
"competencyid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"plan",
"=",
"new",
"plan",
"(",
"$",
"planid",
")",
";",
"// First we do a permissions check.",
"if",
"(",
"!",
"$",
"plan",
"->",
"can_manage",
"(",
")",
")",
"{",
"$",
"context",
"=",
"context_user",
"::",
"instance",
"(",
"$",
"plan",
"->",
"get",
"(",
"'userid'",
")",
")",
";",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:planmanage'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"else",
"if",
"(",
"$",
"plan",
"->",
"is_based_on_template",
"(",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'A competency can not be removed from a learning plan based on a template'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"plan",
"->",
"can_be_edited",
"(",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'A competency can not be removed from a learning plan completed'",
")",
";",
"}",
"$",
"link",
"=",
"plan_competency",
"::",
"get_record",
"(",
"array",
"(",
"'planid'",
"=>",
"$",
"planid",
",",
"'competencyid'",
"=>",
"$",
"competencyid",
")",
")",
";",
"if",
"(",
"$",
"link",
")",
"{",
"return",
"$",
"link",
"->",
"delete",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Remove a competency from a plan.
@param int $planid The plan id
@param int $competencyid The id of the competency
@return bool
|
[
"Remove",
"a",
"competency",
"from",
"a",
"plan",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L3365-L3387
|
217,282
|
moodle/moodle
|
competency/classes/api.php
|
api.reorder_plan_competency
|
public static function reorder_plan_competency($planid, $competencyidfrom, $competencyidto) {
static::require_enabled();
$plan = new plan($planid);
// First we do a permissions check.
if (!$plan->can_manage()) {
$context = context_user::instance($plan->get('userid'));
throw new required_capability_exception($context, 'moodle/competency:planmanage', 'nopermissions', '');
} else if ($plan->is_based_on_template()) {
throw new coding_exception('A competency can not be reordered in a learning plan based on a template');
}
if (!$plan->can_be_edited()) {
throw new coding_exception('A competency can not be reordered in a learning plan completed');
}
$down = true;
$matches = plan_competency::get_records(array('planid' => $planid, 'competencyid' => $competencyidfrom));
if (count($matches) == 0) {
throw new coding_exception('The link does not exist');
}
$competencyfrom = array_pop($matches);
$matches = plan_competency::get_records(array('planid' => $planid, 'competencyid' => $competencyidto));
if (count($matches) == 0) {
throw new coding_exception('The link does not exist');
}
$competencyto = array_pop($matches);
$all = plan_competency::get_records(array('planid' => $planid), 'sortorder', 'ASC', 0, 0);
if ($competencyfrom->get('sortorder') > $competencyto->get('sortorder')) {
// We are moving up, so put it before the "to" item.
$down = false;
}
foreach ($all as $id => $plancompetency) {
$sort = $plancompetency->get('sortorder');
if ($down && $sort > $competencyfrom->get('sortorder') && $sort <= $competencyto->get('sortorder')) {
$plancompetency->set('sortorder', $plancompetency->get('sortorder') - 1);
$plancompetency->update();
} else if (!$down && $sort >= $competencyto->get('sortorder') && $sort < $competencyfrom->get('sortorder')) {
$plancompetency->set('sortorder', $plancompetency->get('sortorder') + 1);
$plancompetency->update();
}
}
$competencyfrom->set('sortorder', $competencyto->get('sortorder'));
return $competencyfrom->update();
}
|
php
|
public static function reorder_plan_competency($planid, $competencyidfrom, $competencyidto) {
static::require_enabled();
$plan = new plan($planid);
// First we do a permissions check.
if (!$plan->can_manage()) {
$context = context_user::instance($plan->get('userid'));
throw new required_capability_exception($context, 'moodle/competency:planmanage', 'nopermissions', '');
} else if ($plan->is_based_on_template()) {
throw new coding_exception('A competency can not be reordered in a learning plan based on a template');
}
if (!$plan->can_be_edited()) {
throw new coding_exception('A competency can not be reordered in a learning plan completed');
}
$down = true;
$matches = plan_competency::get_records(array('planid' => $planid, 'competencyid' => $competencyidfrom));
if (count($matches) == 0) {
throw new coding_exception('The link does not exist');
}
$competencyfrom = array_pop($matches);
$matches = plan_competency::get_records(array('planid' => $planid, 'competencyid' => $competencyidto));
if (count($matches) == 0) {
throw new coding_exception('The link does not exist');
}
$competencyto = array_pop($matches);
$all = plan_competency::get_records(array('planid' => $planid), 'sortorder', 'ASC', 0, 0);
if ($competencyfrom->get('sortorder') > $competencyto->get('sortorder')) {
// We are moving up, so put it before the "to" item.
$down = false;
}
foreach ($all as $id => $plancompetency) {
$sort = $plancompetency->get('sortorder');
if ($down && $sort > $competencyfrom->get('sortorder') && $sort <= $competencyto->get('sortorder')) {
$plancompetency->set('sortorder', $plancompetency->get('sortorder') - 1);
$plancompetency->update();
} else if (!$down && $sort >= $competencyto->get('sortorder') && $sort < $competencyfrom->get('sortorder')) {
$plancompetency->set('sortorder', $plancompetency->get('sortorder') + 1);
$plancompetency->update();
}
}
$competencyfrom->set('sortorder', $competencyto->get('sortorder'));
return $competencyfrom->update();
}
|
[
"public",
"static",
"function",
"reorder_plan_competency",
"(",
"$",
"planid",
",",
"$",
"competencyidfrom",
",",
"$",
"competencyidto",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"plan",
"=",
"new",
"plan",
"(",
"$",
"planid",
")",
";",
"// First we do a permissions check.",
"if",
"(",
"!",
"$",
"plan",
"->",
"can_manage",
"(",
")",
")",
"{",
"$",
"context",
"=",
"context_user",
"::",
"instance",
"(",
"$",
"plan",
"->",
"get",
"(",
"'userid'",
")",
")",
";",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:planmanage'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"else",
"if",
"(",
"$",
"plan",
"->",
"is_based_on_template",
"(",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'A competency can not be reordered in a learning plan based on a template'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"plan",
"->",
"can_be_edited",
"(",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'A competency can not be reordered in a learning plan completed'",
")",
";",
"}",
"$",
"down",
"=",
"true",
";",
"$",
"matches",
"=",
"plan_competency",
"::",
"get_records",
"(",
"array",
"(",
"'planid'",
"=>",
"$",
"planid",
",",
"'competencyid'",
"=>",
"$",
"competencyidfrom",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"matches",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The link does not exist'",
")",
";",
"}",
"$",
"competencyfrom",
"=",
"array_pop",
"(",
"$",
"matches",
")",
";",
"$",
"matches",
"=",
"plan_competency",
"::",
"get_records",
"(",
"array",
"(",
"'planid'",
"=>",
"$",
"planid",
",",
"'competencyid'",
"=>",
"$",
"competencyidto",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"matches",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The link does not exist'",
")",
";",
"}",
"$",
"competencyto",
"=",
"array_pop",
"(",
"$",
"matches",
")",
";",
"$",
"all",
"=",
"plan_competency",
"::",
"get_records",
"(",
"array",
"(",
"'planid'",
"=>",
"$",
"planid",
")",
",",
"'sortorder'",
",",
"'ASC'",
",",
"0",
",",
"0",
")",
";",
"if",
"(",
"$",
"competencyfrom",
"->",
"get",
"(",
"'sortorder'",
")",
">",
"$",
"competencyto",
"->",
"get",
"(",
"'sortorder'",
")",
")",
"{",
"// We are moving up, so put it before the \"to\" item.",
"$",
"down",
"=",
"false",
";",
"}",
"foreach",
"(",
"$",
"all",
"as",
"$",
"id",
"=>",
"$",
"plancompetency",
")",
"{",
"$",
"sort",
"=",
"$",
"plancompetency",
"->",
"get",
"(",
"'sortorder'",
")",
";",
"if",
"(",
"$",
"down",
"&&",
"$",
"sort",
">",
"$",
"competencyfrom",
"->",
"get",
"(",
"'sortorder'",
")",
"&&",
"$",
"sort",
"<=",
"$",
"competencyto",
"->",
"get",
"(",
"'sortorder'",
")",
")",
"{",
"$",
"plancompetency",
"->",
"set",
"(",
"'sortorder'",
",",
"$",
"plancompetency",
"->",
"get",
"(",
"'sortorder'",
")",
"-",
"1",
")",
";",
"$",
"plancompetency",
"->",
"update",
"(",
")",
";",
"}",
"else",
"if",
"(",
"!",
"$",
"down",
"&&",
"$",
"sort",
">=",
"$",
"competencyto",
"->",
"get",
"(",
"'sortorder'",
")",
"&&",
"$",
"sort",
"<",
"$",
"competencyfrom",
"->",
"get",
"(",
"'sortorder'",
")",
")",
"{",
"$",
"plancompetency",
"->",
"set",
"(",
"'sortorder'",
",",
"$",
"plancompetency",
"->",
"get",
"(",
"'sortorder'",
")",
"+",
"1",
")",
";",
"$",
"plancompetency",
"->",
"update",
"(",
")",
";",
"}",
"}",
"$",
"competencyfrom",
"->",
"set",
"(",
"'sortorder'",
",",
"$",
"competencyto",
"->",
"get",
"(",
"'sortorder'",
")",
")",
";",
"return",
"$",
"competencyfrom",
"->",
"update",
"(",
")",
";",
"}"
] |
Move the plan competency up or down in the display list.
Requires moodle/competency:planmanage capability at the system context.
@param int $planid The plan id
@param int $competencyidfrom The id of the competency we are moving.
@param int $competencyidto The id of the competency we are moving to.
@return boolean
|
[
"Move",
"the",
"plan",
"competency",
"up",
"or",
"down",
"in",
"the",
"display",
"list",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L3399-L3449
|
217,283
|
moodle/moodle
|
competency/classes/api.php
|
api.user_competency_cancel_review_request
|
public static function user_competency_cancel_review_request($userid, $competencyid) {
static::require_enabled();
$context = context_user::instance($userid);
$uc = user_competency::get_record(array('userid' => $userid, 'competencyid' => $competencyid));
if (!$uc || !$uc->can_read()) {
throw new required_capability_exception($context, 'moodle/competency:usercompetencyview', 'nopermissions', '');
} else if ($uc->get('status') != user_competency::STATUS_WAITING_FOR_REVIEW) {
throw new coding_exception('The competency can not be cancel review request at this stage.');
} else if (!$uc->can_request_review()) {
throw new required_capability_exception($context, 'moodle/competency:usercompetencyrequestreview', 'nopermissions', '');
}
$uc->set('status', user_competency::STATUS_IDLE);
$result = $uc->update();
if ($result) {
\core\event\competency_user_competency_review_request_cancelled::create_from_user_competency($uc)->trigger();
}
return $result;
}
|
php
|
public static function user_competency_cancel_review_request($userid, $competencyid) {
static::require_enabled();
$context = context_user::instance($userid);
$uc = user_competency::get_record(array('userid' => $userid, 'competencyid' => $competencyid));
if (!$uc || !$uc->can_read()) {
throw new required_capability_exception($context, 'moodle/competency:usercompetencyview', 'nopermissions', '');
} else if ($uc->get('status') != user_competency::STATUS_WAITING_FOR_REVIEW) {
throw new coding_exception('The competency can not be cancel review request at this stage.');
} else if (!$uc->can_request_review()) {
throw new required_capability_exception($context, 'moodle/competency:usercompetencyrequestreview', 'nopermissions', '');
}
$uc->set('status', user_competency::STATUS_IDLE);
$result = $uc->update();
if ($result) {
\core\event\competency_user_competency_review_request_cancelled::create_from_user_competency($uc)->trigger();
}
return $result;
}
|
[
"public",
"static",
"function",
"user_competency_cancel_review_request",
"(",
"$",
"userid",
",",
"$",
"competencyid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"context",
"=",
"context_user",
"::",
"instance",
"(",
"$",
"userid",
")",
";",
"$",
"uc",
"=",
"user_competency",
"::",
"get_record",
"(",
"array",
"(",
"'userid'",
"=>",
"$",
"userid",
",",
"'competencyid'",
"=>",
"$",
"competencyid",
")",
")",
";",
"if",
"(",
"!",
"$",
"uc",
"||",
"!",
"$",
"uc",
"->",
"can_read",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:usercompetencyview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"else",
"if",
"(",
"$",
"uc",
"->",
"get",
"(",
"'status'",
")",
"!=",
"user_competency",
"::",
"STATUS_WAITING_FOR_REVIEW",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The competency can not be cancel review request at this stage.'",
")",
";",
"}",
"else",
"if",
"(",
"!",
"$",
"uc",
"->",
"can_request_review",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:usercompetencyrequestreview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"$",
"uc",
"->",
"set",
"(",
"'status'",
",",
"user_competency",
"::",
"STATUS_IDLE",
")",
";",
"$",
"result",
"=",
"$",
"uc",
"->",
"update",
"(",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"\\",
"core",
"\\",
"event",
"\\",
"competency_user_competency_review_request_cancelled",
"::",
"create_from_user_competency",
"(",
"$",
"uc",
")",
"->",
"trigger",
"(",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Cancel a user competency review request.
@param int $userid The user ID.
@param int $competencyid The competency ID.
@return bool
|
[
"Cancel",
"a",
"user",
"competency",
"review",
"request",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L3458-L3476
|
217,284
|
moodle/moodle
|
competency/classes/api.php
|
api.user_competency_request_review
|
public static function user_competency_request_review($userid, $competencyid) {
static::require_enabled();
$uc = user_competency::get_record(array('userid' => $userid, 'competencyid' => $competencyid));
if (!$uc) {
$uc = user_competency::create_relation($userid, $competencyid);
$uc->create();
}
if (!$uc->can_read()) {
throw new required_capability_exception($uc->get_context(), 'moodle/competency:usercompetencyview',
'nopermissions', '');
} else if ($uc->get('status') != user_competency::STATUS_IDLE) {
throw new coding_exception('The competency can not be sent for review at this stage.');
} else if (!$uc->can_request_review()) {
throw new required_capability_exception($uc->get_context(), 'moodle/competency:usercompetencyrequestreview',
'nopermissions', '');
}
$uc->set('status', user_competency::STATUS_WAITING_FOR_REVIEW);
$result = $uc->update();
if ($result) {
\core\event\competency_user_competency_review_requested::create_from_user_competency($uc)->trigger();
}
return $result;
}
|
php
|
public static function user_competency_request_review($userid, $competencyid) {
static::require_enabled();
$uc = user_competency::get_record(array('userid' => $userid, 'competencyid' => $competencyid));
if (!$uc) {
$uc = user_competency::create_relation($userid, $competencyid);
$uc->create();
}
if (!$uc->can_read()) {
throw new required_capability_exception($uc->get_context(), 'moodle/competency:usercompetencyview',
'nopermissions', '');
} else if ($uc->get('status') != user_competency::STATUS_IDLE) {
throw new coding_exception('The competency can not be sent for review at this stage.');
} else if (!$uc->can_request_review()) {
throw new required_capability_exception($uc->get_context(), 'moodle/competency:usercompetencyrequestreview',
'nopermissions', '');
}
$uc->set('status', user_competency::STATUS_WAITING_FOR_REVIEW);
$result = $uc->update();
if ($result) {
\core\event\competency_user_competency_review_requested::create_from_user_competency($uc)->trigger();
}
return $result;
}
|
[
"public",
"static",
"function",
"user_competency_request_review",
"(",
"$",
"userid",
",",
"$",
"competencyid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"uc",
"=",
"user_competency",
"::",
"get_record",
"(",
"array",
"(",
"'userid'",
"=>",
"$",
"userid",
",",
"'competencyid'",
"=>",
"$",
"competencyid",
")",
")",
";",
"if",
"(",
"!",
"$",
"uc",
")",
"{",
"$",
"uc",
"=",
"user_competency",
"::",
"create_relation",
"(",
"$",
"userid",
",",
"$",
"competencyid",
")",
";",
"$",
"uc",
"->",
"create",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"uc",
"->",
"can_read",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"uc",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:usercompetencyview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"else",
"if",
"(",
"$",
"uc",
"->",
"get",
"(",
"'status'",
")",
"!=",
"user_competency",
"::",
"STATUS_IDLE",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The competency can not be sent for review at this stage.'",
")",
";",
"}",
"else",
"if",
"(",
"!",
"$",
"uc",
"->",
"can_request_review",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"uc",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:usercompetencyrequestreview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"$",
"uc",
"->",
"set",
"(",
"'status'",
",",
"user_competency",
"::",
"STATUS_WAITING_FOR_REVIEW",
")",
";",
"$",
"result",
"=",
"$",
"uc",
"->",
"update",
"(",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"\\",
"core",
"\\",
"event",
"\\",
"competency_user_competency_review_requested",
"::",
"create_from_user_competency",
"(",
"$",
"uc",
")",
"->",
"trigger",
"(",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Request a user competency review.
@param int $userid The user ID.
@param int $competencyid The competency ID.
@return bool
|
[
"Request",
"a",
"user",
"competency",
"review",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L3485-L3509
|
217,285
|
moodle/moodle
|
competency/classes/api.php
|
api.user_competency_start_review
|
public static function user_competency_start_review($userid, $competencyid) {
global $USER;
static::require_enabled();
$context = context_user::instance($userid);
$uc = user_competency::get_record(array('userid' => $userid, 'competencyid' => $competencyid));
if (!$uc || !$uc->can_read()) {
throw new required_capability_exception($context, 'moodle/competency:usercompetencyview', 'nopermissions', '');
} else if ($uc->get('status') != user_competency::STATUS_WAITING_FOR_REVIEW) {
throw new coding_exception('The competency review can not be started at this stage.');
} else if (!$uc->can_review()) {
throw new required_capability_exception($context, 'moodle/competency:usercompetencyreview', 'nopermissions', '');
}
$uc->set('status', user_competency::STATUS_IN_REVIEW);
$uc->set('reviewerid', $USER->id);
$result = $uc->update();
if ($result) {
\core\event\competency_user_competency_review_started::create_from_user_competency($uc)->trigger();
}
return $result;
}
|
php
|
public static function user_competency_start_review($userid, $competencyid) {
global $USER;
static::require_enabled();
$context = context_user::instance($userid);
$uc = user_competency::get_record(array('userid' => $userid, 'competencyid' => $competencyid));
if (!$uc || !$uc->can_read()) {
throw new required_capability_exception($context, 'moodle/competency:usercompetencyview', 'nopermissions', '');
} else if ($uc->get('status') != user_competency::STATUS_WAITING_FOR_REVIEW) {
throw new coding_exception('The competency review can not be started at this stage.');
} else if (!$uc->can_review()) {
throw new required_capability_exception($context, 'moodle/competency:usercompetencyreview', 'nopermissions', '');
}
$uc->set('status', user_competency::STATUS_IN_REVIEW);
$uc->set('reviewerid', $USER->id);
$result = $uc->update();
if ($result) {
\core\event\competency_user_competency_review_started::create_from_user_competency($uc)->trigger();
}
return $result;
}
|
[
"public",
"static",
"function",
"user_competency_start_review",
"(",
"$",
"userid",
",",
"$",
"competencyid",
")",
"{",
"global",
"$",
"USER",
";",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"context",
"=",
"context_user",
"::",
"instance",
"(",
"$",
"userid",
")",
";",
"$",
"uc",
"=",
"user_competency",
"::",
"get_record",
"(",
"array",
"(",
"'userid'",
"=>",
"$",
"userid",
",",
"'competencyid'",
"=>",
"$",
"competencyid",
")",
")",
";",
"if",
"(",
"!",
"$",
"uc",
"||",
"!",
"$",
"uc",
"->",
"can_read",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:usercompetencyview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"else",
"if",
"(",
"$",
"uc",
"->",
"get",
"(",
"'status'",
")",
"!=",
"user_competency",
"::",
"STATUS_WAITING_FOR_REVIEW",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The competency review can not be started at this stage.'",
")",
";",
"}",
"else",
"if",
"(",
"!",
"$",
"uc",
"->",
"can_review",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:usercompetencyreview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"$",
"uc",
"->",
"set",
"(",
"'status'",
",",
"user_competency",
"::",
"STATUS_IN_REVIEW",
")",
";",
"$",
"uc",
"->",
"set",
"(",
"'reviewerid'",
",",
"$",
"USER",
"->",
"id",
")",
";",
"$",
"result",
"=",
"$",
"uc",
"->",
"update",
"(",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"\\",
"core",
"\\",
"event",
"\\",
"competency_user_competency_review_started",
"::",
"create_from_user_competency",
"(",
"$",
"uc",
")",
"->",
"trigger",
"(",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Start a user competency review.
@param int $userid The user ID.
@param int $competencyid The competency ID.
@return bool
|
[
"Start",
"a",
"user",
"competency",
"review",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L3518-L3539
|
217,286
|
moodle/moodle
|
competency/classes/api.php
|
api.user_competency_stop_review
|
public static function user_competency_stop_review($userid, $competencyid) {
static::require_enabled();
$context = context_user::instance($userid);
$uc = user_competency::get_record(array('userid' => $userid, 'competencyid' => $competencyid));
if (!$uc || !$uc->can_read()) {
throw new required_capability_exception($context, 'moodle/competency:usercompetencyview', 'nopermissions', '');
} else if ($uc->get('status') != user_competency::STATUS_IN_REVIEW) {
throw new coding_exception('The competency review can not be stopped at this stage.');
} else if (!$uc->can_review()) {
throw new required_capability_exception($context, 'moodle/competency:usercompetencyreview', 'nopermissions', '');
}
$uc->set('status', user_competency::STATUS_IDLE);
$result = $uc->update();
if ($result) {
\core\event\competency_user_competency_review_stopped::create_from_user_competency($uc)->trigger();
}
return $result;
}
|
php
|
public static function user_competency_stop_review($userid, $competencyid) {
static::require_enabled();
$context = context_user::instance($userid);
$uc = user_competency::get_record(array('userid' => $userid, 'competencyid' => $competencyid));
if (!$uc || !$uc->can_read()) {
throw new required_capability_exception($context, 'moodle/competency:usercompetencyview', 'nopermissions', '');
} else if ($uc->get('status') != user_competency::STATUS_IN_REVIEW) {
throw new coding_exception('The competency review can not be stopped at this stage.');
} else if (!$uc->can_review()) {
throw new required_capability_exception($context, 'moodle/competency:usercompetencyreview', 'nopermissions', '');
}
$uc->set('status', user_competency::STATUS_IDLE);
$result = $uc->update();
if ($result) {
\core\event\competency_user_competency_review_stopped::create_from_user_competency($uc)->trigger();
}
return $result;
}
|
[
"public",
"static",
"function",
"user_competency_stop_review",
"(",
"$",
"userid",
",",
"$",
"competencyid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"context",
"=",
"context_user",
"::",
"instance",
"(",
"$",
"userid",
")",
";",
"$",
"uc",
"=",
"user_competency",
"::",
"get_record",
"(",
"array",
"(",
"'userid'",
"=>",
"$",
"userid",
",",
"'competencyid'",
"=>",
"$",
"competencyid",
")",
")",
";",
"if",
"(",
"!",
"$",
"uc",
"||",
"!",
"$",
"uc",
"->",
"can_read",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:usercompetencyview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"else",
"if",
"(",
"$",
"uc",
"->",
"get",
"(",
"'status'",
")",
"!=",
"user_competency",
"::",
"STATUS_IN_REVIEW",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The competency review can not be stopped at this stage.'",
")",
";",
"}",
"else",
"if",
"(",
"!",
"$",
"uc",
"->",
"can_review",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:usercompetencyreview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"$",
"uc",
"->",
"set",
"(",
"'status'",
",",
"user_competency",
"::",
"STATUS_IDLE",
")",
";",
"$",
"result",
"=",
"$",
"uc",
"->",
"update",
"(",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"\\",
"core",
"\\",
"event",
"\\",
"competency_user_competency_review_stopped",
"::",
"create_from_user_competency",
"(",
"$",
"uc",
")",
"->",
"trigger",
"(",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Stop a user competency review.
@param int $userid The user ID.
@param int $competencyid The competency ID.
@return bool
|
[
"Stop",
"a",
"user",
"competency",
"review",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L3548-L3566
|
217,287
|
moodle/moodle
|
competency/classes/api.php
|
api.list_related_competencies
|
public static function list_related_competencies($competencyid) {
static::require_enabled();
$competency = new competency($competencyid);
if (!has_any_capability(array('moodle/competency:competencyview', 'moodle/competency:competencymanage'),
$competency->get_context())) {
throw new required_capability_exception($competency->get_context(), 'moodle/competency:competencyview',
'nopermissions', '');
}
return $competency->get_related_competencies();
}
|
php
|
public static function list_related_competencies($competencyid) {
static::require_enabled();
$competency = new competency($competencyid);
if (!has_any_capability(array('moodle/competency:competencyview', 'moodle/competency:competencymanage'),
$competency->get_context())) {
throw new required_capability_exception($competency->get_context(), 'moodle/competency:competencyview',
'nopermissions', '');
}
return $competency->get_related_competencies();
}
|
[
"public",
"static",
"function",
"list_related_competencies",
"(",
"$",
"competencyid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"competency",
"=",
"new",
"competency",
"(",
"$",
"competencyid",
")",
";",
"if",
"(",
"!",
"has_any_capability",
"(",
"array",
"(",
"'moodle/competency:competencyview'",
",",
"'moodle/competency:competencymanage'",
")",
",",
"$",
"competency",
"->",
"get_context",
"(",
")",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"competency",
"->",
"get_context",
"(",
")",
",",
"'moodle/competency:competencyview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"return",
"$",
"competency",
"->",
"get_related_competencies",
"(",
")",
";",
"}"
] |
List all the related competencies.
@param int $competencyid The id of the competency to check.
@return competency[]
|
[
"List",
"all",
"the",
"related",
"competencies",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L3696-L3707
|
217,288
|
moodle/moodle
|
competency/classes/api.php
|
api.add_related_competency
|
public static function add_related_competency($competencyid, $relatedcompetencyid) {
static::require_enabled();
$competency1 = new competency($competencyid);
$competency2 = new competency($relatedcompetencyid);
require_capability('moodle/competency:competencymanage', $competency1->get_context());
$relatedcompetency = related_competency::get_relation($competency1->get('id'), $competency2->get('id'));
if (!$relatedcompetency->get('id')) {
$relatedcompetency->create();
return true;
}
return true;
}
|
php
|
public static function add_related_competency($competencyid, $relatedcompetencyid) {
static::require_enabled();
$competency1 = new competency($competencyid);
$competency2 = new competency($relatedcompetencyid);
require_capability('moodle/competency:competencymanage', $competency1->get_context());
$relatedcompetency = related_competency::get_relation($competency1->get('id'), $competency2->get('id'));
if (!$relatedcompetency->get('id')) {
$relatedcompetency->create();
return true;
}
return true;
}
|
[
"public",
"static",
"function",
"add_related_competency",
"(",
"$",
"competencyid",
",",
"$",
"relatedcompetencyid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"competency1",
"=",
"new",
"competency",
"(",
"$",
"competencyid",
")",
";",
"$",
"competency2",
"=",
"new",
"competency",
"(",
"$",
"relatedcompetencyid",
")",
";",
"require_capability",
"(",
"'moodle/competency:competencymanage'",
",",
"$",
"competency1",
"->",
"get_context",
"(",
")",
")",
";",
"$",
"relatedcompetency",
"=",
"related_competency",
"::",
"get_relation",
"(",
"$",
"competency1",
"->",
"get",
"(",
"'id'",
")",
",",
"$",
"competency2",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"if",
"(",
"!",
"$",
"relatedcompetency",
"->",
"get",
"(",
"'id'",
")",
")",
"{",
"$",
"relatedcompetency",
"->",
"create",
"(",
")",
";",
"return",
"true",
";",
"}",
"return",
"true",
";",
"}"
] |
Add a related competency.
@param int $competencyid The id of the competency
@param int $relatedcompetencyid The id of the related competency.
@return bool False when create failed, true on success, or if the relation already existed.
|
[
"Add",
"a",
"related",
"competency",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L3716-L3730
|
217,289
|
moodle/moodle
|
competency/classes/api.php
|
api.remove_related_competency
|
public static function remove_related_competency($competencyid, $relatedcompetencyid) {
static::require_enabled();
$competency = new competency($competencyid);
// This only check if we have the permission in either competency because both competencies
// should belong to the same framework.
require_capability('moodle/competency:competencymanage', $competency->get_context());
$relatedcompetency = related_competency::get_relation($competencyid, $relatedcompetencyid);
if ($relatedcompetency->get('id')) {
return $relatedcompetency->delete();
}
return false;
}
|
php
|
public static function remove_related_competency($competencyid, $relatedcompetencyid) {
static::require_enabled();
$competency = new competency($competencyid);
// This only check if we have the permission in either competency because both competencies
// should belong to the same framework.
require_capability('moodle/competency:competencymanage', $competency->get_context());
$relatedcompetency = related_competency::get_relation($competencyid, $relatedcompetencyid);
if ($relatedcompetency->get('id')) {
return $relatedcompetency->delete();
}
return false;
}
|
[
"public",
"static",
"function",
"remove_related_competency",
"(",
"$",
"competencyid",
",",
"$",
"relatedcompetencyid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"competency",
"=",
"new",
"competency",
"(",
"$",
"competencyid",
")",
";",
"// This only check if we have the permission in either competency because both competencies",
"// should belong to the same framework.",
"require_capability",
"(",
"'moodle/competency:competencymanage'",
",",
"$",
"competency",
"->",
"get_context",
"(",
")",
")",
";",
"$",
"relatedcompetency",
"=",
"related_competency",
"::",
"get_relation",
"(",
"$",
"competencyid",
",",
"$",
"relatedcompetencyid",
")",
";",
"if",
"(",
"$",
"relatedcompetency",
"->",
"get",
"(",
"'id'",
")",
")",
"{",
"return",
"$",
"relatedcompetency",
"->",
"delete",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Remove a related competency.
@param int $competencyid The id of the competency.
@param int $relatedcompetencyid The id of the related competency.
@return bool True when it was deleted, false when it wasn't or the relation doesn't exist.
|
[
"Remove",
"a",
"related",
"competency",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L3739-L3753
|
217,290
|
moodle/moodle
|
competency/classes/api.php
|
api.read_user_evidence
|
public static function read_user_evidence($id) {
static::require_enabled();
$userevidence = new user_evidence($id);
if (!$userevidence->can_read()) {
$context = $userevidence->get_context();
throw new required_capability_exception($context, 'moodle/competency:userevidenceview', 'nopermissions', '');
}
return $userevidence;
}
|
php
|
public static function read_user_evidence($id) {
static::require_enabled();
$userevidence = new user_evidence($id);
if (!$userevidence->can_read()) {
$context = $userevidence->get_context();
throw new required_capability_exception($context, 'moodle/competency:userevidenceview', 'nopermissions', '');
}
return $userevidence;
}
|
[
"public",
"static",
"function",
"read_user_evidence",
"(",
"$",
"id",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"userevidence",
"=",
"new",
"user_evidence",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"userevidence",
"->",
"can_read",
"(",
")",
")",
"{",
"$",
"context",
"=",
"$",
"userevidence",
"->",
"get_context",
"(",
")",
";",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:userevidenceview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"return",
"$",
"userevidence",
";",
"}"
] |
Read a user evidence.
@param int $id
@return user_evidence
|
[
"Read",
"a",
"user",
"evidence",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L3761-L3771
|
217,291
|
moodle/moodle
|
competency/classes/api.php
|
api.list_user_evidence
|
public static function list_user_evidence($userid) {
static::require_enabled();
if (!user_evidence::can_read_user($userid)) {
$context = context_user::instance($userid);
throw new required_capability_exception($context, 'moodle/competency:userevidenceview', 'nopermissions', '');
}
$evidence = user_evidence::get_records(array('userid' => $userid), 'name');
return $evidence;
}
|
php
|
public static function list_user_evidence($userid) {
static::require_enabled();
if (!user_evidence::can_read_user($userid)) {
$context = context_user::instance($userid);
throw new required_capability_exception($context, 'moodle/competency:userevidenceview', 'nopermissions', '');
}
$evidence = user_evidence::get_records(array('userid' => $userid), 'name');
return $evidence;
}
|
[
"public",
"static",
"function",
"list_user_evidence",
"(",
"$",
"userid",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"if",
"(",
"!",
"user_evidence",
"::",
"can_read_user",
"(",
"$",
"userid",
")",
")",
"{",
"$",
"context",
"=",
"context_user",
"::",
"instance",
"(",
"$",
"userid",
")",
";",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:userevidenceview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"$",
"evidence",
"=",
"user_evidence",
"::",
"get_records",
"(",
"array",
"(",
"'userid'",
"=>",
"$",
"userid",
")",
",",
"'name'",
")",
";",
"return",
"$",
"evidence",
";",
"}"
] |
List the user evidence of a user.
@param int $userid The user ID.
@return user_evidence[]
|
[
"List",
"the",
"user",
"evidence",
"of",
"a",
"user",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L3879-L3888
|
217,292
|
moodle/moodle
|
competency/classes/api.php
|
api.create_user_evidence_competency
|
public static function create_user_evidence_competency($userevidenceorid, $competencyid) {
global $USER;
static::require_enabled();
$userevidence = $userevidenceorid;
if (!is_object($userevidence)) {
$userevidence = self::read_user_evidence($userevidence);
}
// Perform user evidence capability checks.
if (!$userevidence->can_manage()) {
$context = $userevidence->get_context();
throw new required_capability_exception($context, 'moodle/competency:userevidencemanage', 'nopermissions', '');
}
// Perform competency capability checks.
$competency = self::read_competency($competencyid);
// Get (and create) the relation.
$relation = user_evidence_competency::get_relation($userevidence->get('id'), $competency->get('id'));
if (!$relation->get('id')) {
$relation->create();
$link = url::user_evidence($userevidence->get('id'));
self::add_evidence(
$userevidence->get('userid'),
$competency,
$userevidence->get_context(),
evidence::ACTION_LOG,
'evidence_evidenceofpriorlearninglinked',
'core_competency',
$userevidence->get('name'),
false,
$link->out(false),
null,
$USER->id
);
}
return $relation;
}
|
php
|
public static function create_user_evidence_competency($userevidenceorid, $competencyid) {
global $USER;
static::require_enabled();
$userevidence = $userevidenceorid;
if (!is_object($userevidence)) {
$userevidence = self::read_user_evidence($userevidence);
}
// Perform user evidence capability checks.
if (!$userevidence->can_manage()) {
$context = $userevidence->get_context();
throw new required_capability_exception($context, 'moodle/competency:userevidencemanage', 'nopermissions', '');
}
// Perform competency capability checks.
$competency = self::read_competency($competencyid);
// Get (and create) the relation.
$relation = user_evidence_competency::get_relation($userevidence->get('id'), $competency->get('id'));
if (!$relation->get('id')) {
$relation->create();
$link = url::user_evidence($userevidence->get('id'));
self::add_evidence(
$userevidence->get('userid'),
$competency,
$userevidence->get_context(),
evidence::ACTION_LOG,
'evidence_evidenceofpriorlearninglinked',
'core_competency',
$userevidence->get('name'),
false,
$link->out(false),
null,
$USER->id
);
}
return $relation;
}
|
[
"public",
"static",
"function",
"create_user_evidence_competency",
"(",
"$",
"userevidenceorid",
",",
"$",
"competencyid",
")",
"{",
"global",
"$",
"USER",
";",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"userevidence",
"=",
"$",
"userevidenceorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"userevidence",
")",
")",
"{",
"$",
"userevidence",
"=",
"self",
"::",
"read_user_evidence",
"(",
"$",
"userevidence",
")",
";",
"}",
"// Perform user evidence capability checks.",
"if",
"(",
"!",
"$",
"userevidence",
"->",
"can_manage",
"(",
")",
")",
"{",
"$",
"context",
"=",
"$",
"userevidence",
"->",
"get_context",
"(",
")",
";",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:userevidencemanage'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// Perform competency capability checks.",
"$",
"competency",
"=",
"self",
"::",
"read_competency",
"(",
"$",
"competencyid",
")",
";",
"// Get (and create) the relation.",
"$",
"relation",
"=",
"user_evidence_competency",
"::",
"get_relation",
"(",
"$",
"userevidence",
"->",
"get",
"(",
"'id'",
")",
",",
"$",
"competency",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"if",
"(",
"!",
"$",
"relation",
"->",
"get",
"(",
"'id'",
")",
")",
"{",
"$",
"relation",
"->",
"create",
"(",
")",
";",
"$",
"link",
"=",
"url",
"::",
"user_evidence",
"(",
"$",
"userevidence",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"self",
"::",
"add_evidence",
"(",
"$",
"userevidence",
"->",
"get",
"(",
"'userid'",
")",
",",
"$",
"competency",
",",
"$",
"userevidence",
"->",
"get_context",
"(",
")",
",",
"evidence",
"::",
"ACTION_LOG",
",",
"'evidence_evidenceofpriorlearninglinked'",
",",
"'core_competency'",
",",
"$",
"userevidence",
"->",
"get",
"(",
"'name'",
")",
",",
"false",
",",
"$",
"link",
"->",
"out",
"(",
"false",
")",
",",
"null",
",",
"$",
"USER",
"->",
"id",
")",
";",
"}",
"return",
"$",
"relation",
";",
"}"
] |
Link a user evidence with a competency.
@param user_evidence|int $userevidenceorid User evidence or its ID.
@param int $competencyid Competency ID.
@return user_evidence_competency
|
[
"Link",
"a",
"user",
"evidence",
"with",
"a",
"competency",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L3897-L3937
|
217,293
|
moodle/moodle
|
competency/classes/api.php
|
api.delete_user_evidence_competency
|
public static function delete_user_evidence_competency($userevidenceorid, $competencyid) {
global $USER;
static::require_enabled();
$userevidence = $userevidenceorid;
if (!is_object($userevidence)) {
$userevidence = self::read_user_evidence($userevidence);
}
// Perform user evidence capability checks.
if (!$userevidence->can_manage()) {
$context = $userevidence->get_context();
throw new required_capability_exception($context, 'moodle/competency:userevidencemanage', 'nopermissions', '');
}
// Get (and delete) the relation.
$relation = user_evidence_competency::get_relation($userevidence->get('id'), $competencyid);
if (!$relation->get('id')) {
return true;
}
$success = $relation->delete();
if ($success) {
self::add_evidence(
$userevidence->get('userid'),
$competencyid,
$userevidence->get_context(),
evidence::ACTION_LOG,
'evidence_evidenceofpriorlearningunlinked',
'core_competency',
$userevidence->get('name'),
false,
null,
null,
$USER->id
);
}
return $success;
}
|
php
|
public static function delete_user_evidence_competency($userevidenceorid, $competencyid) {
global $USER;
static::require_enabled();
$userevidence = $userevidenceorid;
if (!is_object($userevidence)) {
$userevidence = self::read_user_evidence($userevidence);
}
// Perform user evidence capability checks.
if (!$userevidence->can_manage()) {
$context = $userevidence->get_context();
throw new required_capability_exception($context, 'moodle/competency:userevidencemanage', 'nopermissions', '');
}
// Get (and delete) the relation.
$relation = user_evidence_competency::get_relation($userevidence->get('id'), $competencyid);
if (!$relation->get('id')) {
return true;
}
$success = $relation->delete();
if ($success) {
self::add_evidence(
$userevidence->get('userid'),
$competencyid,
$userevidence->get_context(),
evidence::ACTION_LOG,
'evidence_evidenceofpriorlearningunlinked',
'core_competency',
$userevidence->get('name'),
false,
null,
null,
$USER->id
);
}
return $success;
}
|
[
"public",
"static",
"function",
"delete_user_evidence_competency",
"(",
"$",
"userevidenceorid",
",",
"$",
"competencyid",
")",
"{",
"global",
"$",
"USER",
";",
"static",
"::",
"require_enabled",
"(",
")",
";",
"$",
"userevidence",
"=",
"$",
"userevidenceorid",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"userevidence",
")",
")",
"{",
"$",
"userevidence",
"=",
"self",
"::",
"read_user_evidence",
"(",
"$",
"userevidence",
")",
";",
"}",
"// Perform user evidence capability checks.",
"if",
"(",
"!",
"$",
"userevidence",
"->",
"can_manage",
"(",
")",
")",
"{",
"$",
"context",
"=",
"$",
"userevidence",
"->",
"get_context",
"(",
")",
";",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:userevidencemanage'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// Get (and delete) the relation.",
"$",
"relation",
"=",
"user_evidence_competency",
"::",
"get_relation",
"(",
"$",
"userevidence",
"->",
"get",
"(",
"'id'",
")",
",",
"$",
"competencyid",
")",
";",
"if",
"(",
"!",
"$",
"relation",
"->",
"get",
"(",
"'id'",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"success",
"=",
"$",
"relation",
"->",
"delete",
"(",
")",
";",
"if",
"(",
"$",
"success",
")",
"{",
"self",
"::",
"add_evidence",
"(",
"$",
"userevidence",
"->",
"get",
"(",
"'userid'",
")",
",",
"$",
"competencyid",
",",
"$",
"userevidence",
"->",
"get_context",
"(",
")",
",",
"evidence",
"::",
"ACTION_LOG",
",",
"'evidence_evidenceofpriorlearningunlinked'",
",",
"'core_competency'",
",",
"$",
"userevidence",
"->",
"get",
"(",
"'name'",
")",
",",
"false",
",",
"null",
",",
"null",
",",
"$",
"USER",
"->",
"id",
")",
";",
"}",
"return",
"$",
"success",
";",
"}"
] |
Delete a relationship between a user evidence and a competency.
@param user_evidence|int $userevidenceorid User evidence or its ID.
@param int $competencyid Competency ID.
@return bool
|
[
"Delete",
"a",
"relationship",
"between",
"a",
"user",
"evidence",
"and",
"a",
"competency",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L3946-L3985
|
217,294
|
moodle/moodle
|
competency/classes/api.php
|
api.request_review_of_user_evidence_linked_competencies
|
public static function request_review_of_user_evidence_linked_competencies($id) {
$userevidence = new user_evidence($id);
$context = $userevidence->get_context();
$userid = $userevidence->get('userid');
if (!$userevidence->can_manage()) {
throw new required_capability_exception($context, 'moodle/competency:userevidencemanage', 'nopermissions', '');
}
$usercompetencies = user_evidence_competency::get_user_competencies_by_userevidenceid($id);
foreach ($usercompetencies as $usercompetency) {
if ($usercompetency->get('status') == user_competency::STATUS_IDLE) {
static::user_competency_request_review($userid, $usercompetency->get('competencyid'));
}
}
return true;
}
|
php
|
public static function request_review_of_user_evidence_linked_competencies($id) {
$userevidence = new user_evidence($id);
$context = $userevidence->get_context();
$userid = $userevidence->get('userid');
if (!$userevidence->can_manage()) {
throw new required_capability_exception($context, 'moodle/competency:userevidencemanage', 'nopermissions', '');
}
$usercompetencies = user_evidence_competency::get_user_competencies_by_userevidenceid($id);
foreach ($usercompetencies as $usercompetency) {
if ($usercompetency->get('status') == user_competency::STATUS_IDLE) {
static::user_competency_request_review($userid, $usercompetency->get('competencyid'));
}
}
return true;
}
|
[
"public",
"static",
"function",
"request_review_of_user_evidence_linked_competencies",
"(",
"$",
"id",
")",
"{",
"$",
"userevidence",
"=",
"new",
"user_evidence",
"(",
"$",
"id",
")",
";",
"$",
"context",
"=",
"$",
"userevidence",
"->",
"get_context",
"(",
")",
";",
"$",
"userid",
"=",
"$",
"userevidence",
"->",
"get",
"(",
"'userid'",
")",
";",
"if",
"(",
"!",
"$",
"userevidence",
"->",
"can_manage",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:userevidencemanage'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"$",
"usercompetencies",
"=",
"user_evidence_competency",
"::",
"get_user_competencies_by_userevidenceid",
"(",
"$",
"id",
")",
";",
"foreach",
"(",
"$",
"usercompetencies",
"as",
"$",
"usercompetency",
")",
"{",
"if",
"(",
"$",
"usercompetency",
"->",
"get",
"(",
"'status'",
")",
"==",
"user_competency",
"::",
"STATUS_IDLE",
")",
"{",
"static",
"::",
"user_competency_request_review",
"(",
"$",
"userid",
",",
"$",
"usercompetency",
"->",
"get",
"(",
"'competencyid'",
")",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Send request review for user evidence competencies.
@param int $id The user evidence ID.
@return bool
|
[
"Send",
"request",
"review",
"for",
"user",
"evidence",
"competencies",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L3993-L4010
|
217,295
|
moodle/moodle
|
competency/classes/api.php
|
api.duplicate_competency_tree
|
protected static function duplicate_competency_tree($frameworkid, $tree, $oldparent = 0, $newparent = 0) {
$matchids = array();
foreach ($tree as $node) {
if ($node->competency->get('parentid') == $oldparent) {
$parentid = $node->competency->get('id');
// Create the competency.
$competency = new competency(0, $node->competency->to_record());
$competency->set('competencyframeworkid', $frameworkid);
$competency->set('parentid', $newparent);
$competency->set('path', '');
$competency->set('id', 0);
$competency->reset_rule();
$competency->create();
// Trigger the created event competency.
\core\event\competency_created::create_from_competency($competency)->trigger();
// Match the old id with the new one.
$matchids[$parentid] = $competency;
if (!empty($node->children)) {
// Duplicate children competency.
$childrenids = self::duplicate_competency_tree($frameworkid, $node->children, $parentid, $competency->get('id'));
// Array_merge does not keep keys when merging so we use the + operator.
$matchids = $matchids + $childrenids;
}
}
}
return $matchids;
}
|
php
|
protected static function duplicate_competency_tree($frameworkid, $tree, $oldparent = 0, $newparent = 0) {
$matchids = array();
foreach ($tree as $node) {
if ($node->competency->get('parentid') == $oldparent) {
$parentid = $node->competency->get('id');
// Create the competency.
$competency = new competency(0, $node->competency->to_record());
$competency->set('competencyframeworkid', $frameworkid);
$competency->set('parentid', $newparent);
$competency->set('path', '');
$competency->set('id', 0);
$competency->reset_rule();
$competency->create();
// Trigger the created event competency.
\core\event\competency_created::create_from_competency($competency)->trigger();
// Match the old id with the new one.
$matchids[$parentid] = $competency;
if (!empty($node->children)) {
// Duplicate children competency.
$childrenids = self::duplicate_competency_tree($frameworkid, $node->children, $parentid, $competency->get('id'));
// Array_merge does not keep keys when merging so we use the + operator.
$matchids = $matchids + $childrenids;
}
}
}
return $matchids;
}
|
[
"protected",
"static",
"function",
"duplicate_competency_tree",
"(",
"$",
"frameworkid",
",",
"$",
"tree",
",",
"$",
"oldparent",
"=",
"0",
",",
"$",
"newparent",
"=",
"0",
")",
"{",
"$",
"matchids",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"tree",
"as",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"->",
"competency",
"->",
"get",
"(",
"'parentid'",
")",
"==",
"$",
"oldparent",
")",
"{",
"$",
"parentid",
"=",
"$",
"node",
"->",
"competency",
"->",
"get",
"(",
"'id'",
")",
";",
"// Create the competency.",
"$",
"competency",
"=",
"new",
"competency",
"(",
"0",
",",
"$",
"node",
"->",
"competency",
"->",
"to_record",
"(",
")",
")",
";",
"$",
"competency",
"->",
"set",
"(",
"'competencyframeworkid'",
",",
"$",
"frameworkid",
")",
";",
"$",
"competency",
"->",
"set",
"(",
"'parentid'",
",",
"$",
"newparent",
")",
";",
"$",
"competency",
"->",
"set",
"(",
"'path'",
",",
"''",
")",
";",
"$",
"competency",
"->",
"set",
"(",
"'id'",
",",
"0",
")",
";",
"$",
"competency",
"->",
"reset_rule",
"(",
")",
";",
"$",
"competency",
"->",
"create",
"(",
")",
";",
"// Trigger the created event competency.",
"\\",
"core",
"\\",
"event",
"\\",
"competency_created",
"::",
"create_from_competency",
"(",
"$",
"competency",
")",
"->",
"trigger",
"(",
")",
";",
"// Match the old id with the new one.",
"$",
"matchids",
"[",
"$",
"parentid",
"]",
"=",
"$",
"competency",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"node",
"->",
"children",
")",
")",
"{",
"// Duplicate children competency.",
"$",
"childrenids",
"=",
"self",
"::",
"duplicate_competency_tree",
"(",
"$",
"frameworkid",
",",
"$",
"node",
"->",
"children",
",",
"$",
"parentid",
",",
"$",
"competency",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"// Array_merge does not keep keys when merging so we use the + operator.",
"$",
"matchids",
"=",
"$",
"matchids",
"+",
"$",
"childrenids",
";",
"}",
"}",
"}",
"return",
"$",
"matchids",
";",
"}"
] |
Recursively duplicate competencies from a tree, we start duplicating from parents to children to have a correct path.
This method does not copy the related competencies.
@param int $frameworkid - framework id
@param competency[] $tree - array of competencies object
@param int $oldparent - old parent id
@param int $newparent - new parent id
@return competency[] $matchids - List of old competencies ids matched with new competencies object.
|
[
"Recursively",
"duplicate",
"competencies",
"from",
"a",
"tree",
"we",
"start",
"duplicating",
"from",
"parents",
"to",
"children",
"to",
"have",
"a",
"correct",
"path",
".",
"This",
"method",
"does",
"not",
"copy",
"the",
"related",
"competencies",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L4022-L4052
|
217,296
|
moodle/moodle
|
competency/classes/api.php
|
api.migrate_competency_tree_rules
|
protected static function migrate_competency_tree_rules($tree, $matchids) {
foreach ($tree as $node) {
$oldcompid = $node->competency->get('id');
if ($node->competency->get('ruletype') && array_key_exists($oldcompid, $matchids)) {
try {
// Get the new competency.
$competency = $matchids[$oldcompid];
$class = $node->competency->get('ruletype');
$newruleconfig = $class::migrate_config($node->competency->get('ruleconfig'), $matchids);
$competency->set('ruleconfig', $newruleconfig);
$competency->set('ruletype', $class);
$competency->set('ruleoutcome', $node->competency->get('ruleoutcome'));
$competency->update();
} catch (\Exception $e) {
debugging('Could not migrate competency rule from: ' . $oldcompid . ' to: ' . $competency->get('id') . '.' .
' Exception: ' . $e->getMessage(), DEBUG_DEVELOPER);
$competency->reset_rule();
}
}
if (!empty($node->children)) {
self::migrate_competency_tree_rules($node->children, $matchids);
}
}
}
|
php
|
protected static function migrate_competency_tree_rules($tree, $matchids) {
foreach ($tree as $node) {
$oldcompid = $node->competency->get('id');
if ($node->competency->get('ruletype') && array_key_exists($oldcompid, $matchids)) {
try {
// Get the new competency.
$competency = $matchids[$oldcompid];
$class = $node->competency->get('ruletype');
$newruleconfig = $class::migrate_config($node->competency->get('ruleconfig'), $matchids);
$competency->set('ruleconfig', $newruleconfig);
$competency->set('ruletype', $class);
$competency->set('ruleoutcome', $node->competency->get('ruleoutcome'));
$competency->update();
} catch (\Exception $e) {
debugging('Could not migrate competency rule from: ' . $oldcompid . ' to: ' . $competency->get('id') . '.' .
' Exception: ' . $e->getMessage(), DEBUG_DEVELOPER);
$competency->reset_rule();
}
}
if (!empty($node->children)) {
self::migrate_competency_tree_rules($node->children, $matchids);
}
}
}
|
[
"protected",
"static",
"function",
"migrate_competency_tree_rules",
"(",
"$",
"tree",
",",
"$",
"matchids",
")",
"{",
"foreach",
"(",
"$",
"tree",
"as",
"$",
"node",
")",
"{",
"$",
"oldcompid",
"=",
"$",
"node",
"->",
"competency",
"->",
"get",
"(",
"'id'",
")",
";",
"if",
"(",
"$",
"node",
"->",
"competency",
"->",
"get",
"(",
"'ruletype'",
")",
"&&",
"array_key_exists",
"(",
"$",
"oldcompid",
",",
"$",
"matchids",
")",
")",
"{",
"try",
"{",
"// Get the new competency.",
"$",
"competency",
"=",
"$",
"matchids",
"[",
"$",
"oldcompid",
"]",
";",
"$",
"class",
"=",
"$",
"node",
"->",
"competency",
"->",
"get",
"(",
"'ruletype'",
")",
";",
"$",
"newruleconfig",
"=",
"$",
"class",
"::",
"migrate_config",
"(",
"$",
"node",
"->",
"competency",
"->",
"get",
"(",
"'ruleconfig'",
")",
",",
"$",
"matchids",
")",
";",
"$",
"competency",
"->",
"set",
"(",
"'ruleconfig'",
",",
"$",
"newruleconfig",
")",
";",
"$",
"competency",
"->",
"set",
"(",
"'ruletype'",
",",
"$",
"class",
")",
";",
"$",
"competency",
"->",
"set",
"(",
"'ruleoutcome'",
",",
"$",
"node",
"->",
"competency",
"->",
"get",
"(",
"'ruleoutcome'",
")",
")",
";",
"$",
"competency",
"->",
"update",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"debugging",
"(",
"'Could not migrate competency rule from: '",
".",
"$",
"oldcompid",
".",
"' to: '",
".",
"$",
"competency",
"->",
"get",
"(",
"'id'",
")",
".",
"'.'",
".",
"' Exception: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"DEBUG_DEVELOPER",
")",
";",
"$",
"competency",
"->",
"reset_rule",
"(",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"node",
"->",
"children",
")",
")",
"{",
"self",
"::",
"migrate_competency_tree_rules",
"(",
"$",
"node",
"->",
"children",
",",
"$",
"matchids",
")",
";",
"}",
"}",
"}"
] |
Recursively migrate competency rules.
@param competency[] $tree - array of competencies object
@param competency[] $matchids - List of old competencies ids matched with new competencies object
|
[
"Recursively",
"migrate",
"competency",
"rules",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L4060-L4085
|
217,297
|
moodle/moodle
|
competency/classes/api.php
|
api.archive_user_competencies_in_plan
|
protected static function archive_user_competencies_in_plan($plan) {
// Check if the plan was already completed.
if ($plan->get('status') == plan::STATUS_COMPLETE) {
throw new coding_exception('The plan is already completed.');
}
$competencies = $plan->get_competencies();
$usercompetencies = user_competency::get_multiple($plan->get('userid'), $competencies);
$i = 0;
foreach ($competencies as $competency) {
$found = false;
foreach ($usercompetencies as $uckey => $uc) {
if ($uc->get('competencyid') == $competency->get('id')) {
$found = true;
$ucprecord = $uc->to_record();
$ucprecord->planid = $plan->get('id');
$ucprecord->sortorder = $i;
unset($ucprecord->id);
unset($ucprecord->status);
unset($ucprecord->reviewerid);
$usercompetencyplan = new user_competency_plan(0, $ucprecord);
$usercompetencyplan->create();
unset($usercompetencies[$uckey]);
break;
}
}
// If the user competency doesn't exist, we create a new relation in user_competency_plan.
if (!$found) {
$usercompetencyplan = user_competency_plan::create_relation($plan->get('userid'), $competency->get('id'),
$plan->get('id'));
$usercompetencyplan->set('sortorder', $i);
$usercompetencyplan->create();
}
$i++;
}
}
|
php
|
protected static function archive_user_competencies_in_plan($plan) {
// Check if the plan was already completed.
if ($plan->get('status') == plan::STATUS_COMPLETE) {
throw new coding_exception('The plan is already completed.');
}
$competencies = $plan->get_competencies();
$usercompetencies = user_competency::get_multiple($plan->get('userid'), $competencies);
$i = 0;
foreach ($competencies as $competency) {
$found = false;
foreach ($usercompetencies as $uckey => $uc) {
if ($uc->get('competencyid') == $competency->get('id')) {
$found = true;
$ucprecord = $uc->to_record();
$ucprecord->planid = $plan->get('id');
$ucprecord->sortorder = $i;
unset($ucprecord->id);
unset($ucprecord->status);
unset($ucprecord->reviewerid);
$usercompetencyplan = new user_competency_plan(0, $ucprecord);
$usercompetencyplan->create();
unset($usercompetencies[$uckey]);
break;
}
}
// If the user competency doesn't exist, we create a new relation in user_competency_plan.
if (!$found) {
$usercompetencyplan = user_competency_plan::create_relation($plan->get('userid'), $competency->get('id'),
$plan->get('id'));
$usercompetencyplan->set('sortorder', $i);
$usercompetencyplan->create();
}
$i++;
}
}
|
[
"protected",
"static",
"function",
"archive_user_competencies_in_plan",
"(",
"$",
"plan",
")",
"{",
"// Check if the plan was already completed.",
"if",
"(",
"$",
"plan",
"->",
"get",
"(",
"'status'",
")",
"==",
"plan",
"::",
"STATUS_COMPLETE",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The plan is already completed.'",
")",
";",
"}",
"$",
"competencies",
"=",
"$",
"plan",
"->",
"get_competencies",
"(",
")",
";",
"$",
"usercompetencies",
"=",
"user_competency",
"::",
"get_multiple",
"(",
"$",
"plan",
"->",
"get",
"(",
"'userid'",
")",
",",
"$",
"competencies",
")",
";",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"competencies",
"as",
"$",
"competency",
")",
"{",
"$",
"found",
"=",
"false",
";",
"foreach",
"(",
"$",
"usercompetencies",
"as",
"$",
"uckey",
"=>",
"$",
"uc",
")",
"{",
"if",
"(",
"$",
"uc",
"->",
"get",
"(",
"'competencyid'",
")",
"==",
"$",
"competency",
"->",
"get",
"(",
"'id'",
")",
")",
"{",
"$",
"found",
"=",
"true",
";",
"$",
"ucprecord",
"=",
"$",
"uc",
"->",
"to_record",
"(",
")",
";",
"$",
"ucprecord",
"->",
"planid",
"=",
"$",
"plan",
"->",
"get",
"(",
"'id'",
")",
";",
"$",
"ucprecord",
"->",
"sortorder",
"=",
"$",
"i",
";",
"unset",
"(",
"$",
"ucprecord",
"->",
"id",
")",
";",
"unset",
"(",
"$",
"ucprecord",
"->",
"status",
")",
";",
"unset",
"(",
"$",
"ucprecord",
"->",
"reviewerid",
")",
";",
"$",
"usercompetencyplan",
"=",
"new",
"user_competency_plan",
"(",
"0",
",",
"$",
"ucprecord",
")",
";",
"$",
"usercompetencyplan",
"->",
"create",
"(",
")",
";",
"unset",
"(",
"$",
"usercompetencies",
"[",
"$",
"uckey",
"]",
")",
";",
"break",
";",
"}",
"}",
"// If the user competency doesn't exist, we create a new relation in user_competency_plan.",
"if",
"(",
"!",
"$",
"found",
")",
"{",
"$",
"usercompetencyplan",
"=",
"user_competency_plan",
"::",
"create_relation",
"(",
"$",
"plan",
"->",
"get",
"(",
"'userid'",
")",
",",
"$",
"competency",
"->",
"get",
"(",
"'id'",
")",
",",
"$",
"plan",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"$",
"usercompetencyplan",
"->",
"set",
"(",
"'sortorder'",
",",
"$",
"i",
")",
";",
"$",
"usercompetencyplan",
"->",
"create",
"(",
")",
";",
"}",
"$",
"i",
"++",
";",
"}",
"}"
] |
Archive user competencies in a plan.
@param int $plan The plan object.
@return void
|
[
"Archive",
"user",
"competencies",
"in",
"a",
"plan",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L4093-L4135
|
217,298
|
moodle/moodle
|
competency/classes/api.php
|
api.remove_archived_user_competencies_in_plan
|
protected static function remove_archived_user_competencies_in_plan($plan) {
$competencies = $plan->get_competencies();
$usercompetenciesplan = user_competency_plan::get_multiple($plan->get('userid'), $plan->get('id'), $competencies);
foreach ($usercompetenciesplan as $ucpkey => $ucp) {
$ucp->delete();
}
}
|
php
|
protected static function remove_archived_user_competencies_in_plan($plan) {
$competencies = $plan->get_competencies();
$usercompetenciesplan = user_competency_plan::get_multiple($plan->get('userid'), $plan->get('id'), $competencies);
foreach ($usercompetenciesplan as $ucpkey => $ucp) {
$ucp->delete();
}
}
|
[
"protected",
"static",
"function",
"remove_archived_user_competencies_in_plan",
"(",
"$",
"plan",
")",
"{",
"$",
"competencies",
"=",
"$",
"plan",
"->",
"get_competencies",
"(",
")",
";",
"$",
"usercompetenciesplan",
"=",
"user_competency_plan",
"::",
"get_multiple",
"(",
"$",
"plan",
"->",
"get",
"(",
"'userid'",
")",
",",
"$",
"plan",
"->",
"get",
"(",
"'id'",
")",
",",
"$",
"competencies",
")",
";",
"foreach",
"(",
"$",
"usercompetenciesplan",
"as",
"$",
"ucpkey",
"=>",
"$",
"ucp",
")",
"{",
"$",
"ucp",
"->",
"delete",
"(",
")",
";",
"}",
"}"
] |
Delete archived user competencies in a plan.
@param int $plan The plan object.
@return void
|
[
"Delete",
"archived",
"user",
"competencies",
"in",
"a",
"plan",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L4143-L4150
|
217,299
|
moodle/moodle
|
competency/classes/api.php
|
api.list_evidence
|
public static function list_evidence($userid = 0, $competencyid = 0, $planid = 0, $sort = 'timecreated',
$order = 'DESC', $skip = 0, $limit = 0) {
static::require_enabled();
if (!user_competency::can_read_user($userid)) {
$context = context_user::instance($userid);
throw new required_capability_exception($context, 'moodle/competency:usercompetencyview', 'nopermissions', '');
}
$usercompetency = user_competency::get_record(array('userid' => $userid, 'competencyid' => $competencyid));
if (!$usercompetency) {
return array();
}
$plancompleted = false;
if ($planid != 0) {
$plan = new plan($planid);
if ($plan->get('status') == plan::STATUS_COMPLETE) {
$plancompleted = true;
}
}
$select = 'usercompetencyid = :usercompetencyid';
$params = array('usercompetencyid' => $usercompetency->get('id'));
if ($plancompleted) {
$select .= ' AND timecreated <= :timecompleted';
$params['timecompleted'] = $plan->get('timemodified');
}
$orderby = $sort . ' ' . $order;
$orderby .= !empty($orderby) ? ', id DESC' : 'id DESC'; // Prevent random ordering.
$evidence = evidence::get_records_select($select, $params, $orderby, '*', $skip, $limit);
return $evidence;
}
|
php
|
public static function list_evidence($userid = 0, $competencyid = 0, $planid = 0, $sort = 'timecreated',
$order = 'DESC', $skip = 0, $limit = 0) {
static::require_enabled();
if (!user_competency::can_read_user($userid)) {
$context = context_user::instance($userid);
throw new required_capability_exception($context, 'moodle/competency:usercompetencyview', 'nopermissions', '');
}
$usercompetency = user_competency::get_record(array('userid' => $userid, 'competencyid' => $competencyid));
if (!$usercompetency) {
return array();
}
$plancompleted = false;
if ($planid != 0) {
$plan = new plan($planid);
if ($plan->get('status') == plan::STATUS_COMPLETE) {
$plancompleted = true;
}
}
$select = 'usercompetencyid = :usercompetencyid';
$params = array('usercompetencyid' => $usercompetency->get('id'));
if ($plancompleted) {
$select .= ' AND timecreated <= :timecompleted';
$params['timecompleted'] = $plan->get('timemodified');
}
$orderby = $sort . ' ' . $order;
$orderby .= !empty($orderby) ? ', id DESC' : 'id DESC'; // Prevent random ordering.
$evidence = evidence::get_records_select($select, $params, $orderby, '*', $skip, $limit);
return $evidence;
}
|
[
"public",
"static",
"function",
"list_evidence",
"(",
"$",
"userid",
"=",
"0",
",",
"$",
"competencyid",
"=",
"0",
",",
"$",
"planid",
"=",
"0",
",",
"$",
"sort",
"=",
"'timecreated'",
",",
"$",
"order",
"=",
"'DESC'",
",",
"$",
"skip",
"=",
"0",
",",
"$",
"limit",
"=",
"0",
")",
"{",
"static",
"::",
"require_enabled",
"(",
")",
";",
"if",
"(",
"!",
"user_competency",
"::",
"can_read_user",
"(",
"$",
"userid",
")",
")",
"{",
"$",
"context",
"=",
"context_user",
"::",
"instance",
"(",
"$",
"userid",
")",
";",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/competency:usercompetencyview'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"$",
"usercompetency",
"=",
"user_competency",
"::",
"get_record",
"(",
"array",
"(",
"'userid'",
"=>",
"$",
"userid",
",",
"'competencyid'",
"=>",
"$",
"competencyid",
")",
")",
";",
"if",
"(",
"!",
"$",
"usercompetency",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"plancompleted",
"=",
"false",
";",
"if",
"(",
"$",
"planid",
"!=",
"0",
")",
"{",
"$",
"plan",
"=",
"new",
"plan",
"(",
"$",
"planid",
")",
";",
"if",
"(",
"$",
"plan",
"->",
"get",
"(",
"'status'",
")",
"==",
"plan",
"::",
"STATUS_COMPLETE",
")",
"{",
"$",
"plancompleted",
"=",
"true",
";",
"}",
"}",
"$",
"select",
"=",
"'usercompetencyid = :usercompetencyid'",
";",
"$",
"params",
"=",
"array",
"(",
"'usercompetencyid'",
"=>",
"$",
"usercompetency",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"if",
"(",
"$",
"plancompleted",
")",
"{",
"$",
"select",
".=",
"' AND timecreated <= :timecompleted'",
";",
"$",
"params",
"[",
"'timecompleted'",
"]",
"=",
"$",
"plan",
"->",
"get",
"(",
"'timemodified'",
")",
";",
"}",
"$",
"orderby",
"=",
"$",
"sort",
".",
"' '",
".",
"$",
"order",
";",
"$",
"orderby",
".=",
"!",
"empty",
"(",
"$",
"orderby",
")",
"?",
"', id DESC'",
":",
"'id DESC'",
";",
"// Prevent random ordering.",
"$",
"evidence",
"=",
"evidence",
"::",
"get_records_select",
"(",
"$",
"select",
",",
"$",
"params",
",",
"$",
"orderby",
",",
"'*'",
",",
"$",
"skip",
",",
"$",
"limit",
")",
";",
"return",
"$",
"evidence",
";",
"}"
] |
List all the evidence for a user competency.
@param int $userid The user id - only used if usercompetencyid is 0.
@param int $competencyid The competency id - only used it usercompetencyid is 0.
@param int $planid The plan id - not used yet - but can be used to only list archived evidence if a plan is completed.
@param string $sort The field to sort the evidence by.
@param string $order The ordering of the sorting.
@param int $skip Number of records to skip.
@param int $limit Number of records to return.
@return \core_competency\evidence[]
@return array of \core_competency\evidence
|
[
"List",
"all",
"the",
"evidence",
"for",
"a",
"user",
"competency",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/api.php#L4165-L4199
|
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.