Browse Source

update delete by folder

pull/1/head
wahyun 9 months ago
parent
commit
977db0ec5a
  1. 42
      app/Http/Controllers/FolderDocumentProyekController.php

42
app/Http/Controllers/FolderDocumentProyekController.php

@ -2,9 +2,12 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Models\Company;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\FolderDocumentProyek;
use App\Models\DokumenProject; use App\Models\DokumenProject;
use App\Models\FolderDocumentProyek;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class FolderDocumentProyekController extends Controller class FolderDocumentProyekController extends Controller
{ {
@ -44,23 +47,31 @@ class FolderDocumentProyekController extends Controller
} }
} }
public function delete($id) public function delete($id, $company_id)
{ {
DB::beginTransaction();
$data = FolderDocumentProyek::find($id); $data = FolderDocumentProyek::find($id);
$company = Company::find($company_id);
if($data){ if($data && $company) {
$delete = $data->delete(); $destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
}else{ $dir = $destinationPath['pathDocument'];
return response()->json(['status'=>'failed','message'=>'data Folder Document Proyek not found!','code'=>400], 400); $dataFile = DokumenProject::where([['type_dokumen', 'project-document-in-folder'],['ref_id', $data['id']]])->orderByRaw('id ASC')->get();
die(); if (is_dir($dir)) {
} foreach ($dataFile as $file) {
unlink($dir.$file['file']);
}
if($delete){ }
if($data->delete()) {
DB::commit();
return response()->json(['status'=>'success','message'=>'Folder Document Proyek successfully deleted!','code'=>200], 200); return response()->json(['status'=>'success','message'=>'Folder Document Proyek successfully deleted!','code'=>200], 200);
}else{ } else {
DB::rollBack();
return response()->json(['status'=>'failed','message'=>'Folder Document Proyek failed deleted!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'Folder Document Proyek failed deleted!','code'=>400], 400);
} }
} else {
DB::rollBack();
return response()->json(['status'=>'failed','message'=>'Data Folder Document Proyek not found!','code'=>400], 400);
}
} }
public function search(Request $request) public function search(Request $request)
@ -85,6 +96,7 @@ class FolderDocumentProyekController extends Controller
return response()->json(['status'=>'failed','message'=>'failed get list tools request, please try again later!','code'=>400], 400); return response()->json(['status'=>'failed','message'=>'failed get list tools request, please try again later!','code'=>400], 400);
} }
} }
public function getTree($id) public function getTree($id)
{ {
$data = FolderDocumentProyek::where('proyek_id', $id)->whereNull('parent_id')->orderByRaw('id ASC')->get(); $data = FolderDocumentProyek::where('proyek_id', $id)->whereNull('parent_id')->orderByRaw('id ASC')->get();
@ -100,7 +112,7 @@ class FolderDocumentProyekController extends Controller
foreach($dataFile as $objRowFile) { foreach($dataFile as $objRowFile) {
$objRowFile->key = rand(1, 1000); $objRowFile->key = rand(1, 1000);
$objRowFile->isDir = false; $objRowFile->isDir = false;
$objRowFile->proyek_id = $id; $objRowFile->proyek_id = (int)$id;
$finalData[] = $objRowFile; $finalData[] = $objRowFile;
} }
@ -122,7 +134,7 @@ class FolderDocumentProyekController extends Controller
foreach($dataFile as $objRowFile) { foreach($dataFile as $objRowFile) {
$objRowFile->key = rand(1, 1000); $objRowFile->key = rand(1, 1000);
$objRowFile->isDir = false; $objRowFile->isDir = false;
$objRowFile->proyek_id = $proyek_id; $objRowFile->proyek_id = (int)$proyek_id;
$finalData[] = $objRowFile; $finalData[] = $objRowFile;
} }

Loading…
Cancel
Save