Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/chat/locallib.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00022 require_once($CFG->dirroot . '/mod/chat/lib.php');
00023 require_once($CFG->libdir . '/portfolio/caller.php');
00024 
00030 class chat_portfolio_caller extends portfolio_module_caller_base {
00032     private $chat;
00034     protected $start;
00036     protected $end;
00040     public static function expected_callbackargs() {
00041         return array(
00042             'id'    => true,
00043             'start' => false,
00044             'end'   => false,
00045         );
00046     }
00050     public function load_data() {
00051         global $DB;
00052 
00053         if (!$this->cm = get_coursemodule_from_id('chat', $this->id)) {
00054             throw new portfolio_caller_exception('invalidid', 'chat');
00055         }
00056         $this->chat = $DB->get_record('chat', array('id' => $this->cm->instance));
00057         $select = 'chatid = ?';
00058         $params = array($this->chat->id);
00059         if ($this->start && $this->end) {
00060             $select .= ' AND timestamp >= ? AND timestamp <= ?';
00061             $params[] = $this->start;
00062             $params[] = $this->end;
00063         }
00064         $this->messages = $DB->get_records_select(
00065                 'chat_messages',
00066                 $select,
00067                 $params,
00068                 'timestamp ASC'
00069             );
00070         $select .= ' AND userid = ?';
00071         $params[] = $this->user->id;
00072         $this->participated = $DB->record_exists_select(
00073             'chat_messages',
00074             $select,
00075             $params
00076         );
00077     }
00081     public static function base_supported_formats() {
00082         return array(PORTFOLIO_FORMAT_PLAINHTML);
00083     }
00087     public function expected_time() {
00088         return portfolio_expected_time_db(count($this->messages));
00089     }
00093     public function get_sha1() {
00094         $str = '';
00095         ksort($this->messages);
00096         foreach ($this->messages as $m) {
00097             $str .= implode('', (array)$m);
00098         }
00099         return sha1($str);
00100     }
00101 
00105     public function check_permissions() {
00106         $context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
00107         return has_capability('mod/chat:exportsession', $context)
00108             || ($this->participated
00109                 && has_capability('mod/chat:exportparticipatedsession', $context));
00110     }
00111 
00115     public function prepare_package() {
00116         $content = '';
00117         $lasttime = 0;
00118         $sessiongap = 5 * 60;    // 5 minutes silence means a new session
00119         foreach ($this->messages as $message) {  // We are walking FORWARDS through messages
00120             $m = clone $message; // grrrrrr - this causes the sha1 to change as chat_format_message changes what it's passed.
00121             $formatmessage = chat_format_message($m, $this->cm->course, $this->user);
00122             if (!isset($formatmessage->html)) {
00123                 continue;
00124             }
00125             if (empty($lasttime) || (($message->timestamp - $lasttime) > $sessiongap)) {
00126                 $content .= '<hr />';
00127                 $content .= userdate($message->timestamp);
00128             }
00129             $content .= $formatmessage->html;
00130             $lasttime = $message->timestamp;
00131         }
00132         $content = preg_replace('/<img[^>]*>/', '', $content);
00133 
00134         $this->exporter->write_new_file($content, clean_filename($this->cm->name . '-session.html'), false);
00135     }
00136 
00140     public static function display_name() {
00141         return get_string('modulename', 'chat');
00142     }
00143 
00148     public function get_return_url() {
00149         global $CFG;
00150 
00151         return $CFG->wwwroot . '/mod/chat/report.php?id='
00152             . $this->cm->id . ((isset($this->start))
00153                 ? '&start=' . $this->start . '&end=' . $this->end
00154                 : '');
00155     }
00156 }
 All Data Structures Namespaces Files Functions Variables Enumerations