noalyss Version-9
Public Member Functions | Private Attributes
Progress_Bar Class Reference

Use one db for tracking progress bar value, the task id must be unique and let you follow the progress of a task. More...

+ Collaboration diagram for Progress_Bar:

Public Member Functions

 __construct ($p_task_id)
 
 answer ()
 Json answer of the task progressing if value is equal or greater than 100 , delete the row. More...
 
 get_value ()
 Get the progress value from db. More...
 
 increment ($p_step)
 increment value with $p_step More...
 
 set_value ($p_value)
 Store the progress value into the db. More...
 

Private Attributes

 $db
 database connexion More...
 
 $task_id
 
 $value
 task id (progress_bar.p_id) More...
 

Detailed Description

Use one db for tracking progress bar value, the task id must be unique and let you follow the progress of a task.

how it works : when calling an ajax , you have to create the task id and start the monitoring of it (js function = progress_bar_start). In your php script called by ajax you call Progress_Bar->set_value to show the progress. The timer created by progress_bar_start will check regularly the progress in the db. The ajax parameter for following the task is task_id

Note
you have to use session_write_close(); in the ajax file , otherwise, the function progress_bar_check will be blocked and won't update the progress bar
See also
progress_bar_start
progress_bar_check
Examples
progress-bar.test.php.

Definition at line 47 of file progress_bar.class.php.

Constructor & Destructor Documentation

◆ __construct()

Progress_Bar::__construct (   $p_task_id)

Definition at line 56 of file progress_bar.class.php.

57 {
58 $this->db=new Database();
59 $this->task_id=$p_task_id;
60 // Find value from db
61 $this->value = $this->db->get_value("select p_value from progress where p_id=$1",
62 [$p_task_id]);
63
64 // if task doesn't exists, create it
65 if ( $this->db->size()==0)
66 {
67 $this->value=0;
68 $this->db->exec_sql("insert into progress(p_id,p_value) values ($1,0)",
69 [$p_task_id]);
70 $this->db->exec_sql("delete from progress where p_created < now() - interval '3 hours' ");
71 }
72 }
contains the class for connecting to Noalyss
$SecUser db

References db, and value.

Member Function Documentation

◆ answer()

Progress_Bar::answer ( )

Json answer of the task progressing if value is equal or greater than 100 , delete the row.

Returns
type

Definition at line 105 of file progress_bar.class.php.

106 {
107 $this->get_value();
108
109 header('Content-Type: application/json');
110 echo json_encode(["value"=>$this->value]);
111 if ($this->value>=100) {
112 $this->db->exec_sql("delete from progress where p_id=$1",[$this->task_id]);
113 }
114 return;
115 }
get_value()
Get the progress value from db.

References db, get_value(), and value.

+ Here is the call graph for this function:

◆ get_value()

Progress_Bar::get_value ( )

Get the progress value from db.

Returns
integer between 0 & 100

Definition at line 93 of file progress_bar.class.php.

94 {
95 $this->value = $this->db->get_value("select p_value from progress where p_id=$1",
96 [$this->task_id]);
97
98 return $this->value;
99 }
$value
task id (progress_bar.p_id)

References $value, db, and value.

Referenced by answer().

◆ increment()

Progress_Bar::increment (   $p_step)

increment value with $p_step

Parameters
int$p_step

Definition at line 120 of file progress_bar.class.php.

121 {
122 if ($this->value+$p_step > 100 ) {
123 $this->set_value(100);
124 return;
125 }
126 $this->set_value($this->value+$p_step);
127 }
set_value($p_value)
Store the progress value into the db.

References $p_step, set_value(), and value.

+ Here is the call graph for this function:

◆ set_value()

Progress_Bar::set_value (   $p_value)

Store the progress value into the db.

Parameters
integer$p_valuevalue of the progress between 0 & 100 @exceptions code 1005 - if p_value is not in between 0 & 100

Definition at line 78 of file progress_bar.class.php.

79 {
80 if ( $p_value > 100 || $p_value < 0 ) {
81 throw new Exception("Invalid value",EXC_PARAM_VALUE);
82 }
83 $this->value=$p_value;
84 $this->db->start();
85 $this->db->exec_sql("update progress set p_value=$1 where p_id=$2",
86 [$this->value,$this->task_id]);
87 $this->db->commit();
88 }
const EXC_PARAM_VALUE
Definition: constant.php:343

References db, EXC_PARAM_VALUE, and value.

Referenced by Document_Export\export_all(), and increment().

Field Documentation

◆ $db

Progress_Bar::$db
private

database connexion

Definition at line 49 of file progress_bar.class.php.

◆ $task_id

Progress_Bar::$task_id
private

Definition at line 50 of file progress_bar.class.php.

◆ $value

Progress_Bar::$value
private

task id (progress_bar.p_id)

value of progress (between 0 & 100)

Definition at line 51 of file progress_bar.class.php.

Referenced by get_value().


The documentation for this class was generated from the following file: