id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
217,900
moodle/moodle
lib/portfolio/forms.php
portfolio_instance_select.definition
function definition() { $this->caller = $this->_customdata['caller']; $options = $this->_customdata['options']; $mform =& $this->_form; $mform->addElement('select', 'instance', get_string('selectplugin', 'portfolio'), $options); $mform->addElement('hidden', 'id', $this->_customdata['id']); $mform->setType('id', PARAM_INT); $this->add_action_buttons(true, get_string('next')); }
php
function definition() { $this->caller = $this->_customdata['caller']; $options = $this->_customdata['options']; $mform =& $this->_form; $mform->addElement('select', 'instance', get_string('selectplugin', 'portfolio'), $options); $mform->addElement('hidden', 'id', $this->_customdata['id']); $mform->setType('id', PARAM_INT); $this->add_action_buttons(true, get_string('next')); }
[ "function", "definition", "(", ")", "{", "$", "this", "->", "caller", "=", "$", "this", "->", "_customdata", "[", "'caller'", "]", ";", "$", "options", "=", "$", "this", "->", "_customdata", "[", "'options'", "]", ";", "$", "mform", "=", "&", "$", "this", "->", "_form", ";", "$", "mform", "->", "addElement", "(", "'select'", ",", "'instance'", ",", "get_string", "(", "'selectplugin'", ",", "'portfolio'", ")", ",", "$", "options", ")", ";", "$", "mform", "->", "addElement", "(", "'hidden'", ",", "'id'", ",", "$", "this", "->", "_customdata", "[", "'id'", "]", ")", ";", "$", "mform", "->", "setType", "(", "'id'", ",", "PARAM_INT", ")", ";", "$", "this", "->", "add_action_buttons", "(", "true", ",", "get_string", "(", "'next'", ")", ")", ";", "}" ]
The required basic elements to the form.
[ "The", "required", "basic", "elements", "to", "the", "form", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/forms.php#L319-L327
217,901
moodle/moodle
backup/util/ui/restore_ui.class.php
restore_ui.process
public function process() { if ($this->progress >= self::PROGRESS_PROCESSED) { throw new restore_ui_exception('restoreuialreadyprocessed'); } $this->progress = self::PROGRESS_PROCESSED; if (optional_param('previous', false, PARAM_BOOL) && $this->stage->get_stage() > self::STAGE_CONFIRM) { $this->stage = $this->initialise_stage($this->stage->get_prev_stage(), $this->stage->get_params()); return false; } // Process the stage. $processoutcome = $this->stage->process(); if ($processoutcome !== false && !($this->get_stage() == self::STAGE_PROCESS && optional_param('substage', false, PARAM_BOOL))) { $this->stage = $this->initialise_stage($this->stage->get_next_stage(), $this->stage->get_params()); } // Process UI event after to check changes are valid. $this->controller->process_ui_event(); return $processoutcome; }
php
public function process() { if ($this->progress >= self::PROGRESS_PROCESSED) { throw new restore_ui_exception('restoreuialreadyprocessed'); } $this->progress = self::PROGRESS_PROCESSED; if (optional_param('previous', false, PARAM_BOOL) && $this->stage->get_stage() > self::STAGE_CONFIRM) { $this->stage = $this->initialise_stage($this->stage->get_prev_stage(), $this->stage->get_params()); return false; } // Process the stage. $processoutcome = $this->stage->process(); if ($processoutcome !== false && !($this->get_stage() == self::STAGE_PROCESS && optional_param('substage', false, PARAM_BOOL))) { $this->stage = $this->initialise_stage($this->stage->get_next_stage(), $this->stage->get_params()); } // Process UI event after to check changes are valid. $this->controller->process_ui_event(); return $processoutcome; }
[ "public", "function", "process", "(", ")", "{", "if", "(", "$", "this", "->", "progress", ">=", "self", "::", "PROGRESS_PROCESSED", ")", "{", "throw", "new", "restore_ui_exception", "(", "'restoreuialreadyprocessed'", ")", ";", "}", "$", "this", "->", "progress", "=", "self", "::", "PROGRESS_PROCESSED", ";", "if", "(", "optional_param", "(", "'previous'", ",", "false", ",", "PARAM_BOOL", ")", "&&", "$", "this", "->", "stage", "->", "get_stage", "(", ")", ">", "self", "::", "STAGE_CONFIRM", ")", "{", "$", "this", "->", "stage", "=", "$", "this", "->", "initialise_stage", "(", "$", "this", "->", "stage", "->", "get_prev_stage", "(", ")", ",", "$", "this", "->", "stage", "->", "get_params", "(", ")", ")", ";", "return", "false", ";", "}", "// Process the stage.", "$", "processoutcome", "=", "$", "this", "->", "stage", "->", "process", "(", ")", ";", "if", "(", "$", "processoutcome", "!==", "false", "&&", "!", "(", "$", "this", "->", "get_stage", "(", ")", "==", "self", "::", "STAGE_PROCESS", "&&", "optional_param", "(", "'substage'", ",", "false", ",", "PARAM_BOOL", ")", ")", ")", "{", "$", "this", "->", "stage", "=", "$", "this", "->", "initialise_stage", "(", "$", "this", "->", "stage", "->", "get_next_stage", "(", ")", ",", "$", "this", "->", "stage", "->", "get_params", "(", ")", ")", ";", "}", "// Process UI event after to check changes are valid.", "$", "this", "->", "controller", "->", "process_ui_event", "(", ")", ";", "return", "$", "processoutcome", ";", "}" ]
This processes the current stage of the restore @throws restore_ui_exception if the progress is wrong. @return bool
[ "This", "processes", "the", "current", "stage", "of", "the", "restore" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/restore_ui.class.php#L129-L149
217,902
moodle/moodle
backup/util/ui/restore_ui.class.php
restore_ui.execute
public function execute() { if ($this->progress >= self::PROGRESS_EXECUTED) { throw new restore_ui_exception('restoreuialreadyexecuted'); } if ($this->stage->get_stage() < self::STAGE_PROCESS) { throw new restore_ui_exception('restoreuifinalisedbeforeexecute'); } if ($this->controller->get_target() == backup::TARGET_CURRENT_DELETING || $this->controller->get_target() == backup::TARGET_EXISTING_DELETING) { $options = array(); $options['keep_roles_and_enrolments'] = $this->get_setting_value('keep_roles_and_enrolments'); $options['keep_groups_and_groupings'] = $this->get_setting_value('keep_groups_and_groupings'); restore_dbops::delete_course_content($this->controller->get_courseid(), $options); } $this->controller->execute_plan(); $this->progress = self::PROGRESS_EXECUTED; $this->stage = new restore_ui_stage_complete($this, $this->stage->get_params(), $this->controller->get_results()); return true; }
php
public function execute() { if ($this->progress >= self::PROGRESS_EXECUTED) { throw new restore_ui_exception('restoreuialreadyexecuted'); } if ($this->stage->get_stage() < self::STAGE_PROCESS) { throw new restore_ui_exception('restoreuifinalisedbeforeexecute'); } if ($this->controller->get_target() == backup::TARGET_CURRENT_DELETING || $this->controller->get_target() == backup::TARGET_EXISTING_DELETING) { $options = array(); $options['keep_roles_and_enrolments'] = $this->get_setting_value('keep_roles_and_enrolments'); $options['keep_groups_and_groupings'] = $this->get_setting_value('keep_groups_and_groupings'); restore_dbops::delete_course_content($this->controller->get_courseid(), $options); } $this->controller->execute_plan(); $this->progress = self::PROGRESS_EXECUTED; $this->stage = new restore_ui_stage_complete($this, $this->stage->get_params(), $this->controller->get_results()); return true; }
[ "public", "function", "execute", "(", ")", "{", "if", "(", "$", "this", "->", "progress", ">=", "self", "::", "PROGRESS_EXECUTED", ")", "{", "throw", "new", "restore_ui_exception", "(", "'restoreuialreadyexecuted'", ")", ";", "}", "if", "(", "$", "this", "->", "stage", "->", "get_stage", "(", ")", "<", "self", "::", "STAGE_PROCESS", ")", "{", "throw", "new", "restore_ui_exception", "(", "'restoreuifinalisedbeforeexecute'", ")", ";", "}", "if", "(", "$", "this", "->", "controller", "->", "get_target", "(", ")", "==", "backup", "::", "TARGET_CURRENT_DELETING", "||", "$", "this", "->", "controller", "->", "get_target", "(", ")", "==", "backup", "::", "TARGET_EXISTING_DELETING", ")", "{", "$", "options", "=", "array", "(", ")", ";", "$", "options", "[", "'keep_roles_and_enrolments'", "]", "=", "$", "this", "->", "get_setting_value", "(", "'keep_roles_and_enrolments'", ")", ";", "$", "options", "[", "'keep_groups_and_groupings'", "]", "=", "$", "this", "->", "get_setting_value", "(", "'keep_groups_and_groupings'", ")", ";", "restore_dbops", "::", "delete_course_content", "(", "$", "this", "->", "controller", "->", "get_courseid", "(", ")", ",", "$", "options", ")", ";", "}", "$", "this", "->", "controller", "->", "execute_plan", "(", ")", ";", "$", "this", "->", "progress", "=", "self", "::", "PROGRESS_EXECUTED", ";", "$", "this", "->", "stage", "=", "new", "restore_ui_stage_complete", "(", "$", "this", ",", "$", "this", "->", "stage", "->", "get_params", "(", ")", ",", "$", "this", "->", "controller", "->", "get_results", "(", ")", ")", ";", "return", "true", ";", "}" ]
Executes the restore plan @throws restore_ui_exception if the progress or stage is wrong. @return bool
[ "Executes", "the", "restore", "plan" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/restore_ui.class.php#L211-L228
217,903
moodle/moodle
backup/util/ui/restore_ui.class.php
restore_ui.cleanup
public function cleanup() { global $DB; $courseid = $this->controller->get_courseid(); if ($this->is_temporary_course_created($courseid) && $course = $DB->get_record('course', array('id' => $courseid))) { $course->deletesource = 'restore'; delete_course($course, false); } }
php
public function cleanup() { global $DB; $courseid = $this->controller->get_courseid(); if ($this->is_temporary_course_created($courseid) && $course = $DB->get_record('course', array('id' => $courseid))) { $course->deletesource = 'restore'; delete_course($course, false); } }
[ "public", "function", "cleanup", "(", ")", "{", "global", "$", "DB", ";", "$", "courseid", "=", "$", "this", "->", "controller", "->", "get_courseid", "(", ")", ";", "if", "(", "$", "this", "->", "is_temporary_course_created", "(", "$", "courseid", ")", "&&", "$", "course", "=", "$", "DB", "->", "get_record", "(", "'course'", ",", "array", "(", "'id'", "=>", "$", "courseid", ")", ")", ")", "{", "$", "course", "->", "deletesource", "=", "'restore'", ";", "delete_course", "(", "$", "course", ",", "false", ")", ";", "}", "}" ]
Delete course which is created by restore process
[ "Delete", "course", "which", "is", "created", "by", "restore", "process" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/restore_ui.class.php#L233-L240
217,904
moodle/moodle
backup/util/ui/restore_ui.class.php
restore_ui.is_temporary_course_created
protected function is_temporary_course_created($courseid) { global $DB; // Check if current controller instance has created new course. if ($this->controller->get_target() == backup::TARGET_NEW_COURSE) { $results = $DB->record_exists_sql("SELECT bc.itemid FROM {backup_controllers} bc, {course} c WHERE bc.operation = 'restore' AND bc.type = 'course' AND bc.itemid = c.id AND bc.itemid = ?", array($courseid) ); return $results; } return false; }
php
protected function is_temporary_course_created($courseid) { global $DB; // Check if current controller instance has created new course. if ($this->controller->get_target() == backup::TARGET_NEW_COURSE) { $results = $DB->record_exists_sql("SELECT bc.itemid FROM {backup_controllers} bc, {course} c WHERE bc.operation = 'restore' AND bc.type = 'course' AND bc.itemid = c.id AND bc.itemid = ?", array($courseid) ); return $results; } return false; }
[ "protected", "function", "is_temporary_course_created", "(", "$", "courseid", ")", "{", "global", "$", "DB", ";", "// Check if current controller instance has created new course.", "if", "(", "$", "this", "->", "controller", "->", "get_target", "(", ")", "==", "backup", "::", "TARGET_NEW_COURSE", ")", "{", "$", "results", "=", "$", "DB", "->", "record_exists_sql", "(", "\"SELECT bc.itemid\n FROM {backup_controllers} bc, {course} c\n WHERE bc.operation = 'restore'\n AND bc.type = 'course'\n AND bc.itemid = c.id\n AND bc.itemid = ?\"", ",", "array", "(", "$", "courseid", ")", ")", ";", "return", "$", "results", ";", "}", "return", "false", ";", "}" ]
Checks if the course is not restored fully and current controller has created it. @param int $courseid id of the course which needs to be checked @return bool
[ "Checks", "if", "the", "course", "is", "not", "restored", "fully", "and", "current", "controller", "has", "created", "it", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/restore_ui.class.php#L247-L262
217,905
moodle/moodle
backup/util/ui/restore_ui.class.php
restore_ui.load_controller
final public static function load_controller($restoreid = false) { // Get the restore id optional param. if ($restoreid) { try { // Try to load the controller with it. // If it fails at this point it is likely because this is the first load. $controller = restore_controller::load_controller($restoreid); return $controller; } catch (Exception $e) { return false; } } return $restoreid; }
php
final public static function load_controller($restoreid = false) { // Get the restore id optional param. if ($restoreid) { try { // Try to load the controller with it. // If it fails at this point it is likely because this is the first load. $controller = restore_controller::load_controller($restoreid); return $controller; } catch (Exception $e) { return false; } } return $restoreid; }
[ "final", "public", "static", "function", "load_controller", "(", "$", "restoreid", "=", "false", ")", "{", "// Get the restore id optional param.", "if", "(", "$", "restoreid", ")", "{", "try", "{", "// Try to load the controller with it.", "// If it fails at this point it is likely because this is the first load.", "$", "controller", "=", "restore_controller", "::", "load_controller", "(", "$", "restoreid", ")", ";", "return", "$", "controller", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "return", "false", ";", "}", "}", "return", "$", "restoreid", ";", "}" ]
Loads the restore controller if we are tracking one @param string|bool $restoreid @return string
[ "Loads", "the", "restore", "controller", "if", "we", "are", "tracking", "one" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/restore_ui.class.php#L277-L290
217,906
moodle/moodle
backup/util/ui/restore_ui.class.php
restore_ui.engage_independent_stage
final public static function engage_independent_stage($stage, $contextid) { if (!($stage & self::STAGE_CONFIRM + self::STAGE_DESTINATION)) { throw new restore_ui_exception('dependentstagerequested'); } $class = 'restore_ui_stage_'.self::$stages[$stage]; if (!class_exists($class)) { throw new restore_ui_exception('unknownuistage'); } return new $class($contextid); }
php
final public static function engage_independent_stage($stage, $contextid) { if (!($stage & self::STAGE_CONFIRM + self::STAGE_DESTINATION)) { throw new restore_ui_exception('dependentstagerequested'); } $class = 'restore_ui_stage_'.self::$stages[$stage]; if (!class_exists($class)) { throw new restore_ui_exception('unknownuistage'); } return new $class($contextid); }
[ "final", "public", "static", "function", "engage_independent_stage", "(", "$", "stage", ",", "$", "contextid", ")", "{", "if", "(", "!", "(", "$", "stage", "&", "self", "::", "STAGE_CONFIRM", "+", "self", "::", "STAGE_DESTINATION", ")", ")", "{", "throw", "new", "restore_ui_exception", "(", "'dependentstagerequested'", ")", ";", "}", "$", "class", "=", "'restore_ui_stage_'", ".", "self", "::", "$", "stages", "[", "$", "stage", "]", ";", "if", "(", "!", "class_exists", "(", "$", "class", ")", ")", "{", "throw", "new", "restore_ui_exception", "(", "'unknownuistage'", ")", ";", "}", "return", "new", "$", "class", "(", "$", "contextid", ")", ";", "}" ]
Initialised the requested independent stage @throws restore_ui_exception @param int $stage One of self::STAGE_* @param int $contextid @return restore_ui_stage_confirm|restore_ui_stage_destination
[ "Initialised", "the", "requested", "independent", "stage" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/restore_ui.class.php#L300-L309
217,907
moodle/moodle
backup/util/ui/restore_ui.class.php
restore_ui.cancel_process
public function cancel_process() { // Delete temporary restore course if exists. if ($this->controller->get_target() == backup::TARGET_NEW_COURSE) { $this->cleanup(); } parent::cancel_process(); }
php
public function cancel_process() { // Delete temporary restore course if exists. if ($this->controller->get_target() == backup::TARGET_NEW_COURSE) { $this->cleanup(); } parent::cancel_process(); }
[ "public", "function", "cancel_process", "(", ")", "{", "// Delete temporary restore course if exists.", "if", "(", "$", "this", "->", "controller", "->", "get_target", "(", ")", "==", "backup", "::", "TARGET_NEW_COURSE", ")", "{", "$", "this", "->", "cleanup", "(", ")", ";", "}", "parent", "::", "cancel_process", "(", ")", ";", "}" ]
Cancels the current restore and redirects the user back to the relevant place
[ "Cancels", "the", "current", "restore", "and", "redirects", "the", "user", "back", "to", "the", "relevant", "place" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/restore_ui.class.php#L314-L320
217,908
moodle/moodle
lib/mlbackend/php/phpml/src/Phpml/Classification/Linear/LogisticRegression.php
LogisticRegression.getCostFunction
protected function getCostFunction() { $penalty = 0; if ($this->penalty == 'L2') { $penalty = $this->lambda; } switch ($this->costFunction) { case 'log': /* * Negative of Log-likelihood cost function to be minimized: * J(x) = ∑( - y . log(h(x)) - (1 - y) . log(1 - h(x))) * * If regularization term is given, then it will be added to the cost: * for L2 : J(x) = J(x) + λ/m . w * * The gradient of the cost function to be used with gradient descent: * ∇J(x) = -(y - h(x)) = (h(x) - y) */ $callback = function ($weights, $sample, $y) use ($penalty) { $this->weights = $weights; $hX = $this->output($sample); // In cases where $hX = 1 or $hX = 0, the log-likelihood // value will give a NaN, so we fix these values if ($hX == 1) { $hX = 1 - 1e-10; } if ($hX == 0) { $hX = 1e-10; } $error = -$y * log($hX) - (1 - $y) * log(1 - $hX); $gradient = $hX - $y; return [$error, $gradient, $penalty]; }; return $callback; case 'sse': /* * Sum of squared errors or least squared errors cost function: * J(x) = ∑ (y - h(x))^2 * * If regularization term is given, then it will be added to the cost: * for L2 : J(x) = J(x) + λ/m . w * * The gradient of the cost function: * ∇J(x) = -(h(x) - y) . h(x) . (1 - h(x)) */ $callback = function ($weights, $sample, $y) use ($penalty) { $this->weights = $weights; $hX = $this->output($sample); $error = ($y - $hX) ** 2; $gradient = -($y - $hX) * $hX * (1 - $hX); return [$error, $gradient, $penalty]; }; return $callback; default: throw new \Exception(sprintf('Logistic regression has invalid cost function: %s.', $this->costFunction)); } }
php
protected function getCostFunction() { $penalty = 0; if ($this->penalty == 'L2') { $penalty = $this->lambda; } switch ($this->costFunction) { case 'log': /* * Negative of Log-likelihood cost function to be minimized: * J(x) = ∑( - y . log(h(x)) - (1 - y) . log(1 - h(x))) * * If regularization term is given, then it will be added to the cost: * for L2 : J(x) = J(x) + λ/m . w * * The gradient of the cost function to be used with gradient descent: * ∇J(x) = -(y - h(x)) = (h(x) - y) */ $callback = function ($weights, $sample, $y) use ($penalty) { $this->weights = $weights; $hX = $this->output($sample); // In cases where $hX = 1 or $hX = 0, the log-likelihood // value will give a NaN, so we fix these values if ($hX == 1) { $hX = 1 - 1e-10; } if ($hX == 0) { $hX = 1e-10; } $error = -$y * log($hX) - (1 - $y) * log(1 - $hX); $gradient = $hX - $y; return [$error, $gradient, $penalty]; }; return $callback; case 'sse': /* * Sum of squared errors or least squared errors cost function: * J(x) = ∑ (y - h(x))^2 * * If regularization term is given, then it will be added to the cost: * for L2 : J(x) = J(x) + λ/m . w * * The gradient of the cost function: * ∇J(x) = -(h(x) - y) . h(x) . (1 - h(x)) */ $callback = function ($weights, $sample, $y) use ($penalty) { $this->weights = $weights; $hX = $this->output($sample); $error = ($y - $hX) ** 2; $gradient = -($y - $hX) * $hX * (1 - $hX); return [$error, $gradient, $penalty]; }; return $callback; default: throw new \Exception(sprintf('Logistic regression has invalid cost function: %s.', $this->costFunction)); } }
[ "protected", "function", "getCostFunction", "(", ")", "{", "$", "penalty", "=", "0", ";", "if", "(", "$", "this", "->", "penalty", "==", "'L2'", ")", "{", "$", "penalty", "=", "$", "this", "->", "lambda", ";", "}", "switch", "(", "$", "this", "->", "costFunction", ")", "{", "case", "'log'", ":", "/*\n * Negative of Log-likelihood cost function to be minimized:\n *\t\tJ(x) = ∑( - y . log(h(x)) - (1 - y) . log(1 - h(x)))\n *\n * If regularization term is given, then it will be added to the cost:\n *\t\tfor L2 : J(x) = J(x) + λ/m . w\n *\n * The gradient of the cost function to be used with gradient descent:\n *\t\t∇J(x) = -(y - h(x)) = (h(x) - y)\n */", "$", "callback", "=", "function", "(", "$", "weights", ",", "$", "sample", ",", "$", "y", ")", "use", "(", "$", "penalty", ")", "{", "$", "this", "->", "weights", "=", "$", "weights", ";", "$", "hX", "=", "$", "this", "->", "output", "(", "$", "sample", ")", ";", "// In cases where $hX = 1 or $hX = 0, the log-likelihood", "// value will give a NaN, so we fix these values", "if", "(", "$", "hX", "==", "1", ")", "{", "$", "hX", "=", "1", "-", "1e-10", ";", "}", "if", "(", "$", "hX", "==", "0", ")", "{", "$", "hX", "=", "1e-10", ";", "}", "$", "error", "=", "-", "$", "y", "*", "log", "(", "$", "hX", ")", "-", "(", "1", "-", "$", "y", ")", "*", "log", "(", "1", "-", "$", "hX", ")", ";", "$", "gradient", "=", "$", "hX", "-", "$", "y", ";", "return", "[", "$", "error", ",", "$", "gradient", ",", "$", "penalty", "]", ";", "}", ";", "return", "$", "callback", ";", "case", "'sse'", ":", "/*\n * Sum of squared errors or least squared errors cost function:\n *\t\tJ(x) = ∑ (y - h(x))^2\n *\n * If regularization term is given, then it will be added to the cost:\n *\t\tfor L2 : J(x) = J(x) + λ/m . w\n *\n * The gradient of the cost function:\n *\t\t∇J(x) = -(h(x) - y) . h(x) . (1 - h(x))\n */", "$", "callback", "=", "function", "(", "$", "weights", ",", "$", "sample", ",", "$", "y", ")", "use", "(", "$", "penalty", ")", "{", "$", "this", "->", "weights", "=", "$", "weights", ";", "$", "hX", "=", "$", "this", "->", "output", "(", "$", "sample", ")", ";", "$", "error", "=", "(", "$", "y", "-", "$", "hX", ")", "**", "2", ";", "$", "gradient", "=", "-", "(", "$", "y", "-", "$", "hX", ")", "*", "$", "hX", "*", "(", "1", "-", "$", "hX", ")", ";", "return", "[", "$", "error", ",", "$", "gradient", ",", "$", "penalty", "]", ";", "}", ";", "return", "$", "callback", ";", "default", ":", "throw", "new", "\\", "Exception", "(", "sprintf", "(", "'Logistic regression has invalid cost function: %s.'", ",", "$", "this", "->", "costFunction", ")", ")", ";", "}", "}" ]
Returns the appropriate callback function for the selected cost function @return \Closure @throws \Exception
[ "Returns", "the", "appropriate", "callback", "function", "for", "the", "selected", "cost", "function" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mlbackend/php/phpml/src/Phpml/Classification/Linear/LogisticRegression.php#L174-L239
217,909
moodle/moodle
lib/outputrequirementslib.php
page_requirements_manager.get_config_for_javascript
public function get_config_for_javascript(moodle_page $page, renderer_base $renderer) { global $CFG; if (empty($this->M_cfg)) { $iconsystem = \core\output\icon_system::instance(); // It is possible that the $page->context is null, so we can't use $page->context->id. $contextid = null; if (!is_null($page->context)) { $contextid = $page->context->id; } $this->M_cfg = array( 'wwwroot' => $CFG->wwwroot, 'sesskey' => sesskey(), 'themerev' => theme_get_revision(), 'slasharguments' => (int)(!empty($CFG->slasharguments)), 'theme' => $page->theme->name, 'iconsystemmodule' => $iconsystem->get_amd_name(), 'jsrev' => $this->get_jsrev(), 'admin' => $CFG->admin, 'svgicons' => $page->theme->use_svg_icons(), 'usertimezone' => usertimezone(), 'contextid' => $contextid, ); if ($CFG->debugdeveloper) { $this->M_cfg['developerdebug'] = true; } if (defined('BEHAT_SITE_RUNNING')) { $this->M_cfg['behatsiterunning'] = true; } } return $this->M_cfg; }
php
public function get_config_for_javascript(moodle_page $page, renderer_base $renderer) { global $CFG; if (empty($this->M_cfg)) { $iconsystem = \core\output\icon_system::instance(); // It is possible that the $page->context is null, so we can't use $page->context->id. $contextid = null; if (!is_null($page->context)) { $contextid = $page->context->id; } $this->M_cfg = array( 'wwwroot' => $CFG->wwwroot, 'sesskey' => sesskey(), 'themerev' => theme_get_revision(), 'slasharguments' => (int)(!empty($CFG->slasharguments)), 'theme' => $page->theme->name, 'iconsystemmodule' => $iconsystem->get_amd_name(), 'jsrev' => $this->get_jsrev(), 'admin' => $CFG->admin, 'svgicons' => $page->theme->use_svg_icons(), 'usertimezone' => usertimezone(), 'contextid' => $contextid, ); if ($CFG->debugdeveloper) { $this->M_cfg['developerdebug'] = true; } if (defined('BEHAT_SITE_RUNNING')) { $this->M_cfg['behatsiterunning'] = true; } } return $this->M_cfg; }
[ "public", "function", "get_config_for_javascript", "(", "moodle_page", "$", "page", ",", "renderer_base", "$", "renderer", ")", "{", "global", "$", "CFG", ";", "if", "(", "empty", "(", "$", "this", "->", "M_cfg", ")", ")", "{", "$", "iconsystem", "=", "\\", "core", "\\", "output", "\\", "icon_system", "::", "instance", "(", ")", ";", "// It is possible that the $page->context is null, so we can't use $page->context->id.", "$", "contextid", "=", "null", ";", "if", "(", "!", "is_null", "(", "$", "page", "->", "context", ")", ")", "{", "$", "contextid", "=", "$", "page", "->", "context", "->", "id", ";", "}", "$", "this", "->", "M_cfg", "=", "array", "(", "'wwwroot'", "=>", "$", "CFG", "->", "wwwroot", ",", "'sesskey'", "=>", "sesskey", "(", ")", ",", "'themerev'", "=>", "theme_get_revision", "(", ")", ",", "'slasharguments'", "=>", "(", "int", ")", "(", "!", "empty", "(", "$", "CFG", "->", "slasharguments", ")", ")", ",", "'theme'", "=>", "$", "page", "->", "theme", "->", "name", ",", "'iconsystemmodule'", "=>", "$", "iconsystem", "->", "get_amd_name", "(", ")", ",", "'jsrev'", "=>", "$", "this", "->", "get_jsrev", "(", ")", ",", "'admin'", "=>", "$", "CFG", "->", "admin", ",", "'svgicons'", "=>", "$", "page", "->", "theme", "->", "use_svg_icons", "(", ")", ",", "'usertimezone'", "=>", "usertimezone", "(", ")", ",", "'contextid'", "=>", "$", "contextid", ",", ")", ";", "if", "(", "$", "CFG", "->", "debugdeveloper", ")", "{", "$", "this", "->", "M_cfg", "[", "'developerdebug'", "]", "=", "true", ";", "}", "if", "(", "defined", "(", "'BEHAT_SITE_RUNNING'", ")", ")", "{", "$", "this", "->", "M_cfg", "[", "'behatsiterunning'", "]", "=", "true", ";", "}", "}", "return", "$", "this", "->", "M_cfg", ";", "}" ]
Return the safe config values that get set for javascript in "M.cfg". @since 2.9 @return array List of safe config values that are available to javascript.
[ "Return", "the", "safe", "config", "values", "that", "get", "set", "for", "javascript", "in", "M", ".", "cfg", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L308-L343
217,910
moodle/moodle
lib/outputrequirementslib.php
page_requirements_manager.init_requirements_data
protected function init_requirements_data(moodle_page $page, core_renderer $renderer) { global $CFG; // Init the js config. $this->get_config_for_javascript($page, $renderer); // Accessibility stuff. $this->skip_link_to('maincontent', get_string('tocontent', 'access')); // Add strings used on many pages. $this->string_for_js('confirmation', 'admin'); $this->string_for_js('cancel', 'moodle'); $this->string_for_js('yes', 'moodle'); // Alter links in top frame to break out of frames. if ($page->pagelayout === 'frametop') { $this->js_init_call('M.util.init_frametop'); } // Include block drag/drop if editing is on if ($page->user_is_editing()) { $params = array( 'courseid' => $page->course->id, 'pagetype' => $page->pagetype, 'pagelayout' => $page->pagelayout, 'subpage' => $page->subpage, 'regions' => $page->blocks->get_regions(), 'contextid' => $page->context->id, ); if (!empty($page->cm->id)) { $params['cmid'] = $page->cm->id; } // Strings for drag and drop. $this->strings_for_js(array('movecontent', 'tocontent', 'emptydragdropregion'), 'moodle'); $page->requires->yui_module('moodle-core-blocks', 'M.core_blocks.init_dragdrop', array($params), null, true); } // Include the YUI CSS Modules. $page->requires->set_yuicssmodules($page->theme->yuicssmodules); }
php
protected function init_requirements_data(moodle_page $page, core_renderer $renderer) { global $CFG; // Init the js config. $this->get_config_for_javascript($page, $renderer); // Accessibility stuff. $this->skip_link_to('maincontent', get_string('tocontent', 'access')); // Add strings used on many pages. $this->string_for_js('confirmation', 'admin'); $this->string_for_js('cancel', 'moodle'); $this->string_for_js('yes', 'moodle'); // Alter links in top frame to break out of frames. if ($page->pagelayout === 'frametop') { $this->js_init_call('M.util.init_frametop'); } // Include block drag/drop if editing is on if ($page->user_is_editing()) { $params = array( 'courseid' => $page->course->id, 'pagetype' => $page->pagetype, 'pagelayout' => $page->pagelayout, 'subpage' => $page->subpage, 'regions' => $page->blocks->get_regions(), 'contextid' => $page->context->id, ); if (!empty($page->cm->id)) { $params['cmid'] = $page->cm->id; } // Strings for drag and drop. $this->strings_for_js(array('movecontent', 'tocontent', 'emptydragdropregion'), 'moodle'); $page->requires->yui_module('moodle-core-blocks', 'M.core_blocks.init_dragdrop', array($params), null, true); } // Include the YUI CSS Modules. $page->requires->set_yuicssmodules($page->theme->yuicssmodules); }
[ "protected", "function", "init_requirements_data", "(", "moodle_page", "$", "page", ",", "core_renderer", "$", "renderer", ")", "{", "global", "$", "CFG", ";", "// Init the js config.", "$", "this", "->", "get_config_for_javascript", "(", "$", "page", ",", "$", "renderer", ")", ";", "// Accessibility stuff.", "$", "this", "->", "skip_link_to", "(", "'maincontent'", ",", "get_string", "(", "'tocontent'", ",", "'access'", ")", ")", ";", "// Add strings used on many pages.", "$", "this", "->", "string_for_js", "(", "'confirmation'", ",", "'admin'", ")", ";", "$", "this", "->", "string_for_js", "(", "'cancel'", ",", "'moodle'", ")", ";", "$", "this", "->", "string_for_js", "(", "'yes'", ",", "'moodle'", ")", ";", "// Alter links in top frame to break out of frames.", "if", "(", "$", "page", "->", "pagelayout", "===", "'frametop'", ")", "{", "$", "this", "->", "js_init_call", "(", "'M.util.init_frametop'", ")", ";", "}", "// Include block drag/drop if editing is on", "if", "(", "$", "page", "->", "user_is_editing", "(", ")", ")", "{", "$", "params", "=", "array", "(", "'courseid'", "=>", "$", "page", "->", "course", "->", "id", ",", "'pagetype'", "=>", "$", "page", "->", "pagetype", ",", "'pagelayout'", "=>", "$", "page", "->", "pagelayout", ",", "'subpage'", "=>", "$", "page", "->", "subpage", ",", "'regions'", "=>", "$", "page", "->", "blocks", "->", "get_regions", "(", ")", ",", "'contextid'", "=>", "$", "page", "->", "context", "->", "id", ",", ")", ";", "if", "(", "!", "empty", "(", "$", "page", "->", "cm", "->", "id", ")", ")", "{", "$", "params", "[", "'cmid'", "]", "=", "$", "page", "->", "cm", "->", "id", ";", "}", "// Strings for drag and drop.", "$", "this", "->", "strings_for_js", "(", "array", "(", "'movecontent'", ",", "'tocontent'", ",", "'emptydragdropregion'", ")", ",", "'moodle'", ")", ";", "$", "page", "->", "requires", "->", "yui_module", "(", "'moodle-core-blocks'", ",", "'M.core_blocks.init_dragdrop'", ",", "array", "(", "$", "params", ")", ",", "null", ",", "true", ")", ";", "}", "// Include the YUI CSS Modules.", "$", "page", "->", "requires", "->", "set_yuicssmodules", "(", "$", "page", "->", "theme", "->", "yuicssmodules", ")", ";", "}" ]
Initialise with the bits of JavaScript that every Moodle page should have. @param moodle_page $page @param core_renderer $renderer
[ "Initialise", "with", "the", "bits", "of", "JavaScript", "that", "every", "Moodle", "page", "should", "have", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L351-L393
217,911
moodle/moodle
lib/outputrequirementslib.php
page_requirements_manager.get_jsrev
protected function get_jsrev() { global $CFG; if (empty($CFG->cachejs)) { $jsrev = -1; } else if (empty($CFG->jsrev)) { $jsrev = 1; } else { $jsrev = $CFG->jsrev; } return $jsrev; }
php
protected function get_jsrev() { global $CFG; if (empty($CFG->cachejs)) { $jsrev = -1; } else if (empty($CFG->jsrev)) { $jsrev = 1; } else { $jsrev = $CFG->jsrev; } return $jsrev; }
[ "protected", "function", "get_jsrev", "(", ")", "{", "global", "$", "CFG", ";", "if", "(", "empty", "(", "$", "CFG", "->", "cachejs", ")", ")", "{", "$", "jsrev", "=", "-", "1", ";", "}", "else", "if", "(", "empty", "(", "$", "CFG", "->", "jsrev", ")", ")", "{", "$", "jsrev", "=", "1", ";", "}", "else", "{", "$", "jsrev", "=", "$", "CFG", "->", "jsrev", ";", "}", "return", "$", "jsrev", ";", "}" ]
Determine the correct JS Revision to use for this load. @return int the jsrev to use.
[ "Determine", "the", "correct", "JS", "Revision", "to", "use", "for", "this", "load", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L400-L412
217,912
moodle/moodle
lib/outputrequirementslib.php
page_requirements_manager.js
public function js($url, $inhead = false) { $url = $this->js_fix_url($url); $where = $inhead ? 'head' : 'footer'; $this->jsincludes[$where][$url->out()] = $url; }
php
public function js($url, $inhead = false) { $url = $this->js_fix_url($url); $where = $inhead ? 'head' : 'footer'; $this->jsincludes[$where][$url->out()] = $url; }
[ "public", "function", "js", "(", "$", "url", ",", "$", "inhead", "=", "false", ")", "{", "$", "url", "=", "$", "this", "->", "js_fix_url", "(", "$", "url", ")", ";", "$", "where", "=", "$", "inhead", "?", "'head'", ":", "'footer'", ";", "$", "this", "->", "jsincludes", "[", "$", "where", "]", "[", "$", "url", "->", "out", "(", ")", "]", "=", "$", "url", ";", "}" ]
Ensure that the specified JavaScript file is linked to from this page. NOTE: This function is to be used in RARE CASES ONLY, please store your JS in module.js file and use $PAGE->requires->js_init_call() instead or use /yui/ subdirectories for YUI modules. By default the link is put at the end of the page, since this gives best page-load performance. Even if a particular script is requested more than once, it will only be linked to once. @param string|moodle_url $url The path to the .js file, relative to $CFG->dirroot / $CFG->wwwroot. For example '/mod/mymod/customscripts.js'; use moodle_url for external scripts @param bool $inhead initialise in head
[ "Ensure", "that", "the", "specified", "JavaScript", "file", "is", "linked", "to", "from", "this", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L429-L433
217,913
moodle/moodle
lib/outputrequirementslib.php
page_requirements_manager.jquery_override_plugin
public function jquery_override_plugin($oldplugin, $newplugin) { if ($this->headdone) { debugging('Can not override jQuery plugins after starting page output!'); return; } $this->jquerypluginoverrides[$oldplugin] = $newplugin; }
php
public function jquery_override_plugin($oldplugin, $newplugin) { if ($this->headdone) { debugging('Can not override jQuery plugins after starting page output!'); return; } $this->jquerypluginoverrides[$oldplugin] = $newplugin; }
[ "public", "function", "jquery_override_plugin", "(", "$", "oldplugin", ",", "$", "newplugin", ")", "{", "if", "(", "$", "this", "->", "headdone", ")", "{", "debugging", "(", "'Can not override jQuery plugins after starting page output!'", ")", ";", "return", ";", "}", "$", "this", "->", "jquerypluginoverrides", "[", "$", "oldplugin", "]", "=", "$", "newplugin", ";", "}" ]
Request replacement of one jQuery plugin by another. This is useful when themes want to replace the jQuery UI theme, the problem is that theme can not prevent others from including the core ui-css plugin. Example: 1/ generate new jQuery UI theme and place it into theme/yourtheme/jquery/ 2/ write theme/yourtheme/jquery/plugins.php 3/ init jQuery from theme <code> // file theme/yourtheme/lib.php function theme_yourtheme_page_init($page) { $page->requires->jquery_plugin('yourtheme-ui-css', 'theme_yourtheme'); $page->requires->jquery_override_plugin('ui-css', 'yourtheme-ui-css'); } </code> This code prevents loading of standard 'ui-css' which my be requested by other plugins, the 'yourtheme-ui-css' gets loaded only if some other code requires jquery. {@see http://docs.moodle.org/dev/jQuery} @param string $oldplugin original plugin @param string $newplugin the replacement
[ "Request", "replacement", "of", "one", "jQuery", "plugin", "by", "another", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L604-L610
217,914
moodle/moodle
lib/outputrequirementslib.php
page_requirements_manager.get_jquery_headcode
protected function get_jquery_headcode() { if (empty($this->jqueryplugins['jquery'])) { // If nobody requested jQuery then do not bother to load anything. // This may be useful for themes that want to override 'ui-css' only if requested by something else. return ''; } $included = array(); $urls = array(); foreach ($this->jqueryplugins as $name => $unused) { if (isset($included[$name])) { continue; } if (array_key_exists($name, $this->jquerypluginoverrides)) { // The following loop tries to resolve the replacements, // use max 100 iterations to prevent infinite loop resulting // in blank page. $cyclic = true; $oldname = $name; for ($i=0; $i<100; $i++) { $name = $this->jquerypluginoverrides[$name]; if (!array_key_exists($name, $this->jquerypluginoverrides)) { $cyclic = false; break; } } if ($cyclic) { // We can not do much with cyclic references here, let's use the old plugin. $name = $oldname; debugging("Cyclic overrides detected for jQuery plugin '$name'"); } else if (empty($name)) { // Developer requested removal of the plugin. continue; } else if (!isset($this->jqueryplugins[$name])) { debugging("Unknown jQuery override plugin '$name' detected"); $name = $oldname; } else if (isset($included[$name])) { // The plugin was already included, easy. continue; } } $plugin = $this->jqueryplugins[$name]; $urls = array_merge($urls, $plugin->urls); $included[$name] = true; } $output = ''; $attributes = array('rel' => 'stylesheet', 'type' => 'text/css'); foreach ($urls as $url) { if (preg_match('/\.js$/', $url)) { $output .= html_writer::script('', $url); } else if (preg_match('/\.css$/', $url)) { $attributes['href'] = $url; $output .= html_writer::empty_tag('link', $attributes) . "\n"; } } return $output; }
php
protected function get_jquery_headcode() { if (empty($this->jqueryplugins['jquery'])) { // If nobody requested jQuery then do not bother to load anything. // This may be useful for themes that want to override 'ui-css' only if requested by something else. return ''; } $included = array(); $urls = array(); foreach ($this->jqueryplugins as $name => $unused) { if (isset($included[$name])) { continue; } if (array_key_exists($name, $this->jquerypluginoverrides)) { // The following loop tries to resolve the replacements, // use max 100 iterations to prevent infinite loop resulting // in blank page. $cyclic = true; $oldname = $name; for ($i=0; $i<100; $i++) { $name = $this->jquerypluginoverrides[$name]; if (!array_key_exists($name, $this->jquerypluginoverrides)) { $cyclic = false; break; } } if ($cyclic) { // We can not do much with cyclic references here, let's use the old plugin. $name = $oldname; debugging("Cyclic overrides detected for jQuery plugin '$name'"); } else if (empty($name)) { // Developer requested removal of the plugin. continue; } else if (!isset($this->jqueryplugins[$name])) { debugging("Unknown jQuery override plugin '$name' detected"); $name = $oldname; } else if (isset($included[$name])) { // The plugin was already included, easy. continue; } } $plugin = $this->jqueryplugins[$name]; $urls = array_merge($urls, $plugin->urls); $included[$name] = true; } $output = ''; $attributes = array('rel' => 'stylesheet', 'type' => 'text/css'); foreach ($urls as $url) { if (preg_match('/\.js$/', $url)) { $output .= html_writer::script('', $url); } else if (preg_match('/\.css$/', $url)) { $attributes['href'] = $url; $output .= html_writer::empty_tag('link', $attributes) . "\n"; } } return $output; }
[ "protected", "function", "get_jquery_headcode", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "jqueryplugins", "[", "'jquery'", "]", ")", ")", "{", "// If nobody requested jQuery then do not bother to load anything.", "// This may be useful for themes that want to override 'ui-css' only if requested by something else.", "return", "''", ";", "}", "$", "included", "=", "array", "(", ")", ";", "$", "urls", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "jqueryplugins", "as", "$", "name", "=>", "$", "unused", ")", "{", "if", "(", "isset", "(", "$", "included", "[", "$", "name", "]", ")", ")", "{", "continue", ";", "}", "if", "(", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "jquerypluginoverrides", ")", ")", "{", "// The following loop tries to resolve the replacements,", "// use max 100 iterations to prevent infinite loop resulting", "// in blank page.", "$", "cyclic", "=", "true", ";", "$", "oldname", "=", "$", "name", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "100", ";", "$", "i", "++", ")", "{", "$", "name", "=", "$", "this", "->", "jquerypluginoverrides", "[", "$", "name", "]", ";", "if", "(", "!", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "jquerypluginoverrides", ")", ")", "{", "$", "cyclic", "=", "false", ";", "break", ";", "}", "}", "if", "(", "$", "cyclic", ")", "{", "// We can not do much with cyclic references here, let's use the old plugin.", "$", "name", "=", "$", "oldname", ";", "debugging", "(", "\"Cyclic overrides detected for jQuery plugin '$name'\"", ")", ";", "}", "else", "if", "(", "empty", "(", "$", "name", ")", ")", "{", "// Developer requested removal of the plugin.", "continue", ";", "}", "else", "if", "(", "!", "isset", "(", "$", "this", "->", "jqueryplugins", "[", "$", "name", "]", ")", ")", "{", "debugging", "(", "\"Unknown jQuery override plugin '$name' detected\"", ")", ";", "$", "name", "=", "$", "oldname", ";", "}", "else", "if", "(", "isset", "(", "$", "included", "[", "$", "name", "]", ")", ")", "{", "// The plugin was already included, easy.", "continue", ";", "}", "}", "$", "plugin", "=", "$", "this", "->", "jqueryplugins", "[", "$", "name", "]", ";", "$", "urls", "=", "array_merge", "(", "$", "urls", ",", "$", "plugin", "->", "urls", ")", ";", "$", "included", "[", "$", "name", "]", "=", "true", ";", "}", "$", "output", "=", "''", ";", "$", "attributes", "=", "array", "(", "'rel'", "=>", "'stylesheet'", ",", "'type'", "=>", "'text/css'", ")", ";", "foreach", "(", "$", "urls", "as", "$", "url", ")", "{", "if", "(", "preg_match", "(", "'/\\.js$/'", ",", "$", "url", ")", ")", "{", "$", "output", ".=", "html_writer", "::", "script", "(", "''", ",", "$", "url", ")", ";", "}", "else", "if", "(", "preg_match", "(", "'/\\.css$/'", ",", "$", "url", ")", ")", "{", "$", "attributes", "[", "'href'", "]", "=", "$", "url", ";", "$", "output", ".=", "html_writer", "::", "empty_tag", "(", "'link'", ",", "$", "attributes", ")", ".", "\"\\n\"", ";", "}", "}", "return", "$", "output", ";", "}" ]
Return jQuery related markup for page start. @return string
[ "Return", "jQuery", "related", "markup", "for", "page", "start", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L616-L679
217,915
moodle/moodle
lib/outputrequirementslib.php
page_requirements_manager.js_fix_url
protected function js_fix_url($url) { global $CFG; if ($url instanceof moodle_url) { return $url; } else if (strpos($url, '/') === 0) { // Fix the admin links if needed. if ($CFG->admin !== 'admin') { if (strpos($url, "/admin/") === 0) { $url = preg_replace("|^/admin/|", "/$CFG->admin/", $url); } } if (debugging()) { // Check file existence only when in debug mode. if (!file_exists($CFG->dirroot . strtok($url, '?'))) { throw new coding_exception('Attempt to require a JavaScript file that does not exist.', $url); } } if (substr($url, -3) === '.js') { $jsrev = $this->get_jsrev(); if (empty($CFG->slasharguments)) { return new moodle_url('/lib/javascript.php', array('rev'=>$jsrev, 'jsfile'=>$url)); } else { $returnurl = new moodle_url('/lib/javascript.php'); $returnurl->set_slashargument('/'.$jsrev.$url); return $returnurl; } } else { return new moodle_url($url); } } else { throw new coding_exception('Invalid JS url, it has to be shortened url starting with / or moodle_url instance.', $url); } }
php
protected function js_fix_url($url) { global $CFG; if ($url instanceof moodle_url) { return $url; } else if (strpos($url, '/') === 0) { // Fix the admin links if needed. if ($CFG->admin !== 'admin') { if (strpos($url, "/admin/") === 0) { $url = preg_replace("|^/admin/|", "/$CFG->admin/", $url); } } if (debugging()) { // Check file existence only when in debug mode. if (!file_exists($CFG->dirroot . strtok($url, '?'))) { throw new coding_exception('Attempt to require a JavaScript file that does not exist.', $url); } } if (substr($url, -3) === '.js') { $jsrev = $this->get_jsrev(); if (empty($CFG->slasharguments)) { return new moodle_url('/lib/javascript.php', array('rev'=>$jsrev, 'jsfile'=>$url)); } else { $returnurl = new moodle_url('/lib/javascript.php'); $returnurl->set_slashargument('/'.$jsrev.$url); return $returnurl; } } else { return new moodle_url($url); } } else { throw new coding_exception('Invalid JS url, it has to be shortened url starting with / or moodle_url instance.', $url); } }
[ "protected", "function", "js_fix_url", "(", "$", "url", ")", "{", "global", "$", "CFG", ";", "if", "(", "$", "url", "instanceof", "moodle_url", ")", "{", "return", "$", "url", ";", "}", "else", "if", "(", "strpos", "(", "$", "url", ",", "'/'", ")", "===", "0", ")", "{", "// Fix the admin links if needed.", "if", "(", "$", "CFG", "->", "admin", "!==", "'admin'", ")", "{", "if", "(", "strpos", "(", "$", "url", ",", "\"/admin/\"", ")", "===", "0", ")", "{", "$", "url", "=", "preg_replace", "(", "\"|^/admin/|\"", ",", "\"/$CFG->admin/\"", ",", "$", "url", ")", ";", "}", "}", "if", "(", "debugging", "(", ")", ")", "{", "// Check file existence only when in debug mode.", "if", "(", "!", "file_exists", "(", "$", "CFG", "->", "dirroot", ".", "strtok", "(", "$", "url", ",", "'?'", ")", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Attempt to require a JavaScript file that does not exist.'", ",", "$", "url", ")", ";", "}", "}", "if", "(", "substr", "(", "$", "url", ",", "-", "3", ")", "===", "'.js'", ")", "{", "$", "jsrev", "=", "$", "this", "->", "get_jsrev", "(", ")", ";", "if", "(", "empty", "(", "$", "CFG", "->", "slasharguments", ")", ")", "{", "return", "new", "moodle_url", "(", "'/lib/javascript.php'", ",", "array", "(", "'rev'", "=>", "$", "jsrev", ",", "'jsfile'", "=>", "$", "url", ")", ")", ";", "}", "else", "{", "$", "returnurl", "=", "new", "moodle_url", "(", "'/lib/javascript.php'", ")", ";", "$", "returnurl", "->", "set_slashargument", "(", "'/'", ".", "$", "jsrev", ".", "$", "url", ")", ";", "return", "$", "returnurl", ";", "}", "}", "else", "{", "return", "new", "moodle_url", "(", "$", "url", ")", ";", "}", "}", "else", "{", "throw", "new", "coding_exception", "(", "'Invalid JS url, it has to be shortened url starting with / or moodle_url instance.'", ",", "$", "url", ")", ";", "}", "}" ]
Returns the actual url through which a script is served. @param moodle_url|string $url full moodle url, or shortened path to script @return moodle_url
[ "Returns", "the", "actual", "url", "through", "which", "a", "script", "is", "served", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L687-L720
217,916
moodle/moodle
lib/outputrequirementslib.php
page_requirements_manager.js_module_loaded
protected function js_module_loaded($module) { if (is_string($module)) { $modulename = $module; } else { $modulename = $module['name']; } return array_key_exists($modulename, $this->YUI_config->modules) || array_key_exists($modulename, $this->extramodules); }
php
protected function js_module_loaded($module) { if (is_string($module)) { $modulename = $module; } else { $modulename = $module['name']; } return array_key_exists($modulename, $this->YUI_config->modules) || array_key_exists($modulename, $this->extramodules); }
[ "protected", "function", "js_module_loaded", "(", "$", "module", ")", "{", "if", "(", "is_string", "(", "$", "module", ")", ")", "{", "$", "modulename", "=", "$", "module", ";", "}", "else", "{", "$", "modulename", "=", "$", "module", "[", "'name'", "]", ";", "}", "return", "array_key_exists", "(", "$", "modulename", ",", "$", "this", "->", "YUI_config", "->", "modules", ")", "||", "array_key_exists", "(", "$", "modulename", ",", "$", "this", "->", "extramodules", ")", ";", "}" ]
Returns true if the module has already been loaded. @param string|array $module @return bool True if the module has already been loaded
[ "Returns", "true", "if", "the", "module", "has", "already", "been", "loaded", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L875-L883
217,917
moodle/moodle
lib/outputrequirementslib.php
page_requirements_manager.css
public function css($stylesheet) { global $CFG; if ($this->headdone) { throw new coding_exception('Cannot require a CSS file after &lt;head> has been printed.', $stylesheet); } if ($stylesheet instanceof moodle_url) { // ok } else if (strpos($stylesheet, '/') === 0) { $stylesheet = new moodle_url($stylesheet); } else { throw new coding_exception('Invalid stylesheet parameter.', $stylesheet); } $this->cssurls[$stylesheet->out()] = $stylesheet; }
php
public function css($stylesheet) { global $CFG; if ($this->headdone) { throw new coding_exception('Cannot require a CSS file after &lt;head> has been printed.', $stylesheet); } if ($stylesheet instanceof moodle_url) { // ok } else if (strpos($stylesheet, '/') === 0) { $stylesheet = new moodle_url($stylesheet); } else { throw new coding_exception('Invalid stylesheet parameter.', $stylesheet); } $this->cssurls[$stylesheet->out()] = $stylesheet; }
[ "public", "function", "css", "(", "$", "stylesheet", ")", "{", "global", "$", "CFG", ";", "if", "(", "$", "this", "->", "headdone", ")", "{", "throw", "new", "coding_exception", "(", "'Cannot require a CSS file after &lt;head> has been printed.'", ",", "$", "stylesheet", ")", ";", "}", "if", "(", "$", "stylesheet", "instanceof", "moodle_url", ")", "{", "// ok", "}", "else", "if", "(", "strpos", "(", "$", "stylesheet", ",", "'/'", ")", "===", "0", ")", "{", "$", "stylesheet", "=", "new", "moodle_url", "(", "$", "stylesheet", ")", ";", "}", "else", "{", "throw", "new", "coding_exception", "(", "'Invalid stylesheet parameter.'", ",", "$", "stylesheet", ")", ";", "}", "$", "this", "->", "cssurls", "[", "$", "stylesheet", "->", "out", "(", ")", "]", "=", "$", "stylesheet", ";", "}" ]
Ensure that the specified CSS file is linked to from this page. Because stylesheet links must go in the <head> part of the HTML, you must call this function before {@link get_head_code()} is called. That normally means before the call to print_header. If you call it when it is too late, an exception will be thrown. Even if a particular style sheet is requested more than once, it will only be linked to once. Please note use of this feature is strongly discouraged, it is suitable only for places where CSS is submitted directly by teachers. (Students must not be allowed to submit any external CSS because it may contain embedded javascript!). Example of correct use is mod/data. @param string $stylesheet The path to the .css file, relative to $CFG->wwwroot. For example: $PAGE->requires->css('mod/data/css.php?d='.$data->id);
[ "Ensure", "that", "the", "specified", "CSS", "file", "is", "linked", "to", "from", "this", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L905-L921
217,918
moodle/moodle
lib/outputrequirementslib.php
page_requirements_manager.js_call_amd
public function js_call_amd($fullmodule, $func = null, $params = array()) { global $CFG; list($component, $module) = explode('/', $fullmodule, 2); $component = clean_param($component, PARAM_COMPONENT); $module = clean_param($module, PARAM_ALPHANUMEXT); if ($func !== null) { $func = clean_param($func, PARAM_ALPHANUMEXT); $jsonparams = array(); foreach ($params as $param) { $jsonparams[] = json_encode($param); } $strparams = implode(', ', $jsonparams); if ($CFG->debugdeveloper) { $toomanyparamslimit = 1024; if (strlen($strparams) > $toomanyparamslimit) { debugging('Too much data passed as arguments to js_call_amd("' . $fullmodule . '", "' . $func . '"). Generally there are better ways to pass lots of data from PHP to JavaScript, for example via Ajax, ' . 'data attributes, ... . This warning is triggered if the argument string becomes longer than ' . $toomanyparamslimit . ' characters.', DEBUG_DEVELOPER); } } $js = 'require(["' . $component . '/' . $module . '"], function(amd) { amd.' . $func . '(' . $strparams . '); });'; } else { $js = 'require(["' . $component . '/' . $module . '"]);'; } $this->js_amd_inline($js); }
php
public function js_call_amd($fullmodule, $func = null, $params = array()) { global $CFG; list($component, $module) = explode('/', $fullmodule, 2); $component = clean_param($component, PARAM_COMPONENT); $module = clean_param($module, PARAM_ALPHANUMEXT); if ($func !== null) { $func = clean_param($func, PARAM_ALPHANUMEXT); $jsonparams = array(); foreach ($params as $param) { $jsonparams[] = json_encode($param); } $strparams = implode(', ', $jsonparams); if ($CFG->debugdeveloper) { $toomanyparamslimit = 1024; if (strlen($strparams) > $toomanyparamslimit) { debugging('Too much data passed as arguments to js_call_amd("' . $fullmodule . '", "' . $func . '"). Generally there are better ways to pass lots of data from PHP to JavaScript, for example via Ajax, ' . 'data attributes, ... . This warning is triggered if the argument string becomes longer than ' . $toomanyparamslimit . ' characters.', DEBUG_DEVELOPER); } } $js = 'require(["' . $component . '/' . $module . '"], function(amd) { amd.' . $func . '(' . $strparams . '); });'; } else { $js = 'require(["' . $component . '/' . $module . '"]);'; } $this->js_amd_inline($js); }
[ "public", "function", "js_call_amd", "(", "$", "fullmodule", ",", "$", "func", "=", "null", ",", "$", "params", "=", "array", "(", ")", ")", "{", "global", "$", "CFG", ";", "list", "(", "$", "component", ",", "$", "module", ")", "=", "explode", "(", "'/'", ",", "$", "fullmodule", ",", "2", ")", ";", "$", "component", "=", "clean_param", "(", "$", "component", ",", "PARAM_COMPONENT", ")", ";", "$", "module", "=", "clean_param", "(", "$", "module", ",", "PARAM_ALPHANUMEXT", ")", ";", "if", "(", "$", "func", "!==", "null", ")", "{", "$", "func", "=", "clean_param", "(", "$", "func", ",", "PARAM_ALPHANUMEXT", ")", ";", "$", "jsonparams", "=", "array", "(", ")", ";", "foreach", "(", "$", "params", "as", "$", "param", ")", "{", "$", "jsonparams", "[", "]", "=", "json_encode", "(", "$", "param", ")", ";", "}", "$", "strparams", "=", "implode", "(", "', '", ",", "$", "jsonparams", ")", ";", "if", "(", "$", "CFG", "->", "debugdeveloper", ")", "{", "$", "toomanyparamslimit", "=", "1024", ";", "if", "(", "strlen", "(", "$", "strparams", ")", ">", "$", "toomanyparamslimit", ")", "{", "debugging", "(", "'Too much data passed as arguments to js_call_amd(\"'", ".", "$", "fullmodule", ".", "'\", \"'", ".", "$", "func", ".", "'\"). Generally there are better ways to pass lots of data from PHP to JavaScript, for example via Ajax, '", ".", "'data attributes, ... . This warning is triggered if the argument string becomes longer than '", ".", "$", "toomanyparamslimit", ".", "' characters.'", ",", "DEBUG_DEVELOPER", ")", ";", "}", "}", "$", "js", "=", "'require([\"'", ".", "$", "component", ".", "'/'", ".", "$", "module", ".", "'\"], function(amd) { amd.'", ".", "$", "func", ".", "'('", ".", "$", "strparams", ".", "'); });'", ";", "}", "else", "{", "$", "js", "=", "'require([\"'", ".", "$", "component", ".", "'/'", ".", "$", "module", ".", "'\"]);'", ";", "}", "$", "this", "->", "js_amd_inline", "(", "$", "js", ")", ";", "}" ]
Load an AMD module and eventually call its method. This function creates a minimal inline JS snippet that requires an AMD module and eventually calls a single function from the module with given arguments. If it is called multiple times, it will be create multiple snippets. @param string $fullmodule The name of the AMD module to load, formatted as <component name>/<module name>. @param string $func Optional function from the module to call, defaults to just loading the AMD module. @param array $params The params to pass to the function (will be serialized into JSON).
[ "Load", "an", "AMD", "module", "and", "eventually", "call", "its", "method", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L1012-L1045
217,919
moodle/moodle
lib/outputrequirementslib.php
page_requirements_manager.yui_module
public function yui_module($modules, $function, array $arguments = null, $galleryversion = null, $ondomready = false) { if (!is_array($modules)) { $modules = array($modules); } if ($galleryversion != null) { debugging('The galleryversion parameter to yui_module has been deprecated since Moodle 2.3.'); } $jscode = 'Y.use('.join(',', array_map('json_encode', convert_to_array($modules))).',function() {'.js_writer::function_call($function, $arguments).'});'; if ($ondomready) { $jscode = "Y.on('domready', function() { $jscode });"; } $this->jsinitcode[] = $jscode; }
php
public function yui_module($modules, $function, array $arguments = null, $galleryversion = null, $ondomready = false) { if (!is_array($modules)) { $modules = array($modules); } if ($galleryversion != null) { debugging('The galleryversion parameter to yui_module has been deprecated since Moodle 2.3.'); } $jscode = 'Y.use('.join(',', array_map('json_encode', convert_to_array($modules))).',function() {'.js_writer::function_call($function, $arguments).'});'; if ($ondomready) { $jscode = "Y.on('domready', function() { $jscode });"; } $this->jsinitcode[] = $jscode; }
[ "public", "function", "yui_module", "(", "$", "modules", ",", "$", "function", ",", "array", "$", "arguments", "=", "null", ",", "$", "galleryversion", "=", "null", ",", "$", "ondomready", "=", "false", ")", "{", "if", "(", "!", "is_array", "(", "$", "modules", ")", ")", "{", "$", "modules", "=", "array", "(", "$", "modules", ")", ";", "}", "if", "(", "$", "galleryversion", "!=", "null", ")", "{", "debugging", "(", "'The galleryversion parameter to yui_module has been deprecated since Moodle 2.3.'", ")", ";", "}", "$", "jscode", "=", "'Y.use('", ".", "join", "(", "','", ",", "array_map", "(", "'json_encode'", ",", "convert_to_array", "(", "$", "modules", ")", ")", ")", ".", "',function() {'", ".", "js_writer", "::", "function_call", "(", "$", "function", ",", "$", "arguments", ")", ".", "'});'", ";", "if", "(", "$", "ondomready", ")", "{", "$", "jscode", "=", "\"Y.on('domready', function() { $jscode });\"", ";", "}", "$", "this", "->", "jsinitcode", "[", "]", "=", "$", "jscode", ";", "}" ]
Creates a JavaScript function call that requires one or more modules to be loaded. This function can be used to include all of the standard YUI module types within JavaScript: - YUI3 modules [node, event, io] - YUI2 modules [yui2-*] - Moodle modules [moodle-*] - Gallery modules [gallery-*] Before writing new code that makes extensive use of YUI, you should consider it's replacement AMD/JQuery. @see js_call_amd() @param array|string $modules One or more modules @param string $function The function to call once modules have been loaded @param array $arguments An array of arguments to pass to the function @param string $galleryversion Deprecated: The gallery version to use @param bool $ondomready
[ "Creates", "a", "JavaScript", "function", "call", "that", "requires", "one", "or", "more", "modules", "to", "be", "loaded", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L1065-L1079
217,920
moodle/moodle
lib/outputrequirementslib.php
page_requirements_manager.js_init_call
public function js_init_call($function, array $extraarguments = null, $ondomready = false, array $module = null) { $jscode = js_writer::function_call_with_Y($function, $extraarguments); if (!$module) { // Detect module automatically. if (preg_match('/M\.([a-z0-9]+_[^\.]+)/', $function, $matches)) { $module = $this->find_module($matches[1]); } } $this->js_init_code($jscode, $ondomready, $module); }
php
public function js_init_call($function, array $extraarguments = null, $ondomready = false, array $module = null) { $jscode = js_writer::function_call_with_Y($function, $extraarguments); if (!$module) { // Detect module automatically. if (preg_match('/M\.([a-z0-9]+_[^\.]+)/', $function, $matches)) { $module = $this->find_module($matches[1]); } } $this->js_init_code($jscode, $ondomready, $module); }
[ "public", "function", "js_init_call", "(", "$", "function", ",", "array", "$", "extraarguments", "=", "null", ",", "$", "ondomready", "=", "false", ",", "array", "$", "module", "=", "null", ")", "{", "$", "jscode", "=", "js_writer", "::", "function_call_with_Y", "(", "$", "function", ",", "$", "extraarguments", ")", ";", "if", "(", "!", "$", "module", ")", "{", "// Detect module automatically.", "if", "(", "preg_match", "(", "'/M\\.([a-z0-9]+_[^\\.]+)/'", ",", "$", "function", ",", "$", "matches", ")", ")", "{", "$", "module", "=", "$", "this", "->", "find_module", "(", "$", "matches", "[", "1", "]", ")", ";", "}", "}", "$", "this", "->", "js_init_code", "(", "$", "jscode", ",", "$", "ondomready", ",", "$", "module", ")", ";", "}" ]
Ensure that the specified JavaScript function is called from an inline script from page footer. @param string $function the name of the JavaScritp function to with init code, usually something like 'M.mod_mymodule.init' @param array $extraarguments and array of arguments to be passed to the function. The first argument is always the YUI3 Y instance with all required dependencies already loaded. @param bool $ondomready wait for dom ready (helps with some IE problems when modifying DOM) @param array $module JS module specification array
[ "Ensure", "that", "the", "specified", "JavaScript", "function", "is", "called", "from", "an", "inline", "script", "from", "page", "footer", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L1102-L1112
217,921
moodle/moodle
lib/outputrequirementslib.php
page_requirements_manager.js_init_code
public function js_init_code($jscode, $ondomready = false, array $module = null) { $jscode = trim($jscode, " ;\n"). ';'; $uniqid = html_writer::random_id(); $startjs = " M.util.js_pending('" . $uniqid . "');"; $endjs = " M.util.js_complete('" . $uniqid . "');"; if ($module) { $this->js_module($module); $modulename = $module['name']; $jscode = "$startjs Y.use('$modulename', function(Y) { $jscode $endjs });"; } if ($ondomready) { $jscode = "$startjs Y.on('domready', function() { $jscode $endjs });"; } $this->jsinitcode[] = $jscode; }
php
public function js_init_code($jscode, $ondomready = false, array $module = null) { $jscode = trim($jscode, " ;\n"). ';'; $uniqid = html_writer::random_id(); $startjs = " M.util.js_pending('" . $uniqid . "');"; $endjs = " M.util.js_complete('" . $uniqid . "');"; if ($module) { $this->js_module($module); $modulename = $module['name']; $jscode = "$startjs Y.use('$modulename', function(Y) { $jscode $endjs });"; } if ($ondomready) { $jscode = "$startjs Y.on('domready', function() { $jscode $endjs });"; } $this->jsinitcode[] = $jscode; }
[ "public", "function", "js_init_code", "(", "$", "jscode", ",", "$", "ondomready", "=", "false", ",", "array", "$", "module", "=", "null", ")", "{", "$", "jscode", "=", "trim", "(", "$", "jscode", ",", "\" ;\\n\"", ")", ".", "';'", ";", "$", "uniqid", "=", "html_writer", "::", "random_id", "(", ")", ";", "$", "startjs", "=", "\" M.util.js_pending('\"", ".", "$", "uniqid", ".", "\"');\"", ";", "$", "endjs", "=", "\" M.util.js_complete('\"", ".", "$", "uniqid", ".", "\"');\"", ";", "if", "(", "$", "module", ")", "{", "$", "this", "->", "js_module", "(", "$", "module", ")", ";", "$", "modulename", "=", "$", "module", "[", "'name'", "]", ";", "$", "jscode", "=", "\"$startjs Y.use('$modulename', function(Y) { $jscode $endjs });\"", ";", "}", "if", "(", "$", "ondomready", ")", "{", "$", "jscode", "=", "\"$startjs Y.on('domready', function() { $jscode $endjs });\"", ";", "}", "$", "this", "->", "jsinitcode", "[", "]", "=", "$", "jscode", ";", "}" ]
Add short static javascript code fragment to page footer. This is intended primarily for loading of js modules and initialising page layout. Ideally the JS code fragment should be stored in plugin renderer so that themes may override it. @param string $jscode @param bool $ondomready wait for dom ready (helps with some IE problems when modifying DOM) @param array $module JS module specification array
[ "Add", "short", "static", "javascript", "code", "fragment", "to", "page", "footer", ".", "This", "is", "intended", "primarily", "for", "loading", "of", "js", "modules", "and", "initialising", "page", "layout", ".", "Ideally", "the", "JS", "code", "fragment", "should", "be", "stored", "in", "plugin", "renderer", "so", "that", "themes", "may", "override", "it", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L1124-L1142
217,922
moodle/moodle
lib/outputrequirementslib.php
page_requirements_manager.string_for_js
public function string_for_js($identifier, $component, $a = null) { if (!$component) { throw new coding_exception('The $component parameter is required for page_requirements_manager::string_for_js().'); } if (isset($this->stringsforjs_as[$component][$identifier]) and $this->stringsforjs_as[$component][$identifier] !== $a) { throw new coding_exception("Attempt to re-define already required string '$identifier' " . "from lang file '$component' with different \$a parameter?"); } if (!isset($this->stringsforjs[$component][$identifier])) { $this->stringsforjs[$component][$identifier] = new lang_string($identifier, $component, $a); $this->stringsforjs_as[$component][$identifier] = $a; } }
php
public function string_for_js($identifier, $component, $a = null) { if (!$component) { throw new coding_exception('The $component parameter is required for page_requirements_manager::string_for_js().'); } if (isset($this->stringsforjs_as[$component][$identifier]) and $this->stringsforjs_as[$component][$identifier] !== $a) { throw new coding_exception("Attempt to re-define already required string '$identifier' " . "from lang file '$component' with different \$a parameter?"); } if (!isset($this->stringsforjs[$component][$identifier])) { $this->stringsforjs[$component][$identifier] = new lang_string($identifier, $component, $a); $this->stringsforjs_as[$component][$identifier] = $a; } }
[ "public", "function", "string_for_js", "(", "$", "identifier", ",", "$", "component", ",", "$", "a", "=", "null", ")", "{", "if", "(", "!", "$", "component", ")", "{", "throw", "new", "coding_exception", "(", "'The $component parameter is required for page_requirements_manager::string_for_js().'", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "stringsforjs_as", "[", "$", "component", "]", "[", "$", "identifier", "]", ")", "and", "$", "this", "->", "stringsforjs_as", "[", "$", "component", "]", "[", "$", "identifier", "]", "!==", "$", "a", ")", "{", "throw", "new", "coding_exception", "(", "\"Attempt to re-define already required string '$identifier' \"", ".", "\"from lang file '$component' with different \\$a parameter?\"", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "stringsforjs", "[", "$", "component", "]", "[", "$", "identifier", "]", ")", ")", "{", "$", "this", "->", "stringsforjs", "[", "$", "component", "]", "[", "$", "identifier", "]", "=", "new", "lang_string", "(", "$", "identifier", ",", "$", "component", ",", "$", "a", ")", ";", "$", "this", "->", "stringsforjs_as", "[", "$", "component", "]", "[", "$", "identifier", "]", "=", "$", "a", ";", "}", "}" ]
Make a language string available to JavaScript. All the strings will be available in a M.str object in the global namespace. So, for example, after a call to $PAGE->requires->string_for_js('course', 'moodle'); then the JavaScript variable M.str.moodle.course will be 'Course', or the equivalent in the current language. The arguments to this function are just like the arguments to get_string except that $component is not optional, and there are some aspects to consider when the string contains {$a} placeholder. If the string does not contain any {$a} placeholder, you can simply use M.str.component.identifier to obtain it. If you prefer, you can call M.util.get_string(identifier, component) to get the same result. If you need to use {$a} placeholders, there are two options. Either the placeholder should be substituted in PHP on server side or it should be substituted in Javascript at client side. To substitute the placeholder at server side, just provide the required value for the placeholder when you require the string. Because each string is only stored once in the JavaScript (based on $identifier and $module) you cannot get the same string with two different values of $a. If you try, an exception will be thrown. Once the placeholder is substituted, you can use M.str or M.util.get_string() as shown above: // Require the string in PHP and replace the placeholder. $PAGE->requires->string_for_js('fullnamedisplay', 'moodle', $USER); // Use the result of the substitution in Javascript. alert(M.str.moodle.fullnamedisplay); To substitute the placeholder at client side, use M.util.get_string() function. It implements the same logic as {@link get_string()}: // Require the string in PHP but keep {$a} as it is. $PAGE->requires->string_for_js('fullnamedisplay', 'moodle'); // Provide the values on the fly in Javascript. user = { firstname : 'Harry', lastname : 'Potter' } alert(M.util.get_string('fullnamedisplay', 'moodle', user); If you do need the same string expanded with different $a values in PHP on server side, then the solution is to put them in your own data structure (e.g. and array) that you pass to JavaScript with {@link data_for_js()}. @param string $identifier the desired string. @param string $component the language file to look in. @param mixed $a any extra data to add into the string (optional).
[ "Make", "a", "language", "string", "available", "to", "JavaScript", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L1193-L1205
217,923
moodle/moodle
lib/outputrequirementslib.php
page_requirements_manager.strings_for_js
public function strings_for_js($identifiers, $component, $a = null) { foreach ($identifiers as $key => $identifier) { if (is_array($a) && array_key_exists($key, $a)) { $extra = $a[$key]; } else { $extra = $a; } $this->string_for_js($identifier, $component, $extra); } }
php
public function strings_for_js($identifiers, $component, $a = null) { foreach ($identifiers as $key => $identifier) { if (is_array($a) && array_key_exists($key, $a)) { $extra = $a[$key]; } else { $extra = $a; } $this->string_for_js($identifier, $component, $extra); } }
[ "public", "function", "strings_for_js", "(", "$", "identifiers", ",", "$", "component", ",", "$", "a", "=", "null", ")", "{", "foreach", "(", "$", "identifiers", "as", "$", "key", "=>", "$", "identifier", ")", "{", "if", "(", "is_array", "(", "$", "a", ")", "&&", "array_key_exists", "(", "$", "key", ",", "$", "a", ")", ")", "{", "$", "extra", "=", "$", "a", "[", "$", "key", "]", ";", "}", "else", "{", "$", "extra", "=", "$", "a", ";", "}", "$", "this", "->", "string_for_js", "(", "$", "identifier", ",", "$", "component", ",", "$", "extra", ")", ";", "}", "}" ]
Make an array of language strings available for JS. This function calls the above function {@link string_for_js()} for each requested string in the $identifiers array that is passed to the argument for a single module passed in $module. <code> $PAGE->requires->strings_for_js(array('one', 'two', 'three'), 'mymod', array('a', null, 3)); // The above is identical to calling: $PAGE->requires->string_for_js('one', 'mymod', 'a'); $PAGE->requires->string_for_js('two', 'mymod'); $PAGE->requires->string_for_js('three', 'mymod', 3); </code> @param array $identifiers An array of desired strings @param string $component The module to load for @param mixed $a This can either be a single variable that gets passed as extra information for every string or it can be an array of mixed data where the key for the data matches that of the identifier it is meant for.
[ "Make", "an", "array", "of", "language", "strings", "available", "for", "JS", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L1231-L1240
217,924
moodle/moodle
lib/outputrequirementslib.php
page_requirements_manager.event_handler
public function event_handler($selector, $event, $function, array $arguments = null) { $this->eventhandlers[] = array('selector'=>$selector, 'event'=>$event, 'function'=>$function, 'arguments'=>$arguments); }
php
public function event_handler($selector, $event, $function, array $arguments = null) { $this->eventhandlers[] = array('selector'=>$selector, 'event'=>$event, 'function'=>$function, 'arguments'=>$arguments); }
[ "public", "function", "event_handler", "(", "$", "selector", ",", "$", "event", ",", "$", "function", ",", "array", "$", "arguments", "=", "null", ")", "{", "$", "this", "->", "eventhandlers", "[", "]", "=", "array", "(", "'selector'", "=>", "$", "selector", ",", "'event'", "=>", "$", "event", ",", "'function'", "=>", "$", "function", ",", "'arguments'", "=>", "$", "arguments", ")", ";", "}" ]
Creates a YUI event handler. @param mixed $selector standard YUI selector for elements, may be array or string, element id is in the form "#idvalue" @param string $event A valid DOM event (click, mousedown, change etc.) @param string $function The name of the function to call @param array $arguments An optional array of argument parameters to pass to the function
[ "Creates", "a", "YUI", "event", "handler", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L1275-L1277
217,925
moodle/moodle
lib/outputrequirementslib.php
page_requirements_manager.get_event_handler_code
protected function get_event_handler_code() { $output = ''; foreach ($this->eventhandlers as $h) { $output .= js_writer::event_handler($h['selector'], $h['event'], $h['function'], $h['arguments']); } return $output; }
php
protected function get_event_handler_code() { $output = ''; foreach ($this->eventhandlers as $h) { $output .= js_writer::event_handler($h['selector'], $h['event'], $h['function'], $h['arguments']); } return $output; }
[ "protected", "function", "get_event_handler_code", "(", ")", "{", "$", "output", "=", "''", ";", "foreach", "(", "$", "this", "->", "eventhandlers", "as", "$", "h", ")", "{", "$", "output", ".=", "js_writer", "::", "event_handler", "(", "$", "h", "[", "'selector'", "]", ",", "$", "h", "[", "'event'", "]", ",", "$", "h", "[", "'function'", "]", ",", "$", "h", "[", "'arguments'", "]", ")", ";", "}", "return", "$", "output", ";", "}" ]
Returns code needed for registering of event handlers. @return string JS code
[ "Returns", "code", "needed", "for", "registering", "of", "event", "handlers", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L1283-L1289
217,926
moodle/moodle
lib/outputrequirementslib.php
page_requirements_manager.get_javascript_code
protected function get_javascript_code($ondomready) { $where = $ondomready ? 'ondomready' : 'normal'; $output = ''; if ($this->jscalls[$where]) { foreach ($this->jscalls[$where] as $data) { $output .= js_writer::function_call($data[0], $data[1], $data[2]); } if (!empty($ondomready)) { $output = " Y.on('domready', function() {\n$output\n});"; } } return $output; }
php
protected function get_javascript_code($ondomready) { $where = $ondomready ? 'ondomready' : 'normal'; $output = ''; if ($this->jscalls[$where]) { foreach ($this->jscalls[$where] as $data) { $output .= js_writer::function_call($data[0], $data[1], $data[2]); } if (!empty($ondomready)) { $output = " Y.on('domready', function() {\n$output\n});"; } } return $output; }
[ "protected", "function", "get_javascript_code", "(", "$", "ondomready", ")", "{", "$", "where", "=", "$", "ondomready", "?", "'ondomready'", ":", "'normal'", ";", "$", "output", "=", "''", ";", "if", "(", "$", "this", "->", "jscalls", "[", "$", "where", "]", ")", "{", "foreach", "(", "$", "this", "->", "jscalls", "[", "$", "where", "]", "as", "$", "data", ")", "{", "$", "output", ".=", "js_writer", "::", "function_call", "(", "$", "data", "[", "0", "]", ",", "$", "data", "[", "1", "]", ",", "$", "data", "[", "2", "]", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "ondomready", ")", ")", "{", "$", "output", "=", "\" Y.on('domready', function() {\\n$output\\n});\"", ";", "}", "}", "return", "$", "output", ";", "}" ]
Get the inline JavaScript code that need to appear in a particular place. @param bool $ondomready @return string
[ "Get", "the", "inline", "JavaScript", "code", "that", "need", "to", "appear", "in", "a", "particular", "place", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L1296-L1308
217,927
moodle/moodle
lib/outputrequirementslib.php
page_requirements_manager.get_yui3lib_headcss
protected function get_yui3lib_headcss() { global $CFG; $yuiformat = '-min'; if ($this->yui3loader->filter === 'RAW') { $yuiformat = ''; } $code = ''; if ($this->yui3loader->combine) { if (!empty($this->yuicssmodules)) { $modules = array(); foreach ($this->yuicssmodules as $module) { $modules[] = "$CFG->yui3version/$module/$module-min.css"; } $code .= '<link rel="stylesheet" type="text/css" href="'.$this->yui3loader->comboBase.implode('&amp;', $modules).'" />'; } $code .= '<link rel="stylesheet" type="text/css" href="'.$this->yui3loader->local_comboBase.'rollup/'.$CFG->yui3version.'/yui-moodlesimple' . $yuiformat . '.css" />'; } else { if (!empty($this->yuicssmodules)) { foreach ($this->yuicssmodules as $module) { $code .= '<link rel="stylesheet" type="text/css" href="'.$this->yui3loader->base.$module.'/'.$module.'-min.css" />'; } } $code .= '<link rel="stylesheet" type="text/css" href="'.$this->yui3loader->local_comboBase.'rollup/'.$CFG->yui3version.'/yui-moodlesimple' . $yuiformat . '.css" />'; } if ($this->yui3loader->filter === 'RAW') { $code = str_replace('-min.css', '.css', $code); } else if ($this->yui3loader->filter === 'DEBUG') { $code = str_replace('-min.css', '.css', $code); } return $code; }
php
protected function get_yui3lib_headcss() { global $CFG; $yuiformat = '-min'; if ($this->yui3loader->filter === 'RAW') { $yuiformat = ''; } $code = ''; if ($this->yui3loader->combine) { if (!empty($this->yuicssmodules)) { $modules = array(); foreach ($this->yuicssmodules as $module) { $modules[] = "$CFG->yui3version/$module/$module-min.css"; } $code .= '<link rel="stylesheet" type="text/css" href="'.$this->yui3loader->comboBase.implode('&amp;', $modules).'" />'; } $code .= '<link rel="stylesheet" type="text/css" href="'.$this->yui3loader->local_comboBase.'rollup/'.$CFG->yui3version.'/yui-moodlesimple' . $yuiformat . '.css" />'; } else { if (!empty($this->yuicssmodules)) { foreach ($this->yuicssmodules as $module) { $code .= '<link rel="stylesheet" type="text/css" href="'.$this->yui3loader->base.$module.'/'.$module.'-min.css" />'; } } $code .= '<link rel="stylesheet" type="text/css" href="'.$this->yui3loader->local_comboBase.'rollup/'.$CFG->yui3version.'/yui-moodlesimple' . $yuiformat . '.css" />'; } if ($this->yui3loader->filter === 'RAW') { $code = str_replace('-min.css', '.css', $code); } else if ($this->yui3loader->filter === 'DEBUG') { $code = str_replace('-min.css', '.css', $code); } return $code; }
[ "protected", "function", "get_yui3lib_headcss", "(", ")", "{", "global", "$", "CFG", ";", "$", "yuiformat", "=", "'-min'", ";", "if", "(", "$", "this", "->", "yui3loader", "->", "filter", "===", "'RAW'", ")", "{", "$", "yuiformat", "=", "''", ";", "}", "$", "code", "=", "''", ";", "if", "(", "$", "this", "->", "yui3loader", "->", "combine", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "yuicssmodules", ")", ")", "{", "$", "modules", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "yuicssmodules", "as", "$", "module", ")", "{", "$", "modules", "[", "]", "=", "\"$CFG->yui3version/$module/$module-min.css\"", ";", "}", "$", "code", ".=", "'<link rel=\"stylesheet\" type=\"text/css\" href=\"'", ".", "$", "this", "->", "yui3loader", "->", "comboBase", ".", "implode", "(", "'&amp;'", ",", "$", "modules", ")", ".", "'\" />'", ";", "}", "$", "code", ".=", "'<link rel=\"stylesheet\" type=\"text/css\" href=\"'", ".", "$", "this", "->", "yui3loader", "->", "local_comboBase", ".", "'rollup/'", ".", "$", "CFG", "->", "yui3version", ".", "'/yui-moodlesimple'", ".", "$", "yuiformat", ".", "'.css\" />'", ";", "}", "else", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "yuicssmodules", ")", ")", "{", "foreach", "(", "$", "this", "->", "yuicssmodules", "as", "$", "module", ")", "{", "$", "code", ".=", "'<link rel=\"stylesheet\" type=\"text/css\" href=\"'", ".", "$", "this", "->", "yui3loader", "->", "base", ".", "$", "module", ".", "'/'", ".", "$", "module", ".", "'-min.css\" />'", ";", "}", "}", "$", "code", ".=", "'<link rel=\"stylesheet\" type=\"text/css\" href=\"'", ".", "$", "this", "->", "yui3loader", "->", "local_comboBase", ".", "'rollup/'", ".", "$", "CFG", "->", "yui3version", ".", "'/yui-moodlesimple'", ".", "$", "yuiformat", ".", "'.css\" />'", ";", "}", "if", "(", "$", "this", "->", "yui3loader", "->", "filter", "===", "'RAW'", ")", "{", "$", "code", "=", "str_replace", "(", "'-min.css'", ",", "'.css'", ",", "$", "code", ")", ";", "}", "else", "if", "(", "$", "this", "->", "yui3loader", "->", "filter", "===", "'DEBUG'", ")", "{", "$", "code", "=", "str_replace", "(", "'-min.css'", ",", "'.css'", ",", "$", "code", ")", ";", "}", "return", "$", "code", ";", "}" ]
Returns basic YUI3 CSS code. @return string
[ "Returns", "basic", "YUI3", "CSS", "code", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L1376-L1410
217,928
moodle/moodle
lib/outputrequirementslib.php
page_requirements_manager.get_yui3lib_headcode
protected function get_yui3lib_headcode() { global $CFG; $jsrev = $this->get_jsrev(); $yuiformat = '-min'; if ($this->yui3loader->filter === 'RAW') { $yuiformat = ''; } $format = '-min'; if ($this->YUI_config->groups['moodle']['filter'] === 'DEBUG') { $format = '-debug'; } $rollupversion = $CFG->yui3version; if (!empty($CFG->yuipatchlevel)) { $rollupversion .= '_' . $CFG->yuipatchlevel; } $baserollups = array( 'rollup/' . $rollupversion . "/yui-moodlesimple{$yuiformat}.js", ); if ($this->yui3loader->combine) { return '<script type="text/javascript" src="' . $this->yui3loader->local_comboBase . implode('&amp;', $baserollups) . '"></script>'; } else { $code = ''; foreach ($baserollups as $rollup) { $code .= '<script type="text/javascript" src="'.$this->yui3loader->local_comboBase.$rollup.'"></script>'; } return $code; } }
php
protected function get_yui3lib_headcode() { global $CFG; $jsrev = $this->get_jsrev(); $yuiformat = '-min'; if ($this->yui3loader->filter === 'RAW') { $yuiformat = ''; } $format = '-min'; if ($this->YUI_config->groups['moodle']['filter'] === 'DEBUG') { $format = '-debug'; } $rollupversion = $CFG->yui3version; if (!empty($CFG->yuipatchlevel)) { $rollupversion .= '_' . $CFG->yuipatchlevel; } $baserollups = array( 'rollup/' . $rollupversion . "/yui-moodlesimple{$yuiformat}.js", ); if ($this->yui3loader->combine) { return '<script type="text/javascript" src="' . $this->yui3loader->local_comboBase . implode('&amp;', $baserollups) . '"></script>'; } else { $code = ''; foreach ($baserollups as $rollup) { $code .= '<script type="text/javascript" src="'.$this->yui3loader->local_comboBase.$rollup.'"></script>'; } return $code; } }
[ "protected", "function", "get_yui3lib_headcode", "(", ")", "{", "global", "$", "CFG", ";", "$", "jsrev", "=", "$", "this", "->", "get_jsrev", "(", ")", ";", "$", "yuiformat", "=", "'-min'", ";", "if", "(", "$", "this", "->", "yui3loader", "->", "filter", "===", "'RAW'", ")", "{", "$", "yuiformat", "=", "''", ";", "}", "$", "format", "=", "'-min'", ";", "if", "(", "$", "this", "->", "YUI_config", "->", "groups", "[", "'moodle'", "]", "[", "'filter'", "]", "===", "'DEBUG'", ")", "{", "$", "format", "=", "'-debug'", ";", "}", "$", "rollupversion", "=", "$", "CFG", "->", "yui3version", ";", "if", "(", "!", "empty", "(", "$", "CFG", "->", "yuipatchlevel", ")", ")", "{", "$", "rollupversion", ".=", "'_'", ".", "$", "CFG", "->", "yuipatchlevel", ";", "}", "$", "baserollups", "=", "array", "(", "'rollup/'", ".", "$", "rollupversion", ".", "\"/yui-moodlesimple{$yuiformat}.js\"", ",", ")", ";", "if", "(", "$", "this", "->", "yui3loader", "->", "combine", ")", "{", "return", "'<script type=\"text/javascript\" src=\"'", ".", "$", "this", "->", "yui3loader", "->", "local_comboBase", ".", "implode", "(", "'&amp;'", ",", "$", "baserollups", ")", ".", "'\"></script>'", ";", "}", "else", "{", "$", "code", "=", "''", ";", "foreach", "(", "$", "baserollups", "as", "$", "rollup", ")", "{", "$", "code", ".=", "'<script type=\"text/javascript\" src=\"'", ".", "$", "this", "->", "yui3loader", "->", "local_comboBase", ".", "$", "rollup", ".", "'\"></script>'", ";", "}", "return", "$", "code", ";", "}", "}" ]
Returns basic YUI3 JS loading code. @return string
[ "Returns", "basic", "YUI3", "JS", "loading", "code", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L1417-L1454
217,929
moodle/moodle
lib/outputrequirementslib.php
page_requirements_manager.get_css_code
protected function get_css_code() { // First of all the theme CSS, then any custom CSS // Please note custom CSS is strongly discouraged, // because it can not be overridden by themes! // It is suitable only for things like mod/data which accepts CSS from teachers. $attributes = array('rel'=>'stylesheet', 'type'=>'text/css'); // Add the YUI code first. We want this to be overridden by any Moodle CSS. $code = $this->get_yui3lib_headcss(); // This line of code may look funny but it is currently required in order // to avoid MASSIVE display issues in Internet Explorer. // As of IE8 + YUI3.1.1 the reference stylesheet (firstthemesheet) gets // ignored whenever another resource is added until such time as a redraw // is forced, usually by moving the mouse over the affected element. $code .= html_writer::tag('script', '/** Required in order to fix style inclusion problems in IE with YUI **/', array('id'=>'firstthemesheet', 'type'=>'text/css')); $urls = $this->cssthemeurls + $this->cssurls; foreach ($urls as $url) { $attributes['href'] = $url; $code .= html_writer::empty_tag('link', $attributes) . "\n"; // This id is needed in first sheet only so that theme may override YUI sheets loaded on the fly. unset($attributes['id']); } return $code; }
php
protected function get_css_code() { // First of all the theme CSS, then any custom CSS // Please note custom CSS is strongly discouraged, // because it can not be overridden by themes! // It is suitable only for things like mod/data which accepts CSS from teachers. $attributes = array('rel'=>'stylesheet', 'type'=>'text/css'); // Add the YUI code first. We want this to be overridden by any Moodle CSS. $code = $this->get_yui3lib_headcss(); // This line of code may look funny but it is currently required in order // to avoid MASSIVE display issues in Internet Explorer. // As of IE8 + YUI3.1.1 the reference stylesheet (firstthemesheet) gets // ignored whenever another resource is added until such time as a redraw // is forced, usually by moving the mouse over the affected element. $code .= html_writer::tag('script', '/** Required in order to fix style inclusion problems in IE with YUI **/', array('id'=>'firstthemesheet', 'type'=>'text/css')); $urls = $this->cssthemeurls + $this->cssurls; foreach ($urls as $url) { $attributes['href'] = $url; $code .= html_writer::empty_tag('link', $attributes) . "\n"; // This id is needed in first sheet only so that theme may override YUI sheets loaded on the fly. unset($attributes['id']); } return $code; }
[ "protected", "function", "get_css_code", "(", ")", "{", "// First of all the theme CSS, then any custom CSS", "// Please note custom CSS is strongly discouraged,", "// because it can not be overridden by themes!", "// It is suitable only for things like mod/data which accepts CSS from teachers.", "$", "attributes", "=", "array", "(", "'rel'", "=>", "'stylesheet'", ",", "'type'", "=>", "'text/css'", ")", ";", "// Add the YUI code first. We want this to be overridden by any Moodle CSS.", "$", "code", "=", "$", "this", "->", "get_yui3lib_headcss", "(", ")", ";", "// This line of code may look funny but it is currently required in order", "// to avoid MASSIVE display issues in Internet Explorer.", "// As of IE8 + YUI3.1.1 the reference stylesheet (firstthemesheet) gets", "// ignored whenever another resource is added until such time as a redraw", "// is forced, usually by moving the mouse over the affected element.", "$", "code", ".=", "html_writer", "::", "tag", "(", "'script'", ",", "'/** Required in order to fix style inclusion problems in IE with YUI **/'", ",", "array", "(", "'id'", "=>", "'firstthemesheet'", ",", "'type'", "=>", "'text/css'", ")", ")", ";", "$", "urls", "=", "$", "this", "->", "cssthemeurls", "+", "$", "this", "->", "cssurls", ";", "foreach", "(", "$", "urls", "as", "$", "url", ")", "{", "$", "attributes", "[", "'href'", "]", "=", "$", "url", ";", "$", "code", ".=", "html_writer", "::", "empty_tag", "(", "'link'", ",", "$", "attributes", ")", ".", "\"\\n\"", ";", "// This id is needed in first sheet only so that theme may override YUI sheets loaded on the fly.", "unset", "(", "$", "attributes", "[", "'id'", "]", ")", ";", "}", "return", "$", "code", ";", "}" ]
Returns html tags needed for inclusion of theme CSS. @return string
[ "Returns", "html", "tags", "needed", "for", "inclusion", "of", "theme", "CSS", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L1461-L1487
217,930
moodle/moodle
lib/outputrequirementslib.php
page_requirements_manager.get_extra_modules_code
protected function get_extra_modules_code() { if (empty($this->extramodules)) { return ''; } return html_writer::script(js_writer::function_call('M.yui.add_module', array($this->extramodules))); }
php
protected function get_extra_modules_code() { if (empty($this->extramodules)) { return ''; } return html_writer::script(js_writer::function_call('M.yui.add_module', array($this->extramodules))); }
[ "protected", "function", "get_extra_modules_code", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "extramodules", ")", ")", "{", "return", "''", ";", "}", "return", "html_writer", "::", "script", "(", "js_writer", "::", "function_call", "(", "'M.yui.add_module'", ",", "array", "(", "$", "this", "->", "extramodules", ")", ")", ")", ";", "}" ]
Adds extra modules specified after printing of page header. @return string
[ "Adds", "extra", "modules", "specified", "after", "printing", "of", "page", "header", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L1494-L1499
217,931
moodle/moodle
lib/outputrequirementslib.php
page_requirements_manager.get_end_code
public function get_end_code() { global $CFG; $output = ''; // Set the log level for the JS logging. $logconfig = new stdClass(); $logconfig->level = 'warn'; if ($CFG->debugdeveloper) { $logconfig->level = 'trace'; } $this->js_call_amd('core/log', 'setConfig', array($logconfig)); // Add any global JS that needs to run on all pages. $this->js_call_amd('core/page_global', 'init'); // Call amd init functions. $output .= $this->get_amd_footercode(); // Add other requested modules. $output .= $this->get_extra_modules_code(); $this->js_init_code('M.util.js_complete("init");', true); // All the other linked scripts - there should be as few as possible. if ($this->jsincludes['footer']) { foreach ($this->jsincludes['footer'] as $url) { $output .= html_writer::script('', $url); } } // Add all needed strings. // First add core strings required for some dialogues. $this->strings_for_js(array( 'confirm', 'yes', 'no', 'areyousure', 'closebuttontitle', 'unknownerror', ), 'moodle'); if (!empty($this->stringsforjs)) { $strings = array(); foreach ($this->stringsforjs as $component=>$v) { foreach($v as $indentifier => $langstring) { $strings[$component][$indentifier] = $langstring->out(); } } $output .= html_writer::script(js_writer::set_variable('M.str', $strings)); } // Add variables. if ($this->jsinitvariables['footer']) { $js = ''; foreach ($this->jsinitvariables['footer'] as $data) { list($var, $value) = $data; $js .= js_writer::set_variable($var, $value, true); } $output .= html_writer::script($js); } $inyuijs = $this->get_javascript_code(false); $ondomreadyjs = $this->get_javascript_code(true); $jsinit = $this->get_javascript_init_code(); $handlersjs = $this->get_event_handler_code(); // There is a global Y, make sure it is available in your scope. $js = "(function() {{$inyuijs}{$ondomreadyjs}{$jsinit}{$handlersjs}})();"; $output .= html_writer::script($js); return $output; }
php
public function get_end_code() { global $CFG; $output = ''; // Set the log level for the JS logging. $logconfig = new stdClass(); $logconfig->level = 'warn'; if ($CFG->debugdeveloper) { $logconfig->level = 'trace'; } $this->js_call_amd('core/log', 'setConfig', array($logconfig)); // Add any global JS that needs to run on all pages. $this->js_call_amd('core/page_global', 'init'); // Call amd init functions. $output .= $this->get_amd_footercode(); // Add other requested modules. $output .= $this->get_extra_modules_code(); $this->js_init_code('M.util.js_complete("init");', true); // All the other linked scripts - there should be as few as possible. if ($this->jsincludes['footer']) { foreach ($this->jsincludes['footer'] as $url) { $output .= html_writer::script('', $url); } } // Add all needed strings. // First add core strings required for some dialogues. $this->strings_for_js(array( 'confirm', 'yes', 'no', 'areyousure', 'closebuttontitle', 'unknownerror', ), 'moodle'); if (!empty($this->stringsforjs)) { $strings = array(); foreach ($this->stringsforjs as $component=>$v) { foreach($v as $indentifier => $langstring) { $strings[$component][$indentifier] = $langstring->out(); } } $output .= html_writer::script(js_writer::set_variable('M.str', $strings)); } // Add variables. if ($this->jsinitvariables['footer']) { $js = ''; foreach ($this->jsinitvariables['footer'] as $data) { list($var, $value) = $data; $js .= js_writer::set_variable($var, $value, true); } $output .= html_writer::script($js); } $inyuijs = $this->get_javascript_code(false); $ondomreadyjs = $this->get_javascript_code(true); $jsinit = $this->get_javascript_init_code(); $handlersjs = $this->get_event_handler_code(); // There is a global Y, make sure it is available in your scope. $js = "(function() {{$inyuijs}{$ondomreadyjs}{$jsinit}{$handlersjs}})();"; $output .= html_writer::script($js); return $output; }
[ "public", "function", "get_end_code", "(", ")", "{", "global", "$", "CFG", ";", "$", "output", "=", "''", ";", "// Set the log level for the JS logging.", "$", "logconfig", "=", "new", "stdClass", "(", ")", ";", "$", "logconfig", "->", "level", "=", "'warn'", ";", "if", "(", "$", "CFG", "->", "debugdeveloper", ")", "{", "$", "logconfig", "->", "level", "=", "'trace'", ";", "}", "$", "this", "->", "js_call_amd", "(", "'core/log'", ",", "'setConfig'", ",", "array", "(", "$", "logconfig", ")", ")", ";", "// Add any global JS that needs to run on all pages.", "$", "this", "->", "js_call_amd", "(", "'core/page_global'", ",", "'init'", ")", ";", "// Call amd init functions.", "$", "output", ".=", "$", "this", "->", "get_amd_footercode", "(", ")", ";", "// Add other requested modules.", "$", "output", ".=", "$", "this", "->", "get_extra_modules_code", "(", ")", ";", "$", "this", "->", "js_init_code", "(", "'M.util.js_complete(\"init\");'", ",", "true", ")", ";", "// All the other linked scripts - there should be as few as possible.", "if", "(", "$", "this", "->", "jsincludes", "[", "'footer'", "]", ")", "{", "foreach", "(", "$", "this", "->", "jsincludes", "[", "'footer'", "]", "as", "$", "url", ")", "{", "$", "output", ".=", "html_writer", "::", "script", "(", "''", ",", "$", "url", ")", ";", "}", "}", "// Add all needed strings.", "// First add core strings required for some dialogues.", "$", "this", "->", "strings_for_js", "(", "array", "(", "'confirm'", ",", "'yes'", ",", "'no'", ",", "'areyousure'", ",", "'closebuttontitle'", ",", "'unknownerror'", ",", ")", ",", "'moodle'", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "stringsforjs", ")", ")", "{", "$", "strings", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "stringsforjs", "as", "$", "component", "=>", "$", "v", ")", "{", "foreach", "(", "$", "v", "as", "$", "indentifier", "=>", "$", "langstring", ")", "{", "$", "strings", "[", "$", "component", "]", "[", "$", "indentifier", "]", "=", "$", "langstring", "->", "out", "(", ")", ";", "}", "}", "$", "output", ".=", "html_writer", "::", "script", "(", "js_writer", "::", "set_variable", "(", "'M.str'", ",", "$", "strings", ")", ")", ";", "}", "// Add variables.", "if", "(", "$", "this", "->", "jsinitvariables", "[", "'footer'", "]", ")", "{", "$", "js", "=", "''", ";", "foreach", "(", "$", "this", "->", "jsinitvariables", "[", "'footer'", "]", "as", "$", "data", ")", "{", "list", "(", "$", "var", ",", "$", "value", ")", "=", "$", "data", ";", "$", "js", ".=", "js_writer", "::", "set_variable", "(", "$", "var", ",", "$", "value", ",", "true", ")", ";", "}", "$", "output", ".=", "html_writer", "::", "script", "(", "$", "js", ")", ";", "}", "$", "inyuijs", "=", "$", "this", "->", "get_javascript_code", "(", "false", ")", ";", "$", "ondomreadyjs", "=", "$", "this", "->", "get_javascript_code", "(", "true", ")", ";", "$", "jsinit", "=", "$", "this", "->", "get_javascript_init_code", "(", ")", ";", "$", "handlersjs", "=", "$", "this", "->", "get_event_handler_code", "(", ")", ";", "// There is a global Y, make sure it is available in your scope.", "$", "js", "=", "\"(function() {{$inyuijs}{$ondomreadyjs}{$jsinit}{$handlersjs}})();\"", ";", "$", "output", ".=", "html_writer", "::", "script", "(", "$", "js", ")", ";", "return", "$", "output", ";", "}" ]
Generate any HTML that needs to go at the end of the page. Normally, this method is called automatically by the code that prints the page footer. You should not normally need to call it in your own code. @return string the HTML code to to at the end of the page.
[ "Generate", "any", "HTML", "that", "needs", "to", "go", "at", "the", "end", "of", "the", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L1603-L1673
217,932
moodle/moodle
lib/outputrequirementslib.php
YUI_config.add_group
public function add_group($name, $config) { if (isset($this->groups[$name])) { throw new coding_exception("A YUI configuration group for '{$name}' already exists. To make changes to this group use YUI_config->update_group()."); } $this->groups[$name] = $config; }
php
public function add_group($name, $config) { if (isset($this->groups[$name])) { throw new coding_exception("A YUI configuration group for '{$name}' already exists. To make changes to this group use YUI_config->update_group()."); } $this->groups[$name] = $config; }
[ "public", "function", "add_group", "(", "$", "name", ",", "$", "config", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "groups", "[", "$", "name", "]", ")", ")", "{", "throw", "new", "coding_exception", "(", "\"A YUI configuration group for '{$name}' already exists. To make changes to this group use YUI_config->update_group().\"", ")", ";", "}", "$", "this", "->", "groups", "[", "$", "name", "]", "=", "$", "config", ";", "}" ]
Create a new group within the YUI_config system. @param String $name The name of the group. This must be unique and not previously used. @param Array $config The configuration for this group. @return void
[ "Create", "a", "new", "group", "within", "the", "YUI_config", "system", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L1796-L1801
217,933
moodle/moodle
lib/outputrequirementslib.php
YUI_config.update_group
public function update_group($name, $config) { if (!isset($this->groups[$name])) { throw new coding_exception('The Moodle YUI module does not exist. You must define the moodle module config using YUI_config->add_module_config first.'); } $this->groups[$name] = $config; }
php
public function update_group($name, $config) { if (!isset($this->groups[$name])) { throw new coding_exception('The Moodle YUI module does not exist. You must define the moodle module config using YUI_config->add_module_config first.'); } $this->groups[$name] = $config; }
[ "public", "function", "update_group", "(", "$", "name", ",", "$", "config", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "groups", "[", "$", "name", "]", ")", ")", "{", "throw", "new", "coding_exception", "(", "'The Moodle YUI module does not exist. You must define the moodle module config using YUI_config->add_module_config first.'", ")", ";", "}", "$", "this", "->", "groups", "[", "$", "name", "]", "=", "$", "config", ";", "}" ]
Update an existing group configuration Note, any existing configuration for that group will be wiped out. This includes module configuration. @param String $name The name of the group. This must be unique and not previously used. @param Array $config The configuration for this group. @return void
[ "Update", "an", "existing", "group", "configuration" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L1814-L1819
217,934
moodle/moodle
lib/outputrequirementslib.php
YUI_config.set_config_function
public function set_config_function($function) { $configname = 'yui' . (count($this->jsconfigfunctions) + 1) . 'ConfigFn'; if (isset($this->jsconfigfunctions[$configname])) { throw new coding_exception("A YUI config function with this name already exists. Config function names must be unique."); } $this->jsconfigfunctions[$configname] = $function; return '@' . $configname . '@'; }
php
public function set_config_function($function) { $configname = 'yui' . (count($this->jsconfigfunctions) + 1) . 'ConfigFn'; if (isset($this->jsconfigfunctions[$configname])) { throw new coding_exception("A YUI config function with this name already exists. Config function names must be unique."); } $this->jsconfigfunctions[$configname] = $function; return '@' . $configname . '@'; }
[ "public", "function", "set_config_function", "(", "$", "function", ")", "{", "$", "configname", "=", "'yui'", ".", "(", "count", "(", "$", "this", "->", "jsconfigfunctions", ")", "+", "1", ")", ".", "'ConfigFn'", ";", "if", "(", "isset", "(", "$", "this", "->", "jsconfigfunctions", "[", "$", "configname", "]", ")", ")", "{", "throw", "new", "coding_exception", "(", "\"A YUI config function with this name already exists. Config function names must be unique.\"", ")", ";", "}", "$", "this", "->", "jsconfigfunctions", "[", "$", "configname", "]", "=", "$", "function", ";", "return", "'@'", ".", "$", "configname", ".", "'@'", ";", "}" ]
Set the value of a configuration function used by the YUI Loader's pattern testing. Only the body of the function should be passed, and not the whole function wrapper. The JS function your write will be passed a single argument 'name' containing the name of the module being loaded. @param $function String the body of the JavaScript function. This should be used i @return String the name of the function to use in the group pattern configuration.
[ "Set", "the", "value", "of", "a", "configuration", "function", "used", "by", "the", "YUI", "Loader", "s", "pattern", "testing", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L1832-L1839
217,935
moodle/moodle
lib/outputrequirementslib.php
YUI_config.get_config_functions
public function get_config_functions() { $configfunctions = ''; foreach ($this->jsconfigfunctions as $functionname => $function) { $configfunctions .= "var {$functionname} = function(me) {"; $configfunctions .= $function; $configfunctions .= "};\n"; } return $configfunctions; }
php
public function get_config_functions() { $configfunctions = ''; foreach ($this->jsconfigfunctions as $functionname => $function) { $configfunctions .= "var {$functionname} = function(me) {"; $configfunctions .= $function; $configfunctions .= "};\n"; } return $configfunctions; }
[ "public", "function", "get_config_functions", "(", ")", "{", "$", "configfunctions", "=", "''", ";", "foreach", "(", "$", "this", "->", "jsconfigfunctions", "as", "$", "functionname", "=>", "$", "function", ")", "{", "$", "configfunctions", ".=", "\"var {$functionname} = function(me) {\"", ";", "$", "configfunctions", ".=", "$", "function", ";", "$", "configfunctions", ".=", "\"};\\n\"", ";", "}", "return", "$", "configfunctions", ";", "}" ]
Retrieve the list of JavaScript functions for YUI_config groups. @return String The complete set of config functions
[ "Retrieve", "the", "list", "of", "JavaScript", "functions", "for", "YUI_config", "groups", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L1876-L1884
217,936
moodle/moodle
lib/outputrequirementslib.php
YUI_config.update_header_js
public function update_header_js($js) { // Update the names of the the configFn variables. // The PHP json_encode function cannot handle literal names so we have to wrap // them in @ and then replace them with literals of the same function name. foreach ($this->jsconfigfunctions as $functionname => $function) { $js = str_replace('"@' . $functionname . '@"', $functionname, $js); } return $js; }
php
public function update_header_js($js) { // Update the names of the the configFn variables. // The PHP json_encode function cannot handle literal names so we have to wrap // them in @ and then replace them with literals of the same function name. foreach ($this->jsconfigfunctions as $functionname => $function) { $js = str_replace('"@' . $functionname . '@"', $functionname, $js); } return $js; }
[ "public", "function", "update_header_js", "(", "$", "js", ")", "{", "// Update the names of the the configFn variables.", "// The PHP json_encode function cannot handle literal names so we have to wrap", "// them in @ and then replace them with literals of the same function name.", "foreach", "(", "$", "this", "->", "jsconfigfunctions", "as", "$", "functionname", "=>", "$", "function", ")", "{", "$", "js", "=", "str_replace", "(", "'\"@'", ".", "$", "functionname", ".", "'@\"'", ",", "$", "functionname", ",", "$", "js", ")", ";", "}", "return", "$", "js", ";", "}" ]
Update the header JavaScript with any required modification for the YUI Loader. @param $js String The JavaScript to manipulate. @return String the modified JS string.
[ "Update", "the", "header", "JavaScript", "with", "any", "required", "modification", "for", "the", "YUI", "Loader", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L1892-L1900
217,937
moodle/moodle
lib/outputrequirementslib.php
YUI_config.add_module_config
public function add_module_config($name, $config, $group = null) { if ($group) { if (!isset($this->groups[$name])) { throw new coding_exception('The Moodle YUI module does not exist. You must define the moodle module config using YUI_config->add_module_config first.'); } if (!isset($this->groups[$group]['modules'])) { $this->groups[$group]['modules'] = array(); } $modules = &$this->groups[$group]['modules']; } else { $modules = &$this->modules; } $modules[$name] = $config; }
php
public function add_module_config($name, $config, $group = null) { if ($group) { if (!isset($this->groups[$name])) { throw new coding_exception('The Moodle YUI module does not exist. You must define the moodle module config using YUI_config->add_module_config first.'); } if (!isset($this->groups[$group]['modules'])) { $this->groups[$group]['modules'] = array(); } $modules = &$this->groups[$group]['modules']; } else { $modules = &$this->modules; } $modules[$name] = $config; }
[ "public", "function", "add_module_config", "(", "$", "name", ",", "$", "config", ",", "$", "group", "=", "null", ")", "{", "if", "(", "$", "group", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "groups", "[", "$", "name", "]", ")", ")", "{", "throw", "new", "coding_exception", "(", "'The Moodle YUI module does not exist. You must define the moodle module config using YUI_config->add_module_config first.'", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "groups", "[", "$", "group", "]", "[", "'modules'", "]", ")", ")", "{", "$", "this", "->", "groups", "[", "$", "group", "]", "[", "'modules'", "]", "=", "array", "(", ")", ";", "}", "$", "modules", "=", "&", "$", "this", "->", "groups", "[", "$", "group", "]", "[", "'modules'", "]", ";", "}", "else", "{", "$", "modules", "=", "&", "$", "this", "->", "modules", ";", "}", "$", "modules", "[", "$", "name", "]", "=", "$", "config", ";", "}" ]
Add configuration for a specific module. @param String $name The name of the module to add configuration for. @param Array $config The configuration for the specified module. @param String $group The name of the group to add configuration for. If not specified, then this module is added to the global configuration. @return void
[ "Add", "configuration", "for", "a", "specific", "module", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L1912-L1925
217,938
moodle/moodle
lib/outputrequirementslib.php
YUI_config.add_moodle_metadata
public function add_moodle_metadata() { global $CFG; if (!isset($this->groups['moodle'])) { throw new coding_exception('The Moodle YUI module does not exist. You must define the moodle module config using YUI_config->add_module_config first.'); } if (!isset($this->groups['moodle']['modules'])) { $this->groups['moodle']['modules'] = array(); } $cache = cache::make('core', 'yuimodules'); if (!isset($CFG->jsrev) || $CFG->jsrev == -1) { $metadata = array(); $metadata = $this->get_moodle_metadata(); $cache->delete('metadata'); } else { // Attempt to get the metadata from the cache. if (!$metadata = $cache->get('metadata')) { $metadata = $this->get_moodle_metadata(); $cache->set('metadata', $metadata); } } // Merge with any metadata added specific to this page which was added manually. $this->groups['moodle']['modules'] = array_merge($this->groups['moodle']['modules'], $metadata); }
php
public function add_moodle_metadata() { global $CFG; if (!isset($this->groups['moodle'])) { throw new coding_exception('The Moodle YUI module does not exist. You must define the moodle module config using YUI_config->add_module_config first.'); } if (!isset($this->groups['moodle']['modules'])) { $this->groups['moodle']['modules'] = array(); } $cache = cache::make('core', 'yuimodules'); if (!isset($CFG->jsrev) || $CFG->jsrev == -1) { $metadata = array(); $metadata = $this->get_moodle_metadata(); $cache->delete('metadata'); } else { // Attempt to get the metadata from the cache. if (!$metadata = $cache->get('metadata')) { $metadata = $this->get_moodle_metadata(); $cache->set('metadata', $metadata); } } // Merge with any metadata added specific to this page which was added manually. $this->groups['moodle']['modules'] = array_merge($this->groups['moodle']['modules'], $metadata); }
[ "public", "function", "add_moodle_metadata", "(", ")", "{", "global", "$", "CFG", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "groups", "[", "'moodle'", "]", ")", ")", "{", "throw", "new", "coding_exception", "(", "'The Moodle YUI module does not exist. You must define the moodle module config using YUI_config->add_module_config first.'", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "groups", "[", "'moodle'", "]", "[", "'modules'", "]", ")", ")", "{", "$", "this", "->", "groups", "[", "'moodle'", "]", "[", "'modules'", "]", "=", "array", "(", ")", ";", "}", "$", "cache", "=", "cache", "::", "make", "(", "'core'", ",", "'yuimodules'", ")", ";", "if", "(", "!", "isset", "(", "$", "CFG", "->", "jsrev", ")", "||", "$", "CFG", "->", "jsrev", "==", "-", "1", ")", "{", "$", "metadata", "=", "array", "(", ")", ";", "$", "metadata", "=", "$", "this", "->", "get_moodle_metadata", "(", ")", ";", "$", "cache", "->", "delete", "(", "'metadata'", ")", ";", "}", "else", "{", "// Attempt to get the metadata from the cache.", "if", "(", "!", "$", "metadata", "=", "$", "cache", "->", "get", "(", "'metadata'", ")", ")", "{", "$", "metadata", "=", "$", "this", "->", "get_moodle_metadata", "(", ")", ";", "$", "cache", "->", "set", "(", "'metadata'", ",", "$", "metadata", ")", ";", "}", "}", "// Merge with any metadata added specific to this page which was added manually.", "$", "this", "->", "groups", "[", "'moodle'", "]", "[", "'modules'", "]", "=", "array_merge", "(", "$", "this", "->", "groups", "[", "'moodle'", "]", "[", "'modules'", "]", ",", "$", "metadata", ")", ";", "}" ]
Add the moodle YUI module metadata for the moodle group to the YUI_config instance. If js caching is disabled, metadata will not be served causing YUI to calculate module dependencies as each module is loaded. If metadata does not exist it will be created and stored in a MUC entry. @return void
[ "Add", "the", "moodle", "YUI", "module", "metadata", "for", "the", "moodle", "group", "to", "the", "YUI_config", "instance", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L1937-L1963
217,939
moodle/moodle
lib/outputrequirementslib.php
YUI_config.get_moodle_metadata
private function get_moodle_metadata() { $moodlemodules = array(); // Core isn't a plugin type or subsystem - handle it seperately. if ($module = $this->get_moodle_path_metadata(core_component::get_component_directory('core'))) { $moodlemodules = array_merge($moodlemodules, $module); } // Handle other core subsystems. $subsystems = core_component::get_core_subsystems(); foreach ($subsystems as $subsystem => $path) { if (is_null($path)) { continue; } if ($module = $this->get_moodle_path_metadata($path)) { $moodlemodules = array_merge($moodlemodules, $module); } } // And finally the plugins. $plugintypes = core_component::get_plugin_types(); foreach ($plugintypes as $plugintype => $pathroot) { $pluginlist = core_component::get_plugin_list($plugintype); foreach ($pluginlist as $plugin => $path) { if ($module = $this->get_moodle_path_metadata($path)) { $moodlemodules = array_merge($moodlemodules, $module); } } } return $moodlemodules; }
php
private function get_moodle_metadata() { $moodlemodules = array(); // Core isn't a plugin type or subsystem - handle it seperately. if ($module = $this->get_moodle_path_metadata(core_component::get_component_directory('core'))) { $moodlemodules = array_merge($moodlemodules, $module); } // Handle other core subsystems. $subsystems = core_component::get_core_subsystems(); foreach ($subsystems as $subsystem => $path) { if (is_null($path)) { continue; } if ($module = $this->get_moodle_path_metadata($path)) { $moodlemodules = array_merge($moodlemodules, $module); } } // And finally the plugins. $plugintypes = core_component::get_plugin_types(); foreach ($plugintypes as $plugintype => $pathroot) { $pluginlist = core_component::get_plugin_list($plugintype); foreach ($pluginlist as $plugin => $path) { if ($module = $this->get_moodle_path_metadata($path)) { $moodlemodules = array_merge($moodlemodules, $module); } } } return $moodlemodules; }
[ "private", "function", "get_moodle_metadata", "(", ")", "{", "$", "moodlemodules", "=", "array", "(", ")", ";", "// Core isn't a plugin type or subsystem - handle it seperately.", "if", "(", "$", "module", "=", "$", "this", "->", "get_moodle_path_metadata", "(", "core_component", "::", "get_component_directory", "(", "'core'", ")", ")", ")", "{", "$", "moodlemodules", "=", "array_merge", "(", "$", "moodlemodules", ",", "$", "module", ")", ";", "}", "// Handle other core subsystems.", "$", "subsystems", "=", "core_component", "::", "get_core_subsystems", "(", ")", ";", "foreach", "(", "$", "subsystems", "as", "$", "subsystem", "=>", "$", "path", ")", "{", "if", "(", "is_null", "(", "$", "path", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "module", "=", "$", "this", "->", "get_moodle_path_metadata", "(", "$", "path", ")", ")", "{", "$", "moodlemodules", "=", "array_merge", "(", "$", "moodlemodules", ",", "$", "module", ")", ";", "}", "}", "// And finally the plugins.", "$", "plugintypes", "=", "core_component", "::", "get_plugin_types", "(", ")", ";", "foreach", "(", "$", "plugintypes", "as", "$", "plugintype", "=>", "$", "pathroot", ")", "{", "$", "pluginlist", "=", "core_component", "::", "get_plugin_list", "(", "$", "plugintype", ")", ";", "foreach", "(", "$", "pluginlist", "as", "$", "plugin", "=>", "$", "path", ")", "{", "if", "(", "$", "module", "=", "$", "this", "->", "get_moodle_path_metadata", "(", "$", "path", ")", ")", "{", "$", "moodlemodules", "=", "array_merge", "(", "$", "moodlemodules", ",", "$", "module", ")", ";", "}", "}", "}", "return", "$", "moodlemodules", ";", "}" ]
Determine the module metadata for all moodle YUI modules. This works through all modules capable of serving YUI modules, and attempts to get metadata for each of those modules. @return Array of module metadata
[ "Determine", "the", "module", "metadata", "for", "all", "moodle", "YUI", "modules", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L1973-L2003
217,940
moodle/moodle
lib/outputrequirementslib.php
YUI_config.get_moodle_path_metadata
private function get_moodle_path_metadata($path) { // Add module metadata is stored in frankenstyle_modname/yui/src/yui_modname/meta/yui_modname.json. $baseyui = $path . '/yui/src'; $modules = array(); if (is_dir($baseyui)) { $items = new DirectoryIterator($baseyui); foreach ($items as $item) { if ($item->isDot() or !$item->isDir()) { continue; } $metafile = realpath($baseyui . '/' . $item . '/meta/' . $item . '.json'); if (!is_readable($metafile)) { continue; } $metadata = file_get_contents($metafile); $modules = array_merge($modules, (array) json_decode($metadata)); } } return $modules; }
php
private function get_moodle_path_metadata($path) { // Add module metadata is stored in frankenstyle_modname/yui/src/yui_modname/meta/yui_modname.json. $baseyui = $path . '/yui/src'; $modules = array(); if (is_dir($baseyui)) { $items = new DirectoryIterator($baseyui); foreach ($items as $item) { if ($item->isDot() or !$item->isDir()) { continue; } $metafile = realpath($baseyui . '/' . $item . '/meta/' . $item . '.json'); if (!is_readable($metafile)) { continue; } $metadata = file_get_contents($metafile); $modules = array_merge($modules, (array) json_decode($metadata)); } } return $modules; }
[ "private", "function", "get_moodle_path_metadata", "(", "$", "path", ")", "{", "// Add module metadata is stored in frankenstyle_modname/yui/src/yui_modname/meta/yui_modname.json.", "$", "baseyui", "=", "$", "path", ".", "'/yui/src'", ";", "$", "modules", "=", "array", "(", ")", ";", "if", "(", "is_dir", "(", "$", "baseyui", ")", ")", "{", "$", "items", "=", "new", "DirectoryIterator", "(", "$", "baseyui", ")", ";", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "if", "(", "$", "item", "->", "isDot", "(", ")", "or", "!", "$", "item", "->", "isDir", "(", ")", ")", "{", "continue", ";", "}", "$", "metafile", "=", "realpath", "(", "$", "baseyui", ".", "'/'", ".", "$", "item", ".", "'/meta/'", ".", "$", "item", ".", "'.json'", ")", ";", "if", "(", "!", "is_readable", "(", "$", "metafile", ")", ")", "{", "continue", ";", "}", "$", "metadata", "=", "file_get_contents", "(", "$", "metafile", ")", ";", "$", "modules", "=", "array_merge", "(", "$", "modules", ",", "(", "array", ")", "json_decode", "(", "$", "metadata", ")", ")", ";", "}", "}", "return", "$", "modules", ";", "}" ]
Helper function process and return the YUI metadata for all of the modules under the specified path. @param String $path the UNC path to the YUI src directory. @return Array the complete array for frankenstyle directory.
[ "Helper", "function", "process", "and", "return", "the", "YUI", "metadata", "for", "all", "of", "the", "modules", "under", "the", "specified", "path", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L2011-L2030
217,941
moodle/moodle
lib/outputrequirementslib.php
YUI_config.define_patched_core_modules
public function define_patched_core_modules($combobase, $yuiversion, $patchlevel, $patchedmodules) { // The version we use is suffixed with a patchlevel so that we can get additional revisions between YUI releases. $subversion = $yuiversion . '_' . $patchlevel; if ($this->comboBase == $combobase) { // If we are using the local combobase in the loader, we can add a group and still make use of the combo // loader. We just need to specify a different root which includes a slightly different YUI version number // to include our patchlevel. $patterns = array(); $modules = array(); foreach ($patchedmodules as $modulename) { // We must define the pattern and module here so that the loader uses our group configuration instead of // the standard module definition. We may lose some metadata provided by upstream but this will be // loaded when the module is loaded anyway. $patterns[$modulename] = array( 'group' => 'yui-patched', ); $modules[$modulename] = array(); } // Actually add the patch group here. $this->add_group('yui-patched', array( 'combine' => true, 'root' => $subversion . '/', 'patterns' => $patterns, 'modules' => $modules, )); } else { // The CDN is in use - we need to instead use the local combobase for this module and override the modules // definition. We cannot use the local base - we must use the combobase because we cannot invalidate the // local base in browser caches. $fullpathbase = $combobase . $subversion . '/'; foreach ($patchedmodules as $modulename) { $this->modules[$modulename] = array( 'fullpath' => $fullpathbase . $modulename . '/' . $modulename . '-min.js' ); } } }
php
public function define_patched_core_modules($combobase, $yuiversion, $patchlevel, $patchedmodules) { // The version we use is suffixed with a patchlevel so that we can get additional revisions between YUI releases. $subversion = $yuiversion . '_' . $patchlevel; if ($this->comboBase == $combobase) { // If we are using the local combobase in the loader, we can add a group and still make use of the combo // loader. We just need to specify a different root which includes a slightly different YUI version number // to include our patchlevel. $patterns = array(); $modules = array(); foreach ($patchedmodules as $modulename) { // We must define the pattern and module here so that the loader uses our group configuration instead of // the standard module definition. We may lose some metadata provided by upstream but this will be // loaded when the module is loaded anyway. $patterns[$modulename] = array( 'group' => 'yui-patched', ); $modules[$modulename] = array(); } // Actually add the patch group here. $this->add_group('yui-patched', array( 'combine' => true, 'root' => $subversion . '/', 'patterns' => $patterns, 'modules' => $modules, )); } else { // The CDN is in use - we need to instead use the local combobase for this module and override the modules // definition. We cannot use the local base - we must use the combobase because we cannot invalidate the // local base in browser caches. $fullpathbase = $combobase . $subversion . '/'; foreach ($patchedmodules as $modulename) { $this->modules[$modulename] = array( 'fullpath' => $fullpathbase . $modulename . '/' . $modulename . '-min.js' ); } } }
[ "public", "function", "define_patched_core_modules", "(", "$", "combobase", ",", "$", "yuiversion", ",", "$", "patchlevel", ",", "$", "patchedmodules", ")", "{", "// The version we use is suffixed with a patchlevel so that we can get additional revisions between YUI releases.", "$", "subversion", "=", "$", "yuiversion", ".", "'_'", ".", "$", "patchlevel", ";", "if", "(", "$", "this", "->", "comboBase", "==", "$", "combobase", ")", "{", "// If we are using the local combobase in the loader, we can add a group and still make use of the combo", "// loader. We just need to specify a different root which includes a slightly different YUI version number", "// to include our patchlevel.", "$", "patterns", "=", "array", "(", ")", ";", "$", "modules", "=", "array", "(", ")", ";", "foreach", "(", "$", "patchedmodules", "as", "$", "modulename", ")", "{", "// We must define the pattern and module here so that the loader uses our group configuration instead of", "// the standard module definition. We may lose some metadata provided by upstream but this will be", "// loaded when the module is loaded anyway.", "$", "patterns", "[", "$", "modulename", "]", "=", "array", "(", "'group'", "=>", "'yui-patched'", ",", ")", ";", "$", "modules", "[", "$", "modulename", "]", "=", "array", "(", ")", ";", "}", "// Actually add the patch group here.", "$", "this", "->", "add_group", "(", "'yui-patched'", ",", "array", "(", "'combine'", "=>", "true", ",", "'root'", "=>", "$", "subversion", ".", "'/'", ",", "'patterns'", "=>", "$", "patterns", ",", "'modules'", "=>", "$", "modules", ",", ")", ")", ";", "}", "else", "{", "// The CDN is in use - we need to instead use the local combobase for this module and override the modules", "// definition. We cannot use the local base - we must use the combobase because we cannot invalidate the", "// local base in browser caches.", "$", "fullpathbase", "=", "$", "combobase", ".", "$", "subversion", ".", "'/'", ";", "foreach", "(", "$", "patchedmodules", "as", "$", "modulename", ")", "{", "$", "this", "->", "modules", "[", "$", "modulename", "]", "=", "array", "(", "'fullpath'", "=>", "$", "fullpathbase", ".", "$", "modulename", ".", "'/'", ".", "$", "modulename", ".", "'-min.js'", ")", ";", "}", "}", "}" ]
Define YUI modules which we have been required to patch between releases. We must do this because we aggressively cache content on the browser, and we must also override use of the external CDN which will serve the true authoritative copy of the code without our patches. @param String combobase The local combobase @param String yuiversion The current YUI version @param Int patchlevel The patch level we're working to for YUI @param Array patchedmodules An array containing the names of the patched modules @return void
[ "Define", "YUI", "modules", "which", "we", "have", "been", "required", "to", "patch", "between", "releases", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputrequirementslib.php#L2044-L2083
217,942
moodle/moodle
report/competency/classes/external.php
external.data_for_report
public static function data_for_report($courseid, $userid, $moduleid) { global $PAGE; $params = self::validate_parameters( self::data_for_report_parameters(), array( 'courseid' => $courseid, 'userid' => $userid, 'moduleid' => $moduleid ) ); $context = context_course::instance($params['courseid']); self::validate_context($context); if (!is_enrolled($context, $params['userid'], 'moodle/competency:coursecompetencygradable')) { throw new coding_exception('invaliduser'); } $renderable = new output\report($params['courseid'], $params['userid'], $params['moduleid']); $renderer = $PAGE->get_renderer('report_competency'); $data = $renderable->export_for_template($renderer); return $data; }
php
public static function data_for_report($courseid, $userid, $moduleid) { global $PAGE; $params = self::validate_parameters( self::data_for_report_parameters(), array( 'courseid' => $courseid, 'userid' => $userid, 'moduleid' => $moduleid ) ); $context = context_course::instance($params['courseid']); self::validate_context($context); if (!is_enrolled($context, $params['userid'], 'moodle/competency:coursecompetencygradable')) { throw new coding_exception('invaliduser'); } $renderable = new output\report($params['courseid'], $params['userid'], $params['moduleid']); $renderer = $PAGE->get_renderer('report_competency'); $data = $renderable->export_for_template($renderer); return $data; }
[ "public", "static", "function", "data_for_report", "(", "$", "courseid", ",", "$", "userid", ",", "$", "moduleid", ")", "{", "global", "$", "PAGE", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "data_for_report_parameters", "(", ")", ",", "array", "(", "'courseid'", "=>", "$", "courseid", ",", "'userid'", "=>", "$", "userid", ",", "'moduleid'", "=>", "$", "moduleid", ")", ")", ";", "$", "context", "=", "context_course", "::", "instance", "(", "$", "params", "[", "'courseid'", "]", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "if", "(", "!", "is_enrolled", "(", "$", "context", ",", "$", "params", "[", "'userid'", "]", ",", "'moodle/competency:coursecompetencygradable'", ")", ")", "{", "throw", "new", "coding_exception", "(", "'invaliduser'", ")", ";", "}", "$", "renderable", "=", "new", "output", "\\", "report", "(", "$", "params", "[", "'courseid'", "]", ",", "$", "params", "[", "'userid'", "]", ",", "$", "params", "[", "'moduleid'", "]", ")", ";", "$", "renderer", "=", "$", "PAGE", "->", "get_renderer", "(", "'report_competency'", ")", ";", "$", "data", "=", "$", "renderable", "->", "export_for_template", "(", "$", "renderer", ")", ";", "return", "$", "data", ";", "}" ]
Loads the data required to render the report. @param int $courseid The course id @param int $userid The user id @param int $moduleid The module id @return \stdClass
[ "Loads", "the", "data", "required", "to", "render", "the", "report", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/competency/classes/external.php#L86-L109
217,943
moodle/moodle
backup/util/plan/restore_step.class.php
restore_step.decrypt
public function decrypt($value) { // No openssl available, skip this field completely. if (!function_exists('openssl_encrypt')) { return null; } // No hash available, skip this field completely. if (!function_exists('hash_hmac')) { return null; } // Cypher not available, skip this field completely. if (!in_array(backup::CIPHER, openssl_get_cipher_methods())) { return null; } // Get the decrypt key. Skip if missing. $key = get_config('backup', 'backup_encryptkey'); if ($key === false) { return null; } // And decode it. $key = base64_decode($key); // Arrived here, let's proceed with authentication (provides integrity). $hmaclen = 32; // SHA256 is 32 bytes. $ivlen = openssl_cipher_iv_length(backup::CIPHER); list($hmac, $iv, $text) = array_values(unpack("a{$hmaclen}hmac/a{$ivlen}iv/a*text", base64_decode($value))); // Verify HMAC matches expectations, skip if not (integrity failed). if (!hash_equals($hmac, hash_hmac('sha256', $iv . $text, $key, true))) { return null; } // Arrived here, integrity is ok, let's decrypt. $result = openssl_decrypt($text, backup::CIPHER, $key, OPENSSL_RAW_DATA, $iv); // For some reason decrypt failed (strange, HMAC check should have deteted it), skip this field completely. if ($result === false) { return null; } return $result; }
php
public function decrypt($value) { // No openssl available, skip this field completely. if (!function_exists('openssl_encrypt')) { return null; } // No hash available, skip this field completely. if (!function_exists('hash_hmac')) { return null; } // Cypher not available, skip this field completely. if (!in_array(backup::CIPHER, openssl_get_cipher_methods())) { return null; } // Get the decrypt key. Skip if missing. $key = get_config('backup', 'backup_encryptkey'); if ($key === false) { return null; } // And decode it. $key = base64_decode($key); // Arrived here, let's proceed with authentication (provides integrity). $hmaclen = 32; // SHA256 is 32 bytes. $ivlen = openssl_cipher_iv_length(backup::CIPHER); list($hmac, $iv, $text) = array_values(unpack("a{$hmaclen}hmac/a{$ivlen}iv/a*text", base64_decode($value))); // Verify HMAC matches expectations, skip if not (integrity failed). if (!hash_equals($hmac, hash_hmac('sha256', $iv . $text, $key, true))) { return null; } // Arrived here, integrity is ok, let's decrypt. $result = openssl_decrypt($text, backup::CIPHER, $key, OPENSSL_RAW_DATA, $iv); // For some reason decrypt failed (strange, HMAC check should have deteted it), skip this field completely. if ($result === false) { return null; } return $result; }
[ "public", "function", "decrypt", "(", "$", "value", ")", "{", "// No openssl available, skip this field completely.", "if", "(", "!", "function_exists", "(", "'openssl_encrypt'", ")", ")", "{", "return", "null", ";", "}", "// No hash available, skip this field completely.", "if", "(", "!", "function_exists", "(", "'hash_hmac'", ")", ")", "{", "return", "null", ";", "}", "// Cypher not available, skip this field completely.", "if", "(", "!", "in_array", "(", "backup", "::", "CIPHER", ",", "openssl_get_cipher_methods", "(", ")", ")", ")", "{", "return", "null", ";", "}", "// Get the decrypt key. Skip if missing.", "$", "key", "=", "get_config", "(", "'backup'", ",", "'backup_encryptkey'", ")", ";", "if", "(", "$", "key", "===", "false", ")", "{", "return", "null", ";", "}", "// And decode it.", "$", "key", "=", "base64_decode", "(", "$", "key", ")", ";", "// Arrived here, let's proceed with authentication (provides integrity).", "$", "hmaclen", "=", "32", ";", "// SHA256 is 32 bytes.", "$", "ivlen", "=", "openssl_cipher_iv_length", "(", "backup", "::", "CIPHER", ")", ";", "list", "(", "$", "hmac", ",", "$", "iv", ",", "$", "text", ")", "=", "array_values", "(", "unpack", "(", "\"a{$hmaclen}hmac/a{$ivlen}iv/a*text\"", ",", "base64_decode", "(", "$", "value", ")", ")", ")", ";", "// Verify HMAC matches expectations, skip if not (integrity failed).", "if", "(", "!", "hash_equals", "(", "$", "hmac", ",", "hash_hmac", "(", "'sha256'", ",", "$", "iv", ".", "$", "text", ",", "$", "key", ",", "true", ")", ")", ")", "{", "return", "null", ";", "}", "// Arrived here, integrity is ok, let's decrypt.", "$", "result", "=", "openssl_decrypt", "(", "$", "text", ",", "backup", "::", "CIPHER", ",", "$", "key", ",", "OPENSSL_RAW_DATA", ",", "$", "iv", ")", ";", "// For some reason decrypt failed (strange, HMAC check should have deteted it), skip this field completely.", "if", "(", "$", "result", "===", "false", ")", "{", "return", "null", ";", "}", "return", "$", "result", ";", "}" ]
Returns symmetric-key AES-256 decryption of base64 encoded contents. This method is used in restore operations to decrypt contents encrypted with {@link encrypted_final_element} automatically decoding (base64) and decrypting contents using the key stored in backup_encryptkey config. Requires openssl, cipher availability, and key existence (backup automatically sets it if missing). Integrity is provided via HMAC. @param string $value {@link encrypted_final_element} value to decode and decrypt. @return string|null decoded and decrypted value or null if the operation can not be performed.
[ "Returns", "symmetric", "-", "key", "AES", "-", "256", "decryption", "of", "base64", "encoded", "contents", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/plan/restore_step.class.php#L109-L154
217,944
moodle/moodle
lib/classes/lock/postgres_lock_factory.php
postgres_lock_factory.get_unique_db_instance_id
protected function get_unique_db_instance_id() { global $CFG; $strkey = $CFG->dbname . ':' . $CFG->prefix; $intkey = crc32($strkey); // Normalize between 64 bit unsigned int and 32 bit signed ints. Php could return either from crc32. if (PHP_INT_SIZE == 8) { if ($intkey > 0x7FFFFFFF) { $intkey -= 0x100000000; } } return $intkey; }
php
protected function get_unique_db_instance_id() { global $CFG; $strkey = $CFG->dbname . ':' . $CFG->prefix; $intkey = crc32($strkey); // Normalize between 64 bit unsigned int and 32 bit signed ints. Php could return either from crc32. if (PHP_INT_SIZE == 8) { if ($intkey > 0x7FFFFFFF) { $intkey -= 0x100000000; } } return $intkey; }
[ "protected", "function", "get_unique_db_instance_id", "(", ")", "{", "global", "$", "CFG", ";", "$", "strkey", "=", "$", "CFG", "->", "dbname", ".", "':'", ".", "$", "CFG", "->", "prefix", ";", "$", "intkey", "=", "crc32", "(", "$", "strkey", ")", ";", "// Normalize between 64 bit unsigned int and 32 bit signed ints. Php could return either from crc32.", "if", "(", "PHP_INT_SIZE", "==", "8", ")", "{", "if", "(", "$", "intkey", ">", "0x7FFFFFFF", ")", "{", "$", "intkey", "-=", "0x100000000", ";", "}", "}", "return", "$", "intkey", ";", "}" ]
Calculate a unique instance id based on the database name and prefix. @return int.
[ "Calculate", "a", "unique", "instance", "id", "based", "on", "the", "database", "name", "and", "prefix", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/lock/postgres_lock_factory.php#L66-L79
217,945
moodle/moodle
lib/classes/lock/postgres_lock_factory.php
postgres_lock_factory.get_index_from_key
protected function get_index_from_key($key) { if (isset(self::$lockidcache[$key])) { return self::$lockidcache[$key]; } $index = 0; $record = $this->db->get_record('lock_db', array('resourcekey' => $key)); if ($record) { $index = $record->id; } if (!$index) { $record = new \stdClass(); $record->resourcekey = $key; try { $index = $this->db->insert_record('lock_db', $record); } catch (\dml_exception $de) { // Race condition - never mind - now the value is guaranteed to exist. $record = $this->db->get_record('lock_db', array('resourcekey' => $key)); if ($record) { $index = $record->id; } } } if (!$index) { throw new \moodle_exception('Could not generate unique index for key'); } self::$lockidcache[$key] = $index; return $index; }
php
protected function get_index_from_key($key) { if (isset(self::$lockidcache[$key])) { return self::$lockidcache[$key]; } $index = 0; $record = $this->db->get_record('lock_db', array('resourcekey' => $key)); if ($record) { $index = $record->id; } if (!$index) { $record = new \stdClass(); $record->resourcekey = $key; try { $index = $this->db->insert_record('lock_db', $record); } catch (\dml_exception $de) { // Race condition - never mind - now the value is guaranteed to exist. $record = $this->db->get_record('lock_db', array('resourcekey' => $key)); if ($record) { $index = $record->id; } } } if (!$index) { throw new \moodle_exception('Could not generate unique index for key'); } self::$lockidcache[$key] = $index; return $index; }
[ "protected", "function", "get_index_from_key", "(", "$", "key", ")", "{", "if", "(", "isset", "(", "self", "::", "$", "lockidcache", "[", "$", "key", "]", ")", ")", "{", "return", "self", "::", "$", "lockidcache", "[", "$", "key", "]", ";", "}", "$", "index", "=", "0", ";", "$", "record", "=", "$", "this", "->", "db", "->", "get_record", "(", "'lock_db'", ",", "array", "(", "'resourcekey'", "=>", "$", "key", ")", ")", ";", "if", "(", "$", "record", ")", "{", "$", "index", "=", "$", "record", "->", "id", ";", "}", "if", "(", "!", "$", "index", ")", "{", "$", "record", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "record", "->", "resourcekey", "=", "$", "key", ";", "try", "{", "$", "index", "=", "$", "this", "->", "db", "->", "insert_record", "(", "'lock_db'", ",", "$", "record", ")", ";", "}", "catch", "(", "\\", "dml_exception", "$", "de", ")", "{", "// Race condition - never mind - now the value is guaranteed to exist.", "$", "record", "=", "$", "this", "->", "db", "->", "get_record", "(", "'lock_db'", ",", "array", "(", "'resourcekey'", "=>", "$", "key", ")", ")", ";", "if", "(", "$", "record", ")", "{", "$", "index", "=", "$", "record", "->", "id", ";", "}", "}", "}", "if", "(", "!", "$", "index", ")", "{", "throw", "new", "\\", "moodle_exception", "(", "'Could not generate unique index for key'", ")", ";", "}", "self", "::", "$", "lockidcache", "[", "$", "key", "]", "=", "$", "index", ";", "return", "$", "index", ";", "}" ]
This function generates the unique index for a specific lock key. Once an index is assigned to a key, it never changes - so this is statically cached. @param string $key @return int @throws \moodle_exception
[ "This", "function", "generates", "the", "unique", "index", "for", "a", "specific", "lock", "key", ".", "Once", "an", "index", "is", "assigned", "to", "a", "key", "it", "never", "changes", "-", "so", "this", "is", "statically", "cached", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/lock/postgres_lock_factory.php#L138-L169
217,946
moodle/moodle
lib/classes/lock/postgres_lock_factory.php
postgres_lock_factory.auto_release
public function auto_release() { // Called from the shutdown handler. Must release all open locks. foreach ($this->openlocks as $key => $unused) { $lock = new lock($key, $this); $lock->release(); } }
php
public function auto_release() { // Called from the shutdown handler. Must release all open locks. foreach ($this->openlocks as $key => $unused) { $lock = new lock($key, $this); $lock->release(); } }
[ "public", "function", "auto_release", "(", ")", "{", "// Called from the shutdown handler. Must release all open locks.", "foreach", "(", "$", "this", "->", "openlocks", "as", "$", "key", "=>", "$", "unused", ")", "{", "$", "lock", "=", "new", "lock", "(", "$", "key", ",", "$", "this", ")", ";", "$", "lock", "->", "release", "(", ")", ";", "}", "}" ]
Auto release any open locks on shutdown. This is required, because we may be using persistent DB connections.
[ "Auto", "release", "any", "open", "locks", "on", "shutdown", ".", "This", "is", "required", "because", "we", "may", "be", "using", "persistent", "DB", "connections", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/lock/postgres_lock_factory.php#L235-L241
217,947
moodle/moodle
lib/dml/pgsql_native_moodle_temptables.php
pgsql_native_moodle_temptables.update_stats
public function update_stats() { $temptables = $this->get_temptables(); foreach ($temptables as $temptablename) { $this->mdb->execute("ANALYZE {".$temptablename."}"); } }
php
public function update_stats() { $temptables = $this->get_temptables(); foreach ($temptables as $temptablename) { $this->mdb->execute("ANALYZE {".$temptablename."}"); } }
[ "public", "function", "update_stats", "(", ")", "{", "$", "temptables", "=", "$", "this", "->", "get_temptables", "(", ")", ";", "foreach", "(", "$", "temptables", "as", "$", "temptablename", ")", "{", "$", "this", "->", "mdb", "->", "execute", "(", "\"ANALYZE {\"", ".", "$", "temptablename", ".", "\"}\"", ")", ";", "}", "}" ]
Analyze the data in temporary tables to force statistics collection after bulk data loads. PostgreSQL does not natively support automatic temporary table stats collection, so we do it. @return void
[ "Analyze", "the", "data", "in", "temporary", "tables", "to", "force", "statistics", "collection", "after", "bulk", "data", "loads", ".", "PostgreSQL", "does", "not", "natively", "support", "automatic", "temporary", "table", "stats", "collection", "so", "we", "do", "it", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/pgsql_native_moodle_temptables.php#L38-L43
217,948
moodle/moodle
lib/htmlpurifier/HTMLPurifier/DoctypeRegistry.php
HTMLPurifier_DoctypeRegistry.register
public function register( $doctype, $xml = true, $modules = array(), $tidy_modules = array(), $aliases = array(), $dtd_public = null, $dtd_system = null ) { if (!is_array($modules)) { $modules = array($modules); } if (!is_array($tidy_modules)) { $tidy_modules = array($tidy_modules); } if (!is_array($aliases)) { $aliases = array($aliases); } if (!is_object($doctype)) { $doctype = new HTMLPurifier_Doctype( $doctype, $xml, $modules, $tidy_modules, $aliases, $dtd_public, $dtd_system ); } $this->doctypes[$doctype->name] = $doctype; $name = $doctype->name; // hookup aliases foreach ($doctype->aliases as $alias) { if (isset($this->doctypes[$alias])) { continue; } $this->aliases[$alias] = $name; } // remove old aliases if (isset($this->aliases[$name])) { unset($this->aliases[$name]); } return $doctype; }
php
public function register( $doctype, $xml = true, $modules = array(), $tidy_modules = array(), $aliases = array(), $dtd_public = null, $dtd_system = null ) { if (!is_array($modules)) { $modules = array($modules); } if (!is_array($tidy_modules)) { $tidy_modules = array($tidy_modules); } if (!is_array($aliases)) { $aliases = array($aliases); } if (!is_object($doctype)) { $doctype = new HTMLPurifier_Doctype( $doctype, $xml, $modules, $tidy_modules, $aliases, $dtd_public, $dtd_system ); } $this->doctypes[$doctype->name] = $doctype; $name = $doctype->name; // hookup aliases foreach ($doctype->aliases as $alias) { if (isset($this->doctypes[$alias])) { continue; } $this->aliases[$alias] = $name; } // remove old aliases if (isset($this->aliases[$name])) { unset($this->aliases[$name]); } return $doctype; }
[ "public", "function", "register", "(", "$", "doctype", ",", "$", "xml", "=", "true", ",", "$", "modules", "=", "array", "(", ")", ",", "$", "tidy_modules", "=", "array", "(", ")", ",", "$", "aliases", "=", "array", "(", ")", ",", "$", "dtd_public", "=", "null", ",", "$", "dtd_system", "=", "null", ")", "{", "if", "(", "!", "is_array", "(", "$", "modules", ")", ")", "{", "$", "modules", "=", "array", "(", "$", "modules", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "tidy_modules", ")", ")", "{", "$", "tidy_modules", "=", "array", "(", "$", "tidy_modules", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "aliases", ")", ")", "{", "$", "aliases", "=", "array", "(", "$", "aliases", ")", ";", "}", "if", "(", "!", "is_object", "(", "$", "doctype", ")", ")", "{", "$", "doctype", "=", "new", "HTMLPurifier_Doctype", "(", "$", "doctype", ",", "$", "xml", ",", "$", "modules", ",", "$", "tidy_modules", ",", "$", "aliases", ",", "$", "dtd_public", ",", "$", "dtd_system", ")", ";", "}", "$", "this", "->", "doctypes", "[", "$", "doctype", "->", "name", "]", "=", "$", "doctype", ";", "$", "name", "=", "$", "doctype", "->", "name", ";", "// hookup aliases", "foreach", "(", "$", "doctype", "->", "aliases", "as", "$", "alias", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "doctypes", "[", "$", "alias", "]", ")", ")", "{", "continue", ";", "}", "$", "this", "->", "aliases", "[", "$", "alias", "]", "=", "$", "name", ";", "}", "// remove old aliases", "if", "(", "isset", "(", "$", "this", "->", "aliases", "[", "$", "name", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "aliases", "[", "$", "name", "]", ")", ";", "}", "return", "$", "doctype", ";", "}" ]
Registers a doctype to the registry @note Accepts a fully-formed doctype object, or the parameters for constructing a doctype object @param string $doctype Name of doctype or literal doctype object @param bool $xml @param array $modules Modules doctype will load @param array $tidy_modules Modules doctype will load for certain modes @param array $aliases Alias names for doctype @param string $dtd_public @param string $dtd_system @return HTMLPurifier_Doctype Editable registered doctype
[ "Registers", "a", "doctype", "to", "the", "registry" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/DoctypeRegistry.php#L31-L74
217,949
moodle/moodle
lib/htmlpurifier/HTMLPurifier/DoctypeRegistry.php
HTMLPurifier_DoctypeRegistry.get
public function get($doctype) { if (isset($this->aliases[$doctype])) { $doctype = $this->aliases[$doctype]; } if (!isset($this->doctypes[$doctype])) { trigger_error('Doctype ' . htmlspecialchars($doctype) . ' does not exist', E_USER_ERROR); $anon = new HTMLPurifier_Doctype($doctype); return $anon; } return $this->doctypes[$doctype]; }
php
public function get($doctype) { if (isset($this->aliases[$doctype])) { $doctype = $this->aliases[$doctype]; } if (!isset($this->doctypes[$doctype])) { trigger_error('Doctype ' . htmlspecialchars($doctype) . ' does not exist', E_USER_ERROR); $anon = new HTMLPurifier_Doctype($doctype); return $anon; } return $this->doctypes[$doctype]; }
[ "public", "function", "get", "(", "$", "doctype", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "aliases", "[", "$", "doctype", "]", ")", ")", "{", "$", "doctype", "=", "$", "this", "->", "aliases", "[", "$", "doctype", "]", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "doctypes", "[", "$", "doctype", "]", ")", ")", "{", "trigger_error", "(", "'Doctype '", ".", "htmlspecialchars", "(", "$", "doctype", ")", ".", "' does not exist'", ",", "E_USER_ERROR", ")", ";", "$", "anon", "=", "new", "HTMLPurifier_Doctype", "(", "$", "doctype", ")", ";", "return", "$", "anon", ";", "}", "return", "$", "this", "->", "doctypes", "[", "$", "doctype", "]", ";", "}" ]
Retrieves reference to a doctype of a certain name @note This function resolves aliases @note When possible, use the more fully-featured make() @param string $doctype Name of doctype @return HTMLPurifier_Doctype Editable doctype object
[ "Retrieves", "reference", "to", "a", "doctype", "of", "a", "certain", "name" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/DoctypeRegistry.php#L83-L94
217,950
moodle/moodle
lib/htmlpurifier/HTMLPurifier/DoctypeRegistry.php
HTMLPurifier_DoctypeRegistry.getDoctypeFromConfig
public function getDoctypeFromConfig($config) { // recommended test $doctype = $config->get('HTML.Doctype'); if (!empty($doctype)) { return $doctype; } $doctype = $config->get('HTML.CustomDoctype'); if (!empty($doctype)) { return $doctype; } // backwards-compatibility if ($config->get('HTML.XHTML')) { $doctype = 'XHTML 1.0'; } else { $doctype = 'HTML 4.01'; } if ($config->get('HTML.Strict')) { $doctype .= ' Strict'; } else { $doctype .= ' Transitional'; } return $doctype; }
php
public function getDoctypeFromConfig($config) { // recommended test $doctype = $config->get('HTML.Doctype'); if (!empty($doctype)) { return $doctype; } $doctype = $config->get('HTML.CustomDoctype'); if (!empty($doctype)) { return $doctype; } // backwards-compatibility if ($config->get('HTML.XHTML')) { $doctype = 'XHTML 1.0'; } else { $doctype = 'HTML 4.01'; } if ($config->get('HTML.Strict')) { $doctype .= ' Strict'; } else { $doctype .= ' Transitional'; } return $doctype; }
[ "public", "function", "getDoctypeFromConfig", "(", "$", "config", ")", "{", "// recommended test", "$", "doctype", "=", "$", "config", "->", "get", "(", "'HTML.Doctype'", ")", ";", "if", "(", "!", "empty", "(", "$", "doctype", ")", ")", "{", "return", "$", "doctype", ";", "}", "$", "doctype", "=", "$", "config", "->", "get", "(", "'HTML.CustomDoctype'", ")", ";", "if", "(", "!", "empty", "(", "$", "doctype", ")", ")", "{", "return", "$", "doctype", ";", "}", "// backwards-compatibility", "if", "(", "$", "config", "->", "get", "(", "'HTML.XHTML'", ")", ")", "{", "$", "doctype", "=", "'XHTML 1.0'", ";", "}", "else", "{", "$", "doctype", "=", "'HTML 4.01'", ";", "}", "if", "(", "$", "config", "->", "get", "(", "'HTML.Strict'", ")", ")", "{", "$", "doctype", ".=", "' Strict'", ";", "}", "else", "{", "$", "doctype", ".=", "' Transitional'", ";", "}", "return", "$", "doctype", ";", "}" ]
Retrieves the doctype from the configuration object @param HTMLPurifier_Config $config @return string
[ "Retrieves", "the", "doctype", "from", "the", "configuration", "object" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/DoctypeRegistry.php#L116-L139
217,951
moodle/moodle
message/renderer.php
core_message_renderer.manage_messageoutput_settings
public function manage_messageoutput_settings($allprocessors, $processors, $providers, $preferences) { $output = html_writer::start_tag('form', array('id' => 'defaultmessageoutputs', 'method' => 'post')); $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())); // Add message output processors enabled/disabled and settings. $output .= $this->heading(get_string('messageoutputs', 'message')); $output .= $this->manage_messageoutputs($allprocessors); // Add active message output processors settings. $output .= $this->heading(get_string('managemessageoutputs', 'message')); $output .= $this->manage_defaultmessageoutputs($processors, $providers, $preferences); $output .= html_writer::start_tag('div', array('class' => 'form-buttons')); $output .= html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('savechanges', 'admin'), 'class' => 'form-submit btn btn-primary') ); $output .= html_writer::end_tag('div'); $output .= html_writer::end_tag('form'); return $output; }
php
public function manage_messageoutput_settings($allprocessors, $processors, $providers, $preferences) { $output = html_writer::start_tag('form', array('id' => 'defaultmessageoutputs', 'method' => 'post')); $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())); // Add message output processors enabled/disabled and settings. $output .= $this->heading(get_string('messageoutputs', 'message')); $output .= $this->manage_messageoutputs($allprocessors); // Add active message output processors settings. $output .= $this->heading(get_string('managemessageoutputs', 'message')); $output .= $this->manage_defaultmessageoutputs($processors, $providers, $preferences); $output .= html_writer::start_tag('div', array('class' => 'form-buttons')); $output .= html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('savechanges', 'admin'), 'class' => 'form-submit btn btn-primary') ); $output .= html_writer::end_tag('div'); $output .= html_writer::end_tag('form'); return $output; }
[ "public", "function", "manage_messageoutput_settings", "(", "$", "allprocessors", ",", "$", "processors", ",", "$", "providers", ",", "$", "preferences", ")", "{", "$", "output", "=", "html_writer", "::", "start_tag", "(", "'form'", ",", "array", "(", "'id'", "=>", "'defaultmessageoutputs'", ",", "'method'", "=>", "'post'", ")", ")", ";", "$", "output", ".=", "html_writer", "::", "empty_tag", "(", "'input'", ",", "array", "(", "'type'", "=>", "'hidden'", ",", "'name'", "=>", "'sesskey'", ",", "'value'", "=>", "sesskey", "(", ")", ")", ")", ";", "// Add message output processors enabled/disabled and settings.", "$", "output", ".=", "$", "this", "->", "heading", "(", "get_string", "(", "'messageoutputs'", ",", "'message'", ")", ")", ";", "$", "output", ".=", "$", "this", "->", "manage_messageoutputs", "(", "$", "allprocessors", ")", ";", "// Add active message output processors settings.", "$", "output", ".=", "$", "this", "->", "heading", "(", "get_string", "(", "'managemessageoutputs'", ",", "'message'", ")", ")", ";", "$", "output", ".=", "$", "this", "->", "manage_defaultmessageoutputs", "(", "$", "processors", ",", "$", "providers", ",", "$", "preferences", ")", ";", "$", "output", ".=", "html_writer", "::", "start_tag", "(", "'div'", ",", "array", "(", "'class'", "=>", "'form-buttons'", ")", ")", ";", "$", "output", ".=", "html_writer", "::", "empty_tag", "(", "'input'", ",", "array", "(", "'type'", "=>", "'submit'", ",", "'value'", "=>", "get_string", "(", "'savechanges'", ",", "'admin'", ")", ",", "'class'", "=>", "'form-submit btn btn-primary'", ")", ")", ";", "$", "output", ".=", "html_writer", "::", "end_tag", "(", "'div'", ")", ";", "$", "output", ".=", "html_writer", "::", "end_tag", "(", "'form'", ")", ";", "return", "$", "output", ";", "}" ]
Display the interface to manage both message outputs and default message outputs @param array $allprocessors array of objects containing all message processors @param array $processors array of objects containing active message processors @param array $providers array of objects containing message providers @param array $preferences array of objects containing current preferences @return string The text to render
[ "Display", "the", "interface", "to", "manage", "both", "message", "outputs", "and", "default", "message", "outputs" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/renderer.php#L48-L68
217,952
moodle/moodle
message/renderer.php
core_message_renderer.manage_messageoutputs
public function manage_messageoutputs($processors) { // Display the current workflows $table = new html_table(); $table->attributes['class'] = 'admintable generaltable'; $table->data = array(); $table->head = array( get_string('name'), get_string('enable'), get_string('settings'), ); $table->colclasses = array( 'displayname', 'availability', 'settings', ); foreach ($processors as $processor) { $row = new html_table_row(); $row->attributes['class'] = 'messageoutputs'; $name = new html_table_cell(get_string('pluginname', 'message_'.$processor->name)); $enable = new html_table_cell(); if (!$processor->available) { $enable->text = html_writer::nonempty_tag('span', get_string('outputnotavailable', 'message'), array('class' => 'error') ); } else { $enable->text = html_writer::checkbox($processor->name, $processor->id, $processor->enabled, '', array('id' => $processor->name) ); } // Settings $settings = new html_table_cell(); if ($processor->available && $processor->hassettings) { $settingsurl = new moodle_url('/admin/settings.php', array('section' => 'messagesetting'.$processor->name)); $settings->text = html_writer::link($settingsurl, get_string('settings', 'message')); } $row->cells = array($name, $enable, $settings); $table->data[] = $row; } return html_writer::table($table); }
php
public function manage_messageoutputs($processors) { // Display the current workflows $table = new html_table(); $table->attributes['class'] = 'admintable generaltable'; $table->data = array(); $table->head = array( get_string('name'), get_string('enable'), get_string('settings'), ); $table->colclasses = array( 'displayname', 'availability', 'settings', ); foreach ($processors as $processor) { $row = new html_table_row(); $row->attributes['class'] = 'messageoutputs'; $name = new html_table_cell(get_string('pluginname', 'message_'.$processor->name)); $enable = new html_table_cell(); if (!$processor->available) { $enable->text = html_writer::nonempty_tag('span', get_string('outputnotavailable', 'message'), array('class' => 'error') ); } else { $enable->text = html_writer::checkbox($processor->name, $processor->id, $processor->enabled, '', array('id' => $processor->name) ); } // Settings $settings = new html_table_cell(); if ($processor->available && $processor->hassettings) { $settingsurl = new moodle_url('/admin/settings.php', array('section' => 'messagesetting'.$processor->name)); $settings->text = html_writer::link($settingsurl, get_string('settings', 'message')); } $row->cells = array($name, $enable, $settings); $table->data[] = $row; } return html_writer::table($table); }
[ "public", "function", "manage_messageoutputs", "(", "$", "processors", ")", "{", "// Display the current workflows", "$", "table", "=", "new", "html_table", "(", ")", ";", "$", "table", "->", "attributes", "[", "'class'", "]", "=", "'admintable generaltable'", ";", "$", "table", "->", "data", "=", "array", "(", ")", ";", "$", "table", "->", "head", "=", "array", "(", "get_string", "(", "'name'", ")", ",", "get_string", "(", "'enable'", ")", ",", "get_string", "(", "'settings'", ")", ",", ")", ";", "$", "table", "->", "colclasses", "=", "array", "(", "'displayname'", ",", "'availability'", ",", "'settings'", ",", ")", ";", "foreach", "(", "$", "processors", "as", "$", "processor", ")", "{", "$", "row", "=", "new", "html_table_row", "(", ")", ";", "$", "row", "->", "attributes", "[", "'class'", "]", "=", "'messageoutputs'", ";", "$", "name", "=", "new", "html_table_cell", "(", "get_string", "(", "'pluginname'", ",", "'message_'", ".", "$", "processor", "->", "name", ")", ")", ";", "$", "enable", "=", "new", "html_table_cell", "(", ")", ";", "if", "(", "!", "$", "processor", "->", "available", ")", "{", "$", "enable", "->", "text", "=", "html_writer", "::", "nonempty_tag", "(", "'span'", ",", "get_string", "(", "'outputnotavailable'", ",", "'message'", ")", ",", "array", "(", "'class'", "=>", "'error'", ")", ")", ";", "}", "else", "{", "$", "enable", "->", "text", "=", "html_writer", "::", "checkbox", "(", "$", "processor", "->", "name", ",", "$", "processor", "->", "id", ",", "$", "processor", "->", "enabled", ",", "''", ",", "array", "(", "'id'", "=>", "$", "processor", "->", "name", ")", ")", ";", "}", "// Settings", "$", "settings", "=", "new", "html_table_cell", "(", ")", ";", "if", "(", "$", "processor", "->", "available", "&&", "$", "processor", "->", "hassettings", ")", "{", "$", "settingsurl", "=", "new", "moodle_url", "(", "'/admin/settings.php'", ",", "array", "(", "'section'", "=>", "'messagesetting'", ".", "$", "processor", "->", "name", ")", ")", ";", "$", "settings", "->", "text", "=", "html_writer", "::", "link", "(", "$", "settingsurl", ",", "get_string", "(", "'settings'", ",", "'message'", ")", ")", ";", "}", "$", "row", "->", "cells", "=", "array", "(", "$", "name", ",", "$", "enable", ",", "$", "settings", ")", ";", "$", "table", "->", "data", "[", "]", "=", "$", "row", ";", "}", "return", "html_writer", "::", "table", "(", "$", "table", ")", ";", "}" ]
Display the interface to manage message outputs @param array $processors array of objects containing message processors @return string The text to render
[ "Display", "the", "interface", "to", "manage", "message", "outputs" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/renderer.php#L76-L116
217,953
moodle/moodle
message/renderer.php
core_message_renderer.render_user_notification_preferences
public function render_user_notification_preferences($user) { $processors = get_message_processors(); $providers = message_get_providers_for_user($user->id); $preferences = \core_message\api::get_all_message_preferences($processors, $providers, $user); $notificationlistoutput = new \core_message\output\preferences\notification_list($processors, $providers, $preferences, $user); return $this->render_from_template('message/notification_preferences', $notificationlistoutput->export_for_template($this)); }
php
public function render_user_notification_preferences($user) { $processors = get_message_processors(); $providers = message_get_providers_for_user($user->id); $preferences = \core_message\api::get_all_message_preferences($processors, $providers, $user); $notificationlistoutput = new \core_message\output\preferences\notification_list($processors, $providers, $preferences, $user); return $this->render_from_template('message/notification_preferences', $notificationlistoutput->export_for_template($this)); }
[ "public", "function", "render_user_notification_preferences", "(", "$", "user", ")", "{", "$", "processors", "=", "get_message_processors", "(", ")", ";", "$", "providers", "=", "message_get_providers_for_user", "(", "$", "user", "->", "id", ")", ";", "$", "preferences", "=", "\\", "core_message", "\\", "api", "::", "get_all_message_preferences", "(", "$", "processors", ",", "$", "providers", ",", "$", "user", ")", ";", "$", "notificationlistoutput", "=", "new", "\\", "core_message", "\\", "output", "\\", "preferences", "\\", "notification_list", "(", "$", "processors", ",", "$", "providers", ",", "$", "preferences", ",", "$", "user", ")", ";", "return", "$", "this", "->", "render_from_template", "(", "'message/notification_preferences'", ",", "$", "notificationlistoutput", "->", "export_for_template", "(", "$", "this", ")", ")", ";", "}" ]
Display the interface for notification preferences @param object $user instance of a user @return string The text to render
[ "Display", "the", "interface", "for", "notification", "preferences" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/renderer.php#L226-L235
217,954
moodle/moodle
message/renderer.php
core_message_renderer.render_user_message_preferences
public function render_user_message_preferences($user) { global $CFG; // Filter out enabled, available system_configured and user_configured processors only. $readyprocessors = array_filter(get_message_processors(), function($processor) { return $processor->enabled && $processor->configured && $processor->object->is_user_configured() && // Filter out processors that don't have and message preferences to configure. $processor->object->has_message_preferences(); }); $providers = array_filter(message_get_providers_for_user($user->id), function($provider) { return $provider->component === 'moodle'; }); $preferences = \core_message\api::get_all_message_preferences($readyprocessors, $providers, $user); $notificationlistoutput = new \core_message\output\preferences\message_notification_list($readyprocessors, $providers, $preferences, $user); $context = $notificationlistoutput->export_for_template($this); // Get the privacy settings options for being messaged. $privacysetting = \core_message\api::get_user_privacy_messaging_preference($user->id); $choices = array(); $choices[] = [ 'value' => \core_message\api::MESSAGE_PRIVACY_ONLYCONTACTS, 'text' => get_string('contactableprivacy_onlycontacts', 'message'), 'checked' => ($privacysetting == \core_message\api::MESSAGE_PRIVACY_ONLYCONTACTS) ]; $choices[] = [ 'value' => \core_message\api::MESSAGE_PRIVACY_COURSEMEMBER, 'text' => get_string('contactableprivacy_coursemember', 'message'), 'checked' => ($privacysetting == \core_message\api::MESSAGE_PRIVACY_COURSEMEMBER) ]; if (!empty($CFG->messagingallusers)) { // Add the MESSAGE_PRIVACY_SITE option when site-wide messaging between users is enabled. $choices[] = [ 'value' => \core_message\api::MESSAGE_PRIVACY_SITE, 'text' => get_string('contactableprivacy_site', 'message'), 'checked' => ($privacysetting == \core_message\api::MESSAGE_PRIVACY_SITE) ]; } $context['privacychoices'] = $choices; return $this->render_from_template('message/message_preferences', $context); }
php
public function render_user_message_preferences($user) { global $CFG; // Filter out enabled, available system_configured and user_configured processors only. $readyprocessors = array_filter(get_message_processors(), function($processor) { return $processor->enabled && $processor->configured && $processor->object->is_user_configured() && // Filter out processors that don't have and message preferences to configure. $processor->object->has_message_preferences(); }); $providers = array_filter(message_get_providers_for_user($user->id), function($provider) { return $provider->component === 'moodle'; }); $preferences = \core_message\api::get_all_message_preferences($readyprocessors, $providers, $user); $notificationlistoutput = new \core_message\output\preferences\message_notification_list($readyprocessors, $providers, $preferences, $user); $context = $notificationlistoutput->export_for_template($this); // Get the privacy settings options for being messaged. $privacysetting = \core_message\api::get_user_privacy_messaging_preference($user->id); $choices = array(); $choices[] = [ 'value' => \core_message\api::MESSAGE_PRIVACY_ONLYCONTACTS, 'text' => get_string('contactableprivacy_onlycontacts', 'message'), 'checked' => ($privacysetting == \core_message\api::MESSAGE_PRIVACY_ONLYCONTACTS) ]; $choices[] = [ 'value' => \core_message\api::MESSAGE_PRIVACY_COURSEMEMBER, 'text' => get_string('contactableprivacy_coursemember', 'message'), 'checked' => ($privacysetting == \core_message\api::MESSAGE_PRIVACY_COURSEMEMBER) ]; if (!empty($CFG->messagingallusers)) { // Add the MESSAGE_PRIVACY_SITE option when site-wide messaging between users is enabled. $choices[] = [ 'value' => \core_message\api::MESSAGE_PRIVACY_SITE, 'text' => get_string('contactableprivacy_site', 'message'), 'checked' => ($privacysetting == \core_message\api::MESSAGE_PRIVACY_SITE) ]; } $context['privacychoices'] = $choices; return $this->render_from_template('message/message_preferences', $context); }
[ "public", "function", "render_user_message_preferences", "(", "$", "user", ")", "{", "global", "$", "CFG", ";", "// Filter out enabled, available system_configured and user_configured processors only.", "$", "readyprocessors", "=", "array_filter", "(", "get_message_processors", "(", ")", ",", "function", "(", "$", "processor", ")", "{", "return", "$", "processor", "->", "enabled", "&&", "$", "processor", "->", "configured", "&&", "$", "processor", "->", "object", "->", "is_user_configured", "(", ")", "&&", "// Filter out processors that don't have and message preferences to configure.", "$", "processor", "->", "object", "->", "has_message_preferences", "(", ")", ";", "}", ")", ";", "$", "providers", "=", "array_filter", "(", "message_get_providers_for_user", "(", "$", "user", "->", "id", ")", ",", "function", "(", "$", "provider", ")", "{", "return", "$", "provider", "->", "component", "===", "'moodle'", ";", "}", ")", ";", "$", "preferences", "=", "\\", "core_message", "\\", "api", "::", "get_all_message_preferences", "(", "$", "readyprocessors", ",", "$", "providers", ",", "$", "user", ")", ";", "$", "notificationlistoutput", "=", "new", "\\", "core_message", "\\", "output", "\\", "preferences", "\\", "message_notification_list", "(", "$", "readyprocessors", ",", "$", "providers", ",", "$", "preferences", ",", "$", "user", ")", ";", "$", "context", "=", "$", "notificationlistoutput", "->", "export_for_template", "(", "$", "this", ")", ";", "// Get the privacy settings options for being messaged.", "$", "privacysetting", "=", "\\", "core_message", "\\", "api", "::", "get_user_privacy_messaging_preference", "(", "$", "user", "->", "id", ")", ";", "$", "choices", "=", "array", "(", ")", ";", "$", "choices", "[", "]", "=", "[", "'value'", "=>", "\\", "core_message", "\\", "api", "::", "MESSAGE_PRIVACY_ONLYCONTACTS", ",", "'text'", "=>", "get_string", "(", "'contactableprivacy_onlycontacts'", ",", "'message'", ")", ",", "'checked'", "=>", "(", "$", "privacysetting", "==", "\\", "core_message", "\\", "api", "::", "MESSAGE_PRIVACY_ONLYCONTACTS", ")", "]", ";", "$", "choices", "[", "]", "=", "[", "'value'", "=>", "\\", "core_message", "\\", "api", "::", "MESSAGE_PRIVACY_COURSEMEMBER", ",", "'text'", "=>", "get_string", "(", "'contactableprivacy_coursemember'", ",", "'message'", ")", ",", "'checked'", "=>", "(", "$", "privacysetting", "==", "\\", "core_message", "\\", "api", "::", "MESSAGE_PRIVACY_COURSEMEMBER", ")", "]", ";", "if", "(", "!", "empty", "(", "$", "CFG", "->", "messagingallusers", ")", ")", "{", "// Add the MESSAGE_PRIVACY_SITE option when site-wide messaging between users is enabled.", "$", "choices", "[", "]", "=", "[", "'value'", "=>", "\\", "core_message", "\\", "api", "::", "MESSAGE_PRIVACY_SITE", ",", "'text'", "=>", "get_string", "(", "'contactableprivacy_site'", ",", "'message'", ")", ",", "'checked'", "=>", "(", "$", "privacysetting", "==", "\\", "core_message", "\\", "api", "::", "MESSAGE_PRIVACY_SITE", ")", "]", ";", "}", "$", "context", "[", "'privacychoices'", "]", "=", "$", "choices", ";", "return", "$", "this", "->", "render_from_template", "(", "'message/message_preferences'", ",", "$", "context", ")", ";", "}" ]
Display the interface for message preferences @param object $user instance of a user @return string The text to render
[ "Display", "the", "interface", "for", "message", "preferences" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/renderer.php#L243-L287
217,955
moodle/moodle
lib/pear/HTML/QuickForm/utils.php
HTML_QuickForm_utils.pathGet
static function pathGet($values, $path, $default = NULL) { foreach ($path as $key) { if (!is_array($values) || !isset($values[$key])) { return $default; } $values = $values[$key]; } return $values; }
php
static function pathGet($values, $path, $default = NULL) { foreach ($path as $key) { if (!is_array($values) || !isset($values[$key])) { return $default; } $values = $values[$key]; } return $values; }
[ "static", "function", "pathGet", "(", "$", "values", ",", "$", "path", ",", "$", "default", "=", "NULL", ")", "{", "foreach", "(", "$", "path", "as", "$", "key", ")", "{", "if", "(", "!", "is_array", "(", "$", "values", ")", "||", "!", "isset", "(", "$", "values", "[", "$", "key", "]", ")", ")", "{", "return", "$", "default", ";", "}", "$", "values", "=", "$", "values", "[", "$", "key", "]", ";", "}", "return", "$", "values", ";", "}" ]
Get a single value from an array-tree. @param array $values Ex: ['foo' => ['bar' => 123]]. @param array $path Ex: ['foo', 'bar']. @param mixed $default @return mixed Ex 123. @access public @static
[ "Get", "a", "single", "value", "from", "an", "array", "-", "tree", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/utils.php#L48-L56
217,956
moodle/moodle
lib/pear/HTML/QuickForm/utils.php
HTML_QuickForm_utils.pathIsset
static function pathIsset($values, $path) { foreach ($path as $key) { if (!is_array($values) || !isset($values[$key])) { return FALSE; } $values = $values[$key]; } return TRUE; }
php
static function pathIsset($values, $path) { foreach ($path as $key) { if (!is_array($values) || !isset($values[$key])) { return FALSE; } $values = $values[$key]; } return TRUE; }
[ "static", "function", "pathIsset", "(", "$", "values", ",", "$", "path", ")", "{", "foreach", "(", "$", "path", "as", "$", "key", ")", "{", "if", "(", "!", "is_array", "(", "$", "values", ")", "||", "!", "isset", "(", "$", "values", "[", "$", "key", "]", ")", ")", "{", "return", "FALSE", ";", "}", "$", "values", "=", "$", "values", "[", "$", "key", "]", ";", "}", "return", "TRUE", ";", "}" ]
Check if a key isset which may be several layers deep. This is a helper for when the calling function does not know how many layers deep the path array is so cannot easily check. @param array $values @param array $path @return bool @access public @static
[ "Check", "if", "a", "key", "isset", "which", "may", "be", "several", "layers", "deep", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/utils.php#L71-L79
217,957
moodle/moodle
lib/pear/HTML/QuickForm/utils.php
HTML_QuickForm_utils.pathSet
static function pathSet(&$values, $pathParts, $value) { $r = &$values; $last = array_pop($pathParts); foreach ($pathParts as $part) { if (!isset($r[$part])) { $r[$part] = array(); } $r = &$r[$part]; } $r[$last] = $value; }
php
static function pathSet(&$values, $pathParts, $value) { $r = &$values; $last = array_pop($pathParts); foreach ($pathParts as $part) { if (!isset($r[$part])) { $r[$part] = array(); } $r = &$r[$part]; } $r[$last] = $value; }
[ "static", "function", "pathSet", "(", "&", "$", "values", ",", "$", "pathParts", ",", "$", "value", ")", "{", "$", "r", "=", "&", "$", "values", ";", "$", "last", "=", "array_pop", "(", "$", "pathParts", ")", ";", "foreach", "(", "$", "pathParts", "as", "$", "part", ")", "{", "if", "(", "!", "isset", "(", "$", "r", "[", "$", "part", "]", ")", ")", "{", "$", "r", "[", "$", "part", "]", "=", "array", "(", ")", ";", "}", "$", "r", "=", "&", "$", "r", "[", "$", "part", "]", ";", "}", "$", "r", "[", "$", "last", "]", "=", "$", "value", ";", "}" ]
Set a single value in an array tree. @param array $values Ex: ['foo' => ['bar' => 123]]. @param array $pathParts Ex: ['foo', 'bar']. @param mixed $value Ex: 456. @return void @access public @static
[ "Set", "a", "single", "value", "in", "an", "array", "tree", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/utils.php#L92-L102
217,958
moodle/moodle
lib/pear/HTML/QuickForm/utils.php
HTML_QuickForm_utils.recursiveBuild
static function recursiveBuild($path, $value, $source = array()) { self::pathSet($source, $path, $value); return $source; }
php
static function recursiveBuild($path, $value, $source = array()) { self::pathSet($source, $path, $value); return $source; }
[ "static", "function", "recursiveBuild", "(", "$", "path", ",", "$", "value", ",", "$", "source", "=", "array", "(", ")", ")", "{", "self", "::", "pathSet", "(", "$", "source", ",", "$", "path", ",", "$", "value", ")", ";", "return", "$", "source", ";", "}" ]
Append the value to the array using the key provided. e.g if value is 'llama' & path is [0, 'email', 'location'] result will be [0 => ['email' => ['location' => 'llama']] @param $path @param $value @param array $source @return array @access public @static
[ "Append", "the", "value", "to", "the", "array", "using", "the", "key", "provided", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/utils.php#L154-L157
217,959
moodle/moodle
mod/choice/classes/external.php
mod_choice_external.submit_choice_response
public static function submit_choice_response($choiceid, $responses) { global $USER; $warnings = array(); $params = self::validate_parameters(self::submit_choice_response_parameters(), array( 'choiceid' => $choiceid, 'responses' => $responses )); if (!$choice = choice_get_choice($params['choiceid'])) { throw new moodle_exception("invalidcoursemodule", "error"); } list($course, $cm) = get_course_and_cm_from_instance($choice, 'choice'); $context = context_module::instance($cm->id); self::validate_context($context); require_capability('mod/choice:choose', $context); $timenow = time(); if (!empty($choice->timeopen) && ($choice->timeopen > $timenow)) { throw new moodle_exception("notopenyet", "choice", '', userdate($choice->timeopen)); } else if (!empty($choice->timeclose) && ($timenow > $choice->timeclose)) { throw new moodle_exception("expired", "choice", '', userdate($choice->timeclose)); } if (!choice_get_my_response($choice) or $choice->allowupdate) { // When a single response is given, we convert the array to a simple variable // in order to avoid choice_user_submit_response to check with allowmultiple even // for a single response. if (count($params['responses']) == 1) { $params['responses'] = reset($params['responses']); } choice_user_submit_response($params['responses'], $choice, $USER->id, $course, $cm); } else { throw new moodle_exception('missingrequiredcapability', 'webservice', '', 'allowupdate'); } $answers = choice_get_my_response($choice); return array( 'answers' => $answers, 'warnings' => $warnings ); }
php
public static function submit_choice_response($choiceid, $responses) { global $USER; $warnings = array(); $params = self::validate_parameters(self::submit_choice_response_parameters(), array( 'choiceid' => $choiceid, 'responses' => $responses )); if (!$choice = choice_get_choice($params['choiceid'])) { throw new moodle_exception("invalidcoursemodule", "error"); } list($course, $cm) = get_course_and_cm_from_instance($choice, 'choice'); $context = context_module::instance($cm->id); self::validate_context($context); require_capability('mod/choice:choose', $context); $timenow = time(); if (!empty($choice->timeopen) && ($choice->timeopen > $timenow)) { throw new moodle_exception("notopenyet", "choice", '', userdate($choice->timeopen)); } else if (!empty($choice->timeclose) && ($timenow > $choice->timeclose)) { throw new moodle_exception("expired", "choice", '', userdate($choice->timeclose)); } if (!choice_get_my_response($choice) or $choice->allowupdate) { // When a single response is given, we convert the array to a simple variable // in order to avoid choice_user_submit_response to check with allowmultiple even // for a single response. if (count($params['responses']) == 1) { $params['responses'] = reset($params['responses']); } choice_user_submit_response($params['responses'], $choice, $USER->id, $course, $cm); } else { throw new moodle_exception('missingrequiredcapability', 'webservice', '', 'allowupdate'); } $answers = choice_get_my_response($choice); return array( 'answers' => $answers, 'warnings' => $warnings ); }
[ "public", "static", "function", "submit_choice_response", "(", "$", "choiceid", ",", "$", "responses", ")", "{", "global", "$", "USER", ";", "$", "warnings", "=", "array", "(", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "submit_choice_response_parameters", "(", ")", ",", "array", "(", "'choiceid'", "=>", "$", "choiceid", ",", "'responses'", "=>", "$", "responses", ")", ")", ";", "if", "(", "!", "$", "choice", "=", "choice_get_choice", "(", "$", "params", "[", "'choiceid'", "]", ")", ")", "{", "throw", "new", "moodle_exception", "(", "\"invalidcoursemodule\"", ",", "\"error\"", ")", ";", "}", "list", "(", "$", "course", ",", "$", "cm", ")", "=", "get_course_and_cm_from_instance", "(", "$", "choice", ",", "'choice'", ")", ";", "$", "context", "=", "context_module", "::", "instance", "(", "$", "cm", "->", "id", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "require_capability", "(", "'mod/choice:choose'", ",", "$", "context", ")", ";", "$", "timenow", "=", "time", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "choice", "->", "timeopen", ")", "&&", "(", "$", "choice", "->", "timeopen", ">", "$", "timenow", ")", ")", "{", "throw", "new", "moodle_exception", "(", "\"notopenyet\"", ",", "\"choice\"", ",", "''", ",", "userdate", "(", "$", "choice", "->", "timeopen", ")", ")", ";", "}", "else", "if", "(", "!", "empty", "(", "$", "choice", "->", "timeclose", ")", "&&", "(", "$", "timenow", ">", "$", "choice", "->", "timeclose", ")", ")", "{", "throw", "new", "moodle_exception", "(", "\"expired\"", ",", "\"choice\"", ",", "''", ",", "userdate", "(", "$", "choice", "->", "timeclose", ")", ")", ";", "}", "if", "(", "!", "choice_get_my_response", "(", "$", "choice", ")", "or", "$", "choice", "->", "allowupdate", ")", "{", "// When a single response is given, we convert the array to a simple variable", "// in order to avoid choice_user_submit_response to check with allowmultiple even", "// for a single response.", "if", "(", "count", "(", "$", "params", "[", "'responses'", "]", ")", "==", "1", ")", "{", "$", "params", "[", "'responses'", "]", "=", "reset", "(", "$", "params", "[", "'responses'", "]", ")", ";", "}", "choice_user_submit_response", "(", "$", "params", "[", "'responses'", "]", ",", "$", "choice", ",", "$", "USER", "->", "id", ",", "$", "course", ",", "$", "cm", ")", ";", "}", "else", "{", "throw", "new", "moodle_exception", "(", "'missingrequiredcapability'", ",", "'webservice'", ",", "''", ",", "'allowupdate'", ")", ";", "}", "$", "answers", "=", "choice_get_my_response", "(", "$", "choice", ")", ";", "return", "array", "(", "'answers'", "=>", "$", "answers", ",", "'warnings'", "=>", "$", "warnings", ")", ";", "}" ]
Submit choice responses @param int $choiceid the choice instance id @param array $responses the response ids @return array answers information and warnings @since Moodle 3.0
[ "Submit", "choice", "responses" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/choice/classes/external.php#L314-L358
217,960
moodle/moodle
mod/choice/classes/external.php
mod_choice_external.submit_choice_response_returns
public static function submit_choice_response_returns() { return new external_single_structure( array( 'answers' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'answer id'), 'choiceid' => new external_value(PARAM_INT, 'choiceid'), 'userid' => new external_value(PARAM_INT, 'user id'), 'optionid' => new external_value(PARAM_INT, 'optionid'), 'timemodified' => new external_value(PARAM_INT, 'time of last modification') ), 'Answers' ) ), 'warnings' => new external_warnings(), ) ); }
php
public static function submit_choice_response_returns() { return new external_single_structure( array( 'answers' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'answer id'), 'choiceid' => new external_value(PARAM_INT, 'choiceid'), 'userid' => new external_value(PARAM_INT, 'user id'), 'optionid' => new external_value(PARAM_INT, 'optionid'), 'timemodified' => new external_value(PARAM_INT, 'time of last modification') ), 'Answers' ) ), 'warnings' => new external_warnings(), ) ); }
[ "public", "static", "function", "submit_choice_response_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'answers'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'answer id'", ")", ",", "'choiceid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'choiceid'", ")", ",", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'user id'", ")", ",", "'optionid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'optionid'", ")", ",", "'timemodified'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'time of last modification'", ")", ")", ",", "'Answers'", ")", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ",", ")", ")", ";", "}" ]
Describes the submit_choice_response return value. @return external_multiple_structure @since Moodle 3.0
[ "Describes", "the", "submit_choice_response", "return", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/choice/classes/external.php#L366-L383
217,961
moodle/moodle
mod/choice/classes/external.php
mod_choice_external.get_choices_by_courses_returns
public static function get_choices_by_courses_returns() { return new external_single_structure( array( 'choices' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'Choice instance id'), 'coursemodule' => new external_value(PARAM_INT, 'Course module id'), 'course' => new external_value(PARAM_INT, 'Course id'), 'name' => new external_value(PARAM_RAW, 'Choice name'), 'intro' => new external_value(PARAM_RAW, 'The choice intro'), 'introformat' => new external_format_value('intro'), 'introfiles' => new external_files('Files in the introduction text', VALUE_OPTIONAL), 'publish' => new external_value(PARAM_BOOL, 'If choice is published', VALUE_OPTIONAL), 'showresults' => new external_value(PARAM_INT, '0 never, 1 after answer, 2 after close, 3 always', VALUE_OPTIONAL), 'display' => new external_value(PARAM_INT, 'Display mode (vertical, horizontal)', VALUE_OPTIONAL), 'allowupdate' => new external_value(PARAM_BOOL, 'Allow update', VALUE_OPTIONAL), 'allowmultiple' => new external_value(PARAM_BOOL, 'Allow multiple choices', VALUE_OPTIONAL), 'showunanswered' => new external_value(PARAM_BOOL, 'Show users who not answered yet', VALUE_OPTIONAL), 'includeinactive' => new external_value(PARAM_BOOL, 'Include inactive users', VALUE_OPTIONAL), 'limitanswers' => new external_value(PARAM_BOOL, 'Limit unswers', VALUE_OPTIONAL), 'timeopen' => new external_value(PARAM_INT, 'Date of opening validity', VALUE_OPTIONAL), 'timeclose' => new external_value(PARAM_INT, 'Date of closing validity', VALUE_OPTIONAL), 'showpreview' => new external_value(PARAM_BOOL, 'Show preview before timeopen', VALUE_OPTIONAL), 'timemodified' => new external_value(PARAM_INT, 'Time of last modification', VALUE_OPTIONAL), 'completionsubmit' => new external_value(PARAM_BOOL, 'Completion on user submission', VALUE_OPTIONAL), 'section' => new external_value(PARAM_INT, 'Course section id', VALUE_OPTIONAL), 'visible' => new external_value(PARAM_BOOL, 'Visible', VALUE_OPTIONAL), 'groupmode' => new external_value(PARAM_INT, 'Group mode', VALUE_OPTIONAL), 'groupingid' => new external_value(PARAM_INT, 'Group id', VALUE_OPTIONAL), ), 'Choices' ) ), 'warnings' => new external_warnings(), ) ); }
php
public static function get_choices_by_courses_returns() { return new external_single_structure( array( 'choices' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'Choice instance id'), 'coursemodule' => new external_value(PARAM_INT, 'Course module id'), 'course' => new external_value(PARAM_INT, 'Course id'), 'name' => new external_value(PARAM_RAW, 'Choice name'), 'intro' => new external_value(PARAM_RAW, 'The choice intro'), 'introformat' => new external_format_value('intro'), 'introfiles' => new external_files('Files in the introduction text', VALUE_OPTIONAL), 'publish' => new external_value(PARAM_BOOL, 'If choice is published', VALUE_OPTIONAL), 'showresults' => new external_value(PARAM_INT, '0 never, 1 after answer, 2 after close, 3 always', VALUE_OPTIONAL), 'display' => new external_value(PARAM_INT, 'Display mode (vertical, horizontal)', VALUE_OPTIONAL), 'allowupdate' => new external_value(PARAM_BOOL, 'Allow update', VALUE_OPTIONAL), 'allowmultiple' => new external_value(PARAM_BOOL, 'Allow multiple choices', VALUE_OPTIONAL), 'showunanswered' => new external_value(PARAM_BOOL, 'Show users who not answered yet', VALUE_OPTIONAL), 'includeinactive' => new external_value(PARAM_BOOL, 'Include inactive users', VALUE_OPTIONAL), 'limitanswers' => new external_value(PARAM_BOOL, 'Limit unswers', VALUE_OPTIONAL), 'timeopen' => new external_value(PARAM_INT, 'Date of opening validity', VALUE_OPTIONAL), 'timeclose' => new external_value(PARAM_INT, 'Date of closing validity', VALUE_OPTIONAL), 'showpreview' => new external_value(PARAM_BOOL, 'Show preview before timeopen', VALUE_OPTIONAL), 'timemodified' => new external_value(PARAM_INT, 'Time of last modification', VALUE_OPTIONAL), 'completionsubmit' => new external_value(PARAM_BOOL, 'Completion on user submission', VALUE_OPTIONAL), 'section' => new external_value(PARAM_INT, 'Course section id', VALUE_OPTIONAL), 'visible' => new external_value(PARAM_BOOL, 'Visible', VALUE_OPTIONAL), 'groupmode' => new external_value(PARAM_INT, 'Group mode', VALUE_OPTIONAL), 'groupingid' => new external_value(PARAM_INT, 'Group id', VALUE_OPTIONAL), ), 'Choices' ) ), 'warnings' => new external_warnings(), ) ); }
[ "public", "static", "function", "get_choices_by_courses_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'choices'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Choice instance id'", ")", ",", "'coursemodule'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Course module id'", ")", ",", "'course'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Course id'", ")", ",", "'name'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Choice name'", ")", ",", "'intro'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'The choice intro'", ")", ",", "'introformat'", "=>", "new", "external_format_value", "(", "'intro'", ")", ",", "'introfiles'", "=>", "new", "external_files", "(", "'Files in the introduction text'", ",", "VALUE_OPTIONAL", ")", ",", "'publish'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'If choice is published'", ",", "VALUE_OPTIONAL", ")", ",", "'showresults'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'0 never, 1 after answer, 2 after close, 3 always'", ",", "VALUE_OPTIONAL", ")", ",", "'display'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Display mode (vertical, horizontal)'", ",", "VALUE_OPTIONAL", ")", ",", "'allowupdate'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Allow update'", ",", "VALUE_OPTIONAL", ")", ",", "'allowmultiple'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Allow multiple choices'", ",", "VALUE_OPTIONAL", ")", ",", "'showunanswered'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Show users who not answered yet'", ",", "VALUE_OPTIONAL", ")", ",", "'includeinactive'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Include inactive users'", ",", "VALUE_OPTIONAL", ")", ",", "'limitanswers'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Limit unswers'", ",", "VALUE_OPTIONAL", ")", ",", "'timeopen'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Date of opening validity'", ",", "VALUE_OPTIONAL", ")", ",", "'timeclose'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Date of closing validity'", ",", "VALUE_OPTIONAL", ")", ",", "'showpreview'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Show preview before timeopen'", ",", "VALUE_OPTIONAL", ")", ",", "'timemodified'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Time of last modification'", ",", "VALUE_OPTIONAL", ")", ",", "'completionsubmit'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Completion on user submission'", ",", "VALUE_OPTIONAL", ")", ",", "'section'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Course section id'", ",", "VALUE_OPTIONAL", ")", ",", "'visible'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Visible'", ",", "VALUE_OPTIONAL", ")", ",", "'groupmode'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Group mode'", ",", "VALUE_OPTIONAL", ")", ",", "'groupingid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Group id'", ",", "VALUE_OPTIONAL", ")", ",", ")", ",", "'Choices'", ")", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ",", ")", ")", ";", "}" ]
Describes the mod_choice_get_choices_by_courses return value. @return external_single_structure @since Moodle 3.0
[ "Describes", "the", "mod_choice_get_choices_by_courses", "return", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/choice/classes/external.php#L548-L585
217,962
moodle/moodle
mod/choice/classes/external.php
mod_choice_external.delete_choice_responses
public static function delete_choice_responses($choiceid, $responses = array()) { $status = false; $warnings = array(); $params = self::validate_parameters(self::delete_choice_responses_parameters(), array( 'choiceid' => $choiceid, 'responses' => $responses )); if (!$choice = choice_get_choice($params['choiceid'])) { throw new moodle_exception("invalidcoursemodule", "error"); } list($course, $cm) = get_course_and_cm_from_instance($choice, 'choice'); $context = context_module::instance($cm->id); self::validate_context($context); require_capability('mod/choice:choose', $context); $candeleteall = has_capability('mod/choice:deleteresponses', $context); if ($candeleteall || $choice->allowupdate) { // Check if we can delete our own responses. if (!$candeleteall) { $timenow = time(); if (!empty($choice->timeclose) && ($timenow > $choice->timeclose)) { throw new moodle_exception("expired", "choice", '', userdate($choice->timeclose)); } } if (empty($params['responses'])) { // No responses indicated so delete only my responses. $todelete = array_keys(choice_get_my_response($choice)); } else { // Fill an array with the responses that can be deleted for this choice. if ($candeleteall) { // Teacher/managers can delete any. $allowedresponses = array_keys(choice_get_all_responses($choice)); } else { // Students can delete only their own responses. $allowedresponses = array_keys(choice_get_my_response($choice)); } $todelete = array(); foreach ($params['responses'] as $response) { if (!in_array($response, $allowedresponses)) { $warnings[] = array( 'item' => 'response', 'itemid' => $response, 'warningcode' => 'nopermissions', 'message' => 'Invalid response id, the response does not exist or you are not allowed to delete it.' ); } else { $todelete[] = $response; } } } $status = choice_delete_responses($todelete, $choice, $cm, $course); } else { // The user requires the capability to delete responses. throw new required_capability_exception($context, 'mod/choice:deleteresponses', 'nopermissions', ''); } return array( 'status' => $status, 'warnings' => $warnings ); }
php
public static function delete_choice_responses($choiceid, $responses = array()) { $status = false; $warnings = array(); $params = self::validate_parameters(self::delete_choice_responses_parameters(), array( 'choiceid' => $choiceid, 'responses' => $responses )); if (!$choice = choice_get_choice($params['choiceid'])) { throw new moodle_exception("invalidcoursemodule", "error"); } list($course, $cm) = get_course_and_cm_from_instance($choice, 'choice'); $context = context_module::instance($cm->id); self::validate_context($context); require_capability('mod/choice:choose', $context); $candeleteall = has_capability('mod/choice:deleteresponses', $context); if ($candeleteall || $choice->allowupdate) { // Check if we can delete our own responses. if (!$candeleteall) { $timenow = time(); if (!empty($choice->timeclose) && ($timenow > $choice->timeclose)) { throw new moodle_exception("expired", "choice", '', userdate($choice->timeclose)); } } if (empty($params['responses'])) { // No responses indicated so delete only my responses. $todelete = array_keys(choice_get_my_response($choice)); } else { // Fill an array with the responses that can be deleted for this choice. if ($candeleteall) { // Teacher/managers can delete any. $allowedresponses = array_keys(choice_get_all_responses($choice)); } else { // Students can delete only their own responses. $allowedresponses = array_keys(choice_get_my_response($choice)); } $todelete = array(); foreach ($params['responses'] as $response) { if (!in_array($response, $allowedresponses)) { $warnings[] = array( 'item' => 'response', 'itemid' => $response, 'warningcode' => 'nopermissions', 'message' => 'Invalid response id, the response does not exist or you are not allowed to delete it.' ); } else { $todelete[] = $response; } } } $status = choice_delete_responses($todelete, $choice, $cm, $course); } else { // The user requires the capability to delete responses. throw new required_capability_exception($context, 'mod/choice:deleteresponses', 'nopermissions', ''); } return array( 'status' => $status, 'warnings' => $warnings ); }
[ "public", "static", "function", "delete_choice_responses", "(", "$", "choiceid", ",", "$", "responses", "=", "array", "(", ")", ")", "{", "$", "status", "=", "false", ";", "$", "warnings", "=", "array", "(", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "delete_choice_responses_parameters", "(", ")", ",", "array", "(", "'choiceid'", "=>", "$", "choiceid", ",", "'responses'", "=>", "$", "responses", ")", ")", ";", "if", "(", "!", "$", "choice", "=", "choice_get_choice", "(", "$", "params", "[", "'choiceid'", "]", ")", ")", "{", "throw", "new", "moodle_exception", "(", "\"invalidcoursemodule\"", ",", "\"error\"", ")", ";", "}", "list", "(", "$", "course", ",", "$", "cm", ")", "=", "get_course_and_cm_from_instance", "(", "$", "choice", ",", "'choice'", ")", ";", "$", "context", "=", "context_module", "::", "instance", "(", "$", "cm", "->", "id", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "require_capability", "(", "'mod/choice:choose'", ",", "$", "context", ")", ";", "$", "candeleteall", "=", "has_capability", "(", "'mod/choice:deleteresponses'", ",", "$", "context", ")", ";", "if", "(", "$", "candeleteall", "||", "$", "choice", "->", "allowupdate", ")", "{", "// Check if we can delete our own responses.", "if", "(", "!", "$", "candeleteall", ")", "{", "$", "timenow", "=", "time", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "choice", "->", "timeclose", ")", "&&", "(", "$", "timenow", ">", "$", "choice", "->", "timeclose", ")", ")", "{", "throw", "new", "moodle_exception", "(", "\"expired\"", ",", "\"choice\"", ",", "''", ",", "userdate", "(", "$", "choice", "->", "timeclose", ")", ")", ";", "}", "}", "if", "(", "empty", "(", "$", "params", "[", "'responses'", "]", ")", ")", "{", "// No responses indicated so delete only my responses.", "$", "todelete", "=", "array_keys", "(", "choice_get_my_response", "(", "$", "choice", ")", ")", ";", "}", "else", "{", "// Fill an array with the responses that can be deleted for this choice.", "if", "(", "$", "candeleteall", ")", "{", "// Teacher/managers can delete any.", "$", "allowedresponses", "=", "array_keys", "(", "choice_get_all_responses", "(", "$", "choice", ")", ")", ";", "}", "else", "{", "// Students can delete only their own responses.", "$", "allowedresponses", "=", "array_keys", "(", "choice_get_my_response", "(", "$", "choice", ")", ")", ";", "}", "$", "todelete", "=", "array", "(", ")", ";", "foreach", "(", "$", "params", "[", "'responses'", "]", "as", "$", "response", ")", "{", "if", "(", "!", "in_array", "(", "$", "response", ",", "$", "allowedresponses", ")", ")", "{", "$", "warnings", "[", "]", "=", "array", "(", "'item'", "=>", "'response'", ",", "'itemid'", "=>", "$", "response", ",", "'warningcode'", "=>", "'nopermissions'", ",", "'message'", "=>", "'Invalid response id, the response does not exist or you are not allowed to delete it.'", ")", ";", "}", "else", "{", "$", "todelete", "[", "]", "=", "$", "response", ";", "}", "}", "}", "$", "status", "=", "choice_delete_responses", "(", "$", "todelete", ",", "$", "choice", ",", "$", "cm", ",", "$", "course", ")", ";", "}", "else", "{", "// The user requires the capability to delete responses.", "throw", "new", "required_capability_exception", "(", "$", "context", ",", "'mod/choice:deleteresponses'", ",", "'nopermissions'", ",", "''", ")", ";", "}", "return", "array", "(", "'status'", "=>", "$", "status", ",", "'warnings'", "=>", "$", "warnings", ")", ";", "}" ]
Delete the given submitted responses in a choice @param int $choiceid the choice instance id @param array $responses the response ids, empty for deleting all the current user responses @return array status information and warnings @throws moodle_exception @since Moodle 3.0
[ "Delete", "the", "given", "submitted", "responses", "in", "a", "choice" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/choice/classes/external.php#L616-L685
217,963
moodle/moodle
lib/classes/antivirus/manager.php
manager.get_enabled
private static function get_enabled() { global $CFG; $active = array(); if (empty($CFG->antiviruses)) { return $active; } foreach (explode(',', $CFG->antiviruses) as $e) { if ($antivirus = self::get_antivirus($e)) { if ($antivirus->is_configured()) { $active[$e] = $antivirus; } } } return $active; }
php
private static function get_enabled() { global $CFG; $active = array(); if (empty($CFG->antiviruses)) { return $active; } foreach (explode(',', $CFG->antiviruses) as $e) { if ($antivirus = self::get_antivirus($e)) { if ($antivirus->is_configured()) { $active[$e] = $antivirus; } } } return $active; }
[ "private", "static", "function", "get_enabled", "(", ")", "{", "global", "$", "CFG", ";", "$", "active", "=", "array", "(", ")", ";", "if", "(", "empty", "(", "$", "CFG", "->", "antiviruses", ")", ")", "{", "return", "$", "active", ";", "}", "foreach", "(", "explode", "(", "','", ",", "$", "CFG", "->", "antiviruses", ")", "as", "$", "e", ")", "{", "if", "(", "$", "antivirus", "=", "self", "::", "get_antivirus", "(", "$", "e", ")", ")", "{", "if", "(", "$", "antivirus", "->", "is_configured", "(", ")", ")", "{", "$", "active", "[", "$", "e", "]", "=", "$", "antivirus", ";", "}", "}", "}", "return", "$", "active", ";", "}" ]
Returns list of enabled antiviruses. @return array Array ('antivirusname'=>stdClass antivirus object).
[ "Returns", "list", "of", "enabled", "antiviruses", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/antivirus/manager.php#L42-L58
217,964
moodle/moodle
lib/classes/antivirus/manager.php
manager.scan_file
public static function scan_file($file, $filename, $deleteinfected) { $antiviruses = self::get_enabled(); foreach ($antiviruses as $antivirus) { $result = $antivirus->scan_file($file, $filename); if ($result === $antivirus::SCAN_RESULT_FOUND) { // Infection found. if ($deleteinfected) { unlink($file); } throw new \core\antivirus\scanner_exception('virusfound', '', array('item' => $filename)); } } }
php
public static function scan_file($file, $filename, $deleteinfected) { $antiviruses = self::get_enabled(); foreach ($antiviruses as $antivirus) { $result = $antivirus->scan_file($file, $filename); if ($result === $antivirus::SCAN_RESULT_FOUND) { // Infection found. if ($deleteinfected) { unlink($file); } throw new \core\antivirus\scanner_exception('virusfound', '', array('item' => $filename)); } } }
[ "public", "static", "function", "scan_file", "(", "$", "file", ",", "$", "filename", ",", "$", "deleteinfected", ")", "{", "$", "antiviruses", "=", "self", "::", "get_enabled", "(", ")", ";", "foreach", "(", "$", "antiviruses", "as", "$", "antivirus", ")", "{", "$", "result", "=", "$", "antivirus", "->", "scan_file", "(", "$", "file", ",", "$", "filename", ")", ";", "if", "(", "$", "result", "===", "$", "antivirus", "::", "SCAN_RESULT_FOUND", ")", "{", "// Infection found.", "if", "(", "$", "deleteinfected", ")", "{", "unlink", "(", "$", "file", ")", ";", "}", "throw", "new", "\\", "core", "\\", "antivirus", "\\", "scanner_exception", "(", "'virusfound'", ",", "''", ",", "array", "(", "'item'", "=>", "$", "filename", ")", ")", ";", "}", "}", "}" ]
Scan file using all enabled antiviruses, throws exception in case of infected file. @param string $file Full path to the file. @param string $filename Name of the file (could be different from physical file if temp file is used). @param bool $deleteinfected whether infected file needs to be deleted. @throws \core\antivirus\scanner_exception If file is infected. @return void
[ "Scan", "file", "using", "all", "enabled", "antiviruses", "throws", "exception", "in", "case", "of", "infected", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/antivirus/manager.php#L69-L81
217,965
moodle/moodle
lib/classes/antivirus/manager.php
manager.scan_data
public static function scan_data($data) { $antiviruses = self::get_enabled(); foreach ($antiviruses as $antivirus) { $result = $antivirus->scan_data($data); if ($result === $antivirus::SCAN_RESULT_FOUND) { throw new \core\antivirus\scanner_exception('virusfound', '', array('item' => get_string('datastream', 'antivirus'))); } } }
php
public static function scan_data($data) { $antiviruses = self::get_enabled(); foreach ($antiviruses as $antivirus) { $result = $antivirus->scan_data($data); if ($result === $antivirus::SCAN_RESULT_FOUND) { throw new \core\antivirus\scanner_exception('virusfound', '', array('item' => get_string('datastream', 'antivirus'))); } } }
[ "public", "static", "function", "scan_data", "(", "$", "data", ")", "{", "$", "antiviruses", "=", "self", "::", "get_enabled", "(", ")", ";", "foreach", "(", "$", "antiviruses", "as", "$", "antivirus", ")", "{", "$", "result", "=", "$", "antivirus", "->", "scan_data", "(", "$", "data", ")", ";", "if", "(", "$", "result", "===", "$", "antivirus", "::", "SCAN_RESULT_FOUND", ")", "{", "throw", "new", "\\", "core", "\\", "antivirus", "\\", "scanner_exception", "(", "'virusfound'", ",", "''", ",", "array", "(", "'item'", "=>", "get_string", "(", "'datastream'", ",", "'antivirus'", ")", ")", ")", ";", "}", "}", "}" ]
Scan data steam using all enabled antiviruses, throws exception in case of infected data. @param string $data The varaible containing the data to scan. @throws \core\antivirus\scanner_exception If data is infected. @return void
[ "Scan", "data", "steam", "using", "all", "enabled", "antiviruses", "throws", "exception", "in", "case", "of", "infected", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/antivirus/manager.php#L90-L98
217,966
moodle/moodle
lib/classes/antivirus/manager.php
manager.get_available
public static function get_available() { $antiviruses = array(); foreach (\core_component::get_plugin_list('antivirus') as $antivirusname => $dir) { $antiviruses[$antivirusname] = get_string('pluginname', 'antivirus_'.$antivirusname); } return $antiviruses; }
php
public static function get_available() { $antiviruses = array(); foreach (\core_component::get_plugin_list('antivirus') as $antivirusname => $dir) { $antiviruses[$antivirusname] = get_string('pluginname', 'antivirus_'.$antivirusname); } return $antiviruses; }
[ "public", "static", "function", "get_available", "(", ")", "{", "$", "antiviruses", "=", "array", "(", ")", ";", "foreach", "(", "\\", "core_component", "::", "get_plugin_list", "(", "'antivirus'", ")", "as", "$", "antivirusname", "=>", "$", "dir", ")", "{", "$", "antiviruses", "[", "$", "antivirusname", "]", "=", "get_string", "(", "'pluginname'", ",", "'antivirus_'", ".", "$", "antivirusname", ")", ";", "}", "return", "$", "antiviruses", ";", "}" ]
Get the list of available antiviruses. @return array Array ('antivirusname'=>'localised antivirus name').
[ "Get", "the", "list", "of", "available", "antiviruses", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/antivirus/manager.php#L121-L127
217,967
moodle/moodle
course/dnduploadlib.php
dndupload_handler.register_type
protected function register_type($identifier, $datatransfertypes, $addmessage, $namemessage, $handlermessage, $priority=100) { if ($this->is_known_type($identifier)) { throw new coding_exception("Type $identifier is already registered"); } $add = new stdClass; $add->identifier = $identifier; $add->datatransfertypes = $datatransfertypes; $add->addmessage = $addmessage; $add->namemessage = $namemessage; $add->handlermessage = $handlermessage; $add->priority = $priority; $add->handlers = array(); $this->types[$identifier] = $add; }
php
protected function register_type($identifier, $datatransfertypes, $addmessage, $namemessage, $handlermessage, $priority=100) { if ($this->is_known_type($identifier)) { throw new coding_exception("Type $identifier is already registered"); } $add = new stdClass; $add->identifier = $identifier; $add->datatransfertypes = $datatransfertypes; $add->addmessage = $addmessage; $add->namemessage = $namemessage; $add->handlermessage = $handlermessage; $add->priority = $priority; $add->handlers = array(); $this->types[$identifier] = $add; }
[ "protected", "function", "register_type", "(", "$", "identifier", ",", "$", "datatransfertypes", ",", "$", "addmessage", ",", "$", "namemessage", ",", "$", "handlermessage", ",", "$", "priority", "=", "100", ")", "{", "if", "(", "$", "this", "->", "is_known_type", "(", "$", "identifier", ")", ")", "{", "throw", "new", "coding_exception", "(", "\"Type $identifier is already registered\"", ")", ";", "}", "$", "add", "=", "new", "stdClass", ";", "$", "add", "->", "identifier", "=", "$", "identifier", ";", "$", "add", "->", "datatransfertypes", "=", "$", "datatransfertypes", ";", "$", "add", "->", "addmessage", "=", "$", "addmessage", ";", "$", "add", "->", "namemessage", "=", "$", "namemessage", ";", "$", "add", "->", "handlermessage", "=", "$", "handlermessage", ";", "$", "add", "->", "priority", "=", "$", "priority", ";", "$", "add", "->", "handlers", "=", "array", "(", ")", ";", "$", "this", "->", "types", "[", "$", "identifier", "]", "=", "$", "add", ";", "}" ]
Used to add a new mime type that can be drag and dropped onto a course displayed in a browser window @param string $identifier The name that this type will be known as @param array $datatransfertypes An array of the different types in the browser 'dataTransfer.types' object that will map to this type @param string $addmessage The message to display in the browser when this type is being dragged onto the page @param string $namemessage The message to pop up when asking for the name to give the course module instance when it is created @param string $handlermessage The message to pop up when asking which module should handle this type @param int $priority Controls the order in which types are checked by the browser (mainly needed to check for 'text' last as that is usually given as fallback)
[ "Used", "to", "add", "a", "new", "mime", "type", "that", "can", "be", "drag", "and", "dropped", "onto", "a", "course", "displayed", "in", "a", "browser", "window" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/dnduploadlib.php#L189-L204
217,968
moodle/moodle
course/dnduploadlib.php
dndupload_handler.register_type_handler
protected function register_type_handler($type, $module, $message, $noname) { if (!$this->is_known_type($type)) { throw new coding_exception("Trying to add handler for unknown type $type"); } $add = new stdClass; $add->type = $type; $add->module = $module; $add->message = $message; $add->noname = $noname ? 1 : 0; $this->types[$type]->handlers[] = $add; }
php
protected function register_type_handler($type, $module, $message, $noname) { if (!$this->is_known_type($type)) { throw new coding_exception("Trying to add handler for unknown type $type"); } $add = new stdClass; $add->type = $type; $add->module = $module; $add->message = $message; $add->noname = $noname ? 1 : 0; $this->types[$type]->handlers[] = $add; }
[ "protected", "function", "register_type_handler", "(", "$", "type", ",", "$", "module", ",", "$", "message", ",", "$", "noname", ")", "{", "if", "(", "!", "$", "this", "->", "is_known_type", "(", "$", "type", ")", ")", "{", "throw", "new", "coding_exception", "(", "\"Trying to add handler for unknown type $type\"", ")", ";", "}", "$", "add", "=", "new", "stdClass", ";", "$", "add", "->", "type", "=", "$", "type", ";", "$", "add", "->", "module", "=", "$", "module", ";", "$", "add", "->", "message", "=", "$", "message", ";", "$", "add", "->", "noname", "=", "$", "noname", "?", "1", ":", "0", ";", "$", "this", "->", "types", "[", "$", "type", "]", "->", "handlers", "[", "]", "=", "$", "add", ";", "}" ]
Used to declare that a particular module will handle a particular type of dropped data @param string $type The name of the type (as declared in register_type) @param string $module The name of the module to handle this type @param string $message The message to show the user if more than one handler is registered for a type and the user needs to make a choice between them @param bool $noname If true, the 'name' dialog should be disabled in the pop-up. @throws coding_exception
[ "Used", "to", "declare", "that", "a", "particular", "module", "will", "handle", "a", "particular", "type", "of", "dropped", "data" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/dnduploadlib.php#L217-L229
217,969
moodle/moodle
course/dnduploadlib.php
dndupload_handler.register_file_handler
protected function register_file_handler($extension, $module, $message) { $extension = strtolower($extension); $add = new stdClass; $add->extension = $extension; $add->module = $module; $add->message = $message; $this->filehandlers[] = $add; }
php
protected function register_file_handler($extension, $module, $message) { $extension = strtolower($extension); $add = new stdClass; $add->extension = $extension; $add->module = $module; $add->message = $message; $this->filehandlers[] = $add; }
[ "protected", "function", "register_file_handler", "(", "$", "extension", ",", "$", "module", ",", "$", "message", ")", "{", "$", "extension", "=", "strtolower", "(", "$", "extension", ")", ";", "$", "add", "=", "new", "stdClass", ";", "$", "add", "->", "extension", "=", "$", "extension", ";", "$", "add", "->", "module", "=", "$", "module", ";", "$", "add", "->", "message", "=", "$", "message", ";", "$", "this", "->", "filehandlers", "[", "]", "=", "$", "add", ";", "}" ]
Used to declare that a particular module will handle a particular type of dropped file @param string $extension The file extension to handle ('*' for all types) @param string $module The name of the module to handle this type @param string $message The message to show the user if more than one handler is registered for a type and the user needs to make a choice between them
[ "Used", "to", "declare", "that", "a", "particular", "module", "will", "handle", "a", "particular", "type", "of", "dropped", "file" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/dnduploadlib.php#L240-L249
217,970
moodle/moodle
course/dnduploadlib.php
dndupload_handler.has_type_handler
public function has_type_handler($module, $type) { if (!$this->is_known_type($type)) { throw new coding_exception("Checking for handler for unknown type $type"); } foreach ($this->types[$type]->handlers as $handler) { if ($handler->module == $module) { return true; } } return false; }
php
public function has_type_handler($module, $type) { if (!$this->is_known_type($type)) { throw new coding_exception("Checking for handler for unknown type $type"); } foreach ($this->types[$type]->handlers as $handler) { if ($handler->module == $module) { return true; } } return false; }
[ "public", "function", "has_type_handler", "(", "$", "module", ",", "$", "type", ")", "{", "if", "(", "!", "$", "this", "->", "is_known_type", "(", "$", "type", ")", ")", "{", "throw", "new", "coding_exception", "(", "\"Checking for handler for unknown type $type\"", ")", ";", "}", "foreach", "(", "$", "this", "->", "types", "[", "$", "type", "]", "->", "handlers", "as", "$", "handler", ")", "{", "if", "(", "$", "handler", "->", "module", "==", "$", "module", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Check to see if the module in question has registered to handle the type given @param string $module The name of the module @param string $type The identifier of the type @return bool True if the module has registered to handle that type
[ "Check", "to", "see", "if", "the", "module", "in", "question", "has", "registered", "to", "handle", "the", "type", "given" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/dnduploadlib.php#L269-L279
217,971
moodle/moodle
course/dnduploadlib.php
dndupload_handler.get_handled_file_types
public function get_handled_file_types($module) { $types = array(); foreach ($this->filehandlers as $handler) { if ($handler->module == $module) { if ($handler->extension == '*') { return '*'; } else { // Prepending '.' as otherwise mimeinfo fails. $types[] = '.'.$handler->extension; } } } return $types; }
php
public function get_handled_file_types($module) { $types = array(); foreach ($this->filehandlers as $handler) { if ($handler->module == $module) { if ($handler->extension == '*') { return '*'; } else { // Prepending '.' as otherwise mimeinfo fails. $types[] = '.'.$handler->extension; } } } return $types; }
[ "public", "function", "get_handled_file_types", "(", "$", "module", ")", "{", "$", "types", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "filehandlers", "as", "$", "handler", ")", "{", "if", "(", "$", "handler", "->", "module", "==", "$", "module", ")", "{", "if", "(", "$", "handler", "->", "extension", "==", "'*'", ")", "{", "return", "'*'", ";", "}", "else", "{", "// Prepending '.' as otherwise mimeinfo fails.", "$", "types", "[", "]", "=", "'.'", ".", "$", "handler", "->", "extension", ";", "}", "}", "}", "return", "$", "types", ";", "}" ]
Gets a list of the file types that are handled by a particular module @param string $module The name of the module to check @return array of file extensions or string '*'
[ "Gets", "a", "list", "of", "the", "file", "types", "that", "are", "handled", "by", "a", "particular", "module" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/dnduploadlib.php#L307-L320
217,972
moodle/moodle
course/dnduploadlib.php
dndupload_handler.type_compare
protected function type_compare($type1, $type2) { if ($type1->priority < $type2->priority) { return -1; } if ($type1->priority > $type2->priority) { return 1; } return 0; }
php
protected function type_compare($type1, $type2) { if ($type1->priority < $type2->priority) { return -1; } if ($type1->priority > $type2->priority) { return 1; } return 0; }
[ "protected", "function", "type_compare", "(", "$", "type1", ",", "$", "type2", ")", "{", "if", "(", "$", "type1", "->", "priority", "<", "$", "type2", "->", "priority", ")", "{", "return", "-", "1", ";", "}", "if", "(", "$", "type1", "->", "priority", ">", "$", "type2", "->", "priority", ")", "{", "return", "1", ";", "}", "return", "0", ";", "}" ]
Comparison function used when sorting types by priority @param object $type1 first type to compare @param object $type2 second type to compare @return integer -1 for $type1 < $type2; 1 for $type1 > $type2; 0 for equal
[ "Comparison", "function", "used", "when", "sorting", "types", "by", "priority" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/dnduploadlib.php#L361-L369
217,973
moodle/moodle
course/dnduploadlib.php
dndupload_ajax_processor.process
public function process($displayname = null, $content = null) { require_capability('moodle/course:manageactivities', $this->context); if ($this->is_file_upload()) { require_capability('moodle/course:managefiles', $this->context); if ($content != null) { throw new moodle_exception('fileuploadwithcontent', 'moodle'); } } else { if (empty($content)) { throw new moodle_exception('dnduploadwithoutcontent', 'moodle'); } } require_sesskey(); $this->displayname = $displayname; if ($this->is_file_upload()) { $this->handle_file_upload(); } else { $this->handle_other_upload($content); } }
php
public function process($displayname = null, $content = null) { require_capability('moodle/course:manageactivities', $this->context); if ($this->is_file_upload()) { require_capability('moodle/course:managefiles', $this->context); if ($content != null) { throw new moodle_exception('fileuploadwithcontent', 'moodle'); } } else { if (empty($content)) { throw new moodle_exception('dnduploadwithoutcontent', 'moodle'); } } require_sesskey(); $this->displayname = $displayname; if ($this->is_file_upload()) { $this->handle_file_upload(); } else { $this->handle_other_upload($content); } }
[ "public", "function", "process", "(", "$", "displayname", "=", "null", ",", "$", "content", "=", "null", ")", "{", "require_capability", "(", "'moodle/course:manageactivities'", ",", "$", "this", "->", "context", ")", ";", "if", "(", "$", "this", "->", "is_file_upload", "(", ")", ")", "{", "require_capability", "(", "'moodle/course:managefiles'", ",", "$", "this", "->", "context", ")", ";", "if", "(", "$", "content", "!=", "null", ")", "{", "throw", "new", "moodle_exception", "(", "'fileuploadwithcontent'", ",", "'moodle'", ")", ";", "}", "}", "else", "{", "if", "(", "empty", "(", "$", "content", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'dnduploadwithoutcontent'", ",", "'moodle'", ")", ";", "}", "}", "require_sesskey", "(", ")", ";", "$", "this", "->", "displayname", "=", "$", "displayname", ";", "if", "(", "$", "this", "->", "is_file_upload", "(", ")", ")", "{", "$", "this", "->", "handle_file_upload", "(", ")", ";", "}", "else", "{", "$", "this", "->", "handle_other_upload", "(", "$", "content", ")", ";", "}", "}" ]
Process the upload - creating the module in the course and returning the result to the browser @param string $displayname optional the name (from the browser) to give the course module instance @param string $content optional the content of the upload (for non-file uploads)
[ "Process", "the", "upload", "-", "creating", "the", "module", "in", "the", "course", "and", "returning", "the", "result", "to", "the", "browser" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/dnduploadlib.php#L457-L480
217,974
moodle/moodle
course/dnduploadlib.php
dndupload_ajax_processor.handle_file_upload
protected function handle_file_upload() { global $CFG; // Add the file to a draft file area. $draftitemid = file_get_unused_draft_itemid(); $maxbytes = get_user_max_upload_file_size($this->context, $CFG->maxbytes, $this->course->maxbytes); $types = $this->dnduploadhandler->get_handled_file_types($this->module->name); $repo = repository::get_instances(array('type' => 'upload', 'currentcontext' => $this->context)); if (empty($repo)) { throw new moodle_exception('errornouploadrepo', 'moodle'); } $repo = reset($repo); // Get the first (and only) upload repo. $details = $repo->process_upload(null, $maxbytes, $types, '/', $draftitemid); if (empty($this->displayname)) { $this->displayname = $this->display_name_from_file($details['file']); } // Create a course module to hold the new instance. $this->create_course_module(); // Ask the module to set itself up. $moduledata = $this->prepare_module_data($draftitemid); $instanceid = plugin_callback('mod', $this->module->name, 'dndupload', 'handle', array($moduledata), 'invalidfunction'); if ($instanceid === 'invalidfunction') { throw new coding_exception("{$this->module->name} does not support drag and drop upload (missing {$this->module->name}_dndupload_handle function"); } // Finish setting up the course module. $this->finish_setup_course_module($instanceid); }
php
protected function handle_file_upload() { global $CFG; // Add the file to a draft file area. $draftitemid = file_get_unused_draft_itemid(); $maxbytes = get_user_max_upload_file_size($this->context, $CFG->maxbytes, $this->course->maxbytes); $types = $this->dnduploadhandler->get_handled_file_types($this->module->name); $repo = repository::get_instances(array('type' => 'upload', 'currentcontext' => $this->context)); if (empty($repo)) { throw new moodle_exception('errornouploadrepo', 'moodle'); } $repo = reset($repo); // Get the first (and only) upload repo. $details = $repo->process_upload(null, $maxbytes, $types, '/', $draftitemid); if (empty($this->displayname)) { $this->displayname = $this->display_name_from_file($details['file']); } // Create a course module to hold the new instance. $this->create_course_module(); // Ask the module to set itself up. $moduledata = $this->prepare_module_data($draftitemid); $instanceid = plugin_callback('mod', $this->module->name, 'dndupload', 'handle', array($moduledata), 'invalidfunction'); if ($instanceid === 'invalidfunction') { throw new coding_exception("{$this->module->name} does not support drag and drop upload (missing {$this->module->name}_dndupload_handle function"); } // Finish setting up the course module. $this->finish_setup_course_module($instanceid); }
[ "protected", "function", "handle_file_upload", "(", ")", "{", "global", "$", "CFG", ";", "// Add the file to a draft file area.", "$", "draftitemid", "=", "file_get_unused_draft_itemid", "(", ")", ";", "$", "maxbytes", "=", "get_user_max_upload_file_size", "(", "$", "this", "->", "context", ",", "$", "CFG", "->", "maxbytes", ",", "$", "this", "->", "course", "->", "maxbytes", ")", ";", "$", "types", "=", "$", "this", "->", "dnduploadhandler", "->", "get_handled_file_types", "(", "$", "this", "->", "module", "->", "name", ")", ";", "$", "repo", "=", "repository", "::", "get_instances", "(", "array", "(", "'type'", "=>", "'upload'", ",", "'currentcontext'", "=>", "$", "this", "->", "context", ")", ")", ";", "if", "(", "empty", "(", "$", "repo", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'errornouploadrepo'", ",", "'moodle'", ")", ";", "}", "$", "repo", "=", "reset", "(", "$", "repo", ")", ";", "// Get the first (and only) upload repo.", "$", "details", "=", "$", "repo", "->", "process_upload", "(", "null", ",", "$", "maxbytes", ",", "$", "types", ",", "'/'", ",", "$", "draftitemid", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "displayname", ")", ")", "{", "$", "this", "->", "displayname", "=", "$", "this", "->", "display_name_from_file", "(", "$", "details", "[", "'file'", "]", ")", ";", "}", "// Create a course module to hold the new instance.", "$", "this", "->", "create_course_module", "(", ")", ";", "// Ask the module to set itself up.", "$", "moduledata", "=", "$", "this", "->", "prepare_module_data", "(", "$", "draftitemid", ")", ";", "$", "instanceid", "=", "plugin_callback", "(", "'mod'", ",", "$", "this", "->", "module", "->", "name", ",", "'dndupload'", ",", "'handle'", ",", "array", "(", "$", "moduledata", ")", ",", "'invalidfunction'", ")", ";", "if", "(", "$", "instanceid", "===", "'invalidfunction'", ")", "{", "throw", "new", "coding_exception", "(", "\"{$this->module->name} does not support drag and drop upload (missing {$this->module->name}_dndupload_handle function\"", ")", ";", "}", "// Finish setting up the course module.", "$", "this", "->", "finish_setup_course_module", "(", "$", "instanceid", ")", ";", "}" ]
Handle uploads containing files - create the course module, ask the upload repository to process the file, ask the mod to set itself up, then return the result to the browser
[ "Handle", "uploads", "containing", "files", "-", "create", "the", "course", "module", "ask", "the", "upload", "repository", "to", "process", "the", "file", "ask", "the", "mod", "to", "set", "itself", "up", "then", "return", "the", "result", "to", "the", "browser" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/dnduploadlib.php#L486-L515
217,975
moodle/moodle
course/dnduploadlib.php
dndupload_ajax_processor.handle_other_upload
protected function handle_other_upload($content) { // Check this plugin is registered to handle this type of upload if (!$this->dnduploadhandler->has_type_handler($this->module->name, $this->type)) { $info = (object)array('modname' => $this->module->name, 'type' => $this->type); throw new moodle_exception('moddoesnotsupporttype', 'moodle', $info); } // Create a course module to hold the new instance. $this->create_course_module(); // Ask the module to set itself up. $moduledata = $this->prepare_module_data(null, $content); $instanceid = plugin_callback('mod', $this->module->name, 'dndupload', 'handle', array($moduledata), 'invalidfunction'); if ($instanceid === 'invalidfunction') { throw new coding_exception("{$this->module->name} does not support drag and drop upload (missing {$this->module->name}_dndupload_handle function"); } // Finish setting up the course module. $this->finish_setup_course_module($instanceid); }
php
protected function handle_other_upload($content) { // Check this plugin is registered to handle this type of upload if (!$this->dnduploadhandler->has_type_handler($this->module->name, $this->type)) { $info = (object)array('modname' => $this->module->name, 'type' => $this->type); throw new moodle_exception('moddoesnotsupporttype', 'moodle', $info); } // Create a course module to hold the new instance. $this->create_course_module(); // Ask the module to set itself up. $moduledata = $this->prepare_module_data(null, $content); $instanceid = plugin_callback('mod', $this->module->name, 'dndupload', 'handle', array($moduledata), 'invalidfunction'); if ($instanceid === 'invalidfunction') { throw new coding_exception("{$this->module->name} does not support drag and drop upload (missing {$this->module->name}_dndupload_handle function"); } // Finish setting up the course module. $this->finish_setup_course_module($instanceid); }
[ "protected", "function", "handle_other_upload", "(", "$", "content", ")", "{", "// Check this plugin is registered to handle this type of upload", "if", "(", "!", "$", "this", "->", "dnduploadhandler", "->", "has_type_handler", "(", "$", "this", "->", "module", "->", "name", ",", "$", "this", "->", "type", ")", ")", "{", "$", "info", "=", "(", "object", ")", "array", "(", "'modname'", "=>", "$", "this", "->", "module", "->", "name", ",", "'type'", "=>", "$", "this", "->", "type", ")", ";", "throw", "new", "moodle_exception", "(", "'moddoesnotsupporttype'", ",", "'moodle'", ",", "$", "info", ")", ";", "}", "// Create a course module to hold the new instance.", "$", "this", "->", "create_course_module", "(", ")", ";", "// Ask the module to set itself up.", "$", "moduledata", "=", "$", "this", "->", "prepare_module_data", "(", "null", ",", "$", "content", ")", ";", "$", "instanceid", "=", "plugin_callback", "(", "'mod'", ",", "$", "this", "->", "module", "->", "name", ",", "'dndupload'", ",", "'handle'", ",", "array", "(", "$", "moduledata", ")", ",", "'invalidfunction'", ")", ";", "if", "(", "$", "instanceid", "===", "'invalidfunction'", ")", "{", "throw", "new", "coding_exception", "(", "\"{$this->module->name} does not support drag and drop upload (missing {$this->module->name}_dndupload_handle function\"", ")", ";", "}", "// Finish setting up the course module.", "$", "this", "->", "finish_setup_course_module", "(", "$", "instanceid", ")", ";", "}" ]
Handle uploads not containing file - create the course module, ask the mod to set itself up, then return the result to the browser @param string $content the content uploaded to the browser
[ "Handle", "uploads", "not", "containing", "file", "-", "create", "the", "course", "module", "ask", "the", "mod", "to", "set", "itself", "up", "then", "return", "the", "result", "to", "the", "browser" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/dnduploadlib.php#L523-L542
217,976
moodle/moodle
course/dnduploadlib.php
dndupload_ajax_processor.display_name_from_file
protected function display_name_from_file($filename) { $pos = core_text::strrpos($filename, '.'); if ($pos) { // Want to skip if $pos === 0 OR $pos === false. $filename = core_text::substr($filename, 0, $pos); } return str_replace('_', ' ', $filename); }
php
protected function display_name_from_file($filename) { $pos = core_text::strrpos($filename, '.'); if ($pos) { // Want to skip if $pos === 0 OR $pos === false. $filename = core_text::substr($filename, 0, $pos); } return str_replace('_', ' ', $filename); }
[ "protected", "function", "display_name_from_file", "(", "$", "filename", ")", "{", "$", "pos", "=", "core_text", "::", "strrpos", "(", "$", "filename", ",", "'.'", ")", ";", "if", "(", "$", "pos", ")", "{", "// Want to skip if $pos === 0 OR $pos === false.", "$", "filename", "=", "core_text", "::", "substr", "(", "$", "filename", ",", "0", ",", "$", "pos", ")", ";", "}", "return", "str_replace", "(", "'_'", ",", "' '", ",", "$", "filename", ")", ";", "}" ]
Generate the name of the mod instance from the name of the file (remove the extension and convert underscore => space @param string $filename the filename of the uploaded file @return string the display name to use
[ "Generate", "the", "name", "of", "the", "mod", "instance", "from", "the", "name", "of", "the", "file", "(", "remove", "the", "extension", "and", "convert", "underscore", "=", ">", "space" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/dnduploadlib.php#L551-L557
217,977
moodle/moodle
course/dnduploadlib.php
dndupload_ajax_processor.prepare_module_data
protected function prepare_module_data($draftitemid = null, $content = null) { $data = new stdClass(); $data->type = $this->type; $data->course = $this->course; if ($draftitemid) { $data->draftitemid = $draftitemid; } else if ($content) { $data->content = $content; } $data->coursemodule = $this->cm->id; $data->displayname = $this->displayname; return $data; }
php
protected function prepare_module_data($draftitemid = null, $content = null) { $data = new stdClass(); $data->type = $this->type; $data->course = $this->course; if ($draftitemid) { $data->draftitemid = $draftitemid; } else if ($content) { $data->content = $content; } $data->coursemodule = $this->cm->id; $data->displayname = $this->displayname; return $data; }
[ "protected", "function", "prepare_module_data", "(", "$", "draftitemid", "=", "null", ",", "$", "content", "=", "null", ")", "{", "$", "data", "=", "new", "stdClass", "(", ")", ";", "$", "data", "->", "type", "=", "$", "this", "->", "type", ";", "$", "data", "->", "course", "=", "$", "this", "->", "course", ";", "if", "(", "$", "draftitemid", ")", "{", "$", "data", "->", "draftitemid", "=", "$", "draftitemid", ";", "}", "else", "if", "(", "$", "content", ")", "{", "$", "data", "->", "content", "=", "$", "content", ";", "}", "$", "data", "->", "coursemodule", "=", "$", "this", "->", "cm", "->", "id", ";", "$", "data", "->", "displayname", "=", "$", "this", "->", "displayname", ";", "return", "$", "data", ";", "}" ]
Gather together all the details to pass on to the mod, so that it can initialise it's own database tables @param int $draftitemid optional the id of the draft area containing the file (for file uploads) @param string $content optional the content dropped onto the course (for non-file uploads) @return object data to pass on to the mod, containing: string $type the 'type' as registered with dndupload_handler (or 'Files') object $course the course the upload was for int $draftitemid optional the id of the draft area containing the files int $coursemodule id of the course module that has already been created string $displayname the name to use for this activity (can be overriden by the mod)
[ "Gather", "together", "all", "the", "details", "to", "pass", "on", "to", "the", "mod", "so", "that", "it", "can", "initialise", "it", "s", "own", "database", "tables" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/dnduploadlib.php#L584-L596
217,978
moodle/moodle
course/dnduploadlib.php
dndupload_ajax_processor.send_response
protected function send_response($mod) { global $OUTPUT, $PAGE; $resp = new stdClass(); $resp->error = self::ERROR_OK; $resp->elementid = 'module-' . $mod->id; $courserenderer = $PAGE->get_renderer('core', 'course'); $completioninfo = new completion_info($this->course); $info = get_fast_modinfo($this->course); $sr = null; $modulehtml = $courserenderer->course_section_cm($this->course, $completioninfo, $mod, null, array()); $resp->fullcontent = $courserenderer->course_section_cm_list_item($this->course, $completioninfo, $mod, $sr); echo $OUTPUT->header(); echo json_encode($resp); die(); }
php
protected function send_response($mod) { global $OUTPUT, $PAGE; $resp = new stdClass(); $resp->error = self::ERROR_OK; $resp->elementid = 'module-' . $mod->id; $courserenderer = $PAGE->get_renderer('core', 'course'); $completioninfo = new completion_info($this->course); $info = get_fast_modinfo($this->course); $sr = null; $modulehtml = $courserenderer->course_section_cm($this->course, $completioninfo, $mod, null, array()); $resp->fullcontent = $courserenderer->course_section_cm_list_item($this->course, $completioninfo, $mod, $sr); echo $OUTPUT->header(); echo json_encode($resp); die(); }
[ "protected", "function", "send_response", "(", "$", "mod", ")", "{", "global", "$", "OUTPUT", ",", "$", "PAGE", ";", "$", "resp", "=", "new", "stdClass", "(", ")", ";", "$", "resp", "->", "error", "=", "self", "::", "ERROR_OK", ";", "$", "resp", "->", "elementid", "=", "'module-'", ".", "$", "mod", "->", "id", ";", "$", "courserenderer", "=", "$", "PAGE", "->", "get_renderer", "(", "'core'", ",", "'course'", ")", ";", "$", "completioninfo", "=", "new", "completion_info", "(", "$", "this", "->", "course", ")", ";", "$", "info", "=", "get_fast_modinfo", "(", "$", "this", "->", "course", ")", ";", "$", "sr", "=", "null", ";", "$", "modulehtml", "=", "$", "courserenderer", "->", "course_section_cm", "(", "$", "this", "->", "course", ",", "$", "completioninfo", ",", "$", "mod", ",", "null", ",", "array", "(", ")", ")", ";", "$", "resp", "->", "fullcontent", "=", "$", "courserenderer", "->", "course_section_cm_list_item", "(", "$", "this", "->", "course", ",", "$", "completioninfo", ",", "$", "mod", ",", "$", "sr", ")", ";", "echo", "$", "OUTPUT", "->", "header", "(", ")", ";", "echo", "json_encode", "(", "$", "resp", ")", ";", "die", "(", ")", ";", "}" ]
Send the details of the newly created activity back to the client browser @param cm_info $mod details of the mod just created
[ "Send", "the", "details", "of", "the", "newly", "created", "activity", "back", "to", "the", "client", "browser" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/dnduploadlib.php#L648-L666
217,979
moodle/moodle
grade/report/singleview/classes/local/ui/bulk_insert.php
bulk_insert.html
public function html() { global $OUTPUT; $text = new text_attribute($this->insertname, "0", 'bulk'); $context = (object) [ 'label' => get_string('bulklegend', 'gradereport_singleview'), 'applylabel' => get_string('bulkperform', 'gradereport_singleview'), 'applyname' => $this->applyname, 'menuname' => $this->selectname, 'menulabel' => get_string('bulkappliesto', 'gradereport_singleview'), 'menuoptions' => [ ['value' => 'all', 'name' => get_string('all_grades', 'gradereport_singleview')], ['value' => 'blanks', 'name' => get_string('blanks', 'gradereport_singleview'), 'selected' => true], ], 'valuename' => $this->insertname, 'valuelabel' => get_string('bulkinsertvalue', 'gradereport_singleview'), 'valuefield' => $text->html() ]; return $OUTPUT->render_from_template('gradereport_singleview/bulk_insert', $context); }
php
public function html() { global $OUTPUT; $text = new text_attribute($this->insertname, "0", 'bulk'); $context = (object) [ 'label' => get_string('bulklegend', 'gradereport_singleview'), 'applylabel' => get_string('bulkperform', 'gradereport_singleview'), 'applyname' => $this->applyname, 'menuname' => $this->selectname, 'menulabel' => get_string('bulkappliesto', 'gradereport_singleview'), 'menuoptions' => [ ['value' => 'all', 'name' => get_string('all_grades', 'gradereport_singleview')], ['value' => 'blanks', 'name' => get_string('blanks', 'gradereport_singleview'), 'selected' => true], ], 'valuename' => $this->insertname, 'valuelabel' => get_string('bulkinsertvalue', 'gradereport_singleview'), 'valuefield' => $text->html() ]; return $OUTPUT->render_from_template('gradereport_singleview/bulk_insert', $context); }
[ "public", "function", "html", "(", ")", "{", "global", "$", "OUTPUT", ";", "$", "text", "=", "new", "text_attribute", "(", "$", "this", "->", "insertname", ",", "\"0\"", ",", "'bulk'", ")", ";", "$", "context", "=", "(", "object", ")", "[", "'label'", "=>", "get_string", "(", "'bulklegend'", ",", "'gradereport_singleview'", ")", ",", "'applylabel'", "=>", "get_string", "(", "'bulkperform'", ",", "'gradereport_singleview'", ")", ",", "'applyname'", "=>", "$", "this", "->", "applyname", ",", "'menuname'", "=>", "$", "this", "->", "selectname", ",", "'menulabel'", "=>", "get_string", "(", "'bulkappliesto'", ",", "'gradereport_singleview'", ")", ",", "'menuoptions'", "=>", "[", "[", "'value'", "=>", "'all'", ",", "'name'", "=>", "get_string", "(", "'all_grades'", ",", "'gradereport_singleview'", ")", "]", ",", "[", "'value'", "=>", "'blanks'", ",", "'name'", "=>", "get_string", "(", "'blanks'", ",", "'gradereport_singleview'", ")", ",", "'selected'", "=>", "true", "]", ",", "]", ",", "'valuename'", "=>", "$", "this", "->", "insertname", ",", "'valuelabel'", "=>", "get_string", "(", "'bulkinsertvalue'", ",", "'gradereport_singleview'", ")", ",", "'valuefield'", "=>", "$", "text", "->", "html", "(", ")", "]", ";", "return", "$", "OUTPUT", "->", "render_from_template", "(", "'gradereport_singleview/bulk_insert'", ",", "$", "context", ")", ";", "}" ]
Generate the html for this form element. @return string HTML
[ "Generate", "the", "html", "for", "this", "form", "element", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/ui/bulk_insert.php#L87-L107
217,980
moodle/moodle
lib/environmentlib.php
environment_results.getPluginName
function getPluginName() { if ($this->plugin) { $manager = core_plugin_manager::instance(); list($plugintype, $pluginname) = core_component::normalize_component($this->plugin); return $manager->plugintype_name($plugintype) . ' / ' . $manager->plugin_name($this->plugin); } else { return ''; } }
php
function getPluginName() { if ($this->plugin) { $manager = core_plugin_manager::instance(); list($plugintype, $pluginname) = core_component::normalize_component($this->plugin); return $manager->plugintype_name($plugintype) . ' / ' . $manager->plugin_name($this->plugin); } else { return ''; } }
[ "function", "getPluginName", "(", ")", "{", "if", "(", "$", "this", "->", "plugin", ")", "{", "$", "manager", "=", "core_plugin_manager", "::", "instance", "(", ")", ";", "list", "(", "$", "plugintype", ",", "$", "pluginname", ")", "=", "core_component", "::", "normalize_component", "(", "$", "this", "->", "plugin", ")", ";", "return", "$", "manager", "->", "plugintype_name", "(", "$", "plugintype", ")", ".", "' / '", ".", "$", "manager", "->", "plugin_name", "(", "$", "this", "->", "plugin", ")", ";", "}", "else", "{", "return", "''", ";", "}", "}" ]
Get plugin name. @return string plugin name
[ "Get", "plugin", "name", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/environmentlib.php#L1513-L1521
217,981
moodle/moodle
mod/forum/classes/local/renderers/discussion_list.php
discussion_list.render
public function render(stdClass $user, \cm_info $cm, ?int $groupid, ?int $sortorder, ?int $pageno, ?int $pagesize) : string { global $PAGE; $forum = $this->forum; $forumexporter = $this->exporterfactory->get_forum_exporter( $user, $this->forum, $groupid ); $pagesize = $this->get_page_size($pagesize); $pageno = $this->get_page_number($pageno); // Count all forum discussion posts. $alldiscussionscount = get_count_all_discussions($forum, $user, $groupid); // Get all forum discussions posts. $discussions = get_discussions($forum, $user, $groupid, $sortorder, $pageno, $pagesize); $forumview = [ 'forum' => (array) $forumexporter->export($this->renderer), 'newdiscussionhtml' => $this->get_discussion_form($user, $cm, $groupid), 'groupchangemenu' => groups_print_activity_menu( $cm, $this->urlfactory->get_forum_view_url_from_forum($forum), true ), 'hasmore' => ($alldiscussionscount > $pagesize), 'notifications' => $this->get_notifications($user, $groupid), 'settings' => [ 'excludetext' => true, 'togglemoreicon' => true ] ]; if (!$discussions) { return $this->renderer->render_from_template($this->template, $forumview); } if ($this->postprocessfortemplate !== null) { // We've got some post processing to do! $exportedposts = ($this->postprocessfortemplate) ($discussions, $user, $forum); } $baseurl = new \moodle_url($PAGE->url, array('o' => $sortorder)); $forumview = array_merge( $forumview, [ 'pagination' => $this->renderer->render(new \paging_bar($alldiscussionscount, $pageno, $pagesize, $baseurl, 'p')), ], $exportedposts ); return $this->renderer->render_from_template($this->template, $forumview); }
php
public function render(stdClass $user, \cm_info $cm, ?int $groupid, ?int $sortorder, ?int $pageno, ?int $pagesize) : string { global $PAGE; $forum = $this->forum; $forumexporter = $this->exporterfactory->get_forum_exporter( $user, $this->forum, $groupid ); $pagesize = $this->get_page_size($pagesize); $pageno = $this->get_page_number($pageno); // Count all forum discussion posts. $alldiscussionscount = get_count_all_discussions($forum, $user, $groupid); // Get all forum discussions posts. $discussions = get_discussions($forum, $user, $groupid, $sortorder, $pageno, $pagesize); $forumview = [ 'forum' => (array) $forumexporter->export($this->renderer), 'newdiscussionhtml' => $this->get_discussion_form($user, $cm, $groupid), 'groupchangemenu' => groups_print_activity_menu( $cm, $this->urlfactory->get_forum_view_url_from_forum($forum), true ), 'hasmore' => ($alldiscussionscount > $pagesize), 'notifications' => $this->get_notifications($user, $groupid), 'settings' => [ 'excludetext' => true, 'togglemoreicon' => true ] ]; if (!$discussions) { return $this->renderer->render_from_template($this->template, $forumview); } if ($this->postprocessfortemplate !== null) { // We've got some post processing to do! $exportedposts = ($this->postprocessfortemplate) ($discussions, $user, $forum); } $baseurl = new \moodle_url($PAGE->url, array('o' => $sortorder)); $forumview = array_merge( $forumview, [ 'pagination' => $this->renderer->render(new \paging_bar($alldiscussionscount, $pageno, $pagesize, $baseurl, 'p')), ], $exportedposts ); return $this->renderer->render_from_template($this->template, $forumview); }
[ "public", "function", "render", "(", "stdClass", "$", "user", ",", "\\", "cm_info", "$", "cm", ",", "?", "int", "$", "groupid", ",", "?", "int", "$", "sortorder", ",", "?", "int", "$", "pageno", ",", "?", "int", "$", "pagesize", ")", ":", "string", "{", "global", "$", "PAGE", ";", "$", "forum", "=", "$", "this", "->", "forum", ";", "$", "forumexporter", "=", "$", "this", "->", "exporterfactory", "->", "get_forum_exporter", "(", "$", "user", ",", "$", "this", "->", "forum", ",", "$", "groupid", ")", ";", "$", "pagesize", "=", "$", "this", "->", "get_page_size", "(", "$", "pagesize", ")", ";", "$", "pageno", "=", "$", "this", "->", "get_page_number", "(", "$", "pageno", ")", ";", "// Count all forum discussion posts.", "$", "alldiscussionscount", "=", "get_count_all_discussions", "(", "$", "forum", ",", "$", "user", ",", "$", "groupid", ")", ";", "// Get all forum discussions posts.", "$", "discussions", "=", "get_discussions", "(", "$", "forum", ",", "$", "user", ",", "$", "groupid", ",", "$", "sortorder", ",", "$", "pageno", ",", "$", "pagesize", ")", ";", "$", "forumview", "=", "[", "'forum'", "=>", "(", "array", ")", "$", "forumexporter", "->", "export", "(", "$", "this", "->", "renderer", ")", ",", "'newdiscussionhtml'", "=>", "$", "this", "->", "get_discussion_form", "(", "$", "user", ",", "$", "cm", ",", "$", "groupid", ")", ",", "'groupchangemenu'", "=>", "groups_print_activity_menu", "(", "$", "cm", ",", "$", "this", "->", "urlfactory", "->", "get_forum_view_url_from_forum", "(", "$", "forum", ")", ",", "true", ")", ",", "'hasmore'", "=>", "(", "$", "alldiscussionscount", ">", "$", "pagesize", ")", ",", "'notifications'", "=>", "$", "this", "->", "get_notifications", "(", "$", "user", ",", "$", "groupid", ")", ",", "'settings'", "=>", "[", "'excludetext'", "=>", "true", ",", "'togglemoreicon'", "=>", "true", "]", "]", ";", "if", "(", "!", "$", "discussions", ")", "{", "return", "$", "this", "->", "renderer", "->", "render_from_template", "(", "$", "this", "->", "template", ",", "$", "forumview", ")", ";", "}", "if", "(", "$", "this", "->", "postprocessfortemplate", "!==", "null", ")", "{", "// We've got some post processing to do!", "$", "exportedposts", "=", "(", "$", "this", "->", "postprocessfortemplate", ")", "(", "$", "discussions", ",", "$", "user", ",", "$", "forum", ")", ";", "}", "$", "baseurl", "=", "new", "\\", "moodle_url", "(", "$", "PAGE", "->", "url", ",", "array", "(", "'o'", "=>", "$", "sortorder", ")", ")", ";", "$", "forumview", "=", "array_merge", "(", "$", "forumview", ",", "[", "'pagination'", "=>", "$", "this", "->", "renderer", "->", "render", "(", "new", "\\", "paging_bar", "(", "$", "alldiscussionscount", ",", "$", "pageno", ",", "$", "pagesize", ",", "$", "baseurl", ",", "'p'", ")", ")", ",", "]", ",", "$", "exportedposts", ")", ";", "return", "$", "this", "->", "renderer", "->", "render_from_template", "(", "$", "this", "->", "template", ",", "$", "forumview", ")", ";", "}" ]
Render for the specified user. @param stdClass $user The user to render for @param cm_info $cm The course module info for this discussion list @param int $groupid The group to render @param int $sortorder The sort order to use when selecting the discussions in the list @param int $pageno The zero-indexed page number to use @param int $pagesize The number of discussions to show on the page @return string The rendered content for display
[ "Render", "for", "the", "specified", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/renderers/discussion_list.php#L143-L199
217,982
moodle/moodle
mod/forum/classes/local/renderers/discussion_list.php
discussion_list.get_page_size
private function get_page_size(?int $pagesize) : int { if (null === $pagesize || $pagesize <= 0) { $pagesize = discussion_list_vault::PAGESIZE_DEFAULT; } return $pagesize; }
php
private function get_page_size(?int $pagesize) : int { if (null === $pagesize || $pagesize <= 0) { $pagesize = discussion_list_vault::PAGESIZE_DEFAULT; } return $pagesize; }
[ "private", "function", "get_page_size", "(", "?", "int", "$", "pagesize", ")", ":", "int", "{", "if", "(", "null", "===", "$", "pagesize", "||", "$", "pagesize", "<=", "0", ")", "{", "$", "pagesize", "=", "discussion_list_vault", "::", "PAGESIZE_DEFAULT", ";", "}", "return", "$", "pagesize", ";", "}" ]
Fetch the page size to use when displaying the page. @param int $pagesize The number of discussions to show on the page @return int The normalised page size
[ "Fetch", "the", "page", "size", "to", "use", "when", "displaying", "the", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/renderers/discussion_list.php#L266-L272
217,983
moodle/moodle
availability/condition/group/classes/frontend.php
frontend.get_all_groups
protected function get_all_groups($courseid) { global $CFG; require_once($CFG->libdir . '/grouplib.php'); if ($courseid != $this->allgroupscourseid) { $this->allgroups = groups_get_all_groups($courseid, 0, 0, 'g.id, g.name'); $this->allgroupscourseid = $courseid; } return $this->allgroups; }
php
protected function get_all_groups($courseid) { global $CFG; require_once($CFG->libdir . '/grouplib.php'); if ($courseid != $this->allgroupscourseid) { $this->allgroups = groups_get_all_groups($courseid, 0, 0, 'g.id, g.name'); $this->allgroupscourseid = $courseid; } return $this->allgroups; }
[ "protected", "function", "get_all_groups", "(", "$", "courseid", ")", "{", "global", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/grouplib.php'", ")", ";", "if", "(", "$", "courseid", "!=", "$", "this", "->", "allgroupscourseid", ")", "{", "$", "this", "->", "allgroups", "=", "groups_get_all_groups", "(", "$", "courseid", ",", "0", ",", "0", ",", "'g.id, g.name'", ")", ";", "$", "this", "->", "allgroupscourseid", "=", "$", "courseid", ";", "}", "return", "$", "this", "->", "allgroups", ";", "}" ]
Gets all groups for the given course. @param int $courseid Course id @return array Array of all the group objects
[ "Gets", "all", "groups", "for", "the", "given", "course", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/availability/condition/group/classes/frontend.php#L67-L76
217,984
moodle/moodle
analytics/classes/local/analyser/by_course.php
by_course.get_analysables_iterator
public function get_analysables_iterator(?string $action = null) { global $DB; list($sql, $params) = $this->get_iterator_sql('course', CONTEXT_COURSE, $action, 'c'); // This will be updated to filter by context as part of MDL-64739. if (!empty($this->options['filter'])) { $courses = array(); foreach ($this->options['filter'] as $courseid) { $courses[$courseid] = new \stdClass(); $courses[$courseid]->id = $courseid; } list($coursesql, $courseparams) = $DB->get_in_or_equal($courses, SQL_PARAMS_NAMED); $sql .= " AND c.id IN $coursesql"; $params = $params + $courseparams; } $ordersql = $this->order_sql('sortorder', 'ASC', 'c'); $recordset = $DB->get_recordset_sql($sql . $ordersql, $params); if (!$recordset->valid()) { $this->add_log(get_string('nocourses', 'analytics')); return new \ArrayIterator([]); } return new \core\dml\recordset_walk($recordset, function($record) { if ($record->id == SITEID) { return false; } $context = \context_helper::preload_from_record($record); return \core_analytics\course::instance($record, $context); }); }
php
public function get_analysables_iterator(?string $action = null) { global $DB; list($sql, $params) = $this->get_iterator_sql('course', CONTEXT_COURSE, $action, 'c'); // This will be updated to filter by context as part of MDL-64739. if (!empty($this->options['filter'])) { $courses = array(); foreach ($this->options['filter'] as $courseid) { $courses[$courseid] = new \stdClass(); $courses[$courseid]->id = $courseid; } list($coursesql, $courseparams) = $DB->get_in_or_equal($courses, SQL_PARAMS_NAMED); $sql .= " AND c.id IN $coursesql"; $params = $params + $courseparams; } $ordersql = $this->order_sql('sortorder', 'ASC', 'c'); $recordset = $DB->get_recordset_sql($sql . $ordersql, $params); if (!$recordset->valid()) { $this->add_log(get_string('nocourses', 'analytics')); return new \ArrayIterator([]); } return new \core\dml\recordset_walk($recordset, function($record) { if ($record->id == SITEID) { return false; } $context = \context_helper::preload_from_record($record); return \core_analytics\course::instance($record, $context); }); }
[ "public", "function", "get_analysables_iterator", "(", "?", "string", "$", "action", "=", "null", ")", "{", "global", "$", "DB", ";", "list", "(", "$", "sql", ",", "$", "params", ")", "=", "$", "this", "->", "get_iterator_sql", "(", "'course'", ",", "CONTEXT_COURSE", ",", "$", "action", ",", "'c'", ")", ";", "// This will be updated to filter by context as part of MDL-64739.", "if", "(", "!", "empty", "(", "$", "this", "->", "options", "[", "'filter'", "]", ")", ")", "{", "$", "courses", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "options", "[", "'filter'", "]", "as", "$", "courseid", ")", "{", "$", "courses", "[", "$", "courseid", "]", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "courses", "[", "$", "courseid", "]", "->", "id", "=", "$", "courseid", ";", "}", "list", "(", "$", "coursesql", ",", "$", "courseparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "courses", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "sql", ".=", "\" AND c.id IN $coursesql\"", ";", "$", "params", "=", "$", "params", "+", "$", "courseparams", ";", "}", "$", "ordersql", "=", "$", "this", "->", "order_sql", "(", "'sortorder'", ",", "'ASC'", ",", "'c'", ")", ";", "$", "recordset", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ".", "$", "ordersql", ",", "$", "params", ")", ";", "if", "(", "!", "$", "recordset", "->", "valid", "(", ")", ")", "{", "$", "this", "->", "add_log", "(", "get_string", "(", "'nocourses'", ",", "'analytics'", ")", ")", ";", "return", "new", "\\", "ArrayIterator", "(", "[", "]", ")", ";", "}", "return", "new", "\\", "core", "\\", "dml", "\\", "recordset_walk", "(", "$", "recordset", ",", "function", "(", "$", "record", ")", "{", "if", "(", "$", "record", "->", "id", "==", "SITEID", ")", "{", "return", "false", ";", "}", "$", "context", "=", "\\", "context_helper", "::", "preload_from_record", "(", "$", "record", ")", ";", "return", "\\", "core_analytics", "\\", "course", "::", "instance", "(", "$", "record", ",", "$", "context", ")", ";", "}", ")", ";", "}" ]
Return the list of courses to analyse. @param string|null $action 'prediction', 'training' or null if no specific action needed. @return \Iterator
[ "Return", "the", "list", "of", "courses", "to", "analyse", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/analyser/by_course.php#L44-L79
217,985
moodle/moodle
lib/horde/framework/Horde/Support/Memory.php
Horde_Support_Memory.push
public function push() { $start = $this->_start[$this->_idx++] = array( memory_get_usage(), memory_get_peak_usage(), memory_get_usage(true), memory_get_peak_usage(true) ); return $start; }
php
public function push() { $start = $this->_start[$this->_idx++] = array( memory_get_usage(), memory_get_peak_usage(), memory_get_usage(true), memory_get_peak_usage(true) ); return $start; }
[ "public", "function", "push", "(", ")", "{", "$", "start", "=", "$", "this", "->", "_start", "[", "$", "this", "->", "_idx", "++", "]", "=", "array", "(", "memory_get_usage", "(", ")", ",", "memory_get_peak_usage", "(", ")", ",", "memory_get_usage", "(", "true", ")", ",", "memory_get_peak_usage", "(", "true", ")", ")", ";", "return", "$", "start", ";", "}" ]
Push a new tracker on the stack.
[ "Push", "a", "new", "tracker", "on", "the", "stack", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Support/Memory.php#L47-L56
217,986
moodle/moodle
lib/horde/framework/Horde/Support/Memory.php
Horde_Support_Memory.pop
public function pop() { if (! ($this->_idx > 0)) { throw new Exception('No timers have been started'); } $start = $this->_start[--$this->_idx]; return array( memory_get_usage() - $start[0], memory_get_peak_usage() - $start[1], memory_get_usage(true) - $start[2], memory_get_peak_usage(true) - $start[3] ); }
php
public function pop() { if (! ($this->_idx > 0)) { throw new Exception('No timers have been started'); } $start = $this->_start[--$this->_idx]; return array( memory_get_usage() - $start[0], memory_get_peak_usage() - $start[1], memory_get_usage(true) - $start[2], memory_get_peak_usage(true) - $start[3] ); }
[ "public", "function", "pop", "(", ")", "{", "if", "(", "!", "(", "$", "this", "->", "_idx", ">", "0", ")", ")", "{", "throw", "new", "Exception", "(", "'No timers have been started'", ")", ";", "}", "$", "start", "=", "$", "this", "->", "_start", "[", "--", "$", "this", "->", "_idx", "]", ";", "return", "array", "(", "memory_get_usage", "(", ")", "-", "$", "start", "[", "0", "]", ",", "memory_get_peak_usage", "(", ")", "-", "$", "start", "[", "1", "]", ",", "memory_get_usage", "(", "true", ")", "-", "$", "start", "[", "2", "]", ",", "memory_get_peak_usage", "(", "true", ")", "-", "$", "start", "[", "3", "]", ")", ";", "}" ]
Pop the latest tracker and return the difference with the current memory situation. @return array The change in memory allocated via emalloc() in between the push() and the pop() call. The array holds four values: the first one indicates the change in current usage of memory while the second value indicates any changes in the peak amount of memory used. The third and fourth value show current and peak usage as well but indicate the real memory usage and not just the part allocated via emalloc(),
[ "Pop", "the", "latest", "tracker", "and", "return", "the", "difference", "with", "the", "current", "memory", "situation", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Support/Memory.php#L70-L82
217,987
moodle/moodle
lib/classes/user.php
core_user.get_user_by_email
public static function get_user_by_email($email, $fields = '*', $mnethostid = null, $strictness = IGNORE_MISSING) { global $DB, $CFG; // Because we use the username as the search criteria, we must also restrict our search based on mnet host. if (empty($mnethostid)) { // If empty, we restrict to local users. $mnethostid = $CFG->mnet_localhost_id; } return $DB->get_record('user', array('email' => $email, 'mnethostid' => $mnethostid), $fields, $strictness); }
php
public static function get_user_by_email($email, $fields = '*', $mnethostid = null, $strictness = IGNORE_MISSING) { global $DB, $CFG; // Because we use the username as the search criteria, we must also restrict our search based on mnet host. if (empty($mnethostid)) { // If empty, we restrict to local users. $mnethostid = $CFG->mnet_localhost_id; } return $DB->get_record('user', array('email' => $email, 'mnethostid' => $mnethostid), $fields, $strictness); }
[ "public", "static", "function", "get_user_by_email", "(", "$", "email", ",", "$", "fields", "=", "'*'", ",", "$", "mnethostid", "=", "null", ",", "$", "strictness", "=", "IGNORE_MISSING", ")", "{", "global", "$", "DB", ",", "$", "CFG", ";", "// Because we use the username as the search criteria, we must also restrict our search based on mnet host.", "if", "(", "empty", "(", "$", "mnethostid", ")", ")", "{", "// If empty, we restrict to local users.", "$", "mnethostid", "=", "$", "CFG", "->", "mnet_localhost_id", ";", "}", "return", "$", "DB", "->", "get_record", "(", "'user'", ",", "array", "(", "'email'", "=>", "$", "email", ",", "'mnethostid'", "=>", "$", "mnethostid", ")", ",", "$", "fields", ",", "$", "strictness", ")", ";", "}" ]
Return user object from db based on their email. @param string $email The email of the user searched. @param string $fields A comma separated list of user fields to be returned, support and noreply user. @param int $mnethostid The id of the remote host. @param int $strictness IGNORE_MISSING means compatible mode, false returned if user not found, debug message if more found; IGNORE_MULTIPLE means return first user, ignore multiple user records found(not recommended); MUST_EXIST means throw an exception if no user record or multiple records found. @return stdClass|bool user record if found, else false. @throws dml_exception if user record not found and respective $strictness is set.
[ "Return", "user", "object", "from", "db", "based", "on", "their", "email", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/user.php#L146-L156
217,988
moodle/moodle
lib/classes/user.php
core_user.get_user_by_username
public static function get_user_by_username($username, $fields = '*', $mnethostid = null, $strictness = IGNORE_MISSING) { global $DB, $CFG; // Because we use the username as the search criteria, we must also restrict our search based on mnet host. if (empty($mnethostid)) { // If empty, we restrict to local users. $mnethostid = $CFG->mnet_localhost_id; } return $DB->get_record('user', array('username' => $username, 'mnethostid' => $mnethostid), $fields, $strictness); }
php
public static function get_user_by_username($username, $fields = '*', $mnethostid = null, $strictness = IGNORE_MISSING) { global $DB, $CFG; // Because we use the username as the search criteria, we must also restrict our search based on mnet host. if (empty($mnethostid)) { // If empty, we restrict to local users. $mnethostid = $CFG->mnet_localhost_id; } return $DB->get_record('user', array('username' => $username, 'mnethostid' => $mnethostid), $fields, $strictness); }
[ "public", "static", "function", "get_user_by_username", "(", "$", "username", ",", "$", "fields", "=", "'*'", ",", "$", "mnethostid", "=", "null", ",", "$", "strictness", "=", "IGNORE_MISSING", ")", "{", "global", "$", "DB", ",", "$", "CFG", ";", "// Because we use the username as the search criteria, we must also restrict our search based on mnet host.", "if", "(", "empty", "(", "$", "mnethostid", ")", ")", "{", "// If empty, we restrict to local users.", "$", "mnethostid", "=", "$", "CFG", "->", "mnet_localhost_id", ";", "}", "return", "$", "DB", "->", "get_record", "(", "'user'", ",", "array", "(", "'username'", "=>", "$", "username", ",", "'mnethostid'", "=>", "$", "mnethostid", ")", ",", "$", "fields", ",", "$", "strictness", ")", ";", "}" ]
Return user object from db based on their username. @param string $username The username of the user searched. @param string $fields A comma separated list of user fields to be returned, support and noreply user. @param int $mnethostid The id of the remote host. @param int $strictness IGNORE_MISSING means compatible mode, false returned if user not found, debug message if more found; IGNORE_MULTIPLE means return first user, ignore multiple user records found(not recommended); MUST_EXIST means throw an exception if no user record or multiple records found. @return stdClass|bool user record if found, else false. @throws dml_exception if user record not found and respective $strictness is set.
[ "Return", "user", "object", "from", "db", "based", "on", "their", "username", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/user.php#L170-L180
217,989
moodle/moodle
lib/classes/user.php
core_user.get_enrolled_sql_on_courses_with_capability
protected static function get_enrolled_sql_on_courses_with_capability($capability) { // Get all courses where user have the capability. $courses = get_user_capability_course($capability, null, true, implode(',', array_values(context_helper::get_preload_record_columns('ctx')))); if (!$courses) { return [null, null]; } // Loop around all courses getting the SQL for enrolled users. Note: This query could // probably be more efficient (without the union) if get_enrolled_sql had a way to // pass an array of courseids, but it doesn't. $unionsql = ''; $unionparams = []; foreach ($courses as $course) { // Get SQL to list user ids enrolled in this course. \context_helper::preload_from_record($course); list ($sql, $params) = get_enrolled_sql(\context_course::instance($course->id)); // Combine to a big union query. if ($unionsql) { $unionsql .= ' UNION '; } $unionsql .= $sql; $unionparams = array_merge($unionparams, $params); } return [$unionsql, $unionparams]; }
php
protected static function get_enrolled_sql_on_courses_with_capability($capability) { // Get all courses where user have the capability. $courses = get_user_capability_course($capability, null, true, implode(',', array_values(context_helper::get_preload_record_columns('ctx')))); if (!$courses) { return [null, null]; } // Loop around all courses getting the SQL for enrolled users. Note: This query could // probably be more efficient (without the union) if get_enrolled_sql had a way to // pass an array of courseids, but it doesn't. $unionsql = ''; $unionparams = []; foreach ($courses as $course) { // Get SQL to list user ids enrolled in this course. \context_helper::preload_from_record($course); list ($sql, $params) = get_enrolled_sql(\context_course::instance($course->id)); // Combine to a big union query. if ($unionsql) { $unionsql .= ' UNION '; } $unionsql .= $sql; $unionparams = array_merge($unionparams, $params); } return [$unionsql, $unionparams]; }
[ "protected", "static", "function", "get_enrolled_sql_on_courses_with_capability", "(", "$", "capability", ")", "{", "// Get all courses where user have the capability.", "$", "courses", "=", "get_user_capability_course", "(", "$", "capability", ",", "null", ",", "true", ",", "implode", "(", "','", ",", "array_values", "(", "context_helper", "::", "get_preload_record_columns", "(", "'ctx'", ")", ")", ")", ")", ";", "if", "(", "!", "$", "courses", ")", "{", "return", "[", "null", ",", "null", "]", ";", "}", "// Loop around all courses getting the SQL for enrolled users. Note: This query could", "// probably be more efficient (without the union) if get_enrolled_sql had a way to", "// pass an array of courseids, but it doesn't.", "$", "unionsql", "=", "''", ";", "$", "unionparams", "=", "[", "]", ";", "foreach", "(", "$", "courses", "as", "$", "course", ")", "{", "// Get SQL to list user ids enrolled in this course.", "\\", "context_helper", "::", "preload_from_record", "(", "$", "course", ")", ";", "list", "(", "$", "sql", ",", "$", "params", ")", "=", "get_enrolled_sql", "(", "\\", "context_course", "::", "instance", "(", "$", "course", "->", "id", ")", ")", ";", "// Combine to a big union query.", "if", "(", "$", "unionsql", ")", "{", "$", "unionsql", ".=", "' UNION '", ";", "}", "$", "unionsql", ".=", "$", "sql", ";", "$", "unionparams", "=", "array_merge", "(", "$", "unionparams", ",", "$", "params", ")", ";", "}", "return", "[", "$", "unionsql", ",", "$", "unionparams", "]", ";", "}" ]
Gets an SQL query that lists all enrolled user ids on any course where the current user has the specified capability. Helper function used for searching users. @param string $capability Required capability @return array Array containing SQL and params, or two nulls if there are no courses
[ "Gets", "an", "SQL", "query", "that", "lists", "all", "enrolled", "user", "ids", "on", "any", "course", "where", "the", "current", "user", "has", "the", "specified", "capability", ".", "Helper", "function", "used", "for", "searching", "users", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/user.php#L382-L409
217,990
moodle/moodle
lib/classes/user.php
core_user.get_dummy_user_record
protected static function get_dummy_user_record() { global $CFG; $dummyuser = new stdClass(); $dummyuser->id = self::NOREPLY_USER; $dummyuser->email = $CFG->noreplyaddress; $dummyuser->firstname = get_string('noreplyname'); $dummyuser->username = 'noreply'; $dummyuser->lastname = ''; $dummyuser->confirmed = 1; $dummyuser->suspended = 0; $dummyuser->deleted = 0; $dummyuser->picture = 0; $dummyuser->auth = 'manual'; $dummyuser->firstnamephonetic = ''; $dummyuser->lastnamephonetic = ''; $dummyuser->middlename = ''; $dummyuser->alternatename = ''; $dummyuser->imagealt = ''; return $dummyuser; }
php
protected static function get_dummy_user_record() { global $CFG; $dummyuser = new stdClass(); $dummyuser->id = self::NOREPLY_USER; $dummyuser->email = $CFG->noreplyaddress; $dummyuser->firstname = get_string('noreplyname'); $dummyuser->username = 'noreply'; $dummyuser->lastname = ''; $dummyuser->confirmed = 1; $dummyuser->suspended = 0; $dummyuser->deleted = 0; $dummyuser->picture = 0; $dummyuser->auth = 'manual'; $dummyuser->firstnamephonetic = ''; $dummyuser->lastnamephonetic = ''; $dummyuser->middlename = ''; $dummyuser->alternatename = ''; $dummyuser->imagealt = ''; return $dummyuser; }
[ "protected", "static", "function", "get_dummy_user_record", "(", ")", "{", "global", "$", "CFG", ";", "$", "dummyuser", "=", "new", "stdClass", "(", ")", ";", "$", "dummyuser", "->", "id", "=", "self", "::", "NOREPLY_USER", ";", "$", "dummyuser", "->", "email", "=", "$", "CFG", "->", "noreplyaddress", ";", "$", "dummyuser", "->", "firstname", "=", "get_string", "(", "'noreplyname'", ")", ";", "$", "dummyuser", "->", "username", "=", "'noreply'", ";", "$", "dummyuser", "->", "lastname", "=", "''", ";", "$", "dummyuser", "->", "confirmed", "=", "1", ";", "$", "dummyuser", "->", "suspended", "=", "0", ";", "$", "dummyuser", "->", "deleted", "=", "0", ";", "$", "dummyuser", "->", "picture", "=", "0", ";", "$", "dummyuser", "->", "auth", "=", "'manual'", ";", "$", "dummyuser", "->", "firstnamephonetic", "=", "''", ";", "$", "dummyuser", "->", "lastnamephonetic", "=", "''", ";", "$", "dummyuser", "->", "middlename", "=", "''", ";", "$", "dummyuser", "->", "alternatename", "=", "''", ";", "$", "dummyuser", "->", "imagealt", "=", "''", ";", "return", "$", "dummyuser", ";", "}" ]
Helper function to return dummy noreply user record. @return stdClass
[ "Helper", "function", "to", "return", "dummy", "noreply", "user", "record", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/user.php#L416-L436
217,991
moodle/moodle
lib/classes/user.php
core_user.is_real_user
public static function is_real_user($userid, $checkdb = false) { global $DB; if ($userid <= 0) { return false; } if ($checkdb) { return $DB->record_exists('user', array('id' => $userid)); } else { return true; } }
php
public static function is_real_user($userid, $checkdb = false) { global $DB; if ($userid <= 0) { return false; } if ($checkdb) { return $DB->record_exists('user', array('id' => $userid)); } else { return true; } }
[ "public", "static", "function", "is_real_user", "(", "$", "userid", ",", "$", "checkdb", "=", "false", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "userid", "<=", "0", ")", "{", "return", "false", ";", "}", "if", "(", "$", "checkdb", ")", "{", "return", "$", "DB", "->", "record_exists", "(", "'user'", ",", "array", "(", "'id'", "=>", "$", "userid", ")", ")", ";", "}", "else", "{", "return", "true", ";", "}", "}" ]
Return true if user id is greater than 0 and alternatively check db. @param int $userid user id. @param bool $checkdb if true userid will be checked in db. By default it's false, and userid is compared with 0 for performance. @return bool true is real user else false.
[ "Return", "true", "if", "user", "id", "is", "greater", "than", "0", "and", "alternatively", "check", "db", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/user.php#L534-L545
217,992
moodle/moodle
lib/classes/user.php
core_user.require_active_user
public static function require_active_user($user, $checksuspended = false, $checknologin = false) { if (!self::is_real_user($user->id)) { throw new moodle_exception('invaliduser', 'error'); } if ($user->deleted) { throw new moodle_exception('userdeleted'); } if (empty($user->confirmed)) { throw new moodle_exception('usernotconfirmed', 'moodle', '', $user->username); } if (isguestuser($user)) { throw new moodle_exception('guestsarenotallowed', 'error'); } if ($checksuspended and $user->suspended) { throw new moodle_exception('suspended', 'auth'); } if ($checknologin and $user->auth == 'nologin') { throw new moodle_exception('suspended', 'auth'); } }
php
public static function require_active_user($user, $checksuspended = false, $checknologin = false) { if (!self::is_real_user($user->id)) { throw new moodle_exception('invaliduser', 'error'); } if ($user->deleted) { throw new moodle_exception('userdeleted'); } if (empty($user->confirmed)) { throw new moodle_exception('usernotconfirmed', 'moodle', '', $user->username); } if (isguestuser($user)) { throw new moodle_exception('guestsarenotallowed', 'error'); } if ($checksuspended and $user->suspended) { throw new moodle_exception('suspended', 'auth'); } if ($checknologin and $user->auth == 'nologin') { throw new moodle_exception('suspended', 'auth'); } }
[ "public", "static", "function", "require_active_user", "(", "$", "user", ",", "$", "checksuspended", "=", "false", ",", "$", "checknologin", "=", "false", ")", "{", "if", "(", "!", "self", "::", "is_real_user", "(", "$", "user", "->", "id", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'invaliduser'", ",", "'error'", ")", ";", "}", "if", "(", "$", "user", "->", "deleted", ")", "{", "throw", "new", "moodle_exception", "(", "'userdeleted'", ")", ";", "}", "if", "(", "empty", "(", "$", "user", "->", "confirmed", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'usernotconfirmed'", ",", "'moodle'", ",", "''", ",", "$", "user", "->", "username", ")", ";", "}", "if", "(", "isguestuser", "(", "$", "user", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'guestsarenotallowed'", ",", "'error'", ")", ";", "}", "if", "(", "$", "checksuspended", "and", "$", "user", "->", "suspended", ")", "{", "throw", "new", "moodle_exception", "(", "'suspended'", ",", "'auth'", ")", ";", "}", "if", "(", "$", "checknologin", "and", "$", "user", "->", "auth", "==", "'nologin'", ")", "{", "throw", "new", "moodle_exception", "(", "'suspended'", ",", "'auth'", ")", ";", "}", "}" ]
Check if the given user is an active user in the site. @param stdClass $user user object @param boolean $checksuspended whether to check if the user has the account suspended @param boolean $checknologin whether to check if the user uses the nologin auth method @throws moodle_exception @since Moodle 3.0
[ "Check", "if", "the", "given", "user", "is", "an", "active", "user", "in", "the", "site", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/user.php#L556-L581
217,993
moodle/moodle
lib/classes/user.php
core_user.update_picture
public static function update_picture(stdClass $usernew, $filemanageroptions = array()) { global $CFG, $DB; require_once("$CFG->libdir/gdlib.php"); $context = context_user::instance($usernew->id, MUST_EXIST); $user = core_user::get_user($usernew->id, 'id, picture', MUST_EXIST); $newpicture = $user->picture; // Get file_storage to process files. $fs = get_file_storage(); if (!empty($usernew->deletepicture)) { // The user has chosen to delete the selected users picture. $fs->delete_area_files($context->id, 'user', 'icon'); // Drop all images in area. $newpicture = 0; } else { // Save newly uploaded file, this will avoid context mismatch for newly created users. file_save_draft_area_files($usernew->imagefile, $context->id, 'user', 'newicon', 0, $filemanageroptions); if (($iconfiles = $fs->get_area_files($context->id, 'user', 'newicon')) && count($iconfiles) == 2) { // Get file which was uploaded in draft area. foreach ($iconfiles as $file) { if (!$file->is_directory()) { break; } } // Copy file to temporary location and the send it for processing icon. if ($iconfile = $file->copy_content_to_temp()) { // There is a new image that has been uploaded. // Process the new image and set the user to make use of it. // NOTE: Uploaded images always take over Gravatar. $newpicture = (int)process_new_icon($context, 'user', 'icon', 0, $iconfile); // Delete temporary file. @unlink($iconfile); // Remove uploaded file. $fs->delete_area_files($context->id, 'user', 'newicon'); } else { // Something went wrong while creating temp file. // Remove uploaded file. $fs->delete_area_files($context->id, 'user', 'newicon'); return false; } } } if ($newpicture != $user->picture) { $DB->set_field('user', 'picture', $newpicture, array('id' => $user->id)); return true; } else { return false; } }
php
public static function update_picture(stdClass $usernew, $filemanageroptions = array()) { global $CFG, $DB; require_once("$CFG->libdir/gdlib.php"); $context = context_user::instance($usernew->id, MUST_EXIST); $user = core_user::get_user($usernew->id, 'id, picture', MUST_EXIST); $newpicture = $user->picture; // Get file_storage to process files. $fs = get_file_storage(); if (!empty($usernew->deletepicture)) { // The user has chosen to delete the selected users picture. $fs->delete_area_files($context->id, 'user', 'icon'); // Drop all images in area. $newpicture = 0; } else { // Save newly uploaded file, this will avoid context mismatch for newly created users. file_save_draft_area_files($usernew->imagefile, $context->id, 'user', 'newicon', 0, $filemanageroptions); if (($iconfiles = $fs->get_area_files($context->id, 'user', 'newicon')) && count($iconfiles) == 2) { // Get file which was uploaded in draft area. foreach ($iconfiles as $file) { if (!$file->is_directory()) { break; } } // Copy file to temporary location and the send it for processing icon. if ($iconfile = $file->copy_content_to_temp()) { // There is a new image that has been uploaded. // Process the new image and set the user to make use of it. // NOTE: Uploaded images always take over Gravatar. $newpicture = (int)process_new_icon($context, 'user', 'icon', 0, $iconfile); // Delete temporary file. @unlink($iconfile); // Remove uploaded file. $fs->delete_area_files($context->id, 'user', 'newicon'); } else { // Something went wrong while creating temp file. // Remove uploaded file. $fs->delete_area_files($context->id, 'user', 'newicon'); return false; } } } if ($newpicture != $user->picture) { $DB->set_field('user', 'picture', $newpicture, array('id' => $user->id)); return true; } else { return false; } }
[ "public", "static", "function", "update_picture", "(", "stdClass", "$", "usernew", ",", "$", "filemanageroptions", "=", "array", "(", ")", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "require_once", "(", "\"$CFG->libdir/gdlib.php\"", ")", ";", "$", "context", "=", "context_user", "::", "instance", "(", "$", "usernew", "->", "id", ",", "MUST_EXIST", ")", ";", "$", "user", "=", "core_user", "::", "get_user", "(", "$", "usernew", "->", "id", ",", "'id, picture'", ",", "MUST_EXIST", ")", ";", "$", "newpicture", "=", "$", "user", "->", "picture", ";", "// Get file_storage to process files.", "$", "fs", "=", "get_file_storage", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "usernew", "->", "deletepicture", ")", ")", "{", "// The user has chosen to delete the selected users picture.", "$", "fs", "->", "delete_area_files", "(", "$", "context", "->", "id", ",", "'user'", ",", "'icon'", ")", ";", "// Drop all images in area.", "$", "newpicture", "=", "0", ";", "}", "else", "{", "// Save newly uploaded file, this will avoid context mismatch for newly created users.", "file_save_draft_area_files", "(", "$", "usernew", "->", "imagefile", ",", "$", "context", "->", "id", ",", "'user'", ",", "'newicon'", ",", "0", ",", "$", "filemanageroptions", ")", ";", "if", "(", "(", "$", "iconfiles", "=", "$", "fs", "->", "get_area_files", "(", "$", "context", "->", "id", ",", "'user'", ",", "'newicon'", ")", ")", "&&", "count", "(", "$", "iconfiles", ")", "==", "2", ")", "{", "// Get file which was uploaded in draft area.", "foreach", "(", "$", "iconfiles", "as", "$", "file", ")", "{", "if", "(", "!", "$", "file", "->", "is_directory", "(", ")", ")", "{", "break", ";", "}", "}", "// Copy file to temporary location and the send it for processing icon.", "if", "(", "$", "iconfile", "=", "$", "file", "->", "copy_content_to_temp", "(", ")", ")", "{", "// There is a new image that has been uploaded.", "// Process the new image and set the user to make use of it.", "// NOTE: Uploaded images always take over Gravatar.", "$", "newpicture", "=", "(", "int", ")", "process_new_icon", "(", "$", "context", ",", "'user'", ",", "'icon'", ",", "0", ",", "$", "iconfile", ")", ";", "// Delete temporary file.", "@", "unlink", "(", "$", "iconfile", ")", ";", "// Remove uploaded file.", "$", "fs", "->", "delete_area_files", "(", "$", "context", "->", "id", ",", "'user'", ",", "'newicon'", ")", ";", "}", "else", "{", "// Something went wrong while creating temp file.", "// Remove uploaded file.", "$", "fs", "->", "delete_area_files", "(", "$", "context", "->", "id", ",", "'user'", ",", "'newicon'", ")", ";", "return", "false", ";", "}", "}", "}", "if", "(", "$", "newpicture", "!=", "$", "user", "->", "picture", ")", "{", "$", "DB", "->", "set_field", "(", "'user'", ",", "'picture'", ",", "$", "newpicture", ",", "array", "(", "'id'", "=>", "$", "user", "->", "id", ")", ")", ";", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Updates the provided users profile picture based upon the expected fields returned from the edit or edit_advanced forms. @param stdClass $usernew An object that contains some information about the user being updated @param array $filemanageroptions @return bool True if the user was updated, false if it stayed the same.
[ "Updates", "the", "provided", "users", "profile", "picture", "based", "upon", "the", "expected", "fields", "returned", "from", "the", "edit", "or", "edit_advanced", "forms", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/user.php#L590-L640
217,994
moodle/moodle
lib/classes/user.php
core_user.get_property_definition
public static function get_property_definition($property) { self::fill_properties_cache(); if (!array_key_exists($property, self::$propertiescache)) { throw new coding_exception('Invalid property requested.'); } return self::$propertiescache[$property]; }
php
public static function get_property_definition($property) { self::fill_properties_cache(); if (!array_key_exists($property, self::$propertiescache)) { throw new coding_exception('Invalid property requested.'); } return self::$propertiescache[$property]; }
[ "public", "static", "function", "get_property_definition", "(", "$", "property", ")", "{", "self", "::", "fill_properties_cache", "(", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "property", ",", "self", "::", "$", "propertiescache", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Invalid property requested.'", ")", ";", "}", "return", "self", "::", "$", "propertiescache", "[", "$", "property", "]", ";", "}" ]
Get properties of a user field. @param string $property property name to be retrieved. @throws coding_exception if the requested property name is invalid. @return array the property definition.
[ "Get", "properties", "of", "a", "user", "field", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/user.php#L744-L753
217,995
moodle/moodle
lib/classes/user.php
core_user.validate
public static function validate($data) { // Get all user profile fields definition. self::fill_properties_cache(); foreach ($data as $property => $value) { try { if (isset(self::$propertiescache[$property])) { validate_param($value, self::$propertiescache[$property]['type'], self::$propertiescache[$property]['null']); } // Check that the value is part of a list of allowed values. if (!empty(self::$propertiescache[$property]['choices']) && !isset(self::$propertiescache[$property]['choices'][$value])) { throw new invalid_parameter_exception($value); } } catch (invalid_parameter_exception $e) { $errors[$property] = $e->getMessage(); } } return empty($errors) ? true : $errors; }
php
public static function validate($data) { // Get all user profile fields definition. self::fill_properties_cache(); foreach ($data as $property => $value) { try { if (isset(self::$propertiescache[$property])) { validate_param($value, self::$propertiescache[$property]['type'], self::$propertiescache[$property]['null']); } // Check that the value is part of a list of allowed values. if (!empty(self::$propertiescache[$property]['choices']) && !isset(self::$propertiescache[$property]['choices'][$value])) { throw new invalid_parameter_exception($value); } } catch (invalid_parameter_exception $e) { $errors[$property] = $e->getMessage(); } } return empty($errors) ? true : $errors; }
[ "public", "static", "function", "validate", "(", "$", "data", ")", "{", "// Get all user profile fields definition.", "self", "::", "fill_properties_cache", "(", ")", ";", "foreach", "(", "$", "data", "as", "$", "property", "=>", "$", "value", ")", "{", "try", "{", "if", "(", "isset", "(", "self", "::", "$", "propertiescache", "[", "$", "property", "]", ")", ")", "{", "validate_param", "(", "$", "value", ",", "self", "::", "$", "propertiescache", "[", "$", "property", "]", "[", "'type'", "]", ",", "self", "::", "$", "propertiescache", "[", "$", "property", "]", "[", "'null'", "]", ")", ";", "}", "// Check that the value is part of a list of allowed values.", "if", "(", "!", "empty", "(", "self", "::", "$", "propertiescache", "[", "$", "property", "]", "[", "'choices'", "]", ")", "&&", "!", "isset", "(", "self", "::", "$", "propertiescache", "[", "$", "property", "]", "[", "'choices'", "]", "[", "$", "value", "]", ")", ")", "{", "throw", "new", "invalid_parameter_exception", "(", "$", "value", ")", ";", "}", "}", "catch", "(", "invalid_parameter_exception", "$", "e", ")", "{", "$", "errors", "[", "$", "property", "]", "=", "$", "e", "->", "getMessage", "(", ")", ";", "}", "}", "return", "empty", "(", "$", "errors", ")", "?", "true", ":", "$", "errors", ";", "}" ]
Validate user data. This method just validates each user field and return an array of errors. It doesn't clean the data, the methods clean() and clean_field() should be used for this purpose. @param stdClass|array $data user data object or array to be validated. @return array|true $errors array of errors found on the user object, true if the validation passed.
[ "Validate", "user", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/user.php#L764-L784
217,996
moodle/moodle
lib/classes/user.php
core_user.clean_data
public static function clean_data($user) { if (empty($user)) { return $user; } foreach ($user as $field => $value) { // Get the property parameter type and do the cleaning. try { $user->$field = core_user::clean_field($value, $field); } catch (coding_exception $e) { debugging("The property '$field' could not be cleaned.", DEBUG_DEVELOPER); } } return $user; }
php
public static function clean_data($user) { if (empty($user)) { return $user; } foreach ($user as $field => $value) { // Get the property parameter type and do the cleaning. try { $user->$field = core_user::clean_field($value, $field); } catch (coding_exception $e) { debugging("The property '$field' could not be cleaned.", DEBUG_DEVELOPER); } } return $user; }
[ "public", "static", "function", "clean_data", "(", "$", "user", ")", "{", "if", "(", "empty", "(", "$", "user", ")", ")", "{", "return", "$", "user", ";", "}", "foreach", "(", "$", "user", "as", "$", "field", "=>", "$", "value", ")", "{", "// Get the property parameter type and do the cleaning.", "try", "{", "$", "user", "->", "$", "field", "=", "core_user", "::", "clean_field", "(", "$", "value", ",", "$", "field", ")", ";", "}", "catch", "(", "coding_exception", "$", "e", ")", "{", "debugging", "(", "\"The property '$field' could not be cleaned.\"", ",", "DEBUG_DEVELOPER", ")", ";", "}", "}", "return", "$", "user", ";", "}" ]
Clean the user data. @param stdClass|array $user the user data to be validated against properties definition. @return stdClass $user the cleaned user data.
[ "Clean", "the", "user", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/user.php#L802-L817
217,997
moodle/moodle
lib/classes/user.php
core_user.clean_field
public static function clean_field($data, $field) { if (empty($data) || empty($field)) { return $data; } try { $type = core_user::get_property_type($field); if (isset(self::$propertiescache[$field]['choices'])) { if (!array_key_exists($data, self::$propertiescache[$field]['choices'])) { if (isset(self::$propertiescache[$field]['default'])) { $data = self::$propertiescache[$field]['default']; } else { $data = ''; } } else { return $data; } } else { $data = clean_param($data, $type); } } catch (coding_exception $e) { debugging("The property '$field' could not be cleaned.", DEBUG_DEVELOPER); } return $data; }
php
public static function clean_field($data, $field) { if (empty($data) || empty($field)) { return $data; } try { $type = core_user::get_property_type($field); if (isset(self::$propertiescache[$field]['choices'])) { if (!array_key_exists($data, self::$propertiescache[$field]['choices'])) { if (isset(self::$propertiescache[$field]['default'])) { $data = self::$propertiescache[$field]['default']; } else { $data = ''; } } else { return $data; } } else { $data = clean_param($data, $type); } } catch (coding_exception $e) { debugging("The property '$field' could not be cleaned.", DEBUG_DEVELOPER); } return $data; }
[ "public", "static", "function", "clean_field", "(", "$", "data", ",", "$", "field", ")", "{", "if", "(", "empty", "(", "$", "data", ")", "||", "empty", "(", "$", "field", ")", ")", "{", "return", "$", "data", ";", "}", "try", "{", "$", "type", "=", "core_user", "::", "get_property_type", "(", "$", "field", ")", ";", "if", "(", "isset", "(", "self", "::", "$", "propertiescache", "[", "$", "field", "]", "[", "'choices'", "]", ")", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "data", ",", "self", "::", "$", "propertiescache", "[", "$", "field", "]", "[", "'choices'", "]", ")", ")", "{", "if", "(", "isset", "(", "self", "::", "$", "propertiescache", "[", "$", "field", "]", "[", "'default'", "]", ")", ")", "{", "$", "data", "=", "self", "::", "$", "propertiescache", "[", "$", "field", "]", "[", "'default'", "]", ";", "}", "else", "{", "$", "data", "=", "''", ";", "}", "}", "else", "{", "return", "$", "data", ";", "}", "}", "else", "{", "$", "data", "=", "clean_param", "(", "$", "data", ",", "$", "type", ")", ";", "}", "}", "catch", "(", "coding_exception", "$", "e", ")", "{", "debugging", "(", "\"The property '$field' could not be cleaned.\"", ",", "DEBUG_DEVELOPER", ")", ";", "}", "return", "$", "data", ";", "}" ]
Clean a specific user field. @param string $data the user field data to be cleaned. @param string $field the user field name on the property definition cache. @return string the cleaned user data.
[ "Clean", "a", "specific", "user", "field", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/user.php#L826-L852
217,998
moodle/moodle
lib/classes/user.php
core_user.get_property_type
public static function get_property_type($property) { self::fill_properties_cache(); if (!array_key_exists($property, self::$propertiescache)) { throw new coding_exception('Invalid property requested: ' . $property); } return self::$propertiescache[$property]['type']; }
php
public static function get_property_type($property) { self::fill_properties_cache(); if (!array_key_exists($property, self::$propertiescache)) { throw new coding_exception('Invalid property requested: ' . $property); } return self::$propertiescache[$property]['type']; }
[ "public", "static", "function", "get_property_type", "(", "$", "property", ")", "{", "self", "::", "fill_properties_cache", "(", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "property", ",", "self", "::", "$", "propertiescache", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Invalid property requested: '", ".", "$", "property", ")", ";", "}", "return", "self", "::", "$", "propertiescache", "[", "$", "property", "]", "[", "'type'", "]", ";", "}" ]
Get the parameter type of the property. @param string $property property name to be retrieved. @throws coding_exception if the requested property name is invalid. @return int the property parameter type.
[ "Get", "the", "parameter", "type", "of", "the", "property", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/user.php#L861-L870
217,999
moodle/moodle
lib/classes/user.php
core_user.get_property_null
public static function get_property_null($property) { self::fill_properties_cache(); if (!array_key_exists($property, self::$propertiescache)) { throw new coding_exception('Invalid property requested: ' . $property); } return self::$propertiescache[$property]['null']; }
php
public static function get_property_null($property) { self::fill_properties_cache(); if (!array_key_exists($property, self::$propertiescache)) { throw new coding_exception('Invalid property requested: ' . $property); } return self::$propertiescache[$property]['null']; }
[ "public", "static", "function", "get_property_null", "(", "$", "property", ")", "{", "self", "::", "fill_properties_cache", "(", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "property", ",", "self", "::", "$", "propertiescache", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Invalid property requested: '", ".", "$", "property", ")", ";", "}", "return", "self", "::", "$", "propertiescache", "[", "$", "property", "]", "[", "'null'", "]", ";", "}" ]
Discover if the property is NULL_ALLOWED or NULL_NOT_ALLOWED. @param string $property property name to be retrieved. @throws coding_exception if the requested property name is invalid. @return bool true if the property is NULL_ALLOWED, false otherwise.
[ "Discover", "if", "the", "property", "is", "NULL_ALLOWED", "or", "NULL_NOT_ALLOWED", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/user.php#L879-L888