|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the bootstrap-bundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2018 WEBEWEB |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace WBW\Bundle\BootstrapBundle\Twig\Extension\Component; |
|
13
|
|
|
|
|
14
|
|
|
use WBW\Bundle\BootstrapBundle\Twig\Extension\AbstractBootstrapTwigExtension; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Abstract progress bar Twig extension. |
|
18
|
|
|
* |
|
19
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
20
|
|
|
* @package WBW\Bundle\BootstrapBundle\Twig\Extension\Component |
|
21
|
|
|
* @abstract |
|
22
|
|
|
*/ |
|
23
|
|
|
abstract class AbstractProgressBarTwigExtension extends AbstractBootstrapTwigExtension { |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Constructor. |
|
27
|
|
|
*/ |
|
28
|
|
|
protected function __construct() { |
|
29
|
|
|
parent::__construct(); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Displays a Bootstrap progress bar. |
|
34
|
|
|
* |
|
35
|
|
|
* @param string $content The progress bar content. |
|
36
|
|
|
* @param integer $value The progress bar value. |
|
37
|
|
|
* @param integer $min The progress bar min. |
|
38
|
|
|
* @param integer $max The progress bar max. |
|
39
|
|
|
* @param boolean $striped Progress bar striped ? |
|
40
|
|
|
* @param boolean $animated Progress bar animated ? |
|
41
|
|
|
* @param string $class The progress bar class. |
|
42
|
|
|
* @return string Returns the Bootstrap progress bar. |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function bootstrapProgressBar($content, $value, $min, $max, $striped, $animated, $class = null) { |
|
45
|
|
|
|
|
46
|
|
|
// Initialize the template. |
|
47
|
|
|
$span = self::bootstrapHTMLElement("span", $value . "%", ["class" => "sr-only"]); |
|
48
|
|
|
|
|
49
|
|
|
// Initialize the attributes. |
|
50
|
|
|
$attributes = []; |
|
51
|
|
|
|
|
52
|
|
|
$attributes["class"] = ["progress-bar", $class]; |
|
53
|
|
|
$attributes["class"][] = true === $striped ? "progress-bar-striped" : null; |
|
54
|
|
|
$attributes["class"][] = true === $animated ? "active" : null; |
|
55
|
|
|
$attributes["style"] = "width: " . $value . "%;"; |
|
56
|
|
|
$attributes["role"] = "progressbar"; |
|
57
|
|
|
$attributes["aria-valuenow"] = $value; |
|
58
|
|
|
$attributes["aria-valuemin"] = $min; |
|
59
|
|
|
$attributes["aria-valuemax"] = $max . "%"; |
|
60
|
|
|
|
|
61
|
|
|
// Initialize the parameters. |
|
62
|
|
|
$innerHTML = null !== $content ? $content : $span; |
|
63
|
|
|
|
|
64
|
|
|
// Initialize the template. |
|
65
|
|
|
$div = self::bootstrapHTMLElement("div", $innerHTML, $attributes); |
|
66
|
|
|
|
|
67
|
|
|
// Return the HTML. |
|
68
|
|
|
return self::bootstrapHTMLElement("div", $div, ["class" => "progress"]); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|