[Pieforms-commit] SF.net SVN: pieforms:[320] pieforms-php5/trunk/src/pieform/elements/bytes. php
Status: Alpha
Brought to you by:
oracleshinoda
From: <ora...@us...> - 2009-11-10 03:32:02
|
Revision: 320 http://pieforms.svn.sourceforge.net/pieforms/?rev=320&view=rev Author: oracleshinoda Date: 2009-11-10 03:31:47 +0000 (Tue, 10 Nov 2009) Log Message: ----------- Make the bytes element support "gigabytes". I even had a go at doing the translations for all the languages. Also, fix a bug where specifying a value that was exactly 1GB ended up showing up as 1024MB. This happens at the other unit boundaries too. Signed-off-by: Nigel McNie <ni...@ca...> Modified Paths: -------------- pieforms-php5/trunk/src/pieform/elements/bytes.php Modified: pieforms-php5/trunk/src/pieform/elements/bytes.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/bytes.php 2009-11-10 03:29:47 UTC (rev 319) +++ pieforms-php5/trunk/src/pieform/elements/bytes.php 2009-11-10 03:31:47 UTC (rev 320) @@ -26,7 +26,7 @@ /** * Provides a size chooser, with a text box for a number and a - * select box to choose the units, in bytes, kilobytes, or megabytes + * select box to choose the units, in bytes, kilobytes, megabytes or gigabytes * * @param Pieform $form The form to render the element for * @param array $element The element to render @@ -108,6 +108,9 @@ function pieform_element_bytes_in($units) {/*{{{*/ switch ($units) { + case 'gigabytes': + return 1073741824; + break; case 'megabytes': return 1048576; break; @@ -126,48 +129,56 @@ 'bytes' => 'Bytes', 'kilobytes' => 'Kilobytes', 'megabytes' => 'Megabytes', + 'gigabytes' => 'Gigabytes', 'invalidvalue' => 'Value must be a number', ), 'de.utf8' => array( 'bytes' => 'Bytes', 'kilobytes' => 'Kilobytes', 'megabytes' => 'Megabytes', + 'gigabytes' => 'Gigabytes', 'invalidvalue' => 'Wert muss eine Zahl sein', ), 'fr.utf8' => array( 'bytes' => 'Octets', 'kilobytes' => 'Kilooctets', 'megabytes' => 'Mégaoctets', + 'gigabytes' => 'Gigaoctets', 'invalidvalue' => 'Valeur doit être un nombre', ), 'ja.utf8' => array( 'bytes' => 'B', 'kilobytes' => 'KB', 'megabytes' => 'MB', + 'gigabytes' => 'GB', 'invalidvalue' => '値は数値にしてください', ), 'es.utf8' => array( 'bytes' => 'Bytes', 'kilobytes' => 'Kilobytes', 'megabytes' => 'Megabytes', + 'gigabytes' => 'Gigabytes', 'invalidvalue' => 'El valor debe ser un número', ), 'sl.utf8' => array( 'bytes' => 'B', 'kilobytes' => 'kB', 'megabytes' => 'MB', + 'gigabytes' => 'GB', 'invalidvalue' => 'Vrednost mora biti število', ), 'nl.utf8' => array( 'bytes' => 'Bytes', 'kilobytes' => 'Kilobytes', 'megabytes' => 'Megabytes', + 'gigabytes' => 'Gigabytes', 'invalidvalue' => 'Waarde moet een getal zijn', ), 'cs.utf8' => array( 'bytes' => 'B', 'kilobytes' => 'kB', 'megabytes' => 'MB', + 'gigabytes' => 'GB', 'invalidvalue' => 'Hodnota musí být číselná', ), 'zh_tw.utf8' => array( @@ -181,7 +192,7 @@ }/*}}}*/ function pieform_element_bytes_get_bytes_units() {/*{{{*/ - return array('bytes', 'kilobytes', 'megabytes'); + return array('bytes', 'kilobytes', 'megabytes', 'gigabytes'); }/*}}}*/ function pieform_element_bytes_get_bytes_from_bytes($bytes) {/*{{{*/ @@ -189,8 +200,8 @@ return array('number' => '0', 'units' => 'bytes'); } - foreach (array('megabytes', 'kilobytes') as $units) { - if ( $bytes > pieform_element_bytes_in($units) ) { + foreach (array('gigabytes', 'megabytes', 'kilobytes') as $units) { + if ( $bytes >= pieform_element_bytes_in($units) ) { return array('number' => $bytes / pieform_element_bytes_in($units) , 'units' => $units); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |