214 lines
6.2 KiB
PHP
Executable File
214 lines
6.2 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
use App\Contracts\AdminActionLogsInterface;
|
|
use App\Contracts\TermsAndPrivacyResourceInterface;
|
|
use App\Helpers\CurrentUserHelper;
|
|
use App\Http\Requests\TermsAndPrivacyFormValidation;
|
|
use App\Http\Resources\TermsAndPrivacyResource;
|
|
use App\Libraries\ParameterHelper;
|
|
use App\TermsAndPrivacy;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Helpers\HttpStatusCode;
|
|
|
|
class TermsAndPrivacyController extends Controller
|
|
{
|
|
|
|
public $terms_and_privacy;
|
|
public $admin_logs;
|
|
|
|
protected $format;
|
|
const MODULE = 'TERMSANDPRIVACY';
|
|
|
|
public function __construct(TermsAndPrivacyResourceInterface $terms_and_privacy, HttpStatusCode $httpStatusCode, AdminActionLogsInterface $admin_logs)
|
|
{
|
|
$this->terms_and_privacy = $terms_and_privacy;
|
|
$this->admin_logs = $admin_logs;
|
|
$this->format = $httpStatusCode;
|
|
$this->module = "TermsAndPrivacy";
|
|
$this->model = "TermsAndPrivacy";
|
|
}
|
|
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index(Request $request)
|
|
{
|
|
//
|
|
$params = [
|
|
'search' => ($request->has('_search') ? $request->get('_search') : NULL),
|
|
'page_size' => ($request->has('page_size') ? $request->get('page_size') : 10),
|
|
'page' => ($request->has('page') ? $request->get('page') : 10),
|
|
'sorting' => ParameterHelper::prepareSortingParameter($request)
|
|
];
|
|
|
|
$list = $this->terms_and_privacy->listing($params);
|
|
|
|
if(count($list)){
|
|
$additionals = $this->format->success("Success",[],false);
|
|
$data = TermsAndPrivacyResource::collection($list)->additional($additionals);
|
|
return $data->response()->setStatusCode(200);
|
|
}else{
|
|
return $this->format->success("No records found",[]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(TermsAndPrivacyFormValidation $request)
|
|
{
|
|
|
|
if ($request->type != 1 && $request->type != 2){
|
|
return $this->format->badRequest();
|
|
}
|
|
|
|
$termsorprivacy = $request->type==1 ? "Terms" : "Privacy";
|
|
|
|
$id = $this->terms_and_privacy->store($request);
|
|
|
|
if($id){
|
|
$this->admin_logs->log($id,self::MODULE,'STORE');
|
|
return $this->format->created($termsorprivacy.' has been added');
|
|
}else{
|
|
return $this->format->badRequest();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show($uuid)
|
|
{
|
|
$details = TermsAndPrivacy::where(['tp_uuid' => $uuid,'is_active' => 1])->first();
|
|
if($details)
|
|
{
|
|
$additionals = $this->format->success("Success",[],false);
|
|
$data = (new TermsAndPrivacyResource($details))->additional($additionals);
|
|
return $data->response()->setStatusCode(200);
|
|
}
|
|
else{
|
|
return $this->format->notFound('Term And Privacy doesn\'t exists');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(TermsAndPrivacyFormValidation $request, $id)
|
|
{
|
|
$currentUser = CurrentUserHelper::get_currentAdmin();
|
|
|
|
|
|
if ($id == null && empty($id)) {
|
|
return $this->format->badRequest();
|
|
|
|
}
|
|
|
|
$termsAndPrivacy = $this->terms_and_privacy->check($id);
|
|
|
|
if(!$termsAndPrivacy){
|
|
return $this->format->badRequest();
|
|
}
|
|
|
|
$termsAndPrivacy->update_by = $currentUser->admin_id;
|
|
$termsAndPrivacy->title = $request->title;
|
|
$termsAndPrivacy->details = $request->details;
|
|
|
|
$details = $this->terms_and_privacy->update($termsAndPrivacy);
|
|
|
|
if (!$details){
|
|
return $this->format->badRequest();
|
|
}
|
|
|
|
$additionals = $this->format->success("Success",[],false);
|
|
$data = (new TermsAndPrivacyResource($details))->additional($additionals);
|
|
|
|
return $data->response()->setStatusCode(200);
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy($uuid)
|
|
{
|
|
$details = $this->terms_and_privacy->getByField('tp_uuid',$uuid);
|
|
if(isset($details['0']))
|
|
{
|
|
$details = $details['0'];
|
|
if($this->terms_and_privacy->delete($uuid))
|
|
{
|
|
$this->admin_logs->log($details['tp_id'],self::MODULE,'DELETE');
|
|
$termsorprivacy = $details->type==1 ? "Terms" : "Privacy";
|
|
return $this->format->success($termsorprivacy." Successfully Deleted");
|
|
}
|
|
}
|
|
|
|
return $this->format->badRequest();
|
|
}
|
|
|
|
public function batch_delete(Request $request)
|
|
{
|
|
$uuid = $request->has('tp_uuid') ? $request->get('tp_uuid') : null;
|
|
|
|
if($uuid)
|
|
{
|
|
$details = $this->terms_and_privacy->getDetailsWhereIn('tp_uuid',$uuid);
|
|
|
|
if($this->terms_and_privacy->delete($uuid))
|
|
{
|
|
foreach ($details as $key => $value)
|
|
{
|
|
$this->admin_logs->log($value['tp_id'],self::MODULE,'DELETE');
|
|
}
|
|
|
|
return $this->format->success("Terms and Privacy Successfully Deleted");
|
|
|
|
}
|
|
else
|
|
{
|
|
return $this->format->badRequest();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$data['tp_uuid'] = 'tp_uuid is required';
|
|
return $this->format->unprocessableEntity("Submit at least one item",$data);
|
|
}
|
|
}
|
|
|
|
public function mobile_terms_privacy()
|
|
{
|
|
$details = $this->terms_and_privacy->getAllActive();
|
|
|
|
if (empty($details)){
|
|
return $this->format->mobile_error('please contact us');
|
|
}
|
|
|
|
$details = nl2br($details);
|
|
|
|
return $this->format->mobile_success('Sucess',$details);
|
|
|
|
}
|
|
|
|
|
|
}
|