You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
4.0 KiB
100 lines
4.0 KiB
3 years ago
|
<?php
|
||
|
|
||
|
namespace App\Http\Controllers;
|
||
|
|
||
|
use Illuminate\Http\Request;
|
||
|
use App\Models\ActivityDokumen;
|
||
|
|
||
|
class ActivityDokumenController extends Controller
|
||
|
{
|
||
|
public function dokumenByActivityId($id){
|
||
|
if($id && $id!="" && (int)$id > 0){
|
||
|
$dataDokumen = ActivityDokumen::where("activity_id", $id)->get();
|
||
|
|
||
|
return response()->json(['status'=>'success','data'=>$dataDokumen,'code'=>200], 200);
|
||
|
}else{
|
||
|
return response()->json(['status'=>'failed','message'=>'activity id is required!','code'=>400], 400);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public function delete($id)
|
||
|
{
|
||
|
if($id && $id!="" && (int)$id > 0){
|
||
|
$dokumen = ActivityDokumen::find($id);
|
||
|
if($dokumen){
|
||
|
if(file_exists($this->pathActivityDocument.$dokumen->file)){
|
||
|
unlink($this->pathActivityDocument.$dokumen->file);
|
||
|
}
|
||
|
$dokumen->delete();
|
||
|
return response()->json(['status'=>'success','message'=>'Dokumen deleted successfully!','code'=>200], 200);
|
||
|
}else{
|
||
|
return response()->json(['status'=>'failed','message'=>'Dokumen not found!','code'=>400], 400);
|
||
|
}
|
||
|
}else{
|
||
|
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public function uploadProjectDokumen(Request $request)
|
||
|
{
|
||
|
if($request->hasFile('dokumen')){
|
||
|
$activity_id = $request->activity_id;
|
||
|
$dokumen = $request->file('dokumen');
|
||
|
$extension = $dokumen->extension();
|
||
|
$name = $dokumen->getClientOriginalName();
|
||
|
|
||
|
$result = $dokumen->move($this->pathActivityDocument, $name);
|
||
|
if($result){
|
||
|
$data = [
|
||
|
'activity_id' => (int)$activity_id,
|
||
|
'file' => $name,
|
||
|
'description' => $request->description
|
||
|
];
|
||
|
|
||
|
$result = ActivityDokumen::create($data);
|
||
|
|
||
|
if($result){
|
||
|
return response()->json(['status'=>'success','message'=>'file upload is successfully!','code'=>200], 200);
|
||
|
}else{
|
||
|
unlink($this->pathActivityDocument.$name);
|
||
|
return response()->json(['status'=>'failed','message'=>'file upload is failed!','code'=>400], 400);
|
||
|
}
|
||
|
|
||
|
}else{
|
||
|
return response()->json(['status'=>'failed','message'=>'file upload is failed!','code'=>400], 400);
|
||
|
}
|
||
|
}else{
|
||
|
return response()->json(['status'=>'failed','message'=>'file is required!','code'=>400], 400);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public function searchDocProject(Request $request){
|
||
|
$payload = $request->all();
|
||
|
$dataBuilder = $this->setUpPayload($payload, 'm_document_activity');
|
||
|
$builder = $dataBuilder['builder'];
|
||
|
$countBuilder = $dataBuilder['count'];
|
||
|
$dataGet = $builder->get();
|
||
|
$totalRecord = $countBuilder->count();
|
||
|
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
|
||
|
}
|
||
|
|
||
|
public function downloadDokumen($id)
|
||
|
{
|
||
|
if($id && $id!="" && (int)$id > 0){
|
||
|
$dokumen = ActivityDokumen::find($id);
|
||
|
if($dokumen){
|
||
|
if(file_exists($this->pathActivityDocument.$dokumen->file)){
|
||
|
$pathToFile = $this->pathActivityDocument.$dokumen->file;
|
||
|
return response()->download($pathToFile);
|
||
|
}else{
|
||
|
return response()->json(['status'=>'failed','message'=>'Dokumen not found!','code'=>400], 400);
|
||
|
}
|
||
|
}else{
|
||
|
return response()->json(['status'=>'failed','message'=>'Dokumen not found!','code'=>400], 400);
|
||
|
}
|
||
|
}else{
|
||
|
return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400);
|
||
|
}
|
||
|
}
|
||
|
}
|