1 | <?php |
||
12 | class ActiveRow implements IteratorAggregate, IRow |
||
13 | { |
||
14 | /** @var NetteDatabaseActiveRow */ |
||
15 | protected $record; |
||
16 | |||
17 | /** @var Structure */ |
||
18 | protected $structure; |
||
19 | |||
20 | /** |
||
21 | * @param NetteDatabaseActiveRow $record |
||
22 | * @param Structure $structure |
||
23 | */ |
||
24 | 36 | public function __construct(NetteDatabaseActiveRow $record, Structure $structure) |
|
29 | |||
30 | /** |
||
31 | * @param string $name |
||
32 | * @return mixed|NetteDatabaseActiveRow |
||
33 | */ |
||
34 | 14 | public function __get($name) |
|
39 | |||
40 | /** |
||
41 | * @return NetteDatabaseActiveRow |
||
42 | */ |
||
43 | public function getRecord() |
||
44 | { |
||
45 | return $this->record; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * @return NetteDatabaseSelection |
||
50 | */ |
||
51 | public function getTable() |
||
52 | { |
||
53 | return $this->record->getTable(); |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * @param NetteDatabaseSelection $selection |
||
58 | */ |
||
59 | public function setTable(NetteDatabaseSelection $selection) |
||
60 | { |
||
61 | trigger_error('Internal IRow interface method', E_USER_NOTICE); |
||
62 | } |
||
63 | |||
64 | /**********************************************************************\ |
||
65 | * Wrapper function |
||
66 | \**********************************************************************/ |
||
67 | |||
68 | /** |
||
69 | * @return string |
||
70 | */ |
||
71 | public function __toString() |
||
72 | { |
||
73 | return (string) $this->record; |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * @return array |
||
78 | */ |
||
79 | 6 | public function toArray() |
|
83 | |||
84 | /** |
||
85 | * @param bool|true $need |
||
86 | * @return mixed |
||
87 | */ |
||
88 | 2 | public function getPrimary($need = true) |
|
92 | |||
93 | /** |
||
94 | * @param bool|true $need |
||
95 | * @return string |
||
96 | */ |
||
97 | 2 | public function getSignature($need = true) |
|
101 | |||
102 | /** |
||
103 | * @param array|\Traversable $data |
||
104 | * @return bool |
||
105 | */ |
||
106 | 2 | public function update($data) |
|
110 | |||
111 | /** |
||
112 | * @return int |
||
113 | */ |
||
114 | 2 | public function delete() |
|
118 | |||
119 | /** |
||
120 | * Returns referenced row |
||
121 | * @param string $key |
||
122 | * @param string $throughColumn |
||
123 | * @return IRow|null |
||
124 | */ |
||
125 | 6 | public function ref($key, $throughColumn = null) |
|
130 | |||
131 | |||
132 | /** |
||
133 | * Returns referencing rows |
||
134 | * @param string $key |
||
135 | * @param string $throughColumn |
||
136 | * @return mixed |
||
137 | */ |
||
138 | 4 | public function related($key, $throughColumn = null) |
|
143 | |||
144 | /**********************************************************************\ |
||
145 | * IteratorAggregate interface |
||
146 | \**********************************************************************/ |
||
147 | |||
148 | /** |
||
149 | * @return ArrayIterator |
||
150 | */ |
||
151 | 2 | public function getIterator() |
|
155 | |||
156 | /**********************************************************************\ |
||
157 | * ArrayAccess interface |
||
158 | \**********************************************************************/ |
||
159 | |||
160 | /** |
||
161 | * Returns value of column |
||
162 | * @param string $key column name |
||
163 | * @return string |
||
164 | */ |
||
165 | 2 | public function offsetGet($key) |
|
169 | |||
170 | /** |
||
171 | * Tests if column exists |
||
172 | * @param string $key column name |
||
173 | * @return bool |
||
174 | */ |
||
175 | 2 | public function offsetExists($key) |
|
179 | |||
180 | /** |
||
181 | * Stores value in column |
||
182 | * @param string $key column name |
||
183 | * @param string $value |
||
184 | * @throws DeprecatedException |
||
185 | */ |
||
186 | 2 | public function offsetSet($key, $value) |
|
190 | |||
191 | /** |
||
192 | * Removes column from data |
||
193 | * @param string $key column name |
||
194 | * @throws DeprecatedException |
||
195 | */ |
||
196 | 2 | public function offsetUnset($key) |
|
200 | |||
201 | /**********************************************************************\ |
||
202 | * Extend methods |
||
203 | \**********************************************************************/ |
||
204 | |||
205 | /** |
||
206 | * Returns mm referencing rows |
||
207 | * @param Selection $selection |
||
208 | * @param string $ref |
||
209 | * @param string $refPrimary |
||
210 | * @return array |
||
211 | */ |
||
212 | 4 | protected function mmRelated(Selection $selection, $ref, $refPrimary = 'id') |
|
213 | { |
||
214 | 4 | $result = []; |
|
215 | 4 | foreach ($selection as $row) { |
|
216 | 4 | $result[$row->ref($ref)->$refPrimary] = $row->ref($ref); |
|
217 | } |
||
218 | 4 | return $result; |
|
219 | } |
||
220 | |||
221 | /**********************************************************************\ |
||
222 | * Build methods |
||
223 | \**********************************************************************/ |
||
224 | |||
225 | /** |
||
226 | * Prepare one record |
||
227 | * @param IRow $row |
||
228 | * @return mixed |
||
229 | */ |
||
230 | 6 | protected function prepareRecord(IRow $row) |
|
235 | |||
236 | /** |
||
237 | * Prepare selection |
||
238 | * @param NetteDatabaseSelection $selection |
||
239 | * @return mixed |
||
240 | */ |
||
241 | 4 | protected function prepareSelection(NetteDatabaseSelection $selection) |
|
246 | } |
||
247 |