Skip to content

Commit

Permalink
Update to current OU live version
Browse files Browse the repository at this point in the history
  • Loading branch information
sammarshallou committed Mar 12, 2013
1 parent 3f36dc0 commit a5bc7d6
Show file tree
Hide file tree
Showing 18 changed files with 955 additions and 47 deletions.
81 changes: 81 additions & 0 deletions feature/export/exportall.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Export to portfolio script. This uses the discussion selector infrastructure to
* handle the situation when discussions are being selected.
* @package forumngfeature
* @subpackage export
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(__FILE__) . '/../forumngfeature_discussion_selector.php');

class export_discussion_selector extends forumngfeature_discussion_selector {
public function get_button_name() {
return get_string('export', 'forumngfeature_export');
}

public function apply($discussion, $all, $selected, $formdata) {
global $COURSE, $USER, $CFG;

if (!$CFG->enableportfolios) {
return '';
}

/*
* It is necessary to encode the array of selected discussion posts as text in order to
* pass the data in the button callback options because it gets filtered as PARAM_ALPHA
*/
if (is_array($selected) && !empty($selected)) {
$seltext = implode('x', $selected);
$letters = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j');
$posts = '';
$selarray = str_split($seltext);
foreach ($selarray as $char) {
$posts .= ($char == 'x')? $char:$letters[$char];
}
} else {
$posts = '';
}

// Get the id of the forum.
$forumngid = $discussion->get_id();

require_once($CFG->libdir . '/portfoliolib.php');

// Check if the forum is shared and pass the cloneid in the callback options.
$linkparams = $discussion->get_link_params_array();
if (array_key_exists('clone', $linkparams)) {
$cloneid = $linkparams['clone'];
} else {
$cloneid = 0;
}

$button = new portfolio_add_button();
$button->set_callback_options('forumng_discussions_portfolio_caller',
array('forumngid' => $forumngid,
'cloneid' => $cloneid,
'discussionids' => $posts),
'/mod/forumng/feature/export/portfoliolib.php');
$button->set_formats(PORTFOLIO_FORMAT_PLAINHTML);

// Redirect to the export page.
redirect($button->to_html(PORTFOLIO_ADD_FAKE_URL));
}
}

forumngfeature_discussion_selector::go(new export_discussion_selector());
25 changes: 20 additions & 5 deletions feature/export/forumngfeature_export.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,25 @@
*/
class forumngfeature_export extends forumngfeature_discussion {
public function get_order() {
return 1000;
global $PAGE;
if ($PAGE->pagetype == 'mod-forumng-view') {
return 300;
} else {
return 1000;
}
}

public function display($discussion) {
return parent::get_button($discussion,
get_string('export', 'forumngfeature_export'),
'feature/export/export.php',
false, array(), '', false, true);
if (is_a($discussion, 'mod_forumng_discussion')) {
return parent::get_button($discussion,
get_string('export', 'forumngfeature_export'),
'feature/export/export.php',
false, array(), '', false, true);
} else {
return forumngfeature_discussion_list::get_button($discussion,
get_string('export', 'forumngfeature_export'), 'feature/export/exportall.php',
false, $_GET, '', 'forumng-dselectorbutton', '', '');
}
}

// Always display the Export button
Expand All @@ -51,4 +62,8 @@ public function should_display($discussion) {

return true;
}

public function supports_discussion_list() {
return true;
}
}
1 change: 1 addition & 0 deletions feature/export/lang/en/forumngfeature_export.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@
*/
$string['export'] = 'Export';
$string['pluginname'] = 'Export posts';
$string['exportallnodisc'] = 'No discussions selected for export';
139 changes: 133 additions & 6 deletions feature/export/portfoliolib.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ class forumng_all_portfolio_caller extends forumng_portfolio_caller_base {
protected $cloneid;
protected $posts;
protected $discussionid;
protected $filenames = array();
protected $content = '';

public static function expected_callbackargs() {
return array(
Expand All @@ -212,7 +214,7 @@ public function get_return_url() {

public function prepare_package() {
global $CFG;

$plugin = $this->get('exporter')->get('instance')->get('plugin');
/*
* decoding the array from letters to numbers, see export.php
*/
Expand All @@ -239,12 +241,22 @@ public function prepare_package() {
$discussion->build_selected_posts_email($selected, $poststext, $postshtml,
array(mod_forumng_post::OPTION_EXPORT => true));
$allhtml .= $postshtml;

// Finish the file.
$allhtml .= html_writer::end_tag('body') . html_writer::end_tag('html');
if ($plugin == 'rtf' && isset($this->discussionids)) {
// Support discussions e.g. all into one file.
if ($this->discussionid != $this->discussionids[0]) {
// Make this text just body if not first discussion.
$allhtml = $postshtml;
}
if ($this->discussionid == $this->discussionids[count($this->discussionids) - 1]) {
// Finish the file if last discussion (might be first and last if only 1).
$allhtml .= html_writer::end_tag('body') . html_writer::end_tag('html');
}
} else {
// Finish the file.
$allhtml .= html_writer::end_tag('body') . html_writer::end_tag('html');
}

// Remove embedded img and attachment paths.
$plugin = $this->get('exporter')->get('instance')->get('plugin');
$portfolioformat = $this->get('exporter')->get('format');
foreach ($this->files as $file) {
$filename = $file->get_filename();
Expand Down Expand Up @@ -289,7 +301,31 @@ public function prepare_package() {
}

$content = $allhtml;
$name = $this->make_filename_safe('forum_discussion') . '.html';
if ($plugin == 'rtf' && isset($this->discussionids)) {
// Different functionality if multiple discussions.
if ($this->discussionid != $this->discussionids[count($this->discussionids) - 1]) {
$this->content .= $content;
return;
} else {
$content = $this->content . $content;
$forum = mod_forumng::get_from_cmid($this->cm->id, $this->cloneid);
$name = $this->make_filename_safe($forum->get_name()) . '.html';
}
} else {
$name = $this->make_filename_safe($discussion->get_subject(true));
if (in_array($name, $this->filenames)) {
// Make unique filename.
for ($a = 1; $a < 100; $a++) {
if (!in_array("$name$a", $this->filenames)) {
$name = "$name$a";
break;
}
}
}
$this->filenames[] = $name;
$name .= '.html';
}

$manifest = ($this->exporter->get('format') instanceof PORTFOLIO_FORMAT_RICH);

$this->copy_files($this->multifiles);
Expand All @@ -306,3 +342,94 @@ public function get_sha1() {
return sha1($bigstring);
}
}

/**
* Portfolio class for exporting the contents of multiple discussions.
*/
class forumng_discussions_portfolio_caller extends forumng_all_portfolio_caller {
protected $discussionids;

public static function expected_callbackargs() {
return array(
'forumngid' => true,
'cloneid' => true,
'discussionids' => true);
}

public function heading_summary() {
$forum = mod_forumng::get_from_cmid($this->cm->id, $this->cloneid);
return get_string('exportingcontentfrom', 'portfolio', strtolower(get_string('forum', 'forumng')).
': ' . $forum->get_name());
}

public function load_data() {
global $DB, $COURSE;

// Load base data
$this->load_base_data($this->forumngid);

// Get all files used in the discussions.
if ($this->discussionids == '') {
// Fallback in case nothing sent - get every discussion in forum!
$this->discussionids = array();
$groupid = mod_forumng::get_activity_group($this->cm, true);
if ($groupid == -1) {
$groupid = null;
}
$discussions = $DB->get_records('forumng_discussions',
array('forumngid' => $this->cm->instance, 'groupid' => $groupid), '', 'id, postid');
foreach ($discussions as $discussionrec) {
if (!$discussionrec->postid) {
continue;
}
$discussion = mod_forumng_discussion::get_from_id($discussionrec->id, $this->cloneid);
if ($discussion->can_view()) {
$this->discussionids[] = $discussion->get_id();
}
}
} else {
$this->posts = $this->discussionids;// Set so decode works.
$this->discussionids = $this->decode_string_to_array();
$this->posts = '';
}
if (empty($this->discussionids)) {
throw new moodle_exception('exportallnodisc', 'forumngfeature_export', $this->get_return_url());
}
foreach ($this->discussionids as $discussionid) {
$this->discussionid = $discussionid;
$this->add_files();
}
}

public function get_return_url() {
return new moodle_url('/mod/forumng/view.php',
array('id' => $this->cm->id, 'clone' => $this->cloneid));
}

public function prepare_package() {
$baseurl = $this->get_return_url();
$this->content = '';
foreach ($this->discussionids as $discussionid) {
$this->discussionid = $discussionid;
parent::prepare_package();
}
}

public function get_sha1() {
$filesha = '';
if (!empty($this->multifiles)) {
$filesha = $this->get_sha1_file();
}
$bigstring = $filesha;

return sha1($bigstring);
}

public static function base_supported_formats() {
return array(PORTFOLIO_FORMAT_RICHHTML);
}

public function get_navigation() {
return array(array(), $this->cm);
}
}
2 changes: 1 addition & 1 deletion feature/export/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

$plugin->version = 2011020301;
$plugin->version = 2013012400;
10 changes: 10 additions & 0 deletions feature/forumngfeature_discussion.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ public function should_display($discussion) {
return $discussion->can_manage() && !$discussion->is_deleted();
}

/**
* Can this discussion feature also show on discussion list page?
* Whether it should or not is check in should_display()
* Defaults to false.
* @return bool true if feature supports discussion list as well
*/
public function supports_discussion_list() {
return false;
}

/**
* @param mod_forumng_discussion $discussion
* @return string HTML code for button
Expand Down
10 changes: 7 additions & 3 deletions feature/forumngfeature_discussion_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@ public abstract function display($forum);
* @param string $script Name/path of .php script (relative to mod/forumng)
* @param bool $post If true, makes the button send a POST request
* @param array $options If included, passes these options as well as 'd'
* (Must send $_GET for discussion selector buttons)
* @param string $afterhtml If specified, adds this HTML at end of (just
* inside) the form
* @param bool $highlight If true, adds a highlight class to the form
* @param string $class Adds a class to the form (set to 'forumng-dselectorbutton'
* to activate discussion selector)
* @param string $beforehtml If specified, adds this HTML at start of (just
* inside) the form
* @param string $buttonclass If set, adds additional css class to the button
* @return string HTML code for button
*/
protected static function get_button($forum, $name, $script,
public static function get_button($forum, $name, $script,
$post=false, $options=array(), $afterhtml='', $class='',
$beforehtml='', $buttonclass='') {
$method = $post ? 'post' : 'get';
Expand Down Expand Up @@ -95,7 +97,9 @@ public static function get_all() {
$all = forumngfeature::get_all();
$results = array();
foreach ($all as $feature) {
if (is_a($feature, 'forumngfeature_discussion_list')) {
if (is_a($feature, 'forumngfeature_discussion_list') ||
(is_a($feature, 'forumngfeature_discussion')
&& $feature->supports_discussion_list())) {
$results[] = $feature;
}
}
Expand Down

0 comments on commit a5bc7d6

Please sign in to comment.