Browse Source

upload/download As K para Radius

Luciano Andrade 7 years ago
parent
commit
4f19e5ca3e
1 changed files with 19 additions and 0 deletions
  1. 19 0
      src/FTTHBundle/Entity/Profile.php

+ 19 - 0
src/FTTHBundle/Entity/Profile.php

@@ -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"); }
 }