this involves moving all formslib includes to where they're actually needed.
it also moves the portfolio stuff from assignment,data,chat,forum and glossary
into a locallib.php which involved creating it for many of those modules.
require_once(dirname(dirname(__FILE__)) . '/config.php');
require_once($CFG->libdir . '/portfoliolib.php');
+require_once($CFG->libdir . '/portfolio/forms.php');
require_once($CFG->libdir . '/adminlib.php');
$edit = optional_param('edit', 0, PARAM_INT);
}
// Portfolio
- if (empty($userindexpage) && $currentuser && !empty($CFG->enableportfolios) && has_capability('moodle/portfolio:export', $systemcontext) && portfolio_instances(true, false)) {
- $portfoliokey = $usersetting->add(get_string('portfolios', 'portfolio'), null, self::TYPE_SETTING);
- $url = new moodle_url($CFG->wwwroot .'/user/portfolio.php');
- $usersetting->get($portfoliokey)->add(get_string('configure', 'portfolio'), $url, self::TYPE_SETTING);
- $url = new moodle_url($CFG->wwwroot .'/user/portfoliologs.php');
- $usersetting->get($portfoliokey)->add(get_string('logs', 'portfolio'), $url, self::TYPE_SETTING);
+ if (empty($userindexpage) && $currentuser && !empty($CFG->enableportfolios) && has_capability('moodle/portfolio:export', $systemcontext)) {
+ require_once($CFG->libdir . '/portfoliolib.php');
+ if (portfolio_instances(true, false)) {
+ $portfoliokey = $usersetting->add(get_string('portfolios', 'portfolio'), null, self::TYPE_SETTING);
+ $url = new moodle_url($CFG->wwwroot .'/user/portfolio.php');
+ $usersetting->get($portfoliokey)->add(get_string('configure', 'portfolio'), $url, self::TYPE_SETTING);
+ $url = new moodle_url($CFG->wwwroot .'/user/portfoliologs.php');
+ $usersetting->get($portfoliokey)->add(get_string('logs', 'portfolio'), $url, self::TYPE_SETTING);
+ }
}
// Repository
* @return boolean whether or not to process the next stage. this is important as the control function is called recursively.
*/
public function process_stage_config() {
- global $OUTPUT;
+ global $OUTPUT, $CFG;
$pluginobj = $callerobj = null;
if ($this->instance->has_export_config()) {
$pluginobj = $this->instance;
'formats' => $formats,
'expectedtime' => $expectedtime,
);
+ require_once($CFG->libdir . '/portfolio/forms.php');
$mform = new portfolio_export_form('', $customdata);
if ($mform->is_cancelled()){
$this->cancel_request();
public static function rewaken_object($id) {
global $DB, $CFG;
require_once($CFG->libdir . '/filelib.php');
+ require_once($CFG->libdir . '/portfolio/exporter.php');
+ require_once($CFG->libdir . '/portfolio/caller.php');
+ require_once($CFG->libdir . '/portfolio/plugin.php');
if (!$data = $DB->get_record('portfolio_tempdata', array('id' => $id))) {
// maybe it's been finished already by a pull plugin
// so look in the logs
throw new portfolio_exception('notyours', 'portfolio');
}
if (!$readonly && $this->get('instance') && !$this->get('instance')->allows_multiple_exports()
- && ($already = portfolio_exporter::existing_exports($this->get('user')->id, $this->get('instance')->get('plugin')))
+ && ($already = portfolio_existing_exports($this->get('user')->id, $this->get('instance')->get('plugin')))
&& array_shift(array_keys($already)) != $this->get('id')
) {
$a = (object)array(
exit;
}
- /**
- * return a list of current exports for the given user
- * this will not go through and call rewaken_object, because it's heavy
- * it's really just used to figure out what exports are currently happening.
- * this is useful for plugins that don't support multiple exports per session
- *
- * @param int $userid the user to check for
- * @param string $type (optional) the portfolio plugin to filter by
- *
- * @return array
- */
- public static function existing_exports($userid, $type=null) {
- global $DB;
- $sql = 'SELECT t.*,t.instance,i.plugin,i.name FROM {portfolio_tempdata} t JOIN {portfolio_instance} i ON t.instance = i.id WHERE t.userid = ? ';
- $values = array($userid);
- if ($type) {
- $sql .= ' AND i.plugin = ?';
- $values[] = $type;
- }
- return $DB->get_records_sql($sql, $values);
- }
-
- /**
- * Return an array of existing exports by type for a given user.
- * This is much more lightweight than {@see existing_exports} because it only returns the types, rather than the whole serialised data
- * so can be used for checking availability of multiple plugins at the same time.
- */
- public static function existing_exports_by_plugin($userid) {
- global $DB;
- $sql = 'SELECT t.id,i.plugin FROM {portfolio_tempdata} t JOIN {portfolio_instance} i ON t.instance = i.id WHERE t.userid = ? ';
- $values = array($userid);
- return $DB->get_records_sql_menu($sql, $values);
- }
-
public static function print_cleaned_export($log, $instance=null) {
global $CFG, $OUTPUT, $PAGE;
if (empty($instance) || !$instance instanceof portfolio_plugin) {
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-/** require all the sublibraries first. */
-require_once($CFG->libdir . '/portfolio/constants.php'); // all the constants for time, export format etc.
+// require some of the sublibraries first.
+// this is not an exhaustive list, the others are pulled in as they're needed
+// so we don't have to always include everything unnecessarily for performance
+
+// very lightweight list of constants. always needed and no further dependencies
+require_once($CFG->libdir . '/portfolio/constants.php');
+// a couple of exception deinitions. always needed and no further dependencies
require_once($CFG->libdir . '/portfolio/exceptions.php'); // exception classes used by portfolio code
-require_once($CFG->libdir . '/portfolio/formats.php'); // the export format hierarchy
-require_once($CFG->libdir . '/portfolio/forms.php'); // the form classes that subclass moodleform
-require_once($CFG->libdir . '/portfolio/exporter.php'); // the exporter class
-require_once($CFG->libdir . '/portfolio/plugin.php'); // the base classes for plugins
-require_once($CFG->libdir . '/portfolio/caller.php'); // the base classes for calling code
+// The base class for the caller classes. We always need this because we're either drawing a button,
+// in which case the button needs to know the calling class definition, which requires the base class,
+// or we're exporting, in which case we need the caller class anyway.
+require_once($CFG->libdir . '/portfolio/caller.php');
+
+// the other dependencies are included on demand:
+// libdir/portfolio/formats.php - the classes for the export formats
+// libdir/portfolio/forms.php - all portfolio form classes (requires formslib)
+// libdir/portfolio/plugin.php - the base class for the export plugins
+// libdir/portfolio/exporter.php - the exporter class
+
/**
* use this to add a portfolio button or icon or form to a page
throw new portfolio_button_exception('nocallbackfile', 'portfolio', $file);
}
$this->callbackfile = $file;
+ require_once($CFG->libdir . '/portfolio/caller.php'); // require the base class first
require_once($CFG->dirroot . $file);
if (!class_exists($class)) {
throw new portfolio_button_exception('nocallbackclass', 'portfolio', $class);
debugging(get_string('instancemisconfigured', 'portfolio', get_string($error[$instance->get('id')], 'portfolio_' . $instance->get('plugin'))));
return;
}
- if (!$instance->allows_multiple_exports() && $already = portfolio_exporter::existing_exports($USER->id, $instance->get('plugin'))) {
+ if (!$instance->allows_multiple_exports() && $already = portfolio_existing_exports($USER->id, $instance->get('plugin'))) {
debugging(get_string('singleinstancenomultiallowed', 'portfolio'));
return;
}
$count = 0;
$selectoutput = "\n" . '<select name="' . $selectname . '">' . "\n";
- $existingexports = portfolio_exporter::existing_exports_by_plugin($USER->id);
+ $existingexports = portfolio_existing_exports_by_plugin($USER->id);
foreach ($instances as $instance) {
$formats = portfolio_supported_formats_intersect($callerformats, $instance->supported_formats());
if (count($formats) == 0) {
* @return string the format constant (see PORTFOLIO_FORMAT_XXX constants)
*/
function portfolio_format_from_file(stored_file $file) {
+ global $CFG;
static $alreadymatched;
if (empty($alreadymatched)) {
$alreadymatched = array();
return $alreadymatched[$mimetype];
}
$allformats = portfolio_supported_formats();
+ require_once($CFG->libdir . '/portfolio/formats.php');
foreach ($allformats as $format => $classname) {
$supportedmimetypes = call_user_func(array($classname, 'mimetypes'));
if (!is_array($supportedmimetypes)) {
* @param array $pluginformats formats the portfolio plugin supports
*/
function portfolio_supported_formats_intersect($callerformats, $pluginformats) {
+ global $CFG;
$allformats = portfolio_supported_formats();
$intersection = array();
foreach ($callerformats as $cf) {
}
continue;
}
+ require_once($CFG->libdir . '/portfolio/formats.php');
$cfobj = new $allformats[$cf]();
foreach ($pluginformats as $p => $pf) {
if (!array_key_exists($pf, $allformats)) {
* @return array merged formats with dups removed
*/
function portfolio_most_specific_formats($specificformats, $generalformats) {
+ global $CFG;
$allformats = portfolio_supported_formats();
if (empty($specificformats)) {
return $generalformats;
foreach ($specificformats as $f) {
// look for something less specific and remove it, ie outside of the inheritance tree of the current formats.
if (!array_key_exists($f, $allformats)) {
- if (!portfolio_format_is_abstract($pf)) {
+ if (!portfolio_format_is_abstract($f)) {
throw new portfolio_button_exception('invalidformat', 'portfolio', $f);
}
}
+ require_once($CFG->libdir . '/portfolio/formats.php');
$fobj = new $allformats[$f];
foreach ($generalformats as $key => $cf) {
$cfclass = $allformats[$cf];
* @return portfolio_format object
*/
function portfolio_format_object($name) {
+ global $CFG;
+ require_once($CFG->libdir . '/portfolio/formats.php');
$formats = portfolio_supported_formats();
return new $formats[$name];
}
throw new portfolio_exception('invalidinstance', 'portfolio');
}
}
+ require_once($CFG->libdir . '/portfolio/plugin.php');
require_once($CFG->dirroot . '/portfolio/'. $instance->plugin . '/lib.php');
$classname = 'portfolio_plugin_' . $instance->plugin;
return new $classname($instanceid, $instance);
array_shift($args);
}
+ require_once($CFG->libdir . '/portfolio/plugin.php');
require_once($CFG->dirroot . '/portfolio/' . $plugin . '/lib.php');
return call_user_func_array(array('portfolio_plugin_' . $plugin, $function), $args);
}
*/
function portfolio_handle_event($eventdata) {
global $CFG;
+
+ require_once($CFG->libdir . '/portfolio/exporter.php');
$exporter = portfolio_exporter::rewaken_object($eventdata);
$exporter->process_stage_package();
$exporter->process_stage_send();
*/
function portfolio_cron() {
global $DB;
-
+ require_once($CFG->libdir . '/portfolio/exporter.php');
if ($expired = $DB->get_records_select('portfolio_tempdata', 'expirytime < ?', array(time()), '', 'id')) {
foreach ($expired as $d) {
try {
$sql = 'SELECT t.id FROM {portfolio_tempdata} t JOIN {portfolio_instance} i ON t.instance = i.id WHERE t.userid = ? AND i.plugin = ?';
return $DB->get_field_sql($sql, array($userid, $type));
}
+
+/**
+ * return a list of current exports for the given user
+ * this will not go through and call rewaken_object, because it's heavy
+ * it's really just used to figure out what exports are currently happening.
+ * this is useful for plugins that don't support multiple exports per session
+ *
+ * @param int $userid the user to check for
+ * @param string $type (optional) the portfolio plugin to filter by
+ *
+ * @return array
+ */
+function portfolio_existing_exports($userid, $type=null) {
+ global $DB;
+ $sql = 'SELECT t.*,t.instance,i.plugin,i.name FROM {portfolio_tempdata} t JOIN {portfolio_instance} i ON t.instance = i.id WHERE t.userid = ? ';
+ $values = array($userid);
+ if ($type) {
+ $sql .= ' AND i.plugin = ?';
+ $values[] = $type;
+ }
+ return $DB->get_records_sql($sql, $values);
+}
+
+/**
+ * Return an array of existing exports by type for a given user.
+ * This is much more lightweight than {@see existing_exports} because it only returns the types, rather than the whole serialised data
+ * so can be used for checking availability of multiple plugins at the same time.
+ */
+function portfolio_existing_exports_by_plugin($userid) {
+ global $DB;
+ $sql = 'SELECT t.id,i.plugin FROM {portfolio_tempdata} t JOIN {portfolio_instance} i ON t.instance = i.id WHERE t.userid = ? ';
+ $values = array($userid);
+ return $DB->get_records_sql_menu($sql, $values);
+}
require_once($CFG->libdir.'/eventslib.php');
/** Include formslib.php */
require_once($CFG->libdir.'/formslib.php');
-/** Include portfoliolib.php */
-require_once($CFG->libdir.'/portfoliolib.php');
/** Include calendar/lib.php */
require_once($CFG->dirroot.'/calendar/lib.php');
$found = false;
if ($files = $fs->get_area_files($this->context->id, 'assignment_submission', $userid, "timemodified", false)) {
+ require_once($CFG->libdir.'/portfoliolib.php');
+ require_once($CFG->dirroot . '/mod/assignment/locallib.php');
$button = new portfolio_add_button();
foreach ($files as $file) {
$filename = $file->get_filename();
$path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/assignment_submission/'.$userid.'/'.$filename);
$output .= '<a href="'.$path.'" ><img src="'.$OUTPUT->old_icon_url(file_mimetype_icon($mimetype)).'" class="icon" alt="'.$mimetype.'" />'.s($filename).'</a>';
if ($this->portfolio_exportable() && has_capability('mod/assignment:exportownsubmission', $this->context)) {
- $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'fileid' => $file->get_id()));
+ $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'fileid' => $file->get_id()), '/mod/assignment/locallib.php');
$button->set_format_by_file($file);
$output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK);
}
return array('moodle/site:accessallgroups', 'moodle/site:viewfullnames');
}
-/**
- * @package mod-assignment
- * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class assignment_portfolio_caller extends portfolio_module_caller_base {
-
- /**
- * the assignment subclass
- */
- private $assignment;
-
- /**
- * the file to include when waking up to load the assignment subclass def
- */
- private $assignmentfile;
-
- /**
- * callback arg for a single file export
- */
- protected $fileid;
-
- public static function expected_callbackargs() {
- return array(
- 'id' => true,
- 'fileid' => false,
- );
- }
-
- public function load_data() {
- global $DB, $CFG;
-
- if (! $this->cm = get_coursemodule_from_id('assignment', $this->id)) {
- throw new portfolio_caller_exception('invalidcoursemodule');
- }
-
- if (! $assignment = $DB->get_record("assignment", array("id"=>$this->cm->instance))) {
- throw new portfolio_caller_exception('invalidid', 'assignment');
- }
-
- $this->assignmentfile = '/mod/assignment/type/' . $assignment->assignmenttype . '/assignment.class.php';
- require_once($CFG->dirroot . $this->assignmentfile);
- $assignmentclass = "assignment_$assignment->assignmenttype";
-
- $this->assignment = new $assignmentclass($this->cm->id, $assignment, $this->cm);
-
- if (!$this->assignment->portfolio_exportable()) {
- throw new portfolio_caller_exception('notexportable', 'portfolio', $this->get_return_url());
- }
-
- $this->set_file_and_format_data($this->fileid, $this->assignment->context->id, 'assignment_submission', $this->user->id, 'timemodified', false);
- }
-
- public function prepare_package() {
- global $CFG;
- if (is_callable(array($this->assignment, 'portfolio_prepare_package'))) {
- return $this->assignment->portfolio_prepare_package($this->exporter, $this->user->id);
- }
- if ($this->exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) {
- $leapwriter = $this->exporter->get('format')->leap2a_writer();
- $files = array();
- if ($this->singlefile) {
- $files[] = $this->singlefile;
- } elseif ($this->multifiles) {
- $files = $this->multifiles;
- } else {
- throw new portfolio_caller_exception('invalidpreparepackagefile', 'portfolio', $this->get_return_url());
- }
- $baseid = 'assignment' . $this->assignment->assignment->assignmenttype . $this->assignment->assignment->id . 'submission';
- foreach ($files as $file) {
- $id = $baseid . $file->get_id();
- $entry = new portfolio_format_leap2a_entry($id, $file->get_filename(), 'resource', $file);
- $entry->add_category('offline', 'resource_type');
- $leapwriter->add_entry($entry);
- $this->exporter->copy_existing_file($file);
- }
- return $this->exporter->write_new_file($leapwriter->to_xml(), $this->exporter->get('format')->manifest_name(), true);
- }
- return $this->prepare_package_file();
- }
-
- public function get_sha1() {
- global $CFG;
- if (is_callable(array($this->assignment, 'portfolio_get_sha1'))) {
- return $this->assignment->portfolio_get_sha1($this->user->id);
- }
- return $this->get_sha1_file();
- }
-
- public function expected_time() {
- if (is_callable(array($this->assignment, 'portfolio_get_expected_time'))) {
- return $this->assignment->portfolio_get_expected_time();
- }
- return $this->expected_time_file();
- }
-
- public function check_permissions() {
- $context = get_context_instance(CONTEXT_MODULE, $this->assignment->cm->id);
- return has_capability('mod/assignment:exportownsubmission', $context);
- }
-
- public function __wakeup() {
- global $CFG;
- if (empty($CFG)) {
- return true; // too early yet
- }
- require_once($CFG->dirroot . $this->assignmentfile);
- $this->assignment = unserialize(serialize($this->assignment));
- }
-
- public static function display_name() {
- return get_string('modulename', 'assignment');
- }
-
- public static function base_supported_formats() {
- return array(PORTFOLIO_FORMAT_FILE, PORTFOLIO_FORMAT_LEAP2A);
- }
-}
-
/**
* @param string $feature FEATURE_xx constant for requested feature
* @return mixed True if module supports feature, null if doesn't know
--- /dev/null
+<?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/>.
+//
+// this file contains all the functions that aren't needed by core moodle
+// but start becoming required once we're actually inside the assignment module.
+
+require_once($CFG->libdir . '/portfolio/caller.php');
+
+/**
+ * @package mod-assignment
+ * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class assignment_portfolio_caller extends portfolio_module_caller_base {
+
+ /**
+ * the assignment subclass
+ */
+ private $assignment;
+
+ /**
+ * the file to include when waking up to load the assignment subclass def
+ */
+ private $assignmentfile;
+
+ /**
+ * callback arg for a single file export
+ */
+ protected $fileid;
+
+ public static function expected_callbackargs() {
+ return array(
+ 'id' => true,
+ 'fileid' => false,
+ );
+ }
+
+ public function load_data() {
+ global $DB, $CFG;
+
+ if (! $this->cm = get_coursemodule_from_id('assignment', $this->id)) {
+ throw new portfolio_caller_exception('invalidcoursemodule');
+ }
+
+ if (! $assignment = $DB->get_record("assignment", array("id"=>$this->cm->instance))) {
+ throw new portfolio_caller_exception('invalidid', 'assignment');
+ }
+
+ $this->assignmentfile = '/mod/assignment/type/' . $assignment->assignmenttype . '/assignment.class.php';
+ require_once($CFG->dirroot . $this->assignmentfile);
+ $assignmentclass = "assignment_$assignment->assignmenttype";
+
+ $this->assignment = new $assignmentclass($this->cm->id, $assignment, $this->cm);
+
+ if (!$this->assignment->portfolio_exportable()) {
+ throw new portfolio_caller_exception('notexportable', 'portfolio', $this->get_return_url());
+ }
+
+ $this->set_file_and_format_data($this->fileid, $this->assignment->context->id, 'assignment_submission', $this->user->id, 'timemodified', false);
+ }
+
+ public function prepare_package() {
+ global $CFG;
+ if (is_callable(array($this->assignment, 'portfolio_prepare_package'))) {
+ return $this->assignment->portfolio_prepare_package($this->exporter, $this->user->id);
+ }
+ if ($this->exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) {
+ $leapwriter = $this->exporter->get('format')->leap2a_writer();
+ $files = array();
+ if ($this->singlefile) {
+ $files[] = $this->singlefile;
+ } elseif ($this->multifiles) {
+ $files = $this->multifiles;
+ } else {
+ throw new portfolio_caller_exception('invalidpreparepackagefile', 'portfolio', $this->get_return_url());
+ }
+ $baseid = 'assignment' . $this->assignment->assignment->assignmenttype . $this->assignment->assignment->id . 'submission';
+ foreach ($files as $file) {
+ $id = $baseid . $file->get_id();
+ $entry = new portfolio_format_leap2a_entry($id, $file->get_filename(), 'resource', $file);
+ $entry->add_category('offline', 'resource_type');
+ $leapwriter->add_entry($entry);
+ $this->exporter->copy_existing_file($file);
+ }
+ return $this->exporter->write_new_file($leapwriter->to_xml(), $this->exporter->get('format')->manifest_name(), true);
+ }
+ return $this->prepare_package_file();
+ }
+
+ public function get_sha1() {
+ global $CFG;
+ if (is_callable(array($this->assignment, 'portfolio_get_sha1'))) {
+ return $this->assignment->portfolio_get_sha1($this->user->id);
+ }
+ return $this->get_sha1_file();
+ }
+
+ public function expected_time() {
+ if (is_callable(array($this->assignment, 'portfolio_get_expected_time'))) {
+ return $this->assignment->portfolio_get_expected_time();
+ }
+ return $this->expected_time_file();
+ }
+
+ public function check_permissions() {
+ $context = get_context_instance(CONTEXT_MODULE, $this->assignment->cm->id);
+ return has_capability('mod/assignment:exportownsubmission', $context);
+ }
+
+ public function __wakeup() {
+ global $CFG;
+ if (empty($CFG)) {
+ return true; // too early yet
+ }
+ require_once($CFG->dirroot . $this->assignmentfile);
+ $this->assignment = unserialize(serialize($this->assignment));
+ }
+
+ public static function display_name() {
+ return get_string('modulename', 'assignment');
+ }
+
+ public static function base_supported_formats() {
+ return array(PORTFOLIO_FORMAT_FILE, PORTFOLIO_FORMAT_LEAP2A);
+ }
+}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-/** Include portfoliolib.php */
-require_once($CFG->libdir.'/portfoliolib.php');
require_once($CFG->dirroot.'/calendar/lib.php');
// The HTML head for the message window to start with (<!-- nix --> is used to get some browsers starting with output
return array('moodle/site:accessallgroups', 'moodle/site:viewfullnames');
}
-/**
- * @package mod-chat
- * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class chat_portfolio_caller extends portfolio_module_caller_base {
- /** @var object */
- private $chat;
- /** @var int Timestamp */
- protected $start;
- /** @var int Timestamp */
- protected $end;
- /**
- * @return array
- */
- public static function expected_callbackargs() {
- return array(
- 'id' => true,
- 'start' => false,
- 'end' => false,
- );
- }
- /**
- * @global object
- */
- public function load_data() {
- global $DB;
-
- if (!$this->cm = get_coursemodule_from_id('chat', $this->id)) {
- throw new portfolio_caller_exception('invalidid', 'chat');
- }
- $this->chat = $DB->get_record('chat', array('id' => $this->cm->instance));
- $select = 'chatid = ?';
- $params = array($this->chat->id);
- if ($this->start && $this->end) {
- $select .= ' AND timestamp >= ? AND timestamp <= ?';
- $params[] = $this->start;
- $params[] = $this->end;
- }
- $this->messages = $DB->get_records_select(
- 'chat_messages',
- $select,
- $params,
- 'timestamp ASC'
- );
- $select .= ' AND userid = ?';
- $params[] = $this->user->id;
- $this->participated = $DB->record_exists_select(
- 'chat_messages',
- $select,
- $params
- );
- }
- /**
- * @return array
- */
- public static function base_supported_formats() {
- return array(PORTFOLIO_FORMAT_PLAINHTML);
- }
- /**
- *
- */
- public function expected_time() {
- return portfolio_expected_time_db(count($this->messages));
- }
- /**
- * @return string
- */
- public function get_sha1() {
- $str = '';
- ksort($this->messages);
- foreach ($this->messages as $m) {
- $str .= implode('', (array)$m);
- }
- return sha1($str);
- }
-
- /**
- * @return bool
- */
- 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));
- }
-
- /**
- * @todo Document this function
- */
- public function prepare_package() {
- $content = '';
- $lasttime = 0;
- $sessiongap = 5 * 60; // 5 minutes silence means a new session
- foreach ($this->messages as $message) { // We are walking FORWARDS through messages
- $m = clone $message; // grrrrrr - this causes the sha1 to change as chat_format_message changes what it's passed.
- $formatmessage = chat_format_message($m, null, $this->user);
- if (!isset($formatmessage->html)) {
- continue;
- }
- if (empty($lasttime) || (($message->timestamp - $lasttime) > $sessiongap)) {
- $content .= '<hr />';
- $content .= userdate($message->timestamp);
- }
- $content .= $formatmessage->html;
- $lasttime = $message->timestamp;
- }
- $content = preg_replace('/\<img[^>]*\>/', '', $content);
-
- $this->exporter->write_new_file($content, clean_filename($this->cm->name . '-session.html'), false);
- }
-
- /**
- * @return string
- */
- public static function display_name() {
- return get_string('modulename', 'chat');
- }
-
- /**
- * @global object
- * @return string
- */
- 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
- : '');
- }
-}
/**
* @param string $feature FEATURE_xx constant for requested feature
--- /dev/null
+<?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/>.
+
+/**
+ * Library of functions for chat outside of the core api
+ */
+
+require_once($CFG->libdir . '/portfolio/caller.php');
+
+/**
+ * @package mod-chat
+ * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class chat_portfolio_caller extends portfolio_module_caller_base {
+ /** @var object */
+ private $chat;
+ /** @var int Timestamp */
+ protected $start;
+ /** @var int Timestamp */
+ protected $end;
+ /**
+ * @return array
+ */
+ public static function expected_callbackargs() {
+ return array(
+ 'id' => true,
+ 'start' => false,
+ 'end' => false,
+ );
+ }
+ /**
+ * @global object
+ */
+ public function load_data() {
+ global $DB;
+
+ if (!$this->cm = get_coursemodule_from_id('chat', $this->id)) {
+ throw new portfolio_caller_exception('invalidid', 'chat');
+ }
+ $this->chat = $DB->get_record('chat', array('id' => $this->cm->instance));
+ $select = 'chatid = ?';
+ $params = array($this->chat->id);
+ if ($this->start && $this->end) {
+ $select .= ' AND timestamp >= ? AND timestamp <= ?';
+ $params[] = $this->start;
+ $params[] = $this->end;
+ }
+ $this->messages = $DB->get_records_select(
+ 'chat_messages',
+ $select,
+ $params,
+ 'timestamp ASC'
+ );
+ $select .= ' AND userid = ?';
+ $params[] = $this->user->id;
+ $this->participated = $DB->record_exists_select(
+ 'chat_messages',
+ $select,
+ $params
+ );
+ }
+ /**
+ * @return array
+ */
+ public static function base_supported_formats() {
+ return array(PORTFOLIO_FORMAT_PLAINHTML);
+ }
+ /**
+ *
+ */
+ public function expected_time() {
+ return portfolio_expected_time_db(count($this->messages));
+ }
+ /**
+ * @return string
+ */
+ public function get_sha1() {
+ $str = '';
+ ksort($this->messages);
+ foreach ($this->messages as $m) {
+ $str .= implode('', (array)$m);
+ }
+ return sha1($str);
+ }
+
+ /**
+ * @return bool
+ */
+ 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));
+ }
+
+ /**
+ * @todo Document this function
+ */
+ public function prepare_package() {
+ $content = '';
+ $lasttime = 0;
+ $sessiongap = 5 * 60; // 5 minutes silence means a new session
+ foreach ($this->messages as $message) { // We are walking FORWARDS through messages
+ $m = clone $message; // grrrrrr - this causes the sha1 to change as chat_format_message changes what it's passed.
+ $formatmessage = chat_format_message($m, $this->course->id, $this->user);
+ if (!isset($formatmessage->html)) {
+ continue;
+ }
+ if (empty($lasttime) || (($message->timestamp - $lasttime) > $sessiongap)) {
+ $content .= '<hr />';
+ $content .= userdate($message->timestamp);
+ }
+ $content .= $formatmessage->html;
+ $lasttime = $message->timestamp;
+ }
+ $content = preg_replace('/\<img[^>]*\>/', '', $content);
+
+ $this->exporter->write_new_file($content, clean_filename($this->cm->name . '-session.html'), false);
+ }
+
+ /**
+ * @return string
+ */
+ public static function display_name() {
+ return get_string('modulename', 'chat');
+ }
+
+ /**
+ * @global object
+ * @return string
+ */
+ 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
+ : '');
+ }
+}
'end' => $end,
);
$button = new portfolio_add_button();
- $button->set_callback_options('chat_portfolio_caller', $buttonoptions, '/mod/chat/lib.php');
+ $button->set_callback_options('chat_portfolio_caller', $buttonoptions, '/mod/chat/locallib.php');
$button->render();
}
echo $OUTPUT->box_end();
'end' => $sessionend,
);
$button = new portfolio_add_button();
- $button->set_callback_options('chat_portfolio_caller', $buttonoptions, '/mod/chat/lib.php');
+ $button->set_callback_options('chat_portfolio_caller', $buttonoptions, '/mod/chat/locallib.php');
$button->render(PORTFOLIO_ADD_TEXT_LINK);
}
if (has_capability('mod/chat:deletelog', $context)) {
if (has_capability('mod/chat:exportsession', $context)) {
require_once($CFG->libdir . '/portfoliolib.php');
$button = new portfolio_add_button();
- $button->set_callback_options('chat_portfolio_caller', array('id' => $cm->id), '/mod/chat/lib.php');
+ $button->set_callback_options('chat_portfolio_caller', array('id' => $cm->id), '/mod/chat/locallib.php');
$button->render(null, get_string('addalltoportfolio', 'portfolio'));
}
// fake portfolio callback stuff and redirect
$formdata['id'] = $cm->id;
$formdata['exporttype'] = 'csv'; // force for now
- $url = portfolio_fake_add_url($formdata['portfolio'], 'data_portfolio_caller', '/mod/data/lib.php', $formdata, array());
+ require_once($CFG->libdir . '/portfoliolib.php');
+ $url = portfolio_fake_add_url($formdata['portfolio'], 'data_portfolio_caller', '/mod/data/locallib.php', $formdata, array(PORTFOLIO_FORMAT_SPREADSHEET));
redirect($url);
}
}
$this->add_checkbox_controller(1, null, null, 1);
require_once($CFG->libdir . '/portfoliolib.php');
+ require_once($CFG->dirroot . '/mod/data/locallib.php');
if ($CFG->enableportfolios && has_capability('mod/data:exportallentries', get_context_instance(CONTEXT_MODULE, $this->_cm->id))) {
if ($portfoliooptions = portfolio_instance_select(
portfolio_instances(),
call_user_func(array('data_portfolio_caller', 'base_supported_formats')),
- 'data_portfolio_caller', null, '', true, true)) {
+ 'data_portfolio_caller', '/mod/data/locallib.php', '', true, true)) {
$mform->addElement('header', 'notice', get_string('portfolionotfile', 'data') . ':');
$portfoliooptions[0] = get_string('none');
ksort($portfoliooptions);
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-/** Require portfoliolib.php */
-require_once($CFG->libdir . '/portfoliolib.php');
-
// Some constants
define ('DATA_MAX_ENTRIES', 50);
define ('DATA_PERPAGE_SINGLE', 1);
if (($template == 'singletemplate' || $template == 'listtemplate')
&& ((has_capability('mod/data:exportentry', $context)
|| (data_isowner($record->id) && has_capability('mod/data:exportownentry', $context))))) {
+ require_once($CFG->libdir . '/portfoliolib.php');
$button = new portfolio_add_button();
- $button->set_callback_options('data_portfolio_caller', array('id' => $cm->id, 'recordid' => $record->id));
+ $button->set_callback_options('data_portfolio_caller', array('id' => $cm->id, 'recordid' => $record->id), '/mod/data/locallib.php');
list($formats, $files) = data_portfolio_caller::formats($fields, $record);
$button->set_formats($formats);
$replacement[] = $button->to_html(PORTFOLIO_ADD_ICON_LINK);
return false;
}
-/**
- * @package mod-data
- * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-class data_portfolio_caller extends portfolio_module_caller_base {
-
- /** @var int */
- protected $recordid;
- /** @var string */
- protected $exporttype;
- /** @var string */
- protected $delimiter_name;
-
- /** @var object */
- private $data;
- /**#@+ @var array */
- private $selectedfields;
- private $fields;
- private $fieldtypes;
- private $exportdata;
- /**#@-*/
- /**#@+ @var object */
- private $singlerecord;
- private $singlefield;
- /**#@-*/
- /**
- * @return array
- */
- public static function expected_callbackargs() {
- return array(
- 'id' => true,
- 'recordid' => false,
- 'delimiter_name' => false,
- 'exporttype' => false,
- );
- }
- /**
- * @param array $callbackargs
- */
- public function __construct($callbackargs) {
- parent::__construct($callbackargs);
- if (empty($this->exporttype)) {
- $this->exporttype = 'csv';
- }
- $this->selectedfields = array();
- foreach ($callbackargs as $key => $value) {
- if (strpos($key, 'field_') === 0) {
- $this->selectedfields[] = substr($key, 6);
- }
- }
- }
-
- /**
- * @global object
- */
- public function load_data() {
- global $DB;
- if (!$this->cm = get_coursemodule_from_id('data', $this->id)) {
- throw new portfolio_caller_exception('invalidid', 'data');
- }
- $this->data = $DB->get_record('data', array('id' => $this->cm->instance));
- $fieldrecords = $DB->get_records('data_fields', array('dataid'=>$this->cm->instance), 'id');
- // populate objets for this databases fields
- $this->fields = array();
- foreach ($fieldrecords as $fieldrecord) {
- $tmp = data_get_field($fieldrecord, $this->data);
- $this->fields[] = $tmp;
- $this->fieldtypes[] = $tmp->type;
- }
-
- if ($this->recordid) {
- //user has selected to export one single entry rather than the whole thing
- // which is completely different
- $this->singlerecord = $DB->get_record('data_records', array('id' => $this->recordid));
- $this->singlerecord->content = $DB->get_records('data_content', array('recordid' => $this->singlerecord->id));
- $this->exporttype = 'single';
-
- list($formats, $files) = self::formats($this->fields, $this->singlerecord);
- if (count($files) == 1 && count($this->fields) == 1) {
- $this->singlefile = $files[0];
- $this->exporttype = 'singlefile';
- } else if (count($files) > 0) {
- $this->multifiles = $files;
- }
- } else {
- // all records as csv or whatever
- $this->exportdata = data_get_exportdata($this->cm->instance, $this->fields, $this->selectedfields);
- }
- }
-
- /**
- * @todo penny later when we suport exporting to more than just csv, we may
- * need to ask the user here if we have not already passed it
- *
- * @return bool
- */
- public function has_export_config() {
- return false;
- }
-
- /**
- * @uses PORTFOLIO_TIME_LOW
- * @return mixed
- */
- public function expected_time() {
- if ($this->exporttype == 'single') {
- return PORTFOLIO_TIME_LOW;
- }
- return portfolio_expected_time_db(count($this->exportdata));
- }
-
- /**
- * @return string
- */
- public function get_sha1() {
- if ($this->exporttype == 'singlefile') {
- return $this->singlefile->get_contenthash();
- }
- $loopdata = $this->exportdata;
- if ($this->exporttype == 'single') {
- $loopdata = $this->singlerecord;
- }
- $str = '';
- foreach ($loopdata as $data) {
- if (is_array($data) || is_object($data)) {
- $testkey = array_pop(array_keys($data));
- if (is_array($data[$testkey]) || is_object($data[$testkey])) {
- foreach ($data as $d) {
- $str .= implode(',', (array)$d);
- }
- } else {
- $str .= implode(',', (array)$data);
- }
- } else {
- $str .= $data;
- }
- }
- return sha1($str . ',' . $this->exporttype);
- }
- /**
- * @global object
- */
- public function prepare_package() {
- global $DB;
- $count = count($this->exportdata);
- $content = '';
- $filename = '';
- switch ($this->exporttype) {
- case 'singlefile':
- return $this->get('exporter')->copy_existing_file($this->singlefile);
- case 'single':
- $content = $this->exportsingle();
- $filename = clean_filename($this->cm->name . '-entry.html');
- break;
- case 'csv':
- $content = data_export_csv($this->exportdata, $this->delimiter_name, $this->cm->name, $count, true);
- $filename = clean_filename($this->cm->name . '.csv');
- break;
- case 'xls':
- throw new portfolio_caller_exception('notimplemented', 'portfolio', '', 'xls');
- $content = data_export_xls($this->exportdata, $this->cm->name, $count, true);
- break;
- case 'ods':
- throw new portfolio_caller_exception('notimplemented', 'portfolio', '', 'ods');
- $content = data_export_ods($this->exportdata, $this->cm->name, $count, true);
- break;
- default:
- throw new portfolio_caller_exception('notimplemented', 'portfolio', '', $this->exporttype);
- break;
- }
- return $this->exporter->write_new_file(
- $content,
- $filename,
- ($this->exporter->get('format') instanceof PORTFOLIO_FORMAT_RICH) // if we have associate files, this is a 'manifest'
- );
- }
-
- /**
- * @return bool
- */
- public function check_permissions() {
- return has_capability('mod/data:exportallentries', get_context_instance(CONTEXT_MODULE, $this->cm->id));
- }
-
- /**
- * @return string
- */
- public static function display_name() {
- return get_string('modulename', 'data');
- }
-
- /**
- * @global object
- * @return bool|void
- */
- public function __wakeup() {
- global $CFG;
- if (empty($CFG)) {
- return true; // too early yet
- }
- foreach ($this->fieldtypes as $key => $field) {
- require_once($CFG->dirroot . '/mod/data/field/' . $field .'/field.class.php');
- $this->fields[$key] = unserialize(serialize($this->fields[$key]));
- }
- }
-
- /**
- * @global object
- * @return string
- */
- private function exportsingle() {
- global $DB;
- // Replacing tags
- $patterns = array();
- $replacement = array();
- $context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
-
- // Then we generate strings to replace for normal tags
- $format = $this->get('exporter')->get('format');
- foreach ($this->fields as $field) {
- $patterns[]='[['.$field->field->name.']]';
- if (is_callable(array($field, 'get_file'))) {
- // TODO this used to be:
- // if ($field instanceof data_field_file) {
- // - see MDL-16493
- if (!$file = $field->get_file($this->singlerecord->id)) {
- $replacement[] = '';
- continue; // probably left empty
- }
- $replacement[] = $format->file_output($file);
- $this->get('exporter')->copy_existing_file($file);
- } else {
- $replacement[] = $field->display_browse_field($this->singlerecord->id, 'singletemplate');
- }
- }
-
- // Replacing special tags (##Edit##, ##Delete##, ##More##)
- $patterns[]='##edit##';
- $patterns[]='##delete##';
- $patterns[]='##export##';
- $patterns[]='##more##';
- $patterns[]='##moreurl##';
- $patterns[]='##user##';
- $patterns[]='##approve##';
- $patterns[]='##comments##';
- $patterns[] = '##timeadded##';
- $patterns[] = '##timemodified##';
- $replacement[] = '';
- $replacement[] = '';
- $replacement[] = '';
- $replacement[] = '';
- $replacement[] = '';
- $replacement[] = '';
- $replacement[] = '';
- $replacement[] = '';
- $replacement[] = userdate($this->singlerecord->timecreated);
- $replacement[] = userdate($this->singlerecord->timemodified);
-
- // actual replacement of the tags
- return str_ireplace($patterns, $replacement, $this->data->singletemplate);
- }
-
- /**
- * @param array $fields
- * @param object $record
- * @uses PORTFOLIO_FORMAT_PLAINHTML
- * @uses PORTFOLIO_FORMAT_RICHHTML
- * @return array
- */
- public static function formats($fields, $record) {
- $formats = array(PORTFOLIO_FORMAT_PLAINHTML);
- $includedfiles = array();
- foreach ($fields as $singlefield) {
- if (is_callable(array($singlefield, 'get_file'))) {
- $includedfiles[] = $singlefield->get_file($record->id);
- }
- }
- if (count($includedfiles) == 1 && count($fields) == 1) {
- $formats= array(portfolio_format_from_file($includedfiles[0]));
- } else if (count($includedfiles) > 0) {
- $formats = array(PORTFOLIO_FORMAT_RICHHTML);
- }
- return array($formats, $includedfiles);
- }
-
- public static function base_supported_formats() {
- return array(PORTFOLIO_FORMAT_FILE, PORTFOLIO_FORMAT_RICHHTML, PORTFOLIO_FORMAT_PLAINHTML);
- }
-}
function data_extend_navigation($navigation, $course, $module, $cm) {
global $CFG, $OUTPUT, $USER, $DB;
--- /dev/null
+<?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/>.
+
+/**
+ * @package mod-data
+ * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+/**
+ * @package mod-data
+ * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+class data_portfolio_caller extends portfolio_module_caller_base {
+
+ /** @var int */
+ protected $recordid;
+ /** @var string */
+ protected $exporttype;
+ /** @var string */
+ protected $delimiter_name;
+
+ /** @var object */
+ private $data;
+ /**#@+ @var array */
+ private $selectedfields;
+ private $fields;
+ private $fieldtypes;
+ private $exportdata;
+ /**#@-*/
+ /**#@+ @var object */
+ private $singlerecord;
+ private $singlefield;
+ /**#@-*/
+ /**
+ * @return array
+ */
+ public static function expected_callbackargs() {
+ return array(
+ 'id' => true,
+ 'recordid' => false,
+ 'delimiter_name' => false,
+ 'exporttype' => false,
+ );
+ }
+ /**
+ * @param array $callbackargs
+ */
+ public function __construct($callbackargs) {
+ parent::__construct($callbackargs);
+ if (empty($this->exporttype)) {
+ $this->exporttype = 'csv';
+ }
+ $this->selectedfields = array();
+ foreach ($callbackargs as $key => $value) {
+ if (strpos($key, 'field_') === 0) {
+ $this->selectedfields[] = substr($key, 6);
+ }
+ }
+ }
+
+ /**
+ * @global object
+ */
+ public function load_data() {
+ global $DB;
+ if (!$this->cm = get_coursemodule_from_id('data', $this->id)) {
+ throw new portfolio_caller_exception('invalidid', 'data');
+ }
+ $this->data = $DB->get_record('data', array('id' => $this->cm->instance));
+ $fieldrecords = $DB->get_records('data_fields', array('dataid'=>$this->cm->instance), 'id');
+ // populate objets for this databases fields
+ $this->fields = array();
+ foreach ($fieldrecords as $fieldrecord) {
+ $tmp = data_get_field($fieldrecord, $this->data);
+ $this->fields[] = $tmp;
+ $this->fieldtypes[] = $tmp->type;
+ }
+
+ if ($this->recordid) {
+ //user has selected to export one single entry rather than the whole thing
+ // which is completely different
+ $this->singlerecord = $DB->get_record('data_records', array('id' => $this->recordid));
+ $this->singlerecord->content = $DB->get_records('data_content', array('recordid' => $this->singlerecord->id));
+ $this->exporttype = 'single';
+
+ list($formats, $files) = self::formats($this->fields, $this->singlerecord);
+ if (count($files) == 1 && count($this->fields) == 1) {
+ $this->singlefile = $files[0];
+ $this->exporttype = 'singlefile';
+ } else if (count($files) > 0) {
+ $this->multifiles = $files;
+ }
+ } else {
+ // all records as csv or whatever
+ $this->exportdata = data_get_exportdata($this->cm->instance, $this->fields, $this->selectedfields);
+ }
+ }
+
+ /**
+ * @todo penny later when we suport exporting to more than just csv, we may
+ * need to ask the user here if we have not already passed it
+ *
+ * @return bool
+ */
+ public function has_export_config() {
+ return false;
+ }
+
+ /**
+ * @uses PORTFOLIO_TIME_LOW
+ * @return mixed
+ */
+ public function expected_time() {
+ if ($this->exporttype == 'single') {
+ return PORTFOLIO_TIME_LOW;
+ }
+ return portfolio_expected_time_db(count($this->exportdata));
+ }
+
+ /**
+ * @return string
+ */
+ public function get_sha1() {
+ if ($this->exporttype == 'singlefile') {
+ return $this->singlefile->get_contenthash();
+ }
+ $loopdata = $this->exportdata;
+ if ($this->exporttype == 'single') {
+ $loopdata = $this->singlerecord;
+ }
+ $str = '';
+ foreach ($loopdata as $data) {
+ if (is_array($data) || is_object($data)) {
+ $testkey = array_pop(array_keys($data));
+ if (is_array($data[$testkey]) || is_object($data[$testkey])) {
+ foreach ($data as $d) {
+ $str .= implode(',', (array)$d);
+ }
+ } else {
+ $str .= implode(',', (array)$data);
+ }
+ } else {
+ $str .= $data;
+ }
+ }
+ return sha1($str . ',' . $this->exporttype);
+ }
+ /**
+ * @global object
+ */
+ public function prepare_package() {
+ global $DB;
+ $count = count($this->exportdata);
+ $content = '';
+ $filename = '';
+ switch ($this->exporttype) {
+ case 'singlefile':
+ return $this->get('exporter')->copy_existing_file($this->singlefile);
+ case 'single':
+ $content = $this->exportsingle();
+ $filename = clean_filename($this->cm->name . '-entry.html');
+ break;
+ case 'csv':
+ $content = data_export_csv($this->exportdata, $this->delimiter_name, $this->cm->name, $count, true);
+ $filename = clean_filename($this->cm->name . '.csv');
+ break;
+ case 'xls':
+ throw new portfolio_caller_exception('notimplemented', 'portfolio', '', 'xls');
+ $content = data_export_xls($this->exportdata, $this->cm->name, $count, true);
+ break;
+ case 'ods':
+ throw new portfolio_caller_exception('notimplemented', 'portfolio', '', 'ods');
+ $content = data_export_ods($this->exportdata, $this->cm->name, $count, true);
+ break;
+ default:
+ throw new portfolio_caller_exception('notimplemented', 'portfolio', '', $this->exporttype);
+ break;
+ }
+ return $this->exporter->write_new_file(
+ $content,
+ $filename,
+ ($this->exporter->get('format') instanceof PORTFOLIO_FORMAT_RICH) // if we have associate files, this is a 'manifest'
+ );
+ }
+
+ /**
+ * @return bool
+ */
+ public function check_permissions() {
+ return has_capability('mod/data:exportallentries', get_context_instance(CONTEXT_MODULE, $this->cm->id));
+ }
+
+ /**
+ * @return string
+ */
+ public static function display_name() {
+ return get_string('modulename', 'data');
+ }
+
+ /**
+ * @global object
+ * @return bool|void
+ */
+ public function __wakeup() {
+ global $CFG;
+ if (empty($CFG)) {
+ return true; // too early yet
+ }
+ foreach ($this->fieldtypes as $key => $field) {
+ require_once($CFG->dirroot . '/mod/data/field/' . $field .'/field.class.php');
+ $this->fields[$key] = unserialize(serialize($this->fields[$key]));
+ }
+ }
+
+ /**
+ * @global object
+ * @return string
+ */
+ private function exportsingle() {
+ global $DB;
+ // Replacing tags
+ $patterns = array();
+ $replacement = array();
+ $context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
+
+ // Then we generate strings to replace for normal tags
+ $format = $this->get('exporter')->get('format');
+ foreach ($this->fields as $field) {
+ $patterns[]='[['.$field->field->name.']]';
+ if (is_callable(array($field, 'get_file'))) {
+ // TODO this used to be:
+ // if ($field instanceof data_field_file) {
+ // - see MDL-16493
+ if (!$file = $field->get_file($this->singlerecord->id)) {
+ $replacement[] = '';
+ continue; // probably left empty
+ }
+ $replacement[] = $format->file_output($file);
+ $this->get('exporter')->copy_existing_file($file);
+ } else {
+ $replacement[] = $field->display_browse_field($this->singlerecord->id, 'singletemplate');
+ }
+ }
+
+ // Replacing special tags (##Edit##, ##Delete##, ##More##)
+ $patterns[]='##edit##';
+ $patterns[]='##delete##';
+ $patterns[]='##export##';
+ $patterns[]='##more##';
+ $patterns[]='##moreurl##';
+ $patterns[]='##user##';
+ $patterns[]='##approve##';
+ $patterns[]='##comments##';
+ $patterns[] = '##timeadded##';
+ $patterns[] = '##timemodified##';
+ $replacement[] = '';
+ $replacement[] = '';
+ $replacement[] = '';
+ $replacement[] = '';
+ $replacement[] = '';
+ $replacement[] = '';
+ $replacement[] = '';
+ $replacement[] = '';
+ $replacement[] = userdate($this->singlerecord->timecreated);
+ $replacement[] = userdate($this->singlerecord->timemodified);
+
+ // actual replacement of the tags
+ return str_ireplace($patterns, $replacement, $this->data->singletemplate);
+ }
+
+ /**
+ * @param array $fields
+ * @param object $record
+ * @uses PORTFOLIO_FORMAT_PLAINHTML
+ * @uses PORTFOLIO_FORMAT_RICHHTML
+ * @return array
+ */
+ public static function formats($fields, $record) {
+ $formats = array(PORTFOLIO_FORMAT_PLAINHTML);
+ $includedfiles = array();
+ foreach ($fields as $singlefield) {
+ if (is_callable(array($singlefield, 'get_file'))) {
+ $includedfiles[] = $singlefield->get_file($record->id);
+ }
+ }
+ if (count($includedfiles) == 1 && count($fields) == 1) {
+ $formats= array(portfolio_format_from_file($includedfiles[0]));
+ } else if (count($includedfiles) > 0) {
+ $formats = array(PORTFOLIO_FORMAT_RICHHTML);
+ }
+ return array($formats, $includedfiles);
+ }
+
+ public static function base_supported_formats() {
+ return array(PORTFOLIO_FORMAT_FILE, PORTFOLIO_FORMAT_RICHHTML, PORTFOLIO_FORMAT_PLAINHTML);
+ }
+}
echo "</td><td>";
if (has_capability('mod/forum:exportdiscussion', $modcontext)) {
+ require_once($CFG->libdir.'/portfoliolib.php');
$button = new portfolio_add_button();
- $button->set_callback_options('forum_portfolio_caller', array('discussionid' => $discussion->id), '/mod/forum/lib.php');
+ $button->set_callback_options('forum_portfolio_caller', array('discussionid' => $discussion->id), '/mod/forum/locallib.php');
$button->render();
echo '</td><td>';
}
/** Include required files */
require_once($CFG->libdir.'/filelib.php');
require_once($CFG->libdir.'/eventslib.php');
-require_once($CFG->libdir.'/portfoliolib.php');
require_once($CFG->libdir . '/completionlib.php');
require_once($CFG->dirroot.'/user/selector/lib.php');
$p = array(
'postid' => $post->id,
);
+ require_once($CFG->libdir.'/portfoliolib.php');
$button = new portfolio_add_button();
- $button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id));
+ $button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id), '/mod/forum/locallib.php');
if (empty($attachments)) {
$button->set_formats(PORTFOLIO_FORMAT_PLAINHTML);
} else {
$canexport = (has_capability('mod/forum:exportpost', $context) || ($post->userid == $USER->id && has_capability('mod/forum:exportownpost', $context)));
+ require_once($CFG->libdir.'/portfoliolib.php');
if ($files = $fs->get_area_files($context->id, 'forum_attachment', $post->id, "timemodified", false)) {
$button = new portfolio_add_button();
foreach ($files as $file) {
$output .= "<a href=\"$path\">$iconimage</a> ";
$output .= "<a href=\"$path\">".s($filename)."</a>";
if ($canexport) {
- $button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id, 'attachment' => $file->get_id()));
+ $button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id, 'attachment' => $file->get_id()), '/mod/forum/locallib.php');
$button->set_format_by_file($file);
$output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK);
}
return array('moodle/site:accessallgroups', 'moodle/site:viewfullnames', 'moodle/site:trustcontent');
}
-/**
- * @package mod-forum
- * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class forum_portfolio_caller extends portfolio_module_caller_base {
-
- protected $postid;
- protected $discussionid;
- protected $attachment;
-
- private $post;
- private $forum;
- private $discussion;
- private $posts;
- private $keyedfiles; // just using multifiles isn't enough if we're exporting a full thread
-
- /**
- * @return array
- */
- public static function expected_callbackargs() {
- return array(
- 'postid' => false,
- 'discussionid' => false,
- 'attachment' => false,
- );
- }
- /**
- * @param array $callbackargs
- */
- function __construct($callbackargs) {
- parent::__construct($callbackargs);
- if (!$this->postid && !$this->discussionid) {
- throw new portfolio_caller_exception('mustprovidediscussionorpost', 'forum');
- }
- }
- /**
- * @global object
- */
- public function load_data() {
- global $DB;
-
- if ($this->postid) {
- if (!$this->post = $DB->get_record('forum_posts', array('id' => $this->postid))) {
- throw new portfolio_caller_exception('invalidpostid', 'forum');
- }
- }
-
- $dparams = array();
- if ($this->discussionid) {
- $dbparams = array('id' => $this->discussionid);
- } else if ($this->post) {
- $dbparams = array('id' => $this->post->discussion);
- } else {
- throw new portfolio_caller_exception('mustprovidediscussionorpost', 'forum');
- }
-
- if (!$this->discussion = $DB->get_record('forum_discussions', $dbparams)) {
- throw new portfolio_caller_exception('invaliddiscussionid', 'forum');
- }
-
- if (!$this->forum = $DB->get_record('forum', array('id' => $this->discussion->forum))) {
- throw new portfolio_caller_exception('invalidforumid', 'forum');
- }
-
- if (!$this->cm = get_coursemodule_from_instance('forum', $this->forum->id)) {
- throw new portfolio_caller_exception('invalidcoursemodule');
- }
-
- $modcontext = get_context_instance(CONTEXT_MODULE, $this->cm->id);
- if ($this->post) {
- $this->set_file_and_format_data($this->attachment, $modcontext->id, 'forum_attachment', $this->post->id, 'timemodified', false);
- if (!empty($this->multifiles)) {
- $this->keyedfiles[$this->post->id] = $this->multifiles;
- } else if (!empty($this->singlefile)) {
- $this->keyedfiles[$this->post->id] = array($this->singlefile);
- }
- } else { // whole thread
- $fs = get_file_storage();
- $this->posts = forum_get_all_discussion_posts($this->discussion->id, 'p.created ASC');
- $this->multifiles = array();
- foreach ($this->posts as $post) {
- if (!$this->keyedfiles[$post->id] = $fs->get_area_files($modcontext->id, 'forum_attachment', $post->id, "timemodified", false)) {
- continue;
- }
- $this->multifiles = array_merge($this->multifiles, array_values($this->keyedfiles[$post->id]));
- }
- }
- if (empty($this->multifiles) && !empty($this->singlefile)) {
- $this->multifiles = array($this->singlefile); // copy_files workaround
- }
- // depending on whether there are files or not, we might have to change richhtml/plainhtml
- if (!empty($this->multifiles)) {
- $this->add_format(PORTFOLIO_FORMAT_RICHHTML);
- } else {
- $this->add_format(PORTFOLIO_FORMAT_PLAINHTML);
- }
- }
-
- /**
- * @global object
- * @return string
- */
- function get_return_url() {
- global $CFG;
- return $CFG->wwwroot . '/mod/forum/discuss.php?d=' . $this->discussion->id;
- }
- /**
- * @global object
- * @return array
- */
- function get_navigation() {
- global $CFG;
-
- $navlinks = array();
- $navlinks[] = array(
- 'name' => format_string($this->discussion->name),
- 'link' => $CFG->wwwroot . '/mod/forum/discuss.php?d=' . $this->discussion->id,
- 'type' => 'title'
- );
- return array($navlinks, $this->cm);
- }
- /**
- * either a whole discussion
- * a single post, with or without attachment
- * or just an attachment with no post
- *
- * @global object
- * @global object
- * @uses PORTFOLIO_FORMAT_RICH
- * @return mixed
- */
- function prepare_package() {
- global $CFG;
-
- // set up the leap2a writer if we need it
- $writingleap = false;
- if ($this->exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) {
- $leapwriter = $this->exporter->get('format')->leap2a_writer();
- $writingleap = true;
- }
- if ($this->attachment) { // simplest case first - single file attachment
- $this->copy_files(array($this->singlefile), $this->attachment);
- if ($writingleap) { // if we're writing leap, make the manifest to go along with the file
- $entry = new portfolio_format_leap2a_entry($id, $this->attachment->get_filename(), 'resource', $this->attachment);
- $entry->add_category('offline', 'resource_type');
- $leapwriter->add_entry($entry);
- return $this->exporter->write_new_file($leapwriter->to_xml(), $this->exporter->get('format')->manifest_name(), true);
- }
-
- } else if (empty($this->post)) { // exporting whole discussion
- $content = ''; // if we're just writing HTML, start a string to add each post to
- $ids = array(); // if we're writing leap2a, keep track of all entryids so we can add a selection element
- foreach ($this->posts as $post) {
- $posthtml = $this->prepare_post($post);
- if ($writingleap) {
- $ids[] = $this->prepare_post_leap2a($leapwriter, $post, $posthtml);
- } else {
- $content .= $posthtml . '<br /><br />';
- }
- }
- $this->copy_files($this->multifiles);
- $name = 'discussion.html';
- $manifest = ($this->exporter->get('format') instanceof PORTFOLIO_FORMAT_RICH);
- if ($writingleap) {
- // add on an extra 'selection' entry
- $selection = new portfolio_format_leap2a_entry('forumdiscussion' . $this->discussionid, get_string('discussion', 'forum'), 'selection');
- $leapwriter->add_entry($selection);
- $leapwriter->make_selection($selection, $ids, 'Grouping');
- $content = $leapwriter->to_xml();
- $name = $this->get('exporter')->get('format')->manifest_name();
- }
- $this->get('exporter')->write_new_file($content, $name, $manifest);
-
- } else { // exporting a single post
- $posthtml = $this->prepare_post($this->post);
-
- $content = $posthtml;
- $name = 'post.html';
- $manifest = ($this->exporter->get('format') instanceof PORTFOLIO_FORMAT_RICH);
-
- if ($writingleap) {
- $this->prepare_post_leap2a($leapwriter, $this->post, $posthtml);
- $content = $leapwriter->to_xml();
- $name = $this->exporter->get('format')->manifest_name();
- }
- $this->copy_files($this->multifiles);
- $this->get('exporter')->write_new_file($content, $name, $manifest);
- }
- }
-
- /**
- * helper function to add a leap2a entry element
- * that corresponds to a single forum post,
- * including any attachments
- *
- * the entry/ies are added directly to the leapwriter, which is passed by ref
- *
- * @param portfolio_format_leap2a_writer $leapwriter writer object to add entries to
- * @param object $post the stdclass object representing the database record
- * @param string $posthtml the content of the post (prepared by {@link prepare_post}
- *
- * @return int id of new entry
- */
- private function prepare_post_leap2a(portfolio_format_leap2a_writer $leapwriter, $post, $posthtml) {
- $entry = new portfolio_format_leap2a_entry('forumpost' . $post->id, $post->subject, 'resource', $posthtml);
- $entry->published = $post->created;
- $entry->updated = $post->modified;
- $entry->author = $post->author;
- if (is_array($this->keyedfiles) && array_key_exists($post->id, $this->keyedfiles) && is_array($this->keyedfiles[$post->id])) {
- foreach ($this->keyedfiles[$post->id] as $file) {
- // copying the file into the package area is handled elsewhere
- $entry->add_attachment($file);
- }
- }
- $entry->add_category('web', 'resource_type');
- $leapwriter->add_entry($entry);
- return $entry->id;
- }
-
- /**
- * @param array $files
- * @param mixed $justone false of id of single file to copy
- * @return bool|void
- */
- private function copy_files($files, $justone=false) {
- if (empty($files)) {
- return;
- }
- foreach ($files as $f) {
- if ($justone && $f->get_id() != $justone) {
- continue;
- }
- $this->get('exporter')->copy_existing_file($f);
- if ($justone && $f->get_id() == $justone) {
- return true; // all we need to do
- }
- }
- }
- /**
- * this is a very cut down version of what is in forum_make_mail_post
- *
- * @global object
- * @param int $post
- * @return string
- */
- private function prepare_post($post, $fileoutputextras=null) {
- global $DB;
- static $users;
- if (empty($users)) {
- $users = array($this->user->id => $this->user);
- }
- if (!array_key_exists($post->userid, $users)) {
- $users[$post->userid] = $DB->get_record('user', array('id' => $post->userid));
- }
- // add the user object on to the post so we can pass it to the leap writer if necessary
- $post->author = $users[$post->userid];
- $viewfullnames = true;
- // format the post body
- $options = new object();
- $options->para = true;
- $formattedtext = format_text($post->message, $post->messageformat, $options, $this->get('course')->id);
-
- $output = '<table border="0" cellpadding="3" cellspacing="0" class="forumpost">';
-
- $output .= '<tr class="header"><td>';// can't print picture.
- $output .= '</td>';
-
- if ($post->parent) {
- $output .= '<td class="topic">';
- } else {
- $output .= '<td class="topic starter">';
- }
- $output .= '<div class="subject">'.format_string($post->subject).'</div>';
-
- $fullname = fullname($users[$post->userid], $viewfullnames);
- $by = new object();
- $by->name = $fullname;
- $by->date = userdate($post->modified, '', $this->user->timezone);
- $output .= '<div class="author">'.get_string('bynameondate', 'forum', $by).'</div>';
-
- $output .= '</td></tr>';
-
- $output .= '<tr><td class="left side" valign="top">';
-
- $output .= '</td><td class="content">';
-
- $output .= $formattedtext;
-
- if (is_array($this->keyedfiles) && array_key_exists($post->id, $this->keyedfiles) && is_array($this->keyedfiles[$post->id]) && count($this->keyedfiles[$post->id]) > 0) {
- $output .= '<div class="attachments">';
- $output .= '<br /><b>' . get_string('attachments', 'forum') . '</b>:<br /><br />';
- $format = $this->get('exporter')->get('format');
- foreach ($this->keyedfiles[$post->id] as $file) {
- $output .= $format->file_output($file) . '<br/ >';
- }
- $output .= "</div>";
- }
-
- $output .= '</td></tr></table>'."\n\n";
-
- return $output;
- }
- /**
- * @return string
- */
- function get_sha1() {
- $filesha = '';
- try {
- $filesha = $this->get_sha1_file();
- } catch (portfolio_caller_exception $e) { } // no files
-
- if ($this->post) {
- return sha1($filesha . ',' . $this->post->subject . ',' . $this->post->message);
- } else {
- $sha1s = array($filesha);
- foreach ($this->posts as $post) {
- $sha1s[] = sha1($post->subject . ',' . $post->message);
- }
- return sha1(implode(',', $sha1s));
- }
- }
-
- function expected_time() {
- $filetime = $this->expected_time_file();
- if ($this->posts) {
- $posttime = portfolio_expected_time_db(count($this->posts));
- if ($filetime < $posttime) {
- return $posttime;
- }
- }
- return $filetime;
- }
- /**
- * @uses CONTEXT_MODULE
- * @return bool
- */
- function check_permissions() {
- $context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
- if ($this->post) {
- return (has_capability('mod/forum:exportpost', $context)
- || ($this->post->userid == $this->user->id
- && has_capability('mod/forum:exportownpost', $context)));
- }
- return has_capability('mod/forum:exportdiscussion', $context);
- }
- /**
- * @return string
- */
- public static function display_name() {
- return get_string('modulename', 'forum');
- }
-
- public static function base_supported_formats() {
- return array(PORTFOLIO_FORMAT_FILE, PORTFOLIO_FORMAT_RICHHTML, PORTFOLIO_FORMAT_PLAINHTML, PORTFOLIO_FORMAT_LEAP2A);
- }
-}
/**
* This function is used to extend the global navigation by add forum nodes if there
return array(get_string("existingsubscribers", 'forum') => $subscribers);
}
-}
\ No newline at end of file
+}
--- /dev/null
+<?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/>.
+
+/**
+ * Library of functions for forum outside of the core api
+ */
+
+require_once($CFG->libdir . '/portfolio/caller.php');
+
+/**
+ * @package mod-forum
+ * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class forum_portfolio_caller extends portfolio_module_caller_base {
+
+ protected $postid;
+ protected $discussionid;
+ protected $attachment;
+
+ private $post;
+ private $forum;
+ private $discussion;
+ private $posts;
+ private $keyedfiles; // just using multifiles isn't enough if we're exporting a full thread
+
+ /**
+ * @return array
+ */
+ public static function expected_callbackargs() {
+ return array(
+ 'postid' => false,
+ 'discussionid' => false,
+ 'attachment' => false,
+ );
+ }
+ /**
+ * @param array $callbackargs
+ */
+ function __construct($callbackargs) {
+ parent::__construct($callbackargs);
+ if (!$this->postid && !$this->discussionid) {
+ throw new portfolio_caller_exception('mustprovidediscussionorpost', 'forum');
+ }
+ }
+ /**
+ * @global object
+ */
+ public function load_data() {
+ global $DB;
+
+ if ($this->postid) {
+ if (!$this->post = $DB->get_record('forum_posts', array('id' => $this->postid))) {
+ throw new portfolio_caller_exception('invalidpostid', 'forum');
+ }
+ }
+
+ $dparams = array();
+ if ($this->discussionid) {
+ $dbparams = array('id' => $this->discussionid);
+ } else if ($this->post) {
+ $dbparams = array('id' => $this->post->discussion);
+ } else {
+ throw new portfolio_caller_exception('mustprovidediscussionorpost', 'forum');
+ }
+
+ if (!$this->discussion = $DB->get_record('forum_discussions', $dbparams)) {
+ throw new portfolio_caller_exception('invaliddiscussionid', 'forum');
+ }
+
+ if (!$this->forum = $DB->get_record('forum', array('id' => $this->discussion->forum))) {
+ throw new portfolio_caller_exception('invalidforumid', 'forum');
+ }
+
+ if (!$this->cm = get_coursemodule_from_instance('forum', $this->forum->id)) {
+ throw new portfolio_caller_exception('invalidcoursemodule');
+ }
+
+ $modcontext = get_context_instance(CONTEXT_MODULE, $this->cm->id);
+ if ($this->post) {
+ $this->set_file_and_format_data($this->attachment, $modcontext->id, 'forum_attachment', $this->post->id, 'timemodified', false);
+ if (!empty($this->multifiles)) {
+ $this->keyedfiles[$this->post->id] = $this->multifiles;
+ } else if (!empty($this->singlefile)) {
+ $this->keyedfiles[$this->post->id] = array($this->singlefile);
+ }
+ } else { // whole thread
+ $fs = get_file_storage();
+ $this->posts = forum_get_all_discussion_posts($this->discussion->id, 'p.created ASC');
+ $this->multifiles = array();
+ foreach ($this->posts as $post) {
+ if (!$this->keyedfiles[$post->id] = $fs->get_area_files($modcontext->id, 'forum_attachment', $post->id, "timemodified", false)) {
+ continue;
+ }
+ $this->multifiles = array_merge($this->multifiles, array_values($this->keyedfiles[$post->id]));
+ }
+ }
+ if (empty($this->multifiles) && !empty($this->singlefile)) {
+ $this->multifiles = array($this->singlefile); // copy_files workaround
+ }
+ // depending on whether there are files or not, we might have to change richhtml/plainhtml
+ if (!empty($this->multifiles)) {
+ $this->add_format(PORTFOLIO_FORMAT_RICHHTML);
+ } else {
+ $this->add_format(PORTFOLIO_FORMAT_PLAINHTML);
+ }
+ }
+
+ /**
+ * @global object
+ * @return string
+ */
+ function get_return_url() {
+ global $CFG;
+ return $CFG->wwwroot . '/mod/forum/discuss.php?d=' . $this->discussion->id;
+ }
+ /**
+ * @global object
+ * @return array
+ */
+ function get_navigation() {
+ global $CFG;
+
+ $navlinks = array();
+ $navlinks[] = array(
+ 'name' => format_string($this->discussion->name),
+ 'link' => $CFG->wwwroot . '/mod/forum/discuss.php?d=' . $this->discussion->id,
+ 'type' => 'title'
+ );
+ return array($navlinks, $this->cm);
+ }
+ /**
+ * either a whole discussion
+ * a single post, with or without attachment
+ * or just an attachment with no post
+ *
+ * @global object
+ * @global object
+ * @uses PORTFOLIO_FORMAT_RICH
+ * @return mixed
+ */
+ function prepare_package() {
+ global $CFG;
+
+ // set up the leap2a writer if we need it
+ $writingleap = false;
+ if ($this->exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) {
+ $leapwriter = $this->exporter->get('format')->leap2a_writer();
+ $writingleap = true;
+ }
+ if ($this->attachment) { // simplest case first - single file attachment
+ $this->copy_files(array($this->singlefile), $this->attachment);
+ if ($writingleap) { // if we're writing leap, make the manifest to go along with the file
+ $entry = new portfolio_format_leap2a_entry($id, $this->attachment->get_filename(), 'resource', $this->attachment);
+ $entry->add_category('offline', 'resource_type');
+ $leapwriter->add_entry($entry);
+ return $this->exporter->write_new_file($leapwriter->to_xml(), $this->exporter->get('format')->manifest_name(), true);
+ }
+
+ } else if (empty($this->post)) { // exporting whole discussion
+ $content = ''; // if we're just writing HTML, start a string to add each post to
+ $ids = array(); // if we're writing leap2a, keep track of all entryids so we can add a selection element
+ foreach ($this->posts as $post) {
+ $posthtml = $this->prepare_post($post);
+ if ($writingleap) {
+ $ids[] = $this->prepare_post_leap2a($leapwriter, $post, $posthtml);
+ } else {
+ $content .= $posthtml . '<br /><br />';
+ }
+ }
+ $this->copy_files($this->multifiles);
+ $name = 'discussion.html';
+ $manifest = ($this->exporter->get('format') instanceof PORTFOLIO_FORMAT_RICH);
+ if ($writingleap) {
+ // add on an extra 'selection' entry
+ $selection = new portfolio_format_leap2a_entry('forumdiscussion' . $this->discussionid, get_string('discussion', 'forum'), 'selection');
+ $leapwriter->add_entry($selection);
+ $leapwriter->make_selection($selection, $ids, 'Grouping');
+ $content = $leapwriter->to_xml();
+ $name = $this->get('exporter')->get('format')->manifest_name();
+ }
+ $this->get('exporter')->write_new_file($content, $name, $manifest);
+
+ } else { // exporting a single post
+ $posthtml = $this->prepare_post($this->post);
+
+ $content = $posthtml;
+ $name = 'post.html';
+ $manifest = ($this->exporter->get('format') instanceof PORTFOLIO_FORMAT_RICH);
+
+ if ($writingleap) {
+ $this->prepare_post_leap2a($leapwriter, $this->post, $posthtml);
+ $content = $leapwriter->to_xml();
+ $name = $this->exporter->get('format')->manifest_name();
+ }
+ $this->copy_files($this->multifiles);
+ $this->get('exporter')->write_new_file($content, $name, $manifest);
+ }
+ }
+
+ /**
+ * helper function to add a leap2a entry element
+ * that corresponds to a single forum post,
+ * including any attachments
+ *
+ * the entry/ies are added directly to the leapwriter, which is passed by ref
+ *
+ * @param portfolio_format_leap2a_writer $leapwriter writer object to add entries to
+ * @param object $post the stdclass object representing the database record
+ * @param string $posthtml the content of the post (prepared by {@link prepare_post}
+ *
+ * @return int id of new entry
+ */
+ private function prepare_post_leap2a(portfolio_format_leap2a_writer $leapwriter, $post, $posthtml) {
+ $entry = new portfolio_format_leap2a_entry('forumpost' . $post->id, $post->subject, 'resource', $posthtml);
+ $entry->published = $post->created;
+ $entry->updated = $post->modified;
+ $entry->author = $post->author;
+ if (is_array($this->keyedfiles) && array_key_exists($post->id, $this->keyedfiles) && is_array($this->keyedfiles[$post->id])) {
+ foreach ($this->keyedfiles[$post->id] as $file) {
+ // copying the file into the package area is handled elsewhere
+ $entry->add_attachment($file);
+ }
+ }
+ $entry->add_category('web', 'resource_type');
+ $leapwriter->add_entry($entry);
+ return $entry->id;
+ }
+
+ /**
+ * @param array $files
+ * @param mixed $justone false of id of single file to copy
+ * @return bool|void
+ */
+ private function copy_files($files, $justone=false) {
+ if (empty($files)) {
+ return;
+ }
+ foreach ($files as $f) {
+ if ($justone && $f->get_id() != $justone) {
+ continue;
+ }
+ $this->get('exporter')->copy_existing_file($f);
+ if ($justone && $f->get_id() == $justone) {
+ return true; // all we need to do
+ }
+ }
+ }
+ /**
+ * this is a very cut down version of what is in forum_make_mail_post
+ *
+ * @global object
+ * @param int $post
+ * @return string
+ */
+ private function prepare_post($post, $fileoutputextras=null) {
+ global $DB;
+ static $users;
+ if (empty($users)) {
+ $users = array($this->user->id => $this->user);
+ }
+ if (!array_key_exists($post->userid, $users)) {
+ $users[$post->userid] = $DB->get_record('user', array('id' => $post->userid));
+ }
+ // add the user object on to the post so we can pass it to the leap writer if necessary
+ $post->author = $users[$post->userid];
+ $viewfullnames = true;
+ // format the post body
+ $options = new object();
+ $options->para = true;
+ $formattedtext = format_text($post->message, $post->messageformat, $options, $this->get('course')->id);
+
+ $output = '<table border="0" cellpadding="3" cellspacing="0" class="forumpost">';
+
+ $output .= '<tr class="header"><td>';// can't print picture.
+ $output .= '</td>';
+
+ if ($post->parent) {
+ $output .= '<td class="topic">';
+ } else {
+ $output .= '<td class="topic starter">';
+ }
+ $output .= '<div class="subject">'.format_string($post->subject).'</div>';
+
+ $fullname = fullname($users[$post->userid], $viewfullnames);
+ $by = new object();
+ $by->name = $fullname;
+ $by->date = userdate($post->modified, '', $this->user->timezone);
+ $output .= '<div class="author">'.get_string('bynameondate', 'forum', $by).'</div>';
+
+ $output .= '</td></tr>';
+
+ $output .= '<tr><td class="left side" valign="top">';
+
+ $output .= '</td><td class="content">';
+
+ $output .= $formattedtext;
+
+ if (is_array($this->keyedfiles) && array_key_exists($post->id, $this->keyedfiles) && is_array($this->keyedfiles[$post->id]) && count($this->keyedfiles[$post->id]) > 0) {
+ $output .= '<div class="attachments">';
+ $output .= '<br /><b>' . get_string('attachments', 'forum') . '</b>:<br /><br />';
+ $format = $this->get('exporter')->get('format');
+ foreach ($this->keyedfiles[$post->id] as $file) {
+ $output .= $format->file_output($file) . '<br/ >';
+ }
+ $output .= "</div>";
+ }
+
+ $output .= '</td></tr></table>'."\n\n";
+
+ return $output;
+ }
+ /**
+ * @return string
+ */
+ function get_sha1() {
+ $filesha = '';
+ try {
+ $filesha = $this->get_sha1_file();
+ } catch (portfolio_caller_exception $e) { } // no files
+
+ if ($this->post) {
+ return sha1($filesha . ',' . $this->post->subject . ',' . $this->post->message);
+ } else {
+ $sha1s = array($filesha);
+ foreach ($this->posts as $post) {
+ $sha1s[] = sha1($post->subject . ',' . $post->message);
+ }
+ return sha1(implode(',', $sha1s));
+ }
+ }
+
+ function expected_time() {
+ $filetime = $this->expected_time_file();
+ if ($this->posts) {
+ $posttime = portfolio_expected_time_db(count($this->posts));
+ if ($filetime < $posttime) {
+ return $posttime;
+ }
+ }
+ return $filetime;
+ }
+ /**
+ * @uses CONTEXT_MODULE
+ * @return bool
+ */
+ function check_permissions() {
+ $context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
+ if ($this->post) {
+ return (has_capability('mod/forum:exportpost', $context)
+ || ($this->post->userid == $this->user->id
+ && has_capability('mod/forum:exportownpost', $context)));
+ }
+ return has_capability('mod/forum:exportdiscussion', $context);
+ }
+ /**
+ * @return string
+ */
+ public static function display_name() {
+ return get_string('modulename', 'forum');
+ }
+
+ public static function base_supported_formats() {
+ return array(PORTFOLIO_FORMAT_FILE, PORTFOLIO_FORMAT_RICHHTML, PORTFOLIO_FORMAT_PLAINHTML, PORTFOLIO_FORMAT_LEAP2A);
+ }
+}
if ($DB->count_records('glossary_entries', array('glossaryid' => $glossary->id))) {
require_once($CFG->libdir . '/portfoliolib.php');
$button = new portfolio_add_button();
- $button->set_callback_options('glossary_full_portfolio_caller', array('id' => $cm->id), '/mod/glossary/lib.php');
+ $button->set_callback_options('glossary_full_portfolio_caller', array('id' => $cm->id), '/mod/glossary/locallib.php');
$button->render();
}
echo $OUTPUT->box_end();
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-/** Include Portfolio lib */
-require_once($CFG->libdir.'/portfoliolib.php');
define("GLOSSARY_SHOW_ALL_CATEGORIES", 0);
define("GLOSSARY_SHOW_NOT_CATEGORISED", -1);
if (has_capability('mod/glossary:exportentry', $context)
|| ($entry->userid == $USER->id
&& has_capability('mod/glossary:exportownentry', $context))) {
+ require_once($CFG->libdir . '/portfoliolib.php');
$button = new portfolio_add_button();
- $button->set_callback_options('glossary_entry_portfolio_caller', array('id' => $cm->id, 'entryid' => $entry->id));
+ $button->set_callback_options('glossary_entry_portfolio_caller', array('id' => $cm->id, 'entryid' => $entry->id), '/mod/glossary/locallib.php');
$filecontext = $context;
if ($entry->sourceglossaryid == $cm->instance) {
$fs = get_file_storage();
if ($files = $fs->get_area_files($filecontext->id, 'glossary_attachment', $entry->id, "timemodified", false)) {
$button->set_formats(PORTFOLIO_FORMAT_RICHHTML);
+ } else {
+ $button->set_formats(PORTFOLIO_FORMAT_PLAINHTML);
}
$return .= $button->to_html(PORTFOLIO_ADD_ICON_LINK);
default: return null;
}
}
-/**
- * @package mod-glossary
- * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class glossary_full_portfolio_caller extends portfolio_module_caller_base {
-
- private $glossary;
- private $exportdata;
- /**
- * @return array
- */
- public static function expected_callbackargs() {
- return array(
- 'id' => true,
- );
- }
- /**
- * @return global
- */
- public function load_data() {
- global $DB;
- if (!$this->cm = get_coursemodule_from_id('glossary', $this->id)) {
- throw new portfolio_caller_exception('invalidid', 'glossary');
- }
- if (!$this->glossary = $DB->get_record('glossary', array('id' => $this->cm->instance))) {
- throw new portfolio_caller_exception('invalidid', 'glossary');
- }
- $entries = $DB->get_records('glossary_entries', array('glossaryid' => $this->glossary->id));
- list($where, $params) = $DB->get_in_or_equal(array_keys($entries));
-
- $aliases = $DB->get_records_select('glossary_alias', 'entryid ' . $where, $params);
- $categoryentries = $DB->get_records_sql('SELECT ec.entryid, c.name FROM {glossary_entries_categories} ec
- JOIN {glossary_categories} c
- ON c.id = ec.categoryid
- WHERE ec.entryid ' . $where, $params);
-
- $this->exportdata = array('entries' => $entries, 'aliases' => $aliases, 'categoryentries' => $categoryentries);
- }
-
- /**
- * @return string
- */
- public function expected_time() {
- return portfolio_expected_time_db(count($this->exportdata['entries']));
- }
- /**
- * @return string
- */
- public function get_sha1() {
- return sha1(serialize($this->exportdata));
- }
- /**
- * @return object
- */
- public function prepare_package() {
- $entries = $this->exportdata['entries'];
- $aliases = array();
- $categories = array();
- if (is_array($this->exportdata['aliases'])) {
- foreach ($this->exportdata['aliases'] as $alias) {
- if (!array_key_exists($alias->entryid, $aliases)) {
- $aliases[$alias->entryid] = array();
- }
- $aliases[$alias->entryid][] = $alias->alias;
- }
- }
- if (is_array($this->exportdata['categoryentries'])) {
- foreach ($this->exportdata['categoryentries'] as $cat) {
- if (!array_key_exists($cat->entryid, $categories)) {
- $categories[$cat->entryid] = array();
- }
- $categories[$cat->entryid][] = $cat->name;
- }
- }
- // TODO detect format here
- $csv = glossary_generate_export_csv($entries, $aliases, $categories);
- return $this->exporter->write_new_file($csv, clean_filename($this->cm->name) . '.csv', false);
- // TODO when csv, what do we do with attachments?!
- }
- /**
- * @return bool
- */
- public function check_permissions() {
- return has_capability('mod/glossary:export', get_context_instance(CONTEXT_MODULE, $this->cm->id));
- }
- /**
- * @return string
- */
- public static function display_name() {
- return get_string('modulename', 'glossary');
- }
-
- public static function base_supported_formats() {
- return array(PORTFOLIO_FORMAT_FILE);
- }
-}
-
-/**
- * @package mod-glossary
- * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class glossary_entry_portfolio_caller extends portfolio_module_caller_base { // TODO files support
-
- private $glossary;
- private $entry;
- protected $entryid;
- /*
- * @return array
- */
- public static function expected_callbackargs() {
- return array(
- 'entryid' => true,
- 'id' => true,
- );
- }
- /**
- * @global object
- */
- public function load_data() {
- global $DB;
- if (!$this->cm = get_coursemodule_from_id('glossary', $this->id)) {
- throw new portfolio_caller_exception('invalidid', 'glossary');
- }
- if (!$this->glossary = $DB->get_record('glossary', array('id' => $this->cm->instance))) {
- throw new portfolio_caller_exception('invalidid', 'glossary');
- }
- if ($this->entryid) {
- if (!$this->entry = $DB->get_record('glossary_entries', array('id' => $this->entryid))) {
- throw new portfolio_caller_exception('noentry', 'glossary');
- }
- // in case we don't have USER this will make the entry be printed
- $this->entry->approved = true;
- }
- $context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
- if ($this->entry->sourceglossaryid == $this->cm->instance) {
- if ($maincm = get_coursemodule_from_instance('glossary', $this->entry->glossaryid)) {
- $context = get_context_instance(CONTEXT_MODULE, $maincm->id);
- }
- }
- $fs = get_file_storage();
- $this->multifiles = $fs->get_area_files($context->id, 'glossary_attachment', $this->entry->id, "timemodified", false);
- }
- /**
- * @return string
- */
- public function expected_time() {
- return PORTFOLIO_TIME_LOW;
- }
- /**
- * @return bool
- */
- public function check_permissions() {
- $context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
- return has_capability('mod/glossary:exportentry', $context)
- || ($this->entry->userid == $this->user->id && has_capability('mod/glossary:exportownentry', $context));
- }
- /**
- * @return string
- */
- public static function display_name() {
- return get_string('modulename', 'glossary');
- }
- /**
- * @return object
- */
- public function prepare_package() {
- define('PORTFOLIO_INTERNAL', true);
- ob_start();
- $entry = clone $this->entry;
- glossary_print_entry($this->get('course'), $this->cm, $this->glossary, $entry, null, null, false);
- $content = ob_get_clean();
- if ($this->multifiles) {
- foreach ($this->multifiles as $file) {
- $this->exporter->copy_existing_file($file);
- }
- }
- return $this->exporter->write_new_file($content, clean_filename($this->entry->concept) . '.html', !empty($files));
- }
- /**
- * @return string
- */
- public function get_sha1() {
- return sha1(serialize($this->entry) . $this->get_sha1_file());
- }
-
- public static function base_supported_formats() {
- return array(PORTFOLIO_FORMAT_RICHHTML, PORTFOLIO_FORMAT_PLAINHTML);
- }
-}
function glossary_extend_navigation($navigation, $course, $module, $cm) {
global $CFG;
--- /dev/null
+<?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/>.
+
+require_once($CFG->libdir . '/portfolio/caller.php');
+
+/**
+ * Library of functions and constants for module glossary
+ * outside of what is required for the core moodle api
+ *
+ * @package mod-glossary
+ * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class glossary_full_portfolio_caller extends portfolio_module_caller_base {
+
+ private $glossary;
+ private $exportdata;
+ /**
+ * @return array
+ */
+ public static function expected_callbackargs() {
+ return array(
+ 'id' => true,
+ );
+ }
+ /**
+ * @return global
+ */
+ public function load_data() {
+ global $DB;
+ if (!$this->cm = get_coursemodule_from_id('glossary', $this->id)) {
+ throw new portfolio_caller_exception('invalidid', 'glossary');
+ }
+ if (!$this->glossary = $DB->get_record('glossary', array('id' => $this->cm->instance))) {
+ throw new portfolio_caller_exception('invalidid', 'glossary');
+ }
+ $entries = $DB->get_records('glossary_entries', array('glossaryid' => $this->glossary->id));
+ list($where, $params) = $DB->get_in_or_equal(array_keys($entries));
+
+ $aliases = $DB->get_records_select('glossary_alias', 'entryid ' . $where, $params);
+ $categoryentries = $DB->get_records_sql('SELECT ec.entryid, c.name FROM {glossary_entries_categories} ec
+ JOIN {glossary_categories} c
+ ON c.id = ec.categoryid
+ WHERE ec.entryid ' . $where, $params);
+
+ $this->exportdata = array('entries' => $entries, 'aliases' => $aliases, 'categoryentries' => $categoryentries);
+ }
+
+ /**
+ * @return string
+ */
+ public function expected_time() {
+ return portfolio_expected_time_db(count($this->exportdata['entries']));
+ }
+ /**
+ * @return string
+ */
+ public function get_sha1() {
+ return sha1(serialize($this->exportdata));
+ }
+ /**
+ * @return object
+ */
+ public function prepare_package() {
+ $entries = $this->exportdata['entries'];
+ $aliases = array();
+ $categories = array();
+ if (is_array($this->exportdata['aliases'])) {
+ foreach ($this->exportdata['aliases'] as $alias) {
+ if (!array_key_exists($alias->entryid, $aliases)) {
+ $aliases[$alias->entryid] = array();
+ }
+ $aliases[$alias->entryid][] = $alias->alias;
+ }
+ }
+ if (is_array($this->exportdata['categoryentries'])) {
+ foreach ($this->exportdata['categoryentries'] as $cat) {
+ if (!array_key_exists($cat->entryid, $categories)) {
+ $categories[$cat->entryid] = array();
+ }
+ $categories[$cat->entryid][] = $cat->name;
+ }
+ }
+ // TODO detect format here
+ $csv = glossary_generate_export_csv($entries, $aliases, $categories);
+ return $this->exporter->write_new_file($csv, clean_filename($this->cm->name) . '.csv', false);
+ // TODO when csv, what do we do with attachments?!
+ }
+ /**
+ * @return bool
+ */
+ public function check_permissions() {
+ return has_capability('mod/glossary:export', get_context_instance(CONTEXT_MODULE, $this->cm->id));
+ }
+ /**
+ * @return string
+ */
+ public static function display_name() {
+ return get_string('modulename', 'glossary');
+ }
+
+ public static function base_supported_formats() {
+ return array(PORTFOLIO_FORMAT_FILE);
+ }
+}
+
+/**
+ * @package mod-glossary
+ * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class glossary_entry_portfolio_caller extends portfolio_module_caller_base { // TODO files support
+
+ private $glossary;
+ private $entry;
+ protected $entryid;
+ /*
+ * @return array
+ */
+ public static function expected_callbackargs() {
+ return array(
+ 'entryid' => true,
+ 'id' => true,
+ );
+ }
+ /**
+ * @global object
+ */
+ public function load_data() {
+ global $DB;
+ if (!$this->cm = get_coursemodule_from_id('glossary', $this->id)) {
+ throw new portfolio_caller_exception('invalidid', 'glossary');
+ }
+ if (!$this->glossary = $DB->get_record('glossary', array('id' => $this->cm->instance))) {
+ throw new portfolio_caller_exception('invalidid', 'glossary');
+ }
+ if ($this->entryid) {
+ if (!$this->entry = $DB->get_record('glossary_entries', array('id' => $this->entryid))) {
+ throw new portfolio_caller_exception('noentry', 'glossary');
+ }
+ // in case we don't have USER this will make the entry be printed
+ $this->entry->approved = true;
+ }
+ $context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
+ if ($this->entry->sourceglossaryid == $this->cm->instance) {
+ if ($maincm = get_coursemodule_from_instance('glossary', $this->entry->glossaryid)) {
+ $context = get_context_instance(CONTEXT_MODULE, $maincm->id);
+ }
+ }
+ $fs = get_file_storage();
+ $this->multifiles = $fs->get_area_files($context->id, 'glossary_attachment', $this->entry->id, "timemodified", false);
+ }
+ /**
+ * @return string
+ */
+ public function expected_time() {
+ return PORTFOLIO_TIME_LOW;
+ }
+ /**
+ * @return bool
+ */
+ public function check_permissions() {
+ $context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
+ return has_capability('mod/glossary:exportentry', $context)
+ || ($this->entry->userid == $this->user->id && has_capability('mod/glossary:exportownentry', $context));
+ }
+ /**
+ * @return string
+ */
+ public static function display_name() {
+ return get_string('modulename', 'glossary');
+ }
+ /**
+ * @return object
+ */
+ public function prepare_package() {
+ define('PORTFOLIO_INTERNAL', true);
+ ob_start();
+ $entry = clone $this->entry;
+ glossary_print_entry($this->get('course'), $this->cm, $this->glossary, $entry, null, null, false);
+ $content = ob_get_clean();
+ if ($this->multifiles) {
+ foreach ($this->multifiles as $file) {
+ $this->exporter->copy_existing_file($file);
+ }
+ }
+ return $this->exporter->write_new_file($content, clean_filename($this->entry->concept) . '.html', !empty($files));
+ }
+ /**
+ * @return string
+ */
+ public function get_sha1() {
+ if ($this->multifiles) {
+ return sha1(serialize($this->entry) . $this->get_sha1_file());
+ }
+ return sha1(serialize($this->entry));
+ }
+
+ public static function base_supported_formats() {
+ return array(PORTFOLIO_FORMAT_RICHHTML, PORTFOLIO_FORMAT_PLAINHTML);
+ }
+}
print_error('disabled', 'portfolio');
}
-// this will pull in all the other required libraries
require_once($CFG->libdir . '/portfoliolib.php');
-// so plugins don't have to.
-require_once($CFG->libdir . '/formslib.php');
+require_once($CFG->libdir . '/portfolio/exporter.php');
+require_once($CFG->libdir . '/portfolio/caller.php');
+require_once($CFG->libdir . '/portfolio/plugin.php');
$dataid = optional_param('id', 0, PARAM_INT); // id of partially completed export. corresponds to a record in portfolio_tempdata
$type = optional_param('type', null, PARAM_SAFEDIR); // if we're returning from an external system (postcontrol) for a single-export only plugin
$instance = array_shift(array_keys($options));
redirect($CFG->wwwroot . '/portfolio/add.php?id= ' . $exporter->get('id') . '&instance=' . $instance . '&sesskey=' . sesskey());
}
+ // be very selective about not including this unless we really need to
+ require_once($CFG->libdir . '/portfolio/forms.php');
$mform = new portfolio_instance_select('', array('id' => $exporter->get('id'), 'caller' => $exporter->get('caller'), 'options' => $options));
if ($mform->is_cancelled()) {
$exporter->cancel_request();
}
require_once($CFG->libdir.'/portfoliolib.php');
+require_once($CFG->libdir.'/portfolio/exporter.php');
+
$PAGE->requires->yui_lib('dom');
$id = required_param('id', PARAM_INT);
}
require_once($CFG->libdir . '/portfoliolib.php');
+require_once($CFG->libdir . '/portfolio/exporter.php');
require_once($CFG->libdir . '/file/stored_file.php');
require_once($CFG->libdir . '/filelib.php');
define('PORTFOLIO_MAHARA_ERR_INVALIDHOST', 'err_invalidhost');
define('PORTFOLIO_MAHARA_ERR_NOMNETAUTH', 'err_nomnetauth');
-require_once($CFG->dirroot . '/lib/portfoliolib.php');
+require_once($CFG->libdir . '/portfoliolib.php');
+require_once($CFG->libdir . '/portfolio/plugin.php');
+require_once($CFG->libdir . '/portfolio/exporter.php');
require_once($CFG->dirroot . '/mnet/lib.php');
define('PORTFOLIO_MAHARA_QUEUE', PORTFOLIO_TIME_HIGH);
* which might be higher up the format hierarchy tree (eg 'file')
*/
private function resolve_format() {
+ global $CFG;
$thisformat = $this->get_export_config('format');
$allformats = portfolio_supported_formats();
+ require_once($CFG->libdir . '/portfolio/formats.php');
$thisobj = new $allformats[$thisformat];
foreach ($this->supported_formats() as $f) {
$class = $allformats[$f];
}
require_once($CFG->libdir . '/portfoliolib.php');
+require_once($CFG->libdir . '/portfolio/plugin.php');
+require_once($CFG->libdir . '/portfolio/exporter.php');
require_once($CFG->dirroot . '/mnet/lib.php');
require_login();
}
require_once($CFG->libdir . '/portfoliolib.php');
+require_once($CFG->libdir . '/portfolio/forms.php');
$config = optional_param('config', 0, PARAM_INT);
$hide = optional_param('hide', 0, PARAM_INT);