3 class block_section_links
extends block_base
{
6 $this->title
= get_string('blockname', 'block_section_links');
7 $this->version
= 2004052800;
10 function instance_config($instance) {
11 parent
::instance_config($instance);
12 $course = get_record('course', 'id', $this->instance
->pageid
);
13 if (isset($course->format
)) {
14 if ($course->format
== 'topics') {
15 $this->title
= get_string('topics', 'block_section_links');
16 } else if ($course->format
== 'weeks') {
17 $this->title
= get_string('weeks', 'block_section_links');
19 $this->title
= get_string('blockname', 'block_section_links');
24 function applicable_formats() {
25 return (array('course-view-weeks' => true, 'course-view-topics' => true, 'course-edit-weeks' => true, 'course-edit-topics' => true));
28 function get_content() {
29 global $CFG, $USER, $COURSE;
33 if ($this->content
!== NULL) {
34 return $this->content
;
37 $this->content
= new stdClass
;
38 $this->content
->footer
= '';
39 $this->content
->text
= '';
41 if (empty($this->instance
)) {
42 return $this->content
;
45 if ($this->instance
->pageid
== $COURSE->id
) {
48 $course = get_record('course', 'id', $this->instance
->pageid
);
50 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
52 if ($course->format
== 'weeks' or $course->format
== 'weekscss') {
53 $highlight = ceil((time()-$course->startdate
)/604800);
54 $linktext = get_string('jumptocurrentweek', 'block_section_links');
55 $sectionname = 'week';
57 else if ($course->format
== 'topics') {
58 $highlight = $course->marker
;
59 $linktext = get_string('jumptocurrenttopic', 'block_section_links');
60 $sectionname = 'topic';
63 if ($course->numsections
> 22) {
66 if ($course->numsections
> 40) {
70 if (!empty($USER->id
)) {
71 $display = get_field('course_display', 'display', 'course', $this->instance
->pageid
, 'userid', $USER->id
);
73 if (!empty($display)) {
74 $link = $CFG->wwwroot
.'/course/view.php?id='.$this->instance
->pageid
.'&'.$sectionname.'=';
78 $text = '<ol class="inline-list">';
79 for ($i = $inc; $i <= $course->numsections
; $i +
= $inc) {
80 $isvisible = get_field('course_sections', 'visible', 'course', $this->instance
->pageid
, 'section', $i);
81 if (!$isvisible and !has_capability('moodle/course:update', $context)) {
84 $style = ($isvisible) ?
'' : ' class="dimmed"';
85 if ($i == $highlight) {
86 $text .= "<li><a href=\"$link$i\"$style><strong>$i</strong></a></li>\n";
88 $text .= "<li><a href=\"$link$i\"$style>$i</a></li>\n";
93 $isvisible = get_field('course_sections', 'visible', 'course', $this->instance
->pageid
, 'section', $highlight);
94 if ($isvisible or has_capability('moodle/course:update', $context)) {
95 $style = ($isvisible) ?
'' : ' class="dimmed"';
96 $text .= "\n<a href=\"$link$highlight\"$style>$linktext</a>";
100 $this->content
->text
= $text;
101 return $this->content
;