1 | <?php |
||
16 | class ActiveRow implements IteratorAggregate, IRow |
||
17 | { |
||
18 | /** @var NetteDatabaseActiveRow */ |
||
19 | protected $record; |
||
20 | |||
21 | /** @var Structure */ |
||
22 | protected $structure; |
||
23 | |||
24 | 38 | /** @var ActiveRow|null */ |
|
25 | protected $referencingRecord; |
||
26 | 38 | ||
27 | 38 | /** |
|
28 | 38 | * @param NetteDatabaseActiveRow $record |
|
29 | * @param Structure $structure |
||
30 | */ |
||
31 | public function __construct(NetteDatabaseActiveRow $record, Structure $structure) |
||
36 | 16 | ||
37 | 14 | /** |
|
38 | * @param string $name |
||
39 | * @return mixed|ActiveRow |
||
40 | */ |
||
41 | public function __get($name) |
||
46 | |||
47 | /** |
||
48 | * @return NetteDatabaseActiveRow |
||
49 | */ |
||
50 | public function getRecord(): NetteDatabaseActiveRow |
||
54 | |||
55 | /** |
||
56 | * @return NetteDatabaseSelection |
||
57 | */ |
||
58 | public function getTable(): NetteDatabaseSelection |
||
62 | |||
63 | /** |
||
64 | * @param NetteDatabaseSelection $selection |
||
65 | * @throws ActiveRowException |
||
66 | */ |
||
67 | public function setTable(NetteDatabaseSelection $selection): void |
||
71 | |||
72 | /**********************************************************************\ |
||
73 | * Wrapper function |
||
74 | \**********************************************************************/ |
||
75 | |||
76 | /** |
||
77 | * @return string |
||
78 | */ |
||
79 | 6 | public function __toString(): string |
|
83 | |||
84 | /** |
||
85 | * @return array |
||
86 | */ |
||
87 | public function toArray(): array |
||
91 | |||
92 | /** |
||
93 | * @param bool|true $need |
||
94 | * @return mixed |
||
95 | */ |
||
96 | public function getPrimary($need = true) |
||
100 | |||
101 | /** |
||
102 | * @param bool|true $need |
||
103 | * @return string |
||
104 | */ |
||
105 | public function getSignature($need = true): string |
||
109 | |||
110 | /** |
||
111 | * @param array|\Traversable $data |
||
112 | * @return bool |
||
113 | */ |
||
114 | 2 | public function update($data): bool |
|
118 | |||
119 | /** |
||
120 | * @return int |
||
121 | */ |
||
122 | public function delete(): int |
||
126 | |||
127 | 6 | /** |
|
128 | 6 | * Returns referenced row |
|
129 | * @param string $key |
||
130 | * @param string $throughColumn |
||
131 | * @return ActiveRow|null |
||
132 | */ |
||
133 | public function ref($key, $throughColumn = null): ?ActiveRow |
||
144 | |||
145 | /** |
||
146 | * Returns referencing rows |
||
147 | * @param string $key |
||
148 | * @param string $throughColumn |
||
149 | * @return Selection |
||
150 | */ |
||
151 | 4 | public function related($key, $throughColumn = null): ?Selection |
|
156 | |||
157 | /**********************************************************************\ |
||
158 | * IteratorAggregate interface |
||
159 | \**********************************************************************/ |
||
160 | |||
161 | /** |
||
162 | * @return ArrayIterator |
||
163 | */ |
||
164 | public function getIterator(): ArrayIterator |
||
168 | |||
169 | /**********************************************************************\ |
||
170 | * ArrayAccess interface |
||
171 | \**********************************************************************/ |
||
172 | |||
173 | /** |
||
174 | * Returns value of column |
||
175 | 2 | * @param string $key column name |
|
176 | * @return mixed |
||
177 | 2 | */ |
|
178 | public function offsetGet($key) |
||
183 | |||
184 | /** |
||
185 | * Tests if column exists |
||
186 | 2 | * @param string $key column name |
|
187 | * @return bool |
||
188 | 2 | */ |
|
189 | public function offsetExists($key): bool |
||
193 | |||
194 | /** |
||
195 | * Stores value in column |
||
196 | 2 | * @param string $key column name |
|
197 | * @param string $value |
||
198 | 2 | * @throws DeprecatedException |
|
199 | */ |
||
200 | public function offsetSet($key, $value): void |
||
204 | |||
205 | /** |
||
206 | * Removes column from data |
||
207 | * @param string $key column name |
||
208 | * @throws DeprecatedException |
||
209 | */ |
||
210 | public function offsetUnset($key): void |
||
214 | 4 | ||
215 | 4 | /**********************************************************************\ |
|
216 | 4 | * Extend methods |
|
217 | 2 | \**********************************************************************/ |
|
218 | 4 | ||
219 | /** |
||
220 | * @param ActiveRow $row |
||
221 | */ |
||
222 | public function setReferencingRecord(ActiveRow $row): void |
||
226 | |||
227 | /** |
||
228 | * @return null|ActiveRow |
||
229 | */ |
||
230 | 8 | public function getReferencingRecord(): ?ActiveRow |
|
234 | |||
235 | /** |
||
236 | * Returns mm referencing rows |
||
237 | * @param Selection $selection |
||
238 | * @param string $ref |
||
239 | * @param string $refPrimary |
||
240 | * @return array |
||
241 | 4 | */ |
|
242 | protected function mmRelated(Selection $selection, string $ref, string $refPrimary = 'id'): array |
||
250 | |||
251 | /**********************************************************************\ |
||
252 | * Build methods |
||
253 | \**********************************************************************/ |
||
254 | |||
255 | /** |
||
256 | * Prepare one record |
||
257 | * @param IRow $row |
||
258 | * @return ActiveRow |
||
259 | */ |
||
260 | protected function prepareRecord(IRow $row): ActiveRow |
||
265 | |||
266 | /** |
||
267 | * Prepare selection |
||
268 | * @param NetteDatabaseSelection $selection |
||
269 | * @return Selection |
||
270 | */ |
||
271 | protected function prepareSelection(NetteDatabaseSelection $selection): Selection |
||
276 | } |
||
277 |