1 | <?php |
||
15 | class ActiveRow implements IteratorAggregate, IRow |
||
16 | { |
||
17 | /** @var NetteDatabaseActiveRow */ |
||
18 | protected $record; |
||
19 | |||
20 | /** @var Structure */ |
||
21 | protected $structure; |
||
22 | |||
23 | /** |
||
24 | * @param NetteDatabaseActiveRow $record |
||
25 | * @param Structure $structure |
||
26 | */ |
||
27 | 50 | public function __construct(NetteDatabaseActiveRow $record, Structure $structure) |
|
32 | |||
33 | /** |
||
34 | * @param string $name |
||
35 | * @return mixed|ActiveRow |
||
36 | */ |
||
37 | 16 | public function __get($name) |
|
42 | |||
43 | /** |
||
44 | * @return NetteDatabaseActiveRow |
||
45 | */ |
||
46 | 2 | public function getRecord(): NetteDatabaseActiveRow |
|
50 | |||
51 | /** |
||
52 | * @return NetteDatabaseSelection |
||
53 | */ |
||
54 | 2 | public function getTable(): NetteDatabaseSelection |
|
58 | |||
59 | /** |
||
60 | * @param NetteDatabaseSelection $selection |
||
61 | * @throws ActiveRowException |
||
62 | */ |
||
63 | 2 | public function setTable(NetteDatabaseSelection $selection): void |
|
67 | |||
68 | /**********************************************************************\ |
||
69 | * Wrapper function |
||
70 | \**********************************************************************/ |
||
71 | |||
72 | /** |
||
73 | * @return string |
||
74 | */ |
||
75 | 2 | public function __toString(): string |
|
79 | |||
80 | /** |
||
81 | * @return array |
||
82 | */ |
||
83 | 6 | public function toArray(): array |
|
87 | |||
88 | /** |
||
89 | * @param bool|true $need |
||
90 | * @return mixed |
||
91 | */ |
||
92 | 2 | public function getPrimary($need = true) |
|
96 | |||
97 | /** |
||
98 | * @param bool|true $need |
||
99 | * @return string |
||
100 | */ |
||
101 | 2 | public function getSignature($need = true): string |
|
105 | |||
106 | /** |
||
107 | * @param array|\Traversable $data |
||
108 | * @return bool |
||
109 | */ |
||
110 | 6 | public function update($data): bool |
|
114 | |||
115 | /** |
||
116 | * @return int |
||
117 | */ |
||
118 | 4 | public function delete(): int |
|
122 | |||
123 | /** |
||
124 | * Returns referenced row |
||
125 | * @param string $key |
||
126 | * @param string $throughColumn |
||
127 | * @return ActiveRow|null |
||
128 | */ |
||
129 | 6 | public function ref($key, $throughColumn = null): ?ActiveRow |
|
134 | |||
135 | |||
136 | /** |
||
137 | * Returns referencing rows |
||
138 | * @param string $key |
||
139 | * @param string $throughColumn |
||
140 | * @return Selection |
||
141 | */ |
||
142 | 4 | public function related($key, $throughColumn = null): ?Selection |
|
147 | |||
148 | /**********************************************************************\ |
||
149 | * IteratorAggregate interface |
||
150 | \**********************************************************************/ |
||
151 | |||
152 | /** |
||
153 | * @return ArrayIterator |
||
154 | */ |
||
155 | 2 | public function getIterator(): ArrayIterator |
|
159 | |||
160 | /**********************************************************************\ |
||
161 | * ArrayAccess interface |
||
162 | \**********************************************************************/ |
||
163 | |||
164 | /** |
||
165 | * Returns value of column |
||
166 | * @param string $key column name |
||
167 | * @return mixed |
||
168 | */ |
||
169 | 6 | public function offsetGet($key) |
|
173 | |||
174 | /** |
||
175 | * Tests if column exists |
||
176 | * @param string $key column name |
||
177 | * @return bool |
||
178 | */ |
||
179 | 2 | public function offsetExists($key): bool |
|
183 | |||
184 | /** |
||
185 | * Stores value in column |
||
186 | * @param string $key column name |
||
187 | * @param string $value |
||
188 | * @throws DeprecatedException |
||
189 | */ |
||
190 | 2 | public function offsetSet($key, $value): void |
|
194 | |||
195 | /** |
||
196 | * Removes column from data |
||
197 | * @param string $key column name |
||
198 | * @throws DeprecatedException |
||
199 | */ |
||
200 | 2 | public function offsetUnset($key): void |
|
204 | |||
205 | /**********************************************************************\ |
||
206 | * Extend methods |
||
207 | \**********************************************************************/ |
||
208 | |||
209 | /** |
||
210 | * Returns mm referencing rows |
||
211 | * @param Selection $selection |
||
212 | * @param string $ref |
||
213 | * @param string $refPrimary |
||
214 | * @return array |
||
215 | */ |
||
216 | 4 | protected function mmRelated(Selection $selection, string $ref, string $refPrimary = 'id'): array |
|
224 | |||
225 | /**********************************************************************\ |
||
226 | * Build methods |
||
227 | \**********************************************************************/ |
||
228 | |||
229 | /** |
||
230 | * Prepare one record |
||
231 | * @param IRow $row |
||
232 | * @return ActiveRow |
||
233 | */ |
||
234 | 8 | protected function prepareRecord(IRow $row): ActiveRow |
|
239 | |||
240 | /** |
||
241 | * Prepare selection |
||
242 | * @param NetteDatabaseSelection $selection |
||
243 | * @return Selection |
||
244 | */ |
||
245 | 4 | protected function prepareSelection(NetteDatabaseSelection $selection): Selection |
|
250 | } |
||
251 |