forked from projects/thebadspace
ro
da0ddb3ef0
Seperated data logic for locations and put it into its own repository class for better organization and readability of controller classes. Data methods are still simple so no need for an interface class just yet, but will probably implement at a later date
100 lines
3.1 KiB
PHP
100 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\Models\Source;
|
|
use App\Repositories\LocationRepository;
|
|
|
|
class FrontIndexController extends Controller
|
|
{
|
|
protected $locationRepository;
|
|
|
|
public function __construct(LocationRepository $locationRepository)
|
|
{
|
|
$this->locationRepository = $locationRepository;
|
|
}
|
|
|
|
public function start()
|
|
{
|
|
$list = $this->locationRepository->getRecent();
|
|
$latest_date = $list[0]->updated_at->format('Y M d');
|
|
return view('front.index', [
|
|
'count' => count($list),
|
|
'sources' => count(Source::where("active", true)->get()),
|
|
'recent' => $list,
|
|
'latest_date' => $latest_date,
|
|
'title' => "The Bad Space"
|
|
]);
|
|
}
|
|
|
|
public function indexSearch(Request $request)
|
|
{
|
|
// this grabs the search results from the db
|
|
$results = $this->locationRepository->search($request);
|
|
|
|
//this gets recent updates to display under search results
|
|
$list = $this->locationRepository->getRecent();
|
|
$latest_date = $list[0]->updated_at->format('Y M d');
|
|
return view('front.index', [
|
|
'count' => count($list),
|
|
'sources' => count(Source::where("active", true)->get()),
|
|
'recent' => $list,
|
|
'results' => $results,
|
|
'recent' => $list,
|
|
'terms' => $request->index_search,
|
|
'latest_date' => $latest_date,
|
|
'title' => "Search Results",
|
|
]);
|
|
}
|
|
|
|
public function about()
|
|
{
|
|
$sources = Source::where("active", true)->get();
|
|
return view('front.about', [
|
|
'title' => "ABOUT",
|
|
'sources' => $sources
|
|
]);
|
|
}
|
|
|
|
public function appeals()
|
|
{
|
|
return view('front.appeals', [
|
|
'title' => "LOCATION APPEALS",
|
|
]);
|
|
}
|
|
|
|
public function location(string $uuid = "1")
|
|
{
|
|
$location = $this->locationRepository->getLocation($uuid);
|
|
$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)
|
|
{
|
|
$listing = $this->locationRepository->getPage($pageNum);
|
|
|
|
return view('front.listing', [
|
|
'title' => "Listings",
|
|
'sources' => count(Source::where("active", true)->get()),
|
|
"totalPages" => $listing[1],
|
|
"prev" => $listing[2],
|
|
"next" => $listing[3],
|
|
'pageNum' => $pageNum,
|
|
'locations' => $listing[0]
|
|
]);
|
|
}
|
|
}
|