Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
feat(filesize): change conversion for file sizes
Browse files Browse the repository at this point in the history
Signed-off-by: Domingo Oropeza <doropeza@teclib.com>
  • Loading branch information
DIOHz0r committed Mar 2, 2018
1 parent b5c5355 commit 02718ba
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 20 deletions.
18 changes: 0 additions & 18 deletions inc/common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,6 @@ class PluginFlyvemdmCommon
{
const SEMVER_VERSION_REGEX = '#\bv?(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[\da-z\-]+(?:\.[\da-z\-]+)*)?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?\b#i';


/**
* Convert int size to GiB
* @param float $size
* @return string format numeric
*/
public static function convertToGiB($size) {
$units = ['KiB', 'MiB', 'GiB', 'TiB'];
$unit = 'B';

while ($size > 1024 && count($units) > 0) {
$size = $size / 1024;
$unit = array_shift($units);
}
$size = Html::formatNumber($size, false, 2);
return "$size $unit";
}

/**
* Display massive actions
* @param array $massiveactionparams
Expand Down
2 changes: 1 addition & 1 deletion inc/file.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ public function showForm($ID, array $options = []) {
$fields['filesize'] = '';
} else {
$fields['filesize'] = fileSize(FLYVEMDM_FILE_PATH . '/' . $fields['source']);
$fields['filesize'] = PluginFlyvemdmCommon::convertToGiB($fields['filesize']);
$fields['filesize'] = Toolbox::getSize($fields['filesize']);
}
$data = [
'withTemplate' => (isset($options['withtemplate']) && $options['withtemplate'] ? "*" : ""),
Expand Down
2 changes: 1 addition & 1 deletion inc/package.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function showForm($ID, array $options = []) {
$this, 'name',
['value' => $objectName, 'display' => false]
);
$fields['filesize'] = PluginFlyvemdmCommon::convertToGiB($fields['filesize']);
$fields['filesize'] = Toolbox::getSize($fields['filesize']);
$data = [
'withTemplate' => (isset($options['withtemplate']) && $options['withtemplate'] ? '*' : ''),
'canUpdate' => (!$this->isNewID($ID)) && ($this->canUpdate() > 0) || $this->isNewID($ID),
Expand Down

0 comments on commit 02718ba

Please sign in to comment.