ForRo/app/Http/Controllers/FrontIndexController.php
ro 175ea25d7b Updated search and listing links, added new icons
Search methodolgy has been tweaked and the correspending result links
have been updated, as well as links in the Listing page to display both
silence and suspend counts and the overall heat rating.

Also plugged in new silence and suspend icons provideb by
https://rage.love/@puf. Big thanks for that, man.
2024-01-23 12:04:52 -06:00

151 lines
4.3 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Models\Location;
use App\Models\Source;
class FrontIndexController extends Controller
{
private $limit = 15;
private function getRecent()
{
$locations = Location::where("active", true)->orderByDesc('updated_at')->get();
$list = [];
foreach ($locations as $location) {
if (($location->block_count + $location->silence_count) >= 2) {
array_push($list, $location);
}
}
return $list;
}
public function start()
{
$list = $this->getRecent();
return view('front.index', [
'count' => count($list),
'sources' => count(Source::where("active", true)->get()),
'recent' => $list,
'title' => "The Bad Space"
]);
}
public function indexSearch(Request $request)
{
// this grabs the search results from the db
$terms = $request->index_search;
$rawSearch = $terms;
$terms = str_replace(",", "", $terms);
$terms = str_replace(" ", "|", $terms);
$raw = DB::select("SELECT * FROM searchlocations(?)", [$terms]);
$results = [];
foreach ($raw as $item) {
if (($item->block_count + $item->silence_count) > 2) {
array_push($results, $item);
}
}
//this gets recent updates to display under search results
$list = $this->getRecent();
return view('front.index', [
'count' => count($list),
'sources' => count(Source::where("active", true)->get()),
'recent' => $list,
'results' => $results,
'recent' => $list,
'terms' => $terms,
'title' => "Search Results",
]);
}
public function about()
{
$sources = Source::where("active", true)->get();
return view('front.about', [
'title' => "ABOUT",
'sources' => $sources
]);
}
public function location(string $uuid = "1")
{
$location = Location::where("uuid", $uuid)->first();
$sources = Source::where("active", true)->get();
$name = "NO LOCATION FOUND";
if ($location) {
$name = $location->name;
}
return view('front.location', [
'title' => str_replace(".", " ", $name),
'location' => $location,
'actions' => $location->block_count + $location->silence_count,
'sources_count' => count($sources),
'images' => json_decode($location->images),
'updated' => $location->updated_at->format('Y M d'),
]);
}
public function listings(int $pageNum = 1)
{
$locations = Location::where("active", true)->get();
$active = [];
foreach ($locations as $location) {
if (($location->block_count + $location->silence_count) >= 2) {
array_push($active, $location);
}
}
$pages = [];
if (count($active) != 0) {
if (count($active) < $this->limit) {
$this->limit = count($active) - 1;
}
$range = $pageNum * $this->limit - $this->limit;
if ($range != 0) {
$range = $range + 1;
}
for ($i = 0; $i <= $this->limit; ++$i) {
if (isset($active[$i + $range])) {
array_push($pages, $active[$i + $range]);
} else {
// chill out
}
}
}
$pageCount = ceil(count($active) / $this->limit);
if ($range != 0) {
$range = $range + 1;
}
$next = $pageNum + 1;
if ($next > $pageCount) {
$next = 1;
}
$prev = $pageNum - 1;
if ($prev <= 0) {
$prev = $pageCount;
}
return view('front.listing', [
'title' => "Listings",
'sources' => count(Source::where("active", true)->get()),
"totalPages" => $pageCount,
"prev" => $prev,
"next" => $next,
'pageNum' => $pageNum,
'locations' => $pages
]);
}
}