forked from oohoo/moodle-mod_tab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
114 lines (93 loc) · 3.58 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/**
* *************************************************************************
* * OOHOO - Tab Display **
* *************************************************************************
* @package mod **
* @subpackage tab **
* @name tab **
* @copyright oohoo.biz **
* @link http://oohoo.biz **
* @author Patrick Thibaudeau **
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later **
* *************************************************************************
* ************************************************************************ */
require('../../config.php');
$id = required_param('id', PARAM_INT); // course id
$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
require_course_login($course, true);
$PAGE->set_pagelayout('incourse');
$strpage = get_string('modulename', 'tab');
$strpages = get_string('modulenameplural', 'tab');
$strsectionname = get_string('sectionname', 'format_' . $course->format);
$strname = get_string('name');
$strintro = get_string('moduleintro');
$strlastmodified = get_string('lastmodified');
$modinfo = get_fast_modinfo($course);
$PAGE->set_url('/mod/tab/index.php', array('id' => $course->id));
$PAGE->set_title($course->shortname . ': ' . $strpages);
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add($strpages);
echo $OUTPUT->header();
//log the view information
$event = \mod_tab\event\course_module_instance_list_viewed::create(array(
'objectid' => $PAGE->cm->instance,
'context' => $PAGE->context,
));
$event->add_record_snapshot('course', $PAGE->course);
$event->add_record_snapshot($PAGE->cm->modname, $tab);
$event->trigger();
if (!$tabs = get_all_instances_in_course('tab', $course))
{
notice(get_string('thereareno', 'moodle', $strpages), "$CFG->wwwroot/course/view.php?id=$course->id");
exit;
}
$usesections = course_format_uses_sections($course->format);
if ($usesections)
{
$sections = $modinfo->get_section_info_all($course->id);
}
$table = new html_table();
$table->attributes['class'] = 'generaltable mod_index';
if ($usesections)
{
$table->head = array($strsectionname, $strname, $strintro);
$table->align = array('center', 'left', 'left');
}
else
{
$table->head = array($strlastmodified, $strname, $strintro);
$table->align = array('left', 'left', 'left');
}
$currentsection = '';
foreach ($tabs as $tab)
{
$cm = $modinfo->cms[$tab->coursemodule];
if ($usesections)
{
$printsection = '';
if ($tab->section !== $currentsection)
{
if ($tab->section)
{
$printsection = get_section_name($course, $sections[$tab->section]);
}
if ($currentsection !== '')
{
$table->data[] = 'hr';
}
$currentsection = $tab->section;
}
}
else
{
$printsection = '<span class="smallinfo">' . userdate($tab->timemodified) . "</span>";
}
$class = $tab->visible ? '' : 'class="dimmed"'; // hidden modules are dimmed
$table->data[] = array(
$printsection,
"<a $class href=\"view.php?id=$cm->id\">" . format_string($tab->name) . "</a>",
format_module_intro('tab', $tab, $cm->id));
}
echo html_writer::table($table);
echo $OUTPUT->footer();