当前位置: 首页>>代码示例>>PHP>>正文


PHP MoodleQuickForm::addRule方法代码示例

本文整理汇总了PHP中MoodleQuickForm::addRule方法的典型用法代码示例。如果您正苦于以下问题:PHP MoodleQuickForm::addRule方法的具体用法?PHP MoodleQuickForm::addRule怎么用?PHP MoodleQuickForm::addRule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MoodleQuickForm的用法示例。


在下文中一共展示了MoodleQuickForm::addRule方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: get_form_elements

 /**
  * Get form elements for the grading page
  *
  * @param stdClass|null $grade
  * @param MoodleQuickForm $mform
  * @param stdClass $data
  * @return bool true if elements were added to the form
  */
 public function get_form_elements($grade, MoodleQuickForm $mform, stdClass $data)
 {
     $choices = get_string_manager()->get_list_of_countries();
     $choices = array('' => get_string('selectacountry') . '...') + $choices;
     $mform->addElement('select', 'country', 'Country for E-signature', $choices);
     $mform->addElement('static', 'description', '', get_string('savechanges', 'assignfeedback_esign'));
     $mform->setDefault('country', 'SE');
     $mform->addRule('country', get_string('selectacountry'), 'required', '', 'client', false, false);
     return true;
 }
开发者ID:dsv-su,项目名称:moodle-assignfeedback_esign,代码行数:18,代码来源:locallib.php

示例2: 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);
     }
//.........这里部分代码省略.........
开发者ID:evltuma,项目名称:moodle,代码行数:101,代码来源:lib.php

示例3: add_submission_form_elements

 /**
  * Add elements to submission form.
  * @param MoodleQuickForm $mform
  * @param stdClass $data
  * @return void
  */
 public function add_submission_form_elements(MoodleQuickForm $mform, stdClass $data)
 {
     global $USER;
     // Team submissions.
     if ($this->get_instance()->teamsubmission) {
         $submission = $this->get_group_submission($USER->id, 0, false);
     } else {
         $submission = $this->get_user_submission($USER->id, false);
     }
     // Submission statement.
     $adminconfig = $this->get_admin_config();
     $requiresubmissionstatement = $this->get_instance()->requiresubmissionstatement && !empty($adminconfig->submissionstatement);
     $draftsenabled = $this->get_instance()->submissiondrafts;
     if ($requiresubmissionstatement && !$draftsenabled) {
         $submissionstatement = '';
         if (!empty($adminconfig->submissionstatement)) {
             $submissionstatement = $adminconfig->submissionstatement;
         }
         $mform->addElement('checkbox', 'submissionstatement', '', ' ' . $submissionstatement);
         $mform->addRule('submissionstatement', get_string('required'), 'required', null, 'client');
     }
     $this->add_plugin_submission_elements($submission, $mform, $data, $USER->id);
     // Hidden params.
     $mform->addElement('hidden', 'id', $this->get_course_module()->id);
     $mform->setType('id', PARAM_INT);
     $mform->addElement('hidden', 'action', 'savesubmission');
     $mform->setType('action', PARAM_TEXT);
 }
开发者ID:covex-nn,项目名称:moodle,代码行数:34,代码来源:locallib.php

示例4: add_submission_form_elements

 /**
  * Add elements to submission form.
  * @param MoodleQuickForm $mform
  * @param stdClass $data
  * @return void
  */
 public function add_submission_form_elements(MoodleQuickForm $mform, stdClass $data)
 {
     global $USER;
     $userid = $data->userid;
     // Team submissions.
     if ($this->get_instance()->teamsubmission) {
         $submission = $this->get_group_submission($userid, 0, false);
     } else {
         $submission = $this->get_user_submission($userid, false);
     }
     // Submission statement.
     $adminconfig = $this->get_admin_config();
     $requiresubmissionstatement = $this->get_instance()->requiresubmissionstatement && !empty($adminconfig->submissionstatement);
     $draftsenabled = $this->get_instance()->submissiondrafts;
     // Only show submission statement if we are editing our own submission.
     if ($requiresubmissionstatement && !$draftsenabled && $userid == $USER->id) {
         $submissionstatement = '';
         if (!empty($adminconfig->submissionstatement)) {
             // Format the submission statement before its sent. We turn off para because this is going within
             // a form element.
             $options = array('context' => $this->get_context(), 'para' => false);
             $submissionstatement = format_text($adminconfig->submissionstatement, FORMAT_MOODLE, $options);
         }
         $mform->addElement('checkbox', 'submissionstatement', '', $submissionstatement);
         $mform->addRule('submissionstatement', get_string('required'), 'required', null, 'client');
     }
     $this->add_plugin_submission_elements($submission, $mform, $data, $userid);
     // Hidden params.
     $mform->addElement('hidden', 'id', $this->get_course_module()->id);
     $mform->setType('id', PARAM_INT);
     $mform->addElement('hidden', 'userid', $userid);
     $mform->setType('userid', PARAM_INT);
     $mform->addElement('hidden', 'action', 'savesubmission');
     $mform->setType('action', PARAM_TEXT);
 }
