コード例 #1
0
 /**
  * Load in existing data as form defaults. Usually new entry defaults are stored directly in
  * form definition (new entry form); this function is used to load in data where values
  * already exist and data is being edited (edit entry form).
  *
  * note: $slashed param removed
  *
  * @param mixed $default_values object or array of default values
  * @param bool $slased true if magic quotes applied to data values
  */
 function set_data($default_values)
 {
     if (is_object($default_values)) {
         $default_values = (array) $default_values;
     }
     $this->_form->setDefaults($default_values);
 }
コード例 #2
0
 /**
  * Load in existing data as form defaults. Usually new entry defaults are stored directly in
  * form definition (new entry form); this function is used to load in data where values
  * already exist and data is being edited (edit entry form).
  *
  * @param mixed $default_values object or array of default values
  * @param bool $slased true if magic quotes applied to data values
  */
 function set_data($default_values, $slashed = false)
 {
     if (is_object($default_values)) {
         $default_values = (array) $default_values;
     }
     $filter = $slashed ? 'stripslashes' : NULL;
     $this->_form->setDefaults($default_values, $filter);
 }
コード例 #3
0
ファイル: formslib.php プロジェクト: veritech/pare-project
 /**
  * Load in existing data as form defaults. Usually new entry defaults are stored directly in
  * form definition (new entry form); this function is used to load in data where values
  * already exist and data is being edited (edit entry form).
  *
  * @param mixed $default_values object or array of default values
  * @param bool $slased true if magic quotes applied to data values
  */
 function set_data($default_values, $slashed = false)
 {
     if (is_object($default_values)) {
         $default_values = (array) $default_values;
     }
     $filter = $slashed ? 'stripslashes' : NULL;
     $this->_form->setDefaults($default_values, $filter);
     //update form definition when data changed
     $this->definition_after_data();
 }
コード例 #4
0
ファイル: lib.php プロジェクト: evltuma/moodle
 /**
  * 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);
     }
 }
コード例 #5
0
 /**
  * Initializes default form values.
  *
  * Edited to decode the html in htmleditor elements.
  *
  * @param     array    $defaultValues       values used to fill the form
  * @param     mixed    $filter              (optional) filter(s) to apply to all default values
  * @since     1.0
  * @access    public
  * @return    void
  */
 function setDefaults($defaultValues = null, $filter = null)
 {
     parent::setDefaults($defaultValues, $filter);
     // decode the values for htmleditor elements
     foreach ($this->_defaultValues as $name => &$value) {
         if ($this->getElementType($name) == 'htmleditor') {
             /********NEEDS ATTENTION*******/
             //need to replace assmgr_db::decode with a function for ilp
             $this->_defaultValues[$name] = ilp_db::decode($value);
         }
     }
     // reinitialise each of the elements
     foreach (array_keys($this->_elements) as $key) {
         $this->_elements[$key]->onQuickFormEvent('updateValue', null, $this);
     }
 }