|
Server : Apache/2.4.41 (Ubuntu) System : Linux vmi1525618.contaboserver.net 5.4.0-105-generic #119-Ubuntu SMP Mon Mar 7 18:49:24 UTC 2022 x86_64 User : www-data ( 33) PHP Version : 8.2.12 Disable Function : NONE Directory : /var/www/parassaas.edukrypt.in/app/Http/Controllers/ |
Upload File : |
<?php
namespace App\Http\Controllers;
use App\Models\Product;
use App\Models\Billing;
use App\Models\Orderproductgroup;
use App\Models\Category;
use App\Models\Main_category;
use App\Models\Content;
use App\Models\S3bucket;
use App\Models\Re_s3bucket;
use App\Models\Schedule_live_product;
use App\Models\Video_history;
use App\Models\Tag;
use App\Models\Pdf_test;
use App\Models\Ebook;
use App\Models\Revision_material;
use App\Models\Revision_material_file;
use App\Models\Blog;
use App\Models\Mcq;
use App\Models\Mcq_history;
use Illuminate\Http\Request;
use JWTAuth;
use Tymon\JWTAuth\Exceptions\JWTException;
use Symfony\Component\HttpFoundation\Response;
use Illuminate\Support\Facades\Validator;
use AWS\S3\S3Client;
use Aws\S3\S3Client as S3S3Client;
use Aws\CognitoIdentity\CognitoIdentityClient;
use Aws\Exception\AwsException;
use Aws\S3\Exception\S3Exception;
use Aws\S3\PostObjectV4;
use App\Helpers\Frontend;
class ApiProductController extends Controller
{
protected $user;
// public function __construct()
// {
// $this->user = JWTAuth::parseToken()->authenticate();
// }
// Parent Category
public function getMainCategory(Request $request)
{
$admin_id = 2;
$category = Main_category::where(['parent_id' => '0', 'status' => '1', 'type' => 'content'])->orderBy('id', 'DESC')->get();
if (!empty($category)) {
return response()->json([
'status' => 1,
'success' => true,
'message' => 'Category Fetch successfully',
'data' => $category
], Response::HTTP_OK);
} else {
return response()->json([
'status' => 0,
'success' => true,
'message' => 'Data Not Found',
'data' => "{}"
], Response::HTTP_OK);
}
}
// Purchased Course list
public function purchasedProductList(Request $request)
{
$data = $request->only('user_unique_id');
$validator = Validator::make($data, [
'user_unique_id' => 'required|string',
]);
$admin_id = 2;
if (!$request->user_unique_id) {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'Please insert All Required Field',
'data' => '{}'
], 200);
}
$billings = Billing::where(['billings.admin_id' => $admin_id, 'billings.user_unique_id' => $request->user_unique_id, 'billings.payment_status' => 'Credit', 'orderproductgroups.expired' => '0'])
->join('orderproductgroups', 'orderproductgroups.billing_id', '=', 'billings.id')
->join('products', 'products.id', '=', 'orderproductgroups.product_id')
->get(['orderproductgroups.*', 'products.name', 'products.image', 'products.type', 'products.teacher_id']);
$purchasedProduct = array();
if (!empty($billings)) {
foreach ($billings as $billing) {
$getTeacher = Frontend::getTeacher($billing->teacher_id);
$_purchasedProduct = array(
'product_id' => $billing->product_id,
'name' => $billing->name,
'teacher_name' => (!empty($getTeacher->username)) ? $getTeacher->username : "",
'type' => $billing->type,
'image' => asset('public/uploads/products/' . $billing->image),
'billing_id' => $billing->billing_id,
);
array_push($purchasedProduct, $_purchasedProduct);
}
}
if (!empty($purchasedProduct)) {
return response()->json([
'status' => 1,
'success' => true,
'message' => 'User created successfully',
'data' => $purchasedProduct
], Response::HTTP_OK);
} else {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'Data Not Found',
'data' => $purchasedProduct
], Response::HTTP_OK);
}
}
// product content details
public function productContentList(Request $request)
{
$data = $request->only('product_id', 'user_unique_id');
$validator = Validator::make($data, [
'product_id' => 'required',
'user_unique_id' => 'required'
]);
if (!$request->user_unique_id || !$request->product_id) {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'Please insert All Required Field',
'data' => '{}'
], 200);
}
$admin_id = 2;
$billings = Billing::select('orderproductgroups.*')->where(['billings.admin_id' => $admin_id, 'billings.user_unique_id' => $request->user_unique_id, 'billings.payment_status' => 'Credit', 'orderproductgroups.expired' => '0', 'orderproductgroups.product_id' => $request->product_id])
->join('orderproductgroups', 'orderproductgroups.billing_id', '=', 'billings.id')
->get()->last();
$video = Content::join('re_s3buckets', 're_s3buckets.etag', '=', 'contents.video_id')
->where(['contents.product_id' => $request->product_id, 'contents.type' => 'video'])
->get(['contents.*', 're_s3buckets.filename', 're_s3buckets.size']);
$play_video = Video_history::join('re_s3buckets', 're_s3buckets.etag', '=', 'video_histories.video_id')
->where(['video_histories.product_id' => $request->product_id, 'video_histories.user_unique_id' => $request->user_unique_id])->get(['re_s3buckets.filename', 're_s3buckets.size']);
$practice_test = Content::join('mcqs', 'mcqs.id', '=', 'contents.video_id')
->where(['contents.product_id' => $request->product_id, 'contents.type' => 'practice_test'])
->get(['contents.*', 'mcqs.name']);
$attempt_practice = Mcq_history::join('mcqs', 'mcqs.id', '=', 'mcq_histories.mcq_id')
->where(['mcq_histories.product_id' => $request->product_id, 'mcq_histories.user_unique_id' => $request->user_unique_id])->get(['mcqs.name']);
// days left
$future = strtotime($billings->expire_date); //Future date.
$timefromdb = strtotime(date('Y-m-d')); //source time
$timeleft = $future - $timefromdb;
$daysleft = round((($timeleft / 24) / 60) / 60);
// dd($practice_test->count());
// dd($play_video->count());
// echo "<pre>"; print_r($video);exit;
$data = array(
'product_id' => $request->product_id,
'expire_on' => $billings->expire_date,
'days_left' => $daysleft,
'total_video' => $video->count(),
'video_view' => $play_video->count(),
'video_percent' => round(($play_video->count() * $video->count()) / 100),
'total_practice' => $practice_test->count(),
'attempt_practice' => $attempt_practice->count(),
'practice_percent' => round(($attempt_practice->count() * $practice_test->count()) / 10),
);
if ($billings->count() > 0) {
return response()->json([
'status' => 1,
'success' => true,
'message' => 'Product analytics found',
'data' => $data
], Response::HTTP_OK);
} else {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'Product analytics not found',
'data' => '{}'
], Response::HTTP_OK);
}
}
public function multilevel($cat_id, $admin_id, $product_id)
{
// multilevel
$main_array = array();
$results = Category::where(['product_id' => $product_id, 'admin_id' => $admin_id, 'parent_id' => $cat_id])->get();
if (!empty($results)) {
foreach ($results as $data) {
if ($data->type == 'category') {
$sub_array = array(
'id' => $data->id,
'parent_id' => $data->parent_id,
'name' => $data->name,
'type' => $data->type,
'subcat' => $this->multilevel($data->id, $admin_id, $product_id)
);
} else {
$sub_array = array(
'id' => $data->id,
'parent_id' => $data->parent_id,
'name' => $data->name,
'type' => $data->type,
'content' => array(
'video' => array(),
'pdf' => array(),
'practice_test' => array()
)
);
$contents = Content::join('re_s3buckets', 're_s3buckets.etag', '=', 'contents.video_id')
->where(['cat_id' => $data->id])
->get(['contents.*', 're_s3buckets.filename', 're_s3buckets.size']);
// dd($contents);
if (!empty($contents)) {
foreach ($contents as $content) {
if ($content->type == 'video') {
$_video_arr = array(
'product_id' => $content->product_id,
'cat_id' => $content->cat_id,
'video_id' => $content->video_id,
'filename' => $content->filename,
'size' => $content->size,
);
array_push($sub_array['content']['video'], $_video_arr);
} else if ($content->type == 'pdf') {
$_video_arr = array(
'product_id' => $content->product_id,
'cat_id' => $content->cat_id,
'video_id' => $content->video_id,
'filename' => $content->filename,
'size' => $content->size,
);
array_push($sub_array['content']['pdf'], $_video_arr);
} else if ($content->type == 'practice_test') {
$_video_arr = array(
'product_id' => $content->product_id,
'cat_id' => $content->cat_id,
'video_id' => $content->video_id,
'filename' => $content->filename,
'size' => $content->size,
);
array_push($sub_array['content']['practice_test'], $_video_arr);
}
}
}
}
array_push($main_array, $sub_array);
}
}
return $main_array;
}
public function videoDownload(Request $request)
{
$data = $request->only('user_unique_id', 'product_id', 'video_id');
$validator = Validator::make($data, [
'user_unique_id' => 'required',
'product_id' => 'required',
'video_id' => 'required'
]);
if (!$request->user_unique_id || !$request->product_id || !$request->video_id) {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'Please insert All Required Field',
'data' => '{}'
], 200);
}
$admin_id = 2;
$billings = Billing::select('orderproductgroups.*')->where(['billings.admin_id' => $admin_id, 'orderproductgroups.expired' => '0', 'billings.user_unique_id' => $request->user_unique_id, 'billings.payment_status' => 'Credit', 'orderproductgroups.product_id' => $request->product_id])
->join('orderproductgroups', 'orderproductgroups.billing_id', '=', 'billings.id')
->get()->last();
if (!empty($billings)) {
$bucket = S3bucket::where(['etag' => $request->video_id])->first();
// dd($bucket);
if (!empty($bucket->path)) {
$path = $bucket->path;
$getLink = $this->getObjectlink($path);
return response()->json([
'status' => 1,
'success' => true,
'message' => 'Link Created',
'data' => $getLink
], Response::HTTP_OK);
} else {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'Video Not Found',
'data' => '{}'
], Response::HTTP_OK);
}
} else {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'Not Autorised User',
'data' => '{}'
], Response::HTTP_OK);
}
}
public function getObjectlink($path)
{
// $accessKey = "CFJCRZGYFSPGIHPGRL7E";
// $secretKey = "uXwwK1/VqejH+b/82xwHfHlfqAYf2pYgGU8IwxUO2J4";
// $region = "nyc3";
// $host = "https://nyc3.digitaloceanspaces.com";
// $bucket = "navinclasses";
$accessKey = env('AWS_S3_ACCESS_KEY');
$secretKey = env('AWS_S3_SECRET_KEY');
$region = env('AWS_REGION');
$host = env('AWS_HOST');
$bucket = env('AWS_BUCKET');
$s3 = new S3S3Client([
'version' => 'latest',
'region' => $region,
'endpoint' => $host,
'credentials' => [
'key' => $accessKey,
'secret' => $secretKey
]
]);
// dd($s3);
$s3->putBucketCors([
'Bucket' => $bucket, // REQUIRED
'CORSConfiguration' => [ // REQUIRED
'CORSRules' => [ // REQUIRED
[
'AllowedMethods' => ['POST', 'GET', 'HEAD', 'DELETE', 'PUT'], // REQUIRED
'AllowedHeaders' => ['*'],
'AllowedOrigins' => ['*'], // REQUIRED
'ExposeHeaders' => ['ETag'],
'MaxAgeSeconds' => 0
],
],
]
]);
try {
//Creating a presigned URL
$cmd = $s3->getCommand('GetObject', [
'Bucket' => $bucket,
'Key' => $path
]);
$request = $s3->createPresignedRequest($cmd, '+55 minutes');
// Get the actual presigned-url
$presignedUrl = (string)$request->getUri();
$_pathf = $path;
$_urlf = "https://" . env('AWS_BUCKET') . "." . env('AWS_REGION') . ".cdn.digitaloceanspaces.com/" . $_pathf . "?" . parse_url($presignedUrl, PHP_URL_QUERY);
$url = array(
'url' => $_urlf
);
return $url;
// echo json_encode(['code' => 200, 'status' => true, 'url' => $presignedUrl]);
} catch (S3Exception $e) {
echo $e->getMessage() . PHP_EOL;
}
}
public function showAllLiveProductForAll(Request $request)
{
$results = array(
'liveschedule' => array(),
'upcomingevents' => array()
);
$data = $request->only('user_unique_id');
$validator = Validator::make($data, [
'user_unique_id' => 'required|string'
]);
if ($validator->fails()) {
return response()->json([
'status' => 0,
'success' => false,
'message' => "All fields are required!",
'data' => '{}'
], 200);
}
$admin_id = 2;
$results_data = Billing::where(['billings.admin_id' => $admin_id, 'orderproductgroups.expired' => '0', 'billings.user_unique_id' => $request->user_unique_id, 'billings.payment_status' => 'Credit'])
->where('schedule_live_products.end_date', '>=', date('Y-m-d'))
->join('orderproductgroups', 'orderproductgroups.billing_id', '=', 'billings.id')
->join('products', 'products.id', '=', 'orderproductgroups.product_id')
->join('schedule_live_products', 'schedule_live_products.prod_id', '=', 'orderproductgroups.product_id')
->join('studios', 'studios.std_id', '=', 'schedule_live_products.studio_id')
->join('admin_users', 'admin_users.id', '=', 'products.teacher_id')
->get(['schedule_live_products.*', 'billings.user_unique_id', 'admin_users.username']);
//dd($results_data);
$purchasedProduct = array();
if (!empty($results_data)) {
foreach ($results_data as $result) {
// for live schdule data current date
$current_date = strtotime(date('Y-m-d'));
$start_date = strtotime($result->start_date);
$end_date = strtotime($result->end_date);
$current_time = date('H:i:s', strtotime(date('H:i:s')));
$start_time = date('H:i:s', strtotime($result->start_time));
$end_time = date('H:i:s', strtotime($result->end_time));
// 05 <= 05 && 05 <= 05
// 14 <= 14 && 14 <= 14
if ($start_date <= $current_date && $current_date <= $end_date) {
if ($start_time <= $current_time && $current_time <= $end_time) {
$res = array(
'id' => $result->id,
'studio_id' => base64_encode($result->studio_id),
'prod_id' => $result->prod_id,
'program_name' => $result->program_name,
'start_date' => $result->start_date,
'end_date' => $result->end_date,
'start_time' => $result->start_time,
'end_time' => $result->end_time,
'status' => $result->status,
'created_at' => date('Y-m-d H:i:s', strtotime($result->created_at)),
'author' => $result->username,
'livestatus' => '1',
);
array_push($results['liveschedule'], $res);
} else {
//if ($start_date <= $current_date && $current_date != $end_date) {
$res = array(
'id' => $result->id,
'studio_id' => base64_encode($result->studio_id),
'prod_id' => $result->prod_id,
'program_name' => $result->program_name,
'start_date' => $result->start_date,
'end_date' => $result->end_date,
'start_time' => $result->start_time,
'end_time' => $result->end_time,
'status' => $result->status,
'created_at' => date('Y-m-d H:i:s', strtotime($result->created_at)),
'author' => $result->username,
'livestatus' => '0',
);
array_push($results['upcomingevents'], $res);
//} else {
//dd($result);
//}
}
} else {
$res = array(
'id' => $result->id,
'studio_id' => base64_encode($result->studio_id),
'prod_id' => $result->prod_id,
'program_name' => $result->program_name,
'start_date' => $result->start_date,
'end_date' => $result->end_date,
'start_time' => $result->start_time,
'end_time' => $result->end_time,
'status' => $result->status,
'created_at' => date('Y-m-d H:i:s', strtotime($result->created_at)),
'author' => $result->username,
'livestatus' => '0',
);
array_push($results['upcomingevents'], $res);
}
}
}
return response()->json([
'status' => 1,
'success' => true,
'message' => 'data Fetch successfully',
'data' => $results
], Response::HTTP_OK);
}
public function showAllLiveProduct(Request $request)
{
$results = array(
'liveschedule' => array(),
'upcomingevents' => array()
);
$data = $request->only('user_unique_id', 'product_id');
$validator = Validator::make($data, [
'user_unique_id' => 'required|string',
'product_id' => 'required',
]);
if ($validator->fails()) {
return response()->json([
'status' => 0,
'success' => false,
'message' => $validator->messages(),
'data' => '{}'
], 200);
}
$admin_id = 2;
$results_data = Billing::where(['products.id' => $request->product_id, 'billings.admin_id' => $admin_id, 'orderproductgroups.expired' => '0', 'billings.user_unique_id' => $request->user_unique_id, 'billings.payment_status' => 'Credit'])
->where('schedule_live_products.end_date', '>=', date('Y-m-d'))
->join('orderproductgroups', 'orderproductgroups.billing_id', '=', 'billings.id')
->join('products', 'products.id', '=', 'orderproductgroups.product_id')
->join('schedule_live_products', 'schedule_live_products.prod_id', '=', 'orderproductgroups.product_id')
->join('studios', 'studios.std_id', '=', 'schedule_live_products.studio_id')
->join('admin_users', 'admin_users.id', '=', 'products.teacher_id')
->get(['schedule_live_products.*', 'billings.user_unique_id', 'admin_users.username']);
//dd($results_data);
$purchasedProduct = array();
if (!empty($results_data)) {
foreach ($results_data as $result) {
// for live schdule data current date
$current_date = strtotime(date('Y-m-d'));
$start_date = strtotime($result->start_date);
$end_date = strtotime($result->end_date);
$current_time = date('H:i:s', strtotime(date('H:i:s')));
$start_time = date('H:i:s', strtotime($result->start_time));
$end_time = date('H:i:s', strtotime($result->end_time));
// 05 <= 05 && 05 <= 05
// 06 <= 05 && 05 <= 06
if ($start_date <= $current_date && $current_date <= $end_date) {
//echo ($start_time ."<=". $current_time ."&&". $current_time .">=". $end_time); exit;
//echo ($current_time >= $end_time);exit;
if ($start_time <= $current_time && $current_time <= $end_time) {
$res = array(
'id' => $result->id,
'studio_id' => base64_encode($result->studio_id),
'prod_id' => $result->prod_id,
'program_name' => $result->program_name,
'start_date' => $result->start_date,
'end_date' => $result->end_date,
'start_time' => $result->start_time,
'end_time' => $result->end_time,
'status' => $result->status,
'created_at' => date('Y-m-d H:i:s', strtotime($result->created_at)),
'author' => $result->username,
'livestatus' => '1',
);
array_push($results['liveschedule'], $res);
} else {
//if ($start_date <= $current_date && $current_date != $end_date) {
$res = array(
'id' => $result->id,
'studio_id' => base64_encode($result->studio_id),
'prod_id' => $result->prod_id,
'program_name' => $result->program_name,
'start_date' => $result->start_date,
'end_date' => $result->end_date,
'start_time' => $result->start_time,
'end_time' => $result->end_time,
'status' => $result->status,
'created_at' => date('Y-m-d H:i:s', strtotime($result->created_at)),
'author' => $result->username,
'livestatus' => '0',
);
array_push($results['upcomingevents'], $res);
//} else {
//dd($result);
//}
}
} else {
$res = array(
'id' => $result->id,
'studio_id' => base64_encode($result->studio_id),
'prod_id' => $result->prod_id,
'program_name' => $result->program_name,
'start_date' => $result->start_date,
'end_date' => $result->end_date,
'start_time' => $result->start_time,
'end_time' => $result->end_time,
'status' => $result->status,
'created_at' => date('Y-m-d H:i:s', strtotime($result->created_at)),
'author' => $result->username,
'livestatus' => '0',
);
array_push($results['upcomingevents'], $res);
}
}
}
return response()->json([
'status' => 1,
'success' => true,
'message' => 'data Fetch successfully',
'data' => $results
], Response::HTTP_OK);
}
public function categorycontent(Request $request)
{
$data = $request->only('product_id', 'user_unique_id');
$validator = Validator::make($data, [
'product_id' => 'required',
'user_unique_id' => 'required'
]);
if (!$request->user_unique_id || !$request->product_id) {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'Please insert All Required Field',
'data' => '{}'
], 200);
}
$admin_id = 2;
$billings = Billing::select('orderproductgroups.*')->where(['billings.admin_id' => $admin_id, 'billings.user_unique_id' => $request->user_unique_id, 'billings.payment_status' => 'Credit', 'orderproductgroups.expired' => '0', 'orderproductgroups.product_id' => $request->product_id])
->join('orderproductgroups', 'orderproductgroups.billing_id', '=', 'billings.id')
->get()->last();
if (!empty($billings)) {
$categories = Category::where(['product_id' => $request->product_id, 'admin_id' => $admin_id])->get();
return response()->json([
'status' => 1,
'success' => true,
'message' => 'Product category found!',
'data' => $categories
], Response::HTTP_OK);
} else {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'Product category not found',
'data' => '{}'
], Response::HTTP_OK);
}
}
public function videoContent(Request $request)
{
$data = $request->only('product_id', 'user_unique_id', 'cat_id');
$validator = Validator::make($data, [
'product_id' => 'required',
'user_unique_id' => 'required',
'cat_id' => 'required'
]);
if (!$request->user_unique_id || !$request->product_id || !$request->cat_id) {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'Please insert All Required Field',
'data' => '{}'
], 200);
}
$admin_id = 2;
$billings = Billing::select('orderproductgroups.*')->where(['billings.admin_id' => $admin_id, 'billings.user_unique_id' => $request->user_unique_id, 'billings.payment_status' => 'Credit', 'orderproductgroups.expired' => '0', 'orderproductgroups.product_id' => $request->product_id])
->join('orderproductgroups', 'orderproductgroups.billing_id', '=', 'billings.id')
->get()->last();
if (!empty($billings)) {
$videoData = array();
$videos = Content::join('re_s3buckets', 're_s3buckets.etag', '=', 'contents.video_id')
->where(['contents.cat_id' => $request->cat_id])
->get(['contents.*', 're_s3buckets.filename', 're_s3buckets.public_name', 're_s3buckets.path', 're_s3buckets.size', 're_s3buckets.duration']);
//$product = Product::where(['id' => $request->product_id])->first();
$views = $billings->views;
if ($videos->count() > 0) {
foreach ($videos as $video) {
$totalPlayDuration = 0;
$videoHistory = Video_history::where(['admin_id' => $admin_id, 'user_unique_id' => $request->user_unique_id, 'product_id' => $request->product_id, 'cat_id' => $request->cat_id, 'video_id' => $video->video_id])->sum('duration');
if ($videoHistory > 0) {
$totalPlayDuration = round($videoHistory);
}
$totalTime = (!empty($video->duration)) ? ($video->duration * $views) : ($video->duration * $views);
$remainingTime = max(($totalTime - $totalPlayDuration), 0);
$data = array(
'id' => $video->id,
'type' => $video->type,
'video_id' => $video->video_id,
'public_name' => $video->public_name,
'sort_order' => $video->sort_order,
'duration' => $video->duration,
'filename' => $video->filename,
'path' => $video->path,
'size' => $video->size,
"product_id" => $video->product_id,
"cat_id" => $video->cat_id,
'totalTime' => (int) $totalTime,
'remainingTime' => (int) $remainingTime,
'demo_video_type' => '0'
);
array_push($videoData, $data);
}
$tags = Content::join('tags', 'tags.video_id', '=', 'contents.video_id')
->where(['contents.cat_id' => $request->cat_id])
->orderBy('tags.sort_order', 'asc')
->get(['contents.*', 'tags.name', 'tags.video_id', 'tags.time', 'tags.sort_order']);
$content = array(
'videos' => $videoData,
'tags' => $tags
);
return response()->json([
'status' => 1,
'success' => true,
'message' => 'Video content found',
'data' => $content
], Response::HTTP_OK);
} else {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'Video content not found',
'data' => '{}'
], Response::HTTP_OK);
}
} else {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'Video content not found',
'data' => '{}'
], Response::HTTP_OK);
}
}
public function videoHistories(Request $request)
{
$data = $request->only('user_unique_id', 'videohistory');
if (!$request->user_unique_id || !$request->videohistory) {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'Please insert All Required Field',
'data' => '{}'
], 200);
}
$admin_id = 2;
$videoHistoryArray = array();
$sessions = [];
if (count($request->videohistory) > 0) {
$videos = $request->videohistory;
foreach ($videos as $video) {
$data = array(
'admin_id' => $admin_id,
'user_unique_id' => $request->user_unique_id,
'session' => $video['session'],
'product_id' => $video['product_id'],
'cat_id' => $video['cat_id'],
'video_id' => $video['video_id'],
'duration' => $video['duration'],
'created_at' => $video['date']
);
array_push($videoHistoryArray, $data);
$sessions[] = $video['session'];
}
}
$insert = Video_history::insertOrIgnore($videoHistoryArray);
if ($insert) {
return response()->json([
'status' => 1,
'success' => true,
'message' => 'Video play history uploaded successfully',
'data' => $sessions
], Response::HTTP_OK);
} else {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'video play history already uploaded',
'data' => '{}'
], Response::HTTP_OK);
}
}
public function mcqContent(Request $request)
{
$data = $request->only('product_id', 'user_unique_id', 'cat_id');
$validator = Validator::make($data, [
'product_id' => 'required',
'user_unique_id' => 'required',
'cat_id' => 'required'
]);
if (!$request->user_unique_id || !$request->product_id || !$request->cat_id) {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'Please insert All Required Field',
'data' => '{}'
], 200);
}
$admin_id = 2;
$billings = Billing::select('orderproductgroups.*')->where(['billings.admin_id' => $admin_id, 'billings.user_unique_id' => $request->user_unique_id, 'billings.payment_status' => 'Credit', 'orderproductgroups.expired' => '0', 'orderproductgroups.product_id' => $request->product_id])
->join('orderproductgroups', 'orderproductgroups.billing_id', '=', 'billings.id')
->get()->last();
if (!empty($billings)) {
$videos = Content::join('mcqs', 'mcqs.id', '=', 'contents.video_id')
->where(['contents.cat_id' => $request->cat_id, 'contents.type' => 'practice_test'])
->get(['mcqs.id', 'mcqs.name', 'contents.sort_order', 'contents.type', 'contents.product_id', 'contents.cat_id', 'contents.video_id']);
if ($videos->count() > 0) {
return response()->json([
'status' => 1,
'success' => true,
'message' => 'MCQ found',
'data' => $videos
], Response::HTTP_OK);
} else {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'MCQ not found',
'data' => '{}'
], Response::HTTP_OK);
}
} else {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'MCQ not found',
'data' => '{}'
], Response::HTTP_OK);
}
}
public function pdfContent(Request $request)
{
$data = $request->only('product_id', 'user_unique_id', 'cat_id');
$validator = Validator::make($data, [
'product_id' => 'required',
'user_unique_id' => 'required',
'cat_id' => 'required'
]);
if (!$request->user_unique_id || !$request->product_id || !$request->cat_id) {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'Please insert All Required Field',
'data' => '{}'
], 200);
}
$admin_id = 2;
$billings = Billing::select('orderproductgroups.*')->where(['billings.admin_id' => $admin_id, 'billings.user_unique_id' => $request->user_unique_id, 'billings.payment_status' => 'Credit', 'orderproductgroups.expired' => '0', 'orderproductgroups.product_id' => $request->product_id])
->join('orderproductgroups', 'orderproductgroups.billing_id', '=', 'billings.id')
->get()->last();
if (!empty($billings)) {
$videos = Content::join('pdf_tests', 'pdf_tests.etag', '=', 'contents.video_id')
->where(['contents.cat_id' => $request->cat_id, 'contents.type' => 'pdf'])
->get(['contents.*', 'pdf_tests.filename', 'pdf_tests.filename as public_name', 'pdf_tests.etag']);
if ($videos->count() > 0) {
return response()->json([
'status' => 1,
'success' => true,
'message' => 'PDF found',
'data' => $videos
], Response::HTTP_OK);
} else {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'PDF not found',
'data' => '{}'
], Response::HTTP_OK);
}
} else {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'PDF not found',
'data' => '{}'
], Response::HTTP_OK);
}
}
public function pdfTestDownload(Request $request)
{
$data = $request->only('user_unique_id', 'product_id', 'video_id');
$validator = Validator::make($data, [
'user_unique_id' => 'required',
'product_id' => 'required',
'video_id' => 'required'
]);
if (!$request->user_unique_id || !$request->product_id || !$request->video_id) {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'Please insert All Required Field',
'data' => '{}'
], 200);
}
$admin_id = 2;
$billings = Billing::select('orderproductgroups.*')->where(['billings.admin_id' => $admin_id, 'billings.user_unique_id' => $request->user_unique_id, 'billings.payment_status' => 'Credit', 'orderproductgroups.expired' => '0', 'orderproductgroups.product_id' => $request->product_id])
->join('orderproductgroups', 'orderproductgroups.billing_id', '=', 'billings.id')
->get()->last();
if (!empty($billings)) {
$bucket = Pdf_test::where(['etag' => $request->video_id])->first();
if (!empty($bucket->path)) {
$path = $bucket->path;
$getLink = $this->getObjectlink($path);
return response()->json([
'status' => 1,
'success' => true,
'message' => 'Link Created',
'data' => $getLink
], Response::HTTP_OK);
} else {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'Video Not Found',
'data' => '{}'
], Response::HTTP_OK);
}
} else {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'Not Autorised User',
'data' => '{}'
], Response::HTTP_OK);
}
}
// Ebook Content
public function ebookContent(Request $request)
{
$data = $request->only('product_id', 'user_unique_id', 'cat_id');
$validator = Validator::make($data, [
'product_id' => 'required',
'user_unique_id' => 'required',
'cat_id' => 'required'
]);
if (!$request->user_unique_id || !$request->product_id || !$request->cat_id) {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'Please insert All Required Field',
'data' => '{}'
], 200);
}
$admin_id = 2;
$billings = Billing::select('orderproductgroups.*')->where(['billings.admin_id' => $admin_id, 'billings.user_unique_id' => $request->user_unique_id, 'billings.payment_status' => 'Credit', 'orderproductgroups.expired' => '0', 'orderproductgroups.product_id' => $request->product_id])
->join('orderproductgroups', 'orderproductgroups.billing_id', '=', 'billings.id')
->get()->last();
if (!empty($billings)) {
$videos = Content::join('ebooks_mapping', 'ebooks_mapping.etag', '=', 'contents.video_id')
->where(['contents.cat_id' => $request->cat_id, 'contents.type' => 'ebook'])
->get(['contents.*', 'ebooks_mapping.filename', 'ebooks_mapping.public_name', 'ebooks_mapping.etag']);
if ($videos->count() > 0) {
return response()->json([
'status' => 1,
'success' => true,
'message' => 'Ebook found',
'data' => $videos
], Response::HTTP_OK);
} else {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'Ebook not found',
'data' => '{}'
], Response::HTTP_OK);
}
} else {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'Ebook data found',
'data' => '{}'
], Response::HTTP_OK);
}
}
public function ebookDownload(Request $request)
{
$data = $request->only('user_unique_id', 'product_id', 'video_id');
if (!$request->user_unique_id || !$request->product_id || !$request->video_id) {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'Please insert All Required Field',
'data' => '{}'
], 200);
}
$admin_id = 2;
$billings = Billing::select('orderproductgroups.*')->where(['billings.admin_id' => $admin_id, 'billings.user_unique_id' => $request->user_unique_id, 'billings.payment_status' => 'Credit', 'orderproductgroups.expired' => '0', 'orderproductgroups.product_id' => $request->product_id])
->join('orderproductgroups', 'orderproductgroups.billing_id', '=', 'billings.id')
->get()->last();
// dd($billings);
if (!empty($billings)) {
$bucket = Ebook::where(['etag' => $request->video_id])->first();
if (!empty($bucket->path)) {
$path = $bucket->path;
$getLink = $this->getObjectlink($path);
return response()->json([
'status' => 1,
'success' => true,
'message' => 'Link Created',
'data' => $getLink
], Response::HTTP_OK);
} else {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'Video Not Found',
'data' => '{}'
], Response::HTTP_OK);
}
} else {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'Not Autorised User',
'data' => '{}'
], Response::HTTP_OK);
}
}
public function revisionMaterial(Request $request)
{
if (!$request->type || !$request->product_id) {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'Please insert All Required Field',
'data' => '{}'
], 200);
}
$learn_revision = Revision_material::where(['type' => $request->type, 'product_id' => $request->product_id])->get();
//dd($learn_revision);
if (!empty($learn_revision)) {
$revisionMaterial = array();
foreach ($learn_revision as $learn_revi) {
$data = array(
'id' => $learn_revi->id,
'chapters' => $learn_revi->chapters,
'type' => $learn_revi->type,
'product_id' => $learn_revi->product_id,
'files' => array()
);
$learn_revision_files = Revision_material_file::where(['revision_material_id' => $learn_revi->id])->get();
if (!empty($learn_revision_files)) {
foreach ($learn_revision_files as $learn_revision_file) {
$fileURL = base64_encode($learn_revision_file->files_url);
if ($learn_revision_file->type == 'pdf') {
$fileURL = base64_encode("https://sgp1.digitaloceanspaces.com/navincls/" . $learn_revision_file->files_url);
}
$file_data = array(
'id' => $learn_revi->id,
'file_name' => $learn_revision_file->file_name,
'files_url' => $fileURL,
'type' => $learn_revision_file->type,
);
array_push($data['files'], $file_data);
}
}
array_push($revisionMaterial, $data);
}
return response()->json([
'status' => 1,
'success' => true,
'message' => 'Data Fetch Successfully',
'data' => $revisionMaterial
], 200);
} else {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'Data Not Found',
'data' => '{}'
], 200);
}
}
public function blog(Request $request)
{
$blogs = Blog::where(['status' => '1'])->orderBy('sort_order', 'ASC')->get();
if (!empty($blogs)) {
$__blog = array();
foreach ($blogs as $blog) {
$_blog = array(
'id' => $blog->id,
'blog_title' => $blog->blog_title,
'short_desc' => $blog->short_desc,
'description' => $blog->description,
'author' => $blog->author,
'image' => asset('public/uploads/blog/' . $blog->image),
'created_at' => $blog->created_at,
);
array_push($__blog, $_blog);
}
return response()->json([
'status' => 1,
'success' => true,
'message' => 'Data Fetch Successfully',
'data' => $__blog
], 200);
} else {
return response()->json([
'status' => 0,
'success' => false,
'message' => 'Data Not Found',
'data' => '{}'
], 200);
}
}
}