2021-09-10 14:12:19 +02:00
|
|
|
<?php
|
|
|
|
$sections = [];
|
2021-09-17 19:06:56 +02:00
|
|
|
if (!empty($ajax)) {
|
|
|
|
$sections[] = '<div class="search-results-wrapper">';
|
|
|
|
}
|
2021-09-10 14:12:19 +02:00
|
|
|
foreach ($data as $tableName => $tableResult) {
|
2021-09-10 14:46:56 +02:00
|
|
|
if (empty($tableResult['amount'])) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-09-10 14:12:19 +02:00
|
|
|
$section = '';
|
|
|
|
$table = Cake\ORM\TableRegistry::get($tableName);
|
|
|
|
$fieldPath = !empty($table->getDisplayField()) ? $table->getDisplayField() : 'id';
|
|
|
|
$section .= sprintf('<span class="d-flex text-nowrap px-2 search-container-model">
|
2021-09-17 13:04:37 +02:00
|
|
|
<span class="text-uppercase text-muted me-3 model-text">%s</span>
|
2021-09-10 14:12:19 +02:00
|
|
|
<span class="d-flex align-items-center search-container-divider">
|
|
|
|
<hr class="m-0"/>
|
|
|
|
</span>
|
2021-09-17 13:04:37 +02:00
|
|
|
<span class="fw-light text-muted ms-3 model-text">%s</span>
|
2021-09-13 15:56:51 +02:00
|
|
|
</span>', h($tableName), $tableResult['amount']);
|
2021-09-10 14:12:19 +02:00
|
|
|
|
2021-09-10 14:46:56 +02:00
|
|
|
foreach ($tableResult['entries'] as $entry) {
|
2021-11-24 22:38:39 +01:00
|
|
|
if ($entry->getSource() == 'MetaFields') {
|
|
|
|
$section .= sprintf('<a class="dropdown-item" href="%s">%s</a>',
|
|
|
|
Cake\Routing\Router::URL([
|
|
|
|
'controller' => Cake\Utility\Inflector::pluralize($entry->scope),
|
|
|
|
'action' => 'view',
|
|
|
|
h($entry->parent_id)
|
|
|
|
]),
|
|
|
|
sprintf('%s (%s::%s)', h($entry->value), h($entry->scope), h($entry->field))
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$section .= sprintf('<a class="dropdown-item" href="%s">%s</a>',
|
|
|
|
Cake\Routing\Router::URL([
|
|
|
|
'controller' => Cake\Utility\Inflector::pluralize($entry->getSource()),
|
|
|
|
'action' => 'view',
|
|
|
|
h($entry['id'])
|
|
|
|
]),
|
|
|
|
h($entry[$fieldPath])
|
|
|
|
);
|
|
|
|
}
|
2021-09-10 14:12:19 +02:00
|
|
|
}
|
2021-09-10 14:46:56 +02:00
|
|
|
$remaining = $tableResult['amount'] - count($tableResult['entries']);
|
|
|
|
if ($remaining > 0) {
|
2021-09-17 13:04:37 +02:00
|
|
|
$section .= sprintf('<a href="%s" class="dropdown-item total-found d-block pe-2">%s <strong class="total-found-number text-primary">%s</strong><span class="total-found-text d-inline ms-1" href="#">%s</span></a>',
|
2021-09-13 15:56:51 +02:00
|
|
|
Cake\Routing\Router::URL([
|
|
|
|
'controller' => 'instance',
|
|
|
|
'action' => 'search_all',
|
|
|
|
'?' => [
|
|
|
|
'model' => h($tableName),
|
|
|
|
'search' => h($this->request->getParam('?')['search'] ?? ''),
|
|
|
|
'show_all' => 1
|
|
|
|
]
|
|
|
|
]),
|
|
|
|
__('Load'),
|
2021-09-10 14:46:56 +02:00
|
|
|
$remaining,
|
|
|
|
__('more results')
|
|
|
|
);
|
|
|
|
}
|
2021-09-10 14:12:19 +02:00
|
|
|
$sections[] = $section;
|
|
|
|
}
|
|
|
|
|
2021-09-13 15:56:51 +02:00
|
|
|
if (!empty($ajax)) {
|
2021-09-17 13:04:37 +02:00
|
|
|
$sections[] = sprintf('<a class="dropdown-item border-top text-center text-muted p-2" href="%s"><i class="%s me-2"></i>%s</a>',
|
2021-09-13 15:56:51 +02:00
|
|
|
Cake\Routing\Router::URL([
|
|
|
|
'controller' => 'instance',
|
|
|
|
'action' => 'search_all',
|
|
|
|
'?' => [
|
|
|
|
'search' => h($this->request->getParam('?')['search'] ?? '')
|
|
|
|
]
|
|
|
|
]),
|
|
|
|
$this->FontAwesome->getClass('search-plus'),
|
|
|
|
__('View all results')
|
|
|
|
);
|
2021-09-17 19:06:56 +02:00
|
|
|
$sections[] = '</div>';
|
2021-09-13 15:56:51 +02:00
|
|
|
} else {
|
2021-09-17 13:04:37 +02:00
|
|
|
echo sprintf('<h2 class="fw-light mb-4">%s <span class="font-monospace">%s</span></h2>', __('Global search results for:'), h($this->request->getParam('?')['search'] ?? ''));
|
2021-09-13 15:56:51 +02:00
|
|
|
}
|
|
|
|
|
2021-09-10 14:22:28 +02:00
|
|
|
if (!empty($sections)) {
|
|
|
|
echo implode('', $sections);
|
|
|
|
} else {
|
|
|
|
echo sprintf('<span class="dropdown-item p-0 pb-1 text-center">%s</span>', __('- No result -'));
|
|
|
|
}
|