]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-15758 - chat module portfolio export
authormjollnir_ <mjollnir_>
Mon, 18 Aug 2008 10:16:56 +0000 (10:16 +0000)
committermjollnir_ <mjollnir_>
Mon, 18 Aug 2008 10:16:56 +0000 (10:16 +0000)
lang/en_utf8/chat.php
mod/chat/db/access.php
mod/chat/lib.php
mod/chat/report.php
mod/chat/version.php

index cb1ac679d165e76a71c1fa79bf9f95533cd15e83..b6545016f0e59848743640767dee6d8b91ab3e29 100644 (file)
@@ -8,6 +8,8 @@ $string['cantlogin'] = 'Could not log in to chat room!!';
 $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';
index e3d25887c02b0cba6afbbd015dbf6c469dfe88f3..f34243f41ec9c8cc1b14f3873aeec1edfc6d0434 100644 (file)
@@ -68,7 +68,35 @@ $mod_chat_capabilities = array(
             '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,
+        ),
+    ),
 
 );
 
index b0d0eb5ec284775cd802410dc03dc04efd17d7f6..f794995da39ed0d4c5be5a56245957973d6078be 100644 (file)
@@ -819,4 +819,91 @@ function chat_get_extra_capabilities() {
     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
+                : '');
+    }
+}
+
 ?>
index 2d6de6f13806dcff3b665aab177f78c9f74c0aab..6f08cd8aba954ea1698bba77a3e13fcc98a71a17 100644 (file)
                     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&amp;start=$sessionstart&amp;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&amp;start=$sessionstart&amp;end=$sessionend&amp;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);
 
index c933033c04a9bda360b9bbed2cffacc3dbdcc619..8873b80f91803e3070af589f18e418488f851791 100644 (file)
@@ -5,7 +5,7 @@
 ///  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)?