本文整理汇总了PHP中field::format_number方法的典型用法代码示例。如果您正苦于以下问题:PHP field::format_number方法的具体用法?PHP field::format_number怎么用?PHP field::format_number使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类field
的用法示例。
在下文中一共展示了field::format_number方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: definition
/**
* items in the form
*
* @uses $USER
*/
public function definition()
{
global $USER;
$fields = field::get_for_context_level('track');
foreach ($fields as $rec) {
$field = new field($rec);
if (strcmp($field->datatype, "num") == 0) {
$fieldname = "field_{$field->shortname}";
if (isset($this->_customdata['obj']->{$fieldname})) {
$formatnum = $field->format_number($this->_customdata['obj']->{$fieldname});
$this->_customdata['obj']->{$fieldname} = $formatnum;
}
}
}
$this->set_data($this->_customdata['obj']);
$mform =& $this->_form;
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
$curs = array();
if (!empty($USER->id)) {
// TBD: and/or capability 'local/elisprogram:track_edit|view' ?
// This is necessary for creating a new track but will prevent a parent programs from appearing
// when the user has track edit permissions but not track creation permission -- ELIS-5954
$contexts = get_contexts_by_capability_for_user('curriculum', 'local/elisprogram:track_create', $USER->id);
$curs = curriculum_get_listing('name', 'ASC', 0, 0, '', '', $contexts);
}
if (empty($this->_customdata['obj']->id)) {
$curid_options = array();
if (!empty($curs)) {
foreach ($curs as $cur) {
$curid_options[$cur->id] = '(' . $cur->idnumber . ') ' . $cur->name;
}
}
$mform->addElement('select', 'curid', get_string('curriculum', 'local_elisprogram') . ':', $curid_options);
$mform->addRule('curid', get_string('required'), 'required', NULL, 'client');
$mform->addHelpButton('curid', 'trackform:curriculum_curid', 'local_elisprogram');
} else {
// Track editing, do not allow the user to change curriculum
// Make sure that the parent program for this track is always included otherwise the display is messed up
// and hitting the form Cancel button causes a DB error -- ELIS-5954
$track = new track($this->_customdata['obj']->id);
$curs = curriculum_get_listing('name', 'ASC', 0, 0, $track->curriculum->name);
$mform->addElement('static', 'curidstatic', get_string('curriculum', 'local_elisprogram') . ':', $curs[$this->_customdata['obj']->curid]->name);
$mform->addHelpButton('curidstatic', 'trackform:curriculum_curidstatic', 'local_elisprogram');
$mform->addElement('hidden', 'curid');
$mform->setType('curid', PARAM_INT);
}
$mform->addElement('text', 'idnumber', get_string('track_idnumber', 'local_elisprogram') . ':');
$mform->setType('idnumber', PARAM_TEXT);
$mform->addRule('idnumber', get_string('required'), 'required', NULL, 'client');
$mform->addRule('idnumber', null, 'maxlength', 100);
$mform->addHelpButton('idnumber', 'trackform:track_idnumber', 'local_elisprogram');
$mform->addElement('text', 'name', get_string('track_name', 'local_elisprogram') . ':');
$mform->setType('name', PARAM_TEXT);
$mform->addRule('name', null, 'maxlength', 255);
$mform->addRule('name', get_string('required'), 'required', NULL, 'client');
$mform->addHelpButton('name', 'trackform:track_name', 'local_elisprogram');
$mform->addElement('textarea', 'description', get_string('track_description', 'local_elisprogram') . ':');
$mform->setType('description', PARAM_CLEAN);
$mform->addHelpButton('description', 'trackform:track_description', 'local_elisprogram');
$mform->addElement('date_selector', 'startdate', get_string('track_startdate', 'local_elisprogram') . ':', array('optional' => true));
$mform->addElement('date_selector', 'enddate', get_string('track_enddate', 'local_elisprogram') . ':', array('optional' => true));
$mform->addHelpButton('startdate', 'trackform:track_startdate', 'local_elisprogram');
if (!empty($this->_customdata['obj']->id)) {
$trackassignobj = new trackassignment(array('trackid' => $this->_customdata['obj']->id));
}
// Only show auto-create checkbox if the track does not have any classes assigned
if (!isset($trackassignobj) || 0 == $trackassignobj->count_assigned_classes_from_track()) {
$mform->addElement('checkbox', 'autocreate', get_string('track_autocreate', 'local_elisprogram') . ':');
$mform->addHelpButton('autocreate', 'trackform:track_autocreate', 'local_elisprogram');
}
// custom fields
$this->add_custom_fields('track', 'local/elisprogram:track_edit', 'local/elisprogram:track_view', 'curriculum');
$this->add_action_buttons();
}
示例2: 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();
}
}
}