1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: nazarenko |
5
|
|
|
* Date: 10.02.2016 |
6
|
|
|
* Time: 18:51 |
7
|
|
|
*/ |
8
|
|
|
namespace samsoncms\api\renderable; |
9
|
|
|
|
10
|
|
|
use samsoncms\api\field\Row; |
11
|
|
|
use samsonframework\core\RenderInterface; |
12
|
|
|
use samsonframework\core\ViewInterface; |
13
|
|
|
use samsonframework\orm\QueryInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Rendereable fields table. |
17
|
|
|
* Class should be used to simplify additional field tables rendering. |
18
|
|
|
* If your additional fields table has special logic just extend this class |
19
|
|
|
* and change any ot its method. |
20
|
|
|
* |
21
|
|
|
* @see \samsoncms\api\FieldsTable This class is just a wrapper with rendering |
22
|
|
|
* |
23
|
|
|
* @package samsoncms\api\renderable |
24
|
|
|
*/ |
25
|
|
|
class FieldsTable extends \samsoncms\api\field\Table implements RenderInterface |
26
|
|
|
{ |
27
|
|
|
/** Name of the rows variable in index view */ |
28
|
|
|
const ROWS_VIEW_VARIABLE = 'rows'; |
29
|
|
|
|
30
|
|
|
/** Name of the row prefix for variable in row view */ |
31
|
|
|
const ROW_VIEW_VARIABLE = 'row'; |
32
|
|
|
|
33
|
|
|
/** @var string Index view path */ |
34
|
|
|
protected $indexView = 'index'; |
35
|
|
|
|
36
|
|
|
/** @var string Row view path */ |
37
|
|
|
protected $rowView = 'row'; |
38
|
|
|
|
39
|
|
|
/** @var ViewInterface */ |
40
|
|
|
protected $renderer; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* GeneralInfo constructor. |
44
|
|
|
* |
45
|
|
|
* @param QueryInterface $query |
46
|
|
|
* @param ViewInterface $renderer |
47
|
|
|
* @param int[] $navigationID Collection of entity navigation identifiers |
48
|
|
|
* @param int $entityID Entity identifier |
49
|
|
|
* @param string|null $locale Table localization |
50
|
|
|
*/ |
51
|
|
|
public function __construct(QueryInterface $query, ViewInterface $renderer, $navigationID, $entityID, $locale = null) |
52
|
|
|
{ |
53
|
|
|
// Store renderer |
54
|
|
|
$this->renderer = $renderer; |
55
|
|
|
|
56
|
|
|
parent::__construct($query, $navigationID, $entityID, $locale); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Render table row. |
61
|
|
|
* |
62
|
|
|
* @param Row $row Collection of column values. |
63
|
|
|
* |
64
|
|
|
* @return string Rendered HTML |
65
|
|
|
*/ |
66
|
|
|
public function renderRow(Row $row) |
67
|
|
|
{ |
68
|
|
|
return $this->renderer->view($this->rowView)->set(self::ROW_VIEW_VARIABLE, $row)->output(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Render table row. |
73
|
|
|
* |
74
|
|
|
* @param array $items Collection of rendered rows. |
75
|
|
|
* |
76
|
|
|
* @return string Rendered HTML |
77
|
|
|
*/ |
78
|
|
|
public function renderIndex($items) |
79
|
|
|
{ |
80
|
|
|
return $this->renderer->view($this->indexView) |
81
|
|
|
->set(self::ROWS_VIEW_VARIABLE, $items) |
82
|
|
|
->output(); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** @return string Rendered HTML for fields table */ |
86
|
|
|
public function render() |
87
|
|
|
{ |
88
|
|
|
$html = ''; |
89
|
|
|
foreach ($this->collection as $row) { |
90
|
|
|
$html .= $this->renderRow($row); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$html = $this->renderIndex($html); |
|
|
|
|
94
|
|
|
|
95
|
|
|
return $html; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Prepare fields table for rendering in the view. |
100
|
|
|
* |
101
|
|
|
* @param string|null $prefix Prefix to be added to view variables |
102
|
|
|
* @param array $restricted Collection of fields to be restricted |
103
|
|
|
* |
104
|
|
|
* @return array Collection of view variables for rendering |
105
|
|
|
*/ |
106
|
|
|
public function toView($prefix = null, array $restricted = array()) |
107
|
|
|
{ |
108
|
|
|
return array_diff_key(array($prefix.'html' => $this->render()), $restricted); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: