1 | <?php |
||
13 | class ActiveRow implements IteratorAggregate, IRow |
||
14 | { |
||
15 | /** @var NetteDatabaseActiveRow */ |
||
16 | protected $record; |
||
17 | |||
18 | /** @var Structure */ |
||
19 | protected $structure; |
||
20 | |||
21 | /** |
||
22 | * @param NetteDatabaseActiveRow $record |
||
23 | * @param Structure $structure |
||
24 | */ |
||
25 | 46 | public function __construct(NetteDatabaseActiveRow $record, Structure $structure) |
|
30 | |||
31 | /** |
||
32 | * @param string $name |
||
33 | * @return mixed|ActiveRow |
||
34 | */ |
||
35 | 16 | public function __get($name) |
|
40 | |||
41 | /** |
||
42 | * @return NetteDatabaseActiveRow |
||
43 | */ |
||
44 | public function getRecord() |
||
48 | |||
49 | /** |
||
50 | * @return NetteDatabaseSelection |
||
51 | */ |
||
52 | public function getTable() |
||
56 | |||
57 | /** |
||
58 | * @param NetteDatabaseSelection $selection |
||
59 | */ |
||
60 | public function setTable(NetteDatabaseSelection $selection) |
||
64 | |||
65 | /**********************************************************************\ |
||
66 | * Wrapper function |
||
67 | \**********************************************************************/ |
||
68 | |||
69 | /** |
||
70 | * @return string |
||
71 | */ |
||
72 | public function __toString() |
||
76 | |||
77 | /** |
||
78 | * @return array |
||
79 | */ |
||
80 | 6 | public function toArray() |
|
84 | |||
85 | /** |
||
86 | * @param bool|true $need |
||
87 | * @return mixed |
||
88 | */ |
||
89 | 2 | public function getPrimary($need = true) |
|
93 | |||
94 | /** |
||
95 | * @param bool|true $need |
||
96 | * @return string |
||
97 | */ |
||
98 | 2 | public function getSignature($need = true) |
|
102 | |||
103 | /** |
||
104 | * @param array|\Traversable $data |
||
105 | * @return bool |
||
106 | */ |
||
107 | 6 | public function update($data) |
|
111 | |||
112 | /** |
||
113 | * @return int |
||
114 | */ |
||
115 | 4 | public function delete() |
|
119 | |||
120 | /** |
||
121 | * Returns referenced row |
||
122 | * @param string $key |
||
123 | * @param string $throughColumn |
||
124 | * @return ActiveRow|null |
||
125 | */ |
||
126 | 6 | public function ref($key, $throughColumn = null) |
|
131 | |||
132 | |||
133 | /** |
||
134 | * Returns referencing rows |
||
135 | * @param string $key |
||
136 | * @param string $throughColumn |
||
137 | * @return mixed |
||
138 | */ |
||
139 | 4 | public function related($key, $throughColumn = null) |
|
144 | |||
145 | /**********************************************************************\ |
||
146 | * IteratorAggregate interface |
||
147 | \**********************************************************************/ |
||
148 | |||
149 | /** |
||
150 | * @return ArrayIterator |
||
151 | */ |
||
152 | 2 | public function getIterator() |
|
156 | |||
157 | /**********************************************************************\ |
||
158 | * ArrayAccess interface |
||
159 | \**********************************************************************/ |
||
160 | |||
161 | /** |
||
162 | * Returns value of column |
||
163 | * @param string $key column name |
||
164 | * @return string |
||
165 | */ |
||
166 | 6 | public function offsetGet($key) |
|
170 | |||
171 | /** |
||
172 | * Tests if column exists |
||
173 | * @param string $key column name |
||
174 | * @return bool |
||
175 | */ |
||
176 | 2 | public function offsetExists($key) |
|
180 | |||
181 | /** |
||
182 | * Stores value in column |
||
183 | * @param string $key column name |
||
184 | * @param string $value |
||
185 | * @throws DeprecatedException |
||
186 | */ |
||
187 | 2 | public function offsetSet($key, $value) |
|
191 | |||
192 | /** |
||
193 | * Removes column from data |
||
194 | * @param string $key column name |
||
195 | * @throws DeprecatedException |
||
196 | */ |
||
197 | 2 | public function offsetUnset($key) |
|
201 | |||
202 | /**********************************************************************\ |
||
203 | * Extend methods |
||
204 | \**********************************************************************/ |
||
205 | |||
206 | /** |
||
207 | * Returns mm referencing rows |
||
208 | * @param Selection $selection |
||
209 | * @param string $ref |
||
210 | * @param string $refPrimary |
||
211 | * @return array |
||
212 | */ |
||
213 | 4 | protected function mmRelated(Selection $selection, $ref, $refPrimary = 'id') |
|
221 | |||
222 | /**********************************************************************\ |
||
223 | * Build methods |
||
224 | \**********************************************************************/ |
||
225 | |||
226 | /** |
||
227 | * Prepare one record |
||
228 | * @param IRow $row |
||
229 | * @return ActiveRow |
||
230 | */ |
||
231 | 8 | protected function prepareRecord(IRow $row) |
|
236 | |||
237 | /** |
||
238 | * Prepare selection |
||
239 | * @param NetteDatabaseSelection $selection |
||
240 | * @return Selection |
||
241 | */ |
||
242 | 4 | protected function prepareSelection(NetteDatabaseSelection $selection) |
|
247 | } |
||
248 |