forked from NMAI-lab/moodle-mod_socialwiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.php
executable file
·167 lines (144 loc) · 5.64 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
<?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 file contains all necessary code to view a socialwiki page
*
* @package mod_socialwiki
* @copyright 2009 Marc Alier, Jordi Piguillem marc.alier@upc.edu
* @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
*
* @author Jordi Piguillem
* @author Marc Alier
* @author David Jimenez
* @author Josep Arus
* @author Kenneth Riba
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require('../../config.php');
require($CFG->dirroot . '/mod/socialwiki/locallib.php');
require($CFG->dirroot . '/mod/socialwiki/pagelib.php');
$id = optional_param('id', 0, PARAM_INT); // Course Module ID.
$wid = optional_param('wid', 0, PARAM_INT); // Wiki ID.
$swid = optional_param('swid', 0, PARAM_INT); // Subwiki ID.
$pid = optional_param('pageid', 0, PARAM_INT); // Page ID.
$title = optional_param('title', "", PARAM_TEXT); // Page Title.
$group = optional_param('group', 0, PARAM_INT); // Group ID.
$navi = optional_param('navi', -2, PARAM_INT); // Navigation type.
if ($id) {
/*
* Case 0:
*
* User that comes from a course. Home page must be shown
*
* URL params: id -> Course Module ID (required)
*
*/
redirect(new moodle_url('/mod/socialwiki/home.php', array('id' => $id)));
} else if ($pid) {
/*
* Case 1:
*
* A user wants to see a page.
*
* URL Params: pageid -> Page ID (required)
*/
if (!$page = socialwiki_get_page($pid)) {
print_error('incorrectpageid', 'socialwiki');
}
if (!$subwiki = socialwiki_get_subwiki($page->subwikiid)) {
print_error('incorrectsubwikiid', 'socialwiki');
}
if (!$wiki = socialwiki_get_wiki($subwiki->wikiid)) {
print_error('incorrectwikiid', 'socialwiki');
}
if (!$cm = get_coursemodule_from_instance("socialwiki", $subwiki->wikiid)) {
print_error('invalidcoursemodule', 'socialwiki');
}
$group = $subwiki->groupid;
// Checking course instance.
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
require_login($course, true, $cm);
} else if ($wid && $title) {
/*
* Case 2:
*
* Trying to read a page from another group or user
*
* Page can exists or not.
* * If it exists, page must be shown
* * If it does not exists, system must ask for its creation
*
* URL params: wid -> Subwiki ID (required)
* title -> A Page Title (required)
* group -> Group ID (optional)
*/
if (!$wiki = socialwiki_get_wiki($wid)) {
print_error('incorrectwikiid', 'socialwiki');
}
if (!$cm = get_coursemodule_from_instance("socialwiki", $wiki->id)) {
print_error('invalidcoursemodule', 'socialwiki');
}
// Checking course instance.
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
require_login($course, true, $cm);
$groupmode = groups_get_activity_groupmode($cm);
$gid = 0;
if ($groupmode != NOGROUPS) {
$gid = $group;
}
// Getting subwiki instance. If it does not exists, redirect to create page.
if (!$subwiki = socialwiki_get_subwiki_by_group($wiki->id, $gid)) {
$context = context_module::instance($cm->id);
$modeanduser = $wiki->wikimode == 'individual';
$modeandgroupmember = $wiki->wikimode == 'collaborative' && !groups_is_member($gid);
$manage = has_capability('mod/socialwiki:managewiki', $context);
$edit = has_capability('mod/socialwiki:editpage', $context);
$manageandedit = $manage && $edit;
if ($groupmode == VISIBLEGROUPS && ($modeanduser || $modeandgroupmember) && !$manageandedit) {
print_error('nocontent', 'socialwiki');
}
redirect(new moodle_url('/mod/socialwiki/create.php', array('wid' => $wiki->id, 'group' => $gid, 'title' => $title)));
}
// Checking is there is a page with this title. If it does not exists, redirect to first page.
if (!$page = socialwiki_get_page_by_title($subwiki->id, $title)) {
redirect(new moodle_url('/mod/socialwiki/create.php', array('wid' => $wiki->id, 'group' => $gid)));
}
} else {
print_error('incorrectparameters');
}
$context = context_module::instance($cm->id);
require_capability('mod/socialwiki:viewpage', $context);
// Update 'viewed' state if required by completion system.
require_once($CFG->libdir . '/completionlib.php');
$completion = new completion_info($course);
$completion->set_module_viewed($cm);
// Set the navigator if needed.
if (!isset($SESSION->mod_socialwiki)) {
$SESSION->mod_socialwiki = new stdClass();
}
if ($navi !== -2) {
$SESSION->mod_socialwiki->navi = $navi;
} else if (!isset($SESSION->mod_socialwiki->navi)) {
$SESSION->mod_socialwiki->navi = 0;
}
$wikipage = new page_socialwiki_view($wiki, $subwiki, $cm);
$wikipage->set_gid($group);
$wikipage->set_page($page);
$wikipage->print_header();
$wikipage->print_content();
$wikipage->print_comments();
$wikipage->print_footer();