forked from danmarsden/moodle-mod_dialogue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview.php
executable file
·184 lines (155 loc) · 7.59 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?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/>.
/**
* This page prints a particular instance of Dialogue
*
* @package dialogue
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
require_once("../../config.php");
require_once("lib.php");
require_once("locallib.php");
require_once("dialogue_open_form.php");
$id = required_param('id', PARAM_INT);
$pane = optional_param('pane', 1, PARAM_INT);
$group = optional_param('group',-1, PARAM_INT);
$PAGE->set_url('/mod/dialogue/view.php', array('id' => $id,
'pane' => $pane,
'group' => $group));
if (! $cm = get_coursemodule_from_id('dialogue', $id)) {
print_error("Course Module ID was incorrect");
}
if (! $course = $DB->get_record("course", array('id' => $cm->course))) {
print_error("Course is misconfigured");
}
if (! $dialogue = $DB->get_record("dialogue", array('id' => $cm->instance))) {
print_error("Course module is incorrect");
}
require_login($course, false, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id); // m odule context
$hascapopen = has_capability('mod/dialogue:open', $context);
$hascapparticipate = has_capability('mod/dialogue:participate', $context);
$hascapviewall = has_capability('mod/dialogue:viewall', $context);
$hascapmanage = has_capability('mod/dialogue:manage', $context);
$currentgroup = groups_get_activity_group($cm, true);
$groupmode = groups_get_activity_groupmode($cm);
/// Some capability checks.
if (empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities', $context)) {
echo $OUTPUT->notification(get_string("activityiscurrentlyhidden"));
}
add_to_log($course->id, "dialogue", "view", "view.php?id=$cm->id", $dialogue->id, $cm->id);
$strdialogue = get_string("modulename", "dialogue");
$strdialogues = get_string("modulenameplural", "dialogue");
$PAGE->set_context($context);
$PAGE->set_title(format_string($dialogue->name));
$PAGE->set_heading(format_string($course->fullname));
echo $OUTPUT->header();
if (!$hascapparticipate) { // no access
echo $OUTPUT->notification(get_string("notavailable", "dialogue"));
echo $OUTPUT->footer($course);
die;
}
/// find out current groups mode
groups_print_activity_menu($cm, new moodle_url($CFG->wwwroot . '/mod/dialogue/view.php', array('id' => $cm->id,
'pane' => $pane)));
$currentgroup = groups_get_activity_group($cm);
$groupmode = groups_get_activity_groupmode($cm);
/// print intro text
echo $OUTPUT->box(format_module_intro('dialogue', $dialogue, $cm->id), 'generalbox', 'intro');
// get some stats
$countopen = dialogue_count_open($dialogue, $USER, $hascapviewall, $currentgroup);
$countclosed = dialogue_count_closed($dialogue, $USER, $hascapviewall, $currentgroup);
// set up tab table
$names[0] = get_string("pane0", "dialogue");
if ($countopen == 1) {
$names[1] = get_string("pane1one", "dialogue");
} else {
$names[1] = get_string("pane1", "dialogue", $countopen);
}
if ($countclosed == 1) {
$names[3] = get_string("pane3one", "dialogue");
} else {
$names[3] = get_string("pane3", "dialogue", $countclosed);
}
$tabs = array();
if ($hascapopen) {
$URL = "view.php?id=$cm->id&pane=".DIALOGUEPANE_OPEN;
$groupmode = groups_get_activity_groupmode($cm, $course);
if (($groupmode == SEPARATEGROUPS) || ($groupmode == VISIBLEGROUPS)) {
// pass the user's groupid if in groups mode to view.php
// NOTE: this defaults to users first group, needs to be updated to handle grouping mode also
// ULPGC ecastro activity_group handles grouping & group
if($firstgroup = groups_get_activity_group($cm, true)) {
$URL .= "&group=" . $firstgroup;
}
}
$tabs[0][] = new tabobject (0, $URL, $names[0]);
}
$tabs[0][] = new tabobject (1, "view.php?id=$cm->id&pane=".DIALOGUEPANE_CURRENT, $names[1]);
$tabs[0][] = new tabobject (3, "view.php?id=$cm->id&pane=".DIALOGUEPANE_CLOSED, $names[3]);
print_tabs($tabs, $pane, NULL, NULL, false);
echo "<br />\n";
$names = dialogue_get_available_users($dialogue, $context, 0);
switch ($pane) {
case 0: // Open dialogue
if (! $hascapopen) {
echo $OUTPUT->notification(get_string("notavailable", "dialogue"));
echo $OUTPUT->continue_button("view.php?id=$cm->id");
break;
}
if ($groupmode && ! $hascapmanage) {
if ($group>0) {
$members = groups_get_members($group, 'u.id');
if (! in_array($USER->id, array_keys($members))) {
echo $OUTPUT->notification(get_string("cannotadd", "dialogue"));
echo $OUTPUT->continue_button("view.php?id=$cm->id");
break;
}
} else {
echo $OUTPUT->notification(get_string("cannotaddall", "dialogue"));
echo $OUTPUT->continue_button("view.php?id=$cm->id");
break;
}
}
if ($names) {
// setup form for opening a new conversation
$mform = new mod_dialogue_open_form('dialogues.php', array('context'=>$context,
'names'=>$names,
));
//$draftitemid = file_get_unused_draft_itemid();
//$draftitemid = file_get_submitted_draft_itemid('attachment');
//print_object($draftitemid);
//file_prepare_draft_area($draftitemid, $context->id, 'mod_glossary', 'attachment', null);
$mform->set_data(array('id' => $cm->id,
'action' => 'openconversation'));
//,
// 'attachment' => $draftitemid));
$mform->display();
} else {
echo $OUTPUT->notification(get_string("noavailablepeople", "dialogue"));
echo $OUTPUT->continue_button("view.php?id=$cm->id");
}
break;
case 1: // Current dialogues
case 2:
// print active conversations requiring a reply from the other person.
dialogue_list_conversations($dialogue, $currentgroup, 'open');
break;
case 3: // Closed dialogues
dialogue_list_conversations($dialogue, $currentgroup, 'closed');
break;
}
echo $OUTPUT->footer($course);