MDL-62275 qtype_calculatedmulti: Fix typo
[moodle.git] / mod / data / index.php
blob80eecf7224d91c6c92c295c2709fbe3630e1586d
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 print_error('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 $PAGE->set_title($strdata);
55 $PAGE->set_heading($course->fullname);
56 echo $OUTPUT->header();
57 echo $OUTPUT->heading($strdataplural, 2);
59 if (! $datas = get_all_instances_in_course("data", $course)) {
60 notice(get_string('thereareno', 'moodle',$strdataplural) , "$CFG->wwwroot/course/view.php?id=$course->id");
63 $usesections = course_format_uses_sections($course->format);
65 $timenow = time();
66 $strname = get_string('name');
67 $strdescription = get_string("description");
68 $strentries = get_string('entries', 'data');
69 $strnumnotapproved = get_string('numnotapproved', 'data');
71 $table = new html_table();
73 if ($usesections) {
74 $strsectionname = get_string('sectionname', 'format_'.$course->format);
75 $table->head = array ($strsectionname, $strname, $strdescription, $strentries, $strnumnotapproved);
76 $table->align = array ('center', 'center', 'center', 'center', 'center');
77 } else {
78 $table->head = array ($strname, $strdescription, $strentries, $strnumnotapproved);
79 $table->align = array ('center', 'center', 'center', 'center');
82 $rss = (!empty($CFG->enablerssfeeds) && !empty($CFG->data_enablerssfeeds));
84 if ($rss) {
85 require_once($CFG->libdir."/rsslib.php");
86 array_push($table->head, 'RSS');
87 array_push($table->align, 'center');
90 $options = new stdClass();
91 $options->noclean = true;
93 $currentsection = "";
95 foreach ($datas as $data) {
97 $printsection = "";
99 //Calculate the href
100 if (!$data->visible) {
101 //Show dimmed if the mod is hidden
102 $link = "<a class=\"dimmed\" href=\"view.php?id=$data->coursemodule\">".format_string($data->name,true)."</a>";
103 } else {
104 //Show normal if the mod is visible
105 $link = "<a href=\"view.php?id=$data->coursemodule\">".format_string($data->name,true)."</a>";
108 // TODO: add group restricted counts here, and limit unapproved to ppl with approve cap only + link to approval page
110 $numrecords = $DB->count_records_sql('SELECT COUNT(r.id) FROM {data_records} r WHERE r.dataid =?', array($data->id));
112 if ($data->approval == 1) {
113 $numunapprovedrecords = $DB->count_records_sql('SELECT COUNT(r.id) FROM {data_records} r WHERE r.dataid =? AND r.approved <> 1', array($data->id));
114 } else {
115 $numunapprovedrecords = '-';
118 $rsslink = '';
119 if ($rss && $data->rssarticles > 0) {
120 $rsslink = rss_get_link($context->id, $USER->id, 'mod_data', $data->id, 'RSS');
123 if ($usesections) {
124 if ($data->section !== $currentsection) {
125 if ($data->section) {
126 $printsection = get_section_name($course, $data->section);
128 if ($currentsection !== '') {
129 $table->data[] = 'hr';
131 $currentsection = $data->section;
133 $row = array ($printsection, $link, format_text($data->intro, $data->introformat, $options), $numrecords, $numunapprovedrecords);
135 } else {
136 $row = array ($link, format_text($data->intro, $data->introformat, $options), $numrecords, $numunapprovedrecords);
139 if ($rss) {
140 array_push($row, $rsslink);
143 $table->data[] = $row;
146 echo "<br />";
147 echo html_writer::tag('div', html_writer::table($table), array('class'=>'no-overflow'));
148 echo $OUTPUT->footer();