cvs: pear /HTML_Progress2/examples/observer observer2.php

From: Date: Mon, 01 Aug 2005 10:06:00 +0000
Subject: cvs: pear /HTML_Progress2/examples/observer observer2.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-33501@lists.php.net to get a copy of this message
farell Mon Aug 1 06:06:00 2005 EDT Modified files: /pear/HTML_Progress2/examples/observer observer2.php Log: updates to use the new event dispatch interface http://cvs.php.net/diff.php/pear/HTML_Progress2/examples/observer/observer2.php?r1=1.2&r2=1.3&ty=u Index: pear/HTML_Progress2/examples/observer/observer2.php diff -u pear/HTML_Progress2/examples/observer/observer2.php:1.2 pear/HTML_Progress2/examples/observer/observer2.php:1.3 --- pear/HTML_Progress2/examples/observer/observer2.php:1.2 Tue Jul 26 12:41:23 2005 +++ pear/HTML_Progress2/examples/observer/observer2.php Mon Aug 1 06:05:56 2005 @@ -1,9 +1,9 @@ <?php /** * Complex observer pattern for progress meter. - * Uses a custom observer callback that handled progress of the second bar. + * Uses a custom observer to log second progress bar process. * - * @version $Id: observer2.php,v 1.2 2005/07/26 16:41:23 farell Exp $ + * @version $Id: observer2.php,v 1.3 2005/08/01 10:05:56 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress2 * @subpackage Examples @@ -11,21 +11,29 @@ */ require_once 'HTML/Progress2.php'; +function getmicrotime($time) +{ + list($usec, $sec) = explode(' ', $time); + return ((float)$usec + (float)$sec); + +} + // 1. Defines custom observer pattern -function bar1Observer(&$notification) +function myProgressObserver(&$notification) { - global $pb2; + static $fileCount = 0; $notifyName = $notification->getNotificationName(); $notifyInfo = $notification->getNotificationInfo(); - if (strcasecmp($notifyName, 'movestep') == 0) { - if ($notifyInfo['value'] == 0) { - // updates $pb2 because $pb1 has completed a full loop - $pb2->moveNext(); - } else { - // if you want to do special on each step of progress bar1; - // it's here !!! + if (strcasecmp($notifyName, 'onChange') == 0) { + if (strcasecmp($notifyInfo['handler'], 'moveNext') == 0) { + if ($notifyInfo['value'] < 100) { + $fileCount++; + $timestamp = getmicrotime($notifyInfo['time']); + $msg = sprintf('file #%s was proceed on %s', $fileCount, date('r', $timestamp)); + error_log ($msg . PHP_EOL, 3, 'observer2.log'); + } } } } @@ -49,7 +57,7 @@ $pb2->setProgressAttributes('position=absolute top=5 left=250'); // 3. Attach an observer -$pb1->addListener('bar1Observer'); +$pb2->addListener('myProgressObserver'); // 4. Changes look-and-feel of progress bars $pb1->setProgressAttributes('background-color=#E0E0E0'); @@ -57,24 +65,24 @@ 'top' => 85, 'left' => -50, 'color' => 'red' - )); +)); $pb2->setBorderPainted(true); $pb2->setBorderAttributes(array( 'width' => 1, 'color' => 'navy' - )); +)); $pb2->setCellAttributes(array( 'active-color' => '#3874B4', 'inactive-color' => '#EEEECC' - )); +)); $pb2->setLabelAttributes('pct1', array( 'top' => 85, 'left' => 15, 'width' => 100, 'align' => 'center', 'color' => 'yellow' - )); +)); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> @@ -117,6 +125,8 @@ if ($pb1->getPercentComplete() == 1) { // the 1st progress bar has reached 100%, do a new loop $pb1->moveStep(0); + // updates $pb2 because $pb1 has completed a full loop + $pb2->moveNext(); } else { $pb1->moveNext(); // updates 1st progress bar }

« previous php.pear.cvs (#33501) next »