本文整理汇总了PHP中MoodleQuickForm::setConstant方法的典型用法代码示例。如果您正苦于以下问题:PHP MoodleQuickForm::setConstant方法的具体用法?PHP MoodleQuickForm::setConstant怎么用?PHP MoodleQuickForm::setConstant使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MoodleQuickForm
的用法示例。
在下文中一共展示了MoodleQuickForm::setConstant方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: edit_instance_form
/**
* 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);
}
//.........这里部分代码省略.........
示例2: get_form_elements_for_user
/**
* 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);
}
}
示例3: course_edit_form
/**
* 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;
}
}
}
示例4: get_form_elements_for_user
/**
* 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);
}