/** * Adds an appropriate editing control to the provided form * * @param moodleform or HTML_QuickForm $form The form to add the appropriate element to * @param field $field The definition of the field defining the controls * @param boolean $as_filter Whether to display a "choose" message */ function checkbox_control_display($form, $field, $as_filter = false) { if ($form instanceof moodleform) { $mform = $form->_form; } else { $mform = $form; $form->_customdata = null; } if ($field->datatype == 'bool' || $field->datatype == 'int' || $field->datatype == 'num') { $checkbox = $mform->addElement('advcheckbox', "field_{$field->shortname}", $field->name); manual_field_add_help_button($mform, "field_{$field->shortname}", $field); } else { if ($as_filter || $field->multivalued) { require_once CURMAN_DIRLOCATION . '/plugins/manual/field_controls/menu.php'; return menu_control_display($form, $field, $as_filter); } $manual = new field_owner($field->owners['manual']); $options = explode("\n", $manual->param_options); $controls = array(); foreach ($options as $option) { $option = trim($option); if ($field->multivalued) { // FIXME: this doesn't work $cb = $controls[] =& $mform->createElement('checkbox', "field_{$field->shortname}", null, $option); $cb->updateAttributes(array('value' => $option)); } else { $controls[] =& $mform->createElement('radio', "field_{$field->shortname}", null, $option, $option); } } $mform->addGroup($controls, "field_{$field->shortname}", $field->name, '<br />', false); } }
/** * Adds an appropriate editing control to the provided form * * @param moodleform or HTML_QuickForm $form The form to add the appropriate element to * @param field $field The definition of the field defining the controls */ function plaintextarea_control_display($form, $mform, $customdata, $field) { if (!$form instanceof moodleform) { $mform = $form; $form->_customdata = null; } $manual = new field_owner($field->owners['manual']); $mform->_form->addElement('textarea', "field_{$field->shortname}", $field->name, "cols=\"{$manual->param_columns}\" rows=\"{$manual->param_rows}\""); manual_field_add_help_button($mform, "field_{$field->shortname}", $field); }
/** * Adds an appropriate editing control to the provided form * * @param moodleform or HTML_QuickForm $form The form to add the appropriate element to * @param field $field The definition of the field defining the controls */ function password_control_display($form, $mform, $customdata, $field) { if (!$form instanceof moodleform) { $mform = $form; $form->_customdata = null; } $manual = new field_owner($field->owners['manual']); $mform->addElement('password', "field_{$field->shortname}", $field->name, "maxlength=\"{$manual->param_maxlength}\" size=\"{$manual->param_columns}\""); manual_field_add_help_button($mform, "field_{$field->shortname}", $field); }
/** * Adds an appropriate editing control to the provided form * * @param moodleform or HTML_QuickForm $form The form to add the appropriate element to * @param field $field The definition of the field defining the controls * @param boolean $as_filter Whether to display a "choose" message */ function datetime_control_display($form, $mform, $customdata, $field, $as_filter = false) { if (!$form instanceof moodleform) { $mform = $form; $form->_customdata = null; } $manual = new field_owner($field->owners['manual']); $mform->addElement($manual->param_inctime ? 'date_time_selector' : 'date_selector', "field_{$field->shortname}", $field->name, array('startyear' => $manual->param_startyear, 'stopyear' => $manual->param_stopyear, 'optional' => false)); // TBD!?! manual_field_add_help_button($mform, "field_{$field->shortname}", $field); }
/** * Adds an appropriate editing control to the provided form * * @param moodleform or HTML_QuickForm $form The form to add the appropriate element to * @param field $field The definition of the field defining the controls */ function textarea_control_display($form, $mform, $customdata, $field) { if (!$form instanceof moodleform) { $mform = $form; $form->_customdata = null; } $fieldname = "field_{$field->shortname}"; $manual = new field_owner($field->owners['manual']); $mform->addElement('htmleditor', $fieldname, $field->name, "cols=\"{$manual->param_columns}\" rows=\"{$manual->param_rows}\""); $mform->setType($fieldname, PARAM_CLEAN); manual_field_add_help_button($mform, $fieldname, $field); }
/** * Adds an appropriate editing control to the provided form * * @param moodleform or HTML_QuickForm $form The form to add the appropriate element to * @param field $field The definition of the field defining the controls * @param boolean $as_filter Whether to display a "choose" message * @param string $contextname Optional context name/entity */ function checkbox_control_display($form, $mform, $customdata, $field, $as_filter = false, $contextname = 'system') { if (!$form instanceof moodleform) { $mform = $form; $form->_customdata = null; } $manual = new field_owner($field->owners['manual']); $manual_params = unserialize($manual->params); if (!empty($manual_params['options_source']) || !empty($manual_params['options'])) { if ($as_filter || $field->multivalued) { // require_once(CURMAN_DIRLOCATION.'/plugins/manual/field_controls/menu.php'); require_once elis::plugin_file('elisfields_manual', 'field_controls/menu.php'); return menu_control_display($form, $mform, $customdata, $field, $as_filter); } $options = array(); if (!empty($manual_params['options'])) { $options = explode("\n", $manual_params['options']); } $source = ''; if (!empty($manual_params['options_source'])) { $source = $manual_params['options_source']; } if (!empty($source)) { $srcfile = elis::plugin_file('elisfields_manual', "sources/{$source}.php"); if (file_exists($srcfile)) { require_once elis::plugin_file('elisfields_manual', 'sources.php'); require_once $srcfile; $classname = "manual_options_{$source}"; $plugin = new $classname(); if ($plugin && $plugin->is_applicable($contextname)) { $options = $plugin->get_options($customdata); } } } $controls = array(); foreach ($options as $option) { $option = trim($option); if ($field->multivalued) { // FIXME: this doesn't work $cb = $controls[] =& $mform->createElement('checkbox', "field_{$field->shortname}", null, $option); $cb->updateAttributes(array('value' => $option)); } else { $controls[] =& $mform->createElement('radio', "field_{$field->shortname}", null, $option, $option); } } $mform->addGroup($controls, "field_{$field->shortname}", $field->name, '<br />', false); } else { $checkbox = $mform->addElement('advcheckbox', "field_{$field->shortname}", $field->name); } manual_field_add_help_button($mform, "field_{$field->shortname}", $field); }
/** * Adds an appropriate editing control to the provided form * * @param moodleform or HTML_QuickForm $form The form to add the appropriate element to * @param field $field The definition of the field defining the controls * @param boolean $as_filter Whether to display a "choose" message * @param string $contextname Optional context name/entity */ function menu_control_display($form, $mform, $customdata, $field, $as_filter = false, $contextname = 'system') { if (!$form instanceof moodleform) { $mform = $form; $form->_customdata = null; $customdata = null; } $manual = new field_owner($field->owners['manual']); if ($field->datatype != 'bool') { if (!isset($manual->param_options_source) || $manual->param_options_source == '') { $tmpoptions = explode("\n", $manual->param_options); if ($as_filter) { $options = array('' => get_string("choose")); } foreach ($tmpoptions as $key => $option) { $option = trim($option, "\n\r"); $options[$option] = format_string($option); // multilang formatting } } else { $options = array(); $source = $manual->param_options_source; $srcfile = elis::plugin_file('elisfields_manual', "sources/{$source}.php"); if (file_exists($srcfile)) { require_once elis::plugin_file('elisfields_manual', 'sources.php'); require_once $srcfile; $classname = "manual_options_{$source}"; $plugin = new $classname(); if ($plugin && $plugin->is_applicable($contextname)) { $options = $plugin->get_options($customdata); } } } } else { if ($as_filter) { $options = array('' => get_string("choose"), 0 => get_string('no'), 1 => get_string('yes')); } else { $options = array(0 => get_string('no'), 1 => get_string('yes')); } } $menu = $mform->addElement('select', "field_{$field->shortname}", $field->name, $options); if ($field->multivalued && !$as_filter) { $menu->setMultiple(true); } manual_field_add_help_button($mform, "field_{$field->shortname}", $field); }
/** * Adds an appropriate editing control to the provided form * * @param moodleform or HTML_QuickForm $form The form to add the appropriate element to * @param field $field The definition of the field defining the controls */ function text_control_display($form, $mform, $customdata, $field) { if (!$form instanceof moodleform) { $mform = $form; $form->_customdata = null; } $param = ''; if (isset($field->owners['manual'])) { $manual = new field_owner($field->owners['manual']); if (isset($manual->param_maxlength) && isset($manual->param_columns)) { $param = "maxlength=\"{$manual->param_maxlength}\" size=\"{$manual->param_columns}\""; } } $fieldname = "field_{$field->shortname}"; $mform->addElement('text', $fieldname, $field->name, $param); $mform->setType($fieldname, PARAM_MULTILANG); manual_field_add_help_button($mform, $fieldname, $field); }
/** * Adds an appropriate editing control to the provided form * * @param moodleform or HTML_QuickForm $form The form to add the appropriate element to * @param field $field The definition of the field defining the controls * @param boolean $as_filter Whether to display a "choose" message */ function menu_control_display($form, $field, $as_filter = false) { if ($form instanceof moodleform) { $mform = $form->_form; } else { $mform = $form; $form->_customdata = null; } $manual = new field_owner($field->owners['manual']); if ($field->datatype != 'bool') { if (!isset($manual->param_options_source) || $manual->param_options_source == '') { $tmpoptions = explode("\n", $manual->param_options); if ($as_filter) { $options = array('' => get_string("choose")); } foreach ($tmpoptions as $key => $option) { $option = trim($option); $options[$option] = format_string($option); //multilang formatting } } else { $source = $manual->param_options_source; require_once CURMAN_DIRLOCATION . '/plugins/manual/sources.php'; require_once CURMAN_DIRLOCATION . "/plugins/manual/sources/{$source}.php"; $classname = "manual_options_{$source}"; $plugin = new $classname(); $options = $plugin->get_options($form->_customdata); } } else { if ($as_filter) { $options = array('' => get_string("choose"), 0 => get_string('no'), 1 => get_string('yes')); } else { $options = array(0 => get_string('no'), 1 => get_string('yes')); } } $menu = $mform->addElement('select', "field_{$field->shortname}", $field->name, $options); if ($field->multivalued && !$as_filter) { $menu->setMultiple(true); } manual_field_add_help_button($mform, "field_{$field->shortname}", $field); }