diff --git a/Admin/Install/Search.php b/Admin/Install/Search.php new file mode 100644 index 0000000..1d52a1f --- /dev/null +++ b/Admin/Install/Search.php @@ -0,0 +1,43 @@ + __DIR__ . '/SearchCommands.php']); + } +} diff --git a/Admin/Install/SearchCommands.php b/Admin/Install/SearchCommands.php new file mode 100644 index 0000000..d1faf71 --- /dev/null +++ b/Admin/Install/SearchCommands.php @@ -0,0 +1,32 @@ + [ + [ + 'dest' => '\Modules\Profile\Controller\SearchController:searchGeneral', + 'verb' => RouteVerb::ANY, + 'permission' => [ + 'module' => SearchController::NAME, + 'type' => PermissionType::READ, + 'state' => PermissionCategory::PROFILE, + ], + ], + ], +]; diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 3d4f1b9..6d680a7 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -163,7 +163,7 @@ final class ApiController extends Controller $old = clone $profile; - $uploaded = $this->app->moduleManager->get('Media')->uploadFiles( + $uploaded = $this->app->moduleManager->get('Media', 'Api')->uploadFiles( names: $request->getDataList('names'), fileNames: $request->getDataList('filenames'), files: $uploadedFiles, diff --git a/Controller/SearchController.php b/Controller/SearchController.php new file mode 100644 index 0000000..c82a481 --- /dev/null +++ b/Controller/SearchController.php @@ -0,0 +1,100 @@ +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); + } +} diff --git a/info.json b/info.json index 55e50ab..02c0320 100755 --- a/info.json +++ b/info.json @@ -24,7 +24,8 @@ }, "providing": { "Navigation": "*", - "Media": "1.0.0" + "Media": "1.0.0", + "Search": "1.0.0" }, "load": [ {