$string['cantinsert'] = 'Could not insert a chat message!';
$string['chat:chat'] = 'Talk in a chat';
$string['chat:deletelog'] = 'Delete chat logs';
+$string['chat:exportsession'] = 'Export chat session';
+$string['chat:exportparticipatedsession'] = 'Export participated-in chat session';
$string['chat:readlog'] = 'Read chat logs';
$string['chatintro'] = 'Introduction text';
$string['chatname'] = 'Name of this chat room';
'editingteacher' => CAP_ALLOW,
'admin' => CAP_ALLOW
)
- )
+ ),
+
+ 'mod/chat:exportparticipatedsession' => array(
+
+ 'riskbitmask' => RISK_PERSONAL,
+
+ 'captype' => 'read',
+ 'contextlevel' => CONTEXT_MODULE,
+ 'legacy' => array(
+ 'teacher' => CAP_ALLOW,
+ 'editingteacher' => CAP_ALLOW,
+ 'admin' => CAP_ALLOW,
+ // not student - nervous about allowing this by default
+ ),
+
+ ),
+
+ 'mod/chat:exportsession' => array(
+
+ 'riskbitmask' => RISK_PERSONAL,
+
+ 'captype' => 'read',
+ 'contextlevel' => CONTEXT_MODULE,
+ 'legacy' => array(
+ 'teacher' => CAP_ALLOW,
+ 'editingteacher' => CAP_ALLOW,
+ 'admin' => CAP_ALLOW,
+ ),
+ ),
);
return array('moodle/site:accessallgroups', 'moodle/site:viewfullnames');
}
+require_once($CFG->libdir . '/portfoliolib.php');
+class chat_portfolio_caller extends portfolio_module_caller_base {
+
+ private $chat;
+ private $start;
+ private $end;
+
+ public function __construct($callbackargs) {
+ global $DB, $USER;
+ if (!$this->cm = get_coursemodule_from_id('chat', $callbackargs['id'])) {
+ portfolio_exporter::raise_error('invalidid', 'chat');
+ }
+ $this->chat = $DB->get_record('chat', array('id' => $this->cm->instance));
+ $select = 'chatid = ?';
+ $params = array($this->chat->id);
+ if (array_key_exists('start', $callbackargs) && array_key_exists('end', $callbackargs)
+ && !empty($callbackargs['start']) && !empty($callbackargs['end'])) {
+ $select .= ' AND timestamp >= ? AND timestamp <= ?';
+ $params[] = $callbackargs['start'];
+ $params[] = $callbackargs['end'];
+ $this->start = $callbackargs['start'];
+ $this->end = $callbackargs['end'];
+ }
+ $this->messages = $DB->get_records_select(
+ 'chat_messages',
+ $select,
+ $params,
+ 'timestamp ASC'
+ );
+ $select .= ' AND userid = ?';
+ $params[] = $USER->id;
+ $this->participated = $DB->record_exists_select(
+ 'chat_messages',
+ $select,
+ $params
+ );
+ }
+
+ public function expected_time() {
+ return PORTFOLIO_TIME_LOW;
+ }
+
+ public function get_sha1() {
+ $str = '';
+ ksort($this->messages);
+ foreach ($this->messages as $m) {
+ $str .= implode('', (array)$m);
+ }
+ return sha1($str);
+ }
+
+ public function check_permissions() {
+ $context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
+ return has_capability('mod/chat:exportsession', $context)
+ || ($this->participated
+ && has_capability('mod/chat:exportparticipatedsession', $context));
+ }
+
+ public function prepare_package() {
+ $content = '';
+ foreach ($this->messages as $message) { // We are walking FORWARDS through messages
+ $m = clone $message; // grrrrrr
+ $formatmessage = chat_format_message($m, null, $this->user);
+ if (!isset($formatmessage->html)) {
+ continue;
+ }
+ $content .= $formatmessage->html;
+ }
+ $content = preg_replace('/\<img[^>]*\>/', '', $content);
+
+ return $this->exporter->write_new_file($content, clean_filename($this->cm->name . '-session.html'));
+ }
+
+ public static function display_name() {
+ return get_string('modulename', 'chat');
+ }
+
+ public function get_return_url() {
+ global $CFG;
+
+ return $CFG->wwwroot . '/mod/chat/report.php?id='
+ . $this->cm->id . ((isset($this->start))
+ ? '&start=' . $this->start . '&end=' . $this->end
+ : '');
+ }
+}
+
?>
echo $formatmessage->html;
}
}
+ if (has_capability('mod/chat:exportsession', $context)
+ || (array_key_exists($USER->id, $sessionusers)
+ && has_capability('mod/chat:exportparticipatedsession', $context))) {
+ require_once($CFG->libdir . '/portfoliolib.php');
+ $p = array(
+ 'id' => $cm->id,
+ 'start' => $start,
+ 'end' => $end,
+ );
+ echo '<br />' . portfolio_add_button('chat_portfolio_caller', $p, '/mod/chat/lib.php', PORTFOLIO_ADD_FULL_FORM, null, true);
+ }
print_simple_box_end();
}
echo '<p align="right">';
echo "<a href=\"report.php?id=$cm->id&start=$sessionstart&end=$sessionend\">$strseesession</a>";
+ if (has_capability('mod/chat:exportsession', $context)
+ || (array_key_exists($USER->id, $sessionusers)
+ && has_capability('mod/chat:exportparticipatedsession', $context))) {
+ require_once($CFG->libdir . '/portfoliolib.php');
+ $p = array(
+ 'id' => $cm->id,
+ 'start' => $sessionstart,
+ 'end' => $sessionend,
+ );
+ echo '<br />' . portfolio_add_button('chat_portfolio_caller', $p, '/mod/chat/lib.php', PORTFOLIO_ADD_TEXT_LINK, null, true);
+ }
if (has_capability('mod/chat:deletelog', $context)) {
echo "<br /><a href=\"report.php?id=$cm->id&start=$sessionstart&end=$sessionend&deletesession=1\">$strdeletesession</a>";
}
$lasttime = $message->timestamp;
}
+ if (has_capability('mod/chat:exportsession', $context)) {
+ require_once($CFG->libdir . '/portfoliolib.php');
+ $p = array(
+ 'id' => $cm->id,
+ );
+ echo '<br />' . portfolio_add_button('chat_portfolio_caller', $p, '/mod/chat/lib.php', PORTFOLIO_ADD_FULL_FORM, get_string('addalltoportfolio', 'portfolio'), true);
+ }
+
+
/// Finish the page
print_footer($course);
/// This fragment is called by moodle_needs_upgrading() and /admin/index.php
/////////////////////////////////////////////////////////////////////////////////
-$module->version = 2008072400; // The (date) version of this module
+$module->version = 2008081400; // The (date) version of this module
$module->requires = 2007101509; // Requires this Moodle version
$module->cron = 300; // How often should cron check this module (seconds)?