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\Helper; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Grid helper. |
16
|
|
|
* |
17
|
|
|
* @author webeweb <https://github.com/webeweb/> |
18
|
|
|
* @package WBW\Bundle\BootstrapBundle\Helper |
19
|
|
|
*/ |
20
|
|
|
class GridHelper { |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Get a CSS classname. |
24
|
|
|
* |
25
|
|
|
* @param string $size The size. |
26
|
|
|
* @param int $value The value. |
27
|
|
|
* @param string $suffix The suffix. |
28
|
|
|
* @param int $min The min value. |
29
|
|
|
* @param int $max The max value. |
30
|
|
|
* @return string Returns the CSS classname. |
31
|
|
|
*/ |
32
|
|
|
public static function getCSSClassname($size, $value, $suffix, $min = 1, $max = 12) { |
33
|
|
|
|
34
|
|
|
// Check the value. |
35
|
|
|
if ($value < $min || $max < $value) { |
36
|
|
|
return ""; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
// Initialize the values. |
40
|
|
|
$sizes = ["lg", "md", "sm", "xs"]; |
41
|
|
|
$suffixes = ["offset", "pull", "push", ""]; |
42
|
|
|
|
43
|
|
|
// Check the size. |
44
|
|
|
if (false === in_array($size, $sizes)) { |
45
|
|
|
return ""; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
// Check the suffixes. |
49
|
|
|
if (false === in_array($suffix, $suffixes)) { |
50
|
|
|
return ""; |
51
|
|
|
} |
52
|
|
|
if ("" !== $suffix) { |
53
|
|
|
$suffix .= "-"; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
// Returns the classname. |
57
|
|
|
return implode("-", ["col", $size, $suffix . $value]); |
58
|
|
|
} |
59
|
|
|
} |