Examples TOCexamples TOC

Constructor Model

$Date: 2004/04/18 13:25:43 $

 Table of contents

Introduction

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.

[Top]

 PHP script

Build the progress bar

require_once 'HTML/Progress.php';

class TimerProgress extends HTML_Progress_DM
{
    function TimerProgress()
    {       
        $this->HTML_Progress_DM(0,60,5);
    }
}

$timer = new TimerProgress();
$bar = new HTML_Progress($timer);
$bar->setAnimSpeed(100);
$bar->setStringPainted(true);          // get space for the string
$bar->setString('');                   // but don't paint it

$ui =& $bar->getUI();
$ui->setStringAttributes('width=170 height=20 valign=bottom align=center');

Loop to run the progress


do {
    $bar->display();
    if ($bar->getPercentComplete() == 1) {
        $bar->setString('All done!');
        $bar->display();
        break;   // the progress bar has reached 100%
    }
    if ($bar->getPercentComplete() == 0.25) {
        $bar->setString('Fourth part way done!');
    }
    if ($bar->getPercentComplete() == 0.5) {
        $bar->setString('Half way done!');
    }
    if ($bar->getPercentComplete() == 0.75) {
        $bar->setString('Three quarters way done!');
    }
    $bar->incValue();
} while(1);

[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]

 Play full example

Run the script below :


<?php 
require_once 'HTML/Progress.php';

class TimerProgress extends HTML_Progress_DM
{
    function TimerProgress()
    {       
        $this->HTML_Progress_DM(0,60,5);
    }
}

$timer = new TimerProgress();
$bar = new HTML_Progress($timer);
$bar->setAnimSpeed(100);
$bar->setStringPainted(true);          // get space for the string
$bar->setString('');                   // but don't paint it

$ui =& $bar->getUI();
$ui->setStringAttributes('width=170 height=20 valign=bottom align=center');
?>
<html>
<head>
<title>ProgressBar model example</title>
<style type="text/css">
<!--
<?php echo $bar->getStyle(); ?>
// -->
</style>
<script type="text/javascript">
<!--
<?php echo $bar->getScript(); ?>
//-->
</script>
</head>
<body>

<?php 
echo $bar->toHtml(); 

do {
    $bar->display();
    if ($bar->getPercentComplete() == 1) {
        $bar->setString('All done!');
        $bar->display();
        break;   // the progress bar has reached 100%
    }
    if ($bar->getPercentComplete() == 0.25) {
        $bar->setString('Fourth part way done!');
    }
    if ($bar->getPercentComplete() == 0.5) {
        $bar->setString('Half way done!');
    }
    if ($bar->getPercentComplete() == 0.75) {
        $bar->setString('Three quarters way done!');
    }
    $bar->incValue();
} while(1);
?>

</body>
</html>
href:  ./constructor_model.php

[Top]