MDL-65087 message: add button role to action links on bootstrapbase
[moodle.git] / mod / glossary / index.php
blobc432477adef2f5bbaf5a99255ce727906d5a67d4
1 <?php
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(
24 'context' => $context
25 ));
26 $event->add_record_snapshot('course', $course);
27 $event->trigger();
29 /// Get all required strings
31 $strglossarys = get_string("modulenameplural", "glossary");
32 $strglossary = get_string("modulename", "glossary");
33 $strrss = get_string("rss");
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);
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");
47 die;
50 $usesections = course_format_uses_sections($course->format);
52 /// Print the list of instances (your module will probably extend this)
54 $timenow = time();
55 $strname = get_string("name");
56 $strentries = get_string("entries", "glossary");
58 $table = new html_table();
60 if ($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');
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';
75 $currentsection = "";
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>";
85 } else {
86 // Don't show the glossary.
87 continue;
89 $printsection = "";
90 if ($usesections) {
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
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;
117 //Get html code for RSS link
118 $rsslink = rss_get_link($context->id, $userid, 'mod_glossary', $glossary->id, $tooltiptext);
122 if ($usesections) {
123 $linedata = array ($printsection, $link, $count);
124 } else {
125 $linedata = array ($link, $count);
128 if ($show_rss) {
129 $linedata[] = $rsslink;
132 $table->data[] = $linedata;
135 echo "<br />";
137 echo html_writer::table($table);
139 /// Finish the page
141 echo $OUTPUT->footer();