/**
  * Add question-type specific form fields.
  *
  * @param MoodleQuickForm $mform the form being built.
  */
 function definition_inner(&$mform)
 {
     // Add the select control which will select the comparison type to use
     $mform->addElement('select', 'compareby', get_string('compareby', 'qtype_algebra'), array("sage" => get_string('comparesage', 'qtype_algebra'), "eval" => get_string('compareeval', 'qtype_algebra'), "equiv" => get_string('compareequiv', 'qtype_algebra')));
     $mform->setDefault('compareby', 'eval');
     $mform->setHelpButton('compareby', array('comp_algorithm', get_string('compalgorithm', 'qtype_algebra'), 'qtype_algebra'));
     // Add the control to select the number of checks to perform
     // First create an array with all the allowed values. We will then use this array
     // with the array_combine function to create a single array where the keys are the
     // same as the array values
     $chk_array = array('1', '2', '3', '5', '7', '10', '20', '30', '50', '70', '100', '200', '300', '500', '700', '1000');
     // Add the select element using the array_combine method discussed above
     $mform->addElement('select', 'nchecks', get_string('nchecks', 'qtype_algebra'), array_combine($chk_array, $chk_array));
     // Set the default number of checks to perform
     $mform->setDefault('nchecks', '10');
     $mform->setHelpButton('nchecks', array('eval_checks', get_string('evalchecks', 'qtype_algebra'), 'qtype_algebra'));
     // Add the box to set the tolerance to use when performing evaluation checks
     $mform->addElement('text', 'tolerance', get_string('tolerance', 'qtype_algebra'));
     $mform->setType('tolerance', PARAM_NUMBER);
     $mform->setDefault('tolerance', '0.001');
     $mform->setHelpButton('tolerance', array('check_tolerance', get_string('checktolerance', 'qtype_algebra'), 'qtype_algebra'));
     // Add an entry for the answer box prefix
     $mform->addElement('text', 'answerprefix', get_string('answerprefix', 'qtype_algebra'), array('size' => 55));
     $mform->setType('answerprefix', PARAM_RAW);
     $mform->setHelpButton('answerprefix', array('answer_prefix', get_string('answerboxprefix', 'qtype_algebra'), 'qtype_algebra'));
     // Add an entry for a disallowed expression
     $mform->addElement('text', 'disallow', get_string('disallow', 'qtype_algebra'), array('size' => 55));
     $mform->setType('disallow', PARAM_RAW);
     $mform->setHelpButton('disallow', array('disallowed_ans', get_string('disallowanswer', 'qtype_algebra'), 'qtype_algebra'));
     // Create an array which will store the function checkboxes
     $func_group = array();
     // Create an array to add spacers between the boxes
     $spacers = array('<br>');
     // Add the initial all functions box to the list of check boxes
     $func_group[] =& $mform->createElement('checkbox', 'all', '', get_string('allfunctions', 'qtype_algebra'));
     // Create a checkbox element for each function understood by the parser
     for ($i = 0; $i < count(qtype_algebra_parser::$functions); $i++) {
         $func = qtype_algebra_parser::$functions[$i];
         $func_group[] =& $mform->createElement('checkbox', $func, '', $func);
         if ($i % 6 == 5) {
             $spacers[] = '<br>';
         } else {
             $spacers[] = str_repeat('&nbsp;', 8 - strlen($func));
         }
     }
     // Create and add the group of function controls to the form
     $mform->addGroup($func_group, 'allowedfuncs', get_string('allowedfuncs', 'qtype_algebra'), $spacers, true);
     $mform->disabledIf('allowedfuncs', 'allowedfuncs[all]', 'checked');
     $mform->setDefault('allowedfuncs[all]', 'checked');
     $mform->setHelpButton('allowedfuncs', array('allowed_funcs', get_string('allowedfunctions', 'qtype_algebra'), 'qtype_algebra'));
     // Create the array for the list of variables used in the question
     $repeated = array();
     // Create the array for the list of repeated options used by the variable subforms
     $repeatedoptions = array();
     // Add the form elements to enter the variables
     $repeated[] =& $mform->createElement('header', 'variablehdr', get_string('variableno', 'qtype_algebra', '{no}'));
     $repeatedoptions['variablehdr']['helpbutton'] = array('variable', get_string('variable', 'qtype_algebra'), 'qtype_algebra');
     $repeated[] =& $mform->createElement('text', 'variable', get_string('variablename', 'qtype_algebra'), array('size' => 20));
     $mform->setType('variable', PARAM_RAW);
     $repeated[] =& $mform->createElement('text', 'varmin', get_string('varmin', 'qtype_algebra'), array('size' => 20));
     $mform->setType('varmin', PARAM_RAW);
     $repeatedoptions['varmin']['default'] = '';
     $repeated[] =& $mform->createElement('text', 'varmax', get_string('varmax', 'qtype_algebra'), array('size' => 20));
     $mform->setType('varmax', PARAM_RAW);
     $repeatedoptions['varmax']['default'] = '';
     // Get the current number of variables defined, if any
     if (isset($this->question->options)) {
         $countvars = count($this->question->options->variables);
     } else {
         $countvars = 0;
     }
     // Come up with the number of variable entries to add to the form at the start
     if ($this->question->formoptions->repeatelements) {
         $repeatsatstart = SYMB_QUESTION_NUMVAR_START > $countvars + SYMB_QUESTION_NUMVAR_ADD ? SYMB_QUESTION_NUMVAR_START : $countvars + SYMB_QUESTION_NUMVAR_ADD;
     } else {
         $repeatsatstart = $countvars;
     }
     $this->repeat_elements($repeated, $repeatsatstart, $repeatedoptions, 'novariables', 'addvariables', SYMB_QUESTION_NUMVAR_ADD, get_string('addmorevariableblanks', 'qtype_algebra'));
     // Add the instructions for entering answers to the question
     $mform->addElement('static', 'answersinstruct', get_string('correctanswers', 'quiz'), get_string('filloutoneanswer', 'quiz'));
     $mform->closeHeaderBefore('answersinstruct');
     $creategrades = get_grade_options();
     $gradeoptions = $creategrades->gradeoptions;
     $repeated = array();
     $repeated[] =& $mform->createElement('header', 'answerhdr', get_string('answerno', 'qtype_algebra', '{no}'));
     $repeated[] =& $mform->createElement('text', 'answer', get_string('answer', 'quiz'), array('size' => 54));
     $repeated[] =& $mform->createElement('select', 'fraction', get_string('grade'), $gradeoptions);
     $repeated[] =& $mform->createElement('htmleditor', 'feedback', get_string('feedback', 'quiz'), array('course' => $this->coursefilesid));
     if (isset($this->question->options)) {
         $countanswers = count($this->question->options->answers);
     } else {
         $countanswers = 0;
     }
     if ($this->question->formoptions->repeatelements) {
         $repeatsatstart = SYMB_QUESTION_NUMANS_START > $countanswers + SYMB_QUESTION_NUMANS_ADD ? SYMB_QUESTION_NUMANS_START : $countanswers + SYMB_QUESTION_NUMANS_ADD;
     } else {
         $repeatsatstart = $countanswers;
     }
     $repeatedoptions = array();
     $mform->setType('answer', PARAM_RAW);
     $repeatedoptions['fraction']['default'] = 0;
     $this->repeat_elements($repeated, $repeatsatstart, $repeatedoptions, 'noanswers', 'addanswers', SYMB_QUESTION_NUMANS_ADD, get_string('addmoreanswerblanks', 'qtype_algebra'));
 }
