Workshop index page cleanup
[moodle.git] / mod / workshop / index.php
CommitLineData
4eab2e7f 1<?php
53fad4b9
DM
2
3// This file is part of Moodle - http://moodle.org/
4//
4eab2e7f
DM
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.
53fad4b9 14//
4eab2e7f
DM
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/>.
53fad4b9 17
4eab2e7f 18/**
0b5549de 19 * Prints the list of all workshops in the course
4eab2e7f 20 *
65601f04
DM
21 * @package mod
22 * @subpackage workshop
23 * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
4eab2e7f
DM
25 */
26
4eab2e7f
DM
27require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
28require_once(dirname(__FILE__).'/lib.php');
29
30$id = required_param('id', PARAM_INT); // course
31
0b5549de 32$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
4eab2e7f
DM
33
34require_course_login($course);
35
36add_to_log($course->id, 'workshop', 'view all', "index.php?id=$course->id", '');
37
0b5549de
DM
38$PAGE->set_pagelayout('incourse');
39$PAGE->set_url('/mod/workshop/index.php', array('id' => $course->id));
ffac17df
DM
40$PAGE->set_title($course->fullname);
41$PAGE->set_heading($course->shortname);
39861053 42$PAGE->navbar->add(get_string('modulenameplural', 'workshop'));
ffac17df 43
39861053 44/// Output starts here
53fad4b9 45
39861053 46echo $OUTPUT->header();
4eab2e7f
DM
47
48/// Get all the appropriate data
49
50if (! $workshops = get_all_instances_in_course('workshop', $course)) {
ffac17df 51 echo $OUTPUT->heading(get_string('noworkshops', 'workshop'), 2);
a6855934 52 echo $OUTPUT->continue_button(new moodle_url('/course/view.php', array('id' => $course->id)));
ffac17df
DM
53 echo $OUTPUT->footer();
54 die();
4eab2e7f
DM
55}
56
7487c856
SH
57$usesections = course_format_uses_sections($course->format);
58if ($usesections) {
59 $sections = get_all_sections($course->id);
60}
61
0b5549de
DM
62$timenow = time();
63$strsectionname = get_string('sectionname', 'format_'.$course->format);
64$strname = get_string('name');
65$table = new html_table();
4eab2e7f 66
7487c856
SH
67if ($usesections) {
68 $table->head = array ($strsectionname, $strname);
4eab2e7f 69 $table->align = array ('center', 'left');
4eab2e7f
DM
70} else {
71 $table->head = array ($strname);
7487c856 72 $table->align = array ('left');
4eab2e7f
DM
73}
74
75foreach ($workshops as $workshop) {
0b5549de
DM
76 if (empty($workshop->visible)) {
77 $link = html_writer::link(new moodle_url('/mod/workshop/view.php', array('id' => $workshop->coursemodule)),
78 $workshop->name, array('class' => 'dimmed'));
4eab2e7f 79 } else {
0b5549de
DM
80 $link = html_writer::link(new moodle_url('/mod/workshop/view.php', array('id' => $workshop->coursemodule)),
81 $workshop->name);
4eab2e7f
DM
82 }
83
7487c856 84 if ($usesections) {
0b5549de 85 $table->data[] = array(get_section_name($course, $sections[$workshop->section]), $link);
4eab2e7f 86 } else {
0b5549de 87 $table->data[] = array($link);
4eab2e7f
DM
88 }
89}
90
ffac17df 91echo $OUTPUT->heading(get_string('modulenameplural', 'workshop'), 2);
32a979e9 92echo html_writer::table($table);
ffac17df 93echo $OUTPUT->footer();