本文整理汇总了PHP中moodleform::set_data方法的典型用法代码示例。如果您正苦于以下问题:PHP moodleform::set_data方法的具体用法?PHP moodleform::set_data怎么用?PHP moodleform::set_data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类moodleform
的用法示例。
在下文中一共展示了moodleform::set_data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
function set_data($data)
{
global $USER;
// insert some default values
if (!isset($data->id) || !$data->id) {
$data->author = $USER->email . ' (' . $USER->firstname . ' ' . $USER->lastname . ')';
}
return parent::set_data($data);
}
示例2:
/**
* Load in existing data as form defaults. Usually new entry defaults are stored directly in
* form definition (new entry form); this function is used to load in data where values
* already exist and data is being edited (edit entry form).
*
* @param mixed $default_values object or array of default values
*/
function set_data($default_values)
{
if (is_object($default_values)) {
$default_values = (array) $default_values;
}
$this->data_preprocessing($default_values);
parent::set_data($default_values + $this->standard_coursemodule_elements_settings());
//never slashed for moodleform_mod
}
示例3: strval
/**
* Load in existing data as form defaults
*
* @param stdClass|array $default_values object or array of default values
*/
function set_data($default_values)
{
if (!is_object($default_values)) {
// we need object for file_prepare_standard_editor
$default_values = (object) $default_values;
}
$editoroptions = $this->_customdata['editoroptions'];
$default_values = file_prepare_standard_editor($default_values, 'summary', $editoroptions, $editoroptions['context'], 'course', 'section', $default_values->id);
$default_values->usedefaultname = strval($default_values->name) === '';
parent::set_data($default_values);
}
示例4: foreach
function add_data($data, $postdata)
{
$mform = $this->_form;
$this->form = $data;
foreach ($postdata as $key => $value) {
$mform->addElement('hidden', $key);
$mform->setDefault($key, $value);
$mform->setType($key, PARAM_RAW);
}
parent::set_data($data);
}
示例5: set_data
public function set_data($current)
{
if (is_object($current)) {
$current = (array) $current;
}
if (!empty($current['info'])) {
$current['info'] = array('text' => $current['info'], 'infoformat' => $current['infoformat']);
} else {
$current['info'] = array('text' => '', 'infoformat' => FORMAT_HTML);
}
parent::set_data($current);
}
示例6: set_data
public function set_data($data)
{
// Set up the description type.
if (!empty($data['corestring'])) {
$data['descriptiontype'] = 'lang';
} else {
if (!empty($data['description'])) {
$data['descriptiontype'] = 'custom';
} else {
$data['descriptiontype'] = '';
}
}
// Call parent.
parent::set_data($data);
}
示例7: php_report_filtering_update_form
/**
* Updates parameter form fields based on defined preferences
*
* @uses $SESSION
* @param string $report_name "Shortname" of the report
* @param moodleform $parameter_form The from whose fields we are updating
*/
function php_report_filtering_update_form($report_name, &$parameter_form)
{
global $SESSION;
//go through the current user's preferences (persistent ONLY)
if ($existing_preferences = php_report_filtering_get_user_preferences($report_name)) {
foreach ($existing_preferences as $key => $value) {
//if the preference is php-report-related, set the form field
$prefix = 'php_report_' . $report_name . '/';
if (strpos($key, $prefix) === 0) {
//preference contains the form field name and UI value
$field_name = substr($key, strlen($prefix));
// error_log("php_report_filtering_update_form('{$report_name}', ¶meter_form): setting data '{$field_name}' => {$value}");
$parameter_form->set_data(array($field_name => $value));
}
}
}
}
示例8: array
/**
* preloads existing images
*
*/
function set_data($data)
{
global $DB;
if ($cardid = $this->_customdata['cardid']) {
$card = $DB->get_record('flashcard_deckdata', array('id' => $cardid));
$flashcard = $this->_customdata['flashcard'];
if ($flashcard->questionsmediatype != FLASHCARD_MEDIA_TEXT) {
$this->setup_card_filearea($card, 'question', $flashcard->questionsmediatype, $data);
} else {
$data->q0 = $card->questiontext;
}
if ($flashcard->answersmediatype != FLASHCARD_MEDIA_TEXT) {
$this->setup_card_filearea($card, 'answer', $flashcard->answersmediatype, $data);
} else {
$data->a0 = $card->answertext;
}
}
parent::set_data($data);
}
示例9: foreach
function set_data($default_values, $slashed = false)
{
// poke all the basic metadata elements into defaults so
// that they get set in the form
if (isset($default_values->metadata_elements)) {
foreach ($default_values->metadata_elements as $element) {
if ($element->namespace == '') {
if ($element->element == 'issuedate') {
$element->value = strtotime($element->value);
}
$key = $element->element;
$default_values->{$key} = $element->value;
}
}
}
// clean the hash off of the front as this maybe misleading - even though we need it
// to guarantee that the file is unique on the filesystem.
if (!empty($default_values->taoresourcefile) && preg_match('/^\\w+\\-(.*?)$/', $default_values->taoresourcefile, $matches)) {
$default_values->taoresourcefile = $matches[1];
}
$errors = parent::set_data($default_values, $slashed = false);
}
示例10: array
function set_data($question)
{
$formdata = array();
//fill out all data sets and also the fields for the next item to add.
$j = $this->noofitems * count($this->datasetdefs);
for ($itemnumber = $this->noofitems; $itemnumber >= 1; $itemnumber--) {
$data = array();
foreach ($this->datasetdefs as $defid => $datasetdef) {
if (isset($datasetdef->items[$itemnumber])) {
$formdata["number[{$j}]"] = $datasetdef->items[$itemnumber]->value;
$formdata["definition[{$j}]"] = $defid;
$formdata["itemid[{$j}]"] = $datasetdef->items[$itemnumber]->id;
$data[$datasetdef->name] = $datasetdef->items[$itemnumber]->value;
}
$j--;
}
$formdata['answercomment[' . $itemnumber . ']'] = $this->qtypeobj->comment_on_datasetitems($this->question, $data, $itemnumber);
}
$formdata['nextpageparam[forceregeneration]'] = $this->regenerate;
$formdata['selectdelete'] = '1';
$formdata['selectadd'] = '1';
$j = $this->noofitems * count($this->datasetdefs) + 1;
$data = array();
// data for comment_on_datasetitems later
//dataset generation dafaults
if ($this->qtypeobj->supports_dataset_item_generation()) {
$itemnumber = $this->noofitems + 1;
foreach ($this->datasetdefs as $defid => $datasetdef) {
$formdata["number[{$j}]"] = $this->qtypeobj->generate_dataset_item($datasetdef->options);
$formdata["definition[{$j}]"] = $defid;
$formdata["itemid[{$j}]"] = isset($datasetdef->items[$itemnumber]) ? $datasetdef->items[$itemnumber]->id : 0;
$data[$datasetdef->name] = $formdata["number[{$j}]"];
$j++;
}
}
//existing records override generated data depending on radio element
$j = $this->noofitems * count($this->datasetdefs) + 1;
if (!$this->regenerate) {
$idx = 1;
$itemnumber = $this->noofitems + 1;
foreach ($this->datasetdefs as $defid => $datasetdef) {
if (isset($datasetdef->items[$itemnumber])) {
$formdata["number[{$j}]"] = $datasetdef->items[$itemnumber]->value;
$formdata["definition[{$j}]"] = $defid;
$formdata["itemid[{$j}]"] = $datasetdef->items[$itemnumber]->id;
$data[$datasetdef->name] = $datasetdef->items[$itemnumber]->value;
}
$j++;
}
}
//default answercomment will get ignored if answer element is not in the form.
$formdata['answercomment[' . ($this->noofitems + 1) . ']'] = $this->qtypeobj->comment_on_datasetitems($this->question, $data, $this->noofitems + 1);
$formdata = $this->qtypeobj->custom_generator_set_data($this->datasetdefs, $formdata);
parent::set_data((object) ($formdata + (array) $question));
}
示例11:
/**
* Load in existing data as form defaults. Usually new entry defaults are stored directly in
* form definition (new entry form); this function is used to load in data where values
* already exist and data is being edited (edit entry form).
*
* @param mixed $default_values object or array of default values
*/
function set_data($default_values)
{
if (is_object($default_values)) {
$default_values = (array) $default_values;
}
$this->data_preprocessing($default_values);
parent::set_data($default_values);
//never slashed for moodleform_mod
}
示例12: config_set_edit_form_data
/**
* Allows the cache store to set its data against the edit form before it is shown to the user.
*
* @param moodleform $editform
* @param array $config
*/
public static function config_set_edit_form_data(moodleform $editform, array $config)
{
$data = array();
if (!empty($config['server'])) {
$data['server'] = $config['server'];
}
if (!empty($config['database'])) {
$data['database'] = $config['database'];
}
if (isset($config['extendedmode'])) {
$data['extendedmode'] = (bool) $config['extendedmode'];
}
if (!empty($config['username'])) {
$data['username'] = $config['username'];
}
if (!empty($config['password'])) {
$data['password'] = $config['password'];
}
if (!empty($config['replicaset'])) {
$data['replicaset'] = $config['replicaset'];
}
if (isset($config['usesafevalue'])) {
$data['usesafe'] = true;
$data['usesafevalue'] = (int) $data['usesafe'];
} else {
if (isset($config['usesafe'])) {
$data['usesafe'] = (bool) $config['usesafe'];
}
}
$editform->set_data($data);
}
示例13: set_data
/**
* Load in existing data as form defaults
*
* @param stdClass|array $default_values object or array of default values
*/
public function set_data($badge)
{
$default_values = array();
parent::set_data($badge);
if (!empty($badge->expiredate)) {
$default_values['expiry'] = 1;
$default_values['expiredate'] = $badge->expiredate;
} else {
if (!empty($badge->expireperiod)) {
$default_values['expiry'] = 2;
$default_values['expireperiod'] = $badge->expireperiod;
}
}
$default_values['currentimage'] = print_badge_image($badge, $badge->get_context(), 'large');
parent::set_data($default_values);
}
示例14: set_data
public function set_data($data) {
$editoroptions = $this->get_editor_options();
if (!isset($data->text)) {
$data->text = '';
}
if (!isset($data->format)) {
$data->textformat = FORMAT_HTML;
} else {
$data->textformat = $data->format;
}
if (!empty($this->_customdata->submission->id)) {
$itemid = $this->_customdata->submission->id;
} else {
$itemid = null;
}
switch ($this->_customdata->assignment->assignmenttype) {
case 'upload' :
case 'uploadsingle' :
$data = file_prepare_standard_filemanager($data, 'files', $editoroptions, $this->_customdata->context, 'mod_assignment', 'response', $itemid);
break;
default :
break;
}
$data = file_prepare_standard_editor($data, 'submissioncomment', $editoroptions, $this->_customdata->context, $editoroptions['component'], $editoroptions['filearea'], $itemid);
return parent::set_data($data);
}
示例15: array
function set_data($defaults)
{
// Prefix bui_ on all the core field names.
$blockfields = array('showinsubcontexts', 'pagetypepattern', 'subpagepattern', 'defaultregion', 'defaultweight', 'visible', 'region', 'weight');
foreach ($blockfields as $field) {
$newname = 'bui_' . $field;
$defaults->{$newname} = $defaults->{$field};
}
// Copy block config into config_ fields.
if (!empty($this->block->config)) {
foreach ($this->block->config as $field => $value) {
$configfield = 'config_' . $field;
$defaults->{$configfield} = $value;
}
}
// Munge ->subpagepattern becuase HTML selects don't play nicely with NULLs.
if (empty($defaults->bui_subpagepattern)) {
$defaults->bui_subpagepattern = '%@NULL@%';
}
parent::set_data($defaults);
}