Merge branch '3882' into 1.11.x

pull/3944/head
Yannick Warnier 4 years ago
commit 763096b1df
  1. 26
      main/document/document.php
  2. 16
      main/inc/ajax/document.ajax.php
  3. 24
      main/inc/lib/document.lib.php

@ -1894,7 +1894,7 @@ $userIsSubscribed = CourseManager::is_user_subscribed_in_course(
$courseInfo['code']
);
$getSizeURL = api_get_path(WEB_AJAX_PATH).'document.ajax.php?a=get_dir_size&'.api_get_cidreq();
$getSizesURL = api_get_path(WEB_AJAX_PATH).'document.ajax.php?a=get_dirs_size&'.api_get_cidreq();
if (!empty($documentAndFolders)) {
if ($groupId == 0 || $userAccess) {
@ -2005,7 +2005,7 @@ if (!empty($documentAndFolders)) {
if ($document_data['filetype'] === 'folder') {
$displaySize = '<span id="document_size_'.$document_data['id']
.'" data-path= "'.$document_data['path']
.'" data-id= "'.$document_data['id']
.'" class="document_size"></span>';
} else {
$displaySize = format_file_size($document_data['size']);
@ -2273,17 +2273,23 @@ if (false === $disableQuotaMessage && count($documentAndFolders) > 1) {
echo '<script>
$(function() {
var requests = [];
$(".document_size").each(function(i, obj) {
var path = obj.getAttribute("data-path");
$.ajax({
url:"'.$getSizeURL.'&path="+path,
success:function(data){
$(obj).html(data);
}
});
requests.push(obj.getAttribute("data-id"));
});
getPathsSizes(requests)
});
function getPathsSizes(requests){
$.ajax({
url:"'.$getSizesURL.'&requests="+requests,
success:function(data){
var response = JSON.parse(data)
response.forEach(function(data) {
$("#document_size_"+data.id).html(data.size);
});
}
});
}
</script>';
echo '<span id="course_quota"></span>';
}

@ -15,6 +15,22 @@ switch ($action) {
$size = DocumentManager::getTotalFolderSize($path, $isAllowedToEdit);
echo format_file_size($size);
break;
case 'get_dirs_size':
api_protect_course_script(true);
$requests = isset($_GET['requests']) ? $_GET['requests'] : '';
$isAllowedToEdit = api_is_allowed_to_edit();
$response = [];
$requests = explode(',', $requests);
foreach ($requests as $request) {
$fileSize = DocumentManager::getTotalFolderSize($request, $isAllowedToEdit);
$data = [
'id' => $request,
'size' => format_file_size($fileSize),
];
array_push($response, $data);
}
echo json_encode($response);
break;
case 'get_document_quota':
// Getting the course quota
$courseQuota = DocumentManager::get_course_quota();

@ -6485,12 +6485,13 @@ class DocumentManager
* 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 bool $can_see_invisible
* @param string $value Document path or document id
* @param bool $canSeeInvisible
* @param bool $byId Default true, if is getting size by document id or false if getting by path
*
* @return int Total size
*/
public static function getTotalFolderSize($path, $can_see_invisible = false)
public static function getTotalFolderSize($value, $canSeeInvisible = false, $byId = true)
{
$table_itemproperty = Database::get_course_table(TABLE_ITEM_PROPERTY);
$table_document = Database::get_course_table(TABLE_DOCUMENT);
@ -6509,8 +6510,21 @@ class DocumentManager
return 0;
}
$path = Database::escape_string($path);
$visibility_rule = ' props.visibility '.($can_see_invisible ? '<> 2' : '= 1');
$visibility_rule = ' props.visibility '.($canSeeInvisible ? '<> 2' : '= 1');
if ($byId) {
$id = (int) $value;
$query = "SELECT path FROM $table_document WHERE id = $id";
$result1 = Database::query($query);
if ($result1 && Database::num_rows($result1) != 0) {
$row = Database::fetch_row($result1);
$path = $row[0];
} else {
return 0;
}
} else {
$path = Database::escape_string($value);
}
$sql = "SELECT SUM(table1.size) FROM (
SELECT props.ref, size

Loading…
Cancel
Save