Browse Source

Move code to Document manager + rename function name.

"get_total_folder_size" to "getTotalFolderSize"
jmontoyaa 7 years ago
parent
commit
43e9bbb4ce
3 changed files with 52 additions and 51 deletions
  1. 1 1
      main/inc/ajax/document.ajax.php
  2. 51 0
      main/inc/lib/document.lib.php
  3. 0 50
      main/inc/lib/fileDisplay.lib.php

+ 1 - 1
main/inc/ajax/document.ajax.php

@@ -12,7 +12,7 @@ switch ($action) {
         api_protect_course_script(true);
         $path = isset($_GET['path']) ? $_GET['path'] : '';
         $isAllowedToEdit = api_is_allowed_to_edit();
-        $size = get_total_folder_size($path, $isAllowedToEdit);
+        $size = DocumentManager::getTotalFolderSize($path, $isAllowedToEdit);
         echo format_file_size($size);
         break;
     case 'get_document_quota':

+ 51 - 0
main/inc/lib/document.lib.php

@@ -6694,4 +6694,55 @@ class DocumentManager
 
         return $result;
     }
+
+    /**
+     * Calculates the total size of a directory by adding the sizes (that
+     * are stored in the database) of all files & folders in this directory.
+     *
+     * @param    string $path
+     * @param    boolean $can_see_invisible
+     * @return    int Total size
+     */
+    public function getTotalFolderSize($path, $can_see_invisible = false)
+    {
+        $table_itemproperty = Database::get_course_table(TABLE_ITEM_PROPERTY);
+        $table_document = Database::get_course_table(TABLE_DOCUMENT);
+        $tool_document = TOOL_DOCUMENT;
+
+        $course_id = api_get_course_int_id();
+        $session_id = api_get_session_id();
+        $session_condition = api_get_session_condition(
+            $session_id,
+            true,
+            true,
+            'props.session_id'
+        );
+
+        $path = Database::escape_string($path);
+        $visibility_rule = ' props.visibility '.($can_see_invisible ? '<> 2' : '= 1');
+
+        $sql = "SELECT SUM(table1.size) FROM (
+                SELECT props.ref, size
+                FROM $table_itemproperty AS props 
+                INNER JOIN $table_document AS docs
+                ON (docs.id = props.ref AND docs.c_id = props.c_id)
+                WHERE
+                    docs.c_id = $course_id AND                    
+                    docs.path LIKE '$path/%' AND
+                    props.c_id = $course_id AND
+                    props.tool = '$tool_document' AND
+                    $visibility_rule
+                    $session_condition
+                GROUP BY ref
+            ) as table1";
+
+        $result = Database::query($sql);
+        if ($result && Database::num_rows($result) != 0) {
+            $row = Database::fetch_row($result);
+
+            return $row[0] == null ? 0 : $row[0];
+        } else {
+            return 0;
+        }
+    }
 }

+ 0 - 50
main/inc/lib/fileDisplay.lib.php

@@ -260,53 +260,3 @@ function folder_size($dir_name)
     return $size;
 }
 
-/**
- * Calculates the total size of a directory by adding the sizes (that
- * are stored in the database) of all files & folders in this directory.
- *
- * @param    string $path
- * @param    boolean $can_see_invisible
- * @return    int Total size
- */
-function get_total_folder_size($path, $can_see_invisible = false)
-{
-    $table_itemproperty = Database::get_course_table(TABLE_ITEM_PROPERTY);
-    $table_document = Database::get_course_table(TABLE_DOCUMENT);
-    $tool_document = TOOL_DOCUMENT;
-
-    $course_id = api_get_course_int_id();
-    $session_id = api_get_session_id();
-    $session_condition = api_get_session_condition(
-        $session_id,
-        true,
-        true,
-        'props.session_id'
-    );
-
-    $path = Database::escape_string($path);
-    $visibility_rule = ' props.visibility '.($can_see_invisible ? '<> 2' : '= 1');
-
-    $sql = "SELECT SUM(table1.size) FROM (
-                SELECT props.ref, size
-                FROM $table_itemproperty AS props 
-                INNER JOIN $table_document AS docs
-                ON (docs.id = props.ref AND docs.c_id = props.c_id)
-                WHERE
-                    docs.c_id = $course_id AND                    
-                    docs.path LIKE '$path/%' AND
-                    props.c_id = $course_id AND
-                    props.tool = '$tool_document' AND
-                    $visibility_rule
-                    $session_condition
-                GROUP BY ref
-            ) as table1";
-
-    $result = Database::query($sql);
-    if ($result && Database::num_rows($result) != 0) {
-        $row = Database::fetch_row($result);
-
-        return $row[0] == null ? 0 : $row[0];
-    } else {
-        return 0;
-    }
-}