getDataString('search') ?? '')); $names[] = ($request->getDataString('search') ?? ''); $mapper = ProfileMapper::getAll() ->with('account') ->with('image') ->with('account/addresses') ->with('account/contacts') ->limit(8); foreach ($names as $name) { $mapper->where('account/login', '%' . $name . '%', 'LIKE', 'OR') ->where('account/name1', '%' . $name . '%', 'LIKE', 'OR') ->where('account/name2', '%' . $name . '%', 'LIKE', 'OR') ->where('account/name3', '%' . $name . '%', 'LIKE', 'OR'); } /** @var \Modules\Profile\Models\Profile[] $accounts */ $accounts = $mapper->execute(); /** @var \Model\Setting $profileImage */ $profileImage = $this->app->appSettings->get(names: SettingsEnum::DEFAULT_PROFILE_IMAGE, module: 'Profile'); /** @var \Modules\Media\Models\Media $image */ $default = MediaMapper::get() ->where('id', (int) $profileImage->content) ->execute(); $results = []; foreach ($accounts as $account) { $address = empty($account->account->addresses) ? null : \reset($account->account->addresses); $results[] = [ 'title' => $account->account->name1 . ' ' . $account->account->name2, 'link' => '{/base}/profile/view?id=' . $account->id, 'email' => $account->account->getContactByType(ContactType::EMAIL)->content, 'phone' => $account->account->getContactByType(ContactType::PHONE)->content, 'city' => $address?->city, 'image' => $account->image->id === 0 ? $default->getPath() : $account->image->getPath(), 'tags' => [], 'type' => 'list_accounts', 'module' => 'Profile', ]; } $response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true); $response->add($request->uri->__toString(), $results); } }