174 lines
4.7 KiB
PHP
174 lines
4.7 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: root
|
|
* Date: 10/3/18
|
|
* Time: 3:36 PM
|
|
*/
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Contracts\TermsAndPrivacyResourceInterface;
|
|
use App\Helpers\CurrentUserHelper;
|
|
use App\Libraries\UuidHelper;
|
|
use App\TermsAndPrivacy;
|
|
use Response;
|
|
use Schema;
|
|
use Hash;
|
|
|
|
use App\Libraries\ListHelper;
|
|
|
|
|
|
class TermsAndPrivacyService implements TermsAndPrivacyResourceInterface
|
|
{
|
|
|
|
|
|
public $terms_and_privacy;
|
|
public $admin;
|
|
|
|
public function listing($params)
|
|
{
|
|
$pagination = ListHelper::validatePagination($params['page_size'],$params['page']);
|
|
$list = TermsAndPrivacy::where('is_active','=',1)->when($params['search'], function ($query) use ($params) {
|
|
|
|
return $query->where('title', 'like', '%'.$params['search'].'%', 'and')
|
|
->where('details', 'like', '%'.$params['search'].'%', 'or' );
|
|
|
|
});
|
|
|
|
$sorting = $params['sorting'];
|
|
if(count($sorting) > 0)
|
|
{
|
|
$list = $list->orderBy($sorting['field'],$sorting['sort_order']);
|
|
}
|
|
|
|
if($pagination == true){
|
|
return $list->paginate($params['page_size']);
|
|
}else
|
|
return $list->get();
|
|
}
|
|
|
|
public function store($request)
|
|
{
|
|
$currentUser = CurrentUserHelper::get_currentAdmin();
|
|
$this->terms_and_privacy = new TermsAndPrivacy;
|
|
|
|
$uuid = new UuidHelper;
|
|
$this->terms_and_privacy->tp_uuid = $uuid->generate_uuid1();
|
|
$this->terms_and_privacy->title = $request->get('title');
|
|
$this->terms_and_privacy->details = $request->get('details');
|
|
$this->terms_and_privacy->type = $request->get('type');
|
|
$this->terms_and_privacy->created_by = $currentUser->admin_id;
|
|
|
|
if ($this->terms_and_privacy->save())
|
|
{
|
|
return $this->terms_and_privacy->tp_id;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function update($request)
|
|
{
|
|
$currentUser = CurrentUserHelper::get_currentAdmin();
|
|
|
|
$this->terms_and_privacy = TermsAndPrivacy::where([
|
|
['tp_uuid',$request->tp_uuid]
|
|
])->first();
|
|
|
|
$this->terms_and_privacy->title = $request->title;
|
|
$this->terms_and_privacy->details = $request->details;
|
|
$this->terms_and_privacy->type = $request->type;
|
|
$this->terms_and_privacy->updated_by = $currentUser->admin_id;
|
|
|
|
if ($this->terms_and_privacy->save())
|
|
{
|
|
return $this->terms_and_privacy;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function getByField($field,$value)
|
|
{
|
|
$this->terms_and_privacy = TermsAndPrivacy::where($field,$value);
|
|
return $this->terms_and_privacy->get();
|
|
}
|
|
|
|
public function delete($uuid)
|
|
{
|
|
$currentUser = CurrentUserHelper::get_currentAdmin();
|
|
|
|
if(is_array($uuid))
|
|
{
|
|
$this->terms_and_privacy = TermsAndPrivacy::whereIn('tp_uuid',$uuid)
|
|
->update([
|
|
'is_active' => 0,
|
|
'updated_by' => $currentUser->admin_id
|
|
]);
|
|
|
|
if($this->terms_and_privacy)
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
$this->terms_and_privacy = TermsAndPrivacy::where('tp_uuid',$uuid)->first();
|
|
|
|
$this->terms_and_privacy->updated_by = $currentUser->admin_id;
|
|
$this->terms_and_privacy->is_active = 0;
|
|
|
|
if ($this->terms_and_privacy->save())
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function getDetailsWhereIn($field,$value,$relationship = null)
|
|
{
|
|
if($relationship)
|
|
{
|
|
$details = TermsAndPrivacy::with($relationship)->whereIn($field,$value)->get();
|
|
}
|
|
else
|
|
{
|
|
$details = TermsAndPrivacy::whereIn($field,$value)->get();
|
|
}
|
|
|
|
return $details->toArray();
|
|
}
|
|
|
|
public function check($id)
|
|
{
|
|
$this->terms_and_privacy = TermsAndPrivacy::where([
|
|
['tp_uuid',$id]
|
|
])->first();
|
|
|
|
return $this->terms_and_privacy ? $this->terms_and_privacy : false;
|
|
}
|
|
|
|
public function getAllActive()
|
|
{
|
|
$return1 = "<!DOCTYPE html><html><body>";
|
|
$return2 = "";
|
|
$lastPart = "</body></html>";
|
|
$this->terms_and_privacy = TermsAndPrivacy::where("is_active",1)->get();
|
|
|
|
foreach ($this->terms_and_privacy as $key => $value) {
|
|
if ($value->type == 1){
|
|
$return1 .= "<p><b>$value->title</b></p><p>$value->details</p>";
|
|
}else{
|
|
$return2 .= "<p><b>$value->title</b></p><p>$value->details</p>";
|
|
}
|
|
}
|
|
|
|
return $return1.$return2.$lastPart;
|
|
}
|
|
}
|