feat: add account limit for document upload (#2013)

This commit is contained in:
Régis Freyd
2018-11-10 21:57:23 -05:00
committed by GitHub
parent 03a3543e53
commit 364bcc0c43
17 changed files with 200 additions and 21 deletions
@@ -0,0 +1,39 @@
<?php
namespace App\Http\Controllers\Settings;
use App\Models\Contact\Document;
use App\Http\Controllers\Controller;
class StorageController extends Controller
{
/**
* Get all the information about the account in terms of storage.
*/
public function index()
{
$documents = Document::with(['contact' => function ($query) {
$query->where('account_id', auth()->user()->account->id);
}])->orderBy('created_at', 'desc')->get();
// count total account size
// size is in bytes in the database
$currentAccountSize = 0;
foreach ($documents as $document) {
$currentAccountSize += $document->filesize;
}
if ($currentAccountSize != 0) {
$currentAccountSize = round($currentAccountSize / 1000000);
}
// correspondingPercent
$percentUsage = round($currentAccountSize * 100 / config('monica.max_storage_size'));
return view('settings.storage.index')
->withDocuments($documents)
->withCurrentAccountSize($currentAccountSize)
->withAccountLimit(config('monica.max_storage_size'))
->withPercentUsage($percentUsage);
}
}