From 10ae55f99bd8c4465b2f1a80a71cd6fed326f8eb Mon Sep 17 00:00:00 2001 From: mjollnir_ Date: Fri, 25 Jul 2008 12:30:08 +0000 Subject: [PATCH] MDL-15758 : beginning of forum implementation of portfolio export --- lang/en_utf8/forum.php | 3 ++ mod/forum/discuss.php | 11 ++++ mod/forum/lib.php | 114 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 126 insertions(+), 2 deletions(-) diff --git a/lang/en_utf8/forum.php b/lang/en_utf8/forum.php index d4d947389e..9d68ac70f2 100644 --- a/lang/en_utf8/forum.php +++ b/lang/en_utf8/forum.php @@ -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'; diff --git a/mod/forum/discuss.php b/mod/forum/discuss.php index 1c871806f0..cd95b80f4a 100644 --- a/mod/forum/discuss.php +++ b/mod/forum/discuss.php @@ -156,6 +156,13 @@ /// 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 '
'; // groups selector not needed here @@ -164,6 +171,10 @@ forum_print_mode_form($discussion->id, $displaymode); echo ""; + if ($portfolio) { + echo $portfolio . ''; + } + if ($forum->type != 'single' && has_capability('mod/forum:movediscussions', $modcontext)) { diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 869187d89e..47b0732e2d 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -3002,6 +3002,13 @@ function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=fa $commands[] = ''.$strreply.''; } + 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 '
'; echo implode(' | ', $commands); echo '
'; @@ -3760,7 +3767,16 @@ function forum_print_attachments($post, $return=NULL) { if ($return == "html") { $output .= "$image "; - $output .= "$file
"; + $output .= "$file"; + 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 .= "
"; } else if ($return == "text") { $output .= "$strattachment $file:\n$ffurl\n"; @@ -3770,7 +3786,16 @@ function forum_print_attachments($post, $return=NULL) { $imagereturn .= "
\"\""; } else { echo "$image "; - echo filter_text("$file
"); + echo filter_text("$file"); + 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 '
'; } } } @@ -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); + } +} + ?> -- 2.39.5