block-recent_activity MDLSITE-1118 Tweaking styles for recent activity block
[moodle.git] / mod / forum / user.php
CommitLineData
cd4e6b17 1<?php
f9a0ea69 2
8f685009
SH
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.
14//
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/>.
17
18/**
19 * Display user activity reports for a course
20 *
21 * @package mod-forum
22 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
f9a0ea69 25
bb8f3759 26require_once('../../config.php');
27require_once('lib.php');
28
29// Course ID
246c082a 30$course = optional_param('course', SITEID, PARAM_INT);
bb8f3759 31// User ID
32$id = optional_param('id', 0, PARAM_INT);
33$mode = optional_param('mode', 'posts', PARAM_ALPHA);
34$page = optional_param('page', 0, PARAM_INT);
35$perpage = optional_param('perpage', 5, PARAM_INT);
36
241ce9c4
SH
37$url = new moodle_url('/mod/forum/user.php');
38if ($course !== SITEID) {
39 $url->param('course', $course);
40}
cd4e6b17 41if ($id !== 0) {
42 $url->param('id', $id);
43}
44if ($mode !== 'posts') {
45 $url->param('mode', $mode);
46}
cd4e6b17 47$PAGE->set_url($url);
241ce9c4 48$PAGE->set_pagelayout('standard');
cd4e6b17 49
bb8f3759 50if (empty($id)) { // See your own profile by default
51 require_login();
52 $id = $USER->id;
53}
54
241ce9c4
SH
55$user = $DB->get_record("user", array("id" => $id), '*', MUST_EXIST);
56$course = $DB->get_record("course", array("id" => $course), '*', MUST_EXIST);
bb8f3759 57
58$syscontext = get_context_instance(CONTEXT_SYSTEM);
59$usercontext = get_context_instance(CONTEXT_USER, $id);
60
61// do not force parents to enrol
62if (!$DB->get_record('role_assignments', array('userid' => $USER->id, 'contextid' => $usercontext->id))) {
63 require_course_login($course);
241ce9c4
SH
64} else {
65 $PAGE->set_course($course);
bb8f3759 66}
67
68if ($user->deleted) {
15ca5e5e 69 echo $OUTPUT->header();
f43f1834 70 echo $OUTPUT->heading(get_string('userdeleted'));
396fb912 71 echo $OUTPUT->footer();
bb8f3759 72 die;
73}
f9a0ea69 74
bb8f3759 75add_to_log($course->id, "forum", "user report",
76 "user.php?course=$course->id&amp;id=$user->id&amp;mode=$mode", "$user->id");
f5fc83e8 77
bb8f3759 78$strforumposts = get_string('forumposts', 'forum');
79$strparticipants = get_string('participants');
80$strmode = get_string($mode, 'forum');
81$fullname = fullname($user, has_capability('moodle/site:viewfullnames', $syscontext));
f9a0ea69 82
15ca5e5e 83$link = null;
bb8f3759 84if (has_capability('moodle/course:viewparticipants', get_context_instance(CONTEXT_COURSE, $course->id)) || has_capability('moodle/site:viewparticipants', $syscontext)) {
a6855934 85 $link = new moodle_url('/user/index.php',array('id'=>$course->id));
bb8f3759 86}
15ca5e5e 87
7a7e209d 88$PAGE->navigation->extend_for_user($user);
15ca5e5e 89$PAGE->set_title("$course->shortname: $fullname: $strmode");
90$PAGE->set_heading($course->fullname);
91echo $OUTPUT->header();
03d9401e 92echo $OUTPUT->heading($fullname);
f9a0ea69 93
bb8f3759 94switch ($mode) {
95 case 'posts' :
96 $searchterms = array('userid:'.$user->id);
97 $extrasql = '';
98 break;
fa22fd5f 99
bb8f3759 100 default:
101 $searchterms = array('userid:'.$user->id);
102 $extrasql = 'AND p.parent = 0';
103 break;
104}
f9a0ea69 105
bb8f3759 106echo '<div class="user-content">';
2011a95b 107
bb8f3759 108if ($course->id == SITEID) {
109 if (empty($CFG->forceloginforprofiles) || isloggedin()) {
110 // Search throughout the whole site.
111 $searchcourse = 0;
67875aa1 112 } else {
bb8f3759 113 $searchcourse = SITEID;
67875aa1 114 }
bb8f3759 115} else {
116 // Search only for posts the user made in this course.
117 $searchcourse = $course->id;
118}
2011a95b 119
bb8f3759 120// Get the posts.
241ce9c4 121if ($posts = forum_search_posts($searchterms, $searchcourse, $page*$perpage, $perpage, $totalcount, $extrasql)) {
1adbd2c3 122
4e412c45 123 $baseurl = new moodle_url('user.php', array('id' => $user->id, 'course' => $course->id, 'mode' => $mode, 'perpage' => $perpage));
929d7a83 124 echo $OUTPUT->paging_bar($totalcount, $page, $perpage, $baseurl);
65bcf17b 125
bb8f3759 126 $discussions = array();
127 $forums = array();
128 $cms = array();
2011a95b 129
bb8f3759 130 foreach ($posts as $post) {
65bcf17b 131
bb8f3759 132 if (!isset($discussions[$post->discussion])) {
133 if (! $discussion = $DB->get_record('forum_discussions', array('id' => $post->discussion))) {
134 print_error('invaliddiscussionid', 'forum');
f9a0ea69 135 }
bb8f3759 136 $discussions[$post->discussion] = $discussion;
137 } else {
138 $discussion = $discussions[$post->discussion];
139 }
65bcf17b 140
bb8f3759 141 if (!isset($forums[$discussion->forum])) {
142 if (! $forum = $DB->get_record('forum', array('id' => $discussion->forum))) {
143 print_error('invalidforumid', 'forum');
f9a0ea69 144 }
bb8f3759 145 $forums[$discussion->forum] = $forum;
146 } else {
147 $forum = $forums[$discussion->forum];
148 }
65bcf17b 149
bb8f3759 150 $ratings = null;
151 if ($forum->assessed) {
152 if ($scale = make_grades_menu($forum->scale)) {
39790bd8 153 $ratings =new stdClass();
bb8f3759 154 $ratings->scale = $scale;
155 $ratings->assesstimestart = $forum->assesstimestart;
156 $ratings->assesstimefinish = $forum->assesstimefinish;
157 $ratings->allow = false;
2011a95b 158 }
bb8f3759 159 }
2011a95b 160
bb8f3759 161 if (!isset($cms[$forum->id])) {
241ce9c4 162 $cm = get_coursemodule_from_instance('forum', $forum->id, 0, false, MUST_EXIST);
bb8f3759 163 $cms[$forum->id] = $cm;
164 unset($cm); // do not use cm directly, it would break caching
165 }
65bcf17b 166
bb8f3759 167 $fullsubject = "<a href=\"view.php?f=$forum->id\">".format_string($forum->name,true)."</a>";
168 if ($forum->type != 'single') {
169 $fullsubject .= " -> <a href=\"discuss.php?d=$discussion->id\">".format_string($discussion->name,true)."</a>";
170 if ($post->parent != 0) {
171 $fullsubject .= " -> <a href=\"discuss.php?d=$post->discussion&amp;parent=$post->id\">".format_string($post->subject,true)."</a>";
f9a0ea69 172 }
bb8f3759 173 }
2011a95b 174
bb8f3759 175 if ($course->id == SITEID && has_capability('moodle/site:config', $syscontext)) {
8c271b29 176 $postcoursename = $DB->get_field('course', 'shortname', array('id'=>$forum->course));
bb8f3759 177 $fullsubject = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$forum->course.'">'.$postcoursename.'</a> -> '. $fullsubject;
178 }
bbbf2d40 179
bb8f3759 180 $post->subject = $fullsubject;
bbbf2d40 181
bb8f3759 182 $fulllink = "<a href=\"discuss.php?d=$post->discussion#p$post->id\">".
183 get_string("postincontext", "forum")."</a>";
f9a0ea69 184
954035a9 185 forum_print_post($post, $discussion, $forum, $cms[$forum->id], $course, false, false, false, $fulllink);
bb8f3759 186 echo "<br />";
187 }
2011a95b 188
929d7a83 189 echo $OUTPUT->paging_bar($totalcount, $page, $perpage, $baseurl);
bb8f3759 190} else {
191 if ($mode == 'posts') {
f43f1834 192 echo $OUTPUT->heading(get_string('noposts', 'forum'));
f9a0ea69 193 } else {
f43f1834 194 echo $OUTPUT->heading(get_string('nodiscussionsstartedby', 'forum'));
f9a0ea69 195 }
bb8f3759 196}
197echo '</div>';
396fb912 198echo $OUTPUT->footer();
f9a0ea69 199