mirror of
https://koodu.h-i.works/projects/thebadspace
synced 2025-06-25 16:04:37 -05:00
simplified pagination, cleaned up front controller
Adding total actions count to location data has made it possible to simplify backend data queries, so the custom pagination was optimized and location repositories have been cleaned up. the front end controller has been cleaned up as well, which has resulted in the appropriate template being polished up as well.
This commit is contained in:
@ -38,54 +38,25 @@ class LocationRepository
|
||||
return $this->model::where("uuid", $uuid)->first();
|
||||
}
|
||||
|
||||
public function getActiveLocations()
|
||||
{
|
||||
return $this->model::where("active", true)->where('actions_count', '>=', 2)->get();
|
||||
}
|
||||
|
||||
public function getRecent()
|
||||
{
|
||||
$locations = $this->model::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;
|
||||
return $locations = $this->model::where("active", true)->where('actions_count', '>=', 2)
|
||||
->orderByDesc('updated_at')->limit(10)->get();
|
||||
}
|
||||
|
||||
public function getPage($pageNum)
|
||||
{
|
||||
$locations = $this->model::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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$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();
|
||||
$pageCount = ceil(count($active) / $this->limit);
|
||||
|
||||
if ($range != 0) {
|
||||
$range = $range + 1;
|
||||
}
|
||||
|
||||
$next = $pageNum + 1;
|
||||
if ($next > $pageCount) {
|
||||
$next = 1;
|
||||
@ -97,6 +68,6 @@ class LocationRepository
|
||||
$prev = $pageCount;
|
||||
}
|
||||
|
||||
return $result = [$pages, $pageCount, $prev, $next];
|
||||
return $result = [$locations, $pageCount, $prev, $next];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user