Browse Source

update delete by folder

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

274
app/Http/Controllers/FolderDocumentProyekController.php

@ -1,131 +1,143 @@
<?php <?php
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Http\Request; use App\Models\Company;
use App\Models\FolderDocumentProyek; use Illuminate\Http\Request;
use App\Models\DokumenProject; use App\Models\DokumenProject;
use App\Models\FolderDocumentProyek;
class FolderDocumentProyekController extends Controller use Illuminate\Support\Facades\DB;
{ use Illuminate\Support\Facades\Log;
public function add(Request $request){
$this->validate($request, [ class FolderDocumentProyekController extends Controller
'name_folder' => 'required', {
'proyek_id' => 'required' public function add(Request $request){
]); $this->validate($request, [
$data = $request->all(); 'name_folder' => 'required',
$data['created_by'] = $this->currentName; 'proyek_id' => 'required'
]);
$result = FolderDocumentProyek::create($data); $data = $request->all();
if($result){ $data['created_by'] = $this->currentName;
return response()->json(['status'=>'success','message'=>'Folder Document Proyek successfull created','code'=>200]);
}else{ $result = FolderDocumentProyek::create($data);
return response()->json(['status'=>'failed','message'=>'Folder Document Proyek failed created','code'=>400]); if($result){
} return response()->json(['status'=>'success','message'=>'Folder Document Proyek successfull created','code'=>200]);
} }else{
return response()->json(['status'=>'failed','message'=>'Folder Document Proyek failed created','code'=>400]);
public function update(Request $request, $id){ }
}
if(!$id || (int) $id < 0 || $id==""){
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); public function update(Request $request, $id){
}
$data = FolderDocumentProyek::find($id); if(!$id || (int) $id < 0 || $id==""){
if($data){ return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400);
$result = $data->update($request->all()); }
}else{ $data = FolderDocumentProyek::find($id);
return response()->json(['status'=>'failed','message'=>'Data Folder Document Proyek not found!','code'=>400], 400); if($data){
die(); $result = $data->update($request->all());
} }else{
return response()->json(['status'=>'failed','message'=>'Data Folder Document Proyek not found!','code'=>400], 400);
if($result){ die();
return response()->json(['status'=>'success','message'=>'Folder Document Proyek successfully updated!','code'=>200], 200); }
}else{
return response()->json(['status'=>'failed','message'=>'Folder Document Proyek failed updated!','code'=>400], 400); if($result){
} return response()->json(['status'=>'success','message'=>'Folder Document Proyek successfully updated!','code'=>200], 200);
} }else{
return response()->json(['status'=>'failed','message'=>'Folder Document Proyek failed updated!','code'=>400], 400);
public function delete($id) }
{ }
$data = FolderDocumentProyek::find($id);
public function delete($id, $company_id)
if($data){ {
$delete = $data->delete(); DB::beginTransaction();
}else{ $data = FolderDocumentProyek::find($id);
return response()->json(['status'=>'failed','message'=>'data Folder Document Proyek not found!','code'=>400], 400); $company = Company::find($company_id);
die(); if($data && $company) {
} $destinationPath = $this->setCustomeDirectoryUpload($company['company_name']);
$dir = $destinationPath['pathDocument'];
$dataFile = DokumenProject::where([['type_dokumen', 'project-document-in-folder'],['ref_id', $data['id']]])->orderByRaw('id ASC')->get();
if($delete){ if (is_dir($dir)) {
return response()->json(['status'=>'success','message'=>'Folder Document Proyek successfully deleted!','code'=>200], 200); foreach ($dataFile as $file) {
}else{ unlink($dir.$file['file']);
return response()->json(['status'=>'failed','message'=>'Folder Document Proyek failed deleted!','code'=>400], 400); }
} }
} if($data->delete()) {
DB::commit();
public function search(Request $request) return response()->json(['status'=>'success','message'=>'Folder Document Proyek successfully deleted!','code'=>200], 200);
{ } else {
$payload = $request->all(); DB::rollBack();
$dataBuilder = $this->setUpPayload($payload, 'm_FolderDocumentProyek'); return response()->json(['status'=>'failed','message'=>'Folder Document Proyek failed deleted!','code'=>400], 400);
$builder = $dataBuilder['builder']; }
$countBuilder = $dataBuilder['count']; } else {
$dataGet = $builder->get(); DB::rollBack();
$totalRecord = $countBuilder->count(); return response()->json(['status'=>'failed','message'=>'Data Folder Document Proyek not found!','code'=>400], 400);
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); }
} }
public function list() public function search(Request $request)
{ {
$data = FolderDocumentProyek::all(); $payload = $request->all();
$countData = $data->count(); $dataBuilder = $this->setUpPayload($payload, 'm_FolderDocumentProyek');
$builder = $dataBuilder['builder'];
if($data){ $countBuilder = $dataBuilder['count'];
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); $dataGet = $builder->get();
}else{ $totalRecord = $countBuilder->count();
return response()->json(['status'=>'failed','message'=>'failed get list tools request, please try again later!','code'=>400], 400); return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
} }
}
public function getTree($id) public function list()
{ {
$data = FolderDocumentProyek::where('proyek_id', $id)->whereNull('parent_id')->orderByRaw('id ASC')->get(); $data = FolderDocumentProyek::all();
$dataFile = DokumenProject::where('type_dokumen', 'project-document-out-folder')->where('ref_id', $id)->orderByRaw('id ASC')->get(); $countData = $data->count();
$finalData = [];
foreach($data as $objRow){ if($data){
$objRow->children = $this->getChildren($id, $objRow->id); return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200);
$objRow->key = rand(1, 1000); }else{
$objRow->isDir = true; return response()->json(['status'=>'failed','message'=>'failed get list tools request, please try again later!','code'=>400], 400);
$finalData[] = $objRow; }
} }
foreach($dataFile as $objRowFile) { public function getTree($id)
$objRowFile->key = rand(1, 1000); {
$objRowFile->isDir = false; $data = FolderDocumentProyek::where('proyek_id', $id)->whereNull('parent_id')->orderByRaw('id ASC')->get();
$objRowFile->proyek_id = $id; $dataFile = DokumenProject::where('type_dokumen', 'project-document-out-folder')->where('ref_id', $id)->orderByRaw('id ASC')->get();
$finalData[] = $objRowFile; $finalData = [];
} foreach($data as $objRow){
$objRow->children = $this->getChildren($id, $objRow->id);
return response()->json(['status'=>'success','data'=>$finalData,'code'=>200], 200); $objRow->key = rand(1, 1000);
} $objRow->isDir = true;
$finalData[] = $objRow;
private function getChildren($proyek_id, $parent_id) }
{
$finalData = []; foreach($dataFile as $objRowFile) {
$data = FolderDocumentProyek::where('proyek_id', $proyek_id)->where('parent_id', $parent_id)->orderByRaw('id ASC')->get(); $objRowFile->key = rand(1, 1000);
$dataFile = DokumenProject::where('type_dokumen', 'project-document-in-folder')->where('ref_id', $parent_id)->orderByRaw('id ASC')->get(); $objRowFile->isDir = false;
foreach($data as $objRow){ $objRowFile->proyek_id = (int)$id;
$objRow->key = rand(1, 1000); $finalData[] = $objRowFile;
$objRow->children = $this->getChildren($proyek_id, $objRow->id); }
$objRow->isDir = true;
$finalData[] = $objRow; return response()->json(['status'=>'success','data'=>$finalData,'code'=>200], 200);
} }
foreach($dataFile as $objRowFile) { private function getChildren($proyek_id, $parent_id)
$objRowFile->key = rand(1, 1000); {
$objRowFile->isDir = false; $finalData = [];
$objRowFile->proyek_id = $proyek_id; $data = FolderDocumentProyek::where('proyek_id', $proyek_id)->where('parent_id', $parent_id)->orderByRaw('id ASC')->get();
$finalData[] = $objRowFile; $dataFile = DokumenProject::where('type_dokumen', 'project-document-in-folder')->where('ref_id', $parent_id)->orderByRaw('id ASC')->get();
} foreach($data as $objRow){
$objRow->key = rand(1, 1000);
return $finalData; $objRow->children = $this->getChildren($proyek_id, $objRow->id);
} $objRow->isDir = true;
} $finalData[] = $objRow;
}
foreach($dataFile as $objRowFile) {
$objRowFile->key = rand(1, 1000);
$objRowFile->isDir = false;
$objRowFile->proyek_id = (int)$proyek_id;
$finalData[] = $objRowFile;
}
return $finalData;
}
}

Loading…
Cancel
Save