MDL-15833 - make the portfolio callers use the helper functions to detect expected time.
This commit is contained in:
+21
-18
@@ -3147,6 +3147,7 @@ class assignment_portfolio_caller extends portfolio_module_caller_base {
|
||||
private $assignmentfile;
|
||||
private $userid;
|
||||
private $file;
|
||||
private $files;
|
||||
|
||||
public function __construct($callbackargs) {
|
||||
global $DB, $CFG;
|
||||
@@ -3167,10 +3168,14 @@ class assignment_portfolio_caller extends portfolio_module_caller_base {
|
||||
throw new portfolio_caller_exception('notexportable', 'portfolio', $this->get_return_url());
|
||||
}
|
||||
if (array_key_exists('file', $callbackargs)) {
|
||||
$fs = get_file_storage();
|
||||
$this->file = $fs->get_file_by_id($callbackargs['file']);
|
||||
$this->files = array($this->file);
|
||||
$this->supportedformats = array(portfolio_format_from_file($this->file));
|
||||
} else if (is_callable(array($this->assignment, 'portfolio_supported_formats'))) {
|
||||
} else {
|
||||
$fs = get_file_storage();
|
||||
$this->files = $fs->get_area_files($this->assignment->context->id, 'assignment_submission', $this->user->id, '', false);
|
||||
}
|
||||
if (empty($this->supportedformats) && is_callable(array($this->assignment, 'portfolio_supported_formats'))) {
|
||||
$this->supportedformats = $this->assignment->portfolio_supported_formats();
|
||||
}
|
||||
}
|
||||
@@ -3180,14 +3185,10 @@ 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);
|
||||
}
|
||||
$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);
|
||||
}
|
||||
foreach ($this->files as $file) {
|
||||
$this->exporter->copy_existing_file($file);
|
||||
}
|
||||
return $status;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function get_sha1() {
|
||||
@@ -3200,21 +3201,23 @@ class assignment_portfolio_caller extends portfolio_module_caller_base {
|
||||
if ($this->file) {
|
||||
return $this->file->get_contenthash();
|
||||
}
|
||||
$fs = get_file_storage();
|
||||
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);
|
||||
$sha1s = array();
|
||||
foreach ($this->files as $file) {
|
||||
$sha1s[] = $file->get_contenthash();
|
||||
}
|
||||
asort($sha1s);
|
||||
return sha1(implode('', $sha1s));
|
||||
|
||||
}
|
||||
|
||||
public function expected_time() {
|
||||
return PORTFOLIO_TIME_MODERATE; // @TODO check uploaded file size
|
||||
if (is_callable(array($this->assignmnet, 'portfolio_get_expected_time'))) {
|
||||
return $this->assignment->portfolio_get_expected_time();
|
||||
}
|
||||
if (is_array($this->files)) {
|
||||
return portfolio_expected_time_file($this->files);
|
||||
}
|
||||
return PORTFOLIO_TIME_LOW;
|
||||
}
|
||||
|
||||
public function check_permissions() {
|
||||
|
||||
+1
-1
@@ -859,7 +859,7 @@ class chat_portfolio_caller extends portfolio_module_caller_base {
|
||||
}
|
||||
|
||||
public function expected_time() {
|
||||
return PORTFOLIO_TIME_LOW;
|
||||
return portfolio_expected_time_db(count($this->messages));
|
||||
}
|
||||
|
||||
public function get_sha1() {
|
||||
|
||||
+1
-2
@@ -2491,8 +2491,7 @@ class data_portfolio_caller extends portfolio_module_caller_base {
|
||||
if ($this->exporttype == 'single') {
|
||||
return PORTFOLIO_TIME_LOW;
|
||||
}
|
||||
//@todo penny check number of records maybe
|
||||
return PORTFOLIO_TIME_MODERATE;
|
||||
return portfolio_expected_time_db(count($this->exportdata));
|
||||
}
|
||||
|
||||
public function get_sha1() {
|
||||
|
||||
+16
-2
@@ -7231,6 +7231,7 @@ class forum_portfolio_caller extends portfolio_module_caller_base {
|
||||
private $attachment;
|
||||
private $postfiles;
|
||||
private $allfiles;
|
||||
private $posts;
|
||||
|
||||
function __construct($callbackargs) {
|
||||
global $DB;
|
||||
@@ -7425,8 +7426,21 @@ class forum_portfolio_caller extends portfolio_module_caller_base {
|
||||
}
|
||||
|
||||
function expected_time() {
|
||||
// @todo penny check for attachment size
|
||||
return PORTFOLIO_TIME_LOW;
|
||||
// default...
|
||||
$time = PORTFOLIO_TIME_LOW; // generally just means one post with no attachments
|
||||
if ($this->postfiles) {
|
||||
$time = portfolio_expected_time_file($this->postfiles);
|
||||
} else if ($this->allfiles) {
|
||||
// we have something two dimensional...
|
||||
$files = array();
|
||||
foreach ($this->allfiles as $post => $postfiles) {
|
||||
$files = array_merge($files, $postfiles);
|
||||
}
|
||||
$time = portfolio_expected_time_file($files);
|
||||
} else if ($this->posts) {
|
||||
$time = portfolio_expected_time_db(count($this->posts));
|
||||
}
|
||||
return $time;
|
||||
}
|
||||
|
||||
function check_permissions() {
|
||||
|
||||
@@ -2423,8 +2423,7 @@ class glossary_csv_portfolio_caller extends portfolio_module_caller_base {
|
||||
}
|
||||
|
||||
public function expected_time() {
|
||||
//@todo penny check number of records maybe
|
||||
return PORTFOLIO_TIME_MODERATE;
|
||||
return portfolio_expected_time_db(count($this->exportdata['entries']));
|
||||
}
|
||||
|
||||
public function get_sha1() {
|
||||
|
||||
@@ -745,6 +745,7 @@ class resource_portfolio_caller extends portfolio_module_caller_base {
|
||||
|
||||
public function expected_time() {
|
||||
// @todo penny check filesize if the type is uploadey (not implemented yet)
|
||||
// like this: return portfolio_expected_time_file($this->file); // or whatever
|
||||
return PORTFOLIO_TIME_LOW;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user