@@ -114,19 +114,8 @@ function (Filter\Condition $condition) {
114114 $ this ->httpNotFound ('Contact not found ' );
115115 }
116116
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 );
130119
131120 unset($ result ->contact_id );
132121 $ results [] = $ result ;
@@ -155,19 +144,8 @@ function (Filter\Condition $condition) {
155144 do {
156145 /** @var stdClass $row */
157146 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 );
171149
172150 if ($ i > 0 || $ offset !== 0 ) {
173151 echo ", \n" ;
@@ -326,9 +304,9 @@ private function getChannelId(string $channelName): int
326304 *
327305 * @param int $contactId
328306 *
329- * @return ? string
307+ * @return string
330308 */
331- private function fetchContactAddresses (int $ contactId ): ? string
309+ private function fetchContactAddresses (int $ contactId ): string
332310 {
333311 /** @var array<string, string> $addresses */
334312 $ addresses = Database::get ()->fetchPairs (
@@ -338,32 +316,26 @@ private function fetchContactAddresses(int $contactId): ?string
338316 ->where (['contact_id = ? ' => $ contactId ])
339317 );
340318
341- if (! empty ($ addresses )) {
342- return json_encode ($ addresses ) ?: null ;
343- }
344-
345- return null ;
319+ return Json::sanitize ($ addresses , JSON_FORCE_OBJECT );
346320 }
347321
348322 /**
349323 * Fetch the group identifiers of the contact with the given id
350324 *
351325 * @param int $contactId
352326 *
353- * @return ? string[]
327+ * @return string[]
354328 */
355- private function fetchGroupIdentifiers (int $ contactId ): ? array
329+ private function fetchGroupIdentifiers (int $ contactId ): array
356330 {
357- $ groups = Database::get ()->fetchCol (
331+ return Database::get ()->fetchCol (
358332 (new Select ())
359333 ->from ('contactgroup_member cgm ' )
360334 ->columns ('cg.external_uuid ' )
361335 ->joinLeft ('contactgroup cg ' , 'cg.id = cgm.contactgroup_id ' )
362336 ->where (['cgm.contact_id = ? ' => $ contactId ])
363337 ->groupBy ('cg.external_uuid ' )
364338 );
365-
366- return $ groups ?: null ;
367339 }
368340
369341 /**
0 commit comments