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