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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
215,200
|
moodle/moodle
|
mod/workshop/locallib.php
|
workshop.aggregate_submission_grades_process
|
protected function aggregate_submission_grades_process(array $assessments) {
global $DB;
$submissionid = null; // the id of the submission being processed
$current = null; // the grade currently saved in database
$finalgrade = null; // the new grade to be calculated
$sumgrades = 0;
$sumweights = 0;
foreach ($assessments as $assessment) {
if (is_null($submissionid)) {
// the id is the same in all records, fetch it during the first loop cycle
$submissionid = $assessment->submissionid;
}
if (is_null($current)) {
// the currently saved grade is the same in all records, fetch it during the first loop cycle
$current = $assessment->submissiongrade;
}
if (is_null($assessment->grade)) {
// this was not assessed yet
continue;
}
if ($assessment->weight == 0) {
// this does not influence the calculation
continue;
}
$sumgrades += $assessment->grade * $assessment->weight;
$sumweights += $assessment->weight;
}
if ($sumweights > 0 and is_null($finalgrade)) {
$finalgrade = grade_floatval($sumgrades / $sumweights);
}
// check if the new final grade differs from the one stored in the database
if (grade_floats_different($finalgrade, $current)) {
// we need to save new calculation into the database
$record = new stdclass();
$record->id = $submissionid;
$record->grade = $finalgrade;
$record->timegraded = time();
$DB->update_record('workshop_submissions', $record);
}
}
|
php
|
protected function aggregate_submission_grades_process(array $assessments) {
global $DB;
$submissionid = null; // the id of the submission being processed
$current = null; // the grade currently saved in database
$finalgrade = null; // the new grade to be calculated
$sumgrades = 0;
$sumweights = 0;
foreach ($assessments as $assessment) {
if (is_null($submissionid)) {
// the id is the same in all records, fetch it during the first loop cycle
$submissionid = $assessment->submissionid;
}
if (is_null($current)) {
// the currently saved grade is the same in all records, fetch it during the first loop cycle
$current = $assessment->submissiongrade;
}
if (is_null($assessment->grade)) {
// this was not assessed yet
continue;
}
if ($assessment->weight == 0) {
// this does not influence the calculation
continue;
}
$sumgrades += $assessment->grade * $assessment->weight;
$sumweights += $assessment->weight;
}
if ($sumweights > 0 and is_null($finalgrade)) {
$finalgrade = grade_floatval($sumgrades / $sumweights);
}
// check if the new final grade differs from the one stored in the database
if (grade_floats_different($finalgrade, $current)) {
// we need to save new calculation into the database
$record = new stdclass();
$record->id = $submissionid;
$record->grade = $finalgrade;
$record->timegraded = time();
$DB->update_record('workshop_submissions', $record);
}
}
|
[
"protected",
"function",
"aggregate_submission_grades_process",
"(",
"array",
"$",
"assessments",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"submissionid",
"=",
"null",
";",
"// the id of the submission being processed",
"$",
"current",
"=",
"null",
";",
"// the grade currently saved in database",
"$",
"finalgrade",
"=",
"null",
";",
"// the new grade to be calculated",
"$",
"sumgrades",
"=",
"0",
";",
"$",
"sumweights",
"=",
"0",
";",
"foreach",
"(",
"$",
"assessments",
"as",
"$",
"assessment",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"submissionid",
")",
")",
"{",
"// the id is the same in all records, fetch it during the first loop cycle",
"$",
"submissionid",
"=",
"$",
"assessment",
"->",
"submissionid",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"current",
")",
")",
"{",
"// the currently saved grade is the same in all records, fetch it during the first loop cycle",
"$",
"current",
"=",
"$",
"assessment",
"->",
"submissiongrade",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"assessment",
"->",
"grade",
")",
")",
"{",
"// this was not assessed yet",
"continue",
";",
"}",
"if",
"(",
"$",
"assessment",
"->",
"weight",
"==",
"0",
")",
"{",
"// this does not influence the calculation",
"continue",
";",
"}",
"$",
"sumgrades",
"+=",
"$",
"assessment",
"->",
"grade",
"*",
"$",
"assessment",
"->",
"weight",
";",
"$",
"sumweights",
"+=",
"$",
"assessment",
"->",
"weight",
";",
"}",
"if",
"(",
"$",
"sumweights",
">",
"0",
"and",
"is_null",
"(",
"$",
"finalgrade",
")",
")",
"{",
"$",
"finalgrade",
"=",
"grade_floatval",
"(",
"$",
"sumgrades",
"/",
"$",
"sumweights",
")",
";",
"}",
"// check if the new final grade differs from the one stored in the database",
"if",
"(",
"grade_floats_different",
"(",
"$",
"finalgrade",
",",
"$",
"current",
")",
")",
"{",
"// we need to save new calculation into the database",
"$",
"record",
"=",
"new",
"stdclass",
"(",
")",
";",
"$",
"record",
"->",
"id",
"=",
"$",
"submissionid",
";",
"$",
"record",
"->",
"grade",
"=",
"$",
"finalgrade",
";",
"$",
"record",
"->",
"timegraded",
"=",
"time",
"(",
")",
";",
"$",
"DB",
"->",
"update_record",
"(",
"'workshop_submissions'",
",",
"$",
"record",
")",
";",
"}",
"}"
] |
Given an array of all assessments of a single submission, calculates the final grade for this submission
This calculates the weighted mean of the passed assessment grades. If, however, the submission grade
was overridden by a teacher, the gradeover value is returned and the rest of grades are ignored.
@param array $assessments of stdclass(->submissionid ->submissiongrade ->gradeover ->weight ->grade)
@return void
|
[
"Given",
"an",
"array",
"of",
"all",
"assessments",
"of",
"a",
"single",
"submission",
"calculates",
"the",
"final",
"grade",
"for",
"this",
"submission"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/locallib.php#L3221-L3262
|
215,201
|
moodle/moodle
|
mod/workshop/locallib.php
|
workshop.aggregate_grading_grades_process
|
protected function aggregate_grading_grades_process(array $assessments, $timegraded = null) {
global $DB;
$reviewerid = null; // the id of the reviewer being processed
$current = null; // the gradinggrade currently saved in database
$finalgrade = null; // the new grade to be calculated
$agid = null; // aggregation id
$sumgrades = 0;
$count = 0;
if (is_null($timegraded)) {
$timegraded = time();
}
foreach ($assessments as $assessment) {
if (is_null($reviewerid)) {
// the id is the same in all records, fetch it during the first loop cycle
$reviewerid = $assessment->reviewerid;
}
if (is_null($agid)) {
// the id is the same in all records, fetch it during the first loop cycle
$agid = $assessment->aggregationid;
}
if (is_null($current)) {
// the currently saved grade is the same in all records, fetch it during the first loop cycle
$current = $assessment->aggregatedgrade;
}
if (!is_null($assessment->gradinggradeover)) {
// the grading grade for this assessment is overridden by a teacher
$sumgrades += $assessment->gradinggradeover;
$count++;
} else {
if (!is_null($assessment->gradinggrade)) {
$sumgrades += $assessment->gradinggrade;
$count++;
}
}
}
if ($count > 0) {
$finalgrade = grade_floatval($sumgrades / $count);
}
// Event information.
$params = array(
'context' => $this->context,
'courseid' => $this->course->id,
'relateduserid' => $reviewerid
);
// check if the new final grade differs from the one stored in the database
if (grade_floats_different($finalgrade, $current)) {
$params['other'] = array(
'currentgrade' => $current,
'finalgrade' => $finalgrade
);
// we need to save new calculation into the database
if (is_null($agid)) {
// no aggregation record yet
$record = new stdclass();
$record->workshopid = $this->id;
$record->userid = $reviewerid;
$record->gradinggrade = $finalgrade;
$record->timegraded = $timegraded;
$record->id = $DB->insert_record('workshop_aggregations', $record);
$params['objectid'] = $record->id;
$event = \mod_workshop\event\assessment_evaluated::create($params);
$event->trigger();
} else {
$record = new stdclass();
$record->id = $agid;
$record->gradinggrade = $finalgrade;
$record->timegraded = $timegraded;
$DB->update_record('workshop_aggregations', $record);
$params['objectid'] = $agid;
$event = \mod_workshop\event\assessment_reevaluated::create($params);
$event->trigger();
}
}
}
|
php
|
protected function aggregate_grading_grades_process(array $assessments, $timegraded = null) {
global $DB;
$reviewerid = null; // the id of the reviewer being processed
$current = null; // the gradinggrade currently saved in database
$finalgrade = null; // the new grade to be calculated
$agid = null; // aggregation id
$sumgrades = 0;
$count = 0;
if (is_null($timegraded)) {
$timegraded = time();
}
foreach ($assessments as $assessment) {
if (is_null($reviewerid)) {
// the id is the same in all records, fetch it during the first loop cycle
$reviewerid = $assessment->reviewerid;
}
if (is_null($agid)) {
// the id is the same in all records, fetch it during the first loop cycle
$agid = $assessment->aggregationid;
}
if (is_null($current)) {
// the currently saved grade is the same in all records, fetch it during the first loop cycle
$current = $assessment->aggregatedgrade;
}
if (!is_null($assessment->gradinggradeover)) {
// the grading grade for this assessment is overridden by a teacher
$sumgrades += $assessment->gradinggradeover;
$count++;
} else {
if (!is_null($assessment->gradinggrade)) {
$sumgrades += $assessment->gradinggrade;
$count++;
}
}
}
if ($count > 0) {
$finalgrade = grade_floatval($sumgrades / $count);
}
// Event information.
$params = array(
'context' => $this->context,
'courseid' => $this->course->id,
'relateduserid' => $reviewerid
);
// check if the new final grade differs from the one stored in the database
if (grade_floats_different($finalgrade, $current)) {
$params['other'] = array(
'currentgrade' => $current,
'finalgrade' => $finalgrade
);
// we need to save new calculation into the database
if (is_null($agid)) {
// no aggregation record yet
$record = new stdclass();
$record->workshopid = $this->id;
$record->userid = $reviewerid;
$record->gradinggrade = $finalgrade;
$record->timegraded = $timegraded;
$record->id = $DB->insert_record('workshop_aggregations', $record);
$params['objectid'] = $record->id;
$event = \mod_workshop\event\assessment_evaluated::create($params);
$event->trigger();
} else {
$record = new stdclass();
$record->id = $agid;
$record->gradinggrade = $finalgrade;
$record->timegraded = $timegraded;
$DB->update_record('workshop_aggregations', $record);
$params['objectid'] = $agid;
$event = \mod_workshop\event\assessment_reevaluated::create($params);
$event->trigger();
}
}
}
|
[
"protected",
"function",
"aggregate_grading_grades_process",
"(",
"array",
"$",
"assessments",
",",
"$",
"timegraded",
"=",
"null",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"reviewerid",
"=",
"null",
";",
"// the id of the reviewer being processed",
"$",
"current",
"=",
"null",
";",
"// the gradinggrade currently saved in database",
"$",
"finalgrade",
"=",
"null",
";",
"// the new grade to be calculated",
"$",
"agid",
"=",
"null",
";",
"// aggregation id",
"$",
"sumgrades",
"=",
"0",
";",
"$",
"count",
"=",
"0",
";",
"if",
"(",
"is_null",
"(",
"$",
"timegraded",
")",
")",
"{",
"$",
"timegraded",
"=",
"time",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"assessments",
"as",
"$",
"assessment",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"reviewerid",
")",
")",
"{",
"// the id is the same in all records, fetch it during the first loop cycle",
"$",
"reviewerid",
"=",
"$",
"assessment",
"->",
"reviewerid",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"agid",
")",
")",
"{",
"// the id is the same in all records, fetch it during the first loop cycle",
"$",
"agid",
"=",
"$",
"assessment",
"->",
"aggregationid",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"current",
")",
")",
"{",
"// the currently saved grade is the same in all records, fetch it during the first loop cycle",
"$",
"current",
"=",
"$",
"assessment",
"->",
"aggregatedgrade",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"assessment",
"->",
"gradinggradeover",
")",
")",
"{",
"// the grading grade for this assessment is overridden by a teacher",
"$",
"sumgrades",
"+=",
"$",
"assessment",
"->",
"gradinggradeover",
";",
"$",
"count",
"++",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"assessment",
"->",
"gradinggrade",
")",
")",
"{",
"$",
"sumgrades",
"+=",
"$",
"assessment",
"->",
"gradinggrade",
";",
"$",
"count",
"++",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"count",
">",
"0",
")",
"{",
"$",
"finalgrade",
"=",
"grade_floatval",
"(",
"$",
"sumgrades",
"/",
"$",
"count",
")",
";",
"}",
"// Event information.",
"$",
"params",
"=",
"array",
"(",
"'context'",
"=>",
"$",
"this",
"->",
"context",
",",
"'courseid'",
"=>",
"$",
"this",
"->",
"course",
"->",
"id",
",",
"'relateduserid'",
"=>",
"$",
"reviewerid",
")",
";",
"// check if the new final grade differs from the one stored in the database",
"if",
"(",
"grade_floats_different",
"(",
"$",
"finalgrade",
",",
"$",
"current",
")",
")",
"{",
"$",
"params",
"[",
"'other'",
"]",
"=",
"array",
"(",
"'currentgrade'",
"=>",
"$",
"current",
",",
"'finalgrade'",
"=>",
"$",
"finalgrade",
")",
";",
"// we need to save new calculation into the database",
"if",
"(",
"is_null",
"(",
"$",
"agid",
")",
")",
"{",
"// no aggregation record yet",
"$",
"record",
"=",
"new",
"stdclass",
"(",
")",
";",
"$",
"record",
"->",
"workshopid",
"=",
"$",
"this",
"->",
"id",
";",
"$",
"record",
"->",
"userid",
"=",
"$",
"reviewerid",
";",
"$",
"record",
"->",
"gradinggrade",
"=",
"$",
"finalgrade",
";",
"$",
"record",
"->",
"timegraded",
"=",
"$",
"timegraded",
";",
"$",
"record",
"->",
"id",
"=",
"$",
"DB",
"->",
"insert_record",
"(",
"'workshop_aggregations'",
",",
"$",
"record",
")",
";",
"$",
"params",
"[",
"'objectid'",
"]",
"=",
"$",
"record",
"->",
"id",
";",
"$",
"event",
"=",
"\\",
"mod_workshop",
"\\",
"event",
"\\",
"assessment_evaluated",
"::",
"create",
"(",
"$",
"params",
")",
";",
"$",
"event",
"->",
"trigger",
"(",
")",
";",
"}",
"else",
"{",
"$",
"record",
"=",
"new",
"stdclass",
"(",
")",
";",
"$",
"record",
"->",
"id",
"=",
"$",
"agid",
";",
"$",
"record",
"->",
"gradinggrade",
"=",
"$",
"finalgrade",
";",
"$",
"record",
"->",
"timegraded",
"=",
"$",
"timegraded",
";",
"$",
"DB",
"->",
"update_record",
"(",
"'workshop_aggregations'",
",",
"$",
"record",
")",
";",
"$",
"params",
"[",
"'objectid'",
"]",
"=",
"$",
"agid",
";",
"$",
"event",
"=",
"\\",
"mod_workshop",
"\\",
"event",
"\\",
"assessment_reevaluated",
"::",
"create",
"(",
"$",
"params",
")",
";",
"$",
"event",
"->",
"trigger",
"(",
")",
";",
"}",
"}",
"}"
] |
Given an array of all assessments done by a single reviewer, calculates the final grading grade
This calculates the simple mean of the passed grading grades. If, however, the grading grade
was overridden by a teacher, the gradinggradeover value is returned and the rest of grades are ignored.
@param array $assessments of stdclass(->reviewerid ->gradinggrade ->gradinggradeover ->aggregationid ->aggregatedgrade)
@param null|int $timegraded explicit timestamp of the aggregation, defaults to the current time
@return void
|
[
"Given",
"an",
"array",
"of",
"all",
"assessments",
"done",
"by",
"a",
"single",
"reviewer",
"calculates",
"the",
"final",
"grading",
"grade"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/locallib.php#L3274-L3353
|
215,202
|
moodle/moodle
|
mod/workshop/locallib.php
|
workshop.get_users_with_capability_sql
|
protected function get_users_with_capability_sql($capability, $musthavesubmission, $groupid) {
global $CFG;
/** @var int static counter used to generate unique parameter holders */
static $inc = 0;
$inc++;
// If the caller requests all groups and we are using a selected grouping,
// recursively call this function for each group in the grouping (this is
// needed because get_enrolled_sql only supports a single group).
if (empty($groupid) and $this->cm->groupingid) {
$groupingid = $this->cm->groupingid;
$groupinggroupids = array_keys(groups_get_all_groups($this->cm->course, 0, $this->cm->groupingid, 'g.id'));
$sql = array();
$params = array();
foreach ($groupinggroupids as $groupinggroupid) {
if ($groupinggroupid > 0) { // just in case in order not to fall into the endless loop
list($gsql, $gparams) = $this->get_users_with_capability_sql($capability, $musthavesubmission, $groupinggroupid);
$sql[] = $gsql;
$params = array_merge($params, $gparams);
}
}
$sql = implode(PHP_EOL." UNION ".PHP_EOL, $sql);
return array($sql, $params);
}
list($esql, $params) = get_enrolled_sql($this->context, $capability, $groupid, true);
$userfields = user_picture::fields('u');
$sql = "SELECT $userfields
FROM {user} u
JOIN ($esql) je ON (je.id = u.id AND u.deleted = 0) ";
if ($musthavesubmission) {
$sql .= " JOIN {workshop_submissions} ws ON (ws.authorid = u.id AND ws.example = 0 AND ws.workshopid = :workshopid{$inc}) ";
$params['workshopid'.$inc] = $this->id;
}
// If the activity is restricted so that only certain users should appear
// in user lists, integrate this into the same SQL.
$info = new \core_availability\info_module($this->cm);
list ($listsql, $listparams) = $info->get_user_list_sql(false);
if ($listsql) {
$sql .= " JOIN ($listsql) restricted ON restricted.id = u.id ";
$params = array_merge($params, $listparams);
}
return array($sql, $params);
}
|
php
|
protected function get_users_with_capability_sql($capability, $musthavesubmission, $groupid) {
global $CFG;
/** @var int static counter used to generate unique parameter holders */
static $inc = 0;
$inc++;
// If the caller requests all groups and we are using a selected grouping,
// recursively call this function for each group in the grouping (this is
// needed because get_enrolled_sql only supports a single group).
if (empty($groupid) and $this->cm->groupingid) {
$groupingid = $this->cm->groupingid;
$groupinggroupids = array_keys(groups_get_all_groups($this->cm->course, 0, $this->cm->groupingid, 'g.id'));
$sql = array();
$params = array();
foreach ($groupinggroupids as $groupinggroupid) {
if ($groupinggroupid > 0) { // just in case in order not to fall into the endless loop
list($gsql, $gparams) = $this->get_users_with_capability_sql($capability, $musthavesubmission, $groupinggroupid);
$sql[] = $gsql;
$params = array_merge($params, $gparams);
}
}
$sql = implode(PHP_EOL." UNION ".PHP_EOL, $sql);
return array($sql, $params);
}
list($esql, $params) = get_enrolled_sql($this->context, $capability, $groupid, true);
$userfields = user_picture::fields('u');
$sql = "SELECT $userfields
FROM {user} u
JOIN ($esql) je ON (je.id = u.id AND u.deleted = 0) ";
if ($musthavesubmission) {
$sql .= " JOIN {workshop_submissions} ws ON (ws.authorid = u.id AND ws.example = 0 AND ws.workshopid = :workshopid{$inc}) ";
$params['workshopid'.$inc] = $this->id;
}
// If the activity is restricted so that only certain users should appear
// in user lists, integrate this into the same SQL.
$info = new \core_availability\info_module($this->cm);
list ($listsql, $listparams) = $info->get_user_list_sql(false);
if ($listsql) {
$sql .= " JOIN ($listsql) restricted ON restricted.id = u.id ";
$params = array_merge($params, $listparams);
}
return array($sql, $params);
}
|
[
"protected",
"function",
"get_users_with_capability_sql",
"(",
"$",
"capability",
",",
"$",
"musthavesubmission",
",",
"$",
"groupid",
")",
"{",
"global",
"$",
"CFG",
";",
"/** @var int static counter used to generate unique parameter holders */",
"static",
"$",
"inc",
"=",
"0",
";",
"$",
"inc",
"++",
";",
"// If the caller requests all groups and we are using a selected grouping,",
"// recursively call this function for each group in the grouping (this is",
"// needed because get_enrolled_sql only supports a single group).",
"if",
"(",
"empty",
"(",
"$",
"groupid",
")",
"and",
"$",
"this",
"->",
"cm",
"->",
"groupingid",
")",
"{",
"$",
"groupingid",
"=",
"$",
"this",
"->",
"cm",
"->",
"groupingid",
";",
"$",
"groupinggroupids",
"=",
"array_keys",
"(",
"groups_get_all_groups",
"(",
"$",
"this",
"->",
"cm",
"->",
"course",
",",
"0",
",",
"$",
"this",
"->",
"cm",
"->",
"groupingid",
",",
"'g.id'",
")",
")",
";",
"$",
"sql",
"=",
"array",
"(",
")",
";",
"$",
"params",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"groupinggroupids",
"as",
"$",
"groupinggroupid",
")",
"{",
"if",
"(",
"$",
"groupinggroupid",
">",
"0",
")",
"{",
"// just in case in order not to fall into the endless loop",
"list",
"(",
"$",
"gsql",
",",
"$",
"gparams",
")",
"=",
"$",
"this",
"->",
"get_users_with_capability_sql",
"(",
"$",
"capability",
",",
"$",
"musthavesubmission",
",",
"$",
"groupinggroupid",
")",
";",
"$",
"sql",
"[",
"]",
"=",
"$",
"gsql",
";",
"$",
"params",
"=",
"array_merge",
"(",
"$",
"params",
",",
"$",
"gparams",
")",
";",
"}",
"}",
"$",
"sql",
"=",
"implode",
"(",
"PHP_EOL",
".",
"\" UNION \"",
".",
"PHP_EOL",
",",
"$",
"sql",
")",
";",
"return",
"array",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"}",
"list",
"(",
"$",
"esql",
",",
"$",
"params",
")",
"=",
"get_enrolled_sql",
"(",
"$",
"this",
"->",
"context",
",",
"$",
"capability",
",",
"$",
"groupid",
",",
"true",
")",
";",
"$",
"userfields",
"=",
"user_picture",
"::",
"fields",
"(",
"'u'",
")",
";",
"$",
"sql",
"=",
"\"SELECT $userfields\n FROM {user} u\n JOIN ($esql) je ON (je.id = u.id AND u.deleted = 0) \"",
";",
"if",
"(",
"$",
"musthavesubmission",
")",
"{",
"$",
"sql",
".=",
"\" JOIN {workshop_submissions} ws ON (ws.authorid = u.id AND ws.example = 0 AND ws.workshopid = :workshopid{$inc}) \"",
";",
"$",
"params",
"[",
"'workshopid'",
".",
"$",
"inc",
"]",
"=",
"$",
"this",
"->",
"id",
";",
"}",
"// If the activity is restricted so that only certain users should appear",
"// in user lists, integrate this into the same SQL.",
"$",
"info",
"=",
"new",
"\\",
"core_availability",
"\\",
"info_module",
"(",
"$",
"this",
"->",
"cm",
")",
";",
"list",
"(",
"$",
"listsql",
",",
"$",
"listparams",
")",
"=",
"$",
"info",
"->",
"get_user_list_sql",
"(",
"false",
")",
";",
"if",
"(",
"$",
"listsql",
")",
"{",
"$",
"sql",
".=",
"\" JOIN ($listsql) restricted ON restricted.id = u.id \"",
";",
"$",
"params",
"=",
"array_merge",
"(",
"$",
"params",
",",
"$",
"listparams",
")",
";",
"}",
"return",
"array",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"}"
] |
Returns SQL to fetch all enrolled users with the given capability in the current workshop
The returned array consists of string $sql and the $params array. Note that the $sql can be
empty if a grouping is selected and it has no groups.
The list is automatically restricted according to any availability restrictions
that apply to user lists (e.g. group, grouping restrictions).
@param string $capability the name of the capability
@param bool $musthavesubmission ff true, return only users who have already submitted
@param int $groupid 0 means ignore groups, any other value limits the result by group id
@return array of (string)sql, (array)params
|
[
"Returns",
"SQL",
"to",
"fetch",
"all",
"enrolled",
"users",
"with",
"the",
"given",
"capability",
"in",
"the",
"current",
"workshop"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/locallib.php#L3369-L3417
|
215,203
|
moodle/moodle
|
mod/workshop/locallib.php
|
workshop.get_participants_sql
|
protected function get_participants_sql($musthavesubmission=false, $groupid=0) {
list($sql1, $params1) = $this->get_users_with_capability_sql('mod/workshop:submit', $musthavesubmission, $groupid);
list($sql2, $params2) = $this->get_users_with_capability_sql('mod/workshop:peerassess', $musthavesubmission, $groupid);
if (empty($sql1) or empty($sql2)) {
if (empty($sql1) and empty($sql2)) {
return array('', array());
} else if (empty($sql1)) {
$sql = $sql2;
$params = $params2;
} else {
$sql = $sql1;
$params = $params1;
}
} else {
$sql = $sql1.PHP_EOL." UNION ".PHP_EOL.$sql2;
$params = array_merge($params1, $params2);
}
return array($sql, $params);
}
|
php
|
protected function get_participants_sql($musthavesubmission=false, $groupid=0) {
list($sql1, $params1) = $this->get_users_with_capability_sql('mod/workshop:submit', $musthavesubmission, $groupid);
list($sql2, $params2) = $this->get_users_with_capability_sql('mod/workshop:peerassess', $musthavesubmission, $groupid);
if (empty($sql1) or empty($sql2)) {
if (empty($sql1) and empty($sql2)) {
return array('', array());
} else if (empty($sql1)) {
$sql = $sql2;
$params = $params2;
} else {
$sql = $sql1;
$params = $params1;
}
} else {
$sql = $sql1.PHP_EOL." UNION ".PHP_EOL.$sql2;
$params = array_merge($params1, $params2);
}
return array($sql, $params);
}
|
[
"protected",
"function",
"get_participants_sql",
"(",
"$",
"musthavesubmission",
"=",
"false",
",",
"$",
"groupid",
"=",
"0",
")",
"{",
"list",
"(",
"$",
"sql1",
",",
"$",
"params1",
")",
"=",
"$",
"this",
"->",
"get_users_with_capability_sql",
"(",
"'mod/workshop:submit'",
",",
"$",
"musthavesubmission",
",",
"$",
"groupid",
")",
";",
"list",
"(",
"$",
"sql2",
",",
"$",
"params2",
")",
"=",
"$",
"this",
"->",
"get_users_with_capability_sql",
"(",
"'mod/workshop:peerassess'",
",",
"$",
"musthavesubmission",
",",
"$",
"groupid",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"sql1",
")",
"or",
"empty",
"(",
"$",
"sql2",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"sql1",
")",
"and",
"empty",
"(",
"$",
"sql2",
")",
")",
"{",
"return",
"array",
"(",
"''",
",",
"array",
"(",
")",
")",
";",
"}",
"else",
"if",
"(",
"empty",
"(",
"$",
"sql1",
")",
")",
"{",
"$",
"sql",
"=",
"$",
"sql2",
";",
"$",
"params",
"=",
"$",
"params2",
";",
"}",
"else",
"{",
"$",
"sql",
"=",
"$",
"sql1",
";",
"$",
"params",
"=",
"$",
"params1",
";",
"}",
"}",
"else",
"{",
"$",
"sql",
"=",
"$",
"sql1",
".",
"PHP_EOL",
".",
"\" UNION \"",
".",
"PHP_EOL",
".",
"$",
"sql2",
";",
"$",
"params",
"=",
"array_merge",
"(",
"$",
"params1",
",",
"$",
"params2",
")",
";",
"}",
"return",
"array",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"}"
] |
Returns SQL statement that can be used to fetch all actively enrolled participants in the workshop
@param bool $musthavesubmission if true, return only users who have already submitted
@param int $groupid 0 means ignore groups, any other value limits the result by group id
@return array of (string)sql, (array)params
|
[
"Returns",
"SQL",
"statement",
"that",
"can",
"be",
"used",
"to",
"fetch",
"all",
"actively",
"enrolled",
"participants",
"in",
"the",
"workshop"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/locallib.php#L3426-L3447
|
215,204
|
moodle/moodle
|
mod/workshop/locallib.php
|
workshop.reset_userdata_submissions
|
protected function reset_userdata_submissions(stdClass $data) {
global $DB;
$submissions = $this->get_submissions();
foreach ($submissions as $submission) {
$this->delete_submission($submission);
}
return true;
}
|
php
|
protected function reset_userdata_submissions(stdClass $data) {
global $DB;
$submissions = $this->get_submissions();
foreach ($submissions as $submission) {
$this->delete_submission($submission);
}
return true;
}
|
[
"protected",
"function",
"reset_userdata_submissions",
"(",
"stdClass",
"$",
"data",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"submissions",
"=",
"$",
"this",
"->",
"get_submissions",
"(",
")",
";",
"foreach",
"(",
"$",
"submissions",
"as",
"$",
"submission",
")",
"{",
"$",
"this",
"->",
"delete_submission",
"(",
"$",
"submission",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Removes all user data related to participants' submissions.
@param stdClass $data The actual course reset settings.
@return bool|string True on success, error message otherwise.
|
[
"Removes",
"all",
"user",
"data",
"related",
"to",
"participants",
"submissions",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/locallib.php#L3511-L3520
|
215,205
|
moodle/moodle
|
mod/workshop/locallib.php
|
workshop.reset_phase
|
protected function reset_phase() {
global $DB;
$DB->set_field('workshop', 'phase', self::PHASE_SETUP, array('id' => $this->id));
$this->phase = self::PHASE_SETUP;
}
|
php
|
protected function reset_phase() {
global $DB;
$DB->set_field('workshop', 'phase', self::PHASE_SETUP, array('id' => $this->id));
$this->phase = self::PHASE_SETUP;
}
|
[
"protected",
"function",
"reset_phase",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"DB",
"->",
"set_field",
"(",
"'workshop'",
",",
"'phase'",
",",
"self",
"::",
"PHASE_SETUP",
",",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"id",
")",
")",
";",
"$",
"this",
"->",
"phase",
"=",
"self",
"::",
"PHASE_SETUP",
";",
"}"
] |
Hard set the workshop phase to the setup one.
|
[
"Hard",
"set",
"the",
"workshop",
"phase",
"to",
"the",
"setup",
"one",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/locallib.php#L3525-L3530
|
215,206
|
moodle/moodle
|
mod/workshop/locallib.php
|
workshop_user_plan.get_examples
|
public function get_examples() {
if (is_null($this->examples)) {
$this->examples = $this->workshop->get_examples_for_reviewer($this->userid);
}
return $this->examples;
}
|
php
|
public function get_examples() {
if (is_null($this->examples)) {
$this->examples = $this->workshop->get_examples_for_reviewer($this->userid);
}
return $this->examples;
}
|
[
"public",
"function",
"get_examples",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"examples",
")",
")",
"{",
"$",
"this",
"->",
"examples",
"=",
"$",
"this",
"->",
"workshop",
"->",
"get_examples_for_reviewer",
"(",
"$",
"this",
"->",
"userid",
")",
";",
"}",
"return",
"$",
"this",
"->",
"examples",
";",
"}"
] |
Returns example submissions to be assessed by the owner of the planner
This is here to cache the DB query because the same list is needed later in view.php
@see workshop::get_examples_for_reviewer() for the format of returned value
@return array
|
[
"Returns",
"example",
"submissions",
"to",
"be",
"assessed",
"by",
"the",
"owner",
"of",
"the",
"planner"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/locallib.php#L3984-L3989
|
215,207
|
moodle/moodle
|
mod/workshop/locallib.php
|
workshop_submission_base.anonymize
|
public function anonymize() {
$authorfields = explode(',', user_picture::fields());
foreach ($authorfields as $field) {
$prefixedusernamefield = 'author' . $field;
unset($this->{$prefixedusernamefield});
}
$this->anonymous = true;
}
|
php
|
public function anonymize() {
$authorfields = explode(',', user_picture::fields());
foreach ($authorfields as $field) {
$prefixedusernamefield = 'author' . $field;
unset($this->{$prefixedusernamefield});
}
$this->anonymous = true;
}
|
[
"public",
"function",
"anonymize",
"(",
")",
"{",
"$",
"authorfields",
"=",
"explode",
"(",
"','",
",",
"user_picture",
"::",
"fields",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"authorfields",
"as",
"$",
"field",
")",
"{",
"$",
"prefixedusernamefield",
"=",
"'author'",
".",
"$",
"field",
";",
"unset",
"(",
"$",
"this",
"->",
"{",
"$",
"prefixedusernamefield",
"}",
")",
";",
"}",
"$",
"this",
"->",
"anonymous",
"=",
"true",
";",
"}"
] |
Unsets all author-related properties so that the renderer does not have access to them
Usually this is called by the contructor but can be called explicitely, too.
|
[
"Unsets",
"all",
"author",
"-",
"related",
"properties",
"so",
"that",
"the",
"renderer",
"does",
"not",
"have",
"access",
"to",
"them"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/locallib.php#L4044-L4051
|
215,208
|
moodle/moodle
|
mod/workshop/locallib.php
|
workshop_assessment_base.add_action
|
public function add_action(moodle_url $url, $label, $method = 'get') {
$action = new stdClass();
$action->url = $url;
$action->label = $label;
$action->method = $method;
$this->actions[] = $action;
}
|
php
|
public function add_action(moodle_url $url, $label, $method = 'get') {
$action = new stdClass();
$action->url = $url;
$action->label = $label;
$action->method = $method;
$this->actions[] = $action;
}
|
[
"public",
"function",
"add_action",
"(",
"moodle_url",
"$",
"url",
",",
"$",
"label",
",",
"$",
"method",
"=",
"'get'",
")",
"{",
"$",
"action",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"action",
"->",
"url",
"=",
"$",
"url",
";",
"$",
"action",
"->",
"label",
"=",
"$",
"label",
";",
"$",
"action",
"->",
"method",
"=",
"$",
"method",
";",
"$",
"this",
"->",
"actions",
"[",
"]",
"=",
"$",
"action",
";",
"}"
] |
Adds a new action
@param moodle_url $url action URL
@param string $label action label
@param string $method get|post
|
[
"Adds",
"a",
"new",
"action"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/locallib.php#L4285-L4293
|
215,209
|
moodle/moodle
|
mod/workshop/locallib.php
|
workshop_assessment.get_overall_feedback_content
|
public function get_overall_feedback_content() {
if ($this->workshop->overallfeedbackmode == 0) {
return false;
}
if (trim($this->feedbackauthor) === '') {
return null;
}
$content = file_rewrite_pluginfile_urls($this->feedbackauthor, 'pluginfile.php', $this->workshop->context->id,
'mod_workshop', 'overallfeedback_content', $this->id);
$content = format_text($content, $this->feedbackauthorformat,
array('overflowdiv' => true, 'context' => $this->workshop->context));
return $content;
}
|
php
|
public function get_overall_feedback_content() {
if ($this->workshop->overallfeedbackmode == 0) {
return false;
}
if (trim($this->feedbackauthor) === '') {
return null;
}
$content = file_rewrite_pluginfile_urls($this->feedbackauthor, 'pluginfile.php', $this->workshop->context->id,
'mod_workshop', 'overallfeedback_content', $this->id);
$content = format_text($content, $this->feedbackauthorformat,
array('overflowdiv' => true, 'context' => $this->workshop->context));
return $content;
}
|
[
"public",
"function",
"get_overall_feedback_content",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"workshop",
"->",
"overallfeedbackmode",
"==",
"0",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"trim",
"(",
"$",
"this",
"->",
"feedbackauthor",
")",
"===",
"''",
")",
"{",
"return",
"null",
";",
"}",
"$",
"content",
"=",
"file_rewrite_pluginfile_urls",
"(",
"$",
"this",
"->",
"feedbackauthor",
",",
"'pluginfile.php'",
",",
"$",
"this",
"->",
"workshop",
"->",
"context",
"->",
"id",
",",
"'mod_workshop'",
",",
"'overallfeedback_content'",
",",
"$",
"this",
"->",
"id",
")",
";",
"$",
"content",
"=",
"format_text",
"(",
"$",
"content",
",",
"$",
"this",
"->",
"feedbackauthorformat",
",",
"array",
"(",
"'overflowdiv'",
"=>",
"true",
",",
"'context'",
"=>",
"$",
"this",
"->",
"workshop",
"->",
"context",
")",
")",
";",
"return",
"$",
"content",
";",
"}"
] |
Format the overall feedback text content
False is returned if the overall feedback feature is disabled. Null is returned
if the overall feedback content has not been found. Otherwise, string with
formatted feedback text is returned.
@return string|bool|null
|
[
"Format",
"the",
"overall",
"feedback",
"text",
"content"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/locallib.php#L4359-L4375
|
215,210
|
moodle/moodle
|
mod/workshop/locallib.php
|
workshop_assessment.get_overall_feedback_attachments
|
public function get_overall_feedback_attachments() {
if ($this->workshop->overallfeedbackmode == 0) {
return false;
}
if ($this->workshop->overallfeedbackfiles == 0) {
return false;
}
if (empty($this->feedbackauthorattachment)) {
return array();
}
$attachments = array();
$fs = get_file_storage();
$files = $fs->get_area_files($this->workshop->context->id, 'mod_workshop', 'overallfeedback_attachment', $this->id);
foreach ($files as $file) {
if ($file->is_directory()) {
continue;
}
$filepath = $file->get_filepath();
$filename = $file->get_filename();
$fileurl = moodle_url::make_pluginfile_url($this->workshop->context->id, 'mod_workshop',
'overallfeedback_attachment', $this->id, $filepath, $filename, true);
$previewurl = new moodle_url(moodle_url::make_pluginfile_url($this->workshop->context->id, 'mod_workshop',
'overallfeedback_attachment', $this->id, $filepath, $filename, false), array('preview' => 'bigthumb'));
$attachments[] = (object)array(
'filepath' => $filepath,
'filename' => $filename,
'fileurl' => $fileurl,
'previewurl' => $previewurl,
'mimetype' => $file->get_mimetype(),
);
}
return $attachments;
}
|
php
|
public function get_overall_feedback_attachments() {
if ($this->workshop->overallfeedbackmode == 0) {
return false;
}
if ($this->workshop->overallfeedbackfiles == 0) {
return false;
}
if (empty($this->feedbackauthorattachment)) {
return array();
}
$attachments = array();
$fs = get_file_storage();
$files = $fs->get_area_files($this->workshop->context->id, 'mod_workshop', 'overallfeedback_attachment', $this->id);
foreach ($files as $file) {
if ($file->is_directory()) {
continue;
}
$filepath = $file->get_filepath();
$filename = $file->get_filename();
$fileurl = moodle_url::make_pluginfile_url($this->workshop->context->id, 'mod_workshop',
'overallfeedback_attachment', $this->id, $filepath, $filename, true);
$previewurl = new moodle_url(moodle_url::make_pluginfile_url($this->workshop->context->id, 'mod_workshop',
'overallfeedback_attachment', $this->id, $filepath, $filename, false), array('preview' => 'bigthumb'));
$attachments[] = (object)array(
'filepath' => $filepath,
'filename' => $filename,
'fileurl' => $fileurl,
'previewurl' => $previewurl,
'mimetype' => $file->get_mimetype(),
);
}
return $attachments;
}
|
[
"public",
"function",
"get_overall_feedback_attachments",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"workshop",
"->",
"overallfeedbackmode",
"==",
"0",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"workshop",
"->",
"overallfeedbackfiles",
"==",
"0",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"feedbackauthorattachment",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"attachments",
"=",
"array",
"(",
")",
";",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"$",
"files",
"=",
"$",
"fs",
"->",
"get_area_files",
"(",
"$",
"this",
"->",
"workshop",
"->",
"context",
"->",
"id",
",",
"'mod_workshop'",
",",
"'overallfeedback_attachment'",
",",
"$",
"this",
"->",
"id",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"->",
"is_directory",
"(",
")",
")",
"{",
"continue",
";",
"}",
"$",
"filepath",
"=",
"$",
"file",
"->",
"get_filepath",
"(",
")",
";",
"$",
"filename",
"=",
"$",
"file",
"->",
"get_filename",
"(",
")",
";",
"$",
"fileurl",
"=",
"moodle_url",
"::",
"make_pluginfile_url",
"(",
"$",
"this",
"->",
"workshop",
"->",
"context",
"->",
"id",
",",
"'mod_workshop'",
",",
"'overallfeedback_attachment'",
",",
"$",
"this",
"->",
"id",
",",
"$",
"filepath",
",",
"$",
"filename",
",",
"true",
")",
";",
"$",
"previewurl",
"=",
"new",
"moodle_url",
"(",
"moodle_url",
"::",
"make_pluginfile_url",
"(",
"$",
"this",
"->",
"workshop",
"->",
"context",
"->",
"id",
",",
"'mod_workshop'",
",",
"'overallfeedback_attachment'",
",",
"$",
"this",
"->",
"id",
",",
"$",
"filepath",
",",
"$",
"filename",
",",
"false",
")",
",",
"array",
"(",
"'preview'",
"=>",
"'bigthumb'",
")",
")",
";",
"$",
"attachments",
"[",
"]",
"=",
"(",
"object",
")",
"array",
"(",
"'filepath'",
"=>",
"$",
"filepath",
",",
"'filename'",
"=>",
"$",
"filename",
",",
"'fileurl'",
"=>",
"$",
"fileurl",
",",
"'previewurl'",
"=>",
"$",
"previewurl",
",",
"'mimetype'",
"=>",
"$",
"file",
"->",
"get_mimetype",
"(",
")",
",",
")",
";",
"}",
"return",
"$",
"attachments",
";",
"}"
] |
Prepares the list of overall feedback attachments
Returns false if overall feedback attachments are not allowed. Otherwise returns
list of attachments (may be empty).
@return bool|array of stdClass
|
[
"Prepares",
"the",
"list",
"of",
"overall",
"feedback",
"attachments"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/locallib.php#L4385-L4423
|
215,211
|
moodle/moodle
|
mod/workshop/locallib.php
|
workshop_message.set_type
|
public function set_type($type = self::TYPE_INFO) {
if (in_array($type, array(self::TYPE_OK, self::TYPE_ERROR, self::TYPE_INFO))) {
$this->type = $type;
} else {
throw new coding_exception('Unknown message type.');
}
}
|
php
|
public function set_type($type = self::TYPE_INFO) {
if (in_array($type, array(self::TYPE_OK, self::TYPE_ERROR, self::TYPE_INFO))) {
$this->type = $type;
} else {
throw new coding_exception('Unknown message type.');
}
}
|
[
"public",
"function",
"set_type",
"(",
"$",
"type",
"=",
"self",
"::",
"TYPE_INFO",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"type",
",",
"array",
"(",
"self",
"::",
"TYPE_OK",
",",
"self",
"::",
"TYPE_ERROR",
",",
"self",
"::",
"TYPE_INFO",
")",
")",
")",
"{",
"$",
"this",
"->",
"type",
"=",
"$",
"type",
";",
"}",
"else",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Unknown message type.'",
")",
";",
"}",
"}"
] |
Sets the message type
@param int $type
|
[
"Sets",
"the",
"message",
"type"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/locallib.php#L4507-L4513
|
215,212
|
moodle/moodle
|
mod/workshop/locallib.php
|
workshop_message.set_action
|
public function set_action(moodle_url $url, $label) {
$this->actionurl = $url;
$this->actionlabel = $label;
}
|
php
|
public function set_action(moodle_url $url, $label) {
$this->actionurl = $url;
$this->actionlabel = $label;
}
|
[
"public",
"function",
"set_action",
"(",
"moodle_url",
"$",
"url",
",",
"$",
"label",
")",
"{",
"$",
"this",
"->",
"actionurl",
"=",
"$",
"url",
";",
"$",
"this",
"->",
"actionlabel",
"=",
"$",
"label",
";",
"}"
] |
Sets the optional message action
@param moodle_url $url to follow on action
@param string $label action label
|
[
"Sets",
"the",
"optional",
"message",
"action"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/locallib.php#L4521-L4524
|
215,213
|
moodle/moodle
|
mod/workshop/locallib.php
|
workshop_grading_report.export_data_for_external
|
public function export_data_for_external() {
$data = $this->get_data();
$options = $this->get_options();
foreach ($data->grades as $reportdata) {
// If we are in submission phase ignore the following data.
if ($options->workshopphase == workshop::PHASE_SUBMISSION) {
unset($reportdata->submissiongrade);
unset($reportdata->gradinggrade);
unset($reportdata->submissiongradeover);
unset($reportdata->submissiongradeoverby);
unset($reportdata->submissionpublished);
unset($reportdata->reviewedby);
unset($reportdata->reviewerof);
continue;
}
if (!$options->showsubmissiongrade) {
unset($reportdata->submissiongrade);
unset($reportdata->submissiongradeover);
}
if (!$options->showgradinggrade and $tr == 0) {
unset($reportdata->gradinggrade);
}
if (!$options->showreviewernames) {
foreach ($reportdata->reviewedby as $reviewedby) {
$reviewedby->userid = 0;
}
}
if (!$options->showauthornames) {
foreach ($reportdata->reviewerof as $reviewerof) {
$reviewerof->userid = 0;
}
}
}
return $data;
}
|
php
|
public function export_data_for_external() {
$data = $this->get_data();
$options = $this->get_options();
foreach ($data->grades as $reportdata) {
// If we are in submission phase ignore the following data.
if ($options->workshopphase == workshop::PHASE_SUBMISSION) {
unset($reportdata->submissiongrade);
unset($reportdata->gradinggrade);
unset($reportdata->submissiongradeover);
unset($reportdata->submissiongradeoverby);
unset($reportdata->submissionpublished);
unset($reportdata->reviewedby);
unset($reportdata->reviewerof);
continue;
}
if (!$options->showsubmissiongrade) {
unset($reportdata->submissiongrade);
unset($reportdata->submissiongradeover);
}
if (!$options->showgradinggrade and $tr == 0) {
unset($reportdata->gradinggrade);
}
if (!$options->showreviewernames) {
foreach ($reportdata->reviewedby as $reviewedby) {
$reviewedby->userid = 0;
}
}
if (!$options->showauthornames) {
foreach ($reportdata->reviewerof as $reviewerof) {
$reviewerof->userid = 0;
}
}
}
return $data;
}
|
[
"public",
"function",
"export_data_for_external",
"(",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"get_data",
"(",
")",
";",
"$",
"options",
"=",
"$",
"this",
"->",
"get_options",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"->",
"grades",
"as",
"$",
"reportdata",
")",
"{",
"// If we are in submission phase ignore the following data.",
"if",
"(",
"$",
"options",
"->",
"workshopphase",
"==",
"workshop",
"::",
"PHASE_SUBMISSION",
")",
"{",
"unset",
"(",
"$",
"reportdata",
"->",
"submissiongrade",
")",
";",
"unset",
"(",
"$",
"reportdata",
"->",
"gradinggrade",
")",
";",
"unset",
"(",
"$",
"reportdata",
"->",
"submissiongradeover",
")",
";",
"unset",
"(",
"$",
"reportdata",
"->",
"submissiongradeoverby",
")",
";",
"unset",
"(",
"$",
"reportdata",
"->",
"submissionpublished",
")",
";",
"unset",
"(",
"$",
"reportdata",
"->",
"reviewedby",
")",
";",
"unset",
"(",
"$",
"reportdata",
"->",
"reviewerof",
")",
";",
"continue",
";",
"}",
"if",
"(",
"!",
"$",
"options",
"->",
"showsubmissiongrade",
")",
"{",
"unset",
"(",
"$",
"reportdata",
"->",
"submissiongrade",
")",
";",
"unset",
"(",
"$",
"reportdata",
"->",
"submissiongradeover",
")",
";",
"}",
"if",
"(",
"!",
"$",
"options",
"->",
"showgradinggrade",
"and",
"$",
"tr",
"==",
"0",
")",
"{",
"unset",
"(",
"$",
"reportdata",
"->",
"gradinggrade",
")",
";",
"}",
"if",
"(",
"!",
"$",
"options",
"->",
"showreviewernames",
")",
"{",
"foreach",
"(",
"$",
"reportdata",
"->",
"reviewedby",
"as",
"$",
"reviewedby",
")",
"{",
"$",
"reviewedby",
"->",
"userid",
"=",
"0",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"options",
"->",
"showauthornames",
")",
"{",
"foreach",
"(",
"$",
"reportdata",
"->",
"reviewerof",
"as",
"$",
"reviewerof",
")",
"{",
"$",
"reviewerof",
"->",
"userid",
"=",
"0",
";",
"}",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] |
Prepare the data to be exported to a external system via Web Services.
This function applies extra capabilities checks.
@return stdClass the data ready for external systems
|
[
"Prepare",
"the",
"data",
"to",
"be",
"exported",
"to",
"a",
"external",
"system",
"via",
"Web",
"Services",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/locallib.php#L4606-L4646
|
215,214
|
moodle/moodle
|
lib/htmlpurifier/HTMLPurifier/Config.php
|
HTMLPurifier_Config.create
|
public static function create($config, $schema = null)
{
if ($config instanceof HTMLPurifier_Config) {
// pass-through
return $config;
}
if (!$schema) {
$ret = HTMLPurifier_Config::createDefault();
} else {
$ret = new HTMLPurifier_Config($schema);
}
if (is_string($config)) {
$ret->loadIni($config);
} elseif (is_array($config)) $ret->loadArray($config);
return $ret;
}
|
php
|
public static function create($config, $schema = null)
{
if ($config instanceof HTMLPurifier_Config) {
// pass-through
return $config;
}
if (!$schema) {
$ret = HTMLPurifier_Config::createDefault();
} else {
$ret = new HTMLPurifier_Config($schema);
}
if (is_string($config)) {
$ret->loadIni($config);
} elseif (is_array($config)) $ret->loadArray($config);
return $ret;
}
|
[
"public",
"static",
"function",
"create",
"(",
"$",
"config",
",",
"$",
"schema",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"config",
"instanceof",
"HTMLPurifier_Config",
")",
"{",
"// pass-through",
"return",
"$",
"config",
";",
"}",
"if",
"(",
"!",
"$",
"schema",
")",
"{",
"$",
"ret",
"=",
"HTMLPurifier_Config",
"::",
"createDefault",
"(",
")",
";",
"}",
"else",
"{",
"$",
"ret",
"=",
"new",
"HTMLPurifier_Config",
"(",
"$",
"schema",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"config",
")",
")",
"{",
"$",
"ret",
"->",
"loadIni",
"(",
"$",
"config",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"config",
")",
")",
"$",
"ret",
"->",
"loadArray",
"(",
"$",
"config",
")",
";",
"return",
"$",
"ret",
";",
"}"
] |
Convenience constructor that creates a config object based on a mixed var
@param mixed $config Variable that defines the state of the config
object. Can be: a HTMLPurifier_Config() object,
an array of directives based on loadArray(),
or a string filename of an ini file.
@param HTMLPurifier_ConfigSchema $schema Schema object
@return HTMLPurifier_Config Configured object
|
[
"Convenience",
"constructor",
"that",
"creates",
"a",
"config",
"object",
"based",
"on",
"a",
"mixed",
"var"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Config.php#L123-L138
|
215,215
|
moodle/moodle
|
lib/htmlpurifier/HTMLPurifier/Config.php
|
HTMLPurifier_Config.get
|
public function get($key, $a = null)
{
if ($a !== null) {
$this->triggerError(
"Using deprecated API: use \$config->get('$key.$a') instead",
E_USER_WARNING
);
$key = "$key.$a";
}
if (!$this->finalized) {
$this->autoFinalize();
}
if (!isset($this->def->info[$key])) {
// can't add % due to SimpleTest bug
$this->triggerError(
'Cannot retrieve value of undefined directive ' . htmlspecialchars($key),
E_USER_WARNING
);
return;
}
if (isset($this->def->info[$key]->isAlias)) {
$d = $this->def->info[$key];
$this->triggerError(
'Cannot get value from aliased directive, use real name ' . $d->key,
E_USER_ERROR
);
return;
}
if ($this->lock) {
list($ns) = explode('.', $key);
if ($ns !== $this->lock) {
$this->triggerError(
'Cannot get value of namespace ' . $ns . ' when lock for ' .
$this->lock .
' is active, this probably indicates a Definition setup method ' .
'is accessing directives that are not within its namespace',
E_USER_ERROR
);
return;
}
}
return $this->plist->get($key);
}
|
php
|
public function get($key, $a = null)
{
if ($a !== null) {
$this->triggerError(
"Using deprecated API: use \$config->get('$key.$a') instead",
E_USER_WARNING
);
$key = "$key.$a";
}
if (!$this->finalized) {
$this->autoFinalize();
}
if (!isset($this->def->info[$key])) {
// can't add % due to SimpleTest bug
$this->triggerError(
'Cannot retrieve value of undefined directive ' . htmlspecialchars($key),
E_USER_WARNING
);
return;
}
if (isset($this->def->info[$key]->isAlias)) {
$d = $this->def->info[$key];
$this->triggerError(
'Cannot get value from aliased directive, use real name ' . $d->key,
E_USER_ERROR
);
return;
}
if ($this->lock) {
list($ns) = explode('.', $key);
if ($ns !== $this->lock) {
$this->triggerError(
'Cannot get value of namespace ' . $ns . ' when lock for ' .
$this->lock .
' is active, this probably indicates a Definition setup method ' .
'is accessing directives that are not within its namespace',
E_USER_ERROR
);
return;
}
}
return $this->plist->get($key);
}
|
[
"public",
"function",
"get",
"(",
"$",
"key",
",",
"$",
"a",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"a",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"triggerError",
"(",
"\"Using deprecated API: use \\$config->get('$key.$a') instead\"",
",",
"E_USER_WARNING",
")",
";",
"$",
"key",
"=",
"\"$key.$a\"",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"finalized",
")",
"{",
"$",
"this",
"->",
"autoFinalize",
"(",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"def",
"->",
"info",
"[",
"$",
"key",
"]",
")",
")",
"{",
"// can't add % due to SimpleTest bug",
"$",
"this",
"->",
"triggerError",
"(",
"'Cannot retrieve value of undefined directive '",
".",
"htmlspecialchars",
"(",
"$",
"key",
")",
",",
"E_USER_WARNING",
")",
";",
"return",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"def",
"->",
"info",
"[",
"$",
"key",
"]",
"->",
"isAlias",
")",
")",
"{",
"$",
"d",
"=",
"$",
"this",
"->",
"def",
"->",
"info",
"[",
"$",
"key",
"]",
";",
"$",
"this",
"->",
"triggerError",
"(",
"'Cannot get value from aliased directive, use real name '",
".",
"$",
"d",
"->",
"key",
",",
"E_USER_ERROR",
")",
";",
"return",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"lock",
")",
"{",
"list",
"(",
"$",
"ns",
")",
"=",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
";",
"if",
"(",
"$",
"ns",
"!==",
"$",
"this",
"->",
"lock",
")",
"{",
"$",
"this",
"->",
"triggerError",
"(",
"'Cannot get value of namespace '",
".",
"$",
"ns",
".",
"' when lock for '",
".",
"$",
"this",
"->",
"lock",
".",
"' is active, this probably indicates a Definition setup method '",
".",
"'is accessing directives that are not within its namespace'",
",",
"E_USER_ERROR",
")",
";",
"return",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"plist",
"->",
"get",
"(",
"$",
"key",
")",
";",
"}"
] |
Retrieves a value from the configuration.
@param string $key String key
@param mixed $a
@return mixed
|
[
"Retrieves",
"a",
"value",
"from",
"the",
"configuration",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Config.php#L169-L211
|
215,216
|
moodle/moodle
|
lib/htmlpurifier/HTMLPurifier/Config.php
|
HTMLPurifier_Config.getBatch
|
public function getBatch($namespace)
{
if (!$this->finalized) {
$this->autoFinalize();
}
$full = $this->getAll();
if (!isset($full[$namespace])) {
$this->triggerError(
'Cannot retrieve undefined namespace ' .
htmlspecialchars($namespace),
E_USER_WARNING
);
return;
}
return $full[$namespace];
}
|
php
|
public function getBatch($namespace)
{
if (!$this->finalized) {
$this->autoFinalize();
}
$full = $this->getAll();
if (!isset($full[$namespace])) {
$this->triggerError(
'Cannot retrieve undefined namespace ' .
htmlspecialchars($namespace),
E_USER_WARNING
);
return;
}
return $full[$namespace];
}
|
[
"public",
"function",
"getBatch",
"(",
"$",
"namespace",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"finalized",
")",
"{",
"$",
"this",
"->",
"autoFinalize",
"(",
")",
";",
"}",
"$",
"full",
"=",
"$",
"this",
"->",
"getAll",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"full",
"[",
"$",
"namespace",
"]",
")",
")",
"{",
"$",
"this",
"->",
"triggerError",
"(",
"'Cannot retrieve undefined namespace '",
".",
"htmlspecialchars",
"(",
"$",
"namespace",
")",
",",
"E_USER_WARNING",
")",
";",
"return",
";",
"}",
"return",
"$",
"full",
"[",
"$",
"namespace",
"]",
";",
"}"
] |
Retrieves an array of directives to values from a given namespace
@param string $namespace String namespace
@return array
|
[
"Retrieves",
"an",
"array",
"of",
"directives",
"to",
"values",
"from",
"a",
"given",
"namespace"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Config.php#L220-L235
|
215,217
|
moodle/moodle
|
lib/htmlpurifier/HTMLPurifier/Config.php
|
HTMLPurifier_Config.getBatchSerial
|
public function getBatchSerial($namespace)
{
if (empty($this->serials[$namespace])) {
$batch = $this->getBatch($namespace);
unset($batch['DefinitionRev']);
$this->serials[$namespace] = sha1(serialize($batch));
}
return $this->serials[$namespace];
}
|
php
|
public function getBatchSerial($namespace)
{
if (empty($this->serials[$namespace])) {
$batch = $this->getBatch($namespace);
unset($batch['DefinitionRev']);
$this->serials[$namespace] = sha1(serialize($batch));
}
return $this->serials[$namespace];
}
|
[
"public",
"function",
"getBatchSerial",
"(",
"$",
"namespace",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"serials",
"[",
"$",
"namespace",
"]",
")",
")",
"{",
"$",
"batch",
"=",
"$",
"this",
"->",
"getBatch",
"(",
"$",
"namespace",
")",
";",
"unset",
"(",
"$",
"batch",
"[",
"'DefinitionRev'",
"]",
")",
";",
"$",
"this",
"->",
"serials",
"[",
"$",
"namespace",
"]",
"=",
"sha1",
"(",
"serialize",
"(",
"$",
"batch",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"serials",
"[",
"$",
"namespace",
"]",
";",
"}"
] |
Returns a SHA-1 signature of a segment of the configuration object
that uniquely identifies that particular configuration
@param string $namespace Namespace to get serial for
@return string
@note Revision is handled specially and is removed from the batch
before processing!
|
[
"Returns",
"a",
"SHA",
"-",
"1",
"signature",
"of",
"a",
"segment",
"of",
"the",
"configuration",
"object",
"that",
"uniquely",
"identifies",
"that",
"particular",
"configuration"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Config.php#L247-L255
|
215,218
|
moodle/moodle
|
lib/htmlpurifier/HTMLPurifier/Config.php
|
HTMLPurifier_Config.getSerial
|
public function getSerial()
{
if (empty($this->serial)) {
$this->serial = sha1(serialize($this->getAll()));
}
return $this->serial;
}
|
php
|
public function getSerial()
{
if (empty($this->serial)) {
$this->serial = sha1(serialize($this->getAll()));
}
return $this->serial;
}
|
[
"public",
"function",
"getSerial",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"serial",
")",
")",
"{",
"$",
"this",
"->",
"serial",
"=",
"sha1",
"(",
"serialize",
"(",
"$",
"this",
"->",
"getAll",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"serial",
";",
"}"
] |
Returns a SHA-1 signature for the entire configuration object
that uniquely identifies that particular configuration
@return string
|
[
"Returns",
"a",
"SHA",
"-",
"1",
"signature",
"for",
"the",
"entire",
"configuration",
"object",
"that",
"uniquely",
"identifies",
"that",
"particular",
"configuration"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Config.php#L263-L269
|
215,219
|
moodle/moodle
|
lib/htmlpurifier/HTMLPurifier/Config.php
|
HTMLPurifier_Config._listify
|
private function _listify($lookup)
{
$list = array();
foreach ($lookup as $name => $b) {
$list[] = $name;
}
return implode(', ', $list);
}
|
php
|
private function _listify($lookup)
{
$list = array();
foreach ($lookup as $name => $b) {
$list[] = $name;
}
return implode(', ', $list);
}
|
[
"private",
"function",
"_listify",
"(",
"$",
"lookup",
")",
"{",
"$",
"list",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"lookup",
"as",
"$",
"name",
"=>",
"$",
"b",
")",
"{",
"$",
"list",
"[",
"]",
"=",
"$",
"name",
";",
"}",
"return",
"implode",
"(",
"', '",
",",
"$",
"list",
")",
";",
"}"
] |
Convenience function for error reporting
@param array $lookup
@return string
|
[
"Convenience",
"function",
"for",
"error",
"reporting"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Config.php#L390-L397
|
215,220
|
moodle/moodle
|
lib/htmlpurifier/HTMLPurifier/Config.php
|
HTMLPurifier_Config.isFinalized
|
public function isFinalized($error = false)
{
if ($this->finalized && $error) {
$this->triggerError($error, E_USER_ERROR);
}
return $this->finalized;
}
|
php
|
public function isFinalized($error = false)
{
if ($this->finalized && $error) {
$this->triggerError($error, E_USER_ERROR);
}
return $this->finalized;
}
|
[
"public",
"function",
"isFinalized",
"(",
"$",
"error",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"finalized",
"&&",
"$",
"error",
")",
"{",
"$",
"this",
"->",
"triggerError",
"(",
"$",
"error",
",",
"E_USER_ERROR",
")",
";",
"}",
"return",
"$",
"this",
"->",
"finalized",
";",
"}"
] |
Checks whether or not the configuration object is finalized.
@param string|bool $error String error message, or false for no error
@return bool
|
[
"Checks",
"whether",
"or",
"not",
"the",
"configuration",
"object",
"is",
"finalized",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Config.php#L847-L853
|
215,221
|
moodle/moodle
|
enrol/lti/classes/helper.php
|
helper.create_username
|
public static function create_username($consumerkey, $ltiuserid) {
if (!empty($ltiuserid) && !empty($consumerkey)) {
$userkey = $consumerkey . ':' . $ltiuserid;
} else {
$userkey = false;
}
return 'enrol_lti' . sha1($consumerkey . '::' . $userkey);
}
|
php
|
public static function create_username($consumerkey, $ltiuserid) {
if (!empty($ltiuserid) && !empty($consumerkey)) {
$userkey = $consumerkey . ':' . $ltiuserid;
} else {
$userkey = false;
}
return 'enrol_lti' . sha1($consumerkey . '::' . $userkey);
}
|
[
"public",
"static",
"function",
"create_username",
"(",
"$",
"consumerkey",
",",
"$",
"ltiuserid",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"ltiuserid",
")",
"&&",
"!",
"empty",
"(",
"$",
"consumerkey",
")",
")",
"{",
"$",
"userkey",
"=",
"$",
"consumerkey",
".",
"':'",
".",
"$",
"ltiuserid",
";",
"}",
"else",
"{",
"$",
"userkey",
"=",
"false",
";",
"}",
"return",
"'enrol_lti'",
".",
"sha1",
"(",
"$",
"consumerkey",
".",
"'::'",
".",
"$",
"userkey",
")",
";",
"}"
] |
Creates a unique username.
@param string $consumerkey Consumer key
@param string $ltiuserid External tool user id
@return string The new username
|
[
"Creates",
"a",
"unique",
"username",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/helper.php#L89-L97
|
215,222
|
moodle/moodle
|
enrol/lti/classes/helper.php
|
helper.assign_user_tool_data
|
public static function assign_user_tool_data($tool, $user) {
global $CFG;
$user->city = (!empty($tool->city)) ? $tool->city : "";
$user->country = (!empty($tool->country)) ? $tool->country : "";
$user->institution = (!empty($tool->institution)) ? $tool->institution : "";
$user->timezone = (!empty($tool->timezone)) ? $tool->timezone : "";
if (isset($tool->maildisplay)) {
$user->maildisplay = $tool->maildisplay;
} else if (isset($CFG->defaultpreference_maildisplay)) {
$user->maildisplay = $CFG->defaultpreference_maildisplay;
} else {
$user->maildisplay = 2;
}
$user->mnethostid = $CFG->mnet_localhost_id;
$user->confirmed = 1;
$user->lang = $tool->lang;
return $user;
}
|
php
|
public static function assign_user_tool_data($tool, $user) {
global $CFG;
$user->city = (!empty($tool->city)) ? $tool->city : "";
$user->country = (!empty($tool->country)) ? $tool->country : "";
$user->institution = (!empty($tool->institution)) ? $tool->institution : "";
$user->timezone = (!empty($tool->timezone)) ? $tool->timezone : "";
if (isset($tool->maildisplay)) {
$user->maildisplay = $tool->maildisplay;
} else if (isset($CFG->defaultpreference_maildisplay)) {
$user->maildisplay = $CFG->defaultpreference_maildisplay;
} else {
$user->maildisplay = 2;
}
$user->mnethostid = $CFG->mnet_localhost_id;
$user->confirmed = 1;
$user->lang = $tool->lang;
return $user;
}
|
[
"public",
"static",
"function",
"assign_user_tool_data",
"(",
"$",
"tool",
",",
"$",
"user",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"user",
"->",
"city",
"=",
"(",
"!",
"empty",
"(",
"$",
"tool",
"->",
"city",
")",
")",
"?",
"$",
"tool",
"->",
"city",
":",
"\"\"",
";",
"$",
"user",
"->",
"country",
"=",
"(",
"!",
"empty",
"(",
"$",
"tool",
"->",
"country",
")",
")",
"?",
"$",
"tool",
"->",
"country",
":",
"\"\"",
";",
"$",
"user",
"->",
"institution",
"=",
"(",
"!",
"empty",
"(",
"$",
"tool",
"->",
"institution",
")",
")",
"?",
"$",
"tool",
"->",
"institution",
":",
"\"\"",
";",
"$",
"user",
"->",
"timezone",
"=",
"(",
"!",
"empty",
"(",
"$",
"tool",
"->",
"timezone",
")",
")",
"?",
"$",
"tool",
"->",
"timezone",
":",
"\"\"",
";",
"if",
"(",
"isset",
"(",
"$",
"tool",
"->",
"maildisplay",
")",
")",
"{",
"$",
"user",
"->",
"maildisplay",
"=",
"$",
"tool",
"->",
"maildisplay",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"CFG",
"->",
"defaultpreference_maildisplay",
")",
")",
"{",
"$",
"user",
"->",
"maildisplay",
"=",
"$",
"CFG",
"->",
"defaultpreference_maildisplay",
";",
"}",
"else",
"{",
"$",
"user",
"->",
"maildisplay",
"=",
"2",
";",
"}",
"$",
"user",
"->",
"mnethostid",
"=",
"$",
"CFG",
"->",
"mnet_localhost_id",
";",
"$",
"user",
"->",
"confirmed",
"=",
"1",
";",
"$",
"user",
"->",
"lang",
"=",
"$",
"tool",
"->",
"lang",
";",
"return",
"$",
"user",
";",
"}"
] |
Adds default values for the user object based on the tool provided.
@param \stdClass $tool
@param \stdClass $user
@return \stdClass The $user class with added default values
|
[
"Adds",
"default",
"values",
"for",
"the",
"user",
"object",
"based",
"on",
"the",
"tool",
"provided",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/helper.php#L106-L125
|
215,223
|
moodle/moodle
|
enrol/lti/classes/helper.php
|
helper.user_match
|
public static function user_match($newuser, $olduser) {
if ($newuser->firstname != $olduser->firstname) {
return false;
}
if ($newuser->lastname != $olduser->lastname) {
return false;
}
if ($newuser->email != $olduser->email) {
return false;
}
if ($newuser->city != $olduser->city) {
return false;
}
if ($newuser->country != $olduser->country) {
return false;
}
if ($newuser->institution != $olduser->institution) {
return false;
}
if ($newuser->timezone != $olduser->timezone) {
return false;
}
if ($newuser->maildisplay != $olduser->maildisplay) {
return false;
}
if ($newuser->mnethostid != $olduser->mnethostid) {
return false;
}
if ($newuser->confirmed != $olduser->confirmed) {
return false;
}
if ($newuser->lang != $olduser->lang) {
return false;
}
return true;
}
|
php
|
public static function user_match($newuser, $olduser) {
if ($newuser->firstname != $olduser->firstname) {
return false;
}
if ($newuser->lastname != $olduser->lastname) {
return false;
}
if ($newuser->email != $olduser->email) {
return false;
}
if ($newuser->city != $olduser->city) {
return false;
}
if ($newuser->country != $olduser->country) {
return false;
}
if ($newuser->institution != $olduser->institution) {
return false;
}
if ($newuser->timezone != $olduser->timezone) {
return false;
}
if ($newuser->maildisplay != $olduser->maildisplay) {
return false;
}
if ($newuser->mnethostid != $olduser->mnethostid) {
return false;
}
if ($newuser->confirmed != $olduser->confirmed) {
return false;
}
if ($newuser->lang != $olduser->lang) {
return false;
}
return true;
}
|
[
"public",
"static",
"function",
"user_match",
"(",
"$",
"newuser",
",",
"$",
"olduser",
")",
"{",
"if",
"(",
"$",
"newuser",
"->",
"firstname",
"!=",
"$",
"olduser",
"->",
"firstname",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"newuser",
"->",
"lastname",
"!=",
"$",
"olduser",
"->",
"lastname",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"newuser",
"->",
"email",
"!=",
"$",
"olduser",
"->",
"email",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"newuser",
"->",
"city",
"!=",
"$",
"olduser",
"->",
"city",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"newuser",
"->",
"country",
"!=",
"$",
"olduser",
"->",
"country",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"newuser",
"->",
"institution",
"!=",
"$",
"olduser",
"->",
"institution",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"newuser",
"->",
"timezone",
"!=",
"$",
"olduser",
"->",
"timezone",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"newuser",
"->",
"maildisplay",
"!=",
"$",
"olduser",
"->",
"maildisplay",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"newuser",
"->",
"mnethostid",
"!=",
"$",
"olduser",
"->",
"mnethostid",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"newuser",
"->",
"confirmed",
"!=",
"$",
"olduser",
"->",
"confirmed",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"newuser",
"->",
"lang",
"!=",
"$",
"olduser",
"->",
"lang",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Compares two users.
@param \stdClass $newuser The new user
@param \stdClass $olduser The old user
@return bool True if both users are the same
|
[
"Compares",
"two",
"users",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/helper.php#L134-L170
|
215,224
|
moodle/moodle
|
enrol/lti/classes/helper.php
|
helper.update_user_profile_image
|
public static function update_user_profile_image($userid, $url) {
global $CFG, $DB;
require_once($CFG->libdir . '/filelib.php');
require_once($CFG->libdir . '/gdlib.php');
$fs = get_file_storage();
$context = \context_user::instance($userid, MUST_EXIST);
$fs->delete_area_files($context->id, 'user', 'newicon');
$filerecord = array(
'contextid' => $context->id,
'component' => 'user',
'filearea' => 'newicon',
'itemid' => 0,
'filepath' => '/'
);
$urlparams = array(
'calctimeout' => false,
'timeout' => 5,
'skipcertverify' => true,
'connecttimeout' => 5
);
try {
$fs->create_file_from_url($filerecord, $url, $urlparams);
} catch (\file_exception $e) {
return get_string($e->errorcode, $e->module, $e->a);
}
$iconfile = $fs->get_area_files($context->id, 'user', 'newicon', false, 'itemid', false);
// There should only be one.
$iconfile = reset($iconfile);
// Something went wrong while creating temp file - remove the uploaded file.
if (!$iconfile = $iconfile->copy_content_to_temp()) {
$fs->delete_area_files($context->id, 'user', 'newicon');
return self::PROFILE_IMAGE_UPDATE_FAILED;
}
// Copy file to temporary location and the send it for processing icon.
$newpicture = (int) process_new_icon($context, 'user', 'icon', 0, $iconfile);
// Delete temporary file.
@unlink($iconfile);
// Remove uploaded file.
$fs->delete_area_files($context->id, 'user', 'newicon');
// Set the user's picture.
$DB->set_field('user', 'picture', $newpicture, array('id' => $userid));
return self::PROFILE_IMAGE_UPDATE_SUCCESSFUL;
}
|
php
|
public static function update_user_profile_image($userid, $url) {
global $CFG, $DB;
require_once($CFG->libdir . '/filelib.php');
require_once($CFG->libdir . '/gdlib.php');
$fs = get_file_storage();
$context = \context_user::instance($userid, MUST_EXIST);
$fs->delete_area_files($context->id, 'user', 'newicon');
$filerecord = array(
'contextid' => $context->id,
'component' => 'user',
'filearea' => 'newicon',
'itemid' => 0,
'filepath' => '/'
);
$urlparams = array(
'calctimeout' => false,
'timeout' => 5,
'skipcertverify' => true,
'connecttimeout' => 5
);
try {
$fs->create_file_from_url($filerecord, $url, $urlparams);
} catch (\file_exception $e) {
return get_string($e->errorcode, $e->module, $e->a);
}
$iconfile = $fs->get_area_files($context->id, 'user', 'newicon', false, 'itemid', false);
// There should only be one.
$iconfile = reset($iconfile);
// Something went wrong while creating temp file - remove the uploaded file.
if (!$iconfile = $iconfile->copy_content_to_temp()) {
$fs->delete_area_files($context->id, 'user', 'newicon');
return self::PROFILE_IMAGE_UPDATE_FAILED;
}
// Copy file to temporary location and the send it for processing icon.
$newpicture = (int) process_new_icon($context, 'user', 'icon', 0, $iconfile);
// Delete temporary file.
@unlink($iconfile);
// Remove uploaded file.
$fs->delete_area_files($context->id, 'user', 'newicon');
// Set the user's picture.
$DB->set_field('user', 'picture', $newpicture, array('id' => $userid));
return self::PROFILE_IMAGE_UPDATE_SUCCESSFUL;
}
|
[
"public",
"static",
"function",
"update_user_profile_image",
"(",
"$",
"userid",
",",
"$",
"url",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"libdir",
".",
"'/filelib.php'",
")",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"libdir",
".",
"'/gdlib.php'",
")",
";",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"$",
"context",
"=",
"\\",
"context_user",
"::",
"instance",
"(",
"$",
"userid",
",",
"MUST_EXIST",
")",
";",
"$",
"fs",
"->",
"delete_area_files",
"(",
"$",
"context",
"->",
"id",
",",
"'user'",
",",
"'newicon'",
")",
";",
"$",
"filerecord",
"=",
"array",
"(",
"'contextid'",
"=>",
"$",
"context",
"->",
"id",
",",
"'component'",
"=>",
"'user'",
",",
"'filearea'",
"=>",
"'newicon'",
",",
"'itemid'",
"=>",
"0",
",",
"'filepath'",
"=>",
"'/'",
")",
";",
"$",
"urlparams",
"=",
"array",
"(",
"'calctimeout'",
"=>",
"false",
",",
"'timeout'",
"=>",
"5",
",",
"'skipcertverify'",
"=>",
"true",
",",
"'connecttimeout'",
"=>",
"5",
")",
";",
"try",
"{",
"$",
"fs",
"->",
"create_file_from_url",
"(",
"$",
"filerecord",
",",
"$",
"url",
",",
"$",
"urlparams",
")",
";",
"}",
"catch",
"(",
"\\",
"file_exception",
"$",
"e",
")",
"{",
"return",
"get_string",
"(",
"$",
"e",
"->",
"errorcode",
",",
"$",
"e",
"->",
"module",
",",
"$",
"e",
"->",
"a",
")",
";",
"}",
"$",
"iconfile",
"=",
"$",
"fs",
"->",
"get_area_files",
"(",
"$",
"context",
"->",
"id",
",",
"'user'",
",",
"'newicon'",
",",
"false",
",",
"'itemid'",
",",
"false",
")",
";",
"// There should only be one.",
"$",
"iconfile",
"=",
"reset",
"(",
"$",
"iconfile",
")",
";",
"// Something went wrong while creating temp file - remove the uploaded file.",
"if",
"(",
"!",
"$",
"iconfile",
"=",
"$",
"iconfile",
"->",
"copy_content_to_temp",
"(",
")",
")",
"{",
"$",
"fs",
"->",
"delete_area_files",
"(",
"$",
"context",
"->",
"id",
",",
"'user'",
",",
"'newicon'",
")",
";",
"return",
"self",
"::",
"PROFILE_IMAGE_UPDATE_FAILED",
";",
"}",
"// Copy file to temporary location and the send it for processing icon.",
"$",
"newpicture",
"=",
"(",
"int",
")",
"process_new_icon",
"(",
"$",
"context",
",",
"'user'",
",",
"'icon'",
",",
"0",
",",
"$",
"iconfile",
")",
";",
"// Delete temporary file.",
"@",
"unlink",
"(",
"$",
"iconfile",
")",
";",
"// Remove uploaded file.",
"$",
"fs",
"->",
"delete_area_files",
"(",
"$",
"context",
"->",
"id",
",",
"'user'",
",",
"'newicon'",
")",
";",
"// Set the user's picture.",
"$",
"DB",
"->",
"set_field",
"(",
"'user'",
",",
"'picture'",
",",
"$",
"newpicture",
",",
"array",
"(",
"'id'",
"=>",
"$",
"userid",
")",
")",
";",
"return",
"self",
"::",
"PROFILE_IMAGE_UPDATE_SUCCESSFUL",
";",
"}"
] |
Updates the users profile image.
@param int $userid the id of the user
@param string $url the url of the image
@return bool|string true if successful, else a string explaining why it failed
|
[
"Updates",
"the",
"users",
"profile",
"image",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/helper.php#L179-L231
|
215,225
|
moodle/moodle
|
enrol/lti/classes/helper.php
|
helper.enrol_user
|
public static function enrol_user($tool, $userid) {
global $DB;
// Check if the user enrolment exists.
if (!$DB->record_exists('user_enrolments', array('enrolid' => $tool->enrolid, 'userid' => $userid))) {
// Check if the maximum enrolled limit has been met.
if ($tool->maxenrolled) {
if ($DB->count_records('user_enrolments', array('enrolid' => $tool->enrolid)) >= $tool->maxenrolled) {
return self::ENROLMENT_MAX_ENROLLED;
}
}
// Check if the enrolment has not started.
if ($tool->enrolstartdate && time() < $tool->enrolstartdate) {
return self::ENROLMENT_NOT_STARTED;
}
// Check if the enrolment has finished.
if ($tool->enrolenddate && time() > $tool->enrolenddate) {
return self::ENROLMENT_FINISHED;
}
$timeend = 0;
if ($tool->enrolperiod) {
$timeend = time() + $tool->enrolperiod;
}
// Finally, enrol the user.
$instance = new \stdClass();
$instance->id = $tool->enrolid;
$instance->courseid = $tool->courseid;
$instance->enrol = 'lti';
$instance->status = $tool->status;
$ltienrol = enrol_get_plugin('lti');
// Hack - need to do this to workaround DB caching hack. See MDL-53977.
$timestart = intval(substr(time(), 0, 8) . '00') - 1;
$ltienrol->enrol_user($instance, $userid, null, $timestart, $timeend);
}
return self::ENROLMENT_SUCCESSFUL;
}
|
php
|
public static function enrol_user($tool, $userid) {
global $DB;
// Check if the user enrolment exists.
if (!$DB->record_exists('user_enrolments', array('enrolid' => $tool->enrolid, 'userid' => $userid))) {
// Check if the maximum enrolled limit has been met.
if ($tool->maxenrolled) {
if ($DB->count_records('user_enrolments', array('enrolid' => $tool->enrolid)) >= $tool->maxenrolled) {
return self::ENROLMENT_MAX_ENROLLED;
}
}
// Check if the enrolment has not started.
if ($tool->enrolstartdate && time() < $tool->enrolstartdate) {
return self::ENROLMENT_NOT_STARTED;
}
// Check if the enrolment has finished.
if ($tool->enrolenddate && time() > $tool->enrolenddate) {
return self::ENROLMENT_FINISHED;
}
$timeend = 0;
if ($tool->enrolperiod) {
$timeend = time() + $tool->enrolperiod;
}
// Finally, enrol the user.
$instance = new \stdClass();
$instance->id = $tool->enrolid;
$instance->courseid = $tool->courseid;
$instance->enrol = 'lti';
$instance->status = $tool->status;
$ltienrol = enrol_get_plugin('lti');
// Hack - need to do this to workaround DB caching hack. See MDL-53977.
$timestart = intval(substr(time(), 0, 8) . '00') - 1;
$ltienrol->enrol_user($instance, $userid, null, $timestart, $timeend);
}
return self::ENROLMENT_SUCCESSFUL;
}
|
[
"public",
"static",
"function",
"enrol_user",
"(",
"$",
"tool",
",",
"$",
"userid",
")",
"{",
"global",
"$",
"DB",
";",
"// Check if the user enrolment exists.",
"if",
"(",
"!",
"$",
"DB",
"->",
"record_exists",
"(",
"'user_enrolments'",
",",
"array",
"(",
"'enrolid'",
"=>",
"$",
"tool",
"->",
"enrolid",
",",
"'userid'",
"=>",
"$",
"userid",
")",
")",
")",
"{",
"// Check if the maximum enrolled limit has been met.",
"if",
"(",
"$",
"tool",
"->",
"maxenrolled",
")",
"{",
"if",
"(",
"$",
"DB",
"->",
"count_records",
"(",
"'user_enrolments'",
",",
"array",
"(",
"'enrolid'",
"=>",
"$",
"tool",
"->",
"enrolid",
")",
")",
">=",
"$",
"tool",
"->",
"maxenrolled",
")",
"{",
"return",
"self",
"::",
"ENROLMENT_MAX_ENROLLED",
";",
"}",
"}",
"// Check if the enrolment has not started.",
"if",
"(",
"$",
"tool",
"->",
"enrolstartdate",
"&&",
"time",
"(",
")",
"<",
"$",
"tool",
"->",
"enrolstartdate",
")",
"{",
"return",
"self",
"::",
"ENROLMENT_NOT_STARTED",
";",
"}",
"// Check if the enrolment has finished.",
"if",
"(",
"$",
"tool",
"->",
"enrolenddate",
"&&",
"time",
"(",
")",
">",
"$",
"tool",
"->",
"enrolenddate",
")",
"{",
"return",
"self",
"::",
"ENROLMENT_FINISHED",
";",
"}",
"$",
"timeend",
"=",
"0",
";",
"if",
"(",
"$",
"tool",
"->",
"enrolperiod",
")",
"{",
"$",
"timeend",
"=",
"time",
"(",
")",
"+",
"$",
"tool",
"->",
"enrolperiod",
";",
"}",
"// Finally, enrol the user.",
"$",
"instance",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"instance",
"->",
"id",
"=",
"$",
"tool",
"->",
"enrolid",
";",
"$",
"instance",
"->",
"courseid",
"=",
"$",
"tool",
"->",
"courseid",
";",
"$",
"instance",
"->",
"enrol",
"=",
"'lti'",
";",
"$",
"instance",
"->",
"status",
"=",
"$",
"tool",
"->",
"status",
";",
"$",
"ltienrol",
"=",
"enrol_get_plugin",
"(",
"'lti'",
")",
";",
"// Hack - need to do this to workaround DB caching hack. See MDL-53977.",
"$",
"timestart",
"=",
"intval",
"(",
"substr",
"(",
"time",
"(",
")",
",",
"0",
",",
"8",
")",
".",
"'00'",
")",
"-",
"1",
";",
"$",
"ltienrol",
"->",
"enrol_user",
"(",
"$",
"instance",
",",
"$",
"userid",
",",
"null",
",",
"$",
"timestart",
",",
"$",
"timeend",
")",
";",
"}",
"return",
"self",
"::",
"ENROLMENT_SUCCESSFUL",
";",
"}"
] |
Enrol a user in a course.
@param \stdclass $tool The tool object (retrieved using self::get_lti_tool() or self::get_lti_tools())
@param int $userid The user id
@return bool|string returns true if successful, else an error code
|
[
"Enrol",
"a",
"user",
"in",
"a",
"course",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/helper.php#L240-L279
|
215,226
|
moodle/moodle
|
enrol/lti/classes/helper.php
|
helper.get_lti_tools
|
public static function get_lti_tools($params = array(), $limitfrom = 0, $limitnum = 0) {
global $DB;
$sql = "SELECT elt.*, e.name, e.courseid, e.status, e.enrolstartdate, e.enrolenddate, e.enrolperiod
FROM {enrol_lti_tools} elt
JOIN {enrol} e
ON elt.enrolid = e.id";
if ($params) {
$where = "WHERE";
foreach ($params as $colname => $value) {
$sql .= " $where $colname = :$colname";
$where = "AND";
}
}
$sql .= " ORDER BY elt.timecreated";
return $DB->get_records_sql($sql, $params, $limitfrom, $limitnum);
}
|
php
|
public static function get_lti_tools($params = array(), $limitfrom = 0, $limitnum = 0) {
global $DB;
$sql = "SELECT elt.*, e.name, e.courseid, e.status, e.enrolstartdate, e.enrolenddate, e.enrolperiod
FROM {enrol_lti_tools} elt
JOIN {enrol} e
ON elt.enrolid = e.id";
if ($params) {
$where = "WHERE";
foreach ($params as $colname => $value) {
$sql .= " $where $colname = :$colname";
$where = "AND";
}
}
$sql .= " ORDER BY elt.timecreated";
return $DB->get_records_sql($sql, $params, $limitfrom, $limitnum);
}
|
[
"public",
"static",
"function",
"get_lti_tools",
"(",
"$",
"params",
"=",
"array",
"(",
")",
",",
"$",
"limitfrom",
"=",
"0",
",",
"$",
"limitnum",
"=",
"0",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"sql",
"=",
"\"SELECT elt.*, e.name, e.courseid, e.status, e.enrolstartdate, e.enrolenddate, e.enrolperiod\n FROM {enrol_lti_tools} elt\n JOIN {enrol} e\n ON elt.enrolid = e.id\"",
";",
"if",
"(",
"$",
"params",
")",
"{",
"$",
"where",
"=",
"\"WHERE\"",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"colname",
"=>",
"$",
"value",
")",
"{",
"$",
"sql",
".=",
"\" $where $colname = :$colname\"",
";",
"$",
"where",
"=",
"\"AND\"",
";",
"}",
"}",
"$",
"sql",
".=",
"\" ORDER BY elt.timecreated\"",
";",
"return",
"$",
"DB",
"->",
"get_records_sql",
"(",
"$",
"sql",
",",
"$",
"params",
",",
"$",
"limitfrom",
",",
"$",
"limitnum",
")",
";",
"}"
] |
Returns the LTI tools requested.
@param array $params The list of SQL params (eg. array('columnname' => value, 'columnname2' => value)).
@param int $limitfrom return a subset of records, starting at this point (optional).
@param int $limitnum return a subset comprising this many records in total
@return array of tools
|
[
"Returns",
"the",
"LTI",
"tools",
"requested",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/helper.php#L307-L324
|
215,227
|
moodle/moodle
|
enrol/lti/classes/helper.php
|
helper.count_lti_tools
|
public static function count_lti_tools($params = array()) {
global $DB;
$sql = "SELECT COUNT(*)
FROM {enrol_lti_tools} elt
JOIN {enrol} e
ON elt.enrolid = e.id";
if ($params) {
$where = "WHERE";
foreach ($params as $colname => $value) {
$sql .= " $where $colname = :$colname";
$where = "AND";
}
}
return $DB->count_records_sql($sql, $params);
}
|
php
|
public static function count_lti_tools($params = array()) {
global $DB;
$sql = "SELECT COUNT(*)
FROM {enrol_lti_tools} elt
JOIN {enrol} e
ON elt.enrolid = e.id";
if ($params) {
$where = "WHERE";
foreach ($params as $colname => $value) {
$sql .= " $where $colname = :$colname";
$where = "AND";
}
}
return $DB->count_records_sql($sql, $params);
}
|
[
"public",
"static",
"function",
"count_lti_tools",
"(",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"sql",
"=",
"\"SELECT COUNT(*)\n FROM {enrol_lti_tools} elt\n JOIN {enrol} e\n ON elt.enrolid = e.id\"",
";",
"if",
"(",
"$",
"params",
")",
"{",
"$",
"where",
"=",
"\"WHERE\"",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"colname",
"=>",
"$",
"value",
")",
"{",
"$",
"sql",
".=",
"\" $where $colname = :$colname\"",
";",
"$",
"where",
"=",
"\"AND\"",
";",
"}",
"}",
"return",
"$",
"DB",
"->",
"count_records_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"}"
] |
Returns the number of LTI tools.
@param array $params The list of SQL params (eg. array('columnname' => value, 'columnname2' => value)).
@return int The number of tools
|
[
"Returns",
"the",
"number",
"of",
"LTI",
"tools",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/helper.php#L332-L348
|
215,228
|
moodle/moodle
|
enrol/lti/classes/helper.php
|
helper.get_description
|
public static function get_description($tool) {
global $DB;
$description = '';
$context = \context::instance_by_id($tool->contextid);
if ($context->contextlevel == CONTEXT_COURSE) {
$course = $DB->get_record('course', array('id' => $context->instanceid));
$description = $course->summary;
} else if ($context->contextlevel == CONTEXT_MODULE) {
$cmid = $context->instanceid;
$cm = get_coursemodule_from_id(false, $context->instanceid, 0, false, MUST_EXIST);
$module = $DB->get_record($cm->modname, array('id' => $cm->instance));
$description = $module->intro;
}
return trim(html_to_text($description));
}
|
php
|
public static function get_description($tool) {
global $DB;
$description = '';
$context = \context::instance_by_id($tool->contextid);
if ($context->contextlevel == CONTEXT_COURSE) {
$course = $DB->get_record('course', array('id' => $context->instanceid));
$description = $course->summary;
} else if ($context->contextlevel == CONTEXT_MODULE) {
$cmid = $context->instanceid;
$cm = get_coursemodule_from_id(false, $context->instanceid, 0, false, MUST_EXIST);
$module = $DB->get_record($cm->modname, array('id' => $cm->instance));
$description = $module->intro;
}
return trim(html_to_text($description));
}
|
[
"public",
"static",
"function",
"get_description",
"(",
"$",
"tool",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"description",
"=",
"''",
";",
"$",
"context",
"=",
"\\",
"context",
"::",
"instance_by_id",
"(",
"$",
"tool",
"->",
"contextid",
")",
";",
"if",
"(",
"$",
"context",
"->",
"contextlevel",
"==",
"CONTEXT_COURSE",
")",
"{",
"$",
"course",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'course'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"context",
"->",
"instanceid",
")",
")",
";",
"$",
"description",
"=",
"$",
"course",
"->",
"summary",
";",
"}",
"else",
"if",
"(",
"$",
"context",
"->",
"contextlevel",
"==",
"CONTEXT_MODULE",
")",
"{",
"$",
"cmid",
"=",
"$",
"context",
"->",
"instanceid",
";",
"$",
"cm",
"=",
"get_coursemodule_from_id",
"(",
"false",
",",
"$",
"context",
"->",
"instanceid",
",",
"0",
",",
"false",
",",
"MUST_EXIST",
")",
";",
"$",
"module",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"$",
"cm",
"->",
"modname",
",",
"array",
"(",
"'id'",
"=>",
"$",
"cm",
"->",
"instance",
")",
")",
";",
"$",
"description",
"=",
"$",
"module",
"->",
"intro",
";",
"}",
"return",
"trim",
"(",
"html_to_text",
"(",
"$",
"description",
")",
")",
";",
"}"
] |
Returns a description of the course or module that this lti instance points to.
@param \stdClass $tool The lti tool
@return string A description of the tool
@since Moodle 3.2
|
[
"Returns",
"a",
"description",
"of",
"the",
"course",
"or",
"module",
"that",
"this",
"lti",
"instance",
"points",
"to",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/helper.php#L422-L436
|
215,229
|
moodle/moodle
|
enrol/lti/classes/helper.php
|
helper.get_cartridge_url
|
public static function get_cartridge_url($tool) {
global $CFG;
$url = null;
$id = $tool->id;
$token = self::generate_cartridge_token($tool->id);
if ($CFG->slasharguments) {
$url = new \moodle_url('/enrol/lti/cartridge.php/' . $id . '/' . $token . '/cartridge.xml');
} else {
$url = new \moodle_url('/enrol/lti/cartridge.php',
array(
'id' => $id,
'token' => $token
)
);
}
return $url;
}
|
php
|
public static function get_cartridge_url($tool) {
global $CFG;
$url = null;
$id = $tool->id;
$token = self::generate_cartridge_token($tool->id);
if ($CFG->slasharguments) {
$url = new \moodle_url('/enrol/lti/cartridge.php/' . $id . '/' . $token . '/cartridge.xml');
} else {
$url = new \moodle_url('/enrol/lti/cartridge.php',
array(
'id' => $id,
'token' => $token
)
);
}
return $url;
}
|
[
"public",
"static",
"function",
"get_cartridge_url",
"(",
"$",
"tool",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"url",
"=",
"null",
";",
"$",
"id",
"=",
"$",
"tool",
"->",
"id",
";",
"$",
"token",
"=",
"self",
"::",
"generate_cartridge_token",
"(",
"$",
"tool",
"->",
"id",
")",
";",
"if",
"(",
"$",
"CFG",
"->",
"slasharguments",
")",
"{",
"$",
"url",
"=",
"new",
"\\",
"moodle_url",
"(",
"'/enrol/lti/cartridge.php/'",
".",
"$",
"id",
".",
"'/'",
".",
"$",
"token",
".",
"'/cartridge.xml'",
")",
";",
"}",
"else",
"{",
"$",
"url",
"=",
"new",
"\\",
"moodle_url",
"(",
"'/enrol/lti/cartridge.php'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"id",
",",
"'token'",
"=>",
"$",
"token",
")",
")",
";",
"}",
"return",
"$",
"url",
";",
"}"
] |
Returns the url to the cartridge representing the tool.
If you have slash arguments enabled, this will be a nice url ending in cartridge.xml.
If not it will be a php page with some parameters passed.
@param \stdClass $tool The lti tool
@return string The url to the cartridge representing the tool
@since Moodle 3.2
|
[
"Returns",
"the",
"url",
"to",
"the",
"cartridge",
"representing",
"the",
"tool",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/helper.php#L460-L477
|
215,230
|
moodle/moodle
|
enrol/lti/classes/helper.php
|
helper.get_proxy_url
|
public static function get_proxy_url($tool) {
global $CFG;
$url = null;
$id = $tool->id;
$token = self::generate_proxy_token($tool->id);
if ($CFG->slasharguments) {
$url = new \moodle_url('/enrol/lti/proxy.php/' . $id . '/' . $token . '/');
} else {
$url = new \moodle_url('/enrol/lti/proxy.php',
array(
'id' => $id,
'token' => $token
)
);
}
return $url;
}
|
php
|
public static function get_proxy_url($tool) {
global $CFG;
$url = null;
$id = $tool->id;
$token = self::generate_proxy_token($tool->id);
if ($CFG->slasharguments) {
$url = new \moodle_url('/enrol/lti/proxy.php/' . $id . '/' . $token . '/');
} else {
$url = new \moodle_url('/enrol/lti/proxy.php',
array(
'id' => $id,
'token' => $token
)
);
}
return $url;
}
|
[
"public",
"static",
"function",
"get_proxy_url",
"(",
"$",
"tool",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"url",
"=",
"null",
";",
"$",
"id",
"=",
"$",
"tool",
"->",
"id",
";",
"$",
"token",
"=",
"self",
"::",
"generate_proxy_token",
"(",
"$",
"tool",
"->",
"id",
")",
";",
"if",
"(",
"$",
"CFG",
"->",
"slasharguments",
")",
"{",
"$",
"url",
"=",
"new",
"\\",
"moodle_url",
"(",
"'/enrol/lti/proxy.php/'",
".",
"$",
"id",
".",
"'/'",
".",
"$",
"token",
".",
"'/'",
")",
";",
"}",
"else",
"{",
"$",
"url",
"=",
"new",
"\\",
"moodle_url",
"(",
"'/enrol/lti/proxy.php'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"id",
",",
"'token'",
"=>",
"$",
"token",
")",
")",
";",
"}",
"return",
"$",
"url",
";",
"}"
] |
Returns the url to the tool proxy registration url.
If you have slash arguments enabled, this will be a nice url ending in cartridge.xml.
If not it will be a php page with some parameters passed.
@param \stdClass $tool The lti tool
@return string The url to the cartridge representing the tool
|
[
"Returns",
"the",
"url",
"to",
"the",
"tool",
"proxy",
"registration",
"url",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/helper.php#L488-L505
|
215,231
|
moodle/moodle
|
enrol/lti/classes/helper.php
|
helper.get_cartridge_parameters
|
protected static function get_cartridge_parameters($toolid) {
global $PAGE, $SITE;
$PAGE->set_context(\context_system::instance());
// Get the tool.
$tool = self::get_lti_tool($toolid);
// Work out the name of the tool.
$title = self::get_name($tool);
$launchurl = self::get_launch_url($toolid);
$launchurl = $launchurl->out();
$icon = self::get_icon($tool);
$securelaunchurl = null;
$secureicon = null;
$vendorurl = new \moodle_url('/');
$vendorurl = $vendorurl->out();
$description = self::get_description($tool);
// If we are a https site, we can add the launch url and icon urls as secure equivalents.
if (\is_https()) {
$securelaunchurl = $launchurl;
$secureicon = $icon;
}
return array(
"/cc:cartridge_basiclti_link" => array(
"/blti:title" => $title,
"/blti:description" => $description,
"/blti:extensions" => array(
"/lticm:property[@name='icon_url']" => $icon,
"/lticm:property[@name='secure_icon_url']" => $secureicon
),
"/blti:launch_url" => $launchurl,
"/blti:secure_launch_url" => $securelaunchurl,
"/blti:icon" => $icon,
"/blti:secure_icon" => $secureicon,
"/blti:vendor" => array(
"/lticp:code" => $SITE->shortname,
"/lticp:name" => $SITE->fullname,
"/lticp:description" => trim(html_to_text($SITE->summary)),
"/lticp:url" => $vendorurl
)
)
);
}
|
php
|
protected static function get_cartridge_parameters($toolid) {
global $PAGE, $SITE;
$PAGE->set_context(\context_system::instance());
// Get the tool.
$tool = self::get_lti_tool($toolid);
// Work out the name of the tool.
$title = self::get_name($tool);
$launchurl = self::get_launch_url($toolid);
$launchurl = $launchurl->out();
$icon = self::get_icon($tool);
$securelaunchurl = null;
$secureicon = null;
$vendorurl = new \moodle_url('/');
$vendorurl = $vendorurl->out();
$description = self::get_description($tool);
// If we are a https site, we can add the launch url and icon urls as secure equivalents.
if (\is_https()) {
$securelaunchurl = $launchurl;
$secureicon = $icon;
}
return array(
"/cc:cartridge_basiclti_link" => array(
"/blti:title" => $title,
"/blti:description" => $description,
"/blti:extensions" => array(
"/lticm:property[@name='icon_url']" => $icon,
"/lticm:property[@name='secure_icon_url']" => $secureicon
),
"/blti:launch_url" => $launchurl,
"/blti:secure_launch_url" => $securelaunchurl,
"/blti:icon" => $icon,
"/blti:secure_icon" => $secureicon,
"/blti:vendor" => array(
"/lticp:code" => $SITE->shortname,
"/lticp:name" => $SITE->fullname,
"/lticp:description" => trim(html_to_text($SITE->summary)),
"/lticp:url" => $vendorurl
)
)
);
}
|
[
"protected",
"static",
"function",
"get_cartridge_parameters",
"(",
"$",
"toolid",
")",
"{",
"global",
"$",
"PAGE",
",",
"$",
"SITE",
";",
"$",
"PAGE",
"->",
"set_context",
"(",
"\\",
"context_system",
"::",
"instance",
"(",
")",
")",
";",
"// Get the tool.",
"$",
"tool",
"=",
"self",
"::",
"get_lti_tool",
"(",
"$",
"toolid",
")",
";",
"// Work out the name of the tool.",
"$",
"title",
"=",
"self",
"::",
"get_name",
"(",
"$",
"tool",
")",
";",
"$",
"launchurl",
"=",
"self",
"::",
"get_launch_url",
"(",
"$",
"toolid",
")",
";",
"$",
"launchurl",
"=",
"$",
"launchurl",
"->",
"out",
"(",
")",
";",
"$",
"icon",
"=",
"self",
"::",
"get_icon",
"(",
"$",
"tool",
")",
";",
"$",
"securelaunchurl",
"=",
"null",
";",
"$",
"secureicon",
"=",
"null",
";",
"$",
"vendorurl",
"=",
"new",
"\\",
"moodle_url",
"(",
"'/'",
")",
";",
"$",
"vendorurl",
"=",
"$",
"vendorurl",
"->",
"out",
"(",
")",
";",
"$",
"description",
"=",
"self",
"::",
"get_description",
"(",
"$",
"tool",
")",
";",
"// If we are a https site, we can add the launch url and icon urls as secure equivalents.",
"if",
"(",
"\\",
"is_https",
"(",
")",
")",
"{",
"$",
"securelaunchurl",
"=",
"$",
"launchurl",
";",
"$",
"secureicon",
"=",
"$",
"icon",
";",
"}",
"return",
"array",
"(",
"\"/cc:cartridge_basiclti_link\"",
"=>",
"array",
"(",
"\"/blti:title\"",
"=>",
"$",
"title",
",",
"\"/blti:description\"",
"=>",
"$",
"description",
",",
"\"/blti:extensions\"",
"=>",
"array",
"(",
"\"/lticm:property[@name='icon_url']\"",
"=>",
"$",
"icon",
",",
"\"/lticm:property[@name='secure_icon_url']\"",
"=>",
"$",
"secureicon",
")",
",",
"\"/blti:launch_url\"",
"=>",
"$",
"launchurl",
",",
"\"/blti:secure_launch_url\"",
"=>",
"$",
"securelaunchurl",
",",
"\"/blti:icon\"",
"=>",
"$",
"icon",
",",
"\"/blti:secure_icon\"",
"=>",
"$",
"secureicon",
",",
"\"/blti:vendor\"",
"=>",
"array",
"(",
"\"/lticp:code\"",
"=>",
"$",
"SITE",
"->",
"shortname",
",",
"\"/lticp:name\"",
"=>",
"$",
"SITE",
"->",
"fullname",
",",
"\"/lticp:description\"",
"=>",
"trim",
"(",
"html_to_text",
"(",
"$",
"SITE",
"->",
"summary",
")",
")",
",",
"\"/lticp:url\"",
"=>",
"$",
"vendorurl",
")",
")",
")",
";",
"}"
] |
Returns the parameters of the cartridge as an associative array of partial xpath.
@param int $toolid The id of the shared tool
@return array Recursive associative array with partial xpath to be concatenated into an xpath expression
before setting the value.
@since Moodle 3.2
|
[
"Returns",
"the",
"parameters",
"of",
"the",
"cartridge",
"as",
"an",
"associative",
"array",
"of",
"partial",
"xpath",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/helper.php#L569-L613
|
215,232
|
moodle/moodle
|
enrol/lti/classes/helper.php
|
helper.set_xpath
|
protected static function set_xpath($xpath, $parameters, $prefix = '') {
foreach ($parameters as $key => $value) {
if (is_array($value)) {
self::set_xpath($xpath, $value, $prefix . $key);
} else {
$result = @$xpath->query($prefix . $key);
if ($result) {
$node = $result->item(0);
if ($node) {
if (is_null($value)) {
$node->parentNode->removeChild($node);
} else {
$node->nodeValue = $value;
}
}
} else {
throw new \coding_exception('Please check your XPATH and try again.');
}
}
}
}
|
php
|
protected static function set_xpath($xpath, $parameters, $prefix = '') {
foreach ($parameters as $key => $value) {
if (is_array($value)) {
self::set_xpath($xpath, $value, $prefix . $key);
} else {
$result = @$xpath->query($prefix . $key);
if ($result) {
$node = $result->item(0);
if ($node) {
if (is_null($value)) {
$node->parentNode->removeChild($node);
} else {
$node->nodeValue = $value;
}
}
} else {
throw new \coding_exception('Please check your XPATH and try again.');
}
}
}
}
|
[
"protected",
"static",
"function",
"set_xpath",
"(",
"$",
"xpath",
",",
"$",
"parameters",
",",
"$",
"prefix",
"=",
"''",
")",
"{",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"self",
"::",
"set_xpath",
"(",
"$",
"xpath",
",",
"$",
"value",
",",
"$",
"prefix",
".",
"$",
"key",
")",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"@",
"$",
"xpath",
"->",
"query",
"(",
"$",
"prefix",
".",
"$",
"key",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"$",
"node",
"=",
"$",
"result",
"->",
"item",
"(",
"0",
")",
";",
"if",
"(",
"$",
"node",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"$",
"node",
"->",
"parentNode",
"->",
"removeChild",
"(",
"$",
"node",
")",
";",
"}",
"else",
"{",
"$",
"node",
"->",
"nodeValue",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"else",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Please check your XPATH and try again.'",
")",
";",
"}",
"}",
"}",
"}"
] |
Traverses a recursive associative array, setting the properties of the corresponding
xpath element.
@param \DOMXPath $xpath The xpath with the xml to modify
@param array $parameters The array of xpaths to search through
@param string $prefix The current xpath prefix (gets longer the deeper into the array you go)
@return void
@since Moodle 3.2
|
[
"Traverses",
"a",
"recursive",
"associative",
"array",
"setting",
"the",
"properties",
"of",
"the",
"corresponding",
"xpath",
"element",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/helper.php#L625-L645
|
215,233
|
moodle/moodle
|
enrol/lti/classes/helper.php
|
helper.create_cartridge
|
public static function create_cartridge($toolid) {
$cartridge = new \DOMDocument();
$cartridge->load(realpath(__DIR__ . '/../xml/imslticc.xml'));
$xpath = new \DOMXpath($cartridge);
$xpath->registerNamespace('cc', 'http://www.imsglobal.org/xsd/imslticc_v1p0');
$parameters = self::get_cartridge_parameters($toolid);
self::set_xpath($xpath, $parameters);
return $cartridge->saveXML();
}
|
php
|
public static function create_cartridge($toolid) {
$cartridge = new \DOMDocument();
$cartridge->load(realpath(__DIR__ . '/../xml/imslticc.xml'));
$xpath = new \DOMXpath($cartridge);
$xpath->registerNamespace('cc', 'http://www.imsglobal.org/xsd/imslticc_v1p0');
$parameters = self::get_cartridge_parameters($toolid);
self::set_xpath($xpath, $parameters);
return $cartridge->saveXML();
}
|
[
"public",
"static",
"function",
"create_cartridge",
"(",
"$",
"toolid",
")",
"{",
"$",
"cartridge",
"=",
"new",
"\\",
"DOMDocument",
"(",
")",
";",
"$",
"cartridge",
"->",
"load",
"(",
"realpath",
"(",
"__DIR__",
".",
"'/../xml/imslticc.xml'",
")",
")",
";",
"$",
"xpath",
"=",
"new",
"\\",
"DOMXpath",
"(",
"$",
"cartridge",
")",
";",
"$",
"xpath",
"->",
"registerNamespace",
"(",
"'cc'",
",",
"'http://www.imsglobal.org/xsd/imslticc_v1p0'",
")",
";",
"$",
"parameters",
"=",
"self",
"::",
"get_cartridge_parameters",
"(",
"$",
"toolid",
")",
";",
"self",
"::",
"set_xpath",
"(",
"$",
"xpath",
",",
"$",
"parameters",
")",
";",
"return",
"$",
"cartridge",
"->",
"saveXML",
"(",
")",
";",
"}"
] |
Create an IMS cartridge for the tool.
@param int $toolid The id of the shared tool
@return string representing the generated cartridge
@since Moodle 3.2
|
[
"Create",
"an",
"IMS",
"cartridge",
"for",
"the",
"tool",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/classes/helper.php#L654-L663
|
215,234
|
moodle/moodle
|
lib/spout/src/Spout/Common/Helper/GlobalFunctionsHelper.php
|
GlobalFunctionsHelper.convertToUseRealPath
|
protected function convertToUseRealPath($filePath)
{
$realFilePath = $filePath;
if ($this->isZipStream($filePath)) {
if (preg_match('/zip:\/\/(.*)#(.*)/', $filePath, $matches)) {
$documentPath = $matches[1];
$documentInsideZipPath = $matches[2];
$realFilePath = 'zip://' . realpath($documentPath) . '#' . $documentInsideZipPath;
}
} else {
$realFilePath = realpath($filePath);
}
return $realFilePath;
}
|
php
|
protected function convertToUseRealPath($filePath)
{
$realFilePath = $filePath;
if ($this->isZipStream($filePath)) {
if (preg_match('/zip:\/\/(.*)#(.*)/', $filePath, $matches)) {
$documentPath = $matches[1];
$documentInsideZipPath = $matches[2];
$realFilePath = 'zip://' . realpath($documentPath) . '#' . $documentInsideZipPath;
}
} else {
$realFilePath = realpath($filePath);
}
return $realFilePath;
}
|
[
"protected",
"function",
"convertToUseRealPath",
"(",
"$",
"filePath",
")",
"{",
"$",
"realFilePath",
"=",
"$",
"filePath",
";",
"if",
"(",
"$",
"this",
"->",
"isZipStream",
"(",
"$",
"filePath",
")",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/zip:\\/\\/(.*)#(.*)/'",
",",
"$",
"filePath",
",",
"$",
"matches",
")",
")",
"{",
"$",
"documentPath",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"$",
"documentInsideZipPath",
"=",
"$",
"matches",
"[",
"2",
"]",
";",
"$",
"realFilePath",
"=",
"'zip://'",
".",
"realpath",
"(",
"$",
"documentPath",
")",
".",
"'#'",
".",
"$",
"documentInsideZipPath",
";",
"}",
"}",
"else",
"{",
"$",
"realFilePath",
"=",
"realpath",
"(",
"$",
"filePath",
")",
";",
"}",
"return",
"$",
"realFilePath",
";",
"}"
] |
Updates the given file path to use a real path.
This is to avoid issues on some Windows setup.
@param string $filePath File path
@return string The file path using a real path
|
[
"Updates",
"the",
"given",
"file",
"path",
"to",
"use",
"a",
"real",
"path",
".",
"This",
"is",
"to",
"avoid",
"issues",
"on",
"some",
"Windows",
"setup",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Common/Helper/GlobalFunctionsHelper.php#L178-L193
|
215,235
|
moodle/moodle
|
admin/tool/monitor/classes/rule_manager.php
|
rule_manager.clean_ruledata_form
|
public static function clean_ruledata_form($mformdata) {
global $USER;
$rule = new \stdClass();
if (!empty($mformdata->ruleid)) {
$rule->id = $mformdata->ruleid;
}
$rule->userid = empty($mformdata->userid) ? $USER->id : $mformdata->userid;
$rule->courseid = $mformdata->courseid;
$rule->name = $mformdata->name;
$rule->plugin = $mformdata->plugin;
$rule->eventname = $mformdata->eventname;
$rule->description = $mformdata->description['text'];
$rule->descriptionformat = $mformdata->description['format'];
$rule->frequency = $mformdata->frequency;
$rule->timewindow = $mformdata->minutes * MINSECS;
$rule->template = $mformdata->template['text'];
$rule->templateformat = $mformdata->template['format'];
return $rule;
}
|
php
|
public static function clean_ruledata_form($mformdata) {
global $USER;
$rule = new \stdClass();
if (!empty($mformdata->ruleid)) {
$rule->id = $mformdata->ruleid;
}
$rule->userid = empty($mformdata->userid) ? $USER->id : $mformdata->userid;
$rule->courseid = $mformdata->courseid;
$rule->name = $mformdata->name;
$rule->plugin = $mformdata->plugin;
$rule->eventname = $mformdata->eventname;
$rule->description = $mformdata->description['text'];
$rule->descriptionformat = $mformdata->description['format'];
$rule->frequency = $mformdata->frequency;
$rule->timewindow = $mformdata->minutes * MINSECS;
$rule->template = $mformdata->template['text'];
$rule->templateformat = $mformdata->template['format'];
return $rule;
}
|
[
"public",
"static",
"function",
"clean_ruledata_form",
"(",
"$",
"mformdata",
")",
"{",
"global",
"$",
"USER",
";",
"$",
"rule",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"mformdata",
"->",
"ruleid",
")",
")",
"{",
"$",
"rule",
"->",
"id",
"=",
"$",
"mformdata",
"->",
"ruleid",
";",
"}",
"$",
"rule",
"->",
"userid",
"=",
"empty",
"(",
"$",
"mformdata",
"->",
"userid",
")",
"?",
"$",
"USER",
"->",
"id",
":",
"$",
"mformdata",
"->",
"userid",
";",
"$",
"rule",
"->",
"courseid",
"=",
"$",
"mformdata",
"->",
"courseid",
";",
"$",
"rule",
"->",
"name",
"=",
"$",
"mformdata",
"->",
"name",
";",
"$",
"rule",
"->",
"plugin",
"=",
"$",
"mformdata",
"->",
"plugin",
";",
"$",
"rule",
"->",
"eventname",
"=",
"$",
"mformdata",
"->",
"eventname",
";",
"$",
"rule",
"->",
"description",
"=",
"$",
"mformdata",
"->",
"description",
"[",
"'text'",
"]",
";",
"$",
"rule",
"->",
"descriptionformat",
"=",
"$",
"mformdata",
"->",
"description",
"[",
"'format'",
"]",
";",
"$",
"rule",
"->",
"frequency",
"=",
"$",
"mformdata",
"->",
"frequency",
";",
"$",
"rule",
"->",
"timewindow",
"=",
"$",
"mformdata",
"->",
"minutes",
"*",
"MINSECS",
";",
"$",
"rule",
"->",
"template",
"=",
"$",
"mformdata",
"->",
"template",
"[",
"'text'",
"]",
";",
"$",
"rule",
"->",
"templateformat",
"=",
"$",
"mformdata",
"->",
"template",
"[",
"'format'",
"]",
";",
"return",
"$",
"rule",
";",
"}"
] |
Clean data submitted by mform.
@param \stdClass $mformdata data to insert as new rule entry.
@return \stdClass Cleaned rule data.
|
[
"Clean",
"data",
"submitted",
"by",
"mform",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/rule_manager.php#L82-L102
|
215,236
|
moodle/moodle
|
admin/tool/monitor/classes/rule_manager.php
|
rule_manager.delete_rule
|
public static function delete_rule($ruleid, $coursecontext = null) {
global $DB;
subscription_manager::remove_all_subscriptions_for_rule($ruleid, $coursecontext);
// Retrieve the rule from the DB before we delete it, so we have a record when we trigger a rule deleted event.
$rule = $DB->get_record('tool_monitor_rules', array('id' => $ruleid));
$success = $DB->delete_records('tool_monitor_rules', array('id' => $ruleid));
// If successful trigger a rule deleted event.
if ($success) {
// It is possible that we are deleting rules associated with a deleted course, so we should be
// passing the context as the second parameter.
if (!is_null($coursecontext)) {
$context = $coursecontext;
$courseid = $rule->courseid;
} else if (!empty($rule->courseid) && ($context = \context_course::instance($rule->courseid,
IGNORE_MISSING))) {
$courseid = $rule->courseid;
} else {
$courseid = 0;
$context = \context_system::instance();
}
$params = array(
'objectid' => $rule->id,
'courseid' => $courseid,
'context' => $context
);
$event = \tool_monitor\event\rule_deleted::create($params);
$event->add_record_snapshot('tool_monitor_rules', $rule);
$event->trigger();
}
return $success;
}
|
php
|
public static function delete_rule($ruleid, $coursecontext = null) {
global $DB;
subscription_manager::remove_all_subscriptions_for_rule($ruleid, $coursecontext);
// Retrieve the rule from the DB before we delete it, so we have a record when we trigger a rule deleted event.
$rule = $DB->get_record('tool_monitor_rules', array('id' => $ruleid));
$success = $DB->delete_records('tool_monitor_rules', array('id' => $ruleid));
// If successful trigger a rule deleted event.
if ($success) {
// It is possible that we are deleting rules associated with a deleted course, so we should be
// passing the context as the second parameter.
if (!is_null($coursecontext)) {
$context = $coursecontext;
$courseid = $rule->courseid;
} else if (!empty($rule->courseid) && ($context = \context_course::instance($rule->courseid,
IGNORE_MISSING))) {
$courseid = $rule->courseid;
} else {
$courseid = 0;
$context = \context_system::instance();
}
$params = array(
'objectid' => $rule->id,
'courseid' => $courseid,
'context' => $context
);
$event = \tool_monitor\event\rule_deleted::create($params);
$event->add_record_snapshot('tool_monitor_rules', $rule);
$event->trigger();
}
return $success;
}
|
[
"public",
"static",
"function",
"delete_rule",
"(",
"$",
"ruleid",
",",
"$",
"coursecontext",
"=",
"null",
")",
"{",
"global",
"$",
"DB",
";",
"subscription_manager",
"::",
"remove_all_subscriptions_for_rule",
"(",
"$",
"ruleid",
",",
"$",
"coursecontext",
")",
";",
"// Retrieve the rule from the DB before we delete it, so we have a record when we trigger a rule deleted event.",
"$",
"rule",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'tool_monitor_rules'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"ruleid",
")",
")",
";",
"$",
"success",
"=",
"$",
"DB",
"->",
"delete_records",
"(",
"'tool_monitor_rules'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"ruleid",
")",
")",
";",
"// If successful trigger a rule deleted event.",
"if",
"(",
"$",
"success",
")",
"{",
"// It is possible that we are deleting rules associated with a deleted course, so we should be",
"// passing the context as the second parameter.",
"if",
"(",
"!",
"is_null",
"(",
"$",
"coursecontext",
")",
")",
"{",
"$",
"context",
"=",
"$",
"coursecontext",
";",
"$",
"courseid",
"=",
"$",
"rule",
"->",
"courseid",
";",
"}",
"else",
"if",
"(",
"!",
"empty",
"(",
"$",
"rule",
"->",
"courseid",
")",
"&&",
"(",
"$",
"context",
"=",
"\\",
"context_course",
"::",
"instance",
"(",
"$",
"rule",
"->",
"courseid",
",",
"IGNORE_MISSING",
")",
")",
")",
"{",
"$",
"courseid",
"=",
"$",
"rule",
"->",
"courseid",
";",
"}",
"else",
"{",
"$",
"courseid",
"=",
"0",
";",
"$",
"context",
"=",
"\\",
"context_system",
"::",
"instance",
"(",
")",
";",
"}",
"$",
"params",
"=",
"array",
"(",
"'objectid'",
"=>",
"$",
"rule",
"->",
"id",
",",
"'courseid'",
"=>",
"$",
"courseid",
",",
"'context'",
"=>",
"$",
"context",
")",
";",
"$",
"event",
"=",
"\\",
"tool_monitor",
"\\",
"event",
"\\",
"rule_deleted",
"::",
"create",
"(",
"$",
"params",
")",
";",
"$",
"event",
"->",
"add_record_snapshot",
"(",
"'tool_monitor_rules'",
",",
"$",
"rule",
")",
";",
"$",
"event",
"->",
"trigger",
"(",
")",
";",
"}",
"return",
"$",
"success",
";",
"}"
] |
Delete a rule and associated subscriptions, by rule id.
@param int $ruleid id of rule to be deleted.
@param \context|null $coursecontext the context of the course - this is passed when we
can not get the context via \context_course as the course has been deleted.
@return bool
|
[
"Delete",
"a",
"rule",
"and",
"associated",
"subscriptions",
"by",
"rule",
"id",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/rule_manager.php#L113-L149
|
215,237
|
moodle/moodle
|
admin/tool/monitor/classes/rule_manager.php
|
rule_manager.get_rule
|
public static function get_rule($ruleorid) {
global $DB;
if (!is_object($ruleorid)) {
$rule = $DB->get_record('tool_monitor_rules', array('id' => $ruleorid), '*', MUST_EXIST);
} else {
$rule = $ruleorid;
}
return new rule($rule);
}
|
php
|
public static function get_rule($ruleorid) {
global $DB;
if (!is_object($ruleorid)) {
$rule = $DB->get_record('tool_monitor_rules', array('id' => $ruleorid), '*', MUST_EXIST);
} else {
$rule = $ruleorid;
}
return new rule($rule);
}
|
[
"public",
"static",
"function",
"get_rule",
"(",
"$",
"ruleorid",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"ruleorid",
")",
")",
"{",
"$",
"rule",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'tool_monitor_rules'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"ruleorid",
")",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"}",
"else",
"{",
"$",
"rule",
"=",
"$",
"ruleorid",
";",
"}",
"return",
"new",
"rule",
"(",
"$",
"rule",
")",
";",
"}"
] |
Get an instance of rule class.
@param \stdClass|int $ruleorid A rule object from database or rule id.
@return rule object with rule id.
|
[
"Get",
"an",
"instance",
"of",
"rule",
"class",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/rule_manager.php#L158-L167
|
215,238
|
moodle/moodle
|
admin/tool/monitor/classes/rule_manager.php
|
rule_manager.update_rule
|
public static function update_rule($ruledata) {
global $DB;
if (!self::get_rule($ruledata->id)) {
throw new \coding_exception('Invalid rule ID.');
}
$ruledata->timemodified = time();
$success = $DB->update_record('tool_monitor_rules', $ruledata);
// If successful trigger a rule updated event.
if ($success) {
// If we do not have the course id we need to retrieve it.
if (!isset($ruledata->courseid)) {
$courseid = $DB->get_field('tool_monitor_rules', 'courseid', array('id' => $ruledata->id), MUST_EXIST);
} else {
$courseid = $ruledata->courseid;
}
if (!empty($courseid)) {
$context = \context_course::instance($courseid);
} else {
$context = \context_system::instance();
}
$params = array(
'objectid' => $ruledata->id,
'courseid' => $courseid,
'context' => $context
);
$event = \tool_monitor\event\rule_updated::create($params);
$event->trigger();
}
return $success;
}
|
php
|
public static function update_rule($ruledata) {
global $DB;
if (!self::get_rule($ruledata->id)) {
throw new \coding_exception('Invalid rule ID.');
}
$ruledata->timemodified = time();
$success = $DB->update_record('tool_monitor_rules', $ruledata);
// If successful trigger a rule updated event.
if ($success) {
// If we do not have the course id we need to retrieve it.
if (!isset($ruledata->courseid)) {
$courseid = $DB->get_field('tool_monitor_rules', 'courseid', array('id' => $ruledata->id), MUST_EXIST);
} else {
$courseid = $ruledata->courseid;
}
if (!empty($courseid)) {
$context = \context_course::instance($courseid);
} else {
$context = \context_system::instance();
}
$params = array(
'objectid' => $ruledata->id,
'courseid' => $courseid,
'context' => $context
);
$event = \tool_monitor\event\rule_updated::create($params);
$event->trigger();
}
return $success;
}
|
[
"public",
"static",
"function",
"update_rule",
"(",
"$",
"ruledata",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"!",
"self",
"::",
"get_rule",
"(",
"$",
"ruledata",
"->",
"id",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Invalid rule ID.'",
")",
";",
"}",
"$",
"ruledata",
"->",
"timemodified",
"=",
"time",
"(",
")",
";",
"$",
"success",
"=",
"$",
"DB",
"->",
"update_record",
"(",
"'tool_monitor_rules'",
",",
"$",
"ruledata",
")",
";",
"// If successful trigger a rule updated event.",
"if",
"(",
"$",
"success",
")",
"{",
"// If we do not have the course id we need to retrieve it.",
"if",
"(",
"!",
"isset",
"(",
"$",
"ruledata",
"->",
"courseid",
")",
")",
"{",
"$",
"courseid",
"=",
"$",
"DB",
"->",
"get_field",
"(",
"'tool_monitor_rules'",
",",
"'courseid'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"ruledata",
"->",
"id",
")",
",",
"MUST_EXIST",
")",
";",
"}",
"else",
"{",
"$",
"courseid",
"=",
"$",
"ruledata",
"->",
"courseid",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"courseid",
")",
")",
"{",
"$",
"context",
"=",
"\\",
"context_course",
"::",
"instance",
"(",
"$",
"courseid",
")",
";",
"}",
"else",
"{",
"$",
"context",
"=",
"\\",
"context_system",
"::",
"instance",
"(",
")",
";",
"}",
"$",
"params",
"=",
"array",
"(",
"'objectid'",
"=>",
"$",
"ruledata",
"->",
"id",
",",
"'courseid'",
"=>",
"$",
"courseid",
",",
"'context'",
"=>",
"$",
"context",
")",
";",
"$",
"event",
"=",
"\\",
"tool_monitor",
"\\",
"event",
"\\",
"rule_updated",
"::",
"create",
"(",
"$",
"params",
")",
";",
"$",
"event",
"->",
"trigger",
"(",
")",
";",
"}",
"return",
"$",
"success",
";",
"}"
] |
Update rule data.
@throws \coding_exception if $record->ruleid is invalid.
@param object $ruledata rule data to be updated.
@return bool
|
[
"Update",
"rule",
"data",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/rule_manager.php#L177-L211
|
215,239
|
moodle/moodle
|
admin/tool/monitor/classes/rule_manager.php
|
rule_manager.get_rules_by_courseid
|
public static function get_rules_by_courseid($courseid, $limitfrom = 0, $limitto = 0, $includesite = true) {
global $DB;
$select = 'courseid = ?';
$params = array();
$params[] = $courseid;
if ($includesite) {
$select .= ' OR courseid = ?';
$params[] = 0;
}
$orderby = 'courseid DESC, name ASC';
return self::get_instances($DB->get_records_select('tool_monitor_rules', $select, $params, $orderby,
'*', $limitfrom, $limitto));
}
|
php
|
public static function get_rules_by_courseid($courseid, $limitfrom = 0, $limitto = 0, $includesite = true) {
global $DB;
$select = 'courseid = ?';
$params = array();
$params[] = $courseid;
if ($includesite) {
$select .= ' OR courseid = ?';
$params[] = 0;
}
$orderby = 'courseid DESC, name ASC';
return self::get_instances($DB->get_records_select('tool_monitor_rules', $select, $params, $orderby,
'*', $limitfrom, $limitto));
}
|
[
"public",
"static",
"function",
"get_rules_by_courseid",
"(",
"$",
"courseid",
",",
"$",
"limitfrom",
"=",
"0",
",",
"$",
"limitto",
"=",
"0",
",",
"$",
"includesite",
"=",
"true",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"select",
"=",
"'courseid = ?'",
";",
"$",
"params",
"=",
"array",
"(",
")",
";",
"$",
"params",
"[",
"]",
"=",
"$",
"courseid",
";",
"if",
"(",
"$",
"includesite",
")",
"{",
"$",
"select",
".=",
"' OR courseid = ?'",
";",
"$",
"params",
"[",
"]",
"=",
"0",
";",
"}",
"$",
"orderby",
"=",
"'courseid DESC, name ASC'",
";",
"return",
"self",
"::",
"get_instances",
"(",
"$",
"DB",
"->",
"get_records_select",
"(",
"'tool_monitor_rules'",
",",
"$",
"select",
",",
"$",
"params",
",",
"$",
"orderby",
",",
"'*'",
",",
"$",
"limitfrom",
",",
"$",
"limitto",
")",
")",
";",
"}"
] |
Get rules by course id.
@param int $courseid course id of the rule.
@param int $limitfrom Limit from which to fetch rules.
@param int $limitto Limit to which rules need to be fetched.
@param bool $includesite Determines whether we return site wide rules or not.
@return array List of rules for the given course id, if specified will also include site rules.
|
[
"Get",
"rules",
"by",
"course",
"id",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/rule_manager.php#L223-L237
|
215,240
|
moodle/moodle
|
search/classes/base_block.php
|
base_block.get_indexing_restrictions
|
protected function get_indexing_restrictions() {
global $DB;
// This includes completely empty configdata, and also three other values that are
// equivalent to empty:
// - A serialized completely empty object.
// - A serialized object with one field called '0' (string not int) set to boolean false
// (this can happen after backup and restore, at least historically).
// - A serialized null.
$stupidobject = (object)[];
$zero = '0';
$stupidobject->{$zero} = false;
return [$DB->sql_compare_text('bi.configdata') . " != ? AND " .
$DB->sql_compare_text('bi.configdata') . " != ? AND " .
$DB->sql_compare_text('bi.configdata') . " != ? AND " .
$DB->sql_compare_text('bi.configdata') . " != ?",
['', base64_encode(serialize((object)[])), base64_encode(serialize($stupidobject)),
base64_encode(serialize(null))]];
}
|
php
|
protected function get_indexing_restrictions() {
global $DB;
// This includes completely empty configdata, and also three other values that are
// equivalent to empty:
// - A serialized completely empty object.
// - A serialized object with one field called '0' (string not int) set to boolean false
// (this can happen after backup and restore, at least historically).
// - A serialized null.
$stupidobject = (object)[];
$zero = '0';
$stupidobject->{$zero} = false;
return [$DB->sql_compare_text('bi.configdata') . " != ? AND " .
$DB->sql_compare_text('bi.configdata') . " != ? AND " .
$DB->sql_compare_text('bi.configdata') . " != ? AND " .
$DB->sql_compare_text('bi.configdata') . " != ?",
['', base64_encode(serialize((object)[])), base64_encode(serialize($stupidobject)),
base64_encode(serialize(null))]];
}
|
[
"protected",
"function",
"get_indexing_restrictions",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"// This includes completely empty configdata, and also three other values that are",
"// equivalent to empty:",
"// - A serialized completely empty object.",
"// - A serialized object with one field called '0' (string not int) set to boolean false",
"// (this can happen after backup and restore, at least historically).",
"// - A serialized null.",
"$",
"stupidobject",
"=",
"(",
"object",
")",
"[",
"]",
";",
"$",
"zero",
"=",
"'0'",
";",
"$",
"stupidobject",
"->",
"{",
"$",
"zero",
"}",
"=",
"false",
";",
"return",
"[",
"$",
"DB",
"->",
"sql_compare_text",
"(",
"'bi.configdata'",
")",
".",
"\" != ? AND \"",
".",
"$",
"DB",
"->",
"sql_compare_text",
"(",
"'bi.configdata'",
")",
".",
"\" != ? AND \"",
".",
"$",
"DB",
"->",
"sql_compare_text",
"(",
"'bi.configdata'",
")",
".",
"\" != ? AND \"",
".",
"$",
"DB",
"->",
"sql_compare_text",
"(",
"'bi.configdata'",
")",
".",
"\" != ?\"",
",",
"[",
"''",
",",
"base64_encode",
"(",
"serialize",
"(",
"(",
"object",
")",
"[",
"]",
")",
")",
",",
"base64_encode",
"(",
"serialize",
"(",
"$",
"stupidobject",
")",
")",
",",
"base64_encode",
"(",
"serialize",
"(",
"null",
")",
")",
"]",
"]",
";",
"}"
] |
Returns restrictions on which block_instances rows to return. By default, excludes rows
that have empty configdata.
If no restriction is required, you could return ['', []].
@return array 2-element array of SQL restriction and params for it
|
[
"Returns",
"restrictions",
"on",
"which",
"block_instances",
"rows",
"to",
"return",
".",
"By",
"default",
"excludes",
"rows",
"that",
"have",
"empty",
"configdata",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/base_block.php#L72-L90
|
215,241
|
moodle/moodle
|
search/classes/base_block.php
|
base_block.get_document_recordset
|
public function get_document_recordset($modifiedfrom = 0, \context $context = null) {
global $DB;
// Get context restrictions.
list ($contextjoin, $contextparams) = $this->get_context_restriction_sql($context, 'bi');
// Get custom restrictions for block type.
list ($restrictions, $restrictionparams) = $this->get_indexing_restrictions();
if ($restrictions) {
$restrictions = 'AND ' . $restrictions;
}
// Query for all entries in block_instances for this type of block, within the specified
// context. The query is based on the one from get_recordset_by_timestamp and applies the
// same restrictions.
return $DB->get_recordset_sql("
SELECT bi.id, bi.timemodified, bi.timecreated, bi.configdata,
c.id AS courseid, x.id AS contextid
FROM {block_instances} bi
$contextjoin
JOIN {context} x ON x.instanceid = bi.id AND x.contextlevel = ?
JOIN {context} parent ON parent.id = bi.parentcontextid
LEFT JOIN {course_modules} cm ON cm.id = parent.instanceid AND parent.contextlevel = ?
JOIN {course} c ON c.id = cm.course
OR (c.id = parent.instanceid AND parent.contextlevel = ?)
WHERE bi.timemodified >= ?
AND bi.blockname = ?
AND (parent.contextlevel = ? AND (" . $DB->sql_like('bi.pagetypepattern', '?') . "
OR bi.pagetypepattern IN ('site-index', 'course-*', '*')))
$restrictions
ORDER BY bi.timemodified ASC",
array_merge($contextparams, [CONTEXT_BLOCK, CONTEXT_MODULE, CONTEXT_COURSE,
$modifiedfrom, $this->get_block_name(), CONTEXT_COURSE, 'course-view-%'],
$restrictionparams));
}
|
php
|
public function get_document_recordset($modifiedfrom = 0, \context $context = null) {
global $DB;
// Get context restrictions.
list ($contextjoin, $contextparams) = $this->get_context_restriction_sql($context, 'bi');
// Get custom restrictions for block type.
list ($restrictions, $restrictionparams) = $this->get_indexing_restrictions();
if ($restrictions) {
$restrictions = 'AND ' . $restrictions;
}
// Query for all entries in block_instances for this type of block, within the specified
// context. The query is based on the one from get_recordset_by_timestamp and applies the
// same restrictions.
return $DB->get_recordset_sql("
SELECT bi.id, bi.timemodified, bi.timecreated, bi.configdata,
c.id AS courseid, x.id AS contextid
FROM {block_instances} bi
$contextjoin
JOIN {context} x ON x.instanceid = bi.id AND x.contextlevel = ?
JOIN {context} parent ON parent.id = bi.parentcontextid
LEFT JOIN {course_modules} cm ON cm.id = parent.instanceid AND parent.contextlevel = ?
JOIN {course} c ON c.id = cm.course
OR (c.id = parent.instanceid AND parent.contextlevel = ?)
WHERE bi.timemodified >= ?
AND bi.blockname = ?
AND (parent.contextlevel = ? AND (" . $DB->sql_like('bi.pagetypepattern', '?') . "
OR bi.pagetypepattern IN ('site-index', 'course-*', '*')))
$restrictions
ORDER BY bi.timemodified ASC",
array_merge($contextparams, [CONTEXT_BLOCK, CONTEXT_MODULE, CONTEXT_COURSE,
$modifiedfrom, $this->get_block_name(), CONTEXT_COURSE, 'course-view-%'],
$restrictionparams));
}
|
[
"public",
"function",
"get_document_recordset",
"(",
"$",
"modifiedfrom",
"=",
"0",
",",
"\\",
"context",
"$",
"context",
"=",
"null",
")",
"{",
"global",
"$",
"DB",
";",
"// Get context restrictions.",
"list",
"(",
"$",
"contextjoin",
",",
"$",
"contextparams",
")",
"=",
"$",
"this",
"->",
"get_context_restriction_sql",
"(",
"$",
"context",
",",
"'bi'",
")",
";",
"// Get custom restrictions for block type.",
"list",
"(",
"$",
"restrictions",
",",
"$",
"restrictionparams",
")",
"=",
"$",
"this",
"->",
"get_indexing_restrictions",
"(",
")",
";",
"if",
"(",
"$",
"restrictions",
")",
"{",
"$",
"restrictions",
"=",
"'AND '",
".",
"$",
"restrictions",
";",
"}",
"// Query for all entries in block_instances for this type of block, within the specified",
"// context. The query is based on the one from get_recordset_by_timestamp and applies the",
"// same restrictions.",
"return",
"$",
"DB",
"->",
"get_recordset_sql",
"(",
"\"\n SELECT bi.id, bi.timemodified, bi.timecreated, bi.configdata,\n c.id AS courseid, x.id AS contextid\n FROM {block_instances} bi\n $contextjoin\n JOIN {context} x ON x.instanceid = bi.id AND x.contextlevel = ?\n JOIN {context} parent ON parent.id = bi.parentcontextid\n LEFT JOIN {course_modules} cm ON cm.id = parent.instanceid AND parent.contextlevel = ?\n JOIN {course} c ON c.id = cm.course\n OR (c.id = parent.instanceid AND parent.contextlevel = ?)\n WHERE bi.timemodified >= ?\n AND bi.blockname = ?\n AND (parent.contextlevel = ? AND (\"",
".",
"$",
"DB",
"->",
"sql_like",
"(",
"'bi.pagetypepattern'",
",",
"'?'",
")",
".",
"\"\n OR bi.pagetypepattern IN ('site-index', 'course-*', '*')))\n $restrictions\n ORDER BY bi.timemodified ASC\"",
",",
"array_merge",
"(",
"$",
"contextparams",
",",
"[",
"CONTEXT_BLOCK",
",",
"CONTEXT_MODULE",
",",
"CONTEXT_COURSE",
",",
"$",
"modifiedfrom",
",",
"$",
"this",
"->",
"get_block_name",
"(",
")",
",",
"CONTEXT_COURSE",
",",
"'course-view-%'",
"]",
",",
"$",
"restrictionparams",
")",
")",
";",
"}"
] |
Gets recordset of all blocks of this type modified since given time within the given context.
See base class for detailed requirements. This implementation includes the key fields
from block_instances.
This can be overridden to do something totally different if the block's data is stored in
other tables.
If there are certain instances of the block which should not be included in the search index
then you can override get_indexing_restrictions; by default this excludes rows with empty
configdata.
@param int $modifiedfrom Return only records modified after this date
@param \context|null $context Context to find blocks within
@return false|\moodle_recordset|null
|
[
"Gets",
"recordset",
"of",
"all",
"blocks",
"of",
"this",
"type",
"modified",
"since",
"given",
"time",
"within",
"the",
"given",
"context",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/base_block.php#L109-L143
|
215,242
|
moodle/moodle
|
search/classes/base_block.php
|
base_block.check_access
|
public function check_access($id) {
$instance = $this->get_block_instance($id, IGNORE_MISSING);
if (!$instance) {
// This generally won't happen because if the block has been deleted then we won't have
// included its context in the search area list, but just in case.
return manager::ACCESS_DELETED;
}
// Check block has not been moved to an unsupported area since it was indexed. (At the
// moment, only blocks within site and course context are supported, also only certain
// page types.)
if (!$instance->courseid ||
!self::is_supported_page_type_at_course_context($instance->pagetypepattern)) {
return manager::ACCESS_DELETED;
}
// Note we do not need to check if the block was hidden or if the user has access to the
// context, because those checks are included in the list of search contexts user can access
// that is calculated in manager.php every time they do a query.
return manager::ACCESS_GRANTED;
}
|
php
|
public function check_access($id) {
$instance = $this->get_block_instance($id, IGNORE_MISSING);
if (!$instance) {
// This generally won't happen because if the block has been deleted then we won't have
// included its context in the search area list, but just in case.
return manager::ACCESS_DELETED;
}
// Check block has not been moved to an unsupported area since it was indexed. (At the
// moment, only blocks within site and course context are supported, also only certain
// page types.)
if (!$instance->courseid ||
!self::is_supported_page_type_at_course_context($instance->pagetypepattern)) {
return manager::ACCESS_DELETED;
}
// Note we do not need to check if the block was hidden or if the user has access to the
// context, because those checks are included in the list of search contexts user can access
// that is calculated in manager.php every time they do a query.
return manager::ACCESS_GRANTED;
}
|
[
"public",
"function",
"check_access",
"(",
"$",
"id",
")",
"{",
"$",
"instance",
"=",
"$",
"this",
"->",
"get_block_instance",
"(",
"$",
"id",
",",
"IGNORE_MISSING",
")",
";",
"if",
"(",
"!",
"$",
"instance",
")",
"{",
"// This generally won't happen because if the block has been deleted then we won't have",
"// included its context in the search area list, but just in case.",
"return",
"manager",
"::",
"ACCESS_DELETED",
";",
"}",
"// Check block has not been moved to an unsupported area since it was indexed. (At the",
"// moment, only blocks within site and course context are supported, also only certain",
"// page types.)",
"if",
"(",
"!",
"$",
"instance",
"->",
"courseid",
"||",
"!",
"self",
"::",
"is_supported_page_type_at_course_context",
"(",
"$",
"instance",
"->",
"pagetypepattern",
")",
")",
"{",
"return",
"manager",
"::",
"ACCESS_DELETED",
";",
"}",
"// Note we do not need to check if the block was hidden or if the user has access to the",
"// context, because those checks are included in the list of search contexts user can access",
"// that is calculated in manager.php every time they do a query.",
"return",
"manager",
"::",
"ACCESS_GRANTED",
";",
"}"
] |
Checks access for a document in this search area.
If you override this function for a block, you should call this base class version first
as it will check that the block is still visible to users in a supported location.
@param int $id Document id
@return int manager:ACCESS_xx constant
|
[
"Checks",
"access",
"for",
"a",
"document",
"in",
"this",
"search",
"area",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/base_block.php#L190-L210
|
215,243
|
moodle/moodle
|
search/classes/base_block.php
|
base_block.get_block_instance
|
protected function get_block_instance($id, $strictness = MUST_EXIST) {
global $DB;
$cache = \cache::make_from_params(\cache_store::MODE_REQUEST, 'core_search',
self::CACHE_INSTANCES, [], ['simplekeys' => true]);
$id = (int)$id;
$instance = $cache->get($id);
if (!$instance) {
$instance = $DB->get_record_sql("
SELECT bi.id, bi.pagetypepattern, bi.subpagepattern,
c.id AS courseid, cm.id AS cmid
FROM {block_instances} bi
JOIN {context} parent ON parent.id = bi.parentcontextid
LEFT JOIN {course} c ON c.id = parent.instanceid AND parent.contextlevel = ?
LEFT JOIN {course_modules} cm ON cm.id = parent.instanceid AND parent.contextlevel = ?
WHERE bi.id = ?",
[CONTEXT_COURSE, CONTEXT_MODULE, $id], $strictness);
$cache->set($id, $instance);
}
return $instance;
}
|
php
|
protected function get_block_instance($id, $strictness = MUST_EXIST) {
global $DB;
$cache = \cache::make_from_params(\cache_store::MODE_REQUEST, 'core_search',
self::CACHE_INSTANCES, [], ['simplekeys' => true]);
$id = (int)$id;
$instance = $cache->get($id);
if (!$instance) {
$instance = $DB->get_record_sql("
SELECT bi.id, bi.pagetypepattern, bi.subpagepattern,
c.id AS courseid, cm.id AS cmid
FROM {block_instances} bi
JOIN {context} parent ON parent.id = bi.parentcontextid
LEFT JOIN {course} c ON c.id = parent.instanceid AND parent.contextlevel = ?
LEFT JOIN {course_modules} cm ON cm.id = parent.instanceid AND parent.contextlevel = ?
WHERE bi.id = ?",
[CONTEXT_COURSE, CONTEXT_MODULE, $id], $strictness);
$cache->set($id, $instance);
}
return $instance;
}
|
[
"protected",
"function",
"get_block_instance",
"(",
"$",
"id",
",",
"$",
"strictness",
"=",
"MUST_EXIST",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"cache",
"=",
"\\",
"cache",
"::",
"make_from_params",
"(",
"\\",
"cache_store",
"::",
"MODE_REQUEST",
",",
"'core_search'",
",",
"self",
"::",
"CACHE_INSTANCES",
",",
"[",
"]",
",",
"[",
"'simplekeys'",
"=>",
"true",
"]",
")",
";",
"$",
"id",
"=",
"(",
"int",
")",
"$",
"id",
";",
"$",
"instance",
"=",
"$",
"cache",
"->",
"get",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"instance",
")",
"{",
"$",
"instance",
"=",
"$",
"DB",
"->",
"get_record_sql",
"(",
"\"\n SELECT bi.id, bi.pagetypepattern, bi.subpagepattern,\n c.id AS courseid, cm.id AS cmid\n FROM {block_instances} bi\n JOIN {context} parent ON parent.id = bi.parentcontextid\n LEFT JOIN {course} c ON c.id = parent.instanceid AND parent.contextlevel = ?\n LEFT JOIN {course_modules} cm ON cm.id = parent.instanceid AND parent.contextlevel = ?\n WHERE bi.id = ?\"",
",",
"[",
"CONTEXT_COURSE",
",",
"CONTEXT_MODULE",
",",
"$",
"id",
"]",
",",
"$",
"strictness",
")",
";",
"$",
"cache",
"->",
"set",
"(",
"$",
"id",
",",
"$",
"instance",
")",
";",
"}",
"return",
"$",
"instance",
";",
"}"
] |
Gets a block instance with given id.
Returns the fields id, pagetypepattern, subpagepattern from block_instances and also the
cmid (if parent context is an activity module).
@param int $id ID of block instance
@param int $strictness MUST_EXIST or IGNORE_MISSING
@return false|mixed Block instance data (may be false if strictness is IGNORE_MISSING)
|
[
"Gets",
"a",
"block",
"instance",
"with",
"given",
"id",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/base_block.php#L239-L259
|
215,244
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Style/Fill.php
|
PHPExcel_Style_Fill.setStartColor
|
public function setStartColor(PHPExcel_Style_Color $pValue = null)
{
// make sure parameter is a real color and not a supervisor
$color = $pValue->getIsSupervisor() ? $pValue->getSharedComponent() : $pValue;
if ($this->isSupervisor) {
$styleArray = $this->getStartColor()->getStyleArray(array('argb' => $color->getARGB()));
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else {
$this->startColor = $color;
}
return $this;
}
|
php
|
public function setStartColor(PHPExcel_Style_Color $pValue = null)
{
// make sure parameter is a real color and not a supervisor
$color = $pValue->getIsSupervisor() ? $pValue->getSharedComponent() : $pValue;
if ($this->isSupervisor) {
$styleArray = $this->getStartColor()->getStyleArray(array('argb' => $color->getARGB()));
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else {
$this->startColor = $color;
}
return $this;
}
|
[
"public",
"function",
"setStartColor",
"(",
"PHPExcel_Style_Color",
"$",
"pValue",
"=",
"null",
")",
"{",
"// make sure parameter is a real color and not a supervisor",
"$",
"color",
"=",
"$",
"pValue",
"->",
"getIsSupervisor",
"(",
")",
"?",
"$",
"pValue",
"->",
"getSharedComponent",
"(",
")",
":",
"$",
"pValue",
";",
"if",
"(",
"$",
"this",
"->",
"isSupervisor",
")",
"{",
"$",
"styleArray",
"=",
"$",
"this",
"->",
"getStartColor",
"(",
")",
"->",
"getStyleArray",
"(",
"array",
"(",
"'argb'",
"=>",
"$",
"color",
"->",
"getARGB",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"getActiveSheet",
"(",
")",
"->",
"getStyle",
"(",
"$",
"this",
"->",
"getSelectedCells",
"(",
")",
")",
"->",
"applyFromArray",
"(",
"$",
"styleArray",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"startColor",
"=",
"$",
"color",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Set Start Color
@param PHPExcel_Style_Color $pValue
@throws PHPExcel_Exception
@return PHPExcel_Style_Fill
|
[
"Set",
"Start",
"Color"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Style/Fill.php#L259-L271
|
215,245
|
moodle/moodle
|
search/classes/manager.php
|
manager.instance
|
public static function instance($fast = false) {
global $CFG;
// One per request, this should be purged during testing.
if (static::$instance !== null) {
return static::$instance;
}
if (empty($CFG->searchengine)) {
throw new \core_search\engine_exception('enginenotselected', 'search');
}
if (!$engine = static::search_engine_instance()) {
throw new \core_search\engine_exception('enginenotfound', 'search', '', $CFG->searchengine);
}
// Get time now and at last schema check.
$now = (int)self::get_current_time();
$lastschemacheck = get_config($engine->get_plugin_name(), 'lastschemacheck');
// On pages where performance matters, tell the engine to skip schema checks.
$skipcheck = false;
if ($fast && $now < $lastschemacheck + self::SCHEMA_CHECK_REQUIRED_EVERY) {
$skipcheck = true;
$engine->skip_schema_check();
}
if (!$engine->is_installed()) {
throw new \core_search\engine_exception('enginenotinstalled', 'search', '', $CFG->searchengine);
}
$serverstatus = $engine->is_server_ready();
if ($serverstatus !== true) {
// Skip this error in Behat when faking seach results.
if (!defined('BEHAT_SITE_RUNNING') || !get_config('core_search', 'behat_fakeresult')) {
// Clear the record of successful schema checks since it might have failed.
unset_config('lastschemacheck', $engine->get_plugin_name());
// Error message with no details as this is an exception that any user may find if the server crashes.
throw new \core_search\engine_exception('engineserverstatus', 'search');
}
}
// If we did a successful schema check, record this, but not more than once per 10 minutes
// (to avoid updating the config db table/cache too often in case it gets called frequently).
if (!$skipcheck && $now >= $lastschemacheck + self::SCHEMA_CHECK_TRACKING_DELAY) {
set_config('lastschemacheck', $now, $engine->get_plugin_name());
}
static::$instance = new \core_search\manager($engine);
return static::$instance;
}
|
php
|
public static function instance($fast = false) {
global $CFG;
// One per request, this should be purged during testing.
if (static::$instance !== null) {
return static::$instance;
}
if (empty($CFG->searchengine)) {
throw new \core_search\engine_exception('enginenotselected', 'search');
}
if (!$engine = static::search_engine_instance()) {
throw new \core_search\engine_exception('enginenotfound', 'search', '', $CFG->searchengine);
}
// Get time now and at last schema check.
$now = (int)self::get_current_time();
$lastschemacheck = get_config($engine->get_plugin_name(), 'lastschemacheck');
// On pages where performance matters, tell the engine to skip schema checks.
$skipcheck = false;
if ($fast && $now < $lastschemacheck + self::SCHEMA_CHECK_REQUIRED_EVERY) {
$skipcheck = true;
$engine->skip_schema_check();
}
if (!$engine->is_installed()) {
throw new \core_search\engine_exception('enginenotinstalled', 'search', '', $CFG->searchengine);
}
$serverstatus = $engine->is_server_ready();
if ($serverstatus !== true) {
// Skip this error in Behat when faking seach results.
if (!defined('BEHAT_SITE_RUNNING') || !get_config('core_search', 'behat_fakeresult')) {
// Clear the record of successful schema checks since it might have failed.
unset_config('lastschemacheck', $engine->get_plugin_name());
// Error message with no details as this is an exception that any user may find if the server crashes.
throw new \core_search\engine_exception('engineserverstatus', 'search');
}
}
// If we did a successful schema check, record this, but not more than once per 10 minutes
// (to avoid updating the config db table/cache too often in case it gets called frequently).
if (!$skipcheck && $now >= $lastschemacheck + self::SCHEMA_CHECK_TRACKING_DELAY) {
set_config('lastschemacheck', $now, $engine->get_plugin_name());
}
static::$instance = new \core_search\manager($engine);
return static::$instance;
}
|
[
"public",
"static",
"function",
"instance",
"(",
"$",
"fast",
"=",
"false",
")",
"{",
"global",
"$",
"CFG",
";",
"// One per request, this should be purged during testing.",
"if",
"(",
"static",
"::",
"$",
"instance",
"!==",
"null",
")",
"{",
"return",
"static",
"::",
"$",
"instance",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"CFG",
"->",
"searchengine",
")",
")",
"{",
"throw",
"new",
"\\",
"core_search",
"\\",
"engine_exception",
"(",
"'enginenotselected'",
",",
"'search'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"engine",
"=",
"static",
"::",
"search_engine_instance",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"core_search",
"\\",
"engine_exception",
"(",
"'enginenotfound'",
",",
"'search'",
",",
"''",
",",
"$",
"CFG",
"->",
"searchengine",
")",
";",
"}",
"// Get time now and at last schema check.",
"$",
"now",
"=",
"(",
"int",
")",
"self",
"::",
"get_current_time",
"(",
")",
";",
"$",
"lastschemacheck",
"=",
"get_config",
"(",
"$",
"engine",
"->",
"get_plugin_name",
"(",
")",
",",
"'lastschemacheck'",
")",
";",
"// On pages where performance matters, tell the engine to skip schema checks.",
"$",
"skipcheck",
"=",
"false",
";",
"if",
"(",
"$",
"fast",
"&&",
"$",
"now",
"<",
"$",
"lastschemacheck",
"+",
"self",
"::",
"SCHEMA_CHECK_REQUIRED_EVERY",
")",
"{",
"$",
"skipcheck",
"=",
"true",
";",
"$",
"engine",
"->",
"skip_schema_check",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"engine",
"->",
"is_installed",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"core_search",
"\\",
"engine_exception",
"(",
"'enginenotinstalled'",
",",
"'search'",
",",
"''",
",",
"$",
"CFG",
"->",
"searchengine",
")",
";",
"}",
"$",
"serverstatus",
"=",
"$",
"engine",
"->",
"is_server_ready",
"(",
")",
";",
"if",
"(",
"$",
"serverstatus",
"!==",
"true",
")",
"{",
"// Skip this error in Behat when faking seach results.",
"if",
"(",
"!",
"defined",
"(",
"'BEHAT_SITE_RUNNING'",
")",
"||",
"!",
"get_config",
"(",
"'core_search'",
",",
"'behat_fakeresult'",
")",
")",
"{",
"// Clear the record of successful schema checks since it might have failed.",
"unset_config",
"(",
"'lastschemacheck'",
",",
"$",
"engine",
"->",
"get_plugin_name",
"(",
")",
")",
";",
"// Error message with no details as this is an exception that any user may find if the server crashes.",
"throw",
"new",
"\\",
"core_search",
"\\",
"engine_exception",
"(",
"'engineserverstatus'",
",",
"'search'",
")",
";",
"}",
"}",
"// If we did a successful schema check, record this, but not more than once per 10 minutes",
"// (to avoid updating the config db table/cache too often in case it gets called frequently).",
"if",
"(",
"!",
"$",
"skipcheck",
"&&",
"$",
"now",
">=",
"$",
"lastschemacheck",
"+",
"self",
"::",
"SCHEMA_CHECK_TRACKING_DELAY",
")",
"{",
"set_config",
"(",
"'lastschemacheck'",
",",
"$",
"now",
",",
"$",
"engine",
"->",
"get_plugin_name",
"(",
")",
")",
";",
"}",
"static",
"::",
"$",
"instance",
"=",
"new",
"\\",
"core_search",
"\\",
"manager",
"(",
"$",
"engine",
")",
";",
"return",
"static",
"::",
"$",
"instance",
";",
"}"
] |
Returns an initialised \core_search instance.
While constructing the instance, checks on the search schema may be carried out. The $fast
parameter provides a way to skip those checks on pages which are used frequently. It has
no effect if an instance has already been constructed in this request.
@see \core_search\engine::is_installed
@see \core_search\engine::is_server_ready
@param bool $fast Set to true when calling on a page that requires high performance
@throws \core_search\engine_exception
@return \core_search\manager
|
[
"Returns",
"an",
"initialised",
"\\",
"core_search",
"instance",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/manager.php#L189-L239
|
215,246
|
moodle/moodle
|
search/classes/manager.php
|
manager.get_search_area
|
public static function get_search_area($areaid) {
// We have them all here.
if (!empty(static::$allsearchareas[$areaid])) {
return static::$allsearchareas[$areaid];
}
$classname = static::get_area_classname($areaid);
if (class_exists($classname) && static::is_search_area($classname)) {
return new $classname();
}
return false;
}
|
php
|
public static function get_search_area($areaid) {
// We have them all here.
if (!empty(static::$allsearchareas[$areaid])) {
return static::$allsearchareas[$areaid];
}
$classname = static::get_area_classname($areaid);
if (class_exists($classname) && static::is_search_area($classname)) {
return new $classname();
}
return false;
}
|
[
"public",
"static",
"function",
"get_search_area",
"(",
"$",
"areaid",
")",
"{",
"// We have them all here.",
"if",
"(",
"!",
"empty",
"(",
"static",
"::",
"$",
"allsearchareas",
"[",
"$",
"areaid",
"]",
")",
")",
"{",
"return",
"static",
"::",
"$",
"allsearchareas",
"[",
"$",
"areaid",
"]",
";",
"}",
"$",
"classname",
"=",
"static",
"::",
"get_area_classname",
"(",
"$",
"areaid",
")",
";",
"if",
"(",
"class_exists",
"(",
"$",
"classname",
")",
"&&",
"static",
"::",
"is_search_area",
"(",
"$",
"classname",
")",
")",
"{",
"return",
"new",
"$",
"classname",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Returns a new area search indexer instance.
@param string $areaid
@return \core_search\base|bool False if the area is not available.
|
[
"Returns",
"a",
"new",
"area",
"search",
"indexer",
"instance",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/manager.php#L304-L318
|
215,247
|
moodle/moodle
|
search/classes/manager.php
|
manager.get_search_areas_list
|
public static function get_search_areas_list($enabled = false) {
// Two different arrays, we don't expect these arrays to be big.
if (static::$allsearchareas !== null) {
if (!$enabled) {
return static::$allsearchareas;
} else {
return static::$enabledsearchareas;
}
}
static::$allsearchareas = array();
static::$enabledsearchareas = array();
$searchclasses = \core_component::get_component_classes_in_namespace(null, 'search');
foreach ($searchclasses as $classname => $classpath) {
$areaname = substr(strrchr($classname, '\\'), 1);
$componentname = strstr($classname, '\\', 1);
if (!static::is_search_area($classname)) {
continue;
}
$areaid = static::generate_areaid($componentname, $areaname);
$searchclass = new $classname();
static::$allsearchareas[$areaid] = $searchclass;
if ($searchclass->is_enabled()) {
static::$enabledsearchareas[$areaid] = $searchclass;
}
}
if ($enabled) {
return static::$enabledsearchareas;
}
return static::$allsearchareas;
}
|
php
|
public static function get_search_areas_list($enabled = false) {
// Two different arrays, we don't expect these arrays to be big.
if (static::$allsearchareas !== null) {
if (!$enabled) {
return static::$allsearchareas;
} else {
return static::$enabledsearchareas;
}
}
static::$allsearchareas = array();
static::$enabledsearchareas = array();
$searchclasses = \core_component::get_component_classes_in_namespace(null, 'search');
foreach ($searchclasses as $classname => $classpath) {
$areaname = substr(strrchr($classname, '\\'), 1);
$componentname = strstr($classname, '\\', 1);
if (!static::is_search_area($classname)) {
continue;
}
$areaid = static::generate_areaid($componentname, $areaname);
$searchclass = new $classname();
static::$allsearchareas[$areaid] = $searchclass;
if ($searchclass->is_enabled()) {
static::$enabledsearchareas[$areaid] = $searchclass;
}
}
if ($enabled) {
return static::$enabledsearchareas;
}
return static::$allsearchareas;
}
|
[
"public",
"static",
"function",
"get_search_areas_list",
"(",
"$",
"enabled",
"=",
"false",
")",
"{",
"// Two different arrays, we don't expect these arrays to be big.",
"if",
"(",
"static",
"::",
"$",
"allsearchareas",
"!==",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"enabled",
")",
"{",
"return",
"static",
"::",
"$",
"allsearchareas",
";",
"}",
"else",
"{",
"return",
"static",
"::",
"$",
"enabledsearchareas",
";",
"}",
"}",
"static",
"::",
"$",
"allsearchareas",
"=",
"array",
"(",
")",
";",
"static",
"::",
"$",
"enabledsearchareas",
"=",
"array",
"(",
")",
";",
"$",
"searchclasses",
"=",
"\\",
"core_component",
"::",
"get_component_classes_in_namespace",
"(",
"null",
",",
"'search'",
")",
";",
"foreach",
"(",
"$",
"searchclasses",
"as",
"$",
"classname",
"=>",
"$",
"classpath",
")",
"{",
"$",
"areaname",
"=",
"substr",
"(",
"strrchr",
"(",
"$",
"classname",
",",
"'\\\\'",
")",
",",
"1",
")",
";",
"$",
"componentname",
"=",
"strstr",
"(",
"$",
"classname",
",",
"'\\\\'",
",",
"1",
")",
";",
"if",
"(",
"!",
"static",
"::",
"is_search_area",
"(",
"$",
"classname",
")",
")",
"{",
"continue",
";",
"}",
"$",
"areaid",
"=",
"static",
"::",
"generate_areaid",
"(",
"$",
"componentname",
",",
"$",
"areaname",
")",
";",
"$",
"searchclass",
"=",
"new",
"$",
"classname",
"(",
")",
";",
"static",
"::",
"$",
"allsearchareas",
"[",
"$",
"areaid",
"]",
"=",
"$",
"searchclass",
";",
"if",
"(",
"$",
"searchclass",
"->",
"is_enabled",
"(",
")",
")",
"{",
"static",
"::",
"$",
"enabledsearchareas",
"[",
"$",
"areaid",
"]",
"=",
"$",
"searchclass",
";",
"}",
"}",
"if",
"(",
"$",
"enabled",
")",
"{",
"return",
"static",
"::",
"$",
"enabledsearchareas",
";",
"}",
"return",
"static",
"::",
"$",
"allsearchareas",
";",
"}"
] |
Return the list of available search areas.
@param bool $enabled Return only the enabled ones.
@return \core_search\base[]
|
[
"Return",
"the",
"list",
"of",
"available",
"search",
"areas",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/manager.php#L326-L360
|
215,248
|
moodle/moodle
|
search/classes/manager.php
|
manager.get_search_area_category_by_name
|
public static function get_search_area_category_by_name($name) {
if (key_exists($name, self::get_search_area_categories())) {
return self::get_search_area_categories()[$name];
} else {
return self::get_search_area_categories()[self::get_default_area_category_name()];
}
}
|
php
|
public static function get_search_area_category_by_name($name) {
if (key_exists($name, self::get_search_area_categories())) {
return self::get_search_area_categories()[$name];
} else {
return self::get_search_area_categories()[self::get_default_area_category_name()];
}
}
|
[
"public",
"static",
"function",
"get_search_area_category_by_name",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"key_exists",
"(",
"$",
"name",
",",
"self",
"::",
"get_search_area_categories",
"(",
")",
")",
")",
"{",
"return",
"self",
"::",
"get_search_area_categories",
"(",
")",
"[",
"$",
"name",
"]",
";",
"}",
"else",
"{",
"return",
"self",
"::",
"get_search_area_categories",
"(",
")",
"[",
"self",
"::",
"get_default_area_category_name",
"(",
")",
"]",
";",
"}",
"}"
] |
Return search area category instance by category name.
@param string $name Category name. If name is not valid will return default category.
@return \core_search\area_category
|
[
"Return",
"search",
"area",
"category",
"instance",
"by",
"category",
"name",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/manager.php#L369-L375
|
215,249
|
moodle/moodle
|
search/classes/manager.php
|
manager.get_search_area_categories
|
public static function get_search_area_categories() {
if (!isset(static::$searchareacategories)) {
$categories = self::get_core_search_area_categories();
// Go through all existing search areas and get categories they are assigned to.
$areacategories = [];
foreach (self::get_search_areas_list() as $searcharea) {
foreach ($searcharea->get_category_names() as $categoryname) {
if (!key_exists($categoryname, $areacategories)) {
$areacategories[$categoryname] = [];
}
$areacategories[$categoryname][] = $searcharea;
}
}
// Populate core categories by areas.
foreach ($areacategories as $name => $searchareas) {
if (key_exists($name, $categories)) {
$categories[$name]->set_areas($searchareas);
} else {
throw new \coding_exception('Unknown core search area category ' . $name);
}
}
// Get additional categories.
$additionalcategories = self::get_additional_search_area_categories();
foreach ($additionalcategories as $additionalcategory) {
if (!key_exists($additionalcategory->get_name(), $categories)) {
$categories[$additionalcategory->get_name()] = $additionalcategory;
}
}
// Remove categories without areas.
foreach ($categories as $key => $category) {
if (empty($category->get_areas())) {
unset($categories[$key]);
}
}
// Sort categories by order.
uasort($categories, function($category1, $category2) {
return $category1->get_order() > $category2->get_order();
});
static::$searchareacategories = $categories;
}
return static::$searchareacategories;
}
|
php
|
public static function get_search_area_categories() {
if (!isset(static::$searchareacategories)) {
$categories = self::get_core_search_area_categories();
// Go through all existing search areas and get categories they are assigned to.
$areacategories = [];
foreach (self::get_search_areas_list() as $searcharea) {
foreach ($searcharea->get_category_names() as $categoryname) {
if (!key_exists($categoryname, $areacategories)) {
$areacategories[$categoryname] = [];
}
$areacategories[$categoryname][] = $searcharea;
}
}
// Populate core categories by areas.
foreach ($areacategories as $name => $searchareas) {
if (key_exists($name, $categories)) {
$categories[$name]->set_areas($searchareas);
} else {
throw new \coding_exception('Unknown core search area category ' . $name);
}
}
// Get additional categories.
$additionalcategories = self::get_additional_search_area_categories();
foreach ($additionalcategories as $additionalcategory) {
if (!key_exists($additionalcategory->get_name(), $categories)) {
$categories[$additionalcategory->get_name()] = $additionalcategory;
}
}
// Remove categories without areas.
foreach ($categories as $key => $category) {
if (empty($category->get_areas())) {
unset($categories[$key]);
}
}
// Sort categories by order.
uasort($categories, function($category1, $category2) {
return $category1->get_order() > $category2->get_order();
});
static::$searchareacategories = $categories;
}
return static::$searchareacategories;
}
|
[
"public",
"static",
"function",
"get_search_area_categories",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"searchareacategories",
")",
")",
"{",
"$",
"categories",
"=",
"self",
"::",
"get_core_search_area_categories",
"(",
")",
";",
"// Go through all existing search areas and get categories they are assigned to.",
"$",
"areacategories",
"=",
"[",
"]",
";",
"foreach",
"(",
"self",
"::",
"get_search_areas_list",
"(",
")",
"as",
"$",
"searcharea",
")",
"{",
"foreach",
"(",
"$",
"searcharea",
"->",
"get_category_names",
"(",
")",
"as",
"$",
"categoryname",
")",
"{",
"if",
"(",
"!",
"key_exists",
"(",
"$",
"categoryname",
",",
"$",
"areacategories",
")",
")",
"{",
"$",
"areacategories",
"[",
"$",
"categoryname",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"areacategories",
"[",
"$",
"categoryname",
"]",
"[",
"]",
"=",
"$",
"searcharea",
";",
"}",
"}",
"// Populate core categories by areas.",
"foreach",
"(",
"$",
"areacategories",
"as",
"$",
"name",
"=>",
"$",
"searchareas",
")",
"{",
"if",
"(",
"key_exists",
"(",
"$",
"name",
",",
"$",
"categories",
")",
")",
"{",
"$",
"categories",
"[",
"$",
"name",
"]",
"->",
"set_areas",
"(",
"$",
"searchareas",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Unknown core search area category '",
".",
"$",
"name",
")",
";",
"}",
"}",
"// Get additional categories.",
"$",
"additionalcategories",
"=",
"self",
"::",
"get_additional_search_area_categories",
"(",
")",
";",
"foreach",
"(",
"$",
"additionalcategories",
"as",
"$",
"additionalcategory",
")",
"{",
"if",
"(",
"!",
"key_exists",
"(",
"$",
"additionalcategory",
"->",
"get_name",
"(",
")",
",",
"$",
"categories",
")",
")",
"{",
"$",
"categories",
"[",
"$",
"additionalcategory",
"->",
"get_name",
"(",
")",
"]",
"=",
"$",
"additionalcategory",
";",
"}",
"}",
"// Remove categories without areas.",
"foreach",
"(",
"$",
"categories",
"as",
"$",
"key",
"=>",
"$",
"category",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"category",
"->",
"get_areas",
"(",
")",
")",
")",
"{",
"unset",
"(",
"$",
"categories",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"// Sort categories by order.",
"uasort",
"(",
"$",
"categories",
",",
"function",
"(",
"$",
"category1",
",",
"$",
"category2",
")",
"{",
"return",
"$",
"category1",
"->",
"get_order",
"(",
")",
">",
"$",
"category2",
"->",
"get_order",
"(",
")",
";",
"}",
")",
";",
"static",
"::",
"$",
"searchareacategories",
"=",
"$",
"categories",
";",
"}",
"return",
"static",
"::",
"$",
"searchareacategories",
";",
"}"
] |
Return a list of existing search area categories.
@return \core_search\area_category[]
|
[
"Return",
"a",
"list",
"of",
"existing",
"search",
"area",
"categories",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/manager.php#L382-L431
|
215,250
|
moodle/moodle
|
search/classes/manager.php
|
manager.get_core_search_area_categories
|
protected static function get_core_search_area_categories() {
$categories = [];
$categories[self::SEARCH_AREA_CATEGORY_ALL] = new area_category(
self::SEARCH_AREA_CATEGORY_ALL,
get_string('core-all', 'search'),
0,
self::get_search_areas_list(true)
);
$categories[self::SEARCH_AREA_CATEGORY_COURSE_CONTENT] = new area_category(
self::SEARCH_AREA_CATEGORY_COURSE_CONTENT,
get_string('core-course-content', 'search'),
1
);
$categories[self::SEARCH_AREA_CATEGORY_COURSES] = new area_category(
self::SEARCH_AREA_CATEGORY_COURSES,
get_string('core-courses', 'search'),
2
);
$categories[self::SEARCH_AREA_CATEGORY_USERS] = new area_category(
self::SEARCH_AREA_CATEGORY_USERS,
get_string('core-users', 'search'),
3
);
$categories[self::SEARCH_AREA_CATEGORY_OTHER] = new area_category(
self::SEARCH_AREA_CATEGORY_OTHER,
get_string('core-other', 'search'),
4
);
return $categories;
}
|
php
|
protected static function get_core_search_area_categories() {
$categories = [];
$categories[self::SEARCH_AREA_CATEGORY_ALL] = new area_category(
self::SEARCH_AREA_CATEGORY_ALL,
get_string('core-all', 'search'),
0,
self::get_search_areas_list(true)
);
$categories[self::SEARCH_AREA_CATEGORY_COURSE_CONTENT] = new area_category(
self::SEARCH_AREA_CATEGORY_COURSE_CONTENT,
get_string('core-course-content', 'search'),
1
);
$categories[self::SEARCH_AREA_CATEGORY_COURSES] = new area_category(
self::SEARCH_AREA_CATEGORY_COURSES,
get_string('core-courses', 'search'),
2
);
$categories[self::SEARCH_AREA_CATEGORY_USERS] = new area_category(
self::SEARCH_AREA_CATEGORY_USERS,
get_string('core-users', 'search'),
3
);
$categories[self::SEARCH_AREA_CATEGORY_OTHER] = new area_category(
self::SEARCH_AREA_CATEGORY_OTHER,
get_string('core-other', 'search'),
4
);
return $categories;
}
|
[
"protected",
"static",
"function",
"get_core_search_area_categories",
"(",
")",
"{",
"$",
"categories",
"=",
"[",
"]",
";",
"$",
"categories",
"[",
"self",
"::",
"SEARCH_AREA_CATEGORY_ALL",
"]",
"=",
"new",
"area_category",
"(",
"self",
"::",
"SEARCH_AREA_CATEGORY_ALL",
",",
"get_string",
"(",
"'core-all'",
",",
"'search'",
")",
",",
"0",
",",
"self",
"::",
"get_search_areas_list",
"(",
"true",
")",
")",
";",
"$",
"categories",
"[",
"self",
"::",
"SEARCH_AREA_CATEGORY_COURSE_CONTENT",
"]",
"=",
"new",
"area_category",
"(",
"self",
"::",
"SEARCH_AREA_CATEGORY_COURSE_CONTENT",
",",
"get_string",
"(",
"'core-course-content'",
",",
"'search'",
")",
",",
"1",
")",
";",
"$",
"categories",
"[",
"self",
"::",
"SEARCH_AREA_CATEGORY_COURSES",
"]",
"=",
"new",
"area_category",
"(",
"self",
"::",
"SEARCH_AREA_CATEGORY_COURSES",
",",
"get_string",
"(",
"'core-courses'",
",",
"'search'",
")",
",",
"2",
")",
";",
"$",
"categories",
"[",
"self",
"::",
"SEARCH_AREA_CATEGORY_USERS",
"]",
"=",
"new",
"area_category",
"(",
"self",
"::",
"SEARCH_AREA_CATEGORY_USERS",
",",
"get_string",
"(",
"'core-users'",
",",
"'search'",
")",
",",
"3",
")",
";",
"$",
"categories",
"[",
"self",
"::",
"SEARCH_AREA_CATEGORY_OTHER",
"]",
"=",
"new",
"area_category",
"(",
"self",
"::",
"SEARCH_AREA_CATEGORY_OTHER",
",",
"get_string",
"(",
"'core-other'",
",",
"'search'",
")",
",",
"4",
")",
";",
"return",
"$",
"categories",
";",
"}"
] |
Get list of core search area categories.
@return \core_search\area_category[]
|
[
"Get",
"list",
"of",
"core",
"search",
"area",
"categories",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/manager.php#L438-L473
|
215,251
|
moodle/moodle
|
search/classes/manager.php
|
manager.get_additional_search_area_categories
|
protected static function get_additional_search_area_categories() {
$additionalcategories = [];
// Allow plugins to add custom search area categories.
if ($pluginsfunction = get_plugins_with_function('search_area_categories')) {
foreach ($pluginsfunction as $plugintype => $plugins) {
foreach ($plugins as $pluginfunction) {
$plugincategories = $pluginfunction();
// We're expecting a list of valid area categories.
if (is_array($plugincategories)) {
foreach ($plugincategories as $plugincategory) {
if (self::is_valid_area_category($plugincategory)) {
$additionalcategories[] = $plugincategory;
} else {
throw new \coding_exception('Invalid search area category!');
}
}
} else {
throw new \coding_exception($pluginfunction . ' should return a list of search area categories!');
}
}
}
}
return $additionalcategories;
}
|
php
|
protected static function get_additional_search_area_categories() {
$additionalcategories = [];
// Allow plugins to add custom search area categories.
if ($pluginsfunction = get_plugins_with_function('search_area_categories')) {
foreach ($pluginsfunction as $plugintype => $plugins) {
foreach ($plugins as $pluginfunction) {
$plugincategories = $pluginfunction();
// We're expecting a list of valid area categories.
if (is_array($plugincategories)) {
foreach ($plugincategories as $plugincategory) {
if (self::is_valid_area_category($plugincategory)) {
$additionalcategories[] = $plugincategory;
} else {
throw new \coding_exception('Invalid search area category!');
}
}
} else {
throw new \coding_exception($pluginfunction . ' should return a list of search area categories!');
}
}
}
}
return $additionalcategories;
}
|
[
"protected",
"static",
"function",
"get_additional_search_area_categories",
"(",
")",
"{",
"$",
"additionalcategories",
"=",
"[",
"]",
";",
"// Allow plugins to add custom search area categories.",
"if",
"(",
"$",
"pluginsfunction",
"=",
"get_plugins_with_function",
"(",
"'search_area_categories'",
")",
")",
"{",
"foreach",
"(",
"$",
"pluginsfunction",
"as",
"$",
"plugintype",
"=>",
"$",
"plugins",
")",
"{",
"foreach",
"(",
"$",
"plugins",
"as",
"$",
"pluginfunction",
")",
"{",
"$",
"plugincategories",
"=",
"$",
"pluginfunction",
"(",
")",
";",
"// We're expecting a list of valid area categories.",
"if",
"(",
"is_array",
"(",
"$",
"plugincategories",
")",
")",
"{",
"foreach",
"(",
"$",
"plugincategories",
"as",
"$",
"plugincategory",
")",
"{",
"if",
"(",
"self",
"::",
"is_valid_area_category",
"(",
"$",
"plugincategory",
")",
")",
"{",
"$",
"additionalcategories",
"[",
"]",
"=",
"$",
"plugincategory",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Invalid search area category!'",
")",
";",
"}",
"}",
"}",
"else",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"$",
"pluginfunction",
".",
"' should return a list of search area categories!'",
")",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"additionalcategories",
";",
"}"
] |
Gets a list of additional search area categories.
@return \core_search\area_category[]
|
[
"Gets",
"a",
"list",
"of",
"additional",
"search",
"area",
"categories",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/manager.php#L480-L505
|
215,252
|
moodle/moodle
|
search/classes/manager.php
|
manager.clear_static
|
public static function clear_static() {
static::$enabledsearchareas = null;
static::$allsearchareas = null;
static::$instance = null;
static::$searchareacategories = null;
base_block::clear_static();
engine::clear_users_cache();
}
|
php
|
public static function clear_static() {
static::$enabledsearchareas = null;
static::$allsearchareas = null;
static::$instance = null;
static::$searchareacategories = null;
base_block::clear_static();
engine::clear_users_cache();
}
|
[
"public",
"static",
"function",
"clear_static",
"(",
")",
"{",
"static",
"::",
"$",
"enabledsearchareas",
"=",
"null",
";",
"static",
"::",
"$",
"allsearchareas",
"=",
"null",
";",
"static",
"::",
"$",
"instance",
"=",
"null",
";",
"static",
"::",
"$",
"searchareacategories",
"=",
"null",
";",
"base_block",
"::",
"clear_static",
"(",
")",
";",
"engine",
"::",
"clear_users_cache",
"(",
")",
";",
"}"
] |
Clears all static caches.
@return void
|
[
"Clears",
"all",
"static",
"caches",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/manager.php#L523-L532
|
215,253
|
moodle/moodle
|
search/classes/manager.php
|
manager.parse_areaid
|
public static function parse_areaid($areaid) {
$parts = self::extract_areaid_parts($areaid);
if (empty($parts[1])) {
throw new \coding_exception('Trying to parse invalid search area id ' . $areaid);
}
$component = $parts[0];
$area = $parts[1];
if (strpos($component, 'core') === 0) {
$plugin = 'core_search';
$configprefix = str_replace('-', '_', $areaid);
} else {
$plugin = $component;
$configprefix = 'search_' . $area;
}
return [$plugin, $configprefix];
}
|
php
|
public static function parse_areaid($areaid) {
$parts = self::extract_areaid_parts($areaid);
if (empty($parts[1])) {
throw new \coding_exception('Trying to parse invalid search area id ' . $areaid);
}
$component = $parts[0];
$area = $parts[1];
if (strpos($component, 'core') === 0) {
$plugin = 'core_search';
$configprefix = str_replace('-', '_', $areaid);
} else {
$plugin = $component;
$configprefix = 'search_' . $area;
}
return [$plugin, $configprefix];
}
|
[
"public",
"static",
"function",
"parse_areaid",
"(",
"$",
"areaid",
")",
"{",
"$",
"parts",
"=",
"self",
"::",
"extract_areaid_parts",
"(",
"$",
"areaid",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Trying to parse invalid search area id '",
".",
"$",
"areaid",
")",
";",
"}",
"$",
"component",
"=",
"$",
"parts",
"[",
"0",
"]",
";",
"$",
"area",
"=",
"$",
"parts",
"[",
"1",
"]",
";",
"if",
"(",
"strpos",
"(",
"$",
"component",
",",
"'core'",
")",
"===",
"0",
")",
"{",
"$",
"plugin",
"=",
"'core_search'",
";",
"$",
"configprefix",
"=",
"str_replace",
"(",
"'-'",
",",
"'_'",
",",
"$",
"areaid",
")",
";",
"}",
"else",
"{",
"$",
"plugin",
"=",
"$",
"component",
";",
"$",
"configprefix",
"=",
"'search_'",
".",
"$",
"area",
";",
"}",
"return",
"[",
"$",
"plugin",
",",
"$",
"configprefix",
"]",
";",
"}"
] |
Parse a search area id and get plugin name and config name prefix from it.
@param string $areaid Search area id.
@return array Where the first element is a plugin name and the second is config names prefix.
|
[
"Parse",
"a",
"search",
"area",
"id",
"and",
"get",
"plugin",
"name",
"and",
"config",
"name",
"prefix",
"from",
"it",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/manager.php#L564-L583
|
215,254
|
moodle/moodle
|
search/classes/manager.php
|
manager.paged_search
|
public function paged_search(\stdClass $formdata, $pagenum) {
$out = new \stdClass();
if (self::is_search_area_categories_enabled() && !empty($formdata->cat)) {
$cat = self::get_search_area_category_by_name($formdata->cat);
if (empty($formdata->areaids)) {
$formdata->areaids = array_keys($cat->get_areas());
} else {
foreach ($formdata->areaids as $key => $areaid) {
if (!key_exists($areaid, $cat->get_areas())) {
unset($formdata->areaids[$key]);
}
}
}
}
$perpage = static::DISPLAY_RESULTS_PER_PAGE;
// Make sure we only allow request up to max page.
$pagenum = min($pagenum, (static::MAX_RESULTS / $perpage) - 1);
// Calculate the first and last document number for the current page, 1 based.
$mindoc = ($pagenum * $perpage) + 1;
$maxdoc = ($pagenum + 1) * $perpage;
// Get engine documents, up to max.
$docs = $this->search($formdata, $maxdoc);
$resultcount = count($docs);
if ($resultcount < $maxdoc) {
// This means it couldn't give us results to max, so the count must be the max.
$out->totalcount = $resultcount;
} else {
// Get the possible count reported by engine, and limit to our max.
$out->totalcount = $this->engine->get_query_total_count();
$out->totalcount = min($out->totalcount, static::MAX_RESULTS);
}
// Determine the actual page.
if ($resultcount < $mindoc) {
// We couldn't get the min docs for this page, so determine what page we can get.
$out->actualpage = floor(($resultcount - 1) / $perpage);
} else {
$out->actualpage = $pagenum;
}
// Split the results to only return the page.
$out->results = array_slice($docs, $out->actualpage * $perpage, $perpage, true);
return $out;
}
|
php
|
public function paged_search(\stdClass $formdata, $pagenum) {
$out = new \stdClass();
if (self::is_search_area_categories_enabled() && !empty($formdata->cat)) {
$cat = self::get_search_area_category_by_name($formdata->cat);
if (empty($formdata->areaids)) {
$formdata->areaids = array_keys($cat->get_areas());
} else {
foreach ($formdata->areaids as $key => $areaid) {
if (!key_exists($areaid, $cat->get_areas())) {
unset($formdata->areaids[$key]);
}
}
}
}
$perpage = static::DISPLAY_RESULTS_PER_PAGE;
// Make sure we only allow request up to max page.
$pagenum = min($pagenum, (static::MAX_RESULTS / $perpage) - 1);
// Calculate the first and last document number for the current page, 1 based.
$mindoc = ($pagenum * $perpage) + 1;
$maxdoc = ($pagenum + 1) * $perpage;
// Get engine documents, up to max.
$docs = $this->search($formdata, $maxdoc);
$resultcount = count($docs);
if ($resultcount < $maxdoc) {
// This means it couldn't give us results to max, so the count must be the max.
$out->totalcount = $resultcount;
} else {
// Get the possible count reported by engine, and limit to our max.
$out->totalcount = $this->engine->get_query_total_count();
$out->totalcount = min($out->totalcount, static::MAX_RESULTS);
}
// Determine the actual page.
if ($resultcount < $mindoc) {
// We couldn't get the min docs for this page, so determine what page we can get.
$out->actualpage = floor(($resultcount - 1) / $perpage);
} else {
$out->actualpage = $pagenum;
}
// Split the results to only return the page.
$out->results = array_slice($docs, $out->actualpage * $perpage, $perpage, true);
return $out;
}
|
[
"public",
"function",
"paged_search",
"(",
"\\",
"stdClass",
"$",
"formdata",
",",
"$",
"pagenum",
")",
"{",
"$",
"out",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"if",
"(",
"self",
"::",
"is_search_area_categories_enabled",
"(",
")",
"&&",
"!",
"empty",
"(",
"$",
"formdata",
"->",
"cat",
")",
")",
"{",
"$",
"cat",
"=",
"self",
"::",
"get_search_area_category_by_name",
"(",
"$",
"formdata",
"->",
"cat",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"formdata",
"->",
"areaids",
")",
")",
"{",
"$",
"formdata",
"->",
"areaids",
"=",
"array_keys",
"(",
"$",
"cat",
"->",
"get_areas",
"(",
")",
")",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"formdata",
"->",
"areaids",
"as",
"$",
"key",
"=>",
"$",
"areaid",
")",
"{",
"if",
"(",
"!",
"key_exists",
"(",
"$",
"areaid",
",",
"$",
"cat",
"->",
"get_areas",
"(",
")",
")",
")",
"{",
"unset",
"(",
"$",
"formdata",
"->",
"areaids",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"}",
"}",
"$",
"perpage",
"=",
"static",
"::",
"DISPLAY_RESULTS_PER_PAGE",
";",
"// Make sure we only allow request up to max page.",
"$",
"pagenum",
"=",
"min",
"(",
"$",
"pagenum",
",",
"(",
"static",
"::",
"MAX_RESULTS",
"/",
"$",
"perpage",
")",
"-",
"1",
")",
";",
"// Calculate the first and last document number for the current page, 1 based.",
"$",
"mindoc",
"=",
"(",
"$",
"pagenum",
"*",
"$",
"perpage",
")",
"+",
"1",
";",
"$",
"maxdoc",
"=",
"(",
"$",
"pagenum",
"+",
"1",
")",
"*",
"$",
"perpage",
";",
"// Get engine documents, up to max.",
"$",
"docs",
"=",
"$",
"this",
"->",
"search",
"(",
"$",
"formdata",
",",
"$",
"maxdoc",
")",
";",
"$",
"resultcount",
"=",
"count",
"(",
"$",
"docs",
")",
";",
"if",
"(",
"$",
"resultcount",
"<",
"$",
"maxdoc",
")",
"{",
"// This means it couldn't give us results to max, so the count must be the max.",
"$",
"out",
"->",
"totalcount",
"=",
"$",
"resultcount",
";",
"}",
"else",
"{",
"// Get the possible count reported by engine, and limit to our max.",
"$",
"out",
"->",
"totalcount",
"=",
"$",
"this",
"->",
"engine",
"->",
"get_query_total_count",
"(",
")",
";",
"$",
"out",
"->",
"totalcount",
"=",
"min",
"(",
"$",
"out",
"->",
"totalcount",
",",
"static",
"::",
"MAX_RESULTS",
")",
";",
"}",
"// Determine the actual page.",
"if",
"(",
"$",
"resultcount",
"<",
"$",
"mindoc",
")",
"{",
"// We couldn't get the min docs for this page, so determine what page we can get.",
"$",
"out",
"->",
"actualpage",
"=",
"floor",
"(",
"(",
"$",
"resultcount",
"-",
"1",
")",
"/",
"$",
"perpage",
")",
";",
"}",
"else",
"{",
"$",
"out",
"->",
"actualpage",
"=",
"$",
"pagenum",
";",
"}",
"// Split the results to only return the page.",
"$",
"out",
"->",
"results",
"=",
"array_slice",
"(",
"$",
"docs",
",",
"$",
"out",
"->",
"actualpage",
"*",
"$",
"perpage",
",",
"$",
"perpage",
",",
"true",
")",
";",
"return",
"$",
"out",
";",
"}"
] |
Returns requested page of documents plus additional information for paging.
This function does not perform any kind of security checking for access, the caller code
should check that the current user have moodle/search:query capability.
If a page is requested that is beyond the last result, the last valid page is returned in
results, and actualpage indicates which page was returned.
@param stdClass $formdata
@param int $pagenum The 0 based page number.
@return object An object with 3 properties:
results => An array of \core_search\documents for the actual page.
totalcount => Number of records that are possibly available, to base paging on.
actualpage => The actual page returned.
|
[
"Returns",
"requested",
"page",
"of",
"documents",
"plus",
"additional",
"information",
"for",
"paging",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/manager.php#L855-L905
|
215,255
|
moodle/moodle
|
search/classes/manager.php
|
manager.search
|
public function search(\stdClass $formdata, $limit = 0) {
// For Behat testing, the search results can be faked using a special step.
if (defined('BEHAT_SITE_RUNNING')) {
$fakeresult = get_config('core_search', 'behat_fakeresult');
if ($fakeresult) {
// Clear config setting.
unset_config('core_search', 'behat_fakeresult');
// Check query matches expected value.
$details = json_decode($fakeresult);
if ($formdata->q !== $details->query) {
throw new \coding_exception('Unexpected search query: ' . $formdata->q);
}
// Create search documents from the JSON data.
$docs = [];
foreach ($details->results as $result) {
$doc = new \core_search\document($result->itemid, $result->componentname,
$result->areaname);
foreach ((array)$result->fields as $field => $value) {
$doc->set($field, $value);
}
foreach ((array)$result->extrafields as $field => $value) {
$doc->set_extra($field, $value);
}
$area = $this->get_search_area($doc->get('areaid'));
$doc->set_doc_url($area->get_doc_url($doc));
$doc->set_context_url($area->get_context_url($doc));
$docs[] = $doc;
}
return $docs;
}
}
$limitcourseids = $this->build_limitcourseids($formdata);
$limitcontextids = false;
if (!empty($formdata->contextids)) {
$limitcontextids = $formdata->contextids;
}
// Clears previous query errors.
$this->engine->clear_query_error();
$contextinfo = $this->get_areas_user_accesses($limitcourseids, $limitcontextids);
if (!$contextinfo->everything && !$contextinfo->usercontexts) {
// User can not access any context.
$docs = array();
} else {
// If engine does not support groups, remove group information from the context info -
// use the old format instead (true = admin, array = user contexts).
if (!$this->engine->supports_group_filtering()) {
$contextinfo = $contextinfo->everything ? true : $contextinfo->usercontexts;
}
// Execute the actual query.
$docs = $this->engine->execute_query($formdata, $contextinfo, $limit);
}
return $docs;
}
|
php
|
public function search(\stdClass $formdata, $limit = 0) {
// For Behat testing, the search results can be faked using a special step.
if (defined('BEHAT_SITE_RUNNING')) {
$fakeresult = get_config('core_search', 'behat_fakeresult');
if ($fakeresult) {
// Clear config setting.
unset_config('core_search', 'behat_fakeresult');
// Check query matches expected value.
$details = json_decode($fakeresult);
if ($formdata->q !== $details->query) {
throw new \coding_exception('Unexpected search query: ' . $formdata->q);
}
// Create search documents from the JSON data.
$docs = [];
foreach ($details->results as $result) {
$doc = new \core_search\document($result->itemid, $result->componentname,
$result->areaname);
foreach ((array)$result->fields as $field => $value) {
$doc->set($field, $value);
}
foreach ((array)$result->extrafields as $field => $value) {
$doc->set_extra($field, $value);
}
$area = $this->get_search_area($doc->get('areaid'));
$doc->set_doc_url($area->get_doc_url($doc));
$doc->set_context_url($area->get_context_url($doc));
$docs[] = $doc;
}
return $docs;
}
}
$limitcourseids = $this->build_limitcourseids($formdata);
$limitcontextids = false;
if (!empty($formdata->contextids)) {
$limitcontextids = $formdata->contextids;
}
// Clears previous query errors.
$this->engine->clear_query_error();
$contextinfo = $this->get_areas_user_accesses($limitcourseids, $limitcontextids);
if (!$contextinfo->everything && !$contextinfo->usercontexts) {
// User can not access any context.
$docs = array();
} else {
// If engine does not support groups, remove group information from the context info -
// use the old format instead (true = admin, array = user contexts).
if (!$this->engine->supports_group_filtering()) {
$contextinfo = $contextinfo->everything ? true : $contextinfo->usercontexts;
}
// Execute the actual query.
$docs = $this->engine->execute_query($formdata, $contextinfo, $limit);
}
return $docs;
}
|
[
"public",
"function",
"search",
"(",
"\\",
"stdClass",
"$",
"formdata",
",",
"$",
"limit",
"=",
"0",
")",
"{",
"// For Behat testing, the search results can be faked using a special step.",
"if",
"(",
"defined",
"(",
"'BEHAT_SITE_RUNNING'",
")",
")",
"{",
"$",
"fakeresult",
"=",
"get_config",
"(",
"'core_search'",
",",
"'behat_fakeresult'",
")",
";",
"if",
"(",
"$",
"fakeresult",
")",
"{",
"// Clear config setting.",
"unset_config",
"(",
"'core_search'",
",",
"'behat_fakeresult'",
")",
";",
"// Check query matches expected value.",
"$",
"details",
"=",
"json_decode",
"(",
"$",
"fakeresult",
")",
";",
"if",
"(",
"$",
"formdata",
"->",
"q",
"!==",
"$",
"details",
"->",
"query",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Unexpected search query: '",
".",
"$",
"formdata",
"->",
"q",
")",
";",
"}",
"// Create search documents from the JSON data.",
"$",
"docs",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"details",
"->",
"results",
"as",
"$",
"result",
")",
"{",
"$",
"doc",
"=",
"new",
"\\",
"core_search",
"\\",
"document",
"(",
"$",
"result",
"->",
"itemid",
",",
"$",
"result",
"->",
"componentname",
",",
"$",
"result",
"->",
"areaname",
")",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"result",
"->",
"fields",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"$",
"doc",
"->",
"set",
"(",
"$",
"field",
",",
"$",
"value",
")",
";",
"}",
"foreach",
"(",
"(",
"array",
")",
"$",
"result",
"->",
"extrafields",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"$",
"doc",
"->",
"set_extra",
"(",
"$",
"field",
",",
"$",
"value",
")",
";",
"}",
"$",
"area",
"=",
"$",
"this",
"->",
"get_search_area",
"(",
"$",
"doc",
"->",
"get",
"(",
"'areaid'",
")",
")",
";",
"$",
"doc",
"->",
"set_doc_url",
"(",
"$",
"area",
"->",
"get_doc_url",
"(",
"$",
"doc",
")",
")",
";",
"$",
"doc",
"->",
"set_context_url",
"(",
"$",
"area",
"->",
"get_context_url",
"(",
"$",
"doc",
")",
")",
";",
"$",
"docs",
"[",
"]",
"=",
"$",
"doc",
";",
"}",
"return",
"$",
"docs",
";",
"}",
"}",
"$",
"limitcourseids",
"=",
"$",
"this",
"->",
"build_limitcourseids",
"(",
"$",
"formdata",
")",
";",
"$",
"limitcontextids",
"=",
"false",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"formdata",
"->",
"contextids",
")",
")",
"{",
"$",
"limitcontextids",
"=",
"$",
"formdata",
"->",
"contextids",
";",
"}",
"// Clears previous query errors.",
"$",
"this",
"->",
"engine",
"->",
"clear_query_error",
"(",
")",
";",
"$",
"contextinfo",
"=",
"$",
"this",
"->",
"get_areas_user_accesses",
"(",
"$",
"limitcourseids",
",",
"$",
"limitcontextids",
")",
";",
"if",
"(",
"!",
"$",
"contextinfo",
"->",
"everything",
"&&",
"!",
"$",
"contextinfo",
"->",
"usercontexts",
")",
"{",
"// User can not access any context.",
"$",
"docs",
"=",
"array",
"(",
")",
";",
"}",
"else",
"{",
"// If engine does not support groups, remove group information from the context info -",
"// use the old format instead (true = admin, array = user contexts).",
"if",
"(",
"!",
"$",
"this",
"->",
"engine",
"->",
"supports_group_filtering",
"(",
")",
")",
"{",
"$",
"contextinfo",
"=",
"$",
"contextinfo",
"->",
"everything",
"?",
"true",
":",
"$",
"contextinfo",
"->",
"usercontexts",
";",
"}",
"// Execute the actual query.",
"$",
"docs",
"=",
"$",
"this",
"->",
"engine",
"->",
"execute_query",
"(",
"$",
"formdata",
",",
"$",
"contextinfo",
",",
"$",
"limit",
")",
";",
"}",
"return",
"$",
"docs",
";",
"}"
] |
Returns documents from the engine based on the data provided.
This function does not perform any kind of security checking, the caller code
should check that the current user have moodle/search:query capability.
It might return the results from the cache instead.
Valid formdata options include:
- q (query text)
- courseids (optional list of course ids to restrict)
- contextids (optional list of context ids to restrict)
- context (Moodle context object for location user searched from)
- order (optional ordering, one of the types supported by the search engine e.g. 'relevance')
- userids (optional list of user ids to restrict)
@param \stdClass $formdata Query input data (usually from search form)
@param int $limit The maximum number of documents to return
@return \core_search\document[]
|
[
"Returns",
"documents",
"from",
"the",
"engine",
"based",
"on",
"the",
"data",
"provided",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/manager.php#L927-L988
|
215,256
|
moodle/moodle
|
search/classes/manager.php
|
manager.build_limitcourseids
|
protected function build_limitcourseids(\stdClass $formdata) {
$limitcourseids = false;
if (!empty($formdata->mycoursesonly)) {
$limitcourseids = array_keys($this->get_my_courses(false));
}
if (!empty($formdata->courseids)) {
if (empty($limitcourseids)) {
$limitcourseids = $formdata->courseids;
} else {
$limitcourseids = array_intersect($limitcourseids, $formdata->courseids);
}
}
return $limitcourseids;
}
|
php
|
protected function build_limitcourseids(\stdClass $formdata) {
$limitcourseids = false;
if (!empty($formdata->mycoursesonly)) {
$limitcourseids = array_keys($this->get_my_courses(false));
}
if (!empty($formdata->courseids)) {
if (empty($limitcourseids)) {
$limitcourseids = $formdata->courseids;
} else {
$limitcourseids = array_intersect($limitcourseids, $formdata->courseids);
}
}
return $limitcourseids;
}
|
[
"protected",
"function",
"build_limitcourseids",
"(",
"\\",
"stdClass",
"$",
"formdata",
")",
"{",
"$",
"limitcourseids",
"=",
"false",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"formdata",
"->",
"mycoursesonly",
")",
")",
"{",
"$",
"limitcourseids",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"get_my_courses",
"(",
"false",
")",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"formdata",
"->",
"courseids",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"limitcourseids",
")",
")",
"{",
"$",
"limitcourseids",
"=",
"$",
"formdata",
"->",
"courseids",
";",
"}",
"else",
"{",
"$",
"limitcourseids",
"=",
"array_intersect",
"(",
"$",
"limitcourseids",
",",
"$",
"formdata",
"->",
"courseids",
")",
";",
"}",
"}",
"return",
"$",
"limitcourseids",
";",
"}"
] |
Build a list of course ids to limit the search based on submitted form data.
@param \stdClass $formdata Submitted search form data.
@return array|bool
|
[
"Build",
"a",
"list",
"of",
"course",
"ids",
"to",
"limit",
"the",
"search",
"based",
"on",
"submitted",
"form",
"data",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/manager.php#L997-L1013
|
215,257
|
moodle/moodle
|
search/classes/manager.php
|
manager.reset_config
|
public function reset_config($areaid = false) {
if (!empty($areaid)) {
$searchareas = array();
if (!$searchareas[$areaid] = static::get_search_area($areaid)) {
throw new \moodle_exception('errorareanotavailable', 'search', '', $areaid);
}
} else {
// Only the enabled ones.
$searchareas = static::get_search_areas_list(true);
}
foreach ($searchareas as $searcharea) {
list($componentname, $varname) = $searcharea->get_config_var_name();
$config = $searcharea->get_config();
foreach ($config as $key => $value) {
// We reset them all but the enable/disabled one.
if ($key !== $varname . '_enabled') {
set_config($key, 0, $componentname);
}
}
}
}
|
php
|
public function reset_config($areaid = false) {
if (!empty($areaid)) {
$searchareas = array();
if (!$searchareas[$areaid] = static::get_search_area($areaid)) {
throw new \moodle_exception('errorareanotavailable', 'search', '', $areaid);
}
} else {
// Only the enabled ones.
$searchareas = static::get_search_areas_list(true);
}
foreach ($searchareas as $searcharea) {
list($componentname, $varname) = $searcharea->get_config_var_name();
$config = $searcharea->get_config();
foreach ($config as $key => $value) {
// We reset them all but the enable/disabled one.
if ($key !== $varname . '_enabled') {
set_config($key, 0, $componentname);
}
}
}
}
|
[
"public",
"function",
"reset_config",
"(",
"$",
"areaid",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"areaid",
")",
")",
"{",
"$",
"searchareas",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"$",
"searchareas",
"[",
"$",
"areaid",
"]",
"=",
"static",
"::",
"get_search_area",
"(",
"$",
"areaid",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'errorareanotavailable'",
",",
"'search'",
",",
"''",
",",
"$",
"areaid",
")",
";",
"}",
"}",
"else",
"{",
"// Only the enabled ones.",
"$",
"searchareas",
"=",
"static",
"::",
"get_search_areas_list",
"(",
"true",
")",
";",
"}",
"foreach",
"(",
"$",
"searchareas",
"as",
"$",
"searcharea",
")",
"{",
"list",
"(",
"$",
"componentname",
",",
"$",
"varname",
")",
"=",
"$",
"searcharea",
"->",
"get_config_var_name",
"(",
")",
";",
"$",
"config",
"=",
"$",
"searcharea",
"->",
"get_config",
"(",
")",
";",
"foreach",
"(",
"$",
"config",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"// We reset them all but the enable/disabled one.",
"if",
"(",
"$",
"key",
"!==",
"$",
"varname",
".",
"'_enabled'",
")",
"{",
"set_config",
"(",
"$",
"key",
",",
"0",
",",
"$",
"componentname",
")",
";",
"}",
"}",
"}",
"}"
] |
Resets areas config.
@throws \moodle_exception
@param string $areaid
@return void
|
[
"Resets",
"areas",
"config",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/manager.php#L1335-L1358
|
215,258
|
moodle/moodle
|
search/classes/manager.php
|
manager.delete_index
|
public function delete_index($areaid = false) {
if (!empty($areaid)) {
$this->engine->delete($areaid);
$this->reset_config($areaid);
} else {
$this->engine->delete();
$this->reset_config();
}
}
|
php
|
public function delete_index($areaid = false) {
if (!empty($areaid)) {
$this->engine->delete($areaid);
$this->reset_config($areaid);
} else {
$this->engine->delete();
$this->reset_config();
}
}
|
[
"public",
"function",
"delete_index",
"(",
"$",
"areaid",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"areaid",
")",
")",
"{",
"$",
"this",
"->",
"engine",
"->",
"delete",
"(",
"$",
"areaid",
")",
";",
"$",
"this",
"->",
"reset_config",
"(",
"$",
"areaid",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"engine",
"->",
"delete",
"(",
")",
";",
"$",
"this",
"->",
"reset_config",
"(",
")",
";",
"}",
"}"
] |
Deletes an area's documents or all areas documents.
@param string $areaid The area id or false for all
@return void
|
[
"Deletes",
"an",
"area",
"s",
"documents",
"or",
"all",
"areas",
"documents",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/manager.php#L1366-L1374
|
215,259
|
moodle/moodle
|
search/classes/manager.php
|
manager.get_areas_config
|
public function get_areas_config($searchareas) {
$vars = array('indexingstart', 'indexingend', 'lastindexrun', 'docsignored',
'docsprocessed', 'recordsprocessed', 'partial');
$configsettings = [];
foreach ($searchareas as $searcharea) {
$areaid = $searcharea->get_area_id();
$configsettings[$areaid] = new \stdClass();
list($componentname, $varname) = $searcharea->get_config_var_name();
if (!$searcharea->is_enabled()) {
// We delete all indexed data on disable so no info.
foreach ($vars as $var) {
$configsettings[$areaid]->{$var} = 0;
}
} else {
foreach ($vars as $var) {
$configsettings[$areaid]->{$var} = get_config($componentname, $varname .'_' . $var);
}
}
// Formatting the time.
if (!empty($configsettings[$areaid]->lastindexrun)) {
$configsettings[$areaid]->lastindexrun = userdate($configsettings[$areaid]->lastindexrun);
} else {
$configsettings[$areaid]->lastindexrun = get_string('never');
}
}
return $configsettings;
}
|
php
|
public function get_areas_config($searchareas) {
$vars = array('indexingstart', 'indexingend', 'lastindexrun', 'docsignored',
'docsprocessed', 'recordsprocessed', 'partial');
$configsettings = [];
foreach ($searchareas as $searcharea) {
$areaid = $searcharea->get_area_id();
$configsettings[$areaid] = new \stdClass();
list($componentname, $varname) = $searcharea->get_config_var_name();
if (!$searcharea->is_enabled()) {
// We delete all indexed data on disable so no info.
foreach ($vars as $var) {
$configsettings[$areaid]->{$var} = 0;
}
} else {
foreach ($vars as $var) {
$configsettings[$areaid]->{$var} = get_config($componentname, $varname .'_' . $var);
}
}
// Formatting the time.
if (!empty($configsettings[$areaid]->lastindexrun)) {
$configsettings[$areaid]->lastindexrun = userdate($configsettings[$areaid]->lastindexrun);
} else {
$configsettings[$areaid]->lastindexrun = get_string('never');
}
}
return $configsettings;
}
|
[
"public",
"function",
"get_areas_config",
"(",
"$",
"searchareas",
")",
"{",
"$",
"vars",
"=",
"array",
"(",
"'indexingstart'",
",",
"'indexingend'",
",",
"'lastindexrun'",
",",
"'docsignored'",
",",
"'docsprocessed'",
",",
"'recordsprocessed'",
",",
"'partial'",
")",
";",
"$",
"configsettings",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"searchareas",
"as",
"$",
"searcharea",
")",
"{",
"$",
"areaid",
"=",
"$",
"searcharea",
"->",
"get_area_id",
"(",
")",
";",
"$",
"configsettings",
"[",
"$",
"areaid",
"]",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"list",
"(",
"$",
"componentname",
",",
"$",
"varname",
")",
"=",
"$",
"searcharea",
"->",
"get_config_var_name",
"(",
")",
";",
"if",
"(",
"!",
"$",
"searcharea",
"->",
"is_enabled",
"(",
")",
")",
"{",
"// We delete all indexed data on disable so no info.",
"foreach",
"(",
"$",
"vars",
"as",
"$",
"var",
")",
"{",
"$",
"configsettings",
"[",
"$",
"areaid",
"]",
"->",
"{",
"$",
"var",
"}",
"=",
"0",
";",
"}",
"}",
"else",
"{",
"foreach",
"(",
"$",
"vars",
"as",
"$",
"var",
")",
"{",
"$",
"configsettings",
"[",
"$",
"areaid",
"]",
"->",
"{",
"$",
"var",
"}",
"=",
"get_config",
"(",
"$",
"componentname",
",",
"$",
"varname",
".",
"'_'",
".",
"$",
"var",
")",
";",
"}",
"}",
"// Formatting the time.",
"if",
"(",
"!",
"empty",
"(",
"$",
"configsettings",
"[",
"$",
"areaid",
"]",
"->",
"lastindexrun",
")",
")",
"{",
"$",
"configsettings",
"[",
"$",
"areaid",
"]",
"->",
"lastindexrun",
"=",
"userdate",
"(",
"$",
"configsettings",
"[",
"$",
"areaid",
"]",
"->",
"lastindexrun",
")",
";",
"}",
"else",
"{",
"$",
"configsettings",
"[",
"$",
"areaid",
"]",
"->",
"lastindexrun",
"=",
"get_string",
"(",
"'never'",
")",
";",
"}",
"}",
"return",
"$",
"configsettings",
";",
"}"
] |
Returns search areas configuration.
@param \core_search\base[] $searchareas
@return \stdClass[] $configsettings
|
[
"Returns",
"search",
"areas",
"configuration",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/manager.php#L1391-L1423
|
215,260
|
moodle/moodle
|
search/classes/manager.php
|
manager.trigger_search_results_viewed
|
public static function trigger_search_results_viewed($other) {
$event = \core\event\search_results_viewed::create([
'context' => \context_system::instance(),
'other' => $other
]);
$event->trigger();
return $event;
}
|
php
|
public static function trigger_search_results_viewed($other) {
$event = \core\event\search_results_viewed::create([
'context' => \context_system::instance(),
'other' => $other
]);
$event->trigger();
return $event;
}
|
[
"public",
"static",
"function",
"trigger_search_results_viewed",
"(",
"$",
"other",
")",
"{",
"$",
"event",
"=",
"\\",
"core",
"\\",
"event",
"\\",
"search_results_viewed",
"::",
"create",
"(",
"[",
"'context'",
"=>",
"\\",
"context_system",
"::",
"instance",
"(",
")",
",",
"'other'",
"=>",
"$",
"other",
"]",
")",
";",
"$",
"event",
"->",
"trigger",
"(",
")",
";",
"return",
"$",
"event",
";",
"}"
] |
Triggers search_results_viewed event
Other data required:
- q: The query string
- page: The page number
- title: Title filter
- areaids: Search areas filter
- courseids: Courses filter
- timestart: Time start filter
- timeend: Time end filter
@since Moodle 3.2
@param array $other Other info for the event.
@return \core\event\search_results_viewed
|
[
"Triggers",
"search_results_viewed",
"event"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/manager.php#L1441-L1449
|
215,261
|
moodle/moodle
|
search/classes/manager.php
|
manager.request_index
|
public static function request_index(\context $context, $areaid = '',
$priority = self::INDEX_PRIORITY_NORMAL) {
global $DB;
// Check through existing requests for this context or any parent context.
list ($contextsql, $contextparams) = $DB->get_in_or_equal(
$context->get_parent_context_ids(true));
$existing = $DB->get_records_select('search_index_requests',
'contextid ' . $contextsql, $contextparams, '',
'id, searcharea, partialarea, indexpriority');
foreach ($existing as $rec) {
// If we haven't started processing the existing request yet, and it covers the same
// area (or all areas) then that will be sufficient so don't add anything else.
if ($rec->partialarea === '' && ($rec->searcharea === $areaid || $rec->searcharea === '')) {
// If the existing request has the same (or higher) priority, no need to add anything.
if ($rec->indexpriority >= $priority) {
return;
}
// The existing request has lower priority. If it is exactly the same, then just
// adjust the priority of the existing request.
if ($rec->searcharea === $areaid) {
$DB->set_field('search_index_requests', 'indexpriority', $priority,
['id' => $rec->id]);
return;
}
// The existing request would cover this area but is a lower priority. We need to
// add the new request even though that means we will index part of it twice.
}
}
// No suitable existing request, so add a new one.
$newrecord = [ 'contextid' => $context->id, 'searcharea' => $areaid,
'timerequested' => (int)self::get_current_time(),
'partialarea' => '', 'partialtime' => 0,
'indexpriority' => $priority ];
$DB->insert_record('search_index_requests', $newrecord);
}
|
php
|
public static function request_index(\context $context, $areaid = '',
$priority = self::INDEX_PRIORITY_NORMAL) {
global $DB;
// Check through existing requests for this context or any parent context.
list ($contextsql, $contextparams) = $DB->get_in_or_equal(
$context->get_parent_context_ids(true));
$existing = $DB->get_records_select('search_index_requests',
'contextid ' . $contextsql, $contextparams, '',
'id, searcharea, partialarea, indexpriority');
foreach ($existing as $rec) {
// If we haven't started processing the existing request yet, and it covers the same
// area (or all areas) then that will be sufficient so don't add anything else.
if ($rec->partialarea === '' && ($rec->searcharea === $areaid || $rec->searcharea === '')) {
// If the existing request has the same (or higher) priority, no need to add anything.
if ($rec->indexpriority >= $priority) {
return;
}
// The existing request has lower priority. If it is exactly the same, then just
// adjust the priority of the existing request.
if ($rec->searcharea === $areaid) {
$DB->set_field('search_index_requests', 'indexpriority', $priority,
['id' => $rec->id]);
return;
}
// The existing request would cover this area but is a lower priority. We need to
// add the new request even though that means we will index part of it twice.
}
}
// No suitable existing request, so add a new one.
$newrecord = [ 'contextid' => $context->id, 'searcharea' => $areaid,
'timerequested' => (int)self::get_current_time(),
'partialarea' => '', 'partialtime' => 0,
'indexpriority' => $priority ];
$DB->insert_record('search_index_requests', $newrecord);
}
|
[
"public",
"static",
"function",
"request_index",
"(",
"\\",
"context",
"$",
"context",
",",
"$",
"areaid",
"=",
"''",
",",
"$",
"priority",
"=",
"self",
"::",
"INDEX_PRIORITY_NORMAL",
")",
"{",
"global",
"$",
"DB",
";",
"// Check through existing requests for this context or any parent context.",
"list",
"(",
"$",
"contextsql",
",",
"$",
"contextparams",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"context",
"->",
"get_parent_context_ids",
"(",
"true",
")",
")",
";",
"$",
"existing",
"=",
"$",
"DB",
"->",
"get_records_select",
"(",
"'search_index_requests'",
",",
"'contextid '",
".",
"$",
"contextsql",
",",
"$",
"contextparams",
",",
"''",
",",
"'id, searcharea, partialarea, indexpriority'",
")",
";",
"foreach",
"(",
"$",
"existing",
"as",
"$",
"rec",
")",
"{",
"// If we haven't started processing the existing request yet, and it covers the same",
"// area (or all areas) then that will be sufficient so don't add anything else.",
"if",
"(",
"$",
"rec",
"->",
"partialarea",
"===",
"''",
"&&",
"(",
"$",
"rec",
"->",
"searcharea",
"===",
"$",
"areaid",
"||",
"$",
"rec",
"->",
"searcharea",
"===",
"''",
")",
")",
"{",
"// If the existing request has the same (or higher) priority, no need to add anything.",
"if",
"(",
"$",
"rec",
"->",
"indexpriority",
">=",
"$",
"priority",
")",
"{",
"return",
";",
"}",
"// The existing request has lower priority. If it is exactly the same, then just",
"// adjust the priority of the existing request.",
"if",
"(",
"$",
"rec",
"->",
"searcharea",
"===",
"$",
"areaid",
")",
"{",
"$",
"DB",
"->",
"set_field",
"(",
"'search_index_requests'",
",",
"'indexpriority'",
",",
"$",
"priority",
",",
"[",
"'id'",
"=>",
"$",
"rec",
"->",
"id",
"]",
")",
";",
"return",
";",
"}",
"// The existing request would cover this area but is a lower priority. We need to",
"// add the new request even though that means we will index part of it twice.",
"}",
"}",
"// No suitable existing request, so add a new one.",
"$",
"newrecord",
"=",
"[",
"'contextid'",
"=>",
"$",
"context",
"->",
"id",
",",
"'searcharea'",
"=>",
"$",
"areaid",
",",
"'timerequested'",
"=>",
"(",
"int",
")",
"self",
"::",
"get_current_time",
"(",
")",
",",
"'partialarea'",
"=>",
"''",
",",
"'partialtime'",
"=>",
"0",
",",
"'indexpriority'",
"=>",
"$",
"priority",
"]",
";",
"$",
"DB",
"->",
"insert_record",
"(",
"'search_index_requests'",
",",
"$",
"newrecord",
")",
";",
"}"
] |
Requests that a specific context is indexed by the scheduled task. The context will be
added to a queue which is processed by the task.
This is used after a restore to ensure that restored items are indexed, even though their
modified time will be older than the latest indexed. It is also used by the 'Gradual reindex'
admin feature from the search areas screen.
@param \context $context Context to index within
@param string $areaid Area to index, '' = all areas
@param int $priority Priority (INDEX_PRIORITY_xx constant)
|
[
"Requests",
"that",
"a",
"specific",
"context",
"is",
"indexed",
"by",
"the",
"scheduled",
"task",
".",
"The",
"context",
"will",
"be",
"added",
"to",
"a",
"queue",
"which",
"is",
"processed",
"by",
"the",
"task",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/manager.php#L1477-L1513
|
215,262
|
moodle/moodle
|
search/classes/manager.php
|
manager.get_index_requests_info
|
public function get_index_requests_info() {
global $DB;
$result = new \stdClass();
$result->total = $DB->count_records('search_index_requests');
$result->topten = $DB->get_records('search_index_requests', null,
'indexpriority DESC, timerequested, contextid, searcharea',
'id, contextid, timerequested, searcharea, partialarea, partialtime, indexpriority',
0, 10);
foreach ($result->topten as $item) {
$context = \context::instance_by_id($item->contextid);
$item->contextlink = \html_writer::link($context->get_url(),
s($context->get_context_name()));
if ($item->searcharea) {
$item->areaname = $this->get_search_area($item->searcharea)->get_visible_name();
}
if ($item->partialarea) {
$item->partialareaname = $this->get_search_area($item->partialarea)->get_visible_name();
}
switch ($item->indexpriority) {
case self::INDEX_PRIORITY_REINDEXING :
$item->priorityname = get_string('priority_reindexing', 'search');
break;
case self::INDEX_PRIORITY_NORMAL :
$item->priorityname = get_string('priority_normal', 'search');
break;
}
}
// Normalise array indices.
$result->topten = array_values($result->topten);
if ($result->total > 10) {
$result->ellipsis = true;
}
return $result;
}
|
php
|
public function get_index_requests_info() {
global $DB;
$result = new \stdClass();
$result->total = $DB->count_records('search_index_requests');
$result->topten = $DB->get_records('search_index_requests', null,
'indexpriority DESC, timerequested, contextid, searcharea',
'id, contextid, timerequested, searcharea, partialarea, partialtime, indexpriority',
0, 10);
foreach ($result->topten as $item) {
$context = \context::instance_by_id($item->contextid);
$item->contextlink = \html_writer::link($context->get_url(),
s($context->get_context_name()));
if ($item->searcharea) {
$item->areaname = $this->get_search_area($item->searcharea)->get_visible_name();
}
if ($item->partialarea) {
$item->partialareaname = $this->get_search_area($item->partialarea)->get_visible_name();
}
switch ($item->indexpriority) {
case self::INDEX_PRIORITY_REINDEXING :
$item->priorityname = get_string('priority_reindexing', 'search');
break;
case self::INDEX_PRIORITY_NORMAL :
$item->priorityname = get_string('priority_normal', 'search');
break;
}
}
// Normalise array indices.
$result->topten = array_values($result->topten);
if ($result->total > 10) {
$result->ellipsis = true;
}
return $result;
}
|
[
"public",
"function",
"get_index_requests_info",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"result",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"result",
"->",
"total",
"=",
"$",
"DB",
"->",
"count_records",
"(",
"'search_index_requests'",
")",
";",
"$",
"result",
"->",
"topten",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'search_index_requests'",
",",
"null",
",",
"'indexpriority DESC, timerequested, contextid, searcharea'",
",",
"'id, contextid, timerequested, searcharea, partialarea, partialtime, indexpriority'",
",",
"0",
",",
"10",
")",
";",
"foreach",
"(",
"$",
"result",
"->",
"topten",
"as",
"$",
"item",
")",
"{",
"$",
"context",
"=",
"\\",
"context",
"::",
"instance_by_id",
"(",
"$",
"item",
"->",
"contextid",
")",
";",
"$",
"item",
"->",
"contextlink",
"=",
"\\",
"html_writer",
"::",
"link",
"(",
"$",
"context",
"->",
"get_url",
"(",
")",
",",
"s",
"(",
"$",
"context",
"->",
"get_context_name",
"(",
")",
")",
")",
";",
"if",
"(",
"$",
"item",
"->",
"searcharea",
")",
"{",
"$",
"item",
"->",
"areaname",
"=",
"$",
"this",
"->",
"get_search_area",
"(",
"$",
"item",
"->",
"searcharea",
")",
"->",
"get_visible_name",
"(",
")",
";",
"}",
"if",
"(",
"$",
"item",
"->",
"partialarea",
")",
"{",
"$",
"item",
"->",
"partialareaname",
"=",
"$",
"this",
"->",
"get_search_area",
"(",
"$",
"item",
"->",
"partialarea",
")",
"->",
"get_visible_name",
"(",
")",
";",
"}",
"switch",
"(",
"$",
"item",
"->",
"indexpriority",
")",
"{",
"case",
"self",
"::",
"INDEX_PRIORITY_REINDEXING",
":",
"$",
"item",
"->",
"priorityname",
"=",
"get_string",
"(",
"'priority_reindexing'",
",",
"'search'",
")",
";",
"break",
";",
"case",
"self",
"::",
"INDEX_PRIORITY_NORMAL",
":",
"$",
"item",
"->",
"priorityname",
"=",
"get_string",
"(",
"'priority_normal'",
",",
"'search'",
")",
";",
"break",
";",
"}",
"}",
"// Normalise array indices.",
"$",
"result",
"->",
"topten",
"=",
"array_values",
"(",
"$",
"result",
"->",
"topten",
")",
";",
"if",
"(",
"$",
"result",
"->",
"total",
">",
"10",
")",
"{",
"$",
"result",
"->",
"ellipsis",
"=",
"true",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Gets information about the request queue, in the form of a plain object suitable for passing
to a template for rendering.
@return \stdClass Information about queued index requests
|
[
"Gets",
"information",
"about",
"the",
"request",
"queue",
"in",
"the",
"form",
"of",
"a",
"plain",
"object",
"suitable",
"for",
"passing",
"to",
"a",
"template",
"for",
"rendering",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/manager.php#L1604-L1642
|
215,263
|
moodle/moodle
|
search/classes/manager.php
|
manager.get_default_area_category_name
|
public static function get_default_area_category_name() {
$default = get_config('core', 'searchdefaultcategory');
if (empty($default)) {
$default = self::SEARCH_AREA_CATEGORY_ALL;
}
if ($default == self::SEARCH_AREA_CATEGORY_ALL && self::should_hide_all_results_category()) {
$default = self::SEARCH_AREA_CATEGORY_COURSE_CONTENT;
}
return $default;
}
|
php
|
public static function get_default_area_category_name() {
$default = get_config('core', 'searchdefaultcategory');
if (empty($default)) {
$default = self::SEARCH_AREA_CATEGORY_ALL;
}
if ($default == self::SEARCH_AREA_CATEGORY_ALL && self::should_hide_all_results_category()) {
$default = self::SEARCH_AREA_CATEGORY_COURSE_CONTENT;
}
return $default;
}
|
[
"public",
"static",
"function",
"get_default_area_category_name",
"(",
")",
"{",
"$",
"default",
"=",
"get_config",
"(",
"'core'",
",",
"'searchdefaultcategory'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"default",
")",
")",
"{",
"$",
"default",
"=",
"self",
"::",
"SEARCH_AREA_CATEGORY_ALL",
";",
"}",
"if",
"(",
"$",
"default",
"==",
"self",
"::",
"SEARCH_AREA_CATEGORY_ALL",
"&&",
"self",
"::",
"should_hide_all_results_category",
"(",
")",
")",
"{",
"$",
"default",
"=",
"self",
"::",
"SEARCH_AREA_CATEGORY_COURSE_CONTENT",
";",
"}",
"return",
"$",
"default",
";",
"}"
] |
Returns default search area category name.
@return string
|
[
"Returns",
"default",
"search",
"area",
"category",
"name",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/manager.php#L1681-L1693
|
215,264
|
moodle/moodle
|
search/classes/manager.php
|
manager.get_all_courses
|
protected function get_all_courses($limitcourseids) {
global $DB;
if ($limitcourseids) {
list ($coursesql, $courseparams) = $DB->get_in_or_equal($limitcourseids);
$coursesql = 'id ' . $coursesql;
} else {
$coursesql = '';
$courseparams = [];
}
// Get courses using the same list of fields from enrol_get_my_courses.
return $DB->get_records_select('course', $coursesql, $courseparams, '',
'id, category, sortorder, shortname, fullname, idnumber, startdate, visible, ' .
'groupmode, groupmodeforce, cacherev');
}
|
php
|
protected function get_all_courses($limitcourseids) {
global $DB;
if ($limitcourseids) {
list ($coursesql, $courseparams) = $DB->get_in_or_equal($limitcourseids);
$coursesql = 'id ' . $coursesql;
} else {
$coursesql = '';
$courseparams = [];
}
// Get courses using the same list of fields from enrol_get_my_courses.
return $DB->get_records_select('course', $coursesql, $courseparams, '',
'id, category, sortorder, shortname, fullname, idnumber, startdate, visible, ' .
'groupmode, groupmodeforce, cacherev');
}
|
[
"protected",
"function",
"get_all_courses",
"(",
"$",
"limitcourseids",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"$",
"limitcourseids",
")",
"{",
"list",
"(",
"$",
"coursesql",
",",
"$",
"courseparams",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"limitcourseids",
")",
";",
"$",
"coursesql",
"=",
"'id '",
".",
"$",
"coursesql",
";",
"}",
"else",
"{",
"$",
"coursesql",
"=",
"''",
";",
"$",
"courseparams",
"=",
"[",
"]",
";",
"}",
"// Get courses using the same list of fields from enrol_get_my_courses.",
"return",
"$",
"DB",
"->",
"get_records_select",
"(",
"'course'",
",",
"$",
"coursesql",
",",
"$",
"courseparams",
",",
"''",
",",
"'id, category, sortorder, shortname, fullname, idnumber, startdate, visible, '",
".",
"'groupmode, groupmodeforce, cacherev'",
")",
";",
"}"
] |
Get a list of all courses limited by ids if required.
@param array|false $limitcourseids An array of course ids to limit the search to. False for no limiting.
@return array
|
[
"Get",
"a",
"list",
"of",
"all",
"courses",
"limited",
"by",
"ids",
"if",
"required",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/manager.php#L1701-L1716
|
215,265
|
moodle/moodle
|
search/classes/manager.php
|
manager.clean_up_non_existing_area
|
public static function clean_up_non_existing_area($areaid) {
global $DB;
if (!empty(self::get_search_area($areaid))) {
throw new \coding_exception("Area $areaid exists. Please use appropriate search area class to manipulate the data.");
}
$parts = self::parse_areaid($areaid);
$plugin = $parts[0];
$configprefix = $parts[1];
foreach (base::get_settingnames() as $settingname) {
$name = $configprefix. $settingname;
$DB->delete_records('config_plugins', ['name' => $name, 'plugin' => $plugin]);
}
$engine = self::instance()->get_engine();
$engine->delete($areaid);
}
|
php
|
public static function clean_up_non_existing_area($areaid) {
global $DB;
if (!empty(self::get_search_area($areaid))) {
throw new \coding_exception("Area $areaid exists. Please use appropriate search area class to manipulate the data.");
}
$parts = self::parse_areaid($areaid);
$plugin = $parts[0];
$configprefix = $parts[1];
foreach (base::get_settingnames() as $settingname) {
$name = $configprefix. $settingname;
$DB->delete_records('config_plugins', ['name' => $name, 'plugin' => $plugin]);
}
$engine = self::instance()->get_engine();
$engine->delete($areaid);
}
|
[
"public",
"static",
"function",
"clean_up_non_existing_area",
"(",
"$",
"areaid",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"!",
"empty",
"(",
"self",
"::",
"get_search_area",
"(",
"$",
"areaid",
")",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"\"Area $areaid exists. Please use appropriate search area class to manipulate the data.\"",
")",
";",
"}",
"$",
"parts",
"=",
"self",
"::",
"parse_areaid",
"(",
"$",
"areaid",
")",
";",
"$",
"plugin",
"=",
"$",
"parts",
"[",
"0",
"]",
";",
"$",
"configprefix",
"=",
"$",
"parts",
"[",
"1",
"]",
";",
"foreach",
"(",
"base",
"::",
"get_settingnames",
"(",
")",
"as",
"$",
"settingname",
")",
"{",
"$",
"name",
"=",
"$",
"configprefix",
".",
"$",
"settingname",
";",
"$",
"DB",
"->",
"delete_records",
"(",
"'config_plugins'",
",",
"[",
"'name'",
"=>",
"$",
"name",
",",
"'plugin'",
"=>",
"$",
"plugin",
"]",
")",
";",
"}",
"$",
"engine",
"=",
"self",
"::",
"instance",
"(",
")",
"->",
"get_engine",
"(",
")",
";",
"$",
"engine",
"->",
"delete",
"(",
"$",
"areaid",
")",
";",
"}"
] |
Cleans up non existing search area.
1. Remove all configs from {config_plugins} table.
2. Delete all related indexed documents.
@param string $areaid Search area id.
|
[
"Cleans",
"up",
"non",
"existing",
"search",
"area",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/manager.php#L1745-L1764
|
215,266
|
moodle/moodle
|
backup/moodle2/restore_section_task.class.php
|
restore_section_task.define_settings
|
protected function define_settings() {
// All the settings related to this activity will include this prefix
$settingprefix = 'section_' . $this->info->sectionid . '_';
// All these are common settings to be shared by all sections
// Define section_included (to decide if the whole task must be really executed)
$settingname = $settingprefix . 'included';
$section_included = new restore_section_included_setting($settingname, base_setting::IS_BOOLEAN, true);
if (is_number($this->info->title)) {
$label = get_string('includesection', 'backup', $this->info->title);
} elseif (empty($this->info->title)) { // Don't throw error if title is empty, gracefully continue restore.
$this->log('Section title missing in backup for section id '.$this->info->sectionid, backup::LOG_WARNING, $this->name);
$label = get_string('unnamedsection', 'backup');
} else {
$label = $this->info->title;
}
$section_included->get_ui()->set_label($label);
$this->add_setting($section_included);
// Define section_userinfo. Dependent of:
// - users root setting
// - section_included setting.
$settingname = $settingprefix . 'userinfo';
$defaultvalue = false;
if (isset($this->info->settings[$settingname]) && $this->info->settings[$settingname]) { // Only enabled when available
$defaultvalue = true;
}
$section_userinfo = new restore_section_userinfo_setting($settingname, base_setting::IS_BOOLEAN, $defaultvalue);
if (!$defaultvalue) {
// This is a bit hacky, but if there is no user data to restore, then
// we replace the standard check-box with a select menu with the
// single choice 'No', and the select menu is clever enough that if
// there is only one choice, it just displays a static string.
//
// It would probably be better design to have a special UI class
// setting_ui_checkbox_or_no, rather than this hack, but I am not
// going to do that today.
$section_userinfo->set_ui(new backup_setting_ui_select($section_userinfo, get_string('includeuserinfo','backup'),
array(0 => get_string('no'))));
} else {
$section_userinfo->get_ui()->set_label(get_string('includeuserinfo','backup'));
}
$this->add_setting($section_userinfo);
// Look for "users" root setting.
$users = $this->plan->get_setting('users');
$users->add_dependency($section_userinfo);
// Look for "section_included" section setting.
$section_included->add_dependency($section_userinfo);
}
|
php
|
protected function define_settings() {
// All the settings related to this activity will include this prefix
$settingprefix = 'section_' . $this->info->sectionid . '_';
// All these are common settings to be shared by all sections
// Define section_included (to decide if the whole task must be really executed)
$settingname = $settingprefix . 'included';
$section_included = new restore_section_included_setting($settingname, base_setting::IS_BOOLEAN, true);
if (is_number($this->info->title)) {
$label = get_string('includesection', 'backup', $this->info->title);
} elseif (empty($this->info->title)) { // Don't throw error if title is empty, gracefully continue restore.
$this->log('Section title missing in backup for section id '.$this->info->sectionid, backup::LOG_WARNING, $this->name);
$label = get_string('unnamedsection', 'backup');
} else {
$label = $this->info->title;
}
$section_included->get_ui()->set_label($label);
$this->add_setting($section_included);
// Define section_userinfo. Dependent of:
// - users root setting
// - section_included setting.
$settingname = $settingprefix . 'userinfo';
$defaultvalue = false;
if (isset($this->info->settings[$settingname]) && $this->info->settings[$settingname]) { // Only enabled when available
$defaultvalue = true;
}
$section_userinfo = new restore_section_userinfo_setting($settingname, base_setting::IS_BOOLEAN, $defaultvalue);
if (!$defaultvalue) {
// This is a bit hacky, but if there is no user data to restore, then
// we replace the standard check-box with a select menu with the
// single choice 'No', and the select menu is clever enough that if
// there is only one choice, it just displays a static string.
//
// It would probably be better design to have a special UI class
// setting_ui_checkbox_or_no, rather than this hack, but I am not
// going to do that today.
$section_userinfo->set_ui(new backup_setting_ui_select($section_userinfo, get_string('includeuserinfo','backup'),
array(0 => get_string('no'))));
} else {
$section_userinfo->get_ui()->set_label(get_string('includeuserinfo','backup'));
}
$this->add_setting($section_userinfo);
// Look for "users" root setting.
$users = $this->plan->get_setting('users');
$users->add_dependency($section_userinfo);
// Look for "section_included" section setting.
$section_included->add_dependency($section_userinfo);
}
|
[
"protected",
"function",
"define_settings",
"(",
")",
"{",
"// All the settings related to this activity will include this prefix",
"$",
"settingprefix",
"=",
"'section_'",
".",
"$",
"this",
"->",
"info",
"->",
"sectionid",
".",
"'_'",
";",
"// All these are common settings to be shared by all sections",
"// Define section_included (to decide if the whole task must be really executed)",
"$",
"settingname",
"=",
"$",
"settingprefix",
".",
"'included'",
";",
"$",
"section_included",
"=",
"new",
"restore_section_included_setting",
"(",
"$",
"settingname",
",",
"base_setting",
"::",
"IS_BOOLEAN",
",",
"true",
")",
";",
"if",
"(",
"is_number",
"(",
"$",
"this",
"->",
"info",
"->",
"title",
")",
")",
"{",
"$",
"label",
"=",
"get_string",
"(",
"'includesection'",
",",
"'backup'",
",",
"$",
"this",
"->",
"info",
"->",
"title",
")",
";",
"}",
"elseif",
"(",
"empty",
"(",
"$",
"this",
"->",
"info",
"->",
"title",
")",
")",
"{",
"// Don't throw error if title is empty, gracefully continue restore.",
"$",
"this",
"->",
"log",
"(",
"'Section title missing in backup for section id '",
".",
"$",
"this",
"->",
"info",
"->",
"sectionid",
",",
"backup",
"::",
"LOG_WARNING",
",",
"$",
"this",
"->",
"name",
")",
";",
"$",
"label",
"=",
"get_string",
"(",
"'unnamedsection'",
",",
"'backup'",
")",
";",
"}",
"else",
"{",
"$",
"label",
"=",
"$",
"this",
"->",
"info",
"->",
"title",
";",
"}",
"$",
"section_included",
"->",
"get_ui",
"(",
")",
"->",
"set_label",
"(",
"$",
"label",
")",
";",
"$",
"this",
"->",
"add_setting",
"(",
"$",
"section_included",
")",
";",
"// Define section_userinfo. Dependent of:",
"// - users root setting",
"// - section_included setting.",
"$",
"settingname",
"=",
"$",
"settingprefix",
".",
"'userinfo'",
";",
"$",
"defaultvalue",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"info",
"->",
"settings",
"[",
"$",
"settingname",
"]",
")",
"&&",
"$",
"this",
"->",
"info",
"->",
"settings",
"[",
"$",
"settingname",
"]",
")",
"{",
"// Only enabled when available",
"$",
"defaultvalue",
"=",
"true",
";",
"}",
"$",
"section_userinfo",
"=",
"new",
"restore_section_userinfo_setting",
"(",
"$",
"settingname",
",",
"base_setting",
"::",
"IS_BOOLEAN",
",",
"$",
"defaultvalue",
")",
";",
"if",
"(",
"!",
"$",
"defaultvalue",
")",
"{",
"// This is a bit hacky, but if there is no user data to restore, then",
"// we replace the standard check-box with a select menu with the",
"// single choice 'No', and the select menu is clever enough that if",
"// there is only one choice, it just displays a static string.",
"//",
"// It would probably be better design to have a special UI class",
"// setting_ui_checkbox_or_no, rather than this hack, but I am not",
"// going to do that today.",
"$",
"section_userinfo",
"->",
"set_ui",
"(",
"new",
"backup_setting_ui_select",
"(",
"$",
"section_userinfo",
",",
"get_string",
"(",
"'includeuserinfo'",
",",
"'backup'",
")",
",",
"array",
"(",
"0",
"=>",
"get_string",
"(",
"'no'",
")",
")",
")",
")",
";",
"}",
"else",
"{",
"$",
"section_userinfo",
"->",
"get_ui",
"(",
")",
"->",
"set_label",
"(",
"get_string",
"(",
"'includeuserinfo'",
",",
"'backup'",
")",
")",
";",
"}",
"$",
"this",
"->",
"add_setting",
"(",
"$",
"section_userinfo",
")",
";",
"// Look for \"users\" root setting.",
"$",
"users",
"=",
"$",
"this",
"->",
"plan",
"->",
"get_setting",
"(",
"'users'",
")",
";",
"$",
"users",
"->",
"add_dependency",
"(",
"$",
"section_userinfo",
")",
";",
"// Look for \"section_included\" section setting.",
"$",
"section_included",
"->",
"add_dependency",
"(",
"$",
"section_userinfo",
")",
";",
"}"
] |
Define the common setting that any restore section will have
|
[
"Define",
"the",
"common",
"setting",
"that",
"any",
"restore",
"section",
"will",
"have"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/moodle2/restore_section_task.class.php#L152-L206
|
215,267
|
moodle/moodle
|
grade/export/grade_export_form.php
|
grade_export_form.get_data
|
public function get_data() {
global $CFG;
$data = parent::get_data();
if ($data && $this->_customdata['multipledisplaytypes']) {
if (count(array_filter($data->display)) == 0) {
// Ensure that a value was selected as the export plugins expect at least one value.
if ($CFG->grade_export_displaytype == GRADE_DISPLAY_TYPE_LETTER) {
$data->display['letter'] = GRADE_DISPLAY_TYPE_LETTER;
} else if ($CFG->grade_export_displaytype == GRADE_DISPLAY_TYPE_PERCENTAGE) {
$data->display['percentage'] = GRADE_DISPLAY_TYPE_PERCENTAGE;
} else {
$data->display['real'] = GRADE_DISPLAY_TYPE_REAL;
}
}
}
return $data;
}
|
php
|
public function get_data() {
global $CFG;
$data = parent::get_data();
if ($data && $this->_customdata['multipledisplaytypes']) {
if (count(array_filter($data->display)) == 0) {
// Ensure that a value was selected as the export plugins expect at least one value.
if ($CFG->grade_export_displaytype == GRADE_DISPLAY_TYPE_LETTER) {
$data->display['letter'] = GRADE_DISPLAY_TYPE_LETTER;
} else if ($CFG->grade_export_displaytype == GRADE_DISPLAY_TYPE_PERCENTAGE) {
$data->display['percentage'] = GRADE_DISPLAY_TYPE_PERCENTAGE;
} else {
$data->display['real'] = GRADE_DISPLAY_TYPE_REAL;
}
}
}
return $data;
}
|
[
"public",
"function",
"get_data",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"data",
"=",
"parent",
"::",
"get_data",
"(",
")",
";",
"if",
"(",
"$",
"data",
"&&",
"$",
"this",
"->",
"_customdata",
"[",
"'multipledisplaytypes'",
"]",
")",
"{",
"if",
"(",
"count",
"(",
"array_filter",
"(",
"$",
"data",
"->",
"display",
")",
")",
"==",
"0",
")",
"{",
"// Ensure that a value was selected as the export plugins expect at least one value.",
"if",
"(",
"$",
"CFG",
"->",
"grade_export_displaytype",
"==",
"GRADE_DISPLAY_TYPE_LETTER",
")",
"{",
"$",
"data",
"->",
"display",
"[",
"'letter'",
"]",
"=",
"GRADE_DISPLAY_TYPE_LETTER",
";",
"}",
"else",
"if",
"(",
"$",
"CFG",
"->",
"grade_export_displaytype",
"==",
"GRADE_DISPLAY_TYPE_PERCENTAGE",
")",
"{",
"$",
"data",
"->",
"display",
"[",
"'percentage'",
"]",
"=",
"GRADE_DISPLAY_TYPE_PERCENTAGE",
";",
"}",
"else",
"{",
"$",
"data",
"->",
"display",
"[",
"'real'",
"]",
"=",
"GRADE_DISPLAY_TYPE_REAL",
";",
"}",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] |
Overrides the mform get_data method.
Created to force a value since the validation method does not work with multiple checkbox.
@return stdClass form data object.
|
[
"Overrides",
"the",
"mform",
"get_data",
"method",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/export/grade_export_form.php#L214-L230
|
215,268
|
moodle/moodle
|
privacy/classes/output/renderer.php
|
renderer.render_html_page
|
public function render_html_page(exported_html_page $page) {
$data = $page->export_for_template($this);
return parent::render_from_template('core_privacy/htmlpage', $data);
}
|
php
|
public function render_html_page(exported_html_page $page) {
$data = $page->export_for_template($this);
return parent::render_from_template('core_privacy/htmlpage', $data);
}
|
[
"public",
"function",
"render_html_page",
"(",
"exported_html_page",
"$",
"page",
")",
"{",
"$",
"data",
"=",
"$",
"page",
"->",
"export_for_template",
"(",
"$",
"this",
")",
";",
"return",
"parent",
"::",
"render_from_template",
"(",
"'core_privacy/htmlpage'",
",",
"$",
"data",
")",
";",
"}"
] |
Render the html page.
@param html_page $page
@return string
|
[
"Render",
"the",
"html",
"page",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/output/renderer.php#L54-L57
|
215,269
|
moodle/moodle
|
backup/moodle2/backup_plan_builder.class.php
|
backup_plan_builder.build_activity_plan
|
static protected function build_activity_plan($controller, $id) {
$plan = $controller->get_plan();
// Add the activity task, responsible for outputting
// all the module related information
try {
$plan->add_task(backup_factory::get_backup_activity_task($controller->get_format(), $id));
// For the given activity, add as many block tasks as necessary
$blockids = backup_plan_dbops::get_blockids_from_moduleid($id);
foreach ($blockids as $blockid) {
try {
$plan->add_task(backup_factory::get_backup_block_task($controller->get_format(), $blockid, $id));
} catch (backup_task_exception $e) {
$a = stdClass();
$a->mid = $id;
$a->bid = $blockid;
$controller->log(get_string('error_block_for_module_not_found', 'backup', $a), backup::LOG_WARNING);
}
}
} catch (backup_task_exception $e) {
$controller->log(get_string('error_course_module_not_found', 'backup', $id), backup::LOG_WARNING);
}
}
|
php
|
static protected function build_activity_plan($controller, $id) {
$plan = $controller->get_plan();
// Add the activity task, responsible for outputting
// all the module related information
try {
$plan->add_task(backup_factory::get_backup_activity_task($controller->get_format(), $id));
// For the given activity, add as many block tasks as necessary
$blockids = backup_plan_dbops::get_blockids_from_moduleid($id);
foreach ($blockids as $blockid) {
try {
$plan->add_task(backup_factory::get_backup_block_task($controller->get_format(), $blockid, $id));
} catch (backup_task_exception $e) {
$a = stdClass();
$a->mid = $id;
$a->bid = $blockid;
$controller->log(get_string('error_block_for_module_not_found', 'backup', $a), backup::LOG_WARNING);
}
}
} catch (backup_task_exception $e) {
$controller->log(get_string('error_course_module_not_found', 'backup', $id), backup::LOG_WARNING);
}
}
|
[
"static",
"protected",
"function",
"build_activity_plan",
"(",
"$",
"controller",
",",
"$",
"id",
")",
"{",
"$",
"plan",
"=",
"$",
"controller",
"->",
"get_plan",
"(",
")",
";",
"// Add the activity task, responsible for outputting",
"// all the module related information",
"try",
"{",
"$",
"plan",
"->",
"add_task",
"(",
"backup_factory",
"::",
"get_backup_activity_task",
"(",
"$",
"controller",
"->",
"get_format",
"(",
")",
",",
"$",
"id",
")",
")",
";",
"// For the given activity, add as many block tasks as necessary",
"$",
"blockids",
"=",
"backup_plan_dbops",
"::",
"get_blockids_from_moduleid",
"(",
"$",
"id",
")",
";",
"foreach",
"(",
"$",
"blockids",
"as",
"$",
"blockid",
")",
"{",
"try",
"{",
"$",
"plan",
"->",
"add_task",
"(",
"backup_factory",
"::",
"get_backup_block_task",
"(",
"$",
"controller",
"->",
"get_format",
"(",
")",
",",
"$",
"blockid",
",",
"$",
"id",
")",
")",
";",
"}",
"catch",
"(",
"backup_task_exception",
"$",
"e",
")",
"{",
"$",
"a",
"=",
"stdClass",
"(",
")",
";",
"$",
"a",
"->",
"mid",
"=",
"$",
"id",
";",
"$",
"a",
"->",
"bid",
"=",
"$",
"blockid",
";",
"$",
"controller",
"->",
"log",
"(",
"get_string",
"(",
"'error_block_for_module_not_found'",
",",
"'backup'",
",",
"$",
"a",
")",
",",
"backup",
"::",
"LOG_WARNING",
")",
";",
"}",
"}",
"}",
"catch",
"(",
"backup_task_exception",
"$",
"e",
")",
"{",
"$",
"controller",
"->",
"log",
"(",
"get_string",
"(",
"'error_course_module_not_found'",
",",
"'backup'",
",",
"$",
"id",
")",
",",
"backup",
"::",
"LOG_WARNING",
")",
";",
"}",
"}"
] |
Build one 1-activity backup
|
[
"Build",
"one",
"1",
"-",
"activity",
"backup"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/moodle2/backup_plan_builder.class.php#L126-L150
|
215,270
|
moodle/moodle
|
backup/moodle2/backup_plan_builder.class.php
|
backup_plan_builder.build_section_plan
|
static protected function build_section_plan($controller, $id) {
$plan = $controller->get_plan();
// Add the section task, responsible for outputting
// all the section related information
$plan->add_task(backup_factory::get_backup_section_task($controller->get_format(), $id));
// For the given section, add as many activity tasks as necessary
$coursemodules = backup_plan_dbops::get_modules_from_sectionid($id);
foreach ($coursemodules as $coursemodule) {
if (plugin_supports('mod', $coursemodule->modname, FEATURE_BACKUP_MOODLE2)) { // Check we support the format
self::build_activity_plan($controller, $coursemodule->id);
} else {
// TODO: Debug information about module not supported
}
}
}
|
php
|
static protected function build_section_plan($controller, $id) {
$plan = $controller->get_plan();
// Add the section task, responsible for outputting
// all the section related information
$plan->add_task(backup_factory::get_backup_section_task($controller->get_format(), $id));
// For the given section, add as many activity tasks as necessary
$coursemodules = backup_plan_dbops::get_modules_from_sectionid($id);
foreach ($coursemodules as $coursemodule) {
if (plugin_supports('mod', $coursemodule->modname, FEATURE_BACKUP_MOODLE2)) { // Check we support the format
self::build_activity_plan($controller, $coursemodule->id);
} else {
// TODO: Debug information about module not supported
}
}
}
|
[
"static",
"protected",
"function",
"build_section_plan",
"(",
"$",
"controller",
",",
"$",
"id",
")",
"{",
"$",
"plan",
"=",
"$",
"controller",
"->",
"get_plan",
"(",
")",
";",
"// Add the section task, responsible for outputting",
"// all the section related information",
"$",
"plan",
"->",
"add_task",
"(",
"backup_factory",
"::",
"get_backup_section_task",
"(",
"$",
"controller",
"->",
"get_format",
"(",
")",
",",
"$",
"id",
")",
")",
";",
"// For the given section, add as many activity tasks as necessary",
"$",
"coursemodules",
"=",
"backup_plan_dbops",
"::",
"get_modules_from_sectionid",
"(",
"$",
"id",
")",
";",
"foreach",
"(",
"$",
"coursemodules",
"as",
"$",
"coursemodule",
")",
"{",
"if",
"(",
"plugin_supports",
"(",
"'mod'",
",",
"$",
"coursemodule",
"->",
"modname",
",",
"FEATURE_BACKUP_MOODLE2",
")",
")",
"{",
"// Check we support the format",
"self",
"::",
"build_activity_plan",
"(",
"$",
"controller",
",",
"$",
"coursemodule",
"->",
"id",
")",
";",
"}",
"else",
"{",
"// TODO: Debug information about module not supported",
"}",
"}",
"}"
] |
Build one 1-section backup
|
[
"Build",
"one",
"1",
"-",
"section",
"backup"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/moodle2/backup_plan_builder.class.php#L155-L172
|
215,271
|
moodle/moodle
|
backup/moodle2/backup_plan_builder.class.php
|
backup_plan_builder.build_course_plan
|
static protected function build_course_plan($controller, $id) {
$plan = $controller->get_plan();
// Add the course task, responsible for outputting
// all the course related information
$plan->add_task(backup_factory::get_backup_course_task($controller->get_format(), $id));
// For the given course, add as many section tasks as necessary
$sections = backup_plan_dbops::get_sections_from_courseid($id);
foreach ($sections as $section) {
self::build_section_plan($controller, $section);
}
// For the given course, add as many block tasks as necessary
$blockids = backup_plan_dbops::get_blockids_from_courseid($id);
foreach ($blockids as $blockid) {
$plan->add_task(backup_factory::get_backup_block_task($controller->get_format(), $blockid));
}
}
|
php
|
static protected function build_course_plan($controller, $id) {
$plan = $controller->get_plan();
// Add the course task, responsible for outputting
// all the course related information
$plan->add_task(backup_factory::get_backup_course_task($controller->get_format(), $id));
// For the given course, add as many section tasks as necessary
$sections = backup_plan_dbops::get_sections_from_courseid($id);
foreach ($sections as $section) {
self::build_section_plan($controller, $section);
}
// For the given course, add as many block tasks as necessary
$blockids = backup_plan_dbops::get_blockids_from_courseid($id);
foreach ($blockids as $blockid) {
$plan->add_task(backup_factory::get_backup_block_task($controller->get_format(), $blockid));
}
}
|
[
"static",
"protected",
"function",
"build_course_plan",
"(",
"$",
"controller",
",",
"$",
"id",
")",
"{",
"$",
"plan",
"=",
"$",
"controller",
"->",
"get_plan",
"(",
")",
";",
"// Add the course task, responsible for outputting",
"// all the course related information",
"$",
"plan",
"->",
"add_task",
"(",
"backup_factory",
"::",
"get_backup_course_task",
"(",
"$",
"controller",
"->",
"get_format",
"(",
")",
",",
"$",
"id",
")",
")",
";",
"// For the given course, add as many section tasks as necessary",
"$",
"sections",
"=",
"backup_plan_dbops",
"::",
"get_sections_from_courseid",
"(",
"$",
"id",
")",
";",
"foreach",
"(",
"$",
"sections",
"as",
"$",
"section",
")",
"{",
"self",
"::",
"build_section_plan",
"(",
"$",
"controller",
",",
"$",
"section",
")",
";",
"}",
"// For the given course, add as many block tasks as necessary",
"$",
"blockids",
"=",
"backup_plan_dbops",
"::",
"get_blockids_from_courseid",
"(",
"$",
"id",
")",
";",
"foreach",
"(",
"$",
"blockids",
"as",
"$",
"blockid",
")",
"{",
"$",
"plan",
"->",
"add_task",
"(",
"backup_factory",
"::",
"get_backup_block_task",
"(",
"$",
"controller",
"->",
"get_format",
"(",
")",
",",
"$",
"blockid",
")",
")",
";",
"}",
"}"
] |
Build one 1-course backup
|
[
"Build",
"one",
"1",
"-",
"course",
"backup"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/moodle2/backup_plan_builder.class.php#L177-L196
|
215,272
|
moodle/moodle
|
lib/classes/output/inplace_editable.php
|
inplace_editable.set_type_toggle
|
public function set_type_toggle($options = null) {
if ($options === null) {
$options = array(0, 1);
}
$options = array_values($options);
$idx = array_search($this->value, $options, true);
if ($idx === false) {
throw new \coding_exception('Specified value must be one of the toggle options');
}
$nextvalue = ($idx < count($options) - 1) ? $idx + 1 : 0;
$this->type = 'toggle';
$this->options = (string)$nextvalue;
return $this;
}
|
php
|
public function set_type_toggle($options = null) {
if ($options === null) {
$options = array(0, 1);
}
$options = array_values($options);
$idx = array_search($this->value, $options, true);
if ($idx === false) {
throw new \coding_exception('Specified value must be one of the toggle options');
}
$nextvalue = ($idx < count($options) - 1) ? $idx + 1 : 0;
$this->type = 'toggle';
$this->options = (string)$nextvalue;
return $this;
}
|
[
"public",
"function",
"set_type_toggle",
"(",
"$",
"options",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"options",
"===",
"null",
")",
"{",
"$",
"options",
"=",
"array",
"(",
"0",
",",
"1",
")",
";",
"}",
"$",
"options",
"=",
"array_values",
"(",
"$",
"options",
")",
";",
"$",
"idx",
"=",
"array_search",
"(",
"$",
"this",
"->",
"value",
",",
"$",
"options",
",",
"true",
")",
";",
"if",
"(",
"$",
"idx",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Specified value must be one of the toggle options'",
")",
";",
"}",
"$",
"nextvalue",
"=",
"(",
"$",
"idx",
"<",
"count",
"(",
"$",
"options",
")",
"-",
"1",
")",
"?",
"$",
"idx",
"+",
"1",
":",
"0",
";",
"$",
"this",
"->",
"type",
"=",
"'toggle'",
";",
"$",
"this",
"->",
"options",
"=",
"(",
"string",
")",
"$",
"nextvalue",
";",
"return",
"$",
"this",
";",
"}"
] |
Sets the element type to be a toggle
For toggle element $editlabel is not used.
$displayvalue must be specified, it can have text or icons but can not contain html links.
Toggle element can have two or more options.
@param array $options toggle options as simple, non-associative array; defaults to array(0,1)
@return self
|
[
"Sets",
"the",
"element",
"type",
"to",
"be",
"a",
"toggle"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/output/inplace_editable.php#L144-L158
|
215,273
|
moodle/moodle
|
lib/classes/output/inplace_editable.php
|
inplace_editable.set_type_select
|
public function set_type_select($options) {
if (!array_key_exists($this->value, $options)) {
throw new \coding_exception('Options for select element must contain an option for the specified value');
}
if (count($options) < 2) {
$this->editable = false;
}
$this->type = 'select';
$pairedoptions = [];
foreach ($options as $key => $value) {
$pairedoptions[] = [
'key' => $key,
'value' => $value,
];
}
$this->options = json_encode($pairedoptions);
if ($this->displayvalue === null) {
$this->displayvalue = $options[$this->value];
}
return $this;
}
|
php
|
public function set_type_select($options) {
if (!array_key_exists($this->value, $options)) {
throw new \coding_exception('Options for select element must contain an option for the specified value');
}
if (count($options) < 2) {
$this->editable = false;
}
$this->type = 'select';
$pairedoptions = [];
foreach ($options as $key => $value) {
$pairedoptions[] = [
'key' => $key,
'value' => $value,
];
}
$this->options = json_encode($pairedoptions);
if ($this->displayvalue === null) {
$this->displayvalue = $options[$this->value];
}
return $this;
}
|
[
"public",
"function",
"set_type_select",
"(",
"$",
"options",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"this",
"->",
"value",
",",
"$",
"options",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Options for select element must contain an option for the specified value'",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"options",
")",
"<",
"2",
")",
"{",
"$",
"this",
"->",
"editable",
"=",
"false",
";",
"}",
"$",
"this",
"->",
"type",
"=",
"'select'",
";",
"$",
"pairedoptions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"pairedoptions",
"[",
"]",
"=",
"[",
"'key'",
"=>",
"$",
"key",
",",
"'value'",
"=>",
"$",
"value",
",",
"]",
";",
"}",
"$",
"this",
"->",
"options",
"=",
"json_encode",
"(",
"$",
"pairedoptions",
")",
";",
"if",
"(",
"$",
"this",
"->",
"displayvalue",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"displayvalue",
"=",
"$",
"options",
"[",
"$",
"this",
"->",
"value",
"]",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Sets the element type to be a dropdown
For select element specifying $displayvalue is optional, if null it will
be assumed that $displayvalue = $options[$value].
However displayvalue can still be specified if it needs icons and/or
html links.
If only one option specified, the element will not be editable.
@param array $options associative array with dropdown options
@return self
|
[
"Sets",
"the",
"element",
"type",
"to",
"be",
"a",
"dropdown"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/output/inplace_editable.php#L173-L194
|
215,274
|
moodle/moodle
|
lib/classes/output/inplace_editable.php
|
inplace_editable.set_type_autocomplete
|
public function set_type_autocomplete($options, $attributes) {
$this->type = 'autocomplete';
$pairedoptions = [];
foreach ($options as $key => $value) {
$pairedoptions[] = [
'key' => $key,
'value' => $value,
];
}
$this->options = json_encode(['options' => $pairedoptions, 'attributes' => $attributes]);
return $this;
}
|
php
|
public function set_type_autocomplete($options, $attributes) {
$this->type = 'autocomplete';
$pairedoptions = [];
foreach ($options as $key => $value) {
$pairedoptions[] = [
'key' => $key,
'value' => $value,
];
}
$this->options = json_encode(['options' => $pairedoptions, 'attributes' => $attributes]);
return $this;
}
|
[
"public",
"function",
"set_type_autocomplete",
"(",
"$",
"options",
",",
"$",
"attributes",
")",
"{",
"$",
"this",
"->",
"type",
"=",
"'autocomplete'",
";",
"$",
"pairedoptions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"pairedoptions",
"[",
"]",
"=",
"[",
"'key'",
"=>",
"$",
"key",
",",
"'value'",
"=>",
"$",
"value",
",",
"]",
";",
"}",
"$",
"this",
"->",
"options",
"=",
"json_encode",
"(",
"[",
"'options'",
"=>",
"$",
"pairedoptions",
",",
"'attributes'",
"=>",
"$",
"attributes",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Sets the element type to be an autocomplete field
@param array $options associative array with dropdown options
@param array $attributes associative array with attributes for autoselect field. See AMD module core/form-autocomplete.
@return self
|
[
"Sets",
"the",
"element",
"type",
"to",
"be",
"an",
"autocomplete",
"field"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/output/inplace_editable.php#L203-L215
|
215,275
|
moodle/moodle
|
completion/classes/edit_base_form.php
|
core_completion_edit_base_form.support_views
|
protected function support_views() {
foreach ($this->get_module_names() as $modname => $modfullname) {
if (!plugin_supports('mod', $modname, FEATURE_COMPLETION_TRACKS_VIEWS, false)) {
return false;
}
}
return true;
}
|
php
|
protected function support_views() {
foreach ($this->get_module_names() as $modname => $modfullname) {
if (!plugin_supports('mod', $modname, FEATURE_COMPLETION_TRACKS_VIEWS, false)) {
return false;
}
}
return true;
}
|
[
"protected",
"function",
"support_views",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"get_module_names",
"(",
")",
"as",
"$",
"modname",
"=>",
"$",
"modfullname",
")",
"{",
"if",
"(",
"!",
"plugin_supports",
"(",
"'mod'",
",",
"$",
"modname",
",",
"FEATURE_COMPLETION_TRACKS_VIEWS",
",",
"false",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Returns true if all selected modules support tracking view.
@return bool
|
[
"Returns",
"true",
"if",
"all",
"selected",
"modules",
"support",
"tracking",
"view",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/classes/edit_base_form.php#L58-L65
|
215,276
|
moodle/moodle
|
completion/classes/edit_base_form.php
|
core_completion_edit_base_form.support_grades
|
protected function support_grades() {
foreach ($this->get_module_names() as $modname => $modfullname) {
if (!plugin_supports('mod', $modname, FEATURE_GRADE_HAS_GRADE, false)) {
return false;
}
}
return true;
}
|
php
|
protected function support_grades() {
foreach ($this->get_module_names() as $modname => $modfullname) {
if (!plugin_supports('mod', $modname, FEATURE_GRADE_HAS_GRADE, false)) {
return false;
}
}
return true;
}
|
[
"protected",
"function",
"support_grades",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"get_module_names",
"(",
")",
"as",
"$",
"modname",
"=>",
"$",
"modfullname",
")",
"{",
"if",
"(",
"!",
"plugin_supports",
"(",
"'mod'",
",",
"$",
"modname",
",",
"FEATURE_GRADE_HAS_GRADE",
",",
"false",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Returns true if all selected modules support grading.
@return bool
|
[
"Returns",
"true",
"if",
"all",
"selected",
"modules",
"support",
"grading",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/classes/edit_base_form.php#L72-L79
|
215,277
|
moodle/moodle
|
completion/classes/edit_base_form.php
|
core_completion_edit_base_form.add_custom_completion_rules
|
protected function add_custom_completion_rules() {
$modnames = array_keys($this->get_module_names());
if (count($modnames) != 1 || !plugin_supports('mod', $modnames[0], FEATURE_COMPLETION_HAS_RULES, false)) {
return [];
}
try {
// Add completion rules from the module form to this form.
$moduleform = $this->get_module_form();
$moduleform->_form = $this->_form;
if ($customcompletionelements = $moduleform->add_completion_rules()) {
$this->hascustomrules = true;
}
return $customcompletionelements;
} catch (Exception $e) {
debugging('Could not add custom completion rule of module ' . $modnames[0] .
' to this form, this has to be fixed by the developer', DEBUG_DEVELOPER);
return [];
}
}
|
php
|
protected function add_custom_completion_rules() {
$modnames = array_keys($this->get_module_names());
if (count($modnames) != 1 || !plugin_supports('mod', $modnames[0], FEATURE_COMPLETION_HAS_RULES, false)) {
return [];
}
try {
// Add completion rules from the module form to this form.
$moduleform = $this->get_module_form();
$moduleform->_form = $this->_form;
if ($customcompletionelements = $moduleform->add_completion_rules()) {
$this->hascustomrules = true;
}
return $customcompletionelements;
} catch (Exception $e) {
debugging('Could not add custom completion rule of module ' . $modnames[0] .
' to this form, this has to be fixed by the developer', DEBUG_DEVELOPER);
return [];
}
}
|
[
"protected",
"function",
"add_custom_completion_rules",
"(",
")",
"{",
"$",
"modnames",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"get_module_names",
"(",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"modnames",
")",
"!=",
"1",
"||",
"!",
"plugin_supports",
"(",
"'mod'",
",",
"$",
"modnames",
"[",
"0",
"]",
",",
"FEATURE_COMPLETION_HAS_RULES",
",",
"false",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"try",
"{",
"// Add completion rules from the module form to this form.",
"$",
"moduleform",
"=",
"$",
"this",
"->",
"get_module_form",
"(",
")",
";",
"$",
"moduleform",
"->",
"_form",
"=",
"$",
"this",
"->",
"_form",
";",
"if",
"(",
"$",
"customcompletionelements",
"=",
"$",
"moduleform",
"->",
"add_completion_rules",
"(",
")",
")",
"{",
"$",
"this",
"->",
"hascustomrules",
"=",
"true",
";",
"}",
"return",
"$",
"customcompletionelements",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"debugging",
"(",
"'Could not add custom completion rule of module '",
".",
"$",
"modnames",
"[",
"0",
"]",
".",
"' to this form, this has to be fixed by the developer'",
",",
"DEBUG_DEVELOPER",
")",
";",
"return",
"[",
"]",
";",
"}",
"}"
] |
If all selected modules are of the same module type, adds custom completion rules from this module type
@return array
|
[
"If",
"all",
"selected",
"modules",
"are",
"of",
"the",
"same",
"module",
"type",
"adds",
"custom",
"completion",
"rules",
"from",
"this",
"module",
"type"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/classes/edit_base_form.php#L93-L112
|
215,278
|
moodle/moodle
|
lib/horde/framework/Horde/Imap/Client/Fetch/Query.php
|
Horde_Imap_Client_Fetch_Query.headerText
|
public function headerText(array $opts = array())
{
$id = isset($opts['id'])
? $opts['id']
: 0;
$this->_data[Horde_Imap_Client::FETCH_HEADERTEXT][$id] = $opts;
}
|
php
|
public function headerText(array $opts = array())
{
$id = isset($opts['id'])
? $opts['id']
: 0;
$this->_data[Horde_Imap_Client::FETCH_HEADERTEXT][$id] = $opts;
}
|
[
"public",
"function",
"headerText",
"(",
"array",
"$",
"opts",
"=",
"array",
"(",
")",
")",
"{",
"$",
"id",
"=",
"isset",
"(",
"$",
"opts",
"[",
"'id'",
"]",
")",
"?",
"$",
"opts",
"[",
"'id'",
"]",
":",
"0",
";",
"$",
"this",
"->",
"_data",
"[",
"Horde_Imap_Client",
"::",
"FETCH_HEADERTEXT",
"]",
"[",
"$",
"id",
"]",
"=",
"$",
"opts",
";",
"}"
] |
Return header text.
Header text is defined only for the base RFC 2822 message or
message/rfc822 parts.
@param array $opts The following options are available:
- id: (string) The MIME ID to obtain the header text for.
DEFAULT: The header text for the base message will be
returned.
- length: (integer) The length of the substring to return.
DEFAULT: The entire text is returned.
- peek: (boolean) If set, does not set the '\Seen' flag on the
message.
DEFAULT: The seen flag is set.
- start: (integer) If a portion of the full text is desired to be
returned, the starting position is identified here.
DEFAULT: The entire text is returned.
|
[
"Return",
"header",
"text",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Fetch/Query.php#L69-L75
|
215,279
|
moodle/moodle
|
lib/horde/framework/Horde/Imap/Client/Fetch/Query.php
|
Horde_Imap_Client_Fetch_Query.bodyText
|
public function bodyText(array $opts = array())
{
$id = isset($opts['id'])
? $opts['id']
: 0;
$this->_data[Horde_Imap_Client::FETCH_BODYTEXT][$id] = $opts;
}
|
php
|
public function bodyText(array $opts = array())
{
$id = isset($opts['id'])
? $opts['id']
: 0;
$this->_data[Horde_Imap_Client::FETCH_BODYTEXT][$id] = $opts;
}
|
[
"public",
"function",
"bodyText",
"(",
"array",
"$",
"opts",
"=",
"array",
"(",
")",
")",
"{",
"$",
"id",
"=",
"isset",
"(",
"$",
"opts",
"[",
"'id'",
"]",
")",
"?",
"$",
"opts",
"[",
"'id'",
"]",
":",
"0",
";",
"$",
"this",
"->",
"_data",
"[",
"Horde_Imap_Client",
"::",
"FETCH_BODYTEXT",
"]",
"[",
"$",
"id",
"]",
"=",
"$",
"opts",
";",
"}"
] |
Return body text.
Body text is defined only for the base RFC 2822 message or
message/rfc822 parts.
@param array $opts The following options are available:
- id: (string) The MIME ID to obtain the body text for.
DEFAULT: The body text for the entire message will be
returned.
- length: (integer) The length of the substring to return.
DEFAULT: The entire text is returned.
- peek: (boolean) If set, does not set the '\Seen' flag on the
message.
DEFAULT: The seen flag is set.
- start: (integer) If a portion of the full text is desired to be
returned, the starting position is identified here.
DEFAULT: The entire text is returned.
|
[
"Return",
"body",
"text",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Fetch/Query.php#L96-L102
|
215,280
|
moodle/moodle
|
lib/horde/framework/Horde/Imap/Client/Fetch/Query.php
|
Horde_Imap_Client_Fetch_Query.headers
|
public function headers($label, $search, array $opts = array())
{
$this->_data[Horde_Imap_Client::FETCH_HEADERS][$label] = array_merge(
$opts,
array(
'headers' => array_map('strval', $search)
)
);
}
|
php
|
public function headers($label, $search, array $opts = array())
{
$this->_data[Horde_Imap_Client::FETCH_HEADERS][$label] = array_merge(
$opts,
array(
'headers' => array_map('strval', $search)
)
);
}
|
[
"public",
"function",
"headers",
"(",
"$",
"label",
",",
"$",
"search",
",",
"array",
"$",
"opts",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"_data",
"[",
"Horde_Imap_Client",
"::",
"FETCH_HEADERS",
"]",
"[",
"$",
"label",
"]",
"=",
"array_merge",
"(",
"$",
"opts",
",",
"array",
"(",
"'headers'",
"=>",
"array_map",
"(",
"'strval'",
",",
"$",
"search",
")",
")",
")",
";",
"}"
] |
Returns RFC 2822 header text that matches a search string.
This header search work only with the base RFC 2822 message or
message/rfc822 parts.
@param string $label A unique label associated with this particular
search. This is how the results are stored.
@param array $search The search string(s) (case-insensitive).
@param array $opts The following options are available:
- cache: (boolean) If true, and 'peek' is also true, will cache
the result of this call.
DEFAULT: false
- id: (string) The MIME ID to search.
DEFAULT: The base message part
- length: (integer) The length of the substring to return.
DEFAULT: The entire text is returned.
- notsearch: (boolean) Do a 'NOT' search on the headers.
DEFAULT: false
- peek: (boolean) If set, does not set the '\Seen' flag on the
message.
DEFAULT: The seen flag is set.
- start: (integer) If a portion of the full text is desired to be
returned, the starting position is identified here.
DEFAULT: The entire text is returned.
|
[
"Returns",
"RFC",
"2822",
"header",
"text",
"that",
"matches",
"a",
"search",
"string",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Fetch/Query.php#L185-L193
|
215,281
|
moodle/moodle
|
lib/horde/framework/Horde/Imap/Client/Fetch/Query.php
|
Horde_Imap_Client_Fetch_Query.remove
|
public function remove($criteria, $key)
{
if (isset($this->_data[$criteria]) &&
is_array($this->_data[$criteria])) {
unset($this->_data[$criteria][$key]);
if (empty($this->_data[$criteria])) {
unset($this->_data[$criteria]);
}
}
}
|
php
|
public function remove($criteria, $key)
{
if (isset($this->_data[$criteria]) &&
is_array($this->_data[$criteria])) {
unset($this->_data[$criteria][$key]);
if (empty($this->_data[$criteria])) {
unset($this->_data[$criteria]);
}
}
}
|
[
"public",
"function",
"remove",
"(",
"$",
"criteria",
",",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_data",
"[",
"$",
"criteria",
"]",
")",
"&&",
"is_array",
"(",
"$",
"this",
"->",
"_data",
"[",
"$",
"criteria",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"_data",
"[",
"$",
"criteria",
"]",
"[",
"$",
"key",
"]",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_data",
"[",
"$",
"criteria",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"_data",
"[",
"$",
"criteria",
"]",
")",
";",
"}",
"}",
"}"
] |
Remove an entry under a given criteria.
@param integer $criteria Criteria ID.
@param string $key The key to remove.
|
[
"Remove",
"an",
"entry",
"under",
"a",
"given",
"criteria",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Fetch/Query.php#L280-L289
|
215,282
|
moodle/moodle
|
cache/stores/apcu/addinstanceform.php
|
cachestore_apcu_addinstance_form.configuration_definition
|
protected function configuration_definition() {
global $CFG;
$form = $this->_form;
$form->addElement('text', 'prefix', get_string('prefix', 'cachestore_apcu'),
array('maxlength' => 5, 'size' => 5));
$form->addHelpButton('prefix', 'prefix', 'cachestore_apcu');
$form->setType('prefix', PARAM_TEXT); // We set to text but we have a rule to limit to alphanumext.
$form->setDefault('prefix', $CFG->prefix);
$form->addRule('prefix', get_string('prefixinvalid', 'cachestore_apcu'), 'regex', '#^[a-zA-Z0-9\-_]+$#');
$form->addElement('header', 'apc_notice', get_string('notice', 'cachestore_apcu'));
$form->setExpanded('apc_notice');
$link = get_docs_url('Caching#APC');
$form->addElement('html', nl2br(get_string('clusternotice', 'cachestore_apcu', $link)));
}
|
php
|
protected function configuration_definition() {
global $CFG;
$form = $this->_form;
$form->addElement('text', 'prefix', get_string('prefix', 'cachestore_apcu'),
array('maxlength' => 5, 'size' => 5));
$form->addHelpButton('prefix', 'prefix', 'cachestore_apcu');
$form->setType('prefix', PARAM_TEXT); // We set to text but we have a rule to limit to alphanumext.
$form->setDefault('prefix', $CFG->prefix);
$form->addRule('prefix', get_string('prefixinvalid', 'cachestore_apcu'), 'regex', '#^[a-zA-Z0-9\-_]+$#');
$form->addElement('header', 'apc_notice', get_string('notice', 'cachestore_apcu'));
$form->setExpanded('apc_notice');
$link = get_docs_url('Caching#APC');
$form->addElement('html', nl2br(get_string('clusternotice', 'cachestore_apcu', $link)));
}
|
[
"protected",
"function",
"configuration_definition",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"_form",
";",
"$",
"form",
"->",
"addElement",
"(",
"'text'",
",",
"'prefix'",
",",
"get_string",
"(",
"'prefix'",
",",
"'cachestore_apcu'",
")",
",",
"array",
"(",
"'maxlength'",
"=>",
"5",
",",
"'size'",
"=>",
"5",
")",
")",
";",
"$",
"form",
"->",
"addHelpButton",
"(",
"'prefix'",
",",
"'prefix'",
",",
"'cachestore_apcu'",
")",
";",
"$",
"form",
"->",
"setType",
"(",
"'prefix'",
",",
"PARAM_TEXT",
")",
";",
"// We set to text but we have a rule to limit to alphanumext.",
"$",
"form",
"->",
"setDefault",
"(",
"'prefix'",
",",
"$",
"CFG",
"->",
"prefix",
")",
";",
"$",
"form",
"->",
"addRule",
"(",
"'prefix'",
",",
"get_string",
"(",
"'prefixinvalid'",
",",
"'cachestore_apcu'",
")",
",",
"'regex'",
",",
"'#^[a-zA-Z0-9\\-_]+$#'",
")",
";",
"$",
"form",
"->",
"addElement",
"(",
"'header'",
",",
"'apc_notice'",
",",
"get_string",
"(",
"'notice'",
",",
"'cachestore_apcu'",
")",
")",
";",
"$",
"form",
"->",
"setExpanded",
"(",
"'apc_notice'",
")",
";",
"$",
"link",
"=",
"get_docs_url",
"(",
"'Caching#APC'",
")",
";",
"$",
"form",
"->",
"addElement",
"(",
"'html'",
",",
"nl2br",
"(",
"get_string",
"(",
"'clusternotice'",
",",
"'cachestore_apcu'",
",",
"$",
"link",
")",
")",
")",
";",
"}"
] |
Add the desired form elements.
|
[
"Add",
"the",
"desired",
"form",
"elements",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/apcu/addinstanceform.php#L37-L50
|
215,283
|
moodle/moodle
|
cache/stores/apcu/addinstanceform.php
|
cachestore_apcu_addinstance_form.configuration_validation
|
public function configuration_validation($data, $files, array $errors) {
if (empty($errors['prefix'])) {
$factory = cache_factory::instance();
$config = $factory->create_config_instance();
foreach ($config->get_all_stores() as $store) {
if ($store['plugin'] === 'apcu') {
if (isset($store['configuration']['prefix'])) {
if ($data['prefix'] === $store['configuration']['prefix']) {
// The new store has the same prefix as an existing store, thats a problem.
$errors['prefix'] = get_string('prefixnotunique', 'cachestore_apcu');
break;
}
} else if (empty($data['prefix'])) {
// The existing store hasn't got a prefix and neither does the new store, that's a problem.
$errors['prefix'] = get_string('prefixnotunique', 'cachestore_apcu');
break;
}
}
}
}
return $errors;
}
|
php
|
public function configuration_validation($data, $files, array $errors) {
if (empty($errors['prefix'])) {
$factory = cache_factory::instance();
$config = $factory->create_config_instance();
foreach ($config->get_all_stores() as $store) {
if ($store['plugin'] === 'apcu') {
if (isset($store['configuration']['prefix'])) {
if ($data['prefix'] === $store['configuration']['prefix']) {
// The new store has the same prefix as an existing store, thats a problem.
$errors['prefix'] = get_string('prefixnotunique', 'cachestore_apcu');
break;
}
} else if (empty($data['prefix'])) {
// The existing store hasn't got a prefix and neither does the new store, that's a problem.
$errors['prefix'] = get_string('prefixnotunique', 'cachestore_apcu');
break;
}
}
}
}
return $errors;
}
|
[
"public",
"function",
"configuration_validation",
"(",
"$",
"data",
",",
"$",
"files",
",",
"array",
"$",
"errors",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"errors",
"[",
"'prefix'",
"]",
")",
")",
"{",
"$",
"factory",
"=",
"cache_factory",
"::",
"instance",
"(",
")",
";",
"$",
"config",
"=",
"$",
"factory",
"->",
"create_config_instance",
"(",
")",
";",
"foreach",
"(",
"$",
"config",
"->",
"get_all_stores",
"(",
")",
"as",
"$",
"store",
")",
"{",
"if",
"(",
"$",
"store",
"[",
"'plugin'",
"]",
"===",
"'apcu'",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"store",
"[",
"'configuration'",
"]",
"[",
"'prefix'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"data",
"[",
"'prefix'",
"]",
"===",
"$",
"store",
"[",
"'configuration'",
"]",
"[",
"'prefix'",
"]",
")",
"{",
"// The new store has the same prefix as an existing store, thats a problem.",
"$",
"errors",
"[",
"'prefix'",
"]",
"=",
"get_string",
"(",
"'prefixnotunique'",
",",
"'cachestore_apcu'",
")",
";",
"break",
";",
"}",
"}",
"else",
"if",
"(",
"empty",
"(",
"$",
"data",
"[",
"'prefix'",
"]",
")",
")",
"{",
"// The existing store hasn't got a prefix and neither does the new store, that's a problem.",
"$",
"errors",
"[",
"'prefix'",
"]",
"=",
"get_string",
"(",
"'prefixnotunique'",
",",
"'cachestore_apcu'",
")",
";",
"break",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"errors",
";",
"}"
] |
Validates the configuration data.
We need to check that prefix is unique.
@param array $data
@param array $files
@param array $errors
@return array
@throws coding_exception
|
[
"Validates",
"the",
"configuration",
"data",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/apcu/addinstanceform.php#L63-L84
|
215,284
|
moodle/moodle
|
mod/assign/feedback/editpdf/classes/renderer.php
|
assignfeedback_editpdf_renderer.render_toolbar_button
|
private function render_toolbar_button($icon, $tool, $accesskey = null, $disabled=false) {
// Build button alt text.
$alttext = new stdClass();
$alttext->tool = get_string($tool, 'assignfeedback_editpdf');
if (!empty($accesskey)) {
$alttext->shortcut = '(Alt/Shift-Alt/Ctrl-Option + ' . $accesskey . ')';
} else {
$alttext->shortcut = '';
}
$iconalt = get_string('toolbarbutton', 'assignfeedback_editpdf', $alttext);
$iconhtml = $this->image_icon($icon, $iconalt, 'assignfeedback_editpdf');
$iconparams = array('data-tool'=>$tool, 'class'=>$tool . 'button');
if ($disabled) {
$iconparams['disabled'] = 'true';
}
if (!empty($accesskey)) {
$iconparams['accesskey'] = $accesskey;
}
return html_writer::tag('button', $iconhtml, $iconparams);
}
|
php
|
private function render_toolbar_button($icon, $tool, $accesskey = null, $disabled=false) {
// Build button alt text.
$alttext = new stdClass();
$alttext->tool = get_string($tool, 'assignfeedback_editpdf');
if (!empty($accesskey)) {
$alttext->shortcut = '(Alt/Shift-Alt/Ctrl-Option + ' . $accesskey . ')';
} else {
$alttext->shortcut = '';
}
$iconalt = get_string('toolbarbutton', 'assignfeedback_editpdf', $alttext);
$iconhtml = $this->image_icon($icon, $iconalt, 'assignfeedback_editpdf');
$iconparams = array('data-tool'=>$tool, 'class'=>$tool . 'button');
if ($disabled) {
$iconparams['disabled'] = 'true';
}
if (!empty($accesskey)) {
$iconparams['accesskey'] = $accesskey;
}
return html_writer::tag('button', $iconhtml, $iconparams);
}
|
[
"private",
"function",
"render_toolbar_button",
"(",
"$",
"icon",
",",
"$",
"tool",
",",
"$",
"accesskey",
"=",
"null",
",",
"$",
"disabled",
"=",
"false",
")",
"{",
"// Build button alt text.",
"$",
"alttext",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"alttext",
"->",
"tool",
"=",
"get_string",
"(",
"$",
"tool",
",",
"'assignfeedback_editpdf'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"accesskey",
")",
")",
"{",
"$",
"alttext",
"->",
"shortcut",
"=",
"'(Alt/Shift-Alt/Ctrl-Option + '",
".",
"$",
"accesskey",
".",
"')'",
";",
"}",
"else",
"{",
"$",
"alttext",
"->",
"shortcut",
"=",
"''",
";",
"}",
"$",
"iconalt",
"=",
"get_string",
"(",
"'toolbarbutton'",
",",
"'assignfeedback_editpdf'",
",",
"$",
"alttext",
")",
";",
"$",
"iconhtml",
"=",
"$",
"this",
"->",
"image_icon",
"(",
"$",
"icon",
",",
"$",
"iconalt",
",",
"'assignfeedback_editpdf'",
")",
";",
"$",
"iconparams",
"=",
"array",
"(",
"'data-tool'",
"=>",
"$",
"tool",
",",
"'class'",
"=>",
"$",
"tool",
".",
"'button'",
")",
";",
"if",
"(",
"$",
"disabled",
")",
"{",
"$",
"iconparams",
"[",
"'disabled'",
"]",
"=",
"'true'",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"accesskey",
")",
")",
"{",
"$",
"iconparams",
"[",
"'accesskey'",
"]",
"=",
"$",
"accesskey",
";",
"}",
"return",
"html_writer",
"::",
"tag",
"(",
"'button'",
",",
"$",
"iconhtml",
",",
"$",
"iconparams",
")",
";",
"}"
] |
Render a single colour button.
@param string $icon - The key for the icon
@param string $tool - The key for the lang string.
@param string $accesskey Optional - The access key for the button.
@param bool $disabled Optional - Is this button disabled.
@return string
|
[
"Render",
"a",
"single",
"colour",
"button",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/renderer.php#L78-L100
|
215,285
|
moodle/moodle
|
mod/feedback/classes/event/course_module_viewed.php
|
course_module_viewed.create_from_record
|
public static function create_from_record($feedback, $cm, $course) {
$event = self::create(array(
'objectid' => $feedback->id,
'context' => \context_module::instance($cm->id),
'anonymous' => ($feedback->anonymous == FEEDBACK_ANONYMOUS_YES),
'other' => array(
'anonymous' => $feedback->anonymous // Deprecated.
)
));
$event->add_record_snapshot('course_modules', $cm);
$event->add_record_snapshot('course', $course);
$event->add_record_snapshot('feedback', $feedback);
return $event;
}
|
php
|
public static function create_from_record($feedback, $cm, $course) {
$event = self::create(array(
'objectid' => $feedback->id,
'context' => \context_module::instance($cm->id),
'anonymous' => ($feedback->anonymous == FEEDBACK_ANONYMOUS_YES),
'other' => array(
'anonymous' => $feedback->anonymous // Deprecated.
)
));
$event->add_record_snapshot('course_modules', $cm);
$event->add_record_snapshot('course', $course);
$event->add_record_snapshot('feedback', $feedback);
return $event;
}
|
[
"public",
"static",
"function",
"create_from_record",
"(",
"$",
"feedback",
",",
"$",
"cm",
",",
"$",
"course",
")",
"{",
"$",
"event",
"=",
"self",
"::",
"create",
"(",
"array",
"(",
"'objectid'",
"=>",
"$",
"feedback",
"->",
"id",
",",
"'context'",
"=>",
"\\",
"context_module",
"::",
"instance",
"(",
"$",
"cm",
"->",
"id",
")",
",",
"'anonymous'",
"=>",
"(",
"$",
"feedback",
"->",
"anonymous",
"==",
"FEEDBACK_ANONYMOUS_YES",
")",
",",
"'other'",
"=>",
"array",
"(",
"'anonymous'",
"=>",
"$",
"feedback",
"->",
"anonymous",
"// Deprecated.",
")",
")",
")",
";",
"$",
"event",
"->",
"add_record_snapshot",
"(",
"'course_modules'",
",",
"$",
"cm",
")",
";",
"$",
"event",
"->",
"add_record_snapshot",
"(",
"'course'",
",",
"$",
"course",
")",
";",
"$",
"event",
"->",
"add_record_snapshot",
"(",
"'feedback'",
",",
"$",
"feedback",
")",
";",
"return",
"$",
"event",
";",
"}"
] |
Creates an instance from feedback record
@param stdClass $feedback
@param cm_info|stdClass $cm
@param stdClass $course
@return course_module_viewed
|
[
"Creates",
"an",
"instance",
"from",
"feedback",
"record"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/event/course_module_viewed.php#L61-L74
|
215,286
|
moodle/moodle
|
admin/tool/behat/renderer.php
|
tool_behat_renderer.render_stepsdefinitions
|
public function render_stepsdefinitions($stepsdefinitions, $form) {
global $CFG;
require_once($CFG->libdir . '/behat/classes/behat_selectors.php');
$html = $this->generic_info();
// Form.
ob_start();
$form->display();
$html .= ob_get_contents();
ob_end_clean();
if (empty($stepsdefinitions)) {
$stepsdefinitions = get_string('nostepsdefinitions', 'tool_behat');
} else {
$stepsdefinitions = implode('', $stepsdefinitions);
// Replace text selector type arguments with a user-friendly select.
$stepsdefinitions = preg_replace_callback('/(TEXT_SELECTOR\d?_STRING)/',
function ($matches) {
return html_writer::select(behat_selectors::get_allowed_text_selectors(), uniqid());
},
$stepsdefinitions
);
// Replace selector type arguments with a user-friendly select.
$stepsdefinitions = preg_replace_callback('/(SELECTOR\d?_STRING)/',
function ($matches) {
return html_writer::select(behat_selectors::get_allowed_selectors(), uniqid());
},
$stepsdefinitions
);
// Replace simple OR options.
$regex = '#\(\?P<[^>]+>([^\)|]+\|[^\)]+)\)#';
$stepsdefinitions = preg_replace_callback($regex,
function($matches){
return html_writer::select(explode('|', $matches[1]), uniqid());
},
$stepsdefinitions
);
$stepsdefinitions = preg_replace_callback('/(FIELD_VALUE_STRING)/',
function ($matches) {
global $CFG;
// Creating a link to a popup with the help.
$url = new moodle_url(
'/help.php',
array(
'component' => 'tool_behat',
'identifier' => 'fieldvalueargument',
'lang' => current_language()
)
);
// Note: this title is displayed only if JS is disabled,
// otherwise the link will have the new ajax tooltip.
$title = get_string('fieldvalueargument', 'tool_behat');
$title = get_string('helpprefix2', '', trim($title, ". \t"));
$attributes = array('href' => $url, 'title' => $title,
'aria-haspopup' => 'true', 'target' => '_blank');
$output = html_writer::tag('a', 'FIELD_VALUE_STRING', $attributes);
return html_writer::tag('span', $output, array('class' => 'helptooltip'));
},
$stepsdefinitions
);
}
// Steps definitions.
$html .= html_writer::tag('div', $stepsdefinitions, array('class' => 'steps-definitions'));
$html .= $this->output->footer();
return $html;
}
|
php
|
public function render_stepsdefinitions($stepsdefinitions, $form) {
global $CFG;
require_once($CFG->libdir . '/behat/classes/behat_selectors.php');
$html = $this->generic_info();
// Form.
ob_start();
$form->display();
$html .= ob_get_contents();
ob_end_clean();
if (empty($stepsdefinitions)) {
$stepsdefinitions = get_string('nostepsdefinitions', 'tool_behat');
} else {
$stepsdefinitions = implode('', $stepsdefinitions);
// Replace text selector type arguments with a user-friendly select.
$stepsdefinitions = preg_replace_callback('/(TEXT_SELECTOR\d?_STRING)/',
function ($matches) {
return html_writer::select(behat_selectors::get_allowed_text_selectors(), uniqid());
},
$stepsdefinitions
);
// Replace selector type arguments with a user-friendly select.
$stepsdefinitions = preg_replace_callback('/(SELECTOR\d?_STRING)/',
function ($matches) {
return html_writer::select(behat_selectors::get_allowed_selectors(), uniqid());
},
$stepsdefinitions
);
// Replace simple OR options.
$regex = '#\(\?P<[^>]+>([^\)|]+\|[^\)]+)\)#';
$stepsdefinitions = preg_replace_callback($regex,
function($matches){
return html_writer::select(explode('|', $matches[1]), uniqid());
},
$stepsdefinitions
);
$stepsdefinitions = preg_replace_callback('/(FIELD_VALUE_STRING)/',
function ($matches) {
global $CFG;
// Creating a link to a popup with the help.
$url = new moodle_url(
'/help.php',
array(
'component' => 'tool_behat',
'identifier' => 'fieldvalueargument',
'lang' => current_language()
)
);
// Note: this title is displayed only if JS is disabled,
// otherwise the link will have the new ajax tooltip.
$title = get_string('fieldvalueargument', 'tool_behat');
$title = get_string('helpprefix2', '', trim($title, ". \t"));
$attributes = array('href' => $url, 'title' => $title,
'aria-haspopup' => 'true', 'target' => '_blank');
$output = html_writer::tag('a', 'FIELD_VALUE_STRING', $attributes);
return html_writer::tag('span', $output, array('class' => 'helptooltip'));
},
$stepsdefinitions
);
}
// Steps definitions.
$html .= html_writer::tag('div', $stepsdefinitions, array('class' => 'steps-definitions'));
$html .= $this->output->footer();
return $html;
}
|
[
"public",
"function",
"render_stepsdefinitions",
"(",
"$",
"stepsdefinitions",
",",
"$",
"form",
")",
"{",
"global",
"$",
"CFG",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"libdir",
".",
"'/behat/classes/behat_selectors.php'",
")",
";",
"$",
"html",
"=",
"$",
"this",
"->",
"generic_info",
"(",
")",
";",
"// Form.",
"ob_start",
"(",
")",
";",
"$",
"form",
"->",
"display",
"(",
")",
";",
"$",
"html",
".=",
"ob_get_contents",
"(",
")",
";",
"ob_end_clean",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"stepsdefinitions",
")",
")",
"{",
"$",
"stepsdefinitions",
"=",
"get_string",
"(",
"'nostepsdefinitions'",
",",
"'tool_behat'",
")",
";",
"}",
"else",
"{",
"$",
"stepsdefinitions",
"=",
"implode",
"(",
"''",
",",
"$",
"stepsdefinitions",
")",
";",
"// Replace text selector type arguments with a user-friendly select.",
"$",
"stepsdefinitions",
"=",
"preg_replace_callback",
"(",
"'/(TEXT_SELECTOR\\d?_STRING)/'",
",",
"function",
"(",
"$",
"matches",
")",
"{",
"return",
"html_writer",
"::",
"select",
"(",
"behat_selectors",
"::",
"get_allowed_text_selectors",
"(",
")",
",",
"uniqid",
"(",
")",
")",
";",
"}",
",",
"$",
"stepsdefinitions",
")",
";",
"// Replace selector type arguments with a user-friendly select.",
"$",
"stepsdefinitions",
"=",
"preg_replace_callback",
"(",
"'/(SELECTOR\\d?_STRING)/'",
",",
"function",
"(",
"$",
"matches",
")",
"{",
"return",
"html_writer",
"::",
"select",
"(",
"behat_selectors",
"::",
"get_allowed_selectors",
"(",
")",
",",
"uniqid",
"(",
")",
")",
";",
"}",
",",
"$",
"stepsdefinitions",
")",
";",
"// Replace simple OR options.",
"$",
"regex",
"=",
"'#\\(\\?P<[^>]+>([^\\)|]+\\|[^\\)]+)\\)#'",
";",
"$",
"stepsdefinitions",
"=",
"preg_replace_callback",
"(",
"$",
"regex",
",",
"function",
"(",
"$",
"matches",
")",
"{",
"return",
"html_writer",
"::",
"select",
"(",
"explode",
"(",
"'|'",
",",
"$",
"matches",
"[",
"1",
"]",
")",
",",
"uniqid",
"(",
")",
")",
";",
"}",
",",
"$",
"stepsdefinitions",
")",
";",
"$",
"stepsdefinitions",
"=",
"preg_replace_callback",
"(",
"'/(FIELD_VALUE_STRING)/'",
",",
"function",
"(",
"$",
"matches",
")",
"{",
"global",
"$",
"CFG",
";",
"// Creating a link to a popup with the help.",
"$",
"url",
"=",
"new",
"moodle_url",
"(",
"'/help.php'",
",",
"array",
"(",
"'component'",
"=>",
"'tool_behat'",
",",
"'identifier'",
"=>",
"'fieldvalueargument'",
",",
"'lang'",
"=>",
"current_language",
"(",
")",
")",
")",
";",
"// Note: this title is displayed only if JS is disabled,",
"// otherwise the link will have the new ajax tooltip.",
"$",
"title",
"=",
"get_string",
"(",
"'fieldvalueargument'",
",",
"'tool_behat'",
")",
";",
"$",
"title",
"=",
"get_string",
"(",
"'helpprefix2'",
",",
"''",
",",
"trim",
"(",
"$",
"title",
",",
"\". \\t\"",
")",
")",
";",
"$",
"attributes",
"=",
"array",
"(",
"'href'",
"=>",
"$",
"url",
",",
"'title'",
"=>",
"$",
"title",
",",
"'aria-haspopup'",
"=>",
"'true'",
",",
"'target'",
"=>",
"'_blank'",
")",
";",
"$",
"output",
"=",
"html_writer",
"::",
"tag",
"(",
"'a'",
",",
"'FIELD_VALUE_STRING'",
",",
"$",
"attributes",
")",
";",
"return",
"html_writer",
"::",
"tag",
"(",
"'span'",
",",
"$",
"output",
",",
"array",
"(",
"'class'",
"=>",
"'helptooltip'",
")",
")",
";",
"}",
",",
"$",
"stepsdefinitions",
")",
";",
"}",
"// Steps definitions.",
"$",
"html",
".=",
"html_writer",
"::",
"tag",
"(",
"'div'",
",",
"$",
"stepsdefinitions",
",",
"array",
"(",
"'class'",
"=>",
"'steps-definitions'",
")",
")",
";",
"$",
"html",
".=",
"$",
"this",
"->",
"output",
"->",
"footer",
"(",
")",
";",
"return",
"$",
"html",
";",
"}"
] |
Renders the list of available steps according to the submitted filters.
@param mixed $stepsdefinitions Available steps array.
@param moodleform $form
@return string HTML code
|
[
"Renders",
"the",
"list",
"of",
"available",
"steps",
"according",
"to",
"the",
"submitted",
"filters",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/behat/renderer.php#L43-L121
|
215,287
|
moodle/moodle
|
admin/tool/behat/renderer.php
|
tool_behat_renderer.render_error
|
public function render_error($msg) {
$html = $this->generic_info();
$a = new stdClass();
$a->errormsg = $msg;
$a->behatcommand = behat_command::get_behat_command();
$a->behatinit = 'php admin' . DIRECTORY_SEPARATOR . 'tool' . DIRECTORY_SEPARATOR .
'behat' . DIRECTORY_SEPARATOR . 'cli' . DIRECTORY_SEPARATOR . 'init.php';
$msg = get_string('wrongbehatsetup', 'tool_behat', $a);
// Error box including generic error string + specific error msg.
$html .= $this->output->box_start('box errorbox alert alert-danger');
$html .= html_writer::tag('div', $msg);
$html .= $this->output->box_end();
$html .= $this->output->footer();
return $html;
}
|
php
|
public function render_error($msg) {
$html = $this->generic_info();
$a = new stdClass();
$a->errormsg = $msg;
$a->behatcommand = behat_command::get_behat_command();
$a->behatinit = 'php admin' . DIRECTORY_SEPARATOR . 'tool' . DIRECTORY_SEPARATOR .
'behat' . DIRECTORY_SEPARATOR . 'cli' . DIRECTORY_SEPARATOR . 'init.php';
$msg = get_string('wrongbehatsetup', 'tool_behat', $a);
// Error box including generic error string + specific error msg.
$html .= $this->output->box_start('box errorbox alert alert-danger');
$html .= html_writer::tag('div', $msg);
$html .= $this->output->box_end();
$html .= $this->output->footer();
return $html;
}
|
[
"public",
"function",
"render_error",
"(",
"$",
"msg",
")",
"{",
"$",
"html",
"=",
"$",
"this",
"->",
"generic_info",
"(",
")",
";",
"$",
"a",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"a",
"->",
"errormsg",
"=",
"$",
"msg",
";",
"$",
"a",
"->",
"behatcommand",
"=",
"behat_command",
"::",
"get_behat_command",
"(",
")",
";",
"$",
"a",
"->",
"behatinit",
"=",
"'php admin'",
".",
"DIRECTORY_SEPARATOR",
".",
"'tool'",
".",
"DIRECTORY_SEPARATOR",
".",
"'behat'",
".",
"DIRECTORY_SEPARATOR",
".",
"'cli'",
".",
"DIRECTORY_SEPARATOR",
".",
"'init.php'",
";",
"$",
"msg",
"=",
"get_string",
"(",
"'wrongbehatsetup'",
",",
"'tool_behat'",
",",
"$",
"a",
")",
";",
"// Error box including generic error string + specific error msg.",
"$",
"html",
".=",
"$",
"this",
"->",
"output",
"->",
"box_start",
"(",
"'box errorbox alert alert-danger'",
")",
";",
"$",
"html",
".=",
"html_writer",
"::",
"tag",
"(",
"'div'",
",",
"$",
"msg",
")",
";",
"$",
"html",
".=",
"$",
"this",
"->",
"output",
"->",
"box_end",
"(",
")",
";",
"$",
"html",
".=",
"$",
"this",
"->",
"output",
"->",
"footer",
"(",
")",
";",
"return",
"$",
"html",
";",
"}"
] |
Renders an error message adding the generic info about the tool purpose and setup.
@param string $msg The error message
@return string HTML
|
[
"Renders",
"an",
"error",
"message",
"adding",
"the",
"generic",
"info",
"about",
"the",
"tool",
"purpose",
"and",
"setup",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/behat/renderer.php#L129-L149
|
215,288
|
moodle/moodle
|
admin/tool/behat/renderer.php
|
tool_behat_renderer.generic_info
|
protected function generic_info() {
$title = get_string('pluginname', 'tool_behat');
// Header.
$html = $this->output->header();
$html .= $this->output->heading($title);
// Info.
$installurl = behat_command::DOCS_URL;
$installlink = html_writer::tag('a', $installurl, array('href' => $installurl, 'target' => '_blank'));
$writetestsurl = 'https://docs.moodle.org/dev/Writing acceptance tests';
$writetestslink = html_writer::tag('a', $writetestsurl, array('href' => $writetestsurl, 'target' => '_blank'));
$writestepsurl = 'https://docs.moodle.org/dev/Writing_new_acceptance_test_step_definitions';
$writestepslink = html_writer::tag('a', $writestepsurl, array('href' => $writestepsurl, 'target' => '_blank'));
$infos = array(
get_string('installinfo', 'tool_behat', $installlink),
get_string('newtestsinfo', 'tool_behat', $writetestslink),
get_string('newstepsinfo', 'tool_behat', $writestepslink)
);
// List of steps.
$html .= $this->output->box_start();
$html .= html_writer::tag('h3', get_string('infoheading', 'tool_behat'));
$html .= html_writer::tag('div', get_string('aim', 'tool_behat'));
$html .= html_writer::start_tag('div');
$html .= html_writer::start_tag('ul');
$html .= html_writer::start_tag('li');
$html .= implode(html_writer::end_tag('li') . html_writer::start_tag('li'), $infos);
$html .= html_writer::end_tag('li');
$html .= html_writer::end_tag('ul');
$html .= html_writer::end_tag('div');
$html .= $this->output->box_end();
return $html;
}
|
php
|
protected function generic_info() {
$title = get_string('pluginname', 'tool_behat');
// Header.
$html = $this->output->header();
$html .= $this->output->heading($title);
// Info.
$installurl = behat_command::DOCS_URL;
$installlink = html_writer::tag('a', $installurl, array('href' => $installurl, 'target' => '_blank'));
$writetestsurl = 'https://docs.moodle.org/dev/Writing acceptance tests';
$writetestslink = html_writer::tag('a', $writetestsurl, array('href' => $writetestsurl, 'target' => '_blank'));
$writestepsurl = 'https://docs.moodle.org/dev/Writing_new_acceptance_test_step_definitions';
$writestepslink = html_writer::tag('a', $writestepsurl, array('href' => $writestepsurl, 'target' => '_blank'));
$infos = array(
get_string('installinfo', 'tool_behat', $installlink),
get_string('newtestsinfo', 'tool_behat', $writetestslink),
get_string('newstepsinfo', 'tool_behat', $writestepslink)
);
// List of steps.
$html .= $this->output->box_start();
$html .= html_writer::tag('h3', get_string('infoheading', 'tool_behat'));
$html .= html_writer::tag('div', get_string('aim', 'tool_behat'));
$html .= html_writer::start_tag('div');
$html .= html_writer::start_tag('ul');
$html .= html_writer::start_tag('li');
$html .= implode(html_writer::end_tag('li') . html_writer::start_tag('li'), $infos);
$html .= html_writer::end_tag('li');
$html .= html_writer::end_tag('ul');
$html .= html_writer::end_tag('div');
$html .= $this->output->box_end();
return $html;
}
|
[
"protected",
"function",
"generic_info",
"(",
")",
"{",
"$",
"title",
"=",
"get_string",
"(",
"'pluginname'",
",",
"'tool_behat'",
")",
";",
"// Header.",
"$",
"html",
"=",
"$",
"this",
"->",
"output",
"->",
"header",
"(",
")",
";",
"$",
"html",
".=",
"$",
"this",
"->",
"output",
"->",
"heading",
"(",
"$",
"title",
")",
";",
"// Info.",
"$",
"installurl",
"=",
"behat_command",
"::",
"DOCS_URL",
";",
"$",
"installlink",
"=",
"html_writer",
"::",
"tag",
"(",
"'a'",
",",
"$",
"installurl",
",",
"array",
"(",
"'href'",
"=>",
"$",
"installurl",
",",
"'target'",
"=>",
"'_blank'",
")",
")",
";",
"$",
"writetestsurl",
"=",
"'https://docs.moodle.org/dev/Writing acceptance tests'",
";",
"$",
"writetestslink",
"=",
"html_writer",
"::",
"tag",
"(",
"'a'",
",",
"$",
"writetestsurl",
",",
"array",
"(",
"'href'",
"=>",
"$",
"writetestsurl",
",",
"'target'",
"=>",
"'_blank'",
")",
")",
";",
"$",
"writestepsurl",
"=",
"'https://docs.moodle.org/dev/Writing_new_acceptance_test_step_definitions'",
";",
"$",
"writestepslink",
"=",
"html_writer",
"::",
"tag",
"(",
"'a'",
",",
"$",
"writestepsurl",
",",
"array",
"(",
"'href'",
"=>",
"$",
"writestepsurl",
",",
"'target'",
"=>",
"'_blank'",
")",
")",
";",
"$",
"infos",
"=",
"array",
"(",
"get_string",
"(",
"'installinfo'",
",",
"'tool_behat'",
",",
"$",
"installlink",
")",
",",
"get_string",
"(",
"'newtestsinfo'",
",",
"'tool_behat'",
",",
"$",
"writetestslink",
")",
",",
"get_string",
"(",
"'newstepsinfo'",
",",
"'tool_behat'",
",",
"$",
"writestepslink",
")",
")",
";",
"// List of steps.",
"$",
"html",
".=",
"$",
"this",
"->",
"output",
"->",
"box_start",
"(",
")",
";",
"$",
"html",
".=",
"html_writer",
"::",
"tag",
"(",
"'h3'",
",",
"get_string",
"(",
"'infoheading'",
",",
"'tool_behat'",
")",
")",
";",
"$",
"html",
".=",
"html_writer",
"::",
"tag",
"(",
"'div'",
",",
"get_string",
"(",
"'aim'",
",",
"'tool_behat'",
")",
")",
";",
"$",
"html",
".=",
"html_writer",
"::",
"start_tag",
"(",
"'div'",
")",
";",
"$",
"html",
".=",
"html_writer",
"::",
"start_tag",
"(",
"'ul'",
")",
";",
"$",
"html",
".=",
"html_writer",
"::",
"start_tag",
"(",
"'li'",
")",
";",
"$",
"html",
".=",
"implode",
"(",
"html_writer",
"::",
"end_tag",
"(",
"'li'",
")",
".",
"html_writer",
"::",
"start_tag",
"(",
"'li'",
")",
",",
"$",
"infos",
")",
";",
"$",
"html",
".=",
"html_writer",
"::",
"end_tag",
"(",
"'li'",
")",
";",
"$",
"html",
".=",
"html_writer",
"::",
"end_tag",
"(",
"'ul'",
")",
";",
"$",
"html",
".=",
"html_writer",
"::",
"end_tag",
"(",
"'div'",
")",
";",
"$",
"html",
".=",
"$",
"this",
"->",
"output",
"->",
"box_end",
"(",
")",
";",
"return",
"$",
"html",
";",
"}"
] |
Generic info about the tool.
@return string
|
[
"Generic",
"info",
"about",
"the",
"tool",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/behat/renderer.php#L156-L191
|
215,289
|
moodle/moodle
|
mod/forum/classes/existing_subscriber_selector.php
|
mod_forum_existing_subscriber_selector.find_users
|
public function find_users($search) {
global $DB;
list($wherecondition, $params) = $this->search_sql($search, 'u');
$params['forumid'] = $this->forumid;
// only active enrolled or everybody on the frontpage
list($esql, $eparams) = get_enrolled_sql($this->context, '', $this->currentgroup, true);
$fields = $this->required_fields_sql('u');
list($sort, $sortparams) = users_order_by_sql('u', $search, $this->accesscontext);
$params = array_merge($params, $eparams, $sortparams);
$subscribers = $DB->get_records_sql("SELECT $fields
FROM {user} u
JOIN ($esql) je ON je.id = u.id
JOIN {forum_subscriptions} s ON s.userid = u.id
WHERE $wherecondition AND s.forum = :forumid
ORDER BY $sort", $params);
$cm = get_coursemodule_from_instance('forum', $this->forumid);
$modinfo = get_fast_modinfo($cm->course);
$info = new \core_availability\info_module($modinfo->get_cm($cm->id));
$subscribers = $info->filter_user_list($subscribers);
return array(get_string("existingsubscribers", 'forum') => $subscribers);
}
|
php
|
public function find_users($search) {
global $DB;
list($wherecondition, $params) = $this->search_sql($search, 'u');
$params['forumid'] = $this->forumid;
// only active enrolled or everybody on the frontpage
list($esql, $eparams) = get_enrolled_sql($this->context, '', $this->currentgroup, true);
$fields = $this->required_fields_sql('u');
list($sort, $sortparams) = users_order_by_sql('u', $search, $this->accesscontext);
$params = array_merge($params, $eparams, $sortparams);
$subscribers = $DB->get_records_sql("SELECT $fields
FROM {user} u
JOIN ($esql) je ON je.id = u.id
JOIN {forum_subscriptions} s ON s.userid = u.id
WHERE $wherecondition AND s.forum = :forumid
ORDER BY $sort", $params);
$cm = get_coursemodule_from_instance('forum', $this->forumid);
$modinfo = get_fast_modinfo($cm->course);
$info = new \core_availability\info_module($modinfo->get_cm($cm->id));
$subscribers = $info->filter_user_list($subscribers);
return array(get_string("existingsubscribers", 'forum') => $subscribers);
}
|
[
"public",
"function",
"find_users",
"(",
"$",
"search",
")",
"{",
"global",
"$",
"DB",
";",
"list",
"(",
"$",
"wherecondition",
",",
"$",
"params",
")",
"=",
"$",
"this",
"->",
"search_sql",
"(",
"$",
"search",
",",
"'u'",
")",
";",
"$",
"params",
"[",
"'forumid'",
"]",
"=",
"$",
"this",
"->",
"forumid",
";",
"// only active enrolled or everybody on the frontpage",
"list",
"(",
"$",
"esql",
",",
"$",
"eparams",
")",
"=",
"get_enrolled_sql",
"(",
"$",
"this",
"->",
"context",
",",
"''",
",",
"$",
"this",
"->",
"currentgroup",
",",
"true",
")",
";",
"$",
"fields",
"=",
"$",
"this",
"->",
"required_fields_sql",
"(",
"'u'",
")",
";",
"list",
"(",
"$",
"sort",
",",
"$",
"sortparams",
")",
"=",
"users_order_by_sql",
"(",
"'u'",
",",
"$",
"search",
",",
"$",
"this",
"->",
"accesscontext",
")",
";",
"$",
"params",
"=",
"array_merge",
"(",
"$",
"params",
",",
"$",
"eparams",
",",
"$",
"sortparams",
")",
";",
"$",
"subscribers",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"\"SELECT $fields\n FROM {user} u\n JOIN ($esql) je ON je.id = u.id\n JOIN {forum_subscriptions} s ON s.userid = u.id\n WHERE $wherecondition AND s.forum = :forumid\n ORDER BY $sort\"",
",",
"$",
"params",
")",
";",
"$",
"cm",
"=",
"get_coursemodule_from_instance",
"(",
"'forum'",
",",
"$",
"this",
"->",
"forumid",
")",
";",
"$",
"modinfo",
"=",
"get_fast_modinfo",
"(",
"$",
"cm",
"->",
"course",
")",
";",
"$",
"info",
"=",
"new",
"\\",
"core_availability",
"\\",
"info_module",
"(",
"$",
"modinfo",
"->",
"get_cm",
"(",
"$",
"cm",
"->",
"id",
")",
")",
";",
"$",
"subscribers",
"=",
"$",
"info",
"->",
"filter_user_list",
"(",
"$",
"subscribers",
")",
";",
"return",
"array",
"(",
"get_string",
"(",
"\"existingsubscribers\"",
",",
"'forum'",
")",
"=>",
"$",
"subscribers",
")",
";",
"}"
] |
Finds all subscribed users
@param string $search
@return array
|
[
"Finds",
"all",
"subscribed",
"users"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/existing_subscriber_selector.php#L43-L67
|
215,290
|
moodle/moodle
|
lib/behat/classes/behat_command.php
|
behat_command.get_behat_dir
|
public static function get_behat_dir($runprocess = 0) {
global $CFG;
// If not set then return empty string.
if (!isset($CFG->behat_dataroot)) {
return "";
}
// If $CFG->behat_parallel_run starts with index 0 and $runprocess for parallel run starts with 1.
if (!empty($runprocess) && isset($CFG->behat_parallel_run[$runprocess - 1]['behat_dataroot'])) {
$behatdir = $CFG->behat_parallel_run[$runprocess - 1]['behat_dataroot'] . '/behat';;
} else {
$behatdir = $CFG->behat_dataroot . '/behat';
}
if (!is_dir($behatdir)) {
if (!mkdir($behatdir, $CFG->directorypermissions, true)) {
behat_error(BEHAT_EXITCODE_PERMISSIONS, 'Directory ' . $behatdir . ' can not be created');
}
}
if (!is_writable($behatdir)) {
behat_error(BEHAT_EXITCODE_PERMISSIONS, 'Directory ' . $behatdir . ' is not writable');
}
return $behatdir;
}
|
php
|
public static function get_behat_dir($runprocess = 0) {
global $CFG;
// If not set then return empty string.
if (!isset($CFG->behat_dataroot)) {
return "";
}
// If $CFG->behat_parallel_run starts with index 0 and $runprocess for parallel run starts with 1.
if (!empty($runprocess) && isset($CFG->behat_parallel_run[$runprocess - 1]['behat_dataroot'])) {
$behatdir = $CFG->behat_parallel_run[$runprocess - 1]['behat_dataroot'] . '/behat';;
} else {
$behatdir = $CFG->behat_dataroot . '/behat';
}
if (!is_dir($behatdir)) {
if (!mkdir($behatdir, $CFG->directorypermissions, true)) {
behat_error(BEHAT_EXITCODE_PERMISSIONS, 'Directory ' . $behatdir . ' can not be created');
}
}
if (!is_writable($behatdir)) {
behat_error(BEHAT_EXITCODE_PERMISSIONS, 'Directory ' . $behatdir . ' is not writable');
}
return $behatdir;
}
|
[
"public",
"static",
"function",
"get_behat_dir",
"(",
"$",
"runprocess",
"=",
"0",
")",
"{",
"global",
"$",
"CFG",
";",
"// If not set then return empty string.",
"if",
"(",
"!",
"isset",
"(",
"$",
"CFG",
"->",
"behat_dataroot",
")",
")",
"{",
"return",
"\"\"",
";",
"}",
"// If $CFG->behat_parallel_run starts with index 0 and $runprocess for parallel run starts with 1.",
"if",
"(",
"!",
"empty",
"(",
"$",
"runprocess",
")",
"&&",
"isset",
"(",
"$",
"CFG",
"->",
"behat_parallel_run",
"[",
"$",
"runprocess",
"-",
"1",
"]",
"[",
"'behat_dataroot'",
"]",
")",
")",
"{",
"$",
"behatdir",
"=",
"$",
"CFG",
"->",
"behat_parallel_run",
"[",
"$",
"runprocess",
"-",
"1",
"]",
"[",
"'behat_dataroot'",
"]",
".",
"'/behat'",
";",
";",
"}",
"else",
"{",
"$",
"behatdir",
"=",
"$",
"CFG",
"->",
"behat_dataroot",
".",
"'/behat'",
";",
"}",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"behatdir",
")",
")",
"{",
"if",
"(",
"!",
"mkdir",
"(",
"$",
"behatdir",
",",
"$",
"CFG",
"->",
"directorypermissions",
",",
"true",
")",
")",
"{",
"behat_error",
"(",
"BEHAT_EXITCODE_PERMISSIONS",
",",
"'Directory '",
".",
"$",
"behatdir",
".",
"' can not be created'",
")",
";",
"}",
"}",
"if",
"(",
"!",
"is_writable",
"(",
"$",
"behatdir",
")",
")",
"{",
"behat_error",
"(",
"BEHAT_EXITCODE_PERMISSIONS",
",",
"'Directory '",
".",
"$",
"behatdir",
".",
"' is not writable'",
")",
";",
"}",
"return",
"$",
"behatdir",
";",
"}"
] |
Ensures the behat dir exists in moodledata
@param int $runprocess run process for which behat dir is returned.
@return string Full path
|
[
"Ensures",
"the",
"behat",
"dir",
"exists",
"in",
"moodledata"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_command.php#L66-L92
|
215,291
|
moodle/moodle
|
lib/behat/classes/behat_command.php
|
behat_command.get_behat_command
|
public final static function get_behat_command($custombyterm = false, $parallerun = false, $absolutepath = false) {
$separator = DIRECTORY_SEPARATOR;
$exec = 'behat';
// Cygwin uses linux-style directory separators.
if ($custombyterm && testing_is_cygwin()) {
$separator = '/';
// MinGW can not execute .bat scripts.
if (!testing_is_mingw()) {
$exec = 'behat.bat';
}
}
// If relative path then prefix relative path.
if ($absolutepath) {
$pathprefix = testing_cli_argument_path('/');
if (!empty($pathprefix)) {
$pathprefix .= $separator;
}
} else {
$pathprefix = '';
}
if (!$parallerun) {
$command = $pathprefix . 'vendor' . $separator . 'bin' . $separator . $exec;
} else {
$command = 'php ' . $pathprefix . 'admin' . $separator . 'tool' . $separator . 'behat' . $separator . 'cli'
. $separator . 'run.php';
}
return $command;
}
|
php
|
public final static function get_behat_command($custombyterm = false, $parallerun = false, $absolutepath = false) {
$separator = DIRECTORY_SEPARATOR;
$exec = 'behat';
// Cygwin uses linux-style directory separators.
if ($custombyterm && testing_is_cygwin()) {
$separator = '/';
// MinGW can not execute .bat scripts.
if (!testing_is_mingw()) {
$exec = 'behat.bat';
}
}
// If relative path then prefix relative path.
if ($absolutepath) {
$pathprefix = testing_cli_argument_path('/');
if (!empty($pathprefix)) {
$pathprefix .= $separator;
}
} else {
$pathprefix = '';
}
if (!$parallerun) {
$command = $pathprefix . 'vendor' . $separator . 'bin' . $separator . $exec;
} else {
$command = 'php ' . $pathprefix . 'admin' . $separator . 'tool' . $separator . 'behat' . $separator . 'cli'
. $separator . 'run.php';
}
return $command;
}
|
[
"public",
"final",
"static",
"function",
"get_behat_command",
"(",
"$",
"custombyterm",
"=",
"false",
",",
"$",
"parallerun",
"=",
"false",
",",
"$",
"absolutepath",
"=",
"false",
")",
"{",
"$",
"separator",
"=",
"DIRECTORY_SEPARATOR",
";",
"$",
"exec",
"=",
"'behat'",
";",
"// Cygwin uses linux-style directory separators.",
"if",
"(",
"$",
"custombyterm",
"&&",
"testing_is_cygwin",
"(",
")",
")",
"{",
"$",
"separator",
"=",
"'/'",
";",
"// MinGW can not execute .bat scripts.",
"if",
"(",
"!",
"testing_is_mingw",
"(",
")",
")",
"{",
"$",
"exec",
"=",
"'behat.bat'",
";",
"}",
"}",
"// If relative path then prefix relative path.",
"if",
"(",
"$",
"absolutepath",
")",
"{",
"$",
"pathprefix",
"=",
"testing_cli_argument_path",
"(",
"'/'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"pathprefix",
")",
")",
"{",
"$",
"pathprefix",
".=",
"$",
"separator",
";",
"}",
"}",
"else",
"{",
"$",
"pathprefix",
"=",
"''",
";",
"}",
"if",
"(",
"!",
"$",
"parallerun",
")",
"{",
"$",
"command",
"=",
"$",
"pathprefix",
".",
"'vendor'",
".",
"$",
"separator",
".",
"'bin'",
".",
"$",
"separator",
".",
"$",
"exec",
";",
"}",
"else",
"{",
"$",
"command",
"=",
"'php '",
".",
"$",
"pathprefix",
".",
"'admin'",
".",
"$",
"separator",
".",
"'tool'",
".",
"$",
"separator",
".",
"'behat'",
".",
"$",
"separator",
".",
"'cli'",
".",
"$",
"separator",
".",
"'run.php'",
";",
"}",
"return",
"$",
"command",
";",
"}"
] |
Returns the executable path
Allows returning a customized command for cygwin when the
command is just displayed, when using exec(), system() and
friends we stay with DIRECTORY_SEPARATOR as they use the
normal cmd.exe (in Windows).
@param bool $custombyterm If the provided command should depend on the terminal where it runs
@param bool $parallelrun If parallel run is installed.
@param bool $absolutepath return command with absolute path.
@return string
|
[
"Returns",
"the",
"executable",
"path"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_command.php#L107-L139
|
215,292
|
moodle/moodle
|
lib/behat/classes/behat_command.php
|
behat_command.run
|
public final static function run($options = '') {
global $CFG;
$currentcwd = getcwd();
chdir($CFG->dirroot);
exec(self::get_behat_command() . ' ' . $options, $output, $code);
chdir($currentcwd);
return array($output, $code);
}
|
php
|
public final static function run($options = '') {
global $CFG;
$currentcwd = getcwd();
chdir($CFG->dirroot);
exec(self::get_behat_command() . ' ' . $options, $output, $code);
chdir($currentcwd);
return array($output, $code);
}
|
[
"public",
"final",
"static",
"function",
"run",
"(",
"$",
"options",
"=",
"''",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"currentcwd",
"=",
"getcwd",
"(",
")",
";",
"chdir",
"(",
"$",
"CFG",
"->",
"dirroot",
")",
";",
"exec",
"(",
"self",
"::",
"get_behat_command",
"(",
")",
".",
"' '",
".",
"$",
"options",
",",
"$",
"output",
",",
"$",
"code",
")",
";",
"chdir",
"(",
"$",
"currentcwd",
")",
";",
"return",
"array",
"(",
"$",
"output",
",",
"$",
"code",
")",
";",
"}"
] |
Runs behat command with provided options
Execution continues when the process finishes
@param string $options Defaults to '' so tests would be executed
@return array CLI command outputs [0] => string, [1] => integer
|
[
"Runs",
"behat",
"command",
"with",
"provided",
"options"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_command.php#L149-L158
|
215,293
|
moodle/moodle
|
lib/behat/classes/behat_command.php
|
behat_command.behat_setup_problem
|
public static function behat_setup_problem() {
global $CFG;
// Moodle setting.
if (!self::are_behat_dependencies_installed()) {
// Returning composer error code to avoid conflicts with behat and moodle error codes.
self::output_msg(get_string('errorcomposer', 'tool_behat'));
return TESTING_EXITCODE_COMPOSER;
}
// Behat test command.
list($output, $code) = self::run(' --help');
if ($code != 0) {
// Returning composer error code to avoid conflicts with behat and moodle error codes.
self::output_msg(get_string('errorbehatcommand', 'tool_behat', self::get_behat_command()));
return TESTING_EXITCODE_COMPOSER;
}
// No empty values.
if (empty($CFG->behat_dataroot) || empty($CFG->behat_prefix) || empty($CFG->behat_wwwroot)) {
self::output_msg(get_string('errorsetconfig', 'tool_behat'));
return BEHAT_EXITCODE_CONFIG;
}
// Not repeated values.
// We only need to check this when the behat site is not running as
// at this point, when it is running, all $CFG->behat_* vars have
// already been copied to $CFG->dataroot, $CFG->prefix and $CFG->wwwroot.
if (!defined('BEHAT_SITE_RUNNING') &&
($CFG->behat_prefix == $CFG->prefix ||
$CFG->behat_dataroot == $CFG->dataroot ||
$CFG->behat_wwwroot == $CFG->wwwroot ||
(!empty($CFG->phpunit_prefix) && $CFG->phpunit_prefix == $CFG->behat_prefix) ||
(!empty($CFG->phpunit_dataroot) && $CFG->phpunit_dataroot == $CFG->behat_dataroot)
)) {
self::output_msg(get_string('erroruniqueconfig', 'tool_behat'));
return BEHAT_EXITCODE_CONFIG;
}
// Checking behat dataroot existence otherwise echo about admin/tool/behat/cli/init.php.
if (!empty($CFG->behat_dataroot)) {
$CFG->behat_dataroot = realpath($CFG->behat_dataroot);
}
if (empty($CFG->behat_dataroot) || !is_dir($CFG->behat_dataroot) || !is_writable($CFG->behat_dataroot)) {
self::output_msg(get_string('errordataroot', 'tool_behat'));
return BEHAT_EXITCODE_CONFIG;
}
// If app config is supplied, check the value is correct.
if (!empty($CFG->behat_ionic_dirroot) && !file_exists($CFG->behat_ionic_dirroot . '/ionic.config.json')) {
self::output_msg(get_string('errorapproot', 'tool_behat'));
return BEHAT_EXITCODE_CONFIG;
}
return 0;
}
|
php
|
public static function behat_setup_problem() {
global $CFG;
// Moodle setting.
if (!self::are_behat_dependencies_installed()) {
// Returning composer error code to avoid conflicts with behat and moodle error codes.
self::output_msg(get_string('errorcomposer', 'tool_behat'));
return TESTING_EXITCODE_COMPOSER;
}
// Behat test command.
list($output, $code) = self::run(' --help');
if ($code != 0) {
// Returning composer error code to avoid conflicts with behat and moodle error codes.
self::output_msg(get_string('errorbehatcommand', 'tool_behat', self::get_behat_command()));
return TESTING_EXITCODE_COMPOSER;
}
// No empty values.
if (empty($CFG->behat_dataroot) || empty($CFG->behat_prefix) || empty($CFG->behat_wwwroot)) {
self::output_msg(get_string('errorsetconfig', 'tool_behat'));
return BEHAT_EXITCODE_CONFIG;
}
// Not repeated values.
// We only need to check this when the behat site is not running as
// at this point, when it is running, all $CFG->behat_* vars have
// already been copied to $CFG->dataroot, $CFG->prefix and $CFG->wwwroot.
if (!defined('BEHAT_SITE_RUNNING') &&
($CFG->behat_prefix == $CFG->prefix ||
$CFG->behat_dataroot == $CFG->dataroot ||
$CFG->behat_wwwroot == $CFG->wwwroot ||
(!empty($CFG->phpunit_prefix) && $CFG->phpunit_prefix == $CFG->behat_prefix) ||
(!empty($CFG->phpunit_dataroot) && $CFG->phpunit_dataroot == $CFG->behat_dataroot)
)) {
self::output_msg(get_string('erroruniqueconfig', 'tool_behat'));
return BEHAT_EXITCODE_CONFIG;
}
// Checking behat dataroot existence otherwise echo about admin/tool/behat/cli/init.php.
if (!empty($CFG->behat_dataroot)) {
$CFG->behat_dataroot = realpath($CFG->behat_dataroot);
}
if (empty($CFG->behat_dataroot) || !is_dir($CFG->behat_dataroot) || !is_writable($CFG->behat_dataroot)) {
self::output_msg(get_string('errordataroot', 'tool_behat'));
return BEHAT_EXITCODE_CONFIG;
}
// If app config is supplied, check the value is correct.
if (!empty($CFG->behat_ionic_dirroot) && !file_exists($CFG->behat_ionic_dirroot . '/ionic.config.json')) {
self::output_msg(get_string('errorapproot', 'tool_behat'));
return BEHAT_EXITCODE_CONFIG;
}
return 0;
}
|
[
"public",
"static",
"function",
"behat_setup_problem",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"// Moodle setting.",
"if",
"(",
"!",
"self",
"::",
"are_behat_dependencies_installed",
"(",
")",
")",
"{",
"// Returning composer error code to avoid conflicts with behat and moodle error codes.",
"self",
"::",
"output_msg",
"(",
"get_string",
"(",
"'errorcomposer'",
",",
"'tool_behat'",
")",
")",
";",
"return",
"TESTING_EXITCODE_COMPOSER",
";",
"}",
"// Behat test command.",
"list",
"(",
"$",
"output",
",",
"$",
"code",
")",
"=",
"self",
"::",
"run",
"(",
"' --help'",
")",
";",
"if",
"(",
"$",
"code",
"!=",
"0",
")",
"{",
"// Returning composer error code to avoid conflicts with behat and moodle error codes.",
"self",
"::",
"output_msg",
"(",
"get_string",
"(",
"'errorbehatcommand'",
",",
"'tool_behat'",
",",
"self",
"::",
"get_behat_command",
"(",
")",
")",
")",
";",
"return",
"TESTING_EXITCODE_COMPOSER",
";",
"}",
"// No empty values.",
"if",
"(",
"empty",
"(",
"$",
"CFG",
"->",
"behat_dataroot",
")",
"||",
"empty",
"(",
"$",
"CFG",
"->",
"behat_prefix",
")",
"||",
"empty",
"(",
"$",
"CFG",
"->",
"behat_wwwroot",
")",
")",
"{",
"self",
"::",
"output_msg",
"(",
"get_string",
"(",
"'errorsetconfig'",
",",
"'tool_behat'",
")",
")",
";",
"return",
"BEHAT_EXITCODE_CONFIG",
";",
"}",
"// Not repeated values.",
"// We only need to check this when the behat site is not running as",
"// at this point, when it is running, all $CFG->behat_* vars have",
"// already been copied to $CFG->dataroot, $CFG->prefix and $CFG->wwwroot.",
"if",
"(",
"!",
"defined",
"(",
"'BEHAT_SITE_RUNNING'",
")",
"&&",
"(",
"$",
"CFG",
"->",
"behat_prefix",
"==",
"$",
"CFG",
"->",
"prefix",
"||",
"$",
"CFG",
"->",
"behat_dataroot",
"==",
"$",
"CFG",
"->",
"dataroot",
"||",
"$",
"CFG",
"->",
"behat_wwwroot",
"==",
"$",
"CFG",
"->",
"wwwroot",
"||",
"(",
"!",
"empty",
"(",
"$",
"CFG",
"->",
"phpunit_prefix",
")",
"&&",
"$",
"CFG",
"->",
"phpunit_prefix",
"==",
"$",
"CFG",
"->",
"behat_prefix",
")",
"||",
"(",
"!",
"empty",
"(",
"$",
"CFG",
"->",
"phpunit_dataroot",
")",
"&&",
"$",
"CFG",
"->",
"phpunit_dataroot",
"==",
"$",
"CFG",
"->",
"behat_dataroot",
")",
")",
")",
"{",
"self",
"::",
"output_msg",
"(",
"get_string",
"(",
"'erroruniqueconfig'",
",",
"'tool_behat'",
")",
")",
";",
"return",
"BEHAT_EXITCODE_CONFIG",
";",
"}",
"// Checking behat dataroot existence otherwise echo about admin/tool/behat/cli/init.php.",
"if",
"(",
"!",
"empty",
"(",
"$",
"CFG",
"->",
"behat_dataroot",
")",
")",
"{",
"$",
"CFG",
"->",
"behat_dataroot",
"=",
"realpath",
"(",
"$",
"CFG",
"->",
"behat_dataroot",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"CFG",
"->",
"behat_dataroot",
")",
"||",
"!",
"is_dir",
"(",
"$",
"CFG",
"->",
"behat_dataroot",
")",
"||",
"!",
"is_writable",
"(",
"$",
"CFG",
"->",
"behat_dataroot",
")",
")",
"{",
"self",
"::",
"output_msg",
"(",
"get_string",
"(",
"'errordataroot'",
",",
"'tool_behat'",
")",
")",
";",
"return",
"BEHAT_EXITCODE_CONFIG",
";",
"}",
"// If app config is supplied, check the value is correct.",
"if",
"(",
"!",
"empty",
"(",
"$",
"CFG",
"->",
"behat_ionic_dirroot",
")",
"&&",
"!",
"file_exists",
"(",
"$",
"CFG",
"->",
"behat_ionic_dirroot",
".",
"'/ionic.config.json'",
")",
")",
"{",
"self",
"::",
"output_msg",
"(",
"get_string",
"(",
"'errorapproot'",
",",
"'tool_behat'",
")",
")",
";",
"return",
"BEHAT_EXITCODE_CONFIG",
";",
"}",
"return",
"0",
";",
"}"
] |
Checks if behat is set up and working
Notifies failures both from CLI and web interface.
It checks behat dependencies have been installed and runs
the behat help command to ensure it works as expected
@return int Error code or 0 if all ok
|
[
"Checks",
"if",
"behat",
"is",
"set",
"up",
"and",
"working"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_command.php#L170-L229
|
215,294
|
moodle/moodle
|
lib/behat/classes/behat_command.php
|
behat_command.output_msg
|
protected static function output_msg($msg) {
global $CFG, $PAGE;
// If we are using the web interface we want pretty messages.
if (!CLI_SCRIPT) {
$renderer = $PAGE->get_renderer('tool_behat');
echo $renderer->render_error($msg);
// Stopping execution.
exit(1);
} else {
// We continue execution after this.
$clibehaterrorstr = "Ensure you set \$CFG->behat_* vars in config.php " .
"and you ran admin/tool/behat/cli/init.php.\n" .
"More info in " . self::DOCS_URL;
echo 'Error: ' . $msg . "\n\n" . $clibehaterrorstr;
}
}
|
php
|
protected static function output_msg($msg) {
global $CFG, $PAGE;
// If we are using the web interface we want pretty messages.
if (!CLI_SCRIPT) {
$renderer = $PAGE->get_renderer('tool_behat');
echo $renderer->render_error($msg);
// Stopping execution.
exit(1);
} else {
// We continue execution after this.
$clibehaterrorstr = "Ensure you set \$CFG->behat_* vars in config.php " .
"and you ran admin/tool/behat/cli/init.php.\n" .
"More info in " . self::DOCS_URL;
echo 'Error: ' . $msg . "\n\n" . $clibehaterrorstr;
}
}
|
[
"protected",
"static",
"function",
"output_msg",
"(",
"$",
"msg",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"PAGE",
";",
"// If we are using the web interface we want pretty messages.",
"if",
"(",
"!",
"CLI_SCRIPT",
")",
"{",
"$",
"renderer",
"=",
"$",
"PAGE",
"->",
"get_renderer",
"(",
"'tool_behat'",
")",
";",
"echo",
"$",
"renderer",
"->",
"render_error",
"(",
"$",
"msg",
")",
";",
"// Stopping execution.",
"exit",
"(",
"1",
")",
";",
"}",
"else",
"{",
"// We continue execution after this.",
"$",
"clibehaterrorstr",
"=",
"\"Ensure you set \\$CFG->behat_* vars in config.php \"",
".",
"\"and you ran admin/tool/behat/cli/init.php.\\n\"",
".",
"\"More info in \"",
".",
"self",
"::",
"DOCS_URL",
";",
"echo",
"'Error: '",
".",
"$",
"msg",
".",
"\"\\n\\n\"",
".",
"$",
"clibehaterrorstr",
";",
"}",
"}"
] |
Outputs a message.
Used in CLI + web UI methods. Stops the
execution in web.
@param string $msg
@return void
|
[
"Outputs",
"a",
"message",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/behat_command.php#L251-L272
|
215,295
|
moodle/moodle
|
webservice/rest/locallib.php
|
webservice_rest_server.send_response
|
protected function send_response() {
//Check that the returned values are valid
try {
if ($this->function->returns_desc != null) {
$validatedvalues = external_api::clean_returnvalue($this->function->returns_desc, $this->returns);
} else {
$validatedvalues = null;
}
} catch (Exception $ex) {
$exception = $ex;
}
if (!empty($exception)) {
$response = $this->generate_error($exception);
} else {
//We can now convert the response to the requested REST format
if ($this->restformat == 'json') {
$response = json_encode($validatedvalues);
} else {
$response = '<?xml version="1.0" encoding="UTF-8" ?>'."\n";
$response .= '<RESPONSE>'."\n";
$response .= self::xmlize_result($validatedvalues, $this->function->returns_desc);
$response .= '</RESPONSE>'."\n";
}
}
$this->send_headers();
echo $response;
}
|
php
|
protected function send_response() {
//Check that the returned values are valid
try {
if ($this->function->returns_desc != null) {
$validatedvalues = external_api::clean_returnvalue($this->function->returns_desc, $this->returns);
} else {
$validatedvalues = null;
}
} catch (Exception $ex) {
$exception = $ex;
}
if (!empty($exception)) {
$response = $this->generate_error($exception);
} else {
//We can now convert the response to the requested REST format
if ($this->restformat == 'json') {
$response = json_encode($validatedvalues);
} else {
$response = '<?xml version="1.0" encoding="UTF-8" ?>'."\n";
$response .= '<RESPONSE>'."\n";
$response .= self::xmlize_result($validatedvalues, $this->function->returns_desc);
$response .= '</RESPONSE>'."\n";
}
}
$this->send_headers();
echo $response;
}
|
[
"protected",
"function",
"send_response",
"(",
")",
"{",
"//Check that the returned values are valid",
"try",
"{",
"if",
"(",
"$",
"this",
"->",
"function",
"->",
"returns_desc",
"!=",
"null",
")",
"{",
"$",
"validatedvalues",
"=",
"external_api",
"::",
"clean_returnvalue",
"(",
"$",
"this",
"->",
"function",
"->",
"returns_desc",
",",
"$",
"this",
"->",
"returns",
")",
";",
"}",
"else",
"{",
"$",
"validatedvalues",
"=",
"null",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"$",
"exception",
"=",
"$",
"ex",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"exception",
")",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"generate_error",
"(",
"$",
"exception",
")",
";",
"}",
"else",
"{",
"//We can now convert the response to the requested REST format",
"if",
"(",
"$",
"this",
"->",
"restformat",
"==",
"'json'",
")",
"{",
"$",
"response",
"=",
"json_encode",
"(",
"$",
"validatedvalues",
")",
";",
"}",
"else",
"{",
"$",
"response",
"=",
"'<?xml version=\"1.0\" encoding=\"UTF-8\" ?>'",
".",
"\"\\n\"",
";",
"$",
"response",
".=",
"'<RESPONSE>'",
".",
"\"\\n\"",
";",
"$",
"response",
".=",
"self",
"::",
"xmlize_result",
"(",
"$",
"validatedvalues",
",",
"$",
"this",
"->",
"function",
"->",
"returns_desc",
")",
";",
"$",
"response",
".=",
"'</RESPONSE>'",
".",
"\"\\n\"",
";",
"}",
"}",
"$",
"this",
"->",
"send_headers",
"(",
")",
";",
"echo",
"$",
"response",
";",
"}"
] |
Send the result of function call to the WS client
formatted as XML document.
|
[
"Send",
"the",
"result",
"of",
"function",
"call",
"to",
"the",
"WS",
"client",
"formatted",
"as",
"XML",
"document",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/webservice/rest/locallib.php#L101-L130
|
215,296
|
moodle/moodle
|
webservice/rest/locallib.php
|
webservice_rest_server.xmlize_result
|
protected static function xmlize_result($returns, $desc) {
if ($desc === null) {
return '';
} else if ($desc instanceof external_value) {
if (is_bool($returns)) {
// we want 1/0 instead of true/false here
$returns = (int)$returns;
}
if (is_null($returns)) {
return '<VALUE null="null"/>'."\n";
} else {
return '<VALUE>'.htmlspecialchars($returns, ENT_COMPAT, 'UTF-8').'</VALUE>'."\n";
}
} else if ($desc instanceof external_multiple_structure) {
$mult = '<MULTIPLE>'."\n";
if (!empty($returns)) {
foreach ($returns as $val) {
$mult .= self::xmlize_result($val, $desc->content);
}
}
$mult .= '</MULTIPLE>'."\n";
return $mult;
} else if ($desc instanceof external_single_structure) {
$single = '<SINGLE>'."\n";
foreach ($desc->keys as $key=>$subdesc) {
$value = isset($returns[$key]) ? $returns[$key] : null;
$single .= '<KEY name="'.$key.'">'.self::xmlize_result($value, $subdesc).'</KEY>'."\n";
}
$single .= '</SINGLE>'."\n";
return $single;
}
}
|
php
|
protected static function xmlize_result($returns, $desc) {
if ($desc === null) {
return '';
} else if ($desc instanceof external_value) {
if (is_bool($returns)) {
// we want 1/0 instead of true/false here
$returns = (int)$returns;
}
if (is_null($returns)) {
return '<VALUE null="null"/>'."\n";
} else {
return '<VALUE>'.htmlspecialchars($returns, ENT_COMPAT, 'UTF-8').'</VALUE>'."\n";
}
} else if ($desc instanceof external_multiple_structure) {
$mult = '<MULTIPLE>'."\n";
if (!empty($returns)) {
foreach ($returns as $val) {
$mult .= self::xmlize_result($val, $desc->content);
}
}
$mult .= '</MULTIPLE>'."\n";
return $mult;
} else if ($desc instanceof external_single_structure) {
$single = '<SINGLE>'."\n";
foreach ($desc->keys as $key=>$subdesc) {
$value = isset($returns[$key]) ? $returns[$key] : null;
$single .= '<KEY name="'.$key.'">'.self::xmlize_result($value, $subdesc).'</KEY>'."\n";
}
$single .= '</SINGLE>'."\n";
return $single;
}
}
|
[
"protected",
"static",
"function",
"xmlize_result",
"(",
"$",
"returns",
",",
"$",
"desc",
")",
"{",
"if",
"(",
"$",
"desc",
"===",
"null",
")",
"{",
"return",
"''",
";",
"}",
"else",
"if",
"(",
"$",
"desc",
"instanceof",
"external_value",
")",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"returns",
")",
")",
"{",
"// we want 1/0 instead of true/false here",
"$",
"returns",
"=",
"(",
"int",
")",
"$",
"returns",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"returns",
")",
")",
"{",
"return",
"'<VALUE null=\"null\"/>'",
".",
"\"\\n\"",
";",
"}",
"else",
"{",
"return",
"'<VALUE>'",
".",
"htmlspecialchars",
"(",
"$",
"returns",
",",
"ENT_COMPAT",
",",
"'UTF-8'",
")",
".",
"'</VALUE>'",
".",
"\"\\n\"",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"desc",
"instanceof",
"external_multiple_structure",
")",
"{",
"$",
"mult",
"=",
"'<MULTIPLE>'",
".",
"\"\\n\"",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"returns",
")",
")",
"{",
"foreach",
"(",
"$",
"returns",
"as",
"$",
"val",
")",
"{",
"$",
"mult",
".=",
"self",
"::",
"xmlize_result",
"(",
"$",
"val",
",",
"$",
"desc",
"->",
"content",
")",
";",
"}",
"}",
"$",
"mult",
".=",
"'</MULTIPLE>'",
".",
"\"\\n\"",
";",
"return",
"$",
"mult",
";",
"}",
"else",
"if",
"(",
"$",
"desc",
"instanceof",
"external_single_structure",
")",
"{",
"$",
"single",
"=",
"'<SINGLE>'",
".",
"\"\\n\"",
";",
"foreach",
"(",
"$",
"desc",
"->",
"keys",
"as",
"$",
"key",
"=>",
"$",
"subdesc",
")",
"{",
"$",
"value",
"=",
"isset",
"(",
"$",
"returns",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"returns",
"[",
"$",
"key",
"]",
":",
"null",
";",
"$",
"single",
".=",
"'<KEY name=\"'",
".",
"$",
"key",
".",
"'\">'",
".",
"self",
"::",
"xmlize_result",
"(",
"$",
"value",
",",
"$",
"subdesc",
")",
".",
"'</KEY>'",
".",
"\"\\n\"",
";",
"}",
"$",
"single",
".=",
"'</SINGLE>'",
".",
"\"\\n\"",
";",
"return",
"$",
"single",
";",
"}",
"}"
] |
Internal implementation - recursive function producing XML markup.
@param mixed $returns the returned values
@param external_description $desc
@return string
|
[
"Internal",
"implementation",
"-",
"recursive",
"function",
"producing",
"XML",
"markup",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/webservice/rest/locallib.php#L203-L237
|
215,297
|
moodle/moodle
|
lib/horde/framework/Horde/Imap/Client/Data/Format/String.php
|
Horde_Imap_Client_Data_Format_String.escapeStream
|
public function escapeStream()
{
if ($this->literal()) {
throw new Horde_Imap_Client_Data_Format_Exception('String requires literal to output.');
}
rewind($this->_data->stream);
$stream = new Horde_Stream_Temp();
$stream->add($this->_data, true);
stream_filter_register('horde_imap_client_string_quote', 'Horde_Imap_Client_Data_Format_Filter_Quote');
stream_filter_append($stream->stream, 'horde_imap_client_string_quote', STREAM_FILTER_READ);
return $stream->stream;
}
|
php
|
public function escapeStream()
{
if ($this->literal()) {
throw new Horde_Imap_Client_Data_Format_Exception('String requires literal to output.');
}
rewind($this->_data->stream);
$stream = new Horde_Stream_Temp();
$stream->add($this->_data, true);
stream_filter_register('horde_imap_client_string_quote', 'Horde_Imap_Client_Data_Format_Filter_Quote');
stream_filter_append($stream->stream, 'horde_imap_client_string_quote', STREAM_FILTER_READ);
return $stream->stream;
}
|
[
"public",
"function",
"escapeStream",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"literal",
"(",
")",
")",
"{",
"throw",
"new",
"Horde_Imap_Client_Data_Format_Exception",
"(",
"'String requires literal to output.'",
")",
";",
"}",
"rewind",
"(",
"$",
"this",
"->",
"_data",
"->",
"stream",
")",
";",
"$",
"stream",
"=",
"new",
"Horde_Stream_Temp",
"(",
")",
";",
"$",
"stream",
"->",
"add",
"(",
"$",
"this",
"->",
"_data",
",",
"true",
")",
";",
"stream_filter_register",
"(",
"'horde_imap_client_string_quote'",
",",
"'Horde_Imap_Client_Data_Format_Filter_Quote'",
")",
";",
"stream_filter_append",
"(",
"$",
"stream",
"->",
"stream",
",",
"'horde_imap_client_string_quote'",
",",
"STREAM_FILTER_READ",
")",
";",
"return",
"$",
"stream",
"->",
"stream",
";",
"}"
] |
Return the escaped string as a stream.
@return resource The IMAP escaped stream.
|
[
"Return",
"the",
"escaped",
"string",
"as",
"a",
"stream",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Data/Format/String.php#L114-L129
|
215,298
|
moodle/moodle
|
lib/horde/framework/Horde/Imap/Client/Data/Format/String.php
|
Horde_Imap_Client_Data_Format_String.forceLiteral
|
public function forceLiteral()
{
$this->_filter = $this->_filterParams();
// Keep binary status, if set
$this->_filter->literal = true;
$this->_filter->quoted = false;
}
|
php
|
public function forceLiteral()
{
$this->_filter = $this->_filterParams();
// Keep binary status, if set
$this->_filter->literal = true;
$this->_filter->quoted = false;
}
|
[
"public",
"function",
"forceLiteral",
"(",
")",
"{",
"$",
"this",
"->",
"_filter",
"=",
"$",
"this",
"->",
"_filterParams",
"(",
")",
";",
"// Keep binary status, if set",
"$",
"this",
"->",
"_filter",
"->",
"literal",
"=",
"true",
";",
"$",
"this",
"->",
"_filter",
"->",
"quoted",
"=",
"false",
";",
"}"
] |
Force item to be output as a literal.
|
[
"Force",
"item",
"to",
"be",
"output",
"as",
"a",
"literal",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Data/Format/String.php#L166-L172
|
215,299
|
moodle/moodle
|
lib/horde/framework/Horde/Imap/Client/Data/Format/String.php
|
Horde_Imap_Client_Data_Format_String.forceBinary
|
public function forceBinary()
{
$this->_filter = $this->_filterParams();
$this->_filter->binary = true;
$this->_filter->literal = true;
$this->_filter->quoted = false;
}
|
php
|
public function forceBinary()
{
$this->_filter = $this->_filterParams();
$this->_filter->binary = true;
$this->_filter->literal = true;
$this->_filter->quoted = false;
}
|
[
"public",
"function",
"forceBinary",
"(",
")",
"{",
"$",
"this",
"->",
"_filter",
"=",
"$",
"this",
"->",
"_filterParams",
"(",
")",
";",
"$",
"this",
"->",
"_filter",
"->",
"binary",
"=",
"true",
";",
"$",
"this",
"->",
"_filter",
"->",
"literal",
"=",
"true",
";",
"$",
"this",
"->",
"_filter",
"->",
"quoted",
"=",
"false",
";",
"}"
] |
Force item to be output as a binary literal.
|
[
"Force",
"item",
"to",
"be",
"output",
"as",
"a",
"binary",
"literal",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Data/Format/String.php#L187-L193
|
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.