[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 // This page prints reports and info about chats. 18 19 require_once('../../config.php'); 20 require_once ('lib.php'); 21 22 $id = required_param('id', PARAM_INT); 23 $start = optional_param('start', 0, PARAM_INT); // Start of period. 24 $end = optional_param('end', 0, PARAM_INT); // End of period. 25 $deletesession = optional_param('deletesession', 0, PARAM_BOOL); 26 $confirmdelete = optional_param('confirmdelete', 0, PARAM_BOOL); 27 $showall = optional_param('show_all', 0, PARAM_BOOL); 28 29 $url = new moodle_url('/mod/chat/report.php', array('id' => $id)); 30 if ($start !== 0) { 31 $url->param('start', $start); 32 } 33 if ($end !== 0) { 34 $url->param('end', $end); 35 } 36 if ($deletesession !== 0) { 37 $url->param('deletesession', $deletesession); 38 } 39 if ($confirmdelete !== 0) { 40 $url->param('confirmdelete', $confirmdelete); 41 } 42 $PAGE->set_url($url); 43 44 if (! $cm = get_coursemodule_from_id('chat', $id)) { 45 print_error('invalidcoursemodule'); 46 } 47 if (! $chat = $DB->get_record('chat', array('id' => $cm->instance))) { 48 print_error('invalidcoursemodule'); 49 } 50 if (! $course = $DB->get_record('course', array('id' => $chat->course))) { 51 print_error('coursemisconf'); 52 } 53 54 $context = context_module::instance($cm->id); 55 $PAGE->set_context($context); 56 $PAGE->set_heading($course->fullname); 57 58 require_login($course, false, $cm); 59 60 if (empty($chat->studentlogs) && !has_capability('mod/chat:readlog', $context)) { 61 notice(get_string('nopermissiontoseethechatlog', 'chat')); 62 } 63 64 $params = array( 65 'context' => $context, 66 'objectid' => $chat->id, 67 'other' => array( 68 'start' => $start, 69 'end' => $end 70 ) 71 ); 72 $event = \mod_chat\event\sessions_viewed::create($params); 73 $event->add_record_snapshot('chat', $chat); 74 $event->trigger(); 75 76 $strchats = get_string('modulenameplural', 'chat'); 77 $strchat = get_string('modulename', 'chat'); 78 $strchatreport = get_string('chatreport', 'chat'); 79 $strseesession = get_string('seesession', 'chat'); 80 $strdeletesession = get_string('deletesession', 'chat'); 81 82 $navlinks = array(); 83 84 $canexportsess = has_capability('mod/chat:exportsession', $context); 85 86 // Print a session if one has been specified. 87 88 if ($start and $end and !$confirmdelete) { // Show a full transcript. 89 $PAGE->navbar->add($strchatreport); 90 $PAGE->set_title(format_string($chat->name).": $strchatreport"); 91 echo $OUTPUT->header(); 92 echo $OUTPUT->heading(format_string($chat->name), 2); 93 94 // Check to see if groups are being used here. 95 $groupmode = groups_get_activity_groupmode($cm); 96 $currentgroup = groups_get_activity_group($cm, true); 97 groups_print_activity_menu($cm, $CFG->wwwroot . "/mod/chat/report.php?id=$cm->id"); 98 99 $params = array('currentgroup' => $currentgroup, 'chatid' => $chat->id, 'start' => $start, 'end' => $end); 100 101 // If the user is allocated to a group, only show messages from people 102 // in the same group, or no group. 103 if ($currentgroup) { 104 $groupselect = " AND (groupid = :currentgroup OR groupid = 0)"; 105 } else { 106 $groupselect = ""; 107 } 108 109 if ($deletesession and has_capability('mod/chat:deletelog', $context)) { 110 echo $OUTPUT->confirm(get_string('deletesessionsure', 'chat'), 111 "report.php?id=$cm->id&deletesession=1&confirmdelete=1&start=$start&end=$end", 112 "report.php?id=$cm->id"); 113 } 114 115 if (!$messages = $DB->get_records_select('chat_messages', 116 "chatid = :chatid AND timestamp >= :start AND timestamp <= :end $groupselect", 117 $params, 118 "timestamp ASC")) { 119 120 echo $OUTPUT->heading(get_string('nomessages', 'chat')); 121 122 } else { 123 echo '<p class="boxaligncenter">'.userdate($start).' --> '. userdate($end).'</p>'; 124 125 echo $OUTPUT->box_start('center'); 126 $participates = array(); 127 foreach ($messages as $message) { // We are walking FORWARDS through messages. 128 if (!isset($participates[$message->userid])) { 129 $participates[$message->userid] = true; 130 } 131 $formatmessage = chat_format_message($message, $course->id, $USER); 132 if (isset($formatmessage->html)) { 133 echo $formatmessage->html; 134 } 135 } 136 $participatedcap = array_key_exists($USER->id, $participates) 137 && has_capability('mod/chat:exportparticipatedsession', $context); 138 139 if (!empty($CFG->enableportfolios) && ($canexportsess || $participatedcap)) { 140 require_once($CFG->libdir . '/portfoliolib.php'); 141 $buttonoptions = array( 142 'id' => $cm->id, 143 'start' => $start, 144 'end' => $end, 145 ); 146 $button = new portfolio_add_button(); 147 $button->set_callback_options('chat_portfolio_caller', $buttonoptions, 'mod_chat'); 148 $button->render(); 149 } 150 echo $OUTPUT->box_end(); 151 } 152 153 if (!$deletesession or !has_capability('mod/chat:deletelog', $context)) { 154 echo $OUTPUT->continue_button("report.php?id=$cm->id"); 155 } 156 157 echo $OUTPUT->footer(); 158 exit; 159 } 160 161 162 // Print the Sessions display. 163 $PAGE->navbar->add($strchatreport); 164 $PAGE->set_title(format_string($chat->name).": $strchatreport"); 165 echo $OUTPUT->header(); 166 167 echo $OUTPUT->heading(format_string($chat->name).': '.get_string('sessions', 'chat'), 2); 168 169 // Check to see if groups are being used here 170 if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used. 171 $currentgroup = groups_get_activity_group($cm, true); 172 groups_print_activity_menu($cm, $CFG->wwwroot . "/mod/chat/report.php?id=$cm->id"); 173 } else { 174 $currentgroup = false; 175 } 176 177 $params = array('currentgroup' => $currentgroup, 'chatid' => $chat->id, 'start' => $start, 'end' => $end); 178 179 // If the user is allocated to a group, only show discussions with people in 180 // the same group, or no group. 181 if (!empty($currentgroup)) { 182 $groupselect = " AND (groupid = :currentgroup OR groupid = 0)"; 183 } else { 184 $groupselect = ""; 185 } 186 187 // Delete a session if one has been specified. 188 189 if ($deletesession and has_capability('mod/chat:deletelog', $context) 190 and $confirmdelete and $start and $end and confirm_sesskey()) { 191 192 $DB->delete_records_select('chat_messages', "chatid = :chatid AND timestamp >= :start AND 193 timestamp <= :end $groupselect", $params); 194 $strdeleted = get_string('deleted'); 195 echo $OUTPUT->notification("$strdeleted: ".userdate($start).' --> '. userdate($end)); 196 unset($deletesession); 197 } 198 199 // Get the messages. 200 if (empty($messages)) { // May have already got them above. 201 if (!$messages = $DB->get_records_select('chat_messages', "chatid = :chatid $groupselect", $params, "timestamp DESC")) { 202 echo $OUTPUT->heading(get_string('nomessages', 'chat'), 3); 203 echo $OUTPUT->footer(); 204 exit; 205 } 206 } 207 208 if ($showall) { 209 $headingstr = get_string('listing_all_sessions', 'chat') . ' '; 210 $headingstr .= html_writer::link("report.php?id={$cm->id}&show_all=0", get_string('list_complete_sessions', 'chat')); 211 echo $OUTPUT->heading($headingstr, 3); 212 } 213 214 // Show all the sessions. 215 216 $sessiongap = 5 * 60; // 5 minutes silence means a new session. 217 $sessionend = 0; 218 $sessionstart = 0; 219 $sessionusers = array(); 220 $lasttime = 0; 221 $completesessions = 0; 222 223 $messagesleft = count($messages); 224 225 foreach ($messages as $message) { // We are walking BACKWARDS through the messages. 226 227 $messagesleft --; // Countdown. 228 229 if (!$lasttime) { 230 $lasttime = $message->timestamp; 231 } 232 if (!$sessionend) { 233 $sessionend = $message->timestamp; 234 } 235 if ((($lasttime - $message->timestamp) < $sessiongap) and $messagesleft) { // Same session. 236 if ($message->userid and !$message->system) { // Remember user and count messages. 237 if (empty($sessionusers[$message->userid])) { 238 $sessionusers[$message->userid] = 1; 239 } else { 240 $sessionusers[$message->userid] ++; 241 } 242 } 243 } else { 244 $sessionstart = $lasttime; 245 246 $iscomplete = ($sessionend - $sessionstart > 60 and count($sessionusers) > 1); 247 if ($showall or $iscomplete) { 248 249 echo '<p align="center">'.userdate($sessionstart).' --> '. userdate($sessionend).'</p>'; 250 251 echo $OUTPUT->box_start(); 252 253 arsort($sessionusers); 254 foreach ($sessionusers as $sessionuser => $usermessagecount) { 255 if ($user = $DB->get_record('user', array('id' => $sessionuser))) { 256 $OUTPUT->user_picture($user, array('courseid' => $course->id)); 257 echo ' '.fullname($user, true); // XXX TODO use capability instead of true. 258 echo " ($usermessagecount)<br />"; 259 } 260 } 261 262 echo '<p align="right">'; 263 echo "<a href=\"report.php?id=$cm->id&start=$sessionstart&end=$sessionend\">$strseesession</a>"; 264 $participatedcap = (array_key_exists($USER->id, $sessionusers) 265 && has_capability('mod/chat:exportparticipatedsession', $context)); 266 if (!empty($CFG->enableportfolios) && ($canexportsess || $participatedcap)) { 267 require_once($CFG->libdir . '/portfoliolib.php'); 268 $buttonoptions = array( 269 'id' => $cm->id, 270 'start' => $sessionstart, 271 'end' => $sessionend, 272 ); 273 $button = new portfolio_add_button(); 274 $button->set_callback_options('chat_portfolio_caller', $buttonoptions, 'mod_chat'); 275 $portfoliobutton = $button->to_html(PORTFOLIO_ADD_TEXT_LINK); 276 if (!empty($portfoliobutton)) { 277 echo '<br />' . $portfoliobutton; 278 } 279 } 280 if (has_capability('mod/chat:deletelog', $context)) { 281 $deleteurl = "report.php?id=$cm->id&start=$sessionstart&end=$sessionend&deletesession=1"; 282 echo "<br /><a href=\"$deleteurl\">$strdeletesession</a>"; 283 } 284 echo '</p>'; 285 echo $OUTPUT->box_end(); 286 } 287 if ($iscomplete) { 288 $completesessions++; 289 } 290 291 $sessionend = $message->timestamp; 292 $sessionusers = array(); 293 $sessionusers[$message->userid] = 1; 294 } 295 $lasttime = $message->timestamp; 296 } 297 298 if (!empty($CFG->enableportfolios) && $canexportsess) { 299 require_once($CFG->libdir . '/portfoliolib.php'); 300 $button = new portfolio_add_button(); 301 $button->set_callback_options('chat_portfolio_caller', array('id' => $cm->id), 'mod_chat'); 302 $button->render(null, get_string('addalltoportfolio', 'portfolio')); 303 } 304 305 306 if (!$showall and $completesessions == 0) { 307 echo html_writer::start_tag('p'); 308 echo get_string('no_complete_sessions_found', 'chat') . ' '; 309 echo html_writer::link('report.php?id='.$cm->id.'&show_all=1', get_string('list_all_sessions', 'chat')); 310 echo html_writer::end_tag('p'); 311 } 312 313 // Finish the page. 314 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |