Examples TOCexamples

Logs ProgressBar Monitor

$Date: 2005/07/25 12:15:50 $

 Table of contents

Introduction

This example requires :

Be aware that:


This example will logs a default ProgressBar Monitor, and used a default QuickForm renderer without any form template customizations.

User callback 'logger' (defined on lines 13 to 24) which write into a file through PEAR::Log was attached on progress bar at line 27.

Here are the contents of that PEAR::Log file :

[Top]

 Render options

None. All default values are used.

[Top]

 Output

Screenshot

[Top]

 PHP source syntax highlight

  1. <?php
  2. /**
  3.  * Default Monitor ProgressBar example with logging events.
  4.  *
  5.  * @version    $Id: default2.php,v 1.2 2005/07/25 12:17:39 farell Exp $
  6.  * @author     Laurent Laville <pear@laurent-laville.org>
  7.  * @package    HTML_Progress
  8.  * @subpackage Examples
  9.  */
  10.  
  11. require_once 'HTML/Progress/monitor.php';
  12.  
  13. function logger($progressValue, &$bar)
  14. {
  15.     include_once 'Log.php';
  16.     $logger = &Log::singleton('file', 'monitor.log', $_SERVER['REMOTE_ADDR']);
  17.     $percent = $bar->getPercentComplete(false);
  18.  
  19.     if (fmod($progressValue,25) == 0) {
  20.         $logger->info("$percent% has been reached");
  21.     } else {
  22.         $logger->debug("Progress ... $progressValue");
  23.     }
  24. }
  25.  
  26. $monitor = new HTML_Progress_Monitor();
  27. $monitor->setProgressHandler('logger');
  28.  
  29. $pb = &$monitor->getProgressElement();
  30. $dm = &$pb->getDM();
  31. $dm->setMaximum(300);
  32. ?>
  33. <html>
  34. <head>
  35. <title>ProgressBar Monitor - Default renderer </title>
  36. <style type="text/css">
  37. <!--
  38. .progressStatus {
  39.     color:#000000;
  40.     font-size:10px;
  41. }
  42. <?php echo $monitor->getStyle(); ?>
  43. // -->
  44. </style>
  45. <script type="text/javascript">
  46. <!--
  47. <?php echo $monitor->getScript(); ?>
  48. //-->
  49. </script>
  50. </head>
  51. <body>
  52.  
  53. <?php
  54. echo $monitor->toHtml();
  55. $monitor->run();
  56. ?>
  57.  
  58. </body>
  59. </html>

[Top]