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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
218,500
|
moodle/moodle
|
question/type/random/backup/moodle2/restore_qtype_random_plugin.class.php
|
restore_qtype_random_plugin.recode_legacy_state_answer
|
public function recode_legacy_state_answer($state) {
global $DB;
$answer = $state->answer;
$result = '';
// Randomxx-yy answer format.
if (preg_match('~^random([0-9]+)-(.*)$~', $answer, $matches)) {
$questionid = $matches[1];
$subanswer = $matches[2];
$newquestionid = $this->get_mappingid('question', $questionid);
$questionqtype = $DB->get_field('question', 'qtype', array('id' => $newquestionid));
// Delegate subanswer recode to proper qtype, faking one question_states record.
$substate = new stdClass();
$substate->question = $newquestionid;
$substate->answer = $subanswer;
$newanswer = $this->step->restore_recode_legacy_answer($substate, $questionqtype);
$result = 'random' . $newquestionid . '-' . $newanswer;
// Simple question id format.
} else {
$newquestionid = $this->get_mappingid('question', $answer);
$result = $newquestionid;
}
return $result;
}
|
php
|
public function recode_legacy_state_answer($state) {
global $DB;
$answer = $state->answer;
$result = '';
// Randomxx-yy answer format.
if (preg_match('~^random([0-9]+)-(.*)$~', $answer, $matches)) {
$questionid = $matches[1];
$subanswer = $matches[2];
$newquestionid = $this->get_mappingid('question', $questionid);
$questionqtype = $DB->get_field('question', 'qtype', array('id' => $newquestionid));
// Delegate subanswer recode to proper qtype, faking one question_states record.
$substate = new stdClass();
$substate->question = $newquestionid;
$substate->answer = $subanswer;
$newanswer = $this->step->restore_recode_legacy_answer($substate, $questionqtype);
$result = 'random' . $newquestionid . '-' . $newanswer;
// Simple question id format.
} else {
$newquestionid = $this->get_mappingid('question', $answer);
$result = $newquestionid;
}
return $result;
}
|
[
"public",
"function",
"recode_legacy_state_answer",
"(",
"$",
"state",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"answer",
"=",
"$",
"state",
"->",
"answer",
";",
"$",
"result",
"=",
"''",
";",
"// Randomxx-yy answer format.",
"if",
"(",
"preg_match",
"(",
"'~^random([0-9]+)-(.*)$~'",
",",
"$",
"answer",
",",
"$",
"matches",
")",
")",
"{",
"$",
"questionid",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"$",
"subanswer",
"=",
"$",
"matches",
"[",
"2",
"]",
";",
"$",
"newquestionid",
"=",
"$",
"this",
"->",
"get_mappingid",
"(",
"'question'",
",",
"$",
"questionid",
")",
";",
"$",
"questionqtype",
"=",
"$",
"DB",
"->",
"get_field",
"(",
"'question'",
",",
"'qtype'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"newquestionid",
")",
")",
";",
"// Delegate subanswer recode to proper qtype, faking one question_states record.",
"$",
"substate",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"substate",
"->",
"question",
"=",
"$",
"newquestionid",
";",
"$",
"substate",
"->",
"answer",
"=",
"$",
"subanswer",
";",
"$",
"newanswer",
"=",
"$",
"this",
"->",
"step",
"->",
"restore_recode_legacy_answer",
"(",
"$",
"substate",
",",
"$",
"questionqtype",
")",
";",
"$",
"result",
"=",
"'random'",
".",
"$",
"newquestionid",
".",
"'-'",
".",
"$",
"newanswer",
";",
"// Simple question id format.",
"}",
"else",
"{",
"$",
"newquestionid",
"=",
"$",
"this",
"->",
"get_mappingid",
"(",
"'question'",
",",
"$",
"answer",
")",
";",
"$",
"result",
"=",
"$",
"newquestionid",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Given one question_states record, return the answer
recoded pointing to all the restored stuff for random questions
answer format is randomxx-yy, with xx being question->id and
yy the actual response to the question. We'll delegate the recode
to the corresponding qtype
also, some old states can contain, simply, one question->id,
support them, just in case
|
[
"Given",
"one",
"question_states",
"record",
"return",
"the",
"answer",
"recoded",
"pointing",
"to",
"all",
"the",
"restored",
"stuff",
"for",
"random",
"questions"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/random/backup/moodle2/restore_qtype_random_plugin.class.php#L74-L98
|
218,501
|
moodle/moodle
|
question/type/random/backup/moodle2/restore_qtype_random_plugin.class.php
|
restore_qtype_random_plugin.after_execute_question
|
public function after_execute_question() {
global $DB;
// For random questions, questiontext should only ever be '0' or '1'.
// In the past there were sometimes junk values like ''. If there
// were any in the restore, fix them up.
//
// Note, we cannot just do this in one DB query, because MySQL is useless.
// The expected case is that the SELECT returns 0 rows, so loading all the
// ids should not be a problem.
$problemquestions = $DB->get_records_sql_menu("
SELECT q.id, 1
FROM {question} q
JOIN {backup_ids_temp} bi ON q.id = bi.newitemid
WHERE q.qtype = 'random'
AND " . $DB->sql_compare_text('q.questiontext') . " = ?
AND bi.backupid = ?
AND bi.itemname = 'question_created'
", array('', $this->get_restoreid()));
if (!$problemquestions) {
return; // Nothing to do.
}
list($idtest, $params) = $DB->get_in_or_equal(array_keys($problemquestions));
$DB->set_field_select('question', 'questiontext', '0', "id $idtest", $params);
}
|
php
|
public function after_execute_question() {
global $DB;
// For random questions, questiontext should only ever be '0' or '1'.
// In the past there were sometimes junk values like ''. If there
// were any in the restore, fix them up.
//
// Note, we cannot just do this in one DB query, because MySQL is useless.
// The expected case is that the SELECT returns 0 rows, so loading all the
// ids should not be a problem.
$problemquestions = $DB->get_records_sql_menu("
SELECT q.id, 1
FROM {question} q
JOIN {backup_ids_temp} bi ON q.id = bi.newitemid
WHERE q.qtype = 'random'
AND " . $DB->sql_compare_text('q.questiontext') . " = ?
AND bi.backupid = ?
AND bi.itemname = 'question_created'
", array('', $this->get_restoreid()));
if (!$problemquestions) {
return; // Nothing to do.
}
list($idtest, $params) = $DB->get_in_or_equal(array_keys($problemquestions));
$DB->set_field_select('question', 'questiontext', '0', "id $idtest", $params);
}
|
[
"public",
"function",
"after_execute_question",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"// For random questions, questiontext should only ever be '0' or '1'.",
"// In the past there were sometimes junk values like ''. If there",
"// were any in the restore, fix them up.",
"//",
"// Note, we cannot just do this in one DB query, because MySQL is useless.",
"// The expected case is that the SELECT returns 0 rows, so loading all the",
"// ids should not be a problem.",
"$",
"problemquestions",
"=",
"$",
"DB",
"->",
"get_records_sql_menu",
"(",
"\"\n SELECT q.id, 1\n FROM {question} q\n JOIN {backup_ids_temp} bi ON q.id = bi.newitemid\n WHERE q.qtype = 'random'\n AND \"",
".",
"$",
"DB",
"->",
"sql_compare_text",
"(",
"'q.questiontext'",
")",
".",
"\" = ?\n AND bi.backupid = ?\n AND bi.itemname = 'question_created'\n \"",
",",
"array",
"(",
"''",
",",
"$",
"this",
"->",
"get_restoreid",
"(",
")",
")",
")",
";",
"if",
"(",
"!",
"$",
"problemquestions",
")",
"{",
"return",
";",
"// Nothing to do.",
"}",
"list",
"(",
"$",
"idtest",
",",
"$",
"params",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"array_keys",
"(",
"$",
"problemquestions",
")",
")",
";",
"$",
"DB",
"->",
"set_field_select",
"(",
"'question'",
",",
"'questiontext'",
",",
"'0'",
",",
"\"id $idtest\"",
",",
"$",
"params",
")",
";",
"}"
] |
After restoring, make sure questiontext is set properly.
|
[
"After",
"restoring",
"make",
"sure",
"questiontext",
"is",
"set",
"properly",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/random/backup/moodle2/restore_qtype_random_plugin.class.php#L103-L129
|
218,502
|
moodle/moodle
|
mod/quiz/classes/question/bank/custom_view.php
|
custom_view.set_quiz_has_attempts
|
public function set_quiz_has_attempts($quizhasattempts) {
$this->quizhasattempts = $quizhasattempts;
if ($quizhasattempts && isset($this->visiblecolumns['addtoquizaction'])) {
unset($this->visiblecolumns['addtoquizaction']);
}
}
|
php
|
public function set_quiz_has_attempts($quizhasattempts) {
$this->quizhasattempts = $quizhasattempts;
if ($quizhasattempts && isset($this->visiblecolumns['addtoquizaction'])) {
unset($this->visiblecolumns['addtoquizaction']);
}
}
|
[
"public",
"function",
"set_quiz_has_attempts",
"(",
"$",
"quizhasattempts",
")",
"{",
"$",
"this",
"->",
"quizhasattempts",
"=",
"$",
"quizhasattempts",
";",
"if",
"(",
"$",
"quizhasattempts",
"&&",
"isset",
"(",
"$",
"this",
"->",
"visiblecolumns",
"[",
"'addtoquizaction'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"visiblecolumns",
"[",
"'addtoquizaction'",
"]",
")",
";",
"}",
"}"
] |
Let the question bank display know whether the quiz has been attempted,
hence whether some bits of UI, like the add this question to the quiz icon,
should be displayed.
@param bool $quizhasattempts whether the quiz has attempts.
|
[
"Let",
"the",
"question",
"bank",
"display",
"know",
"whether",
"the",
"quiz",
"has",
"been",
"attempted",
"hence",
"whether",
"some",
"bits",
"of",
"UI",
"like",
"the",
"add",
"this",
"question",
"to",
"the",
"quiz",
"icon",
"should",
"be",
"displayed",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/question/bank/custom_view.php#L114-L119
|
218,503
|
moodle/moodle
|
mod/quiz/classes/question/bank/custom_view.php
|
custom_view.print_choose_category_message
|
protected function print_choose_category_message($categoryandcontext) {
global $OUTPUT;
debugging('print_choose_category_message() is deprecated, ' .
'please use \core_question\bank\search\category_condition instead.', DEBUG_DEVELOPER);
echo $OUTPUT->box_start('generalbox questionbank');
$this->display_category_form($this->contexts->having_one_edit_tab_cap('edit'),
$this->baseurl, $categoryandcontext);
echo "<p style=\"text-align:center;\"><b>";
print_string('selectcategoryabove', 'question');
echo "</b></p>";
echo $OUTPUT->box_end();
}
|
php
|
protected function print_choose_category_message($categoryandcontext) {
global $OUTPUT;
debugging('print_choose_category_message() is deprecated, ' .
'please use \core_question\bank\search\category_condition instead.', DEBUG_DEVELOPER);
echo $OUTPUT->box_start('generalbox questionbank');
$this->display_category_form($this->contexts->having_one_edit_tab_cap('edit'),
$this->baseurl, $categoryandcontext);
echo "<p style=\"text-align:center;\"><b>";
print_string('selectcategoryabove', 'question');
echo "</b></p>";
echo $OUTPUT->box_end();
}
|
[
"protected",
"function",
"print_choose_category_message",
"(",
"$",
"categoryandcontext",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"debugging",
"(",
"'print_choose_category_message() is deprecated, '",
".",
"'please use \\core_question\\bank\\search\\category_condition instead.'",
",",
"DEBUG_DEVELOPER",
")",
";",
"echo",
"$",
"OUTPUT",
"->",
"box_start",
"(",
"'generalbox questionbank'",
")",
";",
"$",
"this",
"->",
"display_category_form",
"(",
"$",
"this",
"->",
"contexts",
"->",
"having_one_edit_tab_cap",
"(",
"'edit'",
")",
",",
"$",
"this",
"->",
"baseurl",
",",
"$",
"categoryandcontext",
")",
";",
"echo",
"\"<p style=\\\"text-align:center;\\\"><b>\"",
";",
"print_string",
"(",
"'selectcategoryabove'",
",",
"'question'",
")",
";",
"echo",
"\"</b></p>\"",
";",
"echo",
"$",
"OUTPUT",
"->",
"box_end",
"(",
")",
";",
"}"
] |
Prints a form to choose categories.
@param string $categoryandcontext 'categoryID,contextID'.
@deprecated since Moodle 2.6 MDL-40313.
@see \core_question\bank\search\category_condition
@todo MDL-41978 This will be deleted in Moodle 2.8
|
[
"Prints",
"a",
"form",
"to",
"choose",
"categories",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/question/bank/custom_view.php#L189-L200
|
218,504
|
moodle/moodle
|
calendar/classes/privacy/provider.php
|
provider.get_metadata
|
public static function get_metadata(collection $collection) : collection {
// The calendar 'event' table contains user data.
$collection->add_database_table(
'event',
[
'name' => 'privacy:metadata:calendar:event:name',
'description' => 'privacy:metadata:calendar:event:description',
'eventtype' => 'privacy:metadata:calendar:event:eventtype',
'timestart' => 'privacy:metadata:calendar:event:timestart',
'timeduration' => 'privacy:metadata:calendar:event:timeduration',
],
'privacy:metadata:calendar:event'
);
// The calendar 'event_subscriptions' table contains user data.
$collection->add_database_table(
'event_subscriptions',
[
'name' => 'privacy:metadata:calendar:event_subscriptions:name',
'url' => 'privacy:metadata:calendar:event_subscriptions:url',
'eventtype' => 'privacy:metadata:calendar:event_subscriptions:eventtype',
],
'privacy:metadata:calendar:event_subscriptions'
);
// The calendar user preference setting 'calendar_savedflt'.
$collection->add_user_preference(
'calendar_savedflt',
'privacy:metadata:calendar:preferences:calendar_savedflt'
);
return $collection;
}
|
php
|
public static function get_metadata(collection $collection) : collection {
// The calendar 'event' table contains user data.
$collection->add_database_table(
'event',
[
'name' => 'privacy:metadata:calendar:event:name',
'description' => 'privacy:metadata:calendar:event:description',
'eventtype' => 'privacy:metadata:calendar:event:eventtype',
'timestart' => 'privacy:metadata:calendar:event:timestart',
'timeduration' => 'privacy:metadata:calendar:event:timeduration',
],
'privacy:metadata:calendar:event'
);
// The calendar 'event_subscriptions' table contains user data.
$collection->add_database_table(
'event_subscriptions',
[
'name' => 'privacy:metadata:calendar:event_subscriptions:name',
'url' => 'privacy:metadata:calendar:event_subscriptions:url',
'eventtype' => 'privacy:metadata:calendar:event_subscriptions:eventtype',
],
'privacy:metadata:calendar:event_subscriptions'
);
// The calendar user preference setting 'calendar_savedflt'.
$collection->add_user_preference(
'calendar_savedflt',
'privacy:metadata:calendar:preferences:calendar_savedflt'
);
return $collection;
}
|
[
"public",
"static",
"function",
"get_metadata",
"(",
"collection",
"$",
"collection",
")",
":",
"collection",
"{",
"// The calendar 'event' table contains user data.",
"$",
"collection",
"->",
"add_database_table",
"(",
"'event'",
",",
"[",
"'name'",
"=>",
"'privacy:metadata:calendar:event:name'",
",",
"'description'",
"=>",
"'privacy:metadata:calendar:event:description'",
",",
"'eventtype'",
"=>",
"'privacy:metadata:calendar:event:eventtype'",
",",
"'timestart'",
"=>",
"'privacy:metadata:calendar:event:timestart'",
",",
"'timeduration'",
"=>",
"'privacy:metadata:calendar:event:timeduration'",
",",
"]",
",",
"'privacy:metadata:calendar:event'",
")",
";",
"// The calendar 'event_subscriptions' table contains user data.",
"$",
"collection",
"->",
"add_database_table",
"(",
"'event_subscriptions'",
",",
"[",
"'name'",
"=>",
"'privacy:metadata:calendar:event_subscriptions:name'",
",",
"'url'",
"=>",
"'privacy:metadata:calendar:event_subscriptions:url'",
",",
"'eventtype'",
"=>",
"'privacy:metadata:calendar:event_subscriptions:eventtype'",
",",
"]",
",",
"'privacy:metadata:calendar:event_subscriptions'",
")",
";",
"// The calendar user preference setting 'calendar_savedflt'.",
"$",
"collection",
"->",
"add_user_preference",
"(",
"'calendar_savedflt'",
",",
"'privacy:metadata:calendar:preferences:calendar_savedflt'",
")",
";",
"return",
"$",
"collection",
";",
"}"
] |
Provides meta data that is stored about a user with core_calendar.
@param collection $collection A collection of meta data items to be added to.
@return collection Returns the collection of metadata.
|
[
"Provides",
"meta",
"data",
"that",
"is",
"stored",
"about",
"a",
"user",
"with",
"core_calendar",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/privacy/provider.php#L57-L89
|
218,505
|
moodle/moodle
|
calendar/classes/privacy/provider.php
|
provider.get_contexts_for_userid
|
public static function get_contexts_for_userid(int $userid) : contextlist {
$contextlist = new contextlist();
// Calendar Events can exist at Site, Course Category, Course, Course Group, User, or Course Modules contexts.
$params = [
'sitecontext' => CONTEXT_SYSTEM,
'categorycontext' => CONTEXT_COURSECAT,
'coursecontext' => CONTEXT_COURSE,
'groupcontext' => CONTEXT_COURSE,
'usercontext' => CONTEXT_USER,
'cuserid' => $userid,
'modulecontext' => CONTEXT_MODULE,
'muserid' => $userid
];
// Get contexts of Calendar Events for the owner.
$sql = "SELECT ctx.id
FROM {context} ctx
JOIN {event} e ON
(e.eventtype = 'site' AND ctx.contextlevel = :sitecontext) OR
(e.categoryid = ctx.instanceid AND e.eventtype = 'category' AND ctx.contextlevel = :categorycontext) OR
(e.courseid = ctx.instanceid AND e.eventtype = 'course' AND ctx.contextlevel = :coursecontext) OR
(e.courseid = ctx.instanceid AND e.eventtype = 'group' AND ctx.contextlevel = :groupcontext) OR
(e.userid = ctx.instanceid AND e.eventtype = 'user' AND ctx.contextlevel = :usercontext)
WHERE e.userid = :cuserid
UNION
SELECT ctx.id
FROM {context} ctx
JOIN {course_modules} cm ON cm.id = ctx.instanceid AND ctx.contextlevel = :modulecontext
JOIN {modules} m ON m.id = cm.module
JOIN {event} e ON e.modulename = m.name AND e.courseid = cm.course AND e.instance = cm.instance
WHERE e.userid = :muserid";
$contextlist->add_from_sql($sql, $params);
// Calendar Subscriptions can exist at Site, Course Category, Course, Course Group, or User contexts.
$params = [
'sitecontext' => CONTEXT_SYSTEM,
'categorycontext' => CONTEXT_COURSECAT,
'coursecontext' => CONTEXT_COURSE,
'groupcontext' => CONTEXT_COURSE,
'usercontext' => CONTEXT_USER,
'userid' => $userid
];
// Get contexts for Calendar Subscriptions for the owner.
$sql = "SELECT ctx.id
FROM {context} ctx
JOIN {event_subscriptions} s ON
(s.eventtype = 'site' AND ctx.contextlevel = :sitecontext) OR
(s.categoryid = ctx.instanceid AND s.eventtype = 'category' AND ctx.contextlevel = :categorycontext) OR
(s.courseid = ctx.instanceid AND s.eventtype = 'course' AND ctx.contextlevel = :coursecontext) OR
(s.courseid = ctx.instanceid AND s.eventtype = 'group' AND ctx.contextlevel = :groupcontext) OR
(s.userid = ctx.instanceid AND s.eventtype = 'user' AND ctx.contextlevel = :usercontext)
WHERE s.userid = :userid";
$contextlist->add_from_sql($sql, $params);
// Return combined contextlist for Calendar Events & Calendar Subscriptions.
return $contextlist;
}
|
php
|
public static function get_contexts_for_userid(int $userid) : contextlist {
$contextlist = new contextlist();
// Calendar Events can exist at Site, Course Category, Course, Course Group, User, or Course Modules contexts.
$params = [
'sitecontext' => CONTEXT_SYSTEM,
'categorycontext' => CONTEXT_COURSECAT,
'coursecontext' => CONTEXT_COURSE,
'groupcontext' => CONTEXT_COURSE,
'usercontext' => CONTEXT_USER,
'cuserid' => $userid,
'modulecontext' => CONTEXT_MODULE,
'muserid' => $userid
];
// Get contexts of Calendar Events for the owner.
$sql = "SELECT ctx.id
FROM {context} ctx
JOIN {event} e ON
(e.eventtype = 'site' AND ctx.contextlevel = :sitecontext) OR
(e.categoryid = ctx.instanceid AND e.eventtype = 'category' AND ctx.contextlevel = :categorycontext) OR
(e.courseid = ctx.instanceid AND e.eventtype = 'course' AND ctx.contextlevel = :coursecontext) OR
(e.courseid = ctx.instanceid AND e.eventtype = 'group' AND ctx.contextlevel = :groupcontext) OR
(e.userid = ctx.instanceid AND e.eventtype = 'user' AND ctx.contextlevel = :usercontext)
WHERE e.userid = :cuserid
UNION
SELECT ctx.id
FROM {context} ctx
JOIN {course_modules} cm ON cm.id = ctx.instanceid AND ctx.contextlevel = :modulecontext
JOIN {modules} m ON m.id = cm.module
JOIN {event} e ON e.modulename = m.name AND e.courseid = cm.course AND e.instance = cm.instance
WHERE e.userid = :muserid";
$contextlist->add_from_sql($sql, $params);
// Calendar Subscriptions can exist at Site, Course Category, Course, Course Group, or User contexts.
$params = [
'sitecontext' => CONTEXT_SYSTEM,
'categorycontext' => CONTEXT_COURSECAT,
'coursecontext' => CONTEXT_COURSE,
'groupcontext' => CONTEXT_COURSE,
'usercontext' => CONTEXT_USER,
'userid' => $userid
];
// Get contexts for Calendar Subscriptions for the owner.
$sql = "SELECT ctx.id
FROM {context} ctx
JOIN {event_subscriptions} s ON
(s.eventtype = 'site' AND ctx.contextlevel = :sitecontext) OR
(s.categoryid = ctx.instanceid AND s.eventtype = 'category' AND ctx.contextlevel = :categorycontext) OR
(s.courseid = ctx.instanceid AND s.eventtype = 'course' AND ctx.contextlevel = :coursecontext) OR
(s.courseid = ctx.instanceid AND s.eventtype = 'group' AND ctx.contextlevel = :groupcontext) OR
(s.userid = ctx.instanceid AND s.eventtype = 'user' AND ctx.contextlevel = :usercontext)
WHERE s.userid = :userid";
$contextlist->add_from_sql($sql, $params);
// Return combined contextlist for Calendar Events & Calendar Subscriptions.
return $contextlist;
}
|
[
"public",
"static",
"function",
"get_contexts_for_userid",
"(",
"int",
"$",
"userid",
")",
":",
"contextlist",
"{",
"$",
"contextlist",
"=",
"new",
"contextlist",
"(",
")",
";",
"// Calendar Events can exist at Site, Course Category, Course, Course Group, User, or Course Modules contexts.",
"$",
"params",
"=",
"[",
"'sitecontext'",
"=>",
"CONTEXT_SYSTEM",
",",
"'categorycontext'",
"=>",
"CONTEXT_COURSECAT",
",",
"'coursecontext'",
"=>",
"CONTEXT_COURSE",
",",
"'groupcontext'",
"=>",
"CONTEXT_COURSE",
",",
"'usercontext'",
"=>",
"CONTEXT_USER",
",",
"'cuserid'",
"=>",
"$",
"userid",
",",
"'modulecontext'",
"=>",
"CONTEXT_MODULE",
",",
"'muserid'",
"=>",
"$",
"userid",
"]",
";",
"// Get contexts of Calendar Events for the owner.",
"$",
"sql",
"=",
"\"SELECT ctx.id\n FROM {context} ctx\n JOIN {event} e ON\n (e.eventtype = 'site' AND ctx.contextlevel = :sitecontext) OR\n (e.categoryid = ctx.instanceid AND e.eventtype = 'category' AND ctx.contextlevel = :categorycontext) OR\n (e.courseid = ctx.instanceid AND e.eventtype = 'course' AND ctx.contextlevel = :coursecontext) OR\n (e.courseid = ctx.instanceid AND e.eventtype = 'group' AND ctx.contextlevel = :groupcontext) OR\n (e.userid = ctx.instanceid AND e.eventtype = 'user' AND ctx.contextlevel = :usercontext)\n WHERE e.userid = :cuserid\n UNION\n SELECT ctx.id\n FROM {context} ctx\n JOIN {course_modules} cm ON cm.id = ctx.instanceid AND ctx.contextlevel = :modulecontext\n JOIN {modules} m ON m.id = cm.module\n JOIN {event} e ON e.modulename = m.name AND e.courseid = cm.course AND e.instance = cm.instance\n WHERE e.userid = :muserid\"",
";",
"$",
"contextlist",
"->",
"add_from_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"// Calendar Subscriptions can exist at Site, Course Category, Course, Course Group, or User contexts.",
"$",
"params",
"=",
"[",
"'sitecontext'",
"=>",
"CONTEXT_SYSTEM",
",",
"'categorycontext'",
"=>",
"CONTEXT_COURSECAT",
",",
"'coursecontext'",
"=>",
"CONTEXT_COURSE",
",",
"'groupcontext'",
"=>",
"CONTEXT_COURSE",
",",
"'usercontext'",
"=>",
"CONTEXT_USER",
",",
"'userid'",
"=>",
"$",
"userid",
"]",
";",
"// Get contexts for Calendar Subscriptions for the owner.",
"$",
"sql",
"=",
"\"SELECT ctx.id\n FROM {context} ctx\n JOIN {event_subscriptions} s ON\n (s.eventtype = 'site' AND ctx.contextlevel = :sitecontext) OR\n (s.categoryid = ctx.instanceid AND s.eventtype = 'category' AND ctx.contextlevel = :categorycontext) OR\n (s.courseid = ctx.instanceid AND s.eventtype = 'course' AND ctx.contextlevel = :coursecontext) OR\n (s.courseid = ctx.instanceid AND s.eventtype = 'group' AND ctx.contextlevel = :groupcontext) OR\n (s.userid = ctx.instanceid AND s.eventtype = 'user' AND ctx.contextlevel = :usercontext)\n WHERE s.userid = :userid\"",
";",
"$",
"contextlist",
"->",
"add_from_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"// Return combined contextlist for Calendar Events & Calendar Subscriptions.",
"return",
"$",
"contextlist",
";",
"}"
] |
Get the list of contexts that contain calendar user information for the specified user.
@param int $userid The user to search.
@return contextlist $contextlist The contextlist containing the list of contexts used in this plugin.
|
[
"Get",
"the",
"list",
"of",
"contexts",
"that",
"contain",
"calendar",
"user",
"information",
"for",
"the",
"specified",
"user",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/privacy/provider.php#L97-L155
|
218,506
|
moodle/moodle
|
calendar/classes/privacy/provider.php
|
provider.delete_data_for_all_users_in_context
|
public static function delete_data_for_all_users_in_context(\context $context) {
// Delete all Calendar Events in the specified context in batches.
if ($eventids = array_keys(self::get_calendar_event_ids_by_context($context))) {
self::delete_batch_records('event', 'id', $eventids);
}
// Delete all Calendar Subscriptions in the specified context in batches.
if ($subscriptionids = array_keys(self::get_calendar_subscription_ids_by_context($context))) {
self::delete_batch_records('event_subscriptions', 'id', $subscriptionids);
}
}
|
php
|
public static function delete_data_for_all_users_in_context(\context $context) {
// Delete all Calendar Events in the specified context in batches.
if ($eventids = array_keys(self::get_calendar_event_ids_by_context($context))) {
self::delete_batch_records('event', 'id', $eventids);
}
// Delete all Calendar Subscriptions in the specified context in batches.
if ($subscriptionids = array_keys(self::get_calendar_subscription_ids_by_context($context))) {
self::delete_batch_records('event_subscriptions', 'id', $subscriptionids);
}
}
|
[
"public",
"static",
"function",
"delete_data_for_all_users_in_context",
"(",
"\\",
"context",
"$",
"context",
")",
"{",
"// Delete all Calendar Events in the specified context in batches.",
"if",
"(",
"$",
"eventids",
"=",
"array_keys",
"(",
"self",
"::",
"get_calendar_event_ids_by_context",
"(",
"$",
"context",
")",
")",
")",
"{",
"self",
"::",
"delete_batch_records",
"(",
"'event'",
",",
"'id'",
",",
"$",
"eventids",
")",
";",
"}",
"// Delete all Calendar Subscriptions in the specified context in batches.",
"if",
"(",
"$",
"subscriptionids",
"=",
"array_keys",
"(",
"self",
"::",
"get_calendar_subscription_ids_by_context",
"(",
"$",
"context",
")",
")",
")",
"{",
"self",
"::",
"delete_batch_records",
"(",
"'event_subscriptions'",
",",
"'id'",
",",
"$",
"subscriptionids",
")",
";",
"}",
"}"
] |
Delete all Calendar Event and Calendar Subscription data for all users in the specified context.
@param context $context Transform the specific context to delete data for.
|
[
"Delete",
"all",
"Calendar",
"Event",
"and",
"Calendar",
"Subscription",
"data",
"for",
"all",
"users",
"in",
"the",
"specified",
"context",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/privacy/provider.php#L257-L267
|
218,507
|
moodle/moodle
|
calendar/classes/privacy/provider.php
|
provider.export_user_calendar_event_data
|
protected static function export_user_calendar_event_data(approved_contextlist $contextlist) {
// Calendar Events can exist at Site, Course Category, Course, Course Group, User, or Course Modules contexts.
$eventdetails = self::get_calendar_event_details_by_contextlist($contextlist);
// Multiple Calendar Events of the same eventtype and time can exist for a context, so collate them for export.
$eventrecords = [];
foreach ($eventdetails as $eventdetail) {
// Create an array key based on the contextid, eventtype, and time.
$key = $eventdetail->contextid . $eventdetail->eventtype . $eventdetail->timestart;
if (array_key_exists($key, $eventrecords) === false) {
$eventrecords[$key] = [ $eventdetail ];
} else {
$eventrecords[$key] = array_merge($eventrecords[$key], [$eventdetail]);
}
}
$eventdetails->close();
// Export Calendar Event data.
foreach ($eventrecords as $eventrecord) {
$index = (count($eventrecord) > 1) ? 1 : 0;
foreach ($eventrecord as $event) {
// Export the events using the structure Calendar/Events/{datetime}/{eventtype}-event.json.
$subcontexts = [
get_string('calendar', 'calendar'),
get_string('events', 'calendar'),
date('c', $event->timestart)
];
$name = $event->eventtype . '-event';
// Use name {eventtype}-event-{index}.json if multiple eventtypes and time exists at the same context.
if ($index != 0) {
$name .= '-' . $index;
$index++;
}
$eventdetails = (object) [
'name' => $event->name,
'description' => $event->description,
'location' => $event->location,
'eventtype' => $event->eventtype,
'timestart' => transform::datetime($event->timestart),
'timeduration' => $event->timeduration
];
$context = \context::instance_by_id($event->contextid);
writer::with_context($context)->export_related_data($subcontexts, $name, $eventdetails);
}
}
}
|
php
|
protected static function export_user_calendar_event_data(approved_contextlist $contextlist) {
// Calendar Events can exist at Site, Course Category, Course, Course Group, User, or Course Modules contexts.
$eventdetails = self::get_calendar_event_details_by_contextlist($contextlist);
// Multiple Calendar Events of the same eventtype and time can exist for a context, so collate them for export.
$eventrecords = [];
foreach ($eventdetails as $eventdetail) {
// Create an array key based on the contextid, eventtype, and time.
$key = $eventdetail->contextid . $eventdetail->eventtype . $eventdetail->timestart;
if (array_key_exists($key, $eventrecords) === false) {
$eventrecords[$key] = [ $eventdetail ];
} else {
$eventrecords[$key] = array_merge($eventrecords[$key], [$eventdetail]);
}
}
$eventdetails->close();
// Export Calendar Event data.
foreach ($eventrecords as $eventrecord) {
$index = (count($eventrecord) > 1) ? 1 : 0;
foreach ($eventrecord as $event) {
// Export the events using the structure Calendar/Events/{datetime}/{eventtype}-event.json.
$subcontexts = [
get_string('calendar', 'calendar'),
get_string('events', 'calendar'),
date('c', $event->timestart)
];
$name = $event->eventtype . '-event';
// Use name {eventtype}-event-{index}.json if multiple eventtypes and time exists at the same context.
if ($index != 0) {
$name .= '-' . $index;
$index++;
}
$eventdetails = (object) [
'name' => $event->name,
'description' => $event->description,
'location' => $event->location,
'eventtype' => $event->eventtype,
'timestart' => transform::datetime($event->timestart),
'timeduration' => $event->timeduration
];
$context = \context::instance_by_id($event->contextid);
writer::with_context($context)->export_related_data($subcontexts, $name, $eventdetails);
}
}
}
|
[
"protected",
"static",
"function",
"export_user_calendar_event_data",
"(",
"approved_contextlist",
"$",
"contextlist",
")",
"{",
"// Calendar Events can exist at Site, Course Category, Course, Course Group, User, or Course Modules contexts.",
"$",
"eventdetails",
"=",
"self",
"::",
"get_calendar_event_details_by_contextlist",
"(",
"$",
"contextlist",
")",
";",
"// Multiple Calendar Events of the same eventtype and time can exist for a context, so collate them for export.",
"$",
"eventrecords",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"eventdetails",
"as",
"$",
"eventdetail",
")",
"{",
"// Create an array key based on the contextid, eventtype, and time.",
"$",
"key",
"=",
"$",
"eventdetail",
"->",
"contextid",
".",
"$",
"eventdetail",
"->",
"eventtype",
".",
"$",
"eventdetail",
"->",
"timestart",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"eventrecords",
")",
"===",
"false",
")",
"{",
"$",
"eventrecords",
"[",
"$",
"key",
"]",
"=",
"[",
"$",
"eventdetail",
"]",
";",
"}",
"else",
"{",
"$",
"eventrecords",
"[",
"$",
"key",
"]",
"=",
"array_merge",
"(",
"$",
"eventrecords",
"[",
"$",
"key",
"]",
",",
"[",
"$",
"eventdetail",
"]",
")",
";",
"}",
"}",
"$",
"eventdetails",
"->",
"close",
"(",
")",
";",
"// Export Calendar Event data.",
"foreach",
"(",
"$",
"eventrecords",
"as",
"$",
"eventrecord",
")",
"{",
"$",
"index",
"=",
"(",
"count",
"(",
"$",
"eventrecord",
")",
">",
"1",
")",
"?",
"1",
":",
"0",
";",
"foreach",
"(",
"$",
"eventrecord",
"as",
"$",
"event",
")",
"{",
"// Export the events using the structure Calendar/Events/{datetime}/{eventtype}-event.json.",
"$",
"subcontexts",
"=",
"[",
"get_string",
"(",
"'calendar'",
",",
"'calendar'",
")",
",",
"get_string",
"(",
"'events'",
",",
"'calendar'",
")",
",",
"date",
"(",
"'c'",
",",
"$",
"event",
"->",
"timestart",
")",
"]",
";",
"$",
"name",
"=",
"$",
"event",
"->",
"eventtype",
".",
"'-event'",
";",
"// Use name {eventtype}-event-{index}.json if multiple eventtypes and time exists at the same context.",
"if",
"(",
"$",
"index",
"!=",
"0",
")",
"{",
"$",
"name",
".=",
"'-'",
".",
"$",
"index",
";",
"$",
"index",
"++",
";",
"}",
"$",
"eventdetails",
"=",
"(",
"object",
")",
"[",
"'name'",
"=>",
"$",
"event",
"->",
"name",
",",
"'description'",
"=>",
"$",
"event",
"->",
"description",
",",
"'location'",
"=>",
"$",
"event",
"->",
"location",
",",
"'eventtype'",
"=>",
"$",
"event",
"->",
"eventtype",
",",
"'timestart'",
"=>",
"transform",
"::",
"datetime",
"(",
"$",
"event",
"->",
"timestart",
")",
",",
"'timeduration'",
"=>",
"$",
"event",
"->",
"timeduration",
"]",
";",
"$",
"context",
"=",
"\\",
"context",
"::",
"instance_by_id",
"(",
"$",
"event",
"->",
"contextid",
")",
";",
"writer",
"::",
"with_context",
"(",
"$",
"context",
")",
"->",
"export_related_data",
"(",
"$",
"subcontexts",
",",
"$",
"name",
",",
"$",
"eventdetails",
")",
";",
"}",
"}",
"}"
] |
Helper function to export Calendar Events data by a User's contextlist.
@param approved_contextlist $contextlist
@throws \coding_exception
|
[
"Helper",
"function",
"to",
"export",
"Calendar",
"Events",
"data",
"by",
"a",
"User",
"s",
"contextlist",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/privacy/provider.php#L340-L390
|
218,508
|
moodle/moodle
|
calendar/classes/privacy/provider.php
|
provider.export_user_calendar_subscription_data
|
protected static function export_user_calendar_subscription_data(approved_contextlist $contextlist) {
// Calendar Subscriptions can exist at Site, Course Category, Course, Course Group, or User contexts.
$subscriptiondetails = self::get_calendar_subscription_details_by_contextlist($contextlist);
// Multiple Calendar Subscriptions of the same eventtype can exist for a context, so collate them for export.
$subscriptionrecords = [];
foreach ($subscriptiondetails as $subscriptiondetail) {
// Create an array key based on the contextid and eventtype.
$key = $subscriptiondetail->contextid . $subscriptiondetail->eventtype;
if (array_key_exists($key, $subscriptionrecords) === false) {
$subscriptionrecords[$key] = [ $subscriptiondetail ];
} else {
$subscriptionrecords[$key] = array_merge($subscriptionrecords[$key], [$subscriptiondetail]);
}
}
$subscriptiondetails->close();
// Export Calendar Subscription data.
foreach ($subscriptionrecords as $subscriptionrecord) {
$index = (count($subscriptionrecord) > 1) ? 1 : 0;
foreach ($subscriptionrecord as $subscription) {
// Export the events using the structure Calendar/Subscriptions/{eventtype}-subscription.json.
$subcontexts = [
get_string('calendar', 'calendar'),
get_string('subscriptions', 'calendar')
];
$name = $subscription->eventtype . '-subscription';
// Use name {eventtype}-subscription-{index}.json if multiple eventtypes exists at the same context.
if ($index != 0) {
$name .= '-' . $index;
$index++;
}
$context = \context::instance_by_id($subscription->contextid);
writer::with_context($context)->export_related_data($subcontexts, $name, $subscription);
}
}
}
|
php
|
protected static function export_user_calendar_subscription_data(approved_contextlist $contextlist) {
// Calendar Subscriptions can exist at Site, Course Category, Course, Course Group, or User contexts.
$subscriptiondetails = self::get_calendar_subscription_details_by_contextlist($contextlist);
// Multiple Calendar Subscriptions of the same eventtype can exist for a context, so collate them for export.
$subscriptionrecords = [];
foreach ($subscriptiondetails as $subscriptiondetail) {
// Create an array key based on the contextid and eventtype.
$key = $subscriptiondetail->contextid . $subscriptiondetail->eventtype;
if (array_key_exists($key, $subscriptionrecords) === false) {
$subscriptionrecords[$key] = [ $subscriptiondetail ];
} else {
$subscriptionrecords[$key] = array_merge($subscriptionrecords[$key], [$subscriptiondetail]);
}
}
$subscriptiondetails->close();
// Export Calendar Subscription data.
foreach ($subscriptionrecords as $subscriptionrecord) {
$index = (count($subscriptionrecord) > 1) ? 1 : 0;
foreach ($subscriptionrecord as $subscription) {
// Export the events using the structure Calendar/Subscriptions/{eventtype}-subscription.json.
$subcontexts = [
get_string('calendar', 'calendar'),
get_string('subscriptions', 'calendar')
];
$name = $subscription->eventtype . '-subscription';
// Use name {eventtype}-subscription-{index}.json if multiple eventtypes exists at the same context.
if ($index != 0) {
$name .= '-' . $index;
$index++;
}
$context = \context::instance_by_id($subscription->contextid);
writer::with_context($context)->export_related_data($subcontexts, $name, $subscription);
}
}
}
|
[
"protected",
"static",
"function",
"export_user_calendar_subscription_data",
"(",
"approved_contextlist",
"$",
"contextlist",
")",
"{",
"// Calendar Subscriptions can exist at Site, Course Category, Course, Course Group, or User contexts.",
"$",
"subscriptiondetails",
"=",
"self",
"::",
"get_calendar_subscription_details_by_contextlist",
"(",
"$",
"contextlist",
")",
";",
"// Multiple Calendar Subscriptions of the same eventtype can exist for a context, so collate them for export.",
"$",
"subscriptionrecords",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"subscriptiondetails",
"as",
"$",
"subscriptiondetail",
")",
"{",
"// Create an array key based on the contextid and eventtype.",
"$",
"key",
"=",
"$",
"subscriptiondetail",
"->",
"contextid",
".",
"$",
"subscriptiondetail",
"->",
"eventtype",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"subscriptionrecords",
")",
"===",
"false",
")",
"{",
"$",
"subscriptionrecords",
"[",
"$",
"key",
"]",
"=",
"[",
"$",
"subscriptiondetail",
"]",
";",
"}",
"else",
"{",
"$",
"subscriptionrecords",
"[",
"$",
"key",
"]",
"=",
"array_merge",
"(",
"$",
"subscriptionrecords",
"[",
"$",
"key",
"]",
",",
"[",
"$",
"subscriptiondetail",
"]",
")",
";",
"}",
"}",
"$",
"subscriptiondetails",
"->",
"close",
"(",
")",
";",
"// Export Calendar Subscription data.",
"foreach",
"(",
"$",
"subscriptionrecords",
"as",
"$",
"subscriptionrecord",
")",
"{",
"$",
"index",
"=",
"(",
"count",
"(",
"$",
"subscriptionrecord",
")",
">",
"1",
")",
"?",
"1",
":",
"0",
";",
"foreach",
"(",
"$",
"subscriptionrecord",
"as",
"$",
"subscription",
")",
"{",
"// Export the events using the structure Calendar/Subscriptions/{eventtype}-subscription.json.",
"$",
"subcontexts",
"=",
"[",
"get_string",
"(",
"'calendar'",
",",
"'calendar'",
")",
",",
"get_string",
"(",
"'subscriptions'",
",",
"'calendar'",
")",
"]",
";",
"$",
"name",
"=",
"$",
"subscription",
"->",
"eventtype",
".",
"'-subscription'",
";",
"// Use name {eventtype}-subscription-{index}.json if multiple eventtypes exists at the same context.",
"if",
"(",
"$",
"index",
"!=",
"0",
")",
"{",
"$",
"name",
".=",
"'-'",
".",
"$",
"index",
";",
"$",
"index",
"++",
";",
"}",
"$",
"context",
"=",
"\\",
"context",
"::",
"instance_by_id",
"(",
"$",
"subscription",
"->",
"contextid",
")",
";",
"writer",
"::",
"with_context",
"(",
"$",
"context",
")",
"->",
"export_related_data",
"(",
"$",
"subcontexts",
",",
"$",
"name",
",",
"$",
"subscription",
")",
";",
"}",
"}",
"}"
] |
Helper function to export Calendar Subscriptions data by a User's contextlist.
@param approved_contextlist $contextlist
@throws \coding_exception
|
[
"Helper",
"function",
"to",
"export",
"Calendar",
"Subscriptions",
"data",
"by",
"a",
"User",
"s",
"contextlist",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/privacy/provider.php#L398-L438
|
218,509
|
moodle/moodle
|
calendar/classes/privacy/provider.php
|
provider.get_calendar_event_ids_by_context
|
protected static function get_calendar_event_ids_by_context(\context $context, $userids = array()) {
global $DB;
// Calendar Events can exist at Site (CONTEXT_SYSTEM), Course Category (CONTEXT_COURSECAT),
// Course and Course Group (CONTEXT_COURSE), User (CONTEXT_USER), or Course Modules (CONTEXT_MODULE) contexts.
if (!in_array($context->contextlevel, [CONTEXT_SYSTEM, CONTEXT_COURSECAT, CONTEXT_COURSE, CONTEXT_USER, CONTEXT_MODULE])) {
return [];
}
$whereusersql = '';
$userparams = array();
if (!empty($userids)) {
list($usersql, $userparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
$whereusersql = "AND e.userid {$usersql}";
}
if ($context->contextlevel == CONTEXT_MODULE) { // Course Module events.
$params = ['cmid' => $context->instanceid];
// Get Calendar Events for the specified Course Module context.
$sql = "SELECT DISTINCT e.id AS eventid
FROM {course_modules} cm
JOIN {modules} m ON m.id = cm.module
JOIN {event} e ON e.modulename = m.name AND e.courseid = cm.course AND e.instance = cm.instance
WHERE cm.id = :cmid
$whereusersql";
} else if ($context->contextlevel == CONTEXT_SYSTEM) { // Site events.
$params = [];
$sql = "SELECT DISTINCT e.id AS eventid
FROM {event} e
WHERE e.eventtype = 'site'
$whereusersql";
} else { // The rest.
$eventfields = [
CONTEXT_COURSECAT => 'categoryid',
CONTEXT_COURSE => 'courseid',
CONTEXT_USER => 'userid'
];
$eventfield = $eventfields[$context->contextlevel];
$eventtypes = [
CONTEXT_COURSECAT => 'category',
CONTEXT_COURSE => ['course' , 'group'],
CONTEXT_USER => 'user'
];
list($eventtypesql, $eventtypeparams) = $DB->get_in_or_equal($eventtypes[$context->contextlevel], SQL_PARAMS_NAMED);
$params = $eventtypeparams + ['instanceid' => $context->instanceid];
// Get Calendar Events for the specified Moodle context.
$sql = "SELECT DISTINCT e.id AS eventid
FROM {event} e
WHERE e.eventtype $eventtypesql
AND e.{$eventfield} = :instanceid
$whereusersql";
}
$params += $userparams;
return $DB->get_records_sql($sql, $params);
}
|
php
|
protected static function get_calendar_event_ids_by_context(\context $context, $userids = array()) {
global $DB;
// Calendar Events can exist at Site (CONTEXT_SYSTEM), Course Category (CONTEXT_COURSECAT),
// Course and Course Group (CONTEXT_COURSE), User (CONTEXT_USER), or Course Modules (CONTEXT_MODULE) contexts.
if (!in_array($context->contextlevel, [CONTEXT_SYSTEM, CONTEXT_COURSECAT, CONTEXT_COURSE, CONTEXT_USER, CONTEXT_MODULE])) {
return [];
}
$whereusersql = '';
$userparams = array();
if (!empty($userids)) {
list($usersql, $userparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
$whereusersql = "AND e.userid {$usersql}";
}
if ($context->contextlevel == CONTEXT_MODULE) { // Course Module events.
$params = ['cmid' => $context->instanceid];
// Get Calendar Events for the specified Course Module context.
$sql = "SELECT DISTINCT e.id AS eventid
FROM {course_modules} cm
JOIN {modules} m ON m.id = cm.module
JOIN {event} e ON e.modulename = m.name AND e.courseid = cm.course AND e.instance = cm.instance
WHERE cm.id = :cmid
$whereusersql";
} else if ($context->contextlevel == CONTEXT_SYSTEM) { // Site events.
$params = [];
$sql = "SELECT DISTINCT e.id AS eventid
FROM {event} e
WHERE e.eventtype = 'site'
$whereusersql";
} else { // The rest.
$eventfields = [
CONTEXT_COURSECAT => 'categoryid',
CONTEXT_COURSE => 'courseid',
CONTEXT_USER => 'userid'
];
$eventfield = $eventfields[$context->contextlevel];
$eventtypes = [
CONTEXT_COURSECAT => 'category',
CONTEXT_COURSE => ['course' , 'group'],
CONTEXT_USER => 'user'
];
list($eventtypesql, $eventtypeparams) = $DB->get_in_or_equal($eventtypes[$context->contextlevel], SQL_PARAMS_NAMED);
$params = $eventtypeparams + ['instanceid' => $context->instanceid];
// Get Calendar Events for the specified Moodle context.
$sql = "SELECT DISTINCT e.id AS eventid
FROM {event} e
WHERE e.eventtype $eventtypesql
AND e.{$eventfield} = :instanceid
$whereusersql";
}
$params += $userparams;
return $DB->get_records_sql($sql, $params);
}
|
[
"protected",
"static",
"function",
"get_calendar_event_ids_by_context",
"(",
"\\",
"context",
"$",
"context",
",",
"$",
"userids",
"=",
"array",
"(",
")",
")",
"{",
"global",
"$",
"DB",
";",
"// Calendar Events can exist at Site (CONTEXT_SYSTEM), Course Category (CONTEXT_COURSECAT),",
"// Course and Course Group (CONTEXT_COURSE), User (CONTEXT_USER), or Course Modules (CONTEXT_MODULE) contexts.",
"if",
"(",
"!",
"in_array",
"(",
"$",
"context",
"->",
"contextlevel",
",",
"[",
"CONTEXT_SYSTEM",
",",
"CONTEXT_COURSECAT",
",",
"CONTEXT_COURSE",
",",
"CONTEXT_USER",
",",
"CONTEXT_MODULE",
"]",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"whereusersql",
"=",
"''",
";",
"$",
"userparams",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"userids",
")",
")",
"{",
"list",
"(",
"$",
"usersql",
",",
"$",
"userparams",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"userids",
",",
"SQL_PARAMS_NAMED",
")",
";",
"$",
"whereusersql",
"=",
"\"AND e.userid {$usersql}\"",
";",
"}",
"if",
"(",
"$",
"context",
"->",
"contextlevel",
"==",
"CONTEXT_MODULE",
")",
"{",
"// Course Module events.",
"$",
"params",
"=",
"[",
"'cmid'",
"=>",
"$",
"context",
"->",
"instanceid",
"]",
";",
"// Get Calendar Events for the specified Course Module context.",
"$",
"sql",
"=",
"\"SELECT DISTINCT e.id AS eventid\n FROM {course_modules} cm\n JOIN {modules} m ON m.id = cm.module\n JOIN {event} e ON e.modulename = m.name AND e.courseid = cm.course AND e.instance = cm.instance\n WHERE cm.id = :cmid\n $whereusersql\"",
";",
"}",
"else",
"if",
"(",
"$",
"context",
"->",
"contextlevel",
"==",
"CONTEXT_SYSTEM",
")",
"{",
"// Site events.",
"$",
"params",
"=",
"[",
"]",
";",
"$",
"sql",
"=",
"\"SELECT DISTINCT e.id AS eventid\n FROM {event} e\n WHERE e.eventtype = 'site'\n $whereusersql\"",
";",
"}",
"else",
"{",
"// The rest.",
"$",
"eventfields",
"=",
"[",
"CONTEXT_COURSECAT",
"=>",
"'categoryid'",
",",
"CONTEXT_COURSE",
"=>",
"'courseid'",
",",
"CONTEXT_USER",
"=>",
"'userid'",
"]",
";",
"$",
"eventfield",
"=",
"$",
"eventfields",
"[",
"$",
"context",
"->",
"contextlevel",
"]",
";",
"$",
"eventtypes",
"=",
"[",
"CONTEXT_COURSECAT",
"=>",
"'category'",
",",
"CONTEXT_COURSE",
"=>",
"[",
"'course'",
",",
"'group'",
"]",
",",
"CONTEXT_USER",
"=>",
"'user'",
"]",
";",
"list",
"(",
"$",
"eventtypesql",
",",
"$",
"eventtypeparams",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"eventtypes",
"[",
"$",
"context",
"->",
"contextlevel",
"]",
",",
"SQL_PARAMS_NAMED",
")",
";",
"$",
"params",
"=",
"$",
"eventtypeparams",
"+",
"[",
"'instanceid'",
"=>",
"$",
"context",
"->",
"instanceid",
"]",
";",
"// Get Calendar Events for the specified Moodle context.",
"$",
"sql",
"=",
"\"SELECT DISTINCT e.id AS eventid\n FROM {event} e\n WHERE e.eventtype $eventtypesql\n AND e.{$eventfield} = :instanceid\n $whereusersql\"",
";",
"}",
"$",
"params",
"+=",
"$",
"userparams",
";",
"return",
"$",
"DB",
"->",
"get_records_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"}"
] |
Helper function to return all Calendar Event id results for a specified context and optionally
included user list.
@param \context $context
@param array $userids
@return array|null
@throws \dml_exception
|
[
"Helper",
"function",
"to",
"return",
"all",
"Calendar",
"Event",
"id",
"results",
"for",
"a",
"specified",
"context",
"and",
"optionally",
"included",
"user",
"list",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/privacy/provider.php#L449-L509
|
218,510
|
moodle/moodle
|
calendar/classes/privacy/provider.php
|
provider.get_calendar_event_details_by_contextlist
|
protected static function get_calendar_event_details_by_contextlist(approved_contextlist $contextlist) {
global $DB;
$userid = $contextlist->get_user()->id;
list($contextsql1, $contextparams1) = $DB->get_in_or_equal($contextlist->get_contextids(), SQL_PARAMS_NAMED);
list($contextsql2, $contextparams2) = $DB->get_in_or_equal($contextlist->get_contextids(), SQL_PARAMS_NAMED);
// Calendar Events can exist at Site, Course Category, Course, Course Group, User, or Course Modules contexts.
$params = [
'sitecontext' => CONTEXT_SYSTEM,
'categorycontext' => CONTEXT_COURSECAT,
'coursecontext' => CONTEXT_COURSE,
'groupcontext' => CONTEXT_COURSE,
'usercontext' => CONTEXT_USER,
'cuserid' => $userid,
'modulecontext' => CONTEXT_MODULE,
'muserid' => $userid
];
$params += $contextparams1;
$params += $contextparams2;
// Get Calendar Events details for the approved contexts and the owner.
$sql = "SELECT ctxid as contextid,
details.id as eventid,
details.name as name,
details.description as description,
details.location as location,
details.eventtype as eventtype,
details.timestart as timestart,
details.timeduration as timeduration
FROM (
SELECT e.id AS id,
ctx.id AS ctxid
FROM {context} ctx
INNER JOIN {event} e ON
(e.eventtype = 'site' AND ctx.contextlevel = :sitecontext) OR
(e.categoryid = ctx.instanceid AND e.eventtype = 'category' AND ctx.contextlevel = :categorycontext) OR
(e.courseid = ctx.instanceid AND e.eventtype = 'course' AND ctx.contextlevel = :coursecontext) OR
(e.courseid = ctx.instanceid AND e.eventtype = 'group' AND ctx.contextlevel = :groupcontext) OR
(e.userid = ctx.instanceid AND e.eventtype = 'user' AND ctx.contextlevel = :usercontext)
WHERE e.userid = :cuserid
AND ctx.id {$contextsql1}
UNION
SELECT e.id AS id,
ctx.id AS ctxid
FROM {context} ctx
INNER JOIN {course_modules} cm ON cm.id = ctx.instanceid AND ctx.contextlevel = :modulecontext
INNER JOIN {modules} m ON m.id = cm.module
INNER JOIN {event} e ON e.modulename = m.name AND e.courseid = cm.course AND e.instance = cm.instance
WHERE e.userid = :muserid
AND ctx.id {$contextsql2}
) ids
JOIN {event} details ON details.id = ids.id
ORDER BY ids.id";
return $DB->get_recordset_sql($sql, $params);
}
|
php
|
protected static function get_calendar_event_details_by_contextlist(approved_contextlist $contextlist) {
global $DB;
$userid = $contextlist->get_user()->id;
list($contextsql1, $contextparams1) = $DB->get_in_or_equal($contextlist->get_contextids(), SQL_PARAMS_NAMED);
list($contextsql2, $contextparams2) = $DB->get_in_or_equal($contextlist->get_contextids(), SQL_PARAMS_NAMED);
// Calendar Events can exist at Site, Course Category, Course, Course Group, User, or Course Modules contexts.
$params = [
'sitecontext' => CONTEXT_SYSTEM,
'categorycontext' => CONTEXT_COURSECAT,
'coursecontext' => CONTEXT_COURSE,
'groupcontext' => CONTEXT_COURSE,
'usercontext' => CONTEXT_USER,
'cuserid' => $userid,
'modulecontext' => CONTEXT_MODULE,
'muserid' => $userid
];
$params += $contextparams1;
$params += $contextparams2;
// Get Calendar Events details for the approved contexts and the owner.
$sql = "SELECT ctxid as contextid,
details.id as eventid,
details.name as name,
details.description as description,
details.location as location,
details.eventtype as eventtype,
details.timestart as timestart,
details.timeduration as timeduration
FROM (
SELECT e.id AS id,
ctx.id AS ctxid
FROM {context} ctx
INNER JOIN {event} e ON
(e.eventtype = 'site' AND ctx.contextlevel = :sitecontext) OR
(e.categoryid = ctx.instanceid AND e.eventtype = 'category' AND ctx.contextlevel = :categorycontext) OR
(e.courseid = ctx.instanceid AND e.eventtype = 'course' AND ctx.contextlevel = :coursecontext) OR
(e.courseid = ctx.instanceid AND e.eventtype = 'group' AND ctx.contextlevel = :groupcontext) OR
(e.userid = ctx.instanceid AND e.eventtype = 'user' AND ctx.contextlevel = :usercontext)
WHERE e.userid = :cuserid
AND ctx.id {$contextsql1}
UNION
SELECT e.id AS id,
ctx.id AS ctxid
FROM {context} ctx
INNER JOIN {course_modules} cm ON cm.id = ctx.instanceid AND ctx.contextlevel = :modulecontext
INNER JOIN {modules} m ON m.id = cm.module
INNER JOIN {event} e ON e.modulename = m.name AND e.courseid = cm.course AND e.instance = cm.instance
WHERE e.userid = :muserid
AND ctx.id {$contextsql2}
) ids
JOIN {event} details ON details.id = ids.id
ORDER BY ids.id";
return $DB->get_recordset_sql($sql, $params);
}
|
[
"protected",
"static",
"function",
"get_calendar_event_details_by_contextlist",
"(",
"approved_contextlist",
"$",
"contextlist",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"userid",
"=",
"$",
"contextlist",
"->",
"get_user",
"(",
")",
"->",
"id",
";",
"list",
"(",
"$",
"contextsql1",
",",
"$",
"contextparams1",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"contextlist",
"->",
"get_contextids",
"(",
")",
",",
"SQL_PARAMS_NAMED",
")",
";",
"list",
"(",
"$",
"contextsql2",
",",
"$",
"contextparams2",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"contextlist",
"->",
"get_contextids",
"(",
")",
",",
"SQL_PARAMS_NAMED",
")",
";",
"// Calendar Events can exist at Site, Course Category, Course, Course Group, User, or Course Modules contexts.",
"$",
"params",
"=",
"[",
"'sitecontext'",
"=>",
"CONTEXT_SYSTEM",
",",
"'categorycontext'",
"=>",
"CONTEXT_COURSECAT",
",",
"'coursecontext'",
"=>",
"CONTEXT_COURSE",
",",
"'groupcontext'",
"=>",
"CONTEXT_COURSE",
",",
"'usercontext'",
"=>",
"CONTEXT_USER",
",",
"'cuserid'",
"=>",
"$",
"userid",
",",
"'modulecontext'",
"=>",
"CONTEXT_MODULE",
",",
"'muserid'",
"=>",
"$",
"userid",
"]",
";",
"$",
"params",
"+=",
"$",
"contextparams1",
";",
"$",
"params",
"+=",
"$",
"contextparams2",
";",
"// Get Calendar Events details for the approved contexts and the owner.",
"$",
"sql",
"=",
"\"SELECT ctxid as contextid,\n details.id as eventid,\n details.name as name,\n details.description as description,\n details.location as location,\n details.eventtype as eventtype,\n details.timestart as timestart,\n details.timeduration as timeduration\n FROM (\n SELECT e.id AS id,\n ctx.id AS ctxid\n FROM {context} ctx\n INNER JOIN {event} e ON\n (e.eventtype = 'site' AND ctx.contextlevel = :sitecontext) OR\n (e.categoryid = ctx.instanceid AND e.eventtype = 'category' AND ctx.contextlevel = :categorycontext) OR\n (e.courseid = ctx.instanceid AND e.eventtype = 'course' AND ctx.contextlevel = :coursecontext) OR\n (e.courseid = ctx.instanceid AND e.eventtype = 'group' AND ctx.contextlevel = :groupcontext) OR\n (e.userid = ctx.instanceid AND e.eventtype = 'user' AND ctx.contextlevel = :usercontext)\n WHERE e.userid = :cuserid\n AND ctx.id {$contextsql1}\n UNION\n SELECT e.id AS id,\n ctx.id AS ctxid\n FROM {context} ctx\n INNER JOIN {course_modules} cm ON cm.id = ctx.instanceid AND ctx.contextlevel = :modulecontext\n INNER JOIN {modules} m ON m.id = cm.module\n INNER JOIN {event} e ON e.modulename = m.name AND e.courseid = cm.course AND e.instance = cm.instance\n WHERE e.userid = :muserid\n AND ctx.id {$contextsql2}\n ) ids\n JOIN {event} details ON details.id = ids.id\n ORDER BY ids.id\"",
";",
"return",
"$",
"DB",
"->",
"get_recordset_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"}"
] |
Helper function to return the Calendar Events for a given user and context list.
@param approved_contextlist $contextlist
@return array
@throws \coding_exception
@throws \dml_exception
|
[
"Helper",
"function",
"to",
"return",
"the",
"Calendar",
"Events",
"for",
"a",
"given",
"user",
"and",
"context",
"list",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/privacy/provider.php#L582-L639
|
218,511
|
moodle/moodle
|
calendar/classes/privacy/provider.php
|
provider.get_calendar_subscription_details_by_contextlist
|
protected static function get_calendar_subscription_details_by_contextlist(approved_contextlist $contextlist) {
global $DB;
$user = $contextlist->get_user();
list($contextsql, $contextparams) = $DB->get_in_or_equal($contextlist->get_contextids(), SQL_PARAMS_NAMED);
$params = [
'sitecontext' => CONTEXT_SYSTEM,
'categorycontext' => CONTEXT_COURSECAT,
'coursecontext' => CONTEXT_COURSE,
'groupcontext' => CONTEXT_COURSE,
'usercontext' => CONTEXT_USER,
'userid' => $user->id
];
$params += $contextparams;
// Get Calendar Subscriptions for the approved contexts and the owner.
$sql = "SELECT DISTINCT
c.id as contextid,
s.id as subscriptionid,
s.name as name,
s.url as url,
s.eventtype as eventtype
FROM {context} c
INNER JOIN {event_subscriptions} s ON
(s.eventtype = 'site' AND c.contextlevel = :sitecontext) OR
(s.categoryid = c.instanceid AND s.eventtype = 'category' AND c.contextlevel = :categorycontext) OR
(s.courseid = c.instanceid AND s.eventtype = 'course' AND c.contextlevel = :coursecontext) OR
(s.courseid = c.instanceid AND s.eventtype = 'group' AND c.contextlevel = :groupcontext) OR
(s.userid = c.instanceid AND s.eventtype = 'user' AND c.contextlevel = :usercontext)
WHERE s.userid = :userid
AND c.id {$contextsql}";
return $DB->get_recordset_sql($sql, $params);
}
|
php
|
protected static function get_calendar_subscription_details_by_contextlist(approved_contextlist $contextlist) {
global $DB;
$user = $contextlist->get_user();
list($contextsql, $contextparams) = $DB->get_in_or_equal($contextlist->get_contextids(), SQL_PARAMS_NAMED);
$params = [
'sitecontext' => CONTEXT_SYSTEM,
'categorycontext' => CONTEXT_COURSECAT,
'coursecontext' => CONTEXT_COURSE,
'groupcontext' => CONTEXT_COURSE,
'usercontext' => CONTEXT_USER,
'userid' => $user->id
];
$params += $contextparams;
// Get Calendar Subscriptions for the approved contexts and the owner.
$sql = "SELECT DISTINCT
c.id as contextid,
s.id as subscriptionid,
s.name as name,
s.url as url,
s.eventtype as eventtype
FROM {context} c
INNER JOIN {event_subscriptions} s ON
(s.eventtype = 'site' AND c.contextlevel = :sitecontext) OR
(s.categoryid = c.instanceid AND s.eventtype = 'category' AND c.contextlevel = :categorycontext) OR
(s.courseid = c.instanceid AND s.eventtype = 'course' AND c.contextlevel = :coursecontext) OR
(s.courseid = c.instanceid AND s.eventtype = 'group' AND c.contextlevel = :groupcontext) OR
(s.userid = c.instanceid AND s.eventtype = 'user' AND c.contextlevel = :usercontext)
WHERE s.userid = :userid
AND c.id {$contextsql}";
return $DB->get_recordset_sql($sql, $params);
}
|
[
"protected",
"static",
"function",
"get_calendar_subscription_details_by_contextlist",
"(",
"approved_contextlist",
"$",
"contextlist",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"user",
"=",
"$",
"contextlist",
"->",
"get_user",
"(",
")",
";",
"list",
"(",
"$",
"contextsql",
",",
"$",
"contextparams",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"contextlist",
"->",
"get_contextids",
"(",
")",
",",
"SQL_PARAMS_NAMED",
")",
";",
"$",
"params",
"=",
"[",
"'sitecontext'",
"=>",
"CONTEXT_SYSTEM",
",",
"'categorycontext'",
"=>",
"CONTEXT_COURSECAT",
",",
"'coursecontext'",
"=>",
"CONTEXT_COURSE",
",",
"'groupcontext'",
"=>",
"CONTEXT_COURSE",
",",
"'usercontext'",
"=>",
"CONTEXT_USER",
",",
"'userid'",
"=>",
"$",
"user",
"->",
"id",
"]",
";",
"$",
"params",
"+=",
"$",
"contextparams",
";",
"// Get Calendar Subscriptions for the approved contexts and the owner.",
"$",
"sql",
"=",
"\"SELECT DISTINCT\n c.id as contextid,\n s.id as subscriptionid,\n s.name as name,\n s.url as url,\n s.eventtype as eventtype\n FROM {context} c\n INNER JOIN {event_subscriptions} s ON\n (s.eventtype = 'site' AND c.contextlevel = :sitecontext) OR\n (s.categoryid = c.instanceid AND s.eventtype = 'category' AND c.contextlevel = :categorycontext) OR\n (s.courseid = c.instanceid AND s.eventtype = 'course' AND c.contextlevel = :coursecontext) OR\n (s.courseid = c.instanceid AND s.eventtype = 'group' AND c.contextlevel = :groupcontext) OR\n (s.userid = c.instanceid AND s.eventtype = 'user' AND c.contextlevel = :usercontext)\n WHERE s.userid = :userid\n AND c.id {$contextsql}\"",
";",
"return",
"$",
"DB",
"->",
"get_recordset_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"}"
] |
Helper function to return the Calendar Subscriptions for a given user and context list.
@param approved_contextlist $contextlist
@return array
@throws \coding_exception
@throws \dml_exception
|
[
"Helper",
"function",
"to",
"return",
"the",
"Calendar",
"Subscriptions",
"for",
"a",
"given",
"user",
"and",
"context",
"list",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/privacy/provider.php#L649-L684
|
218,512
|
moodle/moodle
|
calendar/classes/privacy/provider.php
|
provider.delete_batch_records
|
protected static function delete_batch_records($tablename, $field, $values) {
global $DB;
// Batch deletion with an upper limit of 2000 records to minimise the number of deletion queries.
$batchrecords = array_chunk($values, 2000);
foreach ($batchrecords as $batchrecord) {
$DB->delete_records_list($tablename, $field, $batchrecord);
}
}
|
php
|
protected static function delete_batch_records($tablename, $field, $values) {
global $DB;
// Batch deletion with an upper limit of 2000 records to minimise the number of deletion queries.
$batchrecords = array_chunk($values, 2000);
foreach ($batchrecords as $batchrecord) {
$DB->delete_records_list($tablename, $field, $batchrecord);
}
}
|
[
"protected",
"static",
"function",
"delete_batch_records",
"(",
"$",
"tablename",
",",
"$",
"field",
",",
"$",
"values",
")",
"{",
"global",
"$",
"DB",
";",
"// Batch deletion with an upper limit of 2000 records to minimise the number of deletion queries.",
"$",
"batchrecords",
"=",
"array_chunk",
"(",
"$",
"values",
",",
"2000",
")",
";",
"foreach",
"(",
"$",
"batchrecords",
"as",
"$",
"batchrecord",
")",
"{",
"$",
"DB",
"->",
"delete_records_list",
"(",
"$",
"tablename",
",",
"$",
"field",
",",
"$",
"batchrecord",
")",
";",
"}",
"}"
] |
Helper function to delete records in batches in order to minimise amount of deletion queries.
@param string $tablename The table name to delete from.
@param string $field The table column field name to delete records by.
@param array $values The table column field values to delete records by.
@throws \dml_exception
|
[
"Helper",
"function",
"to",
"delete",
"records",
"in",
"batches",
"in",
"order",
"to",
"minimise",
"amount",
"of",
"deletion",
"queries",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/privacy/provider.php#L694-L703
|
218,513
|
moodle/moodle
|
lib/classes/progress/base.php
|
base.start_progress
|
public function start_progress($description, $max = self::INDETERMINATE,
$parentcount = 1) {
if ($max != self::INDETERMINATE && $max < 0) {
throw new \coding_exception(
'start_progress() max value cannot be negative');
}
if ($parentcount < 1) {
throw new \coding_exception(
'start_progress() parent progress count must be at least 1');
}
if (!empty($this->descriptions)) {
$prevmax = end($this->maxes);
if ($prevmax !== self::INDETERMINATE) {
$prevcurrent = end($this->currents);
if ($prevcurrent + $parentcount > $prevmax) {
throw new \coding_exception(
'start_progress() parent progress would exceed max');
}
}
} else {
if ($parentcount != 1) {
throw new \coding_exception(
'start_progress() progress count must be 1 when no parent');
}
}
$this->descriptions[] = $description;
$this->maxes[] = $max;
$this->currents[] = 0;
$this->parentcounts[] = $parentcount;
$this->update_progress();
}
|
php
|
public function start_progress($description, $max = self::INDETERMINATE,
$parentcount = 1) {
if ($max != self::INDETERMINATE && $max < 0) {
throw new \coding_exception(
'start_progress() max value cannot be negative');
}
if ($parentcount < 1) {
throw new \coding_exception(
'start_progress() parent progress count must be at least 1');
}
if (!empty($this->descriptions)) {
$prevmax = end($this->maxes);
if ($prevmax !== self::INDETERMINATE) {
$prevcurrent = end($this->currents);
if ($prevcurrent + $parentcount > $prevmax) {
throw new \coding_exception(
'start_progress() parent progress would exceed max');
}
}
} else {
if ($parentcount != 1) {
throw new \coding_exception(
'start_progress() progress count must be 1 when no parent');
}
}
$this->descriptions[] = $description;
$this->maxes[] = $max;
$this->currents[] = 0;
$this->parentcounts[] = $parentcount;
$this->update_progress();
}
|
[
"public",
"function",
"start_progress",
"(",
"$",
"description",
",",
"$",
"max",
"=",
"self",
"::",
"INDETERMINATE",
",",
"$",
"parentcount",
"=",
"1",
")",
"{",
"if",
"(",
"$",
"max",
"!=",
"self",
"::",
"INDETERMINATE",
"&&",
"$",
"max",
"<",
"0",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'start_progress() max value cannot be negative'",
")",
";",
"}",
"if",
"(",
"$",
"parentcount",
"<",
"1",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'start_progress() parent progress count must be at least 1'",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"descriptions",
")",
")",
"{",
"$",
"prevmax",
"=",
"end",
"(",
"$",
"this",
"->",
"maxes",
")",
";",
"if",
"(",
"$",
"prevmax",
"!==",
"self",
"::",
"INDETERMINATE",
")",
"{",
"$",
"prevcurrent",
"=",
"end",
"(",
"$",
"this",
"->",
"currents",
")",
";",
"if",
"(",
"$",
"prevcurrent",
"+",
"$",
"parentcount",
">",
"$",
"prevmax",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'start_progress() parent progress would exceed max'",
")",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"parentcount",
"!=",
"1",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'start_progress() progress count must be 1 when no parent'",
")",
";",
"}",
"}",
"$",
"this",
"->",
"descriptions",
"[",
"]",
"=",
"$",
"description",
";",
"$",
"this",
"->",
"maxes",
"[",
"]",
"=",
"$",
"max",
";",
"$",
"this",
"->",
"currents",
"[",
"]",
"=",
"0",
";",
"$",
"this",
"->",
"parentcounts",
"[",
"]",
"=",
"$",
"parentcount",
";",
"$",
"this",
"->",
"update_progress",
"(",
")",
";",
"}"
] |
Marks the start of an operation that will display progress.
This can be called multiple times for nested progress sections. It must
be paired with calls to end_progress.
The progress maximum may be {@link self::INDETERMINATE} if the current operation has
an unknown number of steps. (This is default.)
Calling this function will always result in a new display, so this
should not be called exceedingly frequently.
When it is complete by calling {@link end_progress()}, each {@link start_progress} section
automatically adds progress to its parent, as defined by $parentcount.
@param string $description Description to display
@param int $max Maximum value of progress for this section
@param int $parentcount How many progress points this section counts for
@throws \coding_exception If max is invalid
|
[
"Marks",
"the",
"start",
"of",
"an",
"operation",
"that",
"will",
"display",
"progress",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/progress/base.php#L97-L127
|
218,514
|
moodle/moodle
|
lib/classes/progress/base.php
|
base.end_progress
|
public function end_progress() {
if (!count($this->descriptions)) {
throw new \coding_exception('end_progress() without start_progress()');
}
array_pop($this->descriptions);
array_pop($this->maxes);
array_pop($this->currents);
$parentcount = array_pop($this->parentcounts);
if (!empty($this->descriptions)) {
$lastmax = end($this->maxes);
if ($lastmax != self::INDETERMINATE) {
$lastvalue = end($this->currents);
$this->currents[key($this->currents)] = $lastvalue + $parentcount;
}
}
$this->update_progress();
}
|
php
|
public function end_progress() {
if (!count($this->descriptions)) {
throw new \coding_exception('end_progress() without start_progress()');
}
array_pop($this->descriptions);
array_pop($this->maxes);
array_pop($this->currents);
$parentcount = array_pop($this->parentcounts);
if (!empty($this->descriptions)) {
$lastmax = end($this->maxes);
if ($lastmax != self::INDETERMINATE) {
$lastvalue = end($this->currents);
$this->currents[key($this->currents)] = $lastvalue + $parentcount;
}
}
$this->update_progress();
}
|
[
"public",
"function",
"end_progress",
"(",
")",
"{",
"if",
"(",
"!",
"count",
"(",
"$",
"this",
"->",
"descriptions",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'end_progress() without start_progress()'",
")",
";",
"}",
"array_pop",
"(",
"$",
"this",
"->",
"descriptions",
")",
";",
"array_pop",
"(",
"$",
"this",
"->",
"maxes",
")",
";",
"array_pop",
"(",
"$",
"this",
"->",
"currents",
")",
";",
"$",
"parentcount",
"=",
"array_pop",
"(",
"$",
"this",
"->",
"parentcounts",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"descriptions",
")",
")",
"{",
"$",
"lastmax",
"=",
"end",
"(",
"$",
"this",
"->",
"maxes",
")",
";",
"if",
"(",
"$",
"lastmax",
"!=",
"self",
"::",
"INDETERMINATE",
")",
"{",
"$",
"lastvalue",
"=",
"end",
"(",
"$",
"this",
"->",
"currents",
")",
";",
"$",
"this",
"->",
"currents",
"[",
"key",
"(",
"$",
"this",
"->",
"currents",
")",
"]",
"=",
"$",
"lastvalue",
"+",
"$",
"parentcount",
";",
"}",
"}",
"$",
"this",
"->",
"update_progress",
"(",
")",
";",
"}"
] |
Marks the end of an operation that will display progress.
This must be paired with each {@link start_progress} call.
If there is a parent progress section, its progress will be increased
automatically to reflect the end of the child section.
@throws \coding_exception If progress hasn't been started
|
[
"Marks",
"the",
"end",
"of",
"an",
"operation",
"that",
"will",
"display",
"progress",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/progress/base.php#L139-L155
|
218,515
|
moodle/moodle
|
lib/classes/progress/base.php
|
base.progress
|
public function progress($progress = self::INDETERMINATE) {
// Check we are inside a progress section.
$max = end($this->maxes);
if ($max === false) {
throw new \coding_exception(
'progress() without start_progress');
}
// Check and apply new progress.
if ($progress === self::INDETERMINATE) {
// Indeterminate progress.
if ($max !== self::INDETERMINATE) {
throw new \coding_exception(
'progress() INDETERMINATE, expecting value');
}
} else {
// Determinate progress.
$current = end($this->currents);
if ($max === self::INDETERMINATE) {
throw new \coding_exception(
'progress() with value, expecting INDETERMINATE');
} else if ($progress < 0 || $progress > $max) {
throw new \coding_exception(
'progress() value out of range');
} else if ($progress < $current) {
throw new \coding_exception(
'progress() value may not go backwards');
}
$this->currents[key($this->currents)] = $progress;
}
// Don't update progress bar too frequently (more than once per second).
$now = $this->get_time();
if ($now === $this->lastprogresstime) {
return;
}
// Update progress.
$this->count++;
$this->lastprogresstime = $now;
// Update time limit before next progress display.
\core_php_time_limit::raise(self::TIME_LIMIT_WITHOUT_PROGRESS);
$this->update_progress();
}
|
php
|
public function progress($progress = self::INDETERMINATE) {
// Check we are inside a progress section.
$max = end($this->maxes);
if ($max === false) {
throw new \coding_exception(
'progress() without start_progress');
}
// Check and apply new progress.
if ($progress === self::INDETERMINATE) {
// Indeterminate progress.
if ($max !== self::INDETERMINATE) {
throw new \coding_exception(
'progress() INDETERMINATE, expecting value');
}
} else {
// Determinate progress.
$current = end($this->currents);
if ($max === self::INDETERMINATE) {
throw new \coding_exception(
'progress() with value, expecting INDETERMINATE');
} else if ($progress < 0 || $progress > $max) {
throw new \coding_exception(
'progress() value out of range');
} else if ($progress < $current) {
throw new \coding_exception(
'progress() value may not go backwards');
}
$this->currents[key($this->currents)] = $progress;
}
// Don't update progress bar too frequently (more than once per second).
$now = $this->get_time();
if ($now === $this->lastprogresstime) {
return;
}
// Update progress.
$this->count++;
$this->lastprogresstime = $now;
// Update time limit before next progress display.
\core_php_time_limit::raise(self::TIME_LIMIT_WITHOUT_PROGRESS);
$this->update_progress();
}
|
[
"public",
"function",
"progress",
"(",
"$",
"progress",
"=",
"self",
"::",
"INDETERMINATE",
")",
"{",
"// Check we are inside a progress section.",
"$",
"max",
"=",
"end",
"(",
"$",
"this",
"->",
"maxes",
")",
";",
"if",
"(",
"$",
"max",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'progress() without start_progress'",
")",
";",
"}",
"// Check and apply new progress.",
"if",
"(",
"$",
"progress",
"===",
"self",
"::",
"INDETERMINATE",
")",
"{",
"// Indeterminate progress.",
"if",
"(",
"$",
"max",
"!==",
"self",
"::",
"INDETERMINATE",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'progress() INDETERMINATE, expecting value'",
")",
";",
"}",
"}",
"else",
"{",
"// Determinate progress.",
"$",
"current",
"=",
"end",
"(",
"$",
"this",
"->",
"currents",
")",
";",
"if",
"(",
"$",
"max",
"===",
"self",
"::",
"INDETERMINATE",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'progress() with value, expecting INDETERMINATE'",
")",
";",
"}",
"else",
"if",
"(",
"$",
"progress",
"<",
"0",
"||",
"$",
"progress",
">",
"$",
"max",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'progress() value out of range'",
")",
";",
"}",
"else",
"if",
"(",
"$",
"progress",
"<",
"$",
"current",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'progress() value may not go backwards'",
")",
";",
"}",
"$",
"this",
"->",
"currents",
"[",
"key",
"(",
"$",
"this",
"->",
"currents",
")",
"]",
"=",
"$",
"progress",
";",
"}",
"// Don't update progress bar too frequently (more than once per second).",
"$",
"now",
"=",
"$",
"this",
"->",
"get_time",
"(",
")",
";",
"if",
"(",
"$",
"now",
"===",
"$",
"this",
"->",
"lastprogresstime",
")",
"{",
"return",
";",
"}",
"// Update progress.",
"$",
"this",
"->",
"count",
"++",
";",
"$",
"this",
"->",
"lastprogresstime",
"=",
"$",
"now",
";",
"// Update time limit before next progress display.",
"\\",
"core_php_time_limit",
"::",
"raise",
"(",
"self",
"::",
"TIME_LIMIT_WITHOUT_PROGRESS",
")",
";",
"$",
"this",
"->",
"update_progress",
"(",
")",
";",
"}"
] |
Indicates that progress has occurred.
The progress value should indicate the total progress so far, from 0
to the value supplied for $max (inclusive) in {@link start_progress}.
You do not need to call this function for every value. It is OK to skip
values. It is also OK to call this function as often as desired; it
doesn't update the display if called more than once per second.
It must be INDETERMINATE if {@link start_progress} was called with $max set to
INDETERMINATE. Otherwise it must not be indeterminate.
@param int $progress Progress so far
@throws \coding_exception If progress value is invalid
|
[
"Indicates",
"that",
"progress",
"has",
"occurred",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/progress/base.php#L173-L217
|
218,516
|
moodle/moodle
|
lib/classes/progress/base.php
|
base.get_progress_proportion_range
|
public function get_progress_proportion_range() {
// If there is no progress underway, we must have finished.
if (empty($this->currents)) {
return array(1.0, 1.0);
}
$count = count($this->currents);
$min = 0.0;
$max = 1.0;
for ($i = 0; $i < $count; $i++) {
// Get max value at that section - if it's indeterminate we can tell
// no more.
$sectionmax = $this->maxes[$i];
if ($sectionmax === self::INDETERMINATE) {
return array($min, $max);
}
// Special case if current value is max (this should only happen
// just before ending a section).
$sectioncurrent = $this->currents[$i];
if ($sectioncurrent === $sectionmax) {
return array($max, $max);
}
// Using the current value at that section, we know we are somewhere
// between 'current' and the next 'current' value which depends on
// the parentcount of the nested section (if any).
$newmin = ($sectioncurrent / $sectionmax) * ($max - $min) + $min;
$nextcurrent = $sectioncurrent + 1;
if ($i + 1 < $count) {
$weight = $this->parentcounts[$i + 1];
$nextcurrent = $sectioncurrent + $weight;
}
$newmax = ($nextcurrent / $sectionmax) * ($max - $min) + $min;
$min = $newmin;
$max = $newmax;
}
// If there was nothing indeterminate, we use the min value as current.
return array($min, $min);
}
|
php
|
public function get_progress_proportion_range() {
// If there is no progress underway, we must have finished.
if (empty($this->currents)) {
return array(1.0, 1.0);
}
$count = count($this->currents);
$min = 0.0;
$max = 1.0;
for ($i = 0; $i < $count; $i++) {
// Get max value at that section - if it's indeterminate we can tell
// no more.
$sectionmax = $this->maxes[$i];
if ($sectionmax === self::INDETERMINATE) {
return array($min, $max);
}
// Special case if current value is max (this should only happen
// just before ending a section).
$sectioncurrent = $this->currents[$i];
if ($sectioncurrent === $sectionmax) {
return array($max, $max);
}
// Using the current value at that section, we know we are somewhere
// between 'current' and the next 'current' value which depends on
// the parentcount of the nested section (if any).
$newmin = ($sectioncurrent / $sectionmax) * ($max - $min) + $min;
$nextcurrent = $sectioncurrent + 1;
if ($i + 1 < $count) {
$weight = $this->parentcounts[$i + 1];
$nextcurrent = $sectioncurrent + $weight;
}
$newmax = ($nextcurrent / $sectionmax) * ($max - $min) + $min;
$min = $newmin;
$max = $newmax;
}
// If there was nothing indeterminate, we use the min value as current.
return array($min, $min);
}
|
[
"public",
"function",
"get_progress_proportion_range",
"(",
")",
"{",
"// If there is no progress underway, we must have finished.",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"currents",
")",
")",
"{",
"return",
"array",
"(",
"1.0",
",",
"1.0",
")",
";",
"}",
"$",
"count",
"=",
"count",
"(",
"$",
"this",
"->",
"currents",
")",
";",
"$",
"min",
"=",
"0.0",
";",
"$",
"max",
"=",
"1.0",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"count",
";",
"$",
"i",
"++",
")",
"{",
"// Get max value at that section - if it's indeterminate we can tell",
"// no more.",
"$",
"sectionmax",
"=",
"$",
"this",
"->",
"maxes",
"[",
"$",
"i",
"]",
";",
"if",
"(",
"$",
"sectionmax",
"===",
"self",
"::",
"INDETERMINATE",
")",
"{",
"return",
"array",
"(",
"$",
"min",
",",
"$",
"max",
")",
";",
"}",
"// Special case if current value is max (this should only happen",
"// just before ending a section).",
"$",
"sectioncurrent",
"=",
"$",
"this",
"->",
"currents",
"[",
"$",
"i",
"]",
";",
"if",
"(",
"$",
"sectioncurrent",
"===",
"$",
"sectionmax",
")",
"{",
"return",
"array",
"(",
"$",
"max",
",",
"$",
"max",
")",
";",
"}",
"// Using the current value at that section, we know we are somewhere",
"// between 'current' and the next 'current' value which depends on",
"// the parentcount of the nested section (if any).",
"$",
"newmin",
"=",
"(",
"$",
"sectioncurrent",
"/",
"$",
"sectionmax",
")",
"*",
"(",
"$",
"max",
"-",
"$",
"min",
")",
"+",
"$",
"min",
";",
"$",
"nextcurrent",
"=",
"$",
"sectioncurrent",
"+",
"1",
";",
"if",
"(",
"$",
"i",
"+",
"1",
"<",
"$",
"count",
")",
"{",
"$",
"weight",
"=",
"$",
"this",
"->",
"parentcounts",
"[",
"$",
"i",
"+",
"1",
"]",
";",
"$",
"nextcurrent",
"=",
"$",
"sectioncurrent",
"+",
"$",
"weight",
";",
"}",
"$",
"newmax",
"=",
"(",
"$",
"nextcurrent",
"/",
"$",
"sectionmax",
")",
"*",
"(",
"$",
"max",
"-",
"$",
"min",
")",
"+",
"$",
"min",
";",
"$",
"min",
"=",
"$",
"newmin",
";",
"$",
"max",
"=",
"$",
"newmax",
";",
"}",
"// If there was nothing indeterminate, we use the min value as current.",
"return",
"array",
"(",
"$",
"min",
",",
"$",
"min",
")",
";",
"}"
] |
Obtains current progress in a way suitable for drawing a progress bar.
Progress is returned as a minimum and maximum value. If there is no
indeterminate progress, these values will be identical. If there is
intermediate progress, these values can be different. (For example, if
the top level progress sections is indeterminate, then the values will
always be 0.0 and 1.0.)
@return array Minimum and maximum possible progress proportions
|
[
"Obtains",
"current",
"progress",
"in",
"a",
"way",
"suitable",
"for",
"drawing",
"a",
"progress",
"bar",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/progress/base.php#L292-L331
|
218,517
|
moodle/moodle
|
grade/report/history/classes/filter_form.php
|
filter_form.definition
|
public function definition() {
$mform = $this->_form;
$course = $this->_customdata['course'];
$itemids = $this->_customdata['itemids'];
$graders = $this->_customdata['graders'];
$userbutton = $this->_customdata['userbutton'];
$names = \html_writer::span('', 'selectednames');
$mform->addElement('static', 'userselect', get_string('selectusers', 'gradereport_history'), $userbutton);
$mform->addElement('static', 'selectednames', get_string('selectedusers', 'gradereport_history'), $names);
$mform->addElement('select', 'itemid', get_string('gradeitem', 'grades'), $itemids);
$mform->setType('itemid', PARAM_INT);
$mform->addElement('select', 'grader', get_string('grader', 'gradereport_history'), $graders);
$mform->setType('grader', PARAM_INT);
$mform->addElement('date_selector', 'datefrom', get_string('datefrom', 'gradereport_history'), array('optional' => true));
$mform->addElement('date_selector', 'datetill', get_string('dateto', 'gradereport_history'), array('optional' => true));
$mform->addElement('checkbox', 'revisedonly', get_string('revisedonly', 'gradereport_history'));
$mform->addHelpButton('revisedonly', 'revisedonly', 'gradereport_history');
$mform->addElement('hidden', 'id', $course->id);
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'userids');
$mform->setType('userids', PARAM_SEQUENCE);
$mform->addElement('hidden', 'userfullnames');
$mform->setType('userfullnames', PARAM_TEXT);
// Add a submit button.
$mform->addElement('submit', 'submitbutton', get_string('submit'));
}
|
php
|
public function definition() {
$mform = $this->_form;
$course = $this->_customdata['course'];
$itemids = $this->_customdata['itemids'];
$graders = $this->_customdata['graders'];
$userbutton = $this->_customdata['userbutton'];
$names = \html_writer::span('', 'selectednames');
$mform->addElement('static', 'userselect', get_string('selectusers', 'gradereport_history'), $userbutton);
$mform->addElement('static', 'selectednames', get_string('selectedusers', 'gradereport_history'), $names);
$mform->addElement('select', 'itemid', get_string('gradeitem', 'grades'), $itemids);
$mform->setType('itemid', PARAM_INT);
$mform->addElement('select', 'grader', get_string('grader', 'gradereport_history'), $graders);
$mform->setType('grader', PARAM_INT);
$mform->addElement('date_selector', 'datefrom', get_string('datefrom', 'gradereport_history'), array('optional' => true));
$mform->addElement('date_selector', 'datetill', get_string('dateto', 'gradereport_history'), array('optional' => true));
$mform->addElement('checkbox', 'revisedonly', get_string('revisedonly', 'gradereport_history'));
$mform->addHelpButton('revisedonly', 'revisedonly', 'gradereport_history');
$mform->addElement('hidden', 'id', $course->id);
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'userids');
$mform->setType('userids', PARAM_SEQUENCE);
$mform->addElement('hidden', 'userfullnames');
$mform->setType('userfullnames', PARAM_TEXT);
// Add a submit button.
$mform->addElement('submit', 'submitbutton', get_string('submit'));
}
|
[
"public",
"function",
"definition",
"(",
")",
"{",
"$",
"mform",
"=",
"$",
"this",
"->",
"_form",
";",
"$",
"course",
"=",
"$",
"this",
"->",
"_customdata",
"[",
"'course'",
"]",
";",
"$",
"itemids",
"=",
"$",
"this",
"->",
"_customdata",
"[",
"'itemids'",
"]",
";",
"$",
"graders",
"=",
"$",
"this",
"->",
"_customdata",
"[",
"'graders'",
"]",
";",
"$",
"userbutton",
"=",
"$",
"this",
"->",
"_customdata",
"[",
"'userbutton'",
"]",
";",
"$",
"names",
"=",
"\\",
"html_writer",
"::",
"span",
"(",
"''",
",",
"'selectednames'",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'static'",
",",
"'userselect'",
",",
"get_string",
"(",
"'selectusers'",
",",
"'gradereport_history'",
")",
",",
"$",
"userbutton",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'static'",
",",
"'selectednames'",
",",
"get_string",
"(",
"'selectedusers'",
",",
"'gradereport_history'",
")",
",",
"$",
"names",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'select'",
",",
"'itemid'",
",",
"get_string",
"(",
"'gradeitem'",
",",
"'grades'",
")",
",",
"$",
"itemids",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'itemid'",
",",
"PARAM_INT",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'select'",
",",
"'grader'",
",",
"get_string",
"(",
"'grader'",
",",
"'gradereport_history'",
")",
",",
"$",
"graders",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'grader'",
",",
"PARAM_INT",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'date_selector'",
",",
"'datefrom'",
",",
"get_string",
"(",
"'datefrom'",
",",
"'gradereport_history'",
")",
",",
"array",
"(",
"'optional'",
"=>",
"true",
")",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'date_selector'",
",",
"'datetill'",
",",
"get_string",
"(",
"'dateto'",
",",
"'gradereport_history'",
")",
",",
"array",
"(",
"'optional'",
"=>",
"true",
")",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'checkbox'",
",",
"'revisedonly'",
",",
"get_string",
"(",
"'revisedonly'",
",",
"'gradereport_history'",
")",
")",
";",
"$",
"mform",
"->",
"addHelpButton",
"(",
"'revisedonly'",
",",
"'revisedonly'",
",",
"'gradereport_history'",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'hidden'",
",",
"'id'",
",",
"$",
"course",
"->",
"id",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'id'",
",",
"PARAM_INT",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'hidden'",
",",
"'userids'",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'userids'",
",",
"PARAM_SEQUENCE",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'hidden'",
",",
"'userfullnames'",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'userfullnames'",
",",
"PARAM_TEXT",
")",
";",
"// Add a submit button.",
"$",
"mform",
"->",
"addElement",
"(",
"'submit'",
",",
"'submitbutton'",
",",
"get_string",
"(",
"'submit'",
")",
")",
";",
"}"
] |
Definition of the Mform for filters displayed in the report.
|
[
"Definition",
"of",
"the",
"Mform",
"for",
"filters",
"displayed",
"in",
"the",
"report",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/history/classes/filter_form.php#L46-L81
|
218,518
|
moodle/moodle
|
grade/report/history/classes/filter_form.php
|
filter_form.definition_after_data
|
public function definition_after_data() {
$mform = $this->_form;
if ($userfullnames = $mform->getElementValue('userfullnames')) {
$mform->getElement('selectednames')->setValue(\html_writer::span($userfullnames, 'selectednames'));
}
}
|
php
|
public function definition_after_data() {
$mform = $this->_form;
if ($userfullnames = $mform->getElementValue('userfullnames')) {
$mform->getElement('selectednames')->setValue(\html_writer::span($userfullnames, 'selectednames'));
}
}
|
[
"public",
"function",
"definition_after_data",
"(",
")",
"{",
"$",
"mform",
"=",
"$",
"this",
"->",
"_form",
";",
"if",
"(",
"$",
"userfullnames",
"=",
"$",
"mform",
"->",
"getElementValue",
"(",
"'userfullnames'",
")",
")",
"{",
"$",
"mform",
"->",
"getElement",
"(",
"'selectednames'",
")",
"->",
"setValue",
"(",
"\\",
"html_writer",
"::",
"span",
"(",
"$",
"userfullnames",
",",
"'selectednames'",
")",
")",
";",
"}",
"}"
] |
This method implements changes to the form that need to be made once the form data is set.
|
[
"This",
"method",
"implements",
"changes",
"to",
"the",
"form",
"that",
"need",
"to",
"be",
"made",
"once",
"the",
"form",
"data",
"is",
"set",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/history/classes/filter_form.php#L86-L92
|
218,519
|
moodle/moodle
|
lib/ddl/sqlite_sql_generator.php
|
sqlite_sql_generator.getRenameIndexSQL
|
function getRenameIndexSQL($xmldb_table, $xmldb_index, $newname) {
/// Get the real index name
$dbindexname = $this->mdb->get_manager()->find_index_name($xmldb_table, $xmldb_index);
$xmldb_index->setName($newname);
$results = array('DROP INDEX ' . $dbindexname);
$results = array_merge($results, $this->getCreateIndexSQL($xmldb_table, $xmldb_index));
return $results;
}
|
php
|
function getRenameIndexSQL($xmldb_table, $xmldb_index, $newname) {
/// Get the real index name
$dbindexname = $this->mdb->get_manager()->find_index_name($xmldb_table, $xmldb_index);
$xmldb_index->setName($newname);
$results = array('DROP INDEX ' . $dbindexname);
$results = array_merge($results, $this->getCreateIndexSQL($xmldb_table, $xmldb_index));
return $results;
}
|
[
"function",
"getRenameIndexSQL",
"(",
"$",
"xmldb_table",
",",
"$",
"xmldb_index",
",",
"$",
"newname",
")",
"{",
"/// Get the real index name",
"$",
"dbindexname",
"=",
"$",
"this",
"->",
"mdb",
"->",
"get_manager",
"(",
")",
"->",
"find_index_name",
"(",
"$",
"xmldb_table",
",",
"$",
"xmldb_index",
")",
";",
"$",
"xmldb_index",
"->",
"setName",
"(",
"$",
"newname",
")",
";",
"$",
"results",
"=",
"array",
"(",
"'DROP INDEX '",
".",
"$",
"dbindexname",
")",
";",
"$",
"results",
"=",
"array_merge",
"(",
"$",
"results",
",",
"$",
"this",
"->",
"getCreateIndexSQL",
"(",
"$",
"xmldb_table",
",",
"$",
"xmldb_index",
")",
")",
";",
"return",
"$",
"results",
";",
"}"
] |
Given one xmldb_table and one xmldb_index, return the SQL statements needed to rename the index in the table
|
[
"Given",
"one",
"xmldb_table",
"and",
"one",
"xmldb_index",
"return",
"the",
"SQL",
"statements",
"needed",
"to",
"rename",
"the",
"index",
"in",
"the",
"table"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ddl/sqlite_sql_generator.php#L331-L338
|
218,520
|
moodle/moodle
|
grade/report/user/externallib.php
|
gradereport_user_external.check_report_access
|
protected static function check_report_access($courseid, $userid, $groupid = 0) {
global $USER;
// Validate the parameter.
$params = self::validate_parameters(self::get_grades_table_parameters(),
array(
'courseid' => $courseid,
'userid' => $userid,
'groupid' => $groupid,
)
);
// Compact/extract functions are not recommended.
$courseid = $params['courseid'];
$userid = $params['userid'];
$groupid = $params['groupid'];
// Function get_course internally throws an exception if the course doesn't exist.
$course = get_course($courseid);
$context = context_course::instance($courseid);
self::validate_context($context);
// Specific capabilities.
require_capability('gradereport/user:view', $context);
$user = null;
if (empty($userid)) {
require_capability('moodle/grade:viewall', $context);
} else {
$user = core_user::get_user($userid, '*', MUST_EXIST);
core_user::require_active_user($user);
// Check if we can view the user group (if any).
// When userid == 0, we are retrieving all the users, we'll check then if a groupid is required.
if (!groups_user_groups_visible($course, $user->id)) {
throw new moodle_exception('notingroup');
}
}
$access = false;
if (has_capability('moodle/grade:viewall', $context)) {
// Can view all course grades.
$access = true;
} else if ($userid == $USER->id and has_capability('moodle/grade:view', $context) and $course->showgrades) {
// View own grades.
$access = true;
}
if (!$access) {
throw new moodle_exception('nopermissiontoviewgrades', 'error');
}
if (!empty($groupid)) {
// Determine is the group is visible to user.
if (!groups_group_visible($groupid, $course)) {
throw new moodle_exception('notingroup');
}
} else {
// Check to see if groups are being used here.
if ($groupmode = groups_get_course_groupmode($course)) {
$groupid = groups_get_course_group($course);
// Determine is the group is visible to user (this is particullary for the group 0).
if (!groups_group_visible($groupid, $course)) {
throw new moodle_exception('notingroup');
}
} else {
$groupid = 0;
}
}
return array($params, $course, $context, $user, $groupid);
}
|
php
|
protected static function check_report_access($courseid, $userid, $groupid = 0) {
global $USER;
// Validate the parameter.
$params = self::validate_parameters(self::get_grades_table_parameters(),
array(
'courseid' => $courseid,
'userid' => $userid,
'groupid' => $groupid,
)
);
// Compact/extract functions are not recommended.
$courseid = $params['courseid'];
$userid = $params['userid'];
$groupid = $params['groupid'];
// Function get_course internally throws an exception if the course doesn't exist.
$course = get_course($courseid);
$context = context_course::instance($courseid);
self::validate_context($context);
// Specific capabilities.
require_capability('gradereport/user:view', $context);
$user = null;
if (empty($userid)) {
require_capability('moodle/grade:viewall', $context);
} else {
$user = core_user::get_user($userid, '*', MUST_EXIST);
core_user::require_active_user($user);
// Check if we can view the user group (if any).
// When userid == 0, we are retrieving all the users, we'll check then if a groupid is required.
if (!groups_user_groups_visible($course, $user->id)) {
throw new moodle_exception('notingroup');
}
}
$access = false;
if (has_capability('moodle/grade:viewall', $context)) {
// Can view all course grades.
$access = true;
} else if ($userid == $USER->id and has_capability('moodle/grade:view', $context) and $course->showgrades) {
// View own grades.
$access = true;
}
if (!$access) {
throw new moodle_exception('nopermissiontoviewgrades', 'error');
}
if (!empty($groupid)) {
// Determine is the group is visible to user.
if (!groups_group_visible($groupid, $course)) {
throw new moodle_exception('notingroup');
}
} else {
// Check to see if groups are being used here.
if ($groupmode = groups_get_course_groupmode($course)) {
$groupid = groups_get_course_group($course);
// Determine is the group is visible to user (this is particullary for the group 0).
if (!groups_group_visible($groupid, $course)) {
throw new moodle_exception('notingroup');
}
} else {
$groupid = 0;
}
}
return array($params, $course, $context, $user, $groupid);
}
|
[
"protected",
"static",
"function",
"check_report_access",
"(",
"$",
"courseid",
",",
"$",
"userid",
",",
"$",
"groupid",
"=",
"0",
")",
"{",
"global",
"$",
"USER",
";",
"// Validate the parameter.",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_grades_table_parameters",
"(",
")",
",",
"array",
"(",
"'courseid'",
"=>",
"$",
"courseid",
",",
"'userid'",
"=>",
"$",
"userid",
",",
"'groupid'",
"=>",
"$",
"groupid",
",",
")",
")",
";",
"// Compact/extract functions are not recommended.",
"$",
"courseid",
"=",
"$",
"params",
"[",
"'courseid'",
"]",
";",
"$",
"userid",
"=",
"$",
"params",
"[",
"'userid'",
"]",
";",
"$",
"groupid",
"=",
"$",
"params",
"[",
"'groupid'",
"]",
";",
"// Function get_course internally throws an exception if the course doesn't exist.",
"$",
"course",
"=",
"get_course",
"(",
"$",
"courseid",
")",
";",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"courseid",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"// Specific capabilities.",
"require_capability",
"(",
"'gradereport/user:view'",
",",
"$",
"context",
")",
";",
"$",
"user",
"=",
"null",
";",
"if",
"(",
"empty",
"(",
"$",
"userid",
")",
")",
"{",
"require_capability",
"(",
"'moodle/grade:viewall'",
",",
"$",
"context",
")",
";",
"}",
"else",
"{",
"$",
"user",
"=",
"core_user",
"::",
"get_user",
"(",
"$",
"userid",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"core_user",
"::",
"require_active_user",
"(",
"$",
"user",
")",
";",
"// Check if we can view the user group (if any).",
"// When userid == 0, we are retrieving all the users, we'll check then if a groupid is required.",
"if",
"(",
"!",
"groups_user_groups_visible",
"(",
"$",
"course",
",",
"$",
"user",
"->",
"id",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'notingroup'",
")",
";",
"}",
"}",
"$",
"access",
"=",
"false",
";",
"if",
"(",
"has_capability",
"(",
"'moodle/grade:viewall'",
",",
"$",
"context",
")",
")",
"{",
"// Can view all course grades.",
"$",
"access",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"$",
"userid",
"==",
"$",
"USER",
"->",
"id",
"and",
"has_capability",
"(",
"'moodle/grade:view'",
",",
"$",
"context",
")",
"and",
"$",
"course",
"->",
"showgrades",
")",
"{",
"// View own grades.",
"$",
"access",
"=",
"true",
";",
"}",
"if",
"(",
"!",
"$",
"access",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'nopermissiontoviewgrades'",
",",
"'error'",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"groupid",
")",
")",
"{",
"// Determine is the group is visible to user.",
"if",
"(",
"!",
"groups_group_visible",
"(",
"$",
"groupid",
",",
"$",
"course",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'notingroup'",
")",
";",
"}",
"}",
"else",
"{",
"// Check to see if groups are being used here.",
"if",
"(",
"$",
"groupmode",
"=",
"groups_get_course_groupmode",
"(",
"$",
"course",
")",
")",
"{",
"$",
"groupid",
"=",
"groups_get_course_group",
"(",
"$",
"course",
")",
";",
"// Determine is the group is visible to user (this is particullary for the group 0).",
"if",
"(",
"!",
"groups_group_visible",
"(",
"$",
"groupid",
",",
"$",
"course",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'notingroup'",
")",
";",
"}",
"}",
"else",
"{",
"$",
"groupid",
"=",
"0",
";",
"}",
"}",
"return",
"array",
"(",
"$",
"params",
",",
"$",
"course",
",",
"$",
"context",
",",
"$",
"user",
",",
"$",
"groupid",
")",
";",
"}"
] |
Validate access permissions to the report
@param int $courseid the courseid
@param int $userid the user id to retrieve data from
@param int $groupid the group id
@return array with the parameters cleaned and other required information
@since Moodle 3.2
|
[
"Validate",
"access",
"permissions",
"to",
"the",
"report"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/user/externallib.php#L50-L123
|
218,521
|
moodle/moodle
|
grade/report/user/externallib.php
|
gradereport_user_external.get_report_data
|
protected static function get_report_data($course, $context, $user, $userid, $groupid, $tabledata = true) {
global $CFG;
$warnings = array();
// Require files here to save some memory in case validation fails.
require_once($CFG->dirroot . '/group/lib.php');
require_once($CFG->libdir . '/gradelib.php');
require_once($CFG->dirroot . '/grade/lib.php');
require_once($CFG->dirroot . '/grade/report/user/lib.php');
// Force regrade to update items marked as 'needupdate'.
grade_regrade_final_grades($course->id);
$gpr = new grade_plugin_return(
array(
'type' => 'report',
'plugin' => 'user',
'courseid' => $course->id,
'userid' => $userid)
);
$reportdata = array();
// Just one user.
if ($user) {
$report = new grade_report_user($course->id, $gpr, $context, $userid);
$report->fill_table();
$gradeuserdata = array(
'courseid' => $course->id,
'userid' => $user->id,
'userfullname' => fullname($user),
'maxdepth' => $report->maxdepth,
);
if ($tabledata) {
$gradeuserdata['tabledata'] = $report->tabledata;
} else {
$gradeuserdata['gradeitems'] = $report->gradeitemsdata;
}
$reportdata[] = $gradeuserdata;
} else {
$defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol);
$showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol);
$showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $context);
$gui = new graded_users_iterator($course, null, $groupid);
$gui->require_active_enrolment($showonlyactiveenrol);
$gui->init();
while ($userdata = $gui->next_user()) {
$currentuser = $userdata->user;
$report = new grade_report_user($course->id, $gpr, $context, $currentuser->id);
$report->fill_table();
$gradeuserdata = array(
'courseid' => $course->id,
'userid' => $currentuser->id,
'userfullname' => fullname($currentuser),
'maxdepth' => $report->maxdepth,
);
if ($tabledata) {
$gradeuserdata['tabledata'] = $report->tabledata;
} else {
$gradeuserdata['gradeitems'] = $report->gradeitemsdata;
}
$reportdata[] = $gradeuserdata;
}
$gui->close();
}
return array($reportdata, $warnings);
}
|
php
|
protected static function get_report_data($course, $context, $user, $userid, $groupid, $tabledata = true) {
global $CFG;
$warnings = array();
// Require files here to save some memory in case validation fails.
require_once($CFG->dirroot . '/group/lib.php');
require_once($CFG->libdir . '/gradelib.php');
require_once($CFG->dirroot . '/grade/lib.php');
require_once($CFG->dirroot . '/grade/report/user/lib.php');
// Force regrade to update items marked as 'needupdate'.
grade_regrade_final_grades($course->id);
$gpr = new grade_plugin_return(
array(
'type' => 'report',
'plugin' => 'user',
'courseid' => $course->id,
'userid' => $userid)
);
$reportdata = array();
// Just one user.
if ($user) {
$report = new grade_report_user($course->id, $gpr, $context, $userid);
$report->fill_table();
$gradeuserdata = array(
'courseid' => $course->id,
'userid' => $user->id,
'userfullname' => fullname($user),
'maxdepth' => $report->maxdepth,
);
if ($tabledata) {
$gradeuserdata['tabledata'] = $report->tabledata;
} else {
$gradeuserdata['gradeitems'] = $report->gradeitemsdata;
}
$reportdata[] = $gradeuserdata;
} else {
$defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol);
$showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol);
$showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $context);
$gui = new graded_users_iterator($course, null, $groupid);
$gui->require_active_enrolment($showonlyactiveenrol);
$gui->init();
while ($userdata = $gui->next_user()) {
$currentuser = $userdata->user;
$report = new grade_report_user($course->id, $gpr, $context, $currentuser->id);
$report->fill_table();
$gradeuserdata = array(
'courseid' => $course->id,
'userid' => $currentuser->id,
'userfullname' => fullname($currentuser),
'maxdepth' => $report->maxdepth,
);
if ($tabledata) {
$gradeuserdata['tabledata'] = $report->tabledata;
} else {
$gradeuserdata['gradeitems'] = $report->gradeitemsdata;
}
$reportdata[] = $gradeuserdata;
}
$gui->close();
}
return array($reportdata, $warnings);
}
|
[
"protected",
"static",
"function",
"get_report_data",
"(",
"$",
"course",
",",
"$",
"context",
",",
"$",
"user",
",",
"$",
"userid",
",",
"$",
"groupid",
",",
"$",
"tabledata",
"=",
"true",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"warnings",
"=",
"array",
"(",
")",
";",
"// Require files here to save some memory in case validation fails.",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/group/lib.php'",
")",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"libdir",
".",
"'/gradelib.php'",
")",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/grade/lib.php'",
")",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/grade/report/user/lib.php'",
")",
";",
"// Force regrade to update items marked as 'needupdate'.",
"grade_regrade_final_grades",
"(",
"$",
"course",
"->",
"id",
")",
";",
"$",
"gpr",
"=",
"new",
"grade_plugin_return",
"(",
"array",
"(",
"'type'",
"=>",
"'report'",
",",
"'plugin'",
"=>",
"'user'",
",",
"'courseid'",
"=>",
"$",
"course",
"->",
"id",
",",
"'userid'",
"=>",
"$",
"userid",
")",
")",
";",
"$",
"reportdata",
"=",
"array",
"(",
")",
";",
"// Just one user.",
"if",
"(",
"$",
"user",
")",
"{",
"$",
"report",
"=",
"new",
"grade_report_user",
"(",
"$",
"course",
"->",
"id",
",",
"$",
"gpr",
",",
"$",
"context",
",",
"$",
"userid",
")",
";",
"$",
"report",
"->",
"fill_table",
"(",
")",
";",
"$",
"gradeuserdata",
"=",
"array",
"(",
"'courseid'",
"=>",
"$",
"course",
"->",
"id",
",",
"'userid'",
"=>",
"$",
"user",
"->",
"id",
",",
"'userfullname'",
"=>",
"fullname",
"(",
"$",
"user",
")",
",",
"'maxdepth'",
"=>",
"$",
"report",
"->",
"maxdepth",
",",
")",
";",
"if",
"(",
"$",
"tabledata",
")",
"{",
"$",
"gradeuserdata",
"[",
"'tabledata'",
"]",
"=",
"$",
"report",
"->",
"tabledata",
";",
"}",
"else",
"{",
"$",
"gradeuserdata",
"[",
"'gradeitems'",
"]",
"=",
"$",
"report",
"->",
"gradeitemsdata",
";",
"}",
"$",
"reportdata",
"[",
"]",
"=",
"$",
"gradeuserdata",
";",
"}",
"else",
"{",
"$",
"defaultgradeshowactiveenrol",
"=",
"!",
"empty",
"(",
"$",
"CFG",
"->",
"grade_report_showonlyactiveenrol",
")",
";",
"$",
"showonlyactiveenrol",
"=",
"get_user_preferences",
"(",
"'grade_report_showonlyactiveenrol'",
",",
"$",
"defaultgradeshowactiveenrol",
")",
";",
"$",
"showonlyactiveenrol",
"=",
"$",
"showonlyactiveenrol",
"||",
"!",
"has_capability",
"(",
"'moodle/course:viewsuspendedusers'",
",",
"$",
"context",
")",
";",
"$",
"gui",
"=",
"new",
"graded_users_iterator",
"(",
"$",
"course",
",",
"null",
",",
"$",
"groupid",
")",
";",
"$",
"gui",
"->",
"require_active_enrolment",
"(",
"$",
"showonlyactiveenrol",
")",
";",
"$",
"gui",
"->",
"init",
"(",
")",
";",
"while",
"(",
"$",
"userdata",
"=",
"$",
"gui",
"->",
"next_user",
"(",
")",
")",
"{",
"$",
"currentuser",
"=",
"$",
"userdata",
"->",
"user",
";",
"$",
"report",
"=",
"new",
"grade_report_user",
"(",
"$",
"course",
"->",
"id",
",",
"$",
"gpr",
",",
"$",
"context",
",",
"$",
"currentuser",
"->",
"id",
")",
";",
"$",
"report",
"->",
"fill_table",
"(",
")",
";",
"$",
"gradeuserdata",
"=",
"array",
"(",
"'courseid'",
"=>",
"$",
"course",
"->",
"id",
",",
"'userid'",
"=>",
"$",
"currentuser",
"->",
"id",
",",
"'userfullname'",
"=>",
"fullname",
"(",
"$",
"currentuser",
")",
",",
"'maxdepth'",
"=>",
"$",
"report",
"->",
"maxdepth",
",",
")",
";",
"if",
"(",
"$",
"tabledata",
")",
"{",
"$",
"gradeuserdata",
"[",
"'tabledata'",
"]",
"=",
"$",
"report",
"->",
"tabledata",
";",
"}",
"else",
"{",
"$",
"gradeuserdata",
"[",
"'gradeitems'",
"]",
"=",
"$",
"report",
"->",
"gradeitemsdata",
";",
"}",
"$",
"reportdata",
"[",
"]",
"=",
"$",
"gradeuserdata",
";",
"}",
"$",
"gui",
"->",
"close",
"(",
")",
";",
"}",
"return",
"array",
"(",
"$",
"reportdata",
",",
"$",
"warnings",
")",
";",
"}"
] |
Get the report data
@param stdClass $course course object
@param stdClass $context context object
@param stdClass $user user object (it can be null for all the users)
@param int $userid the user to retrieve data from, 0 for all
@param int $groupid the group id to filter
@param bool $tabledata whether to get the table data (true) or the gradeitemdata
@return array data and possible warnings
@since Moodle 3.2
|
[
"Get",
"the",
"report",
"data"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/user/externallib.php#L136-L206
|
218,522
|
moodle/moodle
|
grade/report/user/externallib.php
|
gradereport_user_external.get_grades_table_parameters
|
public static function get_grades_table_parameters() {
return new external_function_parameters (
array(
'courseid' => new external_value(PARAM_INT, 'Course Id', VALUE_REQUIRED),
'userid' => new external_value(PARAM_INT, 'Return grades only for this user (optional)', VALUE_DEFAULT, 0),
'groupid' => new external_value(PARAM_INT, 'Get users from this group only', VALUE_DEFAULT, 0)
)
);
}
|
php
|
public static function get_grades_table_parameters() {
return new external_function_parameters (
array(
'courseid' => new external_value(PARAM_INT, 'Course Id', VALUE_REQUIRED),
'userid' => new external_value(PARAM_INT, 'Return grades only for this user (optional)', VALUE_DEFAULT, 0),
'groupid' => new external_value(PARAM_INT, 'Get users from this group only', VALUE_DEFAULT, 0)
)
);
}
|
[
"public",
"static",
"function",
"get_grades_table_parameters",
"(",
")",
"{",
"return",
"new",
"external_function_parameters",
"(",
"array",
"(",
"'courseid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Course Id'",
",",
"VALUE_REQUIRED",
")",
",",
"'userid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Return grades only for this user (optional)'",
",",
"VALUE_DEFAULT",
",",
"0",
")",
",",
"'groupid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Get users from this group only'",
",",
"VALUE_DEFAULT",
",",
"0",
")",
")",
")",
";",
"}"
] |
Describes the parameters for get_grades_table.
@return external_function_parameters
@since Moodle 2.9
|
[
"Describes",
"the",
"parameters",
"for",
"get_grades_table",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/user/externallib.php#L214-L222
|
218,523
|
moodle/moodle
|
grade/report/user/externallib.php
|
gradereport_user_external.get_grades_table
|
public static function get_grades_table($courseid, $userid = 0, $groupid = 0) {
global $CFG, $USER;
list($params, $course, $context, $user, $groupid) = self::check_report_access($courseid, $userid, $groupid);
$userid = $params['userid'];
// We pass userid because it can be still 0.
list($tables, $warnings) = self::get_report_data($course, $context, $user, $userid, $groupid);
$result = array();
$result['tables'] = $tables;
$result['warnings'] = $warnings;
return $result;
}
|
php
|
public static function get_grades_table($courseid, $userid = 0, $groupid = 0) {
global $CFG, $USER;
list($params, $course, $context, $user, $groupid) = self::check_report_access($courseid, $userid, $groupid);
$userid = $params['userid'];
// We pass userid because it can be still 0.
list($tables, $warnings) = self::get_report_data($course, $context, $user, $userid, $groupid);
$result = array();
$result['tables'] = $tables;
$result['warnings'] = $warnings;
return $result;
}
|
[
"public",
"static",
"function",
"get_grades_table",
"(",
"$",
"courseid",
",",
"$",
"userid",
"=",
"0",
",",
"$",
"groupid",
"=",
"0",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"USER",
";",
"list",
"(",
"$",
"params",
",",
"$",
"course",
",",
"$",
"context",
",",
"$",
"user",
",",
"$",
"groupid",
")",
"=",
"self",
"::",
"check_report_access",
"(",
"$",
"courseid",
",",
"$",
"userid",
",",
"$",
"groupid",
")",
";",
"$",
"userid",
"=",
"$",
"params",
"[",
"'userid'",
"]",
";",
"// We pass userid because it can be still 0.",
"list",
"(",
"$",
"tables",
",",
"$",
"warnings",
")",
"=",
"self",
"::",
"get_report_data",
"(",
"$",
"course",
",",
"$",
"context",
",",
"$",
"user",
",",
"$",
"userid",
",",
"$",
"groupid",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"result",
"[",
"'tables'",
"]",
"=",
"$",
"tables",
";",
"$",
"result",
"[",
"'warnings'",
"]",
"=",
"$",
"warnings",
";",
"return",
"$",
"result",
";",
"}"
] |
Returns a list of grades tables for users in a course.
@param int $courseid Course Id
@param int $userid Only this user (optional)
@param int $groupid Get users from this group only
@return array the grades tables
@since Moodle 2.9
|
[
"Returns",
"a",
"list",
"of",
"grades",
"tables",
"for",
"users",
"in",
"a",
"course",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/user/externallib.php#L234-L247
|
218,524
|
moodle/moodle
|
grade/report/user/externallib.php
|
gradereport_user_external.get_grades_table_returns
|
public static function get_grades_table_returns() {
return new external_single_structure(
array(
'tables' => new external_multiple_structure(
new external_single_structure(
array(
'courseid' => new external_value(PARAM_INT, 'course id'),
'userid' => new external_value(PARAM_INT, 'user id'),
'userfullname' => new external_value(PARAM_TEXT, 'user fullname'),
'maxdepth' => new external_value(PARAM_INT, 'table max depth (needed for printing it)'),
'tabledata' => new external_multiple_structure(
new external_single_structure(
array(
'itemname' => new external_single_structure(
array (
'class' => new external_value(PARAM_RAW, 'class'),
'colspan' => new external_value(PARAM_INT, 'col span'),
'content' => new external_value(PARAM_RAW, 'cell content'),
'celltype' => new external_value(PARAM_RAW, 'cell type'),
'id' => new external_value(PARAM_ALPHANUMEXT, 'id')
), 'The item returned data', VALUE_OPTIONAL
),
'leader' => new external_single_structure(
array (
'class' => new external_value(PARAM_RAW, 'class'),
'rowspan' => new external_value(PARAM_INT, 'row span')
), 'The item returned data', VALUE_OPTIONAL
),
'weight' => new external_single_structure(
self::grades_table_column(), 'weight column', VALUE_OPTIONAL
),
'grade' => new external_single_structure(
self::grades_table_column(), 'grade column', VALUE_OPTIONAL
),
'range' => new external_single_structure(
self::grades_table_column(), 'range column', VALUE_OPTIONAL
),
'percentage' => new external_single_structure(
self::grades_table_column(), 'percentage column', VALUE_OPTIONAL
),
'lettergrade' => new external_single_structure(
self::grades_table_column(), 'lettergrade column', VALUE_OPTIONAL
),
'rank' => new external_single_structure(
self::grades_table_column(), 'rank column', VALUE_OPTIONAL
),
'average' => new external_single_structure(
self::grades_table_column(), 'average column', VALUE_OPTIONAL
),
'feedback' => new external_single_structure(
self::grades_table_column(), 'feedback column', VALUE_OPTIONAL
),
'contributiontocoursetotal' => new external_single_structure(
self::grades_table_column(), 'contributiontocoursetotal column', VALUE_OPTIONAL
),
), 'table'
)
)
)
)
),
'warnings' => new external_warnings()
)
);
}
|
php
|
public static function get_grades_table_returns() {
return new external_single_structure(
array(
'tables' => new external_multiple_structure(
new external_single_structure(
array(
'courseid' => new external_value(PARAM_INT, 'course id'),
'userid' => new external_value(PARAM_INT, 'user id'),
'userfullname' => new external_value(PARAM_TEXT, 'user fullname'),
'maxdepth' => new external_value(PARAM_INT, 'table max depth (needed for printing it)'),
'tabledata' => new external_multiple_structure(
new external_single_structure(
array(
'itemname' => new external_single_structure(
array (
'class' => new external_value(PARAM_RAW, 'class'),
'colspan' => new external_value(PARAM_INT, 'col span'),
'content' => new external_value(PARAM_RAW, 'cell content'),
'celltype' => new external_value(PARAM_RAW, 'cell type'),
'id' => new external_value(PARAM_ALPHANUMEXT, 'id')
), 'The item returned data', VALUE_OPTIONAL
),
'leader' => new external_single_structure(
array (
'class' => new external_value(PARAM_RAW, 'class'),
'rowspan' => new external_value(PARAM_INT, 'row span')
), 'The item returned data', VALUE_OPTIONAL
),
'weight' => new external_single_structure(
self::grades_table_column(), 'weight column', VALUE_OPTIONAL
),
'grade' => new external_single_structure(
self::grades_table_column(), 'grade column', VALUE_OPTIONAL
),
'range' => new external_single_structure(
self::grades_table_column(), 'range column', VALUE_OPTIONAL
),
'percentage' => new external_single_structure(
self::grades_table_column(), 'percentage column', VALUE_OPTIONAL
),
'lettergrade' => new external_single_structure(
self::grades_table_column(), 'lettergrade column', VALUE_OPTIONAL
),
'rank' => new external_single_structure(
self::grades_table_column(), 'rank column', VALUE_OPTIONAL
),
'average' => new external_single_structure(
self::grades_table_column(), 'average column', VALUE_OPTIONAL
),
'feedback' => new external_single_structure(
self::grades_table_column(), 'feedback column', VALUE_OPTIONAL
),
'contributiontocoursetotal' => new external_single_structure(
self::grades_table_column(), 'contributiontocoursetotal column', VALUE_OPTIONAL
),
), 'table'
)
)
)
)
),
'warnings' => new external_warnings()
)
);
}
|
[
"public",
"static",
"function",
"get_grades_table_returns",
"(",
")",
"{",
"return",
"new",
"external_single_structure",
"(",
"array",
"(",
"'tables'",
"=>",
"new",
"external_multiple_structure",
"(",
"new",
"external_single_structure",
"(",
"array",
"(",
"'courseid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'course id'",
")",
",",
"'userid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'user id'",
")",
",",
"'userfullname'",
"=>",
"new",
"external_value",
"(",
"PARAM_TEXT",
",",
"'user fullname'",
")",
",",
"'maxdepth'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'table max depth (needed for printing it)'",
")",
",",
"'tabledata'",
"=>",
"new",
"external_multiple_structure",
"(",
"new",
"external_single_structure",
"(",
"array",
"(",
"'itemname'",
"=>",
"new",
"external_single_structure",
"(",
"array",
"(",
"'class'",
"=>",
"new",
"external_value",
"(",
"PARAM_RAW",
",",
"'class'",
")",
",",
"'colspan'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'col span'",
")",
",",
"'content'",
"=>",
"new",
"external_value",
"(",
"PARAM_RAW",
",",
"'cell content'",
")",
",",
"'celltype'",
"=>",
"new",
"external_value",
"(",
"PARAM_RAW",
",",
"'cell type'",
")",
",",
"'id'",
"=>",
"new",
"external_value",
"(",
"PARAM_ALPHANUMEXT",
",",
"'id'",
")",
")",
",",
"'The item returned data'",
",",
"VALUE_OPTIONAL",
")",
",",
"'leader'",
"=>",
"new",
"external_single_structure",
"(",
"array",
"(",
"'class'",
"=>",
"new",
"external_value",
"(",
"PARAM_RAW",
",",
"'class'",
")",
",",
"'rowspan'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'row span'",
")",
")",
",",
"'The item returned data'",
",",
"VALUE_OPTIONAL",
")",
",",
"'weight'",
"=>",
"new",
"external_single_structure",
"(",
"self",
"::",
"grades_table_column",
"(",
")",
",",
"'weight column'",
",",
"VALUE_OPTIONAL",
")",
",",
"'grade'",
"=>",
"new",
"external_single_structure",
"(",
"self",
"::",
"grades_table_column",
"(",
")",
",",
"'grade column'",
",",
"VALUE_OPTIONAL",
")",
",",
"'range'",
"=>",
"new",
"external_single_structure",
"(",
"self",
"::",
"grades_table_column",
"(",
")",
",",
"'range column'",
",",
"VALUE_OPTIONAL",
")",
",",
"'percentage'",
"=>",
"new",
"external_single_structure",
"(",
"self",
"::",
"grades_table_column",
"(",
")",
",",
"'percentage column'",
",",
"VALUE_OPTIONAL",
")",
",",
"'lettergrade'",
"=>",
"new",
"external_single_structure",
"(",
"self",
"::",
"grades_table_column",
"(",
")",
",",
"'lettergrade column'",
",",
"VALUE_OPTIONAL",
")",
",",
"'rank'",
"=>",
"new",
"external_single_structure",
"(",
"self",
"::",
"grades_table_column",
"(",
")",
",",
"'rank column'",
",",
"VALUE_OPTIONAL",
")",
",",
"'average'",
"=>",
"new",
"external_single_structure",
"(",
"self",
"::",
"grades_table_column",
"(",
")",
",",
"'average column'",
",",
"VALUE_OPTIONAL",
")",
",",
"'feedback'",
"=>",
"new",
"external_single_structure",
"(",
"self",
"::",
"grades_table_column",
"(",
")",
",",
"'feedback column'",
",",
"VALUE_OPTIONAL",
")",
",",
"'contributiontocoursetotal'",
"=>",
"new",
"external_single_structure",
"(",
"self",
"::",
"grades_table_column",
"(",
")",
",",
"'contributiontocoursetotal column'",
",",
"VALUE_OPTIONAL",
")",
",",
")",
",",
"'table'",
")",
")",
")",
")",
")",
",",
"'warnings'",
"=>",
"new",
"external_warnings",
"(",
")",
")",
")",
";",
"}"
] |
Describes tget_grades_table return value.
@return external_single_structure
@since Moodle 2.9
|
[
"Describes",
"tget_grades_table",
"return",
"value",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/user/externallib.php#L269-L333
|
218,525
|
moodle/moodle
|
grade/report/user/externallib.php
|
gradereport_user_external.get_grade_items
|
public static function get_grade_items($courseid, $userid = 0, $groupid = 0) {
global $CFG, $USER;
list($params, $course, $context, $user, $groupid) = self::check_report_access($courseid, $userid, $groupid);
$userid = $params['userid'];
// We pass userid because it can be still 0.
list($gradeitems, $warnings) = self::get_report_data($course, $context, $user, $userid, $groupid, false);
foreach ($gradeitems as $gradeitem) {
if (isset($gradeitem['feedback']) and isset($gradeitem['feedbackformat'])) {
list($gradeitem['feedback'], $gradeitem['feedbackformat']) =
external_format_text($gradeitem['feedback'], $gradeitem['feedbackformat'], $context->id);
}
}
$result = array();
$result['usergrades'] = $gradeitems;
$result['warnings'] = $warnings;
return $result;
}
|
php
|
public static function get_grade_items($courseid, $userid = 0, $groupid = 0) {
global $CFG, $USER;
list($params, $course, $context, $user, $groupid) = self::check_report_access($courseid, $userid, $groupid);
$userid = $params['userid'];
// We pass userid because it can be still 0.
list($gradeitems, $warnings) = self::get_report_data($course, $context, $user, $userid, $groupid, false);
foreach ($gradeitems as $gradeitem) {
if (isset($gradeitem['feedback']) and isset($gradeitem['feedbackformat'])) {
list($gradeitem['feedback'], $gradeitem['feedbackformat']) =
external_format_text($gradeitem['feedback'], $gradeitem['feedbackformat'], $context->id);
}
}
$result = array();
$result['usergrades'] = $gradeitems;
$result['warnings'] = $warnings;
return $result;
}
|
[
"public",
"static",
"function",
"get_grade_items",
"(",
"$",
"courseid",
",",
"$",
"userid",
"=",
"0",
",",
"$",
"groupid",
"=",
"0",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"USER",
";",
"list",
"(",
"$",
"params",
",",
"$",
"course",
",",
"$",
"context",
",",
"$",
"user",
",",
"$",
"groupid",
")",
"=",
"self",
"::",
"check_report_access",
"(",
"$",
"courseid",
",",
"$",
"userid",
",",
"$",
"groupid",
")",
";",
"$",
"userid",
"=",
"$",
"params",
"[",
"'userid'",
"]",
";",
"// We pass userid because it can be still 0.",
"list",
"(",
"$",
"gradeitems",
",",
"$",
"warnings",
")",
"=",
"self",
"::",
"get_report_data",
"(",
"$",
"course",
",",
"$",
"context",
",",
"$",
"user",
",",
"$",
"userid",
",",
"$",
"groupid",
",",
"false",
")",
";",
"foreach",
"(",
"$",
"gradeitems",
"as",
"$",
"gradeitem",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"gradeitem",
"[",
"'feedback'",
"]",
")",
"and",
"isset",
"(",
"$",
"gradeitem",
"[",
"'feedbackformat'",
"]",
")",
")",
"{",
"list",
"(",
"$",
"gradeitem",
"[",
"'feedback'",
"]",
",",
"$",
"gradeitem",
"[",
"'feedbackformat'",
"]",
")",
"=",
"external_format_text",
"(",
"$",
"gradeitem",
"[",
"'feedback'",
"]",
",",
"$",
"gradeitem",
"[",
"'feedbackformat'",
"]",
",",
"$",
"context",
"->",
"id",
")",
";",
"}",
"}",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"result",
"[",
"'usergrades'",
"]",
"=",
"$",
"gradeitems",
";",
"$",
"result",
"[",
"'warnings'",
"]",
"=",
"$",
"warnings",
";",
"return",
"$",
"result",
";",
"}"
] |
Returns the complete list of grade items for users in a course.
@param int $courseid Course Id
@param int $userid Only this user (optional)
@param int $groupid Get users from this group only
@return array the grades tables
@since Moodle 3.2
|
[
"Returns",
"the",
"complete",
"list",
"of",
"grade",
"items",
"for",
"users",
"in",
"a",
"course",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/user/externallib.php#L444-L464
|
218,526
|
moodle/moodle
|
lib/adodb/adodb-perf.inc.php
|
adodb_perf.table
|
static function table($newtable = false)
{
static $_table;
if (!empty($newtable)) $_table = $newtable;
if (empty($_table)) $_table = 'adodb_logsql';
return $_table;
}
|
php
|
static function table($newtable = false)
{
static $_table;
if (!empty($newtable)) $_table = $newtable;
if (empty($_table)) $_table = 'adodb_logsql';
return $_table;
}
|
[
"static",
"function",
"table",
"(",
"$",
"newtable",
"=",
"false",
")",
"{",
"static",
"$",
"_table",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"newtable",
")",
")",
"$",
"_table",
"=",
"$",
"newtable",
";",
"if",
"(",
"empty",
"(",
"$",
"_table",
")",
")",
"$",
"_table",
"=",
"'adodb_logsql'",
";",
"return",
"$",
"_table",
";",
"}"
] |
Sets the tablename to be used
|
[
"Sets",
"the",
"tablename",
"to",
"be",
"used"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-perf.inc.php#L234-L241
|
218,527
|
moodle/moodle
|
lib/adodb/adodb-perf.inc.php
|
adodb_perf._CPULoad
|
function _CPULoad()
{
/*
cpu 524152 2662 2515228 336057010
cpu0 264339 1408 1257951 168025827
cpu1 259813 1254 1257277 168031181
page 622307 25475680
swap 24 1891
intr 890153570 868093576 6 0 4 4 0 6 1 2 0 0 0 124 0 8098760 2 13961053 0 0 0 0 0 0 0 0 0 0 0 0 0 16 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
disk_io: (3,0):(3144904,54369,610378,3090535,50936192) (3,1):(3630212,54097,633016,3576115,50951320)
ctxt 66155838
btime 1062315585
processes 69293
*/
// Algorithm is taken from
// http://social.technet.microsoft.com/Forums/en-US/winservergen/thread/414b0e1b-499c-411e-8a02-6a12e339c0f1/
if (strncmp(PHP_OS,'WIN',3)==0) {
if (PHP_VERSION == '5.0.0') return false;
if (PHP_VERSION == '5.0.1') return false;
if (PHP_VERSION == '5.0.2') return false;
if (PHP_VERSION == '5.0.3') return false;
if (PHP_VERSION == '4.3.10') return false; # see http://bugs.php.net/bug.php?id=31737
static $FAIL = false;
if ($FAIL) return false;
$objName = "winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\CIMV2";
$myQuery = "SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name = '_Total'";
try {
@$objWMIService = new COM($objName);
if (!$objWMIService) {
$FAIL = true;
return false;
}
$info[0] = -1;
$info[1] = 0;
$info[2] = 0;
$info[3] = 0;
foreach($objWMIService->ExecQuery($myQuery) as $objItem) {
$info[0] = $objItem->PercentProcessorTime();
}
} catch(Exception $e) {
$FAIL = true;
echo $e->getMessage();
return false;
}
return $info;
}
// Algorithm - Steve Blinch (BlitzAffe Online, http://www.blitzaffe.com)
$statfile = '/proc/stat';
if (!file_exists($statfile)) return false;
$fd = fopen($statfile,"r");
if (!$fd) return false;
$statinfo = explode("\n",fgets($fd, 1024));
fclose($fd);
foreach($statinfo as $line) {
$info = explode(" ",$line);
if($info[0]=="cpu") {
array_shift($info); // pop off "cpu"
if(!$info[0]) array_shift($info); // pop off blank space (if any)
return $info;
}
}
return false;
}
|
php
|
function _CPULoad()
{
/*
cpu 524152 2662 2515228 336057010
cpu0 264339 1408 1257951 168025827
cpu1 259813 1254 1257277 168031181
page 622307 25475680
swap 24 1891
intr 890153570 868093576 6 0 4 4 0 6 1 2 0 0 0 124 0 8098760 2 13961053 0 0 0 0 0 0 0 0 0 0 0 0 0 16 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
disk_io: (3,0):(3144904,54369,610378,3090535,50936192) (3,1):(3630212,54097,633016,3576115,50951320)
ctxt 66155838
btime 1062315585
processes 69293
*/
// Algorithm is taken from
// http://social.technet.microsoft.com/Forums/en-US/winservergen/thread/414b0e1b-499c-411e-8a02-6a12e339c0f1/
if (strncmp(PHP_OS,'WIN',3)==0) {
if (PHP_VERSION == '5.0.0') return false;
if (PHP_VERSION == '5.0.1') return false;
if (PHP_VERSION == '5.0.2') return false;
if (PHP_VERSION == '5.0.3') return false;
if (PHP_VERSION == '4.3.10') return false; # see http://bugs.php.net/bug.php?id=31737
static $FAIL = false;
if ($FAIL) return false;
$objName = "winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\CIMV2";
$myQuery = "SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name = '_Total'";
try {
@$objWMIService = new COM($objName);
if (!$objWMIService) {
$FAIL = true;
return false;
}
$info[0] = -1;
$info[1] = 0;
$info[2] = 0;
$info[3] = 0;
foreach($objWMIService->ExecQuery($myQuery) as $objItem) {
$info[0] = $objItem->PercentProcessorTime();
}
} catch(Exception $e) {
$FAIL = true;
echo $e->getMessage();
return false;
}
return $info;
}
// Algorithm - Steve Blinch (BlitzAffe Online, http://www.blitzaffe.com)
$statfile = '/proc/stat';
if (!file_exists($statfile)) return false;
$fd = fopen($statfile,"r");
if (!$fd) return false;
$statinfo = explode("\n",fgets($fd, 1024));
fclose($fd);
foreach($statinfo as $line) {
$info = explode(" ",$line);
if($info[0]=="cpu") {
array_shift($info); // pop off "cpu"
if(!$info[0]) array_shift($info); // pop off blank space (if any)
return $info;
}
}
return false;
}
|
[
"function",
"_CPULoad",
"(",
")",
"{",
"/*\n\ncpu 524152 2662 2515228 336057010\ncpu0 264339 1408 1257951 168025827\ncpu1 259813 1254 1257277 168031181\npage 622307 25475680\nswap 24 1891\nintr 890153570 868093576 6 0 4 4 0 6 1 2 0 0 0 124 0 8098760 2 13961053 0 0 0 0 0 0 0 0 0 0 0 0 0 16 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\ndisk_io: (3,0):(3144904,54369,610378,3090535,50936192) (3,1):(3630212,54097,633016,3576115,50951320)\nctxt 66155838\nbtime 1062315585\nprocesses 69293\n\n*/",
"// Algorithm is taken from",
"// http://social.technet.microsoft.com/Forums/en-US/winservergen/thread/414b0e1b-499c-411e-8a02-6a12e339c0f1/",
"if",
"(",
"strncmp",
"(",
"PHP_OS",
",",
"'WIN'",
",",
"3",
")",
"==",
"0",
")",
"{",
"if",
"(",
"PHP_VERSION",
"==",
"'5.0.0'",
")",
"return",
"false",
";",
"if",
"(",
"PHP_VERSION",
"==",
"'5.0.1'",
")",
"return",
"false",
";",
"if",
"(",
"PHP_VERSION",
"==",
"'5.0.2'",
")",
"return",
"false",
";",
"if",
"(",
"PHP_VERSION",
"==",
"'5.0.3'",
")",
"return",
"false",
";",
"if",
"(",
"PHP_VERSION",
"==",
"'4.3.10'",
")",
"return",
"false",
";",
"# see http://bugs.php.net/bug.php?id=31737",
"static",
"$",
"FAIL",
"=",
"false",
";",
"if",
"(",
"$",
"FAIL",
")",
"return",
"false",
";",
"$",
"objName",
"=",
"\"winmgmts:{impersonationLevel=impersonate}!\\\\\\\\.\\\\root\\\\CIMV2\"",
";",
"$",
"myQuery",
"=",
"\"SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name = '_Total'\"",
";",
"try",
"{",
"@",
"$",
"objWMIService",
"=",
"new",
"COM",
"(",
"$",
"objName",
")",
";",
"if",
"(",
"!",
"$",
"objWMIService",
")",
"{",
"$",
"FAIL",
"=",
"true",
";",
"return",
"false",
";",
"}",
"$",
"info",
"[",
"0",
"]",
"=",
"-",
"1",
";",
"$",
"info",
"[",
"1",
"]",
"=",
"0",
";",
"$",
"info",
"[",
"2",
"]",
"=",
"0",
";",
"$",
"info",
"[",
"3",
"]",
"=",
"0",
";",
"foreach",
"(",
"$",
"objWMIService",
"->",
"ExecQuery",
"(",
"$",
"myQuery",
")",
"as",
"$",
"objItem",
")",
"{",
"$",
"info",
"[",
"0",
"]",
"=",
"$",
"objItem",
"->",
"PercentProcessorTime",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"FAIL",
"=",
"true",
";",
"echo",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"return",
"false",
";",
"}",
"return",
"$",
"info",
";",
"}",
"// Algorithm - Steve Blinch (BlitzAffe Online, http://www.blitzaffe.com)",
"$",
"statfile",
"=",
"'/proc/stat'",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"statfile",
")",
")",
"return",
"false",
";",
"$",
"fd",
"=",
"fopen",
"(",
"$",
"statfile",
",",
"\"r\"",
")",
";",
"if",
"(",
"!",
"$",
"fd",
")",
"return",
"false",
";",
"$",
"statinfo",
"=",
"explode",
"(",
"\"\\n\"",
",",
"fgets",
"(",
"$",
"fd",
",",
"1024",
")",
")",
";",
"fclose",
"(",
"$",
"fd",
")",
";",
"foreach",
"(",
"$",
"statinfo",
"as",
"$",
"line",
")",
"{",
"$",
"info",
"=",
"explode",
"(",
"\" \"",
",",
"$",
"line",
")",
";",
"if",
"(",
"$",
"info",
"[",
"0",
"]",
"==",
"\"cpu\"",
")",
"{",
"array_shift",
"(",
"$",
"info",
")",
";",
"// pop off \"cpu\"",
"if",
"(",
"!",
"$",
"info",
"[",
"0",
"]",
")",
"array_shift",
"(",
"$",
"info",
")",
";",
"// pop off blank space (if any)",
"return",
"$",
"info",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
returns array with info to calculate CPU Load
|
[
"returns",
"array",
"with",
"info",
"to",
"calculate",
"CPU",
"Load"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-perf.inc.php#L244-L319
|
218,528
|
moodle/moodle
|
blog/classes/privacy/provider.php
|
provider.delete_all_user_data
|
protected static function delete_all_user_data(context_user $usercontext) {
global $DB;
$userid = $usercontext->instanceid;
// Delete all blog posts.
$recordset = $DB->get_recordset_select('post', 'userid = :userid AND module IN (:blog, :blogext)', [
'userid' => $userid, 'blog' => 'blog', 'blogext' => 'blog_external']);
foreach ($recordset as $record) {
$entry = new blog_entry(null, $record);
$entry->delete(); // Takes care of files and associations.
}
$recordset->close();
// Delete all external blogs, and their associated tags.
$DB->delete_records('blog_external', ['userid' => $userid]);
core_tag_tag::delete_instances('core', 'blog_external', $usercontext->id);
}
|
php
|
protected static function delete_all_user_data(context_user $usercontext) {
global $DB;
$userid = $usercontext->instanceid;
// Delete all blog posts.
$recordset = $DB->get_recordset_select('post', 'userid = :userid AND module IN (:blog, :blogext)', [
'userid' => $userid, 'blog' => 'blog', 'blogext' => 'blog_external']);
foreach ($recordset as $record) {
$entry = new blog_entry(null, $record);
$entry->delete(); // Takes care of files and associations.
}
$recordset->close();
// Delete all external blogs, and their associated tags.
$DB->delete_records('blog_external', ['userid' => $userid]);
core_tag_tag::delete_instances('core', 'blog_external', $usercontext->id);
}
|
[
"protected",
"static",
"function",
"delete_all_user_data",
"(",
"context_user",
"$",
"usercontext",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"userid",
"=",
"$",
"usercontext",
"->",
"instanceid",
";",
"// Delete all blog posts.",
"$",
"recordset",
"=",
"$",
"DB",
"->",
"get_recordset_select",
"(",
"'post'",
",",
"'userid = :userid AND module IN (:blog, :blogext)'",
",",
"[",
"'userid'",
"=>",
"$",
"userid",
",",
"'blog'",
"=>",
"'blog'",
",",
"'blogext'",
"=>",
"'blog_external'",
"]",
")",
";",
"foreach",
"(",
"$",
"recordset",
"as",
"$",
"record",
")",
"{",
"$",
"entry",
"=",
"new",
"blog_entry",
"(",
"null",
",",
"$",
"record",
")",
";",
"$",
"entry",
"->",
"delete",
"(",
")",
";",
"// Takes care of files and associations.",
"}",
"$",
"recordset",
"->",
"close",
"(",
")",
";",
"// Delete all external blogs, and their associated tags.",
"$",
"DB",
"->",
"delete_records",
"(",
"'blog_external'",
",",
"[",
"'userid'",
"=>",
"$",
"userid",
"]",
")",
";",
"core_tag_tag",
"::",
"delete_instances",
"(",
"'core'",
",",
"'blog_external'",
",",
"$",
"usercontext",
"->",
"id",
")",
";",
"}"
] |
Helper method to delete all user data.
@param context_user $usercontext The user context.
@return void
|
[
"Helper",
"method",
"to",
"delete",
"all",
"user",
"data",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blog/classes/privacy/provider.php#L510-L526
|
218,529
|
moodle/moodle
|
enrol/guest/classes/external.php
|
enrol_guest_external.get_instance_info
|
public static function get_instance_info($instanceid) {
global $DB;
$params = self::validate_parameters(self::get_instance_info_parameters(), array('instanceid' => $instanceid));
$warnings = array();
// Retrieve guest enrolment plugin.
$enrolplugin = enrol_get_plugin('guest');
if (empty($enrolplugin)) {
throw new moodle_exception('invaliddata', 'error');
}
self::validate_context(context_system::instance());
$enrolinstance = $DB->get_record('enrol', array('id' => $params['instanceid']), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $enrolinstance->courseid), '*', MUST_EXIST);
if (!core_course_category::can_view_course_info($course) && !can_access_course($course)) {
throw new moodle_exception('coursehidden');
}
$instanceinfo = $enrolplugin->get_enrol_info($enrolinstance);
// Specific instance information.
$instanceinfo->passwordrequired = $instanceinfo->requiredparam->passwordrequired;
unset($instanceinfo->requiredparam);
$result = array();
$result['instanceinfo'] = $instanceinfo;
$result['warnings'] = $warnings;
return $result;
}
|
php
|
public static function get_instance_info($instanceid) {
global $DB;
$params = self::validate_parameters(self::get_instance_info_parameters(), array('instanceid' => $instanceid));
$warnings = array();
// Retrieve guest enrolment plugin.
$enrolplugin = enrol_get_plugin('guest');
if (empty($enrolplugin)) {
throw new moodle_exception('invaliddata', 'error');
}
self::validate_context(context_system::instance());
$enrolinstance = $DB->get_record('enrol', array('id' => $params['instanceid']), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $enrolinstance->courseid), '*', MUST_EXIST);
if (!core_course_category::can_view_course_info($course) && !can_access_course($course)) {
throw new moodle_exception('coursehidden');
}
$instanceinfo = $enrolplugin->get_enrol_info($enrolinstance);
// Specific instance information.
$instanceinfo->passwordrequired = $instanceinfo->requiredparam->passwordrequired;
unset($instanceinfo->requiredparam);
$result = array();
$result['instanceinfo'] = $instanceinfo;
$result['warnings'] = $warnings;
return $result;
}
|
[
"public",
"static",
"function",
"get_instance_info",
"(",
"$",
"instanceid",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_instance_info_parameters",
"(",
")",
",",
"array",
"(",
"'instanceid'",
"=>",
"$",
"instanceid",
")",
")",
";",
"$",
"warnings",
"=",
"array",
"(",
")",
";",
"// Retrieve guest enrolment plugin.",
"$",
"enrolplugin",
"=",
"enrol_get_plugin",
"(",
"'guest'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"enrolplugin",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'invaliddata'",
",",
"'error'",
")",
";",
"}",
"self",
"::",
"validate_context",
"(",
"context_system",
"::",
"instance",
"(",
")",
")",
";",
"$",
"enrolinstance",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'enrol'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"params",
"[",
"'instanceid'",
"]",
")",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"$",
"course",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'course'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"enrolinstance",
"->",
"courseid",
")",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"if",
"(",
"!",
"core_course_category",
"::",
"can_view_course_info",
"(",
"$",
"course",
")",
"&&",
"!",
"can_access_course",
"(",
"$",
"course",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'coursehidden'",
")",
";",
"}",
"$",
"instanceinfo",
"=",
"$",
"enrolplugin",
"->",
"get_enrol_info",
"(",
"$",
"enrolinstance",
")",
";",
"// Specific instance information.",
"$",
"instanceinfo",
"->",
"passwordrequired",
"=",
"$",
"instanceinfo",
"->",
"requiredparam",
"->",
"passwordrequired",
";",
"unset",
"(",
"$",
"instanceinfo",
"->",
"requiredparam",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"result",
"[",
"'instanceinfo'",
"]",
"=",
"$",
"instanceinfo",
";",
"$",
"result",
"[",
"'warnings'",
"]",
"=",
"$",
"warnings",
";",
"return",
"$",
"result",
";",
"}"
] |
Return guest enrolment instance information.
@param int $instanceid instance id of guest enrolment plugin.
@return array warnings and instance information.
@since Moodle 3.1
|
[
"Return",
"guest",
"enrolment",
"instance",
"information",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/guest/classes/external.php#L62-L92
|
218,530
|
moodle/moodle
|
cache/stores/memcached/lib.php
|
cachestore_memcached.is_connection_ready
|
public function is_connection_ready() {
if (!@$this->connection->set("ping", 'ping', 1)) {
// Test the connection to the server.
return false;
}
if ($this->isshared) {
// There is a bug in libmemcached which means that it is not possible to purge the cache in a shared cache
// configuration.
// This issue currently affects:
// - memcached 1.4.23+ with php-memcached <= 2.2.0
// The following combinations are not affected:
// - memcached <= 1.4.22 with any version of php-memcached
// - any version of memcached with php-memcached >= 3.0.1
// This check is cheapest as it does not involve connecting to the server at all.
$safecombination = false;
$extension = new ReflectionExtension('memcached');
if ((version_compare($extension->getVersion(), '3.0.1') >= 0)) {
// This is php-memcached version >= 3.0.1 which is a safe combination.
$safecombination = true;
}
if (!$safecombination) {
$allsafe = true;
foreach ($this->connection->getVersion() as $version) {
$allsafe = $allsafe && (version_compare($version, '1.4.22') <= 0);
}
// All memcached servers connected are version <= 1.4.22 which is a safe combination.
$safecombination = $allsafe;
}
if (!$safecombination) {
// This is memcached 1.4.23+ and php-memcached < 3.0.1.
// The issue may have been resolved in a subsequent update to any of the three libraries.
// The only way to safely determine if the combination is safe is to call getAllKeys.
// A safe combination will return an array, whilst an affected combination will return false.
// This is the most expensive check.
if (!is_array($this->connection->getAllKeys())) {
return false;
}
}
}
return true;
}
|
php
|
public function is_connection_ready() {
if (!@$this->connection->set("ping", 'ping', 1)) {
// Test the connection to the server.
return false;
}
if ($this->isshared) {
// There is a bug in libmemcached which means that it is not possible to purge the cache in a shared cache
// configuration.
// This issue currently affects:
// - memcached 1.4.23+ with php-memcached <= 2.2.0
// The following combinations are not affected:
// - memcached <= 1.4.22 with any version of php-memcached
// - any version of memcached with php-memcached >= 3.0.1
// This check is cheapest as it does not involve connecting to the server at all.
$safecombination = false;
$extension = new ReflectionExtension('memcached');
if ((version_compare($extension->getVersion(), '3.0.1') >= 0)) {
// This is php-memcached version >= 3.0.1 which is a safe combination.
$safecombination = true;
}
if (!$safecombination) {
$allsafe = true;
foreach ($this->connection->getVersion() as $version) {
$allsafe = $allsafe && (version_compare($version, '1.4.22') <= 0);
}
// All memcached servers connected are version <= 1.4.22 which is a safe combination.
$safecombination = $allsafe;
}
if (!$safecombination) {
// This is memcached 1.4.23+ and php-memcached < 3.0.1.
// The issue may have been resolved in a subsequent update to any of the three libraries.
// The only way to safely determine if the combination is safe is to call getAllKeys.
// A safe combination will return an array, whilst an affected combination will return false.
// This is the most expensive check.
if (!is_array($this->connection->getAllKeys())) {
return false;
}
}
}
return true;
}
|
[
"public",
"function",
"is_connection_ready",
"(",
")",
"{",
"if",
"(",
"!",
"@",
"$",
"this",
"->",
"connection",
"->",
"set",
"(",
"\"ping\"",
",",
"'ping'",
",",
"1",
")",
")",
"{",
"// Test the connection to the server.",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isshared",
")",
"{",
"// There is a bug in libmemcached which means that it is not possible to purge the cache in a shared cache",
"// configuration.",
"// This issue currently affects:",
"// - memcached 1.4.23+ with php-memcached <= 2.2.0",
"// The following combinations are not affected:",
"// - memcached <= 1.4.22 with any version of php-memcached",
"// - any version of memcached with php-memcached >= 3.0.1",
"// This check is cheapest as it does not involve connecting to the server at all.",
"$",
"safecombination",
"=",
"false",
";",
"$",
"extension",
"=",
"new",
"ReflectionExtension",
"(",
"'memcached'",
")",
";",
"if",
"(",
"(",
"version_compare",
"(",
"$",
"extension",
"->",
"getVersion",
"(",
")",
",",
"'3.0.1'",
")",
">=",
"0",
")",
")",
"{",
"// This is php-memcached version >= 3.0.1 which is a safe combination.",
"$",
"safecombination",
"=",
"true",
";",
"}",
"if",
"(",
"!",
"$",
"safecombination",
")",
"{",
"$",
"allsafe",
"=",
"true",
";",
"foreach",
"(",
"$",
"this",
"->",
"connection",
"->",
"getVersion",
"(",
")",
"as",
"$",
"version",
")",
"{",
"$",
"allsafe",
"=",
"$",
"allsafe",
"&&",
"(",
"version_compare",
"(",
"$",
"version",
",",
"'1.4.22'",
")",
"<=",
"0",
")",
";",
"}",
"// All memcached servers connected are version <= 1.4.22 which is a safe combination.",
"$",
"safecombination",
"=",
"$",
"allsafe",
";",
"}",
"if",
"(",
"!",
"$",
"safecombination",
")",
"{",
"// This is memcached 1.4.23+ and php-memcached < 3.0.1.",
"// The issue may have been resolved in a subsequent update to any of the three libraries.",
"// The only way to safely determine if the combination is safe is to call getAllKeys.",
"// A safe combination will return an array, whilst an affected combination will return false.",
"// This is the most expensive check.",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"connection",
"->",
"getAllKeys",
"(",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] |
Confirm whether the connection is ready and usable.
@return boolean
|
[
"Confirm",
"whether",
"the",
"connection",
"is",
"ready",
"and",
"usable",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/memcached/lib.php#L240-L286
|
218,531
|
moodle/moodle
|
cache/stores/memcached/lib.php
|
cachestore_memcached.delete_many_connection
|
protected function delete_many_connection(Memcached $connection, array $keys) {
$count = 0;
if ($this->candeletemulti) {
// We can use deleteMulti, this is a bit faster yay!
$result = $connection->deleteMulti($keys);
foreach ($result as $key => $outcome) {
if ($outcome === true) {
$count++;
}
}
return $count;
}
// They are running an older version of the php memcached extension.
foreach ($keys as $key) {
if ($connection->delete($key)) {
$count++;
}
}
return $count;
}
|
php
|
protected function delete_many_connection(Memcached $connection, array $keys) {
$count = 0;
if ($this->candeletemulti) {
// We can use deleteMulti, this is a bit faster yay!
$result = $connection->deleteMulti($keys);
foreach ($result as $key => $outcome) {
if ($outcome === true) {
$count++;
}
}
return $count;
}
// They are running an older version of the php memcached extension.
foreach ($keys as $key) {
if ($connection->delete($key)) {
$count++;
}
}
return $count;
}
|
[
"protected",
"function",
"delete_many_connection",
"(",
"Memcached",
"$",
"connection",
",",
"array",
"$",
"keys",
")",
"{",
"$",
"count",
"=",
"0",
";",
"if",
"(",
"$",
"this",
"->",
"candeletemulti",
")",
"{",
"// We can use deleteMulti, this is a bit faster yay!",
"$",
"result",
"=",
"$",
"connection",
"->",
"deleteMulti",
"(",
"$",
"keys",
")",
";",
"foreach",
"(",
"$",
"result",
"as",
"$",
"key",
"=>",
"$",
"outcome",
")",
"{",
"if",
"(",
"$",
"outcome",
"===",
"true",
")",
"{",
"$",
"count",
"++",
";",
"}",
"}",
"return",
"$",
"count",
";",
"}",
"// They are running an older version of the php memcached extension.",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"connection",
"->",
"delete",
"(",
"$",
"key",
")",
")",
"{",
"$",
"count",
"++",
";",
"}",
"}",
"return",
"$",
"count",
";",
"}"
] |
Deletes several keys from the cache in a single action for a specific connection.
@param Memcached $connection The connection to work on.
@param array $keys The keys to delete
@return int The number of items successfully deleted.
|
[
"Deletes",
"several",
"keys",
"from",
"the",
"cache",
"in",
"a",
"single",
"action",
"for",
"a",
"specific",
"connection",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/memcached/lib.php#L498-L518
|
218,532
|
moodle/moodle
|
cache/stores/memcached/lib.php
|
cachestore_memcached.get_prefixed_keys
|
protected static function get_prefixed_keys(Memcached $connection, $prefix) {
$connkeys = $connection->getAllKeys();
if (empty($connkeys)) {
return array();
}
$keys = array();
$start = strlen($prefix);
foreach ($connkeys as $key) {
if (strpos($key, $prefix) === 0) {
$keys[] = substr($key, $start);
}
}
return $keys;
}
|
php
|
protected static function get_prefixed_keys(Memcached $connection, $prefix) {
$connkeys = $connection->getAllKeys();
if (empty($connkeys)) {
return array();
}
$keys = array();
$start = strlen($prefix);
foreach ($connkeys as $key) {
if (strpos($key, $prefix) === 0) {
$keys[] = substr($key, $start);
}
}
return $keys;
}
|
[
"protected",
"static",
"function",
"get_prefixed_keys",
"(",
"Memcached",
"$",
"connection",
",",
"$",
"prefix",
")",
"{",
"$",
"connkeys",
"=",
"$",
"connection",
"->",
"getAllKeys",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"connkeys",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"keys",
"=",
"array",
"(",
")",
";",
"$",
"start",
"=",
"strlen",
"(",
"$",
"prefix",
")",
";",
"foreach",
"(",
"$",
"connkeys",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"key",
",",
"$",
"prefix",
")",
"===",
"0",
")",
"{",
"$",
"keys",
"[",
"]",
"=",
"substr",
"(",
"$",
"key",
",",
"$",
"start",
")",
";",
"}",
"}",
"return",
"$",
"keys",
";",
"}"
] |
Returns all of the keys in the given connection that belong to this cache store instance.
Requires php memcached extension version 2.0.0 or greater.
@param Memcached $connection
@param string $prefix
@return array
|
[
"Returns",
"all",
"of",
"the",
"keys",
"in",
"the",
"given",
"connection",
"that",
"belong",
"to",
"this",
"cache",
"store",
"instance",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/memcached/lib.php#L562-L576
|
218,533
|
moodle/moodle
|
cache/stores/memcached/lib.php
|
cachestore_memcached.config_get_hash_options
|
public static function config_get_hash_options() {
$options = array(
Memcached::HASH_DEFAULT => get_string('hash_default', 'cachestore_memcached'),
Memcached::HASH_MD5 => get_string('hash_md5', 'cachestore_memcached'),
Memcached::HASH_CRC => get_string('hash_crc', 'cachestore_memcached'),
Memcached::HASH_FNV1_64 => get_string('hash_fnv1_64', 'cachestore_memcached'),
Memcached::HASH_FNV1A_64 => get_string('hash_fnv1a_64', 'cachestore_memcached'),
Memcached::HASH_FNV1_32 => get_string('hash_fnv1_32', 'cachestore_memcached'),
Memcached::HASH_FNV1A_32 => get_string('hash_fnv1a_32', 'cachestore_memcached'),
Memcached::HASH_HSIEH => get_string('hash_hsieh', 'cachestore_memcached'),
Memcached::HASH_MURMUR => get_string('hash_murmur', 'cachestore_memcached'),
);
return $options;
}
|
php
|
public static function config_get_hash_options() {
$options = array(
Memcached::HASH_DEFAULT => get_string('hash_default', 'cachestore_memcached'),
Memcached::HASH_MD5 => get_string('hash_md5', 'cachestore_memcached'),
Memcached::HASH_CRC => get_string('hash_crc', 'cachestore_memcached'),
Memcached::HASH_FNV1_64 => get_string('hash_fnv1_64', 'cachestore_memcached'),
Memcached::HASH_FNV1A_64 => get_string('hash_fnv1a_64', 'cachestore_memcached'),
Memcached::HASH_FNV1_32 => get_string('hash_fnv1_32', 'cachestore_memcached'),
Memcached::HASH_FNV1A_32 => get_string('hash_fnv1a_32', 'cachestore_memcached'),
Memcached::HASH_HSIEH => get_string('hash_hsieh', 'cachestore_memcached'),
Memcached::HASH_MURMUR => get_string('hash_murmur', 'cachestore_memcached'),
);
return $options;
}
|
[
"public",
"static",
"function",
"config_get_hash_options",
"(",
")",
"{",
"$",
"options",
"=",
"array",
"(",
"Memcached",
"::",
"HASH_DEFAULT",
"=>",
"get_string",
"(",
"'hash_default'",
",",
"'cachestore_memcached'",
")",
",",
"Memcached",
"::",
"HASH_MD5",
"=>",
"get_string",
"(",
"'hash_md5'",
",",
"'cachestore_memcached'",
")",
",",
"Memcached",
"::",
"HASH_CRC",
"=>",
"get_string",
"(",
"'hash_crc'",
",",
"'cachestore_memcached'",
")",
",",
"Memcached",
"::",
"HASH_FNV1_64",
"=>",
"get_string",
"(",
"'hash_fnv1_64'",
",",
"'cachestore_memcached'",
")",
",",
"Memcached",
"::",
"HASH_FNV1A_64",
"=>",
"get_string",
"(",
"'hash_fnv1a_64'",
",",
"'cachestore_memcached'",
")",
",",
"Memcached",
"::",
"HASH_FNV1_32",
"=>",
"get_string",
"(",
"'hash_fnv1_32'",
",",
"'cachestore_memcached'",
")",
",",
"Memcached",
"::",
"HASH_FNV1A_32",
"=>",
"get_string",
"(",
"'hash_fnv1a_32'",
",",
"'cachestore_memcached'",
")",
",",
"Memcached",
"::",
"HASH_HSIEH",
"=>",
"get_string",
"(",
"'hash_hsieh'",
",",
"'cachestore_memcached'",
")",
",",
"Memcached",
"::",
"HASH_MURMUR",
"=>",
"get_string",
"(",
"'hash_murmur'",
",",
"'cachestore_memcached'",
")",
",",
")",
";",
"return",
"$",
"options",
";",
"}"
] |
Gets an array of hash options available during configuration.
@return array
|
[
"Gets",
"an",
"array",
"of",
"hash",
"options",
"available",
"during",
"configuration",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/memcached/lib.php#L599-L612
|
218,534
|
moodle/moodle
|
cache/stores/memcached/lib.php
|
cachestore_memcached.get_warnings
|
public function get_warnings() {
global $CFG;
$warnings = array();
if (isset($CFG->session_memcached_save_path) && count($this->servers)) {
$bits = explode(':', $CFG->session_memcached_save_path, 3);
$host = array_shift($bits);
$port = (count($bits)) ? array_shift($bits) : '11211';
foreach ($this->servers as $server) {
if ((string)$server[0] === $host && (string)$server[1] === $port) {
$warnings[] = get_string('sessionhandlerconflict', 'cachestore_memcached', $this->my_name());
break;
}
}
}
return $warnings;
}
|
php
|
public function get_warnings() {
global $CFG;
$warnings = array();
if (isset($CFG->session_memcached_save_path) && count($this->servers)) {
$bits = explode(':', $CFG->session_memcached_save_path, 3);
$host = array_shift($bits);
$port = (count($bits)) ? array_shift($bits) : '11211';
foreach ($this->servers as $server) {
if ((string)$server[0] === $host && (string)$server[1] === $port) {
$warnings[] = get_string('sessionhandlerconflict', 'cachestore_memcached', $this->my_name());
break;
}
}
}
return $warnings;
}
|
[
"public",
"function",
"get_warnings",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"warnings",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"CFG",
"->",
"session_memcached_save_path",
")",
"&&",
"count",
"(",
"$",
"this",
"->",
"servers",
")",
")",
"{",
"$",
"bits",
"=",
"explode",
"(",
"':'",
",",
"$",
"CFG",
"->",
"session_memcached_save_path",
",",
"3",
")",
";",
"$",
"host",
"=",
"array_shift",
"(",
"$",
"bits",
")",
";",
"$",
"port",
"=",
"(",
"count",
"(",
"$",
"bits",
")",
")",
"?",
"array_shift",
"(",
"$",
"bits",
")",
":",
"'11211'",
";",
"foreach",
"(",
"$",
"this",
"->",
"servers",
"as",
"$",
"server",
")",
"{",
"if",
"(",
"(",
"string",
")",
"$",
"server",
"[",
"0",
"]",
"===",
"$",
"host",
"&&",
"(",
"string",
")",
"$",
"server",
"[",
"1",
"]",
"===",
"$",
"port",
")",
"{",
"$",
"warnings",
"[",
"]",
"=",
"get_string",
"(",
"'sessionhandlerconflict'",
",",
"'cachestore_memcached'",
",",
"$",
"this",
"->",
"my_name",
"(",
")",
")",
";",
"break",
";",
"}",
"}",
"}",
"return",
"$",
"warnings",
";",
"}"
] |
Used to notify of configuration conflicts.
The warnings returned here will be displayed on the cache configuration screen.
@return string[] Returns an array of warnings (strings)
|
[
"Used",
"to",
"notify",
"of",
"configuration",
"conflicts",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/memcached/lib.php#L824-L840
|
218,535
|
moodle/moodle
|
lib/filelib.php
|
curl.resetopt
|
public function resetopt() {
$this->options = array();
$this->options['CURLOPT_USERAGENT'] = 'MoodleBot/1.0';
// True to include the header in the output
$this->options['CURLOPT_HEADER'] = 0;
// True to Exclude the body from the output
$this->options['CURLOPT_NOBODY'] = 0;
// Redirect ny default.
$this->options['CURLOPT_FOLLOWLOCATION'] = 1;
$this->options['CURLOPT_MAXREDIRS'] = 10;
$this->options['CURLOPT_ENCODING'] = '';
// TRUE to return the transfer as a string of the return
// value of curl_exec() instead of outputting it out directly.
$this->options['CURLOPT_RETURNTRANSFER'] = 1;
$this->options['CURLOPT_SSL_VERIFYPEER'] = 0;
$this->options['CURLOPT_SSL_VERIFYHOST'] = 2;
$this->options['CURLOPT_CONNECTTIMEOUT'] = 30;
if ($cacert = self::get_cacert()) {
$this->options['CURLOPT_CAINFO'] = $cacert;
}
}
|
php
|
public function resetopt() {
$this->options = array();
$this->options['CURLOPT_USERAGENT'] = 'MoodleBot/1.0';
// True to include the header in the output
$this->options['CURLOPT_HEADER'] = 0;
// True to Exclude the body from the output
$this->options['CURLOPT_NOBODY'] = 0;
// Redirect ny default.
$this->options['CURLOPT_FOLLOWLOCATION'] = 1;
$this->options['CURLOPT_MAXREDIRS'] = 10;
$this->options['CURLOPT_ENCODING'] = '';
// TRUE to return the transfer as a string of the return
// value of curl_exec() instead of outputting it out directly.
$this->options['CURLOPT_RETURNTRANSFER'] = 1;
$this->options['CURLOPT_SSL_VERIFYPEER'] = 0;
$this->options['CURLOPT_SSL_VERIFYHOST'] = 2;
$this->options['CURLOPT_CONNECTTIMEOUT'] = 30;
if ($cacert = self::get_cacert()) {
$this->options['CURLOPT_CAINFO'] = $cacert;
}
}
|
[
"public",
"function",
"resetopt",
"(",
")",
"{",
"$",
"this",
"->",
"options",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"options",
"[",
"'CURLOPT_USERAGENT'",
"]",
"=",
"'MoodleBot/1.0'",
";",
"// True to include the header in the output",
"$",
"this",
"->",
"options",
"[",
"'CURLOPT_HEADER'",
"]",
"=",
"0",
";",
"// True to Exclude the body from the output",
"$",
"this",
"->",
"options",
"[",
"'CURLOPT_NOBODY'",
"]",
"=",
"0",
";",
"// Redirect ny default.",
"$",
"this",
"->",
"options",
"[",
"'CURLOPT_FOLLOWLOCATION'",
"]",
"=",
"1",
";",
"$",
"this",
"->",
"options",
"[",
"'CURLOPT_MAXREDIRS'",
"]",
"=",
"10",
";",
"$",
"this",
"->",
"options",
"[",
"'CURLOPT_ENCODING'",
"]",
"=",
"''",
";",
"// TRUE to return the transfer as a string of the return",
"// value of curl_exec() instead of outputting it out directly.",
"$",
"this",
"->",
"options",
"[",
"'CURLOPT_RETURNTRANSFER'",
"]",
"=",
"1",
";",
"$",
"this",
"->",
"options",
"[",
"'CURLOPT_SSL_VERIFYPEER'",
"]",
"=",
"0",
";",
"$",
"this",
"->",
"options",
"[",
"'CURLOPT_SSL_VERIFYHOST'",
"]",
"=",
"2",
";",
"$",
"this",
"->",
"options",
"[",
"'CURLOPT_CONNECTTIMEOUT'",
"]",
"=",
"30",
";",
"if",
"(",
"$",
"cacert",
"=",
"self",
"::",
"get_cacert",
"(",
")",
")",
"{",
"$",
"this",
"->",
"options",
"[",
"'CURLOPT_CAINFO'",
"]",
"=",
"$",
"cacert",
";",
"}",
"}"
] |
Resets the CURL options that have already been set
|
[
"Resets",
"the",
"CURL",
"options",
"that",
"have",
"already",
"been",
"set"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filelib.php#L3103-L3124
|
218,536
|
moodle/moodle
|
lib/filelib.php
|
curl.get_cacert
|
public static function get_cacert() {
global $CFG;
// Bundle in dataroot always wins.
if (is_readable("$CFG->dataroot/moodleorgca.crt")) {
return realpath("$CFG->dataroot/moodleorgca.crt");
}
// Next comes the default from php.ini
$cacert = ini_get('curl.cainfo');
if (!empty($cacert) and is_readable($cacert)) {
return realpath($cacert);
}
// Windows PHP does not have any certs, we need to use something.
if ($CFG->ostype === 'WINDOWS') {
if (is_readable("$CFG->libdir/cacert.pem")) {
return realpath("$CFG->libdir/cacert.pem");
}
}
// Use default, this should work fine on all properly configured *nix systems.
return null;
}
|
php
|
public static function get_cacert() {
global $CFG;
// Bundle in dataroot always wins.
if (is_readable("$CFG->dataroot/moodleorgca.crt")) {
return realpath("$CFG->dataroot/moodleorgca.crt");
}
// Next comes the default from php.ini
$cacert = ini_get('curl.cainfo');
if (!empty($cacert) and is_readable($cacert)) {
return realpath($cacert);
}
// Windows PHP does not have any certs, we need to use something.
if ($CFG->ostype === 'WINDOWS') {
if (is_readable("$CFG->libdir/cacert.pem")) {
return realpath("$CFG->libdir/cacert.pem");
}
}
// Use default, this should work fine on all properly configured *nix systems.
return null;
}
|
[
"public",
"static",
"function",
"get_cacert",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"// Bundle in dataroot always wins.",
"if",
"(",
"is_readable",
"(",
"\"$CFG->dataroot/moodleorgca.crt\"",
")",
")",
"{",
"return",
"realpath",
"(",
"\"$CFG->dataroot/moodleorgca.crt\"",
")",
";",
"}",
"// Next comes the default from php.ini",
"$",
"cacert",
"=",
"ini_get",
"(",
"'curl.cainfo'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"cacert",
")",
"and",
"is_readable",
"(",
"$",
"cacert",
")",
")",
"{",
"return",
"realpath",
"(",
"$",
"cacert",
")",
";",
"}",
"// Windows PHP does not have any certs, we need to use something.",
"if",
"(",
"$",
"CFG",
"->",
"ostype",
"===",
"'WINDOWS'",
")",
"{",
"if",
"(",
"is_readable",
"(",
"\"$CFG->libdir/cacert.pem\"",
")",
")",
"{",
"return",
"realpath",
"(",
"\"$CFG->libdir/cacert.pem\"",
")",
";",
"}",
"}",
"// Use default, this should work fine on all properly configured *nix systems.",
"return",
"null",
";",
"}"
] |
Get the location of ca certificates.
@return string absolute file path or empty if default used
|
[
"Get",
"the",
"location",
"of",
"ca",
"certificates",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filelib.php#L3130-L3153
|
218,537
|
moodle/moodle
|
lib/filelib.php
|
curl.setHeader
|
public function setHeader($header) {
if (is_array($header)) {
foreach ($header as $v) {
$this->setHeader($v);
}
} else {
// Remove newlines, they are not allowed in headers.
$newvalue = preg_replace('/[\r\n]/', '', $header);
if (!in_array($newvalue, $this->header)) {
$this->header[] = $newvalue;
}
}
}
|
php
|
public function setHeader($header) {
if (is_array($header)) {
foreach ($header as $v) {
$this->setHeader($v);
}
} else {
// Remove newlines, they are not allowed in headers.
$newvalue = preg_replace('/[\r\n]/', '', $header);
if (!in_array($newvalue, $this->header)) {
$this->header[] = $newvalue;
}
}
}
|
[
"public",
"function",
"setHeader",
"(",
"$",
"header",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"header",
")",
")",
"{",
"foreach",
"(",
"$",
"header",
"as",
"$",
"v",
")",
"{",
"$",
"this",
"->",
"setHeader",
"(",
"$",
"v",
")",
";",
"}",
"}",
"else",
"{",
"// Remove newlines, they are not allowed in headers.",
"$",
"newvalue",
"=",
"preg_replace",
"(",
"'/[\\r\\n]/'",
",",
"''",
",",
"$",
"header",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"newvalue",
",",
"$",
"this",
"->",
"header",
")",
")",
"{",
"$",
"this",
"->",
"header",
"[",
"]",
"=",
"$",
"newvalue",
";",
"}",
"}",
"}"
] |
Set HTTP Request Header
@param array $header
|
[
"Set",
"HTTP",
"Request",
"Header"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filelib.php#L3223-L3235
|
218,538
|
moodle/moodle
|
lib/filelib.php
|
curl.set_security
|
public function set_security($securityobject) {
if ($securityobject instanceof \core\files\curl_security_helper) {
$this->securityhelper = $securityobject;
return true;
}
return false;
}
|
php
|
public function set_security($securityobject) {
if ($securityobject instanceof \core\files\curl_security_helper) {
$this->securityhelper = $securityobject;
return true;
}
return false;
}
|
[
"public",
"function",
"set_security",
"(",
"$",
"securityobject",
")",
"{",
"if",
"(",
"$",
"securityobject",
"instanceof",
"\\",
"core",
"\\",
"files",
"\\",
"curl_security_helper",
")",
"{",
"$",
"this",
"->",
"securityhelper",
"=",
"$",
"securityobject",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Sets the curl security helper.
@param \core\files\curl_security_helper $securityobject instance/subclass of the base curl_security_helper class.
@return bool true if the security helper could be set, false otherwise.
|
[
"Sets",
"the",
"curl",
"security",
"helper",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filelib.php#L3469-L3475
|
218,539
|
moodle/moodle
|
lib/filelib.php
|
curl.multi
|
protected function multi($requests, $options = array()) {
$count = count($requests);
$handles = array();
$results = array();
$main = curl_multi_init();
for ($i = 0; $i < $count; $i++) {
if (!empty($requests[$i]['filepath']) and empty($requests[$i]['file'])) {
// open file
$requests[$i]['file'] = fopen($requests[$i]['filepath'], 'w');
$requests[$i]['auto-handle'] = true;
}
foreach($requests[$i] as $n=>$v) {
$options[$n] = $v;
}
$handles[$i] = curl_init($requests[$i]['url']);
$this->apply_opt($handles[$i], $options);
curl_multi_add_handle($main, $handles[$i]);
}
$running = 0;
do {
curl_multi_exec($main, $running);
} while($running > 0);
for ($i = 0; $i < $count; $i++) {
if (!empty($options['CURLOPT_RETURNTRANSFER'])) {
$results[] = true;
} else {
$results[] = curl_multi_getcontent($handles[$i]);
}
curl_multi_remove_handle($main, $handles[$i]);
}
curl_multi_close($main);
for ($i = 0; $i < $count; $i++) {
if (!empty($requests[$i]['filepath']) and !empty($requests[$i]['auto-handle'])) {
// close file handler if file is opened in this function
fclose($requests[$i]['file']);
}
}
return $results;
}
|
php
|
protected function multi($requests, $options = array()) {
$count = count($requests);
$handles = array();
$results = array();
$main = curl_multi_init();
for ($i = 0; $i < $count; $i++) {
if (!empty($requests[$i]['filepath']) and empty($requests[$i]['file'])) {
// open file
$requests[$i]['file'] = fopen($requests[$i]['filepath'], 'w');
$requests[$i]['auto-handle'] = true;
}
foreach($requests[$i] as $n=>$v) {
$options[$n] = $v;
}
$handles[$i] = curl_init($requests[$i]['url']);
$this->apply_opt($handles[$i], $options);
curl_multi_add_handle($main, $handles[$i]);
}
$running = 0;
do {
curl_multi_exec($main, $running);
} while($running > 0);
for ($i = 0; $i < $count; $i++) {
if (!empty($options['CURLOPT_RETURNTRANSFER'])) {
$results[] = true;
} else {
$results[] = curl_multi_getcontent($handles[$i]);
}
curl_multi_remove_handle($main, $handles[$i]);
}
curl_multi_close($main);
for ($i = 0; $i < $count; $i++) {
if (!empty($requests[$i]['filepath']) and !empty($requests[$i]['auto-handle'])) {
// close file handler if file is opened in this function
fclose($requests[$i]['file']);
}
}
return $results;
}
|
[
"protected",
"function",
"multi",
"(",
"$",
"requests",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"count",
"=",
"count",
"(",
"$",
"requests",
")",
";",
"$",
"handles",
"=",
"array",
"(",
")",
";",
"$",
"results",
"=",
"array",
"(",
")",
";",
"$",
"main",
"=",
"curl_multi_init",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"count",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"requests",
"[",
"$",
"i",
"]",
"[",
"'filepath'",
"]",
")",
"and",
"empty",
"(",
"$",
"requests",
"[",
"$",
"i",
"]",
"[",
"'file'",
"]",
")",
")",
"{",
"// open file",
"$",
"requests",
"[",
"$",
"i",
"]",
"[",
"'file'",
"]",
"=",
"fopen",
"(",
"$",
"requests",
"[",
"$",
"i",
"]",
"[",
"'filepath'",
"]",
",",
"'w'",
")",
";",
"$",
"requests",
"[",
"$",
"i",
"]",
"[",
"'auto-handle'",
"]",
"=",
"true",
";",
"}",
"foreach",
"(",
"$",
"requests",
"[",
"$",
"i",
"]",
"as",
"$",
"n",
"=>",
"$",
"v",
")",
"{",
"$",
"options",
"[",
"$",
"n",
"]",
"=",
"$",
"v",
";",
"}",
"$",
"handles",
"[",
"$",
"i",
"]",
"=",
"curl_init",
"(",
"$",
"requests",
"[",
"$",
"i",
"]",
"[",
"'url'",
"]",
")",
";",
"$",
"this",
"->",
"apply_opt",
"(",
"$",
"handles",
"[",
"$",
"i",
"]",
",",
"$",
"options",
")",
";",
"curl_multi_add_handle",
"(",
"$",
"main",
",",
"$",
"handles",
"[",
"$",
"i",
"]",
")",
";",
"}",
"$",
"running",
"=",
"0",
";",
"do",
"{",
"curl_multi_exec",
"(",
"$",
"main",
",",
"$",
"running",
")",
";",
"}",
"while",
"(",
"$",
"running",
">",
"0",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"count",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'CURLOPT_RETURNTRANSFER'",
"]",
")",
")",
"{",
"$",
"results",
"[",
"]",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"results",
"[",
"]",
"=",
"curl_multi_getcontent",
"(",
"$",
"handles",
"[",
"$",
"i",
"]",
")",
";",
"}",
"curl_multi_remove_handle",
"(",
"$",
"main",
",",
"$",
"handles",
"[",
"$",
"i",
"]",
")",
";",
"}",
"curl_multi_close",
"(",
"$",
"main",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"count",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"requests",
"[",
"$",
"i",
"]",
"[",
"'filepath'",
"]",
")",
"and",
"!",
"empty",
"(",
"$",
"requests",
"[",
"$",
"i",
"]",
"[",
"'auto-handle'",
"]",
")",
")",
"{",
"// close file handler if file is opened in this function",
"fclose",
"(",
"$",
"requests",
"[",
"$",
"i",
"]",
"[",
"'file'",
"]",
")",
";",
"}",
"}",
"return",
"$",
"results",
";",
"}"
] |
Multi HTTP Requests
This function could run multi-requests in parallel.
@param array $requests An array of files to request
@param array $options An array of options to set
@return array An array of results
|
[
"Multi",
"HTTP",
"Requests",
"This",
"function",
"could",
"run",
"multi",
"-",
"requests",
"in",
"parallel",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filelib.php#L3485-L3524
|
218,540
|
moodle/moodle
|
lib/filelib.php
|
curl.reset_request_state_vars
|
protected function reset_request_state_vars() {
$this->info = array();
$this->error = '';
$this->errno = 0;
$this->response = array();
$this->rawresponse = array();
$this->responsefinished = false;
}
|
php
|
protected function reset_request_state_vars() {
$this->info = array();
$this->error = '';
$this->errno = 0;
$this->response = array();
$this->rawresponse = array();
$this->responsefinished = false;
}
|
[
"protected",
"function",
"reset_request_state_vars",
"(",
")",
"{",
"$",
"this",
"->",
"info",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"error",
"=",
"''",
";",
"$",
"this",
"->",
"errno",
"=",
"0",
";",
"$",
"this",
"->",
"response",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"rawresponse",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"responsefinished",
"=",
"false",
";",
"}"
] |
Helper function to reset the request state vars.
@return void.
|
[
"Helper",
"function",
"to",
"reset",
"the",
"request",
"state",
"vars",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filelib.php#L3531-L3538
|
218,541
|
moodle/moodle
|
lib/filelib.php
|
curl.download_one
|
public function download_one($url, $params, $options = array()) {
$options['CURLOPT_HTTPGET'] = 1;
if (!empty($params)) {
$url .= (stripos($url, '?') !== false) ? '&' : '?';
$url .= http_build_query($params, '', '&');
}
if (!empty($options['filepath']) && empty($options['file'])) {
// open file
if (!($options['file'] = fopen($options['filepath'], 'w'))) {
$this->errno = 100;
return get_string('cannotwritefile', 'error', $options['filepath']);
}
$filepath = $options['filepath'];
}
unset($options['filepath']);
$result = $this->request($url, $options);
if (isset($filepath)) {
fclose($options['file']);
if ($result !== true) {
unlink($filepath);
}
}
return $result;
}
|
php
|
public function download_one($url, $params, $options = array()) {
$options['CURLOPT_HTTPGET'] = 1;
if (!empty($params)) {
$url .= (stripos($url, '?') !== false) ? '&' : '?';
$url .= http_build_query($params, '', '&');
}
if (!empty($options['filepath']) && empty($options['file'])) {
// open file
if (!($options['file'] = fopen($options['filepath'], 'w'))) {
$this->errno = 100;
return get_string('cannotwritefile', 'error', $options['filepath']);
}
$filepath = $options['filepath'];
}
unset($options['filepath']);
$result = $this->request($url, $options);
if (isset($filepath)) {
fclose($options['file']);
if ($result !== true) {
unlink($filepath);
}
}
return $result;
}
|
[
"public",
"function",
"download_one",
"(",
"$",
"url",
",",
"$",
"params",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"options",
"[",
"'CURLOPT_HTTPGET'",
"]",
"=",
"1",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"params",
")",
")",
"{",
"$",
"url",
".=",
"(",
"stripos",
"(",
"$",
"url",
",",
"'?'",
")",
"!==",
"false",
")",
"?",
"'&'",
":",
"'?'",
";",
"$",
"url",
".=",
"http_build_query",
"(",
"$",
"params",
",",
"''",
",",
"'&'",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'filepath'",
"]",
")",
"&&",
"empty",
"(",
"$",
"options",
"[",
"'file'",
"]",
")",
")",
"{",
"// open file",
"if",
"(",
"!",
"(",
"$",
"options",
"[",
"'file'",
"]",
"=",
"fopen",
"(",
"$",
"options",
"[",
"'filepath'",
"]",
",",
"'w'",
")",
")",
")",
"{",
"$",
"this",
"->",
"errno",
"=",
"100",
";",
"return",
"get_string",
"(",
"'cannotwritefile'",
",",
"'error'",
",",
"$",
"options",
"[",
"'filepath'",
"]",
")",
";",
"}",
"$",
"filepath",
"=",
"$",
"options",
"[",
"'filepath'",
"]",
";",
"}",
"unset",
"(",
"$",
"options",
"[",
"'filepath'",
"]",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"request",
"(",
"$",
"url",
",",
"$",
"options",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"filepath",
")",
")",
"{",
"fclose",
"(",
"$",
"options",
"[",
"'file'",
"]",
")",
";",
"if",
"(",
"$",
"result",
"!==",
"true",
")",
"{",
"unlink",
"(",
"$",
"filepath",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] |
Downloads one file and writes it to the specified file handler
<code>
$c = new curl();
$file = fopen('savepath', 'w');
$result = $c->download_one('http://localhost/', null,
array('file' => $file, 'timeout' => 5, 'followlocation' => true, 'maxredirs' => 3));
fclose($file);
$download_info = $c->get_info();
if ($result === true) {
// file downloaded successfully
} else {
$error_text = $result;
$error_code = $c->get_errno();
}
</code>
<code>
$c = new curl();
$result = $c->download_one('http://localhost/', null,
array('filepath' => 'savepath', 'timeout' => 5, 'followlocation' => true, 'maxredirs' => 3));
// ... see above, no need to close handle and remove file if unsuccessful
</code>
@param string $url
@param array|null $params key-value pairs to be added to $url as query string
@param array $options request options. Must include either 'file' or 'filepath'
@return bool|string true on success or error string on failure
|
[
"Downloads",
"one",
"file",
"and",
"writes",
"it",
"to",
"the",
"specified",
"file",
"handler"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filelib.php#L3835-L3858
|
218,542
|
moodle/moodle
|
lib/filelib.php
|
curl_cache.cleanup
|
public function cleanup($expire) {
if ($dir = opendir($this->dir)) {
while (false !== ($file = readdir($dir))) {
if(!is_dir($file) && $file != '.' && $file != '..') {
$lasttime = @filemtime($this->dir.$file);
if (time() - $lasttime > $expire) {
@unlink($this->dir.$file);
}
}
}
closedir($dir);
}
}
|
php
|
public function cleanup($expire) {
if ($dir = opendir($this->dir)) {
while (false !== ($file = readdir($dir))) {
if(!is_dir($file) && $file != '.' && $file != '..') {
$lasttime = @filemtime($this->dir.$file);
if (time() - $lasttime > $expire) {
@unlink($this->dir.$file);
}
}
}
closedir($dir);
}
}
|
[
"public",
"function",
"cleanup",
"(",
"$",
"expire",
")",
"{",
"if",
"(",
"$",
"dir",
"=",
"opendir",
"(",
"$",
"this",
"->",
"dir",
")",
")",
"{",
"while",
"(",
"false",
"!==",
"(",
"$",
"file",
"=",
"readdir",
"(",
"$",
"dir",
")",
")",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"file",
")",
"&&",
"$",
"file",
"!=",
"'.'",
"&&",
"$",
"file",
"!=",
"'..'",
")",
"{",
"$",
"lasttime",
"=",
"@",
"filemtime",
"(",
"$",
"this",
"->",
"dir",
".",
"$",
"file",
")",
";",
"if",
"(",
"time",
"(",
")",
"-",
"$",
"lasttime",
">",
"$",
"expire",
")",
"{",
"@",
"unlink",
"(",
"$",
"this",
"->",
"dir",
".",
"$",
"file",
")",
";",
"}",
"}",
"}",
"closedir",
"(",
"$",
"dir",
")",
";",
"}",
"}"
] |
Remove cache files
@param int $expire The number of seconds before expiry
|
[
"Remove",
"cache",
"files"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filelib.php#L4094-L4106
|
218,543
|
moodle/moodle
|
lib/spout/src/Spout/Reader/XLSX/Helper/StyleHelper.php
|
StyleHelper.shouldFormatNumericValueAsDate
|
public function shouldFormatNumericValueAsDate($styleId)
{
$stylesAttributes = $this->getStylesAttributes();
// Default style (0) does not format numeric values as timestamps. Only custom styles do.
// Also if the style ID does not exist in the styles.xml file, format as numeric value.
// Using isset here because it is way faster than array_key_exists...
if ($styleId === self::DEFAULT_STYLE_ID || !isset($stylesAttributes[$styleId])) {
return false;
}
$styleAttributes = $stylesAttributes[$styleId];
return $this->doesStyleIndicateDate($styleAttributes);
}
|
php
|
public function shouldFormatNumericValueAsDate($styleId)
{
$stylesAttributes = $this->getStylesAttributes();
// Default style (0) does not format numeric values as timestamps. Only custom styles do.
// Also if the style ID does not exist in the styles.xml file, format as numeric value.
// Using isset here because it is way faster than array_key_exists...
if ($styleId === self::DEFAULT_STYLE_ID || !isset($stylesAttributes[$styleId])) {
return false;
}
$styleAttributes = $stylesAttributes[$styleId];
return $this->doesStyleIndicateDate($styleAttributes);
}
|
[
"public",
"function",
"shouldFormatNumericValueAsDate",
"(",
"$",
"styleId",
")",
"{",
"$",
"stylesAttributes",
"=",
"$",
"this",
"->",
"getStylesAttributes",
"(",
")",
";",
"// Default style (0) does not format numeric values as timestamps. Only custom styles do.",
"// Also if the style ID does not exist in the styles.xml file, format as numeric value.",
"// Using isset here because it is way faster than array_key_exists...",
"if",
"(",
"$",
"styleId",
"===",
"self",
"::",
"DEFAULT_STYLE_ID",
"||",
"!",
"isset",
"(",
"$",
"stylesAttributes",
"[",
"$",
"styleId",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"styleAttributes",
"=",
"$",
"stylesAttributes",
"[",
"$",
"styleId",
"]",
";",
"return",
"$",
"this",
"->",
"doesStyleIndicateDate",
"(",
"$",
"styleAttributes",
")",
";",
"}"
] |
Returns whether the style with the given ID should consider
numeric values as timestamps and format the cell as a date.
@param int $styleId Zero-based style ID
@return bool Whether the cell with the given cell should display a date instead of a numeric value
|
[
"Returns",
"whether",
"the",
"style",
"with",
"the",
"given",
"ID",
"should",
"consider",
"numeric",
"values",
"as",
"timestamps",
"and",
"format",
"the",
"cell",
"as",
"a",
"date",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Reader/XLSX/Helper/StyleHelper.php#L84-L98
|
218,544
|
moodle/moodle
|
lib/spout/src/Spout/Reader/XLSX/Helper/StyleHelper.php
|
StyleHelper.extractRelevantInfo
|
protected function extractRelevantInfo()
{
$this->customNumberFormats = [];
$this->stylesAttributes = [];
$xmlReader = new XMLReader();
if ($xmlReader->openFileInZip($this->filePath, self::STYLES_XML_FILE_PATH)) {
while ($xmlReader->read()) {
if ($xmlReader->isPositionedOnStartingNode(self::XML_NODE_NUM_FMTS)) {
$this->extractNumberFormats($xmlReader);
} else if ($xmlReader->isPositionedOnStartingNode(self::XML_NODE_CELL_XFS)) {
$this->extractStyleAttributes($xmlReader);
}
}
$xmlReader->close();
}
}
|
php
|
protected function extractRelevantInfo()
{
$this->customNumberFormats = [];
$this->stylesAttributes = [];
$xmlReader = new XMLReader();
if ($xmlReader->openFileInZip($this->filePath, self::STYLES_XML_FILE_PATH)) {
while ($xmlReader->read()) {
if ($xmlReader->isPositionedOnStartingNode(self::XML_NODE_NUM_FMTS)) {
$this->extractNumberFormats($xmlReader);
} else if ($xmlReader->isPositionedOnStartingNode(self::XML_NODE_CELL_XFS)) {
$this->extractStyleAttributes($xmlReader);
}
}
$xmlReader->close();
}
}
|
[
"protected",
"function",
"extractRelevantInfo",
"(",
")",
"{",
"$",
"this",
"->",
"customNumberFormats",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"stylesAttributes",
"=",
"[",
"]",
";",
"$",
"xmlReader",
"=",
"new",
"XMLReader",
"(",
")",
";",
"if",
"(",
"$",
"xmlReader",
"->",
"openFileInZip",
"(",
"$",
"this",
"->",
"filePath",
",",
"self",
"::",
"STYLES_XML_FILE_PATH",
")",
")",
"{",
"while",
"(",
"$",
"xmlReader",
"->",
"read",
"(",
")",
")",
"{",
"if",
"(",
"$",
"xmlReader",
"->",
"isPositionedOnStartingNode",
"(",
"self",
"::",
"XML_NODE_NUM_FMTS",
")",
")",
"{",
"$",
"this",
"->",
"extractNumberFormats",
"(",
"$",
"xmlReader",
")",
";",
"}",
"else",
"if",
"(",
"$",
"xmlReader",
"->",
"isPositionedOnStartingNode",
"(",
"self",
"::",
"XML_NODE_CELL_XFS",
")",
")",
"{",
"$",
"this",
"->",
"extractStyleAttributes",
"(",
"$",
"xmlReader",
")",
";",
"}",
"}",
"$",
"xmlReader",
"->",
"close",
"(",
")",
";",
"}",
"}"
] |
Reads the styles.xml file and extract the relevant information from the file.
@return void
|
[
"Reads",
"the",
"styles",
".",
"xml",
"file",
"and",
"extract",
"the",
"relevant",
"information",
"from",
"the",
"file",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Reader/XLSX/Helper/StyleHelper.php#L105-L124
|
218,545
|
moodle/moodle
|
lib/spout/src/Spout/Reader/XLSX/Helper/StyleHelper.php
|
StyleHelper.extractNumberFormats
|
protected function extractNumberFormats($xmlReader)
{
while ($xmlReader->read()) {
if ($xmlReader->isPositionedOnStartingNode(self::XML_NODE_NUM_FMT)) {
$numFmtId = intval($xmlReader->getAttribute(self::XML_ATTRIBUTE_NUM_FMT_ID));
$formatCode = $xmlReader->getAttribute(self::XML_ATTRIBUTE_FORMAT_CODE);
$this->customNumberFormats[$numFmtId] = $formatCode;
} else if ($xmlReader->isPositionedOnEndingNode(self::XML_NODE_NUM_FMTS)) {
// Once done reading "numFmts" node's children
break;
}
}
}
|
php
|
protected function extractNumberFormats($xmlReader)
{
while ($xmlReader->read()) {
if ($xmlReader->isPositionedOnStartingNode(self::XML_NODE_NUM_FMT)) {
$numFmtId = intval($xmlReader->getAttribute(self::XML_ATTRIBUTE_NUM_FMT_ID));
$formatCode = $xmlReader->getAttribute(self::XML_ATTRIBUTE_FORMAT_CODE);
$this->customNumberFormats[$numFmtId] = $formatCode;
} else if ($xmlReader->isPositionedOnEndingNode(self::XML_NODE_NUM_FMTS)) {
// Once done reading "numFmts" node's children
break;
}
}
}
|
[
"protected",
"function",
"extractNumberFormats",
"(",
"$",
"xmlReader",
")",
"{",
"while",
"(",
"$",
"xmlReader",
"->",
"read",
"(",
")",
")",
"{",
"if",
"(",
"$",
"xmlReader",
"->",
"isPositionedOnStartingNode",
"(",
"self",
"::",
"XML_NODE_NUM_FMT",
")",
")",
"{",
"$",
"numFmtId",
"=",
"intval",
"(",
"$",
"xmlReader",
"->",
"getAttribute",
"(",
"self",
"::",
"XML_ATTRIBUTE_NUM_FMT_ID",
")",
")",
";",
"$",
"formatCode",
"=",
"$",
"xmlReader",
"->",
"getAttribute",
"(",
"self",
"::",
"XML_ATTRIBUTE_FORMAT_CODE",
")",
";",
"$",
"this",
"->",
"customNumberFormats",
"[",
"$",
"numFmtId",
"]",
"=",
"$",
"formatCode",
";",
"}",
"else",
"if",
"(",
"$",
"xmlReader",
"->",
"isPositionedOnEndingNode",
"(",
"self",
"::",
"XML_NODE_NUM_FMTS",
")",
")",
"{",
"// Once done reading \"numFmts\" node's children",
"break",
";",
"}",
"}",
"}"
] |
Extracts number formats from the "numFmt" nodes.
For simplicity, the styles attributes are kept in memory. This is possible thanks
to the reuse of formats. So 1 million cells should not use 1 million formats.
@param \Box\Spout\Reader\Wrapper\XMLReader $xmlReader XML Reader positioned on the "numFmts" node
@return void
|
[
"Extracts",
"number",
"formats",
"from",
"the",
"numFmt",
"nodes",
".",
"For",
"simplicity",
"the",
"styles",
"attributes",
"are",
"kept",
"in",
"memory",
".",
"This",
"is",
"possible",
"thanks",
"to",
"the",
"reuse",
"of",
"formats",
".",
"So",
"1",
"million",
"cells",
"should",
"not",
"use",
"1",
"million",
"formats",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Reader/XLSX/Helper/StyleHelper.php#L134-L146
|
218,546
|
moodle/moodle
|
lib/spout/src/Spout/Reader/XLSX/Helper/StyleHelper.php
|
StyleHelper.extractStyleAttributes
|
protected function extractStyleAttributes($xmlReader)
{
while ($xmlReader->read()) {
if ($xmlReader->isPositionedOnStartingNode(self::XML_NODE_XF)) {
$numFmtId = $xmlReader->getAttribute(self::XML_ATTRIBUTE_NUM_FMT_ID);
$normalizedNumFmtId = ($numFmtId !== null) ? intval($numFmtId) : null;
$applyNumberFormat = $xmlReader->getAttribute(self::XML_ATTRIBUTE_APPLY_NUMBER_FORMAT);
$normalizedApplyNumberFormat = ($applyNumberFormat !== null) ? !!$applyNumberFormat : null;
$this->stylesAttributes[] = [
self::XML_ATTRIBUTE_NUM_FMT_ID => $normalizedNumFmtId,
self::XML_ATTRIBUTE_APPLY_NUMBER_FORMAT => $normalizedApplyNumberFormat,
];
} else if ($xmlReader->isPositionedOnEndingNode(self::XML_NODE_CELL_XFS)) {
// Once done reading "cellXfs" node's children
break;
}
}
}
|
php
|
protected function extractStyleAttributes($xmlReader)
{
while ($xmlReader->read()) {
if ($xmlReader->isPositionedOnStartingNode(self::XML_NODE_XF)) {
$numFmtId = $xmlReader->getAttribute(self::XML_ATTRIBUTE_NUM_FMT_ID);
$normalizedNumFmtId = ($numFmtId !== null) ? intval($numFmtId) : null;
$applyNumberFormat = $xmlReader->getAttribute(self::XML_ATTRIBUTE_APPLY_NUMBER_FORMAT);
$normalizedApplyNumberFormat = ($applyNumberFormat !== null) ? !!$applyNumberFormat : null;
$this->stylesAttributes[] = [
self::XML_ATTRIBUTE_NUM_FMT_ID => $normalizedNumFmtId,
self::XML_ATTRIBUTE_APPLY_NUMBER_FORMAT => $normalizedApplyNumberFormat,
];
} else if ($xmlReader->isPositionedOnEndingNode(self::XML_NODE_CELL_XFS)) {
// Once done reading "cellXfs" node's children
break;
}
}
}
|
[
"protected",
"function",
"extractStyleAttributes",
"(",
"$",
"xmlReader",
")",
"{",
"while",
"(",
"$",
"xmlReader",
"->",
"read",
"(",
")",
")",
"{",
"if",
"(",
"$",
"xmlReader",
"->",
"isPositionedOnStartingNode",
"(",
"self",
"::",
"XML_NODE_XF",
")",
")",
"{",
"$",
"numFmtId",
"=",
"$",
"xmlReader",
"->",
"getAttribute",
"(",
"self",
"::",
"XML_ATTRIBUTE_NUM_FMT_ID",
")",
";",
"$",
"normalizedNumFmtId",
"=",
"(",
"$",
"numFmtId",
"!==",
"null",
")",
"?",
"intval",
"(",
"$",
"numFmtId",
")",
":",
"null",
";",
"$",
"applyNumberFormat",
"=",
"$",
"xmlReader",
"->",
"getAttribute",
"(",
"self",
"::",
"XML_ATTRIBUTE_APPLY_NUMBER_FORMAT",
")",
";",
"$",
"normalizedApplyNumberFormat",
"=",
"(",
"$",
"applyNumberFormat",
"!==",
"null",
")",
"?",
"!",
"!",
"$",
"applyNumberFormat",
":",
"null",
";",
"$",
"this",
"->",
"stylesAttributes",
"[",
"]",
"=",
"[",
"self",
"::",
"XML_ATTRIBUTE_NUM_FMT_ID",
"=>",
"$",
"normalizedNumFmtId",
",",
"self",
"::",
"XML_ATTRIBUTE_APPLY_NUMBER_FORMAT",
"=>",
"$",
"normalizedApplyNumberFormat",
",",
"]",
";",
"}",
"else",
"if",
"(",
"$",
"xmlReader",
"->",
"isPositionedOnEndingNode",
"(",
"self",
"::",
"XML_NODE_CELL_XFS",
")",
")",
"{",
"// Once done reading \"cellXfs\" node's children",
"break",
";",
"}",
"}",
"}"
] |
Extracts style attributes from the "xf" nodes, inside the "cellXfs" section.
For simplicity, the styles attributes are kept in memory. This is possible thanks
to the reuse of styles. So 1 million cells should not use 1 million styles.
@param \Box\Spout\Reader\Wrapper\XMLReader $xmlReader XML Reader positioned on the "cellXfs" node
@return void
|
[
"Extracts",
"style",
"attributes",
"from",
"the",
"xf",
"nodes",
"inside",
"the",
"cellXfs",
"section",
".",
"For",
"simplicity",
"the",
"styles",
"attributes",
"are",
"kept",
"in",
"memory",
".",
"This",
"is",
"possible",
"thanks",
"to",
"the",
"reuse",
"of",
"styles",
".",
"So",
"1",
"million",
"cells",
"should",
"not",
"use",
"1",
"million",
"styles",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Reader/XLSX/Helper/StyleHelper.php#L156-L175
|
218,547
|
moodle/moodle
|
lib/spout/src/Spout/Reader/XLSX/Helper/StyleHelper.php
|
StyleHelper.doesNumFmtIdIndicateDate
|
protected function doesNumFmtIdIndicateDate($numFmtId)
{
if (!isset($this->numFmtIdToIsDateFormatCache[$numFmtId])) {
$formatCode = $this->getFormatCodeForNumFmtId($numFmtId);
$this->numFmtIdToIsDateFormatCache[$numFmtId] = (
$this->isNumFmtIdBuiltInDateFormat($numFmtId) ||
$this->isFormatCodeCustomDateFormat($formatCode)
);
}
return $this->numFmtIdToIsDateFormatCache[$numFmtId];
}
|
php
|
protected function doesNumFmtIdIndicateDate($numFmtId)
{
if (!isset($this->numFmtIdToIsDateFormatCache[$numFmtId])) {
$formatCode = $this->getFormatCodeForNumFmtId($numFmtId);
$this->numFmtIdToIsDateFormatCache[$numFmtId] = (
$this->isNumFmtIdBuiltInDateFormat($numFmtId) ||
$this->isFormatCodeCustomDateFormat($formatCode)
);
}
return $this->numFmtIdToIsDateFormatCache[$numFmtId];
}
|
[
"protected",
"function",
"doesNumFmtIdIndicateDate",
"(",
"$",
"numFmtId",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"numFmtIdToIsDateFormatCache",
"[",
"$",
"numFmtId",
"]",
")",
")",
"{",
"$",
"formatCode",
"=",
"$",
"this",
"->",
"getFormatCodeForNumFmtId",
"(",
"$",
"numFmtId",
")",
";",
"$",
"this",
"->",
"numFmtIdToIsDateFormatCache",
"[",
"$",
"numFmtId",
"]",
"=",
"(",
"$",
"this",
"->",
"isNumFmtIdBuiltInDateFormat",
"(",
"$",
"numFmtId",
")",
"||",
"$",
"this",
"->",
"isFormatCodeCustomDateFormat",
"(",
"$",
"formatCode",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"numFmtIdToIsDateFormatCache",
"[",
"$",
"numFmtId",
"]",
";",
"}"
] |
Returns whether the number format ID indicates that the number is a date.
The result is cached to avoid recomputing the same thing over and over, as
"numFmtId" attributes can be shared between multiple styles.
@param int $numFmtId
@return bool Whether the number format ID indicates that the number is a date
|
[
"Returns",
"whether",
"the",
"number",
"format",
"ID",
"indicates",
"that",
"the",
"number",
"is",
"a",
"date",
".",
"The",
"result",
"is",
"cached",
"to",
"avoid",
"recomputing",
"the",
"same",
"thing",
"over",
"and",
"over",
"as",
"numFmtId",
"attributes",
"can",
"be",
"shared",
"between",
"multiple",
"styles",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Reader/XLSX/Helper/StyleHelper.php#L230-L242
|
218,548
|
moodle/moodle
|
mod/feedback/classes/responses_anon_table.php
|
mod_feedback_responses_anon_table.col_random_response
|
public function col_random_response($row) {
if ($this->is_downloading()) {
return $row->random_response;
} else {
return html_writer::link($this->get_link_single_entry($row),
get_string('response_nr', 'feedback').': '. $row->random_response);
}
}
|
php
|
public function col_random_response($row) {
if ($this->is_downloading()) {
return $row->random_response;
} else {
return html_writer::link($this->get_link_single_entry($row),
get_string('response_nr', 'feedback').': '. $row->random_response);
}
}
|
[
"public",
"function",
"col_random_response",
"(",
"$",
"row",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"is_downloading",
"(",
")",
")",
"{",
"return",
"$",
"row",
"->",
"random_response",
";",
"}",
"else",
"{",
"return",
"html_writer",
"::",
"link",
"(",
"$",
"this",
"->",
"get_link_single_entry",
"(",
"$",
"row",
")",
",",
"get_string",
"(",
"'response_nr'",
",",
"'feedback'",
")",
".",
"': '",
".",
"$",
"row",
"->",
"random_response",
")",
";",
"}",
"}"
] |
Prepares column reponse for display
@param stdClass $row
@return string
|
[
"Prepares",
"column",
"reponse",
"for",
"display"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/responses_anon_table.php#L106-L113
|
218,549
|
moodle/moodle
|
admin/tool/log/store/database/backup/moodle2/restore_logstore_database_subplugin.class.php
|
restore_logstore_database_subplugin.process_logstore_database_log
|
public function process_logstore_database_log($data) {
// Do not bother processing if we can not add it to a database.
if (!self::$extdb || !self::$extdbtablename) {
return;
}
$data = $this->process_log($data, get_config('logstore_database', 'jsonformat'));
if ($data) {
self::$extdb->insert_record(self::$extdbtablename, $data);
}
}
|
php
|
public function process_logstore_database_log($data) {
// Do not bother processing if we can not add it to a database.
if (!self::$extdb || !self::$extdbtablename) {
return;
}
$data = $this->process_log($data, get_config('logstore_database', 'jsonformat'));
if ($data) {
self::$extdb->insert_record(self::$extdbtablename, $data);
}
}
|
[
"public",
"function",
"process_logstore_database_log",
"(",
"$",
"data",
")",
"{",
"// Do not bother processing if we can not add it to a database.",
"if",
"(",
"!",
"self",
"::",
"$",
"extdb",
"||",
"!",
"self",
"::",
"$",
"extdbtablename",
")",
"{",
"return",
";",
"}",
"$",
"data",
"=",
"$",
"this",
"->",
"process_log",
"(",
"$",
"data",
",",
"get_config",
"(",
"'logstore_database'",
",",
"'jsonformat'",
")",
")",
";",
"if",
"(",
"$",
"data",
")",
"{",
"self",
"::",
"$",
"extdb",
"->",
"insert_record",
"(",
"self",
"::",
"$",
"extdbtablename",
",",
"$",
"data",
")",
";",
"}",
"}"
] |
Process logstore_database_log entries.
This method proceeds to read, complete, remap and, finally,
discard or save every log entry.
@param array() $data log entry.
@return null if we are not restoring the log.
|
[
"Process",
"logstore_database_log",
"entries",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/log/store/database/backup/moodle2/restore_logstore_database_subplugin.class.php#L90-L101
|
218,550
|
moodle/moodle
|
mod/lti/classes/local/ltiservice/service_base.php
|
service_base.is_used_in_context
|
public function is_used_in_context($typeid, $courseid) {
global $DB;
$ok = $DB->record_exists('lti', array('course' => $courseid, 'typeid' => $typeid));
return $ok || $DB->record_exists('lti_types', array('course' => $courseid, 'id' => $typeid));
}
|
php
|
public function is_used_in_context($typeid, $courseid) {
global $DB;
$ok = $DB->record_exists('lti', array('course' => $courseid, 'typeid' => $typeid));
return $ok || $DB->record_exists('lti_types', array('course' => $courseid, 'id' => $typeid));
}
|
[
"public",
"function",
"is_used_in_context",
"(",
"$",
"typeid",
",",
"$",
"courseid",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"ok",
"=",
"$",
"DB",
"->",
"record_exists",
"(",
"'lti'",
",",
"array",
"(",
"'course'",
"=>",
"$",
"courseid",
",",
"'typeid'",
"=>",
"$",
"typeid",
")",
")",
";",
"return",
"$",
"ok",
"||",
"$",
"DB",
"->",
"record_exists",
"(",
"'lti_types'",
",",
"array",
"(",
"'course'",
"=>",
"$",
"courseid",
",",
"'id'",
"=>",
"$",
"typeid",
")",
")",
";",
"}"
] |
Default implementation will check for the existence of at least one mod_lti entry for that tool and context.
It may be overridden if other inferences can be done.
Ideally a Site Tool should be explicitly engaged with a course, the check on the presence of a link is a proxy
to infer a Site Tool engagement until an explicit Site Tool - Course relationship exists.
@param int $typeid The tool lti type id.
@param int $courseid The course id.
@return bool returns True if tool is used in context, false otherwise.
|
[
"Default",
"implementation",
"will",
"check",
"for",
"the",
"existence",
"of",
"at",
"least",
"one",
"mod_lti",
"entry",
"for",
"that",
"tool",
"and",
"context",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lti/classes/local/ltiservice/service_base.php#L172-L177
|
218,551
|
moodle/moodle
|
mod/lti/classes/local/ltiservice/service_base.php
|
service_base.is_allowed_in_context
|
public function is_allowed_in_context($typeid, $courseid) {
global $DB;
// Check if it is a Course tool for this course or a Site tool.
$type = $DB->get_record('lti_types', array('id' => $typeid));
return $type && ($type->course == $courseid || $type->course == SITEID);
}
|
php
|
public function is_allowed_in_context($typeid, $courseid) {
global $DB;
// Check if it is a Course tool for this course or a Site tool.
$type = $DB->get_record('lti_types', array('id' => $typeid));
return $type && ($type->course == $courseid || $type->course == SITEID);
}
|
[
"public",
"function",
"is_allowed_in_context",
"(",
"$",
"typeid",
",",
"$",
"courseid",
")",
"{",
"global",
"$",
"DB",
";",
"// Check if it is a Course tool for this course or a Site tool.",
"$",
"type",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'lti_types'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"typeid",
")",
")",
";",
"return",
"$",
"type",
"&&",
"(",
"$",
"type",
"->",
"course",
"==",
"$",
"courseid",
"||",
"$",
"type",
"->",
"course",
"==",
"SITEID",
")",
";",
"}"
] |
Checks if there is a site tool or a course tool for this site.
@param int $typeid The tool lti type id.
@param int $courseid The course id.
@return bool returns True if tool is allowed in context, false otherwise.
|
[
"Checks",
"if",
"there",
"is",
"a",
"site",
"tool",
"or",
"a",
"course",
"tool",
"for",
"this",
"site",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lti/classes/local/ltiservice/service_base.php#L186-L193
|
218,552
|
moodle/moodle
|
mod/lti/classes/local/ltiservice/service_base.php
|
service_base.parse_value
|
public function parse_value($value) {
if (empty($this->resources)) {
$this->resources = $this->get_resources();
}
if (!empty($this->resources)) {
foreach ($this->resources as $resource) {
$value = $resource->parse_value($value);
}
}
return $value;
}
|
php
|
public function parse_value($value) {
if (empty($this->resources)) {
$this->resources = $this->get_resources();
}
if (!empty($this->resources)) {
foreach ($this->resources as $resource) {
$value = $resource->parse_value($value);
}
}
return $value;
}
|
[
"public",
"function",
"parse_value",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"resources",
")",
")",
"{",
"$",
"this",
"->",
"resources",
"=",
"$",
"this",
"->",
"get_resources",
"(",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"resources",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"resources",
"as",
"$",
"resource",
")",
"{",
"$",
"value",
"=",
"$",
"resource",
"->",
"parse_value",
"(",
"$",
"value",
")",
";",
"}",
"}",
"return",
"$",
"value",
";",
"}"
] |
Parse a string for custom substitution parameter variables supported by this service's resources.
@param string $value Value to be parsed
@return string
|
[
"Parse",
"a",
"string",
"for",
"custom",
"substitution",
"parameter",
"variables",
"supported",
"by",
"this",
"service",
"s",
"resources",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lti/classes/local/ltiservice/service_base.php#L232-L245
|
218,553
|
moodle/moodle
|
mod/lti/classes/local/ltiservice/service_base.php
|
service_base.check_signature
|
private function check_signature($consumerkey, $secret, $body) {
$ok = true;
try {
// TODO: Switch to core oauthlib once implemented - MDL-30149.
lti\handle_oauth_body_post($consumerkey, $secret, $body);
} catch (\Exception $e) {
debugging($e->getMessage() . "\n");
$ok = false;
}
return $ok;
}
|
php
|
private function check_signature($consumerkey, $secret, $body) {
$ok = true;
try {
// TODO: Switch to core oauthlib once implemented - MDL-30149.
lti\handle_oauth_body_post($consumerkey, $secret, $body);
} catch (\Exception $e) {
debugging($e->getMessage() . "\n");
$ok = false;
}
return $ok;
}
|
[
"private",
"function",
"check_signature",
"(",
"$",
"consumerkey",
",",
"$",
"secret",
",",
"$",
"body",
")",
"{",
"$",
"ok",
"=",
"true",
";",
"try",
"{",
"// TODO: Switch to core oauthlib once implemented - MDL-30149.",
"lti",
"\\",
"handle_oauth_body_post",
"(",
"$",
"consumerkey",
",",
"$",
"secret",
",",
"$",
"body",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"debugging",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
".",
"\"\\n\"",
")",
";",
"$",
"ok",
"=",
"false",
";",
"}",
"return",
"$",
"ok",
";",
"}"
] |
Check the request signature.
@param string $consumerkey Consumer key
@param string $secret Shared secret
@param string $body Request body
@return boolean
|
[
"Check",
"the",
"request",
"signature",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lti/classes/local/ltiservice/service_base.php#L317-L330
|
218,554
|
moodle/moodle
|
lib/horde/framework/Horde/Mail/Rfc822.php
|
Horde_Mail_Rfc822.parseAddressList
|
public function parseAddressList($address, array $params = array())
{
if ($address instanceof Horde_Mail_Rfc822_List) {
return $address;
}
if (empty($params['limit'])) {
$params['limit'] = -1;
}
$this->_params = array_merge(array(
'default_domain' => null,
'validate' => false
), $params);
$this->_listob = empty($this->_params['group'])
? new Horde_Mail_Rfc822_List()
: new Horde_Mail_Rfc822_GroupList();
if (!is_array($address)) {
$address = array($address);
}
$tmp = array();
foreach ($address as $val) {
if ($val instanceof Horde_Mail_Rfc822_Object) {
$this->_listob->add($val);
} else {
$tmp[] = rtrim(trim($val), ',');
}
}
if (!empty($tmp)) {
$this->_data = implode(',', $tmp);
$this->_datalen = strlen($this->_data);
$this->_ptr = 0;
$this->_parseAddressList();
}
$ret = $this->_listob;
unset($this->_listob);
return $ret;
}
|
php
|
public function parseAddressList($address, array $params = array())
{
if ($address instanceof Horde_Mail_Rfc822_List) {
return $address;
}
if (empty($params['limit'])) {
$params['limit'] = -1;
}
$this->_params = array_merge(array(
'default_domain' => null,
'validate' => false
), $params);
$this->_listob = empty($this->_params['group'])
? new Horde_Mail_Rfc822_List()
: new Horde_Mail_Rfc822_GroupList();
if (!is_array($address)) {
$address = array($address);
}
$tmp = array();
foreach ($address as $val) {
if ($val instanceof Horde_Mail_Rfc822_Object) {
$this->_listob->add($val);
} else {
$tmp[] = rtrim(trim($val), ',');
}
}
if (!empty($tmp)) {
$this->_data = implode(',', $tmp);
$this->_datalen = strlen($this->_data);
$this->_ptr = 0;
$this->_parseAddressList();
}
$ret = $this->_listob;
unset($this->_listob);
return $ret;
}
|
[
"public",
"function",
"parseAddressList",
"(",
"$",
"address",
",",
"array",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"$",
"address",
"instanceof",
"Horde_Mail_Rfc822_List",
")",
"{",
"return",
"$",
"address",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"params",
"[",
"'limit'",
"]",
")",
")",
"{",
"$",
"params",
"[",
"'limit'",
"]",
"=",
"-",
"1",
";",
"}",
"$",
"this",
"->",
"_params",
"=",
"array_merge",
"(",
"array",
"(",
"'default_domain'",
"=>",
"null",
",",
"'validate'",
"=>",
"false",
")",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"_listob",
"=",
"empty",
"(",
"$",
"this",
"->",
"_params",
"[",
"'group'",
"]",
")",
"?",
"new",
"Horde_Mail_Rfc822_List",
"(",
")",
":",
"new",
"Horde_Mail_Rfc822_GroupList",
"(",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"address",
")",
")",
"{",
"$",
"address",
"=",
"array",
"(",
"$",
"address",
")",
";",
"}",
"$",
"tmp",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"address",
"as",
"$",
"val",
")",
"{",
"if",
"(",
"$",
"val",
"instanceof",
"Horde_Mail_Rfc822_Object",
")",
"{",
"$",
"this",
"->",
"_listob",
"->",
"add",
"(",
"$",
"val",
")",
";",
"}",
"else",
"{",
"$",
"tmp",
"[",
"]",
"=",
"rtrim",
"(",
"trim",
"(",
"$",
"val",
")",
",",
"','",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"tmp",
")",
")",
"{",
"$",
"this",
"->",
"_data",
"=",
"implode",
"(",
"','",
",",
"$",
"tmp",
")",
";",
"$",
"this",
"->",
"_datalen",
"=",
"strlen",
"(",
"$",
"this",
"->",
"_data",
")",
";",
"$",
"this",
"->",
"_ptr",
"=",
"0",
";",
"$",
"this",
"->",
"_parseAddressList",
"(",
")",
";",
"}",
"$",
"ret",
"=",
"$",
"this",
"->",
"_listob",
";",
"unset",
"(",
"$",
"this",
"->",
"_listob",
")",
";",
"return",
"$",
"ret",
";",
"}"
] |
Starts the whole process.
@param mixed $address The address(es) to validate. Either a string,
a Horde_Mail_Rfc822_Object, or an array of
strings and/or Horde_Mail_Rfc822_Objects.
@param array $params Optional parameters:
- default_domain: (string) Default domain/host.
DEFAULT: None
- group: (boolean) Return a GroupList object instead of a List object?
DEFAULT: false
- limit: (integer) Stop processing after this many addresses.
DEFAULT: No limit (0)
- validate: (mixed) Strict validation of personal part data? If
false, attempts to allow non-ASCII characters and
non-quoted strings in the personal data, and will
silently abort if an unparseable address is found.
If true, does strict RFC 5322 (ASCII-only) parsing. If
'eai' (@since 2.5.0), allows RFC 6532 (EAI/UTF-8)
addresses.
DEFAULT: false
@return Horde_Mail_Rfc822_List A list object.
@throws Horde_Mail_Exception
|
[
"Starts",
"the",
"whole",
"process",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mail/Rfc822.php#L145-L189
|
218,555
|
moodle/moodle
|
lib/horde/framework/Horde/Mail/Rfc822.php
|
Horde_Mail_Rfc822._rfc822IsAtext
|
protected function _rfc822IsAtext($chr, $validate = null)
{
if (!$this->_params['validate'] && !is_null($validate)) {
return strcspn($chr, $validate);
}
$ord = ord($chr);
/* UTF-8 characters check. */
if ($ord > 127) {
return ($this->_params['validate'] === 'eai');
}
/* Check for DISALLOWED characters under both RFCs 5322 and 6532. */
/* Unprintable characters && [SPACE] */
if ($ord <= 32) {
return false;
}
/* "(),:;<>@[\] [DEL] */
switch ($ord) {
case 34:
case 40:
case 41:
case 44:
case 58:
case 59:
case 60:
case 62:
case 64:
case 91:
case 92:
case 93:
case 127:
return false;
}
return true;
}
|
php
|
protected function _rfc822IsAtext($chr, $validate = null)
{
if (!$this->_params['validate'] && !is_null($validate)) {
return strcspn($chr, $validate);
}
$ord = ord($chr);
/* UTF-8 characters check. */
if ($ord > 127) {
return ($this->_params['validate'] === 'eai');
}
/* Check for DISALLOWED characters under both RFCs 5322 and 6532. */
/* Unprintable characters && [SPACE] */
if ($ord <= 32) {
return false;
}
/* "(),:;<>@[\] [DEL] */
switch ($ord) {
case 34:
case 40:
case 41:
case 44:
case 58:
case 59:
case 60:
case 62:
case 64:
case 91:
case 92:
case 93:
case 127:
return false;
}
return true;
}
|
[
"protected",
"function",
"_rfc822IsAtext",
"(",
"$",
"chr",
",",
"$",
"validate",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_params",
"[",
"'validate'",
"]",
"&&",
"!",
"is_null",
"(",
"$",
"validate",
")",
")",
"{",
"return",
"strcspn",
"(",
"$",
"chr",
",",
"$",
"validate",
")",
";",
"}",
"$",
"ord",
"=",
"ord",
"(",
"$",
"chr",
")",
";",
"/* UTF-8 characters check. */",
"if",
"(",
"$",
"ord",
">",
"127",
")",
"{",
"return",
"(",
"$",
"this",
"->",
"_params",
"[",
"'validate'",
"]",
"===",
"'eai'",
")",
";",
"}",
"/* Check for DISALLOWED characters under both RFCs 5322 and 6532. */",
"/* Unprintable characters && [SPACE] */",
"if",
"(",
"$",
"ord",
"<=",
"32",
")",
"{",
"return",
"false",
";",
"}",
"/* \"(),:;<>@[\\] [DEL] */",
"switch",
"(",
"$",
"ord",
")",
"{",
"case",
"34",
":",
"case",
"40",
":",
"case",
"41",
":",
"case",
"44",
":",
"case",
"58",
":",
"case",
"59",
":",
"case",
"60",
":",
"case",
"62",
":",
"case",
"64",
":",
"case",
"91",
":",
"case",
"92",
":",
"case",
"93",
":",
"case",
"127",
":",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Check if data is an atom.
@param string $chr The character to check.
@param string $validate If in non-validate mode, use these characters
as the non-atom delimiters.
@return boolean True if a valid atom.
|
[
"Check",
"if",
"data",
"is",
"an",
"atom",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mail/Rfc822.php#L799-L838
|
218,556
|
moodle/moodle
|
lib/horde/framework/Horde/Mail/Rfc822.php
|
Horde_Mail_Rfc822._curr
|
protected function _curr($advance = false)
{
return ($this->_ptr >= $this->_datalen)
? false
: $this->_data[$advance ? $this->_ptr++ : $this->_ptr];
}
|
php
|
protected function _curr($advance = false)
{
return ($this->_ptr >= $this->_datalen)
? false
: $this->_data[$advance ? $this->_ptr++ : $this->_ptr];
}
|
[
"protected",
"function",
"_curr",
"(",
"$",
"advance",
"=",
"false",
")",
"{",
"return",
"(",
"$",
"this",
"->",
"_ptr",
">=",
"$",
"this",
"->",
"_datalen",
")",
"?",
"false",
":",
"$",
"this",
"->",
"_data",
"[",
"$",
"advance",
"?",
"$",
"this",
"->",
"_ptr",
"++",
":",
"$",
"this",
"->",
"_ptr",
"]",
";",
"}"
] |
Return current character.
@param boolean $advance If true, advance the cursor.
@return string The current character (false if EOF reached).
|
[
"Return",
"current",
"character",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mail/Rfc822.php#L849-L854
|
218,557
|
moodle/moodle
|
admin/tool/lp/classes/site_competencies_form_element.php
|
tool_lp_site_competencies_form_element.toHtml
|
public function toHtml() {
global $PAGE;
$html = parent::toHTML();
if (!$this->isFrozen()) {
$context = context_system::instance();
$params = [$context->id];
// Require some JS to select the competencies.
$PAGE->requires->js_call_amd('tool_lp/form_competency_element', 'init', $params);
$html .= '<div class="form-group row">';
$html .= '<div class="col-md-3"></div>';
$html .= '<div class="col-md-9">';
$html .= '<div data-region="competencies"></div>';
$html .= '<div class="mt-3">';
$html .= '<a class="btn btn-secondary" role="button" data-action="select-competencies">';
$html .= get_string('addcompetency', 'tool_lp');
$html .= '</a>';
$html .= '</div>';
$html .= '</div>';
$html .= '</div>';
}
return $html;
}
|
php
|
public function toHtml() {
global $PAGE;
$html = parent::toHTML();
if (!$this->isFrozen()) {
$context = context_system::instance();
$params = [$context->id];
// Require some JS to select the competencies.
$PAGE->requires->js_call_amd('tool_lp/form_competency_element', 'init', $params);
$html .= '<div class="form-group row">';
$html .= '<div class="col-md-3"></div>';
$html .= '<div class="col-md-9">';
$html .= '<div data-region="competencies"></div>';
$html .= '<div class="mt-3">';
$html .= '<a class="btn btn-secondary" role="button" data-action="select-competencies">';
$html .= get_string('addcompetency', 'tool_lp');
$html .= '</a>';
$html .= '</div>';
$html .= '</div>';
$html .= '</div>';
}
return $html;
}
|
[
"public",
"function",
"toHtml",
"(",
")",
"{",
"global",
"$",
"PAGE",
";",
"$",
"html",
"=",
"parent",
"::",
"toHTML",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isFrozen",
"(",
")",
")",
"{",
"$",
"context",
"=",
"context_system",
"::",
"instance",
"(",
")",
";",
"$",
"params",
"=",
"[",
"$",
"context",
"->",
"id",
"]",
";",
"// Require some JS to select the competencies.",
"$",
"PAGE",
"->",
"requires",
"->",
"js_call_amd",
"(",
"'tool_lp/form_competency_element'",
",",
"'init'",
",",
"$",
"params",
")",
";",
"$",
"html",
".=",
"'<div class=\"form-group row\">'",
";",
"$",
"html",
".=",
"'<div class=\"col-md-3\"></div>'",
";",
"$",
"html",
".=",
"'<div class=\"col-md-9\">'",
";",
"$",
"html",
".=",
"'<div data-region=\"competencies\"></div>'",
";",
"$",
"html",
".=",
"'<div class=\"mt-3\">'",
";",
"$",
"html",
".=",
"'<a class=\"btn btn-secondary\" role=\"button\" data-action=\"select-competencies\">'",
";",
"$",
"html",
".=",
"get_string",
"(",
"'addcompetency'",
",",
"'tool_lp'",
")",
";",
"$",
"html",
".=",
"'</a>'",
";",
"$",
"html",
".=",
"'</div>'",
";",
"$",
"html",
".=",
"'</div>'",
";",
"$",
"html",
".=",
"'</div>'",
";",
"}",
"return",
"$",
"html",
";",
"}"
] |
Generate the hidden field and the controls to show and pick the competencies.
|
[
"Generate",
"the",
"hidden",
"field",
"and",
"the",
"controls",
"to",
"show",
"and",
"pick",
"the",
"competencies",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lp/classes/site_competencies_form_element.php#L62-L85
|
218,558
|
moodle/moodle
|
mod/quiz/classes/local/structure/slot_random.php
|
slot_random.get_quiz
|
public function get_quiz() {
global $DB;
if (empty($this->quiz)) {
if (empty($this->record->quizid)) {
throw new \coding_exception('quizid is not set.');
}
$this->quiz = $DB->get_record('quiz', array('id' => $this->record->quizid));
}
return $this->quiz;
}
|
php
|
public function get_quiz() {
global $DB;
if (empty($this->quiz)) {
if (empty($this->record->quizid)) {
throw new \coding_exception('quizid is not set.');
}
$this->quiz = $DB->get_record('quiz', array('id' => $this->record->quizid));
}
return $this->quiz;
}
|
[
"public",
"function",
"get_quiz",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"quiz",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"record",
"->",
"quizid",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'quizid is not set.'",
")",
";",
"}",
"$",
"this",
"->",
"quiz",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'quiz'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"record",
"->",
"quizid",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"quiz",
";",
"}"
] |
Returns the quiz for this question slot.
The quiz is fetched the first time it is requested and then stored in a member variable to be returned each subsequent time.
@return mixed
@throws \coding_exception
|
[
"Returns",
"the",
"quiz",
"for",
"this",
"question",
"slot",
".",
"The",
"quiz",
"is",
"fetched",
"the",
"first",
"time",
"it",
"is",
"requested",
"and",
"then",
"stored",
"in",
"a",
"member",
"variable",
"to",
"be",
"returned",
"each",
"subsequent",
"time",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/local/structure/slot_random.php#L77-L88
|
218,559
|
moodle/moodle
|
mod/quiz/classes/local/structure/slot_random.php
|
slot_random.set_quiz
|
public function set_quiz($quiz) {
$this->quiz = $quiz;
$this->record->quizid = $quiz->id;
}
|
php
|
public function set_quiz($quiz) {
$this->quiz = $quiz;
$this->record->quizid = $quiz->id;
}
|
[
"public",
"function",
"set_quiz",
"(",
"$",
"quiz",
")",
"{",
"$",
"this",
"->",
"quiz",
"=",
"$",
"quiz",
";",
"$",
"this",
"->",
"record",
"->",
"quizid",
"=",
"$",
"quiz",
"->",
"id",
";",
"}"
] |
Sets the quiz object for the quiz slot.
It is not mandatory to set the quiz as the quiz slot can fetch it the first time it is accessed,
however it helps with the performance to set the quiz if you already have it.
@param \stdClass $quiz The qui object.
|
[
"Sets",
"the",
"quiz",
"object",
"for",
"the",
"quiz",
"slot",
".",
"It",
"is",
"not",
"mandatory",
"to",
"set",
"the",
"quiz",
"as",
"the",
"quiz",
"slot",
"can",
"fetch",
"it",
"the",
"first",
"time",
"it",
"is",
"accessed",
"however",
"it",
"helps",
"with",
"the",
"performance",
"to",
"set",
"the",
"quiz",
"if",
"you",
"already",
"have",
"it",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/local/structure/slot_random.php#L97-L100
|
218,560
|
moodle/moodle
|
mod/quiz/classes/local/structure/slot_random.php
|
slot_random.set_tags
|
public function set_tags($tags) {
$this->tags = [];
foreach ($tags as $tag) {
// We use $tag->id as the key for the array so not only it handles duplicates of the same tag being given,
// but also it is consistent with the behaviour of set_tags_by_id() below.
$this->tags[$tag->id] = $tag;
}
}
|
php
|
public function set_tags($tags) {
$this->tags = [];
foreach ($tags as $tag) {
// We use $tag->id as the key for the array so not only it handles duplicates of the same tag being given,
// but also it is consistent with the behaviour of set_tags_by_id() below.
$this->tags[$tag->id] = $tag;
}
}
|
[
"public",
"function",
"set_tags",
"(",
"$",
"tags",
")",
"{",
"$",
"this",
"->",
"tags",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"tags",
"as",
"$",
"tag",
")",
"{",
"// We use $tag->id as the key for the array so not only it handles duplicates of the same tag being given,",
"// but also it is consistent with the behaviour of set_tags_by_id() below.",
"$",
"this",
"->",
"tags",
"[",
"$",
"tag",
"->",
"id",
"]",
"=",
"$",
"tag",
";",
"}",
"}"
] |
Set some tags for this quiz slot.
@param \core_tag_tag[] $tags
|
[
"Set",
"some",
"tags",
"for",
"this",
"quiz",
"slot",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/local/structure/slot_random.php#L107-L114
|
218,561
|
moodle/moodle
|
lib/classes/task/refresh_mod_calendar_events_task.php
|
refresh_mod_calendar_events_task.execute
|
public function execute() {
global $CFG;
require_once($CFG->dirroot . '/course/lib.php');
// Specific list of plugins that need to be refreshed. If not set, then all mod plugins will be refreshed.
$pluginstorefresh = null;
if (isset($this->get_custom_data()->plugins)) {
$pluginstorefresh = $this->get_custom_data()->plugins;
}
// Is course id set?
if (isset($this->get_custom_data()->courseid)) {
$courseid = $this->get_custom_data()->courseid;
} else {
$courseid = 0;
}
$pluginmanager = core_plugin_manager::instance();
$modplugins = $pluginmanager->get_plugins_of_type('mod');
foreach ($modplugins as $plugin) {
// Check if a specific list of plugins is defined and check if it contains the plugin that is currently being evaluated.
if (!empty($pluginstorefresh) && !in_array($plugin->name, $pluginstorefresh)) {
// This plugin is not in the list, move on to the next one.
continue;
}
// Refresh events.
mtrace('Refreshing events for ' . $plugin->name);
course_module_bulk_update_calendar_events($plugin->name, $courseid);
}
}
|
php
|
public function execute() {
global $CFG;
require_once($CFG->dirroot . '/course/lib.php');
// Specific list of plugins that need to be refreshed. If not set, then all mod plugins will be refreshed.
$pluginstorefresh = null;
if (isset($this->get_custom_data()->plugins)) {
$pluginstorefresh = $this->get_custom_data()->plugins;
}
// Is course id set?
if (isset($this->get_custom_data()->courseid)) {
$courseid = $this->get_custom_data()->courseid;
} else {
$courseid = 0;
}
$pluginmanager = core_plugin_manager::instance();
$modplugins = $pluginmanager->get_plugins_of_type('mod');
foreach ($modplugins as $plugin) {
// Check if a specific list of plugins is defined and check if it contains the plugin that is currently being evaluated.
if (!empty($pluginstorefresh) && !in_array($plugin->name, $pluginstorefresh)) {
// This plugin is not in the list, move on to the next one.
continue;
}
// Refresh events.
mtrace('Refreshing events for ' . $plugin->name);
course_module_bulk_update_calendar_events($plugin->name, $courseid);
}
}
|
[
"public",
"function",
"execute",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/course/lib.php'",
")",
";",
"// Specific list of plugins that need to be refreshed. If not set, then all mod plugins will be refreshed.",
"$",
"pluginstorefresh",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"get_custom_data",
"(",
")",
"->",
"plugins",
")",
")",
"{",
"$",
"pluginstorefresh",
"=",
"$",
"this",
"->",
"get_custom_data",
"(",
")",
"->",
"plugins",
";",
"}",
"// Is course id set?",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"get_custom_data",
"(",
")",
"->",
"courseid",
")",
")",
"{",
"$",
"courseid",
"=",
"$",
"this",
"->",
"get_custom_data",
"(",
")",
"->",
"courseid",
";",
"}",
"else",
"{",
"$",
"courseid",
"=",
"0",
";",
"}",
"$",
"pluginmanager",
"=",
"core_plugin_manager",
"::",
"instance",
"(",
")",
";",
"$",
"modplugins",
"=",
"$",
"pluginmanager",
"->",
"get_plugins_of_type",
"(",
"'mod'",
")",
";",
"foreach",
"(",
"$",
"modplugins",
"as",
"$",
"plugin",
")",
"{",
"// Check if a specific list of plugins is defined and check if it contains the plugin that is currently being evaluated.",
"if",
"(",
"!",
"empty",
"(",
"$",
"pluginstorefresh",
")",
"&&",
"!",
"in_array",
"(",
"$",
"plugin",
"->",
"name",
",",
"$",
"pluginstorefresh",
")",
")",
"{",
"// This plugin is not in the list, move on to the next one.",
"continue",
";",
"}",
"// Refresh events.",
"mtrace",
"(",
"'Refreshing events for '",
".",
"$",
"plugin",
"->",
"name",
")",
";",
"course_module_bulk_update_calendar_events",
"(",
"$",
"plugin",
"->",
"name",
",",
"$",
"courseid",
")",
";",
"}",
"}"
] |
Run the task to refresh calendar events.
|
[
"Run",
"the",
"task",
"to",
"refresh",
"calendar",
"events",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/task/refresh_mod_calendar_events_task.php#L46-L76
|
218,562
|
moodle/moodle
|
repository/nextcloud/classes/access_controlled_link_manager.php
|
access_controlled_link_manager.delete_share_dataowner_sysaccount
|
public function delete_share_dataowner_sysaccount($shareid) {
$shareid = (int) $shareid;
$deleteshareparams = [
'share_id' => $shareid
];
$deleteshareresponse = $this->ocsclient->call('delete_share', $deleteshareparams);
$xml = simplexml_load_string($deleteshareresponse);
if (empty($xml->meta->statuscode) || $xml->meta->statuscode != 100 ) {
notification::warning('You just shared a file with a access controlled link.
However, the share between you and the systemaccount could not be deleted and is still present in your instance.');
}
}
|
php
|
public function delete_share_dataowner_sysaccount($shareid) {
$shareid = (int) $shareid;
$deleteshareparams = [
'share_id' => $shareid
];
$deleteshareresponse = $this->ocsclient->call('delete_share', $deleteshareparams);
$xml = simplexml_load_string($deleteshareresponse);
if (empty($xml->meta->statuscode) || $xml->meta->statuscode != 100 ) {
notification::warning('You just shared a file with a access controlled link.
However, the share between you and the systemaccount could not be deleted and is still present in your instance.');
}
}
|
[
"public",
"function",
"delete_share_dataowner_sysaccount",
"(",
"$",
"shareid",
")",
"{",
"$",
"shareid",
"=",
"(",
"int",
")",
"$",
"shareid",
";",
"$",
"deleteshareparams",
"=",
"[",
"'share_id'",
"=>",
"$",
"shareid",
"]",
";",
"$",
"deleteshareresponse",
"=",
"$",
"this",
"->",
"ocsclient",
"->",
"call",
"(",
"'delete_share'",
",",
"$",
"deleteshareparams",
")",
";",
"$",
"xml",
"=",
"simplexml_load_string",
"(",
"$",
"deleteshareresponse",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"xml",
"->",
"meta",
"->",
"statuscode",
")",
"||",
"$",
"xml",
"->",
"meta",
"->",
"statuscode",
"!=",
"100",
")",
"{",
"notification",
"::",
"warning",
"(",
"'You just shared a file with a access controlled link.\n However, the share between you and the systemaccount could not be deleted and is still present in your instance.'",
")",
";",
"}",
"}"
] |
Deletes the share of the systemaccount and a user. In case the share could not be deleted a notification is
displayed.
@param int $shareid Remote ID of the share to be deleted.
|
[
"Deletes",
"the",
"share",
"of",
"the",
"systemaccount",
"and",
"a",
"user",
".",
"In",
"case",
"the",
"share",
"could",
"not",
"be",
"deleted",
"a",
"notification",
"is",
"displayed",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/nextcloud/classes/access_controlled_link_manager.php#L97-L109
|
218,563
|
moodle/moodle
|
repository/nextcloud/classes/access_controlled_link_manager.php
|
access_controlled_link_manager.transfer_file_to_path
|
public function transfer_file_to_path($srcpath, $dstpath, $operation, $webdavclient = null) {
$this->systemwebdavclient->open();
$webdavendpoint = issuer_management::parse_endpoint_url('webdav', $this->issuer);
$srcpath = ltrim($srcpath, '/');
$sourcepath = $webdavendpoint['path'] . $srcpath;
$dstpath = ltrim($dstpath, '/');
$destinationpath = $webdavendpoint['path'] . $dstpath . '/' . $srcpath;
if ($operation === 'copy') {
$result = $this->systemwebdavclient->copy_file($sourcepath, $destinationpath, true);
} else if ($operation === 'move') {
$result = $webdavclient->move($sourcepath, $destinationpath, false);
if ($result == 412) {
// A file with that name already exists at that target. Find a unique location!
$increment = 0; // Will be appended to/inserted into the filename.
// Define the pattern that is used to insert the increment to the filename.
if (substr_count($srcpath, '.') === 0) {
// No file extension; append increment to the (sprintf-escaped) name.
$namepattern = str_replace('%', '%%', $destinationpath) . ' (%s)';
} else {
// Append the increment to the second-to-last component, which is presumably the one before the extension.
// Again, the original path is sprintf-escaped.
$components = explode('.', str_replace('%', '%%', $destinationpath));
$components[count($components) - 2] .= ' (%s)';
$namepattern = implode('.', $components);
}
}
while ($result == 412) {
$increment++;
$destinationpath = sprintf($namepattern, $increment);
$result = $webdavclient->move($sourcepath, $destinationpath, false);
}
}
$this->systemwebdavclient->close();
if (!($result == 201 || $result == 412)) {
$details = get_string('contactadminwith', 'repository_nextcloud',
'A webdav request to ' . $operation . ' a file failed.');
throw new request_exception(array('instance' => $this->repositoryname, 'errormessage' => $details));
}
return $result;
}
|
php
|
public function transfer_file_to_path($srcpath, $dstpath, $operation, $webdavclient = null) {
$this->systemwebdavclient->open();
$webdavendpoint = issuer_management::parse_endpoint_url('webdav', $this->issuer);
$srcpath = ltrim($srcpath, '/');
$sourcepath = $webdavendpoint['path'] . $srcpath;
$dstpath = ltrim($dstpath, '/');
$destinationpath = $webdavendpoint['path'] . $dstpath . '/' . $srcpath;
if ($operation === 'copy') {
$result = $this->systemwebdavclient->copy_file($sourcepath, $destinationpath, true);
} else if ($operation === 'move') {
$result = $webdavclient->move($sourcepath, $destinationpath, false);
if ($result == 412) {
// A file with that name already exists at that target. Find a unique location!
$increment = 0; // Will be appended to/inserted into the filename.
// Define the pattern that is used to insert the increment to the filename.
if (substr_count($srcpath, '.') === 0) {
// No file extension; append increment to the (sprintf-escaped) name.
$namepattern = str_replace('%', '%%', $destinationpath) . ' (%s)';
} else {
// Append the increment to the second-to-last component, which is presumably the one before the extension.
// Again, the original path is sprintf-escaped.
$components = explode('.', str_replace('%', '%%', $destinationpath));
$components[count($components) - 2] .= ' (%s)';
$namepattern = implode('.', $components);
}
}
while ($result == 412) {
$increment++;
$destinationpath = sprintf($namepattern, $increment);
$result = $webdavclient->move($sourcepath, $destinationpath, false);
}
}
$this->systemwebdavclient->close();
if (!($result == 201 || $result == 412)) {
$details = get_string('contactadminwith', 'repository_nextcloud',
'A webdav request to ' . $operation . ' a file failed.');
throw new request_exception(array('instance' => $this->repositoryname, 'errormessage' => $details));
}
return $result;
}
|
[
"public",
"function",
"transfer_file_to_path",
"(",
"$",
"srcpath",
",",
"$",
"dstpath",
",",
"$",
"operation",
",",
"$",
"webdavclient",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"systemwebdavclient",
"->",
"open",
"(",
")",
";",
"$",
"webdavendpoint",
"=",
"issuer_management",
"::",
"parse_endpoint_url",
"(",
"'webdav'",
",",
"$",
"this",
"->",
"issuer",
")",
";",
"$",
"srcpath",
"=",
"ltrim",
"(",
"$",
"srcpath",
",",
"'/'",
")",
";",
"$",
"sourcepath",
"=",
"$",
"webdavendpoint",
"[",
"'path'",
"]",
".",
"$",
"srcpath",
";",
"$",
"dstpath",
"=",
"ltrim",
"(",
"$",
"dstpath",
",",
"'/'",
")",
";",
"$",
"destinationpath",
"=",
"$",
"webdavendpoint",
"[",
"'path'",
"]",
".",
"$",
"dstpath",
".",
"'/'",
".",
"$",
"srcpath",
";",
"if",
"(",
"$",
"operation",
"===",
"'copy'",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"systemwebdavclient",
"->",
"copy_file",
"(",
"$",
"sourcepath",
",",
"$",
"destinationpath",
",",
"true",
")",
";",
"}",
"else",
"if",
"(",
"$",
"operation",
"===",
"'move'",
")",
"{",
"$",
"result",
"=",
"$",
"webdavclient",
"->",
"move",
"(",
"$",
"sourcepath",
",",
"$",
"destinationpath",
",",
"false",
")",
";",
"if",
"(",
"$",
"result",
"==",
"412",
")",
"{",
"// A file with that name already exists at that target. Find a unique location!",
"$",
"increment",
"=",
"0",
";",
"// Will be appended to/inserted into the filename.",
"// Define the pattern that is used to insert the increment to the filename.",
"if",
"(",
"substr_count",
"(",
"$",
"srcpath",
",",
"'.'",
")",
"===",
"0",
")",
"{",
"// No file extension; append increment to the (sprintf-escaped) name.",
"$",
"namepattern",
"=",
"str_replace",
"(",
"'%'",
",",
"'%%'",
",",
"$",
"destinationpath",
")",
".",
"' (%s)'",
";",
"}",
"else",
"{",
"// Append the increment to the second-to-last component, which is presumably the one before the extension.",
"// Again, the original path is sprintf-escaped.",
"$",
"components",
"=",
"explode",
"(",
"'.'",
",",
"str_replace",
"(",
"'%'",
",",
"'%%'",
",",
"$",
"destinationpath",
")",
")",
";",
"$",
"components",
"[",
"count",
"(",
"$",
"components",
")",
"-",
"2",
"]",
".=",
"' (%s)'",
";",
"$",
"namepattern",
"=",
"implode",
"(",
"'.'",
",",
"$",
"components",
")",
";",
"}",
"}",
"while",
"(",
"$",
"result",
"==",
"412",
")",
"{",
"$",
"increment",
"++",
";",
"$",
"destinationpath",
"=",
"sprintf",
"(",
"$",
"namepattern",
",",
"$",
"increment",
")",
";",
"$",
"result",
"=",
"$",
"webdavclient",
"->",
"move",
"(",
"$",
"sourcepath",
",",
"$",
"destinationpath",
",",
"false",
")",
";",
"}",
"}",
"$",
"this",
"->",
"systemwebdavclient",
"->",
"close",
"(",
")",
";",
"if",
"(",
"!",
"(",
"$",
"result",
"==",
"201",
"||",
"$",
"result",
"==",
"412",
")",
")",
"{",
"$",
"details",
"=",
"get_string",
"(",
"'contactadminwith'",
",",
"'repository_nextcloud'",
",",
"'A webdav request to '",
".",
"$",
"operation",
".",
"' a file failed.'",
")",
";",
"throw",
"new",
"request_exception",
"(",
"array",
"(",
"'instance'",
"=>",
"$",
"this",
"->",
"repositoryname",
",",
"'errormessage'",
"=>",
"$",
"details",
")",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Copy or moves a file to a new path.
@param string $srcpath source path
@param string $dstpath
@param string $operation move or copy
@param \webdav_client $webdavclient needed when moving files.
@return String Http-status of the request
@throws configuration_exception
@throws \coding_exception
@throws \moodle_exception
@throws \repository_nextcloud\request_exception
|
[
"Copy",
"or",
"moves",
"a",
"file",
"to",
"a",
"new",
"path",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/nextcloud/classes/access_controlled_link_manager.php#L175-L216
|
218,564
|
moodle/moodle
|
repository/nextcloud/classes/access_controlled_link_manager.php
|
access_controlled_link_manager.create_folder_path_access_controlled_links
|
public function create_folder_path_access_controlled_links($context, $component, $filearea, $itemid) {
global $CFG, $SITE;
// The fullpath to store the file is generated from the context.
$contextlist = array_reverse($context->get_parent_contexts(true));
$fullpath = '';
$allfolders = [];
foreach ($contextlist as $ctx) {
// Prepare human readable context folders names, making sure they are still unique within the site.
$prevlang = force_current_language($CFG->lang);
$foldername = $ctx->get_context_name();
force_current_language($prevlang);
if ($ctx->contextlevel === CONTEXT_SYSTEM) {
// Append the site short name to the root folder.
$foldername .= ' ('.$SITE->shortname.')';
// Append the relevant object id.
} else if ($ctx->instanceid) {
$foldername .= ' (id '.$ctx->instanceid.')';
} else {
// This does not really happen but just in case.
$foldername .= ' (ctx '.$ctx->id.')';
}
$foldername = clean_param($foldername, PARAM_FILE);
$allfolders[] = $foldername;
}
$allfolders[] = clean_param($component, PARAM_FILE);
$allfolders[] = clean_param($filearea, PARAM_FILE);
$allfolders[] = clean_param($itemid, PARAM_FILE);
// Extracts the end of the webdavendpoint.
$parsedwebdavurl = issuer_management::parse_endpoint_url('webdav', $this->issuer);
$webdavprefix = $parsedwebdavurl['path'];
$this->systemwebdavclient->open();
// Checks whether folder exist and creates non-existent folders.
foreach ($allfolders as $foldername) {
$fullpath .= '/' . $foldername;
$isdir = $this->systemwebdavclient->is_dir($webdavprefix . $fullpath);
// Folder already exist, continue.
if ($isdir === true) {
continue;
}
$response = $this->systemwebdavclient->mkcol($webdavprefix . $fullpath);
if ($response != 201) {
$this->systemwebdavclient->close();
$details = get_string('contactadminwith', 'repository_nextcloud',
get_string('pathnotcreated', 'repository_nextcloud', $fullpath));
throw new request_exception(array('instance' => $this->repositoryname,
'errormessage' => $details));
}
}
$this->systemwebdavclient->close();
return $fullpath;
}
|
php
|
public function create_folder_path_access_controlled_links($context, $component, $filearea, $itemid) {
global $CFG, $SITE;
// The fullpath to store the file is generated from the context.
$contextlist = array_reverse($context->get_parent_contexts(true));
$fullpath = '';
$allfolders = [];
foreach ($contextlist as $ctx) {
// Prepare human readable context folders names, making sure they are still unique within the site.
$prevlang = force_current_language($CFG->lang);
$foldername = $ctx->get_context_name();
force_current_language($prevlang);
if ($ctx->contextlevel === CONTEXT_SYSTEM) {
// Append the site short name to the root folder.
$foldername .= ' ('.$SITE->shortname.')';
// Append the relevant object id.
} else if ($ctx->instanceid) {
$foldername .= ' (id '.$ctx->instanceid.')';
} else {
// This does not really happen but just in case.
$foldername .= ' (ctx '.$ctx->id.')';
}
$foldername = clean_param($foldername, PARAM_FILE);
$allfolders[] = $foldername;
}
$allfolders[] = clean_param($component, PARAM_FILE);
$allfolders[] = clean_param($filearea, PARAM_FILE);
$allfolders[] = clean_param($itemid, PARAM_FILE);
// Extracts the end of the webdavendpoint.
$parsedwebdavurl = issuer_management::parse_endpoint_url('webdav', $this->issuer);
$webdavprefix = $parsedwebdavurl['path'];
$this->systemwebdavclient->open();
// Checks whether folder exist and creates non-existent folders.
foreach ($allfolders as $foldername) {
$fullpath .= '/' . $foldername;
$isdir = $this->systemwebdavclient->is_dir($webdavprefix . $fullpath);
// Folder already exist, continue.
if ($isdir === true) {
continue;
}
$response = $this->systemwebdavclient->mkcol($webdavprefix . $fullpath);
if ($response != 201) {
$this->systemwebdavclient->close();
$details = get_string('contactadminwith', 'repository_nextcloud',
get_string('pathnotcreated', 'repository_nextcloud', $fullpath));
throw new request_exception(array('instance' => $this->repositoryname,
'errormessage' => $details));
}
}
$this->systemwebdavclient->close();
return $fullpath;
}
|
[
"public",
"function",
"create_folder_path_access_controlled_links",
"(",
"$",
"context",
",",
"$",
"component",
",",
"$",
"filearea",
",",
"$",
"itemid",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"SITE",
";",
"// The fullpath to store the file is generated from the context.",
"$",
"contextlist",
"=",
"array_reverse",
"(",
"$",
"context",
"->",
"get_parent_contexts",
"(",
"true",
")",
")",
";",
"$",
"fullpath",
"=",
"''",
";",
"$",
"allfolders",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"contextlist",
"as",
"$",
"ctx",
")",
"{",
"// Prepare human readable context folders names, making sure they are still unique within the site.",
"$",
"prevlang",
"=",
"force_current_language",
"(",
"$",
"CFG",
"->",
"lang",
")",
";",
"$",
"foldername",
"=",
"$",
"ctx",
"->",
"get_context_name",
"(",
")",
";",
"force_current_language",
"(",
"$",
"prevlang",
")",
";",
"if",
"(",
"$",
"ctx",
"->",
"contextlevel",
"===",
"CONTEXT_SYSTEM",
")",
"{",
"// Append the site short name to the root folder.",
"$",
"foldername",
".=",
"' ('",
".",
"$",
"SITE",
"->",
"shortname",
".",
"')'",
";",
"// Append the relevant object id.",
"}",
"else",
"if",
"(",
"$",
"ctx",
"->",
"instanceid",
")",
"{",
"$",
"foldername",
".=",
"' (id '",
".",
"$",
"ctx",
"->",
"instanceid",
".",
"')'",
";",
"}",
"else",
"{",
"// This does not really happen but just in case.",
"$",
"foldername",
".=",
"' (ctx '",
".",
"$",
"ctx",
"->",
"id",
".",
"')'",
";",
"}",
"$",
"foldername",
"=",
"clean_param",
"(",
"$",
"foldername",
",",
"PARAM_FILE",
")",
";",
"$",
"allfolders",
"[",
"]",
"=",
"$",
"foldername",
";",
"}",
"$",
"allfolders",
"[",
"]",
"=",
"clean_param",
"(",
"$",
"component",
",",
"PARAM_FILE",
")",
";",
"$",
"allfolders",
"[",
"]",
"=",
"clean_param",
"(",
"$",
"filearea",
",",
"PARAM_FILE",
")",
";",
"$",
"allfolders",
"[",
"]",
"=",
"clean_param",
"(",
"$",
"itemid",
",",
"PARAM_FILE",
")",
";",
"// Extracts the end of the webdavendpoint.",
"$",
"parsedwebdavurl",
"=",
"issuer_management",
"::",
"parse_endpoint_url",
"(",
"'webdav'",
",",
"$",
"this",
"->",
"issuer",
")",
";",
"$",
"webdavprefix",
"=",
"$",
"parsedwebdavurl",
"[",
"'path'",
"]",
";",
"$",
"this",
"->",
"systemwebdavclient",
"->",
"open",
"(",
")",
";",
"// Checks whether folder exist and creates non-existent folders.",
"foreach",
"(",
"$",
"allfolders",
"as",
"$",
"foldername",
")",
"{",
"$",
"fullpath",
".=",
"'/'",
".",
"$",
"foldername",
";",
"$",
"isdir",
"=",
"$",
"this",
"->",
"systemwebdavclient",
"->",
"is_dir",
"(",
"$",
"webdavprefix",
".",
"$",
"fullpath",
")",
";",
"// Folder already exist, continue.",
"if",
"(",
"$",
"isdir",
"===",
"true",
")",
"{",
"continue",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"systemwebdavclient",
"->",
"mkcol",
"(",
"$",
"webdavprefix",
".",
"$",
"fullpath",
")",
";",
"if",
"(",
"$",
"response",
"!=",
"201",
")",
"{",
"$",
"this",
"->",
"systemwebdavclient",
"->",
"close",
"(",
")",
";",
"$",
"details",
"=",
"get_string",
"(",
"'contactadminwith'",
",",
"'repository_nextcloud'",
",",
"get_string",
"(",
"'pathnotcreated'",
",",
"'repository_nextcloud'",
",",
"$",
"fullpath",
")",
")",
";",
"throw",
"new",
"request_exception",
"(",
"array",
"(",
"'instance'",
"=>",
"$",
"this",
"->",
"repositoryname",
",",
"'errormessage'",
"=>",
"$",
"details",
")",
")",
";",
"}",
"}",
"$",
"this",
"->",
"systemwebdavclient",
"->",
"close",
"(",
")",
";",
"return",
"$",
"fullpath",
";",
"}"
] |
Creates a unique folder path for the access controlled link.
@param context $context
@param string $component
@param string $filearea
@param string $itemid
@return string $result full generated path.
@throws request_exception If the folder path cannot be created.
|
[
"Creates",
"a",
"unique",
"folder",
"path",
"for",
"the",
"access",
"controlled",
"link",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/nextcloud/classes/access_controlled_link_manager.php#L227-L282
|
218,565
|
moodle/moodle
|
repository/nextcloud/classes/access_controlled_link_manager.php
|
access_controlled_link_manager.create_system_dav
|
public function create_system_dav() {
$webdavendpoint = issuer_management::parse_endpoint_url('webdav', $this->issuer);
// Selects the necessary information (port, type, server) from the path to build the webdavclient.
$server = $webdavendpoint['host'];
if ($webdavendpoint['scheme'] === 'https') {
$webdavtype = 'ssl://';
$webdavport = 443;
} else if ($webdavendpoint['scheme'] === 'http') {
$webdavtype = '';
$webdavport = 80;
}
// Override default port, if a specific one is set.
if (isset($webdavendpoint['port'])) {
$webdavport = $webdavendpoint['port'];
}
// Authentication method is `bearer` for OAuth 2. Pass oauth client from which WebDAV obtains the token when needed.
$dav = new \webdav_client($server, '', '', 'bearer', $webdavtype,
$this->systemoauthclient->get_accesstoken()->token, $webdavendpoint['path']);
$dav->port = $webdavport;
$dav->debug = false;
return $dav;
}
|
php
|
public function create_system_dav() {
$webdavendpoint = issuer_management::parse_endpoint_url('webdav', $this->issuer);
// Selects the necessary information (port, type, server) from the path to build the webdavclient.
$server = $webdavendpoint['host'];
if ($webdavendpoint['scheme'] === 'https') {
$webdavtype = 'ssl://';
$webdavport = 443;
} else if ($webdavendpoint['scheme'] === 'http') {
$webdavtype = '';
$webdavport = 80;
}
// Override default port, if a specific one is set.
if (isset($webdavendpoint['port'])) {
$webdavport = $webdavendpoint['port'];
}
// Authentication method is `bearer` for OAuth 2. Pass oauth client from which WebDAV obtains the token when needed.
$dav = new \webdav_client($server, '', '', 'bearer', $webdavtype,
$this->systemoauthclient->get_accesstoken()->token, $webdavendpoint['path']);
$dav->port = $webdavport;
$dav->debug = false;
return $dav;
}
|
[
"public",
"function",
"create_system_dav",
"(",
")",
"{",
"$",
"webdavendpoint",
"=",
"issuer_management",
"::",
"parse_endpoint_url",
"(",
"'webdav'",
",",
"$",
"this",
"->",
"issuer",
")",
";",
"// Selects the necessary information (port, type, server) from the path to build the webdavclient.",
"$",
"server",
"=",
"$",
"webdavendpoint",
"[",
"'host'",
"]",
";",
"if",
"(",
"$",
"webdavendpoint",
"[",
"'scheme'",
"]",
"===",
"'https'",
")",
"{",
"$",
"webdavtype",
"=",
"'ssl://'",
";",
"$",
"webdavport",
"=",
"443",
";",
"}",
"else",
"if",
"(",
"$",
"webdavendpoint",
"[",
"'scheme'",
"]",
"===",
"'http'",
")",
"{",
"$",
"webdavtype",
"=",
"''",
";",
"$",
"webdavport",
"=",
"80",
";",
"}",
"// Override default port, if a specific one is set.",
"if",
"(",
"isset",
"(",
"$",
"webdavendpoint",
"[",
"'port'",
"]",
")",
")",
"{",
"$",
"webdavport",
"=",
"$",
"webdavendpoint",
"[",
"'port'",
"]",
";",
"}",
"// Authentication method is `bearer` for OAuth 2. Pass oauth client from which WebDAV obtains the token when needed.",
"$",
"dav",
"=",
"new",
"\\",
"webdav_client",
"(",
"$",
"server",
",",
"''",
",",
"''",
",",
"'bearer'",
",",
"$",
"webdavtype",
",",
"$",
"this",
"->",
"systemoauthclient",
"->",
"get_accesstoken",
"(",
")",
"->",
"token",
",",
"$",
"webdavendpoint",
"[",
"'path'",
"]",
")",
";",
"$",
"dav",
"->",
"port",
"=",
"$",
"webdavport",
";",
"$",
"dav",
"->",
"debug",
"=",
"false",
";",
"return",
"$",
"dav",
";",
"}"
] |
Creates a new webdav_client for the system account.
@return \webdav_client
@throws configuration_exception
|
[
"Creates",
"a",
"new",
"webdav_client",
"for",
"the",
"system",
"account",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/nextcloud/classes/access_controlled_link_manager.php#L288-L313
|
218,566
|
moodle/moodle
|
repository/nextcloud/classes/access_controlled_link_manager.php
|
access_controlled_link_manager.create_storage_folder
|
public function create_storage_folder($controlledlinkfoldername, $webdavclient) {
$parsedwebdavurl = issuer_management::parse_endpoint_url('webdav', $this->issuer);
$webdavprefix = $parsedwebdavurl['path'];
// Checks whether folder exist and creates non-existent folders.
$webdavclient->open();
$isdir = $webdavclient->is_dir($webdavprefix . $controlledlinkfoldername);
// Folder already exist, continue.
if (!$isdir) {
$responsecreateshare = $webdavclient->mkcol($webdavprefix . $controlledlinkfoldername);
if ($responsecreateshare != 201) {
$webdavclient->close();
throw new request_exception(array('instance' => $this->repositoryname,
'errormessage' => get_string('contactadminwith', 'repository_nextcloud',
'The folder to store files in the user account could not be created.')));
}
}
$webdavclient->close();
}
|
php
|
public function create_storage_folder($controlledlinkfoldername, $webdavclient) {
$parsedwebdavurl = issuer_management::parse_endpoint_url('webdav', $this->issuer);
$webdavprefix = $parsedwebdavurl['path'];
// Checks whether folder exist and creates non-existent folders.
$webdavclient->open();
$isdir = $webdavclient->is_dir($webdavprefix . $controlledlinkfoldername);
// Folder already exist, continue.
if (!$isdir) {
$responsecreateshare = $webdavclient->mkcol($webdavprefix . $controlledlinkfoldername);
if ($responsecreateshare != 201) {
$webdavclient->close();
throw new request_exception(array('instance' => $this->repositoryname,
'errormessage' => get_string('contactadminwith', 'repository_nextcloud',
'The folder to store files in the user account could not be created.')));
}
}
$webdavclient->close();
}
|
[
"public",
"function",
"create_storage_folder",
"(",
"$",
"controlledlinkfoldername",
",",
"$",
"webdavclient",
")",
"{",
"$",
"parsedwebdavurl",
"=",
"issuer_management",
"::",
"parse_endpoint_url",
"(",
"'webdav'",
",",
"$",
"this",
"->",
"issuer",
")",
";",
"$",
"webdavprefix",
"=",
"$",
"parsedwebdavurl",
"[",
"'path'",
"]",
";",
"// Checks whether folder exist and creates non-existent folders.",
"$",
"webdavclient",
"->",
"open",
"(",
")",
";",
"$",
"isdir",
"=",
"$",
"webdavclient",
"->",
"is_dir",
"(",
"$",
"webdavprefix",
".",
"$",
"controlledlinkfoldername",
")",
";",
"// Folder already exist, continue.",
"if",
"(",
"!",
"$",
"isdir",
")",
"{",
"$",
"responsecreateshare",
"=",
"$",
"webdavclient",
"->",
"mkcol",
"(",
"$",
"webdavprefix",
".",
"$",
"controlledlinkfoldername",
")",
";",
"if",
"(",
"$",
"responsecreateshare",
"!=",
"201",
")",
"{",
"$",
"webdavclient",
"->",
"close",
"(",
")",
";",
"throw",
"new",
"request_exception",
"(",
"array",
"(",
"'instance'",
"=>",
"$",
"this",
"->",
"repositoryname",
",",
"'errormessage'",
"=>",
"get_string",
"(",
"'contactadminwith'",
",",
"'repository_nextcloud'",
",",
"'The folder to store files in the user account could not be created.'",
")",
")",
")",
";",
"}",
"}",
"$",
"webdavclient",
"->",
"close",
"(",
")",
";",
"}"
] |
Creates a folder to store access controlled links.
@param string $controlledlinkfoldername
@param \webdav_client $webdavclient
@throws \coding_exception
@throws configuration_exception
@throws request_exception
|
[
"Creates",
"a",
"folder",
"to",
"store",
"access",
"controlled",
"links",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/nextcloud/classes/access_controlled_link_manager.php#L322-L340
|
218,567
|
moodle/moodle
|
repository/nextcloud/classes/access_controlled_link_manager.php
|
access_controlled_link_manager.find_share_in_sysaccount
|
public function find_share_in_sysaccount($path) {
$systemaccount = \core\oauth2\api::get_system_account($this->issuer);
$systemaccountuser = $systemaccount->get('username');
// Find out share ID from user files.
$ocsparams = [
'path' => $path,
'reshares' => true
];
$getsharesresponse = $this->ocsclient->call('get_shares', $ocsparams);
$xml = simplexml_load_string($getsharesresponse);
$validelement = array();
foreach ($fileid = $xml->data->element as $element) {
if ($element->share_with == $systemaccountuser) {
$validelement = $element;
break;
}
}
if (empty($validelement)) {
throw new request_exception(array('instance' => $this->repositoryname,
'errormessage' => get_string('filenotaccessed', 'repository_nextcloud')));
}
$shareid = (int) $validelement->id;
// Use share id to find file name in system account's context.
$ocsparams = [
'share_id' => $shareid
];
$shareinformation = $this->systemocsclient->call('get_information_of_share', $ocsparams);
$xml = simplexml_load_string($shareinformation);
foreach ($fileid = $xml->data->element as $element) {
if ($element->share_with == $systemaccountuser) {
$validfile = $element;
break;
}
}
if (empty($validfile)) {
throw new request_exception(array('instance' => $this->repositoryname,
'errormessage' => get_string('filenotaccessed', 'repository_nextcloud')));
}
return [
'shareid' => $shareid,
'filetarget' => (string) $validfile->file_target
];
}
|
php
|
public function find_share_in_sysaccount($path) {
$systemaccount = \core\oauth2\api::get_system_account($this->issuer);
$systemaccountuser = $systemaccount->get('username');
// Find out share ID from user files.
$ocsparams = [
'path' => $path,
'reshares' => true
];
$getsharesresponse = $this->ocsclient->call('get_shares', $ocsparams);
$xml = simplexml_load_string($getsharesresponse);
$validelement = array();
foreach ($fileid = $xml->data->element as $element) {
if ($element->share_with == $systemaccountuser) {
$validelement = $element;
break;
}
}
if (empty($validelement)) {
throw new request_exception(array('instance' => $this->repositoryname,
'errormessage' => get_string('filenotaccessed', 'repository_nextcloud')));
}
$shareid = (int) $validelement->id;
// Use share id to find file name in system account's context.
$ocsparams = [
'share_id' => $shareid
];
$shareinformation = $this->systemocsclient->call('get_information_of_share', $ocsparams);
$xml = simplexml_load_string($shareinformation);
foreach ($fileid = $xml->data->element as $element) {
if ($element->share_with == $systemaccountuser) {
$validfile = $element;
break;
}
}
if (empty($validfile)) {
throw new request_exception(array('instance' => $this->repositoryname,
'errormessage' => get_string('filenotaccessed', 'repository_nextcloud')));
}
return [
'shareid' => $shareid,
'filetarget' => (string) $validfile->file_target
];
}
|
[
"public",
"function",
"find_share_in_sysaccount",
"(",
"$",
"path",
")",
"{",
"$",
"systemaccount",
"=",
"\\",
"core",
"\\",
"oauth2",
"\\",
"api",
"::",
"get_system_account",
"(",
"$",
"this",
"->",
"issuer",
")",
";",
"$",
"systemaccountuser",
"=",
"$",
"systemaccount",
"->",
"get",
"(",
"'username'",
")",
";",
"// Find out share ID from user files.",
"$",
"ocsparams",
"=",
"[",
"'path'",
"=>",
"$",
"path",
",",
"'reshares'",
"=>",
"true",
"]",
";",
"$",
"getsharesresponse",
"=",
"$",
"this",
"->",
"ocsclient",
"->",
"call",
"(",
"'get_shares'",
",",
"$",
"ocsparams",
")",
";",
"$",
"xml",
"=",
"simplexml_load_string",
"(",
"$",
"getsharesresponse",
")",
";",
"$",
"validelement",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"fileid",
"=",
"$",
"xml",
"->",
"data",
"->",
"element",
"as",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"element",
"->",
"share_with",
"==",
"$",
"systemaccountuser",
")",
"{",
"$",
"validelement",
"=",
"$",
"element",
";",
"break",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"validelement",
")",
")",
"{",
"throw",
"new",
"request_exception",
"(",
"array",
"(",
"'instance'",
"=>",
"$",
"this",
"->",
"repositoryname",
",",
"'errormessage'",
"=>",
"get_string",
"(",
"'filenotaccessed'",
",",
"'repository_nextcloud'",
")",
")",
")",
";",
"}",
"$",
"shareid",
"=",
"(",
"int",
")",
"$",
"validelement",
"->",
"id",
";",
"// Use share id to find file name in system account's context.",
"$",
"ocsparams",
"=",
"[",
"'share_id'",
"=>",
"$",
"shareid",
"]",
";",
"$",
"shareinformation",
"=",
"$",
"this",
"->",
"systemocsclient",
"->",
"call",
"(",
"'get_information_of_share'",
",",
"$",
"ocsparams",
")",
";",
"$",
"xml",
"=",
"simplexml_load_string",
"(",
"$",
"shareinformation",
")",
";",
"foreach",
"(",
"$",
"fileid",
"=",
"$",
"xml",
"->",
"data",
"->",
"element",
"as",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"element",
"->",
"share_with",
"==",
"$",
"systemaccountuser",
")",
"{",
"$",
"validfile",
"=",
"$",
"element",
";",
"break",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"validfile",
")",
")",
"{",
"throw",
"new",
"request_exception",
"(",
"array",
"(",
"'instance'",
"=>",
"$",
"this",
"->",
"repositoryname",
",",
"'errormessage'",
"=>",
"get_string",
"(",
"'filenotaccessed'",
",",
"'repository_nextcloud'",
")",
")",
")",
";",
"}",
"return",
"[",
"'shareid'",
"=>",
"$",
"shareid",
",",
"'filetarget'",
"=>",
"(",
"string",
")",
"$",
"validfile",
"->",
"file_target",
"]",
";",
"}"
] |
Find a file that has previously been shared with the system account.
@param string $path Path to file in user context.
@return array shareid: ID of share, filetarget: path to file in sys account.
@throws request_exception If the share cannot be resolved.
|
[
"Find",
"a",
"file",
"that",
"has",
"previously",
"been",
"shared",
"with",
"the",
"system",
"account",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/nextcloud/classes/access_controlled_link_manager.php#L409-L456
|
218,568
|
moodle/moodle
|
repository/nextcloud/classes/access_controlled_link_manager.php
|
access_controlled_link_manager.download_for_offline_usage
|
public function download_for_offline_usage(string $srcpath, string $targetpath): void {
$this->systemwebdavclient->open();
$webdavendpoint = issuer_management::parse_endpoint_url('webdav', $this->issuer);
$srcpath = ltrim($srcpath, '/');
$sourcepath = $webdavendpoint['path'] . $srcpath;
// Write file into temp location.
if (!$this->systemwebdavclient->get_file($sourcepath, $targetpath)) {
$this->systemwebdavclient->close();
throw new repository_exception('cannotdownload', 'repository');
}
$this->systemwebdavclient->close();
}
|
php
|
public function download_for_offline_usage(string $srcpath, string $targetpath): void {
$this->systemwebdavclient->open();
$webdavendpoint = issuer_management::parse_endpoint_url('webdav', $this->issuer);
$srcpath = ltrim($srcpath, '/');
$sourcepath = $webdavendpoint['path'] . $srcpath;
// Write file into temp location.
if (!$this->systemwebdavclient->get_file($sourcepath, $targetpath)) {
$this->systemwebdavclient->close();
throw new repository_exception('cannotdownload', 'repository');
}
$this->systemwebdavclient->close();
}
|
[
"public",
"function",
"download_for_offline_usage",
"(",
"string",
"$",
"srcpath",
",",
"string",
"$",
"targetpath",
")",
":",
"void",
"{",
"$",
"this",
"->",
"systemwebdavclient",
"->",
"open",
"(",
")",
";",
"$",
"webdavendpoint",
"=",
"issuer_management",
"::",
"parse_endpoint_url",
"(",
"'webdav'",
",",
"$",
"this",
"->",
"issuer",
")",
";",
"$",
"srcpath",
"=",
"ltrim",
"(",
"$",
"srcpath",
",",
"'/'",
")",
";",
"$",
"sourcepath",
"=",
"$",
"webdavendpoint",
"[",
"'path'",
"]",
".",
"$",
"srcpath",
";",
"// Write file into temp location.",
"if",
"(",
"!",
"$",
"this",
"->",
"systemwebdavclient",
"->",
"get_file",
"(",
"$",
"sourcepath",
",",
"$",
"targetpath",
")",
")",
"{",
"$",
"this",
"->",
"systemwebdavclient",
"->",
"close",
"(",
")",
";",
"throw",
"new",
"repository_exception",
"(",
"'cannotdownload'",
",",
"'repository'",
")",
";",
"}",
"$",
"this",
"->",
"systemwebdavclient",
"->",
"close",
"(",
")",
";",
"}"
] |
Download a file from the system account for the purpose of offline usage.
@param string $srcpath Name of a file owned by the system account
@param string $targetpath Temporary filename in Moodle
@throws repository_exception The download was unsuccessful, maybe the file does not exist.
|
[
"Download",
"a",
"file",
"from",
"the",
"system",
"account",
"for",
"the",
"purpose",
"of",
"offline",
"usage",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/nextcloud/classes/access_controlled_link_manager.php#L464-L476
|
218,569
|
moodle/moodle
|
analytics/classes/manager.php
|
manager.check_can_list_insights
|
public static function check_can_list_insights(\context $context, bool $return = false) {
global $USER;
if ($context->contextlevel === CONTEXT_USER && $context->instanceid == $USER->id) {
$capability = 'moodle/analytics:listowninsights';
} else {
$capability = 'moodle/analytics:listinsights';
}
if ($return) {
return has_capability($capability, $context);
} else {
require_capability($capability, $context);
}
}
|
php
|
public static function check_can_list_insights(\context $context, bool $return = false) {
global $USER;
if ($context->contextlevel === CONTEXT_USER && $context->instanceid == $USER->id) {
$capability = 'moodle/analytics:listowninsights';
} else {
$capability = 'moodle/analytics:listinsights';
}
if ($return) {
return has_capability($capability, $context);
} else {
require_capability($capability, $context);
}
}
|
[
"public",
"static",
"function",
"check_can_list_insights",
"(",
"\\",
"context",
"$",
"context",
",",
"bool",
"$",
"return",
"=",
"false",
")",
"{",
"global",
"$",
"USER",
";",
"if",
"(",
"$",
"context",
"->",
"contextlevel",
"===",
"CONTEXT_USER",
"&&",
"$",
"context",
"->",
"instanceid",
"==",
"$",
"USER",
"->",
"id",
")",
"{",
"$",
"capability",
"=",
"'moodle/analytics:listowninsights'",
";",
"}",
"else",
"{",
"$",
"capability",
"=",
"'moodle/analytics:listinsights'",
";",
"}",
"if",
"(",
"$",
"return",
")",
"{",
"return",
"has_capability",
"(",
"$",
"capability",
",",
"$",
"context",
")",
";",
"}",
"else",
"{",
"require_capability",
"(",
"$",
"capability",
",",
"$",
"context",
")",
";",
"}",
"}"
] |
Checks that the user can list that context insights
@throws \required_capability_exception
@param \context $context
@param bool $return The method returns a bool if true.
@return void
|
[
"Checks",
"that",
"the",
"user",
"can",
"list",
"that",
"context",
"insights"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/manager.php#L86-L100
|
218,570
|
moodle/moodle
|
analytics/classes/manager.php
|
manager.get_all_models
|
public static function get_all_models($enabled = false, $trained = false, $predictioncontext = false) {
global $DB;
$params = array();
$sql = "SELECT am.* FROM {analytics_models} am";
if ($enabled || $trained || $predictioncontext) {
$conditions = [];
if ($enabled) {
$conditions[] = 'am.enabled = :enabled';
$params['enabled'] = 1;
}
if ($trained) {
$conditions[] = 'am.trained = :trained';
$params['trained'] = 1;
}
if ($predictioncontext) {
$conditions[] = "EXISTS (SELECT 'x'
FROM {analytics_predictions} ap
WHERE ap.modelid = am.id AND ap.contextid = :contextid)";
$params['contextid'] = $predictioncontext->id;
}
$sql .= ' WHERE ' . implode(' AND ', $conditions);
}
$sql .= ' ORDER BY am.enabled DESC, am.timemodified DESC';
$modelobjs = $DB->get_records_sql($sql, $params);
$models = array();
foreach ($modelobjs as $modelobj) {
$model = new \core_analytics\model($modelobj);
if ($model->is_available()) {
$models[$modelobj->id] = $model;
}
}
return $models;
}
|
php
|
public static function get_all_models($enabled = false, $trained = false, $predictioncontext = false) {
global $DB;
$params = array();
$sql = "SELECT am.* FROM {analytics_models} am";
if ($enabled || $trained || $predictioncontext) {
$conditions = [];
if ($enabled) {
$conditions[] = 'am.enabled = :enabled';
$params['enabled'] = 1;
}
if ($trained) {
$conditions[] = 'am.trained = :trained';
$params['trained'] = 1;
}
if ($predictioncontext) {
$conditions[] = "EXISTS (SELECT 'x'
FROM {analytics_predictions} ap
WHERE ap.modelid = am.id AND ap.contextid = :contextid)";
$params['contextid'] = $predictioncontext->id;
}
$sql .= ' WHERE ' . implode(' AND ', $conditions);
}
$sql .= ' ORDER BY am.enabled DESC, am.timemodified DESC';
$modelobjs = $DB->get_records_sql($sql, $params);
$models = array();
foreach ($modelobjs as $modelobj) {
$model = new \core_analytics\model($modelobj);
if ($model->is_available()) {
$models[$modelobj->id] = $model;
}
}
return $models;
}
|
[
"public",
"static",
"function",
"get_all_models",
"(",
"$",
"enabled",
"=",
"false",
",",
"$",
"trained",
"=",
"false",
",",
"$",
"predictioncontext",
"=",
"false",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"params",
"=",
"array",
"(",
")",
";",
"$",
"sql",
"=",
"\"SELECT am.* FROM {analytics_models} am\"",
";",
"if",
"(",
"$",
"enabled",
"||",
"$",
"trained",
"||",
"$",
"predictioncontext",
")",
"{",
"$",
"conditions",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"enabled",
")",
"{",
"$",
"conditions",
"[",
"]",
"=",
"'am.enabled = :enabled'",
";",
"$",
"params",
"[",
"'enabled'",
"]",
"=",
"1",
";",
"}",
"if",
"(",
"$",
"trained",
")",
"{",
"$",
"conditions",
"[",
"]",
"=",
"'am.trained = :trained'",
";",
"$",
"params",
"[",
"'trained'",
"]",
"=",
"1",
";",
"}",
"if",
"(",
"$",
"predictioncontext",
")",
"{",
"$",
"conditions",
"[",
"]",
"=",
"\"EXISTS (SELECT 'x'\n FROM {analytics_predictions} ap\n WHERE ap.modelid = am.id AND ap.contextid = :contextid)\"",
";",
"$",
"params",
"[",
"'contextid'",
"]",
"=",
"$",
"predictioncontext",
"->",
"id",
";",
"}",
"$",
"sql",
".=",
"' WHERE '",
".",
"implode",
"(",
"' AND '",
",",
"$",
"conditions",
")",
";",
"}",
"$",
"sql",
".=",
"' ORDER BY am.enabled DESC, am.timemodified DESC'",
";",
"$",
"modelobjs",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"$",
"models",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"modelobjs",
"as",
"$",
"modelobj",
")",
"{",
"$",
"model",
"=",
"new",
"\\",
"core_analytics",
"\\",
"model",
"(",
"$",
"modelobj",
")",
";",
"if",
"(",
"$",
"model",
"->",
"is_available",
"(",
")",
")",
"{",
"$",
"models",
"[",
"$",
"modelobj",
"->",
"id",
"]",
"=",
"$",
"model",
";",
"}",
"}",
"return",
"$",
"models",
";",
"}"
] |
Returns all system models that match the provided filters.
@param bool $enabled
@param bool $trained
@param \context|false $predictioncontext
@return \core_analytics\model[]
|
[
"Returns",
"all",
"system",
"models",
"that",
"match",
"the",
"provided",
"filters",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/manager.php#L110-L147
|
218,571
|
moodle/moodle
|
analytics/classes/manager.php
|
manager.get_predictions_processor
|
public static function get_predictions_processor($predictionclass = false, $checkisready = true) {
// We want 0 or 1 so we can use it as an array key for caching.
$checkisready = intval($checkisready);
if (!$predictionclass) {
$predictionclass = get_config('analytics', 'predictionsprocessor');
}
if (empty($predictionclass)) {
// Use the default one if nothing set.
$predictionclass = self::default_mlbackend();
}
if (!class_exists($predictionclass)) {
throw new \coding_exception('Invalid predictions processor ' . $predictionclass . '.');
}
$interfaces = class_implements($predictionclass);
if (empty($interfaces['core_analytics\predictor'])) {
throw new \coding_exception($predictionclass . ' should implement \core_analytics\predictor.');
}
// Return it from the cached list.
if (!isset(self::$predictionprocessors[$checkisready][$predictionclass])) {
$instance = new $predictionclass();
if ($checkisready) {
$isready = $instance->is_ready();
if ($isready !== true) {
throw new \moodle_exception('errorprocessornotready', 'analytics', '', $isready);
}
}
self::$predictionprocessors[$checkisready][$predictionclass] = $instance;
}
return self::$predictionprocessors[$checkisready][$predictionclass];
}
|
php
|
public static function get_predictions_processor($predictionclass = false, $checkisready = true) {
// We want 0 or 1 so we can use it as an array key for caching.
$checkisready = intval($checkisready);
if (!$predictionclass) {
$predictionclass = get_config('analytics', 'predictionsprocessor');
}
if (empty($predictionclass)) {
// Use the default one if nothing set.
$predictionclass = self::default_mlbackend();
}
if (!class_exists($predictionclass)) {
throw new \coding_exception('Invalid predictions processor ' . $predictionclass . '.');
}
$interfaces = class_implements($predictionclass);
if (empty($interfaces['core_analytics\predictor'])) {
throw new \coding_exception($predictionclass . ' should implement \core_analytics\predictor.');
}
// Return it from the cached list.
if (!isset(self::$predictionprocessors[$checkisready][$predictionclass])) {
$instance = new $predictionclass();
if ($checkisready) {
$isready = $instance->is_ready();
if ($isready !== true) {
throw new \moodle_exception('errorprocessornotready', 'analytics', '', $isready);
}
}
self::$predictionprocessors[$checkisready][$predictionclass] = $instance;
}
return self::$predictionprocessors[$checkisready][$predictionclass];
}
|
[
"public",
"static",
"function",
"get_predictions_processor",
"(",
"$",
"predictionclass",
"=",
"false",
",",
"$",
"checkisready",
"=",
"true",
")",
"{",
"// We want 0 or 1 so we can use it as an array key for caching.",
"$",
"checkisready",
"=",
"intval",
"(",
"$",
"checkisready",
")",
";",
"if",
"(",
"!",
"$",
"predictionclass",
")",
"{",
"$",
"predictionclass",
"=",
"get_config",
"(",
"'analytics'",
",",
"'predictionsprocessor'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"predictionclass",
")",
")",
"{",
"// Use the default one if nothing set.",
"$",
"predictionclass",
"=",
"self",
"::",
"default_mlbackend",
"(",
")",
";",
"}",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"predictionclass",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Invalid predictions processor '",
".",
"$",
"predictionclass",
".",
"'.'",
")",
";",
"}",
"$",
"interfaces",
"=",
"class_implements",
"(",
"$",
"predictionclass",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"interfaces",
"[",
"'core_analytics\\predictor'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"$",
"predictionclass",
".",
"' should implement \\core_analytics\\predictor.'",
")",
";",
"}",
"// Return it from the cached list.",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"predictionprocessors",
"[",
"$",
"checkisready",
"]",
"[",
"$",
"predictionclass",
"]",
")",
")",
"{",
"$",
"instance",
"=",
"new",
"$",
"predictionclass",
"(",
")",
";",
"if",
"(",
"$",
"checkisready",
")",
"{",
"$",
"isready",
"=",
"$",
"instance",
"->",
"is_ready",
"(",
")",
";",
"if",
"(",
"$",
"isready",
"!==",
"true",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'errorprocessornotready'",
",",
"'analytics'",
",",
"''",
",",
"$",
"isready",
")",
";",
"}",
"}",
"self",
"::",
"$",
"predictionprocessors",
"[",
"$",
"checkisready",
"]",
"[",
"$",
"predictionclass",
"]",
"=",
"$",
"instance",
";",
"}",
"return",
"self",
"::",
"$",
"predictionprocessors",
"[",
"$",
"checkisready",
"]",
"[",
"$",
"predictionclass",
"]",
";",
"}"
] |
Returns the provided predictions processor class.
@param false|string $predictionclass Returns the system default processor if false
@param bool $checkisready
@return \core_analytics\predictor
|
[
"Returns",
"the",
"provided",
"predictions",
"processor",
"class",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/manager.php#L156-L193
|
218,572
|
moodle/moodle
|
analytics/classes/manager.php
|
manager.get_all_prediction_processors
|
public static function get_all_prediction_processors() {
$mlbackends = \core_component::get_plugin_list('mlbackend');
$predictionprocessors = array();
foreach ($mlbackends as $mlbackend => $unused) {
$classfullpath = '\mlbackend_' . $mlbackend . '\processor';
$predictionprocessors[$classfullpath] = self::get_predictions_processor($classfullpath, false);
}
return $predictionprocessors;
}
|
php
|
public static function get_all_prediction_processors() {
$mlbackends = \core_component::get_plugin_list('mlbackend');
$predictionprocessors = array();
foreach ($mlbackends as $mlbackend => $unused) {
$classfullpath = '\mlbackend_' . $mlbackend . '\processor';
$predictionprocessors[$classfullpath] = self::get_predictions_processor($classfullpath, false);
}
return $predictionprocessors;
}
|
[
"public",
"static",
"function",
"get_all_prediction_processors",
"(",
")",
"{",
"$",
"mlbackends",
"=",
"\\",
"core_component",
"::",
"get_plugin_list",
"(",
"'mlbackend'",
")",
";",
"$",
"predictionprocessors",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"mlbackends",
"as",
"$",
"mlbackend",
"=>",
"$",
"unused",
")",
"{",
"$",
"classfullpath",
"=",
"'\\mlbackend_'",
".",
"$",
"mlbackend",
".",
"'\\processor'",
";",
"$",
"predictionprocessors",
"[",
"$",
"classfullpath",
"]",
"=",
"self",
"::",
"get_predictions_processor",
"(",
"$",
"classfullpath",
",",
"false",
")",
";",
"}",
"return",
"$",
"predictionprocessors",
";",
"}"
] |
Return all system predictions processors.
@return \core_analytics\predictor[]
|
[
"Return",
"all",
"system",
"predictions",
"processors",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/manager.php#L200-L210
|
218,573
|
moodle/moodle
|
analytics/classes/manager.php
|
manager.get_predictions_processor_name
|
public static function get_predictions_processor_name(\core_analytics\predictor $predictionsprocessor) {
$component = substr(get_class($predictionsprocessor), 0, strpos(get_class($predictionsprocessor), '\\', 1));
return get_string('pluginname', $component);
}
|
php
|
public static function get_predictions_processor_name(\core_analytics\predictor $predictionsprocessor) {
$component = substr(get_class($predictionsprocessor), 0, strpos(get_class($predictionsprocessor), '\\', 1));
return get_string('pluginname', $component);
}
|
[
"public",
"static",
"function",
"get_predictions_processor_name",
"(",
"\\",
"core_analytics",
"\\",
"predictor",
"$",
"predictionsprocessor",
")",
"{",
"$",
"component",
"=",
"substr",
"(",
"get_class",
"(",
"$",
"predictionsprocessor",
")",
",",
"0",
",",
"strpos",
"(",
"get_class",
"(",
"$",
"predictionsprocessor",
")",
",",
"'\\\\'",
",",
"1",
")",
")",
";",
"return",
"get_string",
"(",
"'pluginname'",
",",
"$",
"component",
")",
";",
"}"
] |
Returns the name of the provided predictions processor.
@param \core_analytics\predictor $predictionsprocessor
@return string
|
[
"Returns",
"the",
"name",
"of",
"the",
"provided",
"predictions",
"processor",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/manager.php#L218-L221
|
218,574
|
moodle/moodle
|
analytics/classes/manager.php
|
manager.is_mlbackend_used
|
public static function is_mlbackend_used($plugin) {
$models = self::get_all_models();
foreach ($models as $model) {
$processor = $model->get_predictions_processor();
$noprefixnamespace = ltrim(get_class($processor), '\\');
$processorplugin = substr($noprefixnamespace, 0, strpos($noprefixnamespace, '\\'));
if ($processorplugin == $plugin) {
return true;
}
}
// Default predictions processor.
$defaultprocessorclass = get_config('analytics', 'predictionsprocessor');
$pluginclass = '\\' . $plugin . '\\processor';
if ($pluginclass === $defaultprocessorclass) {
return true;
}
return false;
}
|
php
|
public static function is_mlbackend_used($plugin) {
$models = self::get_all_models();
foreach ($models as $model) {
$processor = $model->get_predictions_processor();
$noprefixnamespace = ltrim(get_class($processor), '\\');
$processorplugin = substr($noprefixnamespace, 0, strpos($noprefixnamespace, '\\'));
if ($processorplugin == $plugin) {
return true;
}
}
// Default predictions processor.
$defaultprocessorclass = get_config('analytics', 'predictionsprocessor');
$pluginclass = '\\' . $plugin . '\\processor';
if ($pluginclass === $defaultprocessorclass) {
return true;
}
return false;
}
|
[
"public",
"static",
"function",
"is_mlbackend_used",
"(",
"$",
"plugin",
")",
"{",
"$",
"models",
"=",
"self",
"::",
"get_all_models",
"(",
")",
";",
"foreach",
"(",
"$",
"models",
"as",
"$",
"model",
")",
"{",
"$",
"processor",
"=",
"$",
"model",
"->",
"get_predictions_processor",
"(",
")",
";",
"$",
"noprefixnamespace",
"=",
"ltrim",
"(",
"get_class",
"(",
"$",
"processor",
")",
",",
"'\\\\'",
")",
";",
"$",
"processorplugin",
"=",
"substr",
"(",
"$",
"noprefixnamespace",
",",
"0",
",",
"strpos",
"(",
"$",
"noprefixnamespace",
",",
"'\\\\'",
")",
")",
";",
"if",
"(",
"$",
"processorplugin",
"==",
"$",
"plugin",
")",
"{",
"return",
"true",
";",
"}",
"}",
"// Default predictions processor.",
"$",
"defaultprocessorclass",
"=",
"get_config",
"(",
"'analytics'",
",",
"'predictionsprocessor'",
")",
";",
"$",
"pluginclass",
"=",
"'\\\\'",
".",
"$",
"plugin",
".",
"'\\\\processor'",
";",
"if",
"(",
"$",
"pluginclass",
"===",
"$",
"defaultprocessorclass",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Whether the provided plugin is used by any model.
@param string $plugin
@return bool
|
[
"Whether",
"the",
"provided",
"plugin",
"is",
"used",
"by",
"any",
"model",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/manager.php#L229-L248
|
218,575
|
moodle/moodle
|
analytics/classes/manager.php
|
manager.get_all_time_splittings
|
public static function get_all_time_splittings() {
if (self::$alltimesplittings !== null) {
return self::$alltimesplittings;
}
$classes = self::get_analytics_classes('time_splitting');
self::$alltimesplittings = [];
foreach ($classes as $fullclassname => $classpath) {
$instance = self::get_time_splitting($fullclassname);
// We need to check that it is a valid time splitting method, it may be an abstract class.
if ($instance) {
self::$alltimesplittings[$instance->get_id()] = $instance;
}
}
return self::$alltimesplittings;
}
|
php
|
public static function get_all_time_splittings() {
if (self::$alltimesplittings !== null) {
return self::$alltimesplittings;
}
$classes = self::get_analytics_classes('time_splitting');
self::$alltimesplittings = [];
foreach ($classes as $fullclassname => $classpath) {
$instance = self::get_time_splitting($fullclassname);
// We need to check that it is a valid time splitting method, it may be an abstract class.
if ($instance) {
self::$alltimesplittings[$instance->get_id()] = $instance;
}
}
return self::$alltimesplittings;
}
|
[
"public",
"static",
"function",
"get_all_time_splittings",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"alltimesplittings",
"!==",
"null",
")",
"{",
"return",
"self",
"::",
"$",
"alltimesplittings",
";",
"}",
"$",
"classes",
"=",
"self",
"::",
"get_analytics_classes",
"(",
"'time_splitting'",
")",
";",
"self",
"::",
"$",
"alltimesplittings",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"classes",
"as",
"$",
"fullclassname",
"=>",
"$",
"classpath",
")",
"{",
"$",
"instance",
"=",
"self",
"::",
"get_time_splitting",
"(",
"$",
"fullclassname",
")",
";",
"// We need to check that it is a valid time splitting method, it may be an abstract class.",
"if",
"(",
"$",
"instance",
")",
"{",
"self",
"::",
"$",
"alltimesplittings",
"[",
"$",
"instance",
"->",
"get_id",
"(",
")",
"]",
"=",
"$",
"instance",
";",
"}",
"}",
"return",
"self",
"::",
"$",
"alltimesplittings",
";",
"}"
] |
Get all available time splitting methods.
@return \core_analytics\local\time_splitting\base[]
|
[
"Get",
"all",
"available",
"time",
"splitting",
"methods",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/manager.php#L255-L272
|
218,576
|
moodle/moodle
|
analytics/classes/manager.php
|
manager.get_time_splitting_methods_for_evaluation
|
public static function get_time_splitting_methods_for_evaluation(bool $all = false) {
if ($all === false) {
if ($enabledtimesplittings = get_config('analytics', 'defaulttimesplittingsevaluation')) {
$enabledtimesplittings = array_flip(explode(',', $enabledtimesplittings));
}
}
$timesplittings = self::get_all_time_splittings();
foreach ($timesplittings as $key => $timesplitting) {
if (!$timesplitting->valid_for_evaluation()) {
unset($timesplittings[$key]);
}
if ($all === false) {
// We remove the ones that are not enabled. This also respects the default value (all methods enabled).
if (!empty($enabledtimesplittings) && !isset($enabledtimesplittings[$key])) {
unset($timesplittings[$key]);
}
}
}
return $timesplittings;
}
|
php
|
public static function get_time_splitting_methods_for_evaluation(bool $all = false) {
if ($all === false) {
if ($enabledtimesplittings = get_config('analytics', 'defaulttimesplittingsevaluation')) {
$enabledtimesplittings = array_flip(explode(',', $enabledtimesplittings));
}
}
$timesplittings = self::get_all_time_splittings();
foreach ($timesplittings as $key => $timesplitting) {
if (!$timesplitting->valid_for_evaluation()) {
unset($timesplittings[$key]);
}
if ($all === false) {
// We remove the ones that are not enabled. This also respects the default value (all methods enabled).
if (!empty($enabledtimesplittings) && !isset($enabledtimesplittings[$key])) {
unset($timesplittings[$key]);
}
}
}
return $timesplittings;
}
|
[
"public",
"static",
"function",
"get_time_splitting_methods_for_evaluation",
"(",
"bool",
"$",
"all",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"all",
"===",
"false",
")",
"{",
"if",
"(",
"$",
"enabledtimesplittings",
"=",
"get_config",
"(",
"'analytics'",
",",
"'defaulttimesplittingsevaluation'",
")",
")",
"{",
"$",
"enabledtimesplittings",
"=",
"array_flip",
"(",
"explode",
"(",
"','",
",",
"$",
"enabledtimesplittings",
")",
")",
";",
"}",
"}",
"$",
"timesplittings",
"=",
"self",
"::",
"get_all_time_splittings",
"(",
")",
";",
"foreach",
"(",
"$",
"timesplittings",
"as",
"$",
"key",
"=>",
"$",
"timesplitting",
")",
"{",
"if",
"(",
"!",
"$",
"timesplitting",
"->",
"valid_for_evaluation",
"(",
")",
")",
"{",
"unset",
"(",
"$",
"timesplittings",
"[",
"$",
"key",
"]",
")",
";",
"}",
"if",
"(",
"$",
"all",
"===",
"false",
")",
"{",
"// We remove the ones that are not enabled. This also respects the default value (all methods enabled).",
"if",
"(",
"!",
"empty",
"(",
"$",
"enabledtimesplittings",
")",
"&&",
"!",
"isset",
"(",
"$",
"enabledtimesplittings",
"[",
"$",
"key",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"timesplittings",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"}",
"return",
"$",
"timesplittings",
";",
"}"
] |
Returns the time-splitting methods for model evaluation.
@param bool $all Return all the time-splitting methods that can potentially be used for evaluation or the default ones.
@return \core_analytics\local\time_splitting\base[]
|
[
"Returns",
"the",
"time",
"-",
"splitting",
"methods",
"for",
"model",
"evaluation",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/manager.php#L295-L318
|
218,577
|
moodle/moodle
|
analytics/classes/manager.php
|
manager.get_all_targets
|
public static function get_all_targets() : array {
if (self::$alltargets !== null) {
return self::$alltargets;
}
$classes = self::get_analytics_classes('target');
self::$alltargets = [];
foreach ($classes as $fullclassname => $classpath) {
$instance = self::get_target($fullclassname);
if ($instance) {
self::$alltargets[$instance->get_id()] = $instance;
}
}
return self::$alltargets;
}
|
php
|
public static function get_all_targets() : array {
if (self::$alltargets !== null) {
return self::$alltargets;
}
$classes = self::get_analytics_classes('target');
self::$alltargets = [];
foreach ($classes as $fullclassname => $classpath) {
$instance = self::get_target($fullclassname);
if ($instance) {
self::$alltargets[$instance->get_id()] = $instance;
}
}
return self::$alltargets;
}
|
[
"public",
"static",
"function",
"get_all_targets",
"(",
")",
":",
"array",
"{",
"if",
"(",
"self",
"::",
"$",
"alltargets",
"!==",
"null",
")",
"{",
"return",
"self",
"::",
"$",
"alltargets",
";",
"}",
"$",
"classes",
"=",
"self",
"::",
"get_analytics_classes",
"(",
"'target'",
")",
";",
"self",
"::",
"$",
"alltargets",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"classes",
"as",
"$",
"fullclassname",
"=>",
"$",
"classpath",
")",
"{",
"$",
"instance",
"=",
"self",
"::",
"get_target",
"(",
"$",
"fullclassname",
")",
";",
"if",
"(",
"$",
"instance",
")",
"{",
"self",
"::",
"$",
"alltargets",
"[",
"$",
"instance",
"->",
"get_id",
"(",
")",
"]",
"=",
"$",
"instance",
";",
"}",
"}",
"return",
"self",
"::",
"$",
"alltargets",
";",
"}"
] |
Return all targets in the system.
@return \core_analytics\local\target\base[]
|
[
"Return",
"all",
"targets",
"in",
"the",
"system",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/manager.php#L338-L354
|
218,578
|
moodle/moodle
|
analytics/classes/manager.php
|
manager.get_all_indicators
|
public static function get_all_indicators() {
if (self::$allindicators !== null) {
return self::$allindicators;
}
$classes = self::get_analytics_classes('indicator');
self::$allindicators = [];
foreach ($classes as $fullclassname => $classpath) {
$instance = self::get_indicator($fullclassname);
if ($instance) {
self::$allindicators[$instance->get_id()] = $instance;
}
}
return self::$allindicators;
}
|
php
|
public static function get_all_indicators() {
if (self::$allindicators !== null) {
return self::$allindicators;
}
$classes = self::get_analytics_classes('indicator');
self::$allindicators = [];
foreach ($classes as $fullclassname => $classpath) {
$instance = self::get_indicator($fullclassname);
if ($instance) {
self::$allindicators[$instance->get_id()] = $instance;
}
}
return self::$allindicators;
}
|
[
"public",
"static",
"function",
"get_all_indicators",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"allindicators",
"!==",
"null",
")",
"{",
"return",
"self",
"::",
"$",
"allindicators",
";",
"}",
"$",
"classes",
"=",
"self",
"::",
"get_analytics_classes",
"(",
"'indicator'",
")",
";",
"self",
"::",
"$",
"allindicators",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"classes",
"as",
"$",
"fullclassname",
"=>",
"$",
"classpath",
")",
"{",
"$",
"instance",
"=",
"self",
"::",
"get_indicator",
"(",
"$",
"fullclassname",
")",
";",
"if",
"(",
"$",
"instance",
")",
"{",
"self",
"::",
"$",
"allindicators",
"[",
"$",
"instance",
"->",
"get_id",
"(",
")",
"]",
"=",
"$",
"instance",
";",
"}",
"}",
"return",
"self",
"::",
"$",
"allindicators",
";",
"}"
] |
Return all system indicators.
@return \core_analytics\local\indicator\base[]
|
[
"Return",
"all",
"system",
"indicators",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/manager.php#L360-L376
|
218,579
|
moodle/moodle
|
analytics/classes/manager.php
|
manager.is_valid
|
public static function is_valid($fullclassname, $baseclass) {
if (is_subclass_of($fullclassname, $baseclass)) {
if ((new \ReflectionClass($fullclassname))->isInstantiable()) {
return true;
}
}
return false;
}
|
php
|
public static function is_valid($fullclassname, $baseclass) {
if (is_subclass_of($fullclassname, $baseclass)) {
if ((new \ReflectionClass($fullclassname))->isInstantiable()) {
return true;
}
}
return false;
}
|
[
"public",
"static",
"function",
"is_valid",
"(",
"$",
"fullclassname",
",",
"$",
"baseclass",
")",
"{",
"if",
"(",
"is_subclass_of",
"(",
"$",
"fullclassname",
",",
"$",
"baseclass",
")",
")",
"{",
"if",
"(",
"(",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"fullclassname",
")",
")",
"->",
"isInstantiable",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Returns whether a time splitting method is valid or not.
@param string $fullclassname
@param string $baseclass
@return bool
|
[
"Returns",
"whether",
"a",
"time",
"splitting",
"method",
"is",
"valid",
"or",
"not",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/manager.php#L411-L418
|
218,580
|
moodle/moodle
|
analytics/classes/manager.php
|
manager.get_analytics_logstore
|
public static function get_analytics_logstore() {
$readers = get_log_manager()->get_readers('core\log\sql_reader');
$analyticsstore = get_config('analytics', 'logstore');
if (!empty($analyticsstore) && !empty($readers[$analyticsstore])) {
$logstore = $readers[$analyticsstore];
} else if (empty($analyticsstore) && !empty($readers)) {
// The first one, it is the same default than in settings.
$logstore = reset($readers);
} else if (!empty($readers)) {
$logstore = reset($readers);
debugging('The selected log store for analytics is not available anymore. Using "' .
$logstore->get_name() . '"', DEBUG_DEVELOPER);
}
if (empty($logstore)) {
debugging('No system log stores available to use for analytics', DEBUG_DEVELOPER);
return false;
}
if (!$logstore->is_logging()) {
debugging('The selected log store for analytics "' . $logstore->get_name() .
'" is not logging activity logs', DEBUG_DEVELOPER);
}
return $logstore;
}
|
php
|
public static function get_analytics_logstore() {
$readers = get_log_manager()->get_readers('core\log\sql_reader');
$analyticsstore = get_config('analytics', 'logstore');
if (!empty($analyticsstore) && !empty($readers[$analyticsstore])) {
$logstore = $readers[$analyticsstore];
} else if (empty($analyticsstore) && !empty($readers)) {
// The first one, it is the same default than in settings.
$logstore = reset($readers);
} else if (!empty($readers)) {
$logstore = reset($readers);
debugging('The selected log store for analytics is not available anymore. Using "' .
$logstore->get_name() . '"', DEBUG_DEVELOPER);
}
if (empty($logstore)) {
debugging('No system log stores available to use for analytics', DEBUG_DEVELOPER);
return false;
}
if (!$logstore->is_logging()) {
debugging('The selected log store for analytics "' . $logstore->get_name() .
'" is not logging activity logs', DEBUG_DEVELOPER);
}
return $logstore;
}
|
[
"public",
"static",
"function",
"get_analytics_logstore",
"(",
")",
"{",
"$",
"readers",
"=",
"get_log_manager",
"(",
")",
"->",
"get_readers",
"(",
"'core\\log\\sql_reader'",
")",
";",
"$",
"analyticsstore",
"=",
"get_config",
"(",
"'analytics'",
",",
"'logstore'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"analyticsstore",
")",
"&&",
"!",
"empty",
"(",
"$",
"readers",
"[",
"$",
"analyticsstore",
"]",
")",
")",
"{",
"$",
"logstore",
"=",
"$",
"readers",
"[",
"$",
"analyticsstore",
"]",
";",
"}",
"else",
"if",
"(",
"empty",
"(",
"$",
"analyticsstore",
")",
"&&",
"!",
"empty",
"(",
"$",
"readers",
")",
")",
"{",
"// The first one, it is the same default than in settings.",
"$",
"logstore",
"=",
"reset",
"(",
"$",
"readers",
")",
";",
"}",
"else",
"if",
"(",
"!",
"empty",
"(",
"$",
"readers",
")",
")",
"{",
"$",
"logstore",
"=",
"reset",
"(",
"$",
"readers",
")",
";",
"debugging",
"(",
"'The selected log store for analytics is not available anymore. Using \"'",
".",
"$",
"logstore",
"->",
"get_name",
"(",
")",
".",
"'\"'",
",",
"DEBUG_DEVELOPER",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"logstore",
")",
")",
"{",
"debugging",
"(",
"'No system log stores available to use for analytics'",
",",
"DEBUG_DEVELOPER",
")",
";",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"logstore",
"->",
"is_logging",
"(",
")",
")",
"{",
"debugging",
"(",
"'The selected log store for analytics \"'",
".",
"$",
"logstore",
"->",
"get_name",
"(",
")",
".",
"'\" is not logging activity logs'",
",",
"DEBUG_DEVELOPER",
")",
";",
"}",
"return",
"$",
"logstore",
";",
"}"
] |
Returns the logstore used for analytics.
@return \core\log\sql_reader|false False if no log stores are enabled.
|
[
"Returns",
"the",
"logstore",
"used",
"for",
"analytics",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/manager.php#L425-L451
|
218,581
|
moodle/moodle
|
analytics/classes/manager.php
|
manager.get_indicator_calculations
|
public static function get_indicator_calculations($analysable, $starttime, $endtime, $samplesorigin) {
global $DB;
$params = array('starttime' => $starttime, 'endtime' => $endtime, 'contextid' => $analysable->get_context()->id,
'sampleorigin' => $samplesorigin);
$calculations = $DB->get_recordset('analytics_indicator_calc', $params, '', 'indicator, sampleid, value');
$existingcalculations = array();
foreach ($calculations as $calculation) {
if (empty($existingcalculations[$calculation->indicator])) {
$existingcalculations[$calculation->indicator] = array();
}
$existingcalculations[$calculation->indicator][$calculation->sampleid] = $calculation->value;
}
$calculations->close();
return $existingcalculations;
}
|
php
|
public static function get_indicator_calculations($analysable, $starttime, $endtime, $samplesorigin) {
global $DB;
$params = array('starttime' => $starttime, 'endtime' => $endtime, 'contextid' => $analysable->get_context()->id,
'sampleorigin' => $samplesorigin);
$calculations = $DB->get_recordset('analytics_indicator_calc', $params, '', 'indicator, sampleid, value');
$existingcalculations = array();
foreach ($calculations as $calculation) {
if (empty($existingcalculations[$calculation->indicator])) {
$existingcalculations[$calculation->indicator] = array();
}
$existingcalculations[$calculation->indicator][$calculation->sampleid] = $calculation->value;
}
$calculations->close();
return $existingcalculations;
}
|
[
"public",
"static",
"function",
"get_indicator_calculations",
"(",
"$",
"analysable",
",",
"$",
"starttime",
",",
"$",
"endtime",
",",
"$",
"samplesorigin",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"params",
"=",
"array",
"(",
"'starttime'",
"=>",
"$",
"starttime",
",",
"'endtime'",
"=>",
"$",
"endtime",
",",
"'contextid'",
"=>",
"$",
"analysable",
"->",
"get_context",
"(",
")",
"->",
"id",
",",
"'sampleorigin'",
"=>",
"$",
"samplesorigin",
")",
";",
"$",
"calculations",
"=",
"$",
"DB",
"->",
"get_recordset",
"(",
"'analytics_indicator_calc'",
",",
"$",
"params",
",",
"''",
",",
"'indicator, sampleid, value'",
")",
";",
"$",
"existingcalculations",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"calculations",
"as",
"$",
"calculation",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"existingcalculations",
"[",
"$",
"calculation",
"->",
"indicator",
"]",
")",
")",
"{",
"$",
"existingcalculations",
"[",
"$",
"calculation",
"->",
"indicator",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"existingcalculations",
"[",
"$",
"calculation",
"->",
"indicator",
"]",
"[",
"$",
"calculation",
"->",
"sampleid",
"]",
"=",
"$",
"calculation",
"->",
"value",
";",
"}",
"$",
"calculations",
"->",
"close",
"(",
")",
";",
"return",
"$",
"existingcalculations",
";",
"}"
] |
Returns this analysable calculations during the provided period.
@param \core_analytics\analysable $analysable
@param int $starttime
@param int $endtime
@param string $samplesorigin The samples origin as sampleid is not unique across models.
@return array
|
[
"Returns",
"this",
"analysable",
"calculations",
"during",
"the",
"provided",
"period",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/manager.php#L462-L478
|
218,582
|
moodle/moodle
|
analytics/classes/manager.php
|
manager.get_models_with_insights
|
public static function get_models_with_insights(\context $context) {
self::check_can_list_insights($context);
$models = self::get_all_models(true, true, $context);
foreach ($models as $key => $model) {
// Check that it not only have predictions but also generates insights from them.
if (!$model->uses_insights()) {
unset($models[$key]);
}
}
return $models;
}
|
php
|
public static function get_models_with_insights(\context $context) {
self::check_can_list_insights($context);
$models = self::get_all_models(true, true, $context);
foreach ($models as $key => $model) {
// Check that it not only have predictions but also generates insights from them.
if (!$model->uses_insights()) {
unset($models[$key]);
}
}
return $models;
}
|
[
"public",
"static",
"function",
"get_models_with_insights",
"(",
"\\",
"context",
"$",
"context",
")",
"{",
"self",
"::",
"check_can_list_insights",
"(",
"$",
"context",
")",
";",
"$",
"models",
"=",
"self",
"::",
"get_all_models",
"(",
"true",
",",
"true",
",",
"$",
"context",
")",
";",
"foreach",
"(",
"$",
"models",
"as",
"$",
"key",
"=>",
"$",
"model",
")",
"{",
"// Check that it not only have predictions but also generates insights from them.",
"if",
"(",
"!",
"$",
"model",
"->",
"uses_insights",
"(",
")",
")",
"{",
"unset",
"(",
"$",
"models",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"return",
"$",
"models",
";",
"}"
] |
Returns the models with insights at the provided context.
@param \context $context
@return \core_analytics\model[]
|
[
"Returns",
"the",
"models",
"with",
"insights",
"at",
"the",
"provided",
"context",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/manager.php#L486-L498
|
218,583
|
moodle/moodle
|
analytics/classes/manager.php
|
manager.get_prediction
|
public static function get_prediction($predictionid, $requirelogin = false) {
global $DB;
if (!$predictionobj = $DB->get_record('analytics_predictions', array('id' => $predictionid))) {
throw new \moodle_exception('errorpredictionnotfound', 'analytics');
}
$context = \context::instance_by_id($predictionobj->contextid, IGNORE_MISSING);
if (!$context) {
throw new \moodle_exception('errorpredictioncontextnotavailable', 'analytics');
}
if ($requirelogin) {
list($context, $course, $cm) = get_context_info_array($predictionobj->contextid);
require_login($course, false, $cm);
}
self::check_can_list_insights($context);
$model = new \core_analytics\model($predictionobj->modelid);
$sampledata = $model->prediction_sample_data($predictionobj);
$prediction = new \core_analytics\prediction($predictionobj, $sampledata);
return array($model, $prediction, $context);
}
|
php
|
public static function get_prediction($predictionid, $requirelogin = false) {
global $DB;
if (!$predictionobj = $DB->get_record('analytics_predictions', array('id' => $predictionid))) {
throw new \moodle_exception('errorpredictionnotfound', 'analytics');
}
$context = \context::instance_by_id($predictionobj->contextid, IGNORE_MISSING);
if (!$context) {
throw new \moodle_exception('errorpredictioncontextnotavailable', 'analytics');
}
if ($requirelogin) {
list($context, $course, $cm) = get_context_info_array($predictionobj->contextid);
require_login($course, false, $cm);
}
self::check_can_list_insights($context);
$model = new \core_analytics\model($predictionobj->modelid);
$sampledata = $model->prediction_sample_data($predictionobj);
$prediction = new \core_analytics\prediction($predictionobj, $sampledata);
return array($model, $prediction, $context);
}
|
[
"public",
"static",
"function",
"get_prediction",
"(",
"$",
"predictionid",
",",
"$",
"requirelogin",
"=",
"false",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"!",
"$",
"predictionobj",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'analytics_predictions'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"predictionid",
")",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'errorpredictionnotfound'",
",",
"'analytics'",
")",
";",
"}",
"$",
"context",
"=",
"\\",
"context",
"::",
"instance_by_id",
"(",
"$",
"predictionobj",
"->",
"contextid",
",",
"IGNORE_MISSING",
")",
";",
"if",
"(",
"!",
"$",
"context",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'errorpredictioncontextnotavailable'",
",",
"'analytics'",
")",
";",
"}",
"if",
"(",
"$",
"requirelogin",
")",
"{",
"list",
"(",
"$",
"context",
",",
"$",
"course",
",",
"$",
"cm",
")",
"=",
"get_context_info_array",
"(",
"$",
"predictionobj",
"->",
"contextid",
")",
";",
"require_login",
"(",
"$",
"course",
",",
"false",
",",
"$",
"cm",
")",
";",
"}",
"self",
"::",
"check_can_list_insights",
"(",
"$",
"context",
")",
";",
"$",
"model",
"=",
"new",
"\\",
"core_analytics",
"\\",
"model",
"(",
"$",
"predictionobj",
"->",
"modelid",
")",
";",
"$",
"sampledata",
"=",
"$",
"model",
"->",
"prediction_sample_data",
"(",
"$",
"predictionobj",
")",
";",
"$",
"prediction",
"=",
"new",
"\\",
"core_analytics",
"\\",
"prediction",
"(",
"$",
"predictionobj",
",",
"$",
"sampledata",
")",
";",
"return",
"array",
"(",
"$",
"model",
",",
"$",
"prediction",
",",
"$",
"context",
")",
";",
"}"
] |
Returns a prediction
@param int $predictionid
@param bool $requirelogin
@return array array($model, $prediction, $context)
|
[
"Returns",
"a",
"prediction"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/manager.php#L507-L531
|
218,584
|
moodle/moodle
|
analytics/classes/manager.php
|
manager.cleanup
|
public static function cleanup() {
global $DB;
// Clean up stuff that depends on contexts that do not exist anymore.
$sql = "SELECT DISTINCT ap.contextid FROM {analytics_predictions} ap
LEFT JOIN {context} ctx ON ap.contextid = ctx.id
WHERE ctx.id IS NULL";
$apcontexts = $DB->get_records_sql($sql);
$sql = "SELECT DISTINCT aic.contextid FROM {analytics_indicator_calc} aic
LEFT JOIN {context} ctx ON aic.contextid = ctx.id
WHERE ctx.id IS NULL";
$indcalccontexts = $DB->get_records_sql($sql);
$contexts = $apcontexts + $indcalccontexts;
if ($contexts) {
list($sql, $params) = $DB->get_in_or_equal(array_keys($contexts));
$DB->execute("DELETE FROM {analytics_prediction_actions} WHERE predictionid IN
(SELECT ap.id FROM {analytics_predictions} ap WHERE ap.contextid $sql)", $params);
$DB->delete_records_select('analytics_predictions', "contextid $sql", $params);
$DB->delete_records_select('analytics_indicator_calc', "contextid $sql", $params);
}
// Clean up stuff that depends on analysable ids that do not exist anymore.
$models = self::get_all_models();
foreach ($models as $model) {
$analyser = $model->get_analyser(array('notimesplitting' => true));
$analysables = $analyser->get_analysables_iterator();
$analysableids = [];
foreach ($analysables as $analysable) {
if (!$analysable) {
continue;
}
$analysableids[] = $analysable->get_id();
}
if (empty($analysableids)) {
continue;
}
list($notinsql, $params) = $DB->get_in_or_equal($analysableids, SQL_PARAMS_NAMED, 'param', false);
$params['modelid'] = $model->get_id();
$DB->delete_records_select('analytics_predict_samples', "modelid = :modelid AND analysableid $notinsql", $params);
$DB->delete_records_select('analytics_train_samples', "modelid = :modelid AND analysableid $notinsql", $params);
}
}
|
php
|
public static function cleanup() {
global $DB;
// Clean up stuff that depends on contexts that do not exist anymore.
$sql = "SELECT DISTINCT ap.contextid FROM {analytics_predictions} ap
LEFT JOIN {context} ctx ON ap.contextid = ctx.id
WHERE ctx.id IS NULL";
$apcontexts = $DB->get_records_sql($sql);
$sql = "SELECT DISTINCT aic.contextid FROM {analytics_indicator_calc} aic
LEFT JOIN {context} ctx ON aic.contextid = ctx.id
WHERE ctx.id IS NULL";
$indcalccontexts = $DB->get_records_sql($sql);
$contexts = $apcontexts + $indcalccontexts;
if ($contexts) {
list($sql, $params) = $DB->get_in_or_equal(array_keys($contexts));
$DB->execute("DELETE FROM {analytics_prediction_actions} WHERE predictionid IN
(SELECT ap.id FROM {analytics_predictions} ap WHERE ap.contextid $sql)", $params);
$DB->delete_records_select('analytics_predictions', "contextid $sql", $params);
$DB->delete_records_select('analytics_indicator_calc', "contextid $sql", $params);
}
// Clean up stuff that depends on analysable ids that do not exist anymore.
$models = self::get_all_models();
foreach ($models as $model) {
$analyser = $model->get_analyser(array('notimesplitting' => true));
$analysables = $analyser->get_analysables_iterator();
$analysableids = [];
foreach ($analysables as $analysable) {
if (!$analysable) {
continue;
}
$analysableids[] = $analysable->get_id();
}
if (empty($analysableids)) {
continue;
}
list($notinsql, $params) = $DB->get_in_or_equal($analysableids, SQL_PARAMS_NAMED, 'param', false);
$params['modelid'] = $model->get_id();
$DB->delete_records_select('analytics_predict_samples', "modelid = :modelid AND analysableid $notinsql", $params);
$DB->delete_records_select('analytics_train_samples', "modelid = :modelid AND analysableid $notinsql", $params);
}
}
|
[
"public",
"static",
"function",
"cleanup",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"// Clean up stuff that depends on contexts that do not exist anymore.",
"$",
"sql",
"=",
"\"SELECT DISTINCT ap.contextid FROM {analytics_predictions} ap\n LEFT JOIN {context} ctx ON ap.contextid = ctx.id\n WHERE ctx.id IS NULL\"",
";",
"$",
"apcontexts",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"$",
"sql",
")",
";",
"$",
"sql",
"=",
"\"SELECT DISTINCT aic.contextid FROM {analytics_indicator_calc} aic\n LEFT JOIN {context} ctx ON aic.contextid = ctx.id\n WHERE ctx.id IS NULL\"",
";",
"$",
"indcalccontexts",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"$",
"sql",
")",
";",
"$",
"contexts",
"=",
"$",
"apcontexts",
"+",
"$",
"indcalccontexts",
";",
"if",
"(",
"$",
"contexts",
")",
"{",
"list",
"(",
"$",
"sql",
",",
"$",
"params",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"array_keys",
"(",
"$",
"contexts",
")",
")",
";",
"$",
"DB",
"->",
"execute",
"(",
"\"DELETE FROM {analytics_prediction_actions} WHERE predictionid IN\n (SELECT ap.id FROM {analytics_predictions} ap WHERE ap.contextid $sql)\"",
",",
"$",
"params",
")",
";",
"$",
"DB",
"->",
"delete_records_select",
"(",
"'analytics_predictions'",
",",
"\"contextid $sql\"",
",",
"$",
"params",
")",
";",
"$",
"DB",
"->",
"delete_records_select",
"(",
"'analytics_indicator_calc'",
",",
"\"contextid $sql\"",
",",
"$",
"params",
")",
";",
"}",
"// Clean up stuff that depends on analysable ids that do not exist anymore.",
"$",
"models",
"=",
"self",
"::",
"get_all_models",
"(",
")",
";",
"foreach",
"(",
"$",
"models",
"as",
"$",
"model",
")",
"{",
"$",
"analyser",
"=",
"$",
"model",
"->",
"get_analyser",
"(",
"array",
"(",
"'notimesplitting'",
"=>",
"true",
")",
")",
";",
"$",
"analysables",
"=",
"$",
"analyser",
"->",
"get_analysables_iterator",
"(",
")",
";",
"$",
"analysableids",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"analysables",
"as",
"$",
"analysable",
")",
"{",
"if",
"(",
"!",
"$",
"analysable",
")",
"{",
"continue",
";",
"}",
"$",
"analysableids",
"[",
"]",
"=",
"$",
"analysable",
"->",
"get_id",
"(",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"analysableids",
")",
")",
"{",
"continue",
";",
"}",
"list",
"(",
"$",
"notinsql",
",",
"$",
"params",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"analysableids",
",",
"SQL_PARAMS_NAMED",
",",
"'param'",
",",
"false",
")",
";",
"$",
"params",
"[",
"'modelid'",
"]",
"=",
"$",
"model",
"->",
"get_id",
"(",
")",
";",
"$",
"DB",
"->",
"delete_records_select",
"(",
"'analytics_predict_samples'",
",",
"\"modelid = :modelid AND analysableid $notinsql\"",
",",
"$",
"params",
")",
";",
"$",
"DB",
"->",
"delete_records_select",
"(",
"'analytics_train_samples'",
",",
"\"modelid = :modelid AND analysableid $notinsql\"",
",",
"$",
"params",
")",
";",
"}",
"}"
] |
Cleans up analytics db tables that do not directly depend on analysables that may have been deleted.
|
[
"Cleans",
"up",
"analytics",
"db",
"tables",
"that",
"do",
"not",
"directly",
"depend",
"on",
"analysables",
"that",
"may",
"have",
"been",
"deleted",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/manager.php#L549-L596
|
218,585
|
moodle/moodle
|
analytics/classes/manager.php
|
manager.get_analytics_classes
|
private static function get_analytics_classes($element) {
// Just in case...
$element = clean_param($element, PARAM_ALPHANUMEXT);
$classes = \core_component::get_component_classes_in_namespace(null, 'analytics\\' . $element);
return $classes;
}
|
php
|
private static function get_analytics_classes($element) {
// Just in case...
$element = clean_param($element, PARAM_ALPHANUMEXT);
$classes = \core_component::get_component_classes_in_namespace(null, 'analytics\\' . $element);
return $classes;
}
|
[
"private",
"static",
"function",
"get_analytics_classes",
"(",
"$",
"element",
")",
"{",
"// Just in case...",
"$",
"element",
"=",
"clean_param",
"(",
"$",
"element",
",",
"PARAM_ALPHANUMEXT",
")",
";",
"$",
"classes",
"=",
"\\",
"core_component",
"::",
"get_component_classes_in_namespace",
"(",
"null",
",",
"'analytics\\\\'",
".",
"$",
"element",
")",
";",
"return",
"$",
"classes",
";",
"}"
] |
Returns the provided element classes in the site.
@param string $element
@return string[] Array keys are the FQCN and the values the class path.
|
[
"Returns",
"the",
"provided",
"element",
"classes",
"in",
"the",
"site",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/manager.php#L613-L621
|
218,586
|
moodle/moodle
|
analytics/classes/manager.php
|
manager.update_default_models_for_component
|
public static function update_default_models_for_component(string $componentname): array {
$result = [];
foreach (static::load_default_models_for_component($componentname) as $definition) {
if (!\core_analytics\model::exists(static::get_target($definition['target']))) {
$result[] = static::create_declared_model($definition);
}
}
return $result;
}
|
php
|
public static function update_default_models_for_component(string $componentname): array {
$result = [];
foreach (static::load_default_models_for_component($componentname) as $definition) {
if (!\core_analytics\model::exists(static::get_target($definition['target']))) {
$result[] = static::create_declared_model($definition);
}
}
return $result;
}
|
[
"public",
"static",
"function",
"update_default_models_for_component",
"(",
"string",
"$",
"componentname",
")",
":",
"array",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"static",
"::",
"load_default_models_for_component",
"(",
"$",
"componentname",
")",
"as",
"$",
"definition",
")",
"{",
"if",
"(",
"!",
"\\",
"core_analytics",
"\\",
"model",
"::",
"exists",
"(",
"static",
"::",
"get_target",
"(",
"$",
"definition",
"[",
"'target'",
"]",
")",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"static",
"::",
"create_declared_model",
"(",
"$",
"definition",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] |
Check that all the models declared by the component are up to date.
This is intended to be called during the installation / upgrade to automatically create missing models.
@param string $componentname The name of the component to load models for.
@return array \core_analytics\model[] List of actually created models.
|
[
"Check",
"that",
"all",
"the",
"models",
"declared",
"by",
"the",
"component",
"are",
"up",
"to",
"date",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/manager.php#L631-L642
|
218,587
|
moodle/moodle
|
analytics/classes/manager.php
|
manager.load_default_models_for_component
|
public static function load_default_models_for_component(string $componentname): array {
$dir = \core_component::get_component_directory($componentname);
if (!$dir) {
// This is either an invalid component, or a core subsystem without its own root directory.
return [];
}
$file = $dir . '/' . self::ANALYTICS_FILENAME;
if (!is_readable($file)) {
return [];
}
$models = null;
include($file);
if (!isset($models) || !is_array($models) || empty($models)) {
return [];
}
foreach ($models as &$model) {
if (!isset($model['enabled'])) {
$model['enabled'] = false;
} else {
$model['enabled'] = clean_param($model['enabled'], PARAM_BOOL);
}
}
static::validate_models_declaration($models);
return $models;
}
|
php
|
public static function load_default_models_for_component(string $componentname): array {
$dir = \core_component::get_component_directory($componentname);
if (!$dir) {
// This is either an invalid component, or a core subsystem without its own root directory.
return [];
}
$file = $dir . '/' . self::ANALYTICS_FILENAME;
if (!is_readable($file)) {
return [];
}
$models = null;
include($file);
if (!isset($models) || !is_array($models) || empty($models)) {
return [];
}
foreach ($models as &$model) {
if (!isset($model['enabled'])) {
$model['enabled'] = false;
} else {
$model['enabled'] = clean_param($model['enabled'], PARAM_BOOL);
}
}
static::validate_models_declaration($models);
return $models;
}
|
[
"public",
"static",
"function",
"load_default_models_for_component",
"(",
"string",
"$",
"componentname",
")",
":",
"array",
"{",
"$",
"dir",
"=",
"\\",
"core_component",
"::",
"get_component_directory",
"(",
"$",
"componentname",
")",
";",
"if",
"(",
"!",
"$",
"dir",
")",
"{",
"// This is either an invalid component, or a core subsystem without its own root directory.",
"return",
"[",
"]",
";",
"}",
"$",
"file",
"=",
"$",
"dir",
".",
"'/'",
".",
"self",
"::",
"ANALYTICS_FILENAME",
";",
"if",
"(",
"!",
"is_readable",
"(",
"$",
"file",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"models",
"=",
"null",
";",
"include",
"(",
"$",
"file",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"models",
")",
"||",
"!",
"is_array",
"(",
"$",
"models",
")",
"||",
"empty",
"(",
"$",
"models",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"foreach",
"(",
"$",
"models",
"as",
"&",
"$",
"model",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"model",
"[",
"'enabled'",
"]",
")",
")",
"{",
"$",
"model",
"[",
"'enabled'",
"]",
"=",
"false",
";",
"}",
"else",
"{",
"$",
"model",
"[",
"'enabled'",
"]",
"=",
"clean_param",
"(",
"$",
"model",
"[",
"'enabled'",
"]",
",",
"PARAM_BOOL",
")",
";",
"}",
"}",
"static",
"::",
"validate_models_declaration",
"(",
"$",
"models",
")",
";",
"return",
"$",
"models",
";",
"}"
] |
Return the list of models declared by the given component.
@param string $componentname The name of the component to load models for.
@throws \coding_exception Exception thrown in case of invalid syntax.
@return array The $models description array.
|
[
"Return",
"the",
"list",
"of",
"models",
"declared",
"by",
"the",
"given",
"component",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/manager.php#L651-L684
|
218,588
|
moodle/moodle
|
analytics/classes/manager.php
|
manager.load_default_models_for_all_components
|
public static function load_default_models_for_all_components(): array {
$tmp = [];
foreach (\core_component::get_component_list() as $type => $components) {
foreach (array_keys($components) as $component) {
if ($loaded = static::load_default_models_for_component($component)) {
$tmp[$type][$component] = $loaded;
}
}
}
$result = [];
if ($loaded = static::load_default_models_for_component('core')) {
$result['core'] = $loaded;
}
if (!empty($tmp['core'])) {
$result += $tmp['core'];
unset($tmp['core']);
}
foreach ($tmp as $components) {
$result += $components;
}
return $result;
}
|
php
|
public static function load_default_models_for_all_components(): array {
$tmp = [];
foreach (\core_component::get_component_list() as $type => $components) {
foreach (array_keys($components) as $component) {
if ($loaded = static::load_default_models_for_component($component)) {
$tmp[$type][$component] = $loaded;
}
}
}
$result = [];
if ($loaded = static::load_default_models_for_component('core')) {
$result['core'] = $loaded;
}
if (!empty($tmp['core'])) {
$result += $tmp['core'];
unset($tmp['core']);
}
foreach ($tmp as $components) {
$result += $components;
}
return $result;
}
|
[
"public",
"static",
"function",
"load_default_models_for_all_components",
"(",
")",
":",
"array",
"{",
"$",
"tmp",
"=",
"[",
"]",
";",
"foreach",
"(",
"\\",
"core_component",
"::",
"get_component_list",
"(",
")",
"as",
"$",
"type",
"=>",
"$",
"components",
")",
"{",
"foreach",
"(",
"array_keys",
"(",
"$",
"components",
")",
"as",
"$",
"component",
")",
"{",
"if",
"(",
"$",
"loaded",
"=",
"static",
"::",
"load_default_models_for_component",
"(",
"$",
"component",
")",
")",
"{",
"$",
"tmp",
"[",
"$",
"type",
"]",
"[",
"$",
"component",
"]",
"=",
"$",
"loaded",
";",
"}",
"}",
"}",
"$",
"result",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"loaded",
"=",
"static",
"::",
"load_default_models_for_component",
"(",
"'core'",
")",
")",
"{",
"$",
"result",
"[",
"'core'",
"]",
"=",
"$",
"loaded",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"tmp",
"[",
"'core'",
"]",
")",
")",
"{",
"$",
"result",
"+=",
"$",
"tmp",
"[",
"'core'",
"]",
";",
"unset",
"(",
"$",
"tmp",
"[",
"'core'",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"tmp",
"as",
"$",
"components",
")",
"{",
"$",
"result",
"+=",
"$",
"components",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Return the list of all the models declared anywhere in this Moodle installation.
Models defined by the core and core subsystems come first, followed by those provided by plugins.
@return array indexed by the frankenstyle component
|
[
"Return",
"the",
"list",
"of",
"all",
"the",
"models",
"declared",
"anywhere",
"in",
"this",
"Moodle",
"installation",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/manager.php#L693-L721
|
218,589
|
moodle/moodle
|
analytics/classes/manager.php
|
manager.validate_models_declaration
|
public static function validate_models_declaration(array $models) {
foreach ($models as $model) {
if (!isset($model['target'])) {
throw new \coding_exception('Missing target declaration');
}
if (!static::is_valid($model['target'], '\core_analytics\local\target\base')) {
throw new \coding_exception('Invalid target classname', $model['target']);
}
if (empty($model['indicators']) || !is_array($model['indicators'])) {
throw new \coding_exception('Missing indicators declaration');
}
foreach ($model['indicators'] as $indicator) {
if (!static::is_valid($indicator, '\core_analytics\local\indicator\base')) {
throw new \coding_exception('Invalid indicator classname', $indicator);
}
}
if (isset($model['timesplitting'])) {
if (substr($model['timesplitting'], 0, 1) !== '\\') {
throw new \coding_exception('Expecting fully qualified time splitting classname', $model['timesplitting']);
}
if (!static::is_valid($model['timesplitting'], '\core_analytics\local\time_splitting\base')) {
throw new \coding_exception('Invalid time splitting classname', $model['timesplitting']);
}
}
if (!empty($model['enabled']) && !isset($model['timesplitting'])) {
throw new \coding_exception('Cannot enable a model without time splitting method specified');
}
}
}
|
php
|
public static function validate_models_declaration(array $models) {
foreach ($models as $model) {
if (!isset($model['target'])) {
throw new \coding_exception('Missing target declaration');
}
if (!static::is_valid($model['target'], '\core_analytics\local\target\base')) {
throw new \coding_exception('Invalid target classname', $model['target']);
}
if (empty($model['indicators']) || !is_array($model['indicators'])) {
throw new \coding_exception('Missing indicators declaration');
}
foreach ($model['indicators'] as $indicator) {
if (!static::is_valid($indicator, '\core_analytics\local\indicator\base')) {
throw new \coding_exception('Invalid indicator classname', $indicator);
}
}
if (isset($model['timesplitting'])) {
if (substr($model['timesplitting'], 0, 1) !== '\\') {
throw new \coding_exception('Expecting fully qualified time splitting classname', $model['timesplitting']);
}
if (!static::is_valid($model['timesplitting'], '\core_analytics\local\time_splitting\base')) {
throw new \coding_exception('Invalid time splitting classname', $model['timesplitting']);
}
}
if (!empty($model['enabled']) && !isset($model['timesplitting'])) {
throw new \coding_exception('Cannot enable a model without time splitting method specified');
}
}
}
|
[
"public",
"static",
"function",
"validate_models_declaration",
"(",
"array",
"$",
"models",
")",
"{",
"foreach",
"(",
"$",
"models",
"as",
"$",
"model",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"model",
"[",
"'target'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Missing target declaration'",
")",
";",
"}",
"if",
"(",
"!",
"static",
"::",
"is_valid",
"(",
"$",
"model",
"[",
"'target'",
"]",
",",
"'\\core_analytics\\local\\target\\base'",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Invalid target classname'",
",",
"$",
"model",
"[",
"'target'",
"]",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"model",
"[",
"'indicators'",
"]",
")",
"||",
"!",
"is_array",
"(",
"$",
"model",
"[",
"'indicators'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Missing indicators declaration'",
")",
";",
"}",
"foreach",
"(",
"$",
"model",
"[",
"'indicators'",
"]",
"as",
"$",
"indicator",
")",
"{",
"if",
"(",
"!",
"static",
"::",
"is_valid",
"(",
"$",
"indicator",
",",
"'\\core_analytics\\local\\indicator\\base'",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Invalid indicator classname'",
",",
"$",
"indicator",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"model",
"[",
"'timesplitting'",
"]",
")",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"model",
"[",
"'timesplitting'",
"]",
",",
"0",
",",
"1",
")",
"!==",
"'\\\\'",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Expecting fully qualified time splitting classname'",
",",
"$",
"model",
"[",
"'timesplitting'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"static",
"::",
"is_valid",
"(",
"$",
"model",
"[",
"'timesplitting'",
"]",
",",
"'\\core_analytics\\local\\time_splitting\\base'",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Invalid time splitting classname'",
",",
"$",
"model",
"[",
"'timesplitting'",
"]",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"model",
"[",
"'enabled'",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"model",
"[",
"'timesplitting'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Cannot enable a model without time splitting method specified'",
")",
";",
"}",
"}",
"}"
] |
Validate the declaration of prediction models according the syntax expected in the component's db folder.
The expected structure looks like this:
[
[
'target' => '\fully\qualified\name\of\the\target\class',
'indicators' => [
'\fully\qualified\name\of\the\first\indicator',
'\fully\qualified\name\of\the\second\indicator',
],
'timesplitting' => '\optional\name\of\the\time_splitting\class',
'enabled' => true,
],
];
@param array $models List of declared models.
@throws \coding_exception Exception thrown in case of invalid syntax.
|
[
"Validate",
"the",
"declaration",
"of",
"prediction",
"models",
"according",
"the",
"syntax",
"expected",
"in",
"the",
"component",
"s",
"db",
"folder",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/manager.php#L743-L777
|
218,590
|
moodle/moodle
|
analytics/classes/manager.php
|
manager.create_declared_model
|
public static function create_declared_model(array $definition): \core_analytics\model {
list($target, $indicators) = static::get_declared_target_and_indicators_instances($definition);
if (isset($definition['timesplitting'])) {
$timesplitting = $definition['timesplitting'];
} else {
$timesplitting = false;
}
$created = \core_analytics\model::create($target, $indicators, $timesplitting);
if (!empty($definition['enabled'])) {
$created->enable();
}
return $created;
}
|
php
|
public static function create_declared_model(array $definition): \core_analytics\model {
list($target, $indicators) = static::get_declared_target_and_indicators_instances($definition);
if (isset($definition['timesplitting'])) {
$timesplitting = $definition['timesplitting'];
} else {
$timesplitting = false;
}
$created = \core_analytics\model::create($target, $indicators, $timesplitting);
if (!empty($definition['enabled'])) {
$created->enable();
}
return $created;
}
|
[
"public",
"static",
"function",
"create_declared_model",
"(",
"array",
"$",
"definition",
")",
":",
"\\",
"core_analytics",
"\\",
"model",
"{",
"list",
"(",
"$",
"target",
",",
"$",
"indicators",
")",
"=",
"static",
"::",
"get_declared_target_and_indicators_instances",
"(",
"$",
"definition",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"definition",
"[",
"'timesplitting'",
"]",
")",
")",
"{",
"$",
"timesplitting",
"=",
"$",
"definition",
"[",
"'timesplitting'",
"]",
";",
"}",
"else",
"{",
"$",
"timesplitting",
"=",
"false",
";",
"}",
"$",
"created",
"=",
"\\",
"core_analytics",
"\\",
"model",
"::",
"create",
"(",
"$",
"target",
",",
"$",
"indicators",
",",
"$",
"timesplitting",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"definition",
"[",
"'enabled'",
"]",
")",
")",
"{",
"$",
"created",
"->",
"enable",
"(",
")",
";",
"}",
"return",
"$",
"created",
";",
"}"
] |
Create the defined model.
@param array $definition See {@link self::validate_models_declaration()} for the syntax.
@return \core_analytics\model
|
[
"Create",
"the",
"defined",
"model",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/manager.php#L785-L802
|
218,591
|
moodle/moodle
|
analytics/classes/manager.php
|
manager.get_declared_target_and_indicators_instances
|
public static function get_declared_target_and_indicators_instances(array $definition): array {
$target = static::get_target($definition['target']);
$indicators = [];
foreach ($definition['indicators'] as $indicatorname) {
$indicator = static::get_indicator($indicatorname);
$indicators[$indicator->get_id()] = $indicator;
}
return [$target, $indicators];
}
|
php
|
public static function get_declared_target_and_indicators_instances(array $definition): array {
$target = static::get_target($definition['target']);
$indicators = [];
foreach ($definition['indicators'] as $indicatorname) {
$indicator = static::get_indicator($indicatorname);
$indicators[$indicator->get_id()] = $indicator;
}
return [$target, $indicators];
}
|
[
"public",
"static",
"function",
"get_declared_target_and_indicators_instances",
"(",
"array",
"$",
"definition",
")",
":",
"array",
"{",
"$",
"target",
"=",
"static",
"::",
"get_target",
"(",
"$",
"definition",
"[",
"'target'",
"]",
")",
";",
"$",
"indicators",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"definition",
"[",
"'indicators'",
"]",
"as",
"$",
"indicatorname",
")",
"{",
"$",
"indicator",
"=",
"static",
"::",
"get_indicator",
"(",
"$",
"indicatorname",
")",
";",
"$",
"indicators",
"[",
"$",
"indicator",
"->",
"get_id",
"(",
")",
"]",
"=",
"$",
"indicator",
";",
"}",
"return",
"[",
"$",
"target",
",",
"$",
"indicators",
"]",
";",
"}"
] |
Given a model definition, return actual target and indicators instances.
@param array $definition See {@link self::validate_models_declaration()} for the syntax.
@return array [0] => target instance, [1] => array of indicators instances
|
[
"Given",
"a",
"model",
"definition",
"return",
"actual",
"target",
"and",
"indicators",
"instances",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/manager.php#L820-L832
|
218,592
|
moodle/moodle
|
lib/classes/lock/file_lock_factory.php
|
file_lock_factory.is_available
|
public function is_available() {
global $CFG;
$preventfilelocking = !empty($CFG->preventfilelocking);
$lockdirisdataroot = true;
if (!empty($CFG->file_lock_root) && strpos($CFG->file_lock_root, $CFG->dataroot) !== 0) {
$lockdirisdataroot = false;
}
return !$preventfilelocking || !$lockdirisdataroot;
}
|
php
|
public function is_available() {
global $CFG;
$preventfilelocking = !empty($CFG->preventfilelocking);
$lockdirisdataroot = true;
if (!empty($CFG->file_lock_root) && strpos($CFG->file_lock_root, $CFG->dataroot) !== 0) {
$lockdirisdataroot = false;
}
return !$preventfilelocking || !$lockdirisdataroot;
}
|
[
"public",
"function",
"is_available",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"preventfilelocking",
"=",
"!",
"empty",
"(",
"$",
"CFG",
"->",
"preventfilelocking",
")",
";",
"$",
"lockdirisdataroot",
"=",
"true",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"CFG",
"->",
"file_lock_root",
")",
"&&",
"strpos",
"(",
"$",
"CFG",
"->",
"file_lock_root",
",",
"$",
"CFG",
"->",
"dataroot",
")",
"!==",
"0",
")",
"{",
"$",
"lockdirisdataroot",
"=",
"false",
";",
"}",
"return",
"!",
"$",
"preventfilelocking",
"||",
"!",
"$",
"lockdirisdataroot",
";",
"}"
] |
Is available.
@return boolean - True if preventfilelocking is not set - or the file_lock_root is not in dataroot.
|
[
"Is",
"available",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/lock/file_lock_factory.php#L99-L107
|
218,593
|
moodle/moodle
|
lib/classes/lock/file_lock_factory.php
|
file_lock_factory.get_lock
|
public function get_lock($resource, $timeout, $maxlifetime = 86400) {
$giveuptime = time() + $timeout;
$hash = md5($this->type . '_' . $resource);
$lockdir = $this->lockdirectory . '/' . substr($hash, 0, 2);
if (!check_dir_exists($lockdir, true, true)) {
return false;
}
$lockfilename = $lockdir . '/' . $hash;
$filehandle = fopen($lockfilename, "wb");
// Could not open the lock file.
if (!$filehandle) {
return false;
}
do {
// Will block on windows. So sad.
$wouldblock = false;
$locked = flock($filehandle, LOCK_EX | LOCK_NB, $wouldblock);
if (!$locked && $wouldblock && $timeout > 0) {
usleep(rand(10000, 250000)); // Sleep between 10 and 250 milliseconds.
}
// Try until the giveup time.
} while (!$locked && $wouldblock && time() < $giveuptime);
if (!$locked) {
fclose($filehandle);
return false;
}
if ($this->verbose) {
fwrite($filehandle, $this->get_debug_info());
}
return new lock($filehandle, $this);
}
|
php
|
public function get_lock($resource, $timeout, $maxlifetime = 86400) {
$giveuptime = time() + $timeout;
$hash = md5($this->type . '_' . $resource);
$lockdir = $this->lockdirectory . '/' . substr($hash, 0, 2);
if (!check_dir_exists($lockdir, true, true)) {
return false;
}
$lockfilename = $lockdir . '/' . $hash;
$filehandle = fopen($lockfilename, "wb");
// Could not open the lock file.
if (!$filehandle) {
return false;
}
do {
// Will block on windows. So sad.
$wouldblock = false;
$locked = flock($filehandle, LOCK_EX | LOCK_NB, $wouldblock);
if (!$locked && $wouldblock && $timeout > 0) {
usleep(rand(10000, 250000)); // Sleep between 10 and 250 milliseconds.
}
// Try until the giveup time.
} while (!$locked && $wouldblock && time() < $giveuptime);
if (!$locked) {
fclose($filehandle);
return false;
}
if ($this->verbose) {
fwrite($filehandle, $this->get_debug_info());
}
return new lock($filehandle, $this);
}
|
[
"public",
"function",
"get_lock",
"(",
"$",
"resource",
",",
"$",
"timeout",
",",
"$",
"maxlifetime",
"=",
"86400",
")",
"{",
"$",
"giveuptime",
"=",
"time",
"(",
")",
"+",
"$",
"timeout",
";",
"$",
"hash",
"=",
"md5",
"(",
"$",
"this",
"->",
"type",
".",
"'_'",
".",
"$",
"resource",
")",
";",
"$",
"lockdir",
"=",
"$",
"this",
"->",
"lockdirectory",
".",
"'/'",
".",
"substr",
"(",
"$",
"hash",
",",
"0",
",",
"2",
")",
";",
"if",
"(",
"!",
"check_dir_exists",
"(",
"$",
"lockdir",
",",
"true",
",",
"true",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"lockfilename",
"=",
"$",
"lockdir",
".",
"'/'",
".",
"$",
"hash",
";",
"$",
"filehandle",
"=",
"fopen",
"(",
"$",
"lockfilename",
",",
"\"wb\"",
")",
";",
"// Could not open the lock file.",
"if",
"(",
"!",
"$",
"filehandle",
")",
"{",
"return",
"false",
";",
"}",
"do",
"{",
"// Will block on windows. So sad.",
"$",
"wouldblock",
"=",
"false",
";",
"$",
"locked",
"=",
"flock",
"(",
"$",
"filehandle",
",",
"LOCK_EX",
"|",
"LOCK_NB",
",",
"$",
"wouldblock",
")",
";",
"if",
"(",
"!",
"$",
"locked",
"&&",
"$",
"wouldblock",
"&&",
"$",
"timeout",
">",
"0",
")",
"{",
"usleep",
"(",
"rand",
"(",
"10000",
",",
"250000",
")",
")",
";",
"// Sleep between 10 and 250 milliseconds.",
"}",
"// Try until the giveup time.",
"}",
"while",
"(",
"!",
"$",
"locked",
"&&",
"$",
"wouldblock",
"&&",
"time",
"(",
")",
"<",
"$",
"giveuptime",
")",
";",
"if",
"(",
"!",
"$",
"locked",
")",
"{",
"fclose",
"(",
"$",
"filehandle",
")",
";",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"verbose",
")",
"{",
"fwrite",
"(",
"$",
"filehandle",
",",
"$",
"this",
"->",
"get_debug_info",
"(",
")",
")",
";",
"}",
"return",
"new",
"lock",
"(",
"$",
"filehandle",
",",
"$",
"this",
")",
";",
"}"
] |
Get a lock within the specified timeout or return false.
@param string $resource - The identifier for the lock. Should use frankenstyle prefix.
@param int $timeout - The number of seconds to wait for a lock before giving up.
@param int $maxlifetime - Unused by this lock type.
@return boolean - true if a lock was obtained.
|
[
"Get",
"a",
"lock",
"within",
"the",
"specified",
"timeout",
"or",
"return",
"false",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/lock/file_lock_factory.php#L132-L169
|
218,594
|
moodle/moodle
|
backup/util/settings/backup_setting.class.php
|
backup_setting.make_ui
|
public function make_ui($type, $label, array $attributes = null, array $options = null) {
$this->uisetting = backup_setting_ui::make($this, $type, $label, $attributes, $options);
if (is_array($options) || is_object($options)) {
$options = (array)$options;
switch (get_class($this->uisetting)) {
case 'backup_setting_ui_radio' :
// text
if (array_key_exists('text', $options)) {
$this->uisetting->set_text($options['text']);
}
case 'backup_setting_ui_checkbox' :
// value
if (array_key_exists('value', $options)) {
$this->uisetting->set_value($options['value']);
}
break;
case 'backup_setting_ui_select' :
// options
if (array_key_exists('options', $options)) {
$this->uisetting->set_values($options['options']);
}
break;
}
}
}
|
php
|
public function make_ui($type, $label, array $attributes = null, array $options = null) {
$this->uisetting = backup_setting_ui::make($this, $type, $label, $attributes, $options);
if (is_array($options) || is_object($options)) {
$options = (array)$options;
switch (get_class($this->uisetting)) {
case 'backup_setting_ui_radio' :
// text
if (array_key_exists('text', $options)) {
$this->uisetting->set_text($options['text']);
}
case 'backup_setting_ui_checkbox' :
// value
if (array_key_exists('value', $options)) {
$this->uisetting->set_value($options['value']);
}
break;
case 'backup_setting_ui_select' :
// options
if (array_key_exists('options', $options)) {
$this->uisetting->set_values($options['options']);
}
break;
}
}
}
|
[
"public",
"function",
"make_ui",
"(",
"$",
"type",
",",
"$",
"label",
",",
"array",
"$",
"attributes",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"uisetting",
"=",
"backup_setting_ui",
"::",
"make",
"(",
"$",
"this",
",",
"$",
"type",
",",
"$",
"label",
",",
"$",
"attributes",
",",
"$",
"options",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"options",
")",
"||",
"is_object",
"(",
"$",
"options",
")",
")",
"{",
"$",
"options",
"=",
"(",
"array",
")",
"$",
"options",
";",
"switch",
"(",
"get_class",
"(",
"$",
"this",
"->",
"uisetting",
")",
")",
"{",
"case",
"'backup_setting_ui_radio'",
":",
"// text",
"if",
"(",
"array_key_exists",
"(",
"'text'",
",",
"$",
"options",
")",
")",
"{",
"$",
"this",
"->",
"uisetting",
"->",
"set_text",
"(",
"$",
"options",
"[",
"'text'",
"]",
")",
";",
"}",
"case",
"'backup_setting_ui_checkbox'",
":",
"// value",
"if",
"(",
"array_key_exists",
"(",
"'value'",
",",
"$",
"options",
")",
")",
"{",
"$",
"this",
"->",
"uisetting",
"->",
"set_value",
"(",
"$",
"options",
"[",
"'value'",
"]",
")",
";",
"}",
"break",
";",
"case",
"'backup_setting_ui_select'",
":",
"// options",
"if",
"(",
"array_key_exists",
"(",
"'options'",
",",
"$",
"options",
")",
")",
"{",
"$",
"this",
"->",
"uisetting",
"->",
"set_values",
"(",
"$",
"options",
"[",
"'options'",
"]",
")",
";",
"}",
"break",
";",
"}",
"}",
"}"
] |
Creates and sets a user interface for this setting given appropriate arguments
@param int $type
@param string $label
@param array $attributes
@param array $options
|
[
"Creates",
"and",
"sets",
"a",
"user",
"interface",
"for",
"this",
"setting",
"given",
"appropriate",
"arguments"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/settings/backup_setting.class.php#L67-L91
|
218,595
|
moodle/moodle
|
backup/util/ui/import_extensions.php
|
import_ui_stage_confirmation.display
|
public function display(core_backup_renderer $renderer) {
$form = $this->initialise_stage_form();
$form->require_definition_after_data();
if ($e = $form->get_element('submitbutton')) {
$e->setLabel(get_string('import'.$this->get_ui()->get_name().'stage'.$this->get_stage().'action', 'backup'));
} else {
$elements = $form->get_element('buttonar')->getElements();
foreach ($elements as &$element) {
if ($element->getName() == 'submitbutton') {
$element->setValue(
get_string('import'.$this->get_ui()->get_name().'stage'.$this->get_stage().'action', 'backup')
);
}
}
}
// A nasty hack follows to work around the sad fact that moodle quickforms
// do not allow to actually return the HTML content, just to echo it.
flush();
ob_start();
$form->display();
$output = ob_get_contents();
ob_end_clean();
return $output;
}
|
php
|
public function display(core_backup_renderer $renderer) {
$form = $this->initialise_stage_form();
$form->require_definition_after_data();
if ($e = $form->get_element('submitbutton')) {
$e->setLabel(get_string('import'.$this->get_ui()->get_name().'stage'.$this->get_stage().'action', 'backup'));
} else {
$elements = $form->get_element('buttonar')->getElements();
foreach ($elements as &$element) {
if ($element->getName() == 'submitbutton') {
$element->setValue(
get_string('import'.$this->get_ui()->get_name().'stage'.$this->get_stage().'action', 'backup')
);
}
}
}
// A nasty hack follows to work around the sad fact that moodle quickforms
// do not allow to actually return the HTML content, just to echo it.
flush();
ob_start();
$form->display();
$output = ob_get_contents();
ob_end_clean();
return $output;
}
|
[
"public",
"function",
"display",
"(",
"core_backup_renderer",
"$",
"renderer",
")",
"{",
"$",
"form",
"=",
"$",
"this",
"->",
"initialise_stage_form",
"(",
")",
";",
"$",
"form",
"->",
"require_definition_after_data",
"(",
")",
";",
"if",
"(",
"$",
"e",
"=",
"$",
"form",
"->",
"get_element",
"(",
"'submitbutton'",
")",
")",
"{",
"$",
"e",
"->",
"setLabel",
"(",
"get_string",
"(",
"'import'",
".",
"$",
"this",
"->",
"get_ui",
"(",
")",
"->",
"get_name",
"(",
")",
".",
"'stage'",
".",
"$",
"this",
"->",
"get_stage",
"(",
")",
".",
"'action'",
",",
"'backup'",
")",
")",
";",
"}",
"else",
"{",
"$",
"elements",
"=",
"$",
"form",
"->",
"get_element",
"(",
"'buttonar'",
")",
"->",
"getElements",
"(",
")",
";",
"foreach",
"(",
"$",
"elements",
"as",
"&",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"element",
"->",
"getName",
"(",
")",
"==",
"'submitbutton'",
")",
"{",
"$",
"element",
"->",
"setValue",
"(",
"get_string",
"(",
"'import'",
".",
"$",
"this",
"->",
"get_ui",
"(",
")",
"->",
"get_name",
"(",
")",
".",
"'stage'",
".",
"$",
"this",
"->",
"get_stage",
"(",
")",
".",
"'action'",
",",
"'backup'",
")",
")",
";",
"}",
"}",
"}",
"// A nasty hack follows to work around the sad fact that moodle quickforms",
"// do not allow to actually return the HTML content, just to echo it.",
"flush",
"(",
")",
";",
"ob_start",
"(",
")",
";",
"$",
"form",
"->",
"display",
"(",
")",
";",
"$",
"output",
"=",
"ob_get_contents",
"(",
")",
";",
"ob_end_clean",
"(",
")",
";",
"return",
"$",
"output",
";",
"}"
] |
Displays the stage
This function is overriden so that we can manipulate the strings on the
buttons.
@param core_backup_renderer $renderer
@return string HTML code to echo
|
[
"Displays",
"the",
"stage"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/import_extensions.php#L163-L188
|
218,596
|
moodle/moodle
|
question/type/numerical/questiontype.php
|
qtype_numerical.is_valid_number
|
public static function is_valid_number(string $x) : bool {
$ap = new qtype_numerical_answer_processor(array());
list($value, $unit) = $ap->apply_units($x);
return !is_null($value) && !$unit;
}
|
php
|
public static function is_valid_number(string $x) : bool {
$ap = new qtype_numerical_answer_processor(array());
list($value, $unit) = $ap->apply_units($x);
return !is_null($value) && !$unit;
}
|
[
"public",
"static",
"function",
"is_valid_number",
"(",
"string",
"$",
"x",
")",
":",
"bool",
"{",
"$",
"ap",
"=",
"new",
"qtype_numerical_answer_processor",
"(",
"array",
"(",
")",
")",
";",
"list",
"(",
"$",
"value",
",",
"$",
"unit",
")",
"=",
"$",
"ap",
"->",
"apply_units",
"(",
"$",
"x",
")",
";",
"return",
"!",
"is_null",
"(",
"$",
"value",
")",
"&&",
"!",
"$",
"unit",
";",
"}"
] |
Validate that a string is a number formatted correctly for the current locale.
@param string $x a string
@return bool whether $x is a number that the numerical question type can interpret.
|
[
"Validate",
"that",
"a",
"string",
"is",
"a",
"number",
"formatted",
"correctly",
"for",
"the",
"current",
"locale",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/numerical/questiontype.php#L60-L64
|
218,597
|
moodle/moodle
|
question/type/numerical/questiontype.php
|
qtype_numerical.add_unit
|
public function add_unit($questiondata, $answer, $unit = null) {
if (is_null($unit)) {
$unit = $this->get_default_numerical_unit($questiondata);
}
if (!$unit) {
return $answer;
}
if (!empty($questiondata->options->unitsleft)) {
return $unit->unit . ' ' . $answer;
} else {
return $answer . ' ' . $unit->unit;
}
}
|
php
|
public function add_unit($questiondata, $answer, $unit = null) {
if (is_null($unit)) {
$unit = $this->get_default_numerical_unit($questiondata);
}
if (!$unit) {
return $answer;
}
if (!empty($questiondata->options->unitsleft)) {
return $unit->unit . ' ' . $answer;
} else {
return $answer . ' ' . $unit->unit;
}
}
|
[
"public",
"function",
"add_unit",
"(",
"$",
"questiondata",
",",
"$",
"answer",
",",
"$",
"unit",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"unit",
")",
")",
"{",
"$",
"unit",
"=",
"$",
"this",
"->",
"get_default_numerical_unit",
"(",
"$",
"questiondata",
")",
";",
"}",
"if",
"(",
"!",
"$",
"unit",
")",
"{",
"return",
"$",
"answer",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"questiondata",
"->",
"options",
"->",
"unitsleft",
")",
")",
"{",
"return",
"$",
"unit",
"->",
"unit",
".",
"' '",
".",
"$",
"answer",
";",
"}",
"else",
"{",
"return",
"$",
"answer",
".",
"' '",
".",
"$",
"unit",
"->",
"unit",
";",
"}",
"}"
] |
Add a unit to a response for display.
@param object $questiondata the data defining the quetsion.
@param string $answer a response.
@param object $unit a unit. If null, {@link get_default_numerical_unit()}
is used.
|
[
"Add",
"a",
"unit",
"to",
"a",
"response",
"for",
"display",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/numerical/questiontype.php#L414-L428
|
218,598
|
moodle/moodle
|
question/type/numerical/questiontype.php
|
qtype_numerical_answer_processor.set_characters
|
public function set_characters($decsep, $thousandssep) {
$this->decsep = $decsep;
$this->thousandssep = $thousandssep;
$this->regex = null;
}
|
php
|
public function set_characters($decsep, $thousandssep) {
$this->decsep = $decsep;
$this->thousandssep = $thousandssep;
$this->regex = null;
}
|
[
"public",
"function",
"set_characters",
"(",
"$",
"decsep",
",",
"$",
"thousandssep",
")",
"{",
"$",
"this",
"->",
"decsep",
"=",
"$",
"decsep",
";",
"$",
"this",
"->",
"thousandssep",
"=",
"$",
"thousandssep",
";",
"$",
"this",
"->",
"regex",
"=",
"null",
";",
"}"
] |
Set the decimal point and thousands separator character that should be used.
@param string $decsep
@param string $thousandssep
|
[
"Set",
"the",
"decimal",
"point",
"and",
"thousands",
"separator",
"character",
"that",
"should",
"be",
"used",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/numerical/questiontype.php#L539-L543
|
218,599
|
moodle/moodle
|
question/type/numerical/questiontype.php
|
qtype_numerical_answer_processor.parse_response
|
protected function parse_response($response) {
if (!preg_match($this->build_regex(), $response, $matches)) {
return array(null, null, null, null);
}
$matches += array('', '', '', ''); // Fill in any missing matches.
list($matchedpart, $beforepoint, $decimals, $exponent) = $matches;
// Strip out thousands separators.
$beforepoint = str_replace($this->thousandssep, '', $beforepoint);
// Must be either something before, or something after the decimal point.
// (The only way to do this in the regex would make it much more complicated.)
if ($beforepoint === '' && $decimals === '') {
return array(null, null, null, null);
}
if ($this->unitsbefore) {
$unit = substr($response, 0, -strlen($matchedpart));
} else {
$unit = substr($response, strlen($matchedpart));
}
$unit = trim($unit);
return array($beforepoint, $decimals, $exponent, $unit);
}
|
php
|
protected function parse_response($response) {
if (!preg_match($this->build_regex(), $response, $matches)) {
return array(null, null, null, null);
}
$matches += array('', '', '', ''); // Fill in any missing matches.
list($matchedpart, $beforepoint, $decimals, $exponent) = $matches;
// Strip out thousands separators.
$beforepoint = str_replace($this->thousandssep, '', $beforepoint);
// Must be either something before, or something after the decimal point.
// (The only way to do this in the regex would make it much more complicated.)
if ($beforepoint === '' && $decimals === '') {
return array(null, null, null, null);
}
if ($this->unitsbefore) {
$unit = substr($response, 0, -strlen($matchedpart));
} else {
$unit = substr($response, strlen($matchedpart));
}
$unit = trim($unit);
return array($beforepoint, $decimals, $exponent, $unit);
}
|
[
"protected",
"function",
"parse_response",
"(",
"$",
"response",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"$",
"this",
"->",
"build_regex",
"(",
")",
",",
"$",
"response",
",",
"$",
"matches",
")",
")",
"{",
"return",
"array",
"(",
"null",
",",
"null",
",",
"null",
",",
"null",
")",
";",
"}",
"$",
"matches",
"+=",
"array",
"(",
"''",
",",
"''",
",",
"''",
",",
"''",
")",
";",
"// Fill in any missing matches.",
"list",
"(",
"$",
"matchedpart",
",",
"$",
"beforepoint",
",",
"$",
"decimals",
",",
"$",
"exponent",
")",
"=",
"$",
"matches",
";",
"// Strip out thousands separators.",
"$",
"beforepoint",
"=",
"str_replace",
"(",
"$",
"this",
"->",
"thousandssep",
",",
"''",
",",
"$",
"beforepoint",
")",
";",
"// Must be either something before, or something after the decimal point.",
"// (The only way to do this in the regex would make it much more complicated.)",
"if",
"(",
"$",
"beforepoint",
"===",
"''",
"&&",
"$",
"decimals",
"===",
"''",
")",
"{",
"return",
"array",
"(",
"null",
",",
"null",
",",
"null",
",",
"null",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"unitsbefore",
")",
"{",
"$",
"unit",
"=",
"substr",
"(",
"$",
"response",
",",
"0",
",",
"-",
"strlen",
"(",
"$",
"matchedpart",
")",
")",
";",
"}",
"else",
"{",
"$",
"unit",
"=",
"substr",
"(",
"$",
"response",
",",
"strlen",
"(",
"$",
"matchedpart",
")",
")",
";",
"}",
"$",
"unit",
"=",
"trim",
"(",
"$",
"unit",
")",
";",
"return",
"array",
"(",
"$",
"beforepoint",
",",
"$",
"decimals",
",",
"$",
"exponent",
",",
"$",
"unit",
")",
";",
"}"
] |
This method can be used for more locale-strict parsing of repsonses. At the
moment we don't use it, and instead use the more lax parsing in apply_units.
This is just a note that this funciton was used in the past, so if you are
intersted, look through version control history.
Take a string which is a number with or without a decimal point and exponent,
and possibly followed by one of the units, and split it into bits.
@param string $response a value, optionally with a unit.
@return array four strings (some of which may be blank) the digits before
and after the decimal point, the exponent, and the unit. All four will be
null if the response cannot be parsed.
|
[
"This",
"method",
"can",
"be",
"used",
"for",
"more",
"locale",
"-",
"strict",
"parsing",
"of",
"repsonses",
".",
"At",
"the",
"moment",
"we",
"don",
"t",
"use",
"it",
"and",
"instead",
"use",
"the",
"more",
"lax",
"parsing",
"in",
"apply_units",
".",
"This",
"is",
"just",
"a",
"note",
"that",
"this",
"funciton",
"was",
"used",
"in",
"the",
"past",
"so",
"if",
"you",
"are",
"intersted",
"look",
"through",
"version",
"control",
"history",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/numerical/questiontype.php#L606-L631
|
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.