MDL-80880 quiz: change display of previous attempts summary
[moodle.git] / mod / data / index.php
blobb2c603c678efa2fc02bdf7397f1bbefd8db0f2e2
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * This file is part of the Database module for Moodle
21 * @copyright 1990 Martin Dougiamas http://dougiamas.com
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 * @package mod_data
26 require_once("../../config.php");
27 require_once("lib.php");
29 $id = required_param('id', PARAM_INT); // course
31 $PAGE->set_url('/mod/data/index.php', array('id'=>$id));
33 if (!$course = $DB->get_record('course', array('id'=>$id))) {
34 throw new \moodle_exception('invalidcourseid');
37 require_course_login($course);
38 $PAGE->set_pagelayout('incourse');
40 $context = context_course::instance($course->id);
42 $params = array(
43 'context' => context_course::instance($course->id)
45 $event = \mod_data\event\course_module_instance_list_viewed::create($params);
46 $event->add_record_snapshot('course', $course);
47 $event->trigger();
49 $strname = get_string('name');
50 $strdata = get_string('modulename','data');
51 $strdataplural = get_string('modulenameplural','data');
53 $PAGE->navbar->add($strdata, new moodle_url('/mod/data/index.php', array('id'=>$course->id)));
54 $titleparts = [
55 $strdataplural,
56 format_string($course->fullname),
58 $PAGE->set_title(implode(moodle_page::TITLE_SEPARATOR, $titleparts));
59 $PAGE->set_heading($course->fullname);
60 echo $OUTPUT->header();
61 echo $OUTPUT->heading($strdataplural, 2);
63 if (! $datas = get_all_instances_in_course("data", $course)) {
64 notice(get_string('thereareno', 'moodle',$strdataplural) , "$CFG->wwwroot/course/view.php?id=$course->id");
67 $usesections = course_format_uses_sections($course->format);
69 $timenow = time();
70 $strname = get_string('name');
71 $strdescription = get_string("description");
72 $strentries = get_string('entries', 'data');
73 $strnumnotapproved = get_string('numnotapproved', 'data');
75 $table = new html_table();
77 if ($usesections) {
78 $strsectionname = get_string('sectionname', 'format_'.$course->format);
79 $table->head = array ($strsectionname, $strname, $strdescription, $strentries, $strnumnotapproved);
80 $table->align = array ('center', 'center', 'center', 'center', 'center');
81 } else {
82 $table->head = array ($strname, $strdescription, $strentries, $strnumnotapproved);
83 $table->align = array ('center', 'center', 'center', 'center');
86 $rss = (!empty($CFG->enablerssfeeds) && !empty($CFG->data_enablerssfeeds));
88 if ($rss) {
89 require_once($CFG->libdir."/rsslib.php");
90 array_push($table->head, 'RSS');
91 array_push($table->align, 'center');
94 $currentsection = "";
96 foreach ($datas as $data) {
98 $printsection = "";
100 //Calculate the href
101 if (!$data->visible) {
102 //Show dimmed if the mod is hidden
103 $link = "<a class=\"dimmed\" href=\"view.php?id=$data->coursemodule\">".format_string($data->name,true)."</a>";
104 } else {
105 //Show normal if the mod is visible
106 $link = "<a href=\"view.php?id=$data->coursemodule\">".format_string($data->name,true)."</a>";
109 // TODO: add group restricted counts here, and limit unapproved to ppl with approve cap only + link to approval page
111 $numrecords = $DB->count_records_sql('SELECT COUNT(r.id) FROM {data_records} r WHERE r.dataid =?', array($data->id));
113 if ($data->approval == 1) {
114 $numunapprovedrecords = $DB->count_records_sql('SELECT COUNT(r.id) FROM {data_records} r WHERE r.dataid =? AND r.approved <> 1', array($data->id));
115 } else {
116 $numunapprovedrecords = '-';
119 $rsslink = '';
120 if ($rss && $data->rssarticles > 0) {
121 $rsslink = rss_get_link($context->id, $USER->id, 'mod_data', $data->id, 'RSS');
124 if ($usesections) {
125 if ($data->section !== $currentsection) {
126 if ($data->section) {
127 $printsection = get_section_name($course, $data->section);
129 if ($currentsection !== '') {
130 $table->data[] = 'hr';
132 $currentsection = $data->section;
134 $row = array($printsection, $link, format_module_intro('data', $data, $data->coursemodule),
135 $numrecords, $numunapprovedrecords);
137 } else {
138 $row = array($link, format_module_intro('data', $data, $data->coursemodule),
139 $numrecords, $numunapprovedrecords);
142 if ($rss) {
143 array_push($row, $rsslink);
146 $table->data[] = $row;
149 echo "<br />";
150 echo html_writer::tag('div', html_writer::table($table), array('class'=>'no-overflow'));
151 echo $OUTPUT->footer();