Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Progress Bar: Difference between revisions

From MoodleDocs
No edit summary
 
m (Text replacement - "</code>" to "</syntaxhighlight>")
 
(3 intermediate revisions by 3 users not shown)
Line 3: Line 3:


== Old Progress Bar ==
== Old Progress Bar ==
<pre>
<syntaxhighlight lang="php">
function print_progress($done, $total, $updatetime=5, $sleeptime=1, $donetext='')
function print_progress($done, $total, $updatetime=5, $sleeptime=1, $donetext='')
</pre>
</syntaxhighlight>
== OOP Progress Bar ==
== OOP Progress Bar ==


Usage:
Usage:
<pre>
<syntaxhighlight lang="php">
set_time_limit(0);
set_time_limit(0);
$pb = new progressbar('bar', 500);
$pb = new progressbar('bar', 500);
Line 20: Line 20:
         ;;;
         ;;;
     }
     }
     $pb->update_adv($cur_task, $num_tasks, 'this is'. $cur_task . 'h');
     $pb->update($cur_task, $num_tasks, 'this is'. $cur_task . 'h');
}
}
?>
?>
Line 34: Line 34:
         ;;;
         ;;;
     }
     }
     $pt->update_adv($cur_task, $num_tasks, 'this is'. $cur_task . 'h');
     $pt->update($cur_task, $num_tasks, 'this is'. $cur_task . 'h');
}
}
</pre>
</syntaxhighlight>

Latest revision as of 20:24, 14 July 2021

Progress Bar Lib

There are two Progress Bar libs avaiable in Moodle, the old one and a OOP one.

Old Progress Bar

function print_progress($done, $total, $updatetime=5, $sleeptime=1, $donetext='')

OOP Progress Bar

Usage:

set_time_limit(0);
$pb = new progressbar('bar', 500);
$pb->create();
$num_tasks = 200; // the number of tasks to be completed.
for($cur_task = 0; $cur_task <= $num_tasks; $cur_task++)
{
    for ($i=0; $i<100000; $i++)
    {
        ;;;
    }
    $pb->update($cur_task, $num_tasks, 'this is'. $cur_task . 'h');
}
?>
<hr/>
<?php
$pt = new progressbar('zbar', 900);
$pt->create();
$num_tasks = 200; // the number of tasks to be completed.
for($cur_task = 0; $cur_task <= $num_tasks; $cur_task++)
{
    for ($i=0; $i<100000; $i++)
    {
        ;;;
    }
    $pt->update($cur_task, $num_tasks, 'this is'. $cur_task . 'h');
}