Exemplo n.º 2
0
/**
 * Populate mform with a new question
 * @param MoodleQuickForm $mform
 * @param unknown_type $number
 * @param unknown_type $options
 * @param array $keys array of letters or symbols to numerate the options i.e. A,B,C,D...
 * @param unknown_type $defaults
 */
function create_question(MoodleQuickForm $mform, $number, $options, $keys, $warnings = null)
{
    //print_object($options);
    //print_object($number);
    $returnobj = new stdClass();
    //	if (isset($defaults['invalid']))
    //		$invalid = $defaults['invalid'];
    //	else
    //		$invalid = null;
    $i = 0;
    $questionarray = array();
    $warn = '';
    $icon = '';
    /**
     * option to unmark all others. Marked if all options are clear
     */
    if ($options[0]->questiontype == 'CIRCLE') {
        $questionarray[] =& MoodleQuickForm::createElement('radio', '' . $number, '', get_string('unmarked', 'blended'), $number . 'none');
        $mform->setDefault('' . $number, $number . 'none');
    }
    foreach ($options as $option) {
        $option->key = $keys[$i];
        /**
         * Report about any warning of error with this option
         */
        if (isset($warnings[$option->id])) {
            $warn .= $warn ? ',' : '';
            $warn .= " {$option->key}";
            $icon = '<img src="images/warning.png" width="16" alt="' . get_string('MarkWarning', 'blended') . '"/>';
        }
        if (isset($warnings[$option->id])) {
            $warnOptionStyle = $icon;
        } else {
            $warnOptionStyle = '';
        }
        if ($option->questiontype == 'SQUARE') {
            $questionarray[] =& MoodleQuickForm::createElement('advcheckbox', $option->label, '', $warnOptionStyle . $option->key, array('group' => 1));
            $returnobj->radioindex = null;
        } else {
            if ($option->questiontype == 'CIRCLE') {
                $questionarray[] =& MoodleQuickForm::createElement('radio', '' . $number, '', $warnOptionStyle . $option->key, $option->label);
                $returnobj->radioindex = $number;
            }
        }
        $i++;
    }
    foreach ($options as $option) {
        if ($option->value == 1) {
            $mform->setDefault('' . $number, $option->label);
        }
    }
    $questionName = 'Pregunta ' . $number;
    if ($warn) {
        $questionName = $questionName . $icon;
    }
    $mform->addGroup($questionarray, $number, $questionName, array(''), false);
    if ($warn) {
        $mform->setHelpButton($number, array('MarkWarning', get_string('MarkWarning', 'blended'), 'blended'), false);
    }
    /**
     * TODO resolver manejo de opciones inválidas
     * Enter description here ...
     * @var unknown_type
     */
    $invalid = 0;
    if ($invalid == 1) {
        $returnobj->invalid = 1;
        //$mform->addElement('hidden', 'invalid', $invalidquestions);
        mtrace('<CENTER>La pregunta número ' . $number . ' es inválida. Se han encontrado múltiples respuestas 
		para una pregunta de selección simple. <BR><BR></CENTER>');
    } else {
        $returnobj->invalid = null;
    }
    return $returnobj;
}
Exemplo n.º 3
0
/**
 * Adds a help button to the provided form for the provided field
 * 
 * @param  MoodleQuickForm  $mform        The form to add the help button to
 * @param  string           $elementname  The shortname of the element to add the help button to
 * @param  field            $field        The field corresponding to the input control
 */
function manual_field_add_help_button($mform, $elementname, $field)
{
    $manual = new field_owner($field->owners['manual']);
    if (!empty($manual->param_help_file)) {
        list($plugin, $filename) = explode('/', $manual->param_help_file, 2);
        $mform->setHelpButton($elementname, array($filename, $field->name, $plugin));
    }
}