HTML_Progress
[ class tree: HTML_Progress ] [ index: HTML_Progress ] [ all elements ]

Source for file observer_simple.php

Documentation is available at observer_simple.php

  1. <?php 
  2. @include '../../include_path.php';
  3. /**
  4.  * Observer ProgressBar example. Uses a custom observer class.
  5.  * 
  6.  * @version    $Id: observer_simple.php,v 1.2 2004/04/18 13:25:44 farell Exp $
  7.  * @author     Laurent Laville <pear@laurent-laville.org>
  8.  * @package    HTML_Progress
  9.  */
  10.  
  11. require_once 'HTML/Progress.php';
  12. require_once 'HTML/Progress/observer.php';
  13.  
  14. // 1. Defines ProgressBar observer
  15. {
  16.     var $_console;
  17.     var $_out;
  18.     
  19.     function MyObserver($out)
  20.     {
  21.         $this->_console '.' . DIRECTORY_SEPARATOR . 'observer_complex.log';
  22.         $this->HTML_Progress_Observer();
  23.         $this->_out strtolower($out);
  24.     }
  25.  
  26.     function notify($event)
  27.     {
  28.         if (is_array($event)) {
  29.             $log = isset($event['log']$event['log'"undefined event id.";
  30.             $val = isset($event['value']$event['value'"unknown value";
  31.             $msg = "$log = $val";
  32.         else {
  33.             $msg $event;
  34.         }
  35.         if ($this->_out == 'file'{
  36.             error_log("$msg \n"3$this->_console);
  37.         else {
  38.             print ("$msg <br />\n");
  39.     }
  40.     }
  41. }
  42.  
  43. // 2. Creates ProgressBar
  44. $bar = new HTML_Progress();
  45. $bar->setAnimSpeed(100);
  46. $bar->setIncrement(5);
  47.  
  48. // 3. Creates and attach a listener 
  49. $observer = new MyObserver('screen');
  50. //$observer = new MyObserver('file');
  51.  
  52. $ok $bar->addListener($observer);
  53. if (!$ok{
  54.     die ("Cannot add a valid listener to progress bar !");
  55. }
  56.  
  57. // 4. Changes look-and-feel of ProgressBar
  58. $ui $bar->getUI();
  59. $ui->setStringAttributes('color = red');
  60. $ui->setComment('Simple Observer ProgressBar example');
  61. ?>
  62. <html>
  63. <head>
  64. <title>Simple Observer ProgressBar example</title>
  65. <style type="text/css">
  66. <!--
  67. <?php echo $bar->getStyle()?>
  68. // -->
  69. </style>
  70. <script type="text/javascript">
  71. <!--
  72. <?php echo $bar->getScript()?>
  73. //-->
  74. </script>
  75. </head>
  76. <body>
  77. <h1><?php echo basename(__FILE__)?></h1>
  78.  
  79. <?php 
  80. echo $bar->toHTML()
  81.  
  82. do {
  83.     $bar->display();
  84.     if ($bar->getPercentComplete(== 1{
  85.         break;   // the progress bar has reached 100%
  86.     }
  87.     $bar->incValue();
  88. while(1);
  89. ?>
  90.  
  91. <p>&lt;&lt; <a href="index.html">Back examples TOC</a></p>
  92.  
  93. </body>
  94. </html>

Documentation generated on Mon, 11 Mar 2019 10:15:08 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.