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