2024-02-09 21:53:08 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Repositories;
|
|
|
|
|
|
|
|
use App\Models\Location;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
class LocationRepository
|
|
|
|
{
|
|
|
|
protected $model;
|
|
|
|
private $limit = 15;
|
|
|
|
|
|
|
|
public function __construct(Location $model)
|
|
|
|
{
|
|
|
|
$this->model = $model;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function search($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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getLocation($uuid)
|
|
|
|
{
|
|
|
|
return $this->model::where("uuid", $uuid)->first();
|
|
|
|
}
|
|
|
|
|
2024-02-10 18:48:09 +01:00
|
|
|
public function getActiveLocations()
|
|
|
|
{
|
|
|
|
return $this->model::where("active", true)->where('actions_count', '>=', 2)->get();
|
|
|
|
}
|
|
|
|
|
2024-02-09 21:53:08 +01:00
|
|
|
public function getRecent()
|
|
|
|
{
|
2024-02-10 18:48:09 +01:00
|
|
|
return $locations = $this->model::where("active", true)->where('actions_count', '>=', 2)
|
|
|
|
->orderByDesc('updated_at')->limit(10)->get();
|
2024-02-09 21:53:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getPage($pageNum)
|
|
|
|
{
|
2024-02-10 18:48:09 +01:00
|
|
|
$range = $pageNum * $this->limit - $this->limit;
|
|
|
|
$active = $this->model::where("active", true)->where('actions_count', '>=', 2)->get();
|
|
|
|
$locations = $this->model::where("active", true)->where('actions_count', '>=', 2)
|
|
|
|
->limit($this->limit)->offset($range)->orderBy('id', 'asc')->get();
|
2024-02-09 21:53:08 +01:00
|
|
|
$pageCount = ceil(count($active) / $this->limit);
|
|
|
|
|
|
|
|
$next = $pageNum + 1;
|
|
|
|
if ($next > $pageCount) {
|
|
|
|
$next = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$prev = $pageNum - 1;
|
|
|
|
|
|
|
|
if ($prev <= 0) {
|
|
|
|
$prev = $pageCount;
|
|
|
|
}
|
|
|
|
|
2024-02-10 18:48:09 +01:00
|
|
|
return $result = [$locations, $pageCount, $prev, $next];
|
2024-02-09 21:53:08 +01:00
|
|
|
}
|
|
|
|
}
|