static public progressBar ( $id, array $options = [] ) : nothing | ||
$id | HTML ID of the progress bar | |
$options | array | array progress status - create do we have to create it ? - message add or change the message - percent current level |
return | nothing | (display) |
static function progressBar($id, array $options = array())
{
$params = array();
$params['create'] = false;
$params['message'] = NULL;
$params['percent'] = -1;
if (is_array($options) && count($options)) {
foreach ($options as $key => $val) {
$params[$key] = $val;
}
}
if ($params['create']) {
echo "<div class='doaction_cadre'>";
echo "<div class='doaction_progress' id='{$id}'>";
echo "<div class='doaction_progress_text' id='" . $id . "_text' > </div>";
echo "</div>";
echo "</div><br>";
echo Html::scriptBlock(self::jsGetElementbyID($id) . ".progressbar();");
}
if ($params['message'] !== NULL) {
echo Html::scriptBlock(self::jsGetElementbyID($id . '_text') . ".text(\"" . addslashes($params['message']) . "\");");
}
if ($params['percent'] >= 0 && $params['percent'] <= 100) {
echo Html::scriptBlock(self::jsGetElementbyID($id) . ".progressbar('option', 'value', " . $params['percent'] . " );");
}
if (!$params['create']) {
Html::glpi_flush();
}
}
/** * Update the progress bar * * Display and update the progress bar. If the delay is more than 1 second, then activate it * * @return nothing (display only) **/ function updateProgressBars() { if ($this->timer->getTime() > 1) { // If the action's delay is more than one second, the display progress bars $this->display_progress_bars = true; } if ($this->display_progress_bars) { if (!isset($this->progress_bar_displayed)) { Html::progressBar('main_' . $this->identifier, array('create' => true, 'message' => $this->action_name)); $this->progress_bar_displayed = true; $this->fields_to_remove_when_reload[] = 'progress_bar_displayed'; if (count($this->items) > 1) { Html::progressBar('itemtype_' . $this->identifier, array('create' => true)); } } $percent = 100 * $this->nb_done / $this->nb_items; Html::progressBar('main_' . $this->identifier, array('percent' => $percent)); if (count($this->items) > 1 && isset($this->current_itemtype)) { $itemtype = $this->current_itemtype; if (isset($this->items[$itemtype])) { if (isset($this->done[$itemtype])) { $nb_done = count($this->done[$itemtype]); } else { $nb_done = 0; } $percent = 100 * $nb_done / count($this->items[$itemtype]); Html::progressBar('itemtype_' . $this->identifier, array('message' => $itemtype::getTypeName(Session::getPluralNumber()), 'percent' => $percent)); } } } }