diff --git a/Admin/Install/Search.php b/Admin/Install/Search.php new file mode 100644 index 0000000..c62d618 --- /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..b36e8bd --- /dev/null +++ b/Admin/Install/SearchCommands.php @@ -0,0 +1,32 @@ + [ + [ + 'dest' => '\Modules\SupplierManagement\Controller\SearchController:searchGeneral', + 'verb' => RouteVerb::ANY, + 'permission' => [ + 'module' => SearchController::NAME, + 'type' => PermissionType::READ, + 'state' => PermissionCategory::SUPPLIER, + ], + ], + ], +]; diff --git a/Admin/Install/attributes.json b/Admin/Install/attributes.json index 20879c0..459a11d 100755 --- a/Admin/Install/attributes.json +++ b/Admin/Install/attributes.json @@ -6,7 +6,7 @@ "de": "Bewertung" }, "value_type": 2, - "is_custom_allowed": true, + "is_custom_allowed": false, "validation_pattern": "", "is_required": false, "default_value": "", @@ -55,6 +55,89 @@ } ] }, + { + "name": "supplier_area", + "l11n": { + "en": "Supplier area", + "de": "Lieferantenebiet" + }, + "value_type": 2, + "is_custom_allowed": false, + "validation_pattern": "", + "is_required": false, + "default_value": "01", + "values": [ + { + "value": "01" + } + ] + }, + { + "name": "bill_emails", + "l11n": { + "en": "Send bills as emails", + "de": "Sende Rechnungen als Email" + }, + "value_type": 5, + "is_custom_allowed": false, + "validation_pattern": "", + "is_required": false, + "default_value": true, + "values": [ + { + "value": false + }, + { + "value": true + } + ] + }, + { + "name": "bill_email_address", + "l11n": { + "en": "Email address for billing", + "de": "Emailadresse für Rechnungen" + }, + "value_type": 2, + "is_custom_allowed": true, + "validation_pattern": "", + "is_required": false, + "default_value": "", + "values": [] + }, + { + "name": "support_emails", + "l11n": { + "en": "Send ticket as emails", + "de": "Sende Ticket als Email" + }, + "value_type": 5, + "is_custom_allowed": false, + "validation_pattern": "", + "is_required": false, + "default_value": 1, + "values": [ + { + "value": false + }, + { + "value": true + } + ] + }, + { + "name": "support_email_address", + "l11n": { + "en": "Email address for tickets", + "de": "Emailadresse für Tickets" + }, + "value_type": 2, + "is_custom_allowed": true, + "validation_pattern": "", + "is_required": false, + "default_value": "", + "values": [] + }, { "name": "segment", "l11n": { diff --git a/Controller/ApiController.php b/Controller/ApiController.php index f664fe7..9f5abd2 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -323,7 +323,7 @@ final class ApiController extends Controller return; } - $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/BackendController.php b/Controller/BackendController.php index aa1f00f..b0dcd11 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -224,10 +224,8 @@ final class BackendController extends Controller $view->data['supplier'] = $supplier; // Get item profile image - // It might not be part of the 5 newest item files from above - // @todo It would be nice to have something like this as a default method in the model e.g. - // ItemManagement::getRelations()->with('types')->where(...); - // This should return the relations and NOT the model itself + // @feature Create a new read mapper function that returns relation models instead of its own model + // https://github.com/Karaka-Management/phpOMS/issues/320 $query = new Builder($this->app->dbPool->get()); $results = $query->selectAs(SupplierMapper::HAS_MANY['files']['external'], 'file') ->from(SupplierMapper::TABLE) @@ -243,7 +241,6 @@ final class BackendController extends Controller ->where(MediaTypeMapper::TABLE . '.' . MediaTypeMapper::getColumnByMember('name'), '=', 'supplier_profile_image'); $clientImage = MediaMapper::get() - ->with('types') ->where('id', $results) ->limit(1) ->execute(); diff --git a/Controller/SearchController.php b/Controller/SearchController.php new file mode 100644 index 0000000..409ec86 --- /dev/null +++ b/Controller/SearchController.php @@ -0,0 +1,112 @@ +getDataString('search') ?? '')); + $names[] = ($request->getDataString('search') ?? ''); + + $mapper = SupplierMapper::getAll() + ->with('account') + ->with('mainAddress') + ->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\SupplierManagement\Models\Supplier[] $accounts */ + $accounts = $mapper->execute(); + + $results = []; + foreach ($accounts as $account) { + // Get item profile image + // @feature Create a new read mapper function that returns relation models instead of its own model + // https://github.com/Karaka-Management/phpOMS/issues/320 + $query = new Builder($this->app->dbPool->get()); + $iResults = $query->selectAs(SupplierMapper::HAS_MANY['files']['external'], 'file') + ->from(SupplierMapper::TABLE) + ->leftJoin(SupplierMapper::HAS_MANY['files']['table']) + ->on(SupplierMapper::HAS_MANY['files']['table'] . '.' . SupplierMapper::HAS_MANY['files']['self'], '=', SupplierMapper::TABLE . '.' . SupplierMapper::PRIMARYFIELD) + ->leftJoin(MediaMapper::TABLE) + ->on(SupplierMapper::HAS_MANY['files']['table'] . '.' . SupplierMapper::HAS_MANY['files']['external'], '=', MediaMapper::TABLE . '.' . MediaMapper::PRIMARYFIELD) + ->leftJoin(MediaMapper::HAS_MANY['types']['table']) + ->on(MediaMapper::TABLE . '.' . MediaMapper::PRIMARYFIELD, '=', MediaMapper::HAS_MANY['types']['table'] . '.' . MediaMapper::HAS_MANY['types']['self']) + ->leftJoin(MediaTypeMapper::TABLE) + ->on(MediaMapper::HAS_MANY['types']['table'] . '.' . MediaMapper::HAS_MANY['types']['external'], '=', MediaTypeMapper::TABLE . '.' . MediaTypeMapper::PRIMARYFIELD) + ->where(SupplierMapper::HAS_MANY['files']['self'], '=', $account->id) + ->where(MediaTypeMapper::TABLE . '.' . MediaTypeMapper::getColumnByMember('name'), '=', 'supplier_profile_image'); + + $image = MediaMapper::get() + ->where('id', $iResults) + ->limit(1) + ->execute(); + + $results[] = [ + 'title' => $account->account->name1 . ' ' . $account->account->name2, + 'link' => '{/base}/purchase/supplier/view?id=' . $account->id, + 'email' => $account->account->getContactByType(ContactType::EMAIL)->content, + 'phone' => $account->account->getContactByType(ContactType::PHONE)->content, + 'city' => $account->mainAddress?->city, + 'image' => $image->id === 0 + ? 'Web/Backend/img/logo_grey.png' + : $image->getPath(), + 'tags' => [], + 'type' => 'list_accounts', + 'module' => 'Supplier Management', + ]; + } + + $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 b68214a..6d38d81 100755 --- a/info.json +++ b/info.json @@ -25,7 +25,8 @@ "providing": { "Navigation": "*", "Editor": "*", - "Media": "*" + "Media": "*", + "Search": "*" }, "load": [ {