Logger Monitor

Overview

This example will run a default Progress2 Monitor, which used a default QuickForm renderer without any form template customization.
Each quarter percent reached, elapse time is printed.

Screenshot

sample screenshot

Demonstration

Give it a try

Dependencies

This example requires mandatory resources :

And also but optional :

Explains step by step

The form windows (ProgressMonitor) have default title (In progress ...), buttons name (Start, Cancel) and size : see class constructor parameters (line 50).

There are 10 cells 15x20:

Property Value Default
active-color   #006600
inactive-color   #CCCCCC
width   15
height   20
spacing   2
See also :

With basic percent text info aligned on right side:

Property Value Default
left   5
top   5
width   50
height   0
align   right
valign   right
background-color   
font-size  11
font-family  Verdana, Tahoma, Arial
font-weight  normal
color  #000000
class  progressPercentLabel%s
See also :

Source Code

  1. <?php
  2. /**
  3. * Progress2 Monitor with default QF renderer
  4. * and a user listener for logging events.
  5. *
  6. * @version    $Id: monitorlog.php,v 1.3 2005/08/01 08:20:36 farell Exp $
  7. * @author     Laurent Laville <pear@laurent-laville.org>
  8. * @package    HTML_Progress2
  9. * @subpackage Examples
  10. * @access     public
  11. */
  12. require_once 'HTML/Progress2/Monitor.php';
  13.  
  14. function getmicrotime($time)
  15. {
  16.     list($usec, $sec) = explode(' ', $time);
  17.     return ((float)$usec + (float)$sec);
  18.  
  19. }
  20.  
  21. function logger(&$notification)
  22. {
  23.     static $time_start;
  24.     global $pm;
  25.  
  26.     $notifyName = $notification->getNotificationName();
  27.     $notifyInfo = $notification->getNotificationInfo();
  28.  
  29.     if ($notifyName == 'onSubmit') {
  30.         $time_start = getmicrotime($notifyInfo['time']);
  31.  
  32.     } elseif ($notifyName == 'onLoad') {
  33.         $elapse = getmicrotime($notifyInfo['time']) - $time_start;
  34.         printf('script runtime: %f seconds.', $elapse);
  35.  
  36.     } elseif ($notifyName == 'onChange') {
  37.  
  38.         if (fmod($notifyInfo['value'], 25) == 0) {
  39.             $time = getmicrotime($notifyInfo['time']);
  40.  
  41.             $elapse = $time - $time_start;
  42.             $pm->setCaption('%value%% has been reached on %time% sec.',
  43.                 array('value' => $notifyInfo['value'], 'time' => sprintf('%01.3f',$elapse))
  44.             );
  45.         }
  46.     }
  47. }
  48.  
  49.  
  50. $pm = new HTML_Progress2_Monitor();
  51.  
  52. $pb =& $pm->getProgressElement();
  53. $pb->setAnimSpeed(100);
  54. $pb->addListener('logger');
  55. ?>
  56. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  57.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  58. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  59. <head>
  60. <title>Logger Progress2 Monitor </title>
  61. <?php
  62. echo $pm->getStyle(false);
  63. echo $pm->getScript(false);
  64. ?>
  65. </head>
  66. <body>
  67.  
  68. <?php
  69. $pm->display();
  70. $pm->run();
  71. ?>
  72.  
  73. </body>
  74. </html>