]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-15833 - make the portfolio callers use the helper functions to detect expected...
authormjollnir_ <mjollnir_>
Tue, 9 Sep 2008 09:32:16 +0000 (09:32 +0000)
committermjollnir_ <mjollnir_>
Tue, 9 Sep 2008 09:32:16 +0000 (09:32 +0000)
mod/assignment/lib.php
mod/chat/lib.php
mod/data/lib.php
mod/forum/lib.php
mod/glossary/lib.php
mod/resource/lib.php

index 3b4597f21492ecce7511bb85486d3177ff129dbc..1c46a6ad80d0d2e61a95a9ade0958f41ef79d203 100644 (file)
@@ -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() {
index edc6269c9290ec533857b2e160eddcafed7719c9..80ca5768fbd1fc5e53035034b92719a3aef1d4cf 100644 (file)
@@ -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() {
index daeddcae9abf313dabe20d25e04697dd6cbaca29..1858fc248b13f42e46bf04aa38510005cd54616c 100755 (executable)
@@ -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() {
index 485ea4a8ae9fa9eff45cca6edb16707b88fb742a..4db7d2f6aa6ddf0c9bc05ed844122a36810c70b8 100644 (file)
@@ -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() {
index e005ecde6010b4860ab7b4151fb4c10bffd7d75d..f15ab9523792d382ef8216d9505cec19f580ba14 100644 (file)
@@ -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() {
index 5bde803928f8e72f767ab15fd85c52cde586b548..e12795179275e5e460a438a5f33066edc7dc771c 100644 (file)
@@ -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;
     }