mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-15777 - updated most of the portfolio code to use files api.
Not done: - forum (the rest of the module isn't using files api yet) - database mod (touches other parts of the code (ods and excel libs) - portfolio download plugin (needs discussion with petr about userfiles) all of these have been disabled in the meantime.
This commit is contained in:
parent
db79c1b960
commit
d67bfc32a1
13 changed files with 178 additions and 126 deletions
|
@ -1714,7 +1714,7 @@ class assignment_base {
|
|||
$path = $browser->encodepath($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/assignment_submission/'.$userid.'/'.$filename);
|
||||
$output .= '<a href="'.$path.'" ><img src="'.$CFG->pixpath.'/f/'.$icon.'" class="icon" alt="'.$icon.'" />'.s($filename).'</a>';
|
||||
if ($this->portfolio_exportable() && true) { // @todo replace with capability check
|
||||
$p['file'] = $file;
|
||||
$p['file'] = $file->get_id();
|
||||
$output .= portfolio_add_button('assignment_portfolio_caller', $p, null, false, true);
|
||||
}
|
||||
$output .= '<br />';
|
||||
|
@ -3144,20 +3144,19 @@ class assignment_portfolio_caller extends portfolio_module_caller_base {
|
|||
$this->file = (array_key_exists('file', $callbackargs)) ? $callbackargs['file'] : null;
|
||||
}
|
||||
|
||||
public function prepare_package($tempdir) {
|
||||
public function prepare_package() {
|
||||
global $CFG;
|
||||
if (is_callable(array($this->assignment, 'portfolio_prepare_package'))) {
|
||||
return $this->assignment->portfolio_prepare_package($tempdir);
|
||||
return $this->assignment->portfolio_prepare_package($this->exporter);
|
||||
}
|
||||
error('TODO: covert');
|
||||
// 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');
|
||||
if ($this->file) {
|
||||
return backup_copy_file($filearea . '/' . $this->file, $tempdir . '/' . $this->file);
|
||||
$fs = get_file_storage();
|
||||
$status = true;
|
||||
if ($files = $fs->get_area_files($this->assignment->context->id, 'assignment_submission', $this->user->id, '', false)) {
|
||||
foreach ($files as $file) {
|
||||
$status = $status && $this->exporter->copy_existing_file($file);
|
||||
}
|
||||
}
|
||||
return backup_copy_file($filearea, $tempdir);
|
||||
return $status;
|
||||
}
|
||||
|
||||
public function get_sha1() {
|
||||
|
@ -3166,17 +3165,19 @@ error('TODO: covert');
|
|||
return $this->assignment->portfolio_get_sha1();
|
||||
}
|
||||
|
||||
error('TODO: covert');
|
||||
// default ...
|
||||
$filearea = $CFG->dataroot . '/' . $this->assignment->file_area_name($this->userid);
|
||||
$fs = get_file_storage();
|
||||
$status = true;
|
||||
if ($this->file) {
|
||||
return sha1_file($filearea . '/' . $this->file);
|
||||
return $fs->get_file($this->file)->get_contenthash();
|
||||
}
|
||||
$sha1s = array();
|
||||
foreach (get_directory_list($filearea) as $file) {
|
||||
$sha1s[] = sha1_file($filearea . '/' . $file);
|
||||
if ($files = $fs->get_area_files($this->assignment->context->id, 'assignment_submission', $this->user->id, '', false)) {
|
||||
$sha1s = array();
|
||||
foreach ($files as $file) {
|
||||
$sha1s[] = $file->get_contenthash();
|
||||
}
|
||||
asort($sha1s);
|
||||
}
|
||||
asort($sha1s);
|
||||
return sha1(implode('', $sha1s));
|
||||
|
||||
}
|
||||
|
|
|
@ -275,12 +275,9 @@ class assignment_online extends assignment_base {
|
|||
return sha1(format_text($submission->data1, $submission->data2));
|
||||
}
|
||||
|
||||
function portfolio_prepare_package($tempdir) {
|
||||
function portfolio_prepare_package($exporter) {
|
||||
$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;
|
||||
return $exporter->write_new_file(format_text($submission->data1, $submission->data2), 'assignment.html');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -53,11 +53,16 @@ class mod_data_export_form extends moodleform {
|
|||
}
|
||||
$this->add_checkbox_controller(1, null, null, 1);
|
||||
require_once($CFG->libdir . '/portfoliolib.php');
|
||||
if ($portfoliooptions = portfolio_instance_select(portfolio_instances(), call_user_func(array('data_portfolio_caller', 'supported_formats')), 'data_portfolio_caller', '', true, true)) {
|
||||
$mform->addElement('header', 'notice', get_string('portfolionotfile', 'portfolio') . ':');
|
||||
$portfoliooptions[0] = get_string('none');
|
||||
ksort($portfoliooptions);
|
||||
$mform->addElement('select', 'portfolio', get_string('portfolio', 'portfolio'), $portfoliooptions);
|
||||
if (false) { // @todo penny replace with permissions check
|
||||
if ($portfoliooptions = portfolio_instance_select(
|
||||
portfolio_instances(),
|
||||
call_user_func(array('data_portfolio_caller', 'supported_formats')),
|
||||
'data_portfolio_caller', '', true, true)) {
|
||||
$mform->addElement('header', 'notice', get_string('portfolionotfile', 'portfolio') . ':');
|
||||
$portfoliooptions[0] = get_string('none');
|
||||
ksort($portfoliooptions);
|
||||
$mform->addElement('select', 'portfolio', get_string('portfolio', 'portfolio'), $portfoliooptions);
|
||||
}
|
||||
}
|
||||
$this->add_action_buttons(true, get_string('exportdatabaserecords', 'data'));
|
||||
}
|
||||
|
|
|
@ -2472,7 +2472,7 @@ class data_portfolio_caller extends portfolio_module_caller_base {
|
|||
return sha1($str . ',' . $this->exporttype);
|
||||
}
|
||||
|
||||
public function prepare_package($tempdir) {
|
||||
public function prepare_package() {
|
||||
global $DB;
|
||||
$count = count($this->exportdata);
|
||||
switch ($this->exporttype) {
|
||||
|
|
|
@ -3072,7 +3072,7 @@ function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=fa
|
|||
$p = array(
|
||||
'postid' => $post->id,
|
||||
);
|
||||
$commands[] = portfolio_add_button('forum_portfolio_caller', $p, '/mod/forum/lib.php', false, true);
|
||||
//$commands[] = portfolio_add_button('forum_portfolio_caller', $p, '/mod/forum/lib.php', false, true);
|
||||
}
|
||||
|
||||
echo '<div class="commands">';
|
||||
|
@ -3840,7 +3840,7 @@ function forum_print_attachments($post, $return=NULL) {
|
|||
'postid' => $post->id,
|
||||
'attachment' => 1,
|
||||
);
|
||||
$output .= portfolio_add_button('forum_portfolio_caller', $p, '/mod/forum/lib.php', false, true);
|
||||
//$output .= portfolio_add_button('forum_portfolio_caller', $p, '/mod/forum/lib.php', false, true);
|
||||
}
|
||||
$output .= "<br />";
|
||||
|
||||
|
@ -3859,7 +3859,7 @@ function forum_print_attachments($post, $return=NULL) {
|
|||
'postid' => $post->id,
|
||||
'attachment' => 1,
|
||||
);
|
||||
portfolio_add_button('forum_portfolio_caller', $p, '/mod/forum/lib.php', false);
|
||||
//portfolio_add_button('forum_portfolio_caller', $p, '/mod/forum/lib.php', false);
|
||||
}
|
||||
echo '<br />';
|
||||
}
|
||||
|
@ -7044,15 +7044,16 @@ class forum_portfolio_caller extends portfolio_module_caller_base {
|
|||
return array($navlinks, $this->cm);
|
||||
}
|
||||
|
||||
function prepare_package($tempdir) {
|
||||
function prepare_package() {
|
||||
global $CFG, $SESSION;
|
||||
// either a whole discussion
|
||||
// a single post, with or without attachment
|
||||
// or just an attachment with no post
|
||||
if (!$this->post) { // whole discussion
|
||||
portfolio_exporter::raise_error('exoprting whole discussion not implemented - see MDL-15758');
|
||||
// @todo see MDL-15758
|
||||
// @todo see MDL-15758
|
||||
} else {
|
||||
|
||||
if ($basedir = forum_file_area($this->post)) {
|
||||
//@todo penny fix all this with files api
|
||||
require_once($CFG->dirroot . '/backup/lib.php');
|
||||
|
|
|
@ -2415,7 +2415,7 @@ class glossary_csv_portfolio_caller extends portfolio_module_caller_base {
|
|||
return sha1(serialize($this->exportdata));
|
||||
}
|
||||
|
||||
public function prepare_package($tempdir) {
|
||||
public function prepare_package() {
|
||||
$entries = $this->exportdata['entries'];
|
||||
$aliases = array();
|
||||
$categories = array();
|
||||
|
@ -2436,11 +2436,7 @@ class glossary_csv_portfolio_caller extends portfolio_module_caller_base {
|
|||
}
|
||||
}
|
||||
$csv = glossary_generate_export_csv($entries, $aliases, $categories);
|
||||
// @todo - convert to files api.
|
||||
$status = ($handle = fopen($tempdir . '/' . clean_filename($this->cm->name) . '.csv', 'w'));
|
||||
$status = $status && fwrite($handle, $csv);
|
||||
$status = $status && fclose($handle);
|
||||
return $status;
|
||||
return $this->exporter->write_new_file($csv, clean_filename($this->cm->name) . '.csv');
|
||||
}
|
||||
|
||||
public function check_permissions() {
|
||||
|
@ -2493,17 +2489,14 @@ class glossary_entry_portfolio_caller extends portfolio_module_caller_base {
|
|||
return get_string('modname', 'glossary');
|
||||
}
|
||||
|
||||
public function prepare_package($tempdir) {
|
||||
$this->entry->approved = true; // in case we don't have $USER which this function checks
|
||||
public function prepare_package() {
|
||||
// in case we don't have USER this will make the entry be printed
|
||||
$this->entry->approved = true;
|
||||
define('PORTFOLIO_INTERNAL', true);
|
||||
ob_start();
|
||||
glossary_print_entry($this->get('course'), $this->cm, $this->glossary, $this->entry, null, null, false);
|
||||
$content = ob_get_clean();
|
||||
// @todo - convert to files api.
|
||||
$status = ($handle = fopen($tempdir . '/' . clean_filename($this->entry->concept) . '.html', 'w'));
|
||||
$status = $status && fwrite($handle, $content);
|
||||
$status = $status && fclose($handle);
|
||||
return $status;
|
||||
return $this->exporter->write_new_file($content, clean_filename($this->entry->concept) . '.html');
|
||||
}
|
||||
|
||||
public function get_sha1() {
|
||||
|
|
|
@ -249,20 +249,17 @@ class resource_base {
|
|||
//override to add your own options
|
||||
}
|
||||
|
||||
function portfolio_prepare_package_uploaded($tempdir) {
|
||||
function portfolio_prepare_package_uploaded($exporter) {
|
||||
// @todo penny implement later - see MDL-15758
|
||||
|
||||
}
|
||||
|
||||
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');
|
||||
function portfolio_prepare_package_online($exporter, $text=false) {
|
||||
$filename = clean_filename($this->cm->name . '.' . (($text) ? 'txt' : 'html'));
|
||||
$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);
|
||||
$status = $status && fclose($handle);
|
||||
return $status;
|
||||
return $exporter->write_new_file($content, $filename);
|
||||
}
|
||||
|
||||
function portfolio_get_sha1_online($text=false) {
|
||||
|
@ -741,8 +738,8 @@ class resource_portfolio_caller extends portfolio_module_caller_base {
|
|||
return PORTFOLIO_TIME_LOW;
|
||||
}
|
||||
|
||||
public function prepare_package($tempdir) {
|
||||
return $this->resource->portfolio_prepare_package($tempdir);
|
||||
public function prepare_package() {
|
||||
return $this->resource->portfolio_prepare_package($this->exporter);
|
||||
}
|
||||
|
||||
public function check_permissions() {
|
||||
|
|
|
@ -193,8 +193,8 @@ function setup_elements(&$mform) {
|
|||
}
|
||||
}
|
||||
|
||||
function portfolio_prepare_package($tempdir) {
|
||||
return parent::portfolio_prepare_package_online($tempdir);
|
||||
function portfolio_prepare_package($exporter) {
|
||||
return parent::portfolio_prepare_package_online($exporter);
|
||||
}
|
||||
|
||||
function portfolio_get_sha1() {
|
||||
|
|
|
@ -199,8 +199,8 @@ function setup_elements(&$mform) {
|
|||
}
|
||||
|
||||
|
||||
function portfolio_prepare_package($tempdir) {
|
||||
return parent::portfolio_prepare_package_online($tempdir, true);
|
||||
function portfolio_prepare_package($exporter) {
|
||||
return parent::portfolio_prepare_package_online($exporter, true);
|
||||
}
|
||||
|
||||
function portfolio_get_sha1() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue