]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-15758 : beginning of forum implementation of portfolio export
authormjollnir_ <mjollnir_>
Fri, 25 Jul 2008 12:30:08 +0000 (12:30 +0000)
committermjollnir_ <mjollnir_>
Fri, 25 Jul 2008 12:30:08 +0000 (12:30 +0000)
lang/en_utf8/forum.php
mod/forum/discuss.php
mod/forum/lib.php

index d4d947389e9d16a45d91cf2842b82132c8cef6ff..9d68ac70f29496d4fe7f42ce70339cf2c533aa8c 100644 (file)
@@ -22,6 +22,7 @@ $string['allsubscribe'] = 'Subscribe to all forums';
 $string['allunsubscribe'] = 'Unsubscribe from all forums';
 $string['anyfile'] = 'Any file';
 $string['attachment'] = 'Attachment';
+$string['attachmentnopost'] = 'You cannot export attachments without a post id';
 $string['blockafter'] = 'Post threshold for blocking';
 $string['blockperiod'] = 'Time period for blocking';
 $string['blockperioddisabled'] = 'Don\'t block';
@@ -160,10 +161,12 @@ $string['modulenameplural'] = 'Forums';
 $string['more'] = 'more';
 $string['movedmarker'] = '(Moved)';
 $string['movethisdiscussionto'] = 'Move this discussion to ...';
+$string['mustprovidediscussionorpost'] = 'You must provide either a discussion id or post id to export';
 $string['namenews'] = 'News forum';
 $string['namesocial'] = 'Social forum';
 $string['nameteacher'] = 'Teacher forum'; //depreciated after 1.7
 $string['newforumposts'] = 'New forum posts';
+$string['noattachments'] = 'There are no attachments to this post';
 $string['nodiscussions'] = 'There are no discussion topics yet in this forum';
 $string['nodiscussionsstartedby'] = 'No discussions started by this user';
 $string['noguestpost'] = 'Sorry, guests are not allowed to post. $a';
index 1c871806f06b87210f8471ce485fccb3c4971be8..cd95b80f4af7c37a179b74e9f63b709dde579d67 100644 (file)
 
 /// Print the controls across the top
 
+    if (true) { // @todo penny replace with capability check later
+
+        $p = array(
+            'discussionid' => $discussion->id,
+        );
+        $portfolio = portfolio_add_button('forum_portfolio_caller', $p, '/mod/forum/lib.php', true, true);
+    }
     echo '<table width="100%" class="discussioncontrols"><tr><td>';
 
     // groups selector not needed here
     forum_print_mode_form($discussion->id, $displaymode);
     echo "</td><td>";
 
+    if ($portfolio) {
+        echo $portfolio . '</td><td>';
+    }
+
     if ($forum->type != 'single'
                 && has_capability('mod/forum:movediscussions', $modcontext)) {
 
index 869187d89e62bbc28baa0d564835a0c20db1195e..47b0732e2d4a27ad1f5f239206ccfb22e44fe9a2 100644 (file)
@@ -3002,6 +3002,13 @@ function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=fa
         $commands[] = '<a href="'.$CFG->wwwroot.'/mod/forum/post.php?reply='.$post->id.'">'.$strreply.'</a>';
     }
 
+    if (true) { // @todo penny replace this later with a capability check
+        $p = array(
+            'postid' => $post->id,
+        );
+        $commands[] = portfolio_add_button('forum_portfolio_caller', $p, '/mod/forum/lib.php', false, true);
+    }
+
     echo '<div class="commands">';
     echo implode(' | ', $commands);
     echo '</div>';
@@ -3760,7 +3767,16 @@ function forum_print_attachments($post, $return=NULL) {
 
                 if ($return == "html") {
                     $output .= "<a href=\"$ffurl\">$image</a> ";
-                    $output .= "<a href=\"$ffurl\">$file</a><br />";
+                    $output .= "<a href=\"$ffurl\">$file</a>";
+                    if (true) { // 'todo penny replace this with a capability check
+                        require_once($CFG->libdir . '/portfoliolib.php');
+                        $p = array(
+                            'postid' => $post->id,
+                            'attachment' => 1,
+                        );
+                        $output .= portfolio_add_button('forum_portfolio_caller', $p, '/mod/forum/lib.php', false, true);
+                    }
+                    $output .= "<br />";
 
                 } else if ($return == "text") {
                     $output .= "$strattachment $file:\n$ffurl\n";
@@ -3770,7 +3786,16 @@ function forum_print_attachments($post, $return=NULL) {
                         $imagereturn .= "<br /><img src=\"$ffurl\" alt=\"\" />";
                     } else {
                         echo "<a href=\"$ffurl\">$image</a> ";
-                        echo filter_text("<a href=\"$ffurl\">$file</a><br />");
+                        echo filter_text("<a href=\"$ffurl\">$file</a>");
+                        if (true) { // 'todo penny replace this with a capability check
+                            require_once($CFG->libdir . '/portfoliolib.php');
+                            $p = array(
+                                'postid' => $post->id,
+                                'attachment' => 1,
+                            );
+                            portfolio_add_button('forum_portfolio_caller', $p, '/mod/forum/lib.php', false);
+                        }
+                        echo '<br />';
                     }
                 }
             }
@@ -6871,4 +6896,89 @@ function forum_get_extra_capabilities() {
     return array('moodle/site:accessallgroups', 'moodle/site:viewfullnames', 'moodle/site:trustcontent');
 }
 
+require_once($CFG->libdir . '/portfoliolib.php');
+class forum_portfolio_caller extends portfolio_caller_base {
+
+    private $cm;
+    private $post;
+    private $forum;
+    private $discussion;
+    private $attachment;
+
+    function __construct($callbackargs) {
+        global $DB;
+
+        if (array_key_exists('postid', $callbackargs)) {
+            if (!$this->post = $DB->get_record('forum_posts', array('id' => $callbackargs['postid']))) {
+                print_error('invalidpostid', 'forum');
+            }
+        }
+        $dparams = array();
+        if (array_key_exists('discussionid', $callbackargs)) {
+            $dbparams = array('id' => $callbackargs['discussionid']);
+        } else if ($this->post) {
+            $dbparams = array('id' => $this->post->discussion);
+        } else {
+            print_error('mustprovidediscussionorpost', 'forum');
+        }
+        if (!$this->discussion = $DB->get_record('forum_discussions', $dbparams)) {
+            print_error('invaliddiscussionid', 'forum');
+        }
+        if (!$this->forum = $DB->get_record('forum', array('id' => $this->discussion->forum))) {
+            print_error('invalidforumid', 'forum');
+        }
+        if (!$this->cm = get_coursemodule_from_instance('forum', $this->forum->id)) {
+            print_error('invalidcoursemodule');
+        }
+        if ($this->attachment = (array_key_exists('attachment', $callbackargs) ? $callbackargs['attachment'] : false)) {
+            if (!$this->post) {
+                print_error('attachmentsnopost', 'forum');
+            }
+            if (!get_directory_list(forum_file_area($this->post->id))) {
+                print_error('noattachments', 'forum');
+            }
+        }
+    }
+
+    function get_return_url() {
+        global $CFG;
+        return $CFG->wwwroot . '/mod/forum/discuss.php?d=' . $this->cm->id;
+    }
+
+    function prepare_package($tempdir) {
+        global $CFG;
+        if ($this->attachment) {
+            if ($basedir = forum_file_area($this->post)) {
+                //@todo penny fix all this with files api
+                require_once($CFG->dirroot . '/backup/lib.php');
+                return backup_copy_file($basedir, $tempdir);
+            }
+            return true;
+        }
+        print_error('TODO');
+        // @todo see MDL-15758
+    }
+
+    static function supported_formats() {
+        // we always have to support the possibility here that we have attachments
+        // and HTML is a subset of FILE anyway.
+        return array(PORTFOLIO_FORMAT_FILE);
+    }
+
+    function expected_time() {
+        // @todo check for attachment size
+        return PORTFOLIO_TIME_LOW;
+    }
+
+    function check_permissions() {
+        //@todo
+        return true;
+    }
+
+    function get_navigation() {
+        $extranav = array('name' => $this->cm->name, 'link' => $this->get_return_url());
+        return array($extranav, $this->cm);
+    }
+}
+
 ?>