1<?php
2
3/// This page lists all the instances of glossary in a particular course
4/// Replace glossary with the name of your module
5
6require_once("../../config.php");
7require_once("lib.php");
8require_once("$CFG->libdir/rsslib.php");
9require_once("$CFG->dirroot/course/lib.php");
10
11$id = required_param('id', PARAM_INT);   // course
12
13$PAGE->set_url('/mod/glossary/index.php', array('id'=>$id));
14
15if (!$course = $DB->get_record('course', array('id'=>$id))) {
16    print_error('invalidcourseid');
17}
18
19require_course_login($course);
20$PAGE->set_pagelayout('incourse');
21$context = context_course::instance($course->id);
22
23$event = \mod_glossary\event\course_module_instance_list_viewed::create(array(
24    'context' => $context
25));
26$event->add_record_snapshot('course', $course);
27$event->trigger();
28
29/// Get all required strings
30
31$strglossarys = get_string("modulenameplural", "glossary");
32$strglossary  = get_string("modulename", "glossary");
33$strrss = get_string("rss");
34
35
36/// Print the header
37$PAGE->navbar->add($strglossarys, "index.php?id=$course->id");
38$PAGE->set_title($strglossarys);
39$PAGE->set_heading($course->fullname);
40echo $OUTPUT->header();
41echo $OUTPUT->heading(format_string($strglossarys), 2);
42
43/// Get all the appropriate data
44
45if (! $glossarys = get_all_instances_in_course("glossary", $course)) {
46    notice(get_string('thereareno', 'moodle', $strglossarys), "../../course/view.php?id=$course->id");
47    die;
48}
49
50$usesections = course_format_uses_sections($course->format);
51
52/// Print the list of instances (your module will probably extend this)
53
54$timenow = time();
55$strname  = get_string("name");
56$strentries  = get_string("entries", "glossary");
57
58$table = new html_table();
59
60if ($usesections) {
61    $strsectionname = get_string('sectionname', 'format_'.$course->format);
62    $table->head  = array ($strsectionname, $strname, $strentries);
63    $table->align = array ('center', 'left', 'center');
64} else {
65    $table->head  = array ($strname, $strentries);
66    $table->align = array ('left', 'center');
67}
68
69if ($show_rss = (isset($CFG->enablerssfeeds) && isset($CFG->glossary_enablerssfeeds) &&
70                 $CFG->enablerssfeeds && $CFG->glossary_enablerssfeeds)) {
71    $table->head[] = $strrss;
72    $table->align[] = 'center';
73}
74
75$currentsection = "";
76
77foreach ($glossarys as $glossary) {
78    if (!$glossary->visible && has_capability('moodle/course:viewhiddenactivities',
79            context_module::instance($glossary->coursemodule))) {
80        // Show dimmed if the mod is hidden.
81        $link = "<a class=\"dimmed\" href=\"view.php?id=$glossary->coursemodule\">".format_string($glossary->name,true)."</a>";
82    } else if ($glossary->visible) {
83        // Show normal if the mod is visible.
84        $link = "<a href=\"view.php?id=$glossary->coursemodule\">".format_string($glossary->name,true)."</a>";
85    } else {
86        // Don't show the glossary.
87        continue;
88    }
89    $printsection = "";
90    if ($usesections) {
91        if ($glossary->section !== $currentsection) {
92            if ($glossary->section) {
93                $printsection = get_section_name($course, $glossary->section);
94            }
95            if ($currentsection !== "") {
96                $table->data[] = 'hr';
97            }
98            $currentsection = $glossary->section;
99        }
100    }
101
102    // TODO: count only approved if not allowed to see them
103
104    $count = $DB->count_records_sql("SELECT COUNT(*) FROM {glossary_entries} WHERE (glossaryid = ? OR sourceglossaryid = ?)", array($glossary->id, $glossary->id));
105
106    //If this glossary has RSS activated, calculate it
107    if ($show_rss) {
108        $rsslink = '';
109        if ($glossary->rsstype and $glossary->rssarticles) {
110            //Calculate the tolltip text
111            $tooltiptext = get_string("rsssubscriberss","glossary",format_string($glossary->name));
112            if (!isloggedin()) {
113                $userid = 0;
114            } else {
115                $userid = $USER->id;
116            }
117            //Get html code for RSS link
118            $rsslink = rss_get_link($context->id, $userid, 'mod_glossary', $glossary->id, $tooltiptext);
119        }
120    }
121
122    if ($usesections) {
123        $linedata = array ($printsection, $link, $count);
124    } else {
125        $linedata = array ($link, $count);
126    }
127
128    if ($show_rss) {
129        $linedata[] = $rsslink;
130    }
131
132    $table->data[] = $linedata;
133}
134
135echo "<br />";
136
137echo html_writer::table($table);
138
139/// Finish the page
140
141echo $OUTPUT->footer();
142
143