From ef94ad8038fcbf8f3f66107fe9a3229d7dfea398 Mon Sep 17 00:00:00 2001 From: Lars Gebhardt-Kusche Date: Tue, 30 Dec 2025 01:13:06 +0100 Subject: [PATCH] asdasd --- partials/landing/search.php | 59 ++++++++++++++++++++++++++ public/page/community.php | 2 +- public/page/community_thread.php | 2 +- public/page/search.php | 73 +------------------------------- src/App/Search.php | 47 ++++++++++++++++++++ 5 files changed, 109 insertions(+), 74 deletions(-) create mode 100644 partials/landing/search.php create mode 100644 src/App/Search.php diff --git a/partials/landing/search.php b/partials/landing/search.php new file mode 100644 index 0000000..1d62d37 --- /dev/null +++ b/partials/landing/search.php @@ -0,0 +1,59 @@ +pdo(); +$q = trim((string)($_GET['q'] ?? '')); +$results = []; + +if ($q !== '' && $pdo) { + $search = new \App\Search($pdo); + $results = $search->searchEvents($q, 100); +} +?> +
+
+

Suche

+

Events finden

+
+
+ + +
+ +
+ + +

Bitte gib einen Suchbegriff ein.

+ +

Ergebnis(se) für „

+ +

Keine passenden Events gefunden.

+ +
+ +
+
+
+ + 📍 + + +
+

+

+ +

Ort:

+ +
+ Details anzeigen +

+
+
+
+ +
+ + +
+
diff --git a/public/page/community.php b/public/page/community.php index e85cf33..ac38ad0 100644 --- a/public/page/community.php +++ b/public/page/community.php @@ -1,4 +1,4 @@ pdo(); -$q = trim((string)($_GET['q'] ?? '')); -$results = []; - -if ($q !== '' && $pdo) { - $like = '%' . $q . '%'; - $sql = 'SELECT id, title, teaser_public, description, city, region, starts_at, visibility, allow_kids, location_label - FROM events - WHERE starts_at >= NOW() - AND status != "cancelled" - AND (title LIKE :q1 OR teaser_public LIKE :q2 OR description LIKE :q3 OR city LIKE :q4 OR region LIKE :q5 OR zip LIKE :q6) - ORDER BY starts_at ASC - LIMIT 100'; - $stmt = $pdo->prepare($sql); - $stmt->execute([ - ':q1' => $like, - ':q2' => $like, - ':q3' => $like, - ':q4' => $like, - ':q5' => $like, - ':q6' => $like, - ]); - $results = $stmt->fetchAll(PDO::FETCH_ASSOC) ?: []; -} -?> -
-
-

Suche

-

Events finden

-
-
- - -
- -
- - -

Bitte gib einen Suchbegriff ein.

- -

Ergebnis(se) für „

- -

Keine passenden Events gefunden.

- -
- -
-
-
- - 📍 - - -
-

-

- -

Ort:

- -
- Details anzeigen -

-
-
-
- -
- - -
-
+tpl('search', 'landing'); diff --git a/src/App/Search.php b/src/App/Search.php new file mode 100644 index 0000000..1c750e4 --- /dev/null +++ b/src/App/Search.php @@ -0,0 +1,47 @@ +pdo) return []; + + $q = trim($query); + if ($q === '') return []; + + $tokens = array_filter(preg_split('/\s+/', $q) ?: [], fn($t) => $t !== ''); + if (!$tokens) { + $tokens = [$q]; + } + + $conditions = []; + $params = []; + $i = 0; + foreach ($tokens as $tok) { + $ph = ':kw' . $i++; + $conditions[] = "(title LIKE $ph OR teaser_public LIKE $ph OR description LIKE $ph OR city LIKE $ph OR region LIKE $ph OR zip LIKE $ph)"; + $params[$ph] = '%' . $tok . '%'; + } + $where = $conditions ? ('AND ' . implode(' AND ', $conditions)) : ''; + + $sql = "SELECT id, title, teaser_public, description, city, region, starts_at, visibility, allow_kids, location_label + FROM events + WHERE starts_at >= NOW() + AND status != 'cancelled' + $where + ORDER BY starts_at ASC + LIMIT :lim"; + $stmt = $this->pdo->prepare($sql); + foreach ($params as $k => $v) { + $stmt->bindValue($k, $v, \PDO::PARAM_STR); + } + $stmt->bindValue(':lim', $limit, \PDO::PARAM_INT); + $stmt->execute(); + return $stmt->fetchAll(\PDO::FETCH_ASSOC) ?: []; + } +}