HTML_Progress2 : The Definitive Guide |
Now we know the basic of progress meter design, its now time to learn how to handle display refresh with the user process.
There are two main ways :
with a user callback. The core of HTML_Progress2 checking progression (until end), and handling display refresh for us.
without user callback. We have to do all tasks that core of HTML_Progress2 can do it for us.
Its the most easy way. We have just to declare the user callback with setProgressHandler() method, and launch execution with run() method. HTML_Progress2 will check progression of meter (both modes supported: indeterminate, determinate) and stop when 100% is reach.
Tip | |
---|---|
If you don't specify a callback, default behavior will call HTML_Progress2 sleep() method in background: delay animation n milliseconds (default = zero). This delay is set by setAnimSpeed() method. |
Here is an example that demonstrates user callback usage. We suppose
that we get image count from any data source and we have to
build/display these images. It could be generated by jpgraph (for
complex graphics), but here we used five times same script that call
a pearImage()
function. Part of code
came from PEAR_Info package.
Here is a copy of such PEAR_Info::pearImage()
function, in the
pearimage.php
script:
And now, the main script.
Lets review this example step by step :
$dataSrc
identify the data source.
Five call to pearimage.php
script.
Main task is to build, and display, five pear logo pictures.
This task is defined by user callback : myProcess
and linked to progress meter by
setProgressHandler()
method.
We used moveStep
strategy with the return $q
code,
and increment compute.
If you remove this line we use the second strategy called moveNext. We will talk about it later. Don't be afraid if you don't know yet what is the difference.
Task is completed, five logo built and shown. The progress bar is hidden.
To show difference of two implementations, we will re-used the same example of pear logo.
Lets review this example step by step :
$dataSrc
identify again the data
source. Five call to pearimage.php
script.
myProcess
is defined as a
reusable function and not a callback for progress meter.
run()
method was replaced by a
for-each loop. We must :
getPercentComplete()
method).
We use again the same moveStep strategy.
Task is completed, five logo built and shown. The progress bar is hidden.
HTML_Progress2 : The Definitive Guide | v 2.4.0 : April 20, 2007 |