From: mjollnir_ Date: Tue, 9 Sep 2008 09:32:16 +0000 (+0000) Subject: MDL-15833 - make the portfolio callers use the helper functions to detect expected... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=d8606b20780b8ad12e553f3bcda88d8c0bd52349;p=moodle.git MDL-15833 - make the portfolio callers use the helper functions to detect expected time. --- diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index 3b4597f214..1c46a6ad80 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -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() { diff --git a/mod/chat/lib.php b/mod/chat/lib.php index edc6269c92..80ca5768fb 100644 --- a/mod/chat/lib.php +++ b/mod/chat/lib.php @@ -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() { diff --git a/mod/data/lib.php b/mod/data/lib.php index daeddcae9a..1858fc248b 100755 --- a/mod/data/lib.php +++ b/mod/data/lib.php @@ -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() { diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 485ea4a8ae..4db7d2f6aa 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -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() { diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index e005ecde60..f15ab95237 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -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() { diff --git a/mod/resource/lib.php b/mod/resource/lib.php index 5bde803928..e127951792 100644 --- a/mod/resource/lib.php +++ b/mod/resource/lib.php @@ -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; }