forked from Tactics/TableBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColumn.php
130 lines (108 loc) · 2.69 KB
/
Column.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
namespace Tactics\TableBundle;
use Symfony\Component\OptionsResolver\OptionsResolver;
class Column implements ColumnInterface
{
/**
* @var $header ColumnHeaderInterface
*/
protected $header;
/**
* @var $name string The name of the column.
*/
protected $name;
/**
* @var $options array The column options.
*/
protected $options;
/**
* @var $extensions The type extensions
*/
protected $extensions;
/**
* {@inheritdoc}
*/
public function __construct($name, ColumnHeader $header, array $options = array(), $extensions = array())
{
$this->name = $name;
$this->header = $header;
$this->extensions = $extensions;
$resolver = new OptionsResolver();
$this->configureOptions($resolver);
foreach($this->extensions as $extension)
{
$extension->configureOptions($resolver);
}
$this->options = $resolver->resolve($options);
$this->header->setColumn($this);
}
/**
* @return ColumnHeader
*/
public function getHeader()
{
return $this->header;
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->name;
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'default';
}
/**
* {@inheritdoc}
*/
public function getCell($row)
{
$cell = isset($row[$this->getName()]) ? $row[$this->getName()] : array();
if (! is_array($cell))
{
$cell = array('value' => $cell);
}
return array_merge(array('value' => null), $cell, $this->getOptions());
}
/**
* {@inheritdoc}
*/
public function executeExtensions(array &$cell, array &$row)
{
foreach($this->extensions as $extension)
{
$extension->execute($this, $row, $cell);
}
}
/**
* {@inheritdoc}
*/
public function getOptions()
{
return $this->options;
}
public function getOption($name)
{
return isset($this->options[$name]) ? $this->options[$name] : null;
}
public function setOption($name, $value)
{
$this->options[$name] = $value;
}
/**
* Sets the default options for this table.
*
* @param OptionsResolver $resolver The resolver for the options.
*/
public function configureOptions(OptionsResolver $resolver)
{
// todo: put this stuff somewhere propelTableBuilder related
$resolver->setDefined(array('method', 'default_value', 'raw', 'hidden'));
$resolver->setDefaults(array('raw' => false, 'hidden' => false));
}
}