ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilProgressBar.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
12 {
13  protected $min; // [int]
14  protected $max; // [int]
15  protected $current; // [int]
16  protected $show_caption; // [bool]
17  protected $type; // [int]
18  protected $caption; // [text]
19  protected $striped; // [bool]
20  protected $animated; // [bool]
21 
22 
23  protected $ajax_url = '';
24  protected $ajax_timeout = 5;
25  protected $unique_id = '';
26 
27  const TYPE_INFO = 1;
28  const TYPE_SUCCESS = 2;
29  const TYPE_WARNING = 3;
30  const TYPE_DANGER = 4;
31 
37  protected function __construct()
38  {
39  $this->setMin(0);
40  $this->setMax(100);
41  $this->setShowCaption(true);
42  $this->setType(self::TYPE_INFO);
43  $this->setStriped(true);
44  }
45 
51  public static function getInstance()
52  {
53  return new self();
54  }
55 
56 
57  //
58  // properties
59  //
60 
66  public function setType($a_value)
67  {
68  $valid = array(
69  self::TYPE_INFO
70  ,self::TYPE_SUCCESS
72  ,self::TYPE_DANGER
73  );
74  if (in_array($a_value, $valid)) {
75  $this->type = $a_value;
76  }
77  }
78 
84  public function setMin($a_value)
85  {
86  $this->min = abs((int) $a_value);
87  }
88 
94  public function setMax($a_value)
95  {
96  $this->max = abs((int) $a_value);
97  }
98 
104  public function setCaption($a_value)
105  {
106  $this->caption = trim($a_value);
107  }
108 
114  public function setShowCaption($a_value)
115  {
116  $this->show_caption = (bool) $a_value;
117  }
118 
124  public function setStriped($a_value)
125  {
126  $this->striped = (bool) $a_value;
127  }
128 
134  public function setAnimated($a_value)
135  {
136  $this->animated = (bool) $a_value;
137  }
138 
144  public function setCurrent($a_value)
145  {
146  $this->current = abs($a_value);
147  }
148 
149  public function setAsyncStatusUrl($a_target)
150  {
151  $this->ajax_url = $a_target;
152  }
153 
154  public function setAsynStatusTimeout($a_timeout)
155  {
156  $this->async_timeout = $a_timeout;
157  }
158 
159  public function setId($a_id)
160  {
161  $this->unique_id = $a_id;
162  }
163 
164  //
165  // presentation
166  //
167 
173  public function render()
174  {
175  $tpl = new ilTemplate("tpl.il_progress.html", true, true, "Services/UIComponent/ProgressBar");
176 
177  $tpl->setVariable("MIN", $this->min);
178  $tpl->setVariable("MAX", $this->max);
179  $tpl->setVariable("CURRENT_INT", round($this->current));
180  $tpl->setVariable("CURRENT", round($this->current));
181  $tpl->setVariable("CAPTION", $this->caption);
182 
183  $map = array(
184  self::TYPE_INFO => "info"
185  ,self::TYPE_SUCCESS => "success"
186  ,self::TYPE_WARNING => "warning"
187  ,self::TYPE_DANGER => "danger"
188  );
189  $css = array("progress-bar-" . $map[$this->type]);
190 
191  if ($this->striped) {
192  $css[] = "progress-bar-striped";
193  }
194 
195  if ($this->animated) {
196  $css[] = "active";
197  }
198 
199  $tpl->setVariable("CSS", implode(" ", $css));
200 
201  if (!$this->show_caption) {
202  $tpl->touchBlock("hide_caption_in_bl");
203  $tpl->touchBlock("hide_caption_out_bl");
204  }
205 
206  if (strlen($this->ajax_url) and $this->ajax_timeout) {
207  $tpl->setCurrentBlock('async_status');
208  $tpl->setVariable('ASYNC_STATUS_ID', $this->unique_id);
209  $tpl->setVariable('ICON_OK', ilUtil::getImagePath('icon_ok.svg'));
210  $tpl->setVariable('AJAX_URL', $this->ajax_url);
211  $tpl->setVariable('AJAX_TIMEOUT', 1000 * (int) $this->ajax_timeout);
212  $tpl->parseCurrentBlock();
213  }
214 
215  $tpl->setVariable('PROGRESS_ID', $this->unique_id);
216 
217  return $tpl->get();
218  }
219 }
const TYPE_WARNING
Definition: langcheck.php:49
$tpl
Definition: ilias.php:10
setCaption($a_value)
Set Caption.
$valid
setAsyncStatusUrl($a_target)
setShowCaption($a_value)
Toggle show caption status.
setMax($a_value)
Set maximum value.
static getInstance()
Factory.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
__construct()
Constructor.
special template class to simplify handling of ITX/PEAR
setMin($a_value)
Set minimum value.
setStriped($a_value)
Toggle striped layout.
setAnimated($a_value)
Toggle animated layout.
setType($a_value)
Set type (currently unwanted)
setAsynStatusTimeout($a_timeout)
setCurrent($a_value)
Set current value.