Examples TOCexamples

Model

$Date: 2005/07/25 10:25:30 $

 Table of contents

Introduction

This example requires :


This example will run a horizontal ProgressBar, with limits (min = 0, max = 60) and increment set to 5 in the mathematical model TimerProgress.

The custom string is center aligned at bottom side of the progress bar. Cells have default size and colors.

First introduction of progress handler (user-callback). Function is defined on lines 21 thru 38, and attached on progress bar at line 45.

[Top]

 Render options

Here are options to build this progress bar string (percent text info):
width  = 170
height = 20
valign = bottom
align  = center
HTML_Progress_UI::setStringAttributes()

[Top]

 Output

Screenshot

[Top]

 PHP source syntax highlight

  1. <?php
  2. /**
  3.  * ProgressBar model example.
  4.  *
  5.  * @version    $Id: model.php,v 1.2 2005/07/25 10:25:30 farell Exp $
  6.  * @author     Laurent Laville <pear@laurent-laville.org>
  7.  * @package    HTML_Progress
  8.  * @subpackage Examples
  9.  */
  10.  
  11. require_once 'HTML/Progress.php';
  12.  
  13. class TimerProgress extends HTML_Progress_DM
  14. {
  15.     function TimerProgress()
  16.     {
  17.         $this->HTML_Progress_DM(0,60,5);
  18.     }
  19. }
  20.  
  21. function myFunctionHandler($progressValue, &$obj)
  22. {
  23.     if ($obj->getPercentComplete() == 0.25) {
  24.         $obj->setString('Fourth part way done!');
  25.     }
  26.     if ($obj->getPercentComplete() == 0.5) {
  27.         $obj->setString('Half way done!');
  28.     }
  29.     if ($obj->getPercentComplete() == 0.75) {
  30.         $obj->setString('Three quarters way done!');
  31.     }
  32.     if ($obj->getPercentComplete() == 1) {
  33.         $obj->setString('All done!');
  34.         $obj->display();
  35.     } else {
  36.         $obj->sleep();
  37.     }
  38. }
  39.  
  40. $timer = new TimerProgress();
  41. $bar = new HTML_Progress($timer);
  42. $bar->setAnimSpeed(100);
  43. $bar->setStringPainted(true);          // get space for the string
  44. $bar->setString('');                   // but don't paint it
  45. $bar->setProgressHandler('myFunctionHandler');
  46.  
  47. $ui =& $bar->getUI();
  48. $ui->setTab('    ');
  49. $ui->setStringAttributes('width=170 height=20 valign=bottom align=center');
  50. ?>
  51. <html>
  52. <head>
  53. <title>ProgressBar model example</title>
  54. <style type="text/css">
  55. <!--
  56. <?php echo $bar->getStyle(); ?>
  57.  
  58. body {
  59.     background-color: #FFFFFF;
  60.     color: #000000;
  61.     font-family: Verdana, Arial;
  62. }
  63.  
  64. a:visited, a:active, a:link {
  65.     color: navy;
  66. }
  67. // -->
  68. </style>
  69. <script type="text/javascript">
  70. <!--
  71. <?php echo $bar->getScript(); ?>
  72. //-->
  73. </script>
  74. </head>
  75. <body>
  76.  
  77. <?php
  78. echo $bar->toHtml();
  79. $bar->run();
  80. ?>
  81.  
  82. </body>
  83. </html>

[Top]