sementara
This commit is contained in:
@@ -3,8 +3,8 @@
|
||||
namespace Modules\Lpj\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Log;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Modules\Location\Models\Province;
|
||||
use Modules\Lpj\Http\Requests\BankDataRequest;
|
||||
use Modules\Lpj\Models\BankData;
|
||||
@@ -88,7 +88,8 @@
|
||||
}
|
||||
} else {
|
||||
// Invalid coordinates
|
||||
Log::warning("Invalid coordinates: Lat: $_lat, Lng: $_lng");// Do something to handle this situation, such as logging an error or skipping the record
|
||||
Log::warning("Invalid coordinates: Lat: $_lat, Lng: $_lng");
|
||||
// Do something to handle this situation, such as logging an error or skipping the record
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,7 +139,8 @@
|
||||
}
|
||||
} else {
|
||||
// Invalid coordinates
|
||||
Log::warning("Invalid coordinates: Lat: $lat, Lng: $lng");// Do something to handle this situation, such as logging an error or skipping the record
|
||||
Log::warning("Invalid coordinates: Lat: $lat, Lng: $lng");
|
||||
// Do something to handle this situation, such as logging an error or skipping the record
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -197,6 +199,24 @@
|
||||
// Retrieve data from the database
|
||||
$query = BankData::query();
|
||||
|
||||
// Check if show_all parameter is set
|
||||
$showAll = $request->has('show_all') && $request->get('show_all') === 'true';
|
||||
|
||||
// If show_all is true, we'll get all data without pagination
|
||||
if ($showAll) {
|
||||
// Get all records without pagination
|
||||
$data = $query->get();
|
||||
|
||||
return response()->json([
|
||||
'data' => $data,
|
||||
'recordsTotal' => $data->count(),
|
||||
'recordsFiltered' => $data->count(),
|
||||
'page' => 1,
|
||||
'pageSize' => $data->count(),
|
||||
'total' => 1
|
||||
]);
|
||||
}
|
||||
|
||||
// Apply search filter if provided
|
||||
if ($request->has('search') && !empty($request->get('search'))) {
|
||||
$search = $request->get('search');
|
||||
@@ -252,8 +272,10 @@
|
||||
// Get the total count of records
|
||||
$totalRecords = $query->count();
|
||||
|
||||
// Apply pagination if provided
|
||||
if ($request->has('page') && $request->has('size')) {
|
||||
// Apply pagination only if explicitly requested or not first load
|
||||
$shouldPaginate = $request->has('page') && $request->has('size') && !$request->has('show_all');
|
||||
|
||||
if ($shouldPaginate) {
|
||||
$page = $request->get('page');
|
||||
$size = $request->get('size');
|
||||
$offset = ($page - 1) * $size; // Calculate the offset
|
||||
@@ -287,11 +309,11 @@
|
||||
];
|
||||
});
|
||||
|
||||
// Calculate the page count
|
||||
$pageCount = ceil($totalRecords / $request->get('size'));
|
||||
// Calculate the page count (1 if showing all data)
|
||||
$pageCount = $shouldPaginate ? ceil($totalRecords / $request->get('size')) : 1;
|
||||
|
||||
// Calculate the current page number
|
||||
$currentPage = $request->get('page', 1);
|
||||
$currentPage = $shouldPaginate ? $request->get('page', 1) : 1;
|
||||
|
||||
// Ensure current page doesn't exceed page count
|
||||
$currentPage = min($currentPage, $pageCount);
|
||||
|
||||
Reference in New Issue
Block a user