mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
portfolio: MDL-21030 - leap2a portfolio format support.
This commit includes: - leap2a portfolio format, and xml writer - proof of concept implementation in forum and assignment modules - a lot of refactoring of the portfolio formats in general: - addition of "abstract" formats - this is necessary for plugins to be able to support groups of formats - addition of the idea of portfolio formats conflicting with eachother - eg richhtml & plainhtml it touches modules other than assignment and forum, because the format api changed and now each place in moodle that exports portfolio content has to deal with the formats it supports slightly differently. At the moment the Mahara portfolio still doesn't support this format, because I haven't done the Mahara side yet. The "file download" plugin supports it though. Still todo: - Add support for the other places in Moodle (glossary, data, etc) - Write tests, once the rest of the portfolio tests have been updated to use the new DB mocking stuff - Fix a bunch of TODOs
This commit is contained in:
parent
9cbced1d2e
commit
59dd457e4b
26 changed files with 994 additions and 111 deletions
|
@ -1821,7 +1821,6 @@ class assignment_base {
|
|||
}
|
||||
if (count($files) > 1 && $this->portfolio_exportable() && has_capability('mod/assignment:exportownsubmission', $this->context)) {
|
||||
$button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id));
|
||||
$button->set_formats(PORTFOLIO_PORMAT_FILE);
|
||||
$output .= '<br />' . $button->to_html();
|
||||
}
|
||||
}
|
||||
|
@ -3395,10 +3394,7 @@ class assignment_portfolio_caller extends portfolio_module_caller_base {
|
|||
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);
|
||||
if (empty($this->supportedformats) && is_callable(array($this->assignment, 'portfolio_supported_formats'))) {
|
||||
$this->supportedformats = $this->assignment->portfolio_supported_formats();
|
||||
}
|
||||
$this->set_file_and_format_data($this->fileid, $this->assignment->context->id, 'assignment_submission', $this->user->id, 'timemodified', false);
|
||||
}
|
||||
|
||||
public function prepare_package() {
|
||||
|
@ -3406,6 +3402,26 @@ class assignment_portfolio_caller extends portfolio_module_caller_base {
|
|||
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();
|
||||
}
|
||||
|
||||
|
@ -3441,6 +3457,10 @@ class assignment_portfolio_caller extends portfolio_module_caller_base {
|
|||
public static function display_name() {
|
||||
return get_string('modulename', 'assignment');
|
||||
}
|
||||
|
||||
public static function base_supported_formats() {
|
||||
return array(PORTFOLIO_FORMAT_FILE, PORTFOLIO_FORMAT_LEAP2A);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -110,6 +110,7 @@ class assignment_online extends assignment_base {
|
|||
echo format_text($text, $submission->data2);
|
||||
$button = new portfolio_add_button();
|
||||
$button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id), '/mod/assignment/lib.php');
|
||||
$button->set_formats(PORTFOLIO_FORMAT_PLAINHTML); //TODO this might have files?
|
||||
$button->render();
|
||||
} else if (!has_capability('mod/assignment:submit', $context)) { //fix for #4604
|
||||
echo '<div style="text-align:center">'. get_string('guestnosubmit', 'assignment').'</div>';
|
||||
|
@ -285,11 +286,19 @@ class assignment_online extends assignment_base {
|
|||
|
||||
function portfolio_prepare_package($exporter, $userid=0) {
|
||||
$submission = $this->get_submission($userid);
|
||||
$exporter->write_new_file(format_text($submission->data1, $submission->data2), 'assignment.html', false);
|
||||
}
|
||||
|
||||
function portfolio_supported_formats() {
|
||||
return array(PORTFOLIO_FORMAT_PLAINHTML);
|
||||
$html = format_text($submission->data1, $submission->data2);
|
||||
if ($exporter->get('formatclass') == PORTFOLIO_FORMAT_PLAINHTML) {
|
||||
return $exporter->write_new_file($html, 'assignment.html', false);
|
||||
} else if ($exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) {
|
||||
$leapwriter = $exporter->get('format')->leap2a_writer();
|
||||
$entry = new portfolio_format_leap2a_entry('assignmentonline' . $this->assignment->id, $this->assignment->name, 'resource', $html); // TODO entry?
|
||||
$entry->add_category('web', 'resource_type');
|
||||
$leapwriter->add_entry($entry);
|
||||
return $exporter->write_new_file($leapwriter->to_xml(), $exporter->get('format')->manifest_name(), true);
|
||||
//TODO attached files?!
|
||||
} else {
|
||||
die('wtf ;' . $exporter->get('formatclass'));
|
||||
}
|
||||
}
|
||||
|
||||
function extend_settings_navigation($node) {
|
||||
|
|
|
@ -368,7 +368,7 @@ class assignment_upload extends assignment_base {
|
|||
}
|
||||
if (count($files) > 1 && has_capability('mod/assignment:exportownsubmission', $this->context)) {
|
||||
$button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id), '/mod/assignment/lib.php');
|
||||
$button->set_formats(PORTFOLIO_FORMAT_FILE);
|
||||
$button->reset_formats(); // reset what we set before, since it's multi-file
|
||||
$output .= $button->to_html();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue