@@ -114,19 +114,8 @@ function (Filter\Condition $condition) {
114
114
$ this ->httpNotFound ('Contact not found ' );
115
115
}
116
116
117
- if ($ result ->username === null ) {
118
- unset($ result ->username );
119
- }
120
-
121
- $ groups = $ this ->fetchGroupIdentifiers ($ result ->contact_id );
122
- if ($ groups ) {
123
- $ result ->groups = $ groups ;
124
- }
125
-
126
- $ addresses = $ this ->fetchContactAddresses ($ result ->contact_id );
127
- if ($ addresses ) {
128
- $ result ->addresses = $ addresses ;
129
- }
117
+ $ result ->groups = $ this ->fetchGroupIdentifiers ($ result ->contact_id );
118
+ $ result ->addresses = $ this ->fetchContactAddresses ($ result ->contact_id );
130
119
131
120
unset($ result ->contact_id );
132
121
$ results [] = $ result ;
@@ -155,19 +144,8 @@ function (Filter\Condition $condition) {
155
144
do {
156
145
/** @var stdClass $row */
157
146
foreach ($ res as $ i => $ row ) {
158
- if ($ row ->username === null ) {
159
- unset($ row ->username );
160
- }
161
-
162
- $ groups = $ this ->fetchGroupIdentifiers ($ row ->contact_id );
163
- if ($ groups ) {
164
- $ row ->groups = $ groups ;
165
- }
166
-
167
- $ addresses = $ this ->fetchContactAddresses ($ row ->contact_id );
168
- if ($ addresses ) {
169
- $ row ->addresses = $ addresses ;
170
- }
147
+ $ row ->groups = $ this ->fetchGroupIdentifiers ($ row ->contact_id );
148
+ $ row ->addresses = $ this ->fetchContactAddresses ($ row ->contact_id );
171
149
172
150
if ($ i > 0 || $ offset !== 0 ) {
173
151
echo ", \n" ;
@@ -326,9 +304,9 @@ private function getChannelId(string $channelName): int
326
304
*
327
305
* @param int $contactId
328
306
*
329
- * @return ? string
307
+ * @return string
330
308
*/
331
- private function fetchContactAddresses (int $ contactId ): ? string
309
+ private function fetchContactAddresses (int $ contactId ): string
332
310
{
333
311
/** @var array<string, string> $addresses */
334
312
$ addresses = Database::get ()->fetchPairs (
@@ -338,32 +316,26 @@ private function fetchContactAddresses(int $contactId): ?string
338
316
->where (['contact_id = ? ' => $ contactId ])
339
317
);
340
318
341
- if (! empty ($ addresses )) {
342
- return json_encode ($ addresses ) ?: null ;
343
- }
344
-
345
- return null ;
319
+ return Json::sanitize ($ addresses , JSON_FORCE_OBJECT );
346
320
}
347
321
348
322
/**
349
323
* Fetch the group identifiers of the contact with the given id
350
324
*
351
325
* @param int $contactId
352
326
*
353
- * @return ? string[]
327
+ * @return string[]
354
328
*/
355
- private function fetchGroupIdentifiers (int $ contactId ): ? array
329
+ private function fetchGroupIdentifiers (int $ contactId ): array
356
330
{
357
- $ groups = Database::get ()->fetchCol (
331
+ return Database::get ()->fetchCol (
358
332
(new Select ())
359
333
->from ('contactgroup_member cgm ' )
360
334
->columns ('cg.external_uuid ' )
361
335
->joinLeft ('contactgroup cg ' , 'cg.id = cgm.contactgroup_id ' )
362
336
->where (['cgm.contact_id = ? ' => $ contactId ])
363
337
->groupBy ('cg.external_uuid ' )
364
338
);
365
-
366
- return $ groups ?: null ;
367
339
}
368
340
369
341
/**
0 commit comments