Select an appropriate file size prefix instead of using MB for everything.
This commit is contained in:
parent
a58a1d348a
commit
6178d6b443
@ -23,11 +23,11 @@ class quotas_theme_Core {
|
|||||||
if (!identity::active_user()->guest) {
|
if (!identity::active_user()->guest) {
|
||||||
$record = ORM::factory("users_space_usage")->where("owner_id", "=", identity::active_user()->id)->find();
|
$record = ORM::factory("users_space_usage")->where("owner_id", "=", identity::active_user()->id)->find();
|
||||||
if ($record->get_usage_limit() == 0) {
|
if ($record->get_usage_limit() == 0) {
|
||||||
print t("You are using %usage MB", array("usage" => number_format($record->total_usage_mb(), 2)));
|
print t("You are using %usage", array("usage" => $record->total_usage_string()));
|
||||||
} else {
|
} else {
|
||||||
print t("You are using %usage of your %limit MB limit (%percentage%)",
|
print t("You are using %usage of your %limit limit (%percentage%)",
|
||||||
array("usage" => number_format($record->current_usage_mb(), 2),
|
array("usage" => $record->current_usage_string(),
|
||||||
"limit" => number_format($record->get_usage_limit_mb(), 2),
|
"limit" => $record->get_usage_limit_string(),
|
||||||
"percentage" => number_format((($record->current_usage() / $record->get_usage_limit()) * 100), 2)));
|
"percentage" => number_format((($record->current_usage() / $record->get_usage_limit()) * 100), 2)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,22 @@
|
|||||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
class Users_Space_Usage_Model_Core extends ORM {
|
class Users_Space_Usage_Model_Core extends ORM {
|
||||||
public function partial_usage_mb($file_type) {
|
static function _format_usage($bytes) {
|
||||||
// Return a value (in megabytes) for the user's total usage in fullsizes, resizes, or thumbs.
|
$usage_unit = array("B","kB","MB","GB","TB","PB","EB","ZB","YB");
|
||||||
|
$unit_counter = 0;
|
||||||
|
while ($bytes >= 1024) {
|
||||||
|
$bytes = $bytes / 1024;
|
||||||
|
$unit_counter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (number_format($bytes, 2) . " " . $usage_unit[$unit_counter]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function partial_usage_string($file_type) {
|
||||||
|
// Return a string for the user's total usage in fullsizes, resizes, or thumbs
|
||||||
|
// with the appropriate file size prefix.
|
||||||
// $file_type should be either fullsize, resize, or thumb.
|
// $file_type should be either fullsize, resize, or thumb.
|
||||||
return ($this->$file_type / 1024 / 1024);
|
return (Users_Space_Usage_Model_Core::_format_usage($this->$file_type));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function total_usage() {
|
public function total_usage() {
|
||||||
@ -29,9 +41,9 @@ class Users_Space_Usage_Model_Core extends ORM {
|
|||||||
return ($this->fullsize + $this->resize + $this->thumb);
|
return ($this->fullsize + $this->resize + $this->thumb);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function total_usage_mb() {
|
public function total_usage_string() {
|
||||||
// Return the user's total usage in megabytes.
|
// Return the user's total usage as a string with the appropriate file size prefix.
|
||||||
return (($this->total_usage()) / 1024 / 1024);
|
return (Users_Space_Usage_Model_Core::_format_usage($this->total_usage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function current_usage() {
|
public function current_usage() {
|
||||||
@ -43,9 +55,10 @@ class Users_Space_Usage_Model_Core extends ORM {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function current_usage_mb() {
|
public function current_usage_string() {
|
||||||
// Return the users relevant usage in megabytes based on the use_all_sizes setting.
|
// Return the users relevant usage as a string with the appropriate file size prefix
|
||||||
return ($this->current_usage() / 1024 / 1024);
|
// based on the use_all_sizes setting.
|
||||||
|
return (Users_Space_Usage_Model_Core::_format_usage($this->current_usage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_usage_limit() {
|
public function get_usage_limit() {
|
||||||
@ -68,9 +81,15 @@ class Users_Space_Usage_Model_Core extends ORM {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_usage_limit_mb() {
|
public function get_usage_limit_string() {
|
||||||
// Returns a user's maximum limit in megabytes.
|
// Returns a user's maximum limit as a string with the appropriate file size prefix
|
||||||
return ($this->get_usage_limit() / 1024 / 1024);
|
// or an infinity symbol if the user has no limit.
|
||||||
|
$user_limit = $this->get_usage_limit();
|
||||||
|
if ($user_limit == 0) {
|
||||||
|
return "∞";
|
||||||
|
} else {
|
||||||
|
return (Users_Space_Usage_Model_Core::_format_usage($this->get_usage_limit()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add_item($item) {
|
public function add_item($item) {
|
||||||
|
@ -34,19 +34,19 @@
|
|||||||
<?= html::clean($user->full_name) ?>
|
<?= html::clean($user->full_name) ?>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<?= number_format($record->partial_usage_mb("fullsize"), 2); ?> MB
|
<?=$record->partial_usage_string("fullsize"); ?>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<?= number_format($record->partial_usage_mb("resize"), 2); ?> MB
|
<?=$record->partial_usage_string("resize"); ?>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<?= number_format($record->partial_usage_mb("thumb"), 2); ?> MB
|
<?=$record->partial_usage_string("thumb"); ?>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<?= number_format($record->total_usage_mb(), 2) ?> MB
|
<?=$record->total_usage_string(); ?>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<?= number_format($record->get_usage_limit_mb(), 2) ?> MB
|
<?=$record->get_usage_limit_string(); ?>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<? endforeach ?>
|
<? endforeach ?>
|
||||||
|
Reference in New Issue
Block a user