Merge remote-tracking branch 'composer/feature/senior-officer' into staging
This commit is contained in:
@@ -656,7 +656,7 @@ class PenilaiController extends Controller
|
||||
'lpjData',
|
||||
'formFoto',
|
||||
'basicData',
|
||||
'inspeksi',
|
||||
'inspeksi',
|
||||
'lpj',
|
||||
'statusLpj',
|
||||
'alamat',
|
||||
|
||||
@@ -384,44 +384,48 @@ class SurveyorController extends Controller
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function processFotoLantaiUnit(Request $request)
|
||||
public function replaceFotoLantaiUnit(Request $request)
|
||||
{
|
||||
$processedFotoLantaiUnit = [];
|
||||
|
||||
// Ambil semua file foto lantai unit
|
||||
$fotoLantaiUnit = $request->file('foto_lantai_unit', []);
|
||||
|
||||
foreach ($fotoLantaiUnit as $lantaiKey => $files) {
|
||||
$processedFiles = [];
|
||||
|
||||
foreach ($files as $index => $file) {
|
||||
// Pastikan foto lantai unit ada dalam request
|
||||
if ($request->has('foto_lantai_unit')) {
|
||||
$fotoLantaiUnit = $request->file('foto_lantai_unit', []);
|
||||
|
||||
// Target lantai dan foto yang ingin diubah
|
||||
$lantaiKey = $request->input('lantai_key'); // Misal: 1
|
||||
$indexToReplace = $request->input('index'); // Misal: 0
|
||||
|
||||
// Cek jika lantaiKey ada dan file yang akan diganti ada
|
||||
if (isset($fotoLantaiUnit[$lantaiKey]) && isset($fotoLantaiUnit[$lantaiKey][$indexToReplace])) {
|
||||
$file = $fotoLantaiUnit[$lantaiKey][$indexToReplace];
|
||||
|
||||
// Pastikan file valid
|
||||
if ($file && $file->isValid()) {
|
||||
// Generate unique filename
|
||||
$filename = $this->generateUniqueFileName($file, "lantai_unit_{$lantaiKey}_{$index}");
|
||||
|
||||
$processedFiles[] = [
|
||||
'path' => $this->uploadFile($file, $filename . '.' . $index),
|
||||
'name' => "Foto Lantai {$lantaiKey} - " . ($index + 1),
|
||||
// Generate filename baru untuk foto yang diganti
|
||||
$filename = $this->generateUniqueFileName($file, "lantai_unit_{$lantaiKey}_{$indexToReplace}");
|
||||
|
||||
// Gantikan foto yang lama dengan yang baru
|
||||
$processedFoto = [
|
||||
'path' => $this->uploadFile($file, $filename . '.' . $file->getClientOriginalExtension()),
|
||||
'name' => "Foto Lantai {$lantaiKey} - " . ($indexToReplace + 1),
|
||||
];
|
||||
|
||||
// Update foto lantai unit yang sudah diproses
|
||||
$fotoLantaiUnit[$lantaiKey][$indexToReplace] = $processedFoto;
|
||||
}
|
||||
}
|
||||
|
||||
// Simpan file yang diproses dengan kunci lantai
|
||||
if (!empty($processedFiles)) {
|
||||
$processedFotoLantaiUnit[$lantaiKey] = $processedFiles;
|
||||
}
|
||||
}
|
||||
|
||||
return $processedFotoLantaiUnit;
|
||||
|
||||
// Kembalikan data foto lantai unit yang sudah diperbarui
|
||||
return response()->json(['foto_lantai_unit' => $fotoLantaiUnit]);
|
||||
}
|
||||
|
||||
// Fungsi helper untuk generate nama file unik
|
||||
private function generateUniqueFileName($file, $prefix = '')
|
||||
{
|
||||
$extension = $file->getClientOriginalExtension();
|
||||
return $prefix . '_' . uniqid() . '.' . $extension;
|
||||
}
|
||||
|
||||
// Fungsi helper untuk generate nama file unik
|
||||
private function generateUniqueFileName($file, $prefix = '')
|
||||
{
|
||||
$extension = $file->getClientOriginalExtension();
|
||||
return $prefix . '_' . uniqid() . '.' . $extension;
|
||||
}
|
||||
|
||||
private function categoryHasNewFiles(Request $request, array $fields): bool
|
||||
{
|
||||
@@ -476,11 +480,11 @@ private function generateUniqueFileName($file, $prefix = '')
|
||||
'name_basement.*' => 'nullable|string|max:255',
|
||||
'foto_gerbang' => 'nullable|image|mimes:jpeg,png,jpg,gif,svg,webp,bmp,tiff,heic,heif|max:'. $maxSize,
|
||||
'name_gerbang' => 'nullable|string|max:255',
|
||||
|
||||
|
||||
|
||||
|
||||
'name_lantai_unit' => 'array',
|
||||
'foto_lantai_unit' => 'array',
|
||||
'foto_lantai_unit.*' => 'array',
|
||||
'foto_lantai_unit.*' => 'array',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -1458,7 +1462,7 @@ private function generateUniqueFileName($file, $prefix = '')
|
||||
|
||||
$query->whereRaw('LOWER(status) = ?', ['assign']);
|
||||
|
||||
if(!Auth::user()->hasRole('administrator')) {
|
||||
if (!Auth::user()->hasRole('administrator')) {
|
||||
$query->whereHas('penilaian.userPenilai', function ($q) {
|
||||
$q->where('user_id', Auth::user()->id);
|
||||
$q->where('role', 'surveyor');
|
||||
@@ -1582,7 +1586,7 @@ private function generateUniqueFileName($file, $prefix = '')
|
||||
|
||||
if ($type == 'Spek Bangunan') {
|
||||
$data = $query->with(['bangunanKategori'])->get();
|
||||
}else{
|
||||
} else {
|
||||
$data = $query->get();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user