|
@@ -132,4 +132,23 @@ class Profile implements TenancyIdTraitInterface
|
|
|
return $this->download;
|
|
|
}
|
|
|
|
|
|
+ function units($value, $prefered=false, $mode = 'short', $decimals = 2, $prefix_grows=1000){
|
|
|
+ $units = array('long' => array('', 'kilo', 'mega','giga', 'tera', 'peta',' exa','zetta', 'yotta'),
|
|
|
+ 'short' => array('', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y',)
|
|
|
+ );
|
|
|
+ $unit = '';
|
|
|
+ for($i = 0; $i < count($units[$mode]); $i++) {
|
|
|
+ $unit = $units[$mode][$i];
|
|
|
+ if($unit === $prefered) break;
|
|
|
+ if($value > $prefix_grows) {
|
|
|
+ $value /= $prefix_grows;
|
|
|
+ } else {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return round($value, $decimals) . $unit;
|
|
|
+ }
|
|
|
+
|
|
|
+ function getDownloadAsK(){return $this->units($this->getDownload(), "k"); }
|
|
|
+ function getUploadAsK() {return $this->units($this->getUpload() , "k"); }
|
|
|
}
|