cvs: pear /HTML_Progress/Progress DM.php
| From: | Laurent Laville | Date: | Mon, 25 Jul 2005 13:08:33 +0000 |
| Subject: | cvs: pear /HTML_Progress/Progress DM.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-33310@lists.php.net to get a copy of this message | ||
farell Mon Jul 25 09:08:33 2005 EDT
Modified files:
/pear/HTML_Progress/Progress DM.php
Log:
- Updates headers comment block
- fixed round error when maximum is set higher than 100 (see related bug #4885)
http://cvs.php.net/diff.php/pear/HTML_Progress/Progress/DM.php?r1=1.6&r2=1.7&ty=u
Index: pear/HTML_Progress/Progress/DM.php
diff -u pear/HTML_Progress/Progress/DM.php:1.6 pear/HTML_Progress/Progress/DM.php:1.7
--- pear/HTML_Progress/Progress/DM.php:1.6 Mon Sep 6 11:12:48 2004
+++ pear/HTML_Progress/Progress/DM.php Mon Jul 25 09:08:32 2005
@@ -1,32 +1,46 @@
<?php
-// +----------------------------------------------------------------------+
-// | PEAR :: HTML :: Progress |
-// +----------------------------------------------------------------------+
-// | Copyright (c) 1997-2004 The PHP Group |
-// +----------------------------------------------------------------------+
-// | This source file is subject to version 3.0 of the PHP license, |
-// | that is bundled with this package in the file LICENSE, and is |
-// | available at through the world-wide-web at |
-// | http://www.php.net/license/3_0.txt.
|
-// | If you did not receive a copy of the PHP license and are unable to |
-// | obtain it through the world-wide-web, please send a note to |
-// | license@php.net so we can mail you a copy immediately. |
-// +----------------------------------------------------------------------+
-// | Author: Laurent Laville <pear@laurent-laville.org> |
-// +----------------------------------------------------------------------+
-//
-// $Id: DM.php,v 1.6 2004/09/06 15:12:48 farell Exp $
-
/**
* The HTML_Progress_DM class handles any mathematical issues
* arising from assigning faulty values.
*
- * @version 1.2.0
+ * PHP versions 4 and 5
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did
not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @category HTML
+ * @package HTML_Progress
+ * @subpackage Progress_DM
* @author Laurent Laville <pear@laurent-laville.org>
- * @access public
+ * @copyright 1997-2005 The PHP Group
+ * @license http://www.php.net/license/3_0.txt
PHP License 3.0
+ * @version CVS: $Id: DM.php,v 1.7 2005/07/25 13:08:32 farell Exp $
+ * @link http://pear.php.net/package/HTML_Progress
+ */
+
+/**
+ * The HTML_Progress_DM class handles any mathematical issues
+ * arising from assigning faulty values.
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did
not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @category HTML
* @package HTML_Progress
* @subpackage Progress_DM
+ * @author Laurent Laville <pear@laurent-laville.org>
+ * @copyright 1997-2005 The PHP Group
* @license http://www.php.net/license/3_0.txt
PHP License 3.0
+ * @version Release: @package_version@
+ * @link http://pear.php.net/package/HTML_Progress
*/
class HTML_Progress_DM
@@ -80,7 +94,7 @@
*
* Constructor Summary
*
- * o Creates a progress mathematical model with a minimum value set to 0,
+ * o Creates a progress mathematical model with a minimum value set to 0,
* a maximum value set to 100, and a increment value set to +1.
* By default, the value is initialized to be equal to the minimum value.
* <code>
@@ -118,7 +132,7 @@
$this->_increment = +1;
$args = func_get_args();
-
+
switch (count($args)) {
case 2:
/* int min, int max */
@@ -386,7 +400,7 @@
}
/**
- * Returns the progress bar's current value. The value is always between
+ * Returns the progress bar's current value. The value is always between
* the minimum and maximum values, inclusive.
* By default, the value is initialized with the minimum value.
*
@@ -459,24 +473,37 @@
/**
* Returns the percent complete for the progress bar. Note that this number is
- * between 0.00 and 1.00.
+ * between 0.00 and 1.00 or 0 and 100.
*
- * @return float
+ * @param boolean $float (optional) float or integer format
+ *
+ * @return mixed
* @since 1.0
* @access public
+ * @throws HTML_PROGRESS2_ERROR_INVALID_INPUT
* @see getValue(), getMaximum()
* @tutorial dm.getpercentcomplete.pkg
*/
- function getPercentComplete()
+ function getPercentComplete($float = true)
{
- $percent = sprintf("%01.2f",
- ( ($this->getValue() - $this->getMinimum()) / $this->getMaximum() )
- );
+ if (!is_bool($float)) {
+ return HTML_Progress::raiseError(HTML_PROGRESS2_ERROR_INVALID_INPUT,
'exception',
+ array('var' => '$float',
+ 'was' => gettype($float),
+ 'expected' => 'boolean',
+ 'paramnum' => 1));
+ }
+
+ $min = $this->_minimum;
+ $max = $this->_maximum;
+ $val = $this->_value;
+
+ $percent = round((($val - $min) / ($max - $min)), 4);
- if (function_exists('floatval')) {
- return floatval($percent); // use for PHP 4.2+
+ if ($float) {
+ return $percent;
} else {
- return (float)$percent; // use for PHP 4.1.x
+ return intval($percent * 100);
}
}
}