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 Nette; |
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
|
1 |
|
{ |
27
|
|
|
|
28
|
1 |
|
use Nette\SmartObject; |
29
|
|
|
|
30
|
|
|
const TEMPLATE_DEFAULT = 'default'; |
31
|
|
|
const TEMPLATE_BOOTSTRAP = 'bootstrap'; |
32
|
|
|
|
33
|
|
|
/** @var Grid */ |
34
|
|
|
protected $grid; |
35
|
|
|
|
36
|
|
|
/** @var string|array */ |
37
|
|
|
protected $buttonClass; |
38
|
|
|
|
39
|
|
|
/** @var string|array */ |
40
|
|
|
protected $iconClass; |
41
|
|
|
|
42
|
|
|
/** @var array */ |
43
|
|
|
protected $templateFiles = []; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param Grid $grid |
47
|
|
|
*/ |
48
|
|
|
public function __construct(Grid $grid) |
49
|
|
|
{ |
50
|
|
|
$this->grid = $grid; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param string|array $class |
55
|
|
|
* @return \Grido\Customization |
56
|
|
|
*/ |
57
|
|
|
public function setButtonClass($class) |
58
|
|
|
{ |
59
|
|
|
$this->buttonClass = $class; |
60
|
|
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param string|array $class |
65
|
|
|
* @return \Grido\Customization |
66
|
|
|
*/ |
67
|
|
|
public function setIconClass($class) |
68
|
|
|
{ |
69
|
|
|
$this->iconClass = $class; |
70
|
|
|
return $this; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return string |
75
|
|
|
*/ |
76
|
|
|
public function getButtonClass() |
77
|
|
|
{ |
78
|
|
|
return is_array($this->buttonClass) |
79
|
|
|
? implode(' ', $this->buttonClass) |
80
|
|
|
: $this->buttonClass; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param string $icon |
85
|
|
|
* @return string |
86
|
|
|
*/ |
87
|
|
|
public function getIconClass($icon = NULL) |
88
|
|
|
{ |
89
|
|
|
if ($icon === NULL) { |
90
|
|
|
$class = $this->iconClass; |
91
|
|
|
} else { |
92
|
|
|
$this->iconClass = (array) $this->iconClass; |
93
|
|
|
$classes = []; |
94
|
|
|
foreach ($this->iconClass as $fontClass) { |
95
|
|
|
$classes[] = "{$fontClass} {$fontClass}-{$icon}"; |
96
|
|
|
} |
97
|
|
|
$class = implode(' ', $classes); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return $class; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @return array |
105
|
|
|
*/ |
106
|
|
|
public function getTemplateFiles() |
107
|
|
|
{ |
108
|
|
|
if (empty($this->templateFiles)) { |
109
|
|
|
foreach (new \DirectoryIterator(__DIR__ . '/templates') as $file) { |
110
|
|
|
if ($file->isFile()) { |
111
|
|
|
$this->templateFiles[$file->getBasename('.latte')] = realpath($file->getPathname()); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
return $this->templateFiles; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Default theme. |
121
|
|
|
* @return \Grido\Customization |
122
|
|
|
*/ |
123
|
|
|
public function useTemplateDefault() |
124
|
|
|
{ |
125
|
|
|
$this->grid->setTemplateFile($this->getTemplateFiles()[self::TEMPLATE_DEFAULT]); |
126
|
|
|
return $this; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Twitter Bootstrap theme. |
131
|
|
|
* @return \Grido\Customization |
132
|
|
|
*/ |
133
|
|
|
public function useTemplateBootstrap() |
134
|
|
|
{ |
135
|
|
|
$this->grid->setTemplateFile($this->getTemplateFiles()[self::TEMPLATE_BOOTSTRAP]); |
136
|
|
|
return $this; |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|