Differences Between: [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]
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 $canviewfullnames = has_capability('moodle/site:viewfullnames', $context); 86 87 // Print a session if one has been specified. 88 89 if ($start and $end and !$confirmdelete) { // Show a full transcript. 90 $PAGE->navbar->add($strchatreport); 91 $PAGE->set_title(format_string($chat->name).": $strchatreport"); 92 echo $OUTPUT->header(); 93 echo $OUTPUT->heading(format_string($chat->name), 2); 94 95 // Check to see if groups are being used here. 96 $groupmode = groups_get_activity_groupmode($cm); 97 $currentgroup = groups_get_activity_group($cm, true); 98 groups_print_activity_menu($cm, $CFG->wwwroot . "/mod/chat/report.php?id=$cm->id"); 99 100 if ($deletesession and has_capability('mod/chat:deletelog', $context)) { 101 echo $OUTPUT->confirm(get_string('deletesessionsure', 'chat'), 102 "report.php?id=$cm->id&deletesession=1&confirmdelete=1&start=$start&end=$end", 103 "report.php?id=$cm->id"); 104 } 105 106 if (!$messages = chat_get_session_messages($chat->id, $currentgroup, $start, $end, 'timestamp ASC')) { 107 echo $OUTPUT->heading(get_string('nomessages', 'chat')); 108 } else { 109 echo '<p class="boxaligncenter">'.userdate($start).' --> '. userdate($end).'</p>'; 110 111 echo $OUTPUT->box_start('center'); 112 $participates = array(); 113 foreach ($messages as $message) { // We are walking FORWARDS through messages. 114 if (!isset($participates[$message->userid])) { 115 $participates[$message->userid] = true; 116 } 117 $formatmessage = chat_format_message($message, $course->id, $USER); 118 if (isset($formatmessage->html)) { 119 echo $formatmessage->html; 120 } 121 } 122 $participatedcap = array_key_exists($USER->id, $participates) 123 && has_capability('mod/chat:exportparticipatedsession', $context); 124 125 if (!empty($CFG->enableportfolios) && ($canexportsess || $participatedcap)) { 126 require_once($CFG->libdir . '/portfoliolib.php'); 127 $buttonoptions = array( 128 'id' => $cm->id, 129 'start' => $start, 130 'end' => $end, 131 ); 132 $button = new portfolio_add_button(); 133 $button->set_callback_options('chat_portfolio_caller', $buttonoptions, 'mod_chat'); 134 $button->render(); 135 } 136 echo $OUTPUT->box_end(); 137 } 138 139 if (!$deletesession or !has_capability('mod/chat:deletelog', $context)) { 140 echo $OUTPUT->continue_button("report.php?id=$cm->id"); 141 } 142 143 echo $OUTPUT->footer(); 144 exit; 145 } 146 147 148 // Print the Sessions display. 149 $PAGE->navbar->add($strchatreport); 150 $PAGE->set_title(format_string($chat->name).": $strchatreport"); 151 echo $OUTPUT->header(); 152 153 echo $OUTPUT->heading(format_string($chat->name).': '.get_string('sessions', 'chat'), 2); 154 155 // Check to see if groups are being used here 156 if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used. 157 $currentgroup = groups_get_activity_group($cm, true); 158 groups_print_activity_menu($cm, $CFG->wwwroot . "/mod/chat/report.php?id=$cm->id"); 159 } else { 160 $currentgroup = false; 161 } 162 163 $params = array('currentgroup' => $currentgroup, 'chatid' => $chat->id, 'start' => $start, 'end' => $end); 164 165 // If the user is allocated to a group, only show discussions with people in 166 // the same group, or no group. 167 if (!empty($currentgroup)) { 168 $groupselect = " AND (groupid = :currentgroup OR groupid = 0)"; 169 } else { 170 $groupselect = ""; 171 } 172 173 // Delete a session if one has been specified. 174 175 if ($deletesession and has_capability('mod/chat:deletelog', $context) 176 and $confirmdelete and $start and $end and confirm_sesskey()) { 177 178 $DB->delete_records_select('chat_messages', "chatid = :chatid AND timestamp >= :start AND 179 timestamp <= :end $groupselect", $params); 180 $strdeleted = get_string('deleted'); 181 echo $OUTPUT->notification("$strdeleted: ".userdate($start).' --> '. userdate($end)); 182 unset($deletesession); 183 } 184 185 // Get the messages. 186 if (empty($messages)) { // May have already got them above. 187 if (!$messages = chat_get_session_messages($chat->id, $currentgroup, 0, 0, 'timestamp DESC')) { 188 echo $OUTPUT->heading(get_string('nomessages', 'chat'), 3); 189 echo $OUTPUT->footer(); 190 exit; 191 } 192 } 193 194 if ($showall) { 195 $headingstr = get_string('listing_all_sessions', 'chat') . ' '; 196 $headingstr .= html_writer::link("report.php?id={$cm->id}&show_all=0", get_string('list_complete_sessions', 'chat')); 197 echo $OUTPUT->heading($headingstr, 3); 198 } 199 200 // Show all the sessions. 201 $completesessions = 0; 202 203 echo '<div class="list-group">'; 204 205 $sessions = chat_get_sessions($messages, $showall); 206 207 foreach ($sessions as $session) { 208 echo '<div class="list-group-item">'; 209 echo '<p>'.userdate($session->sessionstart).' --> '. userdate($session->sessionend).'</p>'; 210 211 echo $OUTPUT->box_start(); 212 213 arsort($session->sessionusers); 214 foreach ($session->sessionusers as $sessionuser => $usermessagecount) { 215 if ($user = $DB->get_record('user', array('id' => $sessionuser))) { 216 $OUTPUT->user_picture($user, array('courseid' => $course->id)); 217 echo ' ' . fullname($user, $canviewfullnames); 218 echo " ($usermessagecount)<br />"; 219 } 220 } 221 222 echo '<p align="right">'; 223 echo "<a href=\"report.php?id=$cm->id&start=$session->sessionstart&end=$session->sessionend\">$strseesession</a>"; 224 $participatedcap = (array_key_exists($USER->id, $session->sessionusers) 225 && has_capability('mod/chat:exportparticipatedsession', $context)); 226 if (!empty($CFG->enableportfolios) && ($canexportsess || $participatedcap)) { 227 require_once($CFG->libdir . '/portfoliolib.php'); 228 $buttonoptions = array( 229 'id' => $cm->id, 230 'start' => $session->sessionstart, 231 'end' => $session->sessionend, 232 ); 233 $button = new portfolio_add_button(); 234 $button->set_callback_options('chat_portfolio_caller', $buttonoptions, 'mod_chat'); 235 $portfoliobutton = $button->to_html(PORTFOLIO_ADD_TEXT_LINK); 236 if (!empty($portfoliobutton)) { 237 echo '<br />' . $portfoliobutton; 238 } 239 } 240 if (has_capability('mod/chat:deletelog', $context)) { 241 $deleteurl = "report.php?id=$cm->id&start=$session->sessionstart&end=$session->sessionend&deletesession=1"; 242 echo "<br /><a href=\"$deleteurl\">$strdeletesession</a>"; 243 } 244 echo '</p>'; 245 echo $OUTPUT->box_end(); 246 echo '</div>'; 247 248 if ($session->iscomplete) { 249 $completesessions++; 250 } 251 } 252 253 echo '</div>'; 254 255 if (!empty($CFG->enableportfolios) && $canexportsess) { 256 require_once($CFG->libdir . '/portfoliolib.php'); 257 $button = new portfolio_add_button(); 258 $button->set_callback_options('chat_portfolio_caller', array('id' => $cm->id), 'mod_chat'); 259 $button->render(null, get_string('addalltoportfolio', 'portfolio')); 260 } 261 262 263 if (!$showall and $completesessions == 0) { 264 echo html_writer::start_tag('p'); 265 echo get_string('no_complete_sessions_found', 'chat') . ' '; 266 echo html_writer::link('report.php?id='.$cm->id.'&show_all=1', get_string('list_all_sessions', 'chat')); 267 echo html_writer::end_tag('p'); 268 } 269 270 // Finish the page. 271 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body