$string['cannotsetvisible'] = 'Cannot set this to visible - the plugin has been completely disabled because of a misconfiguration';
$string['configexport'] = 'Configure exported data';
$string['configplugin'] = 'Configure portfolio plugin';
-$string['confirmexport'] = 'Please confirm the following export';
+$string['confirmexport'] = 'Please confirm this export';
$string['confirmsummary'] = 'Summary of your export';
$string['configure'] = 'Configure';
$string['continuetoportfolio'] = 'Continue to your portfolio';
$string['enableddesc'] = 'This will allow administrators to configure remote systems for users to export content to';
$string['exporting'] = 'Exporting to portfolio';
$string['exportcomplete'] = 'Portfolio export complete!';
+$string['exportedpreviously'] = 'Previous exports';
$string['failedtosendpackage'] = 'Failed to send your data to the selected portfolio system!';
$string['format_file'] = 'File';
$string['format_mbkp'] = 'Moodle Backup';
<?php
-// @TODO think about making some more of the functions final.
/**
* this file contains:
* {@link portfolio_add_button} -entry point for callers
*/
public abstract function get_navigation();
+ /**
+ *
+ */
+ public abstract function get_sha1();
+
/*
* generic getter for properties belonging to this instance
* <b>outside</b> the subclasses
*/
public final function set_export_config($config) {
$allowed = array_merge(
- array('wait', 'hidewait', 'format'),
+ array('wait', 'hidewait', 'format', 'hideformat'),
$this->get_allowed_export_config()
);
foreach ($config as $key => $value) {
*/
public final function get_export_config($key) {
$allowed = array_merge(
- array('wait', 'hidewait', 'format'),
+ array('wait', 'hidewait', 'format', 'hideformat'),
$this->get_allowed_export_config()
);
if (!in_array($key, $allowed)) {
* in the caller (called during the export process
*/
public abstract function check_permissions();
+
+ /**
+ * nice name to display to the user about this caller location
+ */
+ public abstract static function display_name();
}
abstract class portfolio_module_caller_base extends portfolio_caller_base {
*/
public function set_export_config($config) {
$allowed = array_merge(
- array('wait', 'format'),
+ array('wait', 'hidewait', 'format', 'hideformat'),
$this->get_allowed_export_config()
);
foreach ($config as $key => $value) {
*/
public final function get_export_config($key) {
$allowed = array_merge(
- array('wait', 'format'),
+ array('hidewait', 'wait', 'format', 'hideformat'),
$this->get_allowed_export_config()
);
if (!in_array($key, $allowed)) {
$pluginbits['wait'] = 1;
$pluginbits['hidewait'] = 1;
}
+ $callerbits['hideformat'] = $pluginbits['hideformat'] = (count($formats) == 1);
$this->caller->set_export_config($callerbits);
$this->instance->set_export_config($pluginbits);
return true;
}
} else {
$this->noexportconfig = true;
- $this->instance->set_export_config(array('wait' => 1));
+ $format = array_shift($formats);
+ $this->instance->set_export_config(array('hidewait' => 1, 'wait' => 1, 'format' => $format, 'hideformat' => 1));
+ $this->caller->set_export_config(array('format' => $format, 'hideformat' => 1));
return true;
// do not break - fall through to confirm
}
}
-
/**
* processes the 'confirm' stage of the export
*
* @return boolean whether or not to process the next stage. this is important as the control function is called recursively.
*/
public function process_stage_confirm() {
- global $CFG;
- if (isset($this->noexportconfig)) {
+ global $CFG, $DB;
+
+ $previous = $DB->get_records(
+ 'portfolio_log',
+ array(
+ 'userid' => $this->user->id,
+ 'portfolio' => $this->instance->get('id'),
+ 'caller_sha1' => $this->caller->get_sha1(),
+ )
+ );
+ if (isset($this->noexportconfig) && empty($previous)) {
return true;
}
$strconfirm = get_string('confirmexport', 'portfolio');
$yesurl = $CFG->wwwroot . '/portfolio/add.php?stage=' . PORTFOLIO_STAGE_QUEUEORWAIT;
- $nourl = $this->caller->get_return_url();
+ $nourl = $CFG->wwwroot . '/portfolio/add.php?cancel=1';
$this->print_header();
print_heading($strconfirm);
print_simple_box_start();
print_heading(get_string('confirmsummary', 'portfolio'), '', 4);
- $mainsummary = array(
- // @todo do something cleverer about wait
- get_string('selectedformat', 'portfolio') => get_string('format_' . $this->instance->get_export_config('format'), 'portfolio'),
- );
+ $mainsummary = array();
+ if (!$this->instance->get_export_config('hideformat')) {
+ $mainsummary[get_string('selectedformat', 'portfolio')] = get_string('format_' . $this->instance->get_export_config('format'), 'portfolio');
+ }
if (!$this->instance->get_export_config('hidewait')) {
- $mainsummary[get_string('selectedwait', 'portfolio')] = get_string($this->instance->get_export_config('wait') ? 'yes' : 'no');
+ $mainsummary[get_string('selectedwait', 'portfolio')] = get_string(($this->instance->get_export_config('wait') ? 'yes' : 'no'));
+ }
+ if ($previous) {
+ $previousstr = '';
+ foreach ($previous as $row) {
+ $previousstr .= userdate($row->time);
+ if ($row->caller_class != get_class($this->caller)) {
+ require_once($CFG->dirroot . '/' . $row->caller_file);
+ $previousstr .= ' (' . call_user_func(array($row->caller_class, 'display_name')) . ')';
+ }
+ $previousstr .= '<br />';
+ }
+ $mainsummary[get_string('exportedpreviously', 'portfolio')] = $previousstr;
}
if (!$csummary = $this->caller->get_export_summary()) {
$csummary = array();
$isummary = array();
}
$mainsummary = array_merge($mainsummary, $csummary, $isummary);
+ $table = new StdClass;
+ $table->data = array();
foreach ($mainsummary as $string => $value) {
- echo '<b>' . $string . '</b>:' . $value . '<br />' . "\n";
+ $table->data[] = array($string, $value);
}
+ print_table($table);
notice_yesno($strconfirm, $yesurl, $nourl);
print_simple_box_end();
print_footer();
if (!$this->instance->send_package()) {
return $this->raise_error('failedtosendpackage', 'portfolio');
}
+ // log the transfer
+ global $DB;
+ $l = array(
+ 'userid' => $this->user->id,
+ 'portfolio' => $this->instance->get('id'),
+ 'caller_file' => $this->callerfile,
+ 'caller_sha1' => $this->caller->get_sha1(),
+ 'caller_class' => get_class($this->caller),
+ 'time' => time(),
+ );
+ $DB->insert_record('portfolio_log', $l);
return true;
}
public function prepare_package($tempdir) {
global $CFG;
- if ($this->assignment->assignment->assignmenttype == 'online') {
- $submission = $this->assignment->get_submission();
- $handle = fopen($tempdir . '/assignment.html', 'w');
- $status = $handle && fwrite($handle, format_text($submission->data1, $submission->data2));
- $status = $status && fclose($handle);
- return $status;
+ if (is_callable(array($this->assignment, 'portfolio_prepare_package'))) {
+ return $this->assignment->portfolio_prepare_package($tempdir);
}
+ // default...
$filearea = $CFG->dataroot . '/' . $this->assignment->file_area_name($this->userid);
//@todo penny this is a dreadful thing to have to call (replace with files api anyway)
require_once($CFG->dirroot . '/backup/lib.php');
return backup_copy_file($filearea, $tempdir);
}
+ public function get_sha1() {
+ global $CFG;
+ if (is_callable(array($this->assignment, 'portfolio_get_sha1'))) {
+ return $this->assignment->portfolio_get_sha1();
+ }
+ // default ...
+ $filearea = $CFG->dataroot . '/' . $this->assignment->file_area_name($this->userid);
+ if ($this->file) {
+ return sha1_file($filearea . '/' . $this->file);
+ }
+ $sha1s = array();
+ foreach (get_directory_list($filearea) as $file) {
+ $sha1s[] = sha1_file($filearea . '/' . $file);
+ }
+ asort($sha1s);
+ return sha1(implode('', $sha1s));
+
+ }
+
public function expected_time() {
return PORTFOLIO_TIME_MODERATE; // @TODO check uploaded file size
}
require_once($this->assignmentfile);
$this->assignment = unserialize(serialize($this->assignment));
}
+
+ public static function display_name() {
+ return get_string('modulename', 'assignment');
+ }
}
/**
function portfolio_exportable() {
return true;
}
+
+ function portfolio_get_sha1() {
+ $submission = $this->get_submission();
+ return sha1(format_text($submission->data1, $submission->data2));
+ }
+
+ function portfolio_prepare_package($tempdir) {
+ $submission = $this->get_submission();
+ $handle = fopen($tempdir . '/assignment.html', 'w');
+ $status = $handle && fwrite($handle, format_text($submission->data1, $submission->data2));
+ $status = $status && fclose($handle);
+ return $status;
+ }
}
class mod_assignment_online_edit_form extends moodleform {
// @todo see MDL-15758
}
+ function get_sha1() {
+ if ($this->attachment) {
+ if ($basedir = forum_file_area($this->post)) {
+ $sha1s = array();
+ foreach (get_directory_list($basedir) as $file) {
+ $sha1s[] = sha1_file($basedir . '/' . $file);
+ }
+ asort($sha1s);
+ return sha1(implode('', $sha1s));
+ }
+ return false;
+ }
+ portfolio_exporter::raise_error('TODO - see MDL-15758');
+ // @todo see MDL-15758
+ }
+
function expected_time() {
// @todo check for attachment size
return PORTFOLIO_TIME_LOW;
return true;
}
+ public static function display_name() {
+ return get_string('modulename', 'forum');
+ }
}
?>
function portfolio_prepare_package_online($tempdir, $text=false) {
//@todo penny use the files api here
$status = $handle = fopen($tempdir . '/' . clean_filename($this->cm->name . '.' . (($text) ? 'txt' : 'html')), 'w');
- $formatoptions = new object();
- $formatoptions->noclean = true;
+ $formatoptions = (object)array('noclean' => true);
$format = (($text) ? FORMAT_MOODLE : FORMAT_HTML);
$content = format_text($this->resource->alltext, $format, $formatoptions, $this->course->id);
$status = $status && fwrite($handle, $content);
return $status;
}
+ function portfolio_get_sha1_online($text=false) {
+ $formatoptions = (object)array('noclean' => true);
+ $format = (($text) ? FORMAT_MOODLE : FORMAT_HTML);
+ $content = format_text($this->resource->alltext, $format, $formatoptions, $this->course->id);
+ return sha1($content);
+ }
+
+ function portfolio_get_sha1_uploaded() {
+ // @todo penny implement later.
+ }
+
} /// end of class definition
}
public function prepare_package($tempdir) {
- if (!is_callable(array($this->resource, 'portfolio_prepare_package'))) {
- portfolio_exporter::raise_error('portfolionotimplemented', 'resource');
- }
return $this->resource->portfolio_prepare_package($tempdir);
}
public static function add_button($resource, $fullform=true, $return=false) {
// @todo penny can we put the capability check in here?
- if (!is_callable(array($resource, 'portfolio_prepare_package'))) {
+ if (!is_callable(array($resource, 'portfolio_prepare_package')) || !is_callable(array($resource, 'portfolio_get_sha1'))) {
debugging(get_string('portfolionotimplemented', 'resource'));
return false;
}
return portfolio_add_button('resource_portfolio_caller', array('id' => $resource->cm->instance), '/mod/resource/lib.php', $fullform, $return);
}
+
+ public function get_sha1() {
+ return $this->resource->portfolio_get_sha1();
+ }
+
+ public static function display_name() {
+ return get_string('modulename', 'resource');
+ }
}
/**
return parent::portfolio_prepare_package_online($tempdir);
}
+function portfolio_get_sha1() {
+ return parent::portfolio_get_sha1_online();
+}
+
}
function portfolio_prepare_package($tempdir) {
return parent::portfolio_prepare_package_online($tempdir, true);
}
+
+function portfolio_get_sha1() {
+ return parent::portfolio_get_sha1_online(true);
+}
+
}
?>
require_once($CFG->dirroot . '/' . $exporter->callerfile);
$exporter = unserialize(serialize($SESSION->portfolio->exporter));
$SESSION->portfolio->exporter =& $exporter;
- if ($instance = optional_param('instance', 0, PARAM_INT)) {
+ if (!$exporter->get('instance')) {
+ $instance = required_param('instance', PARAM_INT);
$instance = portfolio_instance($instance);
if ($broken = portfolio_instance_sanity_check($instance)) {
print_error(get_string($broken[$instance->get('id')], 'portfolio_' . $instance->get('plugin')));
}
$instance->set('user', $USER);
$exporter->set('instance', $instance);
-
+ }
+ if ($cancel = optional_param('cancel', 0, PARAM_INT)) {
+ $returnurl = $exporter->get('caller')->get_return_url();
+ unset($SESSION->portfolio);
+ redirect($returnurl);
}
} else {
// we'e just posted here for the first time and have might the instance already