HTML_Progress2 : The Definitive Guide |
Suppose we decide to send a mail after a process is over (progress meter reach 100%) and keep aware some users. We will see how to do this now.
First step is to declare a function (user callback) that will observe all progress meter events.
Interface of such function (callback) is pretty easy. It requires only
one argument passed by reference ($notification
) and that should contains a PEAR::Event_Dispatcher instance.
Here are, in purpose of our tutorial, a function that will observe events and send a mail, at end of process, to webmaster@site.com with a short message that gave time elapsed.
Second step is to attach
this function (user callback) to the progress meter with the
addListener()
method.
$notifyName
contains event name
triggered. Three issues : onSubmit, onLoad, onChange.
Caution | |
---|---|
Event name is case sensitive: onsubmit does not match onSubmit. |
$notifyInfo
contains array of
additional informations.
For example :
Array ( [handler] => run [value] => 100 [sender] => html_progress2 [time] => 0.26838700 1127382686 )
When progress meter start, it trigger a onSubmit event through the
run()
method. This event is
catched into user callback and with help of additionnal info we
compute and store start time.
When progress meter reach 100%, it trigger a onLoad event through the run()
method. This event is catched into user
callback. We compute elapse time and send final result by mail to
the webmaster of site.com
All observers attached, are notified by each event. It's up to you to decide if you have to process an event or not. Here we will proceed only two events: onSubmit, onLoad.
Third step (optional) is
stop listen events and then detach user function (callback) to the
progress meter with the removeListener()
method.
Note | |
---|---|
While there are any observers attached, progress meter will continue to notify them of each event when they occured. |
HTML_Progress2 : The Definitive Guide | v 2.4.0 : April 20, 2007 |