1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\AdminListBundle\AdminList; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\PropertyAccess\PropertyAccess; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Field |
9
|
|
|
*/ |
10
|
|
|
class Field |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
private $header; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
private $name; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var bool |
24
|
|
|
*/ |
25
|
|
|
private $sort; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string|null |
29
|
|
|
*/ |
30
|
|
|
private $template; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var FieldAlias|null |
34
|
|
|
*/ |
35
|
|
|
private $alias; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param string $name The name |
39
|
|
|
* @param string $header The header |
40
|
|
|
* @param bool $sort Sort or not |
41
|
|
|
* @param string $template The template |
|
|
|
|
42
|
|
|
* @param FieldAlias $alias The alias |
|
|
|
|
43
|
|
|
*/ |
44
|
20 |
|
public function __construct($name, $header, $sort = false, $template = null, FieldAlias $alias = null) |
45
|
|
|
{ |
46
|
20 |
|
$this->name = $name; |
47
|
20 |
|
$this->header = $header; |
48
|
20 |
|
$this->sort = $sort; |
49
|
20 |
|
$this->template = $template; |
50
|
20 |
|
$this->alias = $alias; |
51
|
20 |
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return string |
55
|
|
|
*/ |
56
|
5 |
|
public function getName() |
57
|
|
|
{ |
58
|
5 |
|
return $this->name; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return string |
63
|
|
|
*/ |
64
|
3 |
|
public function getHeader() |
65
|
|
|
{ |
66
|
3 |
|
return $this->header; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return bool |
71
|
|
|
*/ |
72
|
5 |
|
public function isSortable() |
73
|
|
|
{ |
74
|
5 |
|
return $this->sort; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return string |
|
|
|
|
79
|
|
|
*/ |
80
|
3 |
|
public function getTemplate() |
81
|
|
|
{ |
82
|
3 |
|
return $this->template; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return FieldAlias|null |
87
|
|
|
*/ |
88
|
2 |
|
public function getAlias() |
89
|
|
|
{ |
90
|
2 |
|
return $this->alias; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return bool |
95
|
|
|
*/ |
96
|
1 |
|
public function hasAlias() |
97
|
|
|
{ |
98
|
1 |
|
if (\is_null($this->alias)) { |
99
|
1 |
|
return false; |
100
|
|
|
} |
101
|
|
|
|
102
|
1 |
|
return true; |
103
|
|
|
} |
104
|
|
|
|
105
|
1 |
|
public function getAliasObj($item) |
106
|
|
|
{ |
107
|
1 |
|
$relation = $this->alias->getRelation(); |
108
|
1 |
|
$accessor = PropertyAccess::createPropertyAccessor(); |
109
|
|
|
|
110
|
1 |
|
if ($accessor->isReadable($item, $relation)) { |
111
|
1 |
|
$item = $accessor->getValue($item, $relation); |
112
|
|
|
} |
113
|
|
|
|
114
|
1 |
|
return $item; |
115
|
|
|
} |
116
|
|
|
|
117
|
1 |
|
public function getColumnName($column) |
|
|
|
|
118
|
|
|
{ |
119
|
1 |
|
$abbr = $this->alias->getAbbr().'.'; |
120
|
|
|
|
121
|
1 |
|
if (strpos($column, $abbr) !== false) { |
122
|
1 |
|
$column = str_replace($abbr, '', $column); |
123
|
|
|
} else { |
124
|
1 |
|
throw new \Exception(" '".$abbr."' can not be found in your column name: '".$column."' "); |
125
|
|
|
} |
126
|
|
|
|
127
|
1 |
|
return $column; |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.