|
1
|
|
|
<?php |
|
2
|
|
|
namespace Consolidation\OutputFormatters\StructuredData; |
|
3
|
|
|
|
|
4
|
|
|
use Consolidation\OutputFormatters\StructuredData\RestructureInterface; |
|
5
|
|
|
use Consolidation\OutputFormatters\Options\FormatterOptions; |
|
6
|
|
|
use Consolidation\OutputFormatters\StructuredData\ListDataInterface; |
|
7
|
|
|
use Consolidation\OutputFormatters\Transformations\TableTransformation; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Holds an array where each element of the array is one row, |
|
11
|
|
|
* and each row contains an associative array where the keys |
|
12
|
|
|
* are the field names, and the values are the field data. |
|
13
|
|
|
* |
|
14
|
|
|
* It is presumed that every row contains the same keys. |
|
15
|
|
|
*/ |
|
16
|
|
|
abstract class AbstractStructuredList extends AbstractListData implements RestructureInterface, RenderCellCollectionInterface |
|
17
|
|
|
{ |
|
18
|
|
|
use RenderCellCollectionTrait; |
|
19
|
|
|
|
|
20
|
|
|
public function __construct($data) |
|
21
|
|
|
{ |
|
22
|
|
|
parent::__construct($data); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
abstract public function restructure(FormatterOptions $options); |
|
26
|
|
|
|
|
27
|
|
|
protected function createTableTransformation($data, $options) |
|
28
|
|
|
{ |
|
29
|
|
|
$defaults = $this->defaultOptions(); |
|
30
|
|
|
$fieldLabels = $this->getReorderedFieldLabels($data, $options, $defaults); |
|
31
|
|
|
|
|
32
|
|
|
$tableTransformer = $this->instantiateTableTransformation($data, $fieldLabels, $options->get(FormatterOptions::ROW_LABELS, $defaults)); |
|
33
|
|
|
if ($options->get(FormatterOptions::LIST_ORIENTATION, $defaults)) { |
|
34
|
|
|
$tableTransformer->setLayout(TableTransformation::LIST_LAYOUT); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
return $tableTransformer; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
protected function instantiateTableTransformation($data, $fieldLabels, $rowLabels) |
|
41
|
|
|
{ |
|
42
|
|
|
return new TableTransformation($data, $fieldLabels, $rowLabels); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
protected function defaultOptions() |
|
46
|
|
|
{ |
|
47
|
|
|
return [ |
|
48
|
|
|
FormatterOptions::ROW_LABELS => [], |
|
49
|
|
|
FormatterOptions::DEFAULT_FIELDS => [], |
|
50
|
|
|
] + parent::defaultOptions(); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|