Exemplo n.º 1
0
Arquivo: lib.php Projeto: dg711/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 $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('select', 'customint4', get_string('sendcoursewelcomemessage', 'enrol_self'), enrol_send_welcome_email_options());
     $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
    $options = array(ENROL_EXT_REMOVED_KEEP => get_string('extremovedkeep', 'enrol'), ENROL_EXT_REMOVED_SUSPENDNOROLES => get_string('extremovedsuspendnoroles', 'enrol'), ENROL_EXT_REMOVED_UNENROL => get_string('extremovedunenrol', 'enrol'));
    $settings->add(new admin_setting_configselect('enrol_self/expiredaction', get_string('expiredaction', 'enrol_self'), get_string('expiredaction_help', 'enrol_self'), ENROL_EXT_REMOVED_KEEP, $options));
    $options = array();
    for ($i = 0; $i < 24; $i++) {
        $options[$i] = $i;
    }
    $settings->add(new admin_setting_configselect('enrol_self/expirynotifyhour', get_string('expirynotifyhour', 'core_enrol'), '', 6, $options));
    //--- enrol instance defaults ----------------------------------------------------------------------------
    $settings->add(new admin_setting_heading('enrol_self_defaults', get_string('enrolinstancedefaults', 'admin'), get_string('enrolinstancedefaults_desc', 'admin')));
    $settings->add(new admin_setting_configcheckbox('enrol_self/defaultenrol', get_string('defaultenrol', 'enrol'), get_string('defaultenrol_desc', 'enrol'), 1));
    $options = array(ENROL_INSTANCE_ENABLED => get_string('yes'), ENROL_INSTANCE_DISABLED => get_string('no'));
    $settings->add(new admin_setting_configselect('enrol_self/status', get_string('status', 'enrol_self'), get_string('status_desc', 'enrol_self'), ENROL_INSTANCE_DISABLED, $options));
    $options = array(1 => get_string('yes'), 0 => get_string('no'));
    $settings->add(new admin_setting_configselect('enrol_self/newenrols', get_string('newenrols', 'enrol_self'), get_string('newenrols_desc', 'enrol_self'), 1, $options));
    $options = array(1 => get_string('yes'), 0 => get_string('no'));
    $settings->add(new admin_setting_configselect('enrol_self/groupkey', get_string('groupkey', 'enrol_self'), get_string('groupkey_desc', 'enrol_self'), 0, $options));
    if (!during_initial_install()) {
        $options = get_default_enrol_roles(context_system::instance());
        $student = get_archetype_roles('student');
        $student = reset($student);
        $settings->add(new admin_setting_configselect('enrol_self/roleid', get_string('defaultrole', 'enrol_self'), get_string('defaultrole_desc', 'enrol_self'), $student->id, $options));
    }
    $settings->add(new admin_setting_configduration('enrol_self/enrolperiod', get_string('enrolperiod', 'enrol_self'), get_string('enrolperiod_desc', 'enrol_self'), 0));
    $options = array(0 => get_string('no'), 1 => get_string('expirynotifyenroller', 'core_enrol'), 2 => get_string('expirynotifyall', 'core_enrol'));
    $settings->add(new admin_setting_configselect('enrol_self/expirynotify', get_string('expirynotify', 'core_enrol'), get_string('expirynotify_help', 'core_enrol'), 0, $options));
    $settings->add(new admin_setting_configduration('enrol_self/expirythreshold', get_string('expirythreshold', 'core_enrol'), get_string('expirythreshold_help', 'core_enrol'), 86400, 86400));
    $options = array(0 => get_string('never'), 1800 * 3600 * 24 => get_string('numdays', '', 1800), 1000 * 3600 * 24 => get_string('numdays', '', 1000), 365 * 3600 * 24 => get_string('numdays', '', 365), 180 * 3600 * 24 => get_string('numdays', '', 180), 150 * 3600 * 24 => get_string('numdays', '', 150), 120 * 3600 * 24 => get_string('numdays', '', 120), 90 * 3600 * 24 => get_string('numdays', '', 90), 60 * 3600 * 24 => get_string('numdays', '', 60), 30 * 3600 * 24 => get_string('numdays', '', 30), 21 * 3600 * 24 => get_string('numdays', '', 21), 14 * 3600 * 24 => get_string('numdays', '', 14), 7 * 3600 * 24 => get_string('numdays', '', 7));
    $settings->add(new admin_setting_configselect('enrol_self/longtimenosee', get_string('longtimenosee', 'enrol_self'), get_string('longtimenosee_help', 'enrol_self'), 0, $options));
    $settings->add(new admin_setting_configtext('enrol_self/maxenrolled', get_string('maxenrolled', 'enrol_self'), get_string('maxenrolled_help', 'enrol_self'), 0, PARAM_INT));
    $settings->add(new admin_setting_configselect('enrol_self/sendcoursewelcomemessage', get_string('sendcoursewelcomemessage', 'enrol_self'), get_string('sendcoursewelcomemessage_help', 'enrol_self'), ENROL_SEND_EMAIL_FROM_COURSE_CONTACT, enrol_send_welcome_email_options()));
}