forked from patricktalmadge/bootstrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogress.php
136 lines (120 loc) · 3.21 KB
/
progress.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php namespace Bootstrapper;
use \HTML;
/**
* Progress for creating Twitter Bootstrap style progress bar.
*
* @package Bundles
* @subpackage Twitter
* @author Patrick Talmadge - Follow @patricktalmadge
*
* @see http://twitter.github.com/bootstrap/
*/
class Progress
{
// Progress bar colors
const NORMAL = '';
const SUCCESS = 'progress-success';
const INFO = 'progress-info';
const WARNING = 'progress-warning';
const DANGER = 'progress-danger';
protected static function show($amount, $type = Progress::NORMAL, $attributes = array())
{
$attributes = Helpers::add_class($attributes, 'progress '.$type);
return '<div'.HTML::attributes($attributes).'><div class="bar" style="width: '.$amount.'%;"></div></div>';
}
/**
* Create a new Normal Progress Bar.
*
* @param string $amount
* @param array $attributes
* @return Progress
*/
public static function normal($amount, $attributes = array())
{
return static::show($amount, Progress::NORMAL, $attributes);
}
/**
* Create a new Success Progress Bar.
*
* @param string $amount
* @param array $attributes
* @return Progress
*/
public static function success($amount, $attributes = array())
{
return static::show($amount, Progress::SUCCESS, $attributes);
}
/**
* Create a new Info Progress Bar.
*
* @param string $amount
* @param array $attributes
* @return Progress
*/
public static function info($amount, $attributes = array())
{
return static::show($amount, Progress::INFO, $attributes);
}
/**
* Create a new Warning Progress Bar.
*
* @param string $amount
* @param array $attributes
* @return Progress
*/
public static function warning($amount, $attributes = array())
{
return static::show($amount, Progress::WARNING, $attributes);
}
/**
* Create a new Danger Progress Bar.
*
* @param string $amount
* @param array $attributes
* @return Progress
*/
public static function danger($amount, $attributes = array())
{
return static::show($amount, Progress::DANGER, $attributes);
}
/**
* Checks call to see if we can create a progress bar from a magic call (for you wizards).
* normal_striped_active, info_striped, etc...
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public static function __callStatic($method, $parameters)
{
$method_array = explode('_', strtolower($method));
$types = array('normal', 'success', 'info', 'warning', 'danger');
$type_found = array_intersect($method_array, $types);
if(count($type_found) > 0)
{
$function = $type_found[key($type_found)];
//Set default $attributes and check for a set value
$attributes = array();
if(isset($parameters[1]))
{
if(is_array($parameters[1]))
{
$attributes = $parameters[1];
}
else
{
throw new \Exception("Tabbable attributes parameter should be an array of attributes");
}
}
if(in_array ('striped', $method_array))
{
$attributes = Helpers::add_class($attributes, 'progress-striped');
}
if(in_array ('active', $method_array))
{
$attributes = Helpers::add_class($attributes, 'active');
}
return static::$function($parameters[0], $attributes);
}
}
}