"MDL-15351, move 'move_to_draft' function to parent class"

This commit is contained in:
Dongsheng Cai 2010-04-28 05:00:55 +00:00
parent cfe3ba15bb
commit 7f288e5002
3 changed files with 39 additions and 39 deletions

View File

@ -794,6 +794,42 @@ abstract class repository {
require_once($typedirectory);
return call_user_func_array(array('repository_' . $plugin, $function), $args);
}
/**
* Move a file to draft area
*
* @global object $USER
* @global object $DB
* @param string $encoded The metainfo of file, it is base64 encoded php seriablized data
* @param string $title The intended name of file
* @param string $itemid itemid
* @param string $save_path the new path in draft area
* @return array The information of file
*/
public static function move_to_draft($encoded, $title = '', $itemid = '', $save_path = '/') {
global $USER, $DB;
$ret = array();
$browser = get_file_browser();
$params = unserialize(base64_decode($encoded));
$user_context = get_context_instance(CONTEXT_USER, $USER->id);
// the final file
$contextid = $params['contextid'];
$filearea = $params['filearea'];
$filepath = $params['filepath'];
$filename = $params['filename'];
$fileitemid = $params['itemid'];
$context = get_context_instance_by_id($contextid);
$file_info = $browser->get_file_info($context, $filearea, $fileitemid, $filepath, $filename);
$file_info->copy_to_storage($user_context->id, 'user_draft', $itemid, $save_path, $title);
$ret['itemid'] = $itemid;
$ret['title'] = $title;
$ret['contextid'] = $user_context->id;
$ret['filesize'] = $file_info->get_filesize();
return $ret;
}
/**
* Move file from download folder to file pool using FILE API

View File

@ -121,7 +121,7 @@ class repository_local extends repository {
'size' => 0,
'date' => '',
'source'=> $params,
'thumbnail' => $OUTPUT->pix_url($icon),
'thumbnail' => $OUTPUT->pix_url($icon) . '',
);
$list[] = $node;
}
@ -134,42 +134,6 @@ class repository_local extends repository {
return $ret;
}
/**
* Move a file to draft area
*
* @global object $USER
* @global object $DB
* @param string $encoded The metainfo of file, it is base64 encoded php seriablized data
* @param string $title The intended name of file
* @param string $itemid itemid
* @param string $save_path the new path in draft area
* @return array The information of file
*/
public function move_to_draft($encoded, $title = '', $itemid = '', $save_path = '/') {
global $USER, $DB;
$ret = array();
$browser = get_file_browser();
$params = unserialize(base64_decode($encoded));
$user_context = get_context_instance(CONTEXT_USER, $USER->id);
// the final file
$contextid = $params['contextid'];
$filearea = $params['filearea'];
$filepath = $params['filepath'];
$filename = $params['filename'];
$fileitemid = $params['itemid'];
$context = get_context_instance_by_id($contextid);
$file_info = $browser->get_file_info($context, $filearea, $fileitemid, $filepath, $filename);
$file_info->copy_to_storage($user_context->id, 'user_draft', $itemid, $save_path, $title);
$ret['itemid'] = $itemid;
$ret['title'] = $title;
$ret['contextid'] = $user_context->id;
$ret['filesize'] = $file_info->get_filesize();
return $ret;
}
/**
* Set repository name
*

View File

@ -218,8 +218,8 @@ switch ($action) {
case 'download':
try {
// we have two special repoisitory type need to deal with
if ($repo->options['type'] == 'local') {
$fileinfo = $repo->move_to_draft($source, $saveas_filename, $itemid, $saveas_path);
if ($repo->options['type'] == 'local' || $repo->options['type'] == 'recent' ) {
$fileinfo = repository::move_to_draft($source, $saveas_filename, $itemid, $saveas_path);
$info = array();
$info['client_id'] = $client_id;
$info['file'] = $fileinfo['title'];