|
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\ProgressBar\ProgressBarInterface; |
|
15
|
|
|
use WBW\Bundle\BootstrapBundle\ProgressBar\ProgressBarRenderer; |
|
16
|
|
|
use WBW\Bundle\BootstrapBundle\Twig\Extension\AbstractTwigExtension; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Abstract progress bar Twig extension. |
|
20
|
|
|
* |
|
21
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
22
|
|
|
* @package WBW\Bundle\BootstrapBundle\Twig\Extension\Component |
|
23
|
|
|
* @abstract |
|
24
|
|
|
*/ |
|
25
|
|
|
abstract class AbstractProgressBarTwigExtension extends AbstractTwigExtension { |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Displays a Bootstrap progress bar. |
|
29
|
|
|
* |
|
30
|
|
|
* @param ProgressBarInterface $progressBar The progress bar. |
|
31
|
|
|
* @return string Returns the Bootstrap progress bar. |
|
32
|
|
|
*/ |
|
33
|
|
|
protected function bootstrapProgressBar(ProgressBarInterface $progressBar): string { |
|
34
|
|
|
|
|
35
|
|
|
$span = static::coreHTMLElement("span", $progressBar->getValue() . "%", ["class" => "sr-only"]); |
|
36
|
|
|
|
|
37
|
|
|
$type = ProgressBarRenderer::renderType($progressBar); |
|
38
|
|
|
if (3 !== $this->getVersion()) { |
|
39
|
|
|
$type = preg_replace("/progress-bar-(danger|info|success|warning)/", "bg-$1", $type); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$attributes = []; |
|
43
|
|
|
|
|
44
|
|
|
$attributes["class"] = ["progress-bar", $type]; |
|
45
|
|
|
$attributes["class"][] = ProgressBarRenderer::renderStriped($progressBar); |
|
46
|
|
|
$attributes["class"][] = ProgressBarRenderer::renderAnimated($progressBar); |
|
47
|
|
|
$attributes["style"] = ProgressBarRenderer::renderStyle($progressBar); |
|
48
|
|
|
$attributes["role"] = "progressbar"; |
|
49
|
|
|
$attributes["aria-valuenow"] = $progressBar->getValue(); |
|
50
|
|
|
$attributes["aria-valuemin"] = $progressBar->getMin(); |
|
51
|
|
|
$attributes["aria-valuemax"] = $progressBar->getMax(); |
|
52
|
|
|
|
|
53
|
|
|
$innerHTML = ProgressBarRenderer::renderContent($progressBar, $span); |
|
54
|
|
|
|
|
55
|
|
|
$div = static::coreHTMLElement("div", $innerHTML, $attributes); |
|
56
|
|
|
|
|
57
|
|
|
return static::coreHTMLElement("div", $div, ["class" => "progress"]); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|