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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
216,600
|
moodle/moodle
|
analytics/classes/model.php
|
model.format_predictor_predictions
|
private function format_predictor_predictions($predictorresult) {
$predictions = array();
if (!empty($predictorresult->predictions)) {
foreach ($predictorresult->predictions as $sampleinfo) {
// We parse each prediction.
switch (count($sampleinfo)) {
case 1:
// For whatever reason the predictions processor could not process this sample, we
// skip it and do nothing with it.
debugging($this->model->id . ' model predictions processor could not process the sample with id ' .
$sampleinfo[0], DEBUG_DEVELOPER);
continue 2;
case 2:
// Prediction processors that do not return a prediction score will have the maximum prediction
// score.
list($uniquesampleid, $prediction) = $sampleinfo;
$predictionscore = 1;
break;
case 3:
list($uniquesampleid, $prediction, $predictionscore) = $sampleinfo;
break;
default:
break;
}
$predictiondata = (object)['prediction' => $prediction, 'predictionscore' => $predictionscore];
$predictions[$uniquesampleid] = $predictiondata;
}
}
return $predictions;
}
|
php
|
private function format_predictor_predictions($predictorresult) {
$predictions = array();
if (!empty($predictorresult->predictions)) {
foreach ($predictorresult->predictions as $sampleinfo) {
// We parse each prediction.
switch (count($sampleinfo)) {
case 1:
// For whatever reason the predictions processor could not process this sample, we
// skip it and do nothing with it.
debugging($this->model->id . ' model predictions processor could not process the sample with id ' .
$sampleinfo[0], DEBUG_DEVELOPER);
continue 2;
case 2:
// Prediction processors that do not return a prediction score will have the maximum prediction
// score.
list($uniquesampleid, $prediction) = $sampleinfo;
$predictionscore = 1;
break;
case 3:
list($uniquesampleid, $prediction, $predictionscore) = $sampleinfo;
break;
default:
break;
}
$predictiondata = (object)['prediction' => $prediction, 'predictionscore' => $predictionscore];
$predictions[$uniquesampleid] = $predictiondata;
}
}
return $predictions;
}
|
[
"private",
"function",
"format_predictor_predictions",
"(",
"$",
"predictorresult",
")",
"{",
"$",
"predictions",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"predictorresult",
"->",
"predictions",
")",
")",
"{",
"foreach",
"(",
"$",
"predictorresult",
"->",
"predictions",
"as",
"$",
"sampleinfo",
")",
"{",
"// We parse each prediction.",
"switch",
"(",
"count",
"(",
"$",
"sampleinfo",
")",
")",
"{",
"case",
"1",
":",
"// For whatever reason the predictions processor could not process this sample, we",
"// skip it and do nothing with it.",
"debugging",
"(",
"$",
"this",
"->",
"model",
"->",
"id",
".",
"' model predictions processor could not process the sample with id '",
".",
"$",
"sampleinfo",
"[",
"0",
"]",
",",
"DEBUG_DEVELOPER",
")",
";",
"continue",
"2",
";",
"case",
"2",
":",
"// Prediction processors that do not return a prediction score will have the maximum prediction",
"// score.",
"list",
"(",
"$",
"uniquesampleid",
",",
"$",
"prediction",
")",
"=",
"$",
"sampleinfo",
";",
"$",
"predictionscore",
"=",
"1",
";",
"break",
";",
"case",
"3",
":",
"list",
"(",
"$",
"uniquesampleid",
",",
"$",
"prediction",
",",
"$",
"predictionscore",
")",
"=",
"$",
"sampleinfo",
";",
"break",
";",
"default",
":",
"break",
";",
"}",
"$",
"predictiondata",
"=",
"(",
"object",
")",
"[",
"'prediction'",
"=>",
"$",
"prediction",
",",
"'predictionscore'",
"=>",
"$",
"predictionscore",
"]",
";",
"$",
"predictions",
"[",
"$",
"uniquesampleid",
"]",
"=",
"$",
"predictiondata",
";",
"}",
"}",
"return",
"$",
"predictions",
";",
"}"
] |
Formats the predictor results.
@param array $predictorresult
@return array
|
[
"Formats",
"the",
"predictor",
"results",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L832-L863
|
216,601
|
moodle/moodle
|
analytics/classes/model.php
|
model.execute_prediction_callbacks
|
protected function execute_prediction_callbacks(&$predictions, $indicatorcalculations) {
// Here we will store all predictions' contexts, this will be used to limit which users will see those predictions.
$samplecontexts = array();
$records = array();
foreach ($predictions as $uniquesampleid => $prediction) {
// The unique sample id contains both the sampleid and the rangeindex.
list($sampleid, $rangeindex) = $this->get_time_splitting()->infer_sample_info($uniquesampleid);
if ($this->get_target()->triggers_callback($prediction->prediction, $prediction->predictionscore)) {
// Prepare the record to store the predicted values.
list($record, $samplecontext) = $this->prepare_prediction_record($sampleid, $rangeindex, $prediction->prediction,
$prediction->predictionscore, json_encode($indicatorcalculations[$uniquesampleid]));
// We will later bulk-insert them all.
$records[$uniquesampleid] = $record;
// Also store all samples context to later generate insights or whatever action the target wants to perform.
$samplecontexts[$samplecontext->id] = $samplecontext;
$this->get_target()->prediction_callback($this->model->id, $sampleid, $rangeindex, $samplecontext,
$prediction->prediction, $prediction->predictionscore);
}
}
if (!empty($records)) {
$this->save_predictions($records);
}
return [$samplecontexts, $records];
}
|
php
|
protected function execute_prediction_callbacks(&$predictions, $indicatorcalculations) {
// Here we will store all predictions' contexts, this will be used to limit which users will see those predictions.
$samplecontexts = array();
$records = array();
foreach ($predictions as $uniquesampleid => $prediction) {
// The unique sample id contains both the sampleid and the rangeindex.
list($sampleid, $rangeindex) = $this->get_time_splitting()->infer_sample_info($uniquesampleid);
if ($this->get_target()->triggers_callback($prediction->prediction, $prediction->predictionscore)) {
// Prepare the record to store the predicted values.
list($record, $samplecontext) = $this->prepare_prediction_record($sampleid, $rangeindex, $prediction->prediction,
$prediction->predictionscore, json_encode($indicatorcalculations[$uniquesampleid]));
// We will later bulk-insert them all.
$records[$uniquesampleid] = $record;
// Also store all samples context to later generate insights or whatever action the target wants to perform.
$samplecontexts[$samplecontext->id] = $samplecontext;
$this->get_target()->prediction_callback($this->model->id, $sampleid, $rangeindex, $samplecontext,
$prediction->prediction, $prediction->predictionscore);
}
}
if (!empty($records)) {
$this->save_predictions($records);
}
return [$samplecontexts, $records];
}
|
[
"protected",
"function",
"execute_prediction_callbacks",
"(",
"&",
"$",
"predictions",
",",
"$",
"indicatorcalculations",
")",
"{",
"// Here we will store all predictions' contexts, this will be used to limit which users will see those predictions.",
"$",
"samplecontexts",
"=",
"array",
"(",
")",
";",
"$",
"records",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"predictions",
"as",
"$",
"uniquesampleid",
"=>",
"$",
"prediction",
")",
"{",
"// The unique sample id contains both the sampleid and the rangeindex.",
"list",
"(",
"$",
"sampleid",
",",
"$",
"rangeindex",
")",
"=",
"$",
"this",
"->",
"get_time_splitting",
"(",
")",
"->",
"infer_sample_info",
"(",
"$",
"uniquesampleid",
")",
";",
"if",
"(",
"$",
"this",
"->",
"get_target",
"(",
")",
"->",
"triggers_callback",
"(",
"$",
"prediction",
"->",
"prediction",
",",
"$",
"prediction",
"->",
"predictionscore",
")",
")",
"{",
"// Prepare the record to store the predicted values.",
"list",
"(",
"$",
"record",
",",
"$",
"samplecontext",
")",
"=",
"$",
"this",
"->",
"prepare_prediction_record",
"(",
"$",
"sampleid",
",",
"$",
"rangeindex",
",",
"$",
"prediction",
"->",
"prediction",
",",
"$",
"prediction",
"->",
"predictionscore",
",",
"json_encode",
"(",
"$",
"indicatorcalculations",
"[",
"$",
"uniquesampleid",
"]",
")",
")",
";",
"// We will later bulk-insert them all.",
"$",
"records",
"[",
"$",
"uniquesampleid",
"]",
"=",
"$",
"record",
";",
"// Also store all samples context to later generate insights or whatever action the target wants to perform.",
"$",
"samplecontexts",
"[",
"$",
"samplecontext",
"->",
"id",
"]",
"=",
"$",
"samplecontext",
";",
"$",
"this",
"->",
"get_target",
"(",
")",
"->",
"prediction_callback",
"(",
"$",
"this",
"->",
"model",
"->",
"id",
",",
"$",
"sampleid",
",",
"$",
"rangeindex",
",",
"$",
"samplecontext",
",",
"$",
"prediction",
"->",
"prediction",
",",
"$",
"prediction",
"->",
"predictionscore",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"records",
")",
")",
"{",
"$",
"this",
"->",
"save_predictions",
"(",
"$",
"records",
")",
";",
"}",
"return",
"[",
"$",
"samplecontexts",
",",
"$",
"records",
"]",
";",
"}"
] |
Execute the prediction callbacks defined by the target.
@param \stdClass[] $predictions
@param array $indicatorcalculations
@return array
|
[
"Execute",
"the",
"prediction",
"callbacks",
"defined",
"by",
"the",
"target",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L872-L904
|
216,602
|
moodle/moodle
|
analytics/classes/model.php
|
model.trigger_insights
|
protected function trigger_insights($samplecontexts, $predictionrecords) {
// Notify the target that all predictions have been processed.
if ($this->get_analyser()::one_sample_per_analysable()) {
// We need to do something unusual here. self::save_predictions uses the bulk-insert function (insert_records()) for
// performance reasons and that function does not return us the inserted ids. We need to retrieve them from
// the database, and we need to do it using one single database query (for performance reasons as well).
$predictionrecords = $this->add_prediction_ids($predictionrecords);
// Get \core_analytics\prediction objects also fetching the samplesdata. This costs us
// 1 db read, but we have to pay it if we want that our insights include links to the
// suggested actions.
$predictions = array_map(function($predictionobj) {
$prediction = new \core_analytics\prediction($predictionobj, $this->prediction_sample_data($predictionobj));
return $prediction;
}, $predictionrecords);
} else {
$predictions = [];
}
$this->get_target()->generate_insight_notifications($this->model->id, $samplecontexts, $predictions);
// Update cache.
$cache = \cache::make('core', 'contextwithinsights');
foreach ($samplecontexts as $context) {
$modelids = $cache->get($context->id);
if (!$modelids) {
// The cache is empty, but we don't know if it is empty because there are no insights
// in this context or because cache/s have been purged, we need to be conservative and
// "pay" 1 db read to fill up the cache.
$models = \core_analytics\manager::get_models_with_insights($context);
$cache->set($context->id, array_keys($models));
} else if (!in_array($this->get_id(), $modelids)) {
array_push($modelids, $this->get_id());
$cache->set($context->id, $modelids);
}
}
}
|
php
|
protected function trigger_insights($samplecontexts, $predictionrecords) {
// Notify the target that all predictions have been processed.
if ($this->get_analyser()::one_sample_per_analysable()) {
// We need to do something unusual here. self::save_predictions uses the bulk-insert function (insert_records()) for
// performance reasons and that function does not return us the inserted ids. We need to retrieve them from
// the database, and we need to do it using one single database query (for performance reasons as well).
$predictionrecords = $this->add_prediction_ids($predictionrecords);
// Get \core_analytics\prediction objects also fetching the samplesdata. This costs us
// 1 db read, but we have to pay it if we want that our insights include links to the
// suggested actions.
$predictions = array_map(function($predictionobj) {
$prediction = new \core_analytics\prediction($predictionobj, $this->prediction_sample_data($predictionobj));
return $prediction;
}, $predictionrecords);
} else {
$predictions = [];
}
$this->get_target()->generate_insight_notifications($this->model->id, $samplecontexts, $predictions);
// Update cache.
$cache = \cache::make('core', 'contextwithinsights');
foreach ($samplecontexts as $context) {
$modelids = $cache->get($context->id);
if (!$modelids) {
// The cache is empty, but we don't know if it is empty because there are no insights
// in this context or because cache/s have been purged, we need to be conservative and
// "pay" 1 db read to fill up the cache.
$models = \core_analytics\manager::get_models_with_insights($context);
$cache->set($context->id, array_keys($models));
} else if (!in_array($this->get_id(), $modelids)) {
array_push($modelids, $this->get_id());
$cache->set($context->id, $modelids);
}
}
}
|
[
"protected",
"function",
"trigger_insights",
"(",
"$",
"samplecontexts",
",",
"$",
"predictionrecords",
")",
"{",
"// Notify the target that all predictions have been processed.",
"if",
"(",
"$",
"this",
"->",
"get_analyser",
"(",
")",
"::",
"one_sample_per_analysable",
"(",
")",
")",
"{",
"// We need to do something unusual here. self::save_predictions uses the bulk-insert function (insert_records()) for",
"// performance reasons and that function does not return us the inserted ids. We need to retrieve them from",
"// the database, and we need to do it using one single database query (for performance reasons as well).",
"$",
"predictionrecords",
"=",
"$",
"this",
"->",
"add_prediction_ids",
"(",
"$",
"predictionrecords",
")",
";",
"// Get \\core_analytics\\prediction objects also fetching the samplesdata. This costs us",
"// 1 db read, but we have to pay it if we want that our insights include links to the",
"// suggested actions.",
"$",
"predictions",
"=",
"array_map",
"(",
"function",
"(",
"$",
"predictionobj",
")",
"{",
"$",
"prediction",
"=",
"new",
"\\",
"core_analytics",
"\\",
"prediction",
"(",
"$",
"predictionobj",
",",
"$",
"this",
"->",
"prediction_sample_data",
"(",
"$",
"predictionobj",
")",
")",
";",
"return",
"$",
"prediction",
";",
"}",
",",
"$",
"predictionrecords",
")",
";",
"}",
"else",
"{",
"$",
"predictions",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"get_target",
"(",
")",
"->",
"generate_insight_notifications",
"(",
"$",
"this",
"->",
"model",
"->",
"id",
",",
"$",
"samplecontexts",
",",
"$",
"predictions",
")",
";",
"// Update cache.",
"$",
"cache",
"=",
"\\",
"cache",
"::",
"make",
"(",
"'core'",
",",
"'contextwithinsights'",
")",
";",
"foreach",
"(",
"$",
"samplecontexts",
"as",
"$",
"context",
")",
"{",
"$",
"modelids",
"=",
"$",
"cache",
"->",
"get",
"(",
"$",
"context",
"->",
"id",
")",
";",
"if",
"(",
"!",
"$",
"modelids",
")",
"{",
"// The cache is empty, but we don't know if it is empty because there are no insights",
"// in this context or because cache/s have been purged, we need to be conservative and",
"// \"pay\" 1 db read to fill up the cache.",
"$",
"models",
"=",
"\\",
"core_analytics",
"\\",
"manager",
"::",
"get_models_with_insights",
"(",
"$",
"context",
")",
";",
"$",
"cache",
"->",
"set",
"(",
"$",
"context",
"->",
"id",
",",
"array_keys",
"(",
"$",
"models",
")",
")",
";",
"}",
"else",
"if",
"(",
"!",
"in_array",
"(",
"$",
"this",
"->",
"get_id",
"(",
")",
",",
"$",
"modelids",
")",
")",
"{",
"array_push",
"(",
"$",
"modelids",
",",
"$",
"this",
"->",
"get_id",
"(",
")",
")",
";",
"$",
"cache",
"->",
"set",
"(",
"$",
"context",
"->",
"id",
",",
"$",
"modelids",
")",
";",
"}",
"}",
"}"
] |
Generates insights and updates the cache.
@param \context[] $samplecontexts
@param \stdClass[] $predictionrecords
@return void
|
[
"Generates",
"insights",
"and",
"updates",
"the",
"cache",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L913-L951
|
216,603
|
moodle/moodle
|
analytics/classes/model.php
|
model.prepare_prediction_record
|
protected function prepare_prediction_record($sampleid, $rangeindex, $prediction, $predictionscore, $calculations) {
$context = $this->get_analyser()->sample_access_context($sampleid);
$record = new \stdClass();
$record->modelid = $this->model->id;
$record->contextid = $context->id;
$record->sampleid = $sampleid;
$record->rangeindex = $rangeindex;
$record->prediction = $prediction;
$record->predictionscore = $predictionscore;
$record->calculations = $calculations;
$record->timecreated = time();
$analysable = $this->get_analyser()->get_sample_analysable($sampleid);
$timesplitting = $this->get_time_splitting();
$timesplitting->set_analysable($analysable);
$range = $timesplitting->get_range_by_index($rangeindex);
if ($range) {
$record->timestart = $range['start'];
$record->timeend = $range['end'];
}
return array($record, $context);
}
|
php
|
protected function prepare_prediction_record($sampleid, $rangeindex, $prediction, $predictionscore, $calculations) {
$context = $this->get_analyser()->sample_access_context($sampleid);
$record = new \stdClass();
$record->modelid = $this->model->id;
$record->contextid = $context->id;
$record->sampleid = $sampleid;
$record->rangeindex = $rangeindex;
$record->prediction = $prediction;
$record->predictionscore = $predictionscore;
$record->calculations = $calculations;
$record->timecreated = time();
$analysable = $this->get_analyser()->get_sample_analysable($sampleid);
$timesplitting = $this->get_time_splitting();
$timesplitting->set_analysable($analysable);
$range = $timesplitting->get_range_by_index($rangeindex);
if ($range) {
$record->timestart = $range['start'];
$record->timeend = $range['end'];
}
return array($record, $context);
}
|
[
"protected",
"function",
"prepare_prediction_record",
"(",
"$",
"sampleid",
",",
"$",
"rangeindex",
",",
"$",
"prediction",
",",
"$",
"predictionscore",
",",
"$",
"calculations",
")",
"{",
"$",
"context",
"=",
"$",
"this",
"->",
"get_analyser",
"(",
")",
"->",
"sample_access_context",
"(",
"$",
"sampleid",
")",
";",
"$",
"record",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"record",
"->",
"modelid",
"=",
"$",
"this",
"->",
"model",
"->",
"id",
";",
"$",
"record",
"->",
"contextid",
"=",
"$",
"context",
"->",
"id",
";",
"$",
"record",
"->",
"sampleid",
"=",
"$",
"sampleid",
";",
"$",
"record",
"->",
"rangeindex",
"=",
"$",
"rangeindex",
";",
"$",
"record",
"->",
"prediction",
"=",
"$",
"prediction",
";",
"$",
"record",
"->",
"predictionscore",
"=",
"$",
"predictionscore",
";",
"$",
"record",
"->",
"calculations",
"=",
"$",
"calculations",
";",
"$",
"record",
"->",
"timecreated",
"=",
"time",
"(",
")",
";",
"$",
"analysable",
"=",
"$",
"this",
"->",
"get_analyser",
"(",
")",
"->",
"get_sample_analysable",
"(",
"$",
"sampleid",
")",
";",
"$",
"timesplitting",
"=",
"$",
"this",
"->",
"get_time_splitting",
"(",
")",
";",
"$",
"timesplitting",
"->",
"set_analysable",
"(",
"$",
"analysable",
")",
";",
"$",
"range",
"=",
"$",
"timesplitting",
"->",
"get_range_by_index",
"(",
"$",
"rangeindex",
")",
";",
"if",
"(",
"$",
"range",
")",
"{",
"$",
"record",
"->",
"timestart",
"=",
"$",
"range",
"[",
"'start'",
"]",
";",
"$",
"record",
"->",
"timeend",
"=",
"$",
"range",
"[",
"'end'",
"]",
";",
"}",
"return",
"array",
"(",
"$",
"record",
",",
"$",
"context",
")",
";",
"}"
] |
Stores the prediction in the database.
@param int $sampleid
@param int $rangeindex
@param int $prediction
@param float $predictionscore
@param string $calculations
@return \context
|
[
"Stores",
"the",
"prediction",
"in",
"the",
"database",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L1064-L1087
|
216,604
|
moodle/moodle
|
analytics/classes/model.php
|
model.enable
|
public function enable($timesplittingid = false) {
global $DB, $USER;
$now = time();
if ($timesplittingid && $timesplittingid !== $this->model->timesplitting) {
if (!\core_analytics\manager::is_valid($timesplittingid, '\core_analytics\local\time_splitting\base')) {
throw new \moodle_exception('errorinvalidtimesplitting', 'analytics');
}
if (substr($timesplittingid, 0, 1) !== '\\') {
throw new \moodle_exception('errorinvalidtimesplitting', 'analytics');
}
// Delete generated predictions before changing the model version.
$this->clear();
// It needs to be reset as the version changes.
$this->uniqueid = null;
$this->model->timesplitting = $timesplittingid;
$this->model->version = $now;
// Reset trained flag.
if (!$this->is_static()) {
$this->model->trained = 0;
}
} else if (empty($this->model->timesplitting)) {
// A valid timesplitting method needs to be supplied before a model can be enabled.
throw new \moodle_exception('invalidtimesplitting', 'analytics', '', $this->model->id);
}
// Purge pages with insights as this may change things.
if ($this->model->enabled != 1) {
$this->purge_insights_cache();
}
$this->model->enabled = 1;
$this->model->timemodified = $now;
$this->model->usermodified = $USER->id;
// We don't always update timemodified intentionally as we reserve it for target, indicators or timesplitting updates.
$DB->update_record('analytics_models', $this->model);
}
|
php
|
public function enable($timesplittingid = false) {
global $DB, $USER;
$now = time();
if ($timesplittingid && $timesplittingid !== $this->model->timesplitting) {
if (!\core_analytics\manager::is_valid($timesplittingid, '\core_analytics\local\time_splitting\base')) {
throw new \moodle_exception('errorinvalidtimesplitting', 'analytics');
}
if (substr($timesplittingid, 0, 1) !== '\\') {
throw new \moodle_exception('errorinvalidtimesplitting', 'analytics');
}
// Delete generated predictions before changing the model version.
$this->clear();
// It needs to be reset as the version changes.
$this->uniqueid = null;
$this->model->timesplitting = $timesplittingid;
$this->model->version = $now;
// Reset trained flag.
if (!$this->is_static()) {
$this->model->trained = 0;
}
} else if (empty($this->model->timesplitting)) {
// A valid timesplitting method needs to be supplied before a model can be enabled.
throw new \moodle_exception('invalidtimesplitting', 'analytics', '', $this->model->id);
}
// Purge pages with insights as this may change things.
if ($this->model->enabled != 1) {
$this->purge_insights_cache();
}
$this->model->enabled = 1;
$this->model->timemodified = $now;
$this->model->usermodified = $USER->id;
// We don't always update timemodified intentionally as we reserve it for target, indicators or timesplitting updates.
$DB->update_record('analytics_models', $this->model);
}
|
[
"public",
"function",
"enable",
"(",
"$",
"timesplittingid",
"=",
"false",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"USER",
";",
"$",
"now",
"=",
"time",
"(",
")",
";",
"if",
"(",
"$",
"timesplittingid",
"&&",
"$",
"timesplittingid",
"!==",
"$",
"this",
"->",
"model",
"->",
"timesplitting",
")",
"{",
"if",
"(",
"!",
"\\",
"core_analytics",
"\\",
"manager",
"::",
"is_valid",
"(",
"$",
"timesplittingid",
",",
"'\\core_analytics\\local\\time_splitting\\base'",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'errorinvalidtimesplitting'",
",",
"'analytics'",
")",
";",
"}",
"if",
"(",
"substr",
"(",
"$",
"timesplittingid",
",",
"0",
",",
"1",
")",
"!==",
"'\\\\'",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'errorinvalidtimesplitting'",
",",
"'analytics'",
")",
";",
"}",
"// Delete generated predictions before changing the model version.",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"// It needs to be reset as the version changes.",
"$",
"this",
"->",
"uniqueid",
"=",
"null",
";",
"$",
"this",
"->",
"model",
"->",
"timesplitting",
"=",
"$",
"timesplittingid",
";",
"$",
"this",
"->",
"model",
"->",
"version",
"=",
"$",
"now",
";",
"// Reset trained flag.",
"if",
"(",
"!",
"$",
"this",
"->",
"is_static",
"(",
")",
")",
"{",
"$",
"this",
"->",
"model",
"->",
"trained",
"=",
"0",
";",
"}",
"}",
"else",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"model",
"->",
"timesplitting",
")",
")",
"{",
"// A valid timesplitting method needs to be supplied before a model can be enabled.",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'invalidtimesplitting'",
",",
"'analytics'",
",",
"''",
",",
"$",
"this",
"->",
"model",
"->",
"id",
")",
";",
"}",
"// Purge pages with insights as this may change things.",
"if",
"(",
"$",
"this",
"->",
"model",
"->",
"enabled",
"!=",
"1",
")",
"{",
"$",
"this",
"->",
"purge_insights_cache",
"(",
")",
";",
"}",
"$",
"this",
"->",
"model",
"->",
"enabled",
"=",
"1",
";",
"$",
"this",
"->",
"model",
"->",
"timemodified",
"=",
"$",
"now",
";",
"$",
"this",
"->",
"model",
"->",
"usermodified",
"=",
"$",
"USER",
"->",
"id",
";",
"// We don't always update timemodified intentionally as we reserve it for target, indicators or timesplitting updates.",
"$",
"DB",
"->",
"update_record",
"(",
"'analytics_models'",
",",
"$",
"this",
"->",
"model",
")",
";",
"}"
] |
Enabled the model using the provided time splitting method.
@param string|false $timesplittingid False to respect the current time splitting method.
@return void
|
[
"Enabled",
"the",
"model",
"using",
"the",
"provided",
"time",
"splitting",
"method",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L1105-L1150
|
216,605
|
moodle/moodle
|
analytics/classes/model.php
|
model.mark_as_trained
|
public function mark_as_trained() {
global $DB;
\core_analytics\manager::check_can_manage_models();
$this->model->trained = 1;
$DB->update_record('analytics_models', $this->model);
}
|
php
|
public function mark_as_trained() {
global $DB;
\core_analytics\manager::check_can_manage_models();
$this->model->trained = 1;
$DB->update_record('analytics_models', $this->model);
}
|
[
"public",
"function",
"mark_as_trained",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"\\",
"core_analytics",
"\\",
"manager",
"::",
"check_can_manage_models",
"(",
")",
";",
"$",
"this",
"->",
"model",
"->",
"trained",
"=",
"1",
";",
"$",
"DB",
"->",
"update_record",
"(",
"'analytics_models'",
",",
"$",
"this",
"->",
"model",
")",
";",
"}"
] |
Marks the model as trained
@return void
|
[
"Marks",
"the",
"model",
"as",
"trained"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L1188-L1195
|
216,606
|
moodle/moodle
|
analytics/classes/model.php
|
model.get_predictions_contexts
|
public function get_predictions_contexts($skiphidden = true) {
global $DB, $USER;
$sql = "SELECT DISTINCT ap.contextid FROM {analytics_predictions} ap
JOIN {context} ctx ON ctx.id = ap.contextid
WHERE ap.modelid = :modelid";
$params = array('modelid' => $this->model->id);
if ($skiphidden) {
$sql .= " AND NOT EXISTS (
SELECT 1
FROM {analytics_prediction_actions} apa
WHERE apa.predictionid = ap.id AND apa.userid = :userid AND (apa.actionname = :fixed OR apa.actionname = :notuseful)
)";
$params['userid'] = $USER->id;
$params['fixed'] = \core_analytics\prediction::ACTION_FIXED;
$params['notuseful'] = \core_analytics\prediction::ACTION_NOT_USEFUL;
}
return $DB->get_records_sql($sql, $params);
}
|
php
|
public function get_predictions_contexts($skiphidden = true) {
global $DB, $USER;
$sql = "SELECT DISTINCT ap.contextid FROM {analytics_predictions} ap
JOIN {context} ctx ON ctx.id = ap.contextid
WHERE ap.modelid = :modelid";
$params = array('modelid' => $this->model->id);
if ($skiphidden) {
$sql .= " AND NOT EXISTS (
SELECT 1
FROM {analytics_prediction_actions} apa
WHERE apa.predictionid = ap.id AND apa.userid = :userid AND (apa.actionname = :fixed OR apa.actionname = :notuseful)
)";
$params['userid'] = $USER->id;
$params['fixed'] = \core_analytics\prediction::ACTION_FIXED;
$params['notuseful'] = \core_analytics\prediction::ACTION_NOT_USEFUL;
}
return $DB->get_records_sql($sql, $params);
}
|
[
"public",
"function",
"get_predictions_contexts",
"(",
"$",
"skiphidden",
"=",
"true",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"USER",
";",
"$",
"sql",
"=",
"\"SELECT DISTINCT ap.contextid FROM {analytics_predictions} ap\n JOIN {context} ctx ON ctx.id = ap.contextid\n WHERE ap.modelid = :modelid\"",
";",
"$",
"params",
"=",
"array",
"(",
"'modelid'",
"=>",
"$",
"this",
"->",
"model",
"->",
"id",
")",
";",
"if",
"(",
"$",
"skiphidden",
")",
"{",
"$",
"sql",
".=",
"\" AND NOT EXISTS (\n SELECT 1\n FROM {analytics_prediction_actions} apa\n WHERE apa.predictionid = ap.id AND apa.userid = :userid AND (apa.actionname = :fixed OR apa.actionname = :notuseful)\n )\"",
";",
"$",
"params",
"[",
"'userid'",
"]",
"=",
"$",
"USER",
"->",
"id",
";",
"$",
"params",
"[",
"'fixed'",
"]",
"=",
"\\",
"core_analytics",
"\\",
"prediction",
"::",
"ACTION_FIXED",
";",
"$",
"params",
"[",
"'notuseful'",
"]",
"=",
"\\",
"core_analytics",
"\\",
"prediction",
"::",
"ACTION_NOT_USEFUL",
";",
"}",
"return",
"$",
"DB",
"->",
"get_records_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"}"
] |
Get the contexts with predictions.
@param bool $skiphidden Skip hidden predictions
@return \stdClass[]
|
[
"Get",
"the",
"contexts",
"with",
"predictions",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L1203-L1223
|
216,607
|
moodle/moodle
|
analytics/classes/model.php
|
model.any_prediction_obtained
|
public function any_prediction_obtained() {
global $DB;
return $DB->record_exists('analytics_predict_samples',
array('modelid' => $this->model->id, 'timesplitting' => $this->model->timesplitting));
}
|
php
|
public function any_prediction_obtained() {
global $DB;
return $DB->record_exists('analytics_predict_samples',
array('modelid' => $this->model->id, 'timesplitting' => $this->model->timesplitting));
}
|
[
"public",
"function",
"any_prediction_obtained",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"return",
"$",
"DB",
"->",
"record_exists",
"(",
"'analytics_predict_samples'",
",",
"array",
"(",
"'modelid'",
"=>",
"$",
"this",
"->",
"model",
"->",
"id",
",",
"'timesplitting'",
"=>",
"$",
"this",
"->",
"model",
"->",
"timesplitting",
")",
")",
";",
"}"
] |
Has this model generated predictions?
We don't check analytics_predictions table because targets have the ability to
ignore some predicted values, if that is the case predictions are not even stored
in db.
@return bool
|
[
"Has",
"this",
"model",
"generated",
"predictions?"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L1234-L1238
|
216,608
|
moodle/moodle
|
analytics/classes/model.php
|
model.predictions_exist
|
public function predictions_exist(\context $context) {
global $DB;
// Filters out previous predictions keeping only the last time range one.
$select = "modelid = :modelid AND contextid = :contextid";
$params = array('modelid' => $this->model->id, 'contextid' => $context->id);
return $DB->record_exists_select('analytics_predictions', $select, $params);
}
|
php
|
public function predictions_exist(\context $context) {
global $DB;
// Filters out previous predictions keeping only the last time range one.
$select = "modelid = :modelid AND contextid = :contextid";
$params = array('modelid' => $this->model->id, 'contextid' => $context->id);
return $DB->record_exists_select('analytics_predictions', $select, $params);
}
|
[
"public",
"function",
"predictions_exist",
"(",
"\\",
"context",
"$",
"context",
")",
"{",
"global",
"$",
"DB",
";",
"// Filters out previous predictions keeping only the last time range one.",
"$",
"select",
"=",
"\"modelid = :modelid AND contextid = :contextid\"",
";",
"$",
"params",
"=",
"array",
"(",
"'modelid'",
"=>",
"$",
"this",
"->",
"model",
"->",
"id",
",",
"'contextid'",
"=>",
"$",
"context",
"->",
"id",
")",
";",
"return",
"$",
"DB",
"->",
"record_exists_select",
"(",
"'analytics_predictions'",
",",
"$",
"select",
",",
"$",
"params",
")",
";",
"}"
] |
Whether predictions exist for this context.
@param \context $context
@return bool
|
[
"Whether",
"predictions",
"exist",
"for",
"this",
"context",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L1256-L1263
|
216,609
|
moodle/moodle
|
analytics/classes/model.php
|
model.get_predictions
|
public function get_predictions(\context $context, $skiphidden = true, $page = false, $perpage = 100) {
global $DB, $USER;
\core_analytics\manager::check_can_list_insights($context);
// Filters out previous predictions keeping only the last time range one.
$sql = "SELECT ap.*
FROM {analytics_predictions} ap
JOIN (
SELECT sampleid, max(rangeindex) AS rangeindex
FROM {analytics_predictions}
WHERE modelid = :modelidsubap and contextid = :contextidsubap
GROUP BY sampleid
) apsub
ON ap.sampleid = apsub.sampleid AND ap.rangeindex = apsub.rangeindex
WHERE ap.modelid = :modelid and ap.contextid = :contextid";
$params = array('modelid' => $this->model->id, 'contextid' => $context->id,
'modelidsubap' => $this->model->id, 'contextidsubap' => $context->id);
if ($skiphidden) {
$sql .= " AND NOT EXISTS (
SELECT 1
FROM {analytics_prediction_actions} apa
WHERE apa.predictionid = ap.id AND apa.userid = :userid AND (apa.actionname = :fixed OR apa.actionname = :notuseful)
)";
$params['userid'] = $USER->id;
$params['fixed'] = \core_analytics\prediction::ACTION_FIXED;
$params['notuseful'] = \core_analytics\prediction::ACTION_NOT_USEFUL;
}
$sql .= " ORDER BY ap.timecreated DESC";
if (!$predictions = $DB->get_records_sql($sql, $params)) {
return array();
}
// Get predicted samples' ids.
$sampleids = array_map(function($prediction) {
return $prediction->sampleid;
}, $predictions);
list($unused, $samplesdata) = $this->get_analyser()->get_samples($sampleids);
$current = 0;
if ($page !== false) {
$offset = $page * $perpage;
$limit = $offset + $perpage;
}
foreach ($predictions as $predictionid => $predictiondata) {
$sampleid = $predictiondata->sampleid;
// Filter out predictions which samples are not available anymore.
if (empty($samplesdata[$sampleid])) {
unset($predictions[$predictionid]);
continue;
}
// Return paginated dataset - we cannot paginate in the DB because we post filter the list.
if ($page === false || ($current >= $offset && $current < $limit)) {
// Replace \stdClass object by \core_analytics\prediction objects.
$prediction = new \core_analytics\prediction($predictiondata, $samplesdata[$sampleid]);
$predictions[$predictionid] = $prediction;
} else {
unset($predictions[$predictionid]);
}
$current++;
}
return [$current, $predictions];
}
|
php
|
public function get_predictions(\context $context, $skiphidden = true, $page = false, $perpage = 100) {
global $DB, $USER;
\core_analytics\manager::check_can_list_insights($context);
// Filters out previous predictions keeping only the last time range one.
$sql = "SELECT ap.*
FROM {analytics_predictions} ap
JOIN (
SELECT sampleid, max(rangeindex) AS rangeindex
FROM {analytics_predictions}
WHERE modelid = :modelidsubap and contextid = :contextidsubap
GROUP BY sampleid
) apsub
ON ap.sampleid = apsub.sampleid AND ap.rangeindex = apsub.rangeindex
WHERE ap.modelid = :modelid and ap.contextid = :contextid";
$params = array('modelid' => $this->model->id, 'contextid' => $context->id,
'modelidsubap' => $this->model->id, 'contextidsubap' => $context->id);
if ($skiphidden) {
$sql .= " AND NOT EXISTS (
SELECT 1
FROM {analytics_prediction_actions} apa
WHERE apa.predictionid = ap.id AND apa.userid = :userid AND (apa.actionname = :fixed OR apa.actionname = :notuseful)
)";
$params['userid'] = $USER->id;
$params['fixed'] = \core_analytics\prediction::ACTION_FIXED;
$params['notuseful'] = \core_analytics\prediction::ACTION_NOT_USEFUL;
}
$sql .= " ORDER BY ap.timecreated DESC";
if (!$predictions = $DB->get_records_sql($sql, $params)) {
return array();
}
// Get predicted samples' ids.
$sampleids = array_map(function($prediction) {
return $prediction->sampleid;
}, $predictions);
list($unused, $samplesdata) = $this->get_analyser()->get_samples($sampleids);
$current = 0;
if ($page !== false) {
$offset = $page * $perpage;
$limit = $offset + $perpage;
}
foreach ($predictions as $predictionid => $predictiondata) {
$sampleid = $predictiondata->sampleid;
// Filter out predictions which samples are not available anymore.
if (empty($samplesdata[$sampleid])) {
unset($predictions[$predictionid]);
continue;
}
// Return paginated dataset - we cannot paginate in the DB because we post filter the list.
if ($page === false || ($current >= $offset && $current < $limit)) {
// Replace \stdClass object by \core_analytics\prediction objects.
$prediction = new \core_analytics\prediction($predictiondata, $samplesdata[$sampleid]);
$predictions[$predictionid] = $prediction;
} else {
unset($predictions[$predictionid]);
}
$current++;
}
return [$current, $predictions];
}
|
[
"public",
"function",
"get_predictions",
"(",
"\\",
"context",
"$",
"context",
",",
"$",
"skiphidden",
"=",
"true",
",",
"$",
"page",
"=",
"false",
",",
"$",
"perpage",
"=",
"100",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"USER",
";",
"\\",
"core_analytics",
"\\",
"manager",
"::",
"check_can_list_insights",
"(",
"$",
"context",
")",
";",
"// Filters out previous predictions keeping only the last time range one.",
"$",
"sql",
"=",
"\"SELECT ap.*\n FROM {analytics_predictions} ap\n JOIN (\n SELECT sampleid, max(rangeindex) AS rangeindex\n FROM {analytics_predictions}\n WHERE modelid = :modelidsubap and contextid = :contextidsubap\n GROUP BY sampleid\n ) apsub\n ON ap.sampleid = apsub.sampleid AND ap.rangeindex = apsub.rangeindex\n WHERE ap.modelid = :modelid and ap.contextid = :contextid\"",
";",
"$",
"params",
"=",
"array",
"(",
"'modelid'",
"=>",
"$",
"this",
"->",
"model",
"->",
"id",
",",
"'contextid'",
"=>",
"$",
"context",
"->",
"id",
",",
"'modelidsubap'",
"=>",
"$",
"this",
"->",
"model",
"->",
"id",
",",
"'contextidsubap'",
"=>",
"$",
"context",
"->",
"id",
")",
";",
"if",
"(",
"$",
"skiphidden",
")",
"{",
"$",
"sql",
".=",
"\" AND NOT EXISTS (\n SELECT 1\n FROM {analytics_prediction_actions} apa\n WHERE apa.predictionid = ap.id AND apa.userid = :userid AND (apa.actionname = :fixed OR apa.actionname = :notuseful)\n )\"",
";",
"$",
"params",
"[",
"'userid'",
"]",
"=",
"$",
"USER",
"->",
"id",
";",
"$",
"params",
"[",
"'fixed'",
"]",
"=",
"\\",
"core_analytics",
"\\",
"prediction",
"::",
"ACTION_FIXED",
";",
"$",
"params",
"[",
"'notuseful'",
"]",
"=",
"\\",
"core_analytics",
"\\",
"prediction",
"::",
"ACTION_NOT_USEFUL",
";",
"}",
"$",
"sql",
".=",
"\" ORDER BY ap.timecreated DESC\"",
";",
"if",
"(",
"!",
"$",
"predictions",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"// Get predicted samples' ids.",
"$",
"sampleids",
"=",
"array_map",
"(",
"function",
"(",
"$",
"prediction",
")",
"{",
"return",
"$",
"prediction",
"->",
"sampleid",
";",
"}",
",",
"$",
"predictions",
")",
";",
"list",
"(",
"$",
"unused",
",",
"$",
"samplesdata",
")",
"=",
"$",
"this",
"->",
"get_analyser",
"(",
")",
"->",
"get_samples",
"(",
"$",
"sampleids",
")",
";",
"$",
"current",
"=",
"0",
";",
"if",
"(",
"$",
"page",
"!==",
"false",
")",
"{",
"$",
"offset",
"=",
"$",
"page",
"*",
"$",
"perpage",
";",
"$",
"limit",
"=",
"$",
"offset",
"+",
"$",
"perpage",
";",
"}",
"foreach",
"(",
"$",
"predictions",
"as",
"$",
"predictionid",
"=>",
"$",
"predictiondata",
")",
"{",
"$",
"sampleid",
"=",
"$",
"predictiondata",
"->",
"sampleid",
";",
"// Filter out predictions which samples are not available anymore.",
"if",
"(",
"empty",
"(",
"$",
"samplesdata",
"[",
"$",
"sampleid",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"predictions",
"[",
"$",
"predictionid",
"]",
")",
";",
"continue",
";",
"}",
"// Return paginated dataset - we cannot paginate in the DB because we post filter the list.",
"if",
"(",
"$",
"page",
"===",
"false",
"||",
"(",
"$",
"current",
">=",
"$",
"offset",
"&&",
"$",
"current",
"<",
"$",
"limit",
")",
")",
"{",
"// Replace \\stdClass object by \\core_analytics\\prediction objects.",
"$",
"prediction",
"=",
"new",
"\\",
"core_analytics",
"\\",
"prediction",
"(",
"$",
"predictiondata",
",",
"$",
"samplesdata",
"[",
"$",
"sampleid",
"]",
")",
";",
"$",
"predictions",
"[",
"$",
"predictionid",
"]",
"=",
"$",
"prediction",
";",
"}",
"else",
"{",
"unset",
"(",
"$",
"predictions",
"[",
"$",
"predictionid",
"]",
")",
";",
"}",
"$",
"current",
"++",
";",
"}",
"return",
"[",
"$",
"current",
",",
"$",
"predictions",
"]",
";",
"}"
] |
Gets the predictions for this context.
@param \context $context
@param bool $skiphidden Skip hidden predictions
@param int $page The page of results to fetch. False for all results.
@param int $perpage The max number of results to fetch. Ignored if $page is false.
@return array($total, \core_analytics\prediction[])
|
[
"Gets",
"the",
"predictions",
"for",
"this",
"context",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L1274-L1347
|
216,610
|
moodle/moodle
|
analytics/classes/model.php
|
model.prediction_sample_data
|
public function prediction_sample_data($predictionobj) {
list($unused, $samplesdata) = $this->get_analyser()->get_samples(array($predictionobj->sampleid));
if (empty($samplesdata[$predictionobj->sampleid])) {
throw new \moodle_exception('errorsamplenotavailable', 'analytics');
}
return $samplesdata[$predictionobj->sampleid];
}
|
php
|
public function prediction_sample_data($predictionobj) {
list($unused, $samplesdata) = $this->get_analyser()->get_samples(array($predictionobj->sampleid));
if (empty($samplesdata[$predictionobj->sampleid])) {
throw new \moodle_exception('errorsamplenotavailable', 'analytics');
}
return $samplesdata[$predictionobj->sampleid];
}
|
[
"public",
"function",
"prediction_sample_data",
"(",
"$",
"predictionobj",
")",
"{",
"list",
"(",
"$",
"unused",
",",
"$",
"samplesdata",
")",
"=",
"$",
"this",
"->",
"get_analyser",
"(",
")",
"->",
"get_samples",
"(",
"array",
"(",
"$",
"predictionobj",
"->",
"sampleid",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"samplesdata",
"[",
"$",
"predictionobj",
"->",
"sampleid",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'errorsamplenotavailable'",
",",
"'analytics'",
")",
";",
"}",
"return",
"$",
"samplesdata",
"[",
"$",
"predictionobj",
"->",
"sampleid",
"]",
";",
"}"
] |
Returns the sample data of a prediction.
@param \stdClass $predictionobj
@return array
|
[
"Returns",
"the",
"sample",
"data",
"of",
"a",
"prediction",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L1355-L1364
|
216,611
|
moodle/moodle
|
analytics/classes/model.php
|
model.prediction_sample_description
|
public function prediction_sample_description(\core_analytics\prediction $prediction) {
return $this->get_analyser()->sample_description($prediction->get_prediction_data()->sampleid,
$prediction->get_prediction_data()->contextid, $prediction->get_sample_data());
}
|
php
|
public function prediction_sample_description(\core_analytics\prediction $prediction) {
return $this->get_analyser()->sample_description($prediction->get_prediction_data()->sampleid,
$prediction->get_prediction_data()->contextid, $prediction->get_sample_data());
}
|
[
"public",
"function",
"prediction_sample_description",
"(",
"\\",
"core_analytics",
"\\",
"prediction",
"$",
"prediction",
")",
"{",
"return",
"$",
"this",
"->",
"get_analyser",
"(",
")",
"->",
"sample_description",
"(",
"$",
"prediction",
"->",
"get_prediction_data",
"(",
")",
"->",
"sampleid",
",",
"$",
"prediction",
"->",
"get_prediction_data",
"(",
")",
"->",
"contextid",
",",
"$",
"prediction",
"->",
"get_sample_data",
"(",
")",
")",
";",
"}"
] |
Returns the description of a sample
@param \core_analytics\prediction $prediction
@return array 2 elements: list(string, \renderable)
|
[
"Returns",
"the",
"description",
"of",
"a",
"sample"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L1372-L1375
|
216,612
|
moodle/moodle
|
analytics/classes/model.php
|
model.get_output_dir
|
public function get_output_dir($subdirs = array(), $onlymodelid = false) {
global $CFG;
$subdirstr = '';
foreach ($subdirs as $subdir) {
$subdirstr .= DIRECTORY_SEPARATOR . $subdir;
}
$outputdir = get_config('analytics', 'modeloutputdir');
if (empty($outputdir)) {
// Apply default value.
$outputdir = rtrim($CFG->dataroot, '/') . DIRECTORY_SEPARATOR . 'models';
}
// Append model id.
$outputdir .= DIRECTORY_SEPARATOR . $this->model->id;
if (!$onlymodelid) {
// Append version + subdirs.
$outputdir .= DIRECTORY_SEPARATOR . $this->model->version . $subdirstr;
}
make_writable_directory($outputdir);
return $outputdir;
}
|
php
|
public function get_output_dir($subdirs = array(), $onlymodelid = false) {
global $CFG;
$subdirstr = '';
foreach ($subdirs as $subdir) {
$subdirstr .= DIRECTORY_SEPARATOR . $subdir;
}
$outputdir = get_config('analytics', 'modeloutputdir');
if (empty($outputdir)) {
// Apply default value.
$outputdir = rtrim($CFG->dataroot, '/') . DIRECTORY_SEPARATOR . 'models';
}
// Append model id.
$outputdir .= DIRECTORY_SEPARATOR . $this->model->id;
if (!$onlymodelid) {
// Append version + subdirs.
$outputdir .= DIRECTORY_SEPARATOR . $this->model->version . $subdirstr;
}
make_writable_directory($outputdir);
return $outputdir;
}
|
[
"public",
"function",
"get_output_dir",
"(",
"$",
"subdirs",
"=",
"array",
"(",
")",
",",
"$",
"onlymodelid",
"=",
"false",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"subdirstr",
"=",
"''",
";",
"foreach",
"(",
"$",
"subdirs",
"as",
"$",
"subdir",
")",
"{",
"$",
"subdirstr",
".=",
"DIRECTORY_SEPARATOR",
".",
"$",
"subdir",
";",
"}",
"$",
"outputdir",
"=",
"get_config",
"(",
"'analytics'",
",",
"'modeloutputdir'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"outputdir",
")",
")",
"{",
"// Apply default value.",
"$",
"outputdir",
"=",
"rtrim",
"(",
"$",
"CFG",
"->",
"dataroot",
",",
"'/'",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"'models'",
";",
"}",
"// Append model id.",
"$",
"outputdir",
".=",
"DIRECTORY_SEPARATOR",
".",
"$",
"this",
"->",
"model",
"->",
"id",
";",
"if",
"(",
"!",
"$",
"onlymodelid",
")",
"{",
"// Append version + subdirs.",
"$",
"outputdir",
".=",
"DIRECTORY_SEPARATOR",
".",
"$",
"this",
"->",
"model",
"->",
"version",
".",
"$",
"subdirstr",
";",
"}",
"make_writable_directory",
"(",
"$",
"outputdir",
")",
";",
"return",
"$",
"outputdir",
";",
"}"
] |
Returns the output directory for prediction processors.
Directory structure as follows:
- Evaluation runs:
models/$model->id/$model->version/evaluation/$model->timesplitting
- Training & prediction runs:
models/$model->id/$model->version/execution
@param array $subdirs
@param bool $onlymodelid Preference over $subdirs
@return string
|
[
"Returns",
"the",
"output",
"directory",
"for",
"prediction",
"processors",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L1390-L1414
|
216,613
|
moodle/moodle
|
analytics/classes/model.php
|
model.get_unique_id
|
public function get_unique_id() {
global $CFG;
if (!is_null($this->uniqueid)) {
return $this->uniqueid;
}
// Generate a unique id for this site, this model and this time splitting method, considering the last time
// that the model target and indicators were updated.
$ids = array($CFG->wwwroot, $CFG->prefix, $this->model->id, $this->model->version);
$this->uniqueid = sha1(implode('$$', $ids));
return $this->uniqueid;
}
|
php
|
public function get_unique_id() {
global $CFG;
if (!is_null($this->uniqueid)) {
return $this->uniqueid;
}
// Generate a unique id for this site, this model and this time splitting method, considering the last time
// that the model target and indicators were updated.
$ids = array($CFG->wwwroot, $CFG->prefix, $this->model->id, $this->model->version);
$this->uniqueid = sha1(implode('$$', $ids));
return $this->uniqueid;
}
|
[
"public",
"function",
"get_unique_id",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"uniqueid",
")",
")",
"{",
"return",
"$",
"this",
"->",
"uniqueid",
";",
"}",
"// Generate a unique id for this site, this model and this time splitting method, considering the last time",
"// that the model target and indicators were updated.",
"$",
"ids",
"=",
"array",
"(",
"$",
"CFG",
"->",
"wwwroot",
",",
"$",
"CFG",
"->",
"prefix",
",",
"$",
"this",
"->",
"model",
"->",
"id",
",",
"$",
"this",
"->",
"model",
"->",
"version",
")",
";",
"$",
"this",
"->",
"uniqueid",
"=",
"sha1",
"(",
"implode",
"(",
"'$$'",
",",
"$",
"ids",
")",
")",
";",
"return",
"$",
"this",
"->",
"uniqueid",
";",
"}"
] |
Returns a unique id for this model.
This id should be unique for this site.
@return string
|
[
"Returns",
"a",
"unique",
"id",
"for",
"this",
"model",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L1423-L1436
|
216,614
|
moodle/moodle
|
analytics/classes/model.php
|
model.export
|
public function export(\renderer_base $output) {
\core_analytics\manager::check_can_manage_models();
$data = clone $this->model;
$data->name = $this->inplace_editable_name()->export_for_template($output);
$data->target = $this->get_target()->get_name();
$data->targetclass = $this->get_target()->get_id();
if ($timesplitting = $this->get_time_splitting()) {
$data->timesplitting = $timesplitting->get_name();
}
$data->indicators = array();
foreach ($this->get_indicators() as $indicator) {
$data->indicators[] = $indicator->get_name();
}
return $data;
}
|
php
|
public function export(\renderer_base $output) {
\core_analytics\manager::check_can_manage_models();
$data = clone $this->model;
$data->name = $this->inplace_editable_name()->export_for_template($output);
$data->target = $this->get_target()->get_name();
$data->targetclass = $this->get_target()->get_id();
if ($timesplitting = $this->get_time_splitting()) {
$data->timesplitting = $timesplitting->get_name();
}
$data->indicators = array();
foreach ($this->get_indicators() as $indicator) {
$data->indicators[] = $indicator->get_name();
}
return $data;
}
|
[
"public",
"function",
"export",
"(",
"\\",
"renderer_base",
"$",
"output",
")",
"{",
"\\",
"core_analytics",
"\\",
"manager",
"::",
"check_can_manage_models",
"(",
")",
";",
"$",
"data",
"=",
"clone",
"$",
"this",
"->",
"model",
";",
"$",
"data",
"->",
"name",
"=",
"$",
"this",
"->",
"inplace_editable_name",
"(",
")",
"->",
"export_for_template",
"(",
"$",
"output",
")",
";",
"$",
"data",
"->",
"target",
"=",
"$",
"this",
"->",
"get_target",
"(",
")",
"->",
"get_name",
"(",
")",
";",
"$",
"data",
"->",
"targetclass",
"=",
"$",
"this",
"->",
"get_target",
"(",
")",
"->",
"get_id",
"(",
")",
";",
"if",
"(",
"$",
"timesplitting",
"=",
"$",
"this",
"->",
"get_time_splitting",
"(",
")",
")",
"{",
"$",
"data",
"->",
"timesplitting",
"=",
"$",
"timesplitting",
"->",
"get_name",
"(",
")",
";",
"}",
"$",
"data",
"->",
"indicators",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"get_indicators",
"(",
")",
"as",
"$",
"indicator",
")",
"{",
"$",
"data",
"->",
"indicators",
"[",
"]",
"=",
"$",
"indicator",
"->",
"get_name",
"(",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] |
Exports the model data for displaying it in a template.
@param \renderer_base $output The renderer to use for exporting
@return \stdClass
|
[
"Exports",
"the",
"model",
"data",
"for",
"displaying",
"it",
"in",
"a",
"template",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L1444-L1463
|
216,615
|
moodle/moodle
|
analytics/classes/model.php
|
model.export_model
|
public function export_model(string $zipfilename, bool $includeweights = true) : string {
\core_analytics\manager::check_can_manage_models();
$modelconfig = new model_config($this);
return $modelconfig->export($zipfilename, $includeweights);
}
|
php
|
public function export_model(string $zipfilename, bool $includeweights = true) : string {
\core_analytics\manager::check_can_manage_models();
$modelconfig = new model_config($this);
return $modelconfig->export($zipfilename, $includeweights);
}
|
[
"public",
"function",
"export_model",
"(",
"string",
"$",
"zipfilename",
",",
"bool",
"$",
"includeweights",
"=",
"true",
")",
":",
"string",
"{",
"\\",
"core_analytics",
"\\",
"manager",
"::",
"check_can_manage_models",
"(",
")",
";",
"$",
"modelconfig",
"=",
"new",
"model_config",
"(",
"$",
"this",
")",
";",
"return",
"$",
"modelconfig",
"->",
"export",
"(",
"$",
"zipfilename",
",",
"$",
"includeweights",
")",
";",
"}"
] |
Exports the model data to a zip file.
@param string $zipfilename
@param bool $includeweights Include the model weights if available
@return string Zip file path
|
[
"Exports",
"the",
"model",
"data",
"to",
"a",
"zip",
"file",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L1472-L1478
|
216,616
|
moodle/moodle
|
analytics/classes/model.php
|
model.import_model
|
public static function import_model(string $zipfilepath) : \core_analytics\model {
\core_analytics\manager::check_can_manage_models();
$modelconfig = new \core_analytics\model_config();
return $modelconfig->import($zipfilepath);
}
|
php
|
public static function import_model(string $zipfilepath) : \core_analytics\model {
\core_analytics\manager::check_can_manage_models();
$modelconfig = new \core_analytics\model_config();
return $modelconfig->import($zipfilepath);
}
|
[
"public",
"static",
"function",
"import_model",
"(",
"string",
"$",
"zipfilepath",
")",
":",
"\\",
"core_analytics",
"\\",
"model",
"{",
"\\",
"core_analytics",
"\\",
"manager",
"::",
"check_can_manage_models",
"(",
")",
";",
"$",
"modelconfig",
"=",
"new",
"\\",
"core_analytics",
"\\",
"model_config",
"(",
")",
";",
"return",
"$",
"modelconfig",
"->",
"import",
"(",
"$",
"zipfilepath",
")",
";",
"}"
] |
Imports the provided model.
Note that this method assumes that model_config::check_dependencies has already been called.
@throws \moodle_exception
@param string $zipfilepath Zip file path
@return \core_analytics\model
|
[
"Imports",
"the",
"provided",
"model",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L1489-L1495
|
216,617
|
moodle/moodle
|
analytics/classes/model.php
|
model.can_export_configuration
|
public function can_export_configuration() : bool {
if (empty($this->model->timesplitting)) {
return false;
}
if (!$this->get_indicators()) {
return false;
}
if ($this->is_static()) {
return false;
}
return true;
}
|
php
|
public function can_export_configuration() : bool {
if (empty($this->model->timesplitting)) {
return false;
}
if (!$this->get_indicators()) {
return false;
}
if ($this->is_static()) {
return false;
}
return true;
}
|
[
"public",
"function",
"can_export_configuration",
"(",
")",
":",
"bool",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"model",
"->",
"timesplitting",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"get_indicators",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"is_static",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Can this model be exported?
@return bool
|
[
"Can",
"this",
"model",
"be",
"exported?"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L1502-L1516
|
216,618
|
moodle/moodle
|
analytics/classes/model.php
|
model.get_logs
|
public function get_logs($limitfrom = 0, $limitnum = 0) {
global $DB;
\core_analytics\manager::check_can_manage_models();
return $DB->get_records('analytics_models_log', array('modelid' => $this->get_id()), 'timecreated DESC', '*',
$limitfrom, $limitnum);
}
|
php
|
public function get_logs($limitfrom = 0, $limitnum = 0) {
global $DB;
\core_analytics\manager::check_can_manage_models();
return $DB->get_records('analytics_models_log', array('modelid' => $this->get_id()), 'timecreated DESC', '*',
$limitfrom, $limitnum);
}
|
[
"public",
"function",
"get_logs",
"(",
"$",
"limitfrom",
"=",
"0",
",",
"$",
"limitnum",
"=",
"0",
")",
"{",
"global",
"$",
"DB",
";",
"\\",
"core_analytics",
"\\",
"manager",
"::",
"check_can_manage_models",
"(",
")",
";",
"return",
"$",
"DB",
"->",
"get_records",
"(",
"'analytics_models_log'",
",",
"array",
"(",
"'modelid'",
"=>",
"$",
"this",
"->",
"get_id",
"(",
")",
")",
",",
"'timecreated DESC'",
",",
"'*'",
",",
"$",
"limitfrom",
",",
"$",
"limitnum",
")",
";",
"}"
] |
Returns the model logs data.
@param int $limitfrom
@param int $limitnum
@return \stdClass[]
|
[
"Returns",
"the",
"model",
"logs",
"data",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L1525-L1532
|
216,619
|
moodle/moodle
|
analytics/classes/model.php
|
model.get_training_data
|
public function get_training_data() {
\core_analytics\manager::check_can_manage_models();
$timesplittingid = $this->get_time_splitting()->get_id();
return \core_analytics\dataset_manager::export_training_data($this->get_id(), $timesplittingid);
}
|
php
|
public function get_training_data() {
\core_analytics\manager::check_can_manage_models();
$timesplittingid = $this->get_time_splitting()->get_id();
return \core_analytics\dataset_manager::export_training_data($this->get_id(), $timesplittingid);
}
|
[
"public",
"function",
"get_training_data",
"(",
")",
"{",
"\\",
"core_analytics",
"\\",
"manager",
"::",
"check_can_manage_models",
"(",
")",
";",
"$",
"timesplittingid",
"=",
"$",
"this",
"->",
"get_time_splitting",
"(",
")",
"->",
"get_id",
"(",
")",
";",
"return",
"\\",
"core_analytics",
"\\",
"dataset_manager",
"::",
"export_training_data",
"(",
"$",
"this",
"->",
"get_id",
"(",
")",
",",
"$",
"timesplittingid",
")",
";",
"}"
] |
Merges all training data files into one and returns it.
@return \stored_file|false
|
[
"Merges",
"all",
"training",
"data",
"files",
"into",
"one",
"and",
"returns",
"it",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L1539-L1545
|
216,620
|
moodle/moodle
|
analytics/classes/model.php
|
model.trained_locally
|
public function trained_locally() : bool {
global $DB;
if (!$this->is_trained() || $this->is_static()) {
// Early exit.
return false;
}
if ($DB->record_exists('analytics_train_samples', ['modelid' => $this->model->id])) {
return true;
}
return false;
}
|
php
|
public function trained_locally() : bool {
global $DB;
if (!$this->is_trained() || $this->is_static()) {
// Early exit.
return false;
}
if ($DB->record_exists('analytics_train_samples', ['modelid' => $this->model->id])) {
return true;
}
return false;
}
|
[
"public",
"function",
"trained_locally",
"(",
")",
":",
"bool",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"is_trained",
"(",
")",
"||",
"$",
"this",
"->",
"is_static",
"(",
")",
")",
"{",
"// Early exit.",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"DB",
"->",
"record_exists",
"(",
"'analytics_train_samples'",
",",
"[",
"'modelid'",
"=>",
"$",
"this",
"->",
"model",
"->",
"id",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Has the model been trained using data from this site?
This method is useful to determine if a trained model can be evaluated as
we can not use the same data for training and for evaluation.
@return bool
|
[
"Has",
"the",
"model",
"been",
"trained",
"using",
"data",
"from",
"this",
"site?"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L1555-L1568
|
216,621
|
moodle/moodle
|
analytics/classes/model.php
|
model.flag_file_as_used
|
protected function flag_file_as_used(\stored_file $file, $action) {
global $DB;
$usedfile = new \stdClass();
$usedfile->modelid = $this->model->id;
$usedfile->fileid = $file->get_id();
$usedfile->action = $action;
$usedfile->time = time();
$DB->insert_record('analytics_used_files', $usedfile);
}
|
php
|
protected function flag_file_as_used(\stored_file $file, $action) {
global $DB;
$usedfile = new \stdClass();
$usedfile->modelid = $this->model->id;
$usedfile->fileid = $file->get_id();
$usedfile->action = $action;
$usedfile->time = time();
$DB->insert_record('analytics_used_files', $usedfile);
}
|
[
"protected",
"function",
"flag_file_as_used",
"(",
"\\",
"stored_file",
"$",
"file",
",",
"$",
"action",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"usedfile",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"usedfile",
"->",
"modelid",
"=",
"$",
"this",
"->",
"model",
"->",
"id",
";",
"$",
"usedfile",
"->",
"fileid",
"=",
"$",
"file",
"->",
"get_id",
"(",
")",
";",
"$",
"usedfile",
"->",
"action",
"=",
"$",
"action",
";",
"$",
"usedfile",
"->",
"time",
"=",
"time",
"(",
")",
";",
"$",
"DB",
"->",
"insert_record",
"(",
"'analytics_used_files'",
",",
"$",
"usedfile",
")",
";",
"}"
] |
Flag the provided file as used for training or prediction.
@param \stored_file $file
@param string $action
@return void
|
[
"Flag",
"the",
"provided",
"file",
"as",
"used",
"for",
"training",
"or",
"prediction",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L1577-L1586
|
216,622
|
moodle/moodle
|
analytics/classes/model.php
|
model.log_result
|
protected function log_result($timesplittingid, $score, $dir = false, $info = false, $evaluationmode = 'configuration') {
global $DB, $USER;
$log = new \stdClass();
$log->modelid = $this->get_id();
$log->version = $this->model->version;
$log->evaluationmode = $evaluationmode;
$log->target = $this->model->target;
$log->indicators = $this->model->indicators;
$log->timesplitting = $timesplittingid;
$log->dir = $dir;
if ($info) {
// Ensure it is not an associative array.
$log->info = json_encode(array_values($info));
}
$log->score = $score;
$log->timecreated = time();
$log->usermodified = $USER->id;
return $DB->insert_record('analytics_models_log', $log);
}
|
php
|
protected function log_result($timesplittingid, $score, $dir = false, $info = false, $evaluationmode = 'configuration') {
global $DB, $USER;
$log = new \stdClass();
$log->modelid = $this->get_id();
$log->version = $this->model->version;
$log->evaluationmode = $evaluationmode;
$log->target = $this->model->target;
$log->indicators = $this->model->indicators;
$log->timesplitting = $timesplittingid;
$log->dir = $dir;
if ($info) {
// Ensure it is not an associative array.
$log->info = json_encode(array_values($info));
}
$log->score = $score;
$log->timecreated = time();
$log->usermodified = $USER->id;
return $DB->insert_record('analytics_models_log', $log);
}
|
[
"protected",
"function",
"log_result",
"(",
"$",
"timesplittingid",
",",
"$",
"score",
",",
"$",
"dir",
"=",
"false",
",",
"$",
"info",
"=",
"false",
",",
"$",
"evaluationmode",
"=",
"'configuration'",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"USER",
";",
"$",
"log",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"log",
"->",
"modelid",
"=",
"$",
"this",
"->",
"get_id",
"(",
")",
";",
"$",
"log",
"->",
"version",
"=",
"$",
"this",
"->",
"model",
"->",
"version",
";",
"$",
"log",
"->",
"evaluationmode",
"=",
"$",
"evaluationmode",
";",
"$",
"log",
"->",
"target",
"=",
"$",
"this",
"->",
"model",
"->",
"target",
";",
"$",
"log",
"->",
"indicators",
"=",
"$",
"this",
"->",
"model",
"->",
"indicators",
";",
"$",
"log",
"->",
"timesplitting",
"=",
"$",
"timesplittingid",
";",
"$",
"log",
"->",
"dir",
"=",
"$",
"dir",
";",
"if",
"(",
"$",
"info",
")",
"{",
"// Ensure it is not an associative array.",
"$",
"log",
"->",
"info",
"=",
"json_encode",
"(",
"array_values",
"(",
"$",
"info",
")",
")",
";",
"}",
"$",
"log",
"->",
"score",
"=",
"$",
"score",
";",
"$",
"log",
"->",
"timecreated",
"=",
"time",
"(",
")",
";",
"$",
"log",
"->",
"usermodified",
"=",
"$",
"USER",
"->",
"id",
";",
"return",
"$",
"DB",
"->",
"insert_record",
"(",
"'analytics_models_log'",
",",
"$",
"log",
")",
";",
"}"
] |
Log the evaluation results in the database.
@param string $timesplittingid
@param float $score
@param string $dir
@param array $info
@param string $evaluationmode
@return int The inserted log id
|
[
"Log",
"the",
"evaluation",
"results",
"in",
"the",
"database",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L1598-L1618
|
216,623
|
moodle/moodle
|
analytics/classes/model.php
|
model.indicator_classes
|
private static function indicator_classes($indicators) {
// What we want to check and store are the indicator classes not the keys.
$indicatorclasses = array();
foreach ($indicators as $indicator) {
if (!\core_analytics\manager::is_valid($indicator, '\core_analytics\local\indicator\base')) {
if (!is_object($indicator) && !is_scalar($indicator)) {
$indicator = strval($indicator);
} else if (is_object($indicator)) {
$indicator = '\\' . get_class($indicator);
}
throw new \moodle_exception('errorinvalidindicator', 'analytics', '', $indicator);
}
$indicatorclasses[] = $indicator->get_id();
}
return $indicatorclasses;
}
|
php
|
private static function indicator_classes($indicators) {
// What we want to check and store are the indicator classes not the keys.
$indicatorclasses = array();
foreach ($indicators as $indicator) {
if (!\core_analytics\manager::is_valid($indicator, '\core_analytics\local\indicator\base')) {
if (!is_object($indicator) && !is_scalar($indicator)) {
$indicator = strval($indicator);
} else if (is_object($indicator)) {
$indicator = '\\' . get_class($indicator);
}
throw new \moodle_exception('errorinvalidindicator', 'analytics', '', $indicator);
}
$indicatorclasses[] = $indicator->get_id();
}
return $indicatorclasses;
}
|
[
"private",
"static",
"function",
"indicator_classes",
"(",
"$",
"indicators",
")",
"{",
"// What we want to check and store are the indicator classes not the keys.",
"$",
"indicatorclasses",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"indicators",
"as",
"$",
"indicator",
")",
"{",
"if",
"(",
"!",
"\\",
"core_analytics",
"\\",
"manager",
"::",
"is_valid",
"(",
"$",
"indicator",
",",
"'\\core_analytics\\local\\indicator\\base'",
")",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"indicator",
")",
"&&",
"!",
"is_scalar",
"(",
"$",
"indicator",
")",
")",
"{",
"$",
"indicator",
"=",
"strval",
"(",
"$",
"indicator",
")",
";",
"}",
"else",
"if",
"(",
"is_object",
"(",
"$",
"indicator",
")",
")",
"{",
"$",
"indicator",
"=",
"'\\\\'",
".",
"get_class",
"(",
"$",
"indicator",
")",
";",
"}",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'errorinvalidindicator'",
",",
"'analytics'",
",",
"''",
",",
"$",
"indicator",
")",
";",
"}",
"$",
"indicatorclasses",
"[",
"]",
"=",
"$",
"indicator",
"->",
"get_id",
"(",
")",
";",
"}",
"return",
"$",
"indicatorclasses",
";",
"}"
] |
Utility method to return indicator class names from a list of indicator objects
@param \core_analytics\local\indicator\base[] $indicators
@return string[]
|
[
"Utility",
"method",
"to",
"return",
"indicator",
"class",
"names",
"from",
"a",
"list",
"of",
"indicator",
"objects"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L1626-L1643
|
216,624
|
moodle/moodle
|
analytics/classes/model.php
|
model.clear
|
public function clear() {
global $DB, $USER;
\core_analytics\manager::check_can_manage_models();
// Delete current model version stored stuff.
$predictor = $this->get_predictions_processor(false);
if ($predictor->is_ready() !== true) {
$predictorname = \core_analytics\manager::get_predictions_processor_name($predictor);
debugging('Prediction processor ' . $predictorname . ' is not ready to be used. Model ' .
$this->model->id . ' could not be cleared.');
} else {
$predictor->clear_model($this->get_unique_id(), $this->get_output_dir());
}
$predictionids = $DB->get_fieldset_select('analytics_predictions', 'id', 'modelid = :modelid',
array('modelid' => $this->get_id()));
if ($predictionids) {
list($sql, $params) = $DB->get_in_or_equal($predictionids);
$DB->delete_records_select('analytics_prediction_actions', "predictionid $sql", $params);
}
$DB->delete_records('analytics_predictions', array('modelid' => $this->model->id));
$DB->delete_records('analytics_predict_samples', array('modelid' => $this->model->id));
$DB->delete_records('analytics_train_samples', array('modelid' => $this->model->id));
$DB->delete_records('analytics_used_files', array('modelid' => $this->model->id));
$DB->delete_records('analytics_used_analysables', array('modelid' => $this->model->id));
// Purge all generated files.
\core_analytics\dataset_manager::clear_model_files($this->model->id);
// We don't expect people to clear models regularly and the cost of filling the cache is
// 1 db read per context.
$this->purge_insights_cache();
if (!$this->is_static()) {
$this->model->trained = 0;
}
$this->model->timemodified = time();
$this->model->usermodified = $USER->id;
$DB->update_record('analytics_models', $this->model);
}
|
php
|
public function clear() {
global $DB, $USER;
\core_analytics\manager::check_can_manage_models();
// Delete current model version stored stuff.
$predictor = $this->get_predictions_processor(false);
if ($predictor->is_ready() !== true) {
$predictorname = \core_analytics\manager::get_predictions_processor_name($predictor);
debugging('Prediction processor ' . $predictorname . ' is not ready to be used. Model ' .
$this->model->id . ' could not be cleared.');
} else {
$predictor->clear_model($this->get_unique_id(), $this->get_output_dir());
}
$predictionids = $DB->get_fieldset_select('analytics_predictions', 'id', 'modelid = :modelid',
array('modelid' => $this->get_id()));
if ($predictionids) {
list($sql, $params) = $DB->get_in_or_equal($predictionids);
$DB->delete_records_select('analytics_prediction_actions', "predictionid $sql", $params);
}
$DB->delete_records('analytics_predictions', array('modelid' => $this->model->id));
$DB->delete_records('analytics_predict_samples', array('modelid' => $this->model->id));
$DB->delete_records('analytics_train_samples', array('modelid' => $this->model->id));
$DB->delete_records('analytics_used_files', array('modelid' => $this->model->id));
$DB->delete_records('analytics_used_analysables', array('modelid' => $this->model->id));
// Purge all generated files.
\core_analytics\dataset_manager::clear_model_files($this->model->id);
// We don't expect people to clear models regularly and the cost of filling the cache is
// 1 db read per context.
$this->purge_insights_cache();
if (!$this->is_static()) {
$this->model->trained = 0;
}
$this->model->timemodified = time();
$this->model->usermodified = $USER->id;
$DB->update_record('analytics_models', $this->model);
}
|
[
"public",
"function",
"clear",
"(",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"USER",
";",
"\\",
"core_analytics",
"\\",
"manager",
"::",
"check_can_manage_models",
"(",
")",
";",
"// Delete current model version stored stuff.",
"$",
"predictor",
"=",
"$",
"this",
"->",
"get_predictions_processor",
"(",
"false",
")",
";",
"if",
"(",
"$",
"predictor",
"->",
"is_ready",
"(",
")",
"!==",
"true",
")",
"{",
"$",
"predictorname",
"=",
"\\",
"core_analytics",
"\\",
"manager",
"::",
"get_predictions_processor_name",
"(",
"$",
"predictor",
")",
";",
"debugging",
"(",
"'Prediction processor '",
".",
"$",
"predictorname",
".",
"' is not ready to be used. Model '",
".",
"$",
"this",
"->",
"model",
"->",
"id",
".",
"' could not be cleared.'",
")",
";",
"}",
"else",
"{",
"$",
"predictor",
"->",
"clear_model",
"(",
"$",
"this",
"->",
"get_unique_id",
"(",
")",
",",
"$",
"this",
"->",
"get_output_dir",
"(",
")",
")",
";",
"}",
"$",
"predictionids",
"=",
"$",
"DB",
"->",
"get_fieldset_select",
"(",
"'analytics_predictions'",
",",
"'id'",
",",
"'modelid = :modelid'",
",",
"array",
"(",
"'modelid'",
"=>",
"$",
"this",
"->",
"get_id",
"(",
")",
")",
")",
";",
"if",
"(",
"$",
"predictionids",
")",
"{",
"list",
"(",
"$",
"sql",
",",
"$",
"params",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"predictionids",
")",
";",
"$",
"DB",
"->",
"delete_records_select",
"(",
"'analytics_prediction_actions'",
",",
"\"predictionid $sql\"",
",",
"$",
"params",
")",
";",
"}",
"$",
"DB",
"->",
"delete_records",
"(",
"'analytics_predictions'",
",",
"array",
"(",
"'modelid'",
"=>",
"$",
"this",
"->",
"model",
"->",
"id",
")",
")",
";",
"$",
"DB",
"->",
"delete_records",
"(",
"'analytics_predict_samples'",
",",
"array",
"(",
"'modelid'",
"=>",
"$",
"this",
"->",
"model",
"->",
"id",
")",
")",
";",
"$",
"DB",
"->",
"delete_records",
"(",
"'analytics_train_samples'",
",",
"array",
"(",
"'modelid'",
"=>",
"$",
"this",
"->",
"model",
"->",
"id",
")",
")",
";",
"$",
"DB",
"->",
"delete_records",
"(",
"'analytics_used_files'",
",",
"array",
"(",
"'modelid'",
"=>",
"$",
"this",
"->",
"model",
"->",
"id",
")",
")",
";",
"$",
"DB",
"->",
"delete_records",
"(",
"'analytics_used_analysables'",
",",
"array",
"(",
"'modelid'",
"=>",
"$",
"this",
"->",
"model",
"->",
"id",
")",
")",
";",
"// Purge all generated files.",
"\\",
"core_analytics",
"\\",
"dataset_manager",
"::",
"clear_model_files",
"(",
"$",
"this",
"->",
"model",
"->",
"id",
")",
";",
"// We don't expect people to clear models regularly and the cost of filling the cache is",
"// 1 db read per context.",
"$",
"this",
"->",
"purge_insights_cache",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"is_static",
"(",
")",
")",
"{",
"$",
"this",
"->",
"model",
"->",
"trained",
"=",
"0",
";",
"}",
"$",
"this",
"->",
"model",
"->",
"timemodified",
"=",
"time",
"(",
")",
";",
"$",
"this",
"->",
"model",
"->",
"usermodified",
"=",
"$",
"USER",
"->",
"id",
";",
"$",
"DB",
"->",
"update_record",
"(",
"'analytics_models'",
",",
"$",
"this",
"->",
"model",
")",
";",
"}"
] |
Clears the model training and prediction data.
Executed after updating model critical elements like the time splitting method
or the indicators.
@return void
|
[
"Clears",
"the",
"model",
"training",
"and",
"prediction",
"data",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L1653-L1695
|
216,625
|
moodle/moodle
|
analytics/classes/model.php
|
model.get_name
|
public function get_name() {
if (trim($this->model->name) === '') {
return $this->get_target()->get_name();
} else {
return $this->model->name;
}
}
|
php
|
public function get_name() {
if (trim($this->model->name) === '') {
return $this->get_target()->get_name();
} else {
return $this->model->name;
}
}
|
[
"public",
"function",
"get_name",
"(",
")",
"{",
"if",
"(",
"trim",
"(",
"$",
"this",
"->",
"model",
"->",
"name",
")",
"===",
"''",
")",
"{",
"return",
"$",
"this",
"->",
"get_target",
"(",
")",
"->",
"get_name",
"(",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"model",
"->",
"name",
";",
"}",
"}"
] |
Returns the name of the model.
By default, models use their target's name as their own name. They can have their explicit name, too. In which
case, the explicit name is used instead of the default one.
@return string|lang_string
|
[
"Returns",
"the",
"name",
"of",
"the",
"model",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L1705-L1713
|
216,626
|
moodle/moodle
|
analytics/classes/model.php
|
model.rename
|
public function rename(string $name) {
global $DB, $USER;
$this->model->name = $name;
$this->model->timemodified = time();
$this->model->usermodified = $USER->id;
$DB->update_record('analytics_models', $this->model);
}
|
php
|
public function rename(string $name) {
global $DB, $USER;
$this->model->name = $name;
$this->model->timemodified = time();
$this->model->usermodified = $USER->id;
$DB->update_record('analytics_models', $this->model);
}
|
[
"public",
"function",
"rename",
"(",
"string",
"$",
"name",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"USER",
";",
"$",
"this",
"->",
"model",
"->",
"name",
"=",
"$",
"name",
";",
"$",
"this",
"->",
"model",
"->",
"timemodified",
"=",
"time",
"(",
")",
";",
"$",
"this",
"->",
"model",
"->",
"usermodified",
"=",
"$",
"USER",
"->",
"id",
";",
"$",
"DB",
"->",
"update_record",
"(",
"'analytics_models'",
",",
"$",
"this",
"->",
"model",
")",
";",
"}"
] |
Renames the model to the given name.
When given an empty string, the model falls back to using the associated target's name as its name.
@param string $name The new name for the model, empty string for using the default name.
|
[
"Renames",
"the",
"model",
"to",
"the",
"given",
"name",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L1722-L1730
|
216,627
|
moodle/moodle
|
analytics/classes/model.php
|
model.inplace_editable_name
|
public function inplace_editable_name() {
$displayname = format_string($this->get_name());
return new \core\output\inplace_editable('core_analytics', 'modelname', $this->model->id,
has_capability('moodle/analytics:managemodels', \context_system::instance()), $displayname, $this->model->name);
}
|
php
|
public function inplace_editable_name() {
$displayname = format_string($this->get_name());
return new \core\output\inplace_editable('core_analytics', 'modelname', $this->model->id,
has_capability('moodle/analytics:managemodels', \context_system::instance()), $displayname, $this->model->name);
}
|
[
"public",
"function",
"inplace_editable_name",
"(",
")",
"{",
"$",
"displayname",
"=",
"format_string",
"(",
"$",
"this",
"->",
"get_name",
"(",
")",
")",
";",
"return",
"new",
"\\",
"core",
"\\",
"output",
"\\",
"inplace_editable",
"(",
"'core_analytics'",
",",
"'modelname'",
",",
"$",
"this",
"->",
"model",
"->",
"id",
",",
"has_capability",
"(",
"'moodle/analytics:managemodels'",
",",
"\\",
"context_system",
"::",
"instance",
"(",
")",
")",
",",
"$",
"displayname",
",",
"$",
"this",
"->",
"model",
"->",
"name",
")",
";",
"}"
] |
Returns an inplace editable element with the model's name.
@return \core\output\inplace_editable
|
[
"Returns",
"an",
"inplace",
"editable",
"element",
"with",
"the",
"model",
"s",
"name",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L1737-L1743
|
216,628
|
moodle/moodle
|
mod/scorm/mod_form.php
|
mod_scorm_mod_form.set_data
|
public function set_data($defaultvalues) {
$defaultvalues = (array)$defaultvalues;
if (isset($defaultvalues['scormtype']) and isset($defaultvalues['reference'])) {
switch ($defaultvalues['scormtype']) {
case SCORM_TYPE_LOCALSYNC :
case SCORM_TYPE_EXTERNAL:
case SCORM_TYPE_AICCURL:
$defaultvalues['packageurl'] = $defaultvalues['reference'];
}
}
unset($defaultvalues['reference']);
if (!empty($defaultvalues['options'])) {
$options = explode(',', $defaultvalues['options']);
foreach ($options as $option) {
$opt = explode('=', $option);
if (isset($opt[1])) {
$defaultvalues[$opt[0]] = $opt[1];
}
}
}
parent::set_data($defaultvalues);
}
|
php
|
public function set_data($defaultvalues) {
$defaultvalues = (array)$defaultvalues;
if (isset($defaultvalues['scormtype']) and isset($defaultvalues['reference'])) {
switch ($defaultvalues['scormtype']) {
case SCORM_TYPE_LOCALSYNC :
case SCORM_TYPE_EXTERNAL:
case SCORM_TYPE_AICCURL:
$defaultvalues['packageurl'] = $defaultvalues['reference'];
}
}
unset($defaultvalues['reference']);
if (!empty($defaultvalues['options'])) {
$options = explode(',', $defaultvalues['options']);
foreach ($options as $option) {
$opt = explode('=', $option);
if (isset($opt[1])) {
$defaultvalues[$opt[0]] = $opt[1];
}
}
}
parent::set_data($defaultvalues);
}
|
[
"public",
"function",
"set_data",
"(",
"$",
"defaultvalues",
")",
"{",
"$",
"defaultvalues",
"=",
"(",
"array",
")",
"$",
"defaultvalues",
";",
"if",
"(",
"isset",
"(",
"$",
"defaultvalues",
"[",
"'scormtype'",
"]",
")",
"and",
"isset",
"(",
"$",
"defaultvalues",
"[",
"'reference'",
"]",
")",
")",
"{",
"switch",
"(",
"$",
"defaultvalues",
"[",
"'scormtype'",
"]",
")",
"{",
"case",
"SCORM_TYPE_LOCALSYNC",
":",
"case",
"SCORM_TYPE_EXTERNAL",
":",
"case",
"SCORM_TYPE_AICCURL",
":",
"$",
"defaultvalues",
"[",
"'packageurl'",
"]",
"=",
"$",
"defaultvalues",
"[",
"'reference'",
"]",
";",
"}",
"}",
"unset",
"(",
"$",
"defaultvalues",
"[",
"'reference'",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"defaultvalues",
"[",
"'options'",
"]",
")",
")",
"{",
"$",
"options",
"=",
"explode",
"(",
"','",
",",
"$",
"defaultvalues",
"[",
"'options'",
"]",
")",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"option",
")",
"{",
"$",
"opt",
"=",
"explode",
"(",
"'='",
",",
"$",
"option",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"opt",
"[",
"1",
"]",
")",
")",
"{",
"$",
"defaultvalues",
"[",
"$",
"opt",
"[",
"0",
"]",
"]",
"=",
"$",
"opt",
"[",
"1",
"]",
";",
"}",
"}",
"}",
"parent",
"::",
"set_data",
"(",
"$",
"defaultvalues",
")",
";",
"}"
] |
Need to translate the "options" and "reference" field.
|
[
"Need",
"to",
"translate",
"the",
"options",
"and",
"reference",
"field",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/scorm/mod_form.php#L466-L490
|
216,629
|
moodle/moodle
|
lib/pear/HTML/QuickForm.php
|
HTML_QuickForm.setDatasource
|
function setDatasource(&$datasource, $defaultsFilter = null, $constantsFilter = null)
{
if (is_object($datasource)) {
$this->_datasource =& $datasource;
if (is_callable(array($datasource, 'defaultValues'))) {
$this->setDefaults($datasource->defaultValues($this), $defaultsFilter);
}
if (is_callable(array($datasource, 'constantValues'))) {
$this->setConstants($datasource->constantValues($this), $constantsFilter);
}
} else {
return self::raiseError(null, QUICKFORM_INVALID_DATASOURCE, null, E_USER_WARNING, "Datasource is not an object in QuickForm::setDatasource()", 'HTML_QuickForm_Error', true);
}
}
|
php
|
function setDatasource(&$datasource, $defaultsFilter = null, $constantsFilter = null)
{
if (is_object($datasource)) {
$this->_datasource =& $datasource;
if (is_callable(array($datasource, 'defaultValues'))) {
$this->setDefaults($datasource->defaultValues($this), $defaultsFilter);
}
if (is_callable(array($datasource, 'constantValues'))) {
$this->setConstants($datasource->constantValues($this), $constantsFilter);
}
} else {
return self::raiseError(null, QUICKFORM_INVALID_DATASOURCE, null, E_USER_WARNING, "Datasource is not an object in QuickForm::setDatasource()", 'HTML_QuickForm_Error', true);
}
}
|
[
"function",
"setDatasource",
"(",
"&",
"$",
"datasource",
",",
"$",
"defaultsFilter",
"=",
"null",
",",
"$",
"constantsFilter",
"=",
"null",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"datasource",
")",
")",
"{",
"$",
"this",
"->",
"_datasource",
"=",
"&",
"$",
"datasource",
";",
"if",
"(",
"is_callable",
"(",
"array",
"(",
"$",
"datasource",
",",
"'defaultValues'",
")",
")",
")",
"{",
"$",
"this",
"->",
"setDefaults",
"(",
"$",
"datasource",
"->",
"defaultValues",
"(",
"$",
"this",
")",
",",
"$",
"defaultsFilter",
")",
";",
"}",
"if",
"(",
"is_callable",
"(",
"array",
"(",
"$",
"datasource",
",",
"'constantValues'",
")",
")",
")",
"{",
"$",
"this",
"->",
"setConstants",
"(",
"$",
"datasource",
"->",
"constantValues",
"(",
"$",
"this",
")",
",",
"$",
"constantsFilter",
")",
";",
"}",
"}",
"else",
"{",
"return",
"self",
"::",
"raiseError",
"(",
"null",
",",
"QUICKFORM_INVALID_DATASOURCE",
",",
"null",
",",
"E_USER_WARNING",
",",
"\"Datasource is not an object in QuickForm::setDatasource()\"",
",",
"'HTML_QuickForm_Error'",
",",
"true",
")",
";",
"}",
"}"
] |
Sets a datasource object for this form object
Datasource default and constant values will feed the QuickForm object if
the datasource implements defaultValues() and constantValues() methods.
@param object $datasource datasource object implementing the informal datasource protocol
@param mixed $defaultsFilter string or array of filter(s) to apply to default values
@param mixed $constantsFilter string or array of filter(s) to apply to constants values
@since 3.3
@access public
@return void
|
[
"Sets",
"a",
"datasource",
"object",
"for",
"this",
"form",
"object"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm.php#L404-L417
|
216,630
|
moodle/moodle
|
lib/pear/HTML/QuickForm.php
|
HTML_QuickForm.setDefaults
|
function setDefaults($defaultValues = null, $filter = null)
{
if (is_array($defaultValues)) {
if (isset($filter)) {
if (is_array($filter) && (2 != count($filter) || !is_callable($filter))) {
foreach ($filter as $val) {
if (!is_callable($val)) {
return self::raiseError(null, QUICKFORM_INVALID_FILTER, null, E_USER_WARNING, "Callback function does not exist in QuickForm::setDefaults()", 'HTML_QuickForm_Error', true);
} else {
$defaultValues = $this->_recursiveFilter($val, $defaultValues);
}
}
} elseif (!is_callable($filter)) {
return self::raiseError(null, QUICKFORM_INVALID_FILTER, null, E_USER_WARNING, "Callback function does not exist in QuickForm::setDefaults()", 'HTML_QuickForm_Error', true);
} else {
$defaultValues = $this->_recursiveFilter($filter, $defaultValues);
}
}
$this->_defaultValues = HTML_QuickForm::arrayMerge($this->_defaultValues, $defaultValues);
foreach (array_keys($this->_elements) as $key) {
$this->_elements[$key]->onQuickFormEvent('updateValue', null, $this);
}
}
}
|
php
|
function setDefaults($defaultValues = null, $filter = null)
{
if (is_array($defaultValues)) {
if (isset($filter)) {
if (is_array($filter) && (2 != count($filter) || !is_callable($filter))) {
foreach ($filter as $val) {
if (!is_callable($val)) {
return self::raiseError(null, QUICKFORM_INVALID_FILTER, null, E_USER_WARNING, "Callback function does not exist in QuickForm::setDefaults()", 'HTML_QuickForm_Error', true);
} else {
$defaultValues = $this->_recursiveFilter($val, $defaultValues);
}
}
} elseif (!is_callable($filter)) {
return self::raiseError(null, QUICKFORM_INVALID_FILTER, null, E_USER_WARNING, "Callback function does not exist in QuickForm::setDefaults()", 'HTML_QuickForm_Error', true);
} else {
$defaultValues = $this->_recursiveFilter($filter, $defaultValues);
}
}
$this->_defaultValues = HTML_QuickForm::arrayMerge($this->_defaultValues, $defaultValues);
foreach (array_keys($this->_elements) as $key) {
$this->_elements[$key]->onQuickFormEvent('updateValue', null, $this);
}
}
}
|
[
"function",
"setDefaults",
"(",
"$",
"defaultValues",
"=",
"null",
",",
"$",
"filter",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"defaultValues",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"filter",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"filter",
")",
"&&",
"(",
"2",
"!=",
"count",
"(",
"$",
"filter",
")",
"||",
"!",
"is_callable",
"(",
"$",
"filter",
")",
")",
")",
"{",
"foreach",
"(",
"$",
"filter",
"as",
"$",
"val",
")",
"{",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"val",
")",
")",
"{",
"return",
"self",
"::",
"raiseError",
"(",
"null",
",",
"QUICKFORM_INVALID_FILTER",
",",
"null",
",",
"E_USER_WARNING",
",",
"\"Callback function does not exist in QuickForm::setDefaults()\"",
",",
"'HTML_QuickForm_Error'",
",",
"true",
")",
";",
"}",
"else",
"{",
"$",
"defaultValues",
"=",
"$",
"this",
"->",
"_recursiveFilter",
"(",
"$",
"val",
",",
"$",
"defaultValues",
")",
";",
"}",
"}",
"}",
"elseif",
"(",
"!",
"is_callable",
"(",
"$",
"filter",
")",
")",
"{",
"return",
"self",
"::",
"raiseError",
"(",
"null",
",",
"QUICKFORM_INVALID_FILTER",
",",
"null",
",",
"E_USER_WARNING",
",",
"\"Callback function does not exist in QuickForm::setDefaults()\"",
",",
"'HTML_QuickForm_Error'",
",",
"true",
")",
";",
"}",
"else",
"{",
"$",
"defaultValues",
"=",
"$",
"this",
"->",
"_recursiveFilter",
"(",
"$",
"filter",
",",
"$",
"defaultValues",
")",
";",
"}",
"}",
"$",
"this",
"->",
"_defaultValues",
"=",
"HTML_QuickForm",
"::",
"arrayMerge",
"(",
"$",
"this",
"->",
"_defaultValues",
",",
"$",
"defaultValues",
")",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"_elements",
")",
"as",
"$",
"key",
")",
"{",
"$",
"this",
"->",
"_elements",
"[",
"$",
"key",
"]",
"->",
"onQuickFormEvent",
"(",
"'updateValue'",
",",
"null",
",",
"$",
"this",
")",
";",
"}",
"}",
"}"
] |
Initializes default form values
@param array $defaultValues values used to fill the form
@param mixed $filter (optional) filter(s) to apply to all default values
@since 1.0
@access public
@return void
|
[
"Initializes",
"default",
"form",
"values"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm.php#L431-L454
|
216,631
|
moodle/moodle
|
lib/pear/HTML/QuickForm.php
|
HTML_QuickForm.setConstants
|
function setConstants($constantValues = null, $filter = null)
{
if (is_array($constantValues)) {
if (isset($filter)) {
if (is_array($filter) && (2 != count($filter) || !is_callable($filter))) {
foreach ($filter as $val) {
if (!is_callable($val)) {
return self::raiseError(null, QUICKFORM_INVALID_FILTER, null, E_USER_WARNING, "Callback function does not exist in QuickForm::setConstants()", 'HTML_QuickForm_Error', true);
} else {
$constantValues = $this->_recursiveFilter($val, $constantValues);
}
}
} elseif (!is_callable($filter)) {
return self::raiseError(null, QUICKFORM_INVALID_FILTER, null, E_USER_WARNING, "Callback function does not exist in QuickForm::setConstants()", 'HTML_QuickForm_Error', true);
} else {
$constantValues = $this->_recursiveFilter($filter, $constantValues);
}
}
$this->_constantValues = HTML_QuickForm::arrayMerge($this->_constantValues, $constantValues);
foreach (array_keys($this->_elements) as $key) {
$this->_elements[$key]->onQuickFormEvent('updateValue', null, $this);
}
}
}
|
php
|
function setConstants($constantValues = null, $filter = null)
{
if (is_array($constantValues)) {
if (isset($filter)) {
if (is_array($filter) && (2 != count($filter) || !is_callable($filter))) {
foreach ($filter as $val) {
if (!is_callable($val)) {
return self::raiseError(null, QUICKFORM_INVALID_FILTER, null, E_USER_WARNING, "Callback function does not exist in QuickForm::setConstants()", 'HTML_QuickForm_Error', true);
} else {
$constantValues = $this->_recursiveFilter($val, $constantValues);
}
}
} elseif (!is_callable($filter)) {
return self::raiseError(null, QUICKFORM_INVALID_FILTER, null, E_USER_WARNING, "Callback function does not exist in QuickForm::setConstants()", 'HTML_QuickForm_Error', true);
} else {
$constantValues = $this->_recursiveFilter($filter, $constantValues);
}
}
$this->_constantValues = HTML_QuickForm::arrayMerge($this->_constantValues, $constantValues);
foreach (array_keys($this->_elements) as $key) {
$this->_elements[$key]->onQuickFormEvent('updateValue', null, $this);
}
}
}
|
[
"function",
"setConstants",
"(",
"$",
"constantValues",
"=",
"null",
",",
"$",
"filter",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"constantValues",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"filter",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"filter",
")",
"&&",
"(",
"2",
"!=",
"count",
"(",
"$",
"filter",
")",
"||",
"!",
"is_callable",
"(",
"$",
"filter",
")",
")",
")",
"{",
"foreach",
"(",
"$",
"filter",
"as",
"$",
"val",
")",
"{",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"val",
")",
")",
"{",
"return",
"self",
"::",
"raiseError",
"(",
"null",
",",
"QUICKFORM_INVALID_FILTER",
",",
"null",
",",
"E_USER_WARNING",
",",
"\"Callback function does not exist in QuickForm::setConstants()\"",
",",
"'HTML_QuickForm_Error'",
",",
"true",
")",
";",
"}",
"else",
"{",
"$",
"constantValues",
"=",
"$",
"this",
"->",
"_recursiveFilter",
"(",
"$",
"val",
",",
"$",
"constantValues",
")",
";",
"}",
"}",
"}",
"elseif",
"(",
"!",
"is_callable",
"(",
"$",
"filter",
")",
")",
"{",
"return",
"self",
"::",
"raiseError",
"(",
"null",
",",
"QUICKFORM_INVALID_FILTER",
",",
"null",
",",
"E_USER_WARNING",
",",
"\"Callback function does not exist in QuickForm::setConstants()\"",
",",
"'HTML_QuickForm_Error'",
",",
"true",
")",
";",
"}",
"else",
"{",
"$",
"constantValues",
"=",
"$",
"this",
"->",
"_recursiveFilter",
"(",
"$",
"filter",
",",
"$",
"constantValues",
")",
";",
"}",
"}",
"$",
"this",
"->",
"_constantValues",
"=",
"HTML_QuickForm",
"::",
"arrayMerge",
"(",
"$",
"this",
"->",
"_constantValues",
",",
"$",
"constantValues",
")",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"_elements",
")",
"as",
"$",
"key",
")",
"{",
"$",
"this",
"->",
"_elements",
"[",
"$",
"key",
"]",
"->",
"onQuickFormEvent",
"(",
"'updateValue'",
",",
"null",
",",
"$",
"this",
")",
";",
"}",
"}",
"}"
] |
Initializes constant form values.
These values won't get overridden by POST or GET vars
@param array $constantValues values used to fill the form
@param mixed $filter (optional) filter(s) to apply to all default values
@since 2.0
@access public
@return void
|
[
"Initializes",
"constant",
"form",
"values",
".",
"These",
"values",
"won",
"t",
"get",
"overridden",
"by",
"POST",
"or",
"GET",
"vars"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm.php#L470-L493
|
216,632
|
moodle/moodle
|
lib/pear/HTML/QuickForm.php
|
HTML_QuickForm.setMaxFileSize
|
function setMaxFileSize($bytes = 0)
{
if ($bytes > 0) {
$this->_maxFileSize = $bytes;
}
if (!$this->elementExists('MAX_FILE_SIZE')) {
$this->addElement('hidden', 'MAX_FILE_SIZE', $this->_maxFileSize);
} else {
$el =& $this->getElement('MAX_FILE_SIZE');
$el->updateAttributes(array('value' => $this->_maxFileSize));
}
}
|
php
|
function setMaxFileSize($bytes = 0)
{
if ($bytes > 0) {
$this->_maxFileSize = $bytes;
}
if (!$this->elementExists('MAX_FILE_SIZE')) {
$this->addElement('hidden', 'MAX_FILE_SIZE', $this->_maxFileSize);
} else {
$el =& $this->getElement('MAX_FILE_SIZE');
$el->updateAttributes(array('value' => $this->_maxFileSize));
}
}
|
[
"function",
"setMaxFileSize",
"(",
"$",
"bytes",
"=",
"0",
")",
"{",
"if",
"(",
"$",
"bytes",
">",
"0",
")",
"{",
"$",
"this",
"->",
"_maxFileSize",
"=",
"$",
"bytes",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"elementExists",
"(",
"'MAX_FILE_SIZE'",
")",
")",
"{",
"$",
"this",
"->",
"addElement",
"(",
"'hidden'",
",",
"'MAX_FILE_SIZE'",
",",
"$",
"this",
"->",
"_maxFileSize",
")",
";",
"}",
"else",
"{",
"$",
"el",
"=",
"&",
"$",
"this",
"->",
"getElement",
"(",
"'MAX_FILE_SIZE'",
")",
";",
"$",
"el",
"->",
"updateAttributes",
"(",
"array",
"(",
"'value'",
"=>",
"$",
"this",
"->",
"_maxFileSize",
")",
")",
";",
"}",
"}"
] |
Sets the value of MAX_FILE_SIZE hidden element
@param int $bytes Size in bytes
@since 3.0
@access public
@return void
|
[
"Sets",
"the",
"value",
"of",
"MAX_FILE_SIZE",
"hidden",
"element"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm.php#L506-L517
|
216,633
|
moodle/moodle
|
lib/pear/HTML/QuickForm.php
|
HTML_QuickForm.&
|
function &createElement($elementType)
{
if (!isset($this) || !($this instanceof HTML_QuickForm)) {
// Several form elements in Moodle core before 3.2 were calling this method
// statically suppressing PHP notices. This debugging message should notify
// developers who copied such code and did not test their plugins on PHP 7.1.
// Example of fixing group form elements can be found in commit
// https://github.com/moodle/moodle/commit/721e2def56a48fab4f8d3ec7847af5cd03f5ec79
debugging('Function createElement() can not be called statically, ' .
'this will no longer work in PHP 7.1',
DEBUG_DEVELOPER);
}
$args = func_get_args();
$element = self::_loadElement('createElement', $elementType, array_slice($args, 1));
return $element;
}
|
php
|
function &createElement($elementType)
{
if (!isset($this) || !($this instanceof HTML_QuickForm)) {
// Several form elements in Moodle core before 3.2 were calling this method
// statically suppressing PHP notices. This debugging message should notify
// developers who copied such code and did not test their plugins on PHP 7.1.
// Example of fixing group form elements can be found in commit
// https://github.com/moodle/moodle/commit/721e2def56a48fab4f8d3ec7847af5cd03f5ec79
debugging('Function createElement() can not be called statically, ' .
'this will no longer work in PHP 7.1',
DEBUG_DEVELOPER);
}
$args = func_get_args();
$element = self::_loadElement('createElement', $elementType, array_slice($args, 1));
return $element;
}
|
[
"function",
"&",
"createElement",
"(",
"$",
"elementType",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
")",
"||",
"!",
"(",
"$",
"this",
"instanceof",
"HTML_QuickForm",
")",
")",
"{",
"// Several form elements in Moodle core before 3.2 were calling this method",
"// statically suppressing PHP notices. This debugging message should notify",
"// developers who copied such code and did not test their plugins on PHP 7.1.",
"// Example of fixing group form elements can be found in commit",
"// https://github.com/moodle/moodle/commit/721e2def56a48fab4f8d3ec7847af5cd03f5ec79",
"debugging",
"(",
"'Function createElement() can not be called statically, '",
".",
"'this will no longer work in PHP 7.1'",
",",
"DEBUG_DEVELOPER",
")",
";",
"}",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"$",
"element",
"=",
"self",
"::",
"_loadElement",
"(",
"'createElement'",
",",
"$",
"elementType",
",",
"array_slice",
"(",
"$",
"args",
",",
"1",
")",
")",
";",
"return",
"$",
"element",
";",
"}"
] |
Creates a new form element of the given type.
This method accepts variable number of parameters, their
meaning and count depending on $elementType
@param string $elementType type of element to add (text, textarea, file...)
@since 1.0
@access public
@return object extended class of HTML_element
@throws HTML_QuickForm_Error
|
[
"Creates",
"a",
"new",
"form",
"element",
"of",
"the",
"given",
"type",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm.php#L549-L564
|
216,634
|
moodle/moodle
|
lib/pear/HTML/QuickForm.php
|
HTML_QuickForm.&
|
function &_loadElement($event, $type, $args)
{
$type = strtolower($type);
if (!self::isTypeRegistered($type)) {
$error = self::raiseError(null, QUICKFORM_UNREGISTERED_ELEMENT, null, E_USER_WARNING, "Element '$type' does not exist in HTML_QuickForm::_loadElement()", 'HTML_QuickForm_Error', true);
return $error;
}
$className = $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES'][$type][1];
$includeFile = $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES'][$type][0];
include_once($includeFile);
$elementObject = new $className(); //Moodle: PHP 5.3 compatibility
for ($i = 0; $i < 5; $i++) {
if (!isset($args[$i])) {
$args[$i] = null;
}
}
$err = $elementObject->onQuickFormEvent($event, $args, $this);
if ($err !== true) {
return $err;
}
return $elementObject;
}
|
php
|
function &_loadElement($event, $type, $args)
{
$type = strtolower($type);
if (!self::isTypeRegistered($type)) {
$error = self::raiseError(null, QUICKFORM_UNREGISTERED_ELEMENT, null, E_USER_WARNING, "Element '$type' does not exist in HTML_QuickForm::_loadElement()", 'HTML_QuickForm_Error', true);
return $error;
}
$className = $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES'][$type][1];
$includeFile = $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES'][$type][0];
include_once($includeFile);
$elementObject = new $className(); //Moodle: PHP 5.3 compatibility
for ($i = 0; $i < 5; $i++) {
if (!isset($args[$i])) {
$args[$i] = null;
}
}
$err = $elementObject->onQuickFormEvent($event, $args, $this);
if ($err !== true) {
return $err;
}
return $elementObject;
}
|
[
"function",
"&",
"_loadElement",
"(",
"$",
"event",
",",
"$",
"type",
",",
"$",
"args",
")",
"{",
"$",
"type",
"=",
"strtolower",
"(",
"$",
"type",
")",
";",
"if",
"(",
"!",
"self",
"::",
"isTypeRegistered",
"(",
"$",
"type",
")",
")",
"{",
"$",
"error",
"=",
"self",
"::",
"raiseError",
"(",
"null",
",",
"QUICKFORM_UNREGISTERED_ELEMENT",
",",
"null",
",",
"E_USER_WARNING",
",",
"\"Element '$type' does not exist in HTML_QuickForm::_loadElement()\"",
",",
"'HTML_QuickForm_Error'",
",",
"true",
")",
";",
"return",
"$",
"error",
";",
"}",
"$",
"className",
"=",
"$",
"GLOBALS",
"[",
"'HTML_QUICKFORM_ELEMENT_TYPES'",
"]",
"[",
"$",
"type",
"]",
"[",
"1",
"]",
";",
"$",
"includeFile",
"=",
"$",
"GLOBALS",
"[",
"'HTML_QUICKFORM_ELEMENT_TYPES'",
"]",
"[",
"$",
"type",
"]",
"[",
"0",
"]",
";",
"include_once",
"(",
"$",
"includeFile",
")",
";",
"$",
"elementObject",
"=",
"new",
"$",
"className",
"(",
")",
";",
"//Moodle: PHP 5.3 compatibility",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"5",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"args",
"[",
"$",
"i",
"]",
")",
")",
"{",
"$",
"args",
"[",
"$",
"i",
"]",
"=",
"null",
";",
"}",
"}",
"$",
"err",
"=",
"$",
"elementObject",
"->",
"onQuickFormEvent",
"(",
"$",
"event",
",",
"$",
"args",
",",
"$",
"this",
")",
";",
"if",
"(",
"$",
"err",
"!==",
"true",
")",
"{",
"return",
"$",
"err",
";",
"}",
"return",
"$",
"elementObject",
";",
"}"
] |
Returns a form element of the given type
@param string $event event to send to newly created element ('createElement' or 'addElement')
@param string $type element type
@param array $args arguments for event
@since 2.0
@access private
@return object a new element
@throws HTML_QuickForm_Error
|
[
"Returns",
"a",
"form",
"element",
"of",
"the",
"given",
"type"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm.php#L580-L601
|
216,635
|
moodle/moodle
|
lib/pear/HTML/QuickForm.php
|
HTML_QuickForm.&
|
function &addElement($element)
{
if (is_object($element) && is_subclass_of($element, 'html_quickform_element')) {
$elementObject = &$element;
$elementObject->onQuickFormEvent('updateValue', null, $this);
} else {
$args = func_get_args();
$elementObject =& $this->_loadElement('addElement', $element, array_slice($args, 1));
$pear = new PEAR();
if ($pear->isError($elementObject)) {
return $elementObject;
}
}
$elementName = $elementObject->getName();
// Add the element if it is not an incompatible duplicate
if (!empty($elementName) && isset($this->_elementIndex[$elementName])) {
if ($this->_elements[$this->_elementIndex[$elementName]]->getType() ==
$elementObject->getType()) {
$this->_elements[] =& $elementObject;
$elKeys = array_keys($this->_elements);
$this->_duplicateIndex[$elementName][] = end($elKeys);
} else {
$error = self::raiseError(null, QUICKFORM_INVALID_ELEMENT_NAME, null, E_USER_WARNING, "Element '$elementName' already exists in HTML_QuickForm::addElement()", 'HTML_QuickForm_Error', true);
return $error;
}
} else {
$this->_elements[] =& $elementObject;
$elKeys = array_keys($this->_elements);
$this->_elementIndex[$elementName] = end($elKeys);
}
if ($this->_freezeAll) {
$elementObject->freeze();
}
return $elementObject;
}
|
php
|
function &addElement($element)
{
if (is_object($element) && is_subclass_of($element, 'html_quickform_element')) {
$elementObject = &$element;
$elementObject->onQuickFormEvent('updateValue', null, $this);
} else {
$args = func_get_args();
$elementObject =& $this->_loadElement('addElement', $element, array_slice($args, 1));
$pear = new PEAR();
if ($pear->isError($elementObject)) {
return $elementObject;
}
}
$elementName = $elementObject->getName();
// Add the element if it is not an incompatible duplicate
if (!empty($elementName) && isset($this->_elementIndex[$elementName])) {
if ($this->_elements[$this->_elementIndex[$elementName]]->getType() ==
$elementObject->getType()) {
$this->_elements[] =& $elementObject;
$elKeys = array_keys($this->_elements);
$this->_duplicateIndex[$elementName][] = end($elKeys);
} else {
$error = self::raiseError(null, QUICKFORM_INVALID_ELEMENT_NAME, null, E_USER_WARNING, "Element '$elementName' already exists in HTML_QuickForm::addElement()", 'HTML_QuickForm_Error', true);
return $error;
}
} else {
$this->_elements[] =& $elementObject;
$elKeys = array_keys($this->_elements);
$this->_elementIndex[$elementName] = end($elKeys);
}
if ($this->_freezeAll) {
$elementObject->freeze();
}
return $elementObject;
}
|
[
"function",
"&",
"addElement",
"(",
"$",
"element",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"element",
")",
"&&",
"is_subclass_of",
"(",
"$",
"element",
",",
"'html_quickform_element'",
")",
")",
"{",
"$",
"elementObject",
"=",
"&",
"$",
"element",
";",
"$",
"elementObject",
"->",
"onQuickFormEvent",
"(",
"'updateValue'",
",",
"null",
",",
"$",
"this",
")",
";",
"}",
"else",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"$",
"elementObject",
"=",
"&",
"$",
"this",
"->",
"_loadElement",
"(",
"'addElement'",
",",
"$",
"element",
",",
"array_slice",
"(",
"$",
"args",
",",
"1",
")",
")",
";",
"$",
"pear",
"=",
"new",
"PEAR",
"(",
")",
";",
"if",
"(",
"$",
"pear",
"->",
"isError",
"(",
"$",
"elementObject",
")",
")",
"{",
"return",
"$",
"elementObject",
";",
"}",
"}",
"$",
"elementName",
"=",
"$",
"elementObject",
"->",
"getName",
"(",
")",
";",
"// Add the element if it is not an incompatible duplicate",
"if",
"(",
"!",
"empty",
"(",
"$",
"elementName",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"_elementIndex",
"[",
"$",
"elementName",
"]",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_elements",
"[",
"$",
"this",
"->",
"_elementIndex",
"[",
"$",
"elementName",
"]",
"]",
"->",
"getType",
"(",
")",
"==",
"$",
"elementObject",
"->",
"getType",
"(",
")",
")",
"{",
"$",
"this",
"->",
"_elements",
"[",
"]",
"=",
"&",
"$",
"elementObject",
";",
"$",
"elKeys",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"_elements",
")",
";",
"$",
"this",
"->",
"_duplicateIndex",
"[",
"$",
"elementName",
"]",
"[",
"]",
"=",
"end",
"(",
"$",
"elKeys",
")",
";",
"}",
"else",
"{",
"$",
"error",
"=",
"self",
"::",
"raiseError",
"(",
"null",
",",
"QUICKFORM_INVALID_ELEMENT_NAME",
",",
"null",
",",
"E_USER_WARNING",
",",
"\"Element '$elementName' already exists in HTML_QuickForm::addElement()\"",
",",
"'HTML_QuickForm_Error'",
",",
"true",
")",
";",
"return",
"$",
"error",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"_elements",
"[",
"]",
"=",
"&",
"$",
"elementObject",
";",
"$",
"elKeys",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"_elements",
")",
";",
"$",
"this",
"->",
"_elementIndex",
"[",
"$",
"elementName",
"]",
"=",
"end",
"(",
"$",
"elKeys",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_freezeAll",
")",
"{",
"$",
"elementObject",
"->",
"freeze",
"(",
")",
";",
"}",
"return",
"$",
"elementObject",
";",
"}"
] |
Adds an element into the form
If $element is a string representing element type, then this
method accepts variable number of parameters, their meaning
and count depending on $element
@param mixed $element element object or type of element to add (text, textarea, file...)
@since 1.0
@return object reference to element
@access public
@throws HTML_QuickForm_Error
|
[
"Adds",
"an",
"element",
"into",
"the",
"form"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm.php#L619-L655
|
216,636
|
moodle/moodle
|
lib/pear/HTML/QuickForm.php
|
HTML_QuickForm.&
|
function &insertElementBefore(&$element, $nameAfter)
{
if (!empty($this->_duplicateIndex[$nameAfter])) {
$error = self::raiseError(null, QUICKFORM_INVALID_ELEMENT_NAME, null, E_USER_WARNING, 'Several elements named "' . $nameAfter . '" exist in HTML_QuickForm::insertElementBefore().', 'HTML_QuickForm_Error', true);
return $error;
} elseif (!$this->elementExists($nameAfter)) {
$error = self::raiseError(null, QUICKFORM_NONEXIST_ELEMENT, null, E_USER_WARNING, "Element '$nameAfter' does not exist in HTML_QuickForm::insertElementBefore()", 'HTML_QuickForm_Error', true);
return $error;
}
$elementName = $element->getName();
$targetIdx = $this->_elementIndex[$nameAfter];
$duplicate = false;
// Like in addElement(), check that it's not an incompatible duplicate
if (!empty($elementName) && isset($this->_elementIndex[$elementName])) {
if ($this->_elements[$this->_elementIndex[$elementName]]->getType() != $element->getType()) {
$error = self::raiseError(null, QUICKFORM_INVALID_ELEMENT_NAME, null, E_USER_WARNING, "Element '$elementName' already exists in HTML_QuickForm::insertElementBefore()", 'HTML_QuickForm_Error', true);
return $error;
}
$duplicate = true;
}
// Move all the elements after added back one place, reindex _elementIndex and/or _duplicateIndex
$elKeys = array_keys($this->_elements);
for ($i = end($elKeys); $i >= $targetIdx; $i--) {
if (isset($this->_elements[$i])) {
$currentName = $this->_elements[$i]->getName();
$this->_elements[$i + 1] =& $this->_elements[$i];
if ($this->_elementIndex[$currentName] == $i) {
$this->_elementIndex[$currentName] = $i + 1;
} else {
if (!empty($currentName)) {
$dupIdx = array_search($i, $this->_duplicateIndex[$currentName]);
$this->_duplicateIndex[$currentName][$dupIdx] = $i + 1;
}
}
unset($this->_elements[$i]);
}
}
// Put the element in place finally
$this->_elements[$targetIdx] =& $element;
if (!$duplicate) {
$this->_elementIndex[$elementName] = $targetIdx;
} else {
$this->_duplicateIndex[$elementName][] = $targetIdx;
}
$element->onQuickFormEvent('updateValue', null, $this);
if ($this->_freezeAll) {
$element->freeze();
}
// If not done, the elements will appear in reverse order
ksort($this->_elements);
return $element;
}
|
php
|
function &insertElementBefore(&$element, $nameAfter)
{
if (!empty($this->_duplicateIndex[$nameAfter])) {
$error = self::raiseError(null, QUICKFORM_INVALID_ELEMENT_NAME, null, E_USER_WARNING, 'Several elements named "' . $nameAfter . '" exist in HTML_QuickForm::insertElementBefore().', 'HTML_QuickForm_Error', true);
return $error;
} elseif (!$this->elementExists($nameAfter)) {
$error = self::raiseError(null, QUICKFORM_NONEXIST_ELEMENT, null, E_USER_WARNING, "Element '$nameAfter' does not exist in HTML_QuickForm::insertElementBefore()", 'HTML_QuickForm_Error', true);
return $error;
}
$elementName = $element->getName();
$targetIdx = $this->_elementIndex[$nameAfter];
$duplicate = false;
// Like in addElement(), check that it's not an incompatible duplicate
if (!empty($elementName) && isset($this->_elementIndex[$elementName])) {
if ($this->_elements[$this->_elementIndex[$elementName]]->getType() != $element->getType()) {
$error = self::raiseError(null, QUICKFORM_INVALID_ELEMENT_NAME, null, E_USER_WARNING, "Element '$elementName' already exists in HTML_QuickForm::insertElementBefore()", 'HTML_QuickForm_Error', true);
return $error;
}
$duplicate = true;
}
// Move all the elements after added back one place, reindex _elementIndex and/or _duplicateIndex
$elKeys = array_keys($this->_elements);
for ($i = end($elKeys); $i >= $targetIdx; $i--) {
if (isset($this->_elements[$i])) {
$currentName = $this->_elements[$i]->getName();
$this->_elements[$i + 1] =& $this->_elements[$i];
if ($this->_elementIndex[$currentName] == $i) {
$this->_elementIndex[$currentName] = $i + 1;
} else {
if (!empty($currentName)) {
$dupIdx = array_search($i, $this->_duplicateIndex[$currentName]);
$this->_duplicateIndex[$currentName][$dupIdx] = $i + 1;
}
}
unset($this->_elements[$i]);
}
}
// Put the element in place finally
$this->_elements[$targetIdx] =& $element;
if (!$duplicate) {
$this->_elementIndex[$elementName] = $targetIdx;
} else {
$this->_duplicateIndex[$elementName][] = $targetIdx;
}
$element->onQuickFormEvent('updateValue', null, $this);
if ($this->_freezeAll) {
$element->freeze();
}
// If not done, the elements will appear in reverse order
ksort($this->_elements);
return $element;
}
|
[
"function",
"&",
"insertElementBefore",
"(",
"&",
"$",
"element",
",",
"$",
"nameAfter",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_duplicateIndex",
"[",
"$",
"nameAfter",
"]",
")",
")",
"{",
"$",
"error",
"=",
"self",
"::",
"raiseError",
"(",
"null",
",",
"QUICKFORM_INVALID_ELEMENT_NAME",
",",
"null",
",",
"E_USER_WARNING",
",",
"'Several elements named \"'",
".",
"$",
"nameAfter",
".",
"'\" exist in HTML_QuickForm::insertElementBefore().'",
",",
"'HTML_QuickForm_Error'",
",",
"true",
")",
";",
"return",
"$",
"error",
";",
"}",
"elseif",
"(",
"!",
"$",
"this",
"->",
"elementExists",
"(",
"$",
"nameAfter",
")",
")",
"{",
"$",
"error",
"=",
"self",
"::",
"raiseError",
"(",
"null",
",",
"QUICKFORM_NONEXIST_ELEMENT",
",",
"null",
",",
"E_USER_WARNING",
",",
"\"Element '$nameAfter' does not exist in HTML_QuickForm::insertElementBefore()\"",
",",
"'HTML_QuickForm_Error'",
",",
"true",
")",
";",
"return",
"$",
"error",
";",
"}",
"$",
"elementName",
"=",
"$",
"element",
"->",
"getName",
"(",
")",
";",
"$",
"targetIdx",
"=",
"$",
"this",
"->",
"_elementIndex",
"[",
"$",
"nameAfter",
"]",
";",
"$",
"duplicate",
"=",
"false",
";",
"// Like in addElement(), check that it's not an incompatible duplicate",
"if",
"(",
"!",
"empty",
"(",
"$",
"elementName",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"_elementIndex",
"[",
"$",
"elementName",
"]",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_elements",
"[",
"$",
"this",
"->",
"_elementIndex",
"[",
"$",
"elementName",
"]",
"]",
"->",
"getType",
"(",
")",
"!=",
"$",
"element",
"->",
"getType",
"(",
")",
")",
"{",
"$",
"error",
"=",
"self",
"::",
"raiseError",
"(",
"null",
",",
"QUICKFORM_INVALID_ELEMENT_NAME",
",",
"null",
",",
"E_USER_WARNING",
",",
"\"Element '$elementName' already exists in HTML_QuickForm::insertElementBefore()\"",
",",
"'HTML_QuickForm_Error'",
",",
"true",
")",
";",
"return",
"$",
"error",
";",
"}",
"$",
"duplicate",
"=",
"true",
";",
"}",
"// Move all the elements after added back one place, reindex _elementIndex and/or _duplicateIndex",
"$",
"elKeys",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"_elements",
")",
";",
"for",
"(",
"$",
"i",
"=",
"end",
"(",
"$",
"elKeys",
")",
";",
"$",
"i",
">=",
"$",
"targetIdx",
";",
"$",
"i",
"--",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_elements",
"[",
"$",
"i",
"]",
")",
")",
"{",
"$",
"currentName",
"=",
"$",
"this",
"->",
"_elements",
"[",
"$",
"i",
"]",
"->",
"getName",
"(",
")",
";",
"$",
"this",
"->",
"_elements",
"[",
"$",
"i",
"+",
"1",
"]",
"=",
"&",
"$",
"this",
"->",
"_elements",
"[",
"$",
"i",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"_elementIndex",
"[",
"$",
"currentName",
"]",
"==",
"$",
"i",
")",
"{",
"$",
"this",
"->",
"_elementIndex",
"[",
"$",
"currentName",
"]",
"=",
"$",
"i",
"+",
"1",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"currentName",
")",
")",
"{",
"$",
"dupIdx",
"=",
"array_search",
"(",
"$",
"i",
",",
"$",
"this",
"->",
"_duplicateIndex",
"[",
"$",
"currentName",
"]",
")",
";",
"$",
"this",
"->",
"_duplicateIndex",
"[",
"$",
"currentName",
"]",
"[",
"$",
"dupIdx",
"]",
"=",
"$",
"i",
"+",
"1",
";",
"}",
"}",
"unset",
"(",
"$",
"this",
"->",
"_elements",
"[",
"$",
"i",
"]",
")",
";",
"}",
"}",
"// Put the element in place finally",
"$",
"this",
"->",
"_elements",
"[",
"$",
"targetIdx",
"]",
"=",
"&",
"$",
"element",
";",
"if",
"(",
"!",
"$",
"duplicate",
")",
"{",
"$",
"this",
"->",
"_elementIndex",
"[",
"$",
"elementName",
"]",
"=",
"$",
"targetIdx",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_duplicateIndex",
"[",
"$",
"elementName",
"]",
"[",
"]",
"=",
"$",
"targetIdx",
";",
"}",
"$",
"element",
"->",
"onQuickFormEvent",
"(",
"'updateValue'",
",",
"null",
",",
"$",
"this",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_freezeAll",
")",
"{",
"$",
"element",
"->",
"freeze",
"(",
")",
";",
"}",
"// If not done, the elements will appear in reverse order",
"ksort",
"(",
"$",
"this",
"->",
"_elements",
")",
";",
"return",
"$",
"element",
";",
"}"
] |
Inserts a new element right before the other element
Warning: it is not possible to check whether the $element is already
added to the form, therefore if you want to move the existing form
element to a new position, you'll have to use removeElement():
$form->insertElementBefore($form->removeElement('foo', false), 'bar');
@access public
@since 3.2.4
@param object HTML_QuickForm_element Element to insert
@param string Name of the element before which the new one is inserted
@return object HTML_QuickForm_element reference to inserted element
@throws HTML_QuickForm_Error
|
[
"Inserts",
"a",
"new",
"element",
"right",
"before",
"the",
"other",
"element"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm.php#L675-L726
|
216,637
|
moodle/moodle
|
lib/pear/HTML/QuickForm.php
|
HTML_QuickForm.&
|
function &addGroup($elements, $name=null, $groupLabel='', $separator=null, $appendName = true)
{
static $anonGroups = 1;
if (0 == strlen($name)) {
$name = 'qf_group_' . $anonGroups++;
$appendName = false;
}
$group =& $this->addElement('group', $name, $groupLabel, $elements, $separator, $appendName);
return $group;
}
|
php
|
function &addGroup($elements, $name=null, $groupLabel='', $separator=null, $appendName = true)
{
static $anonGroups = 1;
if (0 == strlen($name)) {
$name = 'qf_group_' . $anonGroups++;
$appendName = false;
}
$group =& $this->addElement('group', $name, $groupLabel, $elements, $separator, $appendName);
return $group;
}
|
[
"function",
"&",
"addGroup",
"(",
"$",
"elements",
",",
"$",
"name",
"=",
"null",
",",
"$",
"groupLabel",
"=",
"''",
",",
"$",
"separator",
"=",
"null",
",",
"$",
"appendName",
"=",
"true",
")",
"{",
"static",
"$",
"anonGroups",
"=",
"1",
";",
"if",
"(",
"0",
"==",
"strlen",
"(",
"$",
"name",
")",
")",
"{",
"$",
"name",
"=",
"'qf_group_'",
".",
"$",
"anonGroups",
"++",
";",
"$",
"appendName",
"=",
"false",
";",
"}",
"$",
"group",
"=",
"&",
"$",
"this",
"->",
"addElement",
"(",
"'group'",
",",
"$",
"name",
",",
"$",
"groupLabel",
",",
"$",
"elements",
",",
"$",
"separator",
",",
"$",
"appendName",
")",
";",
"return",
"$",
"group",
";",
"}"
] |
Adds an element group
@param array $elements array of elements composing the group
@param string $name (optional)group name
@param string $groupLabel (optional)group label
@param string $separator (optional)string to separate elements
@param string $appendName (optional)specify whether the group name should be
used in the form element name ex: group[element]
@return object reference to added group of elements
@since 2.8
@access public
@throws PEAR_Error
|
[
"Adds",
"an",
"element",
"group"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm.php#L744-L754
|
216,638
|
moodle/moodle
|
lib/pear/HTML/QuickForm.php
|
HTML_QuickForm.&
|
function &getElement($element)
{
if (isset($this->_elementIndex[$element])) {
return $this->_elements[$this->_elementIndex[$element]];
} else {
$error = self::raiseError(null, QUICKFORM_NONEXIST_ELEMENT, null, E_USER_WARNING, "Element '$element' does not exist in HTML_QuickForm::getElement()", 'HTML_QuickForm_Error', true);
return $error;
}
}
|
php
|
function &getElement($element)
{
if (isset($this->_elementIndex[$element])) {
return $this->_elements[$this->_elementIndex[$element]];
} else {
$error = self::raiseError(null, QUICKFORM_NONEXIST_ELEMENT, null, E_USER_WARNING, "Element '$element' does not exist in HTML_QuickForm::getElement()", 'HTML_QuickForm_Error', true);
return $error;
}
}
|
[
"function",
"&",
"getElement",
"(",
"$",
"element",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_elementIndex",
"[",
"$",
"element",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_elements",
"[",
"$",
"this",
"->",
"_elementIndex",
"[",
"$",
"element",
"]",
"]",
";",
"}",
"else",
"{",
"$",
"error",
"=",
"self",
"::",
"raiseError",
"(",
"null",
",",
"QUICKFORM_NONEXIST_ELEMENT",
",",
"null",
",",
"E_USER_WARNING",
",",
"\"Element '$element' does not exist in HTML_QuickForm::getElement()\"",
",",
"'HTML_QuickForm_Error'",
",",
"true",
")",
";",
"return",
"$",
"error",
";",
"}",
"}"
] |
Returns a reference to the element
@param string $element Element name
@since 2.0
@access public
@return object reference to element
@throws HTML_QuickForm_Error
|
[
"Returns",
"a",
"reference",
"to",
"the",
"element"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm.php#L768-L776
|
216,639
|
moodle/moodle
|
lib/pear/HTML/QuickForm.php
|
HTML_QuickForm.&
|
function &getElementValue($element)
{
if (!isset($this->_elementIndex[$element])) {
$error = self::raiseError(null, QUICKFORM_NONEXIST_ELEMENT, null, E_USER_WARNING, "Element '$element' does not exist in HTML_QuickForm::getElementValue()", 'HTML_QuickForm_Error', true);
return $error;
}
$value = $this->_elements[$this->_elementIndex[$element]]->getValue();
if (isset($this->_duplicateIndex[$element])) {
foreach ($this->_duplicateIndex[$element] as $index) {
if (null !== ($v = $this->_elements[$index]->getValue())) {
if (is_array($value)) {
$value[] = $v;
} else {
$value = (null === $value)? $v: array($value, $v);
}
}
}
}
return $value;
}
|
php
|
function &getElementValue($element)
{
if (!isset($this->_elementIndex[$element])) {
$error = self::raiseError(null, QUICKFORM_NONEXIST_ELEMENT, null, E_USER_WARNING, "Element '$element' does not exist in HTML_QuickForm::getElementValue()", 'HTML_QuickForm_Error', true);
return $error;
}
$value = $this->_elements[$this->_elementIndex[$element]]->getValue();
if (isset($this->_duplicateIndex[$element])) {
foreach ($this->_duplicateIndex[$element] as $index) {
if (null !== ($v = $this->_elements[$index]->getValue())) {
if (is_array($value)) {
$value[] = $v;
} else {
$value = (null === $value)? $v: array($value, $v);
}
}
}
}
return $value;
}
|
[
"function",
"&",
"getElementValue",
"(",
"$",
"element",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_elementIndex",
"[",
"$",
"element",
"]",
")",
")",
"{",
"$",
"error",
"=",
"self",
"::",
"raiseError",
"(",
"null",
",",
"QUICKFORM_NONEXIST_ELEMENT",
",",
"null",
",",
"E_USER_WARNING",
",",
"\"Element '$element' does not exist in HTML_QuickForm::getElementValue()\"",
",",
"'HTML_QuickForm_Error'",
",",
"true",
")",
";",
"return",
"$",
"error",
";",
"}",
"$",
"value",
"=",
"$",
"this",
"->",
"_elements",
"[",
"$",
"this",
"->",
"_elementIndex",
"[",
"$",
"element",
"]",
"]",
"->",
"getValue",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_duplicateIndex",
"[",
"$",
"element",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_duplicateIndex",
"[",
"$",
"element",
"]",
"as",
"$",
"index",
")",
"{",
"if",
"(",
"null",
"!==",
"(",
"$",
"v",
"=",
"$",
"this",
"->",
"_elements",
"[",
"$",
"index",
"]",
"->",
"getValue",
"(",
")",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"[",
"]",
"=",
"$",
"v",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"(",
"null",
"===",
"$",
"value",
")",
"?",
"$",
"v",
":",
"array",
"(",
"$",
"value",
",",
"$",
"v",
")",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"value",
";",
"}"
] |
Returns the element's raw value
This returns the value as submitted by the form (not filtered)
or set via setDefaults() or setConstants()
@param string $element Element name
@since 2.0
@access public
@return mixed element value
@throws HTML_QuickForm_Error
|
[
"Returns",
"the",
"element",
"s",
"raw",
"value"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm.php#L793-L812
|
216,640
|
moodle/moodle
|
lib/pear/HTML/QuickForm.php
|
HTML_QuickForm.setElementError
|
function setElementError($element, $message = null)
{
if (!empty($message)) {
$this->_errors[$element] = $message;
} else {
unset($this->_errors[$element]);
}
}
|
php
|
function setElementError($element, $message = null)
{
if (!empty($message)) {
$this->_errors[$element] = $message;
} else {
unset($this->_errors[$element]);
}
}
|
[
"function",
"setElementError",
"(",
"$",
"element",
",",
"$",
"message",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"message",
")",
")",
"{",
"$",
"this",
"->",
"_errors",
"[",
"$",
"element",
"]",
"=",
"$",
"message",
";",
"}",
"else",
"{",
"unset",
"(",
"$",
"this",
"->",
"_errors",
"[",
"$",
"element",
"]",
")",
";",
"}",
"}"
] |
Set error message for a form element
@param string $element Name of form element to set error for
@param string $message Error message, if empty then removes the current error message
@since 1.0
@access public
@return void
|
[
"Set",
"error",
"message",
"for",
"a",
"form",
"element"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm.php#L938-L945
|
216,641
|
moodle/moodle
|
lib/pear/HTML/QuickForm.php
|
HTML_QuickForm.getElementType
|
function getElementType($element)
{
if (isset($this->_elementIndex[$element])) {
return $this->_elements[$this->_elementIndex[$element]]->getType();
}
return false;
}
|
php
|
function getElementType($element)
{
if (isset($this->_elementIndex[$element])) {
return $this->_elements[$this->_elementIndex[$element]]->getType();
}
return false;
}
|
[
"function",
"getElementType",
"(",
"$",
"element",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_elementIndex",
"[",
"$",
"element",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_elements",
"[",
"$",
"this",
"->",
"_elementIndex",
"[",
"$",
"element",
"]",
"]",
"->",
"getType",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Returns the type of the given element
@param string $element Name of form element
@since 1.1
@access public
@return string Type of the element, false if the element is not found
|
[
"Returns",
"the",
"type",
"of",
"the",
"given",
"element"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm.php#L958-L964
|
216,642
|
moodle/moodle
|
lib/pear/HTML/QuickForm.php
|
HTML_QuickForm.updateElementAttr
|
function updateElementAttr($elements, $attrs)
{
if (is_string($elements)) {
$elements = preg_split('/[ ]?,[ ]?/', $elements);
}
foreach (array_keys($elements) as $key) {
if (is_object($elements[$key]) && is_a($elements[$key], 'HTML_QuickForm_element')) {
$elements[$key]->updateAttributes($attrs);
} elseif (isset($this->_elementIndex[$elements[$key]])) {
$this->_elements[$this->_elementIndex[$elements[$key]]]->updateAttributes($attrs);
if (isset($this->_duplicateIndex[$elements[$key]])) {
foreach ($this->_duplicateIndex[$elements[$key]] as $index) {
$this->_elements[$index]->updateAttributes($attrs);
}
}
}
}
}
|
php
|
function updateElementAttr($elements, $attrs)
{
if (is_string($elements)) {
$elements = preg_split('/[ ]?,[ ]?/', $elements);
}
foreach (array_keys($elements) as $key) {
if (is_object($elements[$key]) && is_a($elements[$key], 'HTML_QuickForm_element')) {
$elements[$key]->updateAttributes($attrs);
} elseif (isset($this->_elementIndex[$elements[$key]])) {
$this->_elements[$this->_elementIndex[$elements[$key]]]->updateAttributes($attrs);
if (isset($this->_duplicateIndex[$elements[$key]])) {
foreach ($this->_duplicateIndex[$elements[$key]] as $index) {
$this->_elements[$index]->updateAttributes($attrs);
}
}
}
}
}
|
[
"function",
"updateElementAttr",
"(",
"$",
"elements",
",",
"$",
"attrs",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"elements",
")",
")",
"{",
"$",
"elements",
"=",
"preg_split",
"(",
"'/[ ]?,[ ]?/'",
",",
"$",
"elements",
")",
";",
"}",
"foreach",
"(",
"array_keys",
"(",
"$",
"elements",
")",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"elements",
"[",
"$",
"key",
"]",
")",
"&&",
"is_a",
"(",
"$",
"elements",
"[",
"$",
"key",
"]",
",",
"'HTML_QuickForm_element'",
")",
")",
"{",
"$",
"elements",
"[",
"$",
"key",
"]",
"->",
"updateAttributes",
"(",
"$",
"attrs",
")",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"this",
"->",
"_elementIndex",
"[",
"$",
"elements",
"[",
"$",
"key",
"]",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_elements",
"[",
"$",
"this",
"->",
"_elementIndex",
"[",
"$",
"elements",
"[",
"$",
"key",
"]",
"]",
"]",
"->",
"updateAttributes",
"(",
"$",
"attrs",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_duplicateIndex",
"[",
"$",
"elements",
"[",
"$",
"key",
"]",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_duplicateIndex",
"[",
"$",
"elements",
"[",
"$",
"key",
"]",
"]",
"as",
"$",
"index",
")",
"{",
"$",
"this",
"->",
"_elements",
"[",
"$",
"index",
"]",
"->",
"updateAttributes",
"(",
"$",
"attrs",
")",
";",
"}",
"}",
"}",
"}",
"}"
] |
Updates Attributes for one or more elements
@param mixed $elements Array of element names/objects or string of elements to be updated
@param mixed $attrs Array or sting of html attributes
@since 2.10
@access public
@return void
|
[
"Updates",
"Attributes",
"for",
"one",
"or",
"more",
"elements"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm.php#L978-L995
|
216,643
|
moodle/moodle
|
lib/pear/HTML/QuickForm.php
|
HTML_QuickForm.addFormRule
|
function addFormRule($rule)
{
if (!is_callable($rule)) {
return self::raiseError(null, QUICKFORM_INVALID_RULE, null, E_USER_WARNING, 'Callback function does not exist in HTML_QuickForm::addFormRule()', 'HTML_QuickForm_Error', true);
}
$this->_formRules[] = $rule;
}
|
php
|
function addFormRule($rule)
{
if (!is_callable($rule)) {
return self::raiseError(null, QUICKFORM_INVALID_RULE, null, E_USER_WARNING, 'Callback function does not exist in HTML_QuickForm::addFormRule()', 'HTML_QuickForm_Error', true);
}
$this->_formRules[] = $rule;
}
|
[
"function",
"addFormRule",
"(",
"$",
"rule",
")",
"{",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"rule",
")",
")",
"{",
"return",
"self",
"::",
"raiseError",
"(",
"null",
",",
"QUICKFORM_INVALID_RULE",
",",
"null",
",",
"E_USER_WARNING",
",",
"'Callback function does not exist in HTML_QuickForm::addFormRule()'",
",",
"'HTML_QuickForm_Error'",
",",
"true",
")",
";",
"}",
"$",
"this",
"->",
"_formRules",
"[",
"]",
"=",
"$",
"rule",
";",
"}"
] |
Adds a global validation rule
This should be used when for a rule involving several fields or if
you want to use some completely custom validation for your form.
The rule function/method should return true in case of successful
validation and array('element name' => 'error') when there were errors.
@access public
@param mixed Callback, either function name or array(&$object, 'method')
@throws HTML_QuickForm_Error
|
[
"Adds",
"a",
"global",
"validation",
"rule"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm.php#L1201-L1207
|
216,644
|
moodle/moodle
|
lib/pear/HTML/QuickForm.php
|
HTML_QuickForm._recursiveFilter
|
function _recursiveFilter($filter, $value)
{
if (is_array($value)) {
$cleanValues = array();
foreach ($value as $k => $v) {
$cleanValues[$k] = $this->_recursiveFilter($filter, $v);
}
return $cleanValues;
} else {
return call_user_func($filter, $value);
}
}
|
php
|
function _recursiveFilter($filter, $value)
{
if (is_array($value)) {
$cleanValues = array();
foreach ($value as $k => $v) {
$cleanValues[$k] = $this->_recursiveFilter($filter, $v);
}
return $cleanValues;
} else {
return call_user_func($filter, $value);
}
}
|
[
"function",
"_recursiveFilter",
"(",
"$",
"filter",
",",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"cleanValues",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"cleanValues",
"[",
"$",
"k",
"]",
"=",
"$",
"this",
"->",
"_recursiveFilter",
"(",
"$",
"filter",
",",
"$",
"v",
")",
";",
"}",
"return",
"$",
"cleanValues",
";",
"}",
"else",
"{",
"return",
"call_user_func",
"(",
"$",
"filter",
",",
"$",
"value",
")",
";",
"}",
"}"
] |
Recursively apply a filter function
@param string $filter filter to apply
@param mixed $value submitted values
@since 2.0
@access private
@return cleaned values
|
[
"Recursively",
"apply",
"a",
"filter",
"function"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm.php#L1257-L1268
|
216,645
|
moodle/moodle
|
lib/pear/HTML/QuickForm.php
|
HTML_QuickForm.isRuleRegistered
|
function isRuleRegistered($name, $autoRegister = false)
{
if (is_scalar($name) && isset($GLOBALS['_HTML_QuickForm_registered_rules'][$name])) {
return true;
} elseif (!$autoRegister) {
return false;
}
// automatically register the rule if requested
include_once 'HTML/QuickForm/RuleRegistry.php';
$ruleName = false;
if (is_object($name) && is_a($name, 'html_quickform_rule')) {
$ruleName = !empty($name->name)? $name->name: strtolower(get_class($name));
} elseif (is_string($name) && class_exists($name)) {
$parent = strtolower($name);
do {
if ('html_quickform_rule' == strtolower($parent)) {
$ruleName = strtolower($name);
break;
}
} while ($parent = get_parent_class($parent));
}
if ($ruleName) {
$registry =& HTML_QuickForm_RuleRegistry::singleton();
$registry->registerRule($ruleName, null, $name);
}
return $ruleName;
}
|
php
|
function isRuleRegistered($name, $autoRegister = false)
{
if (is_scalar($name) && isset($GLOBALS['_HTML_QuickForm_registered_rules'][$name])) {
return true;
} elseif (!$autoRegister) {
return false;
}
// automatically register the rule if requested
include_once 'HTML/QuickForm/RuleRegistry.php';
$ruleName = false;
if (is_object($name) && is_a($name, 'html_quickform_rule')) {
$ruleName = !empty($name->name)? $name->name: strtolower(get_class($name));
} elseif (is_string($name) && class_exists($name)) {
$parent = strtolower($name);
do {
if ('html_quickform_rule' == strtolower($parent)) {
$ruleName = strtolower($name);
break;
}
} while ($parent = get_parent_class($parent));
}
if ($ruleName) {
$registry =& HTML_QuickForm_RuleRegistry::singleton();
$registry->registerRule($ruleName, null, $name);
}
return $ruleName;
}
|
[
"function",
"isRuleRegistered",
"(",
"$",
"name",
",",
"$",
"autoRegister",
"=",
"false",
")",
"{",
"if",
"(",
"is_scalar",
"(",
"$",
"name",
")",
"&&",
"isset",
"(",
"$",
"GLOBALS",
"[",
"'_HTML_QuickForm_registered_rules'",
"]",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"elseif",
"(",
"!",
"$",
"autoRegister",
")",
"{",
"return",
"false",
";",
"}",
"// automatically register the rule if requested",
"include_once",
"'HTML/QuickForm/RuleRegistry.php'",
";",
"$",
"ruleName",
"=",
"false",
";",
"if",
"(",
"is_object",
"(",
"$",
"name",
")",
"&&",
"is_a",
"(",
"$",
"name",
",",
"'html_quickform_rule'",
")",
")",
"{",
"$",
"ruleName",
"=",
"!",
"empty",
"(",
"$",
"name",
"->",
"name",
")",
"?",
"$",
"name",
"->",
"name",
":",
"strtolower",
"(",
"get_class",
"(",
"$",
"name",
")",
")",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"name",
")",
"&&",
"class_exists",
"(",
"$",
"name",
")",
")",
"{",
"$",
"parent",
"=",
"strtolower",
"(",
"$",
"name",
")",
";",
"do",
"{",
"if",
"(",
"'html_quickform_rule'",
"==",
"strtolower",
"(",
"$",
"parent",
")",
")",
"{",
"$",
"ruleName",
"=",
"strtolower",
"(",
"$",
"name",
")",
";",
"break",
";",
"}",
"}",
"while",
"(",
"$",
"parent",
"=",
"get_parent_class",
"(",
"$",
"parent",
")",
")",
";",
"}",
"if",
"(",
"$",
"ruleName",
")",
"{",
"$",
"registry",
"=",
"&",
"HTML_QuickForm_RuleRegistry",
"::",
"singleton",
"(",
")",
";",
"$",
"registry",
"->",
"registerRule",
"(",
"$",
"ruleName",
",",
"null",
",",
"$",
"name",
")",
";",
"}",
"return",
"$",
"ruleName",
";",
"}"
] |
Returns whether or not the given rule is supported
@param string $name Validation rule name
@param bool Whether to automatically register subclasses of HTML_QuickForm_Rule
@since 1.0
@access public
@return mixed true if previously registered, false if not, new rule name if auto-registering worked
|
[
"Returns",
"whether",
"or",
"not",
"the",
"given",
"rule",
"is",
"supported"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm.php#L1349-L1375
|
216,646
|
moodle/moodle
|
lib/pear/HTML/QuickForm.php
|
HTML_QuickForm.isElementFrozen
|
function isElementFrozen($element)
{
if (isset($this->_elementIndex[$element])) {
return $this->_elements[$this->_elementIndex[$element]]->isFrozen();
}
return false;
}
|
php
|
function isElementFrozen($element)
{
if (isset($this->_elementIndex[$element])) {
return $this->_elements[$this->_elementIndex[$element]]->isFrozen();
}
return false;
}
|
[
"function",
"isElementFrozen",
"(",
"$",
"element",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_elementIndex",
"[",
"$",
"element",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_elements",
"[",
"$",
"this",
"->",
"_elementIndex",
"[",
"$",
"element",
"]",
"]",
"->",
"isFrozen",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Returns whether or not the form element is frozen
@param string $element Form element name
@since 1.0
@access public
@return boolean
|
[
"Returns",
"whether",
"or",
"not",
"the",
"form",
"element",
"is",
"frozen"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm.php#L1419-L1425
|
216,647
|
moodle/moodle
|
lib/pear/HTML/QuickForm.php
|
HTML_QuickForm.freeze
|
function freeze($elementList=null)
{
if (!isset($elementList)) {
$this->_freezeAll = true;
$elementList = array();
} else {
if (!is_array($elementList)) {
$elementList = preg_split('/[ ]*,[ ]*/', $elementList);
}
$elementList = array_flip($elementList);
}
foreach (array_keys($this->_elements) as $key) {
$name = $this->_elements[$key]->getName();
if ($this->_freezeAll || isset($elementList[$name])) {
$this->_elements[$key]->freeze();
unset($elementList[$name]);
}
}
if (!empty($elementList)) {
return self::raiseError(null, QUICKFORM_NONEXIST_ELEMENT, null, E_USER_WARNING, "Nonexistant element(s): '" . implode("', '", array_keys($elementList)) . "' in HTML_QuickForm::freeze()", 'HTML_QuickForm_Error', true);
}
return true;
}
|
php
|
function freeze($elementList=null)
{
if (!isset($elementList)) {
$this->_freezeAll = true;
$elementList = array();
} else {
if (!is_array($elementList)) {
$elementList = preg_split('/[ ]*,[ ]*/', $elementList);
}
$elementList = array_flip($elementList);
}
foreach (array_keys($this->_elements) as $key) {
$name = $this->_elements[$key]->getName();
if ($this->_freezeAll || isset($elementList[$name])) {
$this->_elements[$key]->freeze();
unset($elementList[$name]);
}
}
if (!empty($elementList)) {
return self::raiseError(null, QUICKFORM_NONEXIST_ELEMENT, null, E_USER_WARNING, "Nonexistant element(s): '" . implode("', '", array_keys($elementList)) . "' in HTML_QuickForm::freeze()", 'HTML_QuickForm_Error', true);
}
return true;
}
|
[
"function",
"freeze",
"(",
"$",
"elementList",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"elementList",
")",
")",
"{",
"$",
"this",
"->",
"_freezeAll",
"=",
"true",
";",
"$",
"elementList",
"=",
"array",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"elementList",
")",
")",
"{",
"$",
"elementList",
"=",
"preg_split",
"(",
"'/[ ]*,[ ]*/'",
",",
"$",
"elementList",
")",
";",
"}",
"$",
"elementList",
"=",
"array_flip",
"(",
"$",
"elementList",
")",
";",
"}",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"_elements",
")",
"as",
"$",
"key",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"_elements",
"[",
"$",
"key",
"]",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_freezeAll",
"||",
"isset",
"(",
"$",
"elementList",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_elements",
"[",
"$",
"key",
"]",
"->",
"freeze",
"(",
")",
";",
"unset",
"(",
"$",
"elementList",
"[",
"$",
"name",
"]",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"elementList",
")",
")",
"{",
"return",
"self",
"::",
"raiseError",
"(",
"null",
",",
"QUICKFORM_NONEXIST_ELEMENT",
",",
"null",
",",
"E_USER_WARNING",
",",
"\"Nonexistant element(s): '\"",
".",
"implode",
"(",
"\"', '\"",
",",
"array_keys",
"(",
"$",
"elementList",
")",
")",
".",
"\"' in HTML_QuickForm::freeze()\"",
",",
"'HTML_QuickForm_Error'",
",",
"true",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Displays elements without HTML input tags
@param mixed $elementList array or string of element(s) to be frozen
@since 1.0
@access public
@throws HTML_QuickForm_Error
|
[
"Displays",
"elements",
"without",
"HTML",
"input",
"tags"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm.php#L1572-L1596
|
216,648
|
moodle/moodle
|
lib/pear/HTML/QuickForm.php
|
HTML_QuickForm.process
|
function process($callback, $mergeFiles = true)
{
if (!is_callable($callback)) {
return self::raiseError(null, QUICKFORM_INVALID_PROCESS, null, E_USER_WARNING, "Callback function does not exist in QuickForm::process()", 'HTML_QuickForm_Error', true);
}
$values = ($mergeFiles === true) ? HTML_QuickForm::arrayMerge($this->_submitValues, $this->_submitFiles) : $this->_submitValues;
return call_user_func($callback, $values);
}
|
php
|
function process($callback, $mergeFiles = true)
{
if (!is_callable($callback)) {
return self::raiseError(null, QUICKFORM_INVALID_PROCESS, null, E_USER_WARNING, "Callback function does not exist in QuickForm::process()", 'HTML_QuickForm_Error', true);
}
$values = ($mergeFiles === true) ? HTML_QuickForm::arrayMerge($this->_submitValues, $this->_submitFiles) : $this->_submitValues;
return call_user_func($callback, $values);
}
|
[
"function",
"process",
"(",
"$",
"callback",
",",
"$",
"mergeFiles",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"callback",
")",
")",
"{",
"return",
"self",
"::",
"raiseError",
"(",
"null",
",",
"QUICKFORM_INVALID_PROCESS",
",",
"null",
",",
"E_USER_WARNING",
",",
"\"Callback function does not exist in QuickForm::process()\"",
",",
"'HTML_QuickForm_Error'",
",",
"true",
")",
";",
"}",
"$",
"values",
"=",
"(",
"$",
"mergeFiles",
"===",
"true",
")",
"?",
"HTML_QuickForm",
"::",
"arrayMerge",
"(",
"$",
"this",
"->",
"_submitValues",
",",
"$",
"this",
"->",
"_submitFiles",
")",
":",
"$",
"this",
"->",
"_submitValues",
";",
"return",
"call_user_func",
"(",
"$",
"callback",
",",
"$",
"values",
")",
";",
"}"
] |
Performs the form data processing
@param mixed $callback Callback, either function name or array(&$object, 'method')
@param bool $mergeFiles Whether uploaded files should be processed too
@since 1.0
@access public
@throws HTML_QuickForm_Error
|
[
"Performs",
"the",
"form",
"data",
"processing"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm.php#L1625-L1632
|
216,649
|
moodle/moodle
|
lib/pear/HTML/QuickForm.php
|
HTML_QuickForm.toHtml
|
function toHtml ($in_data = null)
{
if (!is_null($in_data)) {
$this->addElement('html', $in_data);
}
$renderer =& $this->defaultRenderer();
$this->accept($renderer);
return $renderer->toHtml();
}
|
php
|
function toHtml ($in_data = null)
{
if (!is_null($in_data)) {
$this->addElement('html', $in_data);
}
$renderer =& $this->defaultRenderer();
$this->accept($renderer);
return $renderer->toHtml();
}
|
[
"function",
"toHtml",
"(",
"$",
"in_data",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"in_data",
")",
")",
"{",
"$",
"this",
"->",
"addElement",
"(",
"'html'",
",",
"$",
"in_data",
")",
";",
"}",
"$",
"renderer",
"=",
"&",
"$",
"this",
"->",
"defaultRenderer",
"(",
")",
";",
"$",
"this",
"->",
"accept",
"(",
"$",
"renderer",
")",
";",
"return",
"$",
"renderer",
"->",
"toHtml",
"(",
")",
";",
"}"
] |
Returns an HTML version of the form
@param string $in_data (optional) Any extra data to insert right
before form is rendered. Useful when using templates.
@return string Html version of the form
@since 1.0
@access public
|
[
"Returns",
"an",
"HTML",
"version",
"of",
"the",
"form"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm.php#L1690-L1698
|
216,650
|
moodle/moodle
|
lib/pear/HTML/QuickForm.php
|
HTML_QuickForm.getSubmitValues
|
function getSubmitValues($mergeFiles = false)
{
return $mergeFiles? HTML_QuickForm::arrayMerge($this->_submitValues, $this->_submitFiles): $this->_submitValues;
}
|
php
|
function getSubmitValues($mergeFiles = false)
{
return $mergeFiles? HTML_QuickForm::arrayMerge($this->_submitValues, $this->_submitFiles): $this->_submitValues;
}
|
[
"function",
"getSubmitValues",
"(",
"$",
"mergeFiles",
"=",
"false",
")",
"{",
"return",
"$",
"mergeFiles",
"?",
"HTML_QuickForm",
"::",
"arrayMerge",
"(",
"$",
"this",
"->",
"_submitValues",
",",
"$",
"this",
"->",
"_submitFiles",
")",
":",
"$",
"this",
"->",
"_submitValues",
";",
"}"
] |
Returns the values submitted by the form
@since 2.0
@access public
@param bool Whether uploaded files should be returned too
@return array
|
[
"Returns",
"the",
"values",
"submitted",
"by",
"the",
"form"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm.php#L1808-L1811
|
216,651
|
moodle/moodle
|
lib/pear/HTML/QuickForm.php
|
HTML_QuickForm.toArray
|
function toArray($collectHidden = false)
{
include_once 'HTML/QuickForm/Renderer/Array.php';
$renderer = new HTML_QuickForm_Renderer_Array($collectHidden); //Moodle: PHP 5.3 compatibility
$this->accept($renderer);
return $renderer->toArray();
}
|
php
|
function toArray($collectHidden = false)
{
include_once 'HTML/QuickForm/Renderer/Array.php';
$renderer = new HTML_QuickForm_Renderer_Array($collectHidden); //Moodle: PHP 5.3 compatibility
$this->accept($renderer);
return $renderer->toArray();
}
|
[
"function",
"toArray",
"(",
"$",
"collectHidden",
"=",
"false",
")",
"{",
"include_once",
"'HTML/QuickForm/Renderer/Array.php'",
";",
"$",
"renderer",
"=",
"new",
"HTML_QuickForm_Renderer_Array",
"(",
"$",
"collectHidden",
")",
";",
"//Moodle: PHP 5.3 compatibility",
"$",
"this",
"->",
"accept",
"(",
"$",
"renderer",
")",
";",
"return",
"$",
"renderer",
"->",
"toArray",
"(",
")",
";",
"}"
] |
Returns the form's contents in an array.
The description of the array structure is in HTML_QuickForm_Renderer_Array docs
@since 2.0
@access public
@param bool Whether to collect hidden elements (passed to the Renderer's constructor)
@return array of form contents
|
[
"Returns",
"the",
"form",
"s",
"contents",
"in",
"an",
"array",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm.php#L1826-L1832
|
216,652
|
moodle/moodle
|
lib/pear/HTML/QuickForm.php
|
HTML_QuickForm.exportValues
|
function exportValues($elementList = null)
{
$values = array();
if (null === $elementList) {
// iterate over all elements, calling their exportValue() methods
foreach (array_keys($this->_elements) as $key) {
$value = $this->_elements[$key]->exportValue($this->_submitValues, true);
if (is_array($value)) {
// This shit throws a bogus warning in PHP 4.3.x
$values = HTML_QuickForm::arrayMerge($values, $value);
}
}
} else {
if (!is_array($elementList)) {
$elementList = array_map('trim', explode(',', $elementList));
}
foreach ($elementList as $elementName) {
$value = $this->exportValue($elementName);
$pear = new PEAR();
if ($pear->isError($value)) {
return $value;
}
$values[$elementName] = $value;
}
}
return $values;
}
|
php
|
function exportValues($elementList = null)
{
$values = array();
if (null === $elementList) {
// iterate over all elements, calling their exportValue() methods
foreach (array_keys($this->_elements) as $key) {
$value = $this->_elements[$key]->exportValue($this->_submitValues, true);
if (is_array($value)) {
// This shit throws a bogus warning in PHP 4.3.x
$values = HTML_QuickForm::arrayMerge($values, $value);
}
}
} else {
if (!is_array($elementList)) {
$elementList = array_map('trim', explode(',', $elementList));
}
foreach ($elementList as $elementName) {
$value = $this->exportValue($elementName);
$pear = new PEAR();
if ($pear->isError($value)) {
return $value;
}
$values[$elementName] = $value;
}
}
return $values;
}
|
[
"function",
"exportValues",
"(",
"$",
"elementList",
"=",
"null",
")",
"{",
"$",
"values",
"=",
"array",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"elementList",
")",
"{",
"// iterate over all elements, calling their exportValue() methods",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"_elements",
")",
"as",
"$",
"key",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"_elements",
"[",
"$",
"key",
"]",
"->",
"exportValue",
"(",
"$",
"this",
"->",
"_submitValues",
",",
"true",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"// This shit throws a bogus warning in PHP 4.3.x",
"$",
"values",
"=",
"HTML_QuickForm",
"::",
"arrayMerge",
"(",
"$",
"values",
",",
"$",
"value",
")",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"elementList",
")",
")",
"{",
"$",
"elementList",
"=",
"array_map",
"(",
"'trim'",
",",
"explode",
"(",
"','",
",",
"$",
"elementList",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"elementList",
"as",
"$",
"elementName",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"exportValue",
"(",
"$",
"elementName",
")",
";",
"$",
"pear",
"=",
"new",
"PEAR",
"(",
")",
";",
"if",
"(",
"$",
"pear",
"->",
"isError",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"$",
"values",
"[",
"$",
"elementName",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"values",
";",
"}"
] |
Returns 'safe' elements' values
Unlike getSubmitValues(), this will return only the values
corresponding to the elements present in the form.
@param mixed Array/string of element names, whose values we want. If not set then return all elements.
@access public
@return array An assoc array of elements' values
@throws HTML_QuickForm_Error
|
[
"Returns",
"safe",
"elements",
"values"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm.php#L1882-L1908
|
216,653
|
moodle/moodle
|
lib/pear/HTML/QuickForm.php
|
HTML_QuickForm.errorMessage
|
static function errorMessage($value)
{
// make the variable static so that it only has to do the defining on the first call
static $errorMessages;
// define the varies error messages
if (!isset($errorMessages)) {
$errorMessages = array(
QUICKFORM_OK => 'no error',
QUICKFORM_ERROR => 'unknown error',
QUICKFORM_INVALID_RULE => 'the rule does not exist as a registered rule',
QUICKFORM_NONEXIST_ELEMENT => 'nonexistent html element',
QUICKFORM_INVALID_FILTER => 'invalid filter',
QUICKFORM_UNREGISTERED_ELEMENT => 'unregistered element',
QUICKFORM_INVALID_ELEMENT_NAME => 'element already exists',
QUICKFORM_INVALID_PROCESS => 'process callback does not exist',
QUICKFORM_DEPRECATED => 'method is deprecated',
QUICKFORM_INVALID_DATASOURCE => 'datasource is not an object'
);
}
// If this is an error object, then grab the corresponding error code
if (HTML_QuickForm::isError($value)) {
$value = $value->getCode();
}
// return the textual error message corresponding to the code
return isset($errorMessages[$value]) ? $errorMessages[$value] : $errorMessages[QUICKFORM_ERROR];
}
|
php
|
static function errorMessage($value)
{
// make the variable static so that it only has to do the defining on the first call
static $errorMessages;
// define the varies error messages
if (!isset($errorMessages)) {
$errorMessages = array(
QUICKFORM_OK => 'no error',
QUICKFORM_ERROR => 'unknown error',
QUICKFORM_INVALID_RULE => 'the rule does not exist as a registered rule',
QUICKFORM_NONEXIST_ELEMENT => 'nonexistent html element',
QUICKFORM_INVALID_FILTER => 'invalid filter',
QUICKFORM_UNREGISTERED_ELEMENT => 'unregistered element',
QUICKFORM_INVALID_ELEMENT_NAME => 'element already exists',
QUICKFORM_INVALID_PROCESS => 'process callback does not exist',
QUICKFORM_DEPRECATED => 'method is deprecated',
QUICKFORM_INVALID_DATASOURCE => 'datasource is not an object'
);
}
// If this is an error object, then grab the corresponding error code
if (HTML_QuickForm::isError($value)) {
$value = $value->getCode();
}
// return the textual error message corresponding to the code
return isset($errorMessages[$value]) ? $errorMessages[$value] : $errorMessages[QUICKFORM_ERROR];
}
|
[
"static",
"function",
"errorMessage",
"(",
"$",
"value",
")",
"{",
"// make the variable static so that it only has to do the defining on the first call",
"static",
"$",
"errorMessages",
";",
"// define the varies error messages",
"if",
"(",
"!",
"isset",
"(",
"$",
"errorMessages",
")",
")",
"{",
"$",
"errorMessages",
"=",
"array",
"(",
"QUICKFORM_OK",
"=>",
"'no error'",
",",
"QUICKFORM_ERROR",
"=>",
"'unknown error'",
",",
"QUICKFORM_INVALID_RULE",
"=>",
"'the rule does not exist as a registered rule'",
",",
"QUICKFORM_NONEXIST_ELEMENT",
"=>",
"'nonexistent html element'",
",",
"QUICKFORM_INVALID_FILTER",
"=>",
"'invalid filter'",
",",
"QUICKFORM_UNREGISTERED_ELEMENT",
"=>",
"'unregistered element'",
",",
"QUICKFORM_INVALID_ELEMENT_NAME",
"=>",
"'element already exists'",
",",
"QUICKFORM_INVALID_PROCESS",
"=>",
"'process callback does not exist'",
",",
"QUICKFORM_DEPRECATED",
"=>",
"'method is deprecated'",
",",
"QUICKFORM_INVALID_DATASOURCE",
"=>",
"'datasource is not an object'",
")",
";",
"}",
"// If this is an error object, then grab the corresponding error code",
"if",
"(",
"HTML_QuickForm",
"::",
"isError",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"->",
"getCode",
"(",
")",
";",
"}",
"// return the textual error message corresponding to the code",
"return",
"isset",
"(",
"$",
"errorMessages",
"[",
"$",
"value",
"]",
")",
"?",
"$",
"errorMessages",
"[",
"$",
"value",
"]",
":",
"$",
"errorMessages",
"[",
"QUICKFORM_ERROR",
"]",
";",
"}"
] |
Return a textual error message for an QuickForm error code
@access public
@param int error code
@return string error message
|
[
"Return",
"a",
"textual",
"error",
"message",
"for",
"an",
"QuickForm",
"error",
"code"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm.php#L1953-L1981
|
216,654
|
moodle/moodle
|
question/type/calculated/questiontype.php
|
qtype_calculated.print_next_wizard_page
|
public function print_next_wizard_page($question, $form, $course) {
global $CFG, $SESSION, $COURSE;
// Catch invalid navigation & reloads.
if (empty($question->id) && empty($SESSION->calculated)) {
redirect('edit.php?courseid='.$COURSE->id, 'The page you are loading has expired.', 3);
}
// See where we're coming from.
switch($form->wizardpage) {
case 'question':
require("{$CFG->dirroot}/question/type/calculated/datasetdefinitions.php");
break;
case 'datasetdefinitions':
case 'datasetitems':
require("{$CFG->dirroot}/question/type/calculated/datasetitems.php");
break;
default:
print_error('invalidwizardpage', 'question');
break;
}
}
|
php
|
public function print_next_wizard_page($question, $form, $course) {
global $CFG, $SESSION, $COURSE;
// Catch invalid navigation & reloads.
if (empty($question->id) && empty($SESSION->calculated)) {
redirect('edit.php?courseid='.$COURSE->id, 'The page you are loading has expired.', 3);
}
// See where we're coming from.
switch($form->wizardpage) {
case 'question':
require("{$CFG->dirroot}/question/type/calculated/datasetdefinitions.php");
break;
case 'datasetdefinitions':
case 'datasetitems':
require("{$CFG->dirroot}/question/type/calculated/datasetitems.php");
break;
default:
print_error('invalidwizardpage', 'question');
break;
}
}
|
[
"public",
"function",
"print_next_wizard_page",
"(",
"$",
"question",
",",
"$",
"form",
",",
"$",
"course",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"SESSION",
",",
"$",
"COURSE",
";",
"// Catch invalid navigation & reloads.",
"if",
"(",
"empty",
"(",
"$",
"question",
"->",
"id",
")",
"&&",
"empty",
"(",
"$",
"SESSION",
"->",
"calculated",
")",
")",
"{",
"redirect",
"(",
"'edit.php?courseid='",
".",
"$",
"COURSE",
"->",
"id",
",",
"'The page you are loading has expired.'",
",",
"3",
")",
";",
"}",
"// See where we're coming from.",
"switch",
"(",
"$",
"form",
"->",
"wizardpage",
")",
"{",
"case",
"'question'",
":",
"require",
"(",
"\"{$CFG->dirroot}/question/type/calculated/datasetdefinitions.php\"",
")",
";",
"break",
";",
"case",
"'datasetdefinitions'",
":",
"case",
"'datasetitems'",
":",
"require",
"(",
"\"{$CFG->dirroot}/question/type/calculated/datasetitems.php\"",
")",
";",
"break",
";",
"default",
":",
"print_error",
"(",
"'invalidwizardpage'",
",",
"'question'",
")",
";",
"break",
";",
"}",
"}"
] |
This gets called by editquestion.php after the standard question is saved.
|
[
"This",
"gets",
"called",
"by",
"editquestion",
".",
"php",
"after",
"the",
"standard",
"question",
"is",
"saved",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/calculated/questiontype.php#L364-L385
|
216,655
|
moodle/moodle
|
question/type/calculated/questiontype.php
|
qtype_calculated.&
|
public function &next_wizard_form($submiturl, $question, $wizardnow) {
global $CFG, $SESSION, $COURSE;
// Catch invalid navigation & reloads.
if (empty($question->id) && empty($SESSION->calculated)) {
redirect('edit.php?courseid=' . $COURSE->id,
'The page you are loading has expired. Cannot get next wizard form.', 3);
}
if (empty($question->id)) {
$question = $SESSION->calculated->questionform;
}
// See where we're coming from.
switch($wizardnow) {
case 'datasetdefinitions':
require("{$CFG->dirroot}/question/type/calculated/datasetdefinitions_form.php");
$mform = new question_dataset_dependent_definitions_form(
"{$submiturl}?wizardnow=datasetdefinitions", $question);
break;
case 'datasetitems':
require("{$CFG->dirroot}/question/type/calculated/datasetitems_form.php");
$regenerate = optional_param('forceregeneration', false, PARAM_BOOL);
$mform = new question_dataset_dependent_items_form(
"{$submiturl}?wizardnow=datasetitems", $question, $regenerate);
break;
default:
print_error('invalidwizardpage', 'question');
break;
}
return $mform;
}
|
php
|
public function &next_wizard_form($submiturl, $question, $wizardnow) {
global $CFG, $SESSION, $COURSE;
// Catch invalid navigation & reloads.
if (empty($question->id) && empty($SESSION->calculated)) {
redirect('edit.php?courseid=' . $COURSE->id,
'The page you are loading has expired. Cannot get next wizard form.', 3);
}
if (empty($question->id)) {
$question = $SESSION->calculated->questionform;
}
// See where we're coming from.
switch($wizardnow) {
case 'datasetdefinitions':
require("{$CFG->dirroot}/question/type/calculated/datasetdefinitions_form.php");
$mform = new question_dataset_dependent_definitions_form(
"{$submiturl}?wizardnow=datasetdefinitions", $question);
break;
case 'datasetitems':
require("{$CFG->dirroot}/question/type/calculated/datasetitems_form.php");
$regenerate = optional_param('forceregeneration', false, PARAM_BOOL);
$mform = new question_dataset_dependent_items_form(
"{$submiturl}?wizardnow=datasetitems", $question, $regenerate);
break;
default:
print_error('invalidwizardpage', 'question');
break;
}
return $mform;
}
|
[
"public",
"function",
"&",
"next_wizard_form",
"(",
"$",
"submiturl",
",",
"$",
"question",
",",
"$",
"wizardnow",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"SESSION",
",",
"$",
"COURSE",
";",
"// Catch invalid navigation & reloads.",
"if",
"(",
"empty",
"(",
"$",
"question",
"->",
"id",
")",
"&&",
"empty",
"(",
"$",
"SESSION",
"->",
"calculated",
")",
")",
"{",
"redirect",
"(",
"'edit.php?courseid='",
".",
"$",
"COURSE",
"->",
"id",
",",
"'The page you are loading has expired. Cannot get next wizard form.'",
",",
"3",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"question",
"->",
"id",
")",
")",
"{",
"$",
"question",
"=",
"$",
"SESSION",
"->",
"calculated",
"->",
"questionform",
";",
"}",
"// See where we're coming from.",
"switch",
"(",
"$",
"wizardnow",
")",
"{",
"case",
"'datasetdefinitions'",
":",
"require",
"(",
"\"{$CFG->dirroot}/question/type/calculated/datasetdefinitions_form.php\"",
")",
";",
"$",
"mform",
"=",
"new",
"question_dataset_dependent_definitions_form",
"(",
"\"{$submiturl}?wizardnow=datasetdefinitions\"",
",",
"$",
"question",
")",
";",
"break",
";",
"case",
"'datasetitems'",
":",
"require",
"(",
"\"{$CFG->dirroot}/question/type/calculated/datasetitems_form.php\"",
")",
";",
"$",
"regenerate",
"=",
"optional_param",
"(",
"'forceregeneration'",
",",
"false",
",",
"PARAM_BOOL",
")",
";",
"$",
"mform",
"=",
"new",
"question_dataset_dependent_items_form",
"(",
"\"{$submiturl}?wizardnow=datasetitems\"",
",",
"$",
"question",
",",
"$",
"regenerate",
")",
";",
"break",
";",
"default",
":",
"print_error",
"(",
"'invalidwizardpage'",
",",
"'question'",
")",
";",
"break",
";",
"}",
"return",
"$",
"mform",
";",
"}"
] |
This gets called by question2.php after the standard question is saved.
|
[
"This",
"gets",
"called",
"by",
"question2",
".",
"php",
"after",
"the",
"standard",
"question",
"is",
"saved",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/calculated/questiontype.php#L388-L419
|
216,656
|
moodle/moodle
|
question/type/calculated/questiontype.php
|
qtype_calculated.validate_question_data
|
protected function validate_question_data($question) {
$this->validate_text($question->questiontext); // Yes, really no ['text'].
if (isset($question->generalfeedback['text'])) {
$this->validate_text($question->generalfeedback['text']);
} else if (isset($question->generalfeedback)) {
$this->validate_text($question->generalfeedback); // Because question import is weird.
}
foreach ($question->answer as $key => $answer) {
$this->validate_answer($answer);
$this->validate_text($question->feedback[$key]['text']);
}
}
|
php
|
protected function validate_question_data($question) {
$this->validate_text($question->questiontext); // Yes, really no ['text'].
if (isset($question->generalfeedback['text'])) {
$this->validate_text($question->generalfeedback['text']);
} else if (isset($question->generalfeedback)) {
$this->validate_text($question->generalfeedback); // Because question import is weird.
}
foreach ($question->answer as $key => $answer) {
$this->validate_answer($answer);
$this->validate_text($question->feedback[$key]['text']);
}
}
|
[
"protected",
"function",
"validate_question_data",
"(",
"$",
"question",
")",
"{",
"$",
"this",
"->",
"validate_text",
"(",
"$",
"question",
"->",
"questiontext",
")",
";",
"// Yes, really no ['text'].",
"if",
"(",
"isset",
"(",
"$",
"question",
"->",
"generalfeedback",
"[",
"'text'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"validate_text",
"(",
"$",
"question",
"->",
"generalfeedback",
"[",
"'text'",
"]",
")",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"question",
"->",
"generalfeedback",
")",
")",
"{",
"$",
"this",
"->",
"validate_text",
"(",
"$",
"question",
"->",
"generalfeedback",
")",
";",
"// Because question import is weird.",
"}",
"foreach",
"(",
"$",
"question",
"->",
"answer",
"as",
"$",
"key",
"=>",
"$",
"answer",
")",
"{",
"$",
"this",
"->",
"validate_answer",
"(",
"$",
"answer",
")",
";",
"$",
"this",
"->",
"validate_text",
"(",
"$",
"question",
"->",
"feedback",
"[",
"$",
"key",
"]",
"[",
"'text'",
"]",
")",
";",
"}",
"}"
] |
Validate data before save.
@param stdClass $question data from the form / import file.
|
[
"Validate",
"data",
"before",
"save",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/calculated/questiontype.php#L486-L499
|
216,657
|
moodle/moodle
|
question/type/calculated/questiontype.php
|
qtype_calculated.get_database_dataset_items
|
public function get_database_dataset_items($definition) {
global $CFG, $DB;
$databasedataitems = $DB->get_records_sql(// Use number as key!!
" SELECT id , itemnumber, definition, value
FROM {question_dataset_items}
WHERE definition = $definition order by id DESC ", array($definition));
$dataitems = Array();
foreach ($databasedataitems as $id => $dataitem) {
if (!isset($dataitems[$dataitem->itemnumber])) {
$dataitems[$dataitem->itemnumber] = $dataitem;
}
}
ksort($dataitems);
return $dataitems;
}
|
php
|
public function get_database_dataset_items($definition) {
global $CFG, $DB;
$databasedataitems = $DB->get_records_sql(// Use number as key!!
" SELECT id , itemnumber, definition, value
FROM {question_dataset_items}
WHERE definition = $definition order by id DESC ", array($definition));
$dataitems = Array();
foreach ($databasedataitems as $id => $dataitem) {
if (!isset($dataitems[$dataitem->itemnumber])) {
$dataitems[$dataitem->itemnumber] = $dataitem;
}
}
ksort($dataitems);
return $dataitems;
}
|
[
"public",
"function",
"get_database_dataset_items",
"(",
"$",
"definition",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
";",
"$",
"databasedataitems",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"// Use number as key!!",
"\" SELECT id , itemnumber, definition, value\n FROM {question_dataset_items}\n WHERE definition = $definition order by id DESC \"",
",",
"array",
"(",
"$",
"definition",
")",
")",
";",
"$",
"dataitems",
"=",
"Array",
"(",
")",
";",
"foreach",
"(",
"$",
"databasedataitems",
"as",
"$",
"id",
"=>",
"$",
"dataitem",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"dataitems",
"[",
"$",
"dataitem",
"->",
"itemnumber",
"]",
")",
")",
"{",
"$",
"dataitems",
"[",
"$",
"dataitem",
"->",
"itemnumber",
"]",
"=",
"$",
"dataitem",
";",
"}",
"}",
"ksort",
"(",
"$",
"dataitems",
")",
";",
"return",
"$",
"dataitems",
";",
"}"
] |
This function get the dataset items using id as unique parameter and return an
array with itemnumber as index sorted ascendant
If the multiple records with the same itemnumber exist, only the newest one
i.e with the greatest id is used, the others are ignored but not deleted.
MDL-19210
|
[
"This",
"function",
"get",
"the",
"dataset",
"items",
"using",
"id",
"as",
"unique",
"parameter",
"and",
"return",
"an",
"array",
"with",
"itemnumber",
"as",
"index",
"sorted",
"ascendant",
"If",
"the",
"multiple",
"records",
"with",
"the",
"same",
"itemnumber",
"exist",
"only",
"the",
"newest",
"one",
"i",
".",
"e",
"with",
"the",
"greatest",
"id",
"is",
"used",
"the",
"others",
"are",
"ignored",
"but",
"not",
"deleted",
".",
"MDL",
"-",
"19210"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/calculated/questiontype.php#L860-L874
|
216,658
|
moodle/moodle
|
question/type/calculated/questiontype.php
|
qtype_calculated.pick_question_dataset
|
public function pick_question_dataset($question, $datasetitem) {
// Select a dataset in the following format:
// an array indexed by the variable names (d.name) pointing to the value
// to be substituted.
global $CFG, $DB;
if (!$dataitems = $DB->get_records_sql(
"SELECT i.id, d.name, i.value
FROM {question_dataset_definitions} d,
{question_dataset_items} i,
{question_datasets} q
WHERE q.question = ?
AND q.datasetdefinition = d.id
AND d.id = i.definition
AND i.itemnumber = ?
ORDER BY i.id DESC ", array($question->id, $datasetitem))) {
$a = new stdClass();
$a->id = $question->id;
$a->item = $datasetitem;
print_error('cannotgetdsfordependent', 'question', '', $a);
}
$dataset = Array();
foreach ($dataitems as $id => $dataitem) {
if (!isset($dataset[$dataitem->name])) {
$dataset[$dataitem->name] = $dataitem->value;
}
}
return $dataset;
}
|
php
|
public function pick_question_dataset($question, $datasetitem) {
// Select a dataset in the following format:
// an array indexed by the variable names (d.name) pointing to the value
// to be substituted.
global $CFG, $DB;
if (!$dataitems = $DB->get_records_sql(
"SELECT i.id, d.name, i.value
FROM {question_dataset_definitions} d,
{question_dataset_items} i,
{question_datasets} q
WHERE q.question = ?
AND q.datasetdefinition = d.id
AND d.id = i.definition
AND i.itemnumber = ?
ORDER BY i.id DESC ", array($question->id, $datasetitem))) {
$a = new stdClass();
$a->id = $question->id;
$a->item = $datasetitem;
print_error('cannotgetdsfordependent', 'question', '', $a);
}
$dataset = Array();
foreach ($dataitems as $id => $dataitem) {
if (!isset($dataset[$dataitem->name])) {
$dataset[$dataitem->name] = $dataitem->value;
}
}
return $dataset;
}
|
[
"public",
"function",
"pick_question_dataset",
"(",
"$",
"question",
",",
"$",
"datasetitem",
")",
"{",
"// Select a dataset in the following format:",
"// an array indexed by the variable names (d.name) pointing to the value",
"// to be substituted.",
"global",
"$",
"CFG",
",",
"$",
"DB",
";",
"if",
"(",
"!",
"$",
"dataitems",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"\"SELECT i.id, d.name, i.value\n FROM {question_dataset_definitions} d,\n {question_dataset_items} i,\n {question_datasets} q\n WHERE q.question = ?\n AND q.datasetdefinition = d.id\n AND d.id = i.definition\n AND i.itemnumber = ?\n ORDER BY i.id DESC \"",
",",
"array",
"(",
"$",
"question",
"->",
"id",
",",
"$",
"datasetitem",
")",
")",
")",
"{",
"$",
"a",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"a",
"->",
"id",
"=",
"$",
"question",
"->",
"id",
";",
"$",
"a",
"->",
"item",
"=",
"$",
"datasetitem",
";",
"print_error",
"(",
"'cannotgetdsfordependent'",
",",
"'question'",
",",
"''",
",",
"$",
"a",
")",
";",
"}",
"$",
"dataset",
"=",
"Array",
"(",
")",
";",
"foreach",
"(",
"$",
"dataitems",
"as",
"$",
"id",
"=>",
"$",
"dataitem",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"dataset",
"[",
"$",
"dataitem",
"->",
"name",
"]",
")",
")",
"{",
"$",
"dataset",
"[",
"$",
"dataitem",
"->",
"name",
"]",
"=",
"$",
"dataitem",
"->",
"value",
";",
"}",
"}",
"return",
"$",
"dataset",
";",
"}"
] |
Dataset functionality.
|
[
"Dataset",
"functionality",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/calculated/questiontype.php#L1460-L1487
|
216,659
|
moodle/moodle
|
question/type/calculated/questiontype.php
|
qtype_calculated.find_dataset_names
|
public function find_dataset_names($text) {
preg_match_all(self::PLACEHODLER_REGEX, $text, $matches);
return array_combine($matches[1], $matches[1]);
}
|
php
|
public function find_dataset_names($text) {
preg_match_all(self::PLACEHODLER_REGEX, $text, $matches);
return array_combine($matches[1], $matches[1]);
}
|
[
"public",
"function",
"find_dataset_names",
"(",
"$",
"text",
")",
"{",
"preg_match_all",
"(",
"self",
"::",
"PLACEHODLER_REGEX",
",",
"$",
"text",
",",
"$",
"matches",
")",
";",
"return",
"array_combine",
"(",
"$",
"matches",
"[",
"1",
"]",
",",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"}"
] |
Find the names of all datasets mentioned in a piece of question content like the question text.
@param $text the text to analyse.
@return array with dataset name for both key and value.
|
[
"Find",
"the",
"names",
"of",
"all",
"datasets",
"mentioned",
"in",
"a",
"piece",
"of",
"question",
"content",
"like",
"the",
"question",
"text",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/calculated/questiontype.php#L1552-L1555
|
216,660
|
moodle/moodle
|
question/type/calculated/questiontype.php
|
qtype_calculated.find_formulas
|
public function find_formulas($text) {
preg_match_all(self::FORMULAS_IN_TEXT_REGEX, $text, $matches);
return array_combine($matches[1], $matches[1]);
}
|
php
|
public function find_formulas($text) {
preg_match_all(self::FORMULAS_IN_TEXT_REGEX, $text, $matches);
return array_combine($matches[1], $matches[1]);
}
|
[
"public",
"function",
"find_formulas",
"(",
"$",
"text",
")",
"{",
"preg_match_all",
"(",
"self",
"::",
"FORMULAS_IN_TEXT_REGEX",
",",
"$",
"text",
",",
"$",
"matches",
")",
";",
"return",
"array_combine",
"(",
"$",
"matches",
"[",
"1",
"]",
",",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"}"
] |
Find all the formulas in a bit of text.
For example, called with "What is {a} plus {b}? (Hint, it is not {={a}*{b}}.)" this
returns ['{a}*{b}'].
@param $text text to analyse.
@return array where they keys an values are the formulas.
|
[
"Find",
"all",
"the",
"formulas",
"in",
"a",
"bit",
"of",
"text",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/calculated/questiontype.php#L1566-L1569
|
216,661
|
moodle/moodle
|
question/type/calculated/questiontype.php
|
qtype_calculated.get_dataset_definitions_category
|
public function get_dataset_definitions_category($form) {
global $CFG, $DB;
$datasetdefs = array();
$lnamemax = 30;
if (!empty($form->category)) {
$sql = "SELECT i.*, d.*
FROM {question_datasets} d, {question_dataset_definitions} i
WHERE i.id = d.datasetdefinition AND i.category = ?";
if ($records = $DB->get_records_sql($sql, array($form->category))) {
foreach ($records as $r) {
if (!isset ($datasetdefs["{$r->name}"])) {
$datasetdefs["{$r->name}"] = $r->itemcount;
}
}
}
}
return $datasetdefs;
}
|
php
|
public function get_dataset_definitions_category($form) {
global $CFG, $DB;
$datasetdefs = array();
$lnamemax = 30;
if (!empty($form->category)) {
$sql = "SELECT i.*, d.*
FROM {question_datasets} d, {question_dataset_definitions} i
WHERE i.id = d.datasetdefinition AND i.category = ?";
if ($records = $DB->get_records_sql($sql, array($form->category))) {
foreach ($records as $r) {
if (!isset ($datasetdefs["{$r->name}"])) {
$datasetdefs["{$r->name}"] = $r->itemcount;
}
}
}
}
return $datasetdefs;
}
|
[
"public",
"function",
"get_dataset_definitions_category",
"(",
"$",
"form",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
";",
"$",
"datasetdefs",
"=",
"array",
"(",
")",
";",
"$",
"lnamemax",
"=",
"30",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"form",
"->",
"category",
")",
")",
"{",
"$",
"sql",
"=",
"\"SELECT i.*, d.*\n FROM {question_datasets} d, {question_dataset_definitions} i\n WHERE i.id = d.datasetdefinition AND i.category = ?\"",
";",
"if",
"(",
"$",
"records",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"$",
"sql",
",",
"array",
"(",
"$",
"form",
"->",
"category",
")",
")",
")",
"{",
"foreach",
"(",
"$",
"records",
"as",
"$",
"r",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"datasetdefs",
"[",
"\"{$r->name}\"",
"]",
")",
")",
"{",
"$",
"datasetdefs",
"[",
"\"{$r->name}\"",
"]",
"=",
"$",
"r",
"->",
"itemcount",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"datasetdefs",
";",
"}"
] |
This function retrieve the item count of the available category shareable
wild cards that is added as a comment displayed when a wild card with
the same name is displayed in datasetdefinitions_form.php
|
[
"This",
"function",
"retrieve",
"the",
"item",
"count",
"of",
"the",
"available",
"category",
"shareable",
"wild",
"cards",
"that",
"is",
"added",
"as",
"a",
"comment",
"displayed",
"when",
"a",
"wild",
"card",
"with",
"the",
"same",
"name",
"is",
"displayed",
"in",
"datasetdefinitions_form",
".",
"php"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/calculated/questiontype.php#L1576-L1593
|
216,662
|
moodle/moodle
|
question/type/calculated/questiontype.php
|
qtype_calculated.get_short_question_name
|
public function get_short_question_name($stringtoshorten, $characterlimit)
{
if (!empty($stringtoshorten)) {
$returnstring = format_string($stringtoshorten);
if (strlen($returnstring) > $characterlimit) {
$returnstring = shorten_text($returnstring, $characterlimit, true);
}
return $returnstring;
} else {
return '';
}
}
|
php
|
public function get_short_question_name($stringtoshorten, $characterlimit)
{
if (!empty($stringtoshorten)) {
$returnstring = format_string($stringtoshorten);
if (strlen($returnstring) > $characterlimit) {
$returnstring = shorten_text($returnstring, $characterlimit, true);
}
return $returnstring;
} else {
return '';
}
}
|
[
"public",
"function",
"get_short_question_name",
"(",
"$",
"stringtoshorten",
",",
"$",
"characterlimit",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"stringtoshorten",
")",
")",
"{",
"$",
"returnstring",
"=",
"format_string",
"(",
"$",
"stringtoshorten",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"returnstring",
")",
">",
"$",
"characterlimit",
")",
"{",
"$",
"returnstring",
"=",
"shorten_text",
"(",
"$",
"returnstring",
",",
"$",
"characterlimit",
",",
"true",
")",
";",
"}",
"return",
"$",
"returnstring",
";",
"}",
"else",
"{",
"return",
"''",
";",
"}",
"}"
] |
This function shortens a question name if it exceeds the character limit.
@param string $stringtoshorten the string to be shortened.
@param int $characterlimit the character limit.
@return string
|
[
"This",
"function",
"shortens",
"a",
"question",
"name",
"if",
"it",
"exceeds",
"the",
"character",
"limit",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/calculated/questiontype.php#L1676-L1687
|
216,663
|
moodle/moodle
|
mod/forum/classes/local/vaults/preprocessors/extract_context.php
|
extract_context.execute
|
public function execute(array $records) : array {
return array_map(function($record) {
$contextid = $record->ctxid;
context_helper::preload_from_record($record);
$context = context::instance_by_id($contextid);
return $context;
}, $records);
}
|
php
|
public function execute(array $records) : array {
return array_map(function($record) {
$contextid = $record->ctxid;
context_helper::preload_from_record($record);
$context = context::instance_by_id($contextid);
return $context;
}, $records);
}
|
[
"public",
"function",
"execute",
"(",
"array",
"$",
"records",
")",
":",
"array",
"{",
"return",
"array_map",
"(",
"function",
"(",
"$",
"record",
")",
"{",
"$",
"contextid",
"=",
"$",
"record",
"->",
"ctxid",
";",
"context_helper",
"::",
"preload_from_record",
"(",
"$",
"record",
")",
";",
"$",
"context",
"=",
"context",
"::",
"instance_by_id",
"(",
"$",
"contextid",
")",
";",
"return",
"$",
"context",
";",
"}",
",",
"$",
"records",
")",
";",
"}"
] |
Extract the contexts from a list of records.
@param stdClass[] $records The list of records which have context properties
@return context[] List of contexts matching the records.
|
[
"Extract",
"the",
"contexts",
"from",
"a",
"list",
"of",
"records",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/preprocessors/extract_context.php#L45-L52
|
216,664
|
moodle/moodle
|
report/loglive/classes/table_log.php
|
report_loglive_table_log.col_course
|
public function col_course($event) {
if (empty($event->courseid) || empty($this->courseshortnames[$event->courseid])) {
return '-';
} else {
return $this->courseshortnames[$event->courseid];
}
}
|
php
|
public function col_course($event) {
if (empty($event->courseid) || empty($this->courseshortnames[$event->courseid])) {
return '-';
} else {
return $this->courseshortnames[$event->courseid];
}
}
|
[
"public",
"function",
"col_course",
"(",
"$",
"event",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"event",
"->",
"courseid",
")",
"||",
"empty",
"(",
"$",
"this",
"->",
"courseshortnames",
"[",
"$",
"event",
"->",
"courseid",
"]",
")",
")",
"{",
"return",
"'-'",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"courseshortnames",
"[",
"$",
"event",
"->",
"courseid",
"]",
";",
"}",
"}"
] |
Generate the course column.
@param stdClass $event event data.
@return string HTML for the course column.
|
[
"Generate",
"the",
"course",
"column",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/loglive/classes/table_log.php#L104-L110
|
216,665
|
moodle/moodle
|
report/loglive/classes/table_log.php
|
report_loglive_table_log.col_eventname
|
public function col_eventname($event) {
// Event name.
if ($this->filterparams->logreader instanceof logstore_legacy\log\store) {
// Hack for support of logstore_legacy.
$eventname = $event->eventname;
} else {
$eventname = $event->get_name();
}
if ($url = $event->get_url()) {
$eventname = $this->action_link($url, $eventname, 'action');
}
return $eventname;
}
|
php
|
public function col_eventname($event) {
// Event name.
if ($this->filterparams->logreader instanceof logstore_legacy\log\store) {
// Hack for support of logstore_legacy.
$eventname = $event->eventname;
} else {
$eventname = $event->get_name();
}
if ($url = $event->get_url()) {
$eventname = $this->action_link($url, $eventname, 'action');
}
return $eventname;
}
|
[
"public",
"function",
"col_eventname",
"(",
"$",
"event",
")",
"{",
"// Event name.",
"if",
"(",
"$",
"this",
"->",
"filterparams",
"->",
"logreader",
"instanceof",
"logstore_legacy",
"\\",
"log",
"\\",
"store",
")",
"{",
"// Hack for support of logstore_legacy.",
"$",
"eventname",
"=",
"$",
"event",
"->",
"eventname",
";",
"}",
"else",
"{",
"$",
"eventname",
"=",
"$",
"event",
"->",
"get_name",
"(",
")",
";",
"}",
"if",
"(",
"$",
"url",
"=",
"$",
"event",
"->",
"get_url",
"(",
")",
")",
"{",
"$",
"eventname",
"=",
"$",
"this",
"->",
"action_link",
"(",
"$",
"url",
",",
"$",
"eventname",
",",
"'action'",
")",
";",
"}",
"return",
"$",
"eventname",
";",
"}"
] |
Generate the event name column.
@param stdClass $event event data.
@return string HTML for the event name column
|
[
"Generate",
"the",
"event",
"name",
"column",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/loglive/classes/table_log.php#L232-L244
|
216,666
|
moodle/moodle
|
admin/tool/httpsreplace/classes/url_finder.php
|
url_finder.domain_swap
|
protected function domain_swap($table, $column, $domain, $search) {
global $DB;
$renames = json_decode(get_config('tool_httpsreplace', 'renames'), true);
if (isset($renames[$domain])) {
$replace = preg_replace('|http://'.preg_quote($domain).'|i', 'https://' . $renames[$domain], $search);
} else {
$replace = preg_replace('|http://|i', 'https://', $search);
}
$DB->set_debug(true);
$DB->replace_all_text($table, $column, $search, $replace);
$DB->set_debug(false);
}
|
php
|
protected function domain_swap($table, $column, $domain, $search) {
global $DB;
$renames = json_decode(get_config('tool_httpsreplace', 'renames'), true);
if (isset($renames[$domain])) {
$replace = preg_replace('|http://'.preg_quote($domain).'|i', 'https://' . $renames[$domain], $search);
} else {
$replace = preg_replace('|http://|i', 'https://', $search);
}
$DB->set_debug(true);
$DB->replace_all_text($table, $column, $search, $replace);
$DB->set_debug(false);
}
|
[
"protected",
"function",
"domain_swap",
"(",
"$",
"table",
",",
"$",
"column",
",",
"$",
"domain",
",",
"$",
"search",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"renames",
"=",
"json_decode",
"(",
"get_config",
"(",
"'tool_httpsreplace'",
",",
"'renames'",
")",
",",
"true",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"renames",
"[",
"$",
"domain",
"]",
")",
")",
"{",
"$",
"replace",
"=",
"preg_replace",
"(",
"'|http://'",
".",
"preg_quote",
"(",
"$",
"domain",
")",
".",
"'|i'",
",",
"'https://'",
".",
"$",
"renames",
"[",
"$",
"domain",
"]",
",",
"$",
"search",
")",
";",
"}",
"else",
"{",
"$",
"replace",
"=",
"preg_replace",
"(",
"'|http://|i'",
",",
"'https://'",
",",
"$",
"search",
")",
";",
"}",
"$",
"DB",
"->",
"set_debug",
"(",
"true",
")",
";",
"$",
"DB",
"->",
"replace_all_text",
"(",
"$",
"table",
",",
"$",
"column",
",",
"$",
"search",
",",
"$",
"replace",
")",
";",
"$",
"DB",
"->",
"set_debug",
"(",
"false",
")",
";",
"}"
] |
Replace http domains with https equivalent, with two types of exceptions
for less straightforward swaps.
@param string $table
@param database_column_info $column
@param string $domain
@param string $search search string that has prefix, protocol, domain name and one extra character,
example1: src="http://host.com/
example2: DATA="HTTP://MYDOMAIN.EDU"
example3: src="HTTP://hello.world?
@return void
|
[
"Replace",
"http",
"domains",
"with",
"https",
"equivalent",
"with",
"two",
"types",
"of",
"exceptions",
"for",
"less",
"straightforward",
"swaps",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/httpsreplace/classes/url_finder.php#L74-L87
|
216,667
|
moodle/moodle
|
admin/tool/httpsreplace/classes/url_finder.php
|
url_finder.get_select_search_in_column
|
protected function get_select_search_in_column($columnname) {
global $DB;
if ($DB->sql_regex_supported()) {
// Database supports regex, use it for better match.
$select = $columnname . ' ' . $DB->sql_regex() . ' ?';
$params = ["(src|data)\ *=\ *[\\\"\']http://"];
} else {
// Databases without regex support should use case-insensitive LIKE.
// This will have false positive matches and more results than we need, we'll have to filter them in php.
$select = $DB->sql_like($columnname, '?', false);
$params = ['%=%http://%'];
}
return [$select, $params];
}
|
php
|
protected function get_select_search_in_column($columnname) {
global $DB;
if ($DB->sql_regex_supported()) {
// Database supports regex, use it for better match.
$select = $columnname . ' ' . $DB->sql_regex() . ' ?';
$params = ["(src|data)\ *=\ *[\\\"\']http://"];
} else {
// Databases without regex support should use case-insensitive LIKE.
// This will have false positive matches and more results than we need, we'll have to filter them in php.
$select = $DB->sql_like($columnname, '?', false);
$params = ['%=%http://%'];
}
return [$select, $params];
}
|
[
"protected",
"function",
"get_select_search_in_column",
"(",
"$",
"columnname",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"$",
"DB",
"->",
"sql_regex_supported",
"(",
")",
")",
"{",
"// Database supports regex, use it for better match.",
"$",
"select",
"=",
"$",
"columnname",
".",
"' '",
".",
"$",
"DB",
"->",
"sql_regex",
"(",
")",
".",
"' ?'",
";",
"$",
"params",
"=",
"[",
"\"(src|data)\\ *=\\ *[\\\\\\\"\\']http://\"",
"]",
";",
"}",
"else",
"{",
"// Databases without regex support should use case-insensitive LIKE.",
"// This will have false positive matches and more results than we need, we'll have to filter them in php.",
"$",
"select",
"=",
"$",
"DB",
"->",
"sql_like",
"(",
"$",
"columnname",
",",
"'?'",
",",
"false",
")",
";",
"$",
"params",
"=",
"[",
"'%=%http://%'",
"]",
";",
"}",
"return",
"[",
"$",
"select",
",",
"$",
"params",
"]",
";",
"}"
] |
Returns SQL to be used to match embedded http links in the given column
@param string $columnname name of the column (ready to be used in the SQL query)
@return array
|
[
"Returns",
"SQL",
"to",
"be",
"used",
"to",
"match",
"embedded",
"http",
"links",
"in",
"the",
"given",
"column"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/httpsreplace/classes/url_finder.php#L95-L110
|
216,668
|
moodle/moodle
|
question/type/rendererbase.php
|
qtype_renderer.clear_wrong
|
public function clear_wrong(question_attempt $qa) {
$response = $qa->get_last_qt_data();
if (!$response) {
return '';
}
$cleanresponse = $qa->get_question()->clear_wrong_from_response($response);
$output = '';
foreach ($cleanresponse as $name => $value) {
$attr = array(
'type' => 'hidden',
'name' => $qa->get_qt_field_name($name),
'value' => s($value),
);
$output .= html_writer::empty_tag('input', $attr);
}
return $output;
}
|
php
|
public function clear_wrong(question_attempt $qa) {
$response = $qa->get_last_qt_data();
if (!$response) {
return '';
}
$cleanresponse = $qa->get_question()->clear_wrong_from_response($response);
$output = '';
foreach ($cleanresponse as $name => $value) {
$attr = array(
'type' => 'hidden',
'name' => $qa->get_qt_field_name($name),
'value' => s($value),
);
$output .= html_writer::empty_tag('input', $attr);
}
return $output;
}
|
[
"public",
"function",
"clear_wrong",
"(",
"question_attempt",
"$",
"qa",
")",
"{",
"$",
"response",
"=",
"$",
"qa",
"->",
"get_last_qt_data",
"(",
")",
";",
"if",
"(",
"!",
"$",
"response",
")",
"{",
"return",
"''",
";",
"}",
"$",
"cleanresponse",
"=",
"$",
"qa",
"->",
"get_question",
"(",
")",
"->",
"clear_wrong_from_response",
"(",
"$",
"response",
")",
";",
"$",
"output",
"=",
"''",
";",
"foreach",
"(",
"$",
"cleanresponse",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"attr",
"=",
"array",
"(",
"'type'",
"=>",
"'hidden'",
",",
"'name'",
"=>",
"$",
"qa",
"->",
"get_qt_field_name",
"(",
"$",
"name",
")",
",",
"'value'",
"=>",
"s",
"(",
"$",
"value",
")",
",",
")",
";",
"$",
"output",
".=",
"html_writer",
"::",
"empty_tag",
"(",
"'input'",
",",
"$",
"attr",
")",
";",
"}",
"return",
"$",
"output",
";",
"}"
] |
Output hidden form fields to clear any wrong parts of the student's response.
This method will only be called if the question is in read-only mode.
@param question_attempt $qa the question attempt to display.
@return string HTML fragment.
|
[
"Output",
"hidden",
"form",
"fields",
"to",
"clear",
"any",
"wrong",
"parts",
"of",
"the",
"student",
"s",
"response",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/rendererbase.php#L69-L85
|
216,669
|
moodle/moodle
|
question/type/rendererbase.php
|
qtype_renderer.feedback
|
public function feedback(question_attempt $qa, question_display_options $options) {
$output = '';
$hint = null;
if ($options->feedback) {
$output .= html_writer::nonempty_tag('div', $this->specific_feedback($qa),
array('class' => 'specificfeedback'));
$hint = $qa->get_applicable_hint();
}
if ($options->numpartscorrect) {
$output .= html_writer::nonempty_tag('div', $this->num_parts_correct($qa),
array('class' => 'numpartscorrect'));
}
if ($hint) {
$output .= $this->hint($qa, $hint);
}
if ($options->generalfeedback) {
$output .= html_writer::nonempty_tag('div', $this->general_feedback($qa),
array('class' => 'generalfeedback'));
}
if ($options->rightanswer) {
$output .= html_writer::nonempty_tag('div', $this->correct_response($qa),
array('class' => 'rightanswer'));
}
return $output;
}
|
php
|
public function feedback(question_attempt $qa, question_display_options $options) {
$output = '';
$hint = null;
if ($options->feedback) {
$output .= html_writer::nonempty_tag('div', $this->specific_feedback($qa),
array('class' => 'specificfeedback'));
$hint = $qa->get_applicable_hint();
}
if ($options->numpartscorrect) {
$output .= html_writer::nonempty_tag('div', $this->num_parts_correct($qa),
array('class' => 'numpartscorrect'));
}
if ($hint) {
$output .= $this->hint($qa, $hint);
}
if ($options->generalfeedback) {
$output .= html_writer::nonempty_tag('div', $this->general_feedback($qa),
array('class' => 'generalfeedback'));
}
if ($options->rightanswer) {
$output .= html_writer::nonempty_tag('div', $this->correct_response($qa),
array('class' => 'rightanswer'));
}
return $output;
}
|
[
"public",
"function",
"feedback",
"(",
"question_attempt",
"$",
"qa",
",",
"question_display_options",
"$",
"options",
")",
"{",
"$",
"output",
"=",
"''",
";",
"$",
"hint",
"=",
"null",
";",
"if",
"(",
"$",
"options",
"->",
"feedback",
")",
"{",
"$",
"output",
".=",
"html_writer",
"::",
"nonempty_tag",
"(",
"'div'",
",",
"$",
"this",
"->",
"specific_feedback",
"(",
"$",
"qa",
")",
",",
"array",
"(",
"'class'",
"=>",
"'specificfeedback'",
")",
")",
";",
"$",
"hint",
"=",
"$",
"qa",
"->",
"get_applicable_hint",
"(",
")",
";",
"}",
"if",
"(",
"$",
"options",
"->",
"numpartscorrect",
")",
"{",
"$",
"output",
".=",
"html_writer",
"::",
"nonempty_tag",
"(",
"'div'",
",",
"$",
"this",
"->",
"num_parts_correct",
"(",
"$",
"qa",
")",
",",
"array",
"(",
"'class'",
"=>",
"'numpartscorrect'",
")",
")",
";",
"}",
"if",
"(",
"$",
"hint",
")",
"{",
"$",
"output",
".=",
"$",
"this",
"->",
"hint",
"(",
"$",
"qa",
",",
"$",
"hint",
")",
";",
"}",
"if",
"(",
"$",
"options",
"->",
"generalfeedback",
")",
"{",
"$",
"output",
".=",
"html_writer",
"::",
"nonempty_tag",
"(",
"'div'",
",",
"$",
"this",
"->",
"general_feedback",
"(",
"$",
"qa",
")",
",",
"array",
"(",
"'class'",
"=>",
"'generalfeedback'",
")",
")",
";",
"}",
"if",
"(",
"$",
"options",
"->",
"rightanswer",
")",
"{",
"$",
"output",
".=",
"html_writer",
"::",
"nonempty_tag",
"(",
"'div'",
",",
"$",
"this",
"->",
"correct_response",
"(",
"$",
"qa",
")",
",",
"array",
"(",
"'class'",
"=>",
"'rightanswer'",
")",
")",
";",
"}",
"return",
"$",
"output",
";",
"}"
] |
Generate the display of the outcome part of the question. This is the
area that contains the various forms of feedback. This function generates
the content of this area belonging to the question type.
Subclasses will normally want to override the more specific methods
{specific_feedback()}, {general_feedback()} and {correct_response()}
that this method calls.
@param question_attempt $qa the question attempt to display.
@param question_display_options $options controls what should and should not be displayed.
@return string HTML fragment.
|
[
"Generate",
"the",
"display",
"of",
"the",
"outcome",
"part",
"of",
"the",
"question",
".",
"This",
"is",
"the",
"area",
"that",
"contains",
"the",
"various",
"forms",
"of",
"feedback",
".",
"This",
"function",
"generates",
"the",
"content",
"of",
"this",
"area",
"belonging",
"to",
"the",
"question",
"type",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/rendererbase.php#L100-L130
|
216,670
|
moodle/moodle
|
question/type/rendererbase.php
|
qtype_renderer.num_parts_correct
|
protected function num_parts_correct(question_attempt $qa) {
$a = new stdClass();
list($a->num, $a->outof) = $qa->get_question()->get_num_parts_right(
$qa->get_last_qt_data());
if (is_null($a->outof)) {
return '';
} else {
return get_string('yougotnright', 'question', $a);
}
}
|
php
|
protected function num_parts_correct(question_attempt $qa) {
$a = new stdClass();
list($a->num, $a->outof) = $qa->get_question()->get_num_parts_right(
$qa->get_last_qt_data());
if (is_null($a->outof)) {
return '';
} else {
return get_string('yougotnright', 'question', $a);
}
}
|
[
"protected",
"function",
"num_parts_correct",
"(",
"question_attempt",
"$",
"qa",
")",
"{",
"$",
"a",
"=",
"new",
"stdClass",
"(",
")",
";",
"list",
"(",
"$",
"a",
"->",
"num",
",",
"$",
"a",
"->",
"outof",
")",
"=",
"$",
"qa",
"->",
"get_question",
"(",
")",
"->",
"get_num_parts_right",
"(",
"$",
"qa",
"->",
"get_last_qt_data",
"(",
")",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"a",
"->",
"outof",
")",
")",
"{",
"return",
"''",
";",
"}",
"else",
"{",
"return",
"get_string",
"(",
"'yougotnright'",
",",
"'question'",
",",
"$",
"a",
")",
";",
"}",
"}"
] |
Gereate a brief statement of how many sub-parts of this question the
student got right.
@param question_attempt $qa the question attempt to display.
@return string HTML fragment.
|
[
"Gereate",
"a",
"brief",
"statement",
"of",
"how",
"many",
"sub",
"-",
"parts",
"of",
"this",
"question",
"the",
"student",
"got",
"right",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/rendererbase.php#L148-L157
|
216,671
|
moodle/moodle
|
question/type/rendererbase.php
|
qtype_renderer.hint
|
protected function hint(question_attempt $qa, question_hint $hint) {
return html_writer::nonempty_tag('div',
$qa->get_question()->format_hint($hint, $qa), array('class' => 'hint'));
}
|
php
|
protected function hint(question_attempt $qa, question_hint $hint) {
return html_writer::nonempty_tag('div',
$qa->get_question()->format_hint($hint, $qa), array('class' => 'hint'));
}
|
[
"protected",
"function",
"hint",
"(",
"question_attempt",
"$",
"qa",
",",
"question_hint",
"$",
"hint",
")",
"{",
"return",
"html_writer",
"::",
"nonempty_tag",
"(",
"'div'",
",",
"$",
"qa",
"->",
"get_question",
"(",
")",
"->",
"format_hint",
"(",
"$",
"hint",
",",
"$",
"qa",
")",
",",
"array",
"(",
"'class'",
"=>",
"'hint'",
")",
")",
";",
"}"
] |
Gereate the specific feedback. This is feedback that varies according to
the response the student gave.
@param question_attempt $qa the question attempt to display.
@return string HTML fragment.
|
[
"Gereate",
"the",
"specific",
"feedback",
".",
"This",
"is",
"feedback",
"that",
"varies",
"according",
"to",
"the",
"response",
"the",
"student",
"gave",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/rendererbase.php#L165-L168
|
216,672
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Shared/JAMA/QRDecomposition.php
|
PHPExcel_Shared_JAMA_QRDecomposition.isFullRank
|
public function isFullRank()
{
for ($j = 0; $j < $this->n; ++$j) {
if ($this->Rdiag[$j] == 0) {
return false;
}
}
return true;
}
|
php
|
public function isFullRank()
{
for ($j = 0; $j < $this->n; ++$j) {
if ($this->Rdiag[$j] == 0) {
return false;
}
}
return true;
}
|
[
"public",
"function",
"isFullRank",
"(",
")",
"{",
"for",
"(",
"$",
"j",
"=",
"0",
";",
"$",
"j",
"<",
"$",
"this",
"->",
"n",
";",
"++",
"$",
"j",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"Rdiag",
"[",
"$",
"j",
"]",
"==",
"0",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Is the matrix full rank?
@return boolean true if R, and hence A, has full rank, else false.
|
[
"Is",
"the",
"matrix",
"full",
"rank?"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Shared/JAMA/QRDecomposition.php#L102-L110
|
216,673
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Shared/JAMA/QRDecomposition.php
|
PHPExcel_Shared_JAMA_QRDecomposition.getH
|
public function getH()
{
for ($i = 0; $i < $this->m; ++$i) {
for ($j = 0; $j < $this->n; ++$j) {
if ($i >= $j) {
$H[$i][$j] = $this->QR[$i][$j];
} else {
$H[$i][$j] = 0.0;
}
}
}
return new PHPExcel_Shared_JAMA_Matrix($H);
}
|
php
|
public function getH()
{
for ($i = 0; $i < $this->m; ++$i) {
for ($j = 0; $j < $this->n; ++$j) {
if ($i >= $j) {
$H[$i][$j] = $this->QR[$i][$j];
} else {
$H[$i][$j] = 0.0;
}
}
}
return new PHPExcel_Shared_JAMA_Matrix($H);
}
|
[
"public",
"function",
"getH",
"(",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"m",
";",
"++",
"$",
"i",
")",
"{",
"for",
"(",
"$",
"j",
"=",
"0",
";",
"$",
"j",
"<",
"$",
"this",
"->",
"n",
";",
"++",
"$",
"j",
")",
"{",
"if",
"(",
"$",
"i",
">=",
"$",
"j",
")",
"{",
"$",
"H",
"[",
"$",
"i",
"]",
"[",
"$",
"j",
"]",
"=",
"$",
"this",
"->",
"QR",
"[",
"$",
"i",
"]",
"[",
"$",
"j",
"]",
";",
"}",
"else",
"{",
"$",
"H",
"[",
"$",
"i",
"]",
"[",
"$",
"j",
"]",
"=",
"0.0",
";",
"}",
"}",
"}",
"return",
"new",
"PHPExcel_Shared_JAMA_Matrix",
"(",
"$",
"H",
")",
";",
"}"
] |
Return the Householder vectors
@return Matrix Lower trapezoidal matrix whose columns define the reflections
|
[
"Return",
"the",
"Householder",
"vectors"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Shared/JAMA/QRDecomposition.php#L117-L129
|
216,674
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Shared/JAMA/QRDecomposition.php
|
PHPExcel_Shared_JAMA_QRDecomposition.getR
|
public function getR()
{
for ($i = 0; $i < $this->n; ++$i) {
for ($j = 0; $j < $this->n; ++$j) {
if ($i < $j) {
$R[$i][$j] = $this->QR[$i][$j];
} elseif ($i == $j) {
$R[$i][$j] = $this->Rdiag[$i];
} else {
$R[$i][$j] = 0.0;
}
}
}
return new PHPExcel_Shared_JAMA_Matrix($R);
}
|
php
|
public function getR()
{
for ($i = 0; $i < $this->n; ++$i) {
for ($j = 0; $j < $this->n; ++$j) {
if ($i < $j) {
$R[$i][$j] = $this->QR[$i][$j];
} elseif ($i == $j) {
$R[$i][$j] = $this->Rdiag[$i];
} else {
$R[$i][$j] = 0.0;
}
}
}
return new PHPExcel_Shared_JAMA_Matrix($R);
}
|
[
"public",
"function",
"getR",
"(",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"n",
";",
"++",
"$",
"i",
")",
"{",
"for",
"(",
"$",
"j",
"=",
"0",
";",
"$",
"j",
"<",
"$",
"this",
"->",
"n",
";",
"++",
"$",
"j",
")",
"{",
"if",
"(",
"$",
"i",
"<",
"$",
"j",
")",
"{",
"$",
"R",
"[",
"$",
"i",
"]",
"[",
"$",
"j",
"]",
"=",
"$",
"this",
"->",
"QR",
"[",
"$",
"i",
"]",
"[",
"$",
"j",
"]",
";",
"}",
"elseif",
"(",
"$",
"i",
"==",
"$",
"j",
")",
"{",
"$",
"R",
"[",
"$",
"i",
"]",
"[",
"$",
"j",
"]",
"=",
"$",
"this",
"->",
"Rdiag",
"[",
"$",
"i",
"]",
";",
"}",
"else",
"{",
"$",
"R",
"[",
"$",
"i",
"]",
"[",
"$",
"j",
"]",
"=",
"0.0",
";",
"}",
"}",
"}",
"return",
"new",
"PHPExcel_Shared_JAMA_Matrix",
"(",
"$",
"R",
")",
";",
"}"
] |
Return the upper triangular factor
@return Matrix upper triangular factor
|
[
"Return",
"the",
"upper",
"triangular",
"factor"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Shared/JAMA/QRDecomposition.php#L136-L150
|
216,675
|
moodle/moodle
|
completion/completion_criteria_completion.php
|
completion_criteria_completion.mark_complete
|
public function mark_complete() {
// Create record
$this->timecompleted = time();
// Save record
if ($this->id) {
$this->update();
} else {
$this->insert();
}
// Mark course completion record as started (if not already)
$cc = array(
'course' => $this->course,
'userid' => $this->userid
);
$ccompletion = new completion_completion($cc);
$ccompletion->mark_inprogress($this->timecompleted);
}
|
php
|
public function mark_complete() {
// Create record
$this->timecompleted = time();
// Save record
if ($this->id) {
$this->update();
} else {
$this->insert();
}
// Mark course completion record as started (if not already)
$cc = array(
'course' => $this->course,
'userid' => $this->userid
);
$ccompletion = new completion_completion($cc);
$ccompletion->mark_inprogress($this->timecompleted);
}
|
[
"public",
"function",
"mark_complete",
"(",
")",
"{",
"// Create record",
"$",
"this",
"->",
"timecompleted",
"=",
"time",
"(",
")",
";",
"// Save record",
"if",
"(",
"$",
"this",
"->",
"id",
")",
"{",
"$",
"this",
"->",
"update",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"insert",
"(",
")",
";",
"}",
"// Mark course completion record as started (if not already)",
"$",
"cc",
"=",
"array",
"(",
"'course'",
"=>",
"$",
"this",
"->",
"course",
",",
"'userid'",
"=>",
"$",
"this",
"->",
"userid",
")",
";",
"$",
"ccompletion",
"=",
"new",
"completion_completion",
"(",
"$",
"cc",
")",
";",
"$",
"ccompletion",
"->",
"mark_inprogress",
"(",
"$",
"this",
"->",
"timecompleted",
")",
";",
"}"
] |
Mark this criteria complete for the associated user
This method creates a course_completion_crit_compl record
|
[
"Mark",
"this",
"criteria",
"complete",
"for",
"the",
"associated",
"user"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/completion_criteria_completion.php#L106-L124
|
216,676
|
moodle/moodle
|
completion/completion_criteria_completion.php
|
completion_criteria_completion.get_criteria
|
public function get_criteria() {
if (!$this->_criteria) {
global $DB;
$params = array(
'id' => $this->criteriaid
);
$record = $DB->get_record('course_completion_criteria', $params);
$this->attach_criteria(completion_criteria::factory((array) $record));
}
return $this->_criteria;
}
|
php
|
public function get_criteria() {
if (!$this->_criteria) {
global $DB;
$params = array(
'id' => $this->criteriaid
);
$record = $DB->get_record('course_completion_criteria', $params);
$this->attach_criteria(completion_criteria::factory((array) $record));
}
return $this->_criteria;
}
|
[
"public",
"function",
"get_criteria",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_criteria",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"params",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"criteriaid",
")",
";",
"$",
"record",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'course_completion_criteria'",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"attach_criteria",
"(",
"completion_criteria",
"::",
"factory",
"(",
"(",
"array",
")",
"$",
"record",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_criteria",
";",
"}"
] |
Return the associated criteria with this completion
If nothing attached, load from the db
@return completion_criteria
|
[
"Return",
"the",
"associated",
"criteria",
"with",
"this",
"completion",
"If",
"nothing",
"attached",
"load",
"from",
"the",
"db"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/completion_criteria_completion.php#L141-L156
|
216,677
|
moodle/moodle
|
lib/classes/output/external.php
|
external.load_template
|
public static function load_template($component, $template, $themename, $includecomments = false) {
global $DB, $CFG, $PAGE;
$params = self::validate_parameters(self::load_template_parameters(),
array('component' => $component,
'template' => $template,
'themename' => $themename,
'includecomments' => $includecomments));
$loader = new mustache_template_source_loader();
// Will throw exceptions if the template does not exist.
return $loader->load(
$params['component'],
$params['template'],
$params['themename'],
$params['includecomments']
);
}
|
php
|
public static function load_template($component, $template, $themename, $includecomments = false) {
global $DB, $CFG, $PAGE;
$params = self::validate_parameters(self::load_template_parameters(),
array('component' => $component,
'template' => $template,
'themename' => $themename,
'includecomments' => $includecomments));
$loader = new mustache_template_source_loader();
// Will throw exceptions if the template does not exist.
return $loader->load(
$params['component'],
$params['template'],
$params['themename'],
$params['includecomments']
);
}
|
[
"public",
"static",
"function",
"load_template",
"(",
"$",
"component",
",",
"$",
"template",
",",
"$",
"themename",
",",
"$",
"includecomments",
"=",
"false",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"CFG",
",",
"$",
"PAGE",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"load_template_parameters",
"(",
")",
",",
"array",
"(",
"'component'",
"=>",
"$",
"component",
",",
"'template'",
"=>",
"$",
"template",
",",
"'themename'",
"=>",
"$",
"themename",
",",
"'includecomments'",
"=>",
"$",
"includecomments",
")",
")",
";",
"$",
"loader",
"=",
"new",
"mustache_template_source_loader",
"(",
")",
";",
"// Will throw exceptions if the template does not exist.",
"return",
"$",
"loader",
"->",
"load",
"(",
"$",
"params",
"[",
"'component'",
"]",
",",
"$",
"params",
"[",
"'template'",
"]",
",",
"$",
"params",
"[",
"'themename'",
"]",
",",
"$",
"params",
"[",
"'includecomments'",
"]",
")",
";",
"}"
] |
Return a mustache template, and all the strings it requires.
@param string $component The component that holds the template.
@param string $templatename The name of the template.
@param string $themename The name of the current theme.
@return string the template
|
[
"Return",
"a",
"mustache",
"template",
"and",
"all",
"the",
"strings",
"it",
"requires",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/output/external.php#L69-L86
|
216,678
|
moodle/moodle
|
lib/classes/output/external.php
|
external.load_template_with_dependencies
|
public static function load_template_with_dependencies(
string $component,
string $template,
string $themename,
bool $includecomments = false,
string $lang = null
) {
global $DB, $CFG, $PAGE;
$params = self::validate_parameters(
self::load_template_with_dependencies_parameters(),
[
'component' => $component,
'template' => $template,
'themename' => $themename,
'includecomments' => $includecomments,
'lang' => $lang
]
);
$loader = new mustache_template_source_loader();
// Will throw exceptions if the template does not exist.
$dependencies = $loader->load_with_dependencies(
$params['component'],
$params['template'],
$params['themename'],
$params['includecomments'],
[],
[],
$params['lang']
);
$formatdependencies = function($dependency) {
$results = [];
foreach ($dependency as $dependencycomponent => $dependencyvalues) {
foreach ($dependencyvalues as $dependencyname => $dependencyvalue) {
array_push($results, [
'component' => $dependencycomponent,
'name' => $dependencyname,
'value' => $dependencyvalue
]);
}
}
return $results;
};
// Now we have to unpack the dependencies into a format that can be returned
// by external functions (because they don't support dynamic keys).
return [
'templates' => $formatdependencies($dependencies['templates']),
'strings' => $formatdependencies($dependencies['strings'])
];
}
|
php
|
public static function load_template_with_dependencies(
string $component,
string $template,
string $themename,
bool $includecomments = false,
string $lang = null
) {
global $DB, $CFG, $PAGE;
$params = self::validate_parameters(
self::load_template_with_dependencies_parameters(),
[
'component' => $component,
'template' => $template,
'themename' => $themename,
'includecomments' => $includecomments,
'lang' => $lang
]
);
$loader = new mustache_template_source_loader();
// Will throw exceptions if the template does not exist.
$dependencies = $loader->load_with_dependencies(
$params['component'],
$params['template'],
$params['themename'],
$params['includecomments'],
[],
[],
$params['lang']
);
$formatdependencies = function($dependency) {
$results = [];
foreach ($dependency as $dependencycomponent => $dependencyvalues) {
foreach ($dependencyvalues as $dependencyname => $dependencyvalue) {
array_push($results, [
'component' => $dependencycomponent,
'name' => $dependencyname,
'value' => $dependencyvalue
]);
}
}
return $results;
};
// Now we have to unpack the dependencies into a format that can be returned
// by external functions (because they don't support dynamic keys).
return [
'templates' => $formatdependencies($dependencies['templates']),
'strings' => $formatdependencies($dependencies['strings'])
];
}
|
[
"public",
"static",
"function",
"load_template_with_dependencies",
"(",
"string",
"$",
"component",
",",
"string",
"$",
"template",
",",
"string",
"$",
"themename",
",",
"bool",
"$",
"includecomments",
"=",
"false",
",",
"string",
"$",
"lang",
"=",
"null",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"CFG",
",",
"$",
"PAGE",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"load_template_with_dependencies_parameters",
"(",
")",
",",
"[",
"'component'",
"=>",
"$",
"component",
",",
"'template'",
"=>",
"$",
"template",
",",
"'themename'",
"=>",
"$",
"themename",
",",
"'includecomments'",
"=>",
"$",
"includecomments",
",",
"'lang'",
"=>",
"$",
"lang",
"]",
")",
";",
"$",
"loader",
"=",
"new",
"mustache_template_source_loader",
"(",
")",
";",
"// Will throw exceptions if the template does not exist.",
"$",
"dependencies",
"=",
"$",
"loader",
"->",
"load_with_dependencies",
"(",
"$",
"params",
"[",
"'component'",
"]",
",",
"$",
"params",
"[",
"'template'",
"]",
",",
"$",
"params",
"[",
"'themename'",
"]",
",",
"$",
"params",
"[",
"'includecomments'",
"]",
",",
"[",
"]",
",",
"[",
"]",
",",
"$",
"params",
"[",
"'lang'",
"]",
")",
";",
"$",
"formatdependencies",
"=",
"function",
"(",
"$",
"dependency",
")",
"{",
"$",
"results",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"dependency",
"as",
"$",
"dependencycomponent",
"=>",
"$",
"dependencyvalues",
")",
"{",
"foreach",
"(",
"$",
"dependencyvalues",
"as",
"$",
"dependencyname",
"=>",
"$",
"dependencyvalue",
")",
"{",
"array_push",
"(",
"$",
"results",
",",
"[",
"'component'",
"=>",
"$",
"dependencycomponent",
",",
"'name'",
"=>",
"$",
"dependencyname",
",",
"'value'",
"=>",
"$",
"dependencyvalue",
"]",
")",
";",
"}",
"}",
"return",
"$",
"results",
";",
"}",
";",
"// Now we have to unpack the dependencies into a format that can be returned",
"// by external functions (because they don't support dynamic keys).",
"return",
"[",
"'templates'",
"=>",
"$",
"formatdependencies",
"(",
"$",
"dependencies",
"[",
"'templates'",
"]",
")",
",",
"'strings'",
"=>",
"$",
"formatdependencies",
"(",
"$",
"dependencies",
"[",
"'strings'",
"]",
")",
"]",
";",
"}"
] |
Return a mustache template, and all the child templates and strings it requires.
@param string $component The component that holds the template.
@param string $template The name of the template.
@param string $themename The name of the current theme.
@param bool $includecomments Whether to strip comments from the template source.
@param string $lang moodle translation language, null means use current.
@return string the template
|
[
"Return",
"a",
"mustache",
"template",
"and",
"all",
"the",
"child",
"templates",
"and",
"strings",
"it",
"requires",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/output/external.php#L122-L173
|
216,679
|
moodle/moodle
|
lib/classes/output/external.php
|
external.load_fontawesome_icon_map
|
public static function load_fontawesome_icon_map() {
$instance = icon_system::instance(icon_system::FONTAWESOME);
$map = $instance->get_icon_name_map();
$result = [];
foreach ($map as $from => $to) {
list($component, $pix) = explode(':', $from);
$one = [];
$one['component'] = $component;
$one['pix'] = $pix;
$one['to'] = $to;
$result[] = $one;
}
return $result;
}
|
php
|
public static function load_fontawesome_icon_map() {
$instance = icon_system::instance(icon_system::FONTAWESOME);
$map = $instance->get_icon_name_map();
$result = [];
foreach ($map as $from => $to) {
list($component, $pix) = explode(':', $from);
$one = [];
$one['component'] = $component;
$one['pix'] = $pix;
$one['to'] = $to;
$result[] = $one;
}
return $result;
}
|
[
"public",
"static",
"function",
"load_fontawesome_icon_map",
"(",
")",
"{",
"$",
"instance",
"=",
"icon_system",
"::",
"instance",
"(",
"icon_system",
"::",
"FONTAWESOME",
")",
";",
"$",
"map",
"=",
"$",
"instance",
"->",
"get_icon_name_map",
"(",
")",
";",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"map",
"as",
"$",
"from",
"=>",
"$",
"to",
")",
"{",
"list",
"(",
"$",
"component",
",",
"$",
"pix",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"from",
")",
";",
"$",
"one",
"=",
"[",
"]",
";",
"$",
"one",
"[",
"'component'",
"]",
"=",
"$",
"component",
";",
"$",
"one",
"[",
"'pix'",
"]",
"=",
"$",
"pix",
";",
"$",
"one",
"[",
"'to'",
"]",
"=",
"$",
"to",
";",
"$",
"result",
"[",
"]",
"=",
"$",
"one",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Return a mapping of icon names to icons.
@return array the mapping
|
[
"Return",
"a",
"mapping",
"of",
"icon",
"names",
"to",
"icons",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/output/external.php#L207-L223
|
216,680
|
moodle/moodle
|
lib/adodb/drivers/adodb-sybase_ase.inc.php
|
ADODB_sybase_ase.MetaTables
|
function MetaTables($ttype=false,$showSchema=false,$mask=false)
{
$false = false;
if ($this->metaTablesSQL) {
// complicated state saving by the need for backward compat
if ($ttype == 'VIEWS'){
$sql = str_replace('U', 'V', $this->metaTablesSQL);
}elseif (false === $ttype){
$sql = str_replace('U',"U' OR type='V", $this->metaTablesSQL);
}else{ // TABLES OR ANY OTHER
$sql = $this->metaTablesSQL;
}
$rs = $this->Execute($sql);
if ($rs === false || !method_exists($rs, 'GetArray')){
return $false;
}
$arr = $rs->GetArray();
$arr2 = array();
foreach($arr as $key=>$value){
$arr2[] = trim($value['name']);
}
return $arr2;
}
return $false;
}
|
php
|
function MetaTables($ttype=false,$showSchema=false,$mask=false)
{
$false = false;
if ($this->metaTablesSQL) {
// complicated state saving by the need for backward compat
if ($ttype == 'VIEWS'){
$sql = str_replace('U', 'V', $this->metaTablesSQL);
}elseif (false === $ttype){
$sql = str_replace('U',"U' OR type='V", $this->metaTablesSQL);
}else{ // TABLES OR ANY OTHER
$sql = $this->metaTablesSQL;
}
$rs = $this->Execute($sql);
if ($rs === false || !method_exists($rs, 'GetArray')){
return $false;
}
$arr = $rs->GetArray();
$arr2 = array();
foreach($arr as $key=>$value){
$arr2[] = trim($value['name']);
}
return $arr2;
}
return $false;
}
|
[
"function",
"MetaTables",
"(",
"$",
"ttype",
"=",
"false",
",",
"$",
"showSchema",
"=",
"false",
",",
"$",
"mask",
"=",
"false",
")",
"{",
"$",
"false",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"metaTablesSQL",
")",
"{",
"// complicated state saving by the need for backward compat",
"if",
"(",
"$",
"ttype",
"==",
"'VIEWS'",
")",
"{",
"$",
"sql",
"=",
"str_replace",
"(",
"'U'",
",",
"'V'",
",",
"$",
"this",
"->",
"metaTablesSQL",
")",
";",
"}",
"elseif",
"(",
"false",
"===",
"$",
"ttype",
")",
"{",
"$",
"sql",
"=",
"str_replace",
"(",
"'U'",
",",
"\"U' OR type='V\"",
",",
"$",
"this",
"->",
"metaTablesSQL",
")",
";",
"}",
"else",
"{",
"// TABLES OR ANY OTHER",
"$",
"sql",
"=",
"$",
"this",
"->",
"metaTablesSQL",
";",
"}",
"$",
"rs",
"=",
"$",
"this",
"->",
"Execute",
"(",
"$",
"sql",
")",
";",
"if",
"(",
"$",
"rs",
"===",
"false",
"||",
"!",
"method_exists",
"(",
"$",
"rs",
",",
"'GetArray'",
")",
")",
"{",
"return",
"$",
"false",
";",
"}",
"$",
"arr",
"=",
"$",
"rs",
"->",
"GetArray",
"(",
")",
";",
"$",
"arr2",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"arr",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"arr2",
"[",
"]",
"=",
"trim",
"(",
"$",
"value",
"[",
"'name'",
"]",
")",
";",
"}",
"return",
"$",
"arr2",
";",
"}",
"return",
"$",
"false",
";",
"}"
] |
split the Views, Tables and procedures.
|
[
"split",
"the",
"Views",
"Tables",
"and",
"procedures",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/drivers/adodb-sybase_ase.inc.php#L30-L57
|
216,681
|
moodle/moodle
|
lib/adodb/drivers/adodb-sybase_ase.inc.php
|
ADODB_sybase_ase.MetaColumns
|
function MetaColumns($table,$upper=false)
{
$false = false;
if (!empty($this->metaColumnsSQL)) {
$rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
if ($rs === false) return $false;
$retarr = array();
while (!$rs->EOF) {
$fld = new ADOFieldObject();
$fld->name = $rs->Fields('field_name');
$fld->type = $rs->Fields('type');
$fld->max_length = $rs->Fields('width');
$retarr[strtoupper($fld->name)] = $fld;
$rs->MoveNext();
}
$rs->Close();
return $retarr;
}
return $false;
}
|
php
|
function MetaColumns($table,$upper=false)
{
$false = false;
if (!empty($this->metaColumnsSQL)) {
$rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
if ($rs === false) return $false;
$retarr = array();
while (!$rs->EOF) {
$fld = new ADOFieldObject();
$fld->name = $rs->Fields('field_name');
$fld->type = $rs->Fields('type');
$fld->max_length = $rs->Fields('width');
$retarr[strtoupper($fld->name)] = $fld;
$rs->MoveNext();
}
$rs->Close();
return $retarr;
}
return $false;
}
|
[
"function",
"MetaColumns",
"(",
"$",
"table",
",",
"$",
"upper",
"=",
"false",
")",
"{",
"$",
"false",
"=",
"false",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"metaColumnsSQL",
")",
")",
"{",
"$",
"rs",
"=",
"$",
"this",
"->",
"Execute",
"(",
"sprintf",
"(",
"$",
"this",
"->",
"metaColumnsSQL",
",",
"$",
"table",
")",
")",
";",
"if",
"(",
"$",
"rs",
"===",
"false",
")",
"return",
"$",
"false",
";",
"$",
"retarr",
"=",
"array",
"(",
")",
";",
"while",
"(",
"!",
"$",
"rs",
"->",
"EOF",
")",
"{",
"$",
"fld",
"=",
"new",
"ADOFieldObject",
"(",
")",
";",
"$",
"fld",
"->",
"name",
"=",
"$",
"rs",
"->",
"Fields",
"(",
"'field_name'",
")",
";",
"$",
"fld",
"->",
"type",
"=",
"$",
"rs",
"->",
"Fields",
"(",
"'type'",
")",
";",
"$",
"fld",
"->",
"max_length",
"=",
"$",
"rs",
"->",
"Fields",
"(",
"'width'",
")",
";",
"$",
"retarr",
"[",
"strtoupper",
"(",
"$",
"fld",
"->",
"name",
")",
"]",
"=",
"$",
"fld",
";",
"$",
"rs",
"->",
"MoveNext",
"(",
")",
";",
"}",
"$",
"rs",
"->",
"Close",
"(",
")",
";",
"return",
"$",
"retarr",
";",
"}",
"return",
"$",
"false",
";",
"}"
] |
fix a bug which prevent the metaColumns query to be executed for Sybase ASE
|
[
"fix",
"a",
"bug",
"which",
"prevent",
"the",
"metaColumns",
"query",
"to",
"be",
"executed",
"for",
"Sybase",
"ASE"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/drivers/adodb-sybase_ase.inc.php#L76-L97
|
216,682
|
moodle/moodle
|
backup/controller/restore_controller.class.php
|
restore_controller.execute_precheck
|
public function execute_precheck($droptemptablesafter = false) {
if (is_array($this->precheck)) {
throw new restore_controller_exception('precheck_alredy_executed', $this->status);
}
if ($this->status != backup::STATUS_NEED_PRECHECK) {
throw new restore_controller_exception('cannot_precheck_wrong_status', $this->status);
}
// Basic/initial prevention against time/memory limits
core_php_time_limit::raise(1 * 60 * 60); // 1 hour for 1 course initially granted
raise_memory_limit(MEMORY_EXTRA);
$this->precheck = restore_prechecks_helper::execute_prechecks($this, $droptemptablesafter);
if (!array_key_exists('errors', $this->precheck)) { // No errors, can be executed
$this->set_status(backup::STATUS_AWAITING);
}
if (empty($this->precheck)) { // No errors nor warnings, return true
return true;
}
return false;
}
|
php
|
public function execute_precheck($droptemptablesafter = false) {
if (is_array($this->precheck)) {
throw new restore_controller_exception('precheck_alredy_executed', $this->status);
}
if ($this->status != backup::STATUS_NEED_PRECHECK) {
throw new restore_controller_exception('cannot_precheck_wrong_status', $this->status);
}
// Basic/initial prevention against time/memory limits
core_php_time_limit::raise(1 * 60 * 60); // 1 hour for 1 course initially granted
raise_memory_limit(MEMORY_EXTRA);
$this->precheck = restore_prechecks_helper::execute_prechecks($this, $droptemptablesafter);
if (!array_key_exists('errors', $this->precheck)) { // No errors, can be executed
$this->set_status(backup::STATUS_AWAITING);
}
if (empty($this->precheck)) { // No errors nor warnings, return true
return true;
}
return false;
}
|
[
"public",
"function",
"execute_precheck",
"(",
"$",
"droptemptablesafter",
"=",
"false",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"precheck",
")",
")",
"{",
"throw",
"new",
"restore_controller_exception",
"(",
"'precheck_alredy_executed'",
",",
"$",
"this",
"->",
"status",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"status",
"!=",
"backup",
"::",
"STATUS_NEED_PRECHECK",
")",
"{",
"throw",
"new",
"restore_controller_exception",
"(",
"'cannot_precheck_wrong_status'",
",",
"$",
"this",
"->",
"status",
")",
";",
"}",
"// Basic/initial prevention against time/memory limits",
"core_php_time_limit",
"::",
"raise",
"(",
"1",
"*",
"60",
"*",
"60",
")",
";",
"// 1 hour for 1 course initially granted",
"raise_memory_limit",
"(",
"MEMORY_EXTRA",
")",
";",
"$",
"this",
"->",
"precheck",
"=",
"restore_prechecks_helper",
"::",
"execute_prechecks",
"(",
"$",
"this",
",",
"$",
"droptemptablesafter",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"'errors'",
",",
"$",
"this",
"->",
"precheck",
")",
")",
"{",
"// No errors, can be executed",
"$",
"this",
"->",
"set_status",
"(",
"backup",
"::",
"STATUS_AWAITING",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"precheck",
")",
")",
"{",
"// No errors nor warnings, return true",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Execute the restore prechecks to detect any problem before proceed with restore
This function checks various parts of the restore (versions, users, roles...)
returning true if everything was ok or false if any warning/error was detected.
Any warning/error is returned by the get_precheck_results() method.
Note: if any problem is found it will, automatically, drop all the restore temp
tables as far as the next step is to inform about the warning/errors. If no problem
is found, then default behaviour is to keep the temp tables so, in the same request
restore will be executed, saving a lot of checks to be executed again.
Note: If for any reason (UI to show after prechecks...) you want to force temp tables
to be dropped always, you can pass true to the $droptemptablesafter parameter
|
[
"Execute",
"the",
"restore",
"prechecks",
"to",
"detect",
"any",
"problem",
"before",
"proceed",
"with",
"restore"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/controller/restore_controller.class.php#L387-L405
|
216,683
|
moodle/moodle
|
backup/controller/restore_controller.class.php
|
restore_controller.save_controller
|
public function save_controller($includeobj = true, $cleanobj = false) {
// Going to save controller to persistent storage, calculate checksum for later checks and save it
// TODO: flag the controller as NA. Any operation on it should be forbidden util loaded back
$this->log('saving controller to db', backup::LOG_DEBUG);
if ($includeobj ) { // Only calculate checksum if we are going to include the object.
$this->checksum = $this->calculate_checksum();
}
restore_controller_dbops::save_controller($this, $this->checksum, $includeobj, $cleanobj);
}
|
php
|
public function save_controller($includeobj = true, $cleanobj = false) {
// Going to save controller to persistent storage, calculate checksum for later checks and save it
// TODO: flag the controller as NA. Any operation on it should be forbidden util loaded back
$this->log('saving controller to db', backup::LOG_DEBUG);
if ($includeobj ) { // Only calculate checksum if we are going to include the object.
$this->checksum = $this->calculate_checksum();
}
restore_controller_dbops::save_controller($this, $this->checksum, $includeobj, $cleanobj);
}
|
[
"public",
"function",
"save_controller",
"(",
"$",
"includeobj",
"=",
"true",
",",
"$",
"cleanobj",
"=",
"false",
")",
"{",
"// Going to save controller to persistent storage, calculate checksum for later checks and save it",
"// TODO: flag the controller as NA. Any operation on it should be forbidden util loaded back",
"$",
"this",
"->",
"log",
"(",
"'saving controller to db'",
",",
"backup",
"::",
"LOG_DEBUG",
")",
";",
"if",
"(",
"$",
"includeobj",
")",
"{",
"// Only calculate checksum if we are going to include the object.",
"$",
"this",
"->",
"checksum",
"=",
"$",
"this",
"->",
"calculate_checksum",
"(",
")",
";",
"}",
"restore_controller_dbops",
"::",
"save_controller",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"checksum",
",",
"$",
"includeobj",
",",
"$",
"cleanobj",
")",
";",
"}"
] |
Save controller information
@param bool $includeobj to decide if the object itself must be updated (true) or no (false)
@param bool $cleanobj to decide if the object itself must be cleaned (true) or no (false)
|
[
"Save",
"controller",
"information"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/controller/restore_controller.class.php#L432-L440
|
216,684
|
moodle/moodle
|
backup/controller/restore_controller.class.php
|
restore_controller.apply_defaults
|
protected function apply_defaults() {
$this->log('applying restore defaults', backup::LOG_DEBUG);
restore_controller_dbops::apply_config_defaults($this);
$this->set_status(backup::STATUS_CONFIGURED);
}
|
php
|
protected function apply_defaults() {
$this->log('applying restore defaults', backup::LOG_DEBUG);
restore_controller_dbops::apply_config_defaults($this);
$this->set_status(backup::STATUS_CONFIGURED);
}
|
[
"protected",
"function",
"apply_defaults",
"(",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"'applying restore defaults'",
",",
"backup",
"::",
"LOG_DEBUG",
")",
";",
"restore_controller_dbops",
"::",
"apply_config_defaults",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"set_status",
"(",
"backup",
"::",
"STATUS_CONFIGURED",
")",
";",
"}"
] |
Apply defaults from the global admin settings
|
[
"Apply",
"defaults",
"from",
"the",
"global",
"admin",
"settings"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/controller/restore_controller.class.php#L535-L539
|
216,685
|
moodle/moodle
|
grade/report/singleview/classes/local/ui/range.php
|
range.determine_format
|
public function determine_format() {
$decimals = $this->item->get_decimals();
$min = format_float($this->item->grademin, $decimals);
$max = format_float($this->item->grademax, $decimals);
return new empty_element("$min - $max");
}
|
php
|
public function determine_format() {
$decimals = $this->item->get_decimals();
$min = format_float($this->item->grademin, $decimals);
$max = format_float($this->item->grademax, $decimals);
return new empty_element("$min - $max");
}
|
[
"public",
"function",
"determine_format",
"(",
")",
"{",
"$",
"decimals",
"=",
"$",
"this",
"->",
"item",
"->",
"get_decimals",
"(",
")",
";",
"$",
"min",
"=",
"format_float",
"(",
"$",
"this",
"->",
"item",
"->",
"grademin",
",",
"$",
"decimals",
")",
";",
"$",
"max",
"=",
"format_float",
"(",
"$",
"this",
"->",
"item",
"->",
"grademax",
",",
"$",
"decimals",
")",
";",
"return",
"new",
"empty_element",
"(",
"\"$min - $max\"",
")",
";",
"}"
] |
Build this UI element.
@return element
|
[
"Build",
"this",
"UI",
"element",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/ui/range.php#L51-L58
|
216,686
|
moodle/moodle
|
lib/horde/framework/Horde/Imap/Client/Interaction/Server.php
|
Horde_Imap_Client_Interaction_Server.create
|
public static function create(Horde_Imap_Client_Tokenize $t)
{
$t->rewind();
$tag = $t->next();
$t->next();
switch ($tag) {
case '+':
return new Horde_Imap_Client_Interaction_Server_Continuation($t);
case '*':
return new Horde_Imap_Client_Interaction_Server_Untagged($t);
default:
return new Horde_Imap_Client_Interaction_Server_Tagged($t, $tag);
}
}
|
php
|
public static function create(Horde_Imap_Client_Tokenize $t)
{
$t->rewind();
$tag = $t->next();
$t->next();
switch ($tag) {
case '+':
return new Horde_Imap_Client_Interaction_Server_Continuation($t);
case '*':
return new Horde_Imap_Client_Interaction_Server_Untagged($t);
default:
return new Horde_Imap_Client_Interaction_Server_Tagged($t, $tag);
}
}
|
[
"public",
"static",
"function",
"create",
"(",
"Horde_Imap_Client_Tokenize",
"$",
"t",
")",
"{",
"$",
"t",
"->",
"rewind",
"(",
")",
";",
"$",
"tag",
"=",
"$",
"t",
"->",
"next",
"(",
")",
";",
"$",
"t",
"->",
"next",
"(",
")",
";",
"switch",
"(",
"$",
"tag",
")",
"{",
"case",
"'+'",
":",
"return",
"new",
"Horde_Imap_Client_Interaction_Server_Continuation",
"(",
"$",
"t",
")",
";",
"case",
"'*'",
":",
"return",
"new",
"Horde_Imap_Client_Interaction_Server_Untagged",
"(",
"$",
"t",
")",
";",
"default",
":",
"return",
"new",
"Horde_Imap_Client_Interaction_Server_Tagged",
"(",
"$",
"t",
",",
"$",
"tag",
")",
";",
"}",
"}"
] |
Auto-scan an incoming line to determine the response type.
@param Horde_Imap_Client_Tokenize $t Tokenized data returned from the
server.
@return Horde_Imap_Client_Interaction_Server A server response object.
|
[
"Auto",
"-",
"scan",
"an",
"incoming",
"line",
"to",
"determine",
"the",
"response",
"type",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Interaction/Server.php#L73-L89
|
216,687
|
moodle/moodle
|
lib/adodb/drivers/adodb-mssql.inc.php
|
ADODB_mssql.MetaPrimaryKeys
|
function MetaPrimaryKeys($table, $owner=false)
{
global $ADODB_FETCH_MODE;
$schema = '';
$this->_findschema($table,$schema);
if (!$schema) $schema = $this->database;
if ($schema) $schema = "and k.table_catalog like '$schema%'";
$sql = "select distinct k.column_name,ordinal_position from information_schema.key_column_usage k,
information_schema.table_constraints tc
where tc.constraint_name = k.constraint_name and tc.constraint_type =
'PRIMARY KEY' and k.table_name = '$table' $schema order by ordinal_position ";
$savem = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
$a = $this->GetCol($sql);
$ADODB_FETCH_MODE = $savem;
if ($a && sizeof($a)>0) return $a;
$false = false;
return $false;
}
|
php
|
function MetaPrimaryKeys($table, $owner=false)
{
global $ADODB_FETCH_MODE;
$schema = '';
$this->_findschema($table,$schema);
if (!$schema) $schema = $this->database;
if ($schema) $schema = "and k.table_catalog like '$schema%'";
$sql = "select distinct k.column_name,ordinal_position from information_schema.key_column_usage k,
information_schema.table_constraints tc
where tc.constraint_name = k.constraint_name and tc.constraint_type =
'PRIMARY KEY' and k.table_name = '$table' $schema order by ordinal_position ";
$savem = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
$a = $this->GetCol($sql);
$ADODB_FETCH_MODE = $savem;
if ($a && sizeof($a)>0) return $a;
$false = false;
return $false;
}
|
[
"function",
"MetaPrimaryKeys",
"(",
"$",
"table",
",",
"$",
"owner",
"=",
"false",
")",
"{",
"global",
"$",
"ADODB_FETCH_MODE",
";",
"$",
"schema",
"=",
"''",
";",
"$",
"this",
"->",
"_findschema",
"(",
"$",
"table",
",",
"$",
"schema",
")",
";",
"if",
"(",
"!",
"$",
"schema",
")",
"$",
"schema",
"=",
"$",
"this",
"->",
"database",
";",
"if",
"(",
"$",
"schema",
")",
"$",
"schema",
"=",
"\"and k.table_catalog like '$schema%'\"",
";",
"$",
"sql",
"=",
"\"select distinct k.column_name,ordinal_position from information_schema.key_column_usage k,\n\t\tinformation_schema.table_constraints tc\n\t\twhere tc.constraint_name = k.constraint_name and tc.constraint_type =\n\t\t'PRIMARY KEY' and k.table_name = '$table' $schema order by ordinal_position \"",
";",
"$",
"savem",
"=",
"$",
"ADODB_FETCH_MODE",
";",
"$",
"ADODB_FETCH_MODE",
"=",
"ADODB_FETCH_NUM",
";",
"$",
"a",
"=",
"$",
"this",
"->",
"GetCol",
"(",
"$",
"sql",
")",
";",
"$",
"ADODB_FETCH_MODE",
"=",
"$",
"savem",
";",
"if",
"(",
"$",
"a",
"&&",
"sizeof",
"(",
"$",
"a",
")",
">",
"0",
")",
"return",
"$",
"a",
";",
"$",
"false",
"=",
"false",
";",
"return",
"$",
"false",
";",
"}"
] |
tested with MSSQL 2000
|
[
"tested",
"with",
"MSSQL",
"2000"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/drivers/adodb-mssql.inc.php#L540-L562
|
216,688
|
moodle/moodle
|
lib/adodb/drivers/adodb-mssql.inc.php
|
ADODB_mssql._connect
|
function _connect($argHostname, $argUsername, $argPassword, $argDatabasename,$newconnect=false)
{
if (!function_exists('mssql_pconnect')) return null;
$this->_connectionID = mssql_connect($argHostname,$argUsername,$argPassword,$newconnect);
if ($this->_connectionID === false) return false;
if ($argDatabasename) return $this->SelectDB($argDatabasename);
return true;
}
|
php
|
function _connect($argHostname, $argUsername, $argPassword, $argDatabasename,$newconnect=false)
{
if (!function_exists('mssql_pconnect')) return null;
$this->_connectionID = mssql_connect($argHostname,$argUsername,$argPassword,$newconnect);
if ($this->_connectionID === false) return false;
if ($argDatabasename) return $this->SelectDB($argDatabasename);
return true;
}
|
[
"function",
"_connect",
"(",
"$",
"argHostname",
",",
"$",
"argUsername",
",",
"$",
"argPassword",
",",
"$",
"argDatabasename",
",",
"$",
"newconnect",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"function_exists",
"(",
"'mssql_pconnect'",
")",
")",
"return",
"null",
";",
"$",
"this",
"->",
"_connectionID",
"=",
"mssql_connect",
"(",
"$",
"argHostname",
",",
"$",
"argUsername",
",",
"$",
"argPassword",
",",
"$",
"newconnect",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_connectionID",
"===",
"false",
")",
"return",
"false",
";",
"if",
"(",
"$",
"argDatabasename",
")",
"return",
"$",
"this",
"->",
"SelectDB",
"(",
"$",
"argDatabasename",
")",
";",
"return",
"true",
";",
"}"
] |
returns true or false, newconnect supported since php 5.1.0.
|
[
"returns",
"true",
"or",
"false",
"newconnect",
"supported",
"since",
"php",
"5",
".",
"1",
".",
"0",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/drivers/adodb-mssql.inc.php#L613-L620
|
216,689
|
moodle/moodle
|
lib/classes/output/chooser.php
|
chooser.add_param
|
public function add_param($name, $value, $id = null) {
if (!$id) {
$id = $name;
}
$this->params[] = [
'name' => $name,
'value' => $value,
'id' => $id
];
}
|
php
|
public function add_param($name, $value, $id = null) {
if (!$id) {
$id = $name;
}
$this->params[] = [
'name' => $name,
'value' => $value,
'id' => $id
];
}
|
[
"public",
"function",
"add_param",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"id",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"id",
")",
"{",
"$",
"id",
"=",
"$",
"name",
";",
"}",
"$",
"this",
"->",
"params",
"[",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"name",
",",
"'value'",
"=>",
"$",
"value",
",",
"'id'",
"=>",
"$",
"id",
"]",
";",
"}"
] |
Add a parameter to submit with the form.
@param string $name The parameter name.
@param string $value The parameter value.
@param string $id The parameter ID.
|
[
"Add",
"a",
"parameter",
"to",
"submit",
"with",
"the",
"form",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/output/chooser.php#L81-L90
|
216,690
|
moodle/moodle
|
admin/roles/classes/view_role_definition_table.php
|
core_role_view_role_definition_table.get_role_risks_info
|
protected function get_role_risks_info() {
global $OUTPUT;
if (empty($this->roleid)) {
return '';
}
$risks = array();
$allrisks = get_all_risks();
foreach ($this->capabilities as $capability) {
$perm = $this->permissions[$capability->name];
if ($perm != CAP_ALLOW) {
continue;
}
foreach ($allrisks as $type => $risk) {
if ($risk & (int)$capability->riskbitmask) {
$risks[$type] = $risk;
}
}
}
$risksurl = new moodle_url(get_docs_url(s(get_string('risks', 'core_role'))));
foreach ($risks as $type => $risk) {
$pixicon = new pix_icon('/i/' . str_replace('risk', 'risk_', $type), get_string($type . 'short', 'admin'));
$risks[$type] = $OUTPUT->action_icon($risksurl, $pixicon, new popup_action('click', $risksurl));
}
return implode(' ', $risks);
}
|
php
|
protected function get_role_risks_info() {
global $OUTPUT;
if (empty($this->roleid)) {
return '';
}
$risks = array();
$allrisks = get_all_risks();
foreach ($this->capabilities as $capability) {
$perm = $this->permissions[$capability->name];
if ($perm != CAP_ALLOW) {
continue;
}
foreach ($allrisks as $type => $risk) {
if ($risk & (int)$capability->riskbitmask) {
$risks[$type] = $risk;
}
}
}
$risksurl = new moodle_url(get_docs_url(s(get_string('risks', 'core_role'))));
foreach ($risks as $type => $risk) {
$pixicon = new pix_icon('/i/' . str_replace('risk', 'risk_', $type), get_string($type . 'short', 'admin'));
$risks[$type] = $OUTPUT->action_icon($risksurl, $pixicon, new popup_action('click', $risksurl));
}
return implode(' ', $risks);
}
|
[
"protected",
"function",
"get_role_risks_info",
"(",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"roleid",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"risks",
"=",
"array",
"(",
")",
";",
"$",
"allrisks",
"=",
"get_all_risks",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"capabilities",
"as",
"$",
"capability",
")",
"{",
"$",
"perm",
"=",
"$",
"this",
"->",
"permissions",
"[",
"$",
"capability",
"->",
"name",
"]",
";",
"if",
"(",
"$",
"perm",
"!=",
"CAP_ALLOW",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"allrisks",
"as",
"$",
"type",
"=>",
"$",
"risk",
")",
"{",
"if",
"(",
"$",
"risk",
"&",
"(",
"int",
")",
"$",
"capability",
"->",
"riskbitmask",
")",
"{",
"$",
"risks",
"[",
"$",
"type",
"]",
"=",
"$",
"risk",
";",
"}",
"}",
"}",
"$",
"risksurl",
"=",
"new",
"moodle_url",
"(",
"get_docs_url",
"(",
"s",
"(",
"get_string",
"(",
"'risks'",
",",
"'core_role'",
")",
")",
")",
")",
";",
"foreach",
"(",
"$",
"risks",
"as",
"$",
"type",
"=>",
"$",
"risk",
")",
"{",
"$",
"pixicon",
"=",
"new",
"pix_icon",
"(",
"'/i/'",
".",
"str_replace",
"(",
"'risk'",
",",
"'risk_'",
",",
"$",
"type",
")",
",",
"get_string",
"(",
"$",
"type",
".",
"'short'",
",",
"'admin'",
")",
")",
";",
"$",
"risks",
"[",
"$",
"type",
"]",
"=",
"$",
"OUTPUT",
"->",
"action_icon",
"(",
"$",
"risksurl",
",",
"$",
"pixicon",
",",
"new",
"popup_action",
"(",
"'click'",
",",
"$",
"risksurl",
")",
")",
";",
"}",
"return",
"implode",
"(",
"' '",
",",
"$",
"risks",
")",
";",
"}"
] |
Returns HTML risk icons.
@return string
|
[
"Returns",
"HTML",
"risk",
"icons",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/roles/classes/view_role_definition_table.php#L77-L105
|
216,691
|
moodle/moodle
|
admin/roles/classes/view_role_definition_table.php
|
core_role_view_role_definition_table.skip_row
|
protected function skip_row($capability) {
$perm = $this->permissions[$capability->name];
if ($perm == CAP_INHERIT) {
// Do not print empty rows in role overview, admins need to know quickly what is allowed and prohibited,
// if they want to see the list of all capabilities they can go to edit role page.
return true;
}
parent::skip_row($capability);
}
|
php
|
protected function skip_row($capability) {
$perm = $this->permissions[$capability->name];
if ($perm == CAP_INHERIT) {
// Do not print empty rows in role overview, admins need to know quickly what is allowed and prohibited,
// if they want to see the list of all capabilities they can go to edit role page.
return true;
}
parent::skip_row($capability);
}
|
[
"protected",
"function",
"skip_row",
"(",
"$",
"capability",
")",
"{",
"$",
"perm",
"=",
"$",
"this",
"->",
"permissions",
"[",
"$",
"capability",
"->",
"name",
"]",
";",
"if",
"(",
"$",
"perm",
"==",
"CAP_INHERIT",
")",
"{",
"// Do not print empty rows in role overview, admins need to know quickly what is allowed and prohibited,",
"// if they want to see the list of all capabilities they can go to edit role page.",
"return",
"true",
";",
"}",
"parent",
"::",
"skip_row",
"(",
"$",
"capability",
")",
";",
"}"
] |
Returns true if the row should be skipped.
@param string $capability
@return bool
|
[
"Returns",
"true",
"if",
"the",
"row",
"should",
"be",
"skipped",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/roles/classes/view_role_definition_table.php#L113-L121
|
216,692
|
moodle/moodle
|
backup/util/ui/base_moodleform.class.php
|
base_moodleform.definition
|
public function definition() {
$ui = $this->uistage->get_ui();
$mform = $this->_form;
$mform->setDisableShortforms();
$stage = $mform->addElement('hidden', 'stage', $this->uistage->get_stage());
$mform->setType('stage', PARAM_INT);
$stage = $mform->addElement('hidden', $ui->get_name(), $ui->get_uniqueid());
$mform->setType($ui->get_name(), PARAM_ALPHANUM);
$params = $this->uistage->get_params();
if (is_array($params) && count($params) > 0) {
foreach ($params as $name => $value) {
// TODO: Horrible hack, but current backup ui structure does not allow
// to make this easy (only changing params to objects that would be
// possible. MDL-38735.
$intparams = array(
'contextid', 'importid', 'target');
$stage = $mform->addElement('hidden', $name, $value);
if (in_array($name, $intparams)) {
$mform->setType($name, PARAM_INT);
} else {
// Adding setType() to avoid missing setType() warnings.
// MDL-39126: support $mform->setType() for additional backup parameters.
$mform->setType($name, PARAM_RAW);
}
}
}
}
|
php
|
public function definition() {
$ui = $this->uistage->get_ui();
$mform = $this->_form;
$mform->setDisableShortforms();
$stage = $mform->addElement('hidden', 'stage', $this->uistage->get_stage());
$mform->setType('stage', PARAM_INT);
$stage = $mform->addElement('hidden', $ui->get_name(), $ui->get_uniqueid());
$mform->setType($ui->get_name(), PARAM_ALPHANUM);
$params = $this->uistage->get_params();
if (is_array($params) && count($params) > 0) {
foreach ($params as $name => $value) {
// TODO: Horrible hack, but current backup ui structure does not allow
// to make this easy (only changing params to objects that would be
// possible. MDL-38735.
$intparams = array(
'contextid', 'importid', 'target');
$stage = $mform->addElement('hidden', $name, $value);
if (in_array($name, $intparams)) {
$mform->setType($name, PARAM_INT);
} else {
// Adding setType() to avoid missing setType() warnings.
// MDL-39126: support $mform->setType() for additional backup parameters.
$mform->setType($name, PARAM_RAW);
}
}
}
}
|
[
"public",
"function",
"definition",
"(",
")",
"{",
"$",
"ui",
"=",
"$",
"this",
"->",
"uistage",
"->",
"get_ui",
"(",
")",
";",
"$",
"mform",
"=",
"$",
"this",
"->",
"_form",
";",
"$",
"mform",
"->",
"setDisableShortforms",
"(",
")",
";",
"$",
"stage",
"=",
"$",
"mform",
"->",
"addElement",
"(",
"'hidden'",
",",
"'stage'",
",",
"$",
"this",
"->",
"uistage",
"->",
"get_stage",
"(",
")",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'stage'",
",",
"PARAM_INT",
")",
";",
"$",
"stage",
"=",
"$",
"mform",
"->",
"addElement",
"(",
"'hidden'",
",",
"$",
"ui",
"->",
"get_name",
"(",
")",
",",
"$",
"ui",
"->",
"get_uniqueid",
"(",
")",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"$",
"ui",
"->",
"get_name",
"(",
")",
",",
"PARAM_ALPHANUM",
")",
";",
"$",
"params",
"=",
"$",
"this",
"->",
"uistage",
"->",
"get_params",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"params",
")",
"&&",
"count",
"(",
"$",
"params",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"params",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"// TODO: Horrible hack, but current backup ui structure does not allow",
"// to make this easy (only changing params to objects that would be",
"// possible. MDL-38735.",
"$",
"intparams",
"=",
"array",
"(",
"'contextid'",
",",
"'importid'",
",",
"'target'",
")",
";",
"$",
"stage",
"=",
"$",
"mform",
"->",
"addElement",
"(",
"'hidden'",
",",
"$",
"name",
",",
"$",
"value",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"name",
",",
"$",
"intparams",
")",
")",
"{",
"$",
"mform",
"->",
"setType",
"(",
"$",
"name",
",",
"PARAM_INT",
")",
";",
"}",
"else",
"{",
"// Adding setType() to avoid missing setType() warnings.",
"// MDL-39126: support $mform->setType() for additional backup parameters.",
"$",
"mform",
"->",
"setType",
"(",
"$",
"name",
",",
"PARAM_RAW",
")",
";",
"}",
"}",
"}",
"}"
] |
The standard form definition... obviously not much here
|
[
"The",
"standard",
"form",
"definition",
"...",
"obviously",
"not",
"much",
"here"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/base_moodleform.class.php#L96-L122
|
216,693
|
moodle/moodle
|
backup/util/ui/base_moodleform.class.php
|
base_moodleform.definition_after_data
|
public function definition_after_data() {
$buttonarray = array();
if (!$this->uistage->is_first_stage()) {
$buttonarray[] = $this->_form->createElement('submit', 'previous', get_string('previousstage', 'backup'));
} else if ($this->uistage instanceof backup_ui_stage) {
// Only display the button on the first stage of backup, they only place where it has an effect.
$buttonarray[] = $this->_form->createElement('submit', 'oneclickbackup', get_string('jumptofinalstep', 'backup'),
array('class' => 'oneclickbackup'));
}
$buttonarray[] = $this->_form->createElement('cancel', 'cancel', get_string('cancel'), array('class' => 'confirmcancel'));
$buttonarray[] = $this->_form->createElement(
'submit',
'submitbutton',
get_string($this->uistage->get_ui()->get_name().'stage'.$this->uistage->get_stage().'action', 'backup'),
array('class' => 'proceedbutton')
);
$this->_form->addGroup($buttonarray, 'buttonar', '', array(' '), false);
$this->_form->closeHeaderBefore('buttonar');
$this->_definition_finalized = true;
}
|
php
|
public function definition_after_data() {
$buttonarray = array();
if (!$this->uistage->is_first_stage()) {
$buttonarray[] = $this->_form->createElement('submit', 'previous', get_string('previousstage', 'backup'));
} else if ($this->uistage instanceof backup_ui_stage) {
// Only display the button on the first stage of backup, they only place where it has an effect.
$buttonarray[] = $this->_form->createElement('submit', 'oneclickbackup', get_string('jumptofinalstep', 'backup'),
array('class' => 'oneclickbackup'));
}
$buttonarray[] = $this->_form->createElement('cancel', 'cancel', get_string('cancel'), array('class' => 'confirmcancel'));
$buttonarray[] = $this->_form->createElement(
'submit',
'submitbutton',
get_string($this->uistage->get_ui()->get_name().'stage'.$this->uistage->get_stage().'action', 'backup'),
array('class' => 'proceedbutton')
);
$this->_form->addGroup($buttonarray, 'buttonar', '', array(' '), false);
$this->_form->closeHeaderBefore('buttonar');
$this->_definition_finalized = true;
}
|
[
"public",
"function",
"definition_after_data",
"(",
")",
"{",
"$",
"buttonarray",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"uistage",
"->",
"is_first_stage",
"(",
")",
")",
"{",
"$",
"buttonarray",
"[",
"]",
"=",
"$",
"this",
"->",
"_form",
"->",
"createElement",
"(",
"'submit'",
",",
"'previous'",
",",
"get_string",
"(",
"'previousstage'",
",",
"'backup'",
")",
")",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"uistage",
"instanceof",
"backup_ui_stage",
")",
"{",
"// Only display the button on the first stage of backup, they only place where it has an effect.",
"$",
"buttonarray",
"[",
"]",
"=",
"$",
"this",
"->",
"_form",
"->",
"createElement",
"(",
"'submit'",
",",
"'oneclickbackup'",
",",
"get_string",
"(",
"'jumptofinalstep'",
",",
"'backup'",
")",
",",
"array",
"(",
"'class'",
"=>",
"'oneclickbackup'",
")",
")",
";",
"}",
"$",
"buttonarray",
"[",
"]",
"=",
"$",
"this",
"->",
"_form",
"->",
"createElement",
"(",
"'cancel'",
",",
"'cancel'",
",",
"get_string",
"(",
"'cancel'",
")",
",",
"array",
"(",
"'class'",
"=>",
"'confirmcancel'",
")",
")",
";",
"$",
"buttonarray",
"[",
"]",
"=",
"$",
"this",
"->",
"_form",
"->",
"createElement",
"(",
"'submit'",
",",
"'submitbutton'",
",",
"get_string",
"(",
"$",
"this",
"->",
"uistage",
"->",
"get_ui",
"(",
")",
"->",
"get_name",
"(",
")",
".",
"'stage'",
".",
"$",
"this",
"->",
"uistage",
"->",
"get_stage",
"(",
")",
".",
"'action'",
",",
"'backup'",
")",
",",
"array",
"(",
"'class'",
"=>",
"'proceedbutton'",
")",
")",
";",
"$",
"this",
"->",
"_form",
"->",
"addGroup",
"(",
"$",
"buttonarray",
",",
"'buttonar'",
",",
"''",
",",
"array",
"(",
"' '",
")",
",",
"false",
")",
";",
"$",
"this",
"->",
"_form",
"->",
"closeHeaderBefore",
"(",
"'buttonar'",
")",
";",
"$",
"this",
"->",
"_definition_finalized",
"=",
"true",
";",
"}"
] |
Definition applied after the data is organised.. why's it here? because I want
to add elements on the fly.
@global moodle_page $PAGE
|
[
"Definition",
"applied",
"after",
"the",
"data",
"is",
"organised",
"..",
"why",
"s",
"it",
"here?",
"because",
"I",
"want",
"to",
"add",
"elements",
"on",
"the",
"fly",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/base_moodleform.class.php#L128-L148
|
216,694
|
moodle/moodle
|
backup/util/ui/base_moodleform.class.php
|
base_moodleform.close_task_divs
|
public function close_task_divs() {
if ($this->activitydiv) {
$this->_form->addElement('html', html_writer::end_tag('div'));
$this->activitydiv = false;
}
if ($this->sectiondiv) {
$this->_form->addElement('html', html_writer::end_tag('div'));
$this->sectiondiv = false;
}
if ($this->coursediv) {
$this->_form->addElement('html', html_writer::end_tag('div'));
$this->coursediv = false;
}
}
|
php
|
public function close_task_divs() {
if ($this->activitydiv) {
$this->_form->addElement('html', html_writer::end_tag('div'));
$this->activitydiv = false;
}
if ($this->sectiondiv) {
$this->_form->addElement('html', html_writer::end_tag('div'));
$this->sectiondiv = false;
}
if ($this->coursediv) {
$this->_form->addElement('html', html_writer::end_tag('div'));
$this->coursediv = false;
}
}
|
[
"public",
"function",
"close_task_divs",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"activitydiv",
")",
"{",
"$",
"this",
"->",
"_form",
"->",
"addElement",
"(",
"'html'",
",",
"html_writer",
"::",
"end_tag",
"(",
"'div'",
")",
")",
";",
"$",
"this",
"->",
"activitydiv",
"=",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"sectiondiv",
")",
"{",
"$",
"this",
"->",
"_form",
"->",
"addElement",
"(",
"'html'",
",",
"html_writer",
"::",
"end_tag",
"(",
"'div'",
")",
")",
";",
"$",
"this",
"->",
"sectiondiv",
"=",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"coursediv",
")",
"{",
"$",
"this",
"->",
"_form",
"->",
"addElement",
"(",
"'html'",
",",
"html_writer",
"::",
"end_tag",
"(",
"'div'",
")",
")",
";",
"$",
"this",
"->",
"coursediv",
"=",
"false",
";",
"}",
"}"
] |
Closes any open divs
|
[
"Closes",
"any",
"open",
"divs"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/base_moodleform.class.php#L153-L166
|
216,695
|
moodle/moodle
|
backup/util/ui/base_moodleform.class.php
|
base_moodleform.add_setting
|
public function add_setting(backup_setting $setting, base_task $task = null) {
return $this->add_settings(array(array($setting, $task)));
}
|
php
|
public function add_setting(backup_setting $setting, base_task $task = null) {
return $this->add_settings(array(array($setting, $task)));
}
|
[
"public",
"function",
"add_setting",
"(",
"backup_setting",
"$",
"setting",
",",
"base_task",
"$",
"task",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"add_settings",
"(",
"array",
"(",
"array",
"(",
"$",
"setting",
",",
"$",
"task",
")",
")",
")",
";",
"}"
] |
Adds the backup_setting as a element to the form
@param backup_setting $setting
@param base_task $task
@return bool
|
[
"Adds",
"the",
"backup_setting",
"as",
"a",
"element",
"to",
"the",
"form"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/base_moodleform.class.php#L174-L176
|
216,696
|
moodle/moodle
|
backup/util/ui/base_moodleform.class.php
|
base_moodleform.add_settings
|
public function add_settings(array $settingstasks) {
global $OUTPUT;
// Determine highest setting level, which is displayed in this stage. This is relevant for considering only
// locks of dependency settings for parent settings, which are not displayed in this stage.
$highestlevel = backup_setting::ACTIVITY_LEVEL;
foreach ($settingstasks as $st) {
list($setting, $task) = $st;
if ($setting->get_level() < $highestlevel) {
$highestlevel = $setting->get_level();
}
}
$defaults = array();
foreach ($settingstasks as $st) {
list($setting, $task) = $st;
// If the setting cant be changed or isn't visible then add it as a fixed setting.
if (!$setting->get_ui()->is_changeable($highestlevel) ||
$setting->get_visibility() != backup_setting::VISIBLE) {
$this->add_fixed_setting($setting, $task);
continue;
}
// First add the formatting for this setting.
$this->add_html_formatting($setting);
// Then call the add method with the get_element_properties array.
call_user_func_array(array($this->_form, 'addElement'), $setting->get_ui()->get_element_properties($task, $OUTPUT));
$this->_form->setType($setting->get_ui_name(), $setting->get_param_validation());
$defaults[$setting->get_ui_name()] = $setting->get_value();
if ($setting->has_help()) {
list($identifier, $component) = $setting->get_help();
$this->_form->addHelpButton($setting->get_ui_name(), $identifier, $component);
}
$this->_form->addElement('html', html_writer::end_tag('div'));
}
$this->_form->setDefaults($defaults);
return true;
}
|
php
|
public function add_settings(array $settingstasks) {
global $OUTPUT;
// Determine highest setting level, which is displayed in this stage. This is relevant for considering only
// locks of dependency settings for parent settings, which are not displayed in this stage.
$highestlevel = backup_setting::ACTIVITY_LEVEL;
foreach ($settingstasks as $st) {
list($setting, $task) = $st;
if ($setting->get_level() < $highestlevel) {
$highestlevel = $setting->get_level();
}
}
$defaults = array();
foreach ($settingstasks as $st) {
list($setting, $task) = $st;
// If the setting cant be changed or isn't visible then add it as a fixed setting.
if (!$setting->get_ui()->is_changeable($highestlevel) ||
$setting->get_visibility() != backup_setting::VISIBLE) {
$this->add_fixed_setting($setting, $task);
continue;
}
// First add the formatting for this setting.
$this->add_html_formatting($setting);
// Then call the add method with the get_element_properties array.
call_user_func_array(array($this->_form, 'addElement'), $setting->get_ui()->get_element_properties($task, $OUTPUT));
$this->_form->setType($setting->get_ui_name(), $setting->get_param_validation());
$defaults[$setting->get_ui_name()] = $setting->get_value();
if ($setting->has_help()) {
list($identifier, $component) = $setting->get_help();
$this->_form->addHelpButton($setting->get_ui_name(), $identifier, $component);
}
$this->_form->addElement('html', html_writer::end_tag('div'));
}
$this->_form->setDefaults($defaults);
return true;
}
|
[
"public",
"function",
"add_settings",
"(",
"array",
"$",
"settingstasks",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"// Determine highest setting level, which is displayed in this stage. This is relevant for considering only",
"// locks of dependency settings for parent settings, which are not displayed in this stage.",
"$",
"highestlevel",
"=",
"backup_setting",
"::",
"ACTIVITY_LEVEL",
";",
"foreach",
"(",
"$",
"settingstasks",
"as",
"$",
"st",
")",
"{",
"list",
"(",
"$",
"setting",
",",
"$",
"task",
")",
"=",
"$",
"st",
";",
"if",
"(",
"$",
"setting",
"->",
"get_level",
"(",
")",
"<",
"$",
"highestlevel",
")",
"{",
"$",
"highestlevel",
"=",
"$",
"setting",
"->",
"get_level",
"(",
")",
";",
"}",
"}",
"$",
"defaults",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"settingstasks",
"as",
"$",
"st",
")",
"{",
"list",
"(",
"$",
"setting",
",",
"$",
"task",
")",
"=",
"$",
"st",
";",
"// If the setting cant be changed or isn't visible then add it as a fixed setting.",
"if",
"(",
"!",
"$",
"setting",
"->",
"get_ui",
"(",
")",
"->",
"is_changeable",
"(",
"$",
"highestlevel",
")",
"||",
"$",
"setting",
"->",
"get_visibility",
"(",
")",
"!=",
"backup_setting",
"::",
"VISIBLE",
")",
"{",
"$",
"this",
"->",
"add_fixed_setting",
"(",
"$",
"setting",
",",
"$",
"task",
")",
";",
"continue",
";",
"}",
"// First add the formatting for this setting.",
"$",
"this",
"->",
"add_html_formatting",
"(",
"$",
"setting",
")",
";",
"// Then call the add method with the get_element_properties array.",
"call_user_func_array",
"(",
"array",
"(",
"$",
"this",
"->",
"_form",
",",
"'addElement'",
")",
",",
"$",
"setting",
"->",
"get_ui",
"(",
")",
"->",
"get_element_properties",
"(",
"$",
"task",
",",
"$",
"OUTPUT",
")",
")",
";",
"$",
"this",
"->",
"_form",
"->",
"setType",
"(",
"$",
"setting",
"->",
"get_ui_name",
"(",
")",
",",
"$",
"setting",
"->",
"get_param_validation",
"(",
")",
")",
";",
"$",
"defaults",
"[",
"$",
"setting",
"->",
"get_ui_name",
"(",
")",
"]",
"=",
"$",
"setting",
"->",
"get_value",
"(",
")",
";",
"if",
"(",
"$",
"setting",
"->",
"has_help",
"(",
")",
")",
"{",
"list",
"(",
"$",
"identifier",
",",
"$",
"component",
")",
"=",
"$",
"setting",
"->",
"get_help",
"(",
")",
";",
"$",
"this",
"->",
"_form",
"->",
"addHelpButton",
"(",
"$",
"setting",
"->",
"get_ui_name",
"(",
")",
",",
"$",
"identifier",
",",
"$",
"component",
")",
";",
"}",
"$",
"this",
"->",
"_form",
"->",
"addElement",
"(",
"'html'",
",",
"html_writer",
"::",
"end_tag",
"(",
"'div'",
")",
")",
";",
"}",
"$",
"this",
"->",
"_form",
"->",
"setDefaults",
"(",
"$",
"defaults",
")",
";",
"return",
"true",
";",
"}"
] |
Adds multiple backup_settings as elements to the form
@param array $settingstasks Consists of array($setting, $task) elements
@return bool
|
[
"Adds",
"multiple",
"backup_settings",
"as",
"elements",
"to",
"the",
"form"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/base_moodleform.class.php#L183-L221
|
216,697
|
moodle/moodle
|
backup/util/ui/base_moodleform.class.php
|
base_moodleform.add_fixed_setting
|
public function add_fixed_setting(backup_setting $setting, base_task $task) {
global $OUTPUT;
$settingui = $setting->get_ui();
if ($setting->get_visibility() == backup_setting::VISIBLE) {
$this->add_html_formatting($setting);
switch ($setting->get_status()) {
case backup_setting::LOCKED_BY_PERMISSION:
$icon = ' '.$OUTPUT->pix_icon('i/permissionlock', get_string('lockedbypermission', 'backup'), 'moodle',
array('class' => 'smallicon lockedicon permissionlock'));
break;
case backup_setting::LOCKED_BY_CONFIG:
$icon = ' '.$OUTPUT->pix_icon('i/configlock', get_string('lockedbyconfig', 'backup'), 'moodle',
array('class' => 'smallicon lockedicon configlock'));
break;
case backup_setting::LOCKED_BY_HIERARCHY:
$icon = ' '.$OUTPUT->pix_icon('i/hierarchylock', get_string('lockedbyhierarchy', 'backup'), 'moodle',
array('class' => 'smallicon lockedicon configlock'));
break;
default:
$icon = '';
break;
}
$context = context_course::instance($task->get_courseid());
$label = format_string($settingui->get_label($task), true, array('context' => $context));
$labelicon = $settingui->get_icon();
if (!empty($labelicon)) {
$label .= ' '.$OUTPUT->render($labelicon);
}
$this->_form->addElement('static', 'static_'.$settingui->get_name(), $label, $settingui->get_static_value().$icon);
$this->_form->addElement('html', html_writer::end_tag('div'));
}
$this->_form->addElement('hidden', $settingui->get_name(), $settingui->get_value());
$this->_form->setType($settingui->get_name(), $settingui->get_param_validation());
}
|
php
|
public function add_fixed_setting(backup_setting $setting, base_task $task) {
global $OUTPUT;
$settingui = $setting->get_ui();
if ($setting->get_visibility() == backup_setting::VISIBLE) {
$this->add_html_formatting($setting);
switch ($setting->get_status()) {
case backup_setting::LOCKED_BY_PERMISSION:
$icon = ' '.$OUTPUT->pix_icon('i/permissionlock', get_string('lockedbypermission', 'backup'), 'moodle',
array('class' => 'smallicon lockedicon permissionlock'));
break;
case backup_setting::LOCKED_BY_CONFIG:
$icon = ' '.$OUTPUT->pix_icon('i/configlock', get_string('lockedbyconfig', 'backup'), 'moodle',
array('class' => 'smallicon lockedicon configlock'));
break;
case backup_setting::LOCKED_BY_HIERARCHY:
$icon = ' '.$OUTPUT->pix_icon('i/hierarchylock', get_string('lockedbyhierarchy', 'backup'), 'moodle',
array('class' => 'smallicon lockedicon configlock'));
break;
default:
$icon = '';
break;
}
$context = context_course::instance($task->get_courseid());
$label = format_string($settingui->get_label($task), true, array('context' => $context));
$labelicon = $settingui->get_icon();
if (!empty($labelicon)) {
$label .= ' '.$OUTPUT->render($labelicon);
}
$this->_form->addElement('static', 'static_'.$settingui->get_name(), $label, $settingui->get_static_value().$icon);
$this->_form->addElement('html', html_writer::end_tag('div'));
}
$this->_form->addElement('hidden', $settingui->get_name(), $settingui->get_value());
$this->_form->setType($settingui->get_name(), $settingui->get_param_validation());
}
|
[
"public",
"function",
"add_fixed_setting",
"(",
"backup_setting",
"$",
"setting",
",",
"base_task",
"$",
"task",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"$",
"settingui",
"=",
"$",
"setting",
"->",
"get_ui",
"(",
")",
";",
"if",
"(",
"$",
"setting",
"->",
"get_visibility",
"(",
")",
"==",
"backup_setting",
"::",
"VISIBLE",
")",
"{",
"$",
"this",
"->",
"add_html_formatting",
"(",
"$",
"setting",
")",
";",
"switch",
"(",
"$",
"setting",
"->",
"get_status",
"(",
")",
")",
"{",
"case",
"backup_setting",
"::",
"LOCKED_BY_PERMISSION",
":",
"$",
"icon",
"=",
"' '",
".",
"$",
"OUTPUT",
"->",
"pix_icon",
"(",
"'i/permissionlock'",
",",
"get_string",
"(",
"'lockedbypermission'",
",",
"'backup'",
")",
",",
"'moodle'",
",",
"array",
"(",
"'class'",
"=>",
"'smallicon lockedicon permissionlock'",
")",
")",
";",
"break",
";",
"case",
"backup_setting",
"::",
"LOCKED_BY_CONFIG",
":",
"$",
"icon",
"=",
"' '",
".",
"$",
"OUTPUT",
"->",
"pix_icon",
"(",
"'i/configlock'",
",",
"get_string",
"(",
"'lockedbyconfig'",
",",
"'backup'",
")",
",",
"'moodle'",
",",
"array",
"(",
"'class'",
"=>",
"'smallicon lockedicon configlock'",
")",
")",
";",
"break",
";",
"case",
"backup_setting",
"::",
"LOCKED_BY_HIERARCHY",
":",
"$",
"icon",
"=",
"' '",
".",
"$",
"OUTPUT",
"->",
"pix_icon",
"(",
"'i/hierarchylock'",
",",
"get_string",
"(",
"'lockedbyhierarchy'",
",",
"'backup'",
")",
",",
"'moodle'",
",",
"array",
"(",
"'class'",
"=>",
"'smallicon lockedicon configlock'",
")",
")",
";",
"break",
";",
"default",
":",
"$",
"icon",
"=",
"''",
";",
"break",
";",
"}",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"task",
"->",
"get_courseid",
"(",
")",
")",
";",
"$",
"label",
"=",
"format_string",
"(",
"$",
"settingui",
"->",
"get_label",
"(",
"$",
"task",
")",
",",
"true",
",",
"array",
"(",
"'context'",
"=>",
"$",
"context",
")",
")",
";",
"$",
"labelicon",
"=",
"$",
"settingui",
"->",
"get_icon",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"labelicon",
")",
")",
"{",
"$",
"label",
".=",
"' '",
".",
"$",
"OUTPUT",
"->",
"render",
"(",
"$",
"labelicon",
")",
";",
"}",
"$",
"this",
"->",
"_form",
"->",
"addElement",
"(",
"'static'",
",",
"'static_'",
".",
"$",
"settingui",
"->",
"get_name",
"(",
")",
",",
"$",
"label",
",",
"$",
"settingui",
"->",
"get_static_value",
"(",
")",
".",
"$",
"icon",
")",
";",
"$",
"this",
"->",
"_form",
"->",
"addElement",
"(",
"'html'",
",",
"html_writer",
"::",
"end_tag",
"(",
"'div'",
")",
")",
";",
"}",
"$",
"this",
"->",
"_form",
"->",
"addElement",
"(",
"'hidden'",
",",
"$",
"settingui",
"->",
"get_name",
"(",
")",
",",
"$",
"settingui",
"->",
"get_value",
"(",
")",
")",
";",
"$",
"this",
"->",
"_form",
"->",
"setType",
"(",
"$",
"settingui",
"->",
"get_name",
"(",
")",
",",
"$",
"settingui",
"->",
"get_param_validation",
"(",
")",
")",
";",
"}"
] |
Adds a fixed or static setting to the form
@param backup_setting $setting
@param base_task $task
|
[
"Adds",
"a",
"fixed",
"or",
"static",
"setting",
"to",
"the",
"form"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/base_moodleform.class.php#L294-L327
|
216,698
|
moodle/moodle
|
backup/util/ui/base_moodleform.class.php
|
base_moodleform.add_dependencies
|
public function add_dependencies(backup_setting $setting) {
$mform = $this->_form;
// Apply all dependencies for backup.
foreach ($setting->get_my_dependency_properties() as $key => $dependency) {
call_user_func_array(array($this->_form, 'disabledIf'), $dependency);
}
}
|
php
|
public function add_dependencies(backup_setting $setting) {
$mform = $this->_form;
// Apply all dependencies for backup.
foreach ($setting->get_my_dependency_properties() as $key => $dependency) {
call_user_func_array(array($this->_form, 'disabledIf'), $dependency);
}
}
|
[
"public",
"function",
"add_dependencies",
"(",
"backup_setting",
"$",
"setting",
")",
"{",
"$",
"mform",
"=",
"$",
"this",
"->",
"_form",
";",
"// Apply all dependencies for backup.",
"foreach",
"(",
"$",
"setting",
"->",
"get_my_dependency_properties",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"dependency",
")",
"{",
"call_user_func_array",
"(",
"array",
"(",
"$",
"this",
"->",
"_form",
",",
"'disabledIf'",
")",
",",
"$",
"dependency",
")",
";",
"}",
"}"
] |
Adds dependencies to the form recursively
@param backup_setting $setting
|
[
"Adds",
"dependencies",
"to",
"the",
"form",
"recursively"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/base_moodleform.class.php#L334-L340
|
216,699
|
moodle/moodle
|
backup/util/ui/base_moodleform.class.php
|
base_moodleform.remove_element
|
public function remove_element($elementname) {
if ($this->_form->elementExists($elementname)) {
return $this->_form->removeElement($elementname);
} else {
return false;
}
}
|
php
|
public function remove_element($elementname) {
if ($this->_form->elementExists($elementname)) {
return $this->_form->removeElement($elementname);
} else {
return false;
}
}
|
[
"public",
"function",
"remove_element",
"(",
"$",
"elementname",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_form",
"->",
"elementExists",
"(",
"$",
"elementname",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_form",
"->",
"removeElement",
"(",
"$",
"elementname",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] |
Removes an element from the form if it exists
@param string $elementname
@return bool
|
[
"Removes",
"an",
"element",
"from",
"the",
"form",
"if",
"it",
"exists"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/base_moodleform.class.php#L355-L361
|
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.