|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (c) 2015 ublaboo <[email protected]> |
|
5
|
|
|
* @author Pavel Janda <[email protected]> |
|
6
|
|
|
* @package Ublaboo |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Ublaboo\DataGrid; |
|
10
|
|
|
|
|
11
|
|
|
use Nette; |
|
12
|
|
|
use LeanMapper; |
|
13
|
|
|
use DibiRow; |
|
14
|
|
|
|
|
15
|
|
|
class Row extends Nette\Object |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var DataGrid |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $datagrid; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var mixed |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $item; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var string |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $primary_key; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var mixed |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $id; |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param mixed $item |
|
41
|
|
|
* @param string $primary_key |
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct(DataGrid $datagrid, $item, $primary_key) |
|
44
|
|
|
{ |
|
45
|
|
|
$this->datagrid = $datagrid; |
|
46
|
|
|
$this->item = $item; |
|
47
|
|
|
$this->primary_key = $primary_key; |
|
48
|
|
|
|
|
49
|
|
|
$this->id = is_object($item) ? $item->{$primary_key} : $item[$primary_key]; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Get id value of item |
|
55
|
|
|
* @return mixed |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getId() |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->id; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
public function getValue($key) |
|
64
|
|
|
{ |
|
65
|
|
|
if ($this->item instanceof LeanMapper\Entity) { |
|
|
|
|
|
|
66
|
|
|
return $this->getEntityProperty($this->item, $key); |
|
67
|
|
|
|
|
68
|
|
|
} else if ($this->item instanceof DibiRow) { |
|
|
|
|
|
|
69
|
|
|
return $this->item->{$key}; |
|
70
|
|
|
|
|
71
|
|
|
} else if ($this->item instanceof Nette\Database\Table\ActiveRow) { |
|
|
|
|
|
|
72
|
|
|
return $this->item->{$key}; |
|
73
|
|
|
|
|
74
|
|
|
} else if (is_array($this->item)) { |
|
75
|
|
|
return $this->item[$key]; |
|
76
|
|
|
|
|
77
|
|
|
} else { |
|
78
|
|
|
/** |
|
79
|
|
|
* Doctrine entity |
|
80
|
|
|
*/ |
|
81
|
|
|
return $this->getEntityProperty($this->item, $key); |
|
82
|
|
|
|
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
public function getEntityProperty($item, $key) |
|
88
|
|
|
{ |
|
89
|
|
|
$properties = explode('.', $key); |
|
90
|
|
|
$value = $item; |
|
91
|
|
|
|
|
92
|
|
|
while ($property = array_shift($properties)) { |
|
93
|
|
|
if (!isset($value->{$property})) { |
|
94
|
|
|
if ($this->datagrid->strict_entity_property) { |
|
95
|
|
|
throw new DataGridException(sprintf( |
|
96
|
|
|
'Target Property [%s] is not an object or is empty, trying to get [%s]', |
|
97
|
|
|
$value, str_replace('.', '->', $key) |
|
98
|
|
|
)); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
return NULL; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
$value = $value->{$property}; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
return $value; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Get original item |
|
113
|
|
|
* @return mixed |
|
114
|
|
|
*/ |
|
115
|
|
|
public function getItem() |
|
116
|
|
|
{ |
|
117
|
|
|
return $this->item; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
|
|
121
|
|
|
public function hasGroupAction() |
|
122
|
|
|
{ |
|
123
|
|
|
$condition = $this->datagrid->getRowCondition('group_action'); |
|
124
|
|
|
|
|
125
|
|
|
return $condition ? $condition($this->item) : TRUE; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
|
|
129
|
|
|
public function hasAction($key) |
|
130
|
|
|
{ |
|
131
|
|
|
$condition = $this->datagrid->getRowCondition('action', $key); |
|
132
|
|
|
|
|
133
|
|
|
return $condition ? $condition($this->item) : TRUE; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
} |
|
137
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.