/** * Get the default setting for file submission plugin * * @param MoodleQuickForm $mform The form to add elements to * @return void */ public function get_settings(MoodleQuickForm $mform) { global $CFG, $COURSE; $defaultmaxfilesubmissions = $this->get_config('maxfilesubmissions'); $defaultmaxsubmissionsizebytes = $this->get_config('maxsubmissionsizebytes'); $settings = array(); $options = array(); for ($i = 1; $i <= ASSIGNSUBMISSION_FILE_MAXFILES; $i++) { $options[$i] = $i; } $mform->addElement('select', 'assignsubmission_file_maxfiles', get_string('maxfilessubmission', 'assignsubmission_file'), $options); $mform->addHelpButton('assignsubmission_file_maxfiles', 'maxfilessubmission', 'assignsubmission_file'); $mform->setDefault('assignsubmission_file_maxfiles', $defaultmaxfilesubmissions); $mform->disabledIf('assignsubmission_file_maxfiles', 'assignsubmission_file_enabled', 'eq', 0); $choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes, get_config('assignsubmission_file', 'maxbytes')); // Remove the option for 0 bytes. unset($choices[0]); if ($COURSE->maxbytes == 0) { $choices = array(0 => get_string('siteuploadlimit', 'assignsubmission_file')) + $choices; } else { $choices = array(0 => get_string('courseuploadlimit') . ' (' . display_size($COURSE->maxbytes) . ')') + $choices; } $settings[] = array('type' => 'select', 'name' => 'maxsubmissionsizebytes', 'description' => get_string('maximumsubmissionsize', 'assignsubmission_file'), 'options' => $choices, 'default' => $defaultmaxsubmissionsizebytes); $mform->addElement('select', 'assignsubmission_file_maxsizebytes', get_string('maximumsubmissionsize', 'assignsubmission_file'), $choices); $mform->addHelpButton('assignsubmission_file_maxsizebytes', 'maximumsubmissionsize', 'assignsubmission_file'); $mform->setDefault('assignsubmission_file_maxsizebytes', $defaultmaxsubmissionsizebytes); $mform->disabledIf('assignsubmission_file_maxsizebytes', 'assignsubmission_file_enabled', 'eq', 0); }
/** * Add the form elements for the filter to the supplied form. * * @param MoodleQuickForm $mform The form to add filter settings to. */ public static function add_filter_to_form(\MoodleQuickForm &$mform) { $options = [static::ANYVALUE => get_string('all')]; $options += static::get_filter_options(); $filtername = static::get_filter_name(); $key = "filter_{$filtername}"; $mform->addElement('select', $key, get_string($key, 'tool_usertours'), $options, ['multiple' => true]); $mform->setDefault($key, static::ANYVALUE); $mform->addHelpButton($key, $key, 'tool_usertours'); }
/** * 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); }
public static function add_settings_form_fields(mod_quiz_mod_form $quizform, MoodleQuickForm $mform) { $config = get_config('quizaccess_offlinemode'); $mform->addElement('selectyesno', 'offlinemode_enabled', get_string('offlinemodeenabled', 'quizaccess_offlinemode')); $mform->addHelpButton('offlinemode_enabled', 'offlinemodeenabled', 'quizaccess_offlinemode'); $mform->setDefault('offlinemode_enabled', !empty($config->defaultenabled)); $mform->setAdvanced('offlinemode_enabled', !empty($config->defaultenabled_adv)); foreach (question_engine::get_behaviour_options(null) as $behaviour => $notused) { if (!self::is_compatible_behaviour($behaviour)) { $mform->disabledIf('offlinemode_enabled', 'preferredbehaviour', 'eq', $behaviour); } } }
/** * Get the default setting for OneNote submission plugin * * @param MoodleQuickForm $mform The form to add elements to * @return void */ public function get_settings(MoodleQuickForm $mform) { global $CFG, $COURSE; $defaultmaxfilesubmissions = $this->get_config('maxfilesubmissions'); $defaultmaxsubmissionsizebytes = $this->get_config('maxsubmissionsizebytes'); $settings = array(); $options = array(); for ($i = 1; $i <= \local_onenote\api\base::ASSIGNSUBMISSION_ONENOTE_MAXFILES; $i++) { $options[$i] = $i; } $name = get_string('maxfilessubmission', 'assignsubmission_onenote'); $mform->addElement('select', 'assignsubmission_onenote_maxfiles', $name, $options); $mform->addHelpButton('assignsubmission_onenote_maxfiles', 'maxfilessubmission', 'assignsubmission_onenote'); $mform->setDefault('assignsubmission_onenote_maxfiles', $defaultmaxfilesubmissions); $mform->disabledIf('assignsubmission_onenote_maxfiles', 'assignsubmission_onenote_enabled', 'notchecked'); $choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes, get_config('assignsubmission_onenote', 'maxbytes')); $settings[] = array('type' => 'select', 'name' => 'maxsubmissionsizebytes', 'description' => get_string('maximumsubmissionsize', 'assignsubmission_onenote'), 'options' => $choices, 'default' => $defaultmaxsubmissionsizebytes); $name = get_string('maximumsubmissionsize', 'assignsubmission_onenote'); $mform->addElement('select', 'assignsubmission_onenote_maxsizebytes', $name, $choices); $mform->addHelpButton('assignsubmission_onenote_maxsizebytes', 'maximumsubmissionsize', 'assignsubmission_onenote'); $mform->setDefault('assignsubmission_onenote_maxsizebytes', $defaultmaxsubmissionsizebytes); $mform->disabledIf('assignsubmission_onenote_maxsizebytes', 'assignsubmission_onenote_enabled', 'notchecked'); }
/** * 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'); } }
/** * Add re-usable form elements for forum preferences * @param MoodleQuickForm $mform */ public static function add_elements(&$mform) { global $CFG, $OUTPUT; $mform->addElement('html', $OUTPUT->heading(get_string('forumsubscription', 'forumng'), 3)); $choices = array(); $choices['0'] = get_string('emaildigestoff'); $choices['1'] = get_string('emaildigestcomplete'); $mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices); $mform->setDefault('maildigest', $CFG->defaultpreference_maildigest); $mform->addHelpButton('maildigest', 'emaildigest'); $mform->addElement('html', html_writer::empty_tag('hr')); $choices = array(); $choices['1'] = get_string('htmlformat'); $choices['0'] = get_string('textformat'); $mform->addElement('select', 'mailformat', get_string('emailformat'), $choices); $mform->setDefault('autosubscribe', $CFG->defaultpreference_mailformat); }
/** * 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'); }
public static function add_settings_form_fields(mod_quiz_mod_form $quizform, MoodleQuickForm $mform) { $mform->addElement('select', 'honestycheckrequired', get_string('honestycheckrequired', 'quizaccess_honestycheck'), array(0 => get_string('notrequired', 'quizaccess_honestycheck'), 1 => get_string('honestycheckrequiredoption', 'quizaccess_honestycheck'))); $mform->addHelpButton('honestycheckrequired', 'honestycheckrequired', 'quizaccess_honestycheck'); }
/** * Inject the competencies elements into all moodle module settings forms. * * @param moodleform $formwrapper The moodle quickforms wrapper object. * @param MoodleQuickForm $mform The actual form object (required to modify the form). */ function tool_lp_coursemodule_standard_elements($formwrapper, $mform) { global $CFG, $COURSE; if (!get_config('core_competency', 'enabled')) { return; } else { if (!has_capability('moodle/competency:coursecompetencymanage', $formwrapper->get_context())) { return; } } $mform->addElement('header', 'competenciessection', get_string('competencies', 'core_competency')); MoodleQuickForm::registerElementType('course_competencies', "{$CFG->dirroot}/admin/tool/lp/classes/course_competencies_form_element.php", 'tool_lp_course_competencies_form_element'); $cmid = null; if ($cm = $formwrapper->get_coursemodule()) { $cmid = $cm->id; } $options = array('courseid' => $COURSE->id, 'cmid' => $cmid); $mform->addElement('course_competencies', 'competencies', get_string('modcompetencies', 'tool_lp'), $options); $mform->addHelpButton('competencies', 'modcompetencies', 'tool_lp'); MoodleQuickForm::registerElementType('course_competency_rule', "{$CFG->dirroot}/admin/tool/lp/classes/course_competency_rule_form_element.php", 'tool_lp_course_competency_rule_form_element'); // Reuse the same options. $mform->addElement('course_competency_rule', 'competency_rule', get_string('uponcoursemodulecompletion', 'tool_lp'), $options); }
/** * Extends the course reset form with workshop specific settings. * * @param MoodleQuickForm $mform */ function workshop_reset_course_form_definition($mform) { $mform->addElement('header', 'workshopheader', get_string('modulenameplural', 'mod_workshop')); $mform->addElement('advcheckbox', 'reset_workshop_submissions', get_string('resetsubmissions', 'mod_workshop')); $mform->addHelpButton('reset_workshop_submissions', 'resetsubmissions', 'mod_workshop'); $mform->addElement('advcheckbox', 'reset_workshop_assessments', get_string('resetassessments', 'mod_workshop')); $mform->addHelpButton('reset_workshop_assessments', 'resetassessments', 'mod_workshop'); $mform->disabledIf('reset_workshop_assessments', 'reset_workshop_submissions', 'checked'); $mform->addElement('advcheckbox', 'reset_workshop_phase', get_string('resetphase', 'mod_workshop')); $mform->addHelpButton('reset_workshop_phase', 'resetphase', 'mod_workshop'); }
/** * Get the default setting for feedback comments plugin * * @param MoodleQuickForm $mform The form to add elements to * @return void */ public function get_settings(MoodleQuickForm $mform) { $default = $this->get_config('commentinline'); $mform->addElement('selectyesno', 'assignfeedback_comments_commentinline', get_string('commentinline', 'assignfeedback_comments')); $mform->addHelpButton('assignfeedback_comments_commentinline', 'commentinline', 'assignfeedback_comments'); $mform->setDefault('assignfeedback_comments_commentinline', $default); // Disable comment online if comment feedback plugin is disabled. $mform->disabledIf('assignfeedback_comments_commentinline', 'assignfeedback_comments_enabled', 'notchecked'); }
if ($quickgrade) { echo html_writer::end_tag('form'); } } // Mini form for setting user preference. $formaction = new moodle_url('/mod/giportfolio/submissions.php', array('id' => $cm->id)); $mform = new MoodleQuickForm('optionspref', 'post', $formaction, '', array('class' => 'optionspref')); $mform->addElement('hidden', 'updatepref'); $mform->setDefault('updatepref', 1); $mform->addElement('header', 'qgprefs', get_string('optionalsettings', 'assignment')); $mform->setDefault('filter', $filter); $mform->addElement('text', 'perpage', get_string('pagesize', 'assignment'), array('size' => 1)); $mform->setDefault('perpage', $perpage); $mform->addElement('checkbox', 'quickgrade', get_string('quickgrade', 'assignment')); $mform->setDefault('quickgrade', $quickgrade); $mform->addHelpButton('quickgrade', 'quickgrade', 'assignment'); $mform->addElement('submit', 'savepreferences', get_string('savepreferences')); $mform->display(); echo $OUTPUT->footer(); /** * Checks if grading method allows quickgrade mode. At the moment it is hardcoded * that advanced grading methods do not allow quickgrade. * * Assignment type plugins are not allowed to override this method * * @param $cmid * @return boolean */ function quickgrade_mode_allowed($cmid) { global $CFG;
/** * 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']; $useridlist = $params['useridlist']; $userid = $useridlist[$rownum]; $grade = $this->get_user_grade($userid, false); // add advanced grading $gradingdisabled = $this->grading_disabled($userid); $gradinginstance = $this->get_grading_instance($userid, $gradingdisabled); 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()); } } else { // use simple direct grading if ($this->get_instance()->grade > 0) { $gradingelement = $mform->addElement('text', 'grade', get_string('gradeoutof', 'assign',$this->get_instance()->grade)); $mform->addHelpButton('grade', 'gradeoutofhelp', 'assign'); $mform->setType('grade', PARAM_TEXT); if ($gradingdisabled) { $gradingelement->freeze(); } } else { $grademenu = make_grades_menu($this->get_instance()->grade); if (count($grademenu) > 0) { $gradingelement = $mform->addElement('select', 'grade', get_string('grade').':', $grademenu); $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 ); } } } if (has_all_capabilities(array('gradereport/grader:view', 'moodle/grade:viewall'), $this->get_course_context())) { $gradestring = $this->output->action_link(new moodle_url('/grade/report/grader/index.php', array('id'=>$this->get_course()->id)), $gradinginfo->items[0]->grades[$userid]->str_grade); } else { $gradestring = $gradinginfo->items[0]->grades[$userid]->str_grade; } $mform->addElement('static', 'finalgrade', get_string('currentgrade', 'assign').':', $gradestring); $mform->addElement('static', 'progress', '', get_string('gradingstudentprogress', 'assign', array('index'=>$rownum+1, 'count'=>count($useridlist)))); // plugins $this->add_plugin_grade_elements($grade, $mform, $data); // 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->addElement('hidden', 'useridlist', implode(',', $useridlist)); $mform->setType('useridlist', PARAM_TEXT); $mform->addElement('hidden', 'ajax', optional_param('ajax', 0, PARAM_INT)); $mform->setType('ajax', PARAM_INT); if ($this->get_instance()->teamsubmission) { $mform->addElement('selectyesno', 'applytoall', get_string('applytoteam', 'assign')); $mform->setDefault('applytoall', 1); } $mform->addElement('hidden', 'action', 'submitgrade'); $mform->setType('action', PARAM_ALPHA); $buttonarray=array(); $buttonarray[] = $mform->createElement('submit', 'savegrade', get_string('savechanges', 'assign')); if (!$last) { $buttonarray[] = $mform->createElement('submit', 'saveandshownext', get_string('savenext','assign')); } $buttonarray[] = $mform->createElement('cancel', 'cancelbutton', get_string('cancel')); $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false); $mform->closeHeaderBefore('buttonar'); $buttonarray=array(); if ($rownum > 0) { $buttonarray[] = $mform->createElement('submit', 'nosaveandprevious', get_string('previous','assign')); } if (!$last) { $buttonarray[] = $mform->createElement('submit', 'nosaveandnext', get_string('nosavebutnext', 'assign')); } $mform->addGroup($buttonarray, 'navar', '', array(' '), false); }
/** * Get form elements for grading form * * @param stdClass $grade * @param MoodleQuickForm $mform * @param stdClass $data * @param int $userid * @return bool true if elements were added to the form */ public function get_form_elements_for_user($grade, MoodleQuickForm $mform, stdClass $data, $userid) { global $PAGE; $attempt = -1; if ($grade) { $attempt = $grade->attemptnumber; } $files = document_services::list_compatible_submission_files_for_attempt($this->setaskment, $userid, $attempt); // Only show the editor if there was a compatible file submitted. if (count($files)) { $renderer = $PAGE->get_renderer('setaskfeedback_editpdf'); $widget = $this->get_widget($userid, $grade, false); $html = $renderer->render($widget); $mform->addElement('static', 'editpdf', get_string('editpdf', 'setaskfeedback_editpdf'), $html); $mform->addHelpButton('editpdf', 'editpdf', 'setaskfeedback_editpdf'); $mform->addElement('hidden', 'editpdf_source_userid', $userid); $mform->setType('editpdf_source_userid', PARAM_INT); $mform->setConstant('editpdf_source_userid', $userid); } }
public static function add_settings_form_fields(mod_quiz_mod_form $quizform, MoodleQuickForm $mform) { $mform->addElement('text', 'reattemptchecker', get_string("preventpassed", "quizaccess_reattemptchecker"), 'maxlength="3" size="3"'); $mform->setType('reattemptchecker', PARAM_INT); $mform->addHelpButton('reattemptchecker', 'preventpassed', 'quizaccess_reattemptchecker'); }
/** * Get the default setting for feedback comments plugin * * @param MoodleQuickForm $mform The form to add elements to * @return void */ public function get_settings(MoodleQuickForm $mform) { $default = $this->get_config('commentinline'); if ($default === false) { // Apply the admin default if we don't have a value yet. $default = get_config('assignfeedback_comments', 'inline'); } $mform->addElement('selectyesno', 'assignfeedback_comments_commentinline', get_string('commentinline', 'assignfeedback_comments')); $mform->addHelpButton('assignfeedback_comments_commentinline', 'commentinline', 'assignfeedback_comments'); $mform->setDefault('assignfeedback_comments_commentinline', $default); // Disable comment online if comment feedback plugin is disabled. $mform->disabledIf('assignfeedback_comments_commentinline', 'assignfeedback_comments_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']); } } 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; $options = $this->get_status_options(); $mform->addElement('select', 'status', get_string('status', 'enrol_guest'), $options); $mform->addHelpButton('status', 'status', 'enrol_guest'); $mform->setDefault('status', $this->get_config('status')); $mform->setAdvanced('status', $this->get_config('status_adv')); $mform->addElement('passwordunmask', 'password', get_string('password', 'enrol_guest')); $mform->addHelpButton('password', 'password', 'enrol_guest'); // If we have a new instance and the password is required - make sure it is set. For existing // instances we do not force the password to be required as it may have been set to empty before // the password was required. We check in the validation function whether this check is required // for existing instances. if (empty($instance->id) && $this->get_config('requirepassword')) { $mform->addRule('password', get_string('required'), 'required', null); } }
protected function form_precise(\MoodleQuickForm $mform, $helptext = '') { $precoptions = array("0" => get_string('normal', 'questionnaire'), "1" => get_string('notapplicablecolumn', 'questionnaire'), "2" => get_string('noduplicates', 'questionnaire'), "3" => get_string('osgood', 'questionnaire')); $mform->addElement('select', 'precise', get_string('kindofratescale', 'questionnaire'), $precoptions); $mform->addHelpButton('precise', 'kindofratescale', 'questionnaire'); $mform->setType('precise', PARAM_INT); return $mform; }
/** * Add the specified step field configuration to the form. * * @param MoodleQuickForm $mform The form to add configuration to. * @param string $key The key to add. * @return $this */ protected function add_config_field_to_form(\MoodleQuickForm &$mform, $key) { $options = [true => get_string('yes'), false => get_string('no')]; $mform->addElement('select', $key, get_string($key, 'tool_usertours'), $options); $mform->setDefault($key, configuration::get_default_value($key)); $mform->addHelpButton($key, $key, 'tool_usertours'); return $this; }
/** * 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(); }
public static function form_precise_text(\MoodleQuickForm $mform, $helpname = '', $value = 0) { $mform->addElement('text', 'precise', get_string($helpname, 'questionnaire'), array('size' => '1')); $mform->setType('precise', PARAM_INT); if (!empty($helpname)) { $mform->addHelpButton('precise', $helpname, 'questionnaire'); } return $mform; }
/** * 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); } }
/** * Display all the submissions ready for grading * * @global object * @global object * @global object * @global object * @param string $message * @return bool|void */ function display_submissions($message='') { global $CFG, $DB, $USER, $DB, $OUTPUT, $PAGE; require_once($CFG->libdir.'/gradelib.php'); /* first we check to see if the form has just been submitted * to request user_preference updates */ $filters = array(self::FILTER_ALL => get_string('all'), self::FILTER_SUBMITTED => get_string('submitted', 'assignment'), self::FILTER_REQUIRE_GRADING => get_string('requiregrading', 'assignment')); $updatepref = optional_param('updatepref', 0, PARAM_INT); if (isset($_POST['updatepref'])){ $perpage = optional_param('perpage', 10, PARAM_INT); $perpage = ($perpage <= 0) ? 10 : $perpage ; $filter = optional_param('filter', 0, PARAM_INT); set_user_preference('assignment_perpage', $perpage); set_user_preference('assignment_quickgrade', optional_param('quickgrade', 0, PARAM_BOOL)); set_user_preference('assignment_filter', $filter); } /* next we get perpage and quickgrade (allow quick grade) params * from database */ $perpage = get_user_preferences('assignment_perpage', 10); $quickgrade = get_user_preferences('assignment_quickgrade', 0); $filter = get_user_preferences('assignment_filter', 0); $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id); if (!empty($CFG->enableoutcomes) and !empty($grading_info->outcomes)) { $uses_outcomes = true; } else { $uses_outcomes = false; } $page = optional_param('page', 0, PARAM_INT); $strsaveallfeedback = get_string('saveallfeedback', 'assignment'); /// Some shortcuts to make the code read better $course = $this->course; $assignment = $this->assignment; $cm = $this->cm; $tabindex = 1; //tabindex for quick grading tabbing; Not working for dropdowns yet add_to_log($course->id, 'assignment', 'view submission', 'submissions.php?id='.$this->cm->id, $this->assignment->id, $this->cm->id); $PAGE->set_title(format_string($this->assignment->name,true)); $PAGE->set_heading($this->course->fullname); echo $OUTPUT->header(); echo '<div class="usersubmissions">'; //hook to allow plagiarism plugins to update status/print links. plagiarism_update_status($this->course, $this->cm); /// Print quickgrade form around the table if ($quickgrade) { $formattrs = array(); $formattrs['action'] = new moodle_url('/mod/assignment/submissions.php'); $formattrs['id'] = 'fastg'; $formattrs['method'] = 'post'; echo html_writer::start_tag('form', $formattrs); echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'id', 'value'=> $this->cm->id)); echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'mode', 'value'=> 'fastgrade')); echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'page', 'value'=> $page)); echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=> sesskey())); } $course_context = get_context_instance(CONTEXT_COURSE, $course->id); if (has_capability('gradereport/grader:view', $course_context) && has_capability('moodle/grade:viewall', $course_context)) { echo '<div class="allcoursegrades"><a href="' . $CFG->wwwroot . '/grade/report/grader/index.php?id=' . $course->id . '">' . get_string('seeallcoursegrades', 'grades') . '</a></div>'; } if (!empty($message)) { echo $message; // display messages here if any } $context = get_context_instance(CONTEXT_MODULE, $cm->id); /// Check to see if groups are being used in this assignment /// find out current groups mode $groupmode = groups_get_activity_groupmode($cm); $currentgroup = groups_get_activity_group($cm, true); groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/assignment/submissions.php?id=' . $this->cm->id); /// Get all ppl that are allowed to submit assignments list($esql, $params) = get_enrolled_sql($context, 'mod/assignment:view', $currentgroup); if ($filter == self::FILTER_ALL) { $sql = "SELECT u.id FROM {user} u ". "LEFT JOIN ($esql) eu ON eu.id=u.id ". "WHERE u.deleted = 0 AND eu.id=u.id "; } else { $wherefilter = ''; if($filter == self::FILTER_SUBMITTED) { $wherefilter = ' AND s.timemodified > 0'; } else if($filter == self::FILTER_REQUIRE_GRADING) { $wherefilter = ' AND s.timemarked < s.timemodified '; } $sql = "SELECT u.id FROM {user} u ". "LEFT JOIN ($esql) eu ON eu.id=u.id ". "LEFT JOIN {assignment_submissions} s ON (u.id = s.userid) " . "WHERE u.deleted = 0 AND eu.id=u.id ". 'AND s.assignment = '. $this->assignment->id . $wherefilter; } $users = $DB->get_records_sql($sql, $params); if (!empty($users)) { $users = array_keys($users); } // if groupmembersonly used, remove users who are not in any group if ($users and !empty($CFG->enablegroupmembersonly) and $cm->groupmembersonly) { if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) { $users = array_intersect($users, array_keys($groupingusers)); } } $tablecolumns = array('picture', 'fullname', 'grade', 'submissioncomment', 'timemodified', 'timemarked', 'status', 'finalgrade'); if ($uses_outcomes) { $tablecolumns[] = 'outcome'; // no sorting based on outcomes column } $tableheaders = array('', get_string('fullname'), get_string('grade'), get_string('comment', 'assignment'), get_string('lastmodified').' ('.get_string('submission', 'assignment').')', get_string('lastmodified').' ('.get_string('grade').')', get_string('status'), get_string('finalgrade', 'grades')); if ($uses_outcomes) { $tableheaders[] = get_string('outcome', 'grades'); } require_once($CFG->libdir.'/tablelib.php'); $table = new flexible_table('mod-assignment-submissions'); $table->define_columns($tablecolumns); $table->define_headers($tableheaders); $table->define_baseurl($CFG->wwwroot.'/mod/assignment/submissions.php?id='.$this->cm->id.'&currentgroup='.$currentgroup); $table->sortable(true, 'lastname');//sorted by lastname by default $table->collapsible(true); $table->initialbars(true); $table->column_suppress('picture'); $table->column_suppress('fullname'); $table->column_class('picture', 'picture'); $table->column_class('fullname', 'fullname'); $table->column_class('grade', 'grade'); $table->column_class('submissioncomment', 'comment'); $table->column_class('timemodified', 'timemodified'); $table->column_class('timemarked', 'timemarked'); $table->column_class('status', 'status'); $table->column_class('finalgrade', 'finalgrade'); if ($uses_outcomes) { $table->column_class('outcome', 'outcome'); } $table->set_attribute('cellspacing', '0'); $table->set_attribute('id', 'attempts'); $table->set_attribute('class', 'submissions'); $table->set_attribute('width', '100%'); //$table->set_attribute('align', 'center'); $table->no_sorting('finalgrade'); $table->no_sorting('outcome'); // Start working -- this is necessary as soon as the niceties are over $table->setup(); if (empty($users)) { echo $OUTPUT->heading(get_string('nosubmitusers','assignment')); echo '</div>'; return true; } if ($this->assignment->assignmenttype=='upload' || $this->assignment->assignmenttype=='online' || $this->assignment->assignmenttype=='uploadsingle') { //TODO: this is an ugly hack, where is the plugin spirit? (skodak) echo '<div style="text-align:right"><a href="submissions.php?id='.$this->cm->id.'&download=zip">'.get_string('downloadall', 'assignment').'</a></div>'; } /// Construct the SQL list($where, $params) = $table->get_sql_where(); if ($where) { $where .= ' AND '; } if ($filter == self::FILTER_SUBMITTED) { $where .= 's.timemodified > 0 AND '; } else if($filter == self::FILTER_REQUIRE_GRADING) { $where .= 's.timemarked < s.timemodified AND '; } if ($sort = $table->get_sql_sort()) { $sort = ' ORDER BY '.$sort; } $ufields = user_picture::fields('u'); $select = "SELECT $ufields, s.id AS submissionid, s.grade, s.submissioncomment, s.timemodified, s.timemarked, COALESCE(SIGN(SIGN(s.timemarked) + SIGN(s.timemarked - s.timemodified)), 0) AS status "; $sql = 'FROM {user} u '. 'LEFT JOIN {assignment_submissions} s ON u.id = s.userid AND s.assignment = '.$this->assignment->id.' '. 'WHERE '.$where.'u.id IN ('.implode(',',$users).') '; $ausers = $DB->get_records_sql($select.$sql.$sort, $params, $table->get_page_start(), $table->get_page_size()); $table->pagesize($perpage, count($users)); ///offset used to calculate index of student in that particular query, needed for the pop up to know who's next $offset = $page * $perpage; $strupdate = get_string('update'); $strgrade = get_string('grade'); $grademenu = make_grades_menu($this->assignment->grade); if ($ausers !== false) { $grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, array_keys($ausers)); $endposition = $offset + $perpage; $currentposition = 0; foreach ($ausers as $auser) { if ($currentposition == $offset && $offset < $endposition) { $final_grade = $grading_info->items[0]->grades[$auser->id]; $grademax = $grading_info->items[0]->grademax; $final_grade->formatted_grade = round($final_grade->grade,2) .' / ' . round($grademax,2); $locked_overridden = 'locked'; if ($final_grade->overridden) { $locked_overridden = 'overridden'; } /// Calculate user status $auser->status = ($auser->timemarked > 0) && ($auser->timemarked >= $auser->timemodified); $picture = $OUTPUT->user_picture($auser); if (empty($auser->submissionid)) { $auser->grade = -1; //no submission yet } if (!empty($auser->submissionid)) { ///Prints student answer and student modified date ///attach file or print link to student answer, depending on the type of the assignment. ///Refer to print_student_answer in inherited classes. if ($auser->timemodified > 0) { $studentmodified = '<div id="ts'.$auser->id.'">'.$this->print_student_answer($auser->id) . userdate($auser->timemodified).'</div>'; } else { $studentmodified = '<div id="ts'.$auser->id.'"> </div>'; } ///Print grade, dropdown or text if ($auser->timemarked > 0) { $teachermodified = '<div id="tt'.$auser->id.'">'.userdate($auser->timemarked).'</div>'; if ($final_grade->locked or $final_grade->overridden) { $grade = '<div id="g'.$auser->id.'" class="'. $locked_overridden .'">'.$final_grade->formatted_grade.'</div>'; } else if ($quickgrade) { $attributes = array(); $attributes['tabindex'] = $tabindex++; $menu = html_writer::select(make_grades_menu($this->assignment->grade), 'menu['.$auser->id.']', $auser->grade, array(-1=>get_string('nograde')), $attributes); $grade = '<div id="g'.$auser->id.'">'. $menu .'</div>'; } else { $grade = '<div id="g'.$auser->id.'">'.$this->display_grade($auser->grade).'</div>'; } } else { $teachermodified = '<div id="tt'.$auser->id.'"> </div>'; if ($final_grade->locked or $final_grade->overridden) { $grade = '<div id="g'.$auser->id.'" class="'. $locked_overridden .'">'.$final_grade->formatted_grade.'</div>'; } else if ($quickgrade) { $attributes = array(); $attributes['tabindex'] = $tabindex++; $menu = html_writer::select(make_grades_menu($this->assignment->grade), 'menu['.$auser->id.']', $auser->grade, array(-1=>get_string('nograde')), $attributes); $grade = '<div id="g'.$auser->id.'">'.$menu.'</div>'; } else { $grade = '<div id="g'.$auser->id.'">'.$this->display_grade($auser->grade).'</div>'; } } ///Print Comment if ($final_grade->locked or $final_grade->overridden) { $comment = '<div id="com'.$auser->id.'">'.shorten_text(strip_tags($final_grade->str_feedback),15).'</div>'; } else if ($quickgrade) { $comment = '<div id="com'.$auser->id.'">' . '<textarea tabindex="'.$tabindex++.'" name="submissioncomment['.$auser->id.']" id="submissioncomment' . $auser->id.'" rows="2" cols="20">'.($auser->submissioncomment).'</textarea></div>'; } else { $comment = '<div id="com'.$auser->id.'">'.shorten_text(strip_tags($auser->submissioncomment),15).'</div>'; } } else { $studentmodified = '<div id="ts'.$auser->id.'"> </div>'; $teachermodified = '<div id="tt'.$auser->id.'"> </div>'; $status = '<div id="st'.$auser->id.'"> </div>'; if ($final_grade->locked or $final_grade->overridden) { $grade = '<div id="g'.$auser->id.'">'.$final_grade->formatted_grade . '</div>'; } else if ($quickgrade) { // allow editing $attributes = array(); $attributes['tabindex'] = $tabindex++; $menu = html_writer::select(make_grades_menu($this->assignment->grade), 'menu['.$auser->id.']', $auser->grade, array(-1=>get_string('nograde')), $attributes); $grade = '<div id="g'.$auser->id.'">'.$menu.'</div>'; } else { $grade = '<div id="g'.$auser->id.'">-</div>'; } if ($final_grade->locked or $final_grade->overridden) { $comment = '<div id="com'.$auser->id.'">'.$final_grade->str_feedback.'</div>'; } else if ($quickgrade) { $comment = '<div id="com'.$auser->id.'">' . '<textarea tabindex="'.$tabindex++.'" name="submissioncomment['.$auser->id.']" id="submissioncomment' . $auser->id.'" rows="2" cols="20">'.($auser->submissioncomment).'</textarea></div>'; } else { $comment = '<div id="com'.$auser->id.'"> </div>'; } } if (empty($auser->status)) { /// Confirm we have exclusively 0 or 1 $auser->status = 0; } else { $auser->status = 1; } $buttontext = ($auser->status == 1) ? $strupdate : $strgrade; ///No more buttons, we use popups ;-). $popup_url = '/mod/assignment/submissions.php?id='.$this->cm->id . '&userid='.$auser->id.'&mode=single'.'&filter='.$filter.'&offset='.$offset++; $button = $OUTPUT->action_link($popup_url, $buttontext); $status = '<div id="up'.$auser->id.'" class="s'.$auser->status.'">'.$button.'</div>'; $finalgrade = '<span id="finalgrade_'.$auser->id.'">'.$final_grade->str_grade.'</span>'; $outcomes = ''; if ($uses_outcomes) { foreach($grading_info->outcomes as $n=>$outcome) { $outcomes .= '<div class="outcome"><label>'.$outcome->name.'</label>'; $options = make_grades_menu(-$outcome->scaleid); if ($outcome->grades[$auser->id]->locked or !$quickgrade) { $options[0] = get_string('nooutcome', 'grades'); $outcomes .= ': <span id="outcome_'.$n.'_'.$auser->id.'">'.$options[$outcome->grades[$auser->id]->grade].'</span>'; } else { $attributes = array(); $attributes['tabindex'] = $tabindex++; $attributes['id'] = 'outcome_'.$n.'_'.$auser->id; $outcomes .= ' '.html_writer::select($options, 'outcome_'.$n.'['.$auser->id.']', $outcome->grades[$auser->id]->grade, array(0=>get_string('nooutcome', 'grades')), $attributes); } $outcomes .= '</div>'; } } $userlink = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $auser->id . '&course=' . $course->id . '">' . fullname($auser, has_capability('moodle/site:viewfullnames', $this->context)) . '</a>'; $row = array($picture, $userlink, $grade, $comment, $studentmodified, $teachermodified, $status, $finalgrade); if ($uses_outcomes) { $row[] = $outcomes; } $table->add_data($row); } $currentposition++; } } $table->print_html(); /// Print the whole table /// Print quickgrade form around the table if ($quickgrade && $table->started_output){ $mailinfopref = false; if (get_user_preferences('assignment_mailinfo', 1)) { $mailinfopref = true; } $emailnotification = html_writer::checkbox('mailinfo', 1, $mailinfopref, get_string('enableemailnotification','assignment')); $emailnotification .= $OUTPUT->help_icon('enableemailnotification', 'assignment'); echo html_writer::tag('div', $emailnotification, array('class'=>'emailnotification')); $savefeedback = html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'fastg', 'value'=>get_string('saveallfeedback', 'assignment'))); echo html_writer::tag('div', $savefeedback, array('class'=>'fastgbutton')); echo html_writer::end_tag('form'); } else if ($quickgrade) { echo html_writer::end_tag('form'); } echo '</div>'; /// End of fast grading form /// Mini form for setting user preference $formaction = new moodle_url('/mod/assignment/submissions.php', array('id'=>$this->cm->id)); $mform = new MoodleQuickForm('optionspref', 'post', $formaction, '', array('class'=>'optionspref')); $mform->addElement('hidden', 'updatepref'); $mform->setDefault('updatepref', 1); $mform->addElement('header', 'qgprefs', get_string('optionalsettings', 'assignment')); $mform->addElement('select', 'filter', get_string('show'), $filters); $mform->setDefault('filter', $filter); $mform->addElement('text', 'perpage', get_string('pagesize', 'assignment'), array('size'=>1)); $mform->setDefault('perpage', $perpage); $mform->addElement('checkbox', 'quickgrade', get_string('quickgrade','assignment')); $mform->setDefault('quickgrade', $quickgrade); $mform->addHelpButton('quickgrade', 'quickgrade', 'assignment'); $mform->addElement('submit', 'savepreferences', get_string('savepreferences')); $mform->display(); echo $OUTPUT->footer(); }
/** * Add the form elements defining one PRT node. * @param string $prtname the name of the PRT. * @param string $name the name of the node. * @param array $nextnodechoices the available choices for the next node. * @param bool $deletable whether the user is allowed to delete this node. * @param MoodleQuickForm $mform the form being assembled. */ protected function definition_prt_node($prtname, $name, $nextnodechoices, $deletable, MoodleQuickForm $mform) { $nodekey = $name - 1; unset($nextnodechoices[$nodekey]); $nodegroup = array(); $nodegroup[] = $mform->createElement('select', $prtname . 'answertest[' . $nodekey . ']', stack_string('answertest'), $this->answertestchoices); $nodegroup[] = $mform->createElement('text', $prtname . 'sans[' . $nodekey . ']', stack_string('sans'), array('size' => 15)); $nodegroup[] = $mform->createElement('text', $prtname . 'tans[' . $nodekey . ']', stack_string('tans'), array('size' => 15)); $nodegroup[] = $mform->createElement('text', $prtname . 'testoptions[' . $nodekey . ']', stack_string('testoptions'), array('size' => 5)); $nodegroup[] = $mform->createElement('selectyesno', $prtname . 'quiet[' . $nodekey . ']', stack_string('quiet')); $mform->addGroup($nodegroup, $prtname . 'node[' . $nodekey . ']', html_writer::tag('b', stack_string('nodex', $name)), null, false); $mform->addHelpButton($prtname . 'node[' . $nodekey . ']', 'nodehelp', 'qtype_stack'); $mform->setType($prtname . 'sans[' . $nodekey . ']', PARAM_RAW); $mform->setType($prtname . 'tans[' . $nodekey . ']', PARAM_RAW); $mform->setType($prtname . 'testoptions[' . $nodekey . ']', PARAM_RAW); // Create the section of the form for each node - the branches. foreach (array('true', 'false') as $branch) { $branchgroup = array(); $branchgroup[] = $mform->createElement('select', $prtname . $branch . 'scoremode[' . $nodekey . ']', stack_string('scoremode'), $this->scoremodechoices); if ($nodekey > 0) { if ($branch === 'true') { $mform->setDefault($prtname . $branch . 'scoremode[' . $nodekey . ']', '+'); } else { $mform->setDefault($prtname . $branch . 'scoremode[' . $nodekey . ']', '-'); } } $branchgroup[] = $mform->createElement('text', $prtname . $branch . 'score[' . $nodekey . ']', stack_string('score'), array('size' => 2)); $mform->setDefault($prtname . $branch . 'score[' . $nodekey . ']', (int) ($branch === 'true' && $nodekey == 0)); $branchgroup[] = $mform->createElement('text', $prtname . $branch . 'penalty[' . $nodekey . ']', stack_string('penalty'), array('size' => 2)); $branchgroup[] = $mform->createElement('select', $prtname . $branch . 'nextnode[' . $nodekey . ']', stack_string('next'), $nextnodechoices); $branchgroup[] = $mform->createElement('text', $prtname . $branch . 'answernote[' . $nodekey . ']', stack_string('answernote'), array('size' => 10)); $mform->setDefault($prtname . $branch . 'answernote[' . $nodekey . ']', stack_string('answernotedefault' . $branch, array('prtname' => $prtname, 'nodename' => $name))); $mform->addGroup($branchgroup, $prtname . 'nodewhen' . $branch . '[' . $nodekey . ']', stack_string('nodexwhen' . $branch, $name), null, false); $mform->addHelpButton($prtname . 'nodewhen' . $branch . '[' . $nodekey . ']', $branch . 'branch', 'qtype_stack'); $mform->setType($prtname . $branch . 'score[' . $nodekey . ']', PARAM_RAW); $mform->setType($prtname . $branch . 'penalty[' . $nodekey . ']', PARAM_RAW); $mform->setType($prtname . $branch . 'answernote[' . $nodekey . ']', PARAM_RAW); $mform->addElement('editor', $prtname . $branch . 'feedback[' . $nodekey . ']', stack_string('nodex' . $branch . 'feedback', $name), array('rows' => 1), $this->editoroptions); $mform->addHelpButton($prtname . $branch . 'feedback[' . $nodekey . ']', 'branchfeedback', 'qtype_stack'); } if ($deletable) { $mform->addElement('submit', $prtname . 'nodedelete' . $nodekey, stack_string('nodexdelete', $name)); $mform->registerNoSubmitButton($prtname . 'nodedelete' . $nodekey); } }
/** * 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); }
protected function form_length(\MoodleQuickForm $mform, $helptext = '') { $lengroup = array(); $lengroup[] =& $mform->createElement('radio', 'length', '', get_string('vertical', 'questionnaire'), '0'); $lengroup[] =& $mform->createElement('radio', 'length', '', get_string('horizontal', 'questionnaire'), '1'); $mform->addGroup($lengroup, 'lengroup', get_string('alignment', 'questionnaire'), ' ', false); $mform->addHelpButton('lengroup', 'alignment', 'questionnaire'); $mform->setType('length', PARAM_INT); return $mform; }
/** * 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; }
/** * Adds enrol instance UI to course edit form * * @param object $instance enrol instance or null if does not exist yet * @param MoodleQuickForm $mform * @param object $data * @param object $context context of existing course or parent category if course does not exist * @return void */ public function course_edit_form($instance, MoodleQuickForm $mform, $data, $context) { $i = isset($instance->id) ? $instance->id : 0; if (!$i and !$this->get_config('defaultenrol')) { return; } $header = $this->get_instance_name($instance); $config = has_capability('enrol/guest:config', $context); $mform->addElement('header', 'enrol_guest_header_' . $i, $header); $options = array(ENROL_INSTANCE_ENABLED => get_string('yes'), ENROL_INSTANCE_DISABLED => get_string('no')); $mform->addElement('select', 'enrol_guest_status_' . $i, get_string('status', 'enrol_guest'), $options); $mform->addHelpButton('enrol_guest_status_' . $i, 'status', 'enrol_guest'); $mform->setDefault('enrol_guest_status_' . $i, $this->get_config('status')); $mform->setAdvanced('enrol_guest_status_' . $i, $this->get_config('status_adv')); if (!$config) { $mform->hardFreeze('enrol_guest_status_' . $i); } $mform->addElement('passwordunmask', 'enrol_guest_password_' . $i, get_string('password', 'enrol_guest')); $mform->addHelpButton('enrol_guest_password_' . $i, 'password', 'enrol_guest'); if (!$config) { $mform->hardFreeze('enrol_guest_password_' . $i); } else { $mform->disabledIf('enrol_guest_password_' . $i, 'enrol_guest_status_' . $i, 'noteq', ENROL_INSTANCE_ENABLED); } // now add all values from enrol table if ($instance) { foreach ($instance as $key => $val) { $data->{'enrol_guest_' . $key . '_' . $i} = $val; } } }