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\Components; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Base of grid components. |
16
|
|
|
* |
17
|
|
|
* @package Grido |
18
|
|
|
* @subpackage Components |
19
|
|
|
* @author Petr Bugyík |
20
|
|
|
* |
21
|
|
|
* @property-read string $label |
22
|
|
|
* @property-read string $type |
23
|
|
|
* @property-read \Grido\Grid $grid |
24
|
|
|
* @property-read \Nette\Application\UI\Form $form |
25
|
|
|
*/ |
26
|
|
|
abstract class Component extends \Nette\Application\UI\PresenterComponent |
27
|
1 |
|
{ |
28
|
|
|
/** @var string */ |
29
|
|
|
protected $label; |
30
|
|
|
|
31
|
|
|
/** @var string */ |
32
|
|
|
protected $type; |
33
|
|
|
|
34
|
|
|
/** @var \Grido\Grid */ |
35
|
|
|
protected $grid; |
36
|
|
|
|
37
|
|
|
/** @var \Nette\Application\UI\Form */ |
38
|
|
|
protected $form; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return \Grido\Grid |
42
|
|
|
*/ |
43
|
|
|
public function getGrid() |
44
|
|
|
{ |
45
|
1 |
|
return $this->grid; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return \Nette\Application\UI\Form |
50
|
|
|
*/ |
51
|
|
|
public function getForm() |
52
|
|
|
{ |
53
|
1 |
|
if ($this->form === NULL) { |
54
|
1 |
|
$this->form = $this->grid->getComponent('form'); |
55
|
1 |
|
} |
56
|
|
|
|
57
|
1 |
|
return $this->form; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return string |
62
|
|
|
* @internal |
63
|
|
|
*/ |
64
|
|
|
public function getLabel() |
65
|
|
|
{ |
66
|
1 |
|
return $this->label; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return string |
71
|
|
|
* @internal |
72
|
|
|
*/ |
73
|
|
|
public function getType() |
74
|
|
|
{ |
75
|
1 |
|
return $this->type; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param \Grido\Grid $grid |
80
|
|
|
* @param string $name |
81
|
|
|
* @return \Nette\ComponentModel\Container |
82
|
|
|
*/ |
83
|
|
|
protected function addComponentToGrid($grid, $name) |
84
|
|
|
{ |
85
|
1 |
|
$this->grid = $grid; |
86
|
|
|
|
87
|
|
|
//check container exist |
88
|
1 |
|
$container = $this->grid->getComponent($this::ID, FALSE); |
89
|
1 |
|
if (!$container) { |
90
|
1 |
|
$this->grid->addComponent(new \Nette\ComponentModel\Container, $this::ID); |
91
|
1 |
|
$container = $this->grid->getComponent($this::ID); |
92
|
1 |
|
} |
93
|
|
|
|
94
|
1 |
|
return $container->addComponent($this, $name); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param string $message |
99
|
|
|
* @return string |
100
|
|
|
*/ |
101
|
|
|
protected function translate($message) |
102
|
|
|
{ |
103
|
1 |
|
return call_user_func_array([$this->grid->getTranslator(), "translate"], func_get_args()); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|