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
214,700
moodle/moodle
mod/quiz/renderer.php
mod_quiz_renderer.attempt_state
public function attempt_state($attemptobj) { switch ($attemptobj->get_state()) { case quiz_attempt::IN_PROGRESS: return get_string('stateinprogress', 'quiz'); case quiz_attempt::OVERDUE: return get_string('stateoverdue', 'quiz') . html_writer::tag('span', get_string('stateoverduedetails', 'quiz', userdate($attemptobj->get_due_date())), array('class' => 'statedetails')); case quiz_attempt::FINISHED: return get_string('statefinished', 'quiz') . html_writer::tag('span', get_string('statefinisheddetails', 'quiz', userdate($attemptobj->get_submitted_date())), array('class' => 'statedetails')); case quiz_attempt::ABANDONED: return get_string('stateabandoned', 'quiz'); } }
php
public function attempt_state($attemptobj) { switch ($attemptobj->get_state()) { case quiz_attempt::IN_PROGRESS: return get_string('stateinprogress', 'quiz'); case quiz_attempt::OVERDUE: return get_string('stateoverdue', 'quiz') . html_writer::tag('span', get_string('stateoverduedetails', 'quiz', userdate($attemptobj->get_due_date())), array('class' => 'statedetails')); case quiz_attempt::FINISHED: return get_string('statefinished', 'quiz') . html_writer::tag('span', get_string('statefinisheddetails', 'quiz', userdate($attemptobj->get_submitted_date())), array('class' => 'statedetails')); case quiz_attempt::ABANDONED: return get_string('stateabandoned', 'quiz'); } }
[ "public", "function", "attempt_state", "(", "$", "attemptobj", ")", "{", "switch", "(", "$", "attemptobj", "->", "get_state", "(", ")", ")", "{", "case", "quiz_attempt", "::", "IN_PROGRESS", ":", "return", "get_string", "(", "'stateinprogress'", ",", "'quiz'", ")", ";", "case", "quiz_attempt", "::", "OVERDUE", ":", "return", "get_string", "(", "'stateoverdue'", ",", "'quiz'", ")", ".", "html_writer", "::", "tag", "(", "'span'", ",", "get_string", "(", "'stateoverduedetails'", ",", "'quiz'", ",", "userdate", "(", "$", "attemptobj", "->", "get_due_date", "(", ")", ")", ")", ",", "array", "(", "'class'", "=>", "'statedetails'", ")", ")", ";", "case", "quiz_attempt", "::", "FINISHED", ":", "return", "get_string", "(", "'statefinished'", ",", "'quiz'", ")", ".", "html_writer", "::", "tag", "(", "'span'", ",", "get_string", "(", "'statefinisheddetails'", ",", "'quiz'", ",", "userdate", "(", "$", "attemptobj", "->", "get_submitted_date", "(", ")", ")", ")", ",", "array", "(", "'class'", "=>", "'statedetails'", ")", ")", ";", "case", "quiz_attempt", "::", "ABANDONED", ":", "return", "get_string", "(", "'stateabandoned'", ",", "'quiz'", ")", ";", "}", "}" ]
Generate a brief textual desciption of the current state of an attempt. @param quiz_attempt $attemptobj the attempt @param int $timenow the time to use as 'now'. @return string the appropriate lang string to describe the state.
[ "Generate", "a", "brief", "textual", "desciption", "of", "the", "current", "state", "of", "an", "attempt", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/renderer.php#L1108-L1128
214,701
moodle/moodle
mod/quiz/renderer.php
mod_quiz_renderer.view_result_info
public function view_result_info($quiz, $context, $cm, $viewobj) { $output = ''; if (!$viewobj->numattempts && !$viewobj->gradecolumn && is_null($viewobj->mygrade)) { return $output; } $resultinfo = ''; if ($viewobj->overallstats) { if ($viewobj->moreattempts) { $a = new stdClass(); $a->method = quiz_get_grading_option_name($quiz->grademethod); $a->mygrade = quiz_format_grade($quiz, $viewobj->mygrade); $a->quizgrade = quiz_format_grade($quiz, $quiz->grade); $resultinfo .= $this->heading(get_string('gradesofar', 'quiz', $a), 3); } else { $a = new stdClass(); $a->grade = quiz_format_grade($quiz, $viewobj->mygrade); $a->maxgrade = quiz_format_grade($quiz, $quiz->grade); $a = get_string('outofshort', 'quiz', $a); $resultinfo .= $this->heading(get_string('yourfinalgradeis', 'quiz', $a), 3); } } if ($viewobj->mygradeoverridden) { $resultinfo .= html_writer::tag('p', get_string('overriddennotice', 'grades'), array('class' => 'overriddennotice'))."\n"; } if ($viewobj->gradebookfeedback) { $resultinfo .= $this->heading(get_string('comment', 'quiz'), 3); $resultinfo .= html_writer::div($viewobj->gradebookfeedback, 'quizteacherfeedback') . "\n"; } if ($viewobj->feedbackcolumn) { $resultinfo .= $this->heading(get_string('overallfeedback', 'quiz'), 3); $resultinfo .= html_writer::div( quiz_feedback_for_grade($viewobj->mygrade, $quiz, $context), 'quizgradefeedback') . "\n"; } if ($resultinfo) { $output .= $this->box($resultinfo, 'generalbox', 'feedback'); } return $output; }
php
public function view_result_info($quiz, $context, $cm, $viewobj) { $output = ''; if (!$viewobj->numattempts && !$viewobj->gradecolumn && is_null($viewobj->mygrade)) { return $output; } $resultinfo = ''; if ($viewobj->overallstats) { if ($viewobj->moreattempts) { $a = new stdClass(); $a->method = quiz_get_grading_option_name($quiz->grademethod); $a->mygrade = quiz_format_grade($quiz, $viewobj->mygrade); $a->quizgrade = quiz_format_grade($quiz, $quiz->grade); $resultinfo .= $this->heading(get_string('gradesofar', 'quiz', $a), 3); } else { $a = new stdClass(); $a->grade = quiz_format_grade($quiz, $viewobj->mygrade); $a->maxgrade = quiz_format_grade($quiz, $quiz->grade); $a = get_string('outofshort', 'quiz', $a); $resultinfo .= $this->heading(get_string('yourfinalgradeis', 'quiz', $a), 3); } } if ($viewobj->mygradeoverridden) { $resultinfo .= html_writer::tag('p', get_string('overriddennotice', 'grades'), array('class' => 'overriddennotice'))."\n"; } if ($viewobj->gradebookfeedback) { $resultinfo .= $this->heading(get_string('comment', 'quiz'), 3); $resultinfo .= html_writer::div($viewobj->gradebookfeedback, 'quizteacherfeedback') . "\n"; } if ($viewobj->feedbackcolumn) { $resultinfo .= $this->heading(get_string('overallfeedback', 'quiz'), 3); $resultinfo .= html_writer::div( quiz_feedback_for_grade($viewobj->mygrade, $quiz, $context), 'quizgradefeedback') . "\n"; } if ($resultinfo) { $output .= $this->box($resultinfo, 'generalbox', 'feedback'); } return $output; }
[ "public", "function", "view_result_info", "(", "$", "quiz", ",", "$", "context", ",", "$", "cm", ",", "$", "viewobj", ")", "{", "$", "output", "=", "''", ";", "if", "(", "!", "$", "viewobj", "->", "numattempts", "&&", "!", "$", "viewobj", "->", "gradecolumn", "&&", "is_null", "(", "$", "viewobj", "->", "mygrade", ")", ")", "{", "return", "$", "output", ";", "}", "$", "resultinfo", "=", "''", ";", "if", "(", "$", "viewobj", "->", "overallstats", ")", "{", "if", "(", "$", "viewobj", "->", "moreattempts", ")", "{", "$", "a", "=", "new", "stdClass", "(", ")", ";", "$", "a", "->", "method", "=", "quiz_get_grading_option_name", "(", "$", "quiz", "->", "grademethod", ")", ";", "$", "a", "->", "mygrade", "=", "quiz_format_grade", "(", "$", "quiz", ",", "$", "viewobj", "->", "mygrade", ")", ";", "$", "a", "->", "quizgrade", "=", "quiz_format_grade", "(", "$", "quiz", ",", "$", "quiz", "->", "grade", ")", ";", "$", "resultinfo", ".=", "$", "this", "->", "heading", "(", "get_string", "(", "'gradesofar'", ",", "'quiz'", ",", "$", "a", ")", ",", "3", ")", ";", "}", "else", "{", "$", "a", "=", "new", "stdClass", "(", ")", ";", "$", "a", "->", "grade", "=", "quiz_format_grade", "(", "$", "quiz", ",", "$", "viewobj", "->", "mygrade", ")", ";", "$", "a", "->", "maxgrade", "=", "quiz_format_grade", "(", "$", "quiz", ",", "$", "quiz", "->", "grade", ")", ";", "$", "a", "=", "get_string", "(", "'outofshort'", ",", "'quiz'", ",", "$", "a", ")", ";", "$", "resultinfo", ".=", "$", "this", "->", "heading", "(", "get_string", "(", "'yourfinalgradeis'", ",", "'quiz'", ",", "$", "a", ")", ",", "3", ")", ";", "}", "}", "if", "(", "$", "viewobj", "->", "mygradeoverridden", ")", "{", "$", "resultinfo", ".=", "html_writer", "::", "tag", "(", "'p'", ",", "get_string", "(", "'overriddennotice'", ",", "'grades'", ")", ",", "array", "(", "'class'", "=>", "'overriddennotice'", ")", ")", ".", "\"\\n\"", ";", "}", "if", "(", "$", "viewobj", "->", "gradebookfeedback", ")", "{", "$", "resultinfo", ".=", "$", "this", "->", "heading", "(", "get_string", "(", "'comment'", ",", "'quiz'", ")", ",", "3", ")", ";", "$", "resultinfo", ".=", "html_writer", "::", "div", "(", "$", "viewobj", "->", "gradebookfeedback", ",", "'quizteacherfeedback'", ")", ".", "\"\\n\"", ";", "}", "if", "(", "$", "viewobj", "->", "feedbackcolumn", ")", "{", "$", "resultinfo", ".=", "$", "this", "->", "heading", "(", "get_string", "(", "'overallfeedback'", ",", "'quiz'", ")", ",", "3", ")", ";", "$", "resultinfo", ".=", "html_writer", "::", "div", "(", "quiz_feedback_for_grade", "(", "$", "viewobj", "->", "mygrade", ",", "$", "quiz", ",", "$", "context", ")", ",", "'quizgradefeedback'", ")", ".", "\"\\n\"", ";", "}", "if", "(", "$", "resultinfo", ")", "{", "$", "output", ".=", "$", "this", "->", "box", "(", "$", "resultinfo", ",", "'generalbox'", ",", "'feedback'", ")", ";", "}", "return", "$", "output", ";", "}" ]
Generates data pertaining to quiz results @param array $quiz Array containing quiz data @param int $context The page context ID @param int $cm The Course Module Id @param mod_quiz_view_object $viewobj
[ "Generates", "data", "pertaining", "to", "quiz", "results" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/renderer.php#L1138-L1181
214,702
moodle/moodle
mod/quiz/renderer.php
mod_quiz_renderer.review_link
public function review_link($url, $reviewinpopup, $popupoptions) { if ($reviewinpopup) { $button = new single_button($url, get_string('review', 'quiz')); $button->add_action(new popup_action('click', $url, 'quizpopup', $popupoptions)); return $this->render($button); } else { return html_writer::link($url, get_string('review', 'quiz'), array('title' => get_string('reviewthisattempt', 'quiz'))); } }
php
public function review_link($url, $reviewinpopup, $popupoptions) { if ($reviewinpopup) { $button = new single_button($url, get_string('review', 'quiz')); $button->add_action(new popup_action('click', $url, 'quizpopup', $popupoptions)); return $this->render($button); } else { return html_writer::link($url, get_string('review', 'quiz'), array('title' => get_string('reviewthisattempt', 'quiz'))); } }
[ "public", "function", "review_link", "(", "$", "url", ",", "$", "reviewinpopup", ",", "$", "popupoptions", ")", "{", "if", "(", "$", "reviewinpopup", ")", "{", "$", "button", "=", "new", "single_button", "(", "$", "url", ",", "get_string", "(", "'review'", ",", "'quiz'", ")", ")", ";", "$", "button", "->", "add_action", "(", "new", "popup_action", "(", "'click'", ",", "$", "url", ",", "'quizpopup'", ",", "$", "popupoptions", ")", ")", ";", "return", "$", "this", "->", "render", "(", "$", "button", ")", ";", "}", "else", "{", "return", "html_writer", "::", "link", "(", "$", "url", ",", "get_string", "(", "'review'", ",", "'quiz'", ")", ",", "array", "(", "'title'", "=>", "get_string", "(", "'reviewthisattempt'", ",", "'quiz'", ")", ")", ")", ";", "}", "}" ]
Output either a link to the review page for an attempt, or a button to open the review in a popup window. @param moodle_url $url of the target page. @param bool $reviewinpopup whether a pop-up is required. @param array $popupoptions options to pass to the popup_action constructor. @return string HTML to output.
[ "Output", "either", "a", "link", "to", "the", "review", "page", "for", "an", "attempt", "or", "a", "button", "to", "open", "the", "review", "in", "a", "popup", "window", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/renderer.php#L1192-L1202
214,703
moodle/moodle
mod/quiz/renderer.php
mod_quiz_renderer.chart
public function chart(\core\chart_base $chart, $title) { return $this->heading($title, 3) . html_writer::tag('div', $this->render($chart), array('class' => 'graph')); }
php
public function chart(\core\chart_base $chart, $title) { return $this->heading($title, 3) . html_writer::tag('div', $this->render($chart), array('class' => 'graph')); }
[ "public", "function", "chart", "(", "\\", "core", "\\", "chart_base", "$", "chart", ",", "$", "title", ")", "{", "return", "$", "this", "->", "heading", "(", "$", "title", ",", "3", ")", ".", "html_writer", "::", "tag", "(", "'div'", ",", "$", "this", "->", "render", "(", "$", "chart", ")", ",", "array", "(", "'class'", "=>", "'graph'", ")", ")", ";", "}" ]
Outputs a chart. @param \core\chart_base $chart The chart. @param string $title The title to display above the graph. @return string HTML fragment for the graph.
[ "Outputs", "a", "chart", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/renderer.php#L1251-L1253
214,704
moodle/moodle
mod/quiz/renderer.php
mod_quiz_renderer.graph
public function graph(moodle_url $url, $title) { global $CFG; $graph = html_writer::empty_tag('img', array('src' => $url, 'alt' => $title)); return $this->heading($title, 3) . html_writer::tag('div', $graph, array('class' => 'graph')); }
php
public function graph(moodle_url $url, $title) { global $CFG; $graph = html_writer::empty_tag('img', array('src' => $url, 'alt' => $title)); return $this->heading($title, 3) . html_writer::tag('div', $graph, array('class' => 'graph')); }
[ "public", "function", "graph", "(", "moodle_url", "$", "url", ",", "$", "title", ")", "{", "global", "$", "CFG", ";", "$", "graph", "=", "html_writer", "::", "empty_tag", "(", "'img'", ",", "array", "(", "'src'", "=>", "$", "url", ",", "'alt'", "=>", "$", "title", ")", ")", ";", "return", "$", "this", "->", "heading", "(", "$", "title", ",", "3", ")", ".", "html_writer", "::", "tag", "(", "'div'", ",", "$", "graph", ",", "array", "(", "'class'", "=>", "'graph'", ")", ")", ";", "}" ]
Output a graph, or a message saying that GD is required. @param moodle_url $url the URL of the graph. @param string $title the title to display above the graph. @return string HTML fragment for the graph.
[ "Output", "a", "graph", "or", "a", "message", "saying", "that", "GD", "is", "required", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/renderer.php#L1261-L1267
214,705
moodle/moodle
mod/quiz/renderer.php
mod_quiz_renderer.connection_warning
public function connection_warning() { $options = array('filter' => false, 'newlines' => false); $warning = format_text(get_string('connectionerror', 'quiz'), FORMAT_MARKDOWN, $options); $ok = format_text(get_string('connectionok', 'quiz'), FORMAT_MARKDOWN, $options); return html_writer::tag('div', $warning, array('id' => 'connection-error', 'style' => 'display: none;', 'role' => 'alert')) . html_writer::tag('div', $ok, array('id' => 'connection-ok', 'style' => 'display: none;', 'role' => 'alert')); }
php
public function connection_warning() { $options = array('filter' => false, 'newlines' => false); $warning = format_text(get_string('connectionerror', 'quiz'), FORMAT_MARKDOWN, $options); $ok = format_text(get_string('connectionok', 'quiz'), FORMAT_MARKDOWN, $options); return html_writer::tag('div', $warning, array('id' => 'connection-error', 'style' => 'display: none;', 'role' => 'alert')) . html_writer::tag('div', $ok, array('id' => 'connection-ok', 'style' => 'display: none;', 'role' => 'alert')); }
[ "public", "function", "connection_warning", "(", ")", "{", "$", "options", "=", "array", "(", "'filter'", "=>", "false", ",", "'newlines'", "=>", "false", ")", ";", "$", "warning", "=", "format_text", "(", "get_string", "(", "'connectionerror'", ",", "'quiz'", ")", ",", "FORMAT_MARKDOWN", ",", "$", "options", ")", ";", "$", "ok", "=", "format_text", "(", "get_string", "(", "'connectionok'", ",", "'quiz'", ")", ",", "FORMAT_MARKDOWN", ",", "$", "options", ")", ";", "return", "html_writer", "::", "tag", "(", "'div'", ",", "$", "warning", ",", "array", "(", "'id'", "=>", "'connection-error'", ",", "'style'", "=>", "'display: none;'", ",", "'role'", "=>", "'alert'", ")", ")", ".", "html_writer", "::", "tag", "(", "'div'", ",", "$", "ok", ",", "array", "(", "'id'", "=>", "'connection-ok'", ",", "'style'", "=>", "'display: none;'", ",", "'role'", "=>", "'alert'", ")", ")", ";", "}" ]
Output the connection warning messages, which are initially hidden, and only revealed by JavaScript if necessary.
[ "Output", "the", "connection", "warning", "messages", "which", "are", "initially", "hidden", "and", "only", "revealed", "by", "JavaScript", "if", "necessary", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/renderer.php#L1273-L1280
214,706
moodle/moodle
cache/stores/apcu/lib.php
cachestore_apcu.are_requirements_met
public static function are_requirements_met() { $enabled = ini_get('apc.enabled') && (php_sapi_name() != "cli" || ini_get('apc.enable_cli')); if (!extension_loaded('apcu') || !$enabled) { return false; } $version = phpversion('apcu'); return $version && version_compare($version, self::REQUIRED_VERSION, '>='); }
php
public static function are_requirements_met() { $enabled = ini_get('apc.enabled') && (php_sapi_name() != "cli" || ini_get('apc.enable_cli')); if (!extension_loaded('apcu') || !$enabled) { return false; } $version = phpversion('apcu'); return $version && version_compare($version, self::REQUIRED_VERSION, '>='); }
[ "public", "static", "function", "are_requirements_met", "(", ")", "{", "$", "enabled", "=", "ini_get", "(", "'apc.enabled'", ")", "&&", "(", "php_sapi_name", "(", ")", "!=", "\"cli\"", "||", "ini_get", "(", "'apc.enable_cli'", ")", ")", ";", "if", "(", "!", "extension_loaded", "(", "'apcu'", ")", "||", "!", "$", "enabled", ")", "{", "return", "false", ";", "}", "$", "version", "=", "phpversion", "(", "'apcu'", ")", ";", "return", "$", "version", "&&", "version_compare", "(", "$", "version", ",", "self", "::", "REQUIRED_VERSION", ",", "'>='", ")", ";", "}" ]
Static method to check that the APCu stores requirements have been met. It checks that the APCu extension has been loaded and that it has been enabled. @return bool True if the stores software/hardware requirements have been met and it can be used. False otherwise.
[ "Static", "method", "to", "check", "that", "the", "APCu", "stores", "requirements", "have", "been", "met", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/apcu/lib.php#L71-L79
214,707
moodle/moodle
cache/stores/apcu/lib.php
cachestore_apcu.initialise
public function initialise(cache_definition $definition) { $this->definition = $definition; $this->cacheprefix = $this->storeprefix.$definition->generate_definition_hash().'__'; return true; }
php
public function initialise(cache_definition $definition) { $this->definition = $definition; $this->cacheprefix = $this->storeprefix.$definition->generate_definition_hash().'__'; return true; }
[ "public", "function", "initialise", "(", "cache_definition", "$", "definition", ")", "{", "$", "this", "->", "definition", "=", "$", "definition", ";", "$", "this", "->", "cacheprefix", "=", "$", "this", "->", "storeprefix", ".", "$", "definition", "->", "generate_definition_hash", "(", ")", ".", "'__'", ";", "return", "true", ";", "}" ]
Initialises a new instance of the cache store given the definition the instance is to be used for. This function should prepare any given connections etc. @param cache_definition $definition @return bool
[ "Initialises", "a", "new", "instance", "of", "the", "cache", "store", "given", "the", "definition", "the", "instance", "is", "to", "be", "used", "for", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/apcu/lib.php#L144-L148
214,708
moodle/moodle
mod/survey/classes/external.php
mod_survey_external.get_surveys_by_courses_returns
public static function get_surveys_by_courses_returns() { return new external_single_structure( array( 'surveys' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'Survey id'), 'coursemodule' => new external_value(PARAM_INT, 'Course module id'), 'course' => new external_value(PARAM_INT, 'Course id'), 'name' => new external_value(PARAM_RAW, 'Survey name'), 'intro' => new external_value(PARAM_RAW, 'The Survey intro', VALUE_OPTIONAL), 'introformat' => new external_format_value('intro', VALUE_OPTIONAL), 'introfiles' => new external_files('Files in the introduction text', VALUE_OPTIONAL), 'template' => new external_value(PARAM_INT, 'Survey type', VALUE_OPTIONAL), 'days' => new external_value(PARAM_INT, 'Days', VALUE_OPTIONAL), 'questions' => new external_value(PARAM_RAW, 'Question ids', VALUE_OPTIONAL), 'surveydone' => new external_value(PARAM_INT, 'Did I finish the survey?', VALUE_OPTIONAL), 'timecreated' => new external_value(PARAM_INT, 'Time of creation', VALUE_OPTIONAL), 'timemodified' => new external_value(PARAM_INT, 'Time of last modification', VALUE_OPTIONAL), 'section' => new external_value(PARAM_INT, 'Course section id', VALUE_OPTIONAL), 'visible' => new external_value(PARAM_INT, 'Visible', VALUE_OPTIONAL), 'groupmode' => new external_value(PARAM_INT, 'Group mode', VALUE_OPTIONAL), 'groupingid' => new external_value(PARAM_INT, 'Group id', VALUE_OPTIONAL), ), 'Surveys' ) ), 'warnings' => new external_warnings(), ) ); }
php
public static function get_surveys_by_courses_returns() { return new external_single_structure( array( 'surveys' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'Survey id'), 'coursemodule' => new external_value(PARAM_INT, 'Course module id'), 'course' => new external_value(PARAM_INT, 'Course id'), 'name' => new external_value(PARAM_RAW, 'Survey name'), 'intro' => new external_value(PARAM_RAW, 'The Survey intro', VALUE_OPTIONAL), 'introformat' => new external_format_value('intro', VALUE_OPTIONAL), 'introfiles' => new external_files('Files in the introduction text', VALUE_OPTIONAL), 'template' => new external_value(PARAM_INT, 'Survey type', VALUE_OPTIONAL), 'days' => new external_value(PARAM_INT, 'Days', VALUE_OPTIONAL), 'questions' => new external_value(PARAM_RAW, 'Question ids', VALUE_OPTIONAL), 'surveydone' => new external_value(PARAM_INT, 'Did I finish the survey?', VALUE_OPTIONAL), 'timecreated' => new external_value(PARAM_INT, 'Time of creation', VALUE_OPTIONAL), 'timemodified' => new external_value(PARAM_INT, 'Time of last modification', VALUE_OPTIONAL), 'section' => new external_value(PARAM_INT, 'Course section id', VALUE_OPTIONAL), 'visible' => new external_value(PARAM_INT, 'Visible', VALUE_OPTIONAL), 'groupmode' => new external_value(PARAM_INT, 'Group mode', VALUE_OPTIONAL), 'groupingid' => new external_value(PARAM_INT, 'Group id', VALUE_OPTIONAL), ), 'Surveys' ) ), 'warnings' => new external_warnings(), ) ); }
[ "public", "static", "function", "get_surveys_by_courses_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'surveys'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Survey id'", ")", ",", "'coursemodule'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Course module id'", ")", ",", "'course'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Course id'", ")", ",", "'name'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Survey name'", ")", ",", "'intro'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'The Survey intro'", ",", "VALUE_OPTIONAL", ")", ",", "'introformat'", "=>", "new", "external_format_value", "(", "'intro'", ",", "VALUE_OPTIONAL", ")", ",", "'introfiles'", "=>", "new", "external_files", "(", "'Files in the introduction text'", ",", "VALUE_OPTIONAL", ")", ",", "'template'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Survey type'", ",", "VALUE_OPTIONAL", ")", ",", "'days'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Days'", ",", "VALUE_OPTIONAL", ")", ",", "'questions'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Question ids'", ",", "VALUE_OPTIONAL", ")", ",", "'surveydone'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Did I finish the survey?'", ",", "VALUE_OPTIONAL", ")", ",", "'timecreated'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Time of creation'", ",", "VALUE_OPTIONAL", ")", ",", "'timemodified'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Time of last modification'", ",", "VALUE_OPTIONAL", ")", ",", "'section'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Course section id'", ",", "VALUE_OPTIONAL", ")", ",", "'visible'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Visible'", ",", "VALUE_OPTIONAL", ")", ",", "'groupmode'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Group mode'", ",", "VALUE_OPTIONAL", ")", ",", "'groupingid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Group id'", ",", "VALUE_OPTIONAL", ")", ",", ")", ",", "'Surveys'", ")", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ",", ")", ")", ";", "}" ]
Describes the get_surveys_by_courses return value. @return external_single_structure @since Moodle 3.0
[ "Describes", "the", "get_surveys_by_courses", "return", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/survey/classes/external.php#L142-L171
214,709
moodle/moodle
mod/survey/classes/external.php
mod_survey_external.get_questions
public static function get_questions($surveyid) { global $DB, $USER; $params = self::validate_parameters(self::get_questions_parameters(), array( 'surveyid' => $surveyid )); $warnings = array(); // Request and permission validation. $survey = $DB->get_record('survey', array('id' => $params['surveyid']), '*', MUST_EXIST); list($course, $cm) = get_course_and_cm_from_instance($survey, 'survey'); $context = context_module::instance($cm->id); self::validate_context($context); require_capability('mod/survey:participate', $context); $mainquestions = survey_get_questions($survey); foreach ($mainquestions as $question) { if ($question->type >= 0) { // Parent is used in subquestions. $question->parent = 0; $questions[] = survey_translate_question($question); // Check if the question has subquestions. if ($question->multi) { $subquestions = survey_get_subquestions($question); foreach ($subquestions as $sq) { $sq->parent = $question->id; $questions[] = survey_translate_question($sq); } } } } $result = array(); $result['questions'] = $questions; $result['warnings'] = $warnings; return $result; }
php
public static function get_questions($surveyid) { global $DB, $USER; $params = self::validate_parameters(self::get_questions_parameters(), array( 'surveyid' => $surveyid )); $warnings = array(); // Request and permission validation. $survey = $DB->get_record('survey', array('id' => $params['surveyid']), '*', MUST_EXIST); list($course, $cm) = get_course_and_cm_from_instance($survey, 'survey'); $context = context_module::instance($cm->id); self::validate_context($context); require_capability('mod/survey:participate', $context); $mainquestions = survey_get_questions($survey); foreach ($mainquestions as $question) { if ($question->type >= 0) { // Parent is used in subquestions. $question->parent = 0; $questions[] = survey_translate_question($question); // Check if the question has subquestions. if ($question->multi) { $subquestions = survey_get_subquestions($question); foreach ($subquestions as $sq) { $sq->parent = $question->id; $questions[] = survey_translate_question($sq); } } } } $result = array(); $result['questions'] = $questions; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "get_questions", "(", "$", "surveyid", ")", "{", "global", "$", "DB", ",", "$", "USER", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_questions_parameters", "(", ")", ",", "array", "(", "'surveyid'", "=>", "$", "surveyid", ")", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "// Request and permission validation.", "$", "survey", "=", "$", "DB", "->", "get_record", "(", "'survey'", ",", "array", "(", "'id'", "=>", "$", "params", "[", "'surveyid'", "]", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "list", "(", "$", "course", ",", "$", "cm", ")", "=", "get_course_and_cm_from_instance", "(", "$", "survey", ",", "'survey'", ")", ";", "$", "context", "=", "context_module", "::", "instance", "(", "$", "cm", "->", "id", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "require_capability", "(", "'mod/survey:participate'", ",", "$", "context", ")", ";", "$", "mainquestions", "=", "survey_get_questions", "(", "$", "survey", ")", ";", "foreach", "(", "$", "mainquestions", "as", "$", "question", ")", "{", "if", "(", "$", "question", "->", "type", ">=", "0", ")", "{", "// Parent is used in subquestions.", "$", "question", "->", "parent", "=", "0", ";", "$", "questions", "[", "]", "=", "survey_translate_question", "(", "$", "question", ")", ";", "// Check if the question has subquestions.", "if", "(", "$", "question", "->", "multi", ")", "{", "$", "subquestions", "=", "survey_get_subquestions", "(", "$", "question", ")", ";", "foreach", "(", "$", "subquestions", "as", "$", "sq", ")", "{", "$", "sq", "->", "parent", "=", "$", "question", "->", "id", ";", "$", "questions", "[", "]", "=", "survey_translate_question", "(", "$", "sq", ")", ";", "}", "}", "}", "}", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'questions'", "]", "=", "$", "questions", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Get the complete list of questions for the survey, including subquestions. @param int $surveyid the survey instance id @return array of warnings and the question list @since Moodle 3.0 @throws moodle_exception
[ "Get", "the", "complete", "list", "of", "questions", "for", "the", "survey", "including", "subquestions", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/survey/classes/external.php#L260-L300
214,710
moodle/moodle
mod/survey/classes/external.php
mod_survey_external.submit_answers_parameters
public static function submit_answers_parameters() { return new external_function_parameters( array( 'surveyid' => new external_value(PARAM_INT, 'Survey id'), 'answers' => new external_multiple_structure( new external_single_structure( array( 'key' => new external_value(PARAM_RAW, 'Answer key'), 'value' => new external_value(PARAM_RAW, 'Answer value') ) ) ), ) ); }
php
public static function submit_answers_parameters() { return new external_function_parameters( array( 'surveyid' => new external_value(PARAM_INT, 'Survey id'), 'answers' => new external_multiple_structure( new external_single_structure( array( 'key' => new external_value(PARAM_RAW, 'Answer key'), 'value' => new external_value(PARAM_RAW, 'Answer value') ) ) ), ) ); }
[ "public", "static", "function", "submit_answers_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'surveyid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Survey id'", ")", ",", "'answers'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'key'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Answer key'", ")", ",", "'value'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Answer value'", ")", ")", ")", ")", ",", ")", ")", ";", "}" ]
Describes the parameters for submit_answers. @return external_function_parameters @since Moodle 3.0
[ "Describes", "the", "parameters", "for", "submit_answers", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/survey/classes/external.php#L336-L350
214,711
moodle/moodle
mod/survey/classes/external.php
mod_survey_external.submit_answers
public static function submit_answers($surveyid, $answers) { global $DB, $USER; $params = self::validate_parameters(self::submit_answers_parameters(), array( 'surveyid' => $surveyid, 'answers' => $answers )); $warnings = array(); // Request and permission validation. $survey = $DB->get_record('survey', array('id' => $params['surveyid']), '*', MUST_EXIST); list($course, $cm) = get_course_and_cm_from_instance($survey, 'survey'); $context = context_module::instance($cm->id); self::validate_context($context); require_capability('mod/survey:participate', $context); if (survey_already_done($survey->id, $USER->id)) { throw new moodle_exception("alreadysubmitted", "survey"); } // Build the answers array. Data is cleaned inside the survey_save_answers function. $answers = array(); foreach ($params['answers'] as $answer) { $key = $answer['key']; $answers[$key] = $answer['value']; } survey_save_answers($survey, $answers, $course, $context); $result = array(); $result['status'] = true; $result['warnings'] = $warnings; return $result; }
php
public static function submit_answers($surveyid, $answers) { global $DB, $USER; $params = self::validate_parameters(self::submit_answers_parameters(), array( 'surveyid' => $surveyid, 'answers' => $answers )); $warnings = array(); // Request and permission validation. $survey = $DB->get_record('survey', array('id' => $params['surveyid']), '*', MUST_EXIST); list($course, $cm) = get_course_and_cm_from_instance($survey, 'survey'); $context = context_module::instance($cm->id); self::validate_context($context); require_capability('mod/survey:participate', $context); if (survey_already_done($survey->id, $USER->id)) { throw new moodle_exception("alreadysubmitted", "survey"); } // Build the answers array. Data is cleaned inside the survey_save_answers function. $answers = array(); foreach ($params['answers'] as $answer) { $key = $answer['key']; $answers[$key] = $answer['value']; } survey_save_answers($survey, $answers, $course, $context); $result = array(); $result['status'] = true; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "submit_answers", "(", "$", "surveyid", ",", "$", "answers", ")", "{", "global", "$", "DB", ",", "$", "USER", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "submit_answers_parameters", "(", ")", ",", "array", "(", "'surveyid'", "=>", "$", "surveyid", ",", "'answers'", "=>", "$", "answers", ")", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "// Request and permission validation.", "$", "survey", "=", "$", "DB", "->", "get_record", "(", "'survey'", ",", "array", "(", "'id'", "=>", "$", "params", "[", "'surveyid'", "]", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "list", "(", "$", "course", ",", "$", "cm", ")", "=", "get_course_and_cm_from_instance", "(", "$", "survey", ",", "'survey'", ")", ";", "$", "context", "=", "context_module", "::", "instance", "(", "$", "cm", "->", "id", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "require_capability", "(", "'mod/survey:participate'", ",", "$", "context", ")", ";", "if", "(", "survey_already_done", "(", "$", "survey", "->", "id", ",", "$", "USER", "->", "id", ")", ")", "{", "throw", "new", "moodle_exception", "(", "\"alreadysubmitted\"", ",", "\"survey\"", ")", ";", "}", "// Build the answers array. Data is cleaned inside the survey_save_answers function.", "$", "answers", "=", "array", "(", ")", ";", "foreach", "(", "$", "params", "[", "'answers'", "]", "as", "$", "answer", ")", "{", "$", "key", "=", "$", "answer", "[", "'key'", "]", ";", "$", "answers", "[", "$", "key", "]", "=", "$", "answer", "[", "'value'", "]", ";", "}", "survey_save_answers", "(", "$", "survey", ",", "$", "answers", ",", "$", "course", ",", "$", "context", ")", ";", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'status'", "]", "=", "true", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Submit the answers for a given survey. @param int $surveyid the survey instance id @param array $answers the survey answers @return array of warnings and status result @since Moodle 3.0 @throws moodle_exception
[ "Submit", "the", "answers", "for", "a", "given", "survey", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/survey/classes/external.php#L361-L396
214,712
moodle/moodle
analytics/classes/insights_generator.php
insights_generator.generate
public function generate($samplecontexts, $predictions) { global $OUTPUT; $analyserclass = $this->target->get_analyser_class(); // We will need to restore it later. $actuallanguage = current_language(); if ($analyserclass::one_sample_per_analysable()) { // Iterate through the predictions and the users in each prediction (likely to be just one). foreach ($predictions as $prediction) { $context = $samplecontexts[$prediction->get_prediction_data()->contextid]; $users = $this->target->get_insights_users($context); foreach ($users as $user) { $this->set_notification_language($user); list($insighturl, $fullmessage, $fullmessagehtml) = $this->prediction_info($prediction); $this->notification($context, $user, $insighturl, $fullmessage, $fullmessagehtml); } } } else { // Iterate through the context and the users in each context. foreach ($samplecontexts as $context) { $users = $this->target->get_insights_users($context); foreach ($users as $user) { $this->set_notification_language($user); $insighturl = $this->target->get_insight_context_url($this->modelid, $context); $fullmessage = get_string('insightinfomessage', 'analytics', $insighturl->out(false)); $fullmessagehtml = $OUTPUT->render_from_template('core_analytics/insight_info_message', ['url' => $insighturl->out(false)] ); $this->notification($context, $user, $insighturl, $fullmessage, $fullmessagehtml); } } } force_current_language($actuallanguage); }
php
public function generate($samplecontexts, $predictions) { global $OUTPUT; $analyserclass = $this->target->get_analyser_class(); // We will need to restore it later. $actuallanguage = current_language(); if ($analyserclass::one_sample_per_analysable()) { // Iterate through the predictions and the users in each prediction (likely to be just one). foreach ($predictions as $prediction) { $context = $samplecontexts[$prediction->get_prediction_data()->contextid]; $users = $this->target->get_insights_users($context); foreach ($users as $user) { $this->set_notification_language($user); list($insighturl, $fullmessage, $fullmessagehtml) = $this->prediction_info($prediction); $this->notification($context, $user, $insighturl, $fullmessage, $fullmessagehtml); } } } else { // Iterate through the context and the users in each context. foreach ($samplecontexts as $context) { $users = $this->target->get_insights_users($context); foreach ($users as $user) { $this->set_notification_language($user); $insighturl = $this->target->get_insight_context_url($this->modelid, $context); $fullmessage = get_string('insightinfomessage', 'analytics', $insighturl->out(false)); $fullmessagehtml = $OUTPUT->render_from_template('core_analytics/insight_info_message', ['url' => $insighturl->out(false)] ); $this->notification($context, $user, $insighturl, $fullmessage, $fullmessagehtml); } } } force_current_language($actuallanguage); }
[ "public", "function", "generate", "(", "$", "samplecontexts", ",", "$", "predictions", ")", "{", "global", "$", "OUTPUT", ";", "$", "analyserclass", "=", "$", "this", "->", "target", "->", "get_analyser_class", "(", ")", ";", "// We will need to restore it later.", "$", "actuallanguage", "=", "current_language", "(", ")", ";", "if", "(", "$", "analyserclass", "::", "one_sample_per_analysable", "(", ")", ")", "{", "// Iterate through the predictions and the users in each prediction (likely to be just one).", "foreach", "(", "$", "predictions", "as", "$", "prediction", ")", "{", "$", "context", "=", "$", "samplecontexts", "[", "$", "prediction", "->", "get_prediction_data", "(", ")", "->", "contextid", "]", ";", "$", "users", "=", "$", "this", "->", "target", "->", "get_insights_users", "(", "$", "context", ")", ";", "foreach", "(", "$", "users", "as", "$", "user", ")", "{", "$", "this", "->", "set_notification_language", "(", "$", "user", ")", ";", "list", "(", "$", "insighturl", ",", "$", "fullmessage", ",", "$", "fullmessagehtml", ")", "=", "$", "this", "->", "prediction_info", "(", "$", "prediction", ")", ";", "$", "this", "->", "notification", "(", "$", "context", ",", "$", "user", ",", "$", "insighturl", ",", "$", "fullmessage", ",", "$", "fullmessagehtml", ")", ";", "}", "}", "}", "else", "{", "// Iterate through the context and the users in each context.", "foreach", "(", "$", "samplecontexts", "as", "$", "context", ")", "{", "$", "users", "=", "$", "this", "->", "target", "->", "get_insights_users", "(", "$", "context", ")", ";", "foreach", "(", "$", "users", "as", "$", "user", ")", "{", "$", "this", "->", "set_notification_language", "(", "$", "user", ")", ";", "$", "insighturl", "=", "$", "this", "->", "target", "->", "get_insight_context_url", "(", "$", "this", "->", "modelid", ",", "$", "context", ")", ";", "$", "fullmessage", "=", "get_string", "(", "'insightinfomessage'", ",", "'analytics'", ",", "$", "insighturl", "->", "out", "(", "false", ")", ")", ";", "$", "fullmessagehtml", "=", "$", "OUTPUT", "->", "render_from_template", "(", "'core_analytics/insight_info_message'", ",", "[", "'url'", "=>", "$", "insighturl", "->", "out", "(", "false", ")", "]", ")", ";", "$", "this", "->", "notification", "(", "$", "context", ",", "$", "user", ",", "$", "insighturl", ",", "$", "fullmessage", ",", "$", "fullmessagehtml", ")", ";", "}", "}", "}", "force_current_language", "(", "$", "actuallanguage", ")", ";", "}" ]
Generates insight notifications. @param array $samplecontexts The contexts these predictions belong to @param \core_analytics\prediction[] $predictions The prediction records @return null
[ "Generates", "insight", "notifications", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/insights_generator.php#L73-L120
214,713
moodle/moodle
analytics/classes/insights_generator.php
insights_generator.notification
private function notification(\context $context, \stdClass $user, \moodle_url $insighturl, string $fullmessage, string $fullmessagehtml) { $message = new \core\message\message(); $message->component = 'moodle'; $message->name = 'insights'; $message->userfrom = \core_user::get_noreply_user(); $message->userto = $user; $message->subject = $this->target->get_insight_subject($this->modelid, $context); // Same than the subject. $message->contexturlname = $message->subject; $message->courseid = $this->get_context_courseid($context); $message->fullmessage = $fullmessage; $message->fullmessageformat = FORMAT_PLAIN; $message->fullmessagehtml = $fullmessagehtml; $message->smallmessage = $fullmessage; $message->contexturl = $insighturl->out(false); message_send($message); }
php
private function notification(\context $context, \stdClass $user, \moodle_url $insighturl, string $fullmessage, string $fullmessagehtml) { $message = new \core\message\message(); $message->component = 'moodle'; $message->name = 'insights'; $message->userfrom = \core_user::get_noreply_user(); $message->userto = $user; $message->subject = $this->target->get_insight_subject($this->modelid, $context); // Same than the subject. $message->contexturlname = $message->subject; $message->courseid = $this->get_context_courseid($context); $message->fullmessage = $fullmessage; $message->fullmessageformat = FORMAT_PLAIN; $message->fullmessagehtml = $fullmessagehtml; $message->smallmessage = $fullmessage; $message->contexturl = $insighturl->out(false); message_send($message); }
[ "private", "function", "notification", "(", "\\", "context", "$", "context", ",", "\\", "stdClass", "$", "user", ",", "\\", "moodle_url", "$", "insighturl", ",", "string", "$", "fullmessage", ",", "string", "$", "fullmessagehtml", ")", "{", "$", "message", "=", "new", "\\", "core", "\\", "message", "\\", "message", "(", ")", ";", "$", "message", "->", "component", "=", "'moodle'", ";", "$", "message", "->", "name", "=", "'insights'", ";", "$", "message", "->", "userfrom", "=", "\\", "core_user", "::", "get_noreply_user", "(", ")", ";", "$", "message", "->", "userto", "=", "$", "user", ";", "$", "message", "->", "subject", "=", "$", "this", "->", "target", "->", "get_insight_subject", "(", "$", "this", "->", "modelid", ",", "$", "context", ")", ";", "// Same than the subject.", "$", "message", "->", "contexturlname", "=", "$", "message", "->", "subject", ";", "$", "message", "->", "courseid", "=", "$", "this", "->", "get_context_courseid", "(", "$", "context", ")", ";", "$", "message", "->", "fullmessage", "=", "$", "fullmessage", ";", "$", "message", "->", "fullmessageformat", "=", "FORMAT_PLAIN", ";", "$", "message", "->", "fullmessagehtml", "=", "$", "fullmessagehtml", ";", "$", "message", "->", "smallmessage", "=", "$", "fullmessage", ";", "$", "message", "->", "contexturl", "=", "$", "insighturl", "->", "out", "(", "false", ")", ";", "message_send", "(", "$", "message", ")", ";", "}" ]
Generates a insight notification for the user. @param \context $context @param \stdClass $user @param \moodle_url $insighturl The insight URL @param string $fullmessage @param string $fullmessagehtml @return null
[ "Generates", "a", "insight", "notification", "for", "the", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/insights_generator.php#L132-L154
214,714
moodle/moodle
analytics/classes/insights_generator.php
insights_generator.get_context_courseid
private function get_context_courseid(\context $context) { if (empty($this->contextcourseids[$context->id])) { $coursecontext = $context->get_course_context(false); if (!$coursecontext) { // Default to the frontpage course context. $coursecontext = \context_course::instance(SITEID); } $this->contextcourseids[$context->id] = $coursecontext->instanceid; } return $this->contextcourseids[$context->id]; }
php
private function get_context_courseid(\context $context) { if (empty($this->contextcourseids[$context->id])) { $coursecontext = $context->get_course_context(false); if (!$coursecontext) { // Default to the frontpage course context. $coursecontext = \context_course::instance(SITEID); } $this->contextcourseids[$context->id] = $coursecontext->instanceid; } return $this->contextcourseids[$context->id]; }
[ "private", "function", "get_context_courseid", "(", "\\", "context", "$", "context", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "contextcourseids", "[", "$", "context", "->", "id", "]", ")", ")", "{", "$", "coursecontext", "=", "$", "context", "->", "get_course_context", "(", "false", ")", ";", "if", "(", "!", "$", "coursecontext", ")", "{", "// Default to the frontpage course context.", "$", "coursecontext", "=", "\\", "context_course", "::", "instance", "(", "SITEID", ")", ";", "}", "$", "this", "->", "contextcourseids", "[", "$", "context", "->", "id", "]", "=", "$", "coursecontext", "->", "instanceid", ";", "}", "return", "$", "this", "->", "contextcourseids", "[", "$", "context", "->", "id", "]", ";", "}" ]
Returns the course context of the provided context reading an internal cache first. @param \context $context @return int
[ "Returns", "the", "course", "context", "of", "the", "provided", "context", "reading", "an", "internal", "cache", "first", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/insights_generator.php#L162-L175
214,715
moodle/moodle
analytics/classes/insights_generator.php
insights_generator.prediction_info
private function prediction_info(\core_analytics\prediction $prediction) { global $OUTPUT; $predictionactions = $this->target->prediction_actions($prediction, true, true); // For FORMAT_PLAIN. $fullmessageplaintext = ''; // For FORMAT_HTML. $messageactions = []; $insighturl = null; foreach ($predictionactions as $action) { $actionurl = $action->get_url(); if (!$actionurl->get_param('forwardurl')) { $actiondoneurl = new \moodle_url('/report/insights/done.php'); // Set the forward url to the 'done' script. $actionurl->param('forwardurl', $actiondoneurl->out(false)); } if (empty($insighturl)) { // We use the primary action url as insight url so we log that the user followed the provided link. $insighturl = $action->get_url(); } $actiondata = (object)['url' => $action->get_url()->out(false), 'text' => $action->get_text()]; $fullmessageplaintext .= get_string('insightinfomessageaction', 'analytics', $actiondata) . PHP_EOL; $messageactions[] = $actiondata; } $fullmessagehtml = $OUTPUT->render_from_template('core_analytics/insight_info_message_prediction', ['actions' => $messageactions]); return [$insighturl, $fullmessageplaintext, $fullmessagehtml]; }
php
private function prediction_info(\core_analytics\prediction $prediction) { global $OUTPUT; $predictionactions = $this->target->prediction_actions($prediction, true, true); // For FORMAT_PLAIN. $fullmessageplaintext = ''; // For FORMAT_HTML. $messageactions = []; $insighturl = null; foreach ($predictionactions as $action) { $actionurl = $action->get_url(); if (!$actionurl->get_param('forwardurl')) { $actiondoneurl = new \moodle_url('/report/insights/done.php'); // Set the forward url to the 'done' script. $actionurl->param('forwardurl', $actiondoneurl->out(false)); } if (empty($insighturl)) { // We use the primary action url as insight url so we log that the user followed the provided link. $insighturl = $action->get_url(); } $actiondata = (object)['url' => $action->get_url()->out(false), 'text' => $action->get_text()]; $fullmessageplaintext .= get_string('insightinfomessageaction', 'analytics', $actiondata) . PHP_EOL; $messageactions[] = $actiondata; } $fullmessagehtml = $OUTPUT->render_from_template('core_analytics/insight_info_message_prediction', ['actions' => $messageactions]); return [$insighturl, $fullmessageplaintext, $fullmessagehtml]; }
[ "private", "function", "prediction_info", "(", "\\", "core_analytics", "\\", "prediction", "$", "prediction", ")", "{", "global", "$", "OUTPUT", ";", "$", "predictionactions", "=", "$", "this", "->", "target", "->", "prediction_actions", "(", "$", "prediction", ",", "true", ",", "true", ")", ";", "// For FORMAT_PLAIN.", "$", "fullmessageplaintext", "=", "''", ";", "// For FORMAT_HTML.", "$", "messageactions", "=", "[", "]", ";", "$", "insighturl", "=", "null", ";", "foreach", "(", "$", "predictionactions", "as", "$", "action", ")", "{", "$", "actionurl", "=", "$", "action", "->", "get_url", "(", ")", ";", "if", "(", "!", "$", "actionurl", "->", "get_param", "(", "'forwardurl'", ")", ")", "{", "$", "actiondoneurl", "=", "new", "\\", "moodle_url", "(", "'/report/insights/done.php'", ")", ";", "// Set the forward url to the 'done' script.", "$", "actionurl", "->", "param", "(", "'forwardurl'", ",", "$", "actiondoneurl", "->", "out", "(", "false", ")", ")", ";", "}", "if", "(", "empty", "(", "$", "insighturl", ")", ")", "{", "// We use the primary action url as insight url so we log that the user followed the provided link.", "$", "insighturl", "=", "$", "action", "->", "get_url", "(", ")", ";", "}", "$", "actiondata", "=", "(", "object", ")", "[", "'url'", "=>", "$", "action", "->", "get_url", "(", ")", "->", "out", "(", "false", ")", ",", "'text'", "=>", "$", "action", "->", "get_text", "(", ")", "]", ";", "$", "fullmessageplaintext", ".=", "get_string", "(", "'insightinfomessageaction'", ",", "'analytics'", ",", "$", "actiondata", ")", ".", "PHP_EOL", ";", "$", "messageactions", "[", "]", "=", "$", "actiondata", ";", "}", "$", "fullmessagehtml", "=", "$", "OUTPUT", "->", "render_from_template", "(", "'core_analytics/insight_info_message_prediction'", ",", "[", "'actions'", "=>", "$", "messageactions", "]", ")", ";", "return", "[", "$", "insighturl", ",", "$", "fullmessageplaintext", ",", "$", "fullmessagehtml", "]", ";", "}" ]
Extracts info from the prediction for display purposes. @param \core_analytics\prediction $prediction @return array Three items array with formats [\moodle_url, string, string]
[ "Extracts", "info", "from", "the", "prediction", "for", "display", "purposes", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/insights_generator.php#L183-L215
214,716
moodle/moodle
analytics/classes/insights_generator.php
insights_generator.set_notification_language
private function set_notification_language($user) { global $CFG; // Copied from current_language(). if (!empty($user->lang)) { $lang = $user->lang; } else if (isset($CFG->lang)) { $lang = $CFG->lang; } else { $lang = 'en'; } force_current_language($lang); }
php
private function set_notification_language($user) { global $CFG; // Copied from current_language(). if (!empty($user->lang)) { $lang = $user->lang; } else if (isset($CFG->lang)) { $lang = $CFG->lang; } else { $lang = 'en'; } force_current_language($lang); }
[ "private", "function", "set_notification_language", "(", "$", "user", ")", "{", "global", "$", "CFG", ";", "// Copied from current_language().", "if", "(", "!", "empty", "(", "$", "user", "->", "lang", ")", ")", "{", "$", "lang", "=", "$", "user", "->", "lang", ";", "}", "else", "if", "(", "isset", "(", "$", "CFG", "->", "lang", ")", ")", "{", "$", "lang", "=", "$", "CFG", "->", "lang", ";", "}", "else", "{", "$", "lang", "=", "'en'", ";", "}", "force_current_language", "(", "$", "lang", ")", ";", "}" ]
Sets the session language to the language used by the notification receiver. @param \stdClass $user The user who will receive the message @return null
[ "Sets", "the", "session", "language", "to", "the", "language", "used", "by", "the", "notification", "receiver", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/insights_generator.php#L223-L235
214,717
moodle/moodle
grade/grading/classes/privacy/provider.php
provider.export_item_data
public static function export_item_data(\context $context, int $itemid, array $subcontext) { global $DB; $sql = "SELECT gi.id AS instanceid, gd.id AS definitionid, gd.method FROM {grading_areas} ga JOIN {grading_definitions} gd ON gd.areaid = ga.id JOIN {grading_instances} gi ON gi.definitionid = gd.id AND gi.itemid = :itemid WHERE ga.contextid = :contextid"; $params = [ 'itemid' => $itemid, 'contextid' => $context->id, ]; $records = $DB->get_recordset_sql($sql, $params); foreach ($records as $record) { $instancedata = manager::component_class_callback( "gradingform_{$record->method}", gradingform_provider_v2::class, 'export_gradingform_instance_data', [$context, $record->instanceid, $subcontext] ); } $records->close(); }
php
public static function export_item_data(\context $context, int $itemid, array $subcontext) { global $DB; $sql = "SELECT gi.id AS instanceid, gd.id AS definitionid, gd.method FROM {grading_areas} ga JOIN {grading_definitions} gd ON gd.areaid = ga.id JOIN {grading_instances} gi ON gi.definitionid = gd.id AND gi.itemid = :itemid WHERE ga.contextid = :contextid"; $params = [ 'itemid' => $itemid, 'contextid' => $context->id, ]; $records = $DB->get_recordset_sql($sql, $params); foreach ($records as $record) { $instancedata = manager::component_class_callback( "gradingform_{$record->method}", gradingform_provider_v2::class, 'export_gradingform_instance_data', [$context, $record->instanceid, $subcontext] ); } $records->close(); }
[ "public", "static", "function", "export_item_data", "(", "\\", "context", "$", "context", ",", "int", "$", "itemid", ",", "array", "$", "subcontext", ")", "{", "global", "$", "DB", ";", "$", "sql", "=", "\"SELECT gi.id AS instanceid, gd.id AS definitionid, gd.method\n FROM {grading_areas} ga\n JOIN {grading_definitions} gd ON gd.areaid = ga.id\n JOIN {grading_instances} gi ON gi.definitionid = gd.id AND gi.itemid = :itemid\n WHERE ga.contextid = :contextid\"", ";", "$", "params", "=", "[", "'itemid'", "=>", "$", "itemid", ",", "'contextid'", "=>", "$", "context", "->", "id", ",", "]", ";", "$", "records", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "foreach", "(", "$", "records", "as", "$", "record", ")", "{", "$", "instancedata", "=", "manager", "::", "component_class_callback", "(", "\"gradingform_{$record->method}\"", ",", "gradingform_provider_v2", "::", "class", ",", "'export_gradingform_instance_data'", ",", "[", "$", "context", ",", "$", "record", "->", "instanceid", ",", "$", "subcontext", "]", ")", ";", "}", "$", "records", "->", "close", "(", ")", ";", "}" ]
Export all user data related to a context and itemid. @param \context $context Context to export on. @param int $itemid Item ID to export on. @param array $subcontext Directory location to export to.
[ "Export", "all", "user", "data", "related", "to", "a", "context", "and", "itemid", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/classes/privacy/provider.php#L173-L195
214,718
moodle/moodle
grade/grading/classes/privacy/provider.php
provider.delete_instance_data
public static function delete_instance_data(\context $context, int $itemid = null) { if (is_null($itemid)) { self::delete_data_for_instances($context); } else { self::delete_data_for_instances($context, [$itemid]); } }
php
public static function delete_instance_data(\context $context, int $itemid = null) { if (is_null($itemid)) { self::delete_data_for_instances($context); } else { self::delete_data_for_instances($context, [$itemid]); } }
[ "public", "static", "function", "delete_instance_data", "(", "\\", "context", "$", "context", ",", "int", "$", "itemid", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "itemid", ")", ")", "{", "self", "::", "delete_data_for_instances", "(", "$", "context", ")", ";", "}", "else", "{", "self", "::", "delete_data_for_instances", "(", "$", "context", ",", "[", "$", "itemid", "]", ")", ";", "}", "}" ]
Deletes all user data related to a context and possibly an itemid. @param \context $context The context to delete on. @param int|null $itemid An optional item ID to refine the deletion.
[ "Deletes", "all", "user", "data", "related", "to", "a", "context", "and", "possibly", "an", "itemid", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/classes/privacy/provider.php#L203-L209
214,719
moodle/moodle
grade/grading/classes/privacy/provider.php
provider.delete_data_for_instances
public static function delete_data_for_instances(\context $context, array $itemids = []) { global $DB; $itemsql = ''; $params = ['contextid' => $context->id]; if (!empty($itemids)) { list($itemsql, $itemparams) = $DB->get_in_or_equal($itemids, SQL_PARAMS_NAMED); $params = array_merge($params, $itemparams); $itemsql = "AND itemid $itemsql"; } $sql = "SELECT gi.id AS instanceid, gd.id, gd.method FROM {grading_definitions} gd JOIN {grading_instances} gi ON gi.definitionid = gd.id JOIN {grading_areas} ga ON ga.id = gd.areaid WHERE ga.contextid = :contextid $itemsql"; $records = $DB->get_records_sql($sql, $params); if ($records) { $firstrecord = current($records); $method = $firstrecord->method; $instanceids = array_map(function($record) { return $record->instanceid; }, $records); manager::component_class_callback( "gradingform_{$method}", gradingform_provider_v2::class, 'delete_gradingform_for_instances', [$instanceids]); // Delete grading_instances rows. $DB->delete_records_list('grading_instances', 'id', $instanceids); } }
php
public static function delete_data_for_instances(\context $context, array $itemids = []) { global $DB; $itemsql = ''; $params = ['contextid' => $context->id]; if (!empty($itemids)) { list($itemsql, $itemparams) = $DB->get_in_or_equal($itemids, SQL_PARAMS_NAMED); $params = array_merge($params, $itemparams); $itemsql = "AND itemid $itemsql"; } $sql = "SELECT gi.id AS instanceid, gd.id, gd.method FROM {grading_definitions} gd JOIN {grading_instances} gi ON gi.definitionid = gd.id JOIN {grading_areas} ga ON ga.id = gd.areaid WHERE ga.contextid = :contextid $itemsql"; $records = $DB->get_records_sql($sql, $params); if ($records) { $firstrecord = current($records); $method = $firstrecord->method; $instanceids = array_map(function($record) { return $record->instanceid; }, $records); manager::component_class_callback( "gradingform_{$method}", gradingform_provider_v2::class, 'delete_gradingform_for_instances', [$instanceids]); // Delete grading_instances rows. $DB->delete_records_list('grading_instances', 'id', $instanceids); } }
[ "public", "static", "function", "delete_data_for_instances", "(", "\\", "context", "$", "context", ",", "array", "$", "itemids", "=", "[", "]", ")", "{", "global", "$", "DB", ";", "$", "itemsql", "=", "''", ";", "$", "params", "=", "[", "'contextid'", "=>", "$", "context", "->", "id", "]", ";", "if", "(", "!", "empty", "(", "$", "itemids", ")", ")", "{", "list", "(", "$", "itemsql", ",", "$", "itemparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "itemids", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "params", "=", "array_merge", "(", "$", "params", ",", "$", "itemparams", ")", ";", "$", "itemsql", "=", "\"AND itemid $itemsql\"", ";", "}", "$", "sql", "=", "\"SELECT gi.id AS instanceid, gd.id, gd.method\n FROM {grading_definitions} gd\n JOIN {grading_instances} gi ON gi.definitionid = gd.id\n JOIN {grading_areas} ga ON ga.id = gd.areaid\n WHERE ga.contextid = :contextid $itemsql\"", ";", "$", "records", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "if", "(", "$", "records", ")", "{", "$", "firstrecord", "=", "current", "(", "$", "records", ")", ";", "$", "method", "=", "$", "firstrecord", "->", "method", ";", "$", "instanceids", "=", "array_map", "(", "function", "(", "$", "record", ")", "{", "return", "$", "record", "->", "instanceid", ";", "}", ",", "$", "records", ")", ";", "manager", "::", "component_class_callback", "(", "\"gradingform_{$method}\"", ",", "gradingform_provider_v2", "::", "class", ",", "'delete_gradingform_for_instances'", ",", "[", "$", "instanceids", "]", ")", ";", "// Delete grading_instances rows.", "$", "DB", "->", "delete_records_list", "(", "'grading_instances'", ",", "'id'", ",", "$", "instanceids", ")", ";", "}", "}" ]
Deletes all user data related to a context and possibly itemids. @param \context $context The context to delete on. @param array $itemids An optional list of item IDs to refine the deletion.
[ "Deletes", "all", "user", "data", "related", "to", "a", "context", "and", "possibly", "itemids", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/classes/privacy/provider.php#L217-L246
214,720
moodle/moodle
grade/grading/classes/privacy/provider.php
provider.export_grading_instances
protected static function export_grading_instances(\context $context, array $subcontext, int $definitionid, int $userid = 0) { global $DB; $params = ['definitionid' => $definitionid]; if (!empty($userid)) { $params['raterid'] = $userid; } $instances = $DB->get_recordset('grading_instances', $params); $instancedata = []; foreach ($instances as $instance) { // TODO: Get the status name (instead of the ID). $tmpdata = [ 'rawgrade' => $instance->rawgrade, 'status' => $instance->status, 'feedback' => $instance->feedback, 'feedbackformat' => $instance->feedbackformat, 'timemodified' => transform::datetime($instance->timemodified), ]; $instancedata[] = (object) $tmpdata; } $instances->close(); if (!empty($instancedata)) { $data = (object) [ 'instances' => $instancedata, ]; writer::with_context($context)->export_related_data($subcontext, 'gradinginstances', $data); } }
php
protected static function export_grading_instances(\context $context, array $subcontext, int $definitionid, int $userid = 0) { global $DB; $params = ['definitionid' => $definitionid]; if (!empty($userid)) { $params['raterid'] = $userid; } $instances = $DB->get_recordset('grading_instances', $params); $instancedata = []; foreach ($instances as $instance) { // TODO: Get the status name (instead of the ID). $tmpdata = [ 'rawgrade' => $instance->rawgrade, 'status' => $instance->status, 'feedback' => $instance->feedback, 'feedbackformat' => $instance->feedbackformat, 'timemodified' => transform::datetime($instance->timemodified), ]; $instancedata[] = (object) $tmpdata; } $instances->close(); if (!empty($instancedata)) { $data = (object) [ 'instances' => $instancedata, ]; writer::with_context($context)->export_related_data($subcontext, 'gradinginstances', $data); } }
[ "protected", "static", "function", "export_grading_instances", "(", "\\", "context", "$", "context", ",", "array", "$", "subcontext", ",", "int", "$", "definitionid", ",", "int", "$", "userid", "=", "0", ")", "{", "global", "$", "DB", ";", "$", "params", "=", "[", "'definitionid'", "=>", "$", "definitionid", "]", ";", "if", "(", "!", "empty", "(", "$", "userid", ")", ")", "{", "$", "params", "[", "'raterid'", "]", "=", "$", "userid", ";", "}", "$", "instances", "=", "$", "DB", "->", "get_recordset", "(", "'grading_instances'", ",", "$", "params", ")", ";", "$", "instancedata", "=", "[", "]", ";", "foreach", "(", "$", "instances", "as", "$", "instance", ")", "{", "// TODO: Get the status name (instead of the ID).", "$", "tmpdata", "=", "[", "'rawgrade'", "=>", "$", "instance", "->", "rawgrade", ",", "'status'", "=>", "$", "instance", "->", "status", ",", "'feedback'", "=>", "$", "instance", "->", "feedback", ",", "'feedbackformat'", "=>", "$", "instance", "->", "feedbackformat", ",", "'timemodified'", "=>", "transform", "::", "datetime", "(", "$", "instance", "->", "timemodified", ")", ",", "]", ";", "$", "instancedata", "[", "]", "=", "(", "object", ")", "$", "tmpdata", ";", "}", "$", "instances", "->", "close", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "instancedata", ")", ")", "{", "$", "data", "=", "(", "object", ")", "[", "'instances'", "=>", "$", "instancedata", ",", "]", ";", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_related_data", "(", "$", "subcontext", ",", "'gradinginstances'", ",", "$", "data", ")", ";", "}", "}" ]
Exports the data related to grading instances within the specified definition. @param \context $context Context owner of the data. @param array $subcontext Subcontext owner of the data. @param int $definitionid The definition ID whose grading instance information is to be exported. @param int $userid The user whose information is to be exported.
[ "Exports", "the", "data", "related", "to", "grading", "instances", "within", "the", "specified", "definition", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/classes/privacy/provider.php#L344-L373
214,721
moodle/moodle
enrol/lti/lib.php
enrol_lti_plugin.delete_instance
public function delete_instance($instance) { global $DB; // Get the tool associated with this instance. $tool = $DB->get_record('enrol_lti_tools', array('enrolid' => $instance->id), 'id', MUST_EXIST); // Delete any users associated with this tool. $DB->delete_records('enrol_lti_users', array('toolid' => $tool->id)); // Get tool and consumer mappings. $rsmapping = $DB->get_recordset('enrol_lti_tool_consumer_map', array('toolid' => $tool->id)); // Delete consumers that are linked to this tool and their related data. $dataconnector = new data_connector(); foreach ($rsmapping as $mapping) { $consumer = new ToolConsumer(null, $dataconnector); $consumer->setRecordId($mapping->consumerid); $dataconnector->deleteToolConsumer($consumer); } $rsmapping->close(); // Delete mapping records. $DB->delete_records('enrol_lti_tool_consumer_map', array('toolid' => $tool->id)); // Delete the lti tool record. $DB->delete_records('enrol_lti_tools', array('id' => $tool->id)); // Time for the parent to do it's thang, yeow. parent::delete_instance($instance); }
php
public function delete_instance($instance) { global $DB; // Get the tool associated with this instance. $tool = $DB->get_record('enrol_lti_tools', array('enrolid' => $instance->id), 'id', MUST_EXIST); // Delete any users associated with this tool. $DB->delete_records('enrol_lti_users', array('toolid' => $tool->id)); // Get tool and consumer mappings. $rsmapping = $DB->get_recordset('enrol_lti_tool_consumer_map', array('toolid' => $tool->id)); // Delete consumers that are linked to this tool and their related data. $dataconnector = new data_connector(); foreach ($rsmapping as $mapping) { $consumer = new ToolConsumer(null, $dataconnector); $consumer->setRecordId($mapping->consumerid); $dataconnector->deleteToolConsumer($consumer); } $rsmapping->close(); // Delete mapping records. $DB->delete_records('enrol_lti_tool_consumer_map', array('toolid' => $tool->id)); // Delete the lti tool record. $DB->delete_records('enrol_lti_tools', array('id' => $tool->id)); // Time for the parent to do it's thang, yeow. parent::delete_instance($instance); }
[ "public", "function", "delete_instance", "(", "$", "instance", ")", "{", "global", "$", "DB", ";", "// Get the tool associated with this instance.", "$", "tool", "=", "$", "DB", "->", "get_record", "(", "'enrol_lti_tools'", ",", "array", "(", "'enrolid'", "=>", "$", "instance", "->", "id", ")", ",", "'id'", ",", "MUST_EXIST", ")", ";", "// Delete any users associated with this tool.", "$", "DB", "->", "delete_records", "(", "'enrol_lti_users'", ",", "array", "(", "'toolid'", "=>", "$", "tool", "->", "id", ")", ")", ";", "// Get tool and consumer mappings.", "$", "rsmapping", "=", "$", "DB", "->", "get_recordset", "(", "'enrol_lti_tool_consumer_map'", ",", "array", "(", "'toolid'", "=>", "$", "tool", "->", "id", ")", ")", ";", "// Delete consumers that are linked to this tool and their related data.", "$", "dataconnector", "=", "new", "data_connector", "(", ")", ";", "foreach", "(", "$", "rsmapping", "as", "$", "mapping", ")", "{", "$", "consumer", "=", "new", "ToolConsumer", "(", "null", ",", "$", "dataconnector", ")", ";", "$", "consumer", "->", "setRecordId", "(", "$", "mapping", "->", "consumerid", ")", ";", "$", "dataconnector", "->", "deleteToolConsumer", "(", "$", "consumer", ")", ";", "}", "$", "rsmapping", "->", "close", "(", ")", ";", "// Delete mapping records.", "$", "DB", "->", "delete_records", "(", "'enrol_lti_tool_consumer_map'", ",", "array", "(", "'toolid'", "=>", "$", "tool", "->", "id", ")", ")", ";", "// Delete the lti tool record.", "$", "DB", "->", "delete_records", "(", "'enrol_lti_tools'", ",", "array", "(", "'id'", "=>", "$", "tool", "->", "id", ")", ")", ";", "// Time for the parent to do it's thang, yeow.", "parent", "::", "delete_instance", "(", "$", "instance", ")", ";", "}" ]
Delete plugin specific information. @param stdClass $instance @return void
[ "Delete", "plugin", "specific", "information", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/lib.php#L154-L183
214,722
moodle/moodle
enrol/lti/lib.php
enrol_lti_plugin.unenrol_user
public function unenrol_user(stdClass $instance, $userid) { global $DB; // Get the tool associated with this instance. Note - it may not exist if we have deleted // the tool. This is fine because we have already cleaned the 'enrol_lti_users' table. if ($tool = $DB->get_record('enrol_lti_tools', array('enrolid' => $instance->id), 'id')) { // Need to remove the user from the users table. $DB->delete_records('enrol_lti_users', array('userid' => $userid, 'toolid' => $tool->id)); } parent::unenrol_user($instance, $userid); }
php
public function unenrol_user(stdClass $instance, $userid) { global $DB; // Get the tool associated with this instance. Note - it may not exist if we have deleted // the tool. This is fine because we have already cleaned the 'enrol_lti_users' table. if ($tool = $DB->get_record('enrol_lti_tools', array('enrolid' => $instance->id), 'id')) { // Need to remove the user from the users table. $DB->delete_records('enrol_lti_users', array('userid' => $userid, 'toolid' => $tool->id)); } parent::unenrol_user($instance, $userid); }
[ "public", "function", "unenrol_user", "(", "stdClass", "$", "instance", ",", "$", "userid", ")", "{", "global", "$", "DB", ";", "// Get the tool associated with this instance. Note - it may not exist if we have deleted", "// the tool. This is fine because we have already cleaned the 'enrol_lti_users' table.", "if", "(", "$", "tool", "=", "$", "DB", "->", "get_record", "(", "'enrol_lti_tools'", ",", "array", "(", "'enrolid'", "=>", "$", "instance", "->", "id", ")", ",", "'id'", ")", ")", "{", "// Need to remove the user from the users table.", "$", "DB", "->", "delete_records", "(", "'enrol_lti_users'", ",", "array", "(", "'userid'", "=>", "$", "userid", ",", "'toolid'", "=>", "$", "tool", "->", "id", ")", ")", ";", "}", "parent", "::", "unenrol_user", "(", "$", "instance", ",", "$", "userid", ")", ";", "}" ]
Handles un-enrolling a user. @param stdClass $instance @param int $userid @return void
[ "Handles", "un", "-", "enrolling", "a", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/lib.php#L192-L203
214,723
moodle/moodle
question/type/multichoice/backup/moodle2/restore_qtype_multichoice_plugin.class.php
restore_qtype_multichoice_plugin.recode_choice_order
protected function recode_choice_order($order) { $neworder = array(); foreach (explode(',', $order) as $id) { if ($newid = $this->get_mappingid('question_answer', $id)) { $neworder[] = $newid; } } return implode(',', $neworder); }
php
protected function recode_choice_order($order) { $neworder = array(); foreach (explode(',', $order) as $id) { if ($newid = $this->get_mappingid('question_answer', $id)) { $neworder[] = $newid; } } return implode(',', $neworder); }
[ "protected", "function", "recode_choice_order", "(", "$", "order", ")", "{", "$", "neworder", "=", "array", "(", ")", ";", "foreach", "(", "explode", "(", "','", ",", "$", "order", ")", "as", "$", "id", ")", "{", "if", "(", "$", "newid", "=", "$", "this", "->", "get_mappingid", "(", "'question_answer'", ",", "$", "id", ")", ")", "{", "$", "neworder", "[", "]", "=", "$", "newid", ";", "}", "}", "return", "implode", "(", "','", ",", "$", "neworder", ")", ";", "}" ]
Recode the choice order as stored in the response. @param string $order the original order. @return string the recoded order.
[ "Recode", "the", "choice", "order", "as", "stored", "in", "the", "response", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/multichoice/backup/moodle2/restore_qtype_multichoice_plugin.class.php#L96-L104
214,724
moodle/moodle
question/type/multichoice/backup/moodle2/restore_qtype_multichoice_plugin.class.php
restore_qtype_multichoice_plugin.recode_legacy_state_answer
public function recode_legacy_state_answer($state) { $answer = $state->answer; $orderarr = array(); $responsesarr = array(); $lists = explode(':', $answer); // If only 1 list, answer is missing the order list, adjust. if (count($lists) == 1) { $lists[1] = $lists[0]; // Here we have the responses. $lists[0] = ''; // Here we have the order. } // Map order. if (!empty($lists[0])) { foreach (explode(',', $lists[0]) as $id) { if ($newid = $this->get_mappingid('question_answer', $id)) { $orderarr[] = $newid; } } } // Map responses. if (!empty($lists[1])) { foreach (explode(',', $lists[1]) as $id) { if ($newid = $this->get_mappingid('question_answer', $id)) { $responsesarr[] = $newid; } } } // Build the final answer, if not order, only responses. $result = ''; if (empty($orderarr)) { $result = implode(',', $responsesarr); } else { $result = implode(',', $orderarr) . ':' . implode(',', $responsesarr); } return $result; }
php
public function recode_legacy_state_answer($state) { $answer = $state->answer; $orderarr = array(); $responsesarr = array(); $lists = explode(':', $answer); // If only 1 list, answer is missing the order list, adjust. if (count($lists) == 1) { $lists[1] = $lists[0]; // Here we have the responses. $lists[0] = ''; // Here we have the order. } // Map order. if (!empty($lists[0])) { foreach (explode(',', $lists[0]) as $id) { if ($newid = $this->get_mappingid('question_answer', $id)) { $orderarr[] = $newid; } } } // Map responses. if (!empty($lists[1])) { foreach (explode(',', $lists[1]) as $id) { if ($newid = $this->get_mappingid('question_answer', $id)) { $responsesarr[] = $newid; } } } // Build the final answer, if not order, only responses. $result = ''; if (empty($orderarr)) { $result = implode(',', $responsesarr); } else { $result = implode(',', $orderarr) . ':' . implode(',', $responsesarr); } return $result; }
[ "public", "function", "recode_legacy_state_answer", "(", "$", "state", ")", "{", "$", "answer", "=", "$", "state", "->", "answer", ";", "$", "orderarr", "=", "array", "(", ")", ";", "$", "responsesarr", "=", "array", "(", ")", ";", "$", "lists", "=", "explode", "(", "':'", ",", "$", "answer", ")", ";", "// If only 1 list, answer is missing the order list, adjust.", "if", "(", "count", "(", "$", "lists", ")", "==", "1", ")", "{", "$", "lists", "[", "1", "]", "=", "$", "lists", "[", "0", "]", ";", "// Here we have the responses.", "$", "lists", "[", "0", "]", "=", "''", ";", "// Here we have the order.", "}", "// Map order.", "if", "(", "!", "empty", "(", "$", "lists", "[", "0", "]", ")", ")", "{", "foreach", "(", "explode", "(", "','", ",", "$", "lists", "[", "0", "]", ")", "as", "$", "id", ")", "{", "if", "(", "$", "newid", "=", "$", "this", "->", "get_mappingid", "(", "'question_answer'", ",", "$", "id", ")", ")", "{", "$", "orderarr", "[", "]", "=", "$", "newid", ";", "}", "}", "}", "// Map responses.", "if", "(", "!", "empty", "(", "$", "lists", "[", "1", "]", ")", ")", "{", "foreach", "(", "explode", "(", "','", ",", "$", "lists", "[", "1", "]", ")", "as", "$", "id", ")", "{", "if", "(", "$", "newid", "=", "$", "this", "->", "get_mappingid", "(", "'question_answer'", ",", "$", "id", ")", ")", "{", "$", "responsesarr", "[", "]", "=", "$", "newid", ";", "}", "}", "}", "// Build the final answer, if not order, only responses.", "$", "result", "=", "''", ";", "if", "(", "empty", "(", "$", "orderarr", ")", ")", "{", "$", "result", "=", "implode", "(", "','", ",", "$", "responsesarr", ")", ";", "}", "else", "{", "$", "result", "=", "implode", "(", "','", ",", "$", "orderarr", ")", ".", "':'", ".", "implode", "(", "','", ",", "$", "responsesarr", ")", ";", "}", "return", "$", "result", ";", "}" ]
Given one question_states record, return the answer recoded pointing to all the restored stuff for multichoice questions answer are two (hypen speparated) lists of comma separated question_answers the first to specify the order of the answers and the second to specify the responses. Note the order list (the first one) can be optional
[ "Given", "one", "question_states", "record", "return", "the", "answer", "recoded", "pointing", "to", "all", "the", "restored", "stuff", "for", "multichoice", "questions" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/multichoice/backup/moodle2/restore_qtype_multichoice_plugin.class.php#L114-L148
214,725
moodle/moodle
lib/mustache/src/Mustache/Cache/AbstractCache.php
Mustache_Cache_AbstractCache.setLogger
public function setLogger($logger = null) { if ($logger !== null && !($logger instanceof Mustache_Logger || is_a($logger, 'Psr\\Log\\LoggerInterface'))) { throw new Mustache_Exception_InvalidArgumentException('Expected an instance of Mustache_Logger or Psr\\Log\\LoggerInterface.'); } $this->logger = $logger; }
php
public function setLogger($logger = null) { if ($logger !== null && !($logger instanceof Mustache_Logger || is_a($logger, 'Psr\\Log\\LoggerInterface'))) { throw new Mustache_Exception_InvalidArgumentException('Expected an instance of Mustache_Logger or Psr\\Log\\LoggerInterface.'); } $this->logger = $logger; }
[ "public", "function", "setLogger", "(", "$", "logger", "=", "null", ")", "{", "if", "(", "$", "logger", "!==", "null", "&&", "!", "(", "$", "logger", "instanceof", "Mustache_Logger", "||", "is_a", "(", "$", "logger", ",", "'Psr\\\\Log\\\\LoggerInterface'", ")", ")", ")", "{", "throw", "new", "Mustache_Exception_InvalidArgumentException", "(", "'Expected an instance of Mustache_Logger or Psr\\\\Log\\\\LoggerInterface.'", ")", ";", "}", "$", "this", "->", "logger", "=", "$", "logger", ";", "}" ]
Set a logger instance. @param Mustache_Logger|Psr\Log\LoggerInterface $logger
[ "Set", "a", "logger", "instance", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Cache/AbstractCache.php#L38-L45
214,726
moodle/moodle
badges/criteria/award_criteria.php
award_criteria.build
public static function build($params) { global $CFG; require_once($CFG->libdir . '/badgeslib.php'); $types = badges_list_criteria(false); if (!isset($params['criteriatype']) || !isset($types[$params['criteriatype']])) { print_error('error:invalidcriteriatype', 'badges'); } $class = 'award_criteria_' . $types[$params['criteriatype']]; require_once($CFG->dirroot . '/badges/criteria/' . $class . '.php'); return new $class($params); }
php
public static function build($params) { global $CFG; require_once($CFG->libdir . '/badgeslib.php'); $types = badges_list_criteria(false); if (!isset($params['criteriatype']) || !isset($types[$params['criteriatype']])) { print_error('error:invalidcriteriatype', 'badges'); } $class = 'award_criteria_' . $types[$params['criteriatype']]; require_once($CFG->dirroot . '/badges/criteria/' . $class . '.php'); return new $class($params); }
[ "public", "static", "function", "build", "(", "$", "params", ")", "{", "global", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/badgeslib.php'", ")", ";", "$", "types", "=", "badges_list_criteria", "(", "false", ")", ";", "if", "(", "!", "isset", "(", "$", "params", "[", "'criteriatype'", "]", ")", "||", "!", "isset", "(", "$", "types", "[", "$", "params", "[", "'criteriatype'", "]", "]", ")", ")", "{", "print_error", "(", "'error:invalidcriteriatype'", ",", "'badges'", ")", ";", "}", "$", "class", "=", "'award_criteria_'", ".", "$", "types", "[", "$", "params", "[", "'criteriatype'", "]", "]", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/badges/criteria/'", ".", "$", "class", ".", "'.php'", ")", ";", "return", "new", "$", "class", "(", "$", "params", ")", ";", "}" ]
Factory method for creating criteria class object @param array $params associative arrays varname => value @return award_criteria
[ "Factory", "method", "for", "creating", "criteria", "class", "object" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/badges/criteria/award_criteria.php#L153-L168
214,727
moodle/moodle
badges/criteria/award_criteria.php
award_criteria.config_form_criteria
public function config_form_criteria($data) { global $OUTPUT; $agg = $data->get_aggregation_methods(); $editurl = new moodle_url('/badges/criteria_settings.php', array('badgeid' => $this->badgeid, 'edit' => true, 'type' => $this->criteriatype, 'crit' => $this->id)); $deleteurl = new moodle_url('/badges/criteria_action.php', array('badgeid' => $this->badgeid, 'delete' => true, 'type' => $this->criteriatype)); $editaction = $OUTPUT->action_icon($editurl, new pix_icon('t/edit', get_string('edit')), null, array('class' => 'criteria-action')); $deleteaction = $OUTPUT->action_icon($deleteurl, new pix_icon('t/delete', get_string('delete')), null, array('class' => 'criteria-action')); echo $OUTPUT->box_start(); if (!$data->is_locked() && !$data->is_active()) { echo $OUTPUT->box($deleteaction . $editaction, array('criteria-header')); } echo $OUTPUT->heading($this->get_title() . $OUTPUT->help_icon('criteria_' . $this->criteriatype, 'badges'), 3, 'main help'); if (!empty($this->description)) { $badge = new badge($this->badgeid); echo $OUTPUT->box( format_text($this->description, $this->descriptionformat, array('context' => $badge->get_context())), 'criteria-description' ); } if (!empty($this->params)) { if (count($this->params) > 1) { echo $OUTPUT->box(get_string('criteria_descr_' . $this->criteriatype, 'badges', core_text::strtoupper($agg[$data->get_aggregation_method($this->criteriatype)])), array('clearfix')); } else { echo $OUTPUT->box(get_string('criteria_descr_single_' . $this->criteriatype , 'badges'), array('clearfix')); } echo $OUTPUT->box($this->get_details(), array('clearfix')); } echo $OUTPUT->box_end(); }
php
public function config_form_criteria($data) { global $OUTPUT; $agg = $data->get_aggregation_methods(); $editurl = new moodle_url('/badges/criteria_settings.php', array('badgeid' => $this->badgeid, 'edit' => true, 'type' => $this->criteriatype, 'crit' => $this->id)); $deleteurl = new moodle_url('/badges/criteria_action.php', array('badgeid' => $this->badgeid, 'delete' => true, 'type' => $this->criteriatype)); $editaction = $OUTPUT->action_icon($editurl, new pix_icon('t/edit', get_string('edit')), null, array('class' => 'criteria-action')); $deleteaction = $OUTPUT->action_icon($deleteurl, new pix_icon('t/delete', get_string('delete')), null, array('class' => 'criteria-action')); echo $OUTPUT->box_start(); if (!$data->is_locked() && !$data->is_active()) { echo $OUTPUT->box($deleteaction . $editaction, array('criteria-header')); } echo $OUTPUT->heading($this->get_title() . $OUTPUT->help_icon('criteria_' . $this->criteriatype, 'badges'), 3, 'main help'); if (!empty($this->description)) { $badge = new badge($this->badgeid); echo $OUTPUT->box( format_text($this->description, $this->descriptionformat, array('context' => $badge->get_context())), 'criteria-description' ); } if (!empty($this->params)) { if (count($this->params) > 1) { echo $OUTPUT->box(get_string('criteria_descr_' . $this->criteriatype, 'badges', core_text::strtoupper($agg[$data->get_aggregation_method($this->criteriatype)])), array('clearfix')); } else { echo $OUTPUT->box(get_string('criteria_descr_single_' . $this->criteriatype , 'badges'), array('clearfix')); } echo $OUTPUT->box($this->get_details(), array('clearfix')); } echo $OUTPUT->box_end(); }
[ "public", "function", "config_form_criteria", "(", "$", "data", ")", "{", "global", "$", "OUTPUT", ";", "$", "agg", "=", "$", "data", "->", "get_aggregation_methods", "(", ")", ";", "$", "editurl", "=", "new", "moodle_url", "(", "'/badges/criteria_settings.php'", ",", "array", "(", "'badgeid'", "=>", "$", "this", "->", "badgeid", ",", "'edit'", "=>", "true", ",", "'type'", "=>", "$", "this", "->", "criteriatype", ",", "'crit'", "=>", "$", "this", "->", "id", ")", ")", ";", "$", "deleteurl", "=", "new", "moodle_url", "(", "'/badges/criteria_action.php'", ",", "array", "(", "'badgeid'", "=>", "$", "this", "->", "badgeid", ",", "'delete'", "=>", "true", ",", "'type'", "=>", "$", "this", "->", "criteriatype", ")", ")", ";", "$", "editaction", "=", "$", "OUTPUT", "->", "action_icon", "(", "$", "editurl", ",", "new", "pix_icon", "(", "'t/edit'", ",", "get_string", "(", "'edit'", ")", ")", ",", "null", ",", "array", "(", "'class'", "=>", "'criteria-action'", ")", ")", ";", "$", "deleteaction", "=", "$", "OUTPUT", "->", "action_icon", "(", "$", "deleteurl", ",", "new", "pix_icon", "(", "'t/delete'", ",", "get_string", "(", "'delete'", ")", ")", ",", "null", ",", "array", "(", "'class'", "=>", "'criteria-action'", ")", ")", ";", "echo", "$", "OUTPUT", "->", "box_start", "(", ")", ";", "if", "(", "!", "$", "data", "->", "is_locked", "(", ")", "&&", "!", "$", "data", "->", "is_active", "(", ")", ")", "{", "echo", "$", "OUTPUT", "->", "box", "(", "$", "deleteaction", ".", "$", "editaction", ",", "array", "(", "'criteria-header'", ")", ")", ";", "}", "echo", "$", "OUTPUT", "->", "heading", "(", "$", "this", "->", "get_title", "(", ")", ".", "$", "OUTPUT", "->", "help_icon", "(", "'criteria_'", ".", "$", "this", "->", "criteriatype", ",", "'badges'", ")", ",", "3", ",", "'main help'", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "description", ")", ")", "{", "$", "badge", "=", "new", "badge", "(", "$", "this", "->", "badgeid", ")", ";", "echo", "$", "OUTPUT", "->", "box", "(", "format_text", "(", "$", "this", "->", "description", ",", "$", "this", "->", "descriptionformat", ",", "array", "(", "'context'", "=>", "$", "badge", "->", "get_context", "(", ")", ")", ")", ",", "'criteria-description'", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "params", ")", ")", "{", "if", "(", "count", "(", "$", "this", "->", "params", ")", ">", "1", ")", "{", "echo", "$", "OUTPUT", "->", "box", "(", "get_string", "(", "'criteria_descr_'", ".", "$", "this", "->", "criteriatype", ",", "'badges'", ",", "core_text", "::", "strtoupper", "(", "$", "agg", "[", "$", "data", "->", "get_aggregation_method", "(", "$", "this", "->", "criteriatype", ")", "]", ")", ")", ",", "array", "(", "'clearfix'", ")", ")", ";", "}", "else", "{", "echo", "$", "OUTPUT", "->", "box", "(", "get_string", "(", "'criteria_descr_single_'", ".", "$", "this", "->", "criteriatype", ",", "'badges'", ")", ",", "array", "(", "'clearfix'", ")", ")", ";", "}", "echo", "$", "OUTPUT", "->", "box", "(", "$", "this", "->", "get_details", "(", ")", ",", "array", "(", "'clearfix'", ")", ")", ";", "}", "echo", "$", "OUTPUT", "->", "box_end", "(", ")", ";", "}" ]
Add appropriate criteria elements @param stdClass $data details of various criteria
[ "Add", "appropriate", "criteria", "elements" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/badges/criteria/award_criteria.php#L248-L283
214,728
moodle/moodle
badges/criteria/award_criteria.php
award_criteria.mark_complete
public function mark_complete($userid) { global $DB; $obj = array(); $obj['critid'] = $this->id; $obj['userid'] = $userid; $obj['datemet'] = time(); if (!$DB->record_exists('badge_criteria_met', array('critid' => $this->id, 'userid' => $userid))) { $DB->insert_record('badge_criteria_met', $obj); } }
php
public function mark_complete($userid) { global $DB; $obj = array(); $obj['critid'] = $this->id; $obj['userid'] = $userid; $obj['datemet'] = time(); if (!$DB->record_exists('badge_criteria_met', array('critid' => $this->id, 'userid' => $userid))) { $DB->insert_record('badge_criteria_met', $obj); } }
[ "public", "function", "mark_complete", "(", "$", "userid", ")", "{", "global", "$", "DB", ";", "$", "obj", "=", "array", "(", ")", ";", "$", "obj", "[", "'critid'", "]", "=", "$", "this", "->", "id", ";", "$", "obj", "[", "'userid'", "]", "=", "$", "userid", ";", "$", "obj", "[", "'datemet'", "]", "=", "time", "(", ")", ";", "if", "(", "!", "$", "DB", "->", "record_exists", "(", "'badge_criteria_met'", ",", "array", "(", "'critid'", "=>", "$", "this", "->", "id", ",", "'userid'", "=>", "$", "userid", ")", ")", ")", "{", "$", "DB", "->", "insert_record", "(", "'badge_criteria_met'", ",", "$", "obj", ")", ";", "}", "}" ]
Mark this criteria as complete for a user @param int $userid User whose criteria is completed.
[ "Mark", "this", "criteria", "as", "complete", "for", "a", "user" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/badges/criteria/award_criteria.php#L309-L318
214,729
moodle/moodle
badges/criteria/award_criteria.php
award_criteria.get_params
public function get_params($cid) { global $DB; $params = array(); $records = $DB->get_records('badge_criteria_param', array('critid' => $cid)); foreach ($records as $rec) { $arr = explode('_', $rec->name); $params[$arr[1]][$arr[0]] = $rec->value; } return $params; }
php
public function get_params($cid) { global $DB; $params = array(); $records = $DB->get_records('badge_criteria_param', array('critid' => $cid)); foreach ($records as $rec) { $arr = explode('_', $rec->name); $params[$arr[1]][$arr[0]] = $rec->value; } return $params; }
[ "public", "function", "get_params", "(", "$", "cid", ")", "{", "global", "$", "DB", ";", "$", "params", "=", "array", "(", ")", ";", "$", "records", "=", "$", "DB", "->", "get_records", "(", "'badge_criteria_param'", ",", "array", "(", "'critid'", "=>", "$", "cid", ")", ")", ";", "foreach", "(", "$", "records", "as", "$", "rec", ")", "{", "$", "arr", "=", "explode", "(", "'_'", ",", "$", "rec", "->", "name", ")", ";", "$", "params", "[", "$", "arr", "[", "1", "]", "]", "[", "$", "arr", "[", "0", "]", "]", "=", "$", "rec", "->", "value", ";", "}", "return", "$", "params", ";", "}" ]
Return criteria parameters @param int $critid Criterion ID @return array
[ "Return", "criteria", "parameters" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/badges/criteria/award_criteria.php#L326-L337
214,730
moodle/moodle
badges/criteria/award_criteria.php
award_criteria.delete
public function delete() { global $DB, $PAGE; // Remove any records if it has already been met. $DB->delete_records('badge_criteria_met', array('critid' => $this->id)); // Remove all parameters records. $DB->delete_records('badge_criteria_param', array('critid' => $this->id)); // Finally remove criterion itself. $DB->delete_records('badge_criteria', array('id' => $this->id)); // Trigger event, badge criteria deleted. $eventparams = array('objectid' => $this->id, 'context' => $PAGE->context, 'other' => array('badgeid' => $this->badgeid)); $event = \core\event\badge_criteria_deleted::create($eventparams); $event->trigger(); }
php
public function delete() { global $DB, $PAGE; // Remove any records if it has already been met. $DB->delete_records('badge_criteria_met', array('critid' => $this->id)); // Remove all parameters records. $DB->delete_records('badge_criteria_param', array('critid' => $this->id)); // Finally remove criterion itself. $DB->delete_records('badge_criteria', array('id' => $this->id)); // Trigger event, badge criteria deleted. $eventparams = array('objectid' => $this->id, 'context' => $PAGE->context, 'other' => array('badgeid' => $this->badgeid)); $event = \core\event\badge_criteria_deleted::create($eventparams); $event->trigger(); }
[ "public", "function", "delete", "(", ")", "{", "global", "$", "DB", ",", "$", "PAGE", ";", "// Remove any records if it has already been met.", "$", "DB", "->", "delete_records", "(", "'badge_criteria_met'", ",", "array", "(", "'critid'", "=>", "$", "this", "->", "id", ")", ")", ";", "// Remove all parameters records.", "$", "DB", "->", "delete_records", "(", "'badge_criteria_param'", ",", "array", "(", "'critid'", "=>", "$", "this", "->", "id", ")", ")", ";", "// Finally remove criterion itself.", "$", "DB", "->", "delete_records", "(", "'badge_criteria'", ",", "array", "(", "'id'", "=>", "$", "this", "->", "id", ")", ")", ";", "// Trigger event, badge criteria deleted.", "$", "eventparams", "=", "array", "(", "'objectid'", "=>", "$", "this", "->", "id", ",", "'context'", "=>", "$", "PAGE", "->", "context", ",", "'other'", "=>", "array", "(", "'badgeid'", "=>", "$", "this", "->", "badgeid", ")", ")", ";", "$", "event", "=", "\\", "core", "\\", "event", "\\", "badge_criteria_deleted", "::", "create", "(", "$", "eventparams", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "}" ]
Delete this criterion
[ "Delete", "this", "criterion" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/badges/criteria/award_criteria.php#L343-L361
214,731
moodle/moodle
mod/quiz/attemptlib.php
quiz.create
public static function create($quizid, $userid = null) { global $DB; $quiz = quiz_access_manager::load_quiz_and_settings($quizid); $course = $DB->get_record('course', array('id' => $quiz->course), '*', MUST_EXIST); $cm = get_coursemodule_from_instance('quiz', $quiz->id, $course->id, false, MUST_EXIST); // Update quiz with override information. if ($userid) { $quiz = quiz_update_effective_access($quiz, $userid); } return new quiz($quiz, $cm, $course); }
php
public static function create($quizid, $userid = null) { global $DB; $quiz = quiz_access_manager::load_quiz_and_settings($quizid); $course = $DB->get_record('course', array('id' => $quiz->course), '*', MUST_EXIST); $cm = get_coursemodule_from_instance('quiz', $quiz->id, $course->id, false, MUST_EXIST); // Update quiz with override information. if ($userid) { $quiz = quiz_update_effective_access($quiz, $userid); } return new quiz($quiz, $cm, $course); }
[ "public", "static", "function", "create", "(", "$", "quizid", ",", "$", "userid", "=", "null", ")", "{", "global", "$", "DB", ";", "$", "quiz", "=", "quiz_access_manager", "::", "load_quiz_and_settings", "(", "$", "quizid", ")", ";", "$", "course", "=", "$", "DB", "->", "get_record", "(", "'course'", ",", "array", "(", "'id'", "=>", "$", "quiz", "->", "course", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "$", "cm", "=", "get_coursemodule_from_instance", "(", "'quiz'", ",", "$", "quiz", "->", "id", ",", "$", "course", "->", "id", ",", "false", ",", "MUST_EXIST", ")", ";", "// Update quiz with override information.", "if", "(", "$", "userid", ")", "{", "$", "quiz", "=", "quiz_update_effective_access", "(", "$", "quiz", ",", "$", "userid", ")", ";", "}", "return", "new", "quiz", "(", "$", "quiz", ",", "$", "cm", ",", "$", "course", ")", ";", "}" ]
Static function to create a new quiz object for a specific user. @param int $quizid the the quiz id. @param int $userid the the userid. @return quiz the new quiz object
[ "Static", "function", "to", "create", "a", "new", "quiz", "object", "for", "a", "specific", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L107-L120
214,732
moodle/moodle
mod/quiz/attemptlib.php
quiz.get_sections
public function get_sections() { global $DB; if ($this->sections === null) { $this->sections = array_values($DB->get_records('quiz_sections', array('quizid' => $this->get_quizid()), 'firstslot')); } return $this->sections; }
php
public function get_sections() { global $DB; if ($this->sections === null) { $this->sections = array_values($DB->get_records('quiz_sections', array('quizid' => $this->get_quizid()), 'firstslot')); } return $this->sections; }
[ "public", "function", "get_sections", "(", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "this", "->", "sections", "===", "null", ")", "{", "$", "this", "->", "sections", "=", "array_values", "(", "$", "DB", "->", "get_records", "(", "'quiz_sections'", ",", "array", "(", "'quizid'", "=>", "$", "this", "->", "get_quizid", "(", ")", ")", ",", "'firstslot'", ")", ")", ";", "}", "return", "$", "this", "->", "sections", ";", "}" ]
Get all the sections in this quiz. @return array 0, 1, 2, ... => quiz_sections row from the database.
[ "Get", "all", "the", "sections", "in", "this", "quiz", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L296-L303
214,733
moodle/moodle
mod/quiz/attemptlib.php
quiz.get_access_manager
public function get_access_manager($timenow) { if (is_null($this->accessmanager)) { $this->accessmanager = new quiz_access_manager($this, $timenow, has_capability('mod/quiz:ignoretimelimits', $this->context, null, false)); } return $this->accessmanager; }
php
public function get_access_manager($timenow) { if (is_null($this->accessmanager)) { $this->accessmanager = new quiz_access_manager($this, $timenow, has_capability('mod/quiz:ignoretimelimits', $this->context, null, false)); } return $this->accessmanager; }
[ "public", "function", "get_access_manager", "(", "$", "timenow", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "accessmanager", ")", ")", "{", "$", "this", "->", "accessmanager", "=", "new", "quiz_access_manager", "(", "$", "this", ",", "$", "timenow", ",", "has_capability", "(", "'mod/quiz:ignoretimelimits'", ",", "$", "this", "->", "context", ",", "null", ",", "false", ")", ")", ";", "}", "return", "$", "this", "->", "accessmanager", ";", "}" ]
Return quiz_access_manager and instance of the quiz_access_manager class for this quiz at this time. @param int $timenow the current time as a unix timestamp. @return quiz_access_manager and instance of the quiz_access_manager class for this quiz at this time.
[ "Return", "quiz_access_manager", "and", "instance", "of", "the", "quiz_access_manager", "class", "for", "this", "quiz", "at", "this", "time", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L312-L318
214,734
moodle/moodle
mod/quiz/attemptlib.php
quiz.ensure_question_loaded
protected function ensure_question_loaded($id) { if (isset($this->questions[$id]->_partiallyloaded)) { throw new moodle_quiz_exception($this, 'questionnotloaded', $id); } }
php
protected function ensure_question_loaded($id) { if (isset($this->questions[$id]->_partiallyloaded)) { throw new moodle_quiz_exception($this, 'questionnotloaded', $id); } }
[ "protected", "function", "ensure_question_loaded", "(", "$", "id", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "questions", "[", "$", "id", "]", "->", "_partiallyloaded", ")", ")", "{", "throw", "new", "moodle_quiz_exception", "(", "$", "this", ",", "'questionnotloaded'", ",", "$", "id", ")", ";", "}", "}" ]
Check that the definition of a particular question is loaded, and if not throw an exception. @param $id a questionid.
[ "Check", "that", "the", "definition", "of", "a", "particular", "question", "is", "loaded", "and", "if", "not", "throw", "an", "exception", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L453-L457
214,735
moodle/moodle
mod/quiz/attemptlib.php
quiz.get_all_question_types_used
public function get_all_question_types_used($includepotential = false) { $questiontypes = array(); // To control if we need to look in categories for questions. $qcategories = array(); // We must be careful with random questions, if we find a random question we must assume that the quiz may content // any of the questions in the referenced category (or subcategories). foreach ($this->get_questions() as $questiondata) { if ($questiondata->qtype == 'random' and $includepotential) { $includesubcategories = (bool) $questiondata->questiontext; if (!isset($qcategories[$questiondata->category])) { $qcategories[$questiondata->category] = false; } if ($includesubcategories) { $qcategories[$questiondata->category] = true; } } else { if (!in_array($questiondata->qtype, $questiontypes)) { $questiontypes[] = $questiondata->qtype; } } } if (!empty($qcategories)) { // We have to look for all the question types in these categories. $categoriestolook = array(); foreach ($qcategories as $cat => $includesubcats) { if ($includesubcats) { $categoriestolook = array_merge($categoriestolook, question_categorylist($cat)); } else { $categoriestolook[] = $cat; } } $questiontypesincategories = question_bank::get_all_question_types_in_categories($categoriestolook); $questiontypes = array_merge($questiontypes, $questiontypesincategories); } $questiontypes = array_unique($questiontypes); sort($questiontypes); return $questiontypes; }
php
public function get_all_question_types_used($includepotential = false) { $questiontypes = array(); // To control if we need to look in categories for questions. $qcategories = array(); // We must be careful with random questions, if we find a random question we must assume that the quiz may content // any of the questions in the referenced category (or subcategories). foreach ($this->get_questions() as $questiondata) { if ($questiondata->qtype == 'random' and $includepotential) { $includesubcategories = (bool) $questiondata->questiontext; if (!isset($qcategories[$questiondata->category])) { $qcategories[$questiondata->category] = false; } if ($includesubcategories) { $qcategories[$questiondata->category] = true; } } else { if (!in_array($questiondata->qtype, $questiontypes)) { $questiontypes[] = $questiondata->qtype; } } } if (!empty($qcategories)) { // We have to look for all the question types in these categories. $categoriestolook = array(); foreach ($qcategories as $cat => $includesubcats) { if ($includesubcats) { $categoriestolook = array_merge($categoriestolook, question_categorylist($cat)); } else { $categoriestolook[] = $cat; } } $questiontypesincategories = question_bank::get_all_question_types_in_categories($categoriestolook); $questiontypes = array_merge($questiontypes, $questiontypesincategories); } $questiontypes = array_unique($questiontypes); sort($questiontypes); return $questiontypes; }
[ "public", "function", "get_all_question_types_used", "(", "$", "includepotential", "=", "false", ")", "{", "$", "questiontypes", "=", "array", "(", ")", ";", "// To control if we need to look in categories for questions.", "$", "qcategories", "=", "array", "(", ")", ";", "// We must be careful with random questions, if we find a random question we must assume that the quiz may content", "// any of the questions in the referenced category (or subcategories).", "foreach", "(", "$", "this", "->", "get_questions", "(", ")", "as", "$", "questiondata", ")", "{", "if", "(", "$", "questiondata", "->", "qtype", "==", "'random'", "and", "$", "includepotential", ")", "{", "$", "includesubcategories", "=", "(", "bool", ")", "$", "questiondata", "->", "questiontext", ";", "if", "(", "!", "isset", "(", "$", "qcategories", "[", "$", "questiondata", "->", "category", "]", ")", ")", "{", "$", "qcategories", "[", "$", "questiondata", "->", "category", "]", "=", "false", ";", "}", "if", "(", "$", "includesubcategories", ")", "{", "$", "qcategories", "[", "$", "questiondata", "->", "category", "]", "=", "true", ";", "}", "}", "else", "{", "if", "(", "!", "in_array", "(", "$", "questiondata", "->", "qtype", ",", "$", "questiontypes", ")", ")", "{", "$", "questiontypes", "[", "]", "=", "$", "questiondata", "->", "qtype", ";", "}", "}", "}", "if", "(", "!", "empty", "(", "$", "qcategories", ")", ")", "{", "// We have to look for all the question types in these categories.", "$", "categoriestolook", "=", "array", "(", ")", ";", "foreach", "(", "$", "qcategories", "as", "$", "cat", "=>", "$", "includesubcats", ")", "{", "if", "(", "$", "includesubcats", ")", "{", "$", "categoriestolook", "=", "array_merge", "(", "$", "categoriestolook", ",", "question_categorylist", "(", "$", "cat", ")", ")", ";", "}", "else", "{", "$", "categoriestolook", "[", "]", "=", "$", "cat", ";", "}", "}", "$", "questiontypesincategories", "=", "question_bank", "::", "get_all_question_types_in_categories", "(", "$", "categoriestolook", ")", ";", "$", "questiontypes", "=", "array_merge", "(", "$", "questiontypes", ",", "$", "questiontypesincategories", ")", ";", "}", "$", "questiontypes", "=", "array_unique", "(", "$", "questiontypes", ")", ";", "sort", "(", "$", "questiontypes", ")", ";", "return", "$", "questiontypes", ";", "}" ]
Return all the question types used in this quiz. @param boolean $includepotential if the quiz include random questions, setting this flag to true will make the function to return all the possible question types in the random questions category @return array a sorted array including the different question types @since Moodle 3.1
[ "Return", "all", "the", "question", "types", "used", "in", "this", "quiz", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L467-L508
214,736
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.link_sections_and_slots
protected function link_sections_and_slots() { foreach ($this->sections as $i => $section) { if (isset($this->sections[$i + 1])) { $section->lastslot = $this->sections[$i + 1]->firstslot - 1; } else { $section->lastslot = count($this->slots); } for ($slot = $section->firstslot; $slot <= $section->lastslot; $slot += 1) { $this->slots[$slot]->section = $section; } } }
php
protected function link_sections_and_slots() { foreach ($this->sections as $i => $section) { if (isset($this->sections[$i + 1])) { $section->lastslot = $this->sections[$i + 1]->firstslot - 1; } else { $section->lastslot = count($this->slots); } for ($slot = $section->firstslot; $slot <= $section->lastslot; $slot += 1) { $this->slots[$slot]->section = $section; } } }
[ "protected", "function", "link_sections_and_slots", "(", ")", "{", "foreach", "(", "$", "this", "->", "sections", "as", "$", "i", "=>", "$", "section", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "sections", "[", "$", "i", "+", "1", "]", ")", ")", "{", "$", "section", "->", "lastslot", "=", "$", "this", "->", "sections", "[", "$", "i", "+", "1", "]", "->", "firstslot", "-", "1", ";", "}", "else", "{", "$", "section", "->", "lastslot", "=", "count", "(", "$", "this", "->", "slots", ")", ";", "}", "for", "(", "$", "slot", "=", "$", "section", "->", "firstslot", ";", "$", "slot", "<=", "$", "section", "->", "lastslot", ";", "$", "slot", "+=", "1", ")", "{", "$", "this", "->", "slots", "[", "$", "slot", "]", "->", "section", "=", "$", "section", ";", "}", "}", "}" ]
Let each slot know which section it is part of.
[ "Let", "each", "slot", "know", "which", "section", "it", "is", "part", "of", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L649-L660
214,737
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.determine_layout
protected function determine_layout() { $this->pagelayout = array(); // Break up the layout string into pages. $pagelayouts = explode(',0', $this->attempt->layout); // Strip off any empty last page (normally there is one). if (end($pagelayouts) == '') { array_pop($pagelayouts); } // File the ids into the arrays. // Tracking which is the first slot in each section in this attempt is // trickier than you might guess, since the slots in this section // may be shuffled, so $section->firstslot (the lowest numbered slot in // the section) may not be the first one. $unseensections = $this->sections; $this->pagelayout = array(); foreach ($pagelayouts as $page => $pagelayout) { $pagelayout = trim($pagelayout, ','); if ($pagelayout == '') { continue; } $this->pagelayout[$page] = explode(',', $pagelayout); foreach ($this->pagelayout[$page] as $slot) { $sectionkey = array_search($this->slots[$slot]->section, $unseensections); if ($sectionkey !== false) { $this->slots[$slot]->firstinsection = true; unset($unseensections[$sectionkey]); } else { $this->slots[$slot]->firstinsection = false; } } } }
php
protected function determine_layout() { $this->pagelayout = array(); // Break up the layout string into pages. $pagelayouts = explode(',0', $this->attempt->layout); // Strip off any empty last page (normally there is one). if (end($pagelayouts) == '') { array_pop($pagelayouts); } // File the ids into the arrays. // Tracking which is the first slot in each section in this attempt is // trickier than you might guess, since the slots in this section // may be shuffled, so $section->firstslot (the lowest numbered slot in // the section) may not be the first one. $unseensections = $this->sections; $this->pagelayout = array(); foreach ($pagelayouts as $page => $pagelayout) { $pagelayout = trim($pagelayout, ','); if ($pagelayout == '') { continue; } $this->pagelayout[$page] = explode(',', $pagelayout); foreach ($this->pagelayout[$page] as $slot) { $sectionkey = array_search($this->slots[$slot]->section, $unseensections); if ($sectionkey !== false) { $this->slots[$slot]->firstinsection = true; unset($unseensections[$sectionkey]); } else { $this->slots[$slot]->firstinsection = false; } } } }
[ "protected", "function", "determine_layout", "(", ")", "{", "$", "this", "->", "pagelayout", "=", "array", "(", ")", ";", "// Break up the layout string into pages.", "$", "pagelayouts", "=", "explode", "(", "',0'", ",", "$", "this", "->", "attempt", "->", "layout", ")", ";", "// Strip off any empty last page (normally there is one).", "if", "(", "end", "(", "$", "pagelayouts", ")", "==", "''", ")", "{", "array_pop", "(", "$", "pagelayouts", ")", ";", "}", "// File the ids into the arrays.", "// Tracking which is the first slot in each section in this attempt is", "// trickier than you might guess, since the slots in this section", "// may be shuffled, so $section->firstslot (the lowest numbered slot in", "// the section) may not be the first one.", "$", "unseensections", "=", "$", "this", "->", "sections", ";", "$", "this", "->", "pagelayout", "=", "array", "(", ")", ";", "foreach", "(", "$", "pagelayouts", "as", "$", "page", "=>", "$", "pagelayout", ")", "{", "$", "pagelayout", "=", "trim", "(", "$", "pagelayout", ",", "','", ")", ";", "if", "(", "$", "pagelayout", "==", "''", ")", "{", "continue", ";", "}", "$", "this", "->", "pagelayout", "[", "$", "page", "]", "=", "explode", "(", "','", ",", "$", "pagelayout", ")", ";", "foreach", "(", "$", "this", "->", "pagelayout", "[", "$", "page", "]", "as", "$", "slot", ")", "{", "$", "sectionkey", "=", "array_search", "(", "$", "this", "->", "slots", "[", "$", "slot", "]", "->", "section", ",", "$", "unseensections", ")", ";", "if", "(", "$", "sectionkey", "!==", "false", ")", "{", "$", "this", "->", "slots", "[", "$", "slot", "]", "->", "firstinsection", "=", "true", ";", "unset", "(", "$", "unseensections", "[", "$", "sectionkey", "]", ")", ";", "}", "else", "{", "$", "this", "->", "slots", "[", "$", "slot", "]", "->", "firstinsection", "=", "false", ";", "}", "}", "}", "}" ]
Parse attempt->layout to populate the other arrays the represent the layout.
[ "Parse", "attempt", "-", ">", "layout", "to", "populate", "the", "other", "arrays", "the", "represent", "the", "layout", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L665-L699
214,738
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.has_response_to_at_least_one_graded_question
public function has_response_to_at_least_one_graded_question() { foreach ($this->quba->get_attempt_iterator() as $qa) { if ($qa->get_max_mark() == 0) { continue; } if ($qa->get_num_steps() > 1) { return true; } } return false; }
php
public function has_response_to_at_least_one_graded_question() { foreach ($this->quba->get_attempt_iterator() as $qa) { if ($qa->get_max_mark() == 0) { continue; } if ($qa->get_num_steps() > 1) { return true; } } return false; }
[ "public", "function", "has_response_to_at_least_one_graded_question", "(", ")", "{", "foreach", "(", "$", "this", "->", "quba", "->", "get_attempt_iterator", "(", ")", "as", "$", "qa", ")", "{", "if", "(", "$", "qa", "->", "get_max_mark", "(", ")", "==", "0", ")", "{", "continue", ";", "}", "if", "(", "$", "qa", "->", "get_num_steps", "(", ")", ">", "1", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Has the student, in this attempt, engaged with the quiz in a non-trivial way? That is, is there any question worth a non-zero number of marks, where the student has made some response that we have saved? @return bool true if we have saved a response for at least one graded question.
[ "Has", "the", "student", "in", "this", "attempt", "engaged", "with", "the", "quiz", "in", "a", "non", "-", "trivial", "way?", "That", "is", "is", "there", "any", "question", "worth", "a", "non", "-", "zero", "number", "of", "marks", "where", "the", "student", "has", "made", "some", "response", "that", "we", "have", "saved?" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L902-L912
214,739
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.check_review_capability
public function check_review_capability() { if ($this->get_attempt_state() == mod_quiz_display_options::IMMEDIATELY_AFTER) { $capability = 'mod/quiz:attempt'; } else { $capability = 'mod/quiz:reviewmyattempts'; } // These next tests are in a slighly funny order. The point is that the // common and most performance-critical case is students attempting a quiz // so we want to check that permisison first. if ($this->has_capability($capability)) { // User has the permission that lets you do the quiz as a student. Fine. return; } if ($this->has_capability('mod/quiz:viewreports') || $this->has_capability('mod/quiz:preview')) { // User has the permission that lets teachers review. Fine. return; } // They should not be here. Trigger the standard no-permission error // but using the name of the student capability. // We know this will fail. We just want the stadard exception thown. $this->require_capability($capability); }
php
public function check_review_capability() { if ($this->get_attempt_state() == mod_quiz_display_options::IMMEDIATELY_AFTER) { $capability = 'mod/quiz:attempt'; } else { $capability = 'mod/quiz:reviewmyattempts'; } // These next tests are in a slighly funny order. The point is that the // common and most performance-critical case is students attempting a quiz // so we want to check that permisison first. if ($this->has_capability($capability)) { // User has the permission that lets you do the quiz as a student. Fine. return; } if ($this->has_capability('mod/quiz:viewreports') || $this->has_capability('mod/quiz:preview')) { // User has the permission that lets teachers review. Fine. return; } // They should not be here. Trigger the standard no-permission error // but using the name of the student capability. // We know this will fail. We just want the stadard exception thown. $this->require_capability($capability); }
[ "public", "function", "check_review_capability", "(", ")", "{", "if", "(", "$", "this", "->", "get_attempt_state", "(", ")", "==", "mod_quiz_display_options", "::", "IMMEDIATELY_AFTER", ")", "{", "$", "capability", "=", "'mod/quiz:attempt'", ";", "}", "else", "{", "$", "capability", "=", "'mod/quiz:reviewmyattempts'", ";", "}", "// These next tests are in a slighly funny order. The point is that the", "// common and most performance-critical case is students attempting a quiz", "// so we want to check that permisison first.", "if", "(", "$", "this", "->", "has_capability", "(", "$", "capability", ")", ")", "{", "// User has the permission that lets you do the quiz as a student. Fine.", "return", ";", "}", "if", "(", "$", "this", "->", "has_capability", "(", "'mod/quiz:viewreports'", ")", "||", "$", "this", "->", "has_capability", "(", "'mod/quiz:preview'", ")", ")", "{", "// User has the permission that lets teachers review. Fine.", "return", ";", "}", "// They should not be here. Trigger the standard no-permission error", "// but using the name of the student capability.", "// We know this will fail. We just want the stadard exception thown.", "$", "this", "->", "require_capability", "(", "$", "capability", ")", ";", "}" ]
Check the appropriate capability to see whether this user may review their own attempt. If not, prints an error.
[ "Check", "the", "appropriate", "capability", "to", "see", "whether", "this", "user", "may", "review", "their", "own", "attempt", ".", "If", "not", "prints", "an", "error", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L962-L988
214,740
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.all_question_attempts_originally_in_slot
public function all_question_attempts_originally_in_slot($slot) { $qas = array(); foreach ($this->quba->get_attempt_iterator() as $qa) { if ($qa->get_metadata('originalslot') == $slot) { $qas[] = $qa; } } $qas[] = $this->quba->get_question_attempt($slot); return $qas; }
php
public function all_question_attempts_originally_in_slot($slot) { $qas = array(); foreach ($this->quba->get_attempt_iterator() as $qa) { if ($qa->get_metadata('originalslot') == $slot) { $qas[] = $qa; } } $qas[] = $this->quba->get_question_attempt($slot); return $qas; }
[ "public", "function", "all_question_attempts_originally_in_slot", "(", "$", "slot", ")", "{", "$", "qas", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "quba", "->", "get_attempt_iterator", "(", ")", "as", "$", "qa", ")", "{", "if", "(", "$", "qa", "->", "get_metadata", "(", "'originalslot'", ")", "==", "$", "slot", ")", "{", "$", "qas", "[", "]", "=", "$", "qa", ";", "}", "}", "$", "qas", "[", "]", "=", "$", "this", "->", "quba", "->", "get_question_attempt", "(", "$", "slot", ")", ";", "return", "$", "qas", ";", "}" ]
Get the question_attempt object for a particular question in this attempt. @param int $slot the number used to identify this question within this attempt. @return question_attempt
[ "Get", "the", "question_attempt", "object", "for", "a", "particular", "question", "in", "this", "attempt", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L1144-L1153
214,741
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.is_blocked_by_previous_question
public function is_blocked_by_previous_question($slot) { return $slot > 1 && isset($this->slots[$slot]) && $this->slots[$slot]->requireprevious && !$this->slots[$slot]->section->shufflequestions && !$this->slots[$slot - 1]->section->shufflequestions && $this->get_navigation_method() != QUIZ_NAVMETHOD_SEQ && !$this->get_question_state($slot - 1)->is_finished() && $this->quba->can_question_finish_during_attempt($slot - 1); }
php
public function is_blocked_by_previous_question($slot) { return $slot > 1 && isset($this->slots[$slot]) && $this->slots[$slot]->requireprevious && !$this->slots[$slot]->section->shufflequestions && !$this->slots[$slot - 1]->section->shufflequestions && $this->get_navigation_method() != QUIZ_NAVMETHOD_SEQ && !$this->get_question_state($slot - 1)->is_finished() && $this->quba->can_question_finish_during_attempt($slot - 1); }
[ "public", "function", "is_blocked_by_previous_question", "(", "$", "slot", ")", "{", "return", "$", "slot", ">", "1", "&&", "isset", "(", "$", "this", "->", "slots", "[", "$", "slot", "]", ")", "&&", "$", "this", "->", "slots", "[", "$", "slot", "]", "->", "requireprevious", "&&", "!", "$", "this", "->", "slots", "[", "$", "slot", "]", "->", "section", "->", "shufflequestions", "&&", "!", "$", "this", "->", "slots", "[", "$", "slot", "-", "1", "]", "->", "section", "->", "shufflequestions", "&&", "$", "this", "->", "get_navigation_method", "(", ")", "!=", "QUIZ_NAVMETHOD_SEQ", "&&", "!", "$", "this", "->", "get_question_state", "(", "$", "slot", "-", "1", ")", "->", "is_finished", "(", ")", "&&", "$", "this", "->", "quba", "->", "can_question_finish_during_attempt", "(", "$", "slot", "-", "1", ")", ";", "}" ]
Checks whether the question in this slot requires the previous question to have been completed. @param int $slot the number used to identify this question within this attempt. @return bool whether the previous question must have been completed before this one can be seen.
[ "Checks", "whether", "the", "question", "in", "this", "slot", "requires", "the", "previous", "question", "to", "have", "been", "completed", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L1180-L1187
214,742
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.can_question_be_redone_now
public function can_question_be_redone_now($slot) { return $this->get_quiz()->canredoquestions && !$this->is_finished() && $this->get_question_state($slot)->is_finished(); }
php
public function can_question_be_redone_now($slot) { return $this->get_quiz()->canredoquestions && !$this->is_finished() && $this->get_question_state($slot)->is_finished(); }
[ "public", "function", "can_question_be_redone_now", "(", "$", "slot", ")", "{", "return", "$", "this", "->", "get_quiz", "(", ")", "->", "canredoquestions", "&&", "!", "$", "this", "->", "is_finished", "(", ")", "&&", "$", "this", "->", "get_question_state", "(", "$", "slot", ")", "->", "is_finished", "(", ")", ";", "}" ]
Is it possible for this question to be re-started within this attempt? @param int $slot the number used to identify this question within this attempt. @return whether the student should be given the option to restart this question now.
[ "Is", "it", "possible", "for", "this", "question", "to", "be", "re", "-", "started", "within", "this", "attempt?" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L1195-L1198
214,743
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.get_original_slot
public function get_original_slot($slot) { $originalslot = $this->quba->get_question_attempt_metadata($slot, 'originalslot'); if ($originalslot) { return $originalslot; } else { return $slot; } }
php
public function get_original_slot($slot) { $originalslot = $this->quba->get_question_attempt_metadata($slot, 'originalslot'); if ($originalslot) { return $originalslot; } else { return $slot; } }
[ "public", "function", "get_original_slot", "(", "$", "slot", ")", "{", "$", "originalslot", "=", "$", "this", "->", "quba", "->", "get_question_attempt_metadata", "(", "$", "slot", ",", "'originalslot'", ")", ";", "if", "(", "$", "originalslot", ")", "{", "return", "$", "originalslot", ";", "}", "else", "{", "return", "$", "slot", ";", "}", "}" ]
Given a slot in this attempt, which may or not be a redone question, return the original slot. @param int $slot identifies a particular question in this attempt. @return int the slot where this question was originally.
[ "Given", "a", "slot", "in", "this", "attempt", "which", "may", "or", "not", "be", "a", "redone", "question", "return", "the", "original", "slot", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L1206-L1213
214,744
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.get_heading_before_slot
public function get_heading_before_slot($slot) { if ($this->slots[$slot]->firstinsection) { return $this->slots[$slot]->section->heading; } else { return null; } }
php
public function get_heading_before_slot($slot) { if ($this->slots[$slot]->firstinsection) { return $this->slots[$slot]->section->heading; } else { return null; } }
[ "public", "function", "get_heading_before_slot", "(", "$", "slot", ")", "{", "if", "(", "$", "this", "->", "slots", "[", "$", "slot", "]", "->", "firstinsection", ")", "{", "return", "$", "this", "->", "slots", "[", "$", "slot", "]", "->", "section", "->", "heading", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
If the section heading, if any, that should come just before this slot. @param int $slot identifies a particular question in this attempt. @return string the required heading, or null if there is not one here.
[ "If", "the", "section", "heading", "if", "any", "that", "should", "come", "just", "before", "this", "slot", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L1230-L1236
214,745
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.get_time_left_display
public function get_time_left_display($timenow) { if ($this->attempt->state != self::IN_PROGRESS) { return false; } return $this->get_access_manager($timenow)->get_time_left_display($this->attempt, $timenow); }
php
public function get_time_left_display($timenow) { if ($this->attempt->state != self::IN_PROGRESS) { return false; } return $this->get_access_manager($timenow)->get_time_left_display($this->attempt, $timenow); }
[ "public", "function", "get_time_left_display", "(", "$", "timenow", ")", "{", "if", "(", "$", "this", "->", "attempt", "->", "state", "!=", "self", "::", "IN_PROGRESS", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "get_access_manager", "(", "$", "timenow", ")", "->", "get_time_left_display", "(", "$", "this", "->", "attempt", ",", "$", "timenow", ")", ";", "}" ]
Get the time remaining for an in-progress attempt, if the time is short enought that it would be worth showing a timer. @param int $timenow the time to consider as 'now'. @return int|false the number of seconds remaining for this attempt. False if there is no limit.
[ "Get", "the", "time", "remaining", "for", "an", "in", "-", "progress", "attempt", "if", "the", "time", "is", "short", "enought", "that", "it", "would", "be", "worth", "showing", "a", "timer", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L1338-L1343
214,746
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.get_due_date
public function get_due_date() { $deadlines = array(); if ($this->quizobj->get_quiz()->timelimit) { $deadlines[] = $this->attempt->timestart + $this->quizobj->get_quiz()->timelimit; } if ($this->quizobj->get_quiz()->timeclose) { $deadlines[] = $this->quizobj->get_quiz()->timeclose; } if ($deadlines) { $duedate = min($deadlines); } else { return false; } switch ($this->attempt->state) { case self::IN_PROGRESS: return $duedate; case self::OVERDUE: return $duedate + $this->quizobj->get_quiz()->graceperiod; default: throw new coding_exception('Unexpected state: ' . $this->attempt->state); } }
php
public function get_due_date() { $deadlines = array(); if ($this->quizobj->get_quiz()->timelimit) { $deadlines[] = $this->attempt->timestart + $this->quizobj->get_quiz()->timelimit; } if ($this->quizobj->get_quiz()->timeclose) { $deadlines[] = $this->quizobj->get_quiz()->timeclose; } if ($deadlines) { $duedate = min($deadlines); } else { return false; } switch ($this->attempt->state) { case self::IN_PROGRESS: return $duedate; case self::OVERDUE: return $duedate + $this->quizobj->get_quiz()->graceperiod; default: throw new coding_exception('Unexpected state: ' . $this->attempt->state); } }
[ "public", "function", "get_due_date", "(", ")", "{", "$", "deadlines", "=", "array", "(", ")", ";", "if", "(", "$", "this", "->", "quizobj", "->", "get_quiz", "(", ")", "->", "timelimit", ")", "{", "$", "deadlines", "[", "]", "=", "$", "this", "->", "attempt", "->", "timestart", "+", "$", "this", "->", "quizobj", "->", "get_quiz", "(", ")", "->", "timelimit", ";", "}", "if", "(", "$", "this", "->", "quizobj", "->", "get_quiz", "(", ")", "->", "timeclose", ")", "{", "$", "deadlines", "[", "]", "=", "$", "this", "->", "quizobj", "->", "get_quiz", "(", ")", "->", "timeclose", ";", "}", "if", "(", "$", "deadlines", ")", "{", "$", "duedate", "=", "min", "(", "$", "deadlines", ")", ";", "}", "else", "{", "return", "false", ";", "}", "switch", "(", "$", "this", "->", "attempt", "->", "state", ")", "{", "case", "self", "::", "IN_PROGRESS", ":", "return", "$", "duedate", ";", "case", "self", "::", "OVERDUE", ":", "return", "$", "duedate", "+", "$", "this", "->", "quizobj", "->", "get_quiz", "(", ")", "->", "graceperiod", ";", "default", ":", "throw", "new", "coding_exception", "(", "'Unexpected state: '", ".", "$", "this", "->", "attempt", "->", "state", ")", ";", "}", "}" ]
If the attempt is in an applicable state, work out the time by which the student should next do something. @return int timestamp by which the student needs to do something.
[ "If", "the", "attempt", "is", "in", "an", "applicable", "state", "work", "out", "the", "time", "by", "which", "the", "student", "should", "next", "do", "something", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L1359-L1383
214,747
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.get_html_head_contributions
public function get_html_head_contributions($page = 'all', $showall = false) { if ($showall) { $page = 'all'; } $result = ''; foreach ($this->get_slots($page) as $slot) { $result .= $this->quba->render_question_head_html($slot); } $result .= question_engine::initialise_js(); return $result; }
php
public function get_html_head_contributions($page = 'all', $showall = false) { if ($showall) { $page = 'all'; } $result = ''; foreach ($this->get_slots($page) as $slot) { $result .= $this->quba->render_question_head_html($slot); } $result .= question_engine::initialise_js(); return $result; }
[ "public", "function", "get_html_head_contributions", "(", "$", "page", "=", "'all'", ",", "$", "showall", "=", "false", ")", "{", "if", "(", "$", "showall", ")", "{", "$", "page", "=", "'all'", ";", "}", "$", "result", "=", "''", ";", "foreach", "(", "$", "this", "->", "get_slots", "(", "$", "page", ")", "as", "$", "slot", ")", "{", "$", "result", ".=", "$", "this", "->", "quba", "->", "render_question_head_html", "(", "$", "slot", ")", ";", "}", "$", "result", ".=", "question_engine", "::", "initialise_js", "(", ")", ";", "return", "$", "result", ";", "}" ]
Initialise the JS etc. required all the questions on a page. @param mixed $page a page number, or 'all'.
[ "Initialise", "the", "JS", "etc", ".", "required", "all", "the", "questions", "on", "a", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L1474-L1484
214,748
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.restart_preview_button
public function restart_preview_button() { global $OUTPUT; if ($this->is_preview() && $this->is_preview_user()) { return $OUTPUT->single_button(new moodle_url( $this->start_attempt_url(), array('forcenew' => true)), get_string('startnewpreview', 'quiz')); } else { return ''; } }
php
public function restart_preview_button() { global $OUTPUT; if ($this->is_preview() && $this->is_preview_user()) { return $OUTPUT->single_button(new moodle_url( $this->start_attempt_url(), array('forcenew' => true)), get_string('startnewpreview', 'quiz')); } else { return ''; } }
[ "public", "function", "restart_preview_button", "(", ")", "{", "global", "$", "OUTPUT", ";", "if", "(", "$", "this", "->", "is_preview", "(", ")", "&&", "$", "this", "->", "is_preview_user", "(", ")", ")", "{", "return", "$", "OUTPUT", "->", "single_button", "(", "new", "moodle_url", "(", "$", "this", "->", "start_attempt_url", "(", ")", ",", "array", "(", "'forcenew'", "=>", "true", ")", ")", ",", "get_string", "(", "'startnewpreview'", ",", "'quiz'", ")", ")", ";", "}", "else", "{", "return", "''", ";", "}", "}" ]
Print the HTML for the start new preview button, if the current user is allowed to see one.
[ "Print", "the", "HTML", "for", "the", "start", "new", "preview", "button", "if", "the", "current", "user", "is", "allowed", "to", "see", "one", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L1499-L1508
214,749
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.render_question
public function render_question($slot, $reviewing, mod_quiz_renderer $renderer, $thispageurl = null) { if ($this->is_blocked_by_previous_question($slot)) { $placeholderqa = $this->make_blocked_question_placeholder($slot); $displayoptions = $this->get_display_options($reviewing); $displayoptions->manualcomment = question_display_options::HIDDEN; $displayoptions->history = question_display_options::HIDDEN; $displayoptions->readonly = true; return html_writer::div($placeholderqa->render($displayoptions, $this->get_question_number($this->get_original_slot($slot))), 'mod_quiz-blocked_question_warning'); } return $this->render_question_helper($slot, $reviewing, $thispageurl, $renderer, null); }
php
public function render_question($slot, $reviewing, mod_quiz_renderer $renderer, $thispageurl = null) { if ($this->is_blocked_by_previous_question($slot)) { $placeholderqa = $this->make_blocked_question_placeholder($slot); $displayoptions = $this->get_display_options($reviewing); $displayoptions->manualcomment = question_display_options::HIDDEN; $displayoptions->history = question_display_options::HIDDEN; $displayoptions->readonly = true; return html_writer::div($placeholderqa->render($displayoptions, $this->get_question_number($this->get_original_slot($slot))), 'mod_quiz-blocked_question_warning'); } return $this->render_question_helper($slot, $reviewing, $thispageurl, $renderer, null); }
[ "public", "function", "render_question", "(", "$", "slot", ",", "$", "reviewing", ",", "mod_quiz_renderer", "$", "renderer", ",", "$", "thispageurl", "=", "null", ")", "{", "if", "(", "$", "this", "->", "is_blocked_by_previous_question", "(", "$", "slot", ")", ")", "{", "$", "placeholderqa", "=", "$", "this", "->", "make_blocked_question_placeholder", "(", "$", "slot", ")", ";", "$", "displayoptions", "=", "$", "this", "->", "get_display_options", "(", "$", "reviewing", ")", ";", "$", "displayoptions", "->", "manualcomment", "=", "question_display_options", "::", "HIDDEN", ";", "$", "displayoptions", "->", "history", "=", "question_display_options", "::", "HIDDEN", ";", "$", "displayoptions", "->", "readonly", "=", "true", ";", "return", "html_writer", "::", "div", "(", "$", "placeholderqa", "->", "render", "(", "$", "displayoptions", ",", "$", "this", "->", "get_question_number", "(", "$", "this", "->", "get_original_slot", "(", "$", "slot", ")", ")", ")", ",", "'mod_quiz-blocked_question_warning'", ")", ";", "}", "return", "$", "this", "->", "render_question_helper", "(", "$", "slot", ",", "$", "reviewing", ",", "$", "thispageurl", ",", "$", "renderer", ",", "null", ")", ";", "}" ]
Generate the HTML that displayes the question in its current state, with the appropriate display options. @param int $slot identifies the question in the attempt. @param bool $reviewing is the being printed on an attempt or a review page. @param mod_quiz_renderer $renderer the quiz renderer. @param moodle_url $thispageurl the URL of the page this question is being printed on. @return string HTML for the question in its current state.
[ "Generate", "the", "HTML", "that", "displayes", "the", "question", "in", "its", "current", "state", "with", "the", "appropriate", "display", "options", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L1520-L1535
214,750
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.make_blocked_question_placeholder
protected function make_blocked_question_placeholder($slot) { $replacedquestion = $this->get_question_attempt($slot)->get_question(); question_bank::load_question_definition_classes('description'); $question = new qtype_description_question(); $question->id = $replacedquestion->id; $question->category = null; $question->parent = 0; $question->qtype = question_bank::get_qtype('description'); $question->name = ''; $question->questiontext = get_string('questiondependsonprevious', 'quiz'); $question->questiontextformat = FORMAT_HTML; $question->generalfeedback = ''; $question->defaultmark = $this->quba->get_question_max_mark($slot); $question->length = $replacedquestion->length; $question->penalty = 0; $question->stamp = ''; $question->version = 0; $question->hidden = 0; $question->timecreated = null; $question->timemodified = null; $question->createdby = null; $question->modifiedby = null; $placeholderqa = new question_attempt($question, $this->quba->get_id(), null, $this->quba->get_question_max_mark($slot)); $placeholderqa->set_slot($slot); $placeholderqa->start($this->get_quiz()->preferredbehaviour, 1); $placeholderqa->set_flagged($this->is_question_flagged($slot)); return $placeholderqa; }
php
protected function make_blocked_question_placeholder($slot) { $replacedquestion = $this->get_question_attempt($slot)->get_question(); question_bank::load_question_definition_classes('description'); $question = new qtype_description_question(); $question->id = $replacedquestion->id; $question->category = null; $question->parent = 0; $question->qtype = question_bank::get_qtype('description'); $question->name = ''; $question->questiontext = get_string('questiondependsonprevious', 'quiz'); $question->questiontextformat = FORMAT_HTML; $question->generalfeedback = ''; $question->defaultmark = $this->quba->get_question_max_mark($slot); $question->length = $replacedquestion->length; $question->penalty = 0; $question->stamp = ''; $question->version = 0; $question->hidden = 0; $question->timecreated = null; $question->timemodified = null; $question->createdby = null; $question->modifiedby = null; $placeholderqa = new question_attempt($question, $this->quba->get_id(), null, $this->quba->get_question_max_mark($slot)); $placeholderqa->set_slot($slot); $placeholderqa->start($this->get_quiz()->preferredbehaviour, 1); $placeholderqa->set_flagged($this->is_question_flagged($slot)); return $placeholderqa; }
[ "protected", "function", "make_blocked_question_placeholder", "(", "$", "slot", ")", "{", "$", "replacedquestion", "=", "$", "this", "->", "get_question_attempt", "(", "$", "slot", ")", "->", "get_question", "(", ")", ";", "question_bank", "::", "load_question_definition_classes", "(", "'description'", ")", ";", "$", "question", "=", "new", "qtype_description_question", "(", ")", ";", "$", "question", "->", "id", "=", "$", "replacedquestion", "->", "id", ";", "$", "question", "->", "category", "=", "null", ";", "$", "question", "->", "parent", "=", "0", ";", "$", "question", "->", "qtype", "=", "question_bank", "::", "get_qtype", "(", "'description'", ")", ";", "$", "question", "->", "name", "=", "''", ";", "$", "question", "->", "questiontext", "=", "get_string", "(", "'questiondependsonprevious'", ",", "'quiz'", ")", ";", "$", "question", "->", "questiontextformat", "=", "FORMAT_HTML", ";", "$", "question", "->", "generalfeedback", "=", "''", ";", "$", "question", "->", "defaultmark", "=", "$", "this", "->", "quba", "->", "get_question_max_mark", "(", "$", "slot", ")", ";", "$", "question", "->", "length", "=", "$", "replacedquestion", "->", "length", ";", "$", "question", "->", "penalty", "=", "0", ";", "$", "question", "->", "stamp", "=", "''", ";", "$", "question", "->", "version", "=", "0", ";", "$", "question", "->", "hidden", "=", "0", ";", "$", "question", "->", "timecreated", "=", "null", ";", "$", "question", "->", "timemodified", "=", "null", ";", "$", "question", "->", "createdby", "=", "null", ";", "$", "question", "->", "modifiedby", "=", "null", ";", "$", "placeholderqa", "=", "new", "question_attempt", "(", "$", "question", ",", "$", "this", "->", "quba", "->", "get_id", "(", ")", ",", "null", ",", "$", "this", "->", "quba", "->", "get_question_max_mark", "(", "$", "slot", ")", ")", ";", "$", "placeholderqa", "->", "set_slot", "(", "$", "slot", ")", ";", "$", "placeholderqa", "->", "start", "(", "$", "this", "->", "get_quiz", "(", ")", "->", "preferredbehaviour", ",", "1", ")", ";", "$", "placeholderqa", "->", "set_flagged", "(", "$", "this", "->", "is_question_flagged", "(", "$", "slot", ")", ")", ";", "return", "$", "placeholderqa", ";", "}" ]
Create a fake question to be displayed in place of a question that is blocked until the previous question has been answered. @param int $slot int slot number of the question to replace. @return question_definition the placeholde question.
[ "Create", "a", "fake", "question", "to", "be", "displayed", "in", "place", "of", "a", "question", "that", "is", "blocked", "until", "the", "previous", "question", "has", "been", "answered", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L1590-L1620
214,751
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.check_file_access
public function check_file_access($slot, $reviewing, $contextid, $component, $filearea, $args, $forcedownload) { $options = $this->get_display_options($reviewing); // Check permissions - warning there is similar code in review.php and // reviewquestion.php. If you change on, change them all. if ($reviewing && $this->is_own_attempt() && !$options->attempt) { return false; } if ($reviewing && !$this->is_own_attempt() && !$this->is_review_allowed()) { return false; } return $this->quba->check_file_access($slot, $options, $component, $filearea, $args, $forcedownload); }
php
public function check_file_access($slot, $reviewing, $contextid, $component, $filearea, $args, $forcedownload) { $options = $this->get_display_options($reviewing); // Check permissions - warning there is similar code in review.php and // reviewquestion.php. If you change on, change them all. if ($reviewing && $this->is_own_attempt() && !$options->attempt) { return false; } if ($reviewing && !$this->is_own_attempt() && !$this->is_review_allowed()) { return false; } return $this->quba->check_file_access($slot, $options, $component, $filearea, $args, $forcedownload); }
[ "public", "function", "check_file_access", "(", "$", "slot", ",", "$", "reviewing", ",", "$", "contextid", ",", "$", "component", ",", "$", "filearea", ",", "$", "args", ",", "$", "forcedownload", ")", "{", "$", "options", "=", "$", "this", "->", "get_display_options", "(", "$", "reviewing", ")", ";", "// Check permissions - warning there is similar code in review.php and", "// reviewquestion.php. If you change on, change them all.", "if", "(", "$", "reviewing", "&&", "$", "this", "->", "is_own_attempt", "(", ")", "&&", "!", "$", "options", "->", "attempt", ")", "{", "return", "false", ";", "}", "if", "(", "$", "reviewing", "&&", "!", "$", "this", "->", "is_own_attempt", "(", ")", "&&", "!", "$", "this", "->", "is_review_allowed", "(", ")", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "quba", "->", "check_file_access", "(", "$", "slot", ",", "$", "options", ",", "$", "component", ",", "$", "filearea", ",", "$", "args", ",", "$", "forcedownload", ")", ";", "}" ]
Check wheter access should be allowed to a particular file. @param int $id the id of a question in this quiz attempt. @param bool $reviewing is the being printed on an attempt or a review page. @param string $thispageurl the URL of the page this question is being printed on. @return string HTML for the question in its current state.
[ "Check", "wheter", "access", "should", "be", "allowed", "to", "a", "particular", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L1658-L1674
214,752
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.get_navigation_panel
public function get_navigation_panel(mod_quiz_renderer $output, $panelclass, $page, $showall = false) { $panel = new $panelclass($this, $this->get_display_options(true), $page, $showall); $bc = new block_contents(); $bc->attributes['id'] = 'mod_quiz_navblock'; $bc->attributes['role'] = 'navigation'; $bc->attributes['aria-labelledby'] = 'mod_quiz_navblock_title'; $bc->title = html_writer::span(get_string('quiznavigation', 'quiz'), '', array('id' => 'mod_quiz_navblock_title')); $bc->content = $output->navigation_panel($panel); return $bc; }
php
public function get_navigation_panel(mod_quiz_renderer $output, $panelclass, $page, $showall = false) { $panel = new $panelclass($this, $this->get_display_options(true), $page, $showall); $bc = new block_contents(); $bc->attributes['id'] = 'mod_quiz_navblock'; $bc->attributes['role'] = 'navigation'; $bc->attributes['aria-labelledby'] = 'mod_quiz_navblock_title'; $bc->title = html_writer::span(get_string('quiznavigation', 'quiz'), '', array('id' => 'mod_quiz_navblock_title')); $bc->content = $output->navigation_panel($panel); return $bc; }
[ "public", "function", "get_navigation_panel", "(", "mod_quiz_renderer", "$", "output", ",", "$", "panelclass", ",", "$", "page", ",", "$", "showall", "=", "false", ")", "{", "$", "panel", "=", "new", "$", "panelclass", "(", "$", "this", ",", "$", "this", "->", "get_display_options", "(", "true", ")", ",", "$", "page", ",", "$", "showall", ")", ";", "$", "bc", "=", "new", "block_contents", "(", ")", ";", "$", "bc", "->", "attributes", "[", "'id'", "]", "=", "'mod_quiz_navblock'", ";", "$", "bc", "->", "attributes", "[", "'role'", "]", "=", "'navigation'", ";", "$", "bc", "->", "attributes", "[", "'aria-labelledby'", "]", "=", "'mod_quiz_navblock_title'", ";", "$", "bc", "->", "title", "=", "html_writer", "::", "span", "(", "get_string", "(", "'quiznavigation'", ",", "'quiz'", ")", ",", "''", ",", "array", "(", "'id'", "=>", "'mod_quiz_navblock_title'", ")", ")", ";", "$", "bc", "->", "content", "=", "$", "output", "->", "navigation_panel", "(", "$", "panel", ")", ";", "return", "$", "bc", ";", "}" ]
Get the navigation panel object for this attempt. @param $panelclass The type of panel, quiz_attempt_nav_panel or quiz_review_nav_panel @param $page the current page number. @param $showall whether we are showing the whole quiz on one page. (Used by review.php) @return quiz_nav_panel_base the requested object.
[ "Get", "the", "navigation", "panel", "object", "for", "this", "attempt", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L1684-L1695
214,753
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.links_to_other_attempts
public function links_to_other_attempts(moodle_url $url) { $attempts = quiz_get_user_attempts($this->get_quiz()->id, $this->attempt->userid, 'all'); if (count($attempts) <= 1) { return false; } $links = new mod_quiz_links_to_other_attempts(); foreach ($attempts as $at) { if ($at->id == $this->attempt->id) { $links->links[$at->attempt] = null; } else { $links->links[$at->attempt] = new moodle_url($url, array('attempt' => $at->id)); } } return $links; }
php
public function links_to_other_attempts(moodle_url $url) { $attempts = quiz_get_user_attempts($this->get_quiz()->id, $this->attempt->userid, 'all'); if (count($attempts) <= 1) { return false; } $links = new mod_quiz_links_to_other_attempts(); foreach ($attempts as $at) { if ($at->id == $this->attempt->id) { $links->links[$at->attempt] = null; } else { $links->links[$at->attempt] = new moodle_url($url, array('attempt' => $at->id)); } } return $links; }
[ "public", "function", "links_to_other_attempts", "(", "moodle_url", "$", "url", ")", "{", "$", "attempts", "=", "quiz_get_user_attempts", "(", "$", "this", "->", "get_quiz", "(", ")", "->", "id", ",", "$", "this", "->", "attempt", "->", "userid", ",", "'all'", ")", ";", "if", "(", "count", "(", "$", "attempts", ")", "<=", "1", ")", "{", "return", "false", ";", "}", "$", "links", "=", "new", "mod_quiz_links_to_other_attempts", "(", ")", ";", "foreach", "(", "$", "attempts", "as", "$", "at", ")", "{", "if", "(", "$", "at", "->", "id", "==", "$", "this", "->", "attempt", "->", "id", ")", "{", "$", "links", "->", "links", "[", "$", "at", "->", "attempt", "]", "=", "null", ";", "}", "else", "{", "$", "links", "->", "links", "[", "$", "at", "->", "attempt", "]", "=", "new", "moodle_url", "(", "$", "url", ",", "array", "(", "'attempt'", "=>", "$", "at", "->", "id", ")", ")", ";", "}", "}", "return", "$", "links", ";", "}" ]
Return an array of variant URLs to other attempts at this quiz. The $url passed in must contain an attempt parameter. The {@link mod_quiz_links_to_other_attempts} object returned contains an array with keys that are the attempt number, 1, 2, 3. The array values are either a {@link moodle_url} with the attmept parameter updated to point to the attempt id of the other attempt, or null corresponding to the current attempt number. @param moodle_url $url a URL. @return mod_quiz_links_to_other_attempts containing array int => null|moodle_url.
[ "Return", "an", "array", "of", "variant", "URLs", "to", "other", "attempts", "at", "this", "quiz", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L1711-L1726
214,754
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.links_to_other_redos
public function links_to_other_redos($slot, moodle_url $baseurl) { $originalslot = $this->get_original_slot($slot); $qas = $this->all_question_attempts_originally_in_slot($originalslot); if (count($qas) <= 1) { return null; } $links = new mod_quiz_links_to_other_attempts(); $index = 1; foreach ($qas as $qa) { if ($qa->get_slot() == $slot) { $links->links[$index] = null; } else { $url = new moodle_url($baseurl, array('slot' => $qa->get_slot())); $links->links[$index] = new action_link($url, $index, new popup_action('click', $url, 'reviewquestion', array('width' => 450, 'height' => 650)), array('title' => get_string('reviewresponse', 'question'))); } $index++; } return $links; }
php
public function links_to_other_redos($slot, moodle_url $baseurl) { $originalslot = $this->get_original_slot($slot); $qas = $this->all_question_attempts_originally_in_slot($originalslot); if (count($qas) <= 1) { return null; } $links = new mod_quiz_links_to_other_attempts(); $index = 1; foreach ($qas as $qa) { if ($qa->get_slot() == $slot) { $links->links[$index] = null; } else { $url = new moodle_url($baseurl, array('slot' => $qa->get_slot())); $links->links[$index] = new action_link($url, $index, new popup_action('click', $url, 'reviewquestion', array('width' => 450, 'height' => 650)), array('title' => get_string('reviewresponse', 'question'))); } $index++; } return $links; }
[ "public", "function", "links_to_other_redos", "(", "$", "slot", ",", "moodle_url", "$", "baseurl", ")", "{", "$", "originalslot", "=", "$", "this", "->", "get_original_slot", "(", "$", "slot", ")", ";", "$", "qas", "=", "$", "this", "->", "all_question_attempts_originally_in_slot", "(", "$", "originalslot", ")", ";", "if", "(", "count", "(", "$", "qas", ")", "<=", "1", ")", "{", "return", "null", ";", "}", "$", "links", "=", "new", "mod_quiz_links_to_other_attempts", "(", ")", ";", "$", "index", "=", "1", ";", "foreach", "(", "$", "qas", "as", "$", "qa", ")", "{", "if", "(", "$", "qa", "->", "get_slot", "(", ")", "==", "$", "slot", ")", "{", "$", "links", "->", "links", "[", "$", "index", "]", "=", "null", ";", "}", "else", "{", "$", "url", "=", "new", "moodle_url", "(", "$", "baseurl", ",", "array", "(", "'slot'", "=>", "$", "qa", "->", "get_slot", "(", ")", ")", ")", ";", "$", "links", "->", "links", "[", "$", "index", "]", "=", "new", "action_link", "(", "$", "url", ",", "$", "index", ",", "new", "popup_action", "(", "'click'", ",", "$", "url", ",", "'reviewquestion'", ",", "array", "(", "'width'", "=>", "450", ",", "'height'", "=>", "650", ")", ")", ",", "array", "(", "'title'", "=>", "get_string", "(", "'reviewresponse'", ",", "'question'", ")", ")", ")", ";", "}", "$", "index", "++", ";", "}", "return", "$", "links", ";", "}" ]
Return an array of variant URLs to other redos of the question in a particular slot. The $url passed in must contain a slot parameter. The {@link mod_quiz_links_to_other_attempts} object returned contains an array with keys that are the redo number, 1, 2, 3. The array values are either a {@link moodle_url} with the slot parameter updated to point to the slot that has that redo of this question; or null corresponding to the redo identified by $slot. @param int $slot identifies a question in this attempt. @param moodle_url $baseurl the base URL to modify to generate each link. @return mod_quiz_links_to_other_attempts|null containing array int => null|moodle_url, or null if the question in this slot has not been redone.
[ "Return", "an", "array", "of", "variant", "URLs", "to", "other", "redos", "of", "the", "question", "in", "a", "particular", "slot", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L1744-L1767
214,755
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.handle_if_time_expired
public function handle_if_time_expired($timestamp, $studentisonline) { global $DB; $timeclose = $this->get_access_manager($timestamp)->get_end_time($this->attempt); if ($timeclose === false || $this->is_preview()) { $this->update_timecheckstate(null); return; // No time limit } if ($timestamp < $timeclose) { $this->update_timecheckstate($timeclose); return; // Time has not yet expired. } // If the attempt is already overdue, look to see if it should be abandoned ... if ($this->attempt->state == self::OVERDUE) { $timeoverdue = $timestamp - $timeclose; $graceperiod = $this->quizobj->get_quiz()->graceperiod; if ($timeoverdue >= $graceperiod) { $this->process_abandon($timestamp, $studentisonline); } else { // Overdue time has not yet expired $this->update_timecheckstate($timeclose + $graceperiod); } return; // ... and we are done. } if ($this->attempt->state != self::IN_PROGRESS) { $this->update_timecheckstate(null); return; // Attempt is already in a final state. } // Otherwise, we were in quiz_attempt::IN_PROGRESS, and time has now expired. // Transition to the appropriate state. switch ($this->quizobj->get_quiz()->overduehandling) { case 'autosubmit': $this->process_finish($timestamp, false); return; case 'graceperiod': $this->process_going_overdue($timestamp, $studentisonline); return; case 'autoabandon': $this->process_abandon($timestamp, $studentisonline); return; } // This is an overdue attempt with no overdue handling defined, so just abandon. $this->process_abandon($timestamp, $studentisonline); return; }
php
public function handle_if_time_expired($timestamp, $studentisonline) { global $DB; $timeclose = $this->get_access_manager($timestamp)->get_end_time($this->attempt); if ($timeclose === false || $this->is_preview()) { $this->update_timecheckstate(null); return; // No time limit } if ($timestamp < $timeclose) { $this->update_timecheckstate($timeclose); return; // Time has not yet expired. } // If the attempt is already overdue, look to see if it should be abandoned ... if ($this->attempt->state == self::OVERDUE) { $timeoverdue = $timestamp - $timeclose; $graceperiod = $this->quizobj->get_quiz()->graceperiod; if ($timeoverdue >= $graceperiod) { $this->process_abandon($timestamp, $studentisonline); } else { // Overdue time has not yet expired $this->update_timecheckstate($timeclose + $graceperiod); } return; // ... and we are done. } if ($this->attempt->state != self::IN_PROGRESS) { $this->update_timecheckstate(null); return; // Attempt is already in a final state. } // Otherwise, we were in quiz_attempt::IN_PROGRESS, and time has now expired. // Transition to the appropriate state. switch ($this->quizobj->get_quiz()->overduehandling) { case 'autosubmit': $this->process_finish($timestamp, false); return; case 'graceperiod': $this->process_going_overdue($timestamp, $studentisonline); return; case 'autoabandon': $this->process_abandon($timestamp, $studentisonline); return; } // This is an overdue attempt with no overdue handling defined, so just abandon. $this->process_abandon($timestamp, $studentisonline); return; }
[ "public", "function", "handle_if_time_expired", "(", "$", "timestamp", ",", "$", "studentisonline", ")", "{", "global", "$", "DB", ";", "$", "timeclose", "=", "$", "this", "->", "get_access_manager", "(", "$", "timestamp", ")", "->", "get_end_time", "(", "$", "this", "->", "attempt", ")", ";", "if", "(", "$", "timeclose", "===", "false", "||", "$", "this", "->", "is_preview", "(", ")", ")", "{", "$", "this", "->", "update_timecheckstate", "(", "null", ")", ";", "return", ";", "// No time limit", "}", "if", "(", "$", "timestamp", "<", "$", "timeclose", ")", "{", "$", "this", "->", "update_timecheckstate", "(", "$", "timeclose", ")", ";", "return", ";", "// Time has not yet expired.", "}", "// If the attempt is already overdue, look to see if it should be abandoned ...", "if", "(", "$", "this", "->", "attempt", "->", "state", "==", "self", "::", "OVERDUE", ")", "{", "$", "timeoverdue", "=", "$", "timestamp", "-", "$", "timeclose", ";", "$", "graceperiod", "=", "$", "this", "->", "quizobj", "->", "get_quiz", "(", ")", "->", "graceperiod", ";", "if", "(", "$", "timeoverdue", ">=", "$", "graceperiod", ")", "{", "$", "this", "->", "process_abandon", "(", "$", "timestamp", ",", "$", "studentisonline", ")", ";", "}", "else", "{", "// Overdue time has not yet expired", "$", "this", "->", "update_timecheckstate", "(", "$", "timeclose", "+", "$", "graceperiod", ")", ";", "}", "return", ";", "// ... and we are done.", "}", "if", "(", "$", "this", "->", "attempt", "->", "state", "!=", "self", "::", "IN_PROGRESS", ")", "{", "$", "this", "->", "update_timecheckstate", "(", "null", ")", ";", "return", ";", "// Attempt is already in a final state.", "}", "// Otherwise, we were in quiz_attempt::IN_PROGRESS, and time has now expired.", "// Transition to the appropriate state.", "switch", "(", "$", "this", "->", "quizobj", "->", "get_quiz", "(", ")", "->", "overduehandling", ")", "{", "case", "'autosubmit'", ":", "$", "this", "->", "process_finish", "(", "$", "timestamp", ",", "false", ")", ";", "return", ";", "case", "'graceperiod'", ":", "$", "this", "->", "process_going_overdue", "(", "$", "timestamp", ",", "$", "studentisonline", ")", ";", "return", ";", "case", "'autoabandon'", ":", "$", "this", "->", "process_abandon", "(", "$", "timestamp", ",", "$", "studentisonline", ")", ";", "return", ";", "}", "// This is an overdue attempt with no overdue handling defined, so just abandon.", "$", "this", "->", "process_abandon", "(", "$", "timestamp", ",", "$", "studentisonline", ")", ";", "return", ";", "}" ]
Check this attempt, to see if there are any state transitions that should happen automatically. This function will update the attempt checkstatetime. @param int $timestamp the timestamp that should be stored as the modifed @param bool $studentisonline is the student currently interacting with Moodle?
[ "Check", "this", "attempt", "to", "see", "if", "there", "are", "any", "state", "transitions", "that", "should", "happen", "automatically", ".", "This", "function", "will", "update", "the", "attempt", "checkstatetime", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L1777-L1828
214,756
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.process_submitted_actions
public function process_submitted_actions($timestamp, $becomingoverdue = false, $simulatedresponses = null) { global $DB; $transaction = $DB->start_delegated_transaction(); if ($simulatedresponses !== null) { if (is_int(key($simulatedresponses))) { // Legacy approach. Should be removed one day. $simulatedpostdata = $this->quba->prepare_simulated_post_data($simulatedresponses); } else { $simulatedpostdata = $simulatedresponses; } } else { $simulatedpostdata = null; } $this->quba->process_all_actions($timestamp, $simulatedpostdata); question_engine::save_questions_usage_by_activity($this->quba); $this->attempt->timemodified = $timestamp; if ($this->attempt->state == self::FINISHED) { $this->attempt->sumgrades = $this->quba->get_total_mark(); } if ($becomingoverdue) { $this->process_going_overdue($timestamp, true); } else { $DB->update_record('quiz_attempts', $this->attempt); } if (!$this->is_preview() && $this->attempt->state == self::FINISHED) { quiz_save_best_grade($this->get_quiz(), $this->get_userid()); } $transaction->allow_commit(); }
php
public function process_submitted_actions($timestamp, $becomingoverdue = false, $simulatedresponses = null) { global $DB; $transaction = $DB->start_delegated_transaction(); if ($simulatedresponses !== null) { if (is_int(key($simulatedresponses))) { // Legacy approach. Should be removed one day. $simulatedpostdata = $this->quba->prepare_simulated_post_data($simulatedresponses); } else { $simulatedpostdata = $simulatedresponses; } } else { $simulatedpostdata = null; } $this->quba->process_all_actions($timestamp, $simulatedpostdata); question_engine::save_questions_usage_by_activity($this->quba); $this->attempt->timemodified = $timestamp; if ($this->attempt->state == self::FINISHED) { $this->attempt->sumgrades = $this->quba->get_total_mark(); } if ($becomingoverdue) { $this->process_going_overdue($timestamp, true); } else { $DB->update_record('quiz_attempts', $this->attempt); } if (!$this->is_preview() && $this->attempt->state == self::FINISHED) { quiz_save_best_grade($this->get_quiz(), $this->get_userid()); } $transaction->allow_commit(); }
[ "public", "function", "process_submitted_actions", "(", "$", "timestamp", ",", "$", "becomingoverdue", "=", "false", ",", "$", "simulatedresponses", "=", "null", ")", "{", "global", "$", "DB", ";", "$", "transaction", "=", "$", "DB", "->", "start_delegated_transaction", "(", ")", ";", "if", "(", "$", "simulatedresponses", "!==", "null", ")", "{", "if", "(", "is_int", "(", "key", "(", "$", "simulatedresponses", ")", ")", ")", "{", "// Legacy approach. Should be removed one day.", "$", "simulatedpostdata", "=", "$", "this", "->", "quba", "->", "prepare_simulated_post_data", "(", "$", "simulatedresponses", ")", ";", "}", "else", "{", "$", "simulatedpostdata", "=", "$", "simulatedresponses", ";", "}", "}", "else", "{", "$", "simulatedpostdata", "=", "null", ";", "}", "$", "this", "->", "quba", "->", "process_all_actions", "(", "$", "timestamp", ",", "$", "simulatedpostdata", ")", ";", "question_engine", "::", "save_questions_usage_by_activity", "(", "$", "this", "->", "quba", ")", ";", "$", "this", "->", "attempt", "->", "timemodified", "=", "$", "timestamp", ";", "if", "(", "$", "this", "->", "attempt", "->", "state", "==", "self", "::", "FINISHED", ")", "{", "$", "this", "->", "attempt", "->", "sumgrades", "=", "$", "this", "->", "quba", "->", "get_total_mark", "(", ")", ";", "}", "if", "(", "$", "becomingoverdue", ")", "{", "$", "this", "->", "process_going_overdue", "(", "$", "timestamp", ",", "true", ")", ";", "}", "else", "{", "$", "DB", "->", "update_record", "(", "'quiz_attempts'", ",", "$", "this", "->", "attempt", ")", ";", "}", "if", "(", "!", "$", "this", "->", "is_preview", "(", ")", "&&", "$", "this", "->", "attempt", "->", "state", "==", "self", "::", "FINISHED", ")", "{", "quiz_save_best_grade", "(", "$", "this", "->", "get_quiz", "(", ")", ",", "$", "this", "->", "get_userid", "(", ")", ")", ";", "}", "$", "transaction", "->", "allow_commit", "(", ")", ";", "}" ]
Process all the actions that were submitted as part of the current request. @param int $timestamp the timestamp that should be stored as the modifed time in the database for these actions. If null, will use the current time. @param bool $becomingoverdue @param array|null $simulatedresponses If not null, then we are testing, and this is an array of simulated data. There are two formats supported here, for historical reasons. The newer approach is to pass an array created by {@link core_question_generator::get_simulated_post_data_for_questions_in_usage()}. the second is to pass an array slot no => contains arrays representing student responses which will be passed to {@link question_definition::prepare_simulated_post_data()}. This second method will probably get deprecated one day.
[ "Process", "all", "the", "actions", "that", "were", "submitted", "as", "part", "of", "the", "current", "request", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L1843-L1877
214,757
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.process_redo_question
public function process_redo_question($slot, $timestamp) { global $DB; if (!$this->can_question_be_redone_now($slot)) { throw new coding_exception('Attempt to restart the question in slot ' . $slot . ' when it is not in a state to be restarted.'); } $qubaids = new \mod_quiz\question\qubaids_for_users_attempts( $this->get_quizid(), $this->get_userid()); $transaction = $DB->start_delegated_transaction(); // Choose the replacement question. $questiondata = $DB->get_record('question', array('id' => $this->slots[$slot]->questionid)); if ($questiondata->qtype != 'random') { $newqusetionid = $questiondata->id; } else { $tagids = quiz_retrieve_slot_tag_ids($this->slots[$slot]->id); $randomloader = new \core_question\bank\random_question_loader($qubaids, array()); $newqusetionid = $randomloader->get_next_question_id($questiondata->category, (bool) $questiondata->questiontext, $tagids); if ($newqusetionid === null) { throw new moodle_exception('notenoughrandomquestions', 'quiz', $this->quizobj->view_url(), $questiondata); } } // Add the question to the usage. It is important we do this before we choose a variant. $newquestion = question_bank::load_question($newqusetionid); $newslot = $this->quba->add_question_in_place_of_other($slot, $newquestion); // Choose the variant. if ($newquestion->get_num_variants() == 1) { $variant = 1; } else { $variantstrategy = new core_question\engine\variants\least_used_strategy( $this->quba, $qubaids); $variant = $variantstrategy->choose_variant($newquestion->get_num_variants(), $newquestion->get_variants_selection_seed()); } // Start the question. $this->quba->start_question($slot, $variant); $this->quba->set_max_mark($newslot, 0); $this->quba->set_question_attempt_metadata($newslot, 'originalslot', $slot); question_engine::save_questions_usage_by_activity($this->quba); $transaction->allow_commit(); }
php
public function process_redo_question($slot, $timestamp) { global $DB; if (!$this->can_question_be_redone_now($slot)) { throw new coding_exception('Attempt to restart the question in slot ' . $slot . ' when it is not in a state to be restarted.'); } $qubaids = new \mod_quiz\question\qubaids_for_users_attempts( $this->get_quizid(), $this->get_userid()); $transaction = $DB->start_delegated_transaction(); // Choose the replacement question. $questiondata = $DB->get_record('question', array('id' => $this->slots[$slot]->questionid)); if ($questiondata->qtype != 'random') { $newqusetionid = $questiondata->id; } else { $tagids = quiz_retrieve_slot_tag_ids($this->slots[$slot]->id); $randomloader = new \core_question\bank\random_question_loader($qubaids, array()); $newqusetionid = $randomloader->get_next_question_id($questiondata->category, (bool) $questiondata->questiontext, $tagids); if ($newqusetionid === null) { throw new moodle_exception('notenoughrandomquestions', 'quiz', $this->quizobj->view_url(), $questiondata); } } // Add the question to the usage. It is important we do this before we choose a variant. $newquestion = question_bank::load_question($newqusetionid); $newslot = $this->quba->add_question_in_place_of_other($slot, $newquestion); // Choose the variant. if ($newquestion->get_num_variants() == 1) { $variant = 1; } else { $variantstrategy = new core_question\engine\variants\least_used_strategy( $this->quba, $qubaids); $variant = $variantstrategy->choose_variant($newquestion->get_num_variants(), $newquestion->get_variants_selection_seed()); } // Start the question. $this->quba->start_question($slot, $variant); $this->quba->set_max_mark($newslot, 0); $this->quba->set_question_attempt_metadata($newslot, 'originalslot', $slot); question_engine::save_questions_usage_by_activity($this->quba); $transaction->allow_commit(); }
[ "public", "function", "process_redo_question", "(", "$", "slot", ",", "$", "timestamp", ")", "{", "global", "$", "DB", ";", "if", "(", "!", "$", "this", "->", "can_question_be_redone_now", "(", "$", "slot", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Attempt to restart the question in slot '", ".", "$", "slot", ".", "' when it is not in a state to be restarted.'", ")", ";", "}", "$", "qubaids", "=", "new", "\\", "mod_quiz", "\\", "question", "\\", "qubaids_for_users_attempts", "(", "$", "this", "->", "get_quizid", "(", ")", ",", "$", "this", "->", "get_userid", "(", ")", ")", ";", "$", "transaction", "=", "$", "DB", "->", "start_delegated_transaction", "(", ")", ";", "// Choose the replacement question.", "$", "questiondata", "=", "$", "DB", "->", "get_record", "(", "'question'", ",", "array", "(", "'id'", "=>", "$", "this", "->", "slots", "[", "$", "slot", "]", "->", "questionid", ")", ")", ";", "if", "(", "$", "questiondata", "->", "qtype", "!=", "'random'", ")", "{", "$", "newqusetionid", "=", "$", "questiondata", "->", "id", ";", "}", "else", "{", "$", "tagids", "=", "quiz_retrieve_slot_tag_ids", "(", "$", "this", "->", "slots", "[", "$", "slot", "]", "->", "id", ")", ";", "$", "randomloader", "=", "new", "\\", "core_question", "\\", "bank", "\\", "random_question_loader", "(", "$", "qubaids", ",", "array", "(", ")", ")", ";", "$", "newqusetionid", "=", "$", "randomloader", "->", "get_next_question_id", "(", "$", "questiondata", "->", "category", ",", "(", "bool", ")", "$", "questiondata", "->", "questiontext", ",", "$", "tagids", ")", ";", "if", "(", "$", "newqusetionid", "===", "null", ")", "{", "throw", "new", "moodle_exception", "(", "'notenoughrandomquestions'", ",", "'quiz'", ",", "$", "this", "->", "quizobj", "->", "view_url", "(", ")", ",", "$", "questiondata", ")", ";", "}", "}", "// Add the question to the usage. It is important we do this before we choose a variant.", "$", "newquestion", "=", "question_bank", "::", "load_question", "(", "$", "newqusetionid", ")", ";", "$", "newslot", "=", "$", "this", "->", "quba", "->", "add_question_in_place_of_other", "(", "$", "slot", ",", "$", "newquestion", ")", ";", "// Choose the variant.", "if", "(", "$", "newquestion", "->", "get_num_variants", "(", ")", "==", "1", ")", "{", "$", "variant", "=", "1", ";", "}", "else", "{", "$", "variantstrategy", "=", "new", "core_question", "\\", "engine", "\\", "variants", "\\", "least_used_strategy", "(", "$", "this", "->", "quba", ",", "$", "qubaids", ")", ";", "$", "variant", "=", "$", "variantstrategy", "->", "choose_variant", "(", "$", "newquestion", "->", "get_num_variants", "(", ")", ",", "$", "newquestion", "->", "get_variants_selection_seed", "(", ")", ")", ";", "}", "// Start the question.", "$", "this", "->", "quba", "->", "start_question", "(", "$", "slot", ",", "$", "variant", ")", ";", "$", "this", "->", "quba", "->", "set_max_mark", "(", "$", "newslot", ",", "0", ")", ";", "$", "this", "->", "quba", "->", "set_question_attempt_metadata", "(", "$", "newslot", ",", "'originalslot'", ",", "$", "slot", ")", ";", "question_engine", "::", "save_questions_usage_by_activity", "(", "$", "this", "->", "quba", ")", ";", "$", "transaction", "->", "allow_commit", "(", ")", ";", "}" ]
Replace a question in an attempt with a new attempt at the same qestion. @param int $slot the questoin to restart. @param int $timestamp the timestamp to record for this action.
[ "Replace", "a", "question", "in", "an", "attempt", "with", "a", "new", "attempt", "at", "the", "same", "qestion", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L1884-L1935
214,758
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.process_auto_save
public function process_auto_save($timestamp) { global $DB; $transaction = $DB->start_delegated_transaction(); $this->quba->process_all_autosaves($timestamp); question_engine::save_questions_usage_by_activity($this->quba); $transaction->allow_commit(); }
php
public function process_auto_save($timestamp) { global $DB; $transaction = $DB->start_delegated_transaction(); $this->quba->process_all_autosaves($timestamp); question_engine::save_questions_usage_by_activity($this->quba); $transaction->allow_commit(); }
[ "public", "function", "process_auto_save", "(", "$", "timestamp", ")", "{", "global", "$", "DB", ";", "$", "transaction", "=", "$", "DB", "->", "start_delegated_transaction", "(", ")", ";", "$", "this", "->", "quba", "->", "process_all_autosaves", "(", "$", "timestamp", ")", ";", "question_engine", "::", "save_questions_usage_by_activity", "(", "$", "this", "->", "quba", ")", ";", "$", "transaction", "->", "allow_commit", "(", ")", ";", "}" ]
Process all the autosaved data that was part of the current request. @param int $timestamp the timestamp that should be stored as the modifed time in the database for these actions. If null, will use the current time.
[ "Process", "all", "the", "autosaved", "data", "that", "was", "part", "of", "the", "current", "request", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L1943-L1952
214,759
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.update_timecheckstate
public function update_timecheckstate($time) { global $DB; if ($this->attempt->timecheckstate !== $time) { $this->attempt->timecheckstate = $time; $DB->set_field('quiz_attempts', 'timecheckstate', $time, array('id' => $this->attempt->id)); } }
php
public function update_timecheckstate($time) { global $DB; if ($this->attempt->timecheckstate !== $time) { $this->attempt->timecheckstate = $time; $DB->set_field('quiz_attempts', 'timecheckstate', $time, array('id' => $this->attempt->id)); } }
[ "public", "function", "update_timecheckstate", "(", "$", "time", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "this", "->", "attempt", "->", "timecheckstate", "!==", "$", "time", ")", "{", "$", "this", "->", "attempt", "->", "timecheckstate", "=", "$", "time", ";", "$", "DB", "->", "set_field", "(", "'quiz_attempts'", ",", "'timecheckstate'", ",", "$", "time", ",", "array", "(", "'id'", "=>", "$", "this", "->", "attempt", "->", "id", ")", ")", ";", "}", "}" ]
Update this attempt timecheckstate if necessary. @param int|null the timecheckstate
[ "Update", "this", "attempt", "timecheckstate", "if", "necessary", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L2003-L2009
214,760
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.process_going_overdue
public function process_going_overdue($timestamp, $studentisonline) { global $DB; $transaction = $DB->start_delegated_transaction(); $this->attempt->timemodified = $timestamp; $this->attempt->state = self::OVERDUE; // If we knew the attempt close time, we could compute when the graceperiod ends. // Instead we'll just fix it up through cron. $this->attempt->timecheckstate = $timestamp; $DB->update_record('quiz_attempts', $this->attempt); $this->fire_state_transition_event('\mod_quiz\event\attempt_becameoverdue', $timestamp); $transaction->allow_commit(); quiz_send_overdue_message($this); }
php
public function process_going_overdue($timestamp, $studentisonline) { global $DB; $transaction = $DB->start_delegated_transaction(); $this->attempt->timemodified = $timestamp; $this->attempt->state = self::OVERDUE; // If we knew the attempt close time, we could compute when the graceperiod ends. // Instead we'll just fix it up through cron. $this->attempt->timecheckstate = $timestamp; $DB->update_record('quiz_attempts', $this->attempt); $this->fire_state_transition_event('\mod_quiz\event\attempt_becameoverdue', $timestamp); $transaction->allow_commit(); quiz_send_overdue_message($this); }
[ "public", "function", "process_going_overdue", "(", "$", "timestamp", ",", "$", "studentisonline", ")", "{", "global", "$", "DB", ";", "$", "transaction", "=", "$", "DB", "->", "start_delegated_transaction", "(", ")", ";", "$", "this", "->", "attempt", "->", "timemodified", "=", "$", "timestamp", ";", "$", "this", "->", "attempt", "->", "state", "=", "self", "::", "OVERDUE", ";", "// If we knew the attempt close time, we could compute when the graceperiod ends.", "// Instead we'll just fix it up through cron.", "$", "this", "->", "attempt", "->", "timecheckstate", "=", "$", "timestamp", ";", "$", "DB", "->", "update_record", "(", "'quiz_attempts'", ",", "$", "this", "->", "attempt", ")", ";", "$", "this", "->", "fire_state_transition_event", "(", "'\\mod_quiz\\event\\attempt_becameoverdue'", ",", "$", "timestamp", ")", ";", "$", "transaction", "->", "allow_commit", "(", ")", ";", "quiz_send_overdue_message", "(", "$", "this", ")", ";", "}" ]
Mark this attempt as now overdue. @param int $timestamp the time to deem as now. @param bool $studentisonline is the student currently interacting with Moodle?
[ "Mark", "this", "attempt", "as", "now", "overdue", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L2016-L2032
214,761
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.process_abandon
public function process_abandon($timestamp, $studentisonline) { global $DB; $transaction = $DB->start_delegated_transaction(); $this->attempt->timemodified = $timestamp; $this->attempt->state = self::ABANDONED; $this->attempt->timecheckstate = null; $DB->update_record('quiz_attempts', $this->attempt); $this->fire_state_transition_event('\mod_quiz\event\attempt_abandoned', $timestamp); $transaction->allow_commit(); }
php
public function process_abandon($timestamp, $studentisonline) { global $DB; $transaction = $DB->start_delegated_transaction(); $this->attempt->timemodified = $timestamp; $this->attempt->state = self::ABANDONED; $this->attempt->timecheckstate = null; $DB->update_record('quiz_attempts', $this->attempt); $this->fire_state_transition_event('\mod_quiz\event\attempt_abandoned', $timestamp); $transaction->allow_commit(); }
[ "public", "function", "process_abandon", "(", "$", "timestamp", ",", "$", "studentisonline", ")", "{", "global", "$", "DB", ";", "$", "transaction", "=", "$", "DB", "->", "start_delegated_transaction", "(", ")", ";", "$", "this", "->", "attempt", "->", "timemodified", "=", "$", "timestamp", ";", "$", "this", "->", "attempt", "->", "state", "=", "self", "::", "ABANDONED", ";", "$", "this", "->", "attempt", "->", "timecheckstate", "=", "null", ";", "$", "DB", "->", "update_record", "(", "'quiz_attempts'", ",", "$", "this", "->", "attempt", ")", ";", "$", "this", "->", "fire_state_transition_event", "(", "'\\mod_quiz\\event\\attempt_abandoned'", ",", "$", "timestamp", ")", ";", "$", "transaction", "->", "allow_commit", "(", ")", ";", "}" ]
Mark this attempt as abandoned. @param int $timestamp the time to deem as now. @param bool $studentisonline is the student currently interacting with Moodle?
[ "Mark", "this", "attempt", "as", "abandoned", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L2039-L2051
214,762
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.fire_state_transition_event
protected function fire_state_transition_event($eventclass, $timestamp) { global $USER; $quizrecord = $this->get_quiz(); $params = array( 'context' => $this->get_quizobj()->get_context(), 'courseid' => $this->get_courseid(), 'objectid' => $this->attempt->id, 'relateduserid' => $this->attempt->userid, 'other' => array( 'submitterid' => CLI_SCRIPT ? null : $USER->id, 'quizid' => $quizrecord->id ) ); $event = $eventclass::create($params); $event->add_record_snapshot('quiz', $this->get_quiz()); $event->add_record_snapshot('quiz_attempts', $this->get_attempt()); $event->trigger(); }
php
protected function fire_state_transition_event($eventclass, $timestamp) { global $USER; $quizrecord = $this->get_quiz(); $params = array( 'context' => $this->get_quizobj()->get_context(), 'courseid' => $this->get_courseid(), 'objectid' => $this->attempt->id, 'relateduserid' => $this->attempt->userid, 'other' => array( 'submitterid' => CLI_SCRIPT ? null : $USER->id, 'quizid' => $quizrecord->id ) ); $event = $eventclass::create($params); $event->add_record_snapshot('quiz', $this->get_quiz()); $event->add_record_snapshot('quiz_attempts', $this->get_attempt()); $event->trigger(); }
[ "protected", "function", "fire_state_transition_event", "(", "$", "eventclass", ",", "$", "timestamp", ")", "{", "global", "$", "USER", ";", "$", "quizrecord", "=", "$", "this", "->", "get_quiz", "(", ")", ";", "$", "params", "=", "array", "(", "'context'", "=>", "$", "this", "->", "get_quizobj", "(", ")", "->", "get_context", "(", ")", ",", "'courseid'", "=>", "$", "this", "->", "get_courseid", "(", ")", ",", "'objectid'", "=>", "$", "this", "->", "attempt", "->", "id", ",", "'relateduserid'", "=>", "$", "this", "->", "attempt", "->", "userid", ",", "'other'", "=>", "array", "(", "'submitterid'", "=>", "CLI_SCRIPT", "?", "null", ":", "$", "USER", "->", "id", ",", "'quizid'", "=>", "$", "quizrecord", "->", "id", ")", ")", ";", "$", "event", "=", "$", "eventclass", "::", "create", "(", "$", "params", ")", ";", "$", "event", "->", "add_record_snapshot", "(", "'quiz'", ",", "$", "this", "->", "get_quiz", "(", ")", ")", ";", "$", "event", "->", "add_record_snapshot", "(", "'quiz_attempts'", ",", "$", "this", "->", "get_attempt", "(", ")", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "}" ]
Fire a state transition event. the same event information. @param string $eventclass the event class name. @param int $timestamp the timestamp to include in the event. @return void
[ "Fire", "a", "state", "transition", "event", ".", "the", "same", "event", "information", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L2060-L2078
214,763
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.check_page_access
public function check_page_access($page) { global $DB; if ($this->get_currentpage() != $page) { if ($this->get_navigation_method() == QUIZ_NAVMETHOD_SEQ && $this->get_currentpage() > $page) { return false; } } return true; }
php
public function check_page_access($page) { global $DB; if ($this->get_currentpage() != $page) { if ($this->get_navigation_method() == QUIZ_NAVMETHOD_SEQ && $this->get_currentpage() > $page) { return false; } } return true; }
[ "public", "function", "check_page_access", "(", "$", "page", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "this", "->", "get_currentpage", "(", ")", "!=", "$", "page", ")", "{", "if", "(", "$", "this", "->", "get_navigation_method", "(", ")", "==", "QUIZ_NAVMETHOD_SEQ", "&&", "$", "this", "->", "get_currentpage", "(", ")", ">", "$", "page", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Check a page access to see if is an out of sequence access. @param int $page page number @return boolean false is is an out of sequence access, true otherwise. @since Moodle 3.1
[ "Check", "a", "page", "access", "to", "see", "if", "is", "an", "out", "of", "sequence", "access", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L2276-L2285
214,764
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.set_currentpage
public function set_currentpage($page) { global $DB; if ($this->check_page_access($page)) { $DB->set_field('quiz_attempts', 'currentpage', $page, array('id' => $this->get_attemptid())); return true; } return false; }
php
public function set_currentpage($page) { global $DB; if ($this->check_page_access($page)) { $DB->set_field('quiz_attempts', 'currentpage', $page, array('id' => $this->get_attemptid())); return true; } return false; }
[ "public", "function", "set_currentpage", "(", "$", "page", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "this", "->", "check_page_access", "(", "$", "page", ")", ")", "{", "$", "DB", "->", "set_field", "(", "'quiz_attempts'", ",", "'currentpage'", ",", "$", "page", ",", "array", "(", "'id'", "=>", "$", "this", "->", "get_attemptid", "(", ")", ")", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Update attempt page. @param int $page page number @return boolean true if everything was ok, false otherwise (out of sequence access). @since Moodle 3.1
[ "Update", "attempt", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L2294-L2302
214,765
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.fire_attempt_viewed_event
public function fire_attempt_viewed_event() { $params = array( 'objectid' => $this->get_attemptid(), 'relateduserid' => $this->get_userid(), 'courseid' => $this->get_courseid(), 'context' => context_module::instance($this->get_cmid()), 'other' => array( 'quizid' => $this->get_quizid() ) ); $event = \mod_quiz\event\attempt_viewed::create($params); $event->add_record_snapshot('quiz_attempts', $this->get_attempt()); $event->trigger(); }
php
public function fire_attempt_viewed_event() { $params = array( 'objectid' => $this->get_attemptid(), 'relateduserid' => $this->get_userid(), 'courseid' => $this->get_courseid(), 'context' => context_module::instance($this->get_cmid()), 'other' => array( 'quizid' => $this->get_quizid() ) ); $event = \mod_quiz\event\attempt_viewed::create($params); $event->add_record_snapshot('quiz_attempts', $this->get_attempt()); $event->trigger(); }
[ "public", "function", "fire_attempt_viewed_event", "(", ")", "{", "$", "params", "=", "array", "(", "'objectid'", "=>", "$", "this", "->", "get_attemptid", "(", ")", ",", "'relateduserid'", "=>", "$", "this", "->", "get_userid", "(", ")", ",", "'courseid'", "=>", "$", "this", "->", "get_courseid", "(", ")", ",", "'context'", "=>", "context_module", "::", "instance", "(", "$", "this", "->", "get_cmid", "(", ")", ")", ",", "'other'", "=>", "array", "(", "'quizid'", "=>", "$", "this", "->", "get_quizid", "(", ")", ")", ")", ";", "$", "event", "=", "\\", "mod_quiz", "\\", "event", "\\", "attempt_viewed", "::", "create", "(", "$", "params", ")", ";", "$", "event", "->", "add_record_snapshot", "(", "'quiz_attempts'", ",", "$", "this", "->", "get_attempt", "(", ")", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "}" ]
Trigger the attempt_viewed event. @since Moodle 3.1
[ "Trigger", "the", "attempt_viewed", "event", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L2309-L2322
214,766
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.fire_attempt_summary_viewed_event
public function fire_attempt_summary_viewed_event() { $params = array( 'objectid' => $this->get_attemptid(), 'relateduserid' => $this->get_userid(), 'courseid' => $this->get_courseid(), 'context' => context_module::instance($this->get_cmid()), 'other' => array( 'quizid' => $this->get_quizid() ) ); $event = \mod_quiz\event\attempt_summary_viewed::create($params); $event->add_record_snapshot('quiz_attempts', $this->get_attempt()); $event->trigger(); }
php
public function fire_attempt_summary_viewed_event() { $params = array( 'objectid' => $this->get_attemptid(), 'relateduserid' => $this->get_userid(), 'courseid' => $this->get_courseid(), 'context' => context_module::instance($this->get_cmid()), 'other' => array( 'quizid' => $this->get_quizid() ) ); $event = \mod_quiz\event\attempt_summary_viewed::create($params); $event->add_record_snapshot('quiz_attempts', $this->get_attempt()); $event->trigger(); }
[ "public", "function", "fire_attempt_summary_viewed_event", "(", ")", "{", "$", "params", "=", "array", "(", "'objectid'", "=>", "$", "this", "->", "get_attemptid", "(", ")", ",", "'relateduserid'", "=>", "$", "this", "->", "get_userid", "(", ")", ",", "'courseid'", "=>", "$", "this", "->", "get_courseid", "(", ")", ",", "'context'", "=>", "context_module", "::", "instance", "(", "$", "this", "->", "get_cmid", "(", ")", ")", ",", "'other'", "=>", "array", "(", "'quizid'", "=>", "$", "this", "->", "get_quizid", "(", ")", ")", ")", ";", "$", "event", "=", "\\", "mod_quiz", "\\", "event", "\\", "attempt_summary_viewed", "::", "create", "(", "$", "params", ")", ";", "$", "event", "->", "add_record_snapshot", "(", "'quiz_attempts'", ",", "$", "this", "->", "get_attempt", "(", ")", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "}" ]
Trigger the attempt_summary_viewed event. @since Moodle 3.1
[ "Trigger", "the", "attempt_summary_viewed", "event", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L2329-L2343
214,767
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.fire_attempt_reviewed_event
public function fire_attempt_reviewed_event() { $params = array( 'objectid' => $this->get_attemptid(), 'relateduserid' => $this->get_userid(), 'courseid' => $this->get_courseid(), 'context' => context_module::instance($this->get_cmid()), 'other' => array( 'quizid' => $this->get_quizid() ) ); $event = \mod_quiz\event\attempt_reviewed::create($params); $event->add_record_snapshot('quiz_attempts', $this->get_attempt()); $event->trigger(); }
php
public function fire_attempt_reviewed_event() { $params = array( 'objectid' => $this->get_attemptid(), 'relateduserid' => $this->get_userid(), 'courseid' => $this->get_courseid(), 'context' => context_module::instance($this->get_cmid()), 'other' => array( 'quizid' => $this->get_quizid() ) ); $event = \mod_quiz\event\attempt_reviewed::create($params); $event->add_record_snapshot('quiz_attempts', $this->get_attempt()); $event->trigger(); }
[ "public", "function", "fire_attempt_reviewed_event", "(", ")", "{", "$", "params", "=", "array", "(", "'objectid'", "=>", "$", "this", "->", "get_attemptid", "(", ")", ",", "'relateduserid'", "=>", "$", "this", "->", "get_userid", "(", ")", ",", "'courseid'", "=>", "$", "this", "->", "get_courseid", "(", ")", ",", "'context'", "=>", "context_module", "::", "instance", "(", "$", "this", "->", "get_cmid", "(", ")", ")", ",", "'other'", "=>", "array", "(", "'quizid'", "=>", "$", "this", "->", "get_quizid", "(", ")", ")", ")", ";", "$", "event", "=", "\\", "mod_quiz", "\\", "event", "\\", "attempt_reviewed", "::", "create", "(", "$", "params", ")", ";", "$", "event", "->", "add_record_snapshot", "(", "'quiz_attempts'", ",", "$", "this", "->", "get_attempt", "(", ")", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "}" ]
Trigger the attempt_reviewed event. @since Moodle 3.1
[ "Trigger", "the", "attempt_reviewed", "event", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L2350-L2364
214,768
moodle/moodle
mod/quiz/attemptlib.php
quiz_attempt.set_offline_modified_time
public function set_offline_modified_time($time) { global $DB; // Update the timemodifiedoffline field only if web services are being used. if (WS_SERVER) { $this->attempt->timemodifiedoffline = $time; return true; } return false; }
php
public function set_offline_modified_time($time) { global $DB; // Update the timemodifiedoffline field only if web services are being used. if (WS_SERVER) { $this->attempt->timemodifiedoffline = $time; return true; } return false; }
[ "public", "function", "set_offline_modified_time", "(", "$", "time", ")", "{", "global", "$", "DB", ";", "// Update the timemodifiedoffline field only if web services are being used.", "if", "(", "WS_SERVER", ")", "{", "$", "this", "->", "attempt", "->", "timemodifiedoffline", "=", "$", "time", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Update the timemodifiedoffline attempt field. This function should be used only when web services are being used. @param int $time time stamp @return boolean false if the field is not updated because web services aren't being used. @since Moodle 3.2
[ "Update", "the", "timemodifiedoffline", "attempt", "field", ".", "This", "function", "should", "be", "used", "only", "when", "web", "services", "are", "being", "used", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L2374-L2383
214,769
moodle/moodle
mod/quiz/attemptlib.php
quiz_nav_panel_base.get_question_buttons
public function get_question_buttons() { $buttons = array(); foreach ($this->attemptobj->get_slots() as $slot) { if ($heading = $this->attemptobj->get_heading_before_slot($slot)) { $buttons[] = new quiz_nav_section_heading(format_string($heading)); } $qa = $this->attemptobj->get_question_attempt($slot); $showcorrectness = $this->options->correctness && $qa->has_marks(); $button = new quiz_nav_question_button(); $button->id = 'quiznavbutton' . $slot; $button->number = $this->attemptobj->get_question_number($slot); $button->stateclass = $qa->get_state_class($showcorrectness); $button->navmethod = $this->attemptobj->get_navigation_method(); if (!$showcorrectness && $button->stateclass == 'notanswered') { $button->stateclass = 'complete'; } $button->statestring = $this->get_state_string($qa, $showcorrectness); $button->page = $this->attemptobj->get_question_page($slot); $button->currentpage = $this->showall || $button->page == $this->page; $button->flagged = $qa->is_flagged(); $button->url = $this->get_question_url($slot); if ($this->attemptobj->is_blocked_by_previous_question($slot)) { $button->url = null; $button->stateclass = 'blocked'; $button->statestring = get_string('questiondependsonprevious', 'quiz'); } $buttons[] = $button; } return $buttons; }
php
public function get_question_buttons() { $buttons = array(); foreach ($this->attemptobj->get_slots() as $slot) { if ($heading = $this->attemptobj->get_heading_before_slot($slot)) { $buttons[] = new quiz_nav_section_heading(format_string($heading)); } $qa = $this->attemptobj->get_question_attempt($slot); $showcorrectness = $this->options->correctness && $qa->has_marks(); $button = new quiz_nav_question_button(); $button->id = 'quiznavbutton' . $slot; $button->number = $this->attemptobj->get_question_number($slot); $button->stateclass = $qa->get_state_class($showcorrectness); $button->navmethod = $this->attemptobj->get_navigation_method(); if (!$showcorrectness && $button->stateclass == 'notanswered') { $button->stateclass = 'complete'; } $button->statestring = $this->get_state_string($qa, $showcorrectness); $button->page = $this->attemptobj->get_question_page($slot); $button->currentpage = $this->showall || $button->page == $this->page; $button->flagged = $qa->is_flagged(); $button->url = $this->get_question_url($slot); if ($this->attemptobj->is_blocked_by_previous_question($slot)) { $button->url = null; $button->stateclass = 'blocked'; $button->statestring = get_string('questiondependsonprevious', 'quiz'); } $buttons[] = $button; } return $buttons; }
[ "public", "function", "get_question_buttons", "(", ")", "{", "$", "buttons", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "attemptobj", "->", "get_slots", "(", ")", "as", "$", "slot", ")", "{", "if", "(", "$", "heading", "=", "$", "this", "->", "attemptobj", "->", "get_heading_before_slot", "(", "$", "slot", ")", ")", "{", "$", "buttons", "[", "]", "=", "new", "quiz_nav_section_heading", "(", "format_string", "(", "$", "heading", ")", ")", ";", "}", "$", "qa", "=", "$", "this", "->", "attemptobj", "->", "get_question_attempt", "(", "$", "slot", ")", ";", "$", "showcorrectness", "=", "$", "this", "->", "options", "->", "correctness", "&&", "$", "qa", "->", "has_marks", "(", ")", ";", "$", "button", "=", "new", "quiz_nav_question_button", "(", ")", ";", "$", "button", "->", "id", "=", "'quiznavbutton'", ".", "$", "slot", ";", "$", "button", "->", "number", "=", "$", "this", "->", "attemptobj", "->", "get_question_number", "(", "$", "slot", ")", ";", "$", "button", "->", "stateclass", "=", "$", "qa", "->", "get_state_class", "(", "$", "showcorrectness", ")", ";", "$", "button", "->", "navmethod", "=", "$", "this", "->", "attemptobj", "->", "get_navigation_method", "(", ")", ";", "if", "(", "!", "$", "showcorrectness", "&&", "$", "button", "->", "stateclass", "==", "'notanswered'", ")", "{", "$", "button", "->", "stateclass", "=", "'complete'", ";", "}", "$", "button", "->", "statestring", "=", "$", "this", "->", "get_state_string", "(", "$", "qa", ",", "$", "showcorrectness", ")", ";", "$", "button", "->", "page", "=", "$", "this", "->", "attemptobj", "->", "get_question_page", "(", "$", "slot", ")", ";", "$", "button", "->", "currentpage", "=", "$", "this", "->", "showall", "||", "$", "button", "->", "page", "==", "$", "this", "->", "page", ";", "$", "button", "->", "flagged", "=", "$", "qa", "->", "is_flagged", "(", ")", ";", "$", "button", "->", "url", "=", "$", "this", "->", "get_question_url", "(", "$", "slot", ")", ";", "if", "(", "$", "this", "->", "attemptobj", "->", "is_blocked_by_previous_question", "(", "$", "slot", ")", ")", "{", "$", "button", "->", "url", "=", "null", ";", "$", "button", "->", "stateclass", "=", "'blocked'", ";", "$", "button", "->", "statestring", "=", "get_string", "(", "'questiondependsonprevious'", ",", "'quiz'", ")", ";", "}", "$", "buttons", "[", "]", "=", "$", "button", ";", "}", "return", "$", "buttons", ";", "}" ]
Get the buttons and section headings to go in the quiz navigation block. @return renderable[] the buttons, possibly interleaved with section headings.
[ "Get", "the", "buttons", "and", "section", "headings", "to", "go", "in", "the", "quiz", "navigation", "block", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/attemptlib.php#L2466-L2498
214,770
moodle/moodle
admin/tool/analytics/classes/output/model_logs.php
model_logs.col_indicators
public function col_indicators($log) { $indicatorclasses = json_decode($log->indicators); $indicators = array(); foreach ($indicatorclasses as $indicatorclass) { $indicator = \core_analytics\manager::get_indicator($indicatorclass); if ($indicator) { $indicators[] = $indicator->get_name(); } else { debugging('Can\'t load ' . $indicatorclass . ' indicator', DEBUG_DEVELOPER); } } return '<ul><li>' . implode('</li><li>', $indicators) . '</li></ul>'; }
php
public function col_indicators($log) { $indicatorclasses = json_decode($log->indicators); $indicators = array(); foreach ($indicatorclasses as $indicatorclass) { $indicator = \core_analytics\manager::get_indicator($indicatorclass); if ($indicator) { $indicators[] = $indicator->get_name(); } else { debugging('Can\'t load ' . $indicatorclass . ' indicator', DEBUG_DEVELOPER); } } return '<ul><li>' . implode('</li><li>', $indicators) . '</li></ul>'; }
[ "public", "function", "col_indicators", "(", "$", "log", ")", "{", "$", "indicatorclasses", "=", "json_decode", "(", "$", "log", "->", "indicators", ")", ";", "$", "indicators", "=", "array", "(", ")", ";", "foreach", "(", "$", "indicatorclasses", "as", "$", "indicatorclass", ")", "{", "$", "indicator", "=", "\\", "core_analytics", "\\", "manager", "::", "get_indicator", "(", "$", "indicatorclass", ")", ";", "if", "(", "$", "indicator", ")", "{", "$", "indicators", "[", "]", "=", "$", "indicator", "->", "get_name", "(", ")", ";", "}", "else", "{", "debugging", "(", "'Can\\'t load '", ".", "$", "indicatorclass", ".", "' indicator'", ",", "DEBUG_DEVELOPER", ")", ";", "}", "}", "return", "'<ul><li>'", ".", "implode", "(", "'</li><li>'", ",", "$", "indicators", ")", ".", "'</li></ul>'", ";", "}" ]
Generate the indicators column. @param \stdClass $log log data. @return string HTML for the indicators column
[ "Generate", "the", "indicators", "column", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/analytics/classes/output/model_logs.php#L131-L143
214,771
moodle/moodle
admin/tool/analytics/classes/output/model_logs.php
model_logs.col_info
public function col_info($log) { global $PAGE; if (empty($log->info) && empty($log->dir)) { return ''; } $info = array(); if (!empty($log->info)) { $info = json_decode($log->info); } if (!empty($log->dir)) { $info[] = get_string('predictorresultsin', 'tool_analytics', $log->dir); } $PAGE->requires->js_call_amd('tool_analytics/log_info', 'loadInfo', array($log->id, $info)); return \html_writer::link('#', get_string('view'), array('data-model-log-id' => $log->id)); }
php
public function col_info($log) { global $PAGE; if (empty($log->info) && empty($log->dir)) { return ''; } $info = array(); if (!empty($log->info)) { $info = json_decode($log->info); } if (!empty($log->dir)) { $info[] = get_string('predictorresultsin', 'tool_analytics', $log->dir); } $PAGE->requires->js_call_amd('tool_analytics/log_info', 'loadInfo', array($log->id, $info)); return \html_writer::link('#', get_string('view'), array('data-model-log-id' => $log->id)); }
[ "public", "function", "col_info", "(", "$", "log", ")", "{", "global", "$", "PAGE", ";", "if", "(", "empty", "(", "$", "log", "->", "info", ")", "&&", "empty", "(", "$", "log", "->", "dir", ")", ")", "{", "return", "''", ";", "}", "$", "info", "=", "array", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "log", "->", "info", ")", ")", "{", "$", "info", "=", "json_decode", "(", "$", "log", "->", "info", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "log", "->", "dir", ")", ")", "{", "$", "info", "[", "]", "=", "get_string", "(", "'predictorresultsin'", ",", "'tool_analytics'", ",", "$", "log", "->", "dir", ")", ";", "}", "$", "PAGE", "->", "requires", "->", "js_call_amd", "(", "'tool_analytics/log_info'", ",", "'loadInfo'", ",", "array", "(", "$", "log", "->", "id", ",", "$", "info", ")", ")", ";", "return", "\\", "html_writer", "::", "link", "(", "'#'", ",", "get_string", "(", "'view'", ")", ",", "array", "(", "'data-model-log-id'", "=>", "$", "log", "->", "id", ")", ")", ";", "}" ]
Generate the info column. @param \stdClass $log log data. @return string HTML for the score column
[ "Generate", "the", "info", "column", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/analytics/classes/output/model_logs.php#L172-L188
214,772
moodle/moodle
admin/tool/analytics/classes/output/model_logs.php
model_logs.query_db
public function query_db($pagesize, $useinitialsbar = true) { $total = count($this->model->get_logs()); $this->pagesize($pagesize, $total); $this->rawdata = $this->model->get_logs($this->get_page_start(), $this->get_page_size()); // Set initial bars. if ($useinitialsbar) { $this->initialbars($total > $pagesize); } }
php
public function query_db($pagesize, $useinitialsbar = true) { $total = count($this->model->get_logs()); $this->pagesize($pagesize, $total); $this->rawdata = $this->model->get_logs($this->get_page_start(), $this->get_page_size()); // Set initial bars. if ($useinitialsbar) { $this->initialbars($total > $pagesize); } }
[ "public", "function", "query_db", "(", "$", "pagesize", ",", "$", "useinitialsbar", "=", "true", ")", "{", "$", "total", "=", "count", "(", "$", "this", "->", "model", "->", "get_logs", "(", ")", ")", ";", "$", "this", "->", "pagesize", "(", "$", "pagesize", ",", "$", "total", ")", ";", "$", "this", "->", "rawdata", "=", "$", "this", "->", "model", "->", "get_logs", "(", "$", "this", "->", "get_page_start", "(", ")", ",", "$", "this", "->", "get_page_size", "(", ")", ")", ";", "// Set initial bars.", "if", "(", "$", "useinitialsbar", ")", "{", "$", "this", "->", "initialbars", "(", "$", "total", ">", "$", "pagesize", ")", ";", "}", "}" ]
Query the logs table. Store results in the object for use by build_table. @param int $pagesize size of page for paginated displayed table. @param bool $useinitialsbar do you want to use the initials bar.
[ "Query", "the", "logs", "table", ".", "Store", "results", "in", "the", "object", "for", "use", "by", "build_table", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/analytics/classes/output/model_logs.php#L207-L216
214,773
moodle/moodle
lib/horde/framework/Horde/Mime/QuotedPrintable.php
Horde_Mime_QuotedPrintable.encode
public static function encode($text, $eol = "\n", $wrap = 76) { $fp = fopen('php://temp', 'r+'); stream_filter_append( $fp, 'convert.quoted-printable-encode', STREAM_FILTER_WRITE, array( 'line-break-chars' => $eol, 'line-length' => $wrap ) ); fwrite($fp, $text); rewind($fp); $out = stream_get_contents($fp); fclose($fp); return $out; }
php
public static function encode($text, $eol = "\n", $wrap = 76) { $fp = fopen('php://temp', 'r+'); stream_filter_append( $fp, 'convert.quoted-printable-encode', STREAM_FILTER_WRITE, array( 'line-break-chars' => $eol, 'line-length' => $wrap ) ); fwrite($fp, $text); rewind($fp); $out = stream_get_contents($fp); fclose($fp); return $out; }
[ "public", "static", "function", "encode", "(", "$", "text", ",", "$", "eol", "=", "\"\\n\"", ",", "$", "wrap", "=", "76", ")", "{", "$", "fp", "=", "fopen", "(", "'php://temp'", ",", "'r+'", ")", ";", "stream_filter_append", "(", "$", "fp", ",", "'convert.quoted-printable-encode'", ",", "STREAM_FILTER_WRITE", ",", "array", "(", "'line-break-chars'", "=>", "$", "eol", ",", "'line-length'", "=>", "$", "wrap", ")", ")", ";", "fwrite", "(", "$", "fp", ",", "$", "text", ")", ";", "rewind", "(", "$", "fp", ")", ";", "$", "out", "=", "stream_get_contents", "(", "$", "fp", ")", ";", "fclose", "(", "$", "fp", ")", ";", "return", "$", "out", ";", "}" ]
Encodes text via quoted-printable encoding. @param string $text The text to encode (UTF-8). @param string $eol The EOL sequence to use. @param integer $wrap Wrap a line at this many characters. @return string The quoted-printable encoded string.
[ "Encodes", "text", "via", "quoted", "-", "printable", "encoding", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/QuotedPrintable.php#L47-L65
214,774
moodle/moodle
competency/classes/url.php
url.get
protected static function get($resource, $args) { global $CFG; if (!isset(static::$resolver)) { $klass = !empty($CFG->core_competency_url_resolver) ? $CFG->core_competency_url_resolver : 'tool_lp\\url_resolver'; static::$resolver = new $klass(); } if (!method_exists(static::$resolver, $resource)) { debugging("URL for '$resource' not implemented.", DEBUG_DEVELOPER); return new moodle_url('/'); } return call_user_func_array([static::$resolver, $resource], $args); }
php
protected static function get($resource, $args) { global $CFG; if (!isset(static::$resolver)) { $klass = !empty($CFG->core_competency_url_resolver) ? $CFG->core_competency_url_resolver : 'tool_lp\\url_resolver'; static::$resolver = new $klass(); } if (!method_exists(static::$resolver, $resource)) { debugging("URL for '$resource' not implemented.", DEBUG_DEVELOPER); return new moodle_url('/'); } return call_user_func_array([static::$resolver, $resource], $args); }
[ "protected", "static", "function", "get", "(", "$", "resource", ",", "$", "args", ")", "{", "global", "$", "CFG", ";", "if", "(", "!", "isset", "(", "static", "::", "$", "resolver", ")", ")", "{", "$", "klass", "=", "!", "empty", "(", "$", "CFG", "->", "core_competency_url_resolver", ")", "?", "$", "CFG", "->", "core_competency_url_resolver", ":", "'tool_lp\\\\url_resolver'", ";", "static", "::", "$", "resolver", "=", "new", "$", "klass", "(", ")", ";", "}", "if", "(", "!", "method_exists", "(", "static", "::", "$", "resolver", ",", "$", "resource", ")", ")", "{", "debugging", "(", "\"URL for '$resource' not implemented.\"", ",", "DEBUG_DEVELOPER", ")", ";", "return", "new", "moodle_url", "(", "'/'", ")", ";", "}", "return", "call_user_func_array", "(", "[", "static", "::", "$", "resolver", ",", "$", "resource", "]", ",", "$", "args", ")", ";", "}" ]
Defer to the resolver. @param string $resource The resource type. @param array $args The arguments. @return mixed
[ "Defer", "to", "the", "resolver", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/url.php#L62-L73
214,775
moodle/moodle
lib/classes/access/get_user_capability_course_helper.php
get_user_capability_course_helper.calculate_permission_tree
protected static function calculate_permission_tree(array $pathroleperms) { // Considering each discovered context path as an inflection point, evaluate the user's // permission (based on all roles) at each point. $pathallows = []; $mindepth = 1000; $maxdepth = 0; foreach ($pathroleperms as $path => $roles) { $evaluatedroleperms = []; // Walk up the tree starting from this path. $innerpath = $path; while ($innerpath !== '') { $roles = $pathroleperms[$innerpath]; // Evaluate roles at this path level. foreach ($roles as $roleid => $perm) { if (!array_key_exists($roleid, $evaluatedroleperms)) { $evaluatedroleperms[$roleid] = $perm; } else { // The existing one is at a more specific level so it takes precedence // UNLESS this is a prohibit. if ($perm == CAP_PROHIBIT) { $evaluatedroleperms[$roleid] = $perm; } } } // Go up to next path level (if any). do { $innerpath = substr($innerpath, 0, strrpos($innerpath, '/')); if ($innerpath === '') { // No higher level data. break; } } while (!array_key_exists($innerpath, $pathroleperms)); } // If we have an allow from any role, and no prohibits, then user can access this path, // else not. $allow = false; foreach ($evaluatedroleperms as $perm) { if ($perm == CAP_ALLOW) { $allow = true; } else if ($perm == CAP_PROHIBIT) { $allow = false; break; } } // Store the result based on path and depth so that we can process in depth order in // the next step. $depth = strlen(preg_replace('~[^/]~', '', $path)); $mindepth = min($depth, $mindepth); $maxdepth = max($depth, $maxdepth); $pathallows[$depth][$path] = $allow; } // Organise into a tree structure, processing in depth order so that we have ancestors // set up before we encounter their children. $root = (object)['allow' => false, 'path' => null, 'children' => []]; $nodesbypath = []; for ($depth = $mindepth; $depth <= $maxdepth; $depth++) { // Skip any missing depth levels. if (!array_key_exists($depth, $pathallows)) { continue; } foreach ($pathallows[$depth] as $path => $allow) { // Value for new tree node. $leaf = (object)['allow' => $allow, 'path' => $path, 'children' => []]; // Try to find a place to join it on if there is one. $ancestorpath = $path; $found = false; while ($ancestorpath) { $ancestorpath = substr($ancestorpath, 0, strrpos($ancestorpath, '/')); if (array_key_exists($ancestorpath, $nodesbypath)) { $found = true; break; } } if ($found) { $nodesbypath[$ancestorpath]->children[] = $leaf; } else { $root->children[] = $leaf; } $nodesbypath[$path] = $leaf; } } return $root; }
php
protected static function calculate_permission_tree(array $pathroleperms) { // Considering each discovered context path as an inflection point, evaluate the user's // permission (based on all roles) at each point. $pathallows = []; $mindepth = 1000; $maxdepth = 0; foreach ($pathroleperms as $path => $roles) { $evaluatedroleperms = []; // Walk up the tree starting from this path. $innerpath = $path; while ($innerpath !== '') { $roles = $pathroleperms[$innerpath]; // Evaluate roles at this path level. foreach ($roles as $roleid => $perm) { if (!array_key_exists($roleid, $evaluatedroleperms)) { $evaluatedroleperms[$roleid] = $perm; } else { // The existing one is at a more specific level so it takes precedence // UNLESS this is a prohibit. if ($perm == CAP_PROHIBIT) { $evaluatedroleperms[$roleid] = $perm; } } } // Go up to next path level (if any). do { $innerpath = substr($innerpath, 0, strrpos($innerpath, '/')); if ($innerpath === '') { // No higher level data. break; } } while (!array_key_exists($innerpath, $pathroleperms)); } // If we have an allow from any role, and no prohibits, then user can access this path, // else not. $allow = false; foreach ($evaluatedroleperms as $perm) { if ($perm == CAP_ALLOW) { $allow = true; } else if ($perm == CAP_PROHIBIT) { $allow = false; break; } } // Store the result based on path and depth so that we can process in depth order in // the next step. $depth = strlen(preg_replace('~[^/]~', '', $path)); $mindepth = min($depth, $mindepth); $maxdepth = max($depth, $maxdepth); $pathallows[$depth][$path] = $allow; } // Organise into a tree structure, processing in depth order so that we have ancestors // set up before we encounter their children. $root = (object)['allow' => false, 'path' => null, 'children' => []]; $nodesbypath = []; for ($depth = $mindepth; $depth <= $maxdepth; $depth++) { // Skip any missing depth levels. if (!array_key_exists($depth, $pathallows)) { continue; } foreach ($pathallows[$depth] as $path => $allow) { // Value for new tree node. $leaf = (object)['allow' => $allow, 'path' => $path, 'children' => []]; // Try to find a place to join it on if there is one. $ancestorpath = $path; $found = false; while ($ancestorpath) { $ancestorpath = substr($ancestorpath, 0, strrpos($ancestorpath, '/')); if (array_key_exists($ancestorpath, $nodesbypath)) { $found = true; break; } } if ($found) { $nodesbypath[$ancestorpath]->children[] = $leaf; } else { $root->children[] = $leaf; } $nodesbypath[$path] = $leaf; } } return $root; }
[ "protected", "static", "function", "calculate_permission_tree", "(", "array", "$", "pathroleperms", ")", "{", "// Considering each discovered context path as an inflection point, evaluate the user's", "// permission (based on all roles) at each point.", "$", "pathallows", "=", "[", "]", ";", "$", "mindepth", "=", "1000", ";", "$", "maxdepth", "=", "0", ";", "foreach", "(", "$", "pathroleperms", "as", "$", "path", "=>", "$", "roles", ")", "{", "$", "evaluatedroleperms", "=", "[", "]", ";", "// Walk up the tree starting from this path.", "$", "innerpath", "=", "$", "path", ";", "while", "(", "$", "innerpath", "!==", "''", ")", "{", "$", "roles", "=", "$", "pathroleperms", "[", "$", "innerpath", "]", ";", "// Evaluate roles at this path level.", "foreach", "(", "$", "roles", "as", "$", "roleid", "=>", "$", "perm", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "roleid", ",", "$", "evaluatedroleperms", ")", ")", "{", "$", "evaluatedroleperms", "[", "$", "roleid", "]", "=", "$", "perm", ";", "}", "else", "{", "// The existing one is at a more specific level so it takes precedence", "// UNLESS this is a prohibit.", "if", "(", "$", "perm", "==", "CAP_PROHIBIT", ")", "{", "$", "evaluatedroleperms", "[", "$", "roleid", "]", "=", "$", "perm", ";", "}", "}", "}", "// Go up to next path level (if any).", "do", "{", "$", "innerpath", "=", "substr", "(", "$", "innerpath", ",", "0", ",", "strrpos", "(", "$", "innerpath", ",", "'/'", ")", ")", ";", "if", "(", "$", "innerpath", "===", "''", ")", "{", "// No higher level data.", "break", ";", "}", "}", "while", "(", "!", "array_key_exists", "(", "$", "innerpath", ",", "$", "pathroleperms", ")", ")", ";", "}", "// If we have an allow from any role, and no prohibits, then user can access this path,", "// else not.", "$", "allow", "=", "false", ";", "foreach", "(", "$", "evaluatedroleperms", "as", "$", "perm", ")", "{", "if", "(", "$", "perm", "==", "CAP_ALLOW", ")", "{", "$", "allow", "=", "true", ";", "}", "else", "if", "(", "$", "perm", "==", "CAP_PROHIBIT", ")", "{", "$", "allow", "=", "false", ";", "break", ";", "}", "}", "// Store the result based on path and depth so that we can process in depth order in", "// the next step.", "$", "depth", "=", "strlen", "(", "preg_replace", "(", "'~[^/]~'", ",", "''", ",", "$", "path", ")", ")", ";", "$", "mindepth", "=", "min", "(", "$", "depth", ",", "$", "mindepth", ")", ";", "$", "maxdepth", "=", "max", "(", "$", "depth", ",", "$", "maxdepth", ")", ";", "$", "pathallows", "[", "$", "depth", "]", "[", "$", "path", "]", "=", "$", "allow", ";", "}", "// Organise into a tree structure, processing in depth order so that we have ancestors", "// set up before we encounter their children.", "$", "root", "=", "(", "object", ")", "[", "'allow'", "=>", "false", ",", "'path'", "=>", "null", ",", "'children'", "=>", "[", "]", "]", ";", "$", "nodesbypath", "=", "[", "]", ";", "for", "(", "$", "depth", "=", "$", "mindepth", ";", "$", "depth", "<=", "$", "maxdepth", ";", "$", "depth", "++", ")", "{", "// Skip any missing depth levels.", "if", "(", "!", "array_key_exists", "(", "$", "depth", ",", "$", "pathallows", ")", ")", "{", "continue", ";", "}", "foreach", "(", "$", "pathallows", "[", "$", "depth", "]", "as", "$", "path", "=>", "$", "allow", ")", "{", "// Value for new tree node.", "$", "leaf", "=", "(", "object", ")", "[", "'allow'", "=>", "$", "allow", ",", "'path'", "=>", "$", "path", ",", "'children'", "=>", "[", "]", "]", ";", "// Try to find a place to join it on if there is one.", "$", "ancestorpath", "=", "$", "path", ";", "$", "found", "=", "false", ";", "while", "(", "$", "ancestorpath", ")", "{", "$", "ancestorpath", "=", "substr", "(", "$", "ancestorpath", ",", "0", ",", "strrpos", "(", "$", "ancestorpath", ",", "'/'", ")", ")", ";", "if", "(", "array_key_exists", "(", "$", "ancestorpath", ",", "$", "nodesbypath", ")", ")", "{", "$", "found", "=", "true", ";", "break", ";", "}", "}", "if", "(", "$", "found", ")", "{", "$", "nodesbypath", "[", "$", "ancestorpath", "]", "->", "children", "[", "]", "=", "$", "leaf", ";", "}", "else", "{", "$", "root", "->", "children", "[", "]", "=", "$", "leaf", ";", "}", "$", "nodesbypath", "[", "$", "path", "]", "=", "$", "leaf", ";", "}", "}", "return", "$", "root", ";", "}" ]
Calculates a permission tree based on an array of information about role permissions. The input parameter must be in the format returned by get_capability_info_at_each_context. The output is the root of a tree of stdClass objects with the fields 'path' (a context path), 'allow' (true or false), and 'children' (an array of similar objects). @param array $pathroleperms Array of permissions @return \stdClass Root object of permission tree
[ "Calculates", "a", "permission", "tree", "based", "on", "an", "array", "of", "information", "about", "role", "permissions", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/access/get_user_capability_course_helper.php#L170-L261
214,776
moodle/moodle
lib/classes/access/get_user_capability_course_helper.php
get_user_capability_course_helper.remove_duplicate_nodes
protected static function remove_duplicate_nodes($parent) { $length = count($parent->children); $index = 0; while ($index < $length) { $child = $parent->children[$index]; if ($child->allow === $parent->allow) { // Remove child node, but add its children to this node instead. array_splice($parent->children, $index, 1); $length--; $index--; foreach ($child->children as $grandchild) { $parent->children[] = $grandchild; $length++; } } else { // Keep child node, but recurse to remove its unnecessary children. self::remove_duplicate_nodes($child); } $index++; } }
php
protected static function remove_duplicate_nodes($parent) { $length = count($parent->children); $index = 0; while ($index < $length) { $child = $parent->children[$index]; if ($child->allow === $parent->allow) { // Remove child node, but add its children to this node instead. array_splice($parent->children, $index, 1); $length--; $index--; foreach ($child->children as $grandchild) { $parent->children[] = $grandchild; $length++; } } else { // Keep child node, but recurse to remove its unnecessary children. self::remove_duplicate_nodes($child); } $index++; } }
[ "protected", "static", "function", "remove_duplicate_nodes", "(", "$", "parent", ")", "{", "$", "length", "=", "count", "(", "$", "parent", "->", "children", ")", ";", "$", "index", "=", "0", ";", "while", "(", "$", "index", "<", "$", "length", ")", "{", "$", "child", "=", "$", "parent", "->", "children", "[", "$", "index", "]", ";", "if", "(", "$", "child", "->", "allow", "===", "$", "parent", "->", "allow", ")", "{", "// Remove child node, but add its children to this node instead.", "array_splice", "(", "$", "parent", "->", "children", ",", "$", "index", ",", "1", ")", ";", "$", "length", "--", ";", "$", "index", "--", ";", "foreach", "(", "$", "child", "->", "children", "as", "$", "grandchild", ")", "{", "$", "parent", "->", "children", "[", "]", "=", "$", "grandchild", ";", "$", "length", "++", ";", "}", "}", "else", "{", "// Keep child node, but recurse to remove its unnecessary children.", "self", "::", "remove_duplicate_nodes", "(", "$", "child", ")", ";", "}", "$", "index", "++", ";", "}", "}" ]
Removes duplicate nodes of a tree - where a child node has the same permission as its parent. @param \stdClass $parent Tree root node
[ "Removes", "duplicate", "nodes", "of", "a", "tree", "-", "where", "a", "child", "node", "has", "the", "same", "permission", "as", "its", "parent", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/access/get_user_capability_course_helper.php#L299-L319
214,777
moodle/moodle
lib/classes/access/get_user_capability_course_helper.php
get_user_capability_course_helper.get_tree
protected static function get_tree($userid, $capability) { // Extract raw capability data for this user and capability. $pathroleperms = self::get_capability_info_at_each_context($userid, $capability); // Convert the raw data into a permission tree based on context. $root = self::calculate_permission_tree($pathroleperms); unset($pathroleperms); // Simplify the permission tree by removing unnecessary nodes. $root = self::remove_negative_subtrees($root); self::remove_duplicate_nodes($root); // Return the tree. return $root; }
php
protected static function get_tree($userid, $capability) { // Extract raw capability data for this user and capability. $pathroleperms = self::get_capability_info_at_each_context($userid, $capability); // Convert the raw data into a permission tree based on context. $root = self::calculate_permission_tree($pathroleperms); unset($pathroleperms); // Simplify the permission tree by removing unnecessary nodes. $root = self::remove_negative_subtrees($root); self::remove_duplicate_nodes($root); // Return the tree. return $root; }
[ "protected", "static", "function", "get_tree", "(", "$", "userid", ",", "$", "capability", ")", "{", "// Extract raw capability data for this user and capability.", "$", "pathroleperms", "=", "self", "::", "get_capability_info_at_each_context", "(", "$", "userid", ",", "$", "capability", ")", ";", "// Convert the raw data into a permission tree based on context.", "$", "root", "=", "self", "::", "calculate_permission_tree", "(", "$", "pathroleperms", ")", ";", "unset", "(", "$", "pathroleperms", ")", ";", "// Simplify the permission tree by removing unnecessary nodes.", "$", "root", "=", "self", "::", "remove_negative_subtrees", "(", "$", "root", ")", ";", "self", "::", "remove_duplicate_nodes", "(", "$", "root", ")", ";", "// Return the tree.", "return", "$", "root", ";", "}" ]
Gets a permission tree for the given user and capability, representing the value of that capability at different contexts across the system. The tree will be simplified as far as possible. The output is the root of a tree of stdClass objects with the fields 'path' (a context path), 'allow' (true or false), and 'children' (an array of similar objects). @param int $userid User id @param string $capability Capability e.g. 'moodle/course:view' @return \stdClass Root node of tree
[ "Gets", "a", "permission", "tree", "for", "the", "given", "user", "and", "capability", "representing", "the", "value", "of", "that", "capability", "at", "different", "contexts", "across", "the", "system", ".", "The", "tree", "will", "be", "simplified", "as", "far", "as", "possible", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/access/get_user_capability_course_helper.php#L333-L347
214,778
moodle/moodle
lib/classes/access/get_user_capability_course_helper.php
get_user_capability_course_helper.create_sql
protected static function create_sql($parent) { global $DB; $sql = ''; $params = []; if ($parent->path !== null) { // Except for the root element, create the condition that it applies to the context of // this element (or anything within it). $sql = ' (x.path = ? OR ' . $DB->sql_like('x.path', '?') .')'; $params[] = $parent->path; $params[] = $parent->path . '/%'; if ($parent->children) { // When there are children, these are assumed to have the opposite sign i.e. if we // are allowing the parent, we are not allowing the children, and vice versa. So // the 'OR' clause for children will be inside this 'AND NOT'. $sql .= ' AND NOT ('; } } else if (count($parent->children) > 1) { // Place brackets in the query when it is going to be an OR of multiple conditions. $sql .= ' ('; } if ($parent->children) { $first = true; foreach ($parent->children as $child) { if ($first) { $first = false; } else { $sql .= ' OR'; } // Recuse to get the child requirements - this will be the check that the context // is within the child, plus possibly and 'AND NOT' for any different contexts // within the child. list ($childsql, $childparams) = self::create_sql($child); $sql .= $childsql; $params = array_merge($params, $childparams); } // Close brackets if opened above. if ($parent->path !== null || count($parent->children) > 1) { $sql .= ')'; } } return [$sql, $params]; }
php
protected static function create_sql($parent) { global $DB; $sql = ''; $params = []; if ($parent->path !== null) { // Except for the root element, create the condition that it applies to the context of // this element (or anything within it). $sql = ' (x.path = ? OR ' . $DB->sql_like('x.path', '?') .')'; $params[] = $parent->path; $params[] = $parent->path . '/%'; if ($parent->children) { // When there are children, these are assumed to have the opposite sign i.e. if we // are allowing the parent, we are not allowing the children, and vice versa. So // the 'OR' clause for children will be inside this 'AND NOT'. $sql .= ' AND NOT ('; } } else if (count($parent->children) > 1) { // Place brackets in the query when it is going to be an OR of multiple conditions. $sql .= ' ('; } if ($parent->children) { $first = true; foreach ($parent->children as $child) { if ($first) { $first = false; } else { $sql .= ' OR'; } // Recuse to get the child requirements - this will be the check that the context // is within the child, plus possibly and 'AND NOT' for any different contexts // within the child. list ($childsql, $childparams) = self::create_sql($child); $sql .= $childsql; $params = array_merge($params, $childparams); } // Close brackets if opened above. if ($parent->path !== null || count($parent->children) > 1) { $sql .= ')'; } } return [$sql, $params]; }
[ "protected", "static", "function", "create_sql", "(", "$", "parent", ")", "{", "global", "$", "DB", ";", "$", "sql", "=", "''", ";", "$", "params", "=", "[", "]", ";", "if", "(", "$", "parent", "->", "path", "!==", "null", ")", "{", "// Except for the root element, create the condition that it applies to the context of", "// this element (or anything within it).", "$", "sql", "=", "' (x.path = ? OR '", ".", "$", "DB", "->", "sql_like", "(", "'x.path'", ",", "'?'", ")", ".", "')'", ";", "$", "params", "[", "]", "=", "$", "parent", "->", "path", ";", "$", "params", "[", "]", "=", "$", "parent", "->", "path", ".", "'/%'", ";", "if", "(", "$", "parent", "->", "children", ")", "{", "// When there are children, these are assumed to have the opposite sign i.e. if we", "// are allowing the parent, we are not allowing the children, and vice versa. So", "// the 'OR' clause for children will be inside this 'AND NOT'.", "$", "sql", ".=", "' AND NOT ('", ";", "}", "}", "else", "if", "(", "count", "(", "$", "parent", "->", "children", ")", ">", "1", ")", "{", "// Place brackets in the query when it is going to be an OR of multiple conditions.", "$", "sql", ".=", "' ('", ";", "}", "if", "(", "$", "parent", "->", "children", ")", "{", "$", "first", "=", "true", ";", "foreach", "(", "$", "parent", "->", "children", "as", "$", "child", ")", "{", "if", "(", "$", "first", ")", "{", "$", "first", "=", "false", ";", "}", "else", "{", "$", "sql", ".=", "' OR'", ";", "}", "// Recuse to get the child requirements - this will be the check that the context", "// is within the child, plus possibly and 'AND NOT' for any different contexts", "// within the child.", "list", "(", "$", "childsql", ",", "$", "childparams", ")", "=", "self", "::", "create_sql", "(", "$", "child", ")", ";", "$", "sql", ".=", "$", "childsql", ";", "$", "params", "=", "array_merge", "(", "$", "params", ",", "$", "childparams", ")", ";", "}", "// Close brackets if opened above.", "if", "(", "$", "parent", "->", "path", "!==", "null", "||", "count", "(", "$", "parent", "->", "children", ")", ">", "1", ")", "{", "$", "sql", ".=", "')'", ";", "}", "}", "return", "[", "$", "sql", ",", "$", "params", "]", ";", "}" ]
Creates SQL suitable for restricting by contexts listed in the given permission tree. This function relies on the permission tree being in the format created by get_tree. Specifically, all the children of the root element must be set to 'allow' permission, children of those children must be 'not allow', children of those grandchildren 'allow', etc. @param \stdClass $parent Root node of permission tree @return array Two-element array of SQL (containing ? placeholders) and then a params array
[ "Creates", "SQL", "suitable", "for", "restricting", "by", "contexts", "listed", "in", "the", "given", "permission", "tree", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/access/get_user_capability_course_helper.php#L359-L402
214,779
moodle/moodle
lib/classes/access/get_user_capability_course_helper.php
get_user_capability_course_helper.get_sql
public static function get_sql($userid, $capability) { // Get a tree of capability permission at various contexts for current user. $root = self::get_tree($userid, $capability); // The root node always has permission false. If there are no child nodes then the user // cannot access anything. if (!$root->children) { return [false, false]; } // Get SQL to limit contexts based on the permission tree. return self::create_sql($root); }
php
public static function get_sql($userid, $capability) { // Get a tree of capability permission at various contexts for current user. $root = self::get_tree($userid, $capability); // The root node always has permission false. If there are no child nodes then the user // cannot access anything. if (!$root->children) { return [false, false]; } // Get SQL to limit contexts based on the permission tree. return self::create_sql($root); }
[ "public", "static", "function", "get_sql", "(", "$", "userid", ",", "$", "capability", ")", "{", "// Get a tree of capability permission at various contexts for current user.", "$", "root", "=", "self", "::", "get_tree", "(", "$", "userid", ",", "$", "capability", ")", ";", "// The root node always has permission false. If there are no child nodes then the user", "// cannot access anything.", "if", "(", "!", "$", "root", "->", "children", ")", "{", "return", "[", "false", ",", "false", "]", ";", "}", "// Get SQL to limit contexts based on the permission tree.", "return", "self", "::", "create_sql", "(", "$", "root", ")", ";", "}" ]
Gets SQL to restrict a query to contexts in which the user has a capability. This returns an array with two elements (SQL containing ? placeholders, and a params array). The SQL is intended to be used as part of a WHERE clause. It relies on the prefix 'x' being used for the Moodle context table. If the user does not have the permission anywhere at all (so that there is no point doing the query) then the two returned values will both be false. @param int $userid User id @param string $capability Capability e.g. 'moodle/course:view' @return array Two-element array of SQL (containing ? placeholders) and then a params array
[ "Gets", "SQL", "to", "restrict", "a", "query", "to", "contexts", "in", "which", "the", "user", "has", "a", "capability", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/access/get_user_capability_course_helper.php#L418-L431
214,780
moodle/moodle
question/format/blackboard_six/formatpool.php
qformat_blackboard_six_pool.readquestions
protected function readquestions($text) { // This converts xml to big nasty data structure, // the 0 means keep white space as it is. try { $xml = xmlize($text, 0, 'UTF-8', true); } catch (xml_format_exception $e) { $this->error($e->getMessage(), ''); return false; } $questions = array(); $this->process_category($xml, $questions); $this->process_tf($xml, $questions); $this->process_mc($xml, $questions); $this->process_ma($xml, $questions); $this->process_fib($xml, $questions); $this->process_matching($xml, $questions); $this->process_essay($xml, $questions); return $questions; }
php
protected function readquestions($text) { // This converts xml to big nasty data structure, // the 0 means keep white space as it is. try { $xml = xmlize($text, 0, 'UTF-8', true); } catch (xml_format_exception $e) { $this->error($e->getMessage(), ''); return false; } $questions = array(); $this->process_category($xml, $questions); $this->process_tf($xml, $questions); $this->process_mc($xml, $questions); $this->process_ma($xml, $questions); $this->process_fib($xml, $questions); $this->process_matching($xml, $questions); $this->process_essay($xml, $questions); return $questions; }
[ "protected", "function", "readquestions", "(", "$", "text", ")", "{", "// This converts xml to big nasty data structure,", "// the 0 means keep white space as it is.", "try", "{", "$", "xml", "=", "xmlize", "(", "$", "text", ",", "0", ",", "'UTF-8'", ",", "true", ")", ";", "}", "catch", "(", "xml_format_exception", "$", "e", ")", "{", "$", "this", "->", "error", "(", "$", "e", "->", "getMessage", "(", ")", ",", "''", ")", ";", "return", "false", ";", "}", "$", "questions", "=", "array", "(", ")", ";", "$", "this", "->", "process_category", "(", "$", "xml", ",", "$", "questions", ")", ";", "$", "this", "->", "process_tf", "(", "$", "xml", ",", "$", "questions", ")", ";", "$", "this", "->", "process_mc", "(", "$", "xml", ",", "$", "questions", ")", ";", "$", "this", "->", "process_ma", "(", "$", "xml", ",", "$", "questions", ")", ";", "$", "this", "->", "process_fib", "(", "$", "xml", ",", "$", "questions", ")", ";", "$", "this", "->", "process_matching", "(", "$", "xml", ",", "$", "questions", ")", ";", "$", "this", "->", "process_essay", "(", "$", "xml", ",", "$", "questions", ")", ";", "return", "$", "questions", ";", "}" ]
Parse the xml document into an array of questions This *could* burn memory - but it won't happen that much so fingers crossed! @param array $text array of lines from the input file. @return array (of objects) questions objects.
[ "Parse", "the", "xml", "document", "into", "an", "array", "of", "questions" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/format/blackboard_six/formatpool.php#L52-L75
214,781
moodle/moodle
question/format/blackboard_six/formatpool.php
qformat_blackboard_six_pool.process_common
public function process_common($questiondata) { // This routine initialises the question object. $question = $this->defaultquestion(); // Determine if the question is already escaped html. $this->ishtml = $this->getpath($questiondata, array('#', 'BODY', 0, '#', 'FLAGS', 0, '#', 'ISHTML', 0, '@', 'value'), false, false); // Put questiontext in question object. $text = $this->getpath($questiondata, array('#', 'BODY', 0, '#', 'TEXT', 0, '#'), '', true, get_string('importnotext', 'qformat_blackboard_six')); $questiontext = $this->cleaned_text_field($text); $question->questiontext = $questiontext['text']; $question->questiontextformat = $questiontext['format']; // Needed because add_blank_combined_feedback uses it. if (isset($questiontext['itemid'])) { $question->questiontextitemid = $questiontext['itemid']; } // Put name in question object. We must ensure it is not empty and it is less than 250 chars. $id = $this->getpath($questiondata, array('@', 'id'), '', true); $question->name = $this->create_default_question_name($question->questiontext, get_string('defaultname', 'qformat_blackboard_six' , $id)); $question->generalfeedback = ''; $question->generalfeedbackformat = FORMAT_HTML; $question->generalfeedbackfiles = array(); // TODO : read the mark from the POOL TITLE QUESTIONLIST section. $question->defaultmark = 1; return $question; }
php
public function process_common($questiondata) { // This routine initialises the question object. $question = $this->defaultquestion(); // Determine if the question is already escaped html. $this->ishtml = $this->getpath($questiondata, array('#', 'BODY', 0, '#', 'FLAGS', 0, '#', 'ISHTML', 0, '@', 'value'), false, false); // Put questiontext in question object. $text = $this->getpath($questiondata, array('#', 'BODY', 0, '#', 'TEXT', 0, '#'), '', true, get_string('importnotext', 'qformat_blackboard_six')); $questiontext = $this->cleaned_text_field($text); $question->questiontext = $questiontext['text']; $question->questiontextformat = $questiontext['format']; // Needed because add_blank_combined_feedback uses it. if (isset($questiontext['itemid'])) { $question->questiontextitemid = $questiontext['itemid']; } // Put name in question object. We must ensure it is not empty and it is less than 250 chars. $id = $this->getpath($questiondata, array('@', 'id'), '', true); $question->name = $this->create_default_question_name($question->questiontext, get_string('defaultname', 'qformat_blackboard_six' , $id)); $question->generalfeedback = ''; $question->generalfeedbackformat = FORMAT_HTML; $question->generalfeedbackfiles = array(); // TODO : read the mark from the POOL TITLE QUESTIONLIST section. $question->defaultmark = 1; return $question; }
[ "public", "function", "process_common", "(", "$", "questiondata", ")", "{", "// This routine initialises the question object.", "$", "question", "=", "$", "this", "->", "defaultquestion", "(", ")", ";", "// Determine if the question is already escaped html.", "$", "this", "->", "ishtml", "=", "$", "this", "->", "getpath", "(", "$", "questiondata", ",", "array", "(", "'#'", ",", "'BODY'", ",", "0", ",", "'#'", ",", "'FLAGS'", ",", "0", ",", "'#'", ",", "'ISHTML'", ",", "0", ",", "'@'", ",", "'value'", ")", ",", "false", ",", "false", ")", ";", "// Put questiontext in question object.", "$", "text", "=", "$", "this", "->", "getpath", "(", "$", "questiondata", ",", "array", "(", "'#'", ",", "'BODY'", ",", "0", ",", "'#'", ",", "'TEXT'", ",", "0", ",", "'#'", ")", ",", "''", ",", "true", ",", "get_string", "(", "'importnotext'", ",", "'qformat_blackboard_six'", ")", ")", ";", "$", "questiontext", "=", "$", "this", "->", "cleaned_text_field", "(", "$", "text", ")", ";", "$", "question", "->", "questiontext", "=", "$", "questiontext", "[", "'text'", "]", ";", "$", "question", "->", "questiontextformat", "=", "$", "questiontext", "[", "'format'", "]", ";", "// Needed because add_blank_combined_feedback uses it.", "if", "(", "isset", "(", "$", "questiontext", "[", "'itemid'", "]", ")", ")", "{", "$", "question", "->", "questiontextitemid", "=", "$", "questiontext", "[", "'itemid'", "]", ";", "}", "// Put name in question object. We must ensure it is not empty and it is less than 250 chars.", "$", "id", "=", "$", "this", "->", "getpath", "(", "$", "questiondata", ",", "array", "(", "'@'", ",", "'id'", ")", ",", "''", ",", "true", ")", ";", "$", "question", "->", "name", "=", "$", "this", "->", "create_default_question_name", "(", "$", "question", "->", "questiontext", ",", "get_string", "(", "'defaultname'", ",", "'qformat_blackboard_six'", ",", "$", "id", ")", ")", ";", "$", "question", "->", "generalfeedback", "=", "''", ";", "$", "question", "->", "generalfeedbackformat", "=", "FORMAT_HTML", ";", "$", "question", "->", "generalfeedbackfiles", "=", "array", "(", ")", ";", "// TODO : read the mark from the POOL TITLE QUESTIONLIST section.", "$", "question", "->", "defaultmark", "=", "1", ";", "return", "$", "question", ";", "}" ]
Do question import processing common to every qtype. @param array $questiondata the xml tree related to the current question @return object initialized question object.
[ "Do", "question", "import", "processing", "common", "to", "every", "qtype", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/format/blackboard_six/formatpool.php#L83-L117
214,782
moodle/moodle
question/format/blackboard_six/formatpool.php
qformat_blackboard_six_pool.process_essay
public function process_essay($xml, &$questions) { if ($this->getpath($xml, array('POOL', '#', 'QUESTION_ESSAY'), false, false)) { $essayquestions = $this->getpath($xml, array('POOL', '#', 'QUESTION_ESSAY'), false, false); } else { return; } foreach ($essayquestions as $thisquestion) { $question = $this->process_common($thisquestion); $question->qtype = 'essay'; $question->answer = ''; $answer = $this->getpath($thisquestion, array('#', 'ANSWER', 0, '#', 'TEXT', 0, '#'), '', true); $question->graderinfo = $this->cleaned_text_field($answer); $question->responsetemplate = $this->text_field(''); $question->feedback = ''; $question->responseformat = 'editor'; $question->responserequired = 1; $question->responsefieldlines = 15; $question->attachments = 0; $question->attachmentsrequired = 0; $question->fraction = 0; $questions[] = $question; } }
php
public function process_essay($xml, &$questions) { if ($this->getpath($xml, array('POOL', '#', 'QUESTION_ESSAY'), false, false)) { $essayquestions = $this->getpath($xml, array('POOL', '#', 'QUESTION_ESSAY'), false, false); } else { return; } foreach ($essayquestions as $thisquestion) { $question = $this->process_common($thisquestion); $question->qtype = 'essay'; $question->answer = ''; $answer = $this->getpath($thisquestion, array('#', 'ANSWER', 0, '#', 'TEXT', 0, '#'), '', true); $question->graderinfo = $this->cleaned_text_field($answer); $question->responsetemplate = $this->text_field(''); $question->feedback = ''; $question->responseformat = 'editor'; $question->responserequired = 1; $question->responsefieldlines = 15; $question->attachments = 0; $question->attachmentsrequired = 0; $question->fraction = 0; $questions[] = $question; } }
[ "public", "function", "process_essay", "(", "$", "xml", ",", "&", "$", "questions", ")", "{", "if", "(", "$", "this", "->", "getpath", "(", "$", "xml", ",", "array", "(", "'POOL'", ",", "'#'", ",", "'QUESTION_ESSAY'", ")", ",", "false", ",", "false", ")", ")", "{", "$", "essayquestions", "=", "$", "this", "->", "getpath", "(", "$", "xml", ",", "array", "(", "'POOL'", ",", "'#'", ",", "'QUESTION_ESSAY'", ")", ",", "false", ",", "false", ")", ";", "}", "else", "{", "return", ";", "}", "foreach", "(", "$", "essayquestions", "as", "$", "thisquestion", ")", "{", "$", "question", "=", "$", "this", "->", "process_common", "(", "$", "thisquestion", ")", ";", "$", "question", "->", "qtype", "=", "'essay'", ";", "$", "question", "->", "answer", "=", "''", ";", "$", "answer", "=", "$", "this", "->", "getpath", "(", "$", "thisquestion", ",", "array", "(", "'#'", ",", "'ANSWER'", ",", "0", ",", "'#'", ",", "'TEXT'", ",", "0", ",", "'#'", ")", ",", "''", ",", "true", ")", ";", "$", "question", "->", "graderinfo", "=", "$", "this", "->", "cleaned_text_field", "(", "$", "answer", ")", ";", "$", "question", "->", "responsetemplate", "=", "$", "this", "->", "text_field", "(", "''", ")", ";", "$", "question", "->", "feedback", "=", "''", ";", "$", "question", "->", "responseformat", "=", "'editor'", ";", "$", "question", "->", "responserequired", "=", "1", ";", "$", "question", "->", "responsefieldlines", "=", "15", ";", "$", "question", "->", "attachments", "=", "0", ";", "$", "question", "->", "attachmentsrequired", "=", "0", ";", "$", "question", "->", "fraction", "=", "0", ";", "$", "questions", "[", "]", "=", "$", "question", ";", "}", "}" ]
Process Essay Questions @param array $xml the xml tree @param array $questions the questions already parsed
[ "Process", "Essay", "Questions" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/format/blackboard_six/formatpool.php#L139-L169
214,783
moodle/moodle
question/format/blackboard_six/formatpool.php
qformat_blackboard_six_pool.process_mc
public function process_mc($xml, &$questions) { if ($this->getpath($xml, array('POOL', '#', 'QUESTION_MULTIPLECHOICE'), false, false)) { $mcquestions = $this->getpath($xml, array('POOL', '#', 'QUESTION_MULTIPLECHOICE'), false, false); } else { return; } foreach ($mcquestions as $thisquestion) { $question = $this->process_common($thisquestion); $correctfeedback = $this->getpath($thisquestion, array('#', 'GRADABLE', 0, '#', 'FEEDBACK_WHEN_CORRECT', 0, '#'), '', true); $incorrectfeedback = $this->getpath($thisquestion, array('#', 'GRADABLE', 0, '#', 'FEEDBACK_WHEN_INCORRECT', 0, '#'), '', true); $question->correctfeedback = $this->cleaned_text_field($correctfeedback); $question->partiallycorrectfeedback = $this->text_field(''); $question->incorrectfeedback = $this->cleaned_text_field($incorrectfeedback); $question->qtype = 'multichoice'; $question->single = 1; // Only one answer is allowed. $choices = $this->getpath($thisquestion, array('#', 'ANSWER'), false, false); $correctanswerid = $this->getpath($thisquestion, array('#', 'GRADABLE', 0, '#', 'CORRECTANSWER', 0, '@', 'answer_id'), '', true); foreach ($choices as $choice) { $choicetext = $this->getpath($choice, array('#', 'TEXT', 0, '#'), '', true); // Put this choice in the question object. $question->answer[] = $this->cleaned_text_field($choicetext); $choiceid = $this->getpath($choice, array('@', 'id'), '', true); // If choice is the right answer, give 100% mark, otherwise give 0%. if (strcmp ($choiceid, $correctanswerid) == 0) { $question->fraction[] = 1; } else { $question->fraction[] = 0; } // There is never feedback specific to each choice. $question->feedback[] = $this->text_field(''); } $questions[] = $question; } }
php
public function process_mc($xml, &$questions) { if ($this->getpath($xml, array('POOL', '#', 'QUESTION_MULTIPLECHOICE'), false, false)) { $mcquestions = $this->getpath($xml, array('POOL', '#', 'QUESTION_MULTIPLECHOICE'), false, false); } else { return; } foreach ($mcquestions as $thisquestion) { $question = $this->process_common($thisquestion); $correctfeedback = $this->getpath($thisquestion, array('#', 'GRADABLE', 0, '#', 'FEEDBACK_WHEN_CORRECT', 0, '#'), '', true); $incorrectfeedback = $this->getpath($thisquestion, array('#', 'GRADABLE', 0, '#', 'FEEDBACK_WHEN_INCORRECT', 0, '#'), '', true); $question->correctfeedback = $this->cleaned_text_field($correctfeedback); $question->partiallycorrectfeedback = $this->text_field(''); $question->incorrectfeedback = $this->cleaned_text_field($incorrectfeedback); $question->qtype = 'multichoice'; $question->single = 1; // Only one answer is allowed. $choices = $this->getpath($thisquestion, array('#', 'ANSWER'), false, false); $correctanswerid = $this->getpath($thisquestion, array('#', 'GRADABLE', 0, '#', 'CORRECTANSWER', 0, '@', 'answer_id'), '', true); foreach ($choices as $choice) { $choicetext = $this->getpath($choice, array('#', 'TEXT', 0, '#'), '', true); // Put this choice in the question object. $question->answer[] = $this->cleaned_text_field($choicetext); $choiceid = $this->getpath($choice, array('@', 'id'), '', true); // If choice is the right answer, give 100% mark, otherwise give 0%. if (strcmp ($choiceid, $correctanswerid) == 0) { $question->fraction[] = 1; } else { $question->fraction[] = 0; } // There is never feedback specific to each choice. $question->feedback[] = $this->text_field(''); } $questions[] = $question; } }
[ "public", "function", "process_mc", "(", "$", "xml", ",", "&", "$", "questions", ")", "{", "if", "(", "$", "this", "->", "getpath", "(", "$", "xml", ",", "array", "(", "'POOL'", ",", "'#'", ",", "'QUESTION_MULTIPLECHOICE'", ")", ",", "false", ",", "false", ")", ")", "{", "$", "mcquestions", "=", "$", "this", "->", "getpath", "(", "$", "xml", ",", "array", "(", "'POOL'", ",", "'#'", ",", "'QUESTION_MULTIPLECHOICE'", ")", ",", "false", ",", "false", ")", ";", "}", "else", "{", "return", ";", "}", "foreach", "(", "$", "mcquestions", "as", "$", "thisquestion", ")", "{", "$", "question", "=", "$", "this", "->", "process_common", "(", "$", "thisquestion", ")", ";", "$", "correctfeedback", "=", "$", "this", "->", "getpath", "(", "$", "thisquestion", ",", "array", "(", "'#'", ",", "'GRADABLE'", ",", "0", ",", "'#'", ",", "'FEEDBACK_WHEN_CORRECT'", ",", "0", ",", "'#'", ")", ",", "''", ",", "true", ")", ";", "$", "incorrectfeedback", "=", "$", "this", "->", "getpath", "(", "$", "thisquestion", ",", "array", "(", "'#'", ",", "'GRADABLE'", ",", "0", ",", "'#'", ",", "'FEEDBACK_WHEN_INCORRECT'", ",", "0", ",", "'#'", ")", ",", "''", ",", "true", ")", ";", "$", "question", "->", "correctfeedback", "=", "$", "this", "->", "cleaned_text_field", "(", "$", "correctfeedback", ")", ";", "$", "question", "->", "partiallycorrectfeedback", "=", "$", "this", "->", "text_field", "(", "''", ")", ";", "$", "question", "->", "incorrectfeedback", "=", "$", "this", "->", "cleaned_text_field", "(", "$", "incorrectfeedback", ")", ";", "$", "question", "->", "qtype", "=", "'multichoice'", ";", "$", "question", "->", "single", "=", "1", ";", "// Only one answer is allowed.", "$", "choices", "=", "$", "this", "->", "getpath", "(", "$", "thisquestion", ",", "array", "(", "'#'", ",", "'ANSWER'", ")", ",", "false", ",", "false", ")", ";", "$", "correctanswerid", "=", "$", "this", "->", "getpath", "(", "$", "thisquestion", ",", "array", "(", "'#'", ",", "'GRADABLE'", ",", "0", ",", "'#'", ",", "'CORRECTANSWER'", ",", "0", ",", "'@'", ",", "'answer_id'", ")", ",", "''", ",", "true", ")", ";", "foreach", "(", "$", "choices", "as", "$", "choice", ")", "{", "$", "choicetext", "=", "$", "this", "->", "getpath", "(", "$", "choice", ",", "array", "(", "'#'", ",", "'TEXT'", ",", "0", ",", "'#'", ")", ",", "''", ",", "true", ")", ";", "// Put this choice in the question object.", "$", "question", "->", "answer", "[", "]", "=", "$", "this", "->", "cleaned_text_field", "(", "$", "choicetext", ")", ";", "$", "choiceid", "=", "$", "this", "->", "getpath", "(", "$", "choice", ",", "array", "(", "'@'", ",", "'id'", ")", ",", "''", ",", "true", ")", ";", "// If choice is the right answer, give 100% mark, otherwise give 0%.", "if", "(", "strcmp", "(", "$", "choiceid", ",", "$", "correctanswerid", ")", "==", "0", ")", "{", "$", "question", "->", "fraction", "[", "]", "=", "1", ";", "}", "else", "{", "$", "question", "->", "fraction", "[", "]", "=", "0", ";", "}", "// There is never feedback specific to each choice.", "$", "question", "->", "feedback", "[", "]", "=", "$", "this", "->", "text_field", "(", "''", ")", ";", "}", "$", "questions", "[", "]", "=", "$", "question", ";", "}", "}" ]
Process Multiple Choice Questions with single answer @param array $xml the xml tree @param array $questions the questions already parsed
[ "Process", "Multiple", "Choice", "Questions", "with", "single", "answer" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/format/blackboard_six/formatpool.php#L225-L272
214,784
moodle/moodle
question/format/blackboard_six/formatpool.php
qformat_blackboard_six_pool.process_ma
public function process_ma($xml, &$questions) { if ($this->getpath($xml, array('POOL', '#', 'QUESTION_MULTIPLEANSWER'), false, false)) { $maquestions = $this->getpath($xml, array('POOL', '#', 'QUESTION_MULTIPLEANSWER'), false, false); } else { return; } foreach ($maquestions as $thisquestion) { $question = $this->process_common($thisquestion); $correctfeedback = $this->getpath($thisquestion, array('#', 'GRADABLE', 0, '#', 'FEEDBACK_WHEN_CORRECT', 0, '#'), '', true); $incorrectfeedback = $this->getpath($thisquestion, array('#', 'GRADABLE', 0, '#', 'FEEDBACK_WHEN_INCORRECT', 0, '#'), '', true); $question->correctfeedback = $this->cleaned_text_field($correctfeedback); // As there is no partially correct feedback we use incorrect one. $question->partiallycorrectfeedback = $this->cleaned_text_field($incorrectfeedback); $question->incorrectfeedback = $this->cleaned_text_field($incorrectfeedback); $question->qtype = 'multichoice'; $question->defaultmark = 1; $question->single = 0; // More than one answers allowed. $choices = $this->getpath($thisquestion, array('#', 'ANSWER'), false, false); $correctanswerids = array(); foreach ($this->getpath($thisquestion, array('#', 'GRADABLE', 0, '#', 'CORRECTANSWER'), false, false) as $correctanswer) { if ($correctanswer) { $correctanswerids[] = $this->getpath($correctanswer, array('@', 'answer_id'), '', true); } } $fraction = 1 / count($correctanswerids); foreach ($choices as $choice) { $choicetext = $this->getpath($choice, array('#', 'TEXT', 0, '#'), '', true); // Put this choice in the question object. $question->answer[] = $this->cleaned_text_field($choicetext); $choiceid = $this->getpath($choice, array('@', 'id'), '', true); $iscorrect = in_array($choiceid, $correctanswerids); if ($iscorrect) { $question->fraction[] = $fraction; } else { $question->fraction[] = 0; } // There is never feedback specific to each choice. $question->feedback[] = $this->text_field(''); } $questions[] = $question; } }
php
public function process_ma($xml, &$questions) { if ($this->getpath($xml, array('POOL', '#', 'QUESTION_MULTIPLEANSWER'), false, false)) { $maquestions = $this->getpath($xml, array('POOL', '#', 'QUESTION_MULTIPLEANSWER'), false, false); } else { return; } foreach ($maquestions as $thisquestion) { $question = $this->process_common($thisquestion); $correctfeedback = $this->getpath($thisquestion, array('#', 'GRADABLE', 0, '#', 'FEEDBACK_WHEN_CORRECT', 0, '#'), '', true); $incorrectfeedback = $this->getpath($thisquestion, array('#', 'GRADABLE', 0, '#', 'FEEDBACK_WHEN_INCORRECT', 0, '#'), '', true); $question->correctfeedback = $this->cleaned_text_field($correctfeedback); // As there is no partially correct feedback we use incorrect one. $question->partiallycorrectfeedback = $this->cleaned_text_field($incorrectfeedback); $question->incorrectfeedback = $this->cleaned_text_field($incorrectfeedback); $question->qtype = 'multichoice'; $question->defaultmark = 1; $question->single = 0; // More than one answers allowed. $choices = $this->getpath($thisquestion, array('#', 'ANSWER'), false, false); $correctanswerids = array(); foreach ($this->getpath($thisquestion, array('#', 'GRADABLE', 0, '#', 'CORRECTANSWER'), false, false) as $correctanswer) { if ($correctanswer) { $correctanswerids[] = $this->getpath($correctanswer, array('@', 'answer_id'), '', true); } } $fraction = 1 / count($correctanswerids); foreach ($choices as $choice) { $choicetext = $this->getpath($choice, array('#', 'TEXT', 0, '#'), '', true); // Put this choice in the question object. $question->answer[] = $this->cleaned_text_field($choicetext); $choiceid = $this->getpath($choice, array('@', 'id'), '', true); $iscorrect = in_array($choiceid, $correctanswerids); if ($iscorrect) { $question->fraction[] = $fraction; } else { $question->fraction[] = 0; } // There is never feedback specific to each choice. $question->feedback[] = $this->text_field(''); } $questions[] = $question; } }
[ "public", "function", "process_ma", "(", "$", "xml", ",", "&", "$", "questions", ")", "{", "if", "(", "$", "this", "->", "getpath", "(", "$", "xml", ",", "array", "(", "'POOL'", ",", "'#'", ",", "'QUESTION_MULTIPLEANSWER'", ")", ",", "false", ",", "false", ")", ")", "{", "$", "maquestions", "=", "$", "this", "->", "getpath", "(", "$", "xml", ",", "array", "(", "'POOL'", ",", "'#'", ",", "'QUESTION_MULTIPLEANSWER'", ")", ",", "false", ",", "false", ")", ";", "}", "else", "{", "return", ";", "}", "foreach", "(", "$", "maquestions", "as", "$", "thisquestion", ")", "{", "$", "question", "=", "$", "this", "->", "process_common", "(", "$", "thisquestion", ")", ";", "$", "correctfeedback", "=", "$", "this", "->", "getpath", "(", "$", "thisquestion", ",", "array", "(", "'#'", ",", "'GRADABLE'", ",", "0", ",", "'#'", ",", "'FEEDBACK_WHEN_CORRECT'", ",", "0", ",", "'#'", ")", ",", "''", ",", "true", ")", ";", "$", "incorrectfeedback", "=", "$", "this", "->", "getpath", "(", "$", "thisquestion", ",", "array", "(", "'#'", ",", "'GRADABLE'", ",", "0", ",", "'#'", ",", "'FEEDBACK_WHEN_INCORRECT'", ",", "0", ",", "'#'", ")", ",", "''", ",", "true", ")", ";", "$", "question", "->", "correctfeedback", "=", "$", "this", "->", "cleaned_text_field", "(", "$", "correctfeedback", ")", ";", "// As there is no partially correct feedback we use incorrect one.", "$", "question", "->", "partiallycorrectfeedback", "=", "$", "this", "->", "cleaned_text_field", "(", "$", "incorrectfeedback", ")", ";", "$", "question", "->", "incorrectfeedback", "=", "$", "this", "->", "cleaned_text_field", "(", "$", "incorrectfeedback", ")", ";", "$", "question", "->", "qtype", "=", "'multichoice'", ";", "$", "question", "->", "defaultmark", "=", "1", ";", "$", "question", "->", "single", "=", "0", ";", "// More than one answers allowed.", "$", "choices", "=", "$", "this", "->", "getpath", "(", "$", "thisquestion", ",", "array", "(", "'#'", ",", "'ANSWER'", ")", ",", "false", ",", "false", ")", ";", "$", "correctanswerids", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "getpath", "(", "$", "thisquestion", ",", "array", "(", "'#'", ",", "'GRADABLE'", ",", "0", ",", "'#'", ",", "'CORRECTANSWER'", ")", ",", "false", ",", "false", ")", "as", "$", "correctanswer", ")", "{", "if", "(", "$", "correctanswer", ")", "{", "$", "correctanswerids", "[", "]", "=", "$", "this", "->", "getpath", "(", "$", "correctanswer", ",", "array", "(", "'@'", ",", "'answer_id'", ")", ",", "''", ",", "true", ")", ";", "}", "}", "$", "fraction", "=", "1", "/", "count", "(", "$", "correctanswerids", ")", ";", "foreach", "(", "$", "choices", "as", "$", "choice", ")", "{", "$", "choicetext", "=", "$", "this", "->", "getpath", "(", "$", "choice", ",", "array", "(", "'#'", ",", "'TEXT'", ",", "0", ",", "'#'", ")", ",", "''", ",", "true", ")", ";", "// Put this choice in the question object.", "$", "question", "->", "answer", "[", "]", "=", "$", "this", "->", "cleaned_text_field", "(", "$", "choicetext", ")", ";", "$", "choiceid", "=", "$", "this", "->", "getpath", "(", "$", "choice", ",", "array", "(", "'@'", ",", "'id'", ")", ",", "''", ",", "true", ")", ";", "$", "iscorrect", "=", "in_array", "(", "$", "choiceid", ",", "$", "correctanswerids", ")", ";", "if", "(", "$", "iscorrect", ")", "{", "$", "question", "->", "fraction", "[", "]", "=", "$", "fraction", ";", "}", "else", "{", "$", "question", "->", "fraction", "[", "]", "=", "0", ";", "}", "// There is never feedback specific to each choice.", "$", "question", "->", "feedback", "[", "]", "=", "$", "this", "->", "text_field", "(", "''", ")", ";", "}", "$", "questions", "[", "]", "=", "$", "question", ";", "}", "}" ]
Process Multiple Choice Questions With Multiple Answers @param array $xml the xml tree @param array $questions the questions already parsed
[ "Process", "Multiple", "Choice", "Questions", "With", "Multiple", "Answers" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/format/blackboard_six/formatpool.php#L279-L336
214,785
moodle/moodle
question/format/blackboard_six/formatpool.php
qformat_blackboard_six_pool.process_fib
public function process_fib($xml, &$questions) { if ($this->getpath($xml, array('POOL', '#', 'QUESTION_FILLINBLANK'), false, false)) { $fibquestions = $this->getpath($xml, array('POOL', '#', 'QUESTION_FILLINBLANK'), false, false); } else { return; } foreach ($fibquestions as $thisquestion) { $question = $this->process_common($thisquestion); $question->qtype = 'shortanswer'; $question->usecase = 0; // Ignore case. $correctfeedback = $this->getpath($thisquestion, array('#', 'GRADABLE', 0, '#', 'FEEDBACK_WHEN_CORRECT', 0, '#'), '', true); $incorrectfeedback = $this->getpath($thisquestion, array('#', 'GRADABLE', 0, '#', 'FEEDBACK_WHEN_INCORRECT', 0, '#'), '', true); $answers = $this->getpath($thisquestion, array('#', 'ANSWER'), false, false); foreach ($answers as $answer) { $question->answer[] = $this->getpath($answer, array('#', 'TEXT', 0, '#'), '', true); $question->fraction[] = 1; $question->feedback[] = $this->cleaned_text_field($correctfeedback); } $question->answer[] = '*'; $question->fraction[] = 0; $question->feedback[] = $this->cleaned_text_field($incorrectfeedback); $questions[] = $question; } }
php
public function process_fib($xml, &$questions) { if ($this->getpath($xml, array('POOL', '#', 'QUESTION_FILLINBLANK'), false, false)) { $fibquestions = $this->getpath($xml, array('POOL', '#', 'QUESTION_FILLINBLANK'), false, false); } else { return; } foreach ($fibquestions as $thisquestion) { $question = $this->process_common($thisquestion); $question->qtype = 'shortanswer'; $question->usecase = 0; // Ignore case. $correctfeedback = $this->getpath($thisquestion, array('#', 'GRADABLE', 0, '#', 'FEEDBACK_WHEN_CORRECT', 0, '#'), '', true); $incorrectfeedback = $this->getpath($thisquestion, array('#', 'GRADABLE', 0, '#', 'FEEDBACK_WHEN_INCORRECT', 0, '#'), '', true); $answers = $this->getpath($thisquestion, array('#', 'ANSWER'), false, false); foreach ($answers as $answer) { $question->answer[] = $this->getpath($answer, array('#', 'TEXT', 0, '#'), '', true); $question->fraction[] = 1; $question->feedback[] = $this->cleaned_text_field($correctfeedback); } $question->answer[] = '*'; $question->fraction[] = 0; $question->feedback[] = $this->cleaned_text_field($incorrectfeedback); $questions[] = $question; } }
[ "public", "function", "process_fib", "(", "$", "xml", ",", "&", "$", "questions", ")", "{", "if", "(", "$", "this", "->", "getpath", "(", "$", "xml", ",", "array", "(", "'POOL'", ",", "'#'", ",", "'QUESTION_FILLINBLANK'", ")", ",", "false", ",", "false", ")", ")", "{", "$", "fibquestions", "=", "$", "this", "->", "getpath", "(", "$", "xml", ",", "array", "(", "'POOL'", ",", "'#'", ",", "'QUESTION_FILLINBLANK'", ")", ",", "false", ",", "false", ")", ";", "}", "else", "{", "return", ";", "}", "foreach", "(", "$", "fibquestions", "as", "$", "thisquestion", ")", "{", "$", "question", "=", "$", "this", "->", "process_common", "(", "$", "thisquestion", ")", ";", "$", "question", "->", "qtype", "=", "'shortanswer'", ";", "$", "question", "->", "usecase", "=", "0", ";", "// Ignore case.", "$", "correctfeedback", "=", "$", "this", "->", "getpath", "(", "$", "thisquestion", ",", "array", "(", "'#'", ",", "'GRADABLE'", ",", "0", ",", "'#'", ",", "'FEEDBACK_WHEN_CORRECT'", ",", "0", ",", "'#'", ")", ",", "''", ",", "true", ")", ";", "$", "incorrectfeedback", "=", "$", "this", "->", "getpath", "(", "$", "thisquestion", ",", "array", "(", "'#'", ",", "'GRADABLE'", ",", "0", ",", "'#'", ",", "'FEEDBACK_WHEN_INCORRECT'", ",", "0", ",", "'#'", ")", ",", "''", ",", "true", ")", ";", "$", "answers", "=", "$", "this", "->", "getpath", "(", "$", "thisquestion", ",", "array", "(", "'#'", ",", "'ANSWER'", ")", ",", "false", ",", "false", ")", ";", "foreach", "(", "$", "answers", "as", "$", "answer", ")", "{", "$", "question", "->", "answer", "[", "]", "=", "$", "this", "->", "getpath", "(", "$", "answer", ",", "array", "(", "'#'", ",", "'TEXT'", ",", "0", ",", "'#'", ")", ",", "''", ",", "true", ")", ";", "$", "question", "->", "fraction", "[", "]", "=", "1", ";", "$", "question", "->", "feedback", "[", "]", "=", "$", "this", "->", "cleaned_text_field", "(", "$", "correctfeedback", ")", ";", "}", "$", "question", "->", "answer", "[", "]", "=", "'*'", ";", "$", "question", "->", "fraction", "[", "]", "=", "0", ";", "$", "question", "->", "feedback", "[", "]", "=", "$", "this", "->", "cleaned_text_field", "(", "$", "incorrectfeedback", ")", ";", "$", "questions", "[", "]", "=", "$", "question", ";", "}", "}" ]
Process Fill in the Blank Questions @param array $xml the xml tree @param array $questions the questions already parsed
[ "Process", "Fill", "in", "the", "Blank", "Questions" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/format/blackboard_six/formatpool.php#L343-L377
214,786
moodle/moodle
lib/lessphp/SourceMap/Generator.php
Less_SourceMap_Generator.generateCSS
public function generateCSS(){ $output = new Less_Output_Mapped($this->contentsMap, $this); // catch the output $this->root->genCSS($output); $sourceMapUrl = $this->getOption('sourceMapURL'); $sourceMapFilename = $this->getOption('sourceMapFilename'); $sourceMapContent = $this->generateJson(); $sourceMapWriteTo = $this->getOption('sourceMapWriteTo'); if( !$sourceMapUrl && $sourceMapFilename ){ $sourceMapUrl = $this->normalizeFilename($sourceMapFilename); } // write map to a file if( $sourceMapWriteTo ){ $this->saveMap($sourceMapWriteTo, $sourceMapContent); } // inline the map if( !$sourceMapUrl ){ $sourceMapUrl = sprintf('data:application/json,%s', Less_Functions::encodeURIComponent($sourceMapContent)); } if( $sourceMapUrl ){ $output->add( sprintf('/*# sourceMappingURL=%s */', $sourceMapUrl) ); } return $output->toString(); }
php
public function generateCSS(){ $output = new Less_Output_Mapped($this->contentsMap, $this); // catch the output $this->root->genCSS($output); $sourceMapUrl = $this->getOption('sourceMapURL'); $sourceMapFilename = $this->getOption('sourceMapFilename'); $sourceMapContent = $this->generateJson(); $sourceMapWriteTo = $this->getOption('sourceMapWriteTo'); if( !$sourceMapUrl && $sourceMapFilename ){ $sourceMapUrl = $this->normalizeFilename($sourceMapFilename); } // write map to a file if( $sourceMapWriteTo ){ $this->saveMap($sourceMapWriteTo, $sourceMapContent); } // inline the map if( !$sourceMapUrl ){ $sourceMapUrl = sprintf('data:application/json,%s', Less_Functions::encodeURIComponent($sourceMapContent)); } if( $sourceMapUrl ){ $output->add( sprintf('/*# sourceMappingURL=%s */', $sourceMapUrl) ); } return $output->toString(); }
[ "public", "function", "generateCSS", "(", ")", "{", "$", "output", "=", "new", "Less_Output_Mapped", "(", "$", "this", "->", "contentsMap", ",", "$", "this", ")", ";", "// catch the output\r", "$", "this", "->", "root", "->", "genCSS", "(", "$", "output", ")", ";", "$", "sourceMapUrl", "=", "$", "this", "->", "getOption", "(", "'sourceMapURL'", ")", ";", "$", "sourceMapFilename", "=", "$", "this", "->", "getOption", "(", "'sourceMapFilename'", ")", ";", "$", "sourceMapContent", "=", "$", "this", "->", "generateJson", "(", ")", ";", "$", "sourceMapWriteTo", "=", "$", "this", "->", "getOption", "(", "'sourceMapWriteTo'", ")", ";", "if", "(", "!", "$", "sourceMapUrl", "&&", "$", "sourceMapFilename", ")", "{", "$", "sourceMapUrl", "=", "$", "this", "->", "normalizeFilename", "(", "$", "sourceMapFilename", ")", ";", "}", "// write map to a file\r", "if", "(", "$", "sourceMapWriteTo", ")", "{", "$", "this", "->", "saveMap", "(", "$", "sourceMapWriteTo", ",", "$", "sourceMapContent", ")", ";", "}", "// inline the map\r", "if", "(", "!", "$", "sourceMapUrl", ")", "{", "$", "sourceMapUrl", "=", "sprintf", "(", "'data:application/json,%s'", ",", "Less_Functions", "::", "encodeURIComponent", "(", "$", "sourceMapContent", ")", ")", ";", "}", "if", "(", "$", "sourceMapUrl", ")", "{", "$", "output", "->", "add", "(", "sprintf", "(", "'/*# sourceMappingURL=%s */'", ",", "$", "sourceMapUrl", ")", ")", ";", "}", "return", "$", "output", "->", "toString", "(", ")", ";", "}" ]
Generates the CSS @return string
[ "Generates", "the", "CSS" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/SourceMap/Generator.php#L104-L135
214,787
moodle/moodle
lib/lessphp/SourceMap/Generator.php
Less_SourceMap_Generator.fixWindowsPath
public function fixWindowsPath($path, $addEndSlash = false){ $slash = ($addEndSlash) ? '/' : ''; if( !empty($path) ){ $path = str_replace('\\', '/', $path); $path = rtrim($path,'/') . $slash; } return $path; }
php
public function fixWindowsPath($path, $addEndSlash = false){ $slash = ($addEndSlash) ? '/' : ''; if( !empty($path) ){ $path = str_replace('\\', '/', $path); $path = rtrim($path,'/') . $slash; } return $path; }
[ "public", "function", "fixWindowsPath", "(", "$", "path", ",", "$", "addEndSlash", "=", "false", ")", "{", "$", "slash", "=", "(", "$", "addEndSlash", ")", "?", "'/'", ":", "''", ";", "if", "(", "!", "empty", "(", "$", "path", ")", ")", "{", "$", "path", "=", "str_replace", "(", "'\\\\'", ",", "'/'", ",", "$", "path", ")", ";", "$", "path", "=", "rtrim", "(", "$", "path", ",", "'/'", ")", ".", "$", "slash", ";", "}", "return", "$", "path", ";", "}" ]
fix windows paths @param string $path @return string
[ "fix", "windows", "paths" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/SourceMap/Generator.php#L355-L363
214,788
moodle/moodle
lib/classes/lock/lock.php
lock.extend
public function extend($maxlifetime = 86400) { if ($this->factory) { return $this->factory->extend_lock($this, $maxlifetime); } return false; }
php
public function extend($maxlifetime = 86400) { if ($this->factory) { return $this->factory->extend_lock($this, $maxlifetime); } return false; }
[ "public", "function", "extend", "(", "$", "maxlifetime", "=", "86400", ")", "{", "if", "(", "$", "this", "->", "factory", ")", "{", "return", "$", "this", "->", "factory", "->", "extend_lock", "(", "$", "this", ",", "$", "maxlifetime", ")", ";", "}", "return", "false", ";", "}" ]
Extend the lifetime of this lock. Not supported by all factories. @param int $maxlifetime - the new lifetime for the lock (in seconds). @return bool
[ "Extend", "the", "lifetime", "of", "this", "lock", ".", "Not", "supported", "by", "all", "factories", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/lock/lock.php#L86-L91
214,789
moodle/moodle
lib/classes/lock/lock.php
lock.release
public function release() { $this->released = true; if (empty($this->factory)) { return false; } $result = $this->factory->release_lock($this); // Release any held references to the factory. unset($this->factory); $this->factory = null; $this->key = ''; return $result; }
php
public function release() { $this->released = true; if (empty($this->factory)) { return false; } $result = $this->factory->release_lock($this); // Release any held references to the factory. unset($this->factory); $this->factory = null; $this->key = ''; return $result; }
[ "public", "function", "release", "(", ")", "{", "$", "this", "->", "released", "=", "true", ";", "if", "(", "empty", "(", "$", "this", "->", "factory", ")", ")", "{", "return", "false", ";", "}", "$", "result", "=", "$", "this", "->", "factory", "->", "release_lock", "(", "$", "this", ")", ";", "// Release any held references to the factory.", "unset", "(", "$", "this", "->", "factory", ")", ";", "$", "this", "->", "factory", "=", "null", ";", "$", "this", "->", "key", "=", "''", ";", "return", "$", "result", ";", "}" ]
Release this lock @return bool
[ "Release", "this", "lock" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/lock/lock.php#L97-L108
214,790
moodle/moodle
lib/google/src/Google/Task/Runner.php
Google_Task_Runner.backOff
private function backOff() { $delay = $this->getDelay(); $this->client->getLogger()->debug( 'Retrying task with backoff', array( 'request' => $this->name, 'retry' => $this->attempts, 'backoff_seconds' => $delay ) ); usleep($delay * 1000000); }
php
private function backOff() { $delay = $this->getDelay(); $this->client->getLogger()->debug( 'Retrying task with backoff', array( 'request' => $this->name, 'retry' => $this->attempts, 'backoff_seconds' => $delay ) ); usleep($delay * 1000000); }
[ "private", "function", "backOff", "(", ")", "{", "$", "delay", "=", "$", "this", "->", "getDelay", "(", ")", ";", "$", "this", "->", "client", "->", "getLogger", "(", ")", "->", "debug", "(", "'Retrying task with backoff'", ",", "array", "(", "'request'", "=>", "$", "this", "->", "name", ",", "'retry'", "=>", "$", "this", "->", "attempts", ",", "'backoff_seconds'", "=>", "$", "delay", ")", ")", ";", "usleep", "(", "$", "delay", "*", "1000000", ")", ";", "}" ]
Sleeps in accordance to the backoff configurations.
[ "Sleeps", "in", "accordance", "to", "the", "backoff", "configurations", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/google/src/Google/Task/Runner.php#L218-L232
214,791
moodle/moodle
auth/classes/external.php
core_auth_external.confirm_user
public static function confirm_user($username, $secret) { global $PAGE; $warnings = array(); $params = self::validate_parameters( self::confirm_user_parameters(), array( 'username' => $username, 'secret' => $secret, ) ); $context = context_system::instance(); $PAGE->set_context($context); if (!$authplugin = signup_get_user_confirmation_authplugin()) { throw new moodle_exception('confirmationnotenabled'); } $confirmed = $authplugin->user_confirm($username, $secret); if ($confirmed == AUTH_CONFIRM_ALREADY) { $success = false; $warnings[] = array( 'item' => 'user', 'itemid' => 0, 'warningcode' => 'alreadyconfirmed', 'message' => s(get_string('alreadyconfirmed')) ); } else if ($confirmed == AUTH_CONFIRM_OK) { $success = true; } else { throw new moodle_exception('invalidconfirmdata'); } $result = array( 'success' => $success, 'warnings' => $warnings, ); return $result; }
php
public static function confirm_user($username, $secret) { global $PAGE; $warnings = array(); $params = self::validate_parameters( self::confirm_user_parameters(), array( 'username' => $username, 'secret' => $secret, ) ); $context = context_system::instance(); $PAGE->set_context($context); if (!$authplugin = signup_get_user_confirmation_authplugin()) { throw new moodle_exception('confirmationnotenabled'); } $confirmed = $authplugin->user_confirm($username, $secret); if ($confirmed == AUTH_CONFIRM_ALREADY) { $success = false; $warnings[] = array( 'item' => 'user', 'itemid' => 0, 'warningcode' => 'alreadyconfirmed', 'message' => s(get_string('alreadyconfirmed')) ); } else if ($confirmed == AUTH_CONFIRM_OK) { $success = true; } else { throw new moodle_exception('invalidconfirmdata'); } $result = array( 'success' => $success, 'warnings' => $warnings, ); return $result; }
[ "public", "static", "function", "confirm_user", "(", "$", "username", ",", "$", "secret", ")", "{", "global", "$", "PAGE", ";", "$", "warnings", "=", "array", "(", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "confirm_user_parameters", "(", ")", ",", "array", "(", "'username'", "=>", "$", "username", ",", "'secret'", "=>", "$", "secret", ",", ")", ")", ";", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "$", "PAGE", "->", "set_context", "(", "$", "context", ")", ";", "if", "(", "!", "$", "authplugin", "=", "signup_get_user_confirmation_authplugin", "(", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'confirmationnotenabled'", ")", ";", "}", "$", "confirmed", "=", "$", "authplugin", "->", "user_confirm", "(", "$", "username", ",", "$", "secret", ")", ";", "if", "(", "$", "confirmed", "==", "AUTH_CONFIRM_ALREADY", ")", "{", "$", "success", "=", "false", ";", "$", "warnings", "[", "]", "=", "array", "(", "'item'", "=>", "'user'", ",", "'itemid'", "=>", "0", ",", "'warningcode'", "=>", "'alreadyconfirmed'", ",", "'message'", "=>", "s", "(", "get_string", "(", "'alreadyconfirmed'", ")", ")", ")", ";", "}", "else", "if", "(", "$", "confirmed", "==", "AUTH_CONFIRM_OK", ")", "{", "$", "success", "=", "true", ";", "}", "else", "{", "throw", "new", "moodle_exception", "(", "'invalidconfirmdata'", ")", ";", "}", "$", "result", "=", "array", "(", "'success'", "=>", "$", "success", ",", "'warnings'", "=>", "$", "warnings", ",", ")", ";", "return", "$", "result", ";", "}" ]
Confirm a user account. @param string $username user name @param string $secret confirmation secret (random string) used for validating the confirm request @return array warnings and success status (true if the user was confirmed, false if he was already confirmed) @since Moodle 3.2 @throws moodle_exception
[ "Confirm", "a", "user", "account", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/classes/external.php#L67-L107
214,792
moodle/moodle
auth/classes/external.php
core_auth_external.request_password_reset_parameters
public static function request_password_reset_parameters() { return new external_function_parameters( array( 'username' => new external_value(core_user::get_property_type('username'), 'User name', VALUE_DEFAULT, ''), 'email' => new external_value(core_user::get_property_type('email'), 'User email', VALUE_DEFAULT, ''), ) ); }
php
public static function request_password_reset_parameters() { return new external_function_parameters( array( 'username' => new external_value(core_user::get_property_type('username'), 'User name', VALUE_DEFAULT, ''), 'email' => new external_value(core_user::get_property_type('email'), 'User email', VALUE_DEFAULT, ''), ) ); }
[ "public", "static", "function", "request_password_reset_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'username'", "=>", "new", "external_value", "(", "core_user", "::", "get_property_type", "(", "'username'", ")", ",", "'User name'", ",", "VALUE_DEFAULT", ",", "''", ")", ",", "'email'", "=>", "new", "external_value", "(", "core_user", "::", "get_property_type", "(", "'email'", ")", ",", "'User email'", ",", "VALUE_DEFAULT", ",", "''", ")", ",", ")", ")", ";", "}" ]
Describes the parameters for request_password_reset. @return external_function_parameters @since Moodle 3.4
[ "Describes", "the", "parameters", "for", "request_password_reset", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/classes/external.php#L131-L138
214,793
moodle/moodle
auth/classes/external.php
core_auth_external.request_password_reset
public static function request_password_reset($username = '', $email = '') { global $CFG, $PAGE; require_once($CFG->dirroot . '/login/lib.php'); $warnings = array(); $params = self::validate_parameters( self::request_password_reset_parameters(), array( 'username' => $username, 'email' => $email, ) ); $context = context_system::instance(); $PAGE->set_context($context); // Needed by format_string calls. // Check if an alternate forgotten password method is set. if (!empty($CFG->forgottenpasswordurl)) { throw new moodle_exception('cannotmailconfirm'); } $errors = core_login_validate_forgot_password_data($params); if (!empty($errors)) { $status = 'dataerror'; $notice = ''; foreach ($errors as $itemname => $message) { $warnings[] = array( 'item' => $itemname, 'itemid' => 0, 'warningcode' => 'fielderror', 'message' => s($message) ); } } else { list($status, $notice, $url) = core_login_process_password_reset($params['username'], $params['email']); } return array( 'status' => $status, 'notice' => $notice, 'warnings' => $warnings, ); }
php
public static function request_password_reset($username = '', $email = '') { global $CFG, $PAGE; require_once($CFG->dirroot . '/login/lib.php'); $warnings = array(); $params = self::validate_parameters( self::request_password_reset_parameters(), array( 'username' => $username, 'email' => $email, ) ); $context = context_system::instance(); $PAGE->set_context($context); // Needed by format_string calls. // Check if an alternate forgotten password method is set. if (!empty($CFG->forgottenpasswordurl)) { throw new moodle_exception('cannotmailconfirm'); } $errors = core_login_validate_forgot_password_data($params); if (!empty($errors)) { $status = 'dataerror'; $notice = ''; foreach ($errors as $itemname => $message) { $warnings[] = array( 'item' => $itemname, 'itemid' => 0, 'warningcode' => 'fielderror', 'message' => s($message) ); } } else { list($status, $notice, $url) = core_login_process_password_reset($params['username'], $params['email']); } return array( 'status' => $status, 'notice' => $notice, 'warnings' => $warnings, ); }
[ "public", "static", "function", "request_password_reset", "(", "$", "username", "=", "''", ",", "$", "email", "=", "''", ")", "{", "global", "$", "CFG", ",", "$", "PAGE", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/login/lib.php'", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "request_password_reset_parameters", "(", ")", ",", "array", "(", "'username'", "=>", "$", "username", ",", "'email'", "=>", "$", "email", ",", ")", ")", ";", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "$", "PAGE", "->", "set_context", "(", "$", "context", ")", ";", "// Needed by format_string calls.", "// Check if an alternate forgotten password method is set.", "if", "(", "!", "empty", "(", "$", "CFG", "->", "forgottenpasswordurl", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'cannotmailconfirm'", ")", ";", "}", "$", "errors", "=", "core_login_validate_forgot_password_data", "(", "$", "params", ")", ";", "if", "(", "!", "empty", "(", "$", "errors", ")", ")", "{", "$", "status", "=", "'dataerror'", ";", "$", "notice", "=", "''", ";", "foreach", "(", "$", "errors", "as", "$", "itemname", "=>", "$", "message", ")", "{", "$", "warnings", "[", "]", "=", "array", "(", "'item'", "=>", "$", "itemname", ",", "'itemid'", "=>", "0", ",", "'warningcode'", "=>", "'fielderror'", ",", "'message'", "=>", "s", "(", "$", "message", ")", ")", ";", "}", "}", "else", "{", "list", "(", "$", "status", ",", "$", "notice", ",", "$", "url", ")", "=", "core_login_process_password_reset", "(", "$", "params", "[", "'username'", "]", ",", "$", "params", "[", "'email'", "]", ")", ";", "}", "return", "array", "(", "'status'", "=>", "$", "status", ",", "'notice'", "=>", "$", "notice", ",", "'warnings'", "=>", "$", "warnings", ",", ")", ";", "}" ]
Requests a password reset. @param string $username user name @param string $email user email @return array warnings and success status (including notices and errors while processing) @since Moodle 3.4 @throws moodle_exception
[ "Requests", "a", "password", "reset", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/classes/external.php#L149-L192
214,794
moodle/moodle
auth/classes/external.php
core_auth_external.is_minor
public static function is_minor($age, $country) { global $CFG, $PAGE; require_once($CFG->dirroot . '/login/lib.php'); $params = self::validate_parameters( self::is_minor_parameters(), array( 'age' => $age, 'country' => $country, ) ); if (!array_key_exists($params['country'], get_string_manager()->get_list_of_countries())) { throw new invalid_parameter_exception('Invalid value for country parameter (value: '. $params['country'] .')'); } $context = context_system::instance(); $PAGE->set_context($context); // Check if verification of age and location (minor check) is enabled. if (!\core_auth\digital_consent::is_age_digital_consent_verification_enabled()) { throw new moodle_exception('nopermissions', 'error', '', get_string('agelocationverificationdisabled', 'error')); } $status = \core_auth\digital_consent::is_minor($params['age'], $params['country']); return array( 'status' => $status ); }
php
public static function is_minor($age, $country) { global $CFG, $PAGE; require_once($CFG->dirroot . '/login/lib.php'); $params = self::validate_parameters( self::is_minor_parameters(), array( 'age' => $age, 'country' => $country, ) ); if (!array_key_exists($params['country'], get_string_manager()->get_list_of_countries())) { throw new invalid_parameter_exception('Invalid value for country parameter (value: '. $params['country'] .')'); } $context = context_system::instance(); $PAGE->set_context($context); // Check if verification of age and location (minor check) is enabled. if (!\core_auth\digital_consent::is_age_digital_consent_verification_enabled()) { throw new moodle_exception('nopermissions', 'error', '', get_string('agelocationverificationdisabled', 'error')); } $status = \core_auth\digital_consent::is_minor($params['age'], $params['country']); return array( 'status' => $status ); }
[ "public", "static", "function", "is_minor", "(", "$", "age", ",", "$", "country", ")", "{", "global", "$", "CFG", ",", "$", "PAGE", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/login/lib.php'", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "is_minor_parameters", "(", ")", ",", "array", "(", "'age'", "=>", "$", "age", ",", "'country'", "=>", "$", "country", ",", ")", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "params", "[", "'country'", "]", ",", "get_string_manager", "(", ")", "->", "get_list_of_countries", "(", ")", ")", ")", "{", "throw", "new", "invalid_parameter_exception", "(", "'Invalid value for country parameter (value: '", ".", "$", "params", "[", "'country'", "]", ".", "')'", ")", ";", "}", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "$", "PAGE", "->", "set_context", "(", "$", "context", ")", ";", "// Check if verification of age and location (minor check) is enabled.", "if", "(", "!", "\\", "core_auth", "\\", "digital_consent", "::", "is_age_digital_consent_verification_enabled", "(", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'nopermissions'", ",", "'error'", ",", "''", ",", "get_string", "(", "'agelocationverificationdisabled'", ",", "'error'", ")", ")", ";", "}", "$", "status", "=", "\\", "core_auth", "\\", "digital_consent", "::", "is_minor", "(", "$", "params", "[", "'age'", "]", ",", "$", "params", "[", "'country'", "]", ")", ";", "return", "array", "(", "'status'", "=>", "$", "status", ")", ";", "}" ]
Requests a check if a user is digital minor. @param int $age User age @param string $country Country of residence @return array status (true if the user is a minor, false otherwise) @since Moodle 3.4 @throws moodle_exception
[ "Requests", "a", "check", "if", "a", "user", "is", "digital", "minor", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/classes/external.php#L243-L274
214,795
moodle/moodle
auth/classes/external.php
core_auth_external.is_age_digital_consent_verification_enabled
public static function is_age_digital_consent_verification_enabled() { global $PAGE; $context = context_system::instance(); $PAGE->set_context($context); $status = false; // Check if verification is enabled. if (\core_auth\digital_consent::is_age_digital_consent_verification_enabled()) { $status = true; } return array( 'status' => $status ); }
php
public static function is_age_digital_consent_verification_enabled() { global $PAGE; $context = context_system::instance(); $PAGE->set_context($context); $status = false; // Check if verification is enabled. if (\core_auth\digital_consent::is_age_digital_consent_verification_enabled()) { $status = true; } return array( 'status' => $status ); }
[ "public", "static", "function", "is_age_digital_consent_verification_enabled", "(", ")", "{", "global", "$", "PAGE", ";", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "$", "PAGE", "->", "set_context", "(", "$", "context", ")", ";", "$", "status", "=", "false", ";", "// Check if verification is enabled.", "if", "(", "\\", "core_auth", "\\", "digital_consent", "::", "is_age_digital_consent_verification_enabled", "(", ")", ")", "{", "$", "status", "=", "true", ";", "}", "return", "array", "(", "'status'", "=>", "$", "status", ")", ";", "}" ]
Checks if age digital consent verification is enabled. @return array status (true if digital consent verification is enabled, false otherwise.) @since Moodle 3.3 @throws moodle_exception
[ "Checks", "if", "age", "digital", "consent", "verification", "is", "enabled", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/classes/external.php#L308-L323
214,796
moodle/moodle
auth/classes/external.php
core_auth_external.resend_confirmation_email_parameters
public static function resend_confirmation_email_parameters() { return new external_function_parameters( array( 'username' => new external_value(core_user::get_property_type('username'), 'Username.'), 'password' => new external_value(core_user::get_property_type('password'), 'Plain text password.'), 'redirect' => new external_value(PARAM_LOCALURL, 'Redirect the user to this site url after confirmation.', VALUE_DEFAULT, ''), ) ); }
php
public static function resend_confirmation_email_parameters() { return new external_function_parameters( array( 'username' => new external_value(core_user::get_property_type('username'), 'Username.'), 'password' => new external_value(core_user::get_property_type('password'), 'Plain text password.'), 'redirect' => new external_value(PARAM_LOCALURL, 'Redirect the user to this site url after confirmation.', VALUE_DEFAULT, ''), ) ); }
[ "public", "static", "function", "resend_confirmation_email_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'username'", "=>", "new", "external_value", "(", "core_user", "::", "get_property_type", "(", "'username'", ")", ",", "'Username.'", ")", ",", "'password'", "=>", "new", "external_value", "(", "core_user", "::", "get_property_type", "(", "'password'", ")", ",", "'Plain text password.'", ")", ",", "'redirect'", "=>", "new", "external_value", "(", "PARAM_LOCALURL", ",", "'Redirect the user to this site url after confirmation.'", ",", "VALUE_DEFAULT", ",", "''", ")", ",", ")", ")", ";", "}" ]
Describes the parameters for resend_confirmation_email. @return external_function_parameters @since Moodle 3.6
[ "Describes", "the", "parameters", "for", "resend_confirmation_email", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/classes/external.php#L346-L355
214,797
moodle/moodle
auth/classes/external.php
core_auth_external.resend_confirmation_email
public static function resend_confirmation_email($username, $password, $redirect = '') { global $PAGE; $warnings = array(); $params = self::validate_parameters( self::resend_confirmation_email_parameters(), array( 'username' => $username, 'password' => $password, 'redirect' => $redirect, ) ); $context = context_system::instance(); $PAGE->set_context($context); // Need by internal APIs. $username = trim(core_text::strtolower($params['username'])); $password = $params['password']; if (is_restored_user($username)) { throw new moodle_exception('restoredaccountresetpassword', 'webservice'); } $user = authenticate_user_login($username, $password); if (empty($user)) { throw new moodle_exception('invalidlogin'); } if ($user->confirmed) { throw new moodle_exception('alreadyconfirmed'); } // Check if we should redirect the user once the user is confirmed. $confirmationurl = null; if (!empty($params['redirect'])) { // Pass via moodle_url to fix thinks like admin links. $redirect = new moodle_url($params['redirect']); $confirmationurl = new moodle_url('/login/confirm.php', array('redirect' => $redirect->out())); } $status = send_confirmation_email($user, $confirmationurl); return array( 'status' => $status, 'warnings' => $warnings, ); }
php
public static function resend_confirmation_email($username, $password, $redirect = '') { global $PAGE; $warnings = array(); $params = self::validate_parameters( self::resend_confirmation_email_parameters(), array( 'username' => $username, 'password' => $password, 'redirect' => $redirect, ) ); $context = context_system::instance(); $PAGE->set_context($context); // Need by internal APIs. $username = trim(core_text::strtolower($params['username'])); $password = $params['password']; if (is_restored_user($username)) { throw new moodle_exception('restoredaccountresetpassword', 'webservice'); } $user = authenticate_user_login($username, $password); if (empty($user)) { throw new moodle_exception('invalidlogin'); } if ($user->confirmed) { throw new moodle_exception('alreadyconfirmed'); } // Check if we should redirect the user once the user is confirmed. $confirmationurl = null; if (!empty($params['redirect'])) { // Pass via moodle_url to fix thinks like admin links. $redirect = new moodle_url($params['redirect']); $confirmationurl = new moodle_url('/login/confirm.php', array('redirect' => $redirect->out())); } $status = send_confirmation_email($user, $confirmationurl); return array( 'status' => $status, 'warnings' => $warnings, ); }
[ "public", "static", "function", "resend_confirmation_email", "(", "$", "username", ",", "$", "password", ",", "$", "redirect", "=", "''", ")", "{", "global", "$", "PAGE", ";", "$", "warnings", "=", "array", "(", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "resend_confirmation_email_parameters", "(", ")", ",", "array", "(", "'username'", "=>", "$", "username", ",", "'password'", "=>", "$", "password", ",", "'redirect'", "=>", "$", "redirect", ",", ")", ")", ";", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "$", "PAGE", "->", "set_context", "(", "$", "context", ")", ";", "// Need by internal APIs.", "$", "username", "=", "trim", "(", "core_text", "::", "strtolower", "(", "$", "params", "[", "'username'", "]", ")", ")", ";", "$", "password", "=", "$", "params", "[", "'password'", "]", ";", "if", "(", "is_restored_user", "(", "$", "username", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'restoredaccountresetpassword'", ",", "'webservice'", ")", ";", "}", "$", "user", "=", "authenticate_user_login", "(", "$", "username", ",", "$", "password", ")", ";", "if", "(", "empty", "(", "$", "user", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'invalidlogin'", ")", ";", "}", "if", "(", "$", "user", "->", "confirmed", ")", "{", "throw", "new", "moodle_exception", "(", "'alreadyconfirmed'", ")", ";", "}", "// Check if we should redirect the user once the user is confirmed.", "$", "confirmationurl", "=", "null", ";", "if", "(", "!", "empty", "(", "$", "params", "[", "'redirect'", "]", ")", ")", "{", "// Pass via moodle_url to fix thinks like admin links.", "$", "redirect", "=", "new", "moodle_url", "(", "$", "params", "[", "'redirect'", "]", ")", ";", "$", "confirmationurl", "=", "new", "moodle_url", "(", "'/login/confirm.php'", ",", "array", "(", "'redirect'", "=>", "$", "redirect", "->", "out", "(", ")", ")", ")", ";", "}", "$", "status", "=", "send_confirmation_email", "(", "$", "user", ",", "$", "confirmationurl", ")", ";", "return", "array", "(", "'status'", "=>", "$", "status", ",", "'warnings'", "=>", "$", "warnings", ",", ")", ";", "}" ]
Requests resend the confirmation email. @param string $username user name @param string $password plain text password @param string $redirect redirect the user to this site url after confirmation @return array warnings and success status @since Moodle 3.6 @throws moodle_exception
[ "Requests", "resend", "the", "confirmation", "email", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/classes/external.php#L367-L413
214,798
moodle/moodle
admin/tool/cohortroles/classes/output/cohort_role_assignments_table.php
cohort_role_assignments_table.col_cohortname
protected function col_cohortname($data) { global $OUTPUT; $record = (object) array( 'id' => $data->cohortid, 'idnumber' => $data->cohortidnumber, 'description' => $data->cohortdescription, 'visible' => $data->cohortvisible, 'name' => $data->cohortname, 'theme' => $data->cohorttheme ); $context = context_helper::instance_by_id($data->cohortcontextid); $exporter = new \core_cohort\external\cohort_summary_exporter($record, array('context' => $context)); $cohort = $exporter->export($OUTPUT); $html = $OUTPUT->render_from_template('tool_cohortroles/cohort-in-list', $cohort); return $html; }
php
protected function col_cohortname($data) { global $OUTPUT; $record = (object) array( 'id' => $data->cohortid, 'idnumber' => $data->cohortidnumber, 'description' => $data->cohortdescription, 'visible' => $data->cohortvisible, 'name' => $data->cohortname, 'theme' => $data->cohorttheme ); $context = context_helper::instance_by_id($data->cohortcontextid); $exporter = new \core_cohort\external\cohort_summary_exporter($record, array('context' => $context)); $cohort = $exporter->export($OUTPUT); $html = $OUTPUT->render_from_template('tool_cohortroles/cohort-in-list', $cohort); return $html; }
[ "protected", "function", "col_cohortname", "(", "$", "data", ")", "{", "global", "$", "OUTPUT", ";", "$", "record", "=", "(", "object", ")", "array", "(", "'id'", "=>", "$", "data", "->", "cohortid", ",", "'idnumber'", "=>", "$", "data", "->", "cohortidnumber", ",", "'description'", "=>", "$", "data", "->", "cohortdescription", ",", "'visible'", "=>", "$", "data", "->", "cohortvisible", ",", "'name'", "=>", "$", "data", "->", "cohortname", ",", "'theme'", "=>", "$", "data", "->", "cohorttheme", ")", ";", "$", "context", "=", "context_helper", "::", "instance_by_id", "(", "$", "data", "->", "cohortcontextid", ")", ";", "$", "exporter", "=", "new", "\\", "core_cohort", "\\", "external", "\\", "cohort_summary_exporter", "(", "$", "record", ",", "array", "(", "'context'", "=>", "$", "context", ")", ")", ";", "$", "cohort", "=", "$", "exporter", "->", "export", "(", "$", "OUTPUT", ")", ";", "$", "html", "=", "$", "OUTPUT", "->", "render_from_template", "(", "'tool_cohortroles/cohort-in-list'", ",", "$", "cohort", ")", ";", "return", "$", "html", ";", "}" ]
Cohort name column. @param array $data Row data. @return string
[ "Cohort", "name", "column", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/cohortroles/classes/output/cohort_role_assignments_table.php#L89-L107
214,799
moodle/moodle
admin/tool/cohortroles/classes/output/cohort_role_assignments_table.php
cohort_role_assignments_table.col_actions
protected function col_actions($data) { global $OUTPUT; $action = new \confirm_action(get_string('removecohortroleassignmentconfirm', 'tool_cohortroles')); $url = new moodle_url($this->baseurl); $url->params(array('removecohortroleassignment' => $data->id, 'sesskey' => sesskey())); $pix = new \pix_icon('t/delete', get_string('removecohortroleassignment', 'tool_cohortroles')); return $OUTPUT->action_link($url, '', $action, null, $pix); }
php
protected function col_actions($data) { global $OUTPUT; $action = new \confirm_action(get_string('removecohortroleassignmentconfirm', 'tool_cohortroles')); $url = new moodle_url($this->baseurl); $url->params(array('removecohortroleassignment' => $data->id, 'sesskey' => sesskey())); $pix = new \pix_icon('t/delete', get_string('removecohortroleassignment', 'tool_cohortroles')); return $OUTPUT->action_link($url, '', $action, null, $pix); }
[ "protected", "function", "col_actions", "(", "$", "data", ")", "{", "global", "$", "OUTPUT", ";", "$", "action", "=", "new", "\\", "confirm_action", "(", "get_string", "(", "'removecohortroleassignmentconfirm'", ",", "'tool_cohortroles'", ")", ")", ";", "$", "url", "=", "new", "moodle_url", "(", "$", "this", "->", "baseurl", ")", ";", "$", "url", "->", "params", "(", "array", "(", "'removecohortroleassignment'", "=>", "$", "data", "->", "id", ",", "'sesskey'", "=>", "sesskey", "(", ")", ")", ")", ";", "$", "pix", "=", "new", "\\", "pix_icon", "(", "'t/delete'", ",", "get_string", "(", "'removecohortroleassignment'", ",", "'tool_cohortroles'", ")", ")", ";", "return", "$", "OUTPUT", "->", "action_link", "(", "$", "url", ",", "''", ",", "$", "action", ",", "null", ",", "$", "pix", ")", ";", "}" ]
Actions column. @param array $data Row data. @return string
[ "Actions", "column", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/cohortroles/classes/output/cohort_role_assignments_table.php#L115-L123