319 lines
9.4 KiB
PHP
319 lines
9.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
use App\Contracts\AdminResourceInterface;
|
|
use App\Helpers\CurrentUserHelper;
|
|
use App\Http\Requests\SystemPreferenceFormValidation;
|
|
use App\Http\Resources\SystemPreferencesResource;
|
|
use App\Libraries\S3;
|
|
use App\Libraries\StratuscastLibrary;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Helpers\HttpStatusCode;
|
|
use App\Contracts\SystemPreferenceResourceInterface;
|
|
|
|
use Illuminate\Routing\UrlGenerator;
|
|
|
|
class SystemPreferenceController extends Controller
|
|
{
|
|
|
|
public $systemPreference;
|
|
|
|
protected $format;
|
|
|
|
protected $module;
|
|
|
|
protected $model;
|
|
|
|
public $admin;
|
|
|
|
|
|
public function __construct(SystemPreferenceResourceInterface $systemPreference,HttpStatusCode $httpStatusCode, UrlGenerator $url, AdminResourceInterface $admin)
|
|
{
|
|
|
|
$this->systemPreference = $systemPreference;
|
|
$this->format = $httpStatusCode;
|
|
$this->module = "SystemPreference";
|
|
$this->model = "SystemPreference";
|
|
$this->url = $url;
|
|
$this->admin = $admin;
|
|
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
$rpreference = $this->systemPreference->getAll();
|
|
$data = [];
|
|
foreach ($rpreference as $key => $value) {
|
|
$data[$value['name']] = $value['value'] ;
|
|
}
|
|
|
|
return $this->format->success("SUCCESS",$data);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
//
|
|
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(SystemPreferenceFormValidation $request)
|
|
{
|
|
|
|
$currentUser = CurrentUserHelper::get_currentAdmin();
|
|
|
|
$admin = $this->admin->show($currentUser->admin_uuid);
|
|
|
|
$value['updated_by'] = $admin->admin_id;
|
|
|
|
if ($request['logo'] != null && !empty($request['logo'])){
|
|
$s3 = new S3;
|
|
$path = $s3->upload($request->file('logo'),'systemPreferences');
|
|
$value['name'] = 'logo';
|
|
$value['value'] = S3::public_path($path);
|
|
$this->systemPreference->store($request, $value );
|
|
}
|
|
|
|
if ($request->gps != null && !empty($request->gps)){
|
|
$value['name'] = 'gps';
|
|
$value['value'] = $request->gps;
|
|
$this->systemPreference->store($request, $value );
|
|
|
|
}
|
|
|
|
if ($request->contact_email_address_mobile != null && !empty($request->contact_email_address_mobile)){
|
|
$value['name'] = 'contact_email_address_mobile';
|
|
$value['value'] = $request->contact_email_address_mobile;
|
|
$this->systemPreference->store($request, $value );
|
|
}
|
|
|
|
if ($request->contact_number_mobile != null && !empty($request->contact_number_mobile)){
|
|
$value['name'] = 'contact_number_mobile';
|
|
$value['value'] = $request->contact_number_mobile;
|
|
$this->systemPreference->store($request, $value );
|
|
}
|
|
|
|
if ($request->contact_details != null && !empty($request->contact_details)){
|
|
$value['name'] = 'contact_details';
|
|
$value['value'] = $request->contact_details;
|
|
$this->systemPreference->store($request, $value );
|
|
|
|
}
|
|
|
|
// if ($request->information_guide_details != null && !empty($request->information_guide_details)){
|
|
if ($request->has("information_guide_details")){ // allow empty
|
|
$value['name'] = 'information_guide_details';
|
|
$value['value'] = $request->information_guide_details;
|
|
$this->systemPreference->store($request, $value );
|
|
|
|
}
|
|
|
|
if ($request->has("android_version")){ // allow empty
|
|
$value['name'] = 'android_version';
|
|
$value['value'] = $request->android_version;
|
|
$this->systemPreference->store($request, $value );
|
|
|
|
}
|
|
|
|
if ($request->has("android_update_message")){ // allow empty
|
|
$value['name'] = 'android_update_message';
|
|
$value['value'] = $request->android_update_message;
|
|
$this->systemPreference->store($request, $value );
|
|
|
|
}
|
|
|
|
if ($request->has("android_action")){ // allow empty
|
|
$value['name'] = 'android_action';
|
|
$value['value'] = $request->android_action;
|
|
$this->systemPreference->store($request, $value );
|
|
|
|
}
|
|
|
|
|
|
if ($request->has("ios_version")){ // allow empty
|
|
$value['name'] = 'ios_version';
|
|
$value['value'] = $request->ios_version;
|
|
$this->systemPreference->store($request, $value );
|
|
|
|
}
|
|
|
|
if ($request->has("ios_update_message")){ // allow empty
|
|
$value['name'] = 'ios_update_message';
|
|
$value['value'] = $request->ios_update_message;
|
|
$this->systemPreference->store($request, $value );
|
|
|
|
}
|
|
|
|
if ($request->has("ios_action")){ // allow empty
|
|
$value['name'] = 'ios_action';
|
|
$value['value'] = $request->ios_action;
|
|
$this->systemPreference->store($request, $value );
|
|
|
|
}
|
|
|
|
return $this->format->success("SUCCESS");
|
|
|
|
}
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show($id)
|
|
{
|
|
|
|
$rpreference = $this->systemPreference->getByField('name', $id);
|
|
|
|
if (!$rpreference){
|
|
return $this->format->success("No records found",[]);
|
|
}
|
|
|
|
$additionals = $this->format->success("Success",[],false);
|
|
$data = (new SystemPreferencesResource($rpreference['0']))->additional($additionals);
|
|
|
|
return $data->response()->setStatusCode(200);
|
|
}
|
|
|
|
public function show_mobile($id)
|
|
{
|
|
|
|
$rpreference = $this->systemPreference->getByField('name', $id);
|
|
|
|
if (!$rpreference){
|
|
return $this->format->mobile_success("No records found",[]);
|
|
}
|
|
|
|
|
|
return $this->format->mobile_success('Success',[
|
|
'name' => $rpreference[0]->name,
|
|
'value' => $rpreference[0]->value,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Request $request, $id)
|
|
{
|
|
//
|
|
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
public function mobile_system_preference()
|
|
{
|
|
$rpreference = $this->systemPreference->getAll();
|
|
$data = [];
|
|
foreach ($rpreference as $key => $value) {
|
|
$data[$value['name']] = $value['value'] ;
|
|
}
|
|
|
|
if (empty($data)){
|
|
return $this->format->mobile_error('please contact us');
|
|
}
|
|
return $this->format->mobile_success('Success',$data);
|
|
|
|
}
|
|
|
|
public function about_us()
|
|
{
|
|
$stratuscast = new StratuscastLibrary();
|
|
$stratuscast->getAboutUs();
|
|
|
|
if(isset($stratuscast->response['data']))
|
|
{
|
|
$response = $stratuscast->response['data'];
|
|
|
|
$what_we_do_content = explode(' ', $response->what_we_do_content);
|
|
unset($what_we_do_content[0]);
|
|
|
|
$why_unioil_content = explode(' ', $response->why_unioil_content);
|
|
unset($why_unioil_content[0]);
|
|
|
|
if(
|
|
$this->systemPreference->update('who_we_are_content',$response->who_we_are_content) &&
|
|
$this->systemPreference->update('what_we_do_content',serialize($what_we_do_content)) &&
|
|
$this->systemPreference->update('why_unioil_content',serialize($why_unioil_content))
|
|
)
|
|
{
|
|
return $this->format->success('Success');
|
|
}
|
|
else
|
|
{
|
|
return $this->format->badRequest('Something went wrong');
|
|
}
|
|
}
|
|
else
|
|
return $this->format->badRequest('Something went wrong');
|
|
}
|
|
|
|
|
|
public function mobile_version($platform)
|
|
{
|
|
$data = [];
|
|
if($platform != "android" && $platform != "ios"){
|
|
return $this->format->mobile_error('please contact us');
|
|
}
|
|
|
|
$rpreference = $this->systemPreference->getByField('name', $platform."_version");
|
|
|
|
if (!$rpreference){
|
|
return $this->format->success("No records found",[]);
|
|
}
|
|
|
|
$updateMsg = $this->systemPreference->getByField('name', $platform."_update_message");
|
|
$updateAct = $this->systemPreference->getByField('name', $platform."_action");
|
|
|
|
$data['version'] = $rpreference[0]->value;
|
|
$data['update_action'] = !$updateAct?"0":$updateAct[0]->value;
|
|
$data['update_message'] = !$updateMsg?"A new update is available to provide you with a more secure, stable and seamless user experience.":$updateMsg[0]->value;
|
|
|
|
return $this->format->mobile_success('Success',$data);
|
|
}
|
|
|
|
}
|
|
|