Exemplo n.º 1
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.º 2
0
 /**
  * Get form elements for grading form
  *
  * @param stdClass $grade
  * @param MoodleQuickForm $mform
  * @param stdClass $data
  * @param int $userid
  * @return bool true if elements were added to the form
  */
 public function get_form_elements_for_user($grade, MoodleQuickForm $mform, stdClass $data, $userid)
 {
     global $PAGE;
     $attempt = -1;
     if ($grade) {
         $attempt = $grade->attemptnumber;
     }
     $files = document_services::list_compatible_submission_files_for_attempt($this->setaskment, $userid, $attempt);
     // Only show the editor if there was a compatible file submitted.
     if (count($files)) {
         $renderer = $PAGE->get_renderer('setaskfeedback_editpdf');
         $widget = $this->get_widget($userid, $grade, false);
         $html = $renderer->render($widget);
         $mform->addElement('static', 'editpdf', get_string('editpdf', 'setaskfeedback_editpdf'), $html);
         $mform->addHelpButton('editpdf', 'editpdf', 'setaskfeedback_editpdf');
         $mform->addElement('hidden', 'editpdf_source_userid', $userid);
         $mform->setType('editpdf_source_userid', PARAM_INT);
         $mform->setConstant('editpdf_source_userid', $userid);
     }
 }
Exemplo n.º 3
0
Arquivo: lib.php Projeto: sree443/JNS
 /**
  * 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);
     if (!$i) {
         $config = guess_if_creator_will_have_course_capability('enrol/guest:config', $context);
     } else {
         $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);
         if (!$i) {
             $mform->setConstant('enrol_guest_status_' . $i, $this->get_config('status'));
         } else {
             $mform->setConstant('enrol_guest_status_' . $i, $instance->status);
         }
     }
     $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);
         if (!$i) {
             if ($this->get_config('requirepassword')) {
                 $password = generate_password(20);
             } else {
                 $password = '';
             }
             $mform->setConstant('enrol_guest_password_' . $i, $password);
         } else {
             $mform->setConstant('enrol_guest_password_' . $i, $instance->password);
         }
     } 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;
         }
     }
 }
Exemplo n.º 4
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);
     }
 }
Exemplo n.º 5
0
 /**
  * Get form elements for grading form
  *
  * @param stdClass $grade
  * @param MoodleQuickForm $mform
  * @param stdClass $data
  * @param int $userid
  * @return bool true if elements were added to the form
  */
 public function get_form_elements_for_user($grade, MoodleQuickForm $mform, stdClass $data, $userid)
 {
     global $PAGE;
     $attempt = -1;
     if ($grade) {
         $attempt = $grade->attemptnumber;
     }
     $renderer = $PAGE->get_renderer('assignfeedback_editpdf');
     $widget = $this->get_widget($userid, $grade, false);
     $html = $renderer->render($widget);
     $mform->addElement('static', 'editpdf', get_string('editpdf', 'assignfeedback_editpdf'), $html);
     $mform->addHelpButton('editpdf', 'editpdf', 'assignfeedback_editpdf');
     $mform->addElement('hidden', 'editpdf_source_userid', $userid);
     $mform->setType('editpdf_source_userid', PARAM_INT);
     $mform->setConstant('editpdf_source_userid', $userid);
 }
Exemplo n.º 6
0
 /**
  * Add elements to the edit instance form.
  *
  * @param stdClass $instance
  * @param MoodleQuickForm $mform
  * @param context $coursecontext
  * @return bool
  */
 public function edit_instance_form($instance, MoodleQuickForm $mform, $coursecontext)
 {
     global $DB;
     $mform->addElement('text', 'name', get_string('custominstancename', 'enrol'));
     $mform->setType('name', PARAM_TEXT);
     $options = $this->get_status_options();
     $mform->addElement('select', 'status', get_string('status', 'enrol_cohort'), $options);
     $options = $this->get_cohort_options($instance, $coursecontext);
     $mform->addElement('select', 'customint1', get_string('cohort', 'cohort'), $options);
     if ($instance->id) {
         $mform->setConstant('customint1', $instance->customint1);
         $mform->hardFreeze('customint1', $instance->customint1);
     } else {
         $mform->addRule('customint1', get_string('required'), 'required', null, 'client');
     }
     $roles = $this->get_role_options($instance, $coursecontext);
     $mform->addElement('select', 'roleid', get_string('assignrole', 'enrol_cohort'), $roles);
     $mform->setDefault('roleid', $this->get_config('roleid'));
     $groups = $this->get_group_options($coursecontext);
     $mform->addElement('select', 'customint2', get_string('addgroup', 'enrol_cohort'), $groups);
 }