ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilProgressBar.php
Go to the documentation of this file.
1<?php
2
26{
27 public const TYPE_INFO = 1;
28 public const TYPE_SUCCESS = 2;
29 public const TYPE_WARNING = 3;
30 public const TYPE_DANGER = 4;
32
33 protected int $min = 0;
34 protected int $max = 0;
35 protected int $current = 0;
36 protected bool $show_caption = false;
37 protected int $type = 0;
38 protected string $caption = "";
39 protected bool $striped = false;
40 protected bool $animated = false;
41 protected string $ajax_url = '';
42 protected int $ajax_timeout = 5;
43 protected string $unique_id = '';
44 protected int $async_timeout = 0;
45
46 protected function __construct()
47 {
48 global $DIC;
49
50 $this->main_tpl = $DIC->ui()->mainTemplate();
51
52 $this->setMin(0);
53 $this->setMax(100);
54 $this->setShowCaption(true);
55 $this->setType(self::TYPE_INFO);
56 $this->setStriped(true);
57 }
58
59 public static function getInstance(): self
60 {
61 return new self();
62 }
63
64 public function setType(int $a_value): void
65 {
66 $valid = array(
67 self::TYPE_INFO
68 ,self::TYPE_SUCCESS
69 ,self::TYPE_WARNING
70 ,self::TYPE_DANGER
71 );
72 if (in_array($a_value, $valid)) {
73 $this->type = $a_value;
74 }
75 }
76
77 public function setMin(int $a_value): void
78 {
79 $this->min = abs($a_value);
80 }
81
82 public function setMax(int $a_value): void
83 {
84 $this->max = abs($a_value);
85 }
86
87 public function setCaption(string $a_value): void
88 {
89 $this->caption = trim($a_value);
90 }
91
92 public function setShowCaption(bool $a_value): void
93 {
94 $this->show_caption = $a_value;
95 }
96
97 public function setStriped(bool $a_value): void
98 {
99 $this->striped = $a_value;
100 }
101
102 public function setAnimated(bool $a_value): void
103 {
104 $this->animated = $a_value;
105 }
106
107 public function setCurrent(float $a_value): void
108 {
109 $this->current = (int) abs($a_value);
110 }
111
112 public function setAsyncStatusUrl(string $a_target): void
113 {
114 $this->ajax_url = $a_target;
115 }
116
117 public function setAsynStatusTimeout(int $a_timeout): void
118 {
119 $this->async_timeout = $a_timeout;
120 }
121
122 public function setId(string $a_id): void
123 {
124 $this->unique_id = $a_id;
125 }
126
127 public function render(): string
128 {
129 $tpl = new ilTemplate("tpl.il_progress.html", true, true, "components/ILIAS/UIComponent/ProgressBar");
130
131 $tpl->setVariable("MIN", $this->min);
132 $tpl->setVariable("MAX", $this->max);
133 $tpl->setVariable("CURRENT_INT", round($this->current));
134 $tpl->setVariable("CURRENT", round($this->current));
135 $tpl->setVariable("CAPTION", $this->caption);
136
137 $map = array(
138 self::TYPE_INFO => "info"
139 ,self::TYPE_SUCCESS => "success"
140 ,self::TYPE_WARNING => "warning"
141 ,self::TYPE_DANGER => "danger"
142 );
143 $css = array("progress-bar-" . $map[$this->type]);
144
145 if ($this->striped) {
146 $css[] = "progress-bar-striped";
147 }
148
149 if ($this->animated) {
150 $css[] = "active";
151 }
152
153 $tpl->setVariable("CSS", implode(" ", $css));
154
155 if (!$this->show_caption) {
156 $tpl->touchBlock("hide_caption_in_bl");
157 $tpl->touchBlock("hide_caption_out_bl");
158 }
159
160 if ($this->ajax_url !== '' && $this->ajax_timeout) {
161 $this->main_tpl->addJavaScript("assets/js/progress_bar.js");
162 $tpl->setCurrentBlock('async_status');
163 $tpl->setVariable('ASYNC_STATUS_ID', $this->unique_id);
164 $tpl->setVariable('ICON_OK', ilUtil::getImagePath('standard/icon_ok.svg'));
165 $tpl->setVariable('AJAX_URL', $this->ajax_url);
166 $tpl->setVariable('AJAX_TIMEOUT', 1000 * $this->ajax_timeout);
167 $tpl->parseCurrentBlock();
168 }
169
170 $tpl->setVariable('PROGRESS_ID', $this->unique_id);
171
172 return $tpl->get();
173 }
174}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setMax(int $a_value)
setAnimated(bool $a_value)
setCaption(string $a_value)
setShowCaption(bool $a_value)
setCurrent(float $a_value)
setMin(int $a_value)
setStriped(bool $a_value)
setId(string $a_id)
setType(int $a_value)
ilGlobalTemplateInterface $main_tpl
setAsyncStatusUrl(string $a_target)
setAsynStatusTimeout(int $a_timeout)
special template class to simplify handling of ITX/PEAR
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
$valid
global $DIC
Definition: shib_login.php:26