function tripal_bulk_loader_progress_bar
2.x tripal_bulk_loader.loader.inc | tripal_bulk_loader_progress_bar($current = 0, $total = 100, $size = 50) |
3.x tripal_bulk_loader.loader.inc | tripal_bulk_loader_progress_bar($current = 0, $total = 100, $size = 50) |
1.x tripal_bulk_loader.loader.inc | tripal_bulk_loader_progress_bar($current = 0, $total = 100, $size = 50) |
Used to display loader progress to the user
Related topics
1 call to tripal_bulk_loader_progress_bar()
- tripal_bulk_loader_load_data in tripal_bulk_loader/
includes/ tripal_bulk_loader.loader.inc - Tripal Bulk Loader
File
- tripal_bulk_loader/
includes/ tripal_bulk_loader.loader.inc, line 1051 - @todo Add file header description
Code
function tripal_bulk_loader_progress_bar($current = 0, $total = 100, $size = 50) {
$new_bar = FALSE;
$mem = memory_get_usage();
// First iteration
if ($current == 0) {
$new_bar = TRUE;
fputs(STDOUT, "Progress:\n");
}
// Percentage round off for a more clean, consistent look
$percent = sprintf("%.02f", round(($current / $total) * 100, 2));
// percent indicator must be four characters, if shorter, add some spaces
for ($i = strlen($percent); $i <= 4; $i++) {
$percent = ' ' . $percent;
}
$total_size = $size + $i + 3 + 2;
$place = 0;
// if it's not first go, remove the previous bar
if (!$new_bar) {
for ($place = $total_size; $place > 0; $place--) {
// echo a backspace (hex:08) to remove the previous character
//echo "\x08";
}
}
// output the progess bar as it should be
// Start with a border
echo '[';
for ($place = 0; $place <= $size; $place++) {
// output "full" spaces if this portion is completed
if ($place <= ($current / $total * $size)) {
echo '|';
}
else {
// Otherwise empty space
echo '-';
}
}
// End with a border
echo ']';
// end a bar with a percent indicator
echo " $percent%. ($current of $total) Memory: $mem\r";
// if it's the end, add a new line
if ($current == $total) {
echo "\n";
}
}