diff --git a/src/Controller/InstanceController.php b/src/Controller/InstanceController.php
index c84ee1c..482c59d 100644
--- a/src/Controller/InstanceController.php
+++ b/src/Controller/InstanceController.php
@@ -30,12 +30,17 @@ class InstanceController extends AppController
return $this->RestResponse->viewData($data, 'json');
}
- public function searchAll($limit = 5)
+ public function searchAll()
{
$searchValue = $this->request->getQuery('search');
+ $model = $this->request->getQuery('model', null);
+ $limit = $this->request->getQuery('limit', 5);
+ if (!empty($this->request->getQuery('show_all', false))) {
+ $limit = null;
+ }
$data = [];
if (!empty($searchValue)) {
- $data = $this->Instance->searchAll($searchValue, $limit);
+ $data = $this->Instance->searchAll($searchValue, $limit, $model);
}
if ($this->ParamHandler->isRest()) {
return $this->RestResponse->viewData($data, 'json');
diff --git a/src/Model/Table/InstanceTable.php b/src/Model/Table/InstanceTable.php
index 8c23731..11e894b 100644
--- a/src/Model/Table/InstanceTable.php
+++ b/src/Model/Table/InstanceTable.php
@@ -24,10 +24,18 @@ class InstanceTable extends AppTable
return $validator;
}
- public function searchAll($value, $limit=5)
+ public function searchAll($value, $limit=5, $model=null)
{
$results = [];
- foreach ($this->seachAllTables as $tableName) {
+ $models = $this->seachAllTables;
+ if (!is_null($model)) {
+ if (in_array($model, $this->seachAllTables)) {
+ $models = [$model];
+ } else {
+ return $results; // Cannot search in this model
+ }
+ }
+ foreach ($models as $tableName) {
$controller = $this->getController($tableName);
$table = TableRegistry::get($tableName);
$query = $table->find();
diff --git a/templates/Instance/search_all.php b/templates/Instance/search_all.php
index d49a3e3..fb1973b 100644
--- a/templates/Instance/search_all.php
+++ b/templates/Instance/search_all.php
@@ -12,7 +12,8 @@
- ', h($tableName));
+ %s
+ ', h($tableName), $tableResult['amount']);
foreach ($tableResult['entries'] as $entry) {
$section .= sprintf('%s',
@@ -26,7 +27,17 @@
}
$remaining = $tableResult['amount'] - count($tableResult['entries']);
if ($remaining > 0) {
- $section .= sprintf('%s%s',
+ $section .= sprintf('%s %s%s',
+ Cake\Routing\Router::URL([
+ 'controller' => 'instance',
+ 'action' => 'search_all',
+ '?' => [
+ 'model' => h($tableName),
+ 'search' => h($this->request->getParam('?')['search'] ?? ''),
+ 'show_all' => 1
+ ]
+ ]),
+ __('Load'),
$remaining,
__('more results')
);
@@ -34,6 +45,22 @@
$sections[] = $section;
}
+ if (!empty($ajax)) {
+ $sections[] = sprintf('%s',
+ Cake\Routing\Router::URL([
+ 'controller' => 'instance',
+ 'action' => 'search_all',
+ '?' => [
+ 'search' => h($this->request->getParam('?')['search'] ?? '')
+ ]
+ ]),
+ $this->FontAwesome->getClass('search-plus'),
+ __('View all results')
+ );
+ } else {
+ echo sprintf('