ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
71 ,self::TYPE_WARNING
72 ,self::TYPE_DANGER
73 );
74 if(in_array($a_value, $valid))
75 {
76 $this->type = $a_value;
77 }
78 }
79
85 public function setMin($a_value)
86 {
87 $this->min = abs((int)$a_value);
88 }
89
95 public function setMax($a_value)
96 {
97 $this->max = abs((int)$a_value);
98 }
99
105 public function setCaption($a_value)
106 {
107 $this->caption = trim($a_value);
108 }
109
115 public function setShowCaption($a_value)
116 {
117 $this->show_caption = (bool)$a_value;
118 }
119
125 public function setStriped($a_value)
126 {
127 $this->striped = (bool)$a_value;
128 }
129
135 public function setAnimated($a_value)
136 {
137 $this->animated = (bool)$a_value;
138 }
139
145 public function setCurrent($a_value)
146 {
147 $this->current = abs($a_value);
148 }
149
150 public function setAsyncStatusUrl($a_target)
151 {
152 $this->ajax_url = $a_target;
153 }
154
155 public function setAsynStatusTimeout($a_timeout)
156 {
157 $this->async_timeout = $a_timeout;
158 }
159
160 public function setId($a_id)
161 {
162 $this->unique_id = $a_id;
163 }
164
165 //
166 // presentation
167 //
168
174 public function render()
175 {
176 $tpl = new ilTemplate("tpl.il_progress.html", true, true, "Services/UIComponent/ProgressBar");
177
178 $tpl->setVariable("MIN", $this->min);
179 $tpl->setVariable("MAX", $this->max);
180 $tpl->setVariable("CURRENT_INT", round($this->current));
181 $tpl->setVariable("CURRENT", round($this->current));
182 $tpl->setVariable("CAPTION", $this->caption);
183
184 $map = array(
185 self::TYPE_INFO => "info"
186 ,self::TYPE_SUCCESS => "success"
187 ,self::TYPE_WARNING => "warning"
188 ,self::TYPE_DANGER => "danger"
189 );
190 $css = array("progress-bar-".$map[$this->type]);
191
192 if($this->striped)
193 {
194 $css[] = "progress-bar-striped";
195 }
196
197 if($this->animated)
198 {
199 $css[] = "active";
200 }
201
202 $tpl->setVariable("CSS", implode(" ", $css));
203
204 if(!$this->show_caption)
205 {
206 $tpl->touchBlock("hide_caption_in_bl");
207 $tpl->touchBlock("hide_caption_out_bl");
208 }
209
210 if(strlen($this->ajax_url) and $this->ajax_timeout)
211 {
212 $tpl->setCurrentBlock('async_status');
213 $tpl->setVariable('ASYNC_STATUS_ID',$this->unique_id);
214 $tpl->setVariable('ICON_OK',ilUtil::getImagePath('icon_ok.svg'));
215 $tpl->setVariable('AJAX_URL',$this->ajax_url);
216 $tpl->setVariable('AJAX_TIMEOUT',1000 * (int) $this->ajax_timeout);
217 $tpl->parseCurrentBlock();
218 }
219
220 $tpl->setVariable('PROGRESS_ID',$this->unique_id);
221
222 return $tpl->get();
223 }
224}
global $tpl
Definition: ilias.php:8
setCaption($a_value)
Set Caption.
static getInstance()
Factory.
setMin($a_value)
Set minimum value.
setAsyncStatusUrl($a_target)
setType($a_value)
Set type (currently unwanted)
__construct()
Constructor.
setShowCaption($a_value)
Toggle show caption status.
setAsynStatusTimeout($a_timeout)
setCurrent($a_value)
Set current value.
setStriped($a_value)
Toggle striped layout.
setMax($a_value)
Set maximum value.
setAnimated($a_value)
Toggle animated layout.
special template class to simplify handling of ITX/PEAR
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
$valid