@@ -51,7 +51,11 @@ class History
51
51
State::PK => 'integer '
52
52
);
53
53
54
- //history entries
54
+ /**
55
+ * history entries
56
+ *
57
+ * @var array<int, array<string,mixed>> $entries
58
+ */
55
59
private array $ entries ;
56
60
private int $ id_car ;
57
61
@@ -89,8 +93,7 @@ public function load(int $id): bool
89
93
)->order ('history_date ASC ' );
90
94
91
95
$ results = $ this ->zdb ->execute ($ select );
92
- $ this ->entries = $ results ->toArray ();
93
- $ this ->formatEntries ();
96
+ $ this ->formatEntries ($ results ->toArray ());
94
97
return true ;
95
98
} catch (\Exception $ e ) {
96
99
Analog::log (
@@ -137,23 +140,30 @@ public function getLatest(): ArrayObject|false
137
140
/**
138
141
* Format entries dates, also loads Member
139
142
*
143
+ * @param array<int, array<string,mixed>> $entries list of entries to format
144
+ *
140
145
* @return void
141
146
*/
142
- private function formatEntries (): void
147
+ private function formatEntries (array $ entries ): void
143
148
{
144
- for ($ i = 0 ; $ i < count ($ this ->entries ); $ i ++) {
149
+ $ this ->entries = [];
150
+ foreach ($ entries as $ entry ) {
145
151
//put a formatted date to show
146
- $ date = new \DateTime ($ this ->entries [$ i ]['history_date ' ]);
147
- $ this ->entries [$ i ]['formatted_date ' ] = $ date ->format (__ ('Y-m-d ' ));
152
+ $ date = new \DateTime ($ entry ['history_date ' ]);
153
+ $ entry ['formatted_date ' ] = $ date ->format (__ ('Y-m-d ' ));
154
+
148
155
//associate member to current history entry
149
- $ this ->entries [ $ i ][ ' owner ' ]
150
- = new Adherent ( $ this -> zdb , ( int ) $ this -> entries [ $ i ][ ' id_adh ' ]);
156
+ $ entry [ ' owner ' ] = new Adherent ( $ this ->zdb , ( int ) $ entry [ ' id_adh ' ]);
157
+
151
158
//associate color
152
- $ this ->entries [$ i ]['color ' ]
153
- = new Color ($ this ->zdb , (int )$ this ->entries [$ i ]['id_color ' ]);
159
+ $ color = new Color ($ this ->zdb , (int )$ entry ['id_color ' ]);
160
+ $ entry ['color ' ] = $ color ->value ;
161
+
154
162
//associate state
155
- $ this ->entries [$ i ]['state ' ]
156
- = new State ($ this ->zdb , (int )$ this ->entries [$ i ]['id_state ' ]);
163
+ $ state = new State ($ this ->zdb , (int )$ entry ['id_state ' ]);
164
+ $ entry ['state ' ] = $ state ->value ;
165
+
166
+ $ this ->entries [] = $ entry ;
157
167
}
158
168
}
159
169
@@ -220,8 +230,6 @@ public function __get(string $name)
220
230
return $ this ->$ name ;
221
231
case 'fields ' :
222
232
return array_keys ($ this ->fields );
223
- case 'entries ' :
224
- return $ this ->entries ;
225
233
default :
226
234
Analog::log (
227
235
'[ ' . get_class ($ this ) . '] Trying to get an unknown property ( ' .
@@ -231,4 +239,14 @@ public function __get(string $name)
231
239
break ;
232
240
}
233
241
}
242
+
243
+ /**
244
+ * Get current car history entries
245
+ *
246
+ * @return array<int, array<string,mixed>>
247
+ */
248
+ public function getEntries (): array
249
+ {
250
+ return $ this ->entries ;
251
+ }
234
252
}
0 commit comments