コード例 #1
0
 public function definition()
 {
     $mform =& $this->_form;
     // General settings -------------------------------------------------------------
     /// Adding the "general" fieldset, where all the common settings are showed
     $mform->addElement('header', 'general', get_string('general', 'form'));
     /// Adding the standard "name" field
     $mform->addElement('text', 'name', get_string('subcoursename', 'subcourse'), array('size' => '64'));
     $mform->setType('name', PARAM_TEXT);
     $mform->addRule('name', null, 'required', null, 'client');
     /// Adding the optional "intro" and "introformat" pair of fields
     $this->add_intro_editor(true, get_string('subcourseintro', 'subcourse'));
     // Subcourse information --------------------------------------------------------
     $mform->addElement('header', 'subcoursefieldset', get_string('refcourse', 'subcourse'));
     /// Referenced course selector
     $mycourses = subcourse_available_courses();
     $catlist = array();
     $catparents = array();
     make_categories_list($catlist, $catparents);
     $options = array();
     foreach ($mycourses as $mycourse) {
         if (empty($options[$catlist[$mycourse->category]])) {
             $options[$catlist[$mycourse->category]] = array();
         }
         $courselabel = $mycourse->fullname . ' (' . $mycourse->shortname . ')';
         $options[$catlist[$mycourse->category]][$mycourse->id] = $courselabel;
         if (empty($mycourse->visible)) {
             $hiddenlabel = ' ' . get_string('hiddencourse', 'subcourse');
             $options[$catlist[$mycourse->category]][$mycourse->id] .= $hiddenlabel;
         }
     }
     unset($mycourse);
     /**
      * @var $refcourseelement HTML_QuickForm_input
      */
     $refcourseelement = $mform->addElement('selectgroups', 'refcourse', get_string('refcourselabel', 'subcourse'), $options);
     $mform->addHelpButton('refcourse', 'refcourse', 'subcourse');
     // Option to add a meta course enrolment to the other course.
     /**
      * @var $addmetaelement HTML_QuickForm_input
      */
     $addmetaelement = $mform->addElement('checkbox', 'addmeta', get_string('addmeta', 'subcourse'));
     // If there is a meta enrolment already, we don't want to allow people to delete it as we
     // may cause problems. Force them to delete the whole subcourse if they want to do this
     if (!empty($this->current->id)) {
         $metaexists = subcourse_meta_exists($this->current->course, $this->current->refcourse);
         if ($metaexists) {
             $mform->setDefault('addmeta', 'checked');
             $refcourseelement->updateAttributes(array('disabled' => true));
             $addmetaelement->updateAttributes(array('disabled' => true));
         }
     }
     // add standard elements, common to all modules
     $this->standard_coursemodule_elements();
     // add standard buttons, common to all modules
     $this->add_action_buttons();
 }
コード例 #2
0
 /**
  * Form fields definition
  */
 public function definition()
 {
     global $CFG, $DB, $COURSE;
     $mform = $this->_form;
     // General -------------------------------------------------------------
     $mform->addElement('header', 'general', get_string('general', 'form'));
     $mform->addElement('text', 'name', get_string('subcoursename', 'subcourse'), array('size' => '64'));
     if (!empty($CFG->formatstringstriptags)) {
         $mform->setType('name', PARAM_TEXT);
     } else {
         $mform->setType('name', PARAM_CLEANHTML);
     }
     $mform->addRule('name', null, 'required', null, 'client');
     $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
     if ($CFG->branch >= 29) {
         $this->standard_intro_elements();
     } else {
         $this->add_intro_editor();
     }
     // Referenced course ---------------------------------------------------
     $mform->addElement('header', 'section-refcourse', get_string('refcourse', 'subcourse'));
     $mform->setExpanded('section-refcourse');
     $mform->addHelpButton('section-refcourse', 'refcourse', 'subcourse');
     $mycourses = subcourse_available_courses();
     $currentrefcourseid = isset($this->current->refcourse) ? $this->current->refcourse : null;
     $currentrefcoursename = null;
     $currentrefcourseavailable = false;
     if (!empty($currentrefcourseid)) {
         if ($currentrefcourseid == $COURSE->id) {
             // Invalid self-reference.
             $this->current->refcourse = 0;
             $includenoref = true;
         } else {
             $currentrefcoursename = $DB->get_field('course', 'fullname', array('id' => $currentrefcourseid), IGNORE_MISSING);
         }
         if ($currentrefcoursename === false) {
             // Reference to non-existing course.
             $this->current->refcourse = 0;
             $includenoref = true;
         } else {
             // Check if the currently set value is still available.
             foreach ($mycourses as $mycourse) {
                 if ($mycourse->id == $currentrefcourseid) {
                     $currentrefcourseavailable = true;
                     break;
                 }
             }
         }
     }
     if (!empty($currentrefcourseid) and !$currentrefcourseavailable) {
         // Currently referring to a course that is not available for us (e.g. the admin
         // has set up this Subcourse for the teacher or the teacher lost his role in the referred
         // course etc. Give them a chance to just keep such a reference.
         $mform->addElement('checkbox', 'refcoursecurrent', get_string('refcoursecurrent', 'subcourse'), format_string($currentrefcoursename));
         $mform->setDefault('refcoursecurrent', 1);
         $includekeepref = true;
     }
     $options = array();
     if (empty($mycourses)) {
         if (empty($includekeepref)) {
             $options = array(0 => get_string('nocoursesavailable', 'subcourse'));
             $mform->addElement('select', 'refcourse', get_string('refcourselabel', 'subcourse'), $options);
         } else {
             $mform->addElement('hidden', 'refcourse', 0);
             $mform->setType('refcourse', PARAM_INT);
         }
     } else {
         $catlist = coursecat::make_categories_list('', 0, ' / ');
         foreach ($mycourses as $mycourse) {
             if (empty($options[$catlist[$mycourse->category]])) {
                 $options[$catlist[$mycourse->category]] = array();
             }
             $courselabel = $mycourse->fullname . ' (' . $mycourse->shortname . ')';
             $options[$catlist[$mycourse->category]][$mycourse->id] = $courselabel;
             if (empty($mycourse->visible)) {
                 $hiddenlabel = ' ' . get_string('hiddencourse', 'subcourse');
                 $options[$catlist[$mycourse->category]][$mycourse->id] .= $hiddenlabel;
             }
         }
         if (!empty($includenoref)) {
             $options['---'] = array(0 => get_string('none'));
         }
         $mform->addElement('selectgroups', 'refcourse', get_string('refcourselabel', 'subcourse'), $options);
         if (!empty($includekeepref)) {
             $mform->disabledIf('refcourse', 'refcoursecurrent', 'checked');
         }
     }
     $mform->addElement('checkbox', 'instantredirect', get_string('instantredirect', 'subcourse'));
     $mform->addHelpButton('instantredirect', 'instantredirect', 'subcourse');
     // Common module settings ----------------------------------------------
     $this->standard_coursemodule_elements();
     // Common action buttons
     $this->add_action_buttons();
 }