Ejemplo n.º 1
0
 /**
  * The URL to use for the specified course (with section)
  *
  * This function calls function callback_FORMATNAME_get_section_url() if it exists
  *
  * @param int|stdClass $section Section object from database or just field course_sections.section
  *     if omitted the course view page is returned
  * @param array $options options for view URL. At the moment core uses:
  *     'navigation' (bool) if true and section has no separate page, the function returns null
  *     'sr' (int) used by multipage formats to specify to which section to return
  * @return null|moodle_url
  */
 public function get_view_url($section, $options = array())
 {
     // Use course formatter callback if it exists
     $featurefunction = 'callback_' . $this->format . '_get_section_url';
     if (function_exists($featurefunction) && ($course = $this->get_course())) {
         if (is_object($section)) {
             $sectionnum = $section->section;
         } else {
             $sectionnum = $section;
         }
         if ($sectionnum) {
             $url = $featurefunction($course, $sectionnum);
             if ($url || !empty($options['navigation'])) {
                 return $url;
             }
         }
     }
     // if function is not defined
     if (!$this->uses_sections() || !array_key_exists('coursedisplay', $this->course_format_options())) {
         // default behaviour
         return parent::get_view_url($section, $options);
     }
     $course = $this->get_course();
     $url = new moodle_url('/course/view.php', array('id' => $course->id));
     $sr = null;
     if (array_key_exists('sr', $options)) {
         $sr = $options['sr'];
     }
     if (is_object($section)) {
         $sectionno = $section->section;
     } else {
         $sectionno = $section;
     }
     if ($sectionno !== null) {
         if ($sr !== null) {
             if ($sr) {
                 $usercoursedisplay = COURSE_DISPLAY_MULTIPAGE;
                 $sectionno = $sr;
             } else {
                 $usercoursedisplay = COURSE_DISPLAY_SINGLEPAGE;
             }
         } else {
             $usercoursedisplay = $course->coursedisplay;
         }
         if ($sectionno != 0 && $usercoursedisplay == COURSE_DISPLAY_MULTIPAGE) {
             $url->param('section', $sectionno);
         } else {
             if (!empty($options['navigation'])) {
                 return null;
             }
             $url->set_anchor('section-' . $sectionno);
         }
     }
     return $url;
 }