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