-
Notifications
You must be signed in to change notification settings - Fork 7
/
view.php
98 lines (83 loc) · 3.36 KB
/
view.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
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* mod/taskchain/view.php
*
* @package mod
* @subpackage taskchain
* @copyright 2010 Gordon Bateson (gordon.bateson@gmail.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
*/
/** Include required files */
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once($CFG->dirroot.'/mod/taskchain/locallib.php');
// create object to represent this TaskChain activity
$TC = new mod_taskchain();
// Log this request
mod_taskchain::add_to_log($TC->course->id, 'taskchain', 'view', 'view.php?id='.$TC->coursemodule->id, $TC->taskchain->id, $TC->coursemodule->id);
$completion = new completion_info($TC->course);
$completion->set_module_viewed($TC->coursemodule);
if (! $TC->show_entrypage()) {
// go straight to attempt.php
redirect($TC->url->attempt());
}
switch ($TC->action) {
case 'deleteselected':
$TC->delete_selected_attempts();
$TC->update_completion_state($completion);
break;
case 'manualcompletion':
$TC->update_chainattempt_status();
$TC->update_completion_state($completion);
break;
}
// Set editing mode
mod_taskchain::set_user_editing();
// initialize $PAGE (and compute blocks)
$PAGE->set_url($TC->url->view());
$PAGE->set_title($TC->taskchain->name);
$PAGE->set_heading($TC->course->fullname);
$TC->set_preferred_pagelayout($PAGE);
$output = $PAGE->get_renderer('mod_taskchain');
////////////////////////////////////////////////////////////////////////////////
// Output starts here //
////////////////////////////////////////////////////////////////////////////////
echo $output->header();
if ($TC->can->attempt() || $TC->can->preview()) {
echo $output->entrypage();
} else {
if (isguestuser()) {
// offer guests a choice of logging in or going back.
if (function_exists('get_local_referer')) {
// Moodle >= 2.8
$referer = get_local_referer(false);
} else {
// Moodle <= 2.7
$referer = get_referer(false);
}
$message = html_writer::tag('p', get_string('guestsno', 'mod_taskchain'));
$message .= html_writer::tag('p', get_string('liketologin'));
echo $output->confirm($message, get_login_url(), $referer);
} else {
// user is not enrolled in this course in a good enough role,
// show a link to course enrolment page.
$message = html_writer::tag('p', get_string('youneedtoenrol', 'mod_taskchain'));
$message .= html_writer::tag('p', $output->continue_button($TC->url->course()));
echo $output->box($message, 'generalbox', 'notice');
}
}
echo $output->footer();