1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Grido (https://github.com/o5/grido) |
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
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Customization. |
18
|
|
|
* |
19
|
|
|
* @package Grido |
20
|
|
|
* @author Petr Bugyík |
21
|
|
|
* |
22
|
|
|
* @property string|array $buttonClass |
23
|
|
|
* @property string|array $iconClass |
24
|
|
|
*/ |
25
|
|
|
class Customization |
26
|
|
|
{ |
27
|
1 |
|
use \Nette\SmartObject; |
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
|
1 |
|
$this->grid = $grid; |
50
|
1 |
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string|array $class |
54
|
|
|
* @return \Grido\Customization |
55
|
|
|
*/ |
56
|
|
|
public function setButtonClass($class) |
57
|
|
|
{ |
58
|
1 |
|
$this->buttonClass = $class; |
59
|
1 |
|
return $this; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param string|array $class |
64
|
|
|
* @return \Grido\Customization |
65
|
|
|
*/ |
66
|
|
|
public function setIconClass($class) |
67
|
|
|
{ |
68
|
1 |
|
$this->iconClass = $class; |
69
|
1 |
|
return $this; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
|
|
public function getButtonClass() |
76
|
|
|
{ |
77
|
1 |
|
return is_array($this->buttonClass) |
78
|
1 |
|
? implode(' ', $this->buttonClass) |
79
|
1 |
|
: $this->buttonClass; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param string $icon |
84
|
|
|
* @return string |
85
|
|
|
*/ |
86
|
|
|
public function getIconClass($icon = NULL) |
87
|
|
|
{ |
88
|
1 |
|
if ($icon === NULL) { |
89
|
1 |
|
$class = $this->iconClass; |
90
|
1 |
|
} else { |
91
|
1 |
|
$this->iconClass = (array) $this->iconClass; |
92
|
1 |
|
$classes = []; |
93
|
1 |
|
foreach ($this->iconClass as $fontClass) { |
94
|
1 |
|
$classes[] = "{$fontClass} {$fontClass}-{$icon}"; |
95
|
1 |
|
} |
96
|
1 |
|
$class = implode(' ', $classes); |
97
|
|
|
} |
98
|
|
|
|
99
|
1 |
|
return $class; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return array |
104
|
|
|
*/ |
105
|
|
|
public function getTemplateFiles() |
106
|
|
|
{ |
107
|
1 |
|
if (empty($this->templateFiles)) { |
108
|
1 |
|
foreach (new \DirectoryIterator(__DIR__ . '/templates') as $file) { |
109
|
1 |
|
if ($file->isFile()) { |
110
|
1 |
|
$this->templateFiles[$file->getBasename('.latte')] = realpath($file->getPathname()); |
111
|
1 |
|
} |
112
|
1 |
|
} |
113
|
1 |
|
} |
114
|
|
|
|
115
|
1 |
|
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
|
1 |
|
$this->grid->setTemplateFile($this->getTemplateFiles()[self::TEMPLATE_BOOTSTRAP]); |
135
|
1 |
|
return $this; |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|