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);
         }
     }
 }
Exemple #2
0
 /**
  * Adds controls specific to this filter in the form.
  *
  * @param moodleform $mform a MoodleQuickForm object in which element will be added
  */
 public function setupForm(MoodleQuickForm &$mform)
 {
     $objs = array();
     $objs[] = $mform->createElement('checkbox', $this->_name, null, '');
     $grp = $mform->addElement('group', $this->_name . '_grp', $this->_label, $objs, '', false);
     if ($this->_advanced) {
         $mform->setAdvanced($this->_name . '_grp');
     }
     //Check if disable if options are set. if yes then set rules
     if (!empty($this->disableelements) && is_array($this->disableelements)) {
         foreach ($this->disableelements as $disableelement) {
             $mform->disabledIf($disableelement, $this->_name, 'checked');
         }
     }
 }
 /**
  * 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;
 }
Exemple #4
0
 /**
  * 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;
         }
     }
 }
Exemple #5
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;
     $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);
     }
 }
 /**
  * Add question-type specific form fields.
  *
  * @param MoodleQuickForm $mform the form being built.
  */
 protected function definition_inner($mform)
 {
     global $CFG, $OUTPUT, $SESSION;
     require_once $CFG->dirroot . '/question/type/regexp/locallib.php';
     $this->showalternate = false;
     if ("" != optional_param('showalternate', '', PARAM_RAW)) {
         $this->showalternate = true;
         $this->questionid = optional_param('id', '', PARAM_NOTAGS);
         $this->usecase = optional_param('usecase', '', PARAM_NOTAGS);
         $this->studentshowalternate = optional_param('studentshowalternate', '', PARAM_NOTAGS);
         $this->fraction = optional_param_array('fraction', '', PARAM_RAW);
         $this->currentanswers = optional_param_array('answer', '', PARAM_NOTAGS);
         //$this->feedback = optional_param('feedback', '', PARAM_NOTAGS);
         // no longer works in moodle 2.2 and later see http://moodle.org/mod/forum/discuss.php?d=197118
         // so use data_submitted() instead
         $feedback = data_submitted()->feedback;
         // we only need to get the feedback text, for validation purposes when showalternate is requested
         foreach ($feedback as $key => $fb) {
             $this->feedback[$key]['text'] = clean_param($fb['text'], PARAM_NOTAGS);
         }
     }
     // JR added advanced settings to hide mostly unwanted hints and tags settings
     if ("" != optional_param('addhint', '', PARAM_RAW)) {
         $this->hints = optional_param('hint', '', PARAM_NOTAGS);
     } elseif (isset($this->question->hints)) {
         $this->hints = $this->question->hints;
     }
     $counthints = 0;
     if (isset($this->hints)) {
         $counthints = count($this->hints);
     }
     $mform->setAdvanced('tags');
     for ($i = 0; $i < $counthints; $i++) {
         $mform->setAdvanced("hint[{$i}]");
     }
     // hint mode :: None / Letter / Word
     $menu = array(get_string('none'), get_string('letter', 'qtype_regexp'), get_string('word', 'qtype_regexp'));
     $mform->addElement('select', 'usehint', get_string('usehint', 'qtype_regexp'), $menu);
     $mform->addHelpButton('usehint', 'usehint', 'qtype_regexp');
     // use case :: yes / no
     $menu = array(get_string('caseno', 'qtype_regexp'), get_string('caseyes', 'qtype_regexp'));
     $mform->addElement('select', 'usecase', get_string('casesensitive', 'qtype_regexp'), $menu);
     // display all correct alternate answers to student on review page :: yes / no
     $menu = array(get_string('no'), get_string('yes'));
     $mform->addElement('select', 'studentshowalternate', get_string('studentshowalternate', 'qtype_regexp'), $menu);
     $mform->addHelpButton('studentshowalternate', 'studentshowalternate', 'qtype_regexp');
     //$mform->closeHeaderBefore('answersinstruct');
     $mform->addElement('static', 'answersinstruct', 'Note.-', get_string('filloutoneanswer', 'qtype_regexp'));
     $this->add_per_answer_fields($mform, get_string('answerno', 'qtype_shortanswer', '{no}'), question_bank::fraction_options(), $minoptions = 3, $addoptions = 1);
     $mform->addElement('header', 'showhidealternate', get_string('showhidealternate', 'qtype_regexp'));
     $mform->addHelpButton('showhidealternate', 'showhidealternate', 'qtype_regexp');
     $buttonarray = array();
     $buttonarray[] = $mform->createElement('submit', 'showalternate', get_string('showalternate', 'qtype_regexp'));
     $mform->registerNoSubmitButton('showalternate');
     if ($this->showalternate) {
         $qu = new stdClass();
         $qu->id = $this->questionid;
         $qu->answers = array();
         $i = 0;
         $this->fraction[0] = 1;
         $data = array();
         foreach ($this->currentanswers as $key => $answer) {
             $qu->answers[$i] = new stdClass();
             $qu->answers[$i]->answer = $answer;
             $qu->answers[$i]->fraction = $this->fraction[$i];
             // for sending $data to validation
             $data['answer'][$i] = $answer;
             $data['fraction'][$i] = $this->fraction[$i];
             $data['feedback'][$i] = $this->feedback[$i];
             $i++;
         }
         $moodle_val = $this->validation($data, '');
         if (is_array($moodle_val) && count($moodle_val) !== 0) {
             // non-empty array means errors
             foreach ($moodle_val as $element => $msg) {
                 $mform->setElementError($element, $msg);
             }
             // set to false in order to set hidealternate button to disabled
             $this->showalternate = false;
         } else {
             // we need to unset SESSION in case Answers have been edited since last call to get_alternateanswers()
             if (isset($SESSION->qtype_regexp_question->alternateanswers[$this->questionid])) {
                 unset($SESSION->qtype_regexp_question->alternateanswers[$this->questionid]);
             }
             $alternateanswers = get_alternateanswers($qu);
             $mform->addElement('html', '<div class="alternateanswers">');
             $alternatelist = '';
             foreach ($alternateanswers as $key => $alternateanswer) {
                 $mform->addElement('static', 'alternateanswer', get_string('answer') . ' ' . $key . ' (' . $alternateanswer['fraction'] . ')', '<span class="regexp">' . $alternateanswer['regexp'] . '</span>');
                 $list = '';
                 foreach ($alternateanswer['answers'] as $alternate) {
                     $list .= '<li>' . $alternate . '</li>';
                 }
                 $mform->addElement('static', 'alternateanswer', '', '<ul class="square">' . $list . '</ul>');
             }
             $mform->addElement('html', '</div>');
         }
     }
     $disabled = '';
     if ($this->showalternate) {
         $disabled = '';
     } else {
         $disabled = 'disabled';
     }
     $buttonarray[] = $mform->createElement('submit', 'hidealternate', get_string('hidealternate', 'qtype_regexp'), $disabled);
     $mform->registerNoSubmitButton('hidealternate');
     $mform->addGroup($buttonarray, '', '', array(' '), false);
     $mform->addElement('header', 'multitriesheader', get_string('settingsformultipletries', 'qtype_regexp'));
     $withclearwrong = false;
     $withshownumpartscorrect = false;
     $penalties = array(1.0, 0.5, 0.33, 0.25, 0.2, 0.1, 0.05, 0.0);
     if (!empty($this->question->penalty) && !in_array($this->question->penalty, $penalties)) {
         $penalties[] = $this->question->penalty;
         sort($penalties);
     }
     $penaltyoptions = array();
     foreach ($penalties as $penalty) {
         $penaltyoptions["{$penalty}"] = 100 * $penalty . '%';
     }
     $mform->addElement('select', 'penalty', get_string('penaltyforeachincorrecttry', 'qtype_regexp'), $penaltyoptions);
     $mform->addRule('penalty', null, 'required', null, 'client');
     $mform->addHelpButton('penalty', 'penaltyforeachincorrecttry', 'qtype_regexp');
     $mform->setDefault('penalty', 0.1);
     if ($this->question->formoptions->repeatelements) {
         //$repeatsatstart = max(self::DEFAULT_NUM_HINTS, $counthints);
         // JR we suppose hints are not really needed in REGEXP question type, so set start nb at zero
         $repeatsatstart = max(0, $counthints);
     } else {
         $repeatsatstart = $counthints;
     }
     if ($counthints != 0) {
         $addhint = get_string('addanotherhint', 'question');
     } else {
         $addhint = get_string('addahint', 'qtype_regexp');
     }
     list($repeated, $repeatedoptions) = $this->get_hint_fields($withclearwrong, $withshownumpartscorrect);
     $this->repeat_elements($repeated, $repeatsatstart, $repeatedoptions, 'numhints', 'addhint', 1, $addhint);
 }
