/** * Add question-type specific form fields. * * @param MoodleQuickForm $mform the form being built. */ function definition_inner(&$mform) { $mform->addElement('header', 'globalvarshdr', get_string('globalvarshdr', 'qtype_coordinates')); $mform->removeElement('defaultgrade'); $mform->addElement('hidden', 'defaultgrade'); $mform->setType('defaultgrade', PARAM_RAW); $mform->removeElement('penalty'); $mform->addElement('hidden', 'penalty'); $mform->setType('penalty', PARAM_NUMBER); $mform->setDefault('penalty', 0.1); $mform->addElement('static', 'help_coordinates', get_string('help'), get_string('helponquestionoptions', 'qtype_coordinates')); $mform->addElement('textarea', 'varsrandom', get_string('varsrandom', 'qtype_coordinates'), array('rows' => 4, 'cols' => 70, 'course' => $this->coursefilesid)); $mform->addElement('textarea', 'varsglobal', get_string('varsglobal', 'qtype_coordinates'), array('rows' => 6, 'cols' => 70, 'course' => $this->coursefilesid)); $mform->addElement('select', 'showperanswermark', get_string('showperanswermark', 'qtype_coordinates'), array(get_string('choiceno', 'qtype_coordinates'), get_string('choiceyes', 'qtype_coordinates'))); $mform->setDefault('showperanswermark', 1); $mform->addElement('select', 'peranswersubmit', get_string('peranswersubmit', 'qtype_coordinates'), array(get_string('choiceno', 'qtype_coordinates'), get_string('choiceyes', 'qtype_coordinates'))); $mform->setDefault('peranswersubmit', 1); $mform->addElement('text', 'retrymarkseq', get_string('retrymarkseq', 'qtype_coordinates'), array('size' => 30)); $show_group = array(); $show_group[] =& $mform->createElement('checkbox', 'vars2', '', get_string('vars2', 'qtype_coordinates'), 'onclick="coordinates_form_display(\'vars2\', this.checked)"'); $show_group[] =& $mform->createElement('checkbox', 'preunit', '', get_string('preunit', 'qtype_coordinates'), 'onclick="coordinates_form_display(\'preunit\', this.checked)"'); $show_group[] =& $mform->createElement('checkbox', 'otherrule', '', get_string('otherrule', 'qtype_coordinates'), 'onclick="coordinates_form_display(\'otherrule\', this.checked)"'); //$show_group[] =& $mform->createElement('checkbox','subqtext','',get_string('subqtext','qtype_coordinates'), // 'onclick="coordinates_form_display(\'subqtext\', this.checked)"'); //$show_group[] =& $mform->createElement('checkbox','feedback','',get_string('feedback','qtype_coordinates'), // 'onclick="coordinates_form_display(\'feedback\', this.checked)"'); $show_group[] =& $mform->createElement('checkbox', 'correctnessraw', '', get_string('correctnessraw', 'qtype_coordinates'), 'onclick="coordinates_form_correctness(this.checked)"'); $mform->addGroup($show_group, 'showoptions', get_string('showoptions', 'qtype_coordinates'), array(' '), true); $creategrades = get_grade_options(); $this->add_per_answer_fields($mform, get_string('answerno', 'qtype_coordinates', '{no}'), $creategrades->gradeoptions, 1, 1); }
/** * The definition of the fields to use. * * @param MoodleQuickForm $mform */ protected function specific_definition($mform) { global $DB; // Load defaults. $blockconfig = get_config('block_activity_results'); // Fields for editing activity_results block title and contents. $mform->addElement('header', 'configheader', get_string('blocksettings', 'block')); // Get supported modules (Only modules using grades or scales will be listed). $sql = 'SELECT id, itemname FROM {grade_items} WHERE courseid = ? and itemtype = ? and (gradetype = ? or gradetype = ?)'; $params = array($this->page->course->id, 'mod', GRADE_TYPE_VALUE, GRADE_TYPE_SCALE); $activities = $DB->get_records_sql_menu($sql, $params); if (empty($activities)) { $mform->addElement('static', 'noactivitieswarning', get_string('config_select_activity', 'block_activity_results'), get_string('config_no_activities_in_course', 'block_activity_results')); } else { foreach ($activities as $id => $name) { $activities[$id] = strip_tags(format_string($name)); } $mform->addElement('select', 'config_activitygradeitemid', get_string('config_select_activity', 'block_activity_results'), $activities); $mform->setDefault('config_activitygradeitemid', $this->block->get_owning_activity()->id); } $mform->addElement('text', 'config_showbest', get_string('config_show_best', 'block_activity_results'), array('size' => 3)); $mform->setDefault('config_showbest', $blockconfig->config_showbest); $mform->setType('config_showbest', PARAM_INT); if ($blockconfig->config_showbest_locked) { $mform->freeze('config_showbest'); } $mform->addElement('text', 'config_showworst', get_string('config_show_worst', 'block_activity_results'), array('size' => 3)); $mform->setDefault('config_showworst', $blockconfig->config_showworst); $mform->setType('config_showworst', PARAM_INT); if ($blockconfig->config_showworst_locked) { $mform->freeze('config_showworst'); } $mform->addElement('selectyesno', 'config_usegroups', get_string('config_use_groups', 'block_activity_results')); $mform->setDefault('config_usegroups', $blockconfig->config_usegroups); if ($blockconfig->config_usegroups_locked) { $mform->freeze('config_usegroups'); } $nameoptions = array(B_ACTIVITYRESULTS_NAME_FORMAT_FULL => get_string('config_names_full', 'block_activity_results'), B_ACTIVITYRESULTS_NAME_FORMAT_ID => get_string('config_names_id', 'block_activity_results'), B_ACTIVITYRESULTS_NAME_FORMAT_ANON => get_string('config_names_anon', 'block_activity_results')); $mform->addElement('select', 'config_nameformat', get_string('config_name_format', 'block_activity_results'), $nameoptions); $mform->setDefault('config_nameformat', $blockconfig->config_nameformat); if ($blockconfig->config_nameformat_locked) { $mform->freeze('config_nameformat'); } $gradeeoptions = array(B_ACTIVITYRESULTS_GRADE_FORMAT_PCT => get_string('config_format_percentage', 'block_activity_results'), B_ACTIVITYRESULTS_GRADE_FORMAT_FRA => get_string('config_format_fraction', 'block_activity_results'), B_ACTIVITYRESULTS_GRADE_FORMAT_ABS => get_string('config_format_absolute', 'block_activity_results')); $mform->addElement('select', 'config_gradeformat', get_string('config_grade_format', 'block_activity_results'), $gradeeoptions); $mform->setDefault('config_gradeformat', $blockconfig->config_gradeformat); if ($blockconfig->config_gradeformat_locked) { $mform->freeze('config_gradeformat'); } $options = array(); for ($i = 0; $i <= 5; $i++) { $options[$i] = $i; } $mform->addElement('select', 'config_decimalpoints', get_string('config_decimalplaces', 'block_activity_results'), $options); $mform->setDefault('config_decimalpoints', $blockconfig->config_decimalpoints); $mform->setType('config_decimalpoints', PARAM_INT); if ($blockconfig->config_decimalpoints_locked) { $mform->freeze('config_decimalpoints'); } }
/** * Add question-type specific form fields. * * @param MoodleQuickForm $mform the form being built. */ function definition_inner(&$mform) { global $QTYPES; $this->qtypeobj =& $QTYPES[$this->qtype()]; $label = get_string("sharedwildcards", "qtype_datasetdependent"); $mform->addElement('hidden', 'initialcategory', 1); $html2 = $this->qtypeobj->print_dataset_definitions_category($this->question); $mform->insertElementBefore($mform->createElement('static', 'listcategory', $label, $html2), 'name'); $addfieldsname = 'updatecategory'; $addstring = get_string("updatecategory", "qtype_calculated"); $mform->registerNoSubmitButton($addfieldsname); $mform->insertElementBefore($mform->createElement('submit', $addfieldsname, $addstring), 'listcategory'); $repeated = array(); $repeated[] =& $mform->createElement('header', 'answerhdr', get_string('answerhdr', 'qtype_calculated', '{no}')); $repeated[] =& $mform->createElement('text', 'answers', get_string('correctanswerformula', 'quiz') . '=', array('size' => 50)); $repeatedoptions['answers']['type'] = PARAM_NOTAGS; $creategrades = get_grade_options(); $gradeoptions = $creategrades->gradeoptions; $repeated[] =& $mform->createElement('select', 'fraction', get_string('grade'), $gradeoptions); $repeatedoptions['fraction']['default'] = 0; $repeated[] =& $mform->createElement('text', 'tolerance', get_string('tolerance', 'qtype_calculated')); $repeatedoptions['tolerance']['type'] = PARAM_NUMBER; $repeatedoptions['tolerance']['default'] = 0.01; $repeated[] =& $mform->createElement('select', 'tolerancetype', get_string('tolerancetype', 'quiz'), $this->qtypeobj->tolerance_types()); $repeated[] =& $mform->createElement('select', 'correctanswerlength', get_string('correctanswershows', 'qtype_calculated'), range(0, 9)); $repeatedoptions['correctanswerlength']['default'] = 2; $answerlengthformats = array('1' => get_string('decimalformat', 'quiz'), '2' => get_string('significantfiguresformat', 'quiz')); $repeated[] =& $mform->createElement('select', 'correctanswerformat', get_string('correctanswershowsformat', 'qtype_calculated'), $answerlengthformats); $repeated[] =& $mform->createElement('htmleditor', 'feedback', get_string('feedback', 'quiz')); $repeatedoptions['feedback']['type'] = PARAM_RAW; if (isset($this->question->options)) { $count = count($this->question->options->answers); } else { $count = 0; } $repeatsatstart = $count + 1; $this->repeat_elements($repeated, $repeatsatstart, $repeatedoptions, 'noanswers', 'addanswers', 1, get_string('addmoreanswerblanks', 'qtype_calculated')); $repeated = array(); $repeated[] =& $mform->createElement('header', 'unithdr', get_string('unithdr', 'qtype_numerical', '{no}')); $repeated[] =& $mform->createElement('text', 'unit', get_string('unit', 'quiz')); $mform->setType('unit', PARAM_NOTAGS); $repeated[] =& $mform->createElement('text', 'multiplier', get_string('multiplier', 'quiz')); $mform->setType('multiplier', PARAM_NUMBER); if (isset($this->question->options)) { $countunits = count($this->question->options->units); } else { $countunits = 0; } $repeatsatstart = $countunits + 1; $this->repeat_elements($repeated, $repeatsatstart, array(), 'nounits', 'addunits', 2, get_string('addmoreunitblanks', 'qtype_calculated', '{no}')); $firstunit =& $mform->getElement('multiplier[0]'); $firstunit->freeze(); $firstunit->setValue('1.0'); $firstunit->setPersistantFreeze(true); //hidden elements $mform->addElement('hidden', 'wizard', 'datasetdefinitions'); $mform->setType('wizard', PARAM_ALPHA); }
/** * Add question-type specific form fields. * * @param MoodleQuickForm $mform the form being built. */ function definition_inner(&$mform) { $mform->addElement('editor', 'feedback', get_string('feedback', 'quiz'), null, $this->editoroptions); $mform->setType('feedback', PARAM_RAW); $mform->addElement('hidden', 'fraction', 0); $mform->setType('fraction', PARAM_RAW); //don't need this default element. $mform->removeElement('penalty'); $mform->addElement('hidden', 'penalty', 0); $mform->setType('penalty', PARAM_RAW); }
/** * Add question-type specific form fields. * * @param MoodleQuickForm $mform the form being built. */ function definition_inner(&$mform) { $mform->addElement('htmleditor', 'feedback', get_string("feedback", "quiz"), array('course' => $this->coursefilesid)); $mform->setType('feedback', PARAM_RAW); $mform->addElement('hidden', 'fraction', 0); $mform->setType('fraction', PARAM_RAW); //don't need this default element. $mform->removeElement('penalty'); $mform->addElement('hidden', 'penalty', 0); $mform->setType('penalty', PARAM_RAW); }
/** * Add question-type specific form fields. * * @param MoodleQuickForm $mform the form being built. */ function definition_inner(&$mform) { $questionstoselect = array(); for ($i = 2; $i <= QUESTION_NUMANS; $i++) { $questionstoselect[$i] = $i; } $mform->addElement('select', 'choose', get_string("randomsamatchnumber", "quiz"), $questionstoselect); $mform->setType('feedback', PARAM_RAW); $mform->addElement('hidden', 'fraction', 0); $mform->setType('fraction', PARAM_RAW); }
/** * Add question-type specific form fields. * * @param MoodleQuickForm $mform the form being built. */ function definition_inner(&$mform) { //------------------------------------------------------------------------------------------ $creategrades = get_grade_options(); $gradeoptions = $creategrades->gradeoptions; $repeated = array(); $repeatedoptions = array(); $repeated[] =& $mform->createElement('header', 'answerhdr', get_string('answerno', 'qtype_numerical', '{no}')); $repeated[] =& $mform->createElement('text', 'answer', get_string('answer', 'quiz')); $mform->setType('answer', PARAM_RAW); $repeated[] =& $mform->createElement('text', 'tolerance', get_string('acceptederror', 'quiz')); $mform->setType('tolerance', PARAM_NUMBER); $repeated[] =& $mform->createElement('select', 'fraction', get_string('grade'), $gradeoptions); $repeatedoptions['fraction']['default'] = 0; $repeated[] =& $mform->createElement('htmleditor', 'feedback', get_string('feedback', 'quiz'), array('course' => $this->coursefilesid)); $mform->setType('feedback', PARAM_RAW); if (isset($this->question->options)) { $countanswers = count($this->question->options->answers); } else { $countanswers = 0; } if ($this->question->formoptions->repeatelements) { $repeatsatstart = QUESTION_NUMANS_START > $countanswers + 1 ? QUESTION_NUMANS_START : $countanswers + 1; } else { $repeatsatstart = $countanswers; } $this->repeat_elements($repeated, $repeatsatstart, $repeatedoptions, 'noanswers', 'addanswers', 2, get_string('addmoreanswerblanks', 'qtype_numerical')); //------------------------------------------------------------------------------------------ $repeated = array(); $repeated[] =& $mform->createElement('header', 'unithdr', get_string('unithdr', 'qtype_numerical', '{no}')); $repeated[] =& $mform->createElement('text', 'unit', get_string('unit', 'quiz')); $mform->setType('unit', PARAM_NOTAGS); $repeated[] =& $mform->createElement('text', 'multiplier', get_string('multiplier', 'quiz')); $mform->setType('multiplier', PARAM_NUMBER); if (isset($this->question->options)) { $countunits = count($this->question->options->units); } else { $countunits = 0; } if ($this->question->formoptions->repeatelements) { $repeatsatstart = $countunits + 2; } else { $repeatsatstart = $countunits; } $this->repeat_elements($repeated, $repeatsatstart, array(), 'nounits', 'addunits', 2, get_string('addmoreunitblanks', 'qtype_numerical')); $firstunit =& $mform->getElement('multiplier[0]'); $firstunit->freeze(); $firstunit->setValue('1.0'); $firstunit->setPersistantFreeze(true); }
/** * Add question-type specific form fields. * * @param MoodleQuickForm $mform the form being built. */ protected function definition_inner($mform) { // We don't need this default element. $mform->removeElement('defaultmark'); $mform->addElement('hidden', 'defaultmark', 0); $mform->setType('defaultmark', PARAM_RAW); }
/** * Add question-type specific form fields. * * @param MoodleQuickForm $mform the form being built. */ function definition_inner(&$mform) { $menu = array(get_string('caseno', 'quiz'), get_string('caseyes', 'quiz')); $mform->addElement('select', 'usecase', get_string('casesensitive', 'quiz'), $menu); $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_shortanswer', '{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 = QUESTION_NUMANS_START > $countanswers + QUESTION_NUMANS_ADD ? QUESTION_NUMANS_START : $countanswers + 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', QUESTION_NUMANS_ADD, get_string('addmoreanswerblanks', 'qtype_shortanswer')); }
/** * Add question-type specific form fields. * * @param MoodleQuickForm $mform the form being built. */ function definition_inner(&$mform) { global $COURSE, $CFG; // don't need these default elements : $mform->removeElement('defaultgrade'); $mform->removeElement('penalty'); $mform->addElement('html', '<a target="_new" href="' . $CFG->wwwroot . '/files/index.php?id=' . $COURSE->id . '">' . get_string("openinnewwindow", "qtype_imagedit") . '</a>'); // this element will hold the URL of the HTML's IMG SRC value // of the altered image file that was uploaded by the user // to the current course's "users" folder //$mform->addElement('hidden', 'imgurl', ''); // add feedback $mform->addElement('htmleditor', 'feedback', get_string("feedback", "quiz")); $mform->setType('feedback', PARAM_RAW); // add default elements $mform->addElement('hidden', 'defaultgrade', 0); $mform->addElement('hidden', 'fraction', 0); // add max upload limit menu $choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes); $choices[0] = get_string('courseuploadlimit') . ' (' . display_size($COURSE->maxbytes) . ')'; $mform->addElement('select', 'maxbytes', get_string('maximumupload'), $choices); $mform->setDefault('maxbytes', $COURSE->maxbytes); // add essay area checkbox $mform->addElement('advcheckbox', 'essay', get_string('addessay', 'qtype_imagedit'), null, null, array(0, 1)); }
/** * The constructor function calls the abstract function definition() and it will then * process and clean and attempt to validate incoming data. * * It will call your custom validate method to validate data and will also check any rules * you have specified in definition using addRule * * The name of the form (id attribute of the form) is automatically generated depending on * the name you gave the class extending moodleform. You should call your class something * like * * @param mixed $action the action attribute for the form. If empty defaults to auto detect the * current url. If a moodle_url object then outputs params as hidden variables. * @param array $customdata if your form defintion method needs access to data such as $course * $cm, etc. to construct the form definition then pass it in this array. You can * use globals for somethings. * @param string $method if you set this to anything other than 'post' then _GET and _POST will * be merged and used as incoming data to the form. * @param string $target target frame for form submission. You will rarely use this. Don't use * it if you don't need to as the target attribute is deprecated in xhtml * strict. * @param mixed $attributes you can pass a string of html attributes here or an array. * @return moodleform */ function moodleform($action = null, $customdata = null, $method = 'post', $target = '', $attributes = null, $editable = true) { if (empty($action)) { $action = strip_querystring(qualified_me()); } $this->_formname = get_class($this); // '_form' suffix kept in order to prevent collisions of form id and other element $this->_customdata = $customdata; $this->_form =& new MoodleQuickForm($this->_formname, $method, $action, $target, $attributes); if (!$editable) { $this->_form->hardFreeze(); } $this->set_upload_manager(new upload_manager()); $this->definition(); $this->_form->addElement('hidden', 'sesskey', null); // automatic sesskey protection $this->_form->setType('sesskey', PARAM_RAW); $this->_form->setDefault('sesskey', sesskey()); $this->_form->addElement('hidden', '_qf__' . $this->_formname, null); // form submission marker $this->_form->setType('_qf__' . $this->_formname, PARAM_RAW); $this->_form->setDefault('_qf__' . $this->_formname, 1); $this->_form->_setDefaultRuleMessages(); // we have to know all input types before processing submission ;-) $this->_process_submission($method); }
/** * Add question-type specific form fields. * * @param MoodleQuickForm $mform the form being built. */ function definition_inner(&$mform) { //don't need these default elements : $mform->removeElement('defaultgrade'); $mform->removeElement('penalty'); $mform->addElement('hidden', 'defaultgrade', 0); $mform->setType('defaultgrade', PARAM_RAW); }
/** * Extends the standard instance config form with custom * fields for moodletxt specifically * @param MoodleQuickForm $form Form to extend * @version 2011072201 * @since 2011072201 */ protected function specific_definition($form) { // Section header title according to language file. $form->addElement('header', 'configheader', get_string('headerinstanceconfig', 'block_moodletxt')); // The title of the block $form->addElement('text', 'config_title', get_string('labelblocktitle', 'block_moodletxt')); $form->setDefault('config_title', get_string('blocktitle', 'block_moodletxt')); $form->setType('config_title', PARAM_MULTILANG); }
/** * Builds the form to edit instance settings * * @param MoodleQuickForm $mform */ protected function specific_definition($mform) { // Section header title according to language file. $mform->addElement('header', 'configheader', get_string('blocksettings', 'block')); // Set the title for the block. $mform->addElement('text', 'config_title', get_string('configtitle', 'block_filtered_course_list')); $mform->setDefault('config_title', get_string('blockname', 'block_filtered_course_list')); $mform->setType('config_title', PARAM_TEXT); }
/** * @param MoodleQuickForm $mform */ protected function specific_definition($mform) { // Section header title according to language file. $mform->addElement('header', 'configheader', get_string('blocksettings', 'block')); // A sample string variable with a default value. $mform->addElement('text', 'config_text', get_string('blockstring', 'block_simplehtml')); $mform->setDefault('config_text', 'default value'); $mform->setType('config_text', PARAM_RAW); }
protected function other_preference_fields(MoodleQuickForm $mform) { if (quiz_has_grades($this->_customdata['quiz'])) { $mform->addElement('selectyesno', 'slotmarks', get_string('showdetailedmarks', 'quiz_overview')); } else { $mform->addElement('hidden', 'slotmarks', 0); $mform->setType('slotmarks', PARAM_INT); } }
/** * Add question-type specific form fields. * * @param MoodleQuickForm $mform the form being built. */ protected function definition_inner($mform) { global $PAGE, $CFG; // We don't need those default element. $mform->removeElement('defaultmark'); $mform->addElement('hidden', 'defaultmark', 0); $mform->setType('defaultmark', PARAM_RAW); // $mform->removeElement('generalfeedback'); // $mform->addElement('hidden', 'generalfeedback'); // $mform->setType('generalfeedback', PARAM_RAW); $PAGE->requires->js('/question/type/programmedresp/script.js'); // Adding wwwroot required by script.js echo "<script type=\"text/javascript\">//<![CDATA[\n" . "this.wwwroot = '" . $CFG->wwwroot . "';\n" . "//]]></script>\n"; // TODO: Refacor // context id will be required on contents.php once it will called by AJAX (script.js) $mform->addElement('hidden', 'contextid', $PAGE->context->id); $mform->setType('contextid', PARAM_INT); $outputmanager = new prgrammedresp_output($mform); $editingjsparam = 'false'; // In a new question the vars div should be loaded if (!empty($this->question->id)) { $editingjsparam = 'true'; } // Button label if (!empty($this->question->id)) { $buttonlabel = get_string('refreshvarsvalues', 'qtype_programmedresp'); } else { $buttonlabel = get_string('assignvarsvalues', 'qtype_programmedresp'); } $varsattrs = array('onclick' => 'display_vars(this, ' . $editingjsparam . ');'); $mform->addElement('button', 'vars', $buttonlabel, $varsattrs); // Link to fill vars data $mform->addElement('header', 'varsheader', get_string("varsvalues", "qtype_programmedresp")); $mform->addElement('html', '<div id="id_vars_content">'); if (!empty($this->question->id)) { $outputmanager->display_vars($this->question->questiontext, false, $this->question->options->concatvars); } $mform->addElement('html', '</div>'); // TODO: review this requires. Maybe is not longer nedeed. if (empty($this->question->id)) { // Add the onload javascript to hide next steps $PAGE->requires->js('/question/type/programmedresp/onload.js'); } }
/** * @param MoodleQuickForm $mform */ protected function specific_definition($mform) { global $CFG; $mform->addElement('header', 'configheader', get_string('blocksettings', 'block')); $mods = array('enabledock' => 'yes'); $yesnooptions = array('yes' => get_string('yes'), 'no' => get_string('no')); foreach ($mods as $modname => $default) { $mform->addElement('select', 'config_' . $modname, get_string($modname . 'desc', $this->block->blockname), $yesnooptions); $mform->setDefault('config_' . $modname, $default); } $options = array(block_navigation::TRIM_RIGHT => get_string('trimmoderight', $this->block->blockname), block_navigation::TRIM_LEFT => get_string('trimmodeleft', $this->block->blockname), block_navigation::TRIM_CENTER => get_string('trimmodecenter', $this->block->blockname)); $mform->addElement('select', 'config_trimmode', get_string('trimmode', $this->block->blockname), $options); $mform->setType('config_trimmode', PARAM_INT); $mform->addElement('text', 'config_trimlength', get_string('trimlength', $this->block->blockname)); $mform->setDefault('config_trimlength', 50); $mform->setType('config_trimlength', PARAM_INT); $options = array(0 => get_string('everything', $this->block->blockname), global_navigation::TYPE_COURSE => get_string('courses', $this->block->blockname), global_navigation::TYPE_SECTION => get_string('coursestructures', $this->block->blockname), global_navigation::TYPE_ACTIVITY => get_string('courseactivities', $this->block->blockname)); $mform->addElement('select', 'config_expansionlimit', get_string('expansionlimit', $this->block->blockname), $options); $mform->setType('config_expansionlimit', PARAM_INT); }
/** * Creates form fields specific to this type of block. * * @param MoodleQuickForm $mform The pear quick form form being built. */ protected function specific_definition($mform) { // Create a fieldset with a legend $mform->addElement('header', 'config_header', get_string('blocksettings', 'block')); // Add an input text element to form $mform->addElement('text', 'config_title', get_string('inconfblocktitlelabel', 'block_openveo_videos')); // Add help button $mform->addHelpButton('config_title', 'inconfblocktitlelabel', 'block_openveo_videos'); // Set input text default value $mform->setDefault('config_title', get_string('inconfblocktitlelabel', 'block_openveo_videos')); // Clean title to plain text while submitting $mform->setType('config_title', PARAM_TEXT); }
/** * The definition of the fields to use. * * @param MoodleQuickForm $mform */ protected function specific_definition($mform) { $mform->addElement('header', 'configheader', get_string('blocksettings', 'block')); $numberofsections = array(); for ($i = 1; $i < 53; $i++) { $numberofsections[$i] = $i; } $increments = array(); for ($i = 1; $i < 11; $i++) { $increments[$i] = $i; } $config = get_config('block_section_links'); $selected = array(1 => array(22, 2), 2 => array(40, 5)); if (!empty($config->numsections1)) { if (empty($config->incby1)) { $config->incby1 = $selected[1][1]; } $selected[1] = array($config->numsections1, $config->incby1); } if (!empty($config->numsections2)) { if (empty($config->incby1)) { $config->incby1 = $selected[2][1]; } $selected[2] = array($config->numsections2, $config->incby2); } for ($i = 1; $i < 3; $i++) { $mform->addElement('select', 'config_numsections' . $i, get_string('numsections' . $i, 'block_section_links'), $numberofsections); $mform->setDefault('config_numsections' . $i, $selected[$i][0]); $mform->setType('config_numsections' . $i, PARAM_INT); $mform->addHelpButton('config_numsections' . $i, 'numsections' . $i, 'block_section_links'); $mform->addElement('select', 'config_incby' . $i, get_string('incby' . $i, 'block_section_links'), $increments); $mform->setDefault('config_incby' . $i, $selected[$i][1]); $mform->setType('config_incby' . $i, PARAM_INT); $mform->addHelpButton('config_incby' . $i, 'incby' . $i, 'block_section_links'); } }
/** * @param moodleform $combinedform * @param MoodleQuickForm $mform * @param $repeatenabled */ public function add_form_fragment(moodleform $combinedform, MoodleQuickForm $mform, $repeatenabled) { $mform->addElement('advcheckbox', $this->form_field_name('shuffleanswers'), get_string('shuffle', 'qtype_gapselect')); $answerel = array($mform->createElement('text', $this->form_field_name('answer'), get_string('choicex', 'qtype_gapselect'), array('size' => 57, 'class' => 'tweakcss'))); if ($this->questionrec !== null) { $countanswers = count($this->questionrec->options->answers); } else { $countanswers = 0; } if ($repeatenabled) { $defaultstartnumbers = QUESTION_NUMANS_START * 2; $repeatsatstart = max($defaultstartnumbers, $countanswers + QUESTION_NUMANS_ADD); } else { $repeatsatstart = $countanswers; } $combinedform->repeat_elements($answerel, $repeatsatstart, array(), $this->form_field_name('noofchoices'), $this->form_field_name('morechoices'), QUESTION_NUMANS_ADD, get_string('addmorechoiceblanks', 'qtype_gapselect'), true); $mform->setType($this->form_field_name('answer'), PARAM_RAW_TRIMMED); }
/** * Add question-type specific form fields. * * @param MoodleQuickForm $mform the form being built. */ function definition_inner(&$mform) { global $QTYPES; $this->qtypeobj =& $QTYPES[$this->qtype()]; $label = get_string("sharedwildcards", "qtype_datasetdependent"); $mform->addElement('hidden', 'initialcategory', 1); $mform->setType('initialcategory', PARAM_INT); $html2 = $this->qtypeobj->print_dataset_definitions_category($this->question); $mform->insertElementBefore($mform->createElement('static', 'listcategory', $label, $html2), 'name'); $addfieldsname = 'updatecategory'; $addstring = get_string("updatecategory", "qtype_calculated"); $mform->registerNoSubmitButton($addfieldsname); $mform->insertElementBefore($mform->createElement('submit', $addfieldsname, $addstring), 'listcategory'); $creategrades = get_grade_options(); $this->add_per_answer_fields($mform, get_string('answerhdr', 'qtype_calculated', '{no}'), $creategrades->gradeoptions, 1, 1); $repeated = array(); $repeated[] =& $mform->createElement('header', 'unithdr', get_string('unithdr', 'qtype_numerical', '{no}')); $repeated[] =& $mform->createElement('text', 'unit', get_string('unit', 'quiz')); $mform->setType('unit', PARAM_NOTAGS); $repeated[] =& $mform->createElement('text', 'multiplier', get_string('multiplier', 'quiz')); $mform->setType('multiplier', PARAM_NUMBER); if (isset($this->question->options)) { $countunits = count($this->question->options->units); } else { $countunits = 0; } if ($this->question->formoptions->repeatelements) { $repeatsatstart = $countunits + 1; } else { $repeatsatstart = $countunits; } $this->repeat_elements($repeated, $repeatsatstart, array(), 'nounits', 'addunits', 2, get_string('addmoreunitblanks', 'qtype_calculated', '{no}')); if ($mform->elementExists('multiplier[0]')) { $firstunit =& $mform->getElement('multiplier[0]'); $firstunit->freeze(); $firstunit->setValue('1.0'); $firstunit->setPersistantFreeze(true); } //hidden elements $mform->addElement('hidden', 'wizard', 'datasetdefinitions'); $mform->setType('wizard', PARAM_ALPHA); }
/** * Add question-type specific form fields. * * @param MoodleQuickForm $mform the form being built. */ function definition_inner(&$mform) { global $COURSE, $CFG; // don't need these default elements : $mform->removeElement('defaultgrade'); $mform->removeElement('penalty'); // add feedback $mform->addElement('htmleditor', 'feedback', get_string("feedback", "quiz")); $mform->setType('feedback', PARAM_RAW); // add default elements $mform->addElement('hidden', 'defaultgrade', 0); $mform->addElement('hidden', 'fraction', 0); // add max upload limit menu $choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes); $choices[0] = get_string('courseuploadlimit') . ' (' . display_size($COURSE->maxbytes) . ')'; $mform->addElement('select', 'maxbytes', get_string('maximumupload'), $choices); $mform->setDefault('maxbytes', $COURSE->maxbytes); // add essay area checkbox $mform->addElement('advcheckbox', 'essay', get_string('addessay', 'qtype_fileresponse'), null, null, array(0, 1)); }
/** * Add filter form element * * @param MoodleQuickForm $mform Filter form * @return mr_html_filter_abstract */ public function add_element($mform) { //add div and empty unordered list to the form $ieshim = '<div class="selectmultiplus-ieshim">.</div>'; $mform->addElement('static', $this->name . '_addedlist', $ieshim, '<div id="id_' . $this->name . '_addedlist" class="selectmultiplus"></div>'); // Add the select element setting multiple $mform->addElement('select', $this->name, $this->label, $this->options, 'class="selectmultiplus"')->setMultiple(true); // set the defaults if ($defaults = $this->preferences_get($this->name)) { $mform->setDefault($this->name, explode(',', $defaults)); } if ($this->advanced) { $mform->setAdvanced($this->name); } // add the input field for autocomplete $mform->addElement('text', $this->name . '_autocomplete', $this->label, 'class="selectmultiplus"'); $mform->setType($this->name . '_autocomplete', PARAM_TEXT); // initialize the javascript $helper = new mr_helper(); $helper->html->filter_selectmultiplus_init($this->name); return $this; }
/** * Get the settings for onlinetext submission plugin * * @param MoodleQuickForm $mform The form to add elements to * @return void */ public function get_settings(MoodleQuickForm $mform) { global $CFG, $COURSE; $defaultwordlimit = $this->get_config('wordlimit') == 0 ? '' : $this->get_config('wordlimit'); $defaultwordlimitenabled = $this->get_config('wordlimitenabled'); $options = array('size' => '6', 'maxlength' => '6'); $name = get_string('wordlimit', 'assignsubmission_onlinetext'); // Create a text box that can be enabled/disabled for onlinetext word limit. $wordlimitgrp = array(); $wordlimitgrp[] = $mform->createElement('text', 'assignsubmission_onlinetext_wordlimit', '', $options); $wordlimitgrp[] = $mform->createElement('checkbox', 'assignsubmission_onlinetext_wordlimit_enabled', '', get_string('enable')); $mform->addGroup($wordlimitgrp, 'assignsubmission_onlinetext_wordlimit_group', $name, ' ', false); $mform->addHelpButton('assignsubmission_onlinetext_wordlimit_group', 'wordlimit', 'assignsubmission_onlinetext'); $mform->disabledIf('assignsubmission_onlinetext_wordlimit', 'assignsubmission_onlinetext_wordlimit_enabled', 'notchecked'); // Add numeric rule to text field. $wordlimitgrprules = array(); $wordlimitgrprules['assignsubmission_onlinetext_wordlimit'][] = array(null, 'numeric', null, 'client'); $mform->addGroupRule('assignsubmission_onlinetext_wordlimit_group', $wordlimitgrprules); // Rest of group setup. $mform->setDefault('assignsubmission_onlinetext_wordlimit', $defaultwordlimit); $mform->setDefault('assignsubmission_onlinetext_wordlimit_enabled', $defaultwordlimitenabled); $mform->setType('assignsubmission_onlinetext_wordlimit', PARAM_INT); $mform->disabledIf('assignsubmission_onlinetext_wordlimit_group', 'assignsubmission_onlinetext_enabled', 'notchecked'); }
/** * Adds format options elements to the course/section edit form * * This function is called from {@link course_edit_form::definition_after_data()} * * @param MoodleQuickForm $mform form the elements are added to * @param bool $forsection 'true' if this is a section edit form, 'false' if this is course edit form * @return array array of references to the added form elements */ public function create_edit_form_elements(&$mform, $forsection = false) { $elements = array(); if ($forsection) { $options = $this->section_format_options(true); } else { $options = $this->course_format_options(true); } foreach ($options as $optionname => $option) { if (!isset($option['element_type'])) { $option['element_type'] = 'text'; } $args = array($option['element_type'], $optionname, $option['label']); if (!empty($option['element_attributes'])) { $args = array_merge($args, $option['element_attributes']); } $elements[] = call_user_func_array(array($mform, 'addElement'), $args); if (isset($option['help'])) { $helpcomponent = 'format_' . $this->get_format(); if (isset($option['help_component'])) { $helpcomponent = $option['help_component']; } $mform->addHelpButton($optionname, $option['help'], $helpcomponent); } if (isset($option['type'])) { $mform->setType($optionname, $option['type']); } if (is_null($mform->getElementValue($optionname)) && isset($option['default'])) { $mform->setDefault($optionname, $option['default']); } } if (!$forsection && empty($this->courseid)) { // At this stage (this is called from definition_after_data) course data is already set as default. // We can not overwrite what is in the database. $mform->setDefault('enddate', $this->get_default_course_enddate($mform)); } return $elements; }
/** * Add elements to the edit instance form. * * @param stdClass $instance * @param MoodleQuickForm $mform * @param context $context * @return bool */ public function edit_instance_form($instance, MoodleQuickForm $mform, $context) { global $CFG; // Merge these two settings to one value for the single selection element. if ($instance->notifyall and $instance->expirynotify) { $instance->expirynotify = 2; } unset($instance->notifyall); $nameattribs = array('size' => '20', 'maxlength' => '255'); $mform->addElement('text', 'name', get_string('custominstancename', 'enrol'), $nameattribs); $mform->setType('name', PARAM_TEXT); $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'server'); $options = $this->get_status_options(); $mform->addElement('select', 'status', get_string('status', 'enrol_self'), $options); $mform->addHelpButton('status', 'status', 'enrol_self'); $options = $this->get_newenrols_options(); $mform->addElement('select', 'customint6', get_string('newenrols', 'enrol_self'), $options); $mform->addHelpButton('customint6', 'newenrols', 'enrol_self'); $mform->disabledIf('customint6', 'status', 'eq', ENROL_INSTANCE_DISABLED); $passattribs = array('size' => '20', 'maxlength' => '50'); $mform->addElement('passwordunmask', 'password', get_string('password', 'enrol_self'), $passattribs); $mform->addHelpButton('password', 'password', 'enrol_self'); if (empty($instance->id) and $this->get_config('requirepassword')) { $mform->addRule('password', get_string('required'), 'required', null, 'client'); } $mform->addRule('password', get_string('maximumchars', '', 50), 'maxlength', 50, 'server'); $options = $this->get_groupkey_options(); $mform->addElement('select', 'customint1', get_string('groupkey', 'enrol_self'), $options); $mform->addHelpButton('customint1', 'groupkey', 'enrol_self'); $roles = $this->extend_assignable_roles($context, $instance->roleid); $mform->addElement('select', 'roleid', get_string('role', 'enrol_self'), $roles); $options = array('optional' => true, 'defaultunit' => 86400); $mform->addElement('duration', 'enrolperiod', get_string('enrolperiod', 'enrol_self'), $options); $mform->addHelpButton('enrolperiod', 'enrolperiod', 'enrol_self'); $options = $this->get_expirynotify_options(); $mform->addElement('select', 'expirynotify', get_string('expirynotify', 'core_enrol'), $options); $mform->addHelpButton('expirynotify', 'expirynotify', 'core_enrol'); $options = array('optional' => false, 'defaultunit' => 86400); $mform->addElement('duration', 'expirythreshold', get_string('expirythreshold', 'core_enrol'), $options); $mform->addHelpButton('expirythreshold', 'expirythreshold', 'core_enrol'); $mform->disabledIf('expirythreshold', 'expirynotify', 'eq', 0); $options = array('optional' => true); $mform->addElement('date_time_selector', 'enrolstartdate', get_string('enrolstartdate', 'enrol_self'), $options); $mform->setDefault('enrolstartdate', 0); $mform->addHelpButton('enrolstartdate', 'enrolstartdate', 'enrol_self'); $options = array('optional' => true); $mform->addElement('date_time_selector', 'enrolenddate', get_string('enrolenddate', 'enrol_self'), $options); $mform->setDefault('enrolenddate', 0); $mform->addHelpButton('enrolenddate', 'enrolenddate', 'enrol_self'); $options = $this->get_longtimenosee_options(); $mform->addElement('select', 'customint2', get_string('longtimenosee', 'enrol_self'), $options); $mform->addHelpButton('customint2', 'longtimenosee', 'enrol_self'); $mform->addElement('text', 'customint3', get_string('maxenrolled', 'enrol_self')); $mform->addHelpButton('customint3', 'maxenrolled', 'enrol_self'); $mform->setType('customint3', PARAM_INT); require_once $CFG->dirroot . '/cohort/lib.php'; $cohorts = array(0 => get_string('no')); $allcohorts = cohort_get_available_cohorts($context, 0, 0, 0); if ($instance->customint5 && !isset($allcohorts[$instance->customint5])) { $c = $DB->get_record('cohort', array('id' => $instance->customint5), 'id, name, idnumber, contextid, visible', IGNORE_MISSING); if ($c) { // Current cohort was not found because current user can not see it. Still keep it. $allcohorts[$instance->customint5] = $c; } } foreach ($allcohorts as $c) { $cohorts[$c->id] = format_string($c->name, true, array('context' => context::instance_by_id($c->contextid))); if ($c->idnumber) { $cohorts[$c->id] .= ' [' . s($c->idnumber) . ']'; } } if ($instance->customint5 && !isset($allcohorts[$instance->customint5])) { // Somebody deleted a cohort, better keep the wrong value so that random ppl can not enrol. $cohorts[$instance->customint5] = get_string('unknowncohort', 'cohort', $instance->customint5); } if (count($cohorts) > 1) { $mform->addElement('select', 'customint5', get_string('cohortonly', 'enrol_self'), $cohorts); $mform->addHelpButton('customint5', 'cohortonly', 'enrol_self'); } else { $mform->addElement('hidden', 'customint5'); $mform->setType('customint5', PARAM_INT); $mform->setConstant('customint5', 0); } $mform->addElement('advcheckbox', 'customint4', get_string('sendcoursewelcomemessage', 'enrol_self')); $mform->addHelpButton('customint4', 'sendcoursewelcomemessage', 'enrol_self'); $options = array('cols' => '60', 'rows' => '8'); $mform->addElement('textarea', 'customtext1', get_string('customwelcomemessage', 'enrol_self'), $options); $mform->addHelpButton('customtext1', 'customwelcomemessage', 'enrol_self'); if (enrol_accessing_via_instance($instance)) { $warntext = get_string('instanceeditselfwarningtext', 'core_enrol'); $mform->addElement('static', 'selfwarn', get_string('instanceeditselfwarning', 'core_enrol'), $warntext); } }
/** * Add question-type specific form fields. * * @param MoodleQuickForm $mform the form being built. */ function definition_inner(&$mform) { global $QTYPES; $this->qtypeobj =& $QTYPES[$this->qtype()]; // echo code left for testing period // echo "<p>question ".optional_param('multichoice', '', PARAM_RAW)." optional<pre>";print_r($this->question);echo "</pre></p>"; $label = get_string("sharedwildcards", "qtype_calculated"); $mform->addElement('hidden', 'initialcategory', 1); $mform->addElement('hidden', 'reload', 1); $mform->setType('initialcategory', PARAM_INT); // $html2 = $this->qtypeobj->print_dataset_definitions_category($this->question); $html2 = ""; $mform->insertElementBefore($mform->createElement('static', 'listcategory', $label, $html2), 'name'); if (isset($this->question->id)) { $mform->insertElementBefore($mform->createElement('static', 'initialname', get_string('questionstoredname', 'qtype_calculated'), $this->initialname), 'name'); } $addfieldsname = 'updatecategory'; $addstring = get_string("updatecategory", "qtype_calculated"); $mform->registerNoSubmitButton($addfieldsname); $this->editasmultichoice = 1; $mform->insertElementBefore($mform->createElement('submit', $addfieldsname, $addstring), 'listcategory'); $mform->registerNoSubmitButton('createoptionbutton'); $mform->addElement('hidden', 'multichoice', $this->editasmultichoice); $mform->setType('multichoice', PARAM_INT); // $mform->addElement('header', 'choicehdr',get_string('multichoicecalculatedquestion', 'qtype_calculated')); $menu = array(get_string('answersingleno', 'qtype_multichoice'), get_string('answersingleyes', 'qtype_multichoice')); $mform->addElement('select', 'single', get_string('answerhowmany', 'qtype_multichoice'), $menu); $mform->setDefault('single', 1); $mform->addElement('advcheckbox', 'shuffleanswers', get_string('shuffleanswers', 'qtype_multichoice'), null, null, array(0, 1)); $mform->addHelpButton('shuffleanswers', 'shuffleanswers', 'qtype_multichoice'); $mform->setDefault('shuffleanswers', 1); $numberingoptions = $QTYPES['multichoice']->get_numbering_styles(); $menu = array(); foreach ($numberingoptions as $numberingoption) { $menu[$numberingoption] = get_string('answernumbering' . $numberingoption, 'qtype_multichoice'); } $mform->addElement('select', 'answernumbering', get_string('answernumbering', 'qtype_multichoice'), $menu); $mform->setDefault('answernumbering', 'abc'); $creategrades = get_grade_options(); $this->add_per_answer_fields($mform, get_string('choiceno', 'qtype_multichoice', '{no}'), $creategrades->gradeoptionsfull, max(5, QUESTION_NUMANS_START)); $repeated = array(); // if ($this->editasmultichoice == 1){ $nounits = optional_param('nounits', 1, PARAM_INT); $mform->addElement('hidden', 'nounits', $nounits); $mform->setType('nounits', PARAM_INT); $mform->setConstants(array('nounits' => $nounits)); for ($i = 0; $i < $nounits; $i++) { $mform->addElement('hidden', 'unit' . "[{$i}]", optional_param('unit' . "[{$i}]", '', PARAM_NOTAGS)); $mform->setType('unit' . "[{$i}]", PARAM_NOTAGS); $mform->addElement('hidden', 'multiplier' . "[{$i}]", optional_param('multiplier' . "[{$i}]", '', PARAM_NUMBER)); $mform->setType('multiplier' . "[{$i}]", PARAM_NUMBER); } $mform->setType('addunits', 'hidden'); $mform->addElement('header', 'overallfeedbackhdr', get_string('overallfeedback', 'qtype_multichoice')); foreach (array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback') as $feedbackname) { $mform->addElement('editor', $feedbackname, get_string($feedbackname, 'qtype_multichoice'), null, $this->editoroptions); $mform->setType($feedbackname, PARAM_RAW); } //hidden elements $mform->addElement('hidden', 'synchronize', ''); $mform->setType('synchronize', PARAM_INT); if (isset($this->question->options) && isset($this->question->options->synchronize)) { $mform->setDefault("synchronize", $this->question->options->synchronize); } else { $mform->setDefault("synchronize", 0); } $mform->addElement('hidden', 'wizard', 'datasetdefinitions'); $mform->setType('wizard', PARAM_ALPHA); }
/** * Add question-type specific form fields. * * @param MoodleQuickForm $mform the form being built. */ protected function definition_inner($mform) { $strquestionlabel = $this->qtypeobj->comment_header($this->nonemptyanswer); $label = get_string("sharedwildcards", "qtype_calculated"); $mform->addElement('hidden', 'synchronize', 0); $mform->addElement('hidden', 'initialcategory', 1); $mform->setType('synchronize', PARAM_BOOL); $mform->setType('initialcategory', PARAM_INT); $mform->addElement('hidden', 'reload', 1); $mform->setType('reload', PARAM_INT); $addfieldsname = 'updatequestion value'; $addstring = get_string("updatecategory", "qtype_calculated"); $mform->registerNoSubmitButton($addfieldsname); $this->add_per_answer_fields($mform, get_string('answerhdr', 'qtype_calculated', '{no}'), question_bank::fraction_options(), 1, 1); $this->add_unit_options($mform, $this); $this->add_unit_fields($mform, $this); $this->add_interactive_settings(); $label = "<div class='mdl-align'></div><div class='mdl-align'>" . get_string('wildcardrole', 'qtype_calculatedsimple') . "</div>"; $mform->addElement('html', "<div class='mdl-align'> </div>"); // Explaining the role of datasets so other strings can be shortened. $mform->addElement('html', $label); $mform->addElement('submit', 'analyzequestion', get_string('findwildcards', 'qtype_calculatedsimple')); $mform->registerNoSubmitButton('analyzequestion'); $mform->closeHeaderBefore('analyzequestion'); $this->wizarddisplay = optional_param('analyzequestion', false, PARAM_BOOL); if ($this->maxnumber != -1) { $this->noofitems = $this->maxnumber; } else { $this->noofitems = 0; } if (!empty($this->datasetdefs)) { // So there are some datadefs. // We put them on the page. $key = 0; $mform->addElement('header', 'additemhdr', get_string('wildcardparam', 'qtype_calculatedsimple')); $idx = 1; if (!empty($this->datasetdefs)) { // Unnecessary test. $j = $this->noofitems * count($this->datasetdefs) + 1; // foreach ($this->datasetdefs as $defkey => $datasetdef) { $mform->addElement('static', "na[{$j}]", get_string('param', 'qtype_calculated', $datasetdef->name)); $this->qtypeobj->custom_generator_tools_part($mform, $idx, $j); $mform->addElement('hidden', "datasetdef[{$idx}]"); $mform->setType("datasetdef[{$idx}]", PARAM_RAW); $mform->addElement('hidden', "defoptions[{$idx}]"); $mform->setType("defoptions[{$idx}]", PARAM_RAW); $idx++; $mform->addElement('static', "divider[{$j}]", '', '<hr />'); $j++; } } // This should be done before the elements are created and stored as $this->formdata. // Fill out all data sets and also the fields for the next item to add. /*Here we do already the values error analysis so that * we could force all wild cards values display if there is an error in values. * as using a , in a number */ $this->numbererrors = array(); if (!empty($this->datasetdefs)) { $j = $this->noofitems * count($this->datasetdefs); for ($itemnumber = $this->noofitems; $itemnumber >= 1; $itemnumber--) { $data = array(); $numbererrors = array(); $comment = new stdClass(); $comment->stranswers = array(); $comment->outsidelimit = false; $comment->answers = array(); foreach ($this->datasetdefs as $defid => $datasetdef) { if (isset($datasetdef->items[$itemnumber])) { $this->formdata["definition[{$j}]"] = $defid; $this->formdata["itemid[{$j}]"] = $datasetdef->items[$itemnumber]->id; $data[$datasetdef->name] = $datasetdef->items[$itemnumber]->value; $this->formdata["number[{$j}]"] = $number = $datasetdef->items[$itemnumber]->value; if (!is_numeric($number)) { $a = new stdClass(); $a->name = '{' . $datasetdef->name . '}'; $a->value = $datasetdef->items[$itemnumber]->value; if (stristr($number, ',')) { $this->numbererrors["number[{$j}]"] = get_string('nocommaallowed', 'qtype_calculated'); $numbererrors .= $this->numbererrors['number[' . $j . ']'] . "<br />"; } else { $this->numbererrors["number[{$j}]"] = get_string('notvalidnumber', 'qtype_calculated', $a); $numbererrors .= $this->numbererrors['number[' . $j . ']'] . "<br />"; } } else { if (stristr($number, 'x')) { // Hexa will pass the test. $a = new stdClass(); $a->name = '{' . $datasetdef->name . '}'; $a->value = $datasetdef->items[$itemnumber]->value; $this->numbererrors['number[' . $j . ']'] = get_string('hexanotallowed', 'qtype_calculated', $a); $numbererrors .= $this->numbererrors['number[' . $j . ']'] . "<br />"; } else { if (is_nan($number)) { $a = new stdClass(); $a->name = '{' . $datasetdef->name . '}'; $a->value = $datasetdef->items[$itemnumber]->value; $this->numbererrors["number[{$j}]"] = get_string('notvalidnumber', 'qtype_calculated', $a); $numbererrors .= $this->numbererrors['number[' . $j . ']'] . "<br />"; } } } } $j--; } if ($this->noofitems != 0) { if (empty($numbererrors)) { if (!isset($this->question->id)) { $this->question->id = 0; } $this->question->questiontext = !empty($this->question->questiontext) ? $this->question->questiontext : ''; $comment = $this->qtypeobj->comment_on_datasetitems($this->qtypeobj, $this->question->id, $this->question->questiontext, $this->nonemptyanswer, $data, $itemnumber); if ($comment->outsidelimit) { $this->outsidelimit = $comment->outsidelimit; } $totalcomment = ''; foreach ($this->nonemptyanswer as $key => $answer) { $totalcomment .= $comment->stranswers[$key] . '<br/>'; } $this->formdata['answercomment[' . $itemnumber . ']'] = $totalcomment; } } } $this->formdata['selectdelete'] = '1'; $this->formdata['selectadd'] = '1'; $j = $this->noofitems * count($this->datasetdefs) + 1; $data = array(); // Data for comment_on_datasetitems later. $idx = 1; foreach ($this->datasetdefs as $defid => $datasetdef) { $this->formdata["datasetdef[{$idx}]"] = $defid; $idx++; } $this->formdata = $this->qtypeobj->custom_generator_set_data($this->datasetdefs, $this->formdata); } $addoptions = array(); $addoptions['1'] = '1'; for ($i = 10; $i <= 100; $i += 10) { $addoptions["{$i}"] = "{$i}"; } $showoptions = array(); $showoptions['1'] = '1'; $showoptions['2'] = '2'; $showoptions['5'] = '5'; for ($i = 10; $i <= 100; $i += 10) { $showoptions["{$i}"] = "{$i}"; } $mform->closeHeaderBefore('additemhdr'); $addgrp = array(); $addgrp[] = $mform->createElement('submit', 'addbutton', get_string('generatenewitemsset', 'qtype_calculatedsimple')); $addgrp[] = $mform->createElement('select', "selectadd", '', $addoptions); $addgrp[] = $mform->createElement('static', "stat", '', get_string('newsetwildcardvalues', 'qtype_calculatedsimple')); $mform->addGroup($addgrp, 'addgrp', '', ' ', false); $mform->registerNoSubmitButton('addbutton'); $mform->closeHeaderBefore('addgrp'); $addgrp1 = array(); $addgrp1[] = $mform->createElement('submit', 'showbutton', get_string('showitems', 'qtype_calculatedsimple')); $addgrp1[] = $mform->createElement('select', "selectshow", '', $showoptions); $addgrp1[] = $mform->createElement('static', "stat", '', get_string('setwildcardvalues', 'qtype_calculatedsimple')); $mform->addGroup($addgrp1, 'addgrp1', '', ' ', false); $mform->registerNoSubmitButton('showbutton'); $mform->closeHeaderBefore('addgrp1'); $mform->addElement('static', "divideradd", '', ''); if ($this->noofitems == 0) { $mform->addElement('static', 'warningnoitems', '', '<span class="error">' . get_string('youmustaddatleastonevalue', 'qtype_calculatedsimple') . '</span>'); $mform->closeHeaderBefore('warningnoitems'); } else { $mform->addElement('header', 'additemhdr1', get_string('wildcardvalues', 'qtype_calculatedsimple')); $mform->closeHeaderBefore('additemhdr1'); if (!empty($this->numbererrors) || $this->outsidelimit) { $mform->addElement('static', "alert", '', '<span class="error">' . get_string('useadvance', 'qtype_calculatedsimple') . '</span>'); } $mform->addElement('submit', 'updatedatasets', get_string('updatewildcardvalues', 'qtype_calculatedsimple')); $mform->registerNoSubmitButton('updatedatasets'); $mform->setAdvanced("updatedatasets", true); // ...--------------------------------------------------------------. $j = $this->noofitems * count($this->datasetdefs); $k = optional_param('selectshow', 1, PARAM_INT); for ($i = $this->noofitems; $i >= 1; $i--) { foreach ($this->datasetdefs as $defkey => $datasetdef) { if ($k > 0 || $this->outsidelimit || !empty($this->numbererrors)) { $mform->addElement('text', "number[{$j}]", get_string('wildcard', 'qtype_calculatedsimple', $datasetdef->name)); $mform->setAdvanced("number[{$j}]", true); if (!empty($this->numbererrors['number[' . $j . ']'])) { $mform->addElement('static', "numbercomment[{$j}]", '', '<span class="error">' . $this->numbererrors['number[' . $j . ']'] . '</span>'); $mform->setAdvanced("numbercomment[{$j}]", true); } } else { $mform->addElement('hidden', "number[{$j}]", get_string('wildcard', 'qtype_calculatedsimple', $datasetdef->name)); } $mform->setType("number[{$j}]", PARAM_RAW); // This parameter will be validated in validation(). $mform->addElement('hidden', "itemid[{$j}]"); $mform->setType("itemid[{$j}]", PARAM_INT); $mform->addElement('hidden', "definition[{$j}]"); $mform->setType("definition[{$j}]", PARAM_NOTAGS); $j--; } if (!empty($strquestionlabel) && ($k > 0 || $this->outsidelimit || !empty($this->numbererrors))) { $mform->addElement('static', "answercomment[{$i}]", "<b>" . get_string('setno', 'qtype_calculatedsimple', $i) . "</b> " . $strquestionlabel); } if ($k > 0 || $this->outsidelimit || !empty($this->numbererrors)) { $mform->addElement('static', "divider1[{$j}]", '', '<hr />'); } $k--; } } } else { $mform->addElement('static', 'warningnowildcards', '', '<span class="error">' . get_string('atleastonewildcard', 'qtype_calculatedsimple') . '</span>'); $mform->closeHeaderBefore('warningnowildcards'); } // ...----------------------------------------------------------------------. // Non standard name for button element needed so not using add_action_buttons. // Hidden elements. $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'courseid'); $mform->setType('courseid', PARAM_INT); $mform->setDefault('courseid', 0); $mform->addElement('hidden', 'cmid'); $mform->setType('cmid', PARAM_INT); $mform->setDefault('cmid', 0); if (!empty($this->question->id)) { if ($this->question->formoptions->cansaveasnew) { $mform->addElement('header', 'additemhdr', get_string('converttocalculated', 'qtype_calculatedsimple')); $mform->closeHeaderBefore('additemhdr'); $mform->addElement('checkbox', 'convert', '', get_string('willconverttocalculated', 'qtype_calculatedsimple')); $mform->setDefault('convert', 0); } } }
/** * Add elements to grade form. * * @param MoodleQuickForm $mform * @param stdClass $data * @param array $params * @return void */ public function add_grade_form_elements(MoodleQuickForm $mform, stdClass $data, $params) { global $USER, $CFG; $settings = $this->get_instance(); $rownum = $params['rownum']; $last = $params['last']; $useridlistid = $params['useridlistid']; $userid = $params['userid']; $attemptnumber = $params['attemptnumber']; if (!$userid) { $cache = cache::make_from_params(cache_store::MODE_SESSION, 'mod_assign', 'useridlist'); if (!($useridlist = $cache->get($this->get_course_module()->id . '_' . $useridlistid))) { $useridlist = $this->get_grading_userid_list(); $cache->set($this->get_course_module()->id . '_' . $useridlistid, $useridlist); } } else { $useridlist = array($userid); $rownum = 0; $useridlistid = ''; } $userid = $useridlist[$rownum]; $grade = $this->get_user_grade($userid, false, $attemptnumber); $submission = null; if ($this->get_instance()->teamsubmission) { $submission = $this->get_group_submission($userid, 0, false, $attemptnumber); } else { $submission = $this->get_user_submission($userid, false, $attemptnumber); } // Add advanced grading. $gradingdisabled = $this->grading_disabled($userid); $gradinginstance = $this->get_grading_instance($userid, $grade, $gradingdisabled); $mform->addElement('header', 'gradeheader', get_string('grade')); if ($gradinginstance) { $gradingelement = $mform->addElement('grading', 'advancedgrading', get_string('grade') . ':', array('gradinginstance' => $gradinginstance)); if ($gradingdisabled) { $gradingelement->freeze(); } else { $mform->addElement('hidden', 'advancedgradinginstanceid', $gradinginstance->get_id()); $mform->setType('advancedgradinginstanceid', PARAM_INT); } } else { // Use simple direct grading. if ($this->get_instance()->grade > 0) { $name = get_string('gradeoutof', 'assign', $this->get_instance()->grade); if (!$gradingdisabled) { $gradingelement = $mform->addElement('text', 'grade', $name); $mform->addHelpButton('grade', 'gradeoutofhelp', 'assign'); $mform->setType('grade', PARAM_RAW); } else { $mform->addElement('hidden', 'grade', $name); $mform->hardFreeze('grade'); $mform->setType('grade', PARAM_RAW); $strgradelocked = get_string('gradelocked', 'assign'); $mform->addElement('static', 'gradedisabled', $name, $strgradelocked); $mform->addHelpButton('gradedisabled', 'gradeoutofhelp', 'assign'); } } else { $grademenu = array(-1 => get_string("nograde")) + make_grades_menu($this->get_instance()->grade); if (count($grademenu) > 1) { $gradingelement = $mform->addElement('select', 'grade', get_string('grade') . ':', $grademenu); // The grade is already formatted with format_float so it needs to be converted back to an integer. if (!empty($data->grade)) { $data->grade = (int) unformat_float($data->grade); } $mform->setType('grade', PARAM_INT); if ($gradingdisabled) { $gradingelement->freeze(); } } } } $gradinginfo = grade_get_grades($this->get_course()->id, 'mod', 'assign', $this->get_instance()->id, $userid); if (!empty($CFG->enableoutcomes)) { foreach ($gradinginfo->outcomes as $index => $outcome) { $options = make_grades_menu(-$outcome->scaleid); if ($outcome->grades[$userid]->locked) { $options[0] = get_string('nooutcome', 'grades'); $mform->addElement('static', 'outcome_' . $index . '[' . $userid . ']', $outcome->name . ':', $options[$outcome->grades[$userid]->grade]); } else { $options[''] = get_string('nooutcome', 'grades'); $attributes = array('id' => 'menuoutcome_' . $index); $mform->addElement('select', 'outcome_' . $index . '[' . $userid . ']', $outcome->name . ':', $options, $attributes); $mform->setType('outcome_' . $index . '[' . $userid . ']', PARAM_INT); $mform->setDefault('outcome_' . $index . '[' . $userid . ']', $outcome->grades[$userid]->grade); } } } $capabilitylist = array('gradereport/grader:view', 'moodle/grade:viewall'); if (has_all_capabilities($capabilitylist, $this->get_course_context())) { $urlparams = array('id' => $this->get_course()->id); $url = new moodle_url('/grade/report/grader/index.php', $urlparams); $usergrade = '-'; if (isset($gradinginfo->items[0]->grades[$userid]->str_grade)) { $usergrade = $gradinginfo->items[0]->grades[$userid]->str_grade; } $gradestring = $this->get_renderer()->action_link($url, $usergrade); } else { $usergrade = '-'; if (isset($gradinginfo->items[0]->grades[$userid]) && !$gradinginfo->items[0]->grades[$userid]->hidden) { $usergrade = $gradinginfo->items[0]->grades[$userid]->str_grade; } $gradestring = $usergrade; } if ($this->get_instance()->markingworkflow) { $states = $this->get_marking_workflow_states_for_current_user(); $options = array('' => get_string('markingworkflowstatenotmarked', 'assign')) + $states; $mform->addElement('select', 'workflowstate', get_string('markingworkflowstate', 'assign'), $options); $mform->addHelpButton('workflowstate', 'markingworkflowstate', 'assign'); } if ($this->get_instance()->markingallocation && has_capability('mod/assign:manageallocations', $this->context)) { $markers = get_users_by_capability($this->context, 'mod/assign:grade'); $markerlist = array('' => get_string('choosemarker', 'assign')); foreach ($markers as $marker) { $markerlist[$marker->id] = fullname($marker); } $mform->addElement('select', 'allocatedmarker', get_string('allocatedmarker', 'assign'), $markerlist); $mform->addHelpButton('allocatedmarker', 'allocatedmarker', 'assign'); $mform->disabledIf('allocatedmarker', 'workflowstate', 'eq', ASSIGN_MARKING_WORKFLOW_STATE_READYFORREVIEW); $mform->disabledIf('allocatedmarker', 'workflowstate', 'eq', ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW); $mform->disabledIf('allocatedmarker', 'workflowstate', 'eq', ASSIGN_MARKING_WORKFLOW_STATE_READYFORRELEASE); $mform->disabledIf('allocatedmarker', 'workflowstate', 'eq', ASSIGN_MARKING_WORKFLOW_STATE_RELEASED); } $mform->addElement('static', 'currentgrade', get_string('currentgrade', 'assign'), $gradestring); if (count($useridlist) > 1) { $strparams = array('current' => $rownum + 1, 'total' => count($useridlist)); $name = get_string('outof', 'assign', $strparams); $mform->addElement('static', 'gradingstudent', get_string('gradingstudent', 'assign'), $name); } // Let feedback plugins add elements to the grading form. $this->add_plugin_grade_elements($grade, $mform, $data, $userid); // Hidden params. $mform->addElement('hidden', 'id', $this->get_course_module()->id); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'rownum', $rownum); $mform->setType('rownum', PARAM_INT); $mform->setConstant('rownum', $rownum); $mform->addElement('hidden', 'useridlistid', $useridlistid); $mform->setType('useridlistid', PARAM_INT); $mform->addElement('hidden', 'attemptnumber', $attemptnumber); $mform->setType('attemptnumber', PARAM_INT); $mform->addElement('hidden', 'ajax', optional_param('ajax', 0, PARAM_INT)); $mform->setType('ajax', PARAM_INT); if ($this->get_instance()->teamsubmission) { $mform->addElement('header', 'groupsubmissionsettings', get_string('groupsubmissionsettings', 'assign')); $mform->addElement('selectyesno', 'applytoall', get_string('applytoteam', 'assign')); $mform->setDefault('applytoall', 1); } // Do not show if we are editing a previous attempt. if ($attemptnumber == -1 && $this->get_instance()->attemptreopenmethod != ASSIGN_ATTEMPT_REOPEN_METHOD_NONE) { $mform->addElement('header', 'attemptsettings', get_string('attemptsettings', 'assign')); $attemptreopenmethod = get_string('attemptreopenmethod_' . $this->get_instance()->attemptreopenmethod, 'assign'); $mform->addElement('static', 'attemptreopenmethod', get_string('attemptreopenmethod', 'assign'), $attemptreopenmethod); $attemptnumber = 0; if ($submission) { $attemptnumber = $submission->attemptnumber; } $maxattempts = $this->get_instance()->maxattempts; if ($maxattempts == ASSIGN_UNLIMITED_ATTEMPTS) { $maxattempts = get_string('unlimitedattempts', 'assign'); } $mform->addelement('static', 'maxattemptslabel', get_string('maxattempts', 'assign'), $maxattempts); $mform->addelement('static', 'attemptnumberlabel', get_string('attemptnumber', 'assign'), $attemptnumber + 1); $ismanual = $this->get_instance()->attemptreopenmethod == ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL; $issubmission = !empty($submission); $isunlimited = $this->get_instance()->maxattempts == ASSIGN_UNLIMITED_ATTEMPTS; $islessthanmaxattempts = $issubmission && $submission->attemptnumber < $this->get_instance()->maxattempts - 1; if ($ismanual && (!$issubmission || $isunlimited || $islessthanmaxattempts)) { $mform->addElement('selectyesno', 'addattempt', get_string('addattempt', 'assign')); $mform->setDefault('addattempt', 0); } } $mform->addElement('hidden', 'action', 'submitgrade'); $mform->setType('action', PARAM_ALPHA); $buttonarray = array(); $name = get_string('savechanges', 'assign'); $buttonarray[] = $mform->createElement('submit', 'savegrade', $name); if (!$last) { $name = get_string('savenext', 'assign'); $buttonarray[] = $mform->createElement('submit', 'saveandshownext', $name); } $buttonarray[] = $mform->createElement('cancel', 'cancelbutton', get_string('cancel')); $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false); $mform->closeHeaderBefore('buttonar'); $buttonarray = array(); if ($rownum > 0) { $name = get_string('previous', 'assign'); $buttonarray[] = $mform->createElement('submit', 'nosaveandprevious', $name); } if (!$last) { $name = get_string('nosavebutnext', 'assign'); $buttonarray[] = $mform->createElement('submit', 'nosaveandnext', $name); } if (!empty($buttonarray)) { $mform->addGroup($buttonarray, 'navar', '', array(' '), false); } // The grading form does not work well with shortforms. $mform->setDisableShortforms(); }