Completed
Push — master ( 3c40fd...fd4f3a )
by Petr
06:28
created

Customization::useTemplateBootstrap()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
ccs 0
cts 2
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * This file is part of the Grido (http://grido.bugyik.cz)
5
 *
6
 * Copyright (c) 2011 Petr Bugyík (http://petr.bugyik.cz)
7
 *
8
 * For the full copyright and license information, please view
9
 * the file LICENSE.md that was distributed with this source code.
10
 */
11
12
namespace Grido;
13
14
use Grido\Grid;
15
use Nette\Object;
16
17
/**
18
 * Customization.
19
 *
20
 * @package     Grido
21
 * @author      Petr Bugyík
22
 *
23
 * @property string|array $buttonClass
24
 * @property string|array $iconClass
25
 */
26
class Customization extends Object
27 1
{
28
29
    const TEMPLATE_DEFAULT = 'default';
30
    const TEMPLATE_BOOTSTRAP = 'bootstrap';
31
32
    /** @var Grid */
33
    protected $grid;
34
35
    /** @var string|array */
36
    protected $buttonClass;
37
38
    /** @var string|array */
39
    protected $iconClass;
40
41
    /** @var array */
42
    protected $templateFiles = [];
43
44
    /**
45
     * @param Grid $grid
46
     */
47
    public function __construct(Grid $grid)
48
    {
49
        $this->grid = $grid;
50
    }
51
52
    /**
53
     * @param string|array $class
54
     * @return \Grido\Customization
55
     */
56
    public function setButtonClass($class)
57
    {
58
        $this->buttonClass = $class;
59
        return $this;
60
    }
61
62
    /**
63
     * @param string|array $class
64
     * @return \Grido\Customization
65
     */
66
    public function setIconClass($class)
67
    {
68
        $this->iconClass = $class;
69
        return $this;
70
    }
71
72
    /**
73
     * @return string
74
     */
75
    public function getButtonClass()
76
    {
77
        return is_array($this->buttonClass)
78
            ? implode(' ', $this->buttonClass)
79
            : $this->buttonClass;
80
    }
81
82
    /**
83
     * @param string $icon
84
     * @return string
85
     */
86
    public function getIconClass($icon = NULL)
87
    {
88
        if ($icon === NULL) {
89
            $class = $this->iconClass;
90
        } else {
91
            $this->iconClass = (array) $this->iconClass;
92
            $classes = [];
93
            foreach ($this->iconClass as $fontClass) {
94
                $classes[] = "{$fontClass} {$fontClass}-{$icon}";
95
            }
96
            $class = implode(' ', $classes);
97
        }
98
99
        return $class;
100
    }
101
102
    /**
103
     * @return array
104
     */
105
    public function getTemplateFiles()
106
    {
107
        if (empty($this->templateFiles)) {
108
            foreach (new \DirectoryIterator(__DIR__ . '/templates') as $file) {
109
                if ($file->isFile()) {
110
                    $this->templateFiles[$file->getBasename('.latte')] = realpath($file->getPathname());
111
                }
112
            }
113
        }
114
115
        return $this->templateFiles;
116
    }
117
118
    /**
119
     * Default theme.
120
     * @return \Grido\Customization
121
     */
122
    public function useTemplateDefault()
123
    {
124
        $this->grid->setTemplateFile($this->getTemplateFiles()[self::TEMPLATE_DEFAULT]);
125
        return $this;
126
    }
127
128
    /**
129
     * Twitter Bootstrap theme.
130
     * @return \Grido\Customization
131
     */
132
    public function useTemplateBootstrap()
133
    {
134
        $this->grid->setTemplateFile($this->getTemplateFiles()[self::TEMPLATE_BOOTSTRAP]);
135
        return $this;
136
    }
137
}
138