Exemple #7
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 $DB;
     $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');
     $tools = array();
     $tools[$context->id] = get_string('course');
     $modinfo = get_fast_modinfo($instance->courseid);
     $mods = $modinfo->get_cms();
     foreach ($mods as $mod) {
         $tools[$mod->context->id] = format_string($mod->name);
     }
     $mform->addElement('select', 'contextid', get_string('tooltobeprovided', 'enrol_lti'), $tools);
     $mform->setDefault('contextid', $context->id);
     $mform->addElement('duration', 'enrolperiod', get_string('enrolperiod', 'enrol_lti'), array('optional' => true, 'defaultunit' => DAYSECS));
     $mform->setDefault('enrolperiod', 0);
     $mform->addHelpButton('enrolperiod', 'enrolperiod', 'enrol_lti');
     $mform->addElement('date_time_selector', 'enrolstartdate', get_string('enrolstartdate', 'enrol_lti'), array('optional' => true));
     $mform->setDefault('enrolstartdate', 0);
     $mform->addHelpButton('enrolstartdate', 'enrolstartdate', 'enrol_lti');
     $mform->addElement('date_time_selector', 'enrolenddate', get_string('enrolenddate', 'enrol_lti'), array('optional' => true));
     $mform->setDefault('enrolenddate', 0);
     $mform->addHelpButton('enrolenddate', 'enrolenddate', 'enrol_lti');
     $mform->addElement('text', 'maxenrolled', get_string('maxenrolled', 'enrol_lti'));
     $mform->setDefault('maxenrolled', 0);
     $mform->addHelpButton('maxenrolled', 'maxenrolled', 'enrol_lti');
     $mform->setType('maxenrolled', PARAM_INT);
     $assignableroles = get_assignable_roles($context);
     $mform->addElement('select', 'roleinstructor', get_string('roleinstructor', 'enrol_lti'), $assignableroles);
     $mform->setDefault('roleinstructor', '3');
     $mform->addHelpButton('roleinstructor', 'roleinstructor', 'enrol_lti');
     $mform->addElement('select', 'rolelearner', get_string('rolelearner', 'enrol_lti'), $assignableroles);
     $mform->setDefault('rolelearner', '5');
     $mform->addHelpButton('rolelearner', 'rolelearner', 'enrol_lti');
     $mform->addElement('header', 'remotesystem', get_string('remotesystem', 'enrol_lti'));
     $mform->addElement('text', 'secret', get_string('secret', 'enrol_lti'), 'maxlength="64" size="25"');
     $mform->setType('secret', PARAM_ALPHANUM);
     $mform->setDefault('secret', random_string(32));
     $mform->addHelpButton('secret', 'secret', 'enrol_lti');
     $mform->addRule('secret', get_string('required'), 'required');
     $mform->addElement('selectyesno', 'gradesync', get_string('gradesync', 'enrol_lti'));
     $mform->setDefault('gradesync', 1);
     $mform->addHelpButton('gradesync', 'gradesync', 'enrol_lti');
     $mform->addElement('selectyesno', 'gradesynccompletion', get_string('requirecompletion', 'enrol_lti'));
     $mform->setDefault('gradesynccompletion', 0);
     $mform->disabledIf('gradesynccompletion', 'gradesync', 0);
     $mform->addElement('selectyesno', 'membersync', get_string('membersync', 'enrol_lti'));
     $mform->setDefault('membersync', 1);
     $mform->addHelpButton('membersync', 'membersync', 'enrol_lti');
     $options = array();
     $options[\enrol_lti\helper::MEMBER_SYNC_ENROL_AND_UNENROL] = get_string('membersyncmodeenrolandunenrol', 'enrol_lti');
     $options[\enrol_lti\helper::MEMBER_SYNC_ENROL_NEW] = get_string('membersyncmodeenrolnew', 'enrol_lti');
     $options[\enrol_lti\helper::MEMBER_SYNC_UNENROL_MISSING] = get_string('membersyncmodeunenrolmissing', 'enrol_lti');
     $mform->addElement('select', 'membersyncmode', get_string('membersyncmode', 'enrol_lti'), $options);
     $mform->setDefault('membersyncmode', \enrol_lti\helper::MEMBER_SYNC_ENROL_AND_UNENROL);
     $mform->addHelpButton('membersyncmode', 'membersyncmode', 'enrol_lti');
     $mform->disabledIf('membersyncmode', 'membersync', 0);
     $mform->addElement('header', 'defaultheader', get_string('userdefaultvalues', 'enrol_lti'));
     $emaildisplay = get_config('enrol_lti', 'emaildisplay');
     $choices = array(0 => get_string('emaildisplayno'), 1 => get_string('emaildisplayyes'), 2 => get_string('emaildisplaycourse'));
     $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
     $mform->setDefault('maildisplay', $emaildisplay);
     $city = get_config('enrol_lti', 'city');
     $mform->addElement('text', 'city', get_string('city'), 'maxlength="100" size="25"');
     $mform->setType('city', PARAM_TEXT);
     $mform->setDefault('city', $city);
     $country = get_config('enrol_lti', 'country');
     $countries = array('' => get_string('selectacountry') . '...') + get_string_manager()->get_list_of_countries();
     $mform->addElement('select', 'country', get_string('selectacountry'), $countries);
     $mform->setDefault('country', $country);
     $mform->setAdvanced('country');
     $timezone = get_config('enrol_lti', 'timezone');
     $choices = core_date::get_list_of_timezones(null, true);
     $mform->addElement('select', 'timezone', get_string('timezone'), $choices);
     $mform->setDefault('timezone', $timezone);
     $mform->setAdvanced('timezone');
     $lang = get_config('enrol_lti', 'lang');
     $mform->addElement('select', 'lang', get_string('preferredlanguage'), get_string_manager()->get_list_of_translations());
     $mform->setDefault('lang', $lang);
     $mform->setAdvanced('lang');
     $institution = get_config('enrol_lti', 'institution');
     $mform->addElement('text', 'institution', get_string('institution'), 'maxlength="40" size="25"');
     $mform->setType('institution', core_user::get_property_type('institution'));
     $mform->setDefault('institution', $institution);
     $mform->setAdvanced('institution');
     // Check if we are editing an instance.
     if (!empty($instance->id)) {
         // Get the details from the enrol_lti_tools table.
         $ltitool = $DB->get_record('enrol_lti_tools', array('enrolid' => $instance->id), '*', MUST_EXIST);
         $mform->addElement('hidden', 'toolid');
         $mform->setType('toolid', PARAM_INT);
         $mform->setConstant('toolid', $ltitool->id);
         $mform->setDefaults((array) $ltitool);
     }
 }
Exemple #8
0
 public static function add_settings_form_fields(mod_quiz_mod_form $quizform, MoodleQuickForm $mform)
 {
     global $CFG;
     // Allow to enable the access rule only if the Mobile services are enabled.
     if ($CFG->enablemobilewebservice) {
         $mform->addElement('selectyesno', 'allowofflineattempts', get_string('allowofflineattempts', 'quizaccess_offlineattempts'));
         $mform->addHelpButton('allowofflineattempts', 'allowofflineattempts', 'quizaccess_offlineattempts');
         $mform->setDefault('allowofflineattempts', 0);
         $mform->setAdvanced('allowofflineattempts');
         $mform->disabledIf('allowofflineattempts', 'timelimit[number]', 'neq', 0);
         $mform->disabledIf('allowofflineattempts', 'subnet', 'neq', '');
     }
 }