开发者ID:mercysmart,项目名称:naikelas,代码行数:41,代码来源:locallib.php

示例5: form_choices

 protected function form_choices(\MoodleQuickForm $mform, array $choices, $helpname = '')
 {
     $numchoices = count($choices);
     $allchoices = '';
     foreach ($choices as $choice) {
         if (!empty($allchoices)) {
             $allchoices .= "\n";
         }
         $allchoices .= $choice->content;
     }
     if (empty($helpname)) {
         $helpname = $this->helpname();
     }
     $mform->addElement('html', '<div class="qoptcontainer">');
     $options = array('wrap' => 'virtual', 'class' => 'qopts');
     $mform->addElement('textarea', 'allchoices', get_string('possibleanswers', 'questionnaire'), $options);
     $mform->setType('allchoices', PARAM_RAW);
     $mform->addRule('allchoices', null, 'required', null, 'client');
     $mform->addHelpButton('allchoices', $helpname, 'questionnaire');
     $mform->addElement('html', '</div>');
     $mform->addElement('hidden', 'num_choices', $numchoices);
     $mform->setType('num_choices', PARAM_INT);
     return $allchoices;
 }
开发者ID:remotelearner,项目名称:moodle-mod_questionnaire,代码行数:24,代码来源:base.php

示例6: edit_instance_form

 /**
  * 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;
     $courses = $this->get_course_options($instance, $coursecontext);
     $groups = $this->get_group_options($coursecontext);
     $mform->addElement('select', 'customint1', get_string('linkedcourse', 'enrol_meta'), $courses);
     $mform->addRule('customint1', get_string('required'), 'required', null, 'client');
     if (!empty($instance->id)) {
         $mform->freeze('customint1');
     }
     $mform->addElement('select', 'customint2', get_string('addgroup', 'enrol_meta'), $groups);
 }
开发者ID:kevin-bruton,项目名称:moodle,代码行数:20,代码来源:lib.php

示例7: edit_instance_form

 /**
  * 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;
     $groups = $this->get_group_options($coursecontext);
     $existing = $DB->get_records('enrol', array('enrol' => 'meta', 'courseid' => $coursecontext->instanceid), '', 'customint1, id');
     $excludelist = array($coursecontext->instanceid);
     foreach ($existing as $existinginstance) {
         $excludelist[] = $existinginstance->customint1;
     }
     $options = array('requiredcapabilities' => array('enrol/meta:selectaslinked'), 'multiple' => empty($instance->id), 'exclude' => $excludelist);
     $mform->addElement('course', 'customint1', get_string('linkedcourse', 'enrol_meta'), $options);
     $mform->addRule('customint1', get_string('required'), 'required', null, 'client');
     if (!empty($instance->id)) {
         $mform->freeze('customint1');
     }
     $mform->addElement('select', 'customint2', get_string('addgroup', 'enrol_meta'), $groups);
 }
开发者ID:lucaboesch,项目名称:moodle,代码行数:25,代码来源:lib.php

示例8: get_form_elements

 /**
  * Add elements to submission form
  *
  * @param mixed $submission stdClass|null
  * @param MoodleQuickForm $mform
  * @param stdClass $data
  * @return bool
  */
 public function get_form_elements($submission, MoodleQuickForm $mform, stdClass $data)
 {
     global $DB;
     if ($this->get_config('maxfilesubmissions') <= 0) {
         return false;
     }
     $fileoptions = $this->get_file_options();
     $submissionid = $submission ? $submission->id : 0;
     $context = $this->assignment->get_context();
     $fs = get_file_storage();
     $coversheetfiles = $fs->get_area_files($context->id, 'assignsubmission_pdf', ASSIGNSUBMISSION_PDF_FA_COVERSHEET, false, '', false);
     if ($coversheetfiles) {
         $file = reset($coversheetfiles);
         $fileurl = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), null, $file->get_filepath(), $file->get_filename());
         $filelink = html_writer::link($fileurl, $file->get_filename(), array('target' => '_blank'));
         $mform->addElement('static', 'pdf_coversheet', '', get_string('coversheetnotice', 'assignsubmission_pdf') . ': ' . $filelink);
     }
     file_prepare_standard_filemanager($data, 'pdfs', $fileoptions, $this->assignment->get_context(), 'assignsubmission_pdf', ASSIGNSUBMISSION_PDF_FA_DRAFT, $submissionid);
     $label = html_writer::tag('span', get_string('pdfsubmissions', 'assignsubmission_pdf'), array('class' => 'accesshide'));
     $mform->addElement('filemanager', 'pdfs_filemanager', $label, null, $fileoptions);
     if ($coversheetfiles) {
         if ($templateid = $this->get_config('templateid')) {
             $templateitems = $DB->get_records('assignsubmission_pdf_tmplit', array('templateid' => $templateid));
             $templatedata = array();
             if ($submissionid) {
                 if ($templatedata = $DB->get_field('assignsubmission_pdf', 'templatedata', array('submission' => $submissionid))) {
                     $templatedata = unserialize($templatedata);
                 }
             }
             foreach ($templateitems as $item) {
                 $elname = "pdf_template[{$item->id}]";
                 if ($item->type == 'shorttext') {
                     $mform->addElement('text', $elname, s($item->setting));
                 } else {
                     if ($item->type == 'text') {
                         $mform->addElement('textarea', $elname, s($item->setting));
                     } else {
                         continue;
                     }
                 }
                 $mform->setType($elname, PARAM_TEXT);
                 $mform->addRule($elname, null, 'required', null, 'client');
                 if (isset($templatedata[$item->id])) {
                     $mform->setDefault($elname, $templatedata[$item->id]);
                 }
             }
         }
     }
     return true;
 }
开发者ID:tyleung,项目名称:CMPUT401MoodleExams,代码行数:58,代码来源:locallib.php

示例9: add_choice_group

 /**
  * method to add choice options to the form
  *
  * @param MoodleQuickForm $mform form
  * @param unknown $choice choice (new (negative id) or existing)
  */
 private function add_choice_group(MoodleQuickForm $mform, $choice)
 {
     $elemprefix = 'choices_' . $choice->id . '_';
     $mform->addElement('hidden', $elemprefix . 'id', $choice->id);
     // Save the record's id.
     $mform->setType($elemprefix . 'id', PARAM_INT);
     $elementname = 'fieldset_edit_choice' . $choice->id;
     $mform->addElement('header', $elementname, get_string('edit_choice', self::MOD_NAME, $choice->title));
     $mform->insertElementBefore($mform->removeElement($elementname, false), self::CHOICE_PLACEHOLDER_IDENTIFIER);
     $elementname = $elemprefix . 'title';
     $mform->addElement('text', $elementname, get_string('choice_title', self::MOD_NAME));
     $mform->setDefault($elementname, $choice->title);
     $mform->setType($elementname, PARAM_TEXT);
     $mform->addHelpButton($elementname, 'choice_title', self::MOD_NAME);
     $mform->insertElementBefore($mform->removeElement($elementname, false), self::CHOICE_PLACEHOLDER_IDENTIFIER);
     $mform->addRule($elementname, $this->msgerrorrequired, 'required', null, 'server');
     $elementname = $elemprefix . 'explanation';
     $mform->addElement('text', $elementname, get_string('choice_explanation', self::MOD_NAME));
     $mform->insertElementBefore($mform->removeElement($elementname, false), self::CHOICE_PLACEHOLDER_IDENTIFIER);
     $mform->setDefault($elementname, $choice->explanation);
     $mform->setType($elementname, PARAM_TEXT);
     $elementname = $elemprefix . 'maxsize';
     $mform->addElement('text', $elementname, get_string('choice_maxsize', self::MOD_NAME));
     $mform->insertElementBefore($mform->removeElement($elementname, false), self::CHOICE_PLACEHOLDER_IDENTIFIER);
     $mform->setDefault($elementname, $choice->maxsize);
     $mform->setType($elementname, PARAM_INT);
     $mform->addRule($elementname, $this->msgerrorrequired, 'required', null, 'server');
     $elementname = $elemprefix . 'active';
     $checkbox = $mform->addElement('advcheckbox', $elementname, get_string('choice_active', self::MOD_NAME), null, null, array(0, 1));
     $mform->insertElementBefore($mform->removeElement($elementname, false), self::CHOICE_PLACEHOLDER_IDENTIFIER);
     $mform->setDefault($elementname, $choice->active);
     $mform->addHelpButton($elementname, 'choice_active', self::MOD_NAME);
     $elementname = self::DELETE_CHOICE_ACTION . $choice->id;
     $mform->registerNoSubmitButton($elementname);
     $mform->addElement('submit', $elementname, get_string('deletechoice', self::MOD_NAME));
     $mform->insertElementBefore($mform->removeElement($elementname, false), self::CHOICE_PLACEHOLDER_IDENTIFIER);
 }
开发者ID:andrewhancox,项目名称:moodle-mod_ratingallocate,代码行数:43,代码来源:mod_form.php


注:本文中的MoodleQuickForm::addRule方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。