2023-08-14 22:33:53 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2023-08-21 21:56:26 +02:00
|
|
|
use Illuminate\Http\Request;
|
2023-08-15 23:05:51 +02:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2023-08-14 22:33:53 +02:00
|
|
|
use App\Models\Location;
|
2023-09-05 22:30:57 +02:00
|
|
|
use App\Models\Source;
|
2023-08-14 22:33:53 +02:00
|
|
|
|
|
|
|
class FrontIndexController extends Controller
|
|
|
|
{
|
2023-08-18 04:50:38 +02:00
|
|
|
private $limit = 15;
|
|
|
|
|
2024-01-23 19:04:52 +01:00
|
|
|
private function getRecent()
|
2023-08-14 22:33:53 +02:00
|
|
|
{
|
2024-01-22 20:45:11 +01:00
|
|
|
$locations = Location::where("active", true)->orderByDesc('updated_at')->get();
|
|
|
|
$list = [];
|
|
|
|
foreach ($locations as $location) {
|
2024-01-23 19:04:52 +01:00
|
|
|
if (($location->block_count + $location->silence_count) >= 2) {
|
2024-01-22 20:45:11 +01:00
|
|
|
array_push($list, $location);
|
|
|
|
}
|
|
|
|
}
|
2024-01-23 19:04:52 +01:00
|
|
|
return $list;
|
|
|
|
}
|
2024-01-22 20:45:11 +01:00
|
|
|
|
2024-01-23 19:04:52 +01:00
|
|
|
public function start()
|
|
|
|
{
|
2024-01-26 19:16:38 +01:00
|
|
|
$list = $this->getRecent();
|
|
|
|
$latest_date = $list[0]->updated_at->format('Y M d');
|
2023-08-18 00:14:01 +02:00
|
|
|
return view('front.index', [
|
2024-01-26 19:16:38 +01:00
|
|
|
'count' => count($list),
|
|
|
|
'sources' => count(Source::where("active", true)->get()),
|
|
|
|
'recent' => $list,
|
|
|
|
'latest_date' => $latest_date,
|
|
|
|
'title' => "The Bad Space"
|
2023-08-18 23:34:53 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2023-08-21 21:56:26 +02:00
|
|
|
public function indexSearch(Request $request)
|
|
|
|
{
|
2024-01-23 19:04:52 +01:00
|
|
|
// this grabs the search results from the db
|
2023-08-21 21:56:26 +02:00
|
|
|
$terms = $request->index_search;
|
|
|
|
$rawSearch = $terms;
|
|
|
|
$terms = str_replace(",", "", $terms);
|
|
|
|
$terms = str_replace(" ", "|", $terms);
|
2023-09-21 22:46:14 +02:00
|
|
|
$raw = DB::select("SELECT * FROM searchlocations(?)", [$terms]);
|
2023-09-12 02:40:13 +02:00
|
|
|
$results = [];
|
|
|
|
foreach ($raw as $item) {
|
2023-09-25 22:09:50 +02:00
|
|
|
if (($item->block_count + $item->silence_count) > 2) {
|
2023-09-12 02:40:13 +02:00
|
|
|
array_push($results, $item);
|
|
|
|
}
|
|
|
|
}
|
2023-08-21 21:56:26 +02:00
|
|
|
|
2024-01-23 19:04:52 +01:00
|
|
|
//this gets recent updates to display under search results
|
2024-01-26 19:16:38 +01:00
|
|
|
$list = $this->getRecent();
|
|
|
|
$latest_date = $list[0]->updated_at->format('Y M d');
|
2023-08-21 21:56:26 +02:00
|
|
|
return view('front.index', [
|
2024-01-26 19:16:38 +01:00
|
|
|
'count' => count($list),
|
|
|
|
'sources' => count(Source::where("active", true)->get()),
|
|
|
|
'recent' => $list,
|
|
|
|
'results' => $results,
|
|
|
|
'recent' => $list,
|
|
|
|
'terms' => $terms,
|
|
|
|
'latest_date' => $latest_date,
|
|
|
|
'title' => "Search Results",
|
2023-08-21 21:56:26 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2023-08-18 23:34:53 +02:00
|
|
|
public function about()
|
|
|
|
{
|
2023-09-05 22:30:57 +02:00
|
|
|
$sources = Source::where("active", true)->get();
|
2023-08-18 23:34:53 +02:00
|
|
|
return view('front.about', [
|
2023-09-05 22:30:57 +02:00
|
|
|
'title' => "ABOUT",
|
|
|
|
'sources' => $sources
|
2023-08-18 23:34:53 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2024-02-02 19:16:11 +01:00
|
|
|
public function appeals()
|
|
|
|
{
|
|
|
|
return view('front.appeals', [
|
|
|
|
'title' => "LOCATION APPEALS",
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2023-08-18 23:34:53 +02:00
|
|
|
public function location(string $uuid = "1")
|
|
|
|
{
|
|
|
|
$location = Location::where("uuid", $uuid)->first();
|
2023-09-25 22:09:50 +02:00
|
|
|
$sources = Source::where("active", true)->get();
|
2023-08-18 23:34:53 +02:00
|
|
|
$name = "NO LOCATION FOUND";
|
|
|
|
if ($location) {
|
|
|
|
$name = $location->name;
|
|
|
|
}
|
|
|
|
return view('front.location', [
|
2023-09-25 22:09:50 +02:00
|
|
|
'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'),
|
2023-08-18 00:14:01 +02:00
|
|
|
]);
|
2023-08-14 22:33:53 +02:00
|
|
|
}
|
2023-08-18 04:50:38 +02:00
|
|
|
|
|
|
|
public function listings(int $pageNum = 1)
|
|
|
|
{
|
2024-01-23 19:04:52 +01:00
|
|
|
$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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-18 04:50:38 +02:00
|
|
|
$pageCount = ceil(count($active) / $this->limit);
|
|
|
|
|
2024-01-23 19:04:52 +01:00
|
|
|
if ($range != 0) {
|
|
|
|
$range = $range + 1;
|
|
|
|
}
|
|
|
|
|
2023-08-18 04:50:38 +02:00
|
|
|
$next = $pageNum + 1;
|
|
|
|
if ($next > $pageCount) {
|
|
|
|
$next = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$prev = $pageNum - 1;
|
|
|
|
|
|
|
|
if ($prev <= 0) {
|
|
|
|
$prev = $pageCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
return view('front.listing', [
|
|
|
|
'title' => "Listings",
|
2024-01-23 19:04:52 +01:00
|
|
|
'sources' => count(Source::where("active", true)->get()),
|
2023-08-18 04:50:38 +02:00
|
|
|
"totalPages" => $pageCount,
|
|
|
|
"prev" => $prev,
|
|
|
|
"next" => $next,
|
|
|
|
'pageNum' => $pageNum,
|
2024-01-23 19:04:52 +01:00
|
|
|
'locations' => $pages
|
2023-08-18 04:50:38 +02:00
|
|
|
]);
|
|
|
|
}
|
2023-08-14 22:33:53 +02:00
|
|
|
}
|