1 | <?php |
||
12 | class ActiveRow implements ArrayAccess, IteratorAggregate |
||
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 | 12 | public function __get($name) |
|
39 | |||
40 | /** |
||
41 | * @return NetteDatabaseActiveRow |
||
42 | */ |
||
43 | public function getRecord() |
||
47 | |||
48 | /**********************************************************************\ |
||
49 | * Wrapper function |
||
50 | \**********************************************************************/ |
||
51 | |||
52 | /** |
||
53 | * @return string |
||
54 | */ |
||
55 | public function __toString() |
||
59 | |||
60 | /** |
||
61 | * @return array |
||
62 | */ |
||
63 | 6 | public function toArray() |
|
67 | |||
68 | /** |
||
69 | * @param bool|true $need |
||
70 | * @return mixed |
||
71 | */ |
||
72 | 2 | public function getPrimary($need = true) |
|
76 | |||
77 | /** |
||
78 | * @param bool|true $need |
||
79 | * @return string |
||
80 | */ |
||
81 | 2 | public function getSignature($need = true) |
|
85 | |||
86 | /** |
||
87 | * @param array|\Traversable $data |
||
88 | * @return bool |
||
89 | */ |
||
90 | 2 | public function update($data) |
|
94 | |||
95 | /** |
||
96 | * @return int |
||
97 | */ |
||
98 | 2 | public function delete() |
|
102 | |||
103 | /** |
||
104 | * Returns referenced row |
||
105 | * @param string $key |
||
106 | * @param string $throughColumn |
||
107 | * @return IRow|null |
||
108 | */ |
||
109 | 6 | public function ref($key, $throughColumn = null) |
|
114 | |||
115 | |||
116 | /** |
||
117 | * Returns referencing rows |
||
118 | * @param string $key |
||
119 | * @param string $throughColumn |
||
120 | * @return mixed |
||
121 | */ |
||
122 | 4 | public function related($key, $throughColumn = null) |
|
127 | |||
128 | /**********************************************************************\ |
||
129 | * IteratorAggregate interface |
||
130 | \**********************************************************************/ |
||
131 | |||
132 | /** |
||
133 | * @return ArrayIterator |
||
134 | */ |
||
135 | 2 | public function getIterator() |
|
139 | |||
140 | /**********************************************************************\ |
||
141 | * ArrayAccess interface |
||
142 | \**********************************************************************/ |
||
143 | |||
144 | /** |
||
145 | * Stores value in column |
||
146 | * @param string $key column name |
||
147 | * @param string $value |
||
148 | */ |
||
149 | 2 | public function offsetSet($key, $value) |
|
153 | |||
154 | /** |
||
155 | * Returns value of column |
||
156 | * @param string $key column name |
||
157 | * @return string |
||
158 | */ |
||
159 | 2 | public function offsetGet($key) |
|
163 | |||
164 | /** |
||
165 | * Tests if column exists |
||
166 | * @param string $key column name |
||
167 | * @return bool |
||
168 | */ |
||
169 | 2 | public function offsetExists($key) |
|
173 | |||
174 | /** |
||
175 | * Removes column from data |
||
176 | * @param string $key column name |
||
177 | */ |
||
178 | 2 | public function offsetUnset($key) |
|
182 | |||
183 | /**********************************************************************\ |
||
184 | * Extend methods |
||
185 | \**********************************************************************/ |
||
186 | |||
187 | /** |
||
188 | * Returns mm referencing rows |
||
189 | * @param Selection $selection |
||
190 | * @param string $ref |
||
191 | * @param string $refPrimary |
||
192 | * @return array |
||
193 | */ |
||
194 | 4 | protected function mmRelated(Selection $selection, $ref, $refPrimary = 'id') |
|
202 | |||
203 | /**********************************************************************\ |
||
204 | * Build methods |
||
205 | \**********************************************************************/ |
||
206 | |||
207 | /** |
||
208 | * Prepare one record |
||
209 | * @param IRow $row |
||
210 | * @return mixed |
||
211 | */ |
||
212 | 6 | protected function prepareRecord(IRow $row) |
|
217 | |||
218 | /** |
||
219 | * Prepare selection |
||
220 | * @param NetteDatabaseSelection $selection |
||
221 | * @return mixed |
||
222 | */ |
||
223 | 4 | protected function prepareSelection(NetteDatabaseSelection $selection) |
|
228 | } |
||
229 |