1 | <?php |
||
20 | class Collection extends \samsoncms\api\query\Entity |
||
21 | { |
||
22 | /** Name of the items variable in index view */ |
||
23 | const ITEMS_VIEW_VARIABLE = 'items'; |
||
24 | |||
25 | /** Name of the item prefix for variable in item view */ |
||
26 | const ITEM_VIEW_VARIABLE = 'item'; |
||
27 | |||
28 | /** @var string Block view file */ |
||
29 | protected $indexView = 'www/index'; |
||
30 | |||
31 | /** @var string Item view file */ |
||
32 | protected $itemView = 'www/item'; |
||
33 | |||
34 | /** @var string Empty view file */ |
||
35 | protected $emptyView = 'www/empty'; |
||
36 | |||
37 | /** @var ViewInterface View render object */ |
||
38 | protected $renderer; |
||
39 | |||
40 | /** @var int Count of entities on one page */ |
||
41 | protected $pageSize; |
||
42 | |||
43 | /** @var int Current page number */ |
||
44 | protected $pageNumber; |
||
45 | |||
46 | /** |
||
47 | * Collection constructor. |
||
48 | * |
||
49 | * @param QueryInterface $query Instance for querying database |
||
50 | * @param ViewInterface $renderer Instance for rendering views |
||
51 | * @param string|null $locale Localization language |
||
52 | */ |
||
53 | public function __construct(QueryInterface $query, ViewInterface $renderer, $locale = null) |
||
59 | |||
60 | /** |
||
61 | * Set index view path. |
||
62 | * @param string $indexView Index view path |
||
63 | * @return $this Chaining |
||
64 | */ |
||
65 | public function indexView($indexView) |
||
70 | |||
71 | /** |
||
72 | * Set item view path. |
||
73 | * @param string $itemView Item view path |
||
74 | * @return $this Chaining |
||
75 | */ |
||
76 | public function itemView($itemView) |
||
82 | |||
83 | /** |
||
84 | * Set empty view path. |
||
85 | * @param string $emptyView Empty view path |
||
86 | * @return $this Chaining |
||
87 | */ |
||
88 | public function emptyView($emptyView) |
||
93 | |||
94 | /** |
||
95 | * Render Entity collection item. |
||
96 | * |
||
97 | * @param Entity $item SamsonCMS entity for rendering |
||
98 | * |
||
99 | * @return string Rendered HTML |
||
100 | */ |
||
101 | public function renderItem(Entity $item) |
||
108 | |||
109 | /** |
||
110 | * Render empty collection item. |
||
111 | * |
||
112 | * @return string Rendered HTML |
||
113 | */ |
||
114 | public function renderEmpty() |
||
118 | |||
119 | /** |
||
120 | * Render Entity collection index. |
||
121 | * |
||
122 | * @param string $items Collection of rendered items |
||
123 | * |
||
124 | * @return string Rendered HTML |
||
125 | */ |
||
126 | public function renderIndex($items) |
||
132 | |||
133 | /** |
||
134 | * Set pagination for SamsonCMS query. |
||
135 | * |
||
136 | * @param int $pageNumber Result page number |
||
137 | * @param int|null $pageSize Results page size |
||
138 | * @return $this Chaining |
||
139 | */ |
||
140 | public function pager($pageNumber, $pageSize = null) |
||
147 | |||
148 | /** @return string Rendered HTML for fields table */ |
||
149 | public function render() |
||
169 | } |
||
170 |