本文整理汇总了PHP中field::to_array方法的典型用法代码示例。如果您正苦于以下问题:PHP field::to_array方法的具体用法?PHP field::to_array怎么用?PHP field::to_array使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类field
的用法示例。
在下文中一共展示了field::to_array方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: customfieldpage
//.........这里部分代码省略.........
if (!$moodlefield) {
print_error('invalid_field_id', 'local_elisprogram');
}
unset($moodlefield->id);
$data = $moodlefield;
$data_array = (array) $moodlefield;
$data_array['datatype'] = 'text';
$data_array['manual_field_control'] = $moodlefield->datatype;
switch ($moodlefield->datatype) {
case field::CHECKBOX:
$data_array['datatype'] = 'bool';
break;
case field::DATETIME:
$data_array['datatype'] = 'datetime';
$data_array['manual_field_startyear'] = $moodlefield->param1;
$data_array['manual_field_stopyear'] = $moodlefield->param2;
$data_array['manual_field_inctime'] = $moodlefield->param3;
break;
case field::MENU:
$data_array['datatype'] = 'char';
$data_array['manual_field_options'] = $moodlefield->param1;
break;
case field::TEXTAREA:
$data_array['manual_field_columns'] = $moodlefield->param1;
$data_array['manual_field_rows'] = $moodlefield->param2;
break;
case field::TEXT:
if ($moodlefield->param3) {
$data_array['manual_field_control'] = 'password';
}
$data_array['manual_field_columns'] = $moodlefield->param1;
$data_array['manual_field_maxlength'] = $moodlefield->param2;
break;
}
} else {
$data = new field($id);
$data->load();
$manual = new field_owner(!isset($field->owners) || !isset($field->owners['manual']) ? false : $field->owners['manual']);
$menu_src = !empty($manual->options_source) ? $manual->options_source : 0;
$data_array = $data->to_array();
$field_record = $DB->get_record(field::TABLE, array('id' => $id));
if (!empty($field_record)) {
foreach ($field_record as $field_item => $field_value) {
$data_array[$field_item] = $field_value;
}
}
$defaultdata = field_data::get_for_context_and_field(NULL, $data);
if (!empty($defaultdata)) {
if ($data->multivalued) {
$values = array();
foreach ($defaultdata as $defdata) {
$values[] = $defdata->data;
}
$defaultdata = $values;
} else {
foreach ($defaultdata as $defdata) {
$defaultdata = $defdata->data;
break;
}
}
}
$field = new field();
// Format decimal numbers
if ($data_array['datatype'] == 'num' && $manual->param_control != 'menu') {
$defaultdata = $field->format_number($defaultdata);
}
if (!is_object($defaultdata)) {
$data_array['defaultdata'] = $defaultdata;
}
$plugins = core_component::get_plugin_list('elisfields');
foreach ($plugins as $plugin => $dir) {
if (is_readable($CFG->dirroot . '/local/eliscore/fields/' . $plugin . '/custom_fields.php')) {
include_once $CFG->dirroot . '/local/eliscore/fields/' . $plugin . '/custom_fields.php';
if (function_exists("{$plugin}_field_get_form_data")) {
$data_array += call_user_func("{$plugin}_field_get_form_data", $form, $data);
}
}
}
}
if (isset($data_array['defaultdata'])) {
// ELIS-6699 -- load the field to determine the data type used, $data may be a field_data_* or field object
if (isset($data->fieldid)) {
$field->id = $data->fieldid;
$field->load();
} else {
$field = $data;
}
$data_array['defaultdata_checkbox'] = !empty($data_array['defaultdata']);
// ELIS-6699 -- If this is not a datetime field, then we can't use the default data value as a timestamp
$data_array['defaultdata_datetime'] = $field->datatype == 'datetime' ? $data_array['defaultdata'] : time();
$data_array['defaultdata_text'] = strval($data_array['defaultdata']);
$data_array[empty($menu_src) ? 'defaultdata_menu' : "defaultdata_menu_{$menu_src}"] = $data_array['defaultdata'];
$data_array[empty($menu_src) ? 'defaultdata_radio' : "defaultdata_radio_{$menu_src}"] = $data_array['defaultdata'];
}
$form->set_data($data_array);
}
$form->display();
}
}
}
示例2: customfieldpage
function action_editfield()
{
global $CURMAN;
$level = $this->required_param('level', PARAM_ACTION);
$ctxlvl = context_level_base::get_custom_context_level($level, 'block_curr_admin');
if (!$ctxlvl) {
print_error('invalid_context_level', 'block_curr_admin');
}
$id = $this->optional_param('id', NULL, PARAM_INT);
require_once CURMAN_DIRLOCATION . '/form/customfieldform.class.php';
$tmppage = new customfieldpage(array('level' => $level, 'action' => 'editfield'), $this);
$form = new customfieldform($tmppage->get_moodle_url(), $this);
if ($form->is_cancelled()) {
$tmppage = new customfieldpage(array('level' => $level));
redirect($tmppage->get_url(), get_string('edit_cancelled', 'block_curr_admin'));
} else {
if ($data = $form->get_data()) {
$field = new field($data);
if ($id) {
$field->id = $id;
$field->update();
} else {
$field->add();
// assume each field only belongs to one context level (for now)
$fieldcontext = new field_contextlevel();
$fieldcontext->fieldid = $field->id;
$fieldcontext->contextlevel = $ctxlvl;
$fieldcontext->add();
}
//don't use !empty here because we might be storing a 0 or similar value
if ($data->defaultdata != '') {
// save the default value
$defaultdata = $data->defaultdata;
if ($field->multivalued) {
// parse as a CSV string
// until we can use str_getcsv from PHP 5.3...
$temp = fopen("php://memory", "rw");
fwrite($temp, $defaultdata);
rewind($temp);
$defaultdata = fgetcsv($temp);
fclose($temp);
}
field_data::set_for_context_and_field(NULL, $field, $defaultdata);
} else {
if ($field->multivalued) {
field_data::set_for_context_and_field(NULL, $field, array());
} else {
field_data::set_for_context_and_field(NULL, $field, NULL);
}
}
$plugins = get_list_of_plugins('curriculum/plugins');
foreach ($plugins as $plugin) {
if (is_readable(CURMAN_DIRLOCATION . '/plugins/' . $plugin . '/custom_fields.php')) {
include_once CURMAN_DIRLOCATION . '/plugins/' . $plugin . '/custom_fields.php';
if (function_exists("{$plugin}_field_save_form_data")) {
call_user_func("{$plugin}_field_save_form_data", $form, $field, $data);
}
}
}
$tmppage = new customfieldpage(array('level' => $level));
redirect($tmppage->get_url(), get_string('field_saved', 'block_curr_admin', $field));
} else {
if (!empty($id)) {
if ($this->optional_param('from', NULL, PARAM_CLEAN) == 'moodle' && $level == 'user') {
$moodlefield = $CURMAN->db->get_record('user_info_field', 'id', $id);
if (!$moodlefield) {
print_error('invalidfieldid', 'block_curr_admin');
}
unset($moodlefield->id);
$data_array = (array) $moodlefield;
$data_array['datatype'] = 'text';
$data_array['manual_field_control'] = $moodlefield->datatype;
switch ($moodlefield->datatype) {
case field::checkbox:
$data_array['datatype'] = 'bool';
break;
case field::menu:
$data_array['datatype'] = 'char';
$data_array['manual_field_options'] = $moodlefield->param1;
break;
case field::textarea:
$data_array['manual_field_columns'] = $moodlefield->param1;
$data_array['manual_field_rows'] = $moodlefield->param2;
break;
case field::text:
if ($moodlefield->param3) {
$data_array['manual_field_control'] = 'password';
}
$data_array['manual_field_columns'] = $moodlefield->param1;
$data_array['manual_field_maxlength'] = $moodlefield->param2;
break;
}
} else {
$data = new field($id);
$data_array = $data->to_array();
$defaultdata = field_data::get_for_context_and_field(NULL, $data);
if (!empty($defaultdata)) {
if ($data->multivalued) {
$values = array();
// extract the data
//.........这里部分代码省略.........