farhan048
1 year ago
1 changed files with 95 additions and 95 deletions
@ -1,95 +1,95 @@ |
|||||||
<?php |
<?php |
||||||
|
|
||||||
namespace App\Http\Controllers; |
namespace App\Http\Controllers; |
||||||
|
|
||||||
use Illuminate\Http\Request; |
use Illuminate\Http\Request; |
||||||
use App\Models\ActivityDokumen; |
use App\Models\ActivityDokumen; |
||||||
|
|
||||||
class ActivityDokumenController extends Controller |
class ActivityDokumenController extends Controller |
||||||
{ |
{ |
||||||
|
|
||||||
public function dokumenByActivityId($id){ |
public function dokumenByActivityId($id){ |
||||||
if(empty($id) || !is_int((int)$id)) |
if(empty($id) || !is_int((int)$id)) |
||||||
return response()->json(['status'=>'failed','message'=>'activity id is required!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'activity id is required!','code'=>400], 400); |
||||||
|
|
||||||
$dataDokumen = ActivityDokumen::where("activity_id", $id)->get(); |
$dataDokumen = ActivityDokumen::where("activity_id", $id)->get(); |
||||||
return response()->json(['status'=>'success','data'=>$dataDokumen,'code'=>200], 200); |
return response()->json(['status'=>'success','data'=>$dataDokumen,'code'=>200], 200); |
||||||
} |
} |
||||||
|
|
||||||
public function delete($id) |
public function delete($id) |
||||||
{ |
{ |
||||||
if(empty($id) || !is_int((int)$id)) |
if(empty($id) || !is_int((int)$id)) |
||||||
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); |
||||||
|
|
||||||
$document = ActivityDokumen::find($id); |
$document = ActivityDokumen::find($id); |
||||||
|
|
||||||
if(!$document) |
if(!$document) |
||||||
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); |
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); |
||||||
|
|
||||||
if(file_exists($this->pathActivityDocument.$document->file)) |
if(file_exists($this->pathActivityDocument.$document->file)) |
||||||
unlink($this->pathActivityDocument.$document->file); |
unlink($this->pathActivityDocument.$document->file); |
||||||
|
|
||||||
$document->delete(); |
$document->delete(); |
||||||
return response()->json(['status'=>'success','message'=>'Dokumen deleted successfully!','code'=>200], 200); |
return response()->json(['status'=>'success','message'=>'Dokumen deleted successfully!','code'=>200], 200); |
||||||
} |
} |
||||||
|
|
||||||
public function uploadProjectDokumen(Request $request) |
public function uploadProjectDokumen(Request $request) |
||||||
{ |
{ |
||||||
if(!$request->hasFile('dokumen')) |
if(!$request->hasFile('dokumen')) |
||||||
return response()->json(['status'=>'failed','message'=>'file is required!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'file is required!','code'=>400], 400); |
||||||
|
|
||||||
$activity_id = $request->activity_id; |
$activity_id = $request->activity_id; |
||||||
$document = $request->file('dokumen'); |
$document = $request->file('dokumen'); |
||||||
$name = $document->getClientOriginalName(); |
$name = $document->getClientOriginalName(); |
||||||
|
|
||||||
$result = $document->move($this->pathActivityDocument, $name); |
$result = $document->move($this->pathActivityDocument, $name); |
||||||
|
|
||||||
if(!$result) |
if(!$result) |
||||||
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); |
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); |
||||||
|
|
||||||
$data = [ |
$data = [ |
||||||
'activity_id' => (int)$activity_id, |
'activity_id' => (int)$activity_id, |
||||||
'file' => $name, |
'file' => $name, |
||||||
'description' => $request->description |
'description' => $request->description |
||||||
]; |
]; |
||||||
|
|
||||||
$result = ActivityDokumen::create($data); |
$result = ActivityDokumen::create($data); |
||||||
|
|
||||||
if(!$result){ |
if(!$result){ |
||||||
unlink($this->pathActivityDocument.$name); |
unlink($this->pathActivityDocument.$name); |
||||||
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); |
return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); |
||||||
} |
} |
||||||
|
|
||||||
return response()->json(['status'=>'success','message'=>'Upload success!','code'=>200], 200); |
return response()->json(['status'=>'success','message'=>'Upload success!','code'=>200], 200); |
||||||
} |
} |
||||||
|
|
||||||
public function searchDocProject(Request $request){ |
public function searchDocProject(Request $request){ |
||||||
$payload = $request->all(); |
$payload = $request->all(); |
||||||
|
|
||||||
$dataBuilder = $this->setUpPayload($payload, 'm_document_activity'); |
$dataBuilder = $this->setUpPayload($payload, 'm_document_activity'); |
||||||
$builder = $dataBuilder['builder']; |
$builder = $dataBuilder['builder']; |
||||||
$countBuilder = $dataBuilder['count']; |
$countBuilder = $dataBuilder['count']; |
||||||
$dataGet = $builder->get(); |
$dataGet = $builder->get(); |
||||||
$totalRecord = $countBuilder->count(); |
$totalRecord = $countBuilder->count(); |
||||||
|
|
||||||
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
||||||
} |
} |
||||||
|
|
||||||
public function downloadDokumen($id) |
public function downloadDokumen($id) |
||||||
{ |
{ |
||||||
if(empty($id) || !is_int((int)$id)) |
if(empty($id) || !is_int((int)$id)) |
||||||
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); |
||||||
|
|
||||||
$document = ActivityDokumen::find($id); |
$document = ActivityDokumen::find($id); |
||||||
|
|
||||||
if(!$document) |
if(!$document) |
||||||
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400); |
||||||
|
|
||||||
if(file_exists($this->pathActivityDocument.$document->file)){ |
if(file_exists($this->pathActivityDocument.$document->file)){ |
||||||
$pathToFile = $this->pathActivityDocument.$document->file; |
$pathToFile = $this->pathActivityDocument.$document->file; |
||||||
return response()->download($pathToFile); |
return response()->download($pathToFile); |
||||||
} |
} |
||||||
|
|
||||||
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400); |
return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400); |
||||||
} |
} |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue