|
@@ -17,6 +17,8 @@ use Drupal\search_api\Entity\Index;
|
|
|
*/
|
|
|
class Base extends ControllerBase {
|
|
|
|
|
|
+
|
|
|
+
|
|
|
private $limit = 15;
|
|
|
private $offset = 0;
|
|
|
|
|
@@ -56,6 +58,24 @@ class Base extends ControllerBase {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private function defaultQuery(){
|
|
|
+ $entity_storage = \Drupal::entityTypeManager()->getStorage('node');
|
|
|
+ $this->query = $entity_storage->getQuery()
|
|
|
+ ->condition('type', 'materiau')
|
|
|
+ // ->condition('status', '1')
|
|
|
+ ->range($this->offset, $this->limit)
|
|
|
+ ->accessCheck(TRUE)
|
|
|
+ ->sort('changed', 'DESC');
|
|
|
+ // ->condition('field_example', 'test_value')
|
|
|
+ $this->results = $this->query->execute();
|
|
|
+
|
|
|
+ $this->count_query = $entity_storage->getQuery()
|
|
|
+ ->condition('type', 'materiau')
|
|
|
+ ->accessCheck(TRUE)
|
|
|
+ // ->condition('status', '1')
|
|
|
+ ->count();
|
|
|
+ $this->count = $this->count_query->execute();
|
|
|
+ }
|
|
|
/**
|
|
|
* get params from request
|
|
|
*/
|
|
@@ -79,8 +99,6 @@ class Base extends ControllerBase {
|
|
|
$this->parseRequest($request);
|
|
|
|
|
|
$resp = [
|
|
|
- 'keys' => $this->keys,
|
|
|
- 'term' => $this->term,
|
|
|
'range' => array(
|
|
|
'offset' => $this->offset,
|
|
|
'limit' => $this->limit
|
|
@@ -90,6 +108,8 @@ class Base extends ControllerBase {
|
|
|
if ($this->keys) {
|
|
|
$this->sapiQuery();
|
|
|
|
|
|
+ $resp['keys'] = $this->keys;
|
|
|
+ $resp['term'] = $this->term;
|
|
|
$resp['count'] = $this->results->getResultCount();
|
|
|
$resp['infos'] = t('The search found @count result(s) with keywords @keys.', array(
|
|
|
"@count" => $resp['count'],
|
|
@@ -117,6 +137,22 @@ class Base extends ControllerBase {
|
|
|
// $resp['items'] = $items;
|
|
|
$resp['uuids'] = $uuids;
|
|
|
$resp['nids'] = $nids;
|
|
|
+ } else {
|
|
|
+ // no keys or terms to search for
|
|
|
+ // display the default base page
|
|
|
+ $this->defaultQuery();
|
|
|
+ // $uuids = [];
|
|
|
+ $nids = [];
|
|
|
+ foreach ($this->results as $result) {
|
|
|
+ // $uuids[] = $result->getField('uuid')->getValues()[0];
|
|
|
+ $nids[] = $result;
|
|
|
+ }
|
|
|
+ // $resp['uuids'] = $uuids;
|
|
|
+ $resp['nids'] = $nids;
|
|
|
+ $resp['count'] = $this->count;
|
|
|
+ $resp['infos'] = t('Please use the search form to search from our @count materials.', array(
|
|
|
+ "@count" => $resp['count']
|
|
|
+ ));
|
|
|
}
|
|
|
|
|
|
return new JsonResponse($resp);
|
|
@@ -163,7 +199,7 @@ class Base extends ControllerBase {
|
|
|
|
|
|
$resp['items'] = $this->items;
|
|
|
}else{
|
|
|
- $resp['#markup'] = "no keys to search for";
|
|
|
+ $resp['#markup'] = t("no keys to search for");
|
|
|
}
|
|
|
|
|
|
return $resp;
|