예제 #1
0
파일: lib.php 프로젝트: EsdrasCaleb/moodle
 /**
  * Adds format options elements to the course/section edit form
  *
  * This function is called from {@link course_edit_form::definition_after_data()}
  *
  * @param MoodleQuickForm $mform form the elements are added to
  * @param bool $forsection 'true' if this is a section edit form, 'false' if this is course edit form
  * @return array array of references to the added form elements
  */
 public function create_edit_form_elements(&$mform, $forsection = false)
 {
     $elements = array();
     if ($forsection) {
         $options = $this->section_format_options(true);
     } else {
         $options = $this->course_format_options(true);
     }
     foreach ($options as $optionname => $option) {
         if (!isset($option['element_type'])) {
             $option['element_type'] = 'text';
         }
         $args = array($option['element_type'], $optionname, $option['label']);
         if (!empty($option['element_attributes'])) {
             $args = array_merge($args, $option['element_attributes']);
         }
         $elements[] = call_user_func_array(array($mform, 'addElement'), $args);
         if (isset($option['help'])) {
             $helpcomponent = 'format_' . $this->get_format();
             if (isset($option['help_component'])) {
                 $helpcomponent = $option['help_component'];
             }
             $mform->addHelpButton($optionname, $option['help'], $helpcomponent);
         }
         if (isset($option['type'])) {
             $mform->setType($optionname, $option['type']);
         }
         if (is_null($mform->getElementValue($optionname)) && isset($option['default'])) {
             $mform->setDefault($optionname, $option['default']);
         }
     }
     if (!$forsection && empty($this->courseid)) {
         // At this stage (this is called from definition_after_data) course data is already set as default.
         // We can not overwrite what is in the database.
         $mform->setDefault('enddate', $this->get_default_course_enddate($mform));
     }
     return $elements;
 }
예제 #2
0
 /**
  * Adds format options elements to the course/section edit form
  *
  * This function is called from {@link course_edit_form::definition_after_data()}
  *
  * @param MoodleQuickForm $mform form the elements are added to
  * @param bool $forsection 'true' if this is a section edit form, 'false' if this is course edit form
  * @return array array of references to the added form elements
  */
 public function create_edit_form_elements(&$mform, $forsection = false)
 {
     $elements = array();
     if ($forsection) {
         $options = $this->section_format_options(true);
     } else {
         $options = $this->course_format_options(true);
     }
     foreach ($options as $optionname => $option) {
         if (!isset($option['element_type'])) {
             $option['element_type'] = 'text';
         }
         $args = array($option['element_type'], $optionname, $option['label']);
         if (!empty($option['element_attributes'])) {
             $args = array_merge($args, $option['element_attributes']);
         }
         $elements[] = call_user_func_array(array($mform, 'addElement'), $args);
         if (isset($option['help'])) {
             $helpcomponent = 'format_' . $this->get_format();
             if (isset($option['help_component'])) {
                 $helpcomponent = $option['help_component'];
             }
             $mform->addHelpButton($optionname, $option['help'], $helpcomponent);
         }
         if (isset($option['type'])) {
             $mform->setType($optionname, $option['type']);
         }
         if (is_null($mform->getElementValue($optionname)) && isset($option['default'])) {
             $mform->setDefault($optionname, $option['default']);
         }
     }
     return $elements;
 }