• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List

E:/E/GEAMP/www/openbiz/openbiz/others/Zend/ProgressBar.php

00001 <?php
00028 class Zend_ProgressBar
00029 {
00035     protected $_min;
00036 
00042     protected $_max;
00043 
00049     protected $_current;
00050 
00056     protected $_startTime;
00057 
00063     protected $_statusText = null;
00064 
00070     protected $_adapter;
00071 
00077     protected $_persistenceNamespace = null;
00078 
00088     public function __construct(Zend_ProgressBar_Adapter $adapter, $min = 0, $max = 100, $persistenceNamespace = null)
00089     {
00090         // Check min/max values and set them
00091         if ($min > $max) {
00092             require_once 'Zend/ProgressBar/Exception.php';
00093             throw new Zend_ProgressBar_Exception('$max must be greater than $min');
00094         }
00095 
00096         $this->_min     = (float) $min;
00097         $this->_max     = (float) $max;
00098         $this->_current = (float) $min;
00099 
00100         // See if we have to open a session namespace
00101         if ($persistenceNamespace !== null) {
00102             require_once 'Zend/Session/Namespace.php';
00103 
00104             $this->_persistenceNamespace = new Zend_Session_Namespace($persistenceNamespace);
00105         }
00106 
00107         // Set adapter
00108         $this->_adapter = $adapter;
00109 
00110         // Track the start time
00111         $this->_startTime = time();
00112 
00113         // See If a persistenceNamespace exists and handle accordingly
00114         if ($this->_persistenceNamespace !== null) {
00115             if (isset($this->_persistenceNamespace->isSet)) {
00116                 $this->_startTime  = $this->_persistenceNamespace->startTime;
00117                 $this->_current    = $this->_persistenceNamespace->current;
00118                 $this->_statusText = $this->_persistenceNamespace->statusText;
00119             } else {
00120                 $this->_persistenceNamespace->isSet      = true;
00121                 $this->_persistenceNamespace->startTime  = $this->_startTime;
00122                 $this->_persistenceNamespace->current    = $this->_current;
00123                 $this->_persistenceNamespace->statusText = $this->_statusText;
00124             }
00125         } else {
00126             $this->update();
00127         }
00128     }
00129 
00135     public function getAdapter()
00136     {
00137         return $this->_adapter;
00138     }
00139 
00147     public function update($value = null, $text = null)
00148     {
00149         // Update value if given
00150         if ($value !== null) {
00151             $this->_current = min($this->_max, max($this->_min, $value));
00152         }
00153 
00154         // Update text if given
00155         if ($text !== null) {
00156             $this->_statusText = $text;
00157         }
00158 
00159         // See if we have to update a namespace
00160         if ($this->_persistenceNamespace !== null) {
00161             $this->_persistenceNamespace->current    = $this->_current;
00162             $this->_persistenceNamespace->statusText = $this->_statusText;
00163         }
00164 
00165         // Calculate percent
00166         if ($this->_min === $this->_max) {
00167             $percent = false;
00168         } else {
00169             $percent = (float) ($this->_current - $this->_min) / ($this->_max - $this->_min);
00170         }
00171 
00172         // Calculate ETA
00173         $timeTaken = time() - $this->_startTime;
00174 
00175         if ($percent === .0 || $percent === false) {
00176             $timeRemaining = null;
00177         } else {
00178             $timeRemaining = round(((1 / $percent) * $timeTaken) - $timeTaken);
00179         }
00180 
00181         // Poll the adapter
00182         $this->_adapter->notify($this->_current, $this->_max, $percent, $timeTaken, $timeRemaining, $this->_statusText);
00183     }
00184 
00191     public function next($diff = 1, $text = null)
00192     {
00193         $this->update(max($this->_min, min($this->_max, $this->_current + $diff)), $text);
00194     }
00195 
00201     public function finish()
00202     {
00203         if ($this->_persistenceNamespace !== null) {
00204             unset($this->_persistenceNamespace->isSet);
00205         }
00206 
00207         $this->_adapter->finish();
00208     }
00209 }

Generated on Thu Apr 19 2012 17:01:18 for openbiz by  doxygen 1.7.2