예제 #1
0
/**
 * 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);
    }
}
예제 #2
0
파일: checkbox.php 프로젝트: jamesmcq/elis
/**
 * 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);
}