[ Index ] |
PHP Cross Reference of moodle-2.8 |
[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 /** 18 * Library of functions for chat outside of the core api 19 */ 20 21 require_once($CFG->dirroot . '/mod/chat/lib.php'); 22 require_once($CFG->libdir . '/portfolio/caller.php'); 23 24 /** 25 * @package mod_chat 26 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} 27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 28 */ 29 class chat_portfolio_caller extends portfolio_module_caller_base { 30 /** @var object */ 31 private $chat; 32 /** @var int Timestamp */ 33 protected $start; 34 /** @var int Timestamp */ 35 protected $end; 36 /** 37 * @return array 38 */ 39 public static function expected_callbackargs() { 40 return array( 41 'id' => true, 42 'start' => false, 43 'end' => false, 44 ); 45 } 46 /** 47 * @global object 48 */ 49 public function load_data() { 50 global $DB; 51 52 if (!$this->cm = get_coursemodule_from_id('chat', $this->id)) { 53 throw new portfolio_caller_exception('invalidid', 'chat'); 54 } 55 $this->chat = $DB->get_record('chat', array('id' => $this->cm->instance)); 56 $select = 'chatid = ?'; 57 $params = array($this->chat->id); 58 if ($this->start && $this->end) { 59 $select .= ' AND timestamp >= ? AND timestamp <= ?'; 60 $params[] = $this->start; 61 $params[] = $this->end; 62 } 63 $this->messages = $DB->get_records_select( 64 'chat_messages', 65 $select, 66 $params, 67 'timestamp ASC' 68 ); 69 $select .= ' AND userid = ?'; 70 $params[] = $this->user->id; 71 $this->participated = $DB->record_exists_select( 72 'chat_messages', 73 $select, 74 $params 75 ); 76 } 77 /** 78 * @return array 79 */ 80 public static function base_supported_formats() { 81 return array(PORTFOLIO_FORMAT_PLAINHTML); 82 } 83 /** 84 * 85 */ 86 public function expected_time() { 87 return portfolio_expected_time_db(count($this->messages)); 88 } 89 /** 90 * @return string 91 */ 92 public function get_sha1() { 93 $str = ''; 94 ksort($this->messages); 95 foreach ($this->messages as $m) { 96 $str .= implode('', (array)$m); 97 } 98 return sha1($str); 99 } 100 101 /** 102 * @return bool 103 */ 104 public function check_permissions() { 105 $context = context_module::instance($this->cm->id); 106 return has_capability('mod/chat:exportsession', $context) 107 || ($this->participated 108 && has_capability('mod/chat:exportparticipatedsession', $context)); 109 } 110 111 /** 112 * @todo Document this function 113 */ 114 public function prepare_package() { 115 $content = ''; 116 $lasttime = 0; 117 $sessiongap = 5 * 60; // 5 minutes silence means a new session 118 foreach ($this->messages as $message) { // We are walking FORWARDS through messages 119 $m = clone $message; // grrrrrr - this causes the sha1 to change as chat_format_message changes what it's passed. 120 $formatmessage = chat_format_message($m, $this->cm->course, $this->user); 121 if (!isset($formatmessage->html)) { 122 continue; 123 } 124 if (empty($lasttime) || (($message->timestamp - $lasttime) > $sessiongap)) { 125 $content .= '<hr />'; 126 $content .= userdate($message->timestamp); 127 } 128 $content .= $formatmessage->html; 129 $lasttime = $message->timestamp; 130 } 131 $content = preg_replace('/\<img[^>]*\>/', '', $content); 132 133 $this->exporter->write_new_file($content, clean_filename($this->cm->name . '-session.html'), false); 134 } 135 136 /** 137 * @return string 138 */ 139 public static function display_name() { 140 return get_string('modulename', 'chat'); 141 } 142 143 /** 144 * @global object 145 * @return string 146 */ 147 public function get_return_url() { 148 global $CFG; 149 150 return $CFG->wwwroot . '/mod/chat/report.php?id=' 151 . $this->cm->id . ((isset($this->start)) ? '&start=' . $this->start . '&end=' . $this->end : ''); 152 } 153 } 154 155 /** 156 * A chat event such a user entering or leaving a chat activity 157 * 158 * @package mod_chat 159 * @copyright 2012 Andrew Davis 160 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 161 */ 162 class event_message implements renderable { 163 164 /** @var string The URL of the profile of the user who caused the event */ 165 public $senderprofile; 166 167 /** @var string The ready to display name of the user who caused the event */ 168 public $sendername; 169 170 /** @var string Ready to display event time */ 171 public $time; 172 173 /** @var string Event description */ 174 public $event; 175 176 /** @var string The chat theme name */ 177 public $theme; 178 179 /** 180 * event_message constructor 181 * 182 * @param string $senderprofile The URL of the profile of the user who caused the event 183 * @param string $sendername The ready to display name of the user who caused the event 184 * @param string $time Ready to display event time 185 * @param string $theme The chat theme name 186 */ 187 public function __construct($senderprofile, $sendername, $time, $event, $theme) { 188 189 $this->senderprofile = $senderprofile; 190 $this->sendername = $sendername; 191 $this->time = $time; 192 $this->event = $event; 193 $this->theme = $theme; 194 } 195 } 196 197 /** 198 * A chat message from a user 199 * 200 * @package mod_chat 201 * @copyright 2012 Andrew Davis 202 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 203 */ 204 class user_message implements renderable { 205 206 /** @var string The URL of the profile of the user sending the message */ 207 public $senderprofile; 208 209 /** @var string The ready to display name of the user sending the message */ 210 public $sendername; 211 212 /** @var string HTML for the avatar of the user sending the message */ 213 public $avatar; 214 215 /** @var string Empty or a html class definition to append to the html */ 216 public $mymessageclass; 217 218 /** @var string Ready to display message time */ 219 public $time; 220 221 /** @var string The message */ 222 public $message; 223 224 /** @var string The name of the chat theme to use */ 225 public $theme; 226 227 /** 228 * user_message constructor 229 * 230 * @param string $senderprofile The URL of the profile of the user sending the message 231 * @param string $sendername The ready to display name of the user sending the message 232 * @param string $avatar HTML for the avatar of the user sending the message 233 * @param string $mymessageclass Empty or a html class definition to append to the html 234 * @param string $time Ready to display message time 235 * @param string $message The message 236 * @param string $theme The name of the chat theme to use 237 */ 238 public function __construct($senderprofile, $sendername, $avatar, $mymessageclass, $time, $message, $theme) { 239 240 $this->sendername = $sendername; 241 $this->avatar = $avatar; 242 $this->mymessageclass = $mymessageclass; 243 $this->time = $time; 244 $this->message = $message; 245 $this->theme = $theme; 246 } 247 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |