3 /// This page lists all the instances of glossary in a particular course
4 /// Replace glossary with the name of your module
6 require_once("../../config.php");
7 require_once("lib.php");
8 require_once("$CFG->libdir/rsslib.php");
9 require_once("$CFG->dirroot/course/lib.php");
11 $id = required_param('id', PARAM_INT
); // course
13 $PAGE->set_url('/mod/glossary/index.php', array('id'=>$id));
15 if (!$course = $DB->get_record('course', array('id'=>$id))) {
16 print_error('invalidcourseid');
19 require_course_login($course);
20 $PAGE->set_pagelayout('incourse');
21 $context = context_course
::instance($course->id
);
23 $event = \mod_glossary\event\course_module_instance_list_viewed
::create(array(
26 $event->add_record_snapshot('course', $course);
29 /// Get all required strings
31 $strglossarys = get_string("modulenameplural", "glossary");
32 $strglossary = get_string("modulename", "glossary");
33 $strrss = get_string("rss");
37 $PAGE->navbar
->add($strglossarys, "index.php?id=$course->id");
38 $PAGE->set_title($strglossarys);
39 $PAGE->set_heading($course->fullname
);
40 echo $OUTPUT->header();
41 echo $OUTPUT->heading(format_string($strglossarys), 2);
43 /// Get all the appropriate data
45 if (! $glossarys = get_all_instances_in_course("glossary", $course)) {
46 notice(get_string('thereareno', 'moodle', $strglossarys), "../../course/view.php?id=$course->id");
50 $usesections = course_format_uses_sections($course->format
);
52 /// Print the list of instances (your module will probably extend this)
55 $strname = get_string("name");
56 $strentries = get_string("entries", "glossary");
58 $table = new html_table();
61 $strsectionname = get_string('sectionname', 'format_'.$course->format
);
62 $table->head
= array ($strsectionname, $strname, $strentries);
63 $table->align
= array ('center', 'left', 'center');
65 $table->head
= array ($strname, $strentries);
66 $table->align
= array ('left', 'center');
69 if ($show_rss = (isset($CFG->enablerssfeeds
) && isset($CFG->glossary_enablerssfeeds
) &&
70 $CFG->enablerssfeeds
&& $CFG->glossary_enablerssfeeds
)) {
71 $table->head
[] = $strrss;
72 $table->align
[] = 'center';
77 foreach ($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>";
86 // Don't show the glossary.
91 if ($glossary->section
!== $currentsection) {
92 if ($glossary->section
) {
93 $printsection = get_section_name($course, $glossary->section
);
95 if ($currentsection !== "") {
96 $table->data
[] = 'hr';
98 $currentsection = $glossary->section
;
102 // TODO: count only approved if not allowed to see them
104 $count = $DB->count_records_sql("SELECT COUNT(*) FROM {glossary_entries} WHERE (glossaryid = ? OR sourceglossaryid = ?)", array($glossary->id
, $glossary->id
));
106 //If this glossary has RSS activated, calculate it
109 if ($glossary->rsstype
and $glossary->rssarticles
) {
110 //Calculate the tolltip text
111 $tooltiptext = get_string("rsssubscriberss","glossary",format_string($glossary->name
));
117 //Get html code for RSS link
118 $rsslink = rss_get_link($context->id
, $userid, 'mod_glossary', $glossary->id
, $tooltiptext);
123 $linedata = array ($printsection, $link, $count);
125 $linedata = array ($link, $count);
129 $linedata[] = $rsslink;
132 $table->data
[] = $linedata;
137 echo html_writer
::table($table);
141 echo $OUTPUT->footer();