"MDL-23894, added user quota limit to filesedit form"
authorDongsheng Cai <unoter@gmail.com>
Tue, 24 Aug 2010 07:52:12 +0000 (07:52 +0000)
committerDongsheng Cai <unoter@gmail.com>
Tue, 24 Aug 2010 07:52:12 +0000 (07:52 +0000)
lib/filelib.php
user/filesedit_form.php

index 6d48fba..9b97e8c 100644 (file)
@@ -422,6 +422,10 @@ function file_get_draft_area_info($draftitemid) {
     // The number of files
     $draftfiles = $fs->get_area_files($usercontext->id, 'user', 'draft', $draftitemid, 'id', false);
     $results['filecount'] = count($draftfiles);
+    $results['filesize'] = 0;
+    foreach ($draftfiles as $file) {
+        $results['filesize'] += $file->get_filesize();
+    }
 
     return $results;
 }
index 4c5314b..4fd1e6f 100644 (file)
@@ -41,4 +41,16 @@ class user_filesedit_form extends moodleform {
 
         $this->set_data($data);
     }
+    function validation($data, $files) {
+        global $CFG;
+
+        $errors = array();
+        $draftitemid = $data['files_filemanager'];
+        $fileinfo = file_get_draft_area_info($draftitemid);
+        if ($fileinfo['filesize'] > $CFG->userquota) {
+            $errors['files_filemanager'] = get_string('userquotalimit', 'error');
+        }
+
+        return $errors;
+    }
 }