protected function standard_attempt_fields(MoodleQuickForm $mform)
 {
     $mform->addElement('select', 'attempts', get_string('reportattemptsfrom', 'quiz'), array(quiz_attempts_report::ENROLLED_WITH => get_string('reportuserswith', 'quiz'), quiz_attempts_report::ENROLLED_WITHOUT => get_string('reportuserswithout', 'quiz'), quiz_attempts_report::ENROLLED_ALL => get_string('reportuserswithorwithout', 'quiz'), quiz_attempts_report::ALL_WITH => get_string('reportusersall', 'quiz')));
     $stategroup = array($mform->createElement('advcheckbox', 'stateinprogress', '', get_string('stateinprogress', 'quiz')), $mform->createElement('advcheckbox', 'stateoverdue', '', get_string('stateoverdue', 'quiz')), $mform->createElement('advcheckbox', 'statefinished', '', get_string('statefinished', 'quiz')), $mform->createElement('advcheckbox', 'stateabandoned', '', get_string('stateabandoned', 'quiz')));
     $mform->addGroup($stategroup, 'stateoptions', get_string('reportattemptsthatare', 'quiz'), array(' '), false);
     $mform->setDefault('stateinprogress', 1);
     $mform->setDefault('stateoverdue', 1);
     $mform->setDefault('statefinished', 1);
     $mform->setDefault('stateabandoned', 1);
     $mform->disabledIf('stateinprogress', 'attempts', 'eq', quiz_attempts_report::ENROLLED_WITHOUT);
     $mform->disabledIf('stateoverdue', 'attempts', 'eq', quiz_attempts_report::ENROLLED_WITHOUT);
     $mform->disabledIf('statefinished', 'attempts', 'eq', quiz_attempts_report::ENROLLED_WITHOUT);
     $mform->disabledIf('stateabandoned', 'attempts', 'eq', quiz_attempts_report::ENROLLED_WITHOUT);
     if (quiz_report_can_filter_only_graded($this->_customdata['quiz'])) {
         $gm = html_writer::tag('span', quiz_get_grading_option_name($this->_customdata['quiz']->grademethod), array('class' => 'highlight'));
         $mform->addElement('advcheckbox', 'onlygraded', get_string('reportshowonly', 'quiz'), get_string('optonlygradedattempts', 'quiz_overview', $gm));
         $mform->disabledIf('onlygraded', 'attempts', 'eq', quiz_attempts_report::ENROLLED_WITHOUT);
         $mform->disabledIf('onlygraded', 'statefinished', 'notchecked');
     }
 }
 /**
  * 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);
 }
 /**
  * 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));
 }
Exemplo n.º 4
0
 /**
  * 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);
 }
Exemplo n.º 5
0
 /**
  * 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);
 }
 /**
  * @param MoodleQuickForm $mform
  */
 protected function specific_definition(MoodleQuickForm $mform)
 {
     $mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));
     $options = ['tree' => get_string('config_type_tree', 'block_activity_tree'), 'prev_next' => get_string('config_type_prev_next', 'block_activity_tree')];
     $mform->addElement('select', 'config_type', get_string('config_type', 'block_activity_tree'), $options);
     $mform->setDefault('config_type', 'tree');
 }
 /**
  * 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);
 }
Exemplo n.º 8
0
 /**
  * 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);
 }
Exemplo n.º 9
0
 /**
  * @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);
 }
 /**
  * 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);
 }
Exemplo n.º 11
0
 /**
  * Get form elements for the grading page
  *
  * @param stdClass|null $grade
  * @param MoodleQuickForm $mform
  * @param stdClass $data
  * @return bool true if elements were added to the form
  */
 public function get_form_elements($grade, MoodleQuickForm $mform, stdClass $data)
 {
     $choices = get_string_manager()->get_list_of_countries();
     $choices = array('' => get_string('selectacountry') . '...') + $choices;
     $mform->addElement('select', 'country', 'Country for E-signature', $choices);
     $mform->addElement('static', 'description', '', get_string('savechanges', 'assignfeedback_esign'));
     $mform->setDefault('country', 'SE');
     $mform->addRule('country', get_string('selectacountry'), 'required', '', 'client', false, false);
     return true;
 }
Exemplo n.º 12
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');
 }
Exemplo n.º 13
0
 /**
  * @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);
 }
Exemplo n.º 14
0
 /**
  * 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');
     }
 }
 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);
         }
     }
 }
Exemplo n.º 16
0
 /**
  * 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);
 }
Exemplo n.º 17
0
 /**
  * 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');
 }
Exemplo n.º 18
0
 /**
  * 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');
     }
 }
Exemplo n.º 19
0
 /**
  * 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');
 }
 /**
  * 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));
 }
Exemplo n.º 21
0
 /**
  * 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;
 }
Exemplo n.º 22
0
 /**
  * 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;
 }
Exemplo n.º 23
0
 /**
  * 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);
     }
 }
Exemplo n.º 24
0
 /**
  * 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);
 }
Exemplo n.º 25
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();
 }
Exemplo n.º 26
0
    /**
     *  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.'&amp;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.'&amp;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.'">&nbsp;</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.'">&nbsp;</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.'">&nbsp;</div>';
                        $teachermodified = '<div id="tt'.$auser->id.'">&nbsp;</div>';
                        $status          = '<div id="st'.$auser->id.'">&nbsp;</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.'">&nbsp;</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
                               . '&amp;userid='.$auser->id.'&amp;mode=single'.'&amp;filter='.$filter.'&amp;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 . '&amp;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();
    }
Exemplo n.º 27
0
 /**
  * Renders a search form
  *
  * @param string $search Search string
  * @return string HTML
  */
 protected function helper_search_form($search)
 {
     global $CFG;
     require_once $CFG->libdir . '/formslib.php';
     $mform = new MoodleQuickForm('searchform', 'POST', $this->page->url);
     $mform->addElement('hidden', 'sesskey', sesskey());
     $el[] = $mform->createElement('text', 'search', get_string('search'), array('size' => 20));
     $mform->setDefault('search', $search);
     $el[] = $mform->createElement('submit', 'submitsearch', get_string('search'));
     $el[] = $mform->createElement('submit', 'clearsearch', get_string('clear'));
     $mform->addGroup($el, 'searchgroup', get_string('searchname', 'badges'), ' ', false);
     ob_start();
     $mform->display();
     $out = ob_get_clean();
     return $out;
 }
Exemplo n.º 28
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'];
        $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);
    }
Exemplo n.º 29
0
 /**
  * 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;
 }
 /**
  * Adds the combobox to select penalty for each incorrectly selected area.
  * By default 12.5% (1/8) is selected 
  * 
  * @param MoodleQuickForm $mform
  */
 protected function add_penalty_fields($mform)
 {
     $fldname = 'vd_penalty';
     $mform->addElement('select', $fldname, get_string('penalty_per_wrong_area', 'qtype_vdmarker'), question_bank::fraction_options());
     $mform->setDefault($fldname, 1.0);
 }