diff --git a/app/Http/Controllers/FrontIndexController.php b/app/Http/Controllers/FrontIndexController.php index 7507d00..fb75022 100644 --- a/app/Http/Controllers/FrontIndexController.php +++ b/app/Http/Controllers/FrontIndexController.php @@ -17,33 +17,24 @@ class FrontIndexController extends Controller public function start() { - $list = $this->locationRepository->getRecent(); - $latest_date = $list[0]->updated_at->format('Y M d'); return view('front.index', [ - 'count' => count($list), + 'count' => count($this->locationRepository->getActiveLocations()), 'sources' => count(Source::where("active", true)->get()), - 'recent' => $list, - 'latest_date' => $latest_date, + 'recent' => $this->locationRepository->getRecent(), + 'latest_date' => $this->locationRepository->getRecent()[0]->updated_at->format('Y M d'), '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), + 'count' => count($this->locationRepository->getActiveLocations()), 'sources' => count(Source::where("active", true)->get()), - 'recent' => $list, - 'results' => $results, - 'recent' => $list, + 'recent' => $this->locationRepository->getRecent(), + 'results' => $this->locationRepository->search($request), 'terms' => $request->index_search, - 'latest_date' => $latest_date, + 'latest_date' => $this->locationRepository->getRecent()[0]->updated_at->format('Y M d'), 'title' => "Search Results", ]); } diff --git a/app/Http/Controllers/LocationController.php b/app/Http/Controllers/LocationController.php index c6df1e9..cbeab77 100644 --- a/app/Http/Controllers/LocationController.php +++ b/app/Http/Controllers/LocationController.php @@ -129,6 +129,15 @@ class LocationController extends Controller } } + //TODO: maintenance script to set locations to inactive if they haven't been updated + // over 90 days + + //$diff=date_diff($location->updated_at, new DateTime()); + //$days = $diff->format("%R%a days") + + //$interval = $location->updated_at->diff(new DateTime()); + //$days = $interval->format("%a"); + //get all locations and sort which are present in unified or not /* $sorted = []; diff --git a/app/Repositories/LocationRepository.php b/app/Repositories/LocationRepository.php index 4d06088..05d3ca7 100644 --- a/app/Repositories/LocationRepository.php +++ b/app/Repositories/LocationRepository.php @@ -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]; } } diff --git a/resources/views/front/index.blade.php b/resources/views/front/index.blade.php index 3fd0f76..3ff664a 100644 --- a/resources/views/front/index.blade.php +++ b/resources/views/front/index.blade.php @@ -17,12 +17,8 @@

Found {{count($results)}} results for {{$terms}}

@foreach($results as $item) - @php - $action = $item->block_count + $item->silence_count; - $rating = ($action / $sources)*100; - @endphp - {{$rating}}% + {{($item->actions_count / $sources)*100}}%
@@ -40,24 +36,20 @@

Recent Updates

- @for($i = 0; $i < 10; $i++) - @php - $action = $recent[$i]->block_count + $recent[$i]->silence_count; - $rating = ($action / $sources)*100; - @endphp -
- {{$rating}}% - + @foreach($recent as $item) + + {{($item->actions_count / $sources)*100}}% +
- {{$recent[$i]->silence_count}} + {{$item->silence_count}}
- {{$recent[$i]->block_count}} + {{$item->block_count}}
- @endfor + @endforeach

Info

@@ -67,7 +59,6 @@
-
@endsection \ No newline at end of file