2004-05-07 02:27:56 +00:00
|
|
|
<?PHP //$Id$
|
|
|
|
|
|
|
|
class CourseBlock_section_links extends MoodleBlock {
|
|
|
|
|
|
|
|
function CourseBlock_section_links ($course) {
|
|
|
|
if ($course->format == 'topics') {
|
|
|
|
$this->title = get_string('topics', 'block_section_links');
|
|
|
|
}
|
|
|
|
else if ($course->format == 'weeks') {
|
|
|
|
$this->title = get_string('weeks', 'block_section_links');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$this->title = get_string('blockname', 'block_section_links');
|
|
|
|
}
|
|
|
|
$this->content_type = BLOCK_TYPE_TEXT;
|
|
|
|
$this->course = $course;
|
2004-05-28 10:53:54 +00:00
|
|
|
$this->version = 2004052800;
|
2004-05-07 02:27:56 +00:00
|
|
|
}
|
2004-05-28 10:53:54 +00:00
|
|
|
|
2004-05-07 02:27:56 +00:00
|
|
|
function applicable_formats() {
|
|
|
|
return (COURSE_FORMAT_WEEKS | COURSE_FORMAT_TOPICS);
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_content() {
|
|
|
|
global $CFG, $USER;
|
|
|
|
|
|
|
|
$highlight = 0;
|
|
|
|
|
|
|
|
if($this->content !== NULL) {
|
|
|
|
return $this->content;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->course->format == 'weeks') {
|
|
|
|
$highlight = ceil((time()-$this->course->startdate)/604800);
|
|
|
|
$linktext = get_string('jumptocurrentweek', 'block_section_links');
|
2004-05-29 10:40:07 +00:00
|
|
|
$sectionname = 'week';
|
2004-05-07 02:27:56 +00:00
|
|
|
}
|
|
|
|
else if ($this->course->format == 'topics') {
|
|
|
|
$highlight = $this->course->marker;
|
|
|
|
$linktext = get_string('jumptocurrenttopic', 'block_section_links');
|
2004-05-29 10:40:07 +00:00
|
|
|
$sectionname = 'topic';
|
2004-05-07 02:27:56 +00:00
|
|
|
}
|
|
|
|
$inc = 1;
|
|
|
|
if ($this->course->numsections > 22) {
|
|
|
|
$inc = 2;
|
|
|
|
}
|
|
|
|
if ($this->course->numsections > 40) {
|
|
|
|
$inc = 5;
|
|
|
|
}
|
|
|
|
$courseid = $this->course->id;
|
|
|
|
if ($display = get_field('course_display', 'display', 'course', $courseid, 'userid', $USER->id)) {
|
2004-05-29 10:40:07 +00:00
|
|
|
$link = "$CFG->wwwroot/course/view.php?id=$courseid&$sectionname=";
|
2004-05-07 02:27:56 +00:00
|
|
|
} else {
|
2004-05-29 10:40:07 +00:00
|
|
|
$link = '#';
|
2004-05-07 02:27:56 +00:00
|
|
|
}
|
|
|
|
$text = '<font size=-1>';
|
|
|
|
for ($i = $inc; $i <= $this->course->numsections; $i += $inc) {
|
|
|
|
if ($i == $highlight) {
|
2004-05-29 10:40:07 +00:00
|
|
|
$text .= "<a href=\"$link$i\"><b>$i</b></a> ";
|
2004-05-07 02:27:56 +00:00
|
|
|
} else {
|
2004-05-29 10:40:07 +00:00
|
|
|
$text .= "<a href=\"$link$i\">$i</a> ";
|
2004-05-07 02:27:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($highlight) {
|
2004-05-29 10:40:07 +00:00
|
|
|
$text .= "<br><a href=\"$link$highlight\">$linktext</a>";
|
2004-05-07 02:27:56 +00:00
|
|
|
}
|
2004-05-28 10:53:54 +00:00
|
|
|
|
|
|
|
$this->content = New stdClass;
|
2004-05-07 02:27:56 +00:00
|
|
|
$this->content->footer = '';
|
|
|
|
$this->content->text = $text;
|
|
|
|
return $this->content;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|