1 | <?php |
||
40 | 1 | class Control extends Application\UI\Control |
|
41 | { |
||
42 | /** |
||
43 | * @var string |
||
44 | */ |
||
45 | private $templateFile; |
||
46 | |||
47 | /** |
||
48 | * @var Storage\IStorage |
||
49 | */ |
||
50 | private $storage; |
||
51 | |||
52 | /** |
||
53 | * @var Localization\ITranslator |
||
54 | */ |
||
55 | private $translator; |
||
56 | |||
57 | /** |
||
58 | * @var bool |
||
59 | */ |
||
60 | private $useTitle = FALSE; |
||
61 | |||
62 | /** |
||
63 | * @var bool |
||
64 | */ |
||
65 | private $useOverlay = FALSE; |
||
66 | |||
67 | /** |
||
68 | * @param Localization\ITranslator $translator |
||
69 | * |
||
70 | * @return void |
||
71 | */ |
||
72 | public function injectTranslator(Localization\ITranslator $translator = NULL) |
||
76 | |||
77 | /** |
||
78 | * @param NULL|string $templateFile |
||
79 | * @param Storage\IStorage $storage |
||
80 | * |
||
81 | * @throws Exceptions\FileNotFoundException |
||
82 | */ |
||
83 | public function __construct( |
||
84 | $templateFile = NULL, |
||
85 | Storage\IStorage $storage |
||
86 | ) { |
||
87 | 1 | parent::__construct(); |
|
88 | |||
89 | 1 | if ($templateFile !== NULL) { |
|
90 | $this->setTemplateFile($templateFile); |
||
91 | } |
||
92 | |||
93 | 1 | $this->storage = $storage; |
|
94 | 1 | } |
|
95 | |||
96 | /** |
||
97 | * @param \Nette\ComponentModel\IComponent |
||
98 | * |
||
99 | * @return void |
||
100 | */ |
||
101 | public function attached($presenter) |
||
107 | |||
108 | /** |
||
109 | * @return void |
||
110 | */ |
||
111 | public function enableTitle() |
||
115 | |||
116 | /** |
||
117 | * @return void |
||
118 | */ |
||
119 | public function disableTitle() |
||
123 | |||
124 | /** |
||
125 | * @return void |
||
126 | */ |
||
127 | public function enableOverlay() |
||
131 | |||
132 | /** |
||
133 | * @return void |
||
134 | */ |
||
135 | public function disableOverlay() |
||
139 | |||
140 | /** |
||
141 | * Prepare component for rendering |
||
142 | * |
||
143 | * @return void |
||
144 | */ |
||
145 | public function beforeRender() |
||
171 | |||
172 | /** |
||
173 | * Render control |
||
174 | * |
||
175 | * @return void |
||
176 | */ |
||
177 | public function render() |
||
178 | { |
||
179 | // Check if control has template |
||
180 | 1 | if ($this->template instanceof Nette\Bridges\ApplicationLatte\Template) { |
|
181 | 1 | $this->beforeRender(); |
|
182 | |||
183 | // Render component template |
||
184 | 1 | $this->template->render(); |
|
185 | |||
186 | } else { |
||
187 | throw new Exceptions\InvalidStateException('Flash messages control is without template.'); |
||
188 | } |
||
189 | 1 | } |
|
190 | |||
191 | /** |
||
192 | * Change default control template path |
||
193 | * |
||
194 | * @param string $templateFile |
||
195 | * |
||
196 | * @return void |
||
197 | * |
||
198 | * @throws Exceptions\FileNotFoundException |
||
199 | */ |
||
200 | public function setTemplateFile($templateFile) |
||
201 | { |
||
202 | // Check if template file exists... |
||
203 | 1 | if (!is_file($templateFile)) { |
|
204 | // Get component actual dir |
||
205 | 1 | $dir = dirname($this->getReflection()->getFileName()); |
|
206 | |||
207 | 1 | $templateName = preg_replace('/.latte/', '', $templateFile); |
|
208 | |||
209 | // ...check if extension template is used |
||
210 | 1 | if (is_file($dir . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . $templateName . DIRECTORY_SEPARATOR . 'default.latte')) { |
|
211 | 1 | $templateFile = $dir . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . $templateName . DIRECTORY_SEPARATOR . 'default.latte'; |
|
212 | |||
213 | } else { |
||
214 | // ...if not throw exception |
||
215 | 1 | throw new Exceptions\FileNotFoundException(sprintf('Template file "%s" was not found.', $templateFile)); |
|
216 | } |
||
217 | } |
||
218 | |||
219 | 1 | $this->templateFile = $templateFile; |
|
220 | 1 | } |
|
221 | |||
222 | /** |
||
223 | * @param Localization\ITranslator $translator |
||
224 | * |
||
225 | * @return void |
||
226 | */ |
||
227 | public function setTranslator(Localization\ITranslator $translator) |
||
228 | { |
||
229 | $this->translator = $translator; |
||
230 | } |
||
231 | |||
232 | /** |
||
233 | * @return Localization\ITranslator|null |
||
234 | */ |
||
235 | public function getTranslator() |
||
243 | } |
||
244 |