save to codehub
This commit is contained in:
24
app/Http/Controllers/API/AboutController.php
Normal file
24
app/Http/Controllers/API/AboutController.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\ManageAboutUs;
|
||||
|
||||
class AboutController extends Controller
|
||||
{
|
||||
|
||||
public function get_About_Us() {
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$userid = auth()->user();
|
||||
|
||||
$aboutdata = ManageAboutUs::where($userid)->get();
|
||||
return response([
|
||||
'user' => $aboutdata,
|
||||
// 'token' => $user->createToken('secret')->plainTextToken
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
}
|
||||
51
app/Http/Controllers/API/ContactController.php
Normal file
51
app/Http/Controllers/API/ContactController.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\ContactUs;
|
||||
use App\Models\User;
|
||||
use Auth;
|
||||
|
||||
class ContactController extends Controller {
|
||||
|
||||
public function store_contact_us(Request $req) {
|
||||
try {
|
||||
//
|
||||
$token = readHeaderToken();
|
||||
// print_r($token);exit;
|
||||
if($token){
|
||||
$user = auth()->user();
|
||||
// $bankobj = new ContactUs;
|
||||
// print_r($req->all());
|
||||
// exit;
|
||||
$contactdata = array(
|
||||
'user_id' => $token['sub'],
|
||||
'name' => $req->name,
|
||||
'email_id' => $req->email_id,
|
||||
'contact_number' => $req->contact_number,
|
||||
'subject' => $req->subject,
|
||||
'type' => $req->type,
|
||||
'message' => $req->message,
|
||||
'is_reply' => '0',
|
||||
'is_active' => '1',
|
||||
);
|
||||
|
||||
// print_r($contactdata);
|
||||
// exit;
|
||||
// $userobj = User::find($user);
|
||||
$data = ContactUs::create($contactdata);
|
||||
}
|
||||
return response([
|
||||
'status' => "Success",
|
||||
], 200);
|
||||
// return $data;
|
||||
} catch (Exception $ex) {
|
||||
return response([
|
||||
'status' => "failed",
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CreateNotificationOneSignalController extends Controller
|
||||
{
|
||||
function createNotification(Request $request) {
|
||||
$player_id = $request->player_id;
|
||||
$heading = $request->heading;
|
||||
$message = $request->content;
|
||||
$client = new \GuzzleHttp\Client();
|
||||
$response = $client->request('POST', 'https://onesignal.com/api/v1/notifications?app_id=1be4b99b-8faa-45b8-ad82-c66225d77bf4', [
|
||||
'body' => '{"include_player_ids":["'.$player_id.'"],"headings":{"en":"'.$heading.'"},"contents":{"en":"'.$message.'"},"name":"INTERNAL_CAMPAIGN_NAME"}',
|
||||
'headers' => [
|
||||
'Authorization' => 'Basic MWM2NGEyODUtN2U5MS00MzlkLWJhYmItZGUyODRjYTlmNGJm',
|
||||
'accept' => 'application/json',
|
||||
'content-type' => 'application/json',
|
||||
],
|
||||
]);
|
||||
$resBody = $response->getBody();
|
||||
return $resBody;
|
||||
}
|
||||
}
|
||||
68
app/Http/Controllers/API/DietPlanController.php
Normal file
68
app/Http/Controllers/API/DietPlanController.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\DietPlan;
|
||||
use App\Models\UserOverView;
|
||||
|
||||
|
||||
class DietPlanController extends Controller
|
||||
{
|
||||
|
||||
public function get_diet_categories(Request $request)
|
||||
{
|
||||
try {
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
|
||||
$filters = $request->diet_categories;
|
||||
|
||||
// Retrieve the user's bmr from UserOverview table
|
||||
$userOverview = UserOverview::where('user_id', $user_id)
|
||||
->orderBy('id', 'desc')
|
||||
->first();
|
||||
// dd($userOverview);
|
||||
$bmr = $userOverview->bmr;
|
||||
$bmrInt = intval($bmr);
|
||||
|
||||
// Retrieve diet plans based on filters and bmr range
|
||||
$query = DietPlan::query();
|
||||
|
||||
// Apply filters
|
||||
if ($filters && in_array($filters, ['Veg', 'Non-Veg'])) {
|
||||
$query->where('diet_categories', '=', $filters);
|
||||
}
|
||||
|
||||
// Apply bmr range filter
|
||||
$query->where('bmr_range_from', '<=', $bmrInt)
|
||||
->where('bmr_range_to', '>=', $bmrInt);
|
||||
|
||||
// Add more filter conditions if needed
|
||||
|
||||
$manage_diet_plan = $query->get()->toArray();
|
||||
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data fetched successfully.',
|
||||
'result' => $manage_diet_plan
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("Activity data listing failed: " . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something went wrong.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
24
app/Http/Controllers/API/FaqController.php
Normal file
24
app/Http/Controllers/API/FaqController.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\ManageFaq;
|
||||
use Auth;
|
||||
|
||||
class FaqController extends Controller {
|
||||
|
||||
public function get_faq() {
|
||||
$token = readHeaderToken();
|
||||
if($token){
|
||||
|
||||
$faqdata = ManageFaq::with('category')->where('is_active','1')->get();
|
||||
return response([
|
||||
'user' => $faqdata,
|
||||
// 'token' => $user->createToken('secret')->plainTextToken
|
||||
], 200);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
56
app/Http/Controllers/API/GetAppVersionCotroller.php
Normal file
56
app/Http/Controllers/API/GetAppVersionCotroller.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\AppVersion;
|
||||
class GetAppVersionCotroller extends Controller
|
||||
{
|
||||
public function getOlderVersion(Request $request){
|
||||
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
$appOlderVersionAndroi = $request->old_version_android;
|
||||
$appOlderVersionIOS = $request->old_version_ios;
|
||||
|
||||
if($appOlderVersionAndroi){
|
||||
$version = AppVersion::updateOrCreate(['user_id'=>$user_id],['old_version_android'=>$appOlderVersionAndroi]);
|
||||
}else{
|
||||
$version = AppVersion::updateOrCreate(['user_id'=>$user_id],['old_version_ios'=>$appOlderVersionIOS]);
|
||||
}
|
||||
if($version){
|
||||
return response(['status' => "Success"], 200);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getNewVersion(){
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
|
||||
$newVersion = AppVersion::where('user_id',$user_id)->first();
|
||||
return response(['result' => $newVersion,'status'=>"Success",'message'=>"Data Fetch Successfully"]);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateAppVersion(Request $request){
|
||||
|
||||
$allData = AppVersion::all();
|
||||
|
||||
$ios = $request->new_version_ios;
|
||||
$android = $request->new_version_android;
|
||||
if($ios){
|
||||
AppVersion::update(['new_version_ios'=>$ios]);
|
||||
}elseif($android){
|
||||
AppVersion::update(['new_version_ios'=>$android]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
830
app/Http/Controllers/API/LeaderBordMasterContoller.php
Normal file
830
app/Http/Controllers/API/LeaderBordMasterContoller.php
Normal file
@@ -0,0 +1,830 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\LeaderboardMaster;
|
||||
use App\Models\User;
|
||||
use App\Models\UserDetail;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use App\Models\MonthlyPosition;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class LeaderBordMasterContoller extends Controller {
|
||||
|
||||
// public function get_user_ranking() {
|
||||
// try {
|
||||
// $token = readHeaderToken();
|
||||
// if ($token) {
|
||||
// $user_id = $token['sub'];
|
||||
//
|
||||
// // Retrieve the user's ranking and related user details
|
||||
// $userRanking = LeaderboardMaster::with('user', 'user_details')
|
||||
// ->get();
|
||||
// return response()->json([
|
||||
// 'success' => true,
|
||||
// 'user_ranking' => $userRanking,
|
||||
// 'message' => 'Data Fetch Successfully!.',
|
||||
// ]);
|
||||
// } else {
|
||||
// return response()->json([
|
||||
// 'success' => false,
|
||||
// 'message' => 'Authentication failed.',
|
||||
// ]);
|
||||
// }
|
||||
// } catch (\Exception $e) {
|
||||
// \Log::error("User ranking retrieval failed: " . $e->getMessage());
|
||||
// return response()->json([
|
||||
// 'success' => false,
|
||||
// 'message' => 'Something went wrong.',
|
||||
// ]);
|
||||
// }
|
||||
// }
|
||||
|
||||
public function get_user_ranking($sortOrder = 'desc') {
|
||||
try {
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
|
||||
// Retrieve the user's ranking and related user details
|
||||
$userRanking = LeaderboardMaster::with('user', 'user_data')
|
||||
->orderBy('total_score', $sortOrder)
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'user_ranking' => $userRanking,
|
||||
'message' => 'Data Fetch Successfully!.',
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("User ranking retrieval failed: " . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something went wrong.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_user_gender(Request $request) {
|
||||
try {
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
|
||||
$filters = $request->gender;
|
||||
$query = LeaderboardMaster::with(['user', 'user_data']);
|
||||
|
||||
// Apply filters
|
||||
if ($filters && in_array($filters, ['male', 'female'])) {
|
||||
$query->whereHas('user_data', function ($query) use ($filters) {
|
||||
$query->where('gender', '=', $filters);
|
||||
});
|
||||
}
|
||||
// Add more filter conditions if needed
|
||||
|
||||
$manage_activity = $query->get()->toArray();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data fetched successfully.',
|
||||
'result' => $manage_activity
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("Activity data listing failed: " . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something went wrong.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_user_group_level(Request $request) {
|
||||
try {
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
|
||||
$groupLevelFilter = $request->input('group_level');
|
||||
|
||||
$elites = null;
|
||||
$gameChangers = null;
|
||||
$underdogs = null;
|
||||
|
||||
$elites_user_id = [];
|
||||
if ($groupLevelFilter === 'elites') {
|
||||
$elites = GroupLevelElites();
|
||||
// print_r($elites['elites_user_id']);
|
||||
// exit;
|
||||
} elseif ($groupLevelFilter === 'gameChangers') {
|
||||
|
||||
$gameChangers = GroupLevelGameChanger();
|
||||
} elseif ($groupLevelFilter === 'underdogs') {
|
||||
$underdogs_user_id = [];
|
||||
$game_changer_data = GroupLevelGameChanger();
|
||||
$users_id = $game_changer_data['all_top_users_id'];
|
||||
$underdog = LeaderboardMaster::whereNotIn('user_id', $users_id)->orderBy('total_score', 'desc')->get();
|
||||
foreach ($underdog as $k => $val){
|
||||
$underdogs_user_id[] = $val->user_id;
|
||||
}
|
||||
// dd($underdogs_user_id);
|
||||
|
||||
$underdogs['underdogs'] = $underdog;
|
||||
$underdogs['underdogs_user_id'] = $underdogs_user_id;
|
||||
} else {
|
||||
// Invalid group level filter
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Invalid group level filter.',
|
||||
]);
|
||||
}
|
||||
|
||||
return [
|
||||
'elites' => $elites,
|
||||
'gameChangers' => $gameChangers,
|
||||
'underdogs' => $underdogs,
|
||||
];
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("Activity data listing failed: " . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something went wrong.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// public function filter_users(Request $request) {
|
||||
// try {
|
||||
// $token = readHeaderToken();
|
||||
// if ($token) {
|
||||
// $user_id = $token['sub'];
|
||||
//
|
||||
// $filters = $request->input('gender');
|
||||
// $groupLevelFilter = $request->input('group_level');
|
||||
//
|
||||
// $query = LeaderboardMaster::with(['user', 'user_data']);
|
||||
//
|
||||
// // Apply gender filter
|
||||
// if ($filters && in_array($filters, ['male', 'female'])) {
|
||||
// $query->whereHas('user_data', function ($query) use ($filters) {
|
||||
// $query->where('gender', '=', $filters);
|
||||
// });
|
||||
// } elseif ($filters !== null) {
|
||||
// // Invalid gender filter
|
||||
// return response()->json([
|
||||
// 'success' => false,
|
||||
// 'message' => 'Invalid gender filter.',
|
||||
// ]);
|
||||
// }
|
||||
// // Apply group level filter
|
||||
// $elites = null;
|
||||
// $gameChangers = null;
|
||||
// $underdogs = null;
|
||||
// $elites_user_id = [];
|
||||
//
|
||||
// if ($groupLevelFilter === 'elites') {
|
||||
// $elites = GroupLevelElites();
|
||||
//
|
||||
// // Filter by gender
|
||||
// if ($filters && in_array($filters, ['male', 'female'])) {
|
||||
// $elites = array_filter($elites, function ($elite) use ($filters) {
|
||||
// return $elite['gender'] === $filters;
|
||||
// });
|
||||
// }
|
||||
// } elseif ($groupLevelFilter === 'gameChangers') {
|
||||
// $gameChangers = GroupLevelGameChanger();
|
||||
//
|
||||
// // Filter by gender
|
||||
// if ($filters && in_array($filters, ['male', 'female'])) {
|
||||
// $gameChangers = array_filter($gameChangers, function ($gameChanger) use ($filters) {
|
||||
// return $gameChanger['gender'] === $filters;
|
||||
// });
|
||||
// }
|
||||
// } elseif ($groupLevelFilter === 'underdogs') {
|
||||
// $game_changer_data = GroupLevelGameChanger();
|
||||
// $users_id = $game_changer_data['all_top_users_id'];
|
||||
// $query->whereNotIn('user_id', $users_id)->orderBy('total_score', 'desc');
|
||||
//
|
||||
// // Apply gender filter
|
||||
//if ($filters && in_array($filters, ['male', 'female'])) {
|
||||
// $query->whereHas('user_data', function ($query) use ($filters) {
|
||||
// $query->where('gender', '=', $filters);
|
||||
// });
|
||||
//} elseif ($filters !== null) {
|
||||
// // Invalid gender filter
|
||||
// return response()->json([
|
||||
// 'success' => false,
|
||||
// 'message' => 'Invalid gender filter.',
|
||||
// ]);
|
||||
//}
|
||||
//
|
||||
// $users = $query->get()->toArray();
|
||||
//
|
||||
// return response()->json([
|
||||
// 'success' => true,
|
||||
// 'message' => 'Data fetched successfully.',
|
||||
// 'result' => [
|
||||
// 'users' => $users,
|
||||
// 'elites' => $elites,
|
||||
// 'gameChangers' => $gameChangers,
|
||||
// 'underdogs' => $underdogs,
|
||||
// ],
|
||||
// ]);
|
||||
// } else {
|
||||
// return response()->json([
|
||||
// 'success' => false,
|
||||
// 'message' => 'Authentication failed.',
|
||||
// ]);
|
||||
// }
|
||||
// }
|
||||
// }catch (\Exception $e) {
|
||||
// \Log::error("User filtering failed: " . $e->getMessage());
|
||||
// return response()->json([
|
||||
// 'success' => false,
|
||||
// 'message' => 'Something went wrong.',
|
||||
// ]);
|
||||
// }
|
||||
// }
|
||||
|
||||
public function get_user_data(Request $request)
|
||||
{
|
||||
try {
|
||||
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
//get user data for check gender and group level
|
||||
$user = User::with('user_detail')->find($user_id);
|
||||
|
||||
//request inputs
|
||||
$sortOrder = $request->input('sort_order');
|
||||
$gender = "all";
|
||||
|
||||
// if($gender != "all"){
|
||||
// $gender = $request->input('gender');
|
||||
// }
|
||||
// else{
|
||||
// $gender = "all";
|
||||
// }
|
||||
$groupLevelFilter = $request->input('group_level');
|
||||
|
||||
// Retrieve the user's ranking and related user details
|
||||
$query = LeaderboardMaster::with('user', 'user_data','user.stepCount');
|
||||
|
||||
// for gender
|
||||
// $gender = "all";
|
||||
if($request->has('gender')){
|
||||
$gender = $request->input('gender');
|
||||
// Apply gender filter
|
||||
if ($gender != "all") {
|
||||
$query->whereHas('user_data', function ($query) use ($gender) {
|
||||
$query->where('gender', '=', $gender);
|
||||
});
|
||||
}
|
||||
}
|
||||
// else{
|
||||
|
||||
// $gender = $user->user_detail->gender;
|
||||
// if($gender){
|
||||
// if ($gender && in_array($gender, ['male', 'female'])) {
|
||||
// $query->whereHas('user_data', function ($query) use ($gender) {
|
||||
// $query->where('gender', '=', $gender);
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//for group level
|
||||
$elite = GroupLevelElites();
|
||||
$game_changer = GroupLevelGameChanger();
|
||||
$flattenedEliteArray = Arr::flatten($elite['elites_user_id']);
|
||||
$flattenedGameChangerArray = Arr::flatten($game_changer['all_top_users_id']);
|
||||
$filteredGameChangerArray = array_diff($flattenedGameChangerArray, $flattenedEliteArray);
|
||||
|
||||
if($request->has('group_level')){
|
||||
if ($groupLevelFilter === 'elites') {
|
||||
// Apply elites filter
|
||||
$group_level = "elites";
|
||||
$query->whereIn('user_id', $flattenedEliteArray);
|
||||
} elseif ($groupLevelFilter === 'gameChangers') {
|
||||
// Apply gameChangers filter
|
||||
$group_level = "gameChangers";
|
||||
$query->whereIn('user_id', $filteredGameChangerArray);
|
||||
} elseif ($groupLevelFilter === 'underdogs') {
|
||||
// Apply underdogs filter
|
||||
$group_level = "underdogs";
|
||||
$query->whereNotIn('user_id', $flattenedGameChangerArray);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Invalid group level filter.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (in_array($user_id, $flattenedEliteArray)) {
|
||||
$group_level = "elites";
|
||||
$query->whereIn('user_id', $flattenedEliteArray);
|
||||
} elseif (in_array($user_id, $filteredGameChangerArray)) {
|
||||
$group_level = "gameChangers";
|
||||
$query->whereIn('user_id', $filteredGameChangerArray);
|
||||
} else {
|
||||
$group_level = "underdogs";
|
||||
$query->whereNotIn('user_id', $flattenedGameChangerArray);
|
||||
}
|
||||
}
|
||||
// Apply sorting
|
||||
if ($sortOrder === 'asc') {
|
||||
$query->orderBy('total_score', 'asc');
|
||||
} else {
|
||||
$query->orderBy('total_score', 'desc');
|
||||
}
|
||||
//final query
|
||||
$user_data = $query->get()->toArray();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
// 'user_data' => $user_data,
|
||||
'message' => 'Data Fetch Successfully!.',
|
||||
'user_data' => $user_data,
|
||||
'gender' => $gender,
|
||||
'group_level' => $group_level
|
||||
]);
|
||||
|
||||
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("Data retrieval failed: " . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something went wrong.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_user_data_new(Request $request)
|
||||
{
|
||||
// try {
|
||||
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
// Get user data to check gender and group level
|
||||
$user = User::with('user_detail')->find($user_id);
|
||||
|
||||
// Request inputs
|
||||
$sortOrder = $request->input('sort_order');
|
||||
$gender = "all";
|
||||
$groupLevelFilter = $request->input('group_level');
|
||||
|
||||
// Retrieve the user's ranking and related user details
|
||||
$query = LeaderboardMaster::with([
|
||||
'user',
|
||||
'user_data',
|
||||
'user.latestStepCount'
|
||||
]);
|
||||
|
||||
// Apply gender filter if present
|
||||
if ($request->has('gender')) {
|
||||
$gender = $request->input('gender');
|
||||
if ($gender != "all") {
|
||||
$query->whereHas('user_data', function ($query) use ($gender) {
|
||||
$query->where('gender', '=', $gender);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Group level filtering logic
|
||||
$elite = GroupLevelElites();
|
||||
$game_changer = GroupLevelGameChanger();
|
||||
$flattenedEliteArray = Arr::flatten($elite['elites_user_id']);
|
||||
$flattenedGameChangerArray = Arr::flatten($game_changer['all_top_users_id']);
|
||||
$filteredGameChangerArray = array_diff($flattenedGameChangerArray, $flattenedEliteArray);
|
||||
|
||||
if ($request->has('group_level')) {
|
||||
if ($groupLevelFilter === 'elites') {
|
||||
$group_level = "elites";
|
||||
$query->whereIn('user_id', $flattenedEliteArray);
|
||||
} elseif ($groupLevelFilter === 'gameChangers') {
|
||||
$group_level = "gameChangers";
|
||||
$query->whereIn('user_id', $filteredGameChangerArray);
|
||||
} elseif ($groupLevelFilter === 'underdogs') {
|
||||
$group_level = "underdogs";
|
||||
$query->whereNotIn('user_id', $flattenedGameChangerArray);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Invalid group level filter.',
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
if (in_array($user_id, $flattenedEliteArray)) {
|
||||
$group_level = "elites";
|
||||
$query->whereIn('user_id', $flattenedEliteArray);
|
||||
} elseif (in_array($user_id, $filteredGameChangerArray)) {
|
||||
$group_level = "gameChangers";
|
||||
$query->whereIn('user_id', $filteredGameChangerArray);
|
||||
} else {
|
||||
$group_level = "underdogs";
|
||||
$query->whereNotIn('user_id', $flattenedGameChangerArray);
|
||||
}
|
||||
}
|
||||
|
||||
// Apply sorting
|
||||
if ($sortOrder === 'asc') {
|
||||
$query->orderBy('total_score', 'asc');
|
||||
} else {
|
||||
$query->orderBy('total_score', 'desc');
|
||||
}
|
||||
|
||||
// Fetch the query results
|
||||
$leaderboardData = $query->get();
|
||||
|
||||
// Transform the latest step count to a single element array
|
||||
$leaderboardData->each(function ($item) {
|
||||
$user = $item->user;
|
||||
if ($user) {
|
||||
// $user->append('latestStepCountArray');
|
||||
$user->setHidden(['latestStepCount']);
|
||||
$user->latest_step_count = $user->latest_step_count_array;
|
||||
}
|
||||
});
|
||||
|
||||
// Convert the collection to an array
|
||||
$user_data = $leaderboardData->toArray();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data Fetch Successfully!',
|
||||
'user_data' => $user_data,
|
||||
'gender' => $gender,
|
||||
'group_level' => $group_level
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
|
||||
// } catch (\Exception $e) {
|
||||
// \Log::error("Data retrieval failed pd: " . $e->getMessage());
|
||||
// return response()->json([
|
||||
// 'success' => false,
|
||||
// 'message' => 'Something went wrong.',
|
||||
// ]);
|
||||
// }
|
||||
}
|
||||
|
||||
public function get_user_data_home(Request $request)
|
||||
{
|
||||
try {
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
//get user data for check gender and group level
|
||||
$user = User::with('user_detail')->find($user_id);
|
||||
|
||||
//request inputs
|
||||
$sortOrder = $request->input('sort_order');
|
||||
$gender = "all";
|
||||
|
||||
// if($gender != "all"){
|
||||
// $gender = $request->input('gender');
|
||||
// }
|
||||
// else{
|
||||
// $gender = "all";
|
||||
// }
|
||||
$groupLevelFilter = $request->input('group_level');
|
||||
|
||||
// Retrieve the user's ranking and related user details
|
||||
$query = LeaderboardMaster::with('user', 'user_data');
|
||||
|
||||
// for gender
|
||||
// $gender = "all";
|
||||
if($request->has('gender')){
|
||||
$gender = $request->input('gender');
|
||||
// Apply gender filter
|
||||
if ($gender != "all") {
|
||||
$query->whereHas('user_data', function ($query) use ($gender) {
|
||||
$query->where('gender', '=', $gender);
|
||||
});
|
||||
}
|
||||
}
|
||||
// else{
|
||||
|
||||
// $gender = $user->user_detail->gender;
|
||||
// if($gender){
|
||||
// if ($gender && in_array($gender, ['male', 'female'])) {
|
||||
// $query->whereHas('user_data', function ($query) use ($gender) {
|
||||
// $query->where('gender', '=', $gender);
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//for group level
|
||||
$elite = GroupLevelElites();
|
||||
$game_changer = GroupLevelGameChanger();
|
||||
$flattenedEliteArray = Arr::flatten($elite['elites_user_id']);
|
||||
$flattenedGameChangerArray = Arr::flatten($game_changer['all_top_users_id']);
|
||||
$filteredGameChangerArray = array_diff($flattenedGameChangerArray, $flattenedEliteArray);
|
||||
|
||||
if($request->has('group_level')){
|
||||
if ($groupLevelFilter === 'elites') {
|
||||
// Apply elites filter
|
||||
$group_level = "elites";
|
||||
$query->whereIn('user_id', $flattenedEliteArray);
|
||||
} elseif ($groupLevelFilter === 'gameChangers') {
|
||||
// Apply gameChangers filter
|
||||
$group_level = "gameChangers";
|
||||
$query->whereIn('user_id', $filteredGameChangerArray);
|
||||
} elseif ($groupLevelFilter === 'underdogs') {
|
||||
// Apply underdogs filter
|
||||
$group_level = "underdogs";
|
||||
$query->whereNotIn('user_id', $flattenedGameChangerArray);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Invalid group level filter.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (in_array($user_id, $flattenedEliteArray)) {
|
||||
$group_level = "elites";
|
||||
$query->whereIn('user_id', $flattenedEliteArray);
|
||||
} elseif (in_array($user_id, $filteredGameChangerArray)) {
|
||||
$group_level = "gameChangers";
|
||||
$query->whereIn('user_id', $filteredGameChangerArray);
|
||||
} else {
|
||||
$group_level = "underdogs";
|
||||
$query->whereNotIn('user_id', $flattenedGameChangerArray);
|
||||
}
|
||||
}
|
||||
// Apply sorting
|
||||
if ($sortOrder === 'asc') {
|
||||
$query->orderBy('total_score', 'asc');
|
||||
} else {
|
||||
$query->orderBy('total_score', 'desc');
|
||||
}
|
||||
//final query
|
||||
$user_data = $query->get()->toArray();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
// 'user_data' => $user_data,
|
||||
'message' => 'Data Fetch Successfully!.',
|
||||
'user_data' => $user_data,
|
||||
'gender' => $gender,
|
||||
'group_level' => $group_level
|
||||
]);
|
||||
|
||||
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("Data retrieval failed: " . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something went wrong.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function ranking_position(){
|
||||
|
||||
try {
|
||||
$token = readHeaderToken();
|
||||
|
||||
// $currentYear = now()->format('Y');
|
||||
// $currentMonth = Carbon::now()->format('m');
|
||||
// $monthDate = Carbon::createFromDate($currentYear, $currentMonth, 1)->format('Y-m');
|
||||
|
||||
// $users = User::where('status', '1')->with('user_detail')->get();
|
||||
|
||||
// $elite = GroupLevelElites();
|
||||
// $game_changer = GroupLevelGameChanger();
|
||||
|
||||
// $flattenedEliteArray = Arr::flatten($elite['elites_user_id']);
|
||||
// $flattenedGameChangerArray = Arr::flatten($game_changer['all_top_users_id']);
|
||||
// $filteredGameChangerArray = array_diff($flattenedGameChangerArray, $flattenedEliteArray);
|
||||
|
||||
// $usersGroupedByLevel = [
|
||||
// 1 => $flattenedEliteArray,
|
||||
// 2 => $filteredGameChangerArray,
|
||||
// 3 => array_diff($users->pluck('id')->toArray(), $flattenedGameChangerArray)
|
||||
// ];
|
||||
|
||||
// foreach ($users as $user) {
|
||||
// $userId = $user->id;
|
||||
// $group_level = null;
|
||||
|
||||
// foreach ($usersGroupedByLevel as $level => $userIds) {
|
||||
// if (in_array($userId, $userIds)) {
|
||||
// $group_level = $level;
|
||||
// $user_list = LeaderboardMaster::with('user', 'user_data')
|
||||
// ->whereIn('user_id', $userIds)
|
||||
// ->orderBy('total_score', 'desc')
|
||||
// ->get();
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// $position = null;
|
||||
// foreach ($user_list as $index => $listedUser) {
|
||||
// if ($listedUser->user_id == $userId) {
|
||||
// $position = $index + 1;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// $existingPositionRecord = MonthlyPosition::where([
|
||||
// 'user_id' => $userId,
|
||||
// 'month' => $monthDate,
|
||||
// ])->first();
|
||||
|
||||
// if ($existingPositionRecord) {
|
||||
// if ($existingPositionRecord->group_level >= $group_level &&
|
||||
// ($position < $existingPositionRecord->position || $group_level != $existingPositionRecord->group_level)) {
|
||||
|
||||
// $existingPositionRecord->update([
|
||||
// 'position' => $position,
|
||||
// 'group_level' => $group_level,
|
||||
// ]);
|
||||
// }
|
||||
// } else {
|
||||
// MonthlyPosition::create([
|
||||
// 'user_id' => $userId,
|
||||
// 'month' => $monthDate,
|
||||
// 'position' => $position,
|
||||
// 'group_level' => $group_level,
|
||||
// ]);
|
||||
// }
|
||||
// }
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Position Stored Successfully!.',
|
||||
]);
|
||||
} catch (Exception $ex) {
|
||||
Log::error("Data retrieval failed: " . $ex->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something went wrong.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_user_position(){
|
||||
|
||||
|
||||
try {
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
$currentYear = now()->format('Y');
|
||||
$yearStartDate = Carbon::createFromDate($currentYear, 1, 1)->format('Y-m-d');
|
||||
$yearEndDate = Carbon::createFromDate($currentYear, 12, 31)->format('Y-m-d');
|
||||
|
||||
// Get all the data for the user for the entire current year
|
||||
$user_monthly_positions = MonthlyPosition::whereBetween('month', [$yearStartDate, $yearEndDate])
|
||||
->where('user_id', $user_id)
|
||||
->orderBy('month', 'asc')
|
||||
->get();
|
||||
|
||||
// Create empty records for missing months
|
||||
$allMonths = collect([]);
|
||||
$currentMonthDate = Carbon::createFromDate($currentYear, 1, 1);
|
||||
for ($month = 1; $month <= 12; $month++) {
|
||||
$allMonths->push($currentMonthDate->format('Y-m'));
|
||||
$currentMonthDate->addMonth();
|
||||
}
|
||||
|
||||
// Merge empty records for missing months into the original collection
|
||||
$user_monthly_positions = $allMonths->map(function ($month) use ($user_monthly_positions, $user_id) {
|
||||
return $user_monthly_positions->firstWhere('month', $month) ?? new MonthlyPosition([
|
||||
'user_id' => $user_id,
|
||||
'month' => $month,
|
||||
'position' => null, // You can set a default value for the position here
|
||||
]);
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data Fetch Successfully',
|
||||
'monthly_positions' => $user_monthly_positions,
|
||||
]);
|
||||
}else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
} catch (Exception $ex) {
|
||||
\Log::error("Data retrieval failed: " . $ex->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something went wrong.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_daily_user_position(){
|
||||
|
||||
try {
|
||||
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
|
||||
$userId = $token['sub'];
|
||||
$user = User::with('user_detail')->find($userId);
|
||||
// $user_list = LeaderboardMaster::orderBy('total_score', 'desc')->get();
|
||||
$query = LeaderboardMaster::with('user', 'user_data');
|
||||
//get gender
|
||||
// $gender = $user->user_detail->gender;
|
||||
// if($gender){
|
||||
// if ($gender && in_array($gender, ['male', 'female'])) {
|
||||
// $query->whereHas('user_data', function ($query) use ($gender) {
|
||||
// $query->where('gender', '=', $gender);
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
//for group level
|
||||
$elite = GroupLevelElites();
|
||||
$game_changer = GroupLevelGameChanger();
|
||||
$flattenedEliteArray = Arr::flatten($elite['elites_user_id']);
|
||||
$flattenedGameChangerArray = Arr::flatten($game_changer['all_top_users_id']);
|
||||
$filteredGameChangerArray = array_diff($flattenedGameChangerArray, $flattenedEliteArray);
|
||||
|
||||
if (in_array($userId, $flattenedEliteArray)) {
|
||||
$group_level = "elites";
|
||||
$query->whereIn('user_id', $flattenedEliteArray);
|
||||
} elseif (in_array($userId, $filteredGameChangerArray)) {
|
||||
$group_level = "gameChangers";
|
||||
$query->whereIn('user_id', $filteredGameChangerArray);
|
||||
} else {
|
||||
$group_level = "underdogs";
|
||||
$query->whereNotIn('user_id', $flattenedGameChangerArray);
|
||||
}
|
||||
|
||||
//final query
|
||||
$user_list = $query->orderBy('total_score', 'desc')->get();
|
||||
$position = null;
|
||||
|
||||
foreach ($user_list as $index => $user){
|
||||
if($user->user_id == $userId){
|
||||
$position = $index + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
|
||||
'success' => true,
|
||||
'message' => 'Data Fetch Successfully',
|
||||
'daily_position' => $position,
|
||||
|
||||
]);
|
||||
|
||||
}else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
|
||||
} catch (Exception $ex) {
|
||||
\Log::error("Data retrieval failed: " . $ex->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something went wrong.',
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
333
app/Http/Controllers/API/LoginController.php
Normal file
333
app/Http/Controllers/API/LoginController.php
Normal file
@@ -0,0 +1,333 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\User;
|
||||
use App\Models\UserEmailOtp;
|
||||
use App\Models\UserDetail;
|
||||
use Carbon\Carbon;
|
||||
use Auth;
|
||||
// use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Validator;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Mail\SendUserOtp;
|
||||
use App\Models\mood_o_meter;
|
||||
use App\Models\PersonalAccessToken;
|
||||
use App\Models\LeaderboardMaster;
|
||||
|
||||
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
|
||||
|
||||
public function login(Request $request)
|
||||
{
|
||||
$validator = Validator::make($request->all(),[
|
||||
'email_id' => 'required|email',
|
||||
'password' => 'required|string|min:6'
|
||||
]);
|
||||
|
||||
$credentials = $request->only('email_id', 'password');
|
||||
$token = Auth::guard('api')->attempt($credentials);
|
||||
// $token = auth('api')->attempt($credentials);
|
||||
// dd("TOKEN",$token);
|
||||
if (!$token) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Wrong Creditials',
|
||||
'status'=>401,
|
||||
], 401);
|
||||
}
|
||||
|
||||
$user = Auth::guard('api')->user();
|
||||
|
||||
// dd($user->end_date);
|
||||
$todays_date = Carbon::now()->toDateString();
|
||||
// dd($todays_date);
|
||||
$endDate = Carbon::parse($user->end_date);
|
||||
$startDate = Carbon::parse($user->start_date)->toDateString();
|
||||
$subscriptionEndsIn7Days = $endDate->addDays(7)->toDateString();
|
||||
if($subscriptionEndsIn7Days == null || $subscriptionEndsIn7Days < $todays_date){
|
||||
$logout = auth('api')->logout();
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Subscription end',
|
||||
'status'=>201,], 201);
|
||||
}
|
||||
if($startDate > $todays_date){
|
||||
$logout = auth('api')->logout();
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Subscription end',
|
||||
'status'=>201,], 201);
|
||||
}
|
||||
$personalAccessToken = new PersonalAccessToken();
|
||||
$personalAccessToken->user_id = $user->id;
|
||||
$personalAccessToken->token = $token;
|
||||
$personalAccessToken->last_login = Carbon::now()->format('Y-m-d H:i:s');
|
||||
$personalAccessToken->save();
|
||||
|
||||
//moodometer add data
|
||||
$existingRecord = mood_o_meter::where('user_id', $user->id)->exists();
|
||||
if (!$existingRecord) {
|
||||
// Create a new mood record
|
||||
$newEntry = mood_o_meter::create([
|
||||
'user_id' => $user->id,
|
||||
'mood_o_meter' => null,
|
||||
'is_active' => '1',
|
||||
]);
|
||||
}
|
||||
|
||||
//Leaderboard add data
|
||||
$existingRecord = LeaderboardMaster::where('user_id', $user->id)->exists();
|
||||
if (!$existingRecord) {
|
||||
// Create a new leaderbaord record
|
||||
$newEntry = LeaderboardMaster::create([
|
||||
'user_id' => $user->id,
|
||||
'total_score' => '0',
|
||||
'progress_bar' => '0',
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
$user = User::with('user_detail')->where('id', $user->id)->first()->toArray();
|
||||
// $user = User::select('id','full_name','contact_number','email_id','status')->where('id',$user->id)->first()->toArray();
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'status' => true,
|
||||
'message'=> 'You are successfully logged in',
|
||||
'authorisation' => [
|
||||
'token' => $token,
|
||||
'user_data' => $user,
|
||||
'type' => 'bearer',
|
||||
]
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function update_password(Request $request) {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'user_id' => 'required|exists:users,id',
|
||||
// 'current_password' => 'required|string|min:6',
|
||||
'password' => 'required|string|confirmed'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'status' => 406,
|
||||
'message' => 'Password does not match',
|
||||
'error' => $validator->errors(),
|
||||
], 401);
|
||||
}
|
||||
|
||||
# Match The Old Password
|
||||
|
||||
$user = User::where('id', $request->user_id)->first();
|
||||
$user->password = Hash::make($request->input('password'));
|
||||
$user->update();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'status' => 200,
|
||||
'message' => 'Password changed successfully!',
|
||||
]);
|
||||
}
|
||||
|
||||
public function generate(Request $request) {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'email_id' => 'required|email',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'error' => $validator->errors()], 401);
|
||||
}
|
||||
//check user exist or not
|
||||
$email = $request->email_id;
|
||||
$user = User::where('email_id', $email)->first();
|
||||
|
||||
if(!$user){
|
||||
return response(["status" => 404,
|
||||
'message' => 'Email Id Does Not Exist']
|
||||
);
|
||||
}
|
||||
// Generate An Otp
|
||||
$otp = UserEmailOtp::updateOrCreate(['user_id' => $user->id],
|
||||
[ 'otp' => rand(1000, 9999),
|
||||
'valid_upto' => Carbon::now()->addMinutes(10)
|
||||
]);
|
||||
|
||||
if ($otp) {
|
||||
// send otp in the email
|
||||
$mail_details = [
|
||||
'email' => $request->email_id,
|
||||
'subject' => 'Forgot Password',
|
||||
'body' => 'Your OTP is : ' . $otp->otp
|
||||
];
|
||||
|
||||
$mail = \Mail::to($request->email_id)->send(new SendUserOtp($mail_details));
|
||||
|
||||
return response(["status" => 200,
|
||||
"message" => "OTP sent successfully",
|
||||
'user_id' => $otp['user_id']]);
|
||||
} else {
|
||||
return response(["status" => 401,
|
||||
'message' => 'Invalid']
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function verifyOtp(Request $request) {
|
||||
|
||||
$emailId = $request->email_id;
|
||||
$otp = $request->otp;
|
||||
// dd($emailId,$otp);
|
||||
$user = User::where('email_id', $emailId)->first();
|
||||
$varificationCode = UserEmailOtp::where('user_id', $user->id)->latest()->first();
|
||||
// dd($varificationCode);
|
||||
$now = Carbon::now();
|
||||
|
||||
if ($varificationCode && $now->isAfter($varificationCode->valid_upto)) {
|
||||
return response()->json([
|
||||
'status' => 500,
|
||||
'message' => 'Your OTP has been expired',
|
||||
], 500);
|
||||
}
|
||||
if($varificationCode->otp != $otp){
|
||||
return response(["status" => 401,
|
||||
'message' => 'Invalid OTP']
|
||||
);
|
||||
}else{
|
||||
return response(["status" => 200,
|
||||
'message' => 'Valid OTP']
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function create_new_pass_with_otp(Request $request) {
|
||||
$request->validate([
|
||||
'user_id' => 'required|exists:users,id',
|
||||
]);
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'user_id' => 'required|exists:users,id',
|
||||
'otp' => 'required'
|
||||
]);
|
||||
|
||||
#Validation Logic
|
||||
$verificationCode = UserEmailOtp::where('user_id', $request->user_id)
|
||||
->where('otp', $request->otp)
|
||||
->first();
|
||||
|
||||
$now = Carbon::now();
|
||||
if (!$verificationCode) {
|
||||
return response()->json([
|
||||
'status' => 401,
|
||||
'message' => 'Invalid',
|
||||
], 401);
|
||||
} elseif ($verificationCode && $now->isAfter($verificationCode->valid_upto)) {
|
||||
return response()->json([
|
||||
'status' => 500,
|
||||
'message' => 'Your OTP has been expired',
|
||||
], 500);
|
||||
} else {
|
||||
return response()->json([
|
||||
'status' => 200,
|
||||
'message' => 'Otp Verify successfully',
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
|
||||
public function resend_otp(Request $request) {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'email_id' => 'required|email',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'error' => $validator->errors()], 401);
|
||||
}
|
||||
|
||||
// Generate An Otp
|
||||
$email = $request->email_id;
|
||||
$user = User::where('email_id', $email)->first();
|
||||
$otp = UserEmailOtp::updateOrCreate(['user_id' => $user->id],
|
||||
[ 'otp' => rand(1000, 9999),
|
||||
'valid_upto' => Carbon::now()->addMinutes(10)
|
||||
]);
|
||||
|
||||
if ($otp) {
|
||||
// send otp in the email
|
||||
$mail_details = [
|
||||
'email' => $request->email_id,
|
||||
'subject' => 'Forgot Password',
|
||||
'body' => 'Your OTP is : ' . $otp->otp
|
||||
];
|
||||
// print_r($mail_details);exit;
|
||||
|
||||
\Mail::to($request->email_id)->send(new SendUserOtp($mail_details));
|
||||
|
||||
return response(["status" => 200,
|
||||
"message" => "OTP sent successfully",
|
||||
'user_id' => $otp['user_id']]);
|
||||
} else {
|
||||
return response(["status" => 401,
|
||||
'message' => 'Invalid']
|
||||
);
|
||||
}
|
||||
|
||||
// $message = "Your otp is - ".$varificationCode->otp;
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'status' => 200,
|
||||
'message' => $message,
|
||||
]);
|
||||
}
|
||||
|
||||
public function resetPassword(Request $request){
|
||||
|
||||
$userId = $request->user_id;
|
||||
$oldPass = $request->old_pass;
|
||||
$newPass = $request->new_pass;
|
||||
|
||||
//check old password is not match with new password
|
||||
|
||||
$userPass = User::where('id',$userId)->first();
|
||||
|
||||
if(!Hash::check($oldPass,$userPass->password)){
|
||||
|
||||
return response()->json([
|
||||
'status'=>201 ,
|
||||
'message'=>'Wrong Password'
|
||||
]);
|
||||
}elseif(Hash::check($newPass,$userPass->password)){
|
||||
return response()->json([
|
||||
'status'=>201 ,
|
||||
'message'=>'New Password and Old Password Cannot Be same'
|
||||
]);
|
||||
|
||||
}else{
|
||||
$user = User::where('id', $userId)->first();
|
||||
$user->password = Hash::make($newPass);
|
||||
$user->update();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'status' => 200,
|
||||
'message' => 'Password changed successfully!',
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
545
app/Http/Controllers/API/ManageActivityController.php
Normal file
545
app/Http/Controllers/API/ManageActivityController.php
Normal file
@@ -0,0 +1,545 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\ActivityMaster;
|
||||
use App\Models\SubscriptionMaster;
|
||||
use App\Models\ActivitySchedule;
|
||||
use App\Models\Teacher;
|
||||
use App\Models\ManageFaq;
|
||||
use App\Models\PastSession;
|
||||
use App\Models\LeaderboardMaster;
|
||||
use App\Models\UserContentView;
|
||||
use App\Models\LinkFaqActivityMasterIds;
|
||||
use App\Models\ActivityDay;
|
||||
use App\Models\User;
|
||||
use Validator;
|
||||
use Carbon\Carbon;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Torann\GeoIP\Facades\GeoIP;
|
||||
use Spatie\TimeZone\GoogleTimeZone;
|
||||
|
||||
use App\Helpers\Webhelper;
|
||||
|
||||
|
||||
|
||||
class ManageActivityController extends Controller {
|
||||
|
||||
public function get_manage_activity_id() {
|
||||
try {
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
$activityId = request('activityId');
|
||||
|
||||
$activity = ActivityMaster::with('subscription', 'schedule')->with('faq_activity_link.faqsData')->find($activityId);
|
||||
|
||||
if ($activity) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Activity fetched successfully.',
|
||||
'result' => $activity
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Activity not found.',
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("Activity data listing failed: " . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something went wrong.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_manage_activity(Request $request) {
|
||||
// try {
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
// dd($user_id);
|
||||
|
||||
$user_data = User::where('id',$user_id)->first();
|
||||
$utm_source = $user_data->utm_source;
|
||||
$subscription_data = SubscriptionMaster::where('utm_plan',$utm_source)->first();
|
||||
// dd($utm_source);
|
||||
$subscription_id = $subscription_data->id;
|
||||
// dd($subscription_id);
|
||||
$current_day = Carbon::now()->toDateString();
|
||||
// dd($current_day);
|
||||
$manage_activity = ActivityDay::where('date', '=', $current_day)
|
||||
// ->where('')
|
||||
->where('subscription_id', $subscription_id)
|
||||
->with('subscription')
|
||||
->with('faq_activity_link.faqsData')
|
||||
->with('scheduleData', 'activityData.subscription')
|
||||
->with('activityData.teacher_data')
|
||||
->get();
|
||||
// dd($manage_activity);
|
||||
// $userIP = $request->ip(); // Get the user's IP address // commented by Pradyumn; commented on 5 july 2024; Reason: not in use
|
||||
|
||||
// Make a GET request to ipinfo.io
|
||||
// $response = Http::get("https://ipinfo.io/{$userIP}/json"); // commented by Pradyumn; commented on 5 july 2024; Reason: not in use
|
||||
// Parse the JSON response
|
||||
|
||||
// commented by Pradyumn; commented on 5 july 2024; Reason: not in use
|
||||
// $ch = curl_init("https://ipinfo.io/{$userIP}?token=fb9b51b5a3bbd9");
|
||||
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
// $response = curl_exec($ch);
|
||||
// curl_close($ch);
|
||||
|
||||
// $locationData = json_decode($response); // commented by Pradyumn; commented on 5 july 2024; Reason: not in use
|
||||
// dd($locationData);
|
||||
// Extract the user's time zone from the location data
|
||||
// $userTimeZone = $locationData->timezone; // commented by Pradyumn; commented on 5 july 2024; Reason: not in use
|
||||
// dd($userTimeZone);
|
||||
// Convert the time to the user's time zone
|
||||
// $userTimeZone = $ca$carbonTimetz($userTimeZone);
|
||||
$manage_activity->each(function ($item) {
|
||||
$timestamp = $item->time;
|
||||
$normalTime = Carbon::createFromFormat('H:i', $timestamp, 'Asia/Kolkata'); // Replace 'your_timezone' with the actual timezone of the 'time' column
|
||||
$utcTime = $normalTime->utc();
|
||||
$item->time = $utcTime->format('H:i'); // Update the 'time' value with the UTC time in 'HH:mm' format
|
||||
return $item;
|
||||
});
|
||||
$result = $manage_activity;
|
||||
// $userIP = $request->ip(); // Get the user's IP address
|
||||
|
||||
// // Make a GET request to ipinfo.io
|
||||
// $response = Http::get("https://ipinfo.io/{$userIP}/json");
|
||||
// // Parse the JSON response
|
||||
// $locationData = $response->json();
|
||||
|
||||
// // Extract the user's time zone from the location data
|
||||
// $userTimeZone = $locationData['timezone'];
|
||||
|
||||
// $manage_activity->each(function ($item) use ($userTimeZone) {
|
||||
// $timestamp = $item->time;
|
||||
// $normalTime = Carbon::createFromFormat('H:i', $timestamp, $userTimeZone); // Replace 'your_timezone' with the actual timezone of the 'time' column
|
||||
// $normalTime->setTimezone($userTimeZone); // Convert to the user's time zone
|
||||
// $item->time = $normalTime->format('H:i'); // Update the 'time' value with the user's time zone in 'HH:mm' format
|
||||
// return $item;
|
||||
// });
|
||||
|
||||
// $result = $manage_activity;
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data fetched successfully.',
|
||||
'result' => $result
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function get_manage_activity_schedule() {
|
||||
try {
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
$user_data = User::where('id',$user_id)->first();
|
||||
$utm_source = $user_data->utm_source;
|
||||
|
||||
$subscription_data = SubscriptionMaster::where('utm_plan',$utm_source)->first();
|
||||
// dd($subscription_data);
|
||||
$subscription_id = $subscription_data->id;
|
||||
$current_day = Carbon::now()->toDateString();
|
||||
$activity_schedule = ActivityDay::where('date', '>', $current_day)
|
||||
->where('subscription_id', $subscription_id)
|
||||
->with('subscription')
|
||||
->with('scheduleData', 'activityData.teacher_data')
|
||||
->orderBy('date', 'asc')
|
||||
->get();
|
||||
|
||||
$activity_schedule->each(function ($item) {
|
||||
$timestamp = $item->time;
|
||||
$normalTime = Carbon::createFromFormat('H:i', $timestamp, 'Asia/Kolkata'); // Replace 'your_timezone' with the actual timezone of the 'time' column
|
||||
$utcTime = $normalTime->utc();
|
||||
$item->time = $utcTime->format('H:i'); // Update the 'time' value with the UTC time in 'HH:mm' format
|
||||
return $item;
|
||||
});
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data fetched successfully.',
|
||||
'result' => $activity_schedule
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("User data listing Failed : " . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something Went wrong.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_manage_activity_schedule_utc() {
|
||||
try {
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
$user_data = User::where('id',$user_id)->first();
|
||||
$utm_source = $user_data->utm_source;
|
||||
|
||||
$subscription_data = SubscriptionMaster::where('utm_plan',$utm_source)->first();
|
||||
$subscription_id = $subscription_data->id;
|
||||
$current_day = Carbon::now()->toDateString();
|
||||
$activity_schedule = ActivityDay::where('date', '>', $current_day)
|
||||
->where('subscription_id', $subscription_id)
|
||||
->with('subscription')
|
||||
->with('scheduleData', 'activityData.teacher_data')
|
||||
->get();
|
||||
$activity_schedule->each(function ($item) {
|
||||
$timestamp = $item->time;
|
||||
$normalTime = Carbon::createFromFormat('H:i', $timestamp, 'Asia/Kolkata'); // Replace 'your_timezone' with the actual timezone of the 'time' column
|
||||
$utcTime = $normalTime->utc();
|
||||
$item->time = $utcTime->format('H:i'); // Update the 'time' value with the UTC time in 'HH:mm' format
|
||||
return $item;
|
||||
});
|
||||
// $activity_schedule_array = $activity_schedule->toArray();
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data fetched successfully.',
|
||||
'result' => $activity_schedule
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("User data listing Failed : " . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something Went wrong.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
public function get_schedule_id() {
|
||||
try {
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
$scheduleId = request('scheduleId');
|
||||
// $data = User::with('user_details')->where('id', $user_id)->first()->toArray();
|
||||
|
||||
$activity_schedule = ActivitySchedule::with('subscription')->find($scheduleId);
|
||||
|
||||
// print_r($activity_schedule);exit;
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data fetched successfully.',
|
||||
'result' => $activity_schedule
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("User data listing Failed : " . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something Went wrong.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_manage_past_session() {
|
||||
// try {
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
$user_data = User::where('id',$user_id)->first();
|
||||
// dd($user_data);
|
||||
$utm_source = $user_data->utm_source;
|
||||
// dd($utm_source);
|
||||
|
||||
$subscription_data = SubscriptionMaster::where('utm_plan',$utm_source)->first();
|
||||
$subscription_id = $subscription_data->id;
|
||||
// dd($subscription_id);
|
||||
$activity_data = ActivityMaster::where('subscription_id', $subscription_id)->orderBy('end_date', 'desc')->first();
|
||||
// Calculate the cutoff date (end date + 7 days)
|
||||
$end_date = $activity_data->end_date;
|
||||
// dd($end_date);
|
||||
$cutoffDate = Carbon::parse($end_date)->addDays(7);
|
||||
// dd($cutoffDate);
|
||||
// dd($cutoffDate,Carbon::now()->toDateString());
|
||||
// $current_date = Carbon::now()->format('Y-m-d');
|
||||
// $desired_date = Carbon::createFromDate(2024, 1, 2);
|
||||
// $cutoffDate = $desired_date->format('Y-m-d');
|
||||
// ->where('end_date','>=',$current_date)
|
||||
// dd($desired_date_formatted);
|
||||
|
||||
if(Carbon::now()->toDateString() > $cutoffDate){
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Activity has ended.',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
$past_activity = ActivityMaster::where('subscription_id', $subscription_id)->where('end_date','<',$cutoffDate)->with('teacher_data')->orderBy('start_date', 'desc')->first();
|
||||
$schedule_data = ActivitySchedule::where('activity_master_id', $past_activity['id'])->with('past_data')->orderBy('start_date', 'asc')->get()->toArray();
|
||||
$data_schedule = [];
|
||||
foreach ($schedule_data as $k => $val){
|
||||
if (empty($val['past_data'])){
|
||||
continue;
|
||||
}else{
|
||||
$data_schedule[] = $val;
|
||||
}
|
||||
}
|
||||
$past_activity['schedule'] = $data_schedule;
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data fetched successfully.',
|
||||
'result' => $past_activity
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
// } catch (\Exception $e) {
|
||||
// \Log::error("User data listing Failed: " . $e->getMessage());
|
||||
// return response()->json([
|
||||
// 'success' => false,
|
||||
// 'message' => 'Something went wrong.',
|
||||
// ]);
|
||||
// }
|
||||
}
|
||||
|
||||
public function get_manage_past_session_id() {
|
||||
try {
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
$pastSessionId = request('pastSessionId');
|
||||
// Calculate the date 7 days before the current date
|
||||
$seven_days_before = date('Y-m-d', strtotime('+7 days'));
|
||||
|
||||
// Get past sessions that occurred within 7 days before the current date
|
||||
$passed_session = PastSession::where('created_at', '<=', $seven_days_before)
|
||||
->find($pastSessionId);
|
||||
// dd($passed_session);
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data fetched successfully.',
|
||||
'result' => $passed_session
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("User data listing Failed: " . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something went wrong.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function add_session_status(Request $request) {
|
||||
try {
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
$oldUserRankings = LeaderboardMaster::with('user')
|
||||
->get();
|
||||
//get old points
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'content_id' => 'required',
|
||||
'content_type' => 'required'
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'error' => $validator->errors()
|
||||
], 401);
|
||||
}
|
||||
// validation fails
|
||||
$data = UserContentView::where('user_id', $user_id)
|
||||
->whereDate('created_at', now()->toDateString())
|
||||
->get();
|
||||
|
||||
if ($data->isNotEmpty()) {
|
||||
return response([
|
||||
'status' => "Data already exists"
|
||||
], 400);
|
||||
} else {
|
||||
$add_content_view = new UserContentView;
|
||||
$add_content_view->user_id = $user_id;
|
||||
$add_content_view->content_id = $request->input('content_id');
|
||||
$add_content_view->is_view = $request->input('content_type');
|
||||
$add_content_view->save();
|
||||
|
||||
// Check if user exists in another table
|
||||
$leaderboardMaster = LeaderboardMaster::where('user_id', $user_id)->first();
|
||||
if ($leaderboardMaster) {
|
||||
// Update points if user exists
|
||||
$leaderboardMaster->total_score += 1;
|
||||
$leaderboardMaster->save();
|
||||
} else {
|
||||
// Create a new entry with 1 point if user doesn't exist
|
||||
LeaderboardMaster::create([
|
||||
'user_id' => $user_id,
|
||||
'total_score' => 1,
|
||||
]);
|
||||
}
|
||||
}
|
||||
$newUserRanking = LeaderboardMaster::where('user_id', $user_id)->first();
|
||||
if ($oldUserRankings && $newUserRanking) {
|
||||
foreach ($oldUserRankings as $ranking) {
|
||||
$previousTotalScore = $ranking->total_score;
|
||||
$currentTotalScore = $newUserRanking->total_score;
|
||||
if ($ranking->user_id == $user_id) {
|
||||
if ($previousTotalScore === null) {
|
||||
$ranking->progress_bar = '0'; // Initial entry
|
||||
} elseif ($currentTotalScore > $previousTotalScore) {
|
||||
$ranking->progress_bar = '0'; // Total score increased
|
||||
$message = "You earned 1 point!";
|
||||
} elseif ($currentTotalScore < $previousTotalScore) {
|
||||
$ranking->progress_bar = '1'; // Total score decreased
|
||||
$message = "Your score decreased.";
|
||||
} else {
|
||||
$ranking->progress_bar = '2'; // Total score remained the same
|
||||
$message = "Your score remains the same.";
|
||||
}
|
||||
$ranking->save(); // Save the updated progress_bar value
|
||||
}
|
||||
}
|
||||
|
||||
return response([
|
||||
'status' => "Data added successfully.",
|
||||
'progress_bar' => $message,
|
||||
], 200);
|
||||
}
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.'
|
||||
]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("User data listing Failed: " . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something went wrong.'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function dummy_activity(Request $request){
|
||||
|
||||
|
||||
// try {
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
// dd($user_id);
|
||||
|
||||
$user_data = User::where('id',$user_id)->first();
|
||||
$utm_source = $user_data->utm_source;
|
||||
|
||||
$subscription_data = SubscriptionMaster::where('utm_plan',$utm_source)->first();
|
||||
$subscription_id = $subscription_data->id;
|
||||
// dd($subscription_id);
|
||||
$current_day = Carbon::now()->toDateString();
|
||||
$manage_activity = ActivityDay::where('date', '=', $current_day)
|
||||
// ->where('')
|
||||
->where('subscription_id', $subscription_id)
|
||||
->with('subscription')
|
||||
->with('faq_activity_link.faqsData')
|
||||
->with('scheduleData', 'activityData.subscription')
|
||||
->with('activityData.teacher_data')
|
||||
->get();
|
||||
|
||||
// $userIP = $request->ip(); // Get the user's IP address
|
||||
|
||||
// // Make a GET request to ipinfo.io
|
||||
// $response = Http::get("https://ipinfo.io/{$userIP}/json");
|
||||
// // Parse the JSON response
|
||||
|
||||
// $ch = curl_init("https://ipinfo.io/{$userIP}/json");
|
||||
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
// $response = curl_exec($ch);
|
||||
// curl_close($ch);
|
||||
|
||||
// $locationData = json_decode($response);
|
||||
|
||||
// // Extract the user's time zone from the location data
|
||||
// $userTimeZone = $locationData->timezone;
|
||||
// // dd($userTimeZone);
|
||||
// // Convert the time to the user's time zone
|
||||
// // $userTimeZone = $ca$carbonTimetz($userTimeZone);
|
||||
// $manage_activity->each(function ($item) {
|
||||
// $timestamp = $item->time;
|
||||
// $normalTime = Carbon::createFromFormat('H:i', $timestamp, 'Asia/Kolkata'); // Replace 'your_timezone' with the actual timezone of the 'time' column
|
||||
// $utcTime = $normalTime->utc();
|
||||
// $item->time = $utcTime->format('H:i'); // Update the 'time' value with the UTC time in 'HH:mm' format
|
||||
// return $item;
|
||||
// });
|
||||
// $result = $manage_activity;
|
||||
$userIP = $request->ip(); // Get the user's IP address
|
||||
|
||||
// Make a GET request to ipinfo.io
|
||||
$response = Http::get("https://ipinfo.io/{$userIP}/json");
|
||||
// Parse the JSON response
|
||||
$locationData = $response->json();
|
||||
|
||||
// Extract the user's time zone from the location data
|
||||
$userTimeZone = $locationData['timezone'];
|
||||
|
||||
$manage_activity->each(function ($item) use ($userTimeZone) {
|
||||
$timestamp = $item->time;
|
||||
$normalTime = Carbon::createFromFormat('H:i', $timestamp, $userTimeZone); // Replace 'your_timezone' with the actual timezone of the 'time' column
|
||||
$normalTime->setTimezone($userTimeZone); // Convert to the user's time zone
|
||||
$item->time = $normalTime->format('H:i'); // Update the 'time' value with the user's time zone in 'HH:mm' format
|
||||
return $item;
|
||||
});
|
||||
|
||||
$result = $manage_activity;
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data fetched successfully.',
|
||||
'result' => $result
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
40
app/Http/Controllers/API/ManageBannerController.php
Normal file
40
app/Http/Controllers/API/ManageBannerController.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\ManageBanner;
|
||||
|
||||
|
||||
class ManageBannerController extends Controller
|
||||
{
|
||||
public function manage_banner()
|
||||
{
|
||||
try{
|
||||
$token = readHeaderToken();
|
||||
if($token){
|
||||
$user_id = $token['sub'];
|
||||
// $data = User::with('user_details')->where('id', $user_id)->first()->toArray();
|
||||
// $data = ManageBanner::latest()->first(); // comented by: Pradyumn; Commented at: 5 july 2024; Reason: added select function;
|
||||
$data = ManageBanner::select('id','banner_path','block_position')->orderBy('id','desc')->first();
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message'=> 'Data fetched successfully.',
|
||||
'result' => $data
|
||||
]);
|
||||
}else{
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message'=> 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
}catch(\Exception $e){
|
||||
\Log::error("User data listing Failed : " .$e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message'=> 'Something Went wrong.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
85
app/Http/Controllers/API/ManageFeedbackController.php
Normal file
85
app/Http/Controllers/API/ManageFeedbackController.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\ManageNewsArticles;
|
||||
use App\Models\ManageFeedback;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Auth;
|
||||
|
||||
class ManageFeedbackController extends Controller
|
||||
{
|
||||
public function getData(){
|
||||
$data = ManageFeedback::where('is_active','0')->get();
|
||||
// dd($data);
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data fetched successfully.',
|
||||
'result' => $data
|
||||
]);
|
||||
}
|
||||
|
||||
public function updateFeedback(Request $request) {
|
||||
$token = readHeaderToken();
|
||||
// dd($token);
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
// $user = auth()->user();
|
||||
// dd($user_id);
|
||||
$existingRecord = ManageFeedback::where('user_id', $user_id)->first();
|
||||
|
||||
if ($existingRecord) {
|
||||
$existingRecord->update(['message' => $request->message,'reaction' => $request->reaction]);
|
||||
$data = $existingRecord;
|
||||
} else {
|
||||
$data = ManageFeedback::create([
|
||||
'user_id' => $user_id,
|
||||
'message' => $request->message,
|
||||
'reaction' => $request->reaction
|
||||
]);
|
||||
}
|
||||
|
||||
$message = $existingRecord ? 'Data updated successfully.' : 'Data created successfully.';
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => $message,
|
||||
'result' => $data
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'something went wrong.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// public function updateFeedback(Request $request) {
|
||||
// $token = readHeaderToken();
|
||||
// if ($token) {
|
||||
// $user_id = $token['sub'];
|
||||
// $user = auth()->user();
|
||||
// // dd($user_id);
|
||||
// // Update or create ManageFeedback record
|
||||
// $data = ManageFeedback::updateOrCreate([
|
||||
// 'user_id' => $user_id,
|
||||
// 'message' => $request->message,
|
||||
// 'reaction' => $request->reaction
|
||||
// ]);
|
||||
|
||||
// return response()->json([
|
||||
// 'success' => true,
|
||||
// 'message' => 'Data updated successfully.',
|
||||
// 'result' => $data
|
||||
// ]);
|
||||
// } else {
|
||||
// return response()->json([
|
||||
// 'success' => false,
|
||||
// 'message' => 'something went wrong.',
|
||||
// ]);
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
121
app/Http/Controllers/API/ManageNotificationController.php
Normal file
121
app/Http/Controllers/API/ManageNotificationController.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\User;
|
||||
use App\Models\NotificationMaster;
|
||||
use App\Models\NotificationUser;
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class ManageNotificationController extends Controller
|
||||
{
|
||||
public function get_notification_count(){
|
||||
|
||||
try{
|
||||
$token = readHeaderToken();
|
||||
if($token){
|
||||
$user_id = $token['sub'];
|
||||
$notification_count = NotificationUser::where('user_id',$user_id)
|
||||
->where('is_read','0')->count();
|
||||
// print_r($notification_list);
|
||||
// exit;
|
||||
$notification_list = NotificationUser::with('notification_master_data','user_data')->where('user_id',$user_id)->get()->toArray();
|
||||
// echo "<pre>";
|
||||
// print_r($notification_list);
|
||||
// exit;
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data Fetch Successfully!.',
|
||||
'notification_count' => $notification_count,
|
||||
'notification_list' => $notification_list
|
||||
]);
|
||||
}else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
} catch (Exception $ex) {
|
||||
return response([
|
||||
'status' => "failed",
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function update_read_status(Request $request){
|
||||
|
||||
try {
|
||||
$token = readHeaderToken();
|
||||
if($token){
|
||||
$user_id = $token['sub'];
|
||||
|
||||
$nitification_id = $request->notification_id;
|
||||
|
||||
NotificationUser::where('notification_id',$nitification_id)
|
||||
->where('user_id',$user_id)
|
||||
->update(['is_read' => '1']);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data Updated Successfully!.'
|
||||
]);
|
||||
}else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
|
||||
} catch (Exception $ex) {
|
||||
return response([
|
||||
'status' => "failed",
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function delete_notification(Request $request){
|
||||
|
||||
try{
|
||||
$token = readHeaderToken();
|
||||
if($token){
|
||||
$user_id = $token['sub'];
|
||||
$notification_id = $request->notification_id;
|
||||
|
||||
// print_r($notification_id);
|
||||
// exit;
|
||||
NotificationUser::where('notification_id',$notification_id)
|
||||
->where('user_id',$user_id)->delete();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Deleted Successfully!.'
|
||||
]);
|
||||
|
||||
}else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
} catch (Exception $ex) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// public function delete(){
|
||||
|
||||
// $threeDaysAgo = Carbon::now()->subDays(3);
|
||||
// NotificationUser::where('created_at','<',$threeDaysAgo)->delete();
|
||||
|
||||
// return response()->json([
|
||||
// 'success' => true,
|
||||
// 'message' => 'Deleted Successfully!.'
|
||||
// ]);
|
||||
|
||||
|
||||
// }
|
||||
}
|
||||
21
app/Http/Controllers/API/ManagePodcastController.php
Normal file
21
app/Http/Controllers/API/ManagePodcastController.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\ManagePodcast;
|
||||
|
||||
class ManagePodcastController extends Controller
|
||||
{
|
||||
public function getPodcast(){
|
||||
|
||||
$data['latestPodcast'] = ManagePodcast::where('is_active','1')->inRandomOrder()->get();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data fetched successfully.',
|
||||
'result' => $data
|
||||
]);
|
||||
}
|
||||
}
|
||||
181
app/Http/Controllers/API/MoodOMeterController.php
Normal file
181
app/Http/Controllers/API/MoodOMeterController.php
Normal file
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\User;
|
||||
use App\Models\mood_o_meter;
|
||||
use App\Models\LeaderboardMaster;
|
||||
//use Carbon\Carbon;
|
||||
use Auth;
|
||||
|
||||
class MoodOMeterController extends Controller {
|
||||
|
||||
public function store_mood_o_meter(Request $req) {
|
||||
try {
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
// $user = auth()->user();
|
||||
$user_id = $token['sub'];
|
||||
$oldUserRankings = LeaderboardMaster::with('user')->get();
|
||||
$currentDate = now()->toDateString();
|
||||
$previousDate = now()->subDay()->toDateString();
|
||||
|
||||
// Check if a record for the current user and current day already exists
|
||||
$existingRecord = mood_o_meter::where('user_id', $user_id)
|
||||
// ->whereDate('created_at', now()->toDateString())
|
||||
->whereDate('updated_at', $currentDate)
|
||||
->where('is_active','0')
|
||||
->first();
|
||||
if ($existingRecord) {
|
||||
// Update the existing mood record
|
||||
$existingRecord->update([
|
||||
'mood_o_meter' => $req->input('mood_o_meter'),
|
||||
'is_active' => '0',
|
||||
]);
|
||||
|
||||
return response([
|
||||
'status' => "Mood already added for today",
|
||||
], 200);
|
||||
} else {
|
||||
// Check if a record for the current user and previous day exists
|
||||
// $previousRecord = mood_o_meter::where('user_id', $user_id)
|
||||
// ->whereDate('updated_at', $previousDate)
|
||||
//
|
||||
// ->first();
|
||||
|
||||
// if ($previousRecord) {
|
||||
// Create a new mood record for the current day
|
||||
mood_o_meter::where('user_id', $user_id)
|
||||
->update([
|
||||
'mood_o_meter' => $req->input('mood_o_meter'),
|
||||
'is_active' => '0'
|
||||
]);
|
||||
// }
|
||||
// else {
|
||||
//
|
||||
// mood_o_meter::create([
|
||||
// 'user_id' => $user_id,
|
||||
// 'mood_o_meter' => $req->input('mood_o_meter'),
|
||||
// 'is_active' => '0',
|
||||
// ]);
|
||||
// }
|
||||
// Update is_active column based on the current time
|
||||
$ranking = LeaderboardMaster::with('user')->where('user_id', $user_id)->first();
|
||||
// Check if user exists in another table
|
||||
$leaderboardMaster = LeaderboardMaster::where('user_id', $user_id)->first();
|
||||
if ($leaderboardMaster) {
|
||||
// Update points if user exists
|
||||
$leaderboardMaster->increment('total_score', 1);
|
||||
} else {
|
||||
// Create a new entry with 1 point if user doesn't exist
|
||||
LeaderboardMaster::create([
|
||||
'user_id' => $token['sub'],
|
||||
'total_score' => 1,
|
||||
]);
|
||||
}
|
||||
|
||||
$newUserRanking = LeaderboardMaster::where('user_id', $user_id)->first();
|
||||
if ($newUserRanking) {
|
||||
// dd($oldUserRankings);
|
||||
// $message = 'Hello World';
|
||||
|
||||
// echo '<pre>';
|
||||
// print_r($ranking);
|
||||
// exit();
|
||||
// foreach ($oldUserRankings as $ranking) {
|
||||
$previousTotalScore = $ranking->total_score;
|
||||
$currentTotalScore = $newUserRanking->total_score;
|
||||
if ($ranking->user_id == $user_id) {
|
||||
if ($previousTotalScore === null) {
|
||||
$ranking->progress_bar = '0'; // Initial entry
|
||||
} elseif ($currentTotalScore > $previousTotalScore) {
|
||||
$ranking->progress_bar = '0'; // Total score increased
|
||||
$message = "You earned 1 point!";
|
||||
} elseif ($currentTotalScore < $previousTotalScore) {
|
||||
$ranking->progress_bar = '1'; // Total score decreased
|
||||
$message = "Your score decreased.";
|
||||
} else {
|
||||
$ranking->progress_bar = '2'; // Total score remained the same
|
||||
$message = "Your score remains the same.";
|
||||
}
|
||||
$ranking->save(); // Save the updated progress_bar value
|
||||
|
||||
}
|
||||
// }
|
||||
// dd($userRanking,$newUserRanking);
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'progress_bar' => $message,
|
||||
]);
|
||||
|
||||
}
|
||||
return response([
|
||||
'status' => "Success",
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
} catch (Exception $ex) {
|
||||
return response([
|
||||
'status' => "failed",
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function get_mood_o_meter() {
|
||||
try {
|
||||
// print_r(User::first()->user);exit;
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
$data = mood_o_meter::where('user_id', $user_id)->value('is_active');
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data fetched successfully.',
|
||||
'result' => $data
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("User data listing Failed : " . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something Went wrong.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_mood_o_meter_mood() {
|
||||
try {
|
||||
// print_r(User::first()->user);exit;
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
$data = mood_o_meter::where('user_id', $user_id)->value('mood_o_meter');
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data fetched successfully.',
|
||||
'result' => $data
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("User data listing Failed : " . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something Went wrong.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
39
app/Http/Controllers/API/NewsAndArticleController.php
Normal file
39
app/Http/Controllers/API/NewsAndArticleController.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\ManageNewsArticles;
|
||||
use App\Models\NewsArticlesCategory;
|
||||
|
||||
class NewsAndArticleController extends Controller
|
||||
{
|
||||
public function getData(){
|
||||
$data['category'] = NewsArticlesCategory::with('articles')->where('is_active','1')->inRandomOrder()->get();
|
||||
// dd($data);
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data fetched successfully.',
|
||||
'result' => $data
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function search(Request $request)
|
||||
{
|
||||
$result = ManageNewsArticles::where('article_name', 'LIKE', '%' . $request->article_name . '%')->where('category_id',$request->category_id)->where('is_active','1')->get();
|
||||
// dd($result);
|
||||
|
||||
if (count($result) > 0) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data fetched successfully.',
|
||||
'result' => $result]);
|
||||
} else {
|
||||
return response()->json(['Result' => 'No Data found'], 200);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
88
app/Http/Controllers/API/PeriodDatesController.php
Normal file
88
app/Http/Controllers/API/PeriodDatesController.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\PeriodDate;
|
||||
|
||||
class PeriodDatesController extends Controller
|
||||
{
|
||||
public function storeDates(Request $request){
|
||||
|
||||
$token = readHeaderToken();
|
||||
if($token){
|
||||
|
||||
$user_id = $token['sub'];
|
||||
$data = $request->all();
|
||||
// dd($data);
|
||||
// $datetime = $data['datetime'];
|
||||
$predicted_dates = $data['predicted_dates'];
|
||||
$fertile_dates = $data['fertile_dates'];
|
||||
$ovulating_dates = $data['ovulating_dates'];
|
||||
$pickerdateRange = $data['pickerdateRange'];
|
||||
|
||||
// $jsonEncodedDateTimeArray = json_encode($datetime);
|
||||
$jsonEncodedPredictedDatesArray = json_encode($predicted_dates);
|
||||
$jsonEncodedFertileDatesArray = json_encode($fertile_dates);
|
||||
$jsonEncodedOvulatingDatesArray = json_encode($ovulating_dates);
|
||||
$jsonEncodedPickerDteRangeArray = json_encode($pickerdateRange);
|
||||
|
||||
PeriodDate::updateOrCreate( ['user_id'=>$user_id],
|
||||
[
|
||||
'predicted_dates'=>$jsonEncodedPredictedDatesArray,
|
||||
'fertile_dates'=>$jsonEncodedFertileDatesArray,
|
||||
'ovulating_dates'=>$jsonEncodedOvulatingDatesArray,
|
||||
'pickerdateRange'=>$jsonEncodedPickerDteRangeArray,
|
||||
'period_cycle_length'=>$request->period_cycle_length
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data Added Successfully'
|
||||
],200);
|
||||
}else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getPeriodDates(){
|
||||
|
||||
$token = readHeaderToken();
|
||||
if($token){
|
||||
$user_id = $token['sub'];
|
||||
|
||||
$data = PeriodDate::where('user_id',$user_id)->first();
|
||||
|
||||
$result['predictedDates'] = json_decode($data->predicted_dates);
|
||||
$result['fertileDates'] = json_decode($data->fertile_dates);
|
||||
$result['ovulatingDates'] = json_decode($data->ovulating_dates);
|
||||
$result['pickerdateRange'] = json_decode($data->pickerdateRange);
|
||||
$result['period_cycle_length'] = $data->period_cycle_length;
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data fetched successfully.',
|
||||
'result' => $result
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function deletePeriodDates(){
|
||||
$token = readHeaderToken();
|
||||
if($token){
|
||||
$user_id = $token['sub'];
|
||||
// dd($user_id);
|
||||
$data = PeriodDate::where('user_id',$user_id)->delete();
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data delete successfully.',
|
||||
'result' => $data
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
194
app/Http/Controllers/API/ProfileController.php
Normal file
194
app/Http/Controllers/API/ProfileController.php
Normal file
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Validator;
|
||||
use App\Models\UserDetail;
|
||||
use App\Models\CompanyMaster;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Auth;
|
||||
|
||||
class ProfileController extends Controller {
|
||||
|
||||
public function profileUpdate(Request $request) {
|
||||
try {
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
$user = auth()->user();
|
||||
// print_r($user);exit;
|
||||
// check validation
|
||||
$validator = Validator::make($request->all(), [
|
||||
'full_name'=>'required',
|
||||
'bio' => 'required|string|min:6',
|
||||
'description' => 'required|string|min:6',
|
||||
'gender' => 'required|in:male,female',
|
||||
'age' => 'required',
|
||||
'full_address' => 'required',
|
||||
'city' => 'required',
|
||||
'height' => 'required',
|
||||
// 'weight' => 'required',
|
||||
// 'profile_picture' => 'required|image|mimes:jpg,png,jpeg,gif',
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'error' => $validator->errors()], 401);
|
||||
}
|
||||
|
||||
$profile_completed_status = User::select('status')->find($user_id);
|
||||
if ($profile_completed_status->status == 0) {
|
||||
$UserDetail = new UserDetail;
|
||||
$UserDetail->user_id = $user_id;
|
||||
$UserDetail->user_bio = $request->input('bio');
|
||||
$UserDetail->description = $request->input('description');
|
||||
$UserDetail->gender = $request->input('gender');
|
||||
$UserDetail->age = $request->input('age');
|
||||
$UserDetail->full_address = $request->input('full_address');
|
||||
$UserDetail->city = $request->input('city');
|
||||
$UserDetail->height = $request->input('height');
|
||||
// $UserDetail->weight = $request->input('weight');
|
||||
if ($request->hasFile('profile_picture')) {
|
||||
$file = $request->file('profile_picture');
|
||||
$ext = $file->extension();
|
||||
$file_name = time() . '.' . $ext;
|
||||
$path = public_path() . '/uploads/profile_images/';
|
||||
$file->move($path, $file_name);
|
||||
$UserDetail->profile_picture = url('/public/uploads/profile_images/' . $file_name);
|
||||
}
|
||||
$UserDetail->save();
|
||||
User::where('id', $user_id)->update(array('status' => '1'));
|
||||
$msg = "Profile Completed Successfully.";
|
||||
} else {
|
||||
$user = UserDetail::where('user_id', $user_id)->first();
|
||||
// $file_name = $user->profile_picture;
|
||||
$UserDetails = UserDetail::where('user_id', $user_id)->first();
|
||||
|
||||
$UserDetails->user_bio = $request->input('bio');
|
||||
$UserDetails->description = $request->input('description');
|
||||
$UserDetails->gender = $request->input('gender');
|
||||
$UserDetails->age = $request->input('age');
|
||||
$UserDetails->full_address = $request->input('full_address');
|
||||
$UserDetails->city = $request->input('city');
|
||||
$UserDetails->height = $request->input('height');
|
||||
// 'weight' => $request->input('weight'),
|
||||
if ($request->hasFile('profile_picture')) {
|
||||
$file = $request->file('profile_picture');
|
||||
$ext = $file->extension();
|
||||
$file_name = time() . '.' . $ext;
|
||||
$path = public_path() . '/uploads/profile_images/';
|
||||
$file->move($path, $file_name);
|
||||
// delete previous file
|
||||
$previous_image = public_path('/uploads/profile_images/' . $user->profile_picture);
|
||||
$delete_prv_image = File::delete($previous_image);
|
||||
$UserDetails->profile_picture = url('/public/uploads/profile_images/' . $file_name);
|
||||
}
|
||||
// $UserDetails->profile_picture = url('/public/uploads/profile_images/' . $file_name);
|
||||
$UserDetails->save();
|
||||
User::where('id', $user_id)->update(array('full_name' => $request->input('full_name')));
|
||||
$msg = "Profile Updated Successfully.";
|
||||
}
|
||||
|
||||
$user = User::with('user_detail')->where('id', $user_id)->first()->toArray();
|
||||
// $user = User::select('id','full_name','contact_number','email_id','status')->where('id',$user->id)->first()->toArray();
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'status' => true,
|
||||
'message'=> $msg,
|
||||
'authorisation' => [
|
||||
'token' => null,
|
||||
'user_data' =>$user,
|
||||
'type' => 'bearer',
|
||||
]
|
||||
],200);
|
||||
// return response()->json([
|
||||
// 'success' => true,
|
||||
// 'status' => true,
|
||||
// 'message' => $msg,
|
||||
// 'authorisation' => [
|
||||
// 'token' => null,
|
||||
// 'user_detail' =>$user,
|
||||
// 'type' => 'bearer',
|
||||
// ],
|
||||
// ]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("Update Complete/Update Failed : " . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something Went wrong.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Created By : Pradyumn Dwivedi
|
||||
* Created at : 06 Feb 2023
|
||||
* Use : To display list of User data
|
||||
*/
|
||||
|
||||
public function index() {
|
||||
try {
|
||||
// print_r(User::first()->user);exit;
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
$data = User::with('user_detail')->where('id', $user_id)->first();
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data fetched successfully.',
|
||||
'authorisation' => [
|
||||
'user_data' => $data
|
||||
]
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("User data listing Failed : " . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something Went wrong.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function viewProfile() {
|
||||
try {
|
||||
// print_r(User::first()->user);exit;
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
$data = User::with('user_detail')->get();
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data fetched successfully.',
|
||||
'result' => $data
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("User data listing Failed : " . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something Went wrong.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
131
app/Http/Controllers/API/QuizController.php
Normal file
131
app/Http/Controllers/API/QuizController.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\ManageQuizQuestion;
|
||||
use App\Models\QuizQuestionsAnswer;
|
||||
use App\Models\UserQuizPoints;
|
||||
use App\Models\LeaderboardMaster;
|
||||
|
||||
class QuizController extends Controller
|
||||
{
|
||||
// public function getQuiz(){
|
||||
// $currentDateTime = now();
|
||||
// $data = $data = ManageQuizQuestion::with('answer')->where('is_active', '1')->where('schedule_timing', '=', $currentDateTime)->inRandomOrder()->limit(3)->get()->toArray();
|
||||
// // $data = $data = ManageQuizQuestion::with('answer')->where('is_active', '1')->inRandomOrder()->limit(3)->get()->toArray();
|
||||
|
||||
|
||||
// if (empty($data)) {
|
||||
// return response()->json([
|
||||
// 'success' => false,
|
||||
// 'message' => 'No quiz found.',
|
||||
// 'result' => []
|
||||
// ]);
|
||||
// }
|
||||
|
||||
// return response()->json([
|
||||
// 'success' => true,
|
||||
// 'message' => 'Data fetched successfully.',
|
||||
// 'result' => $data
|
||||
// ]);
|
||||
|
||||
// }
|
||||
|
||||
public function getQuiz() {
|
||||
$currentDateTime = now();
|
||||
|
||||
$todayQuizzes = ManageQuizQuestion::with('answer')->where('is_active', '1')->whereDate('schedule_timing', '=', $currentDateTime)->latest()->limit(3)->get()->toArray();
|
||||
|
||||
// If there are no quizzes scheduled for today or if any one quiz is inactive, fetch past quizzes
|
||||
if (count($todayQuizzes) === 0 || count($todayQuizzes) < 3) {
|
||||
$remainingSlots = 3 - count($todayQuizzes);
|
||||
|
||||
$pastQuizzes = ManageQuizQuestion::with('answer')->where('is_active', '1')->whereDate('schedule_timing', '<', $currentDateTime)->inRandomOrder()->limit($remainingSlots)->get()->toArray();
|
||||
|
||||
// Merge today's and past quizzes
|
||||
$data = array_merge($todayQuizzes, $pastQuizzes);
|
||||
} else {
|
||||
// If there are quizzes scheduled for today, use those
|
||||
$data = $todayQuizzes;
|
||||
}
|
||||
|
||||
if (empty($data)) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'No quiz found.',
|
||||
'result' => []
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data fetched successfully.',
|
||||
'result' => $data
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function storeQuizPoints(Request $request){
|
||||
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
$currentDate = now()->toDateString(); // Extracting only the date part
|
||||
// dd($currentDate);
|
||||
|
||||
$existingRecord = UserQuizPoints::whereDate('created_at', $currentDate)
|
||||
->where('user_id', $user_id)
|
||||
->first();
|
||||
// dd($existingRecord);
|
||||
$points = $request->points*10;
|
||||
if ($existingRecord == null) {
|
||||
UserQuizPoints::create(['user_id'=>$user_id,'quize_points'=>$points,'is_active'=>'1']);
|
||||
$leaderboard = LeaderboardMaster::where('user_id', $user_id)->first();
|
||||
$leaderboard->total_score += $points;
|
||||
$leaderboard->save();
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Points Adeed Succefully'
|
||||
]);
|
||||
}else{
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Points Already Added'
|
||||
]);
|
||||
}
|
||||
}else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function getUerQuizpoints(){
|
||||
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
$currentDate = now()->toDateString(); // Extracting only the date part
|
||||
// dd($currentDate);
|
||||
|
||||
$userQuizPoints = UserQuizPoints::whereDate('created_at', $currentDate)
|
||||
->where('user_id', $user_id)->get();
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data fetched successfully.',
|
||||
'result' => $userQuizPoints
|
||||
]);
|
||||
// dd($existingRecord);
|
||||
}else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
58
app/Http/Controllers/API/RateUsController.php
Normal file
58
app/Http/Controllers/API/RateUsController.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\ManageRateUs;
|
||||
use App\Models\ManageFeedback;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Auth;
|
||||
|
||||
class RateUsController extends Controller
|
||||
{
|
||||
public function getData(){
|
||||
$result = ManageRateUs::where('is_active','1')->get();
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data fetched successfully.',
|
||||
'result' => $result
|
||||
]);
|
||||
}
|
||||
|
||||
public function updateRateUs(Request $request) {
|
||||
$token = readHeaderToken();
|
||||
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
$user = auth()->user();
|
||||
|
||||
$existingRecord = ManageRateUs::where('user_id', $user_id)->first();
|
||||
|
||||
if ($existingRecord) {
|
||||
// If the record exists, update it
|
||||
$existingRecord->update(['rate_us' => $request->rate_us]);
|
||||
$data = $existingRecord;
|
||||
} else {
|
||||
$data = ManageRateUs::create([
|
||||
'user_id' => $user_id,
|
||||
'rate_us' => $request->rate_us,
|
||||
]);
|
||||
}
|
||||
|
||||
$message = $existingRecord ? 'Data updated successfully.' : 'Data created successfully.';
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => $message,
|
||||
'result' => $data
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something went wrong.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
56
app/Http/Controllers/API/RegisterController.php
Normal file
56
app/Http/Controllers/API/RegisterController.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\User;
|
||||
use Auth;
|
||||
use Validator;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class RegisterController extends Controller
|
||||
{
|
||||
public function storeRegistrationData(Request $request)
|
||||
{
|
||||
// print_r("fghjkl");exit;
|
||||
$validator = Validator::make($request->all(),[
|
||||
'full_name'=> 'required',
|
||||
'contact_number'=> 'required',
|
||||
'email_id'=> 'required|unique:users,email_id',
|
||||
'password'=> 'required|confirmed',
|
||||
'address'=> 'required',
|
||||
'fitness_goal'=> 'required',
|
||||
'hear_about_us'=> 'required',
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'error'=>$validator->errors()], 401);
|
||||
}
|
||||
$data = new User;
|
||||
$data->full_name = $request->input('full_name');
|
||||
$data->contact_number = $request->input('contact_number');
|
||||
$data->email_id = $request->input('email_id');
|
||||
$data->password = Hash::make($request->input('password'));
|
||||
$data->address = $request->input('address');
|
||||
$data->fitness_goal = $request->input('fitness_goal');
|
||||
$data->hear_about = $request->input('hear_about_us');
|
||||
$register = $data->save();
|
||||
if($register == 1){
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'status'=>200,
|
||||
'message'=> 'User Register Successfully',
|
||||
]);
|
||||
}else{
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'error'=>400,
|
||||
'message'=> 'Please Try Again',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
81
app/Http/Controllers/API/ShareYourThoughtsController.php
Normal file
81
app/Http/Controllers/API/ShareYourThoughtsController.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\ShareYourThought;
|
||||
use App\Models\User;
|
||||
use App\Models\UserThought;
|
||||
use Auth;
|
||||
|
||||
class ShareYourThoughtsController extends Controller {
|
||||
|
||||
public function add_thoughts(Request $request) {
|
||||
try {
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
$user = auth()->user();
|
||||
// print_r($user);exit;
|
||||
|
||||
// check validation
|
||||
// $validator = Validator::make($request->all(), [
|
||||
// 'rating' => 'required|integer|min:1|max:5',
|
||||
// ]);
|
||||
// if ($validator->fails()) {
|
||||
// return response()->json([
|
||||
// 'error' => $validator->errors()], 401);
|
||||
// }
|
||||
|
||||
$thoughts = new ShareYourThought;
|
||||
$thoughts->rating = $request->input('rating');
|
||||
$thoughts->user_id = $user_id;
|
||||
$thoughts->save();
|
||||
$msg = "Thank You Review Added Successfully.";
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => $msg,
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("Update Complete/Update Failed : " . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something Went wrong.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_thought_id() {
|
||||
try {
|
||||
// print_r(User::first()->user);exit;
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
// $user_id = $token['sub'];
|
||||
$data = UserThought::where('is_active', '1')->inRandomOrder()->get();
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data fetched successfully.',
|
||||
'result' => $data
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("User data listing Failed : " . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something Went wrong.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
220
app/Http/Controllers/API/ShortClipsController.php
Normal file
220
app/Http/Controllers/API/ShortClipsController.php
Normal file
@@ -0,0 +1,220 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\ManageShortClips;
|
||||
use App\Models\ShortClipsLikes;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
//use App\Models\User;
|
||||
use Validator;
|
||||
use db;
|
||||
|
||||
class ShortClipsController extends Controller {
|
||||
|
||||
// public function store_short_clips(Request $req) {
|
||||
//
|
||||
// $validator = Validator::make($req->all(), [
|
||||
// 'video_title' => 'required',
|
||||
// 'video_description' => 'required',
|
||||
// 'video_url' => 'required',
|
||||
// ]);
|
||||
// if ($validator->fails()) {
|
||||
// return response()->json([
|
||||
// 'error' => $validator->errors()], 401);
|
||||
// }
|
||||
// $shortclips = new ManageShortClips();
|
||||
// $shortclips->video_title = $req->input('video_title');
|
||||
// $shortclips->video_description = $req->input('video_description');
|
||||
// $shortclips->video_url = $req->input('video_url');
|
||||
// $shortclips->thumbnail = $req->input('thumbnail');
|
||||
// $storeclips = $shortclips->save();
|
||||
// if ($storeclips == 1) {
|
||||
// return response()->json([
|
||||
// 'success' => true,
|
||||
// 'status' => 200,
|
||||
// 'message' => 'Short Clips Added Successfully',
|
||||
// ]);
|
||||
// } else {
|
||||
// return response()->json([
|
||||
// 'success' => true,
|
||||
// 'error' => 400,
|
||||
// 'message' => 'Please Try Again',
|
||||
// ]);
|
||||
// }
|
||||
// }
|
||||
|
||||
public function like_short_clips(Request $request) {
|
||||
try {
|
||||
// print_r(User::first()->user);exit;
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
// dd($user_id);
|
||||
// check validation
|
||||
$validator = Validator::make($request->all(), [
|
||||
'short_clips_id' => 'required',
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'error' => $validator->errors()], 401);
|
||||
}
|
||||
// check validation end
|
||||
$like = ShortClipsLikes::where('user_id', $user_id)
|
||||
->where('short_clips_id', $request->short_clips_id)
|
||||
->first();
|
||||
|
||||
if (!empty($like)) {
|
||||
if ($like->is_like == '0') {
|
||||
$like->is_like = '1';
|
||||
$like->is_active = '0';
|
||||
$like->update();
|
||||
$manage_likes = ManageShortClips::where('id', $request->short_clips_id)->first();
|
||||
if ($manage_likes->likes > 0) {
|
||||
$manage_likes->likes = $manage_likes->likes - 1;
|
||||
$manage_likes->update();
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => 'you unliked'
|
||||
], 200);
|
||||
} else {
|
||||
$like->is_like = '0';
|
||||
$like->is_active = '1';
|
||||
$like->update();
|
||||
$manage_likes = ManageShortClips::where('id', $request->short_clips_id)->first();
|
||||
$manage_likes->likes = $manage_likes->likes + 1;
|
||||
$manage_likes->update();
|
||||
|
||||
|
||||
|
||||
return response()->json([
|
||||
'message' => 'you liked'
|
||||
], 200);
|
||||
}
|
||||
} else {
|
||||
$like = new ShortClipsLikes();
|
||||
$like->user_id = $user_id;
|
||||
$like->is_active = '1';
|
||||
$like->short_clips_id = $request->short_clips_id;
|
||||
if ($like->save()) {
|
||||
$manage_likes = ManageShortClips::where('id', $request->short_clips_id)->first();
|
||||
$manage_likes->likes = $manage_likes->likes + 1;
|
||||
$manage_likes->update();
|
||||
return response()->json([
|
||||
'message' => 'You Like a post',
|
||||
], 201);
|
||||
} else {
|
||||
return response()->json([
|
||||
'message' => "please try again"
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'likes added successfully.',
|
||||
'result' => $data
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("User data listing Failed : " . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something Went wrong.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function get_short_clips_by_id($id) {
|
||||
// print_r("dfghjk");
|
||||
$get_short_clips = ManageShortClips::find($id);
|
||||
// print_r($get_short_clips);
|
||||
// exit;
|
||||
}
|
||||
|
||||
public function update_short_clips(Request $request) {
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'likes' => 'required',
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'error' => $validator->errors()], 401);
|
||||
}
|
||||
$shortclips = ManageShortClips();
|
||||
$shortclips->likes = $req->input('likes');
|
||||
|
||||
$storeclips = $shortclips->save();
|
||||
if ($storeclips == 1) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'status' => 200,
|
||||
'message' => 'Short Clips Added Successfully',
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'error' => 400,
|
||||
'message' => 'Please Try Again',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_short_clips() {
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
// $userid = auth()->user();
|
||||
|
||||
$shortdata = ManageShortClips::where('is_active','1')->get();
|
||||
|
||||
foreach ($shortdata as $k => $val) {
|
||||
|
||||
$shortdata[$k]['thumbnail'] = ListingImageUrl('short_clips', $val['thumbnail']);
|
||||
}
|
||||
// print_r($shortdata);
|
||||
// exit;
|
||||
return response([
|
||||
'user' => $shortdata,
|
||||
// 'token' => $user->createToken('secret')->plainTextToken
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_short_clips_likes(){
|
||||
// try {
|
||||
// print_r(User::first()->user);exit;
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
|
||||
$data = ShortClipsLikes::with('shortClicpLikes')->where('user_id', $user_id)->where('is_active','1')->get();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data fetched successfully.',
|
||||
'result' => $data
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
// } catch (\Exception $e) {
|
||||
// \Log::error("User data listing Failed : " . $e->getMessage());
|
||||
// return response()->json([
|
||||
// 'success' => false,
|
||||
// 'message' => 'Something Went wrong.',
|
||||
// ]);
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
124
app/Http/Controllers/API/StepCountController.php
Normal file
124
app/Http/Controllers/API/StepCountController.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\DailyStepsCount;
|
||||
use APP\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use App\Models\LeaderboardMaster;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
|
||||
class StepCountController extends Controller
|
||||
{
|
||||
public function store_step_count(Request $request){
|
||||
|
||||
// dd($request->step_count);
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$stepCount = $request->step_count;
|
||||
$userId = $token['sub'];
|
||||
// dd($userId);
|
||||
$server_date = Carbon::now()->toDateString();
|
||||
$user_date = $request->date;
|
||||
|
||||
if($user_date == null){
|
||||
$date = $server_date;
|
||||
}else{
|
||||
$date = $user_date;
|
||||
}
|
||||
|
||||
$dailyStepCount = DailyStepsCount::where('user_id', $userId)
|
||||
->where('date', $date)
|
||||
->first();
|
||||
// dd($dailyStepCount);
|
||||
Log::info("dailyStepCount found at that date");
|
||||
// dd($dailyStepCount->step_count);
|
||||
|
||||
if ($dailyStepCount) {
|
||||
$oldStepCounts = $dailyStepCount->step_count;
|
||||
$oldPoints = $dailyStepCount->points;
|
||||
|
||||
// if($oldStepCounts > $stepCount){
|
||||
// $stepCount = $oldStepCounts + $stepCount;
|
||||
// }
|
||||
|
||||
// if($device !== "android") {
|
||||
// if($stepCount>$oldStepCounts){
|
||||
$dailyStepCount->update(['step_count' => $stepCount]);
|
||||
// }
|
||||
// }else{
|
||||
// $dailyStepCount->update(['step_count' => $stepCount]);
|
||||
// }
|
||||
|
||||
|
||||
$latestSteps = $dailyStepCount->step_count;
|
||||
// Update the step count for the current date and update points
|
||||
|
||||
$latestPoints = intval(floor($latestSteps/1000));
|
||||
if($latestPoints > $oldPoints){
|
||||
$currentPoints = $latestPoints - $oldPoints;
|
||||
|
||||
//update points
|
||||
$dailyStepCount->update(['points' => $latestPoints]);
|
||||
|
||||
$leaderboardMaster = LeaderboardMaster::where('user_id', $userId)->first();
|
||||
|
||||
if ($leaderboardMaster) {
|
||||
// $latestPoints = $latestPoints*5;
|
||||
$leaderboardMaster->total_score += 5*$currentPoints;
|
||||
$leaderboardMaster->save();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$updated_step_counts = $points = intval(floor($dailyStepCount->step_count/1000));
|
||||
$updated_points = $dailyStepCount->points;
|
||||
if($updated_step_counts < $updated_points){
|
||||
$leaderboardMaster = LeaderboardMaster::where('user_id', $userId)->first();
|
||||
if ($leaderboardMaster) {
|
||||
|
||||
$leaderboardMaster->total_score -= 5*$updated_points;
|
||||
$leaderboardMaster->total_score += 5*$updated_step_counts;
|
||||
$leaderboardMaster->save();
|
||||
}
|
||||
$dailyStepCount->update(['points' => $updated_step_counts]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
Log::info("New user Creating");
|
||||
// Create a new record for the new day
|
||||
$points = intval(floor($stepCount/1000));
|
||||
$newDailyStepCount = new DailyStepsCount([
|
||||
'user_id' => $userId,
|
||||
'date' => $date,
|
||||
'step_count' => $stepCount,
|
||||
'points' => $points,
|
||||
]);
|
||||
|
||||
$newDailyStepCount->save();
|
||||
|
||||
$leaderboardMaster = LeaderboardMaster::where('user_id', $userId)->first();
|
||||
if ($leaderboardMaster) {
|
||||
|
||||
$leaderboardMaster->total_score += 5*$points;
|
||||
$leaderboardMaster->save();
|
||||
}
|
||||
}
|
||||
|
||||
return response(['status' => "Success"], 200);
|
||||
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
76
app/Http/Controllers/API/TestimonialController.php
Normal file
76
app/Http/Controllers/API/TestimonialController.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Testimonial;
|
||||
use App\Models\TestimonialImages;
|
||||
use Validator;
|
||||
|
||||
|
||||
class TestimonialController extends Controller
|
||||
{
|
||||
public function get_Testimonial() {
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$testdata = Testimonial::with('testimonial_data')->inRandomOrder()->get();
|
||||
// echo "<pre>";
|
||||
// print_r($testdata);
|
||||
// exit;
|
||||
// foreach ($testdata as $val) {
|
||||
|
||||
// foreach($val['testimonial_data'] as $k =>$image){
|
||||
// $testdata[$k]['image'] = ListingImageUrl('testimonial', $val['image']);
|
||||
// }
|
||||
|
||||
// }
|
||||
return response([
|
||||
'user' => $testdata,
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
|
||||
public function store_testimonial(Request $req) {
|
||||
|
||||
$validator = Validator::make($req->all(), [
|
||||
'user_name' => 'required',
|
||||
'image' => 'required|image|mimes:jpg,png,jpeg,gif',
|
||||
'title' => 'required',
|
||||
'description' => 'required',
|
||||
'rating' => 'required',
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'error' => $validator->errors()], 401);
|
||||
}
|
||||
$testimonials = new Testimonial();
|
||||
$testimonials->user_name = $req->input('user_name');
|
||||
// $testimonials->image = $req->input('image');
|
||||
$testimonials->title = $req->input('title');
|
||||
$testimonials->description = $req->input('description');
|
||||
$testimonials->rating = $req->input('rating');
|
||||
if ($req->hasFile('image')) {
|
||||
$file = $req->file('image');
|
||||
$ext = $file->extension();
|
||||
$file_name = time() . '.' . $ext;
|
||||
$path = public_path() . '/uploads/testimonial/';
|
||||
$file->move($path, $file_name);
|
||||
$testimonials->image = url('/public/uploads/testimonial/' . $file_name);
|
||||
}
|
||||
$storetestimonial = $testimonials->save();
|
||||
if ($storetestimonial == 1) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'status' => 200,
|
||||
'message' => 'Testimonial Added Successfully',
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'error' => 400,
|
||||
'message' => 'Please Try Again',
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
73
app/Http/Controllers/API/UserController.php
Normal file
73
app/Http/Controllers/API/UserController.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Auth;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function userSubscriptionData(){
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
// dd($user_id);
|
||||
$result = User::where('id', $user_id)->where('is_active', '0')->first(['id', 'utm_source', 'start_date', 'end_date']);
|
||||
if ($result) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data fetched successfully.',
|
||||
'result' => $result
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'User not found.'
|
||||
], 404);
|
||||
}
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Token not provided.'
|
||||
], 401);
|
||||
}
|
||||
}
|
||||
|
||||
public function delete_user() {
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
// dd($user_id);
|
||||
$user = User::find($user_id);
|
||||
// dd($user);
|
||||
if ($user) {
|
||||
$data = $user->delete();
|
||||
if ($data) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'User deleted successfully.',
|
||||
'result' => $user
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Failed to delete user.'
|
||||
], 500);
|
||||
}
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'User not found.'
|
||||
], 404);
|
||||
}
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Token not provided.'
|
||||
], 401);
|
||||
}
|
||||
}
|
||||
}
|
||||
329
app/Http/Controllers/API/UserOverviewController.php
Normal file
329
app/Http/Controllers/API/UserOverviewController.php
Normal file
@@ -0,0 +1,329 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\UserOverView;
|
||||
use App\Models\LeaderboardMaster;
|
||||
use App\Models\User;
|
||||
use App\Models\UserDetail;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Validator;
|
||||
use Auth;
|
||||
use App\Models\ActivityMaster;
|
||||
|
||||
class UserOverviewController extends Controller {
|
||||
|
||||
public function add_user_overview(Request $req) {
|
||||
|
||||
try {
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
$todaysDate = Carbon::now()->toDateString();
|
||||
// dd($todaysDate);
|
||||
$oldUserRankings = LeaderboardMaster::with('user')->get();
|
||||
$result = UserOverView::where("user_id", $user_id)
|
||||
->where('created_at', $todaysDate)
|
||||
// ->orderBy('created_at', 'desc')
|
||||
->exists();
|
||||
if ($result) {
|
||||
$lastOverview = UserOverView::where('user_id', $user_id)
|
||||
->orderBy('created_at', 'desc')
|
||||
// ->skip(1)
|
||||
->first();
|
||||
UserOverView::where('user_id', $user_id)
|
||||
->whereDay('created_at', now()->day)
|
||||
->update([
|
||||
"muscle_rate" => $req->muscle_rate,
|
||||
"body_fat" => $req->body_fat,
|
||||
"skeletal_muscle" => $req->skeletal_muscle,
|
||||
"protein" => $req->protein,
|
||||
"bmr" => $req->bmr,
|
||||
"water" => $req->water,
|
||||
"age" => $req->age,
|
||||
"weight" => $req->weight,
|
||||
]);
|
||||
$points = (100 - $req->body_fat) + $req->muscle_rate;
|
||||
|
||||
$leaderboard = LeaderboardMaster::where('user_id', $user_id)->first();
|
||||
if ($leaderboard) {
|
||||
// $lastOverview = UserOverView::where('user_id', $user_id)
|
||||
// ->orderBy('created_at', 'desc')
|
||||
// // ->skip(1)
|
||||
// ->first();
|
||||
if ($lastOverview) {
|
||||
$pointsToDeduct = (100 - $lastOverview->body_fat) + $lastOverview->muscle_rate;
|
||||
$leaderboard->total_score -= $pointsToDeduct;
|
||||
// dd($leaderboard);
|
||||
// Ensure total_score is not negative
|
||||
if ($leaderboard->total_score < 0) {
|
||||
$leaderboard->total_score = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$leaderboard->total_score += $points;
|
||||
|
||||
|
||||
}
|
||||
$leaderboard->save();
|
||||
|
||||
$msg = "User Overview Updated Successfully.";
|
||||
} else {
|
||||
$tellobj = new UserOverView();
|
||||
$tellobj->user_id = $user_id;
|
||||
$tellobj->muscle_rate = $req->muscle_rate;
|
||||
$tellobj->body_fat = $req->body_fat;
|
||||
$tellobj->skeletal_muscle = $req->skeletal_muscle;
|
||||
$tellobj->protein = $req->protein;
|
||||
$tellobj->bmr = $req->bmr;
|
||||
$tellobj->water = $req->water;
|
||||
$tellobj->age = $req->age;
|
||||
$tellobj->weight = $req->weight;
|
||||
$tellobj->save();
|
||||
|
||||
// Calculate points based on body_fat and muscle_rate
|
||||
$points = (100 - $req->body_fat) + $req->muscle_rate ;
|
||||
|
||||
$userDetails = UserDetail::where('user_id', $user_id)->first();
|
||||
if ($userDetails && $userDetails->gender == 'female') {
|
||||
$points += 25;
|
||||
}else{
|
||||
$points += 1;
|
||||
}
|
||||
|
||||
$leaderboard = LeaderboardMaster::where('user_id', $user_id)->first();
|
||||
if ($leaderboard) {
|
||||
// Deduct points from yesterday's overview
|
||||
$lastOverview = UserOverView::where('user_id', $user_id)
|
||||
->orderBy('created_at', 'desc')
|
||||
->skip(1)
|
||||
->first();
|
||||
if ($lastOverview) {
|
||||
$pointsToDeduct = (100 - $lastOverview->body_fat) + $lastOverview->muscle_rate ;
|
||||
$leaderboard->total_score -= $pointsToDeduct;
|
||||
// Ensure total_score is not negative
|
||||
if ($leaderboard->total_score < 0) {
|
||||
$leaderboard->total_score = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$leaderboard->total_score += $points;
|
||||
} else {
|
||||
$leaderboard = new LeaderboardMaster();
|
||||
$leaderboard->user_id = $user_id;
|
||||
$leaderboard->total_score = $points;
|
||||
}
|
||||
|
||||
$leaderboard->save();
|
||||
|
||||
$msg = "User Overview Added Successfully.";
|
||||
}
|
||||
|
||||
// Decrease 5 point for every 3 days since the previous overview
|
||||
$lastOverview = UserOverView::where('user_id', $user_id)
|
||||
->orderBy('created_at', 'desc')
|
||||
->skip(1)
|
||||
->first();
|
||||
|
||||
if ($lastOverview) {
|
||||
$daysSinceLastOverview = $lastOverview->created_at->diffInDays(now());
|
||||
$pointsToDeduct = floor($daysSinceLastOverview / 3);
|
||||
|
||||
$leaderboard = LeaderboardMaster::where('user_id', $user_id)->first();
|
||||
if ($leaderboard) {
|
||||
$leaderboard->total_score -= $pointsToDeduct;
|
||||
$leaderboard->save();
|
||||
}
|
||||
}
|
||||
$newUserRanking = LeaderboardMaster::where('user_id',$user_id)->first();
|
||||
if ($oldUserRankings && $newUserRanking) {
|
||||
foreach ($oldUserRankings as $ranking) {
|
||||
$previousTotalScore = $ranking->total_score;
|
||||
$currentTotalScore = $newUserRanking->total_score;
|
||||
if($ranking->user_id==$user_id){
|
||||
if ($previousTotalScore === null) {
|
||||
$ranking->progress_bar = '0'; // Initial entry
|
||||
} elseif ($currentTotalScore > $previousTotalScore) {
|
||||
$ranking->progress_bar = '0'; // Total score increased
|
||||
$message = "You earned 1 point!";
|
||||
} elseif ($currentTotalScore < $previousTotalScore) {
|
||||
$ranking->progress_bar = '1'; // Total score decreased
|
||||
$message = "Your score decreased.";
|
||||
} else {
|
||||
$ranking->progress_bar = '2'; // Total score remained the same
|
||||
$message = "Your score remains the same.";
|
||||
}
|
||||
|
||||
$ranking->save(); // Save the updated progress_bar value
|
||||
}
|
||||
|
||||
}
|
||||
// dd($userRanking,$newUserRanking);
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => $msg,
|
||||
'progress_bar' => $message,
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
}catch (\Exception $e) {
|
||||
\Log::error("Update Complete/Update Failed : " . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something Went wrong.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_user_overview_by_id() {
|
||||
try {
|
||||
// print_r(User::first()->user);exit;
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
$data = UserOverView::where('user_id', $user_id)->get();
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data fetched successfully.',
|
||||
'result' => $data
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("User data listing Failed : " . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something Went wrong.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function show_user_overview(Request $request) {
|
||||
// dd($request->created_at);
|
||||
// try {
|
||||
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
// dd($request->created_at);
|
||||
$user_id = $token['sub'];
|
||||
if($request->created_at)
|
||||
{
|
||||
$data = UserOverView::where('user_id',$user_id)->where('created_at', $request->created_at)->first();
|
||||
}else{
|
||||
$data = UserOverView::where('user_id',$user_id)->get();
|
||||
}
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data fetched successfully.',
|
||||
'authorisation' => [
|
||||
'user_data' => $data
|
||||
]
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
// } catch (\Exception $e) {
|
||||
// \Log::error("User data listing Failed : " . $e->getMessage());
|
||||
// return response()->json([
|
||||
// 'success' => false,
|
||||
// 'message' => 'Something Went wrong.',
|
||||
// ]);
|
||||
// }
|
||||
}
|
||||
|
||||
public function showUserOverview_new(Request $request){
|
||||
|
||||
// dd($request->created_at);
|
||||
try {
|
||||
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
// dd($request->created_at);
|
||||
$user_id = $token['sub'];
|
||||
if($request->created_at)
|
||||
{
|
||||
$data = UserOverView::where('user_id',$user_id)->where('created_at', $request->created_at)->first();
|
||||
}else{
|
||||
|
||||
if($request->data == "week"){
|
||||
$last7Days = Carbon::now()->subDays(7);
|
||||
$data = UserOverView::where('user_id',$user_id)->where('created_at','>=',$last7Days)->get();
|
||||
}elseif($request->data == "month"){
|
||||
$last30Days = Carbon::now()->subDays(30);
|
||||
$data = UserOverView::where('user_id',$user_id)->where('created_at','>=',$last30Days)->get();
|
||||
}elseif($request->data == "year"){
|
||||
$lastYear = Carbon::now()->subYear();
|
||||
// dd($lastYear);
|
||||
$data = UserOverView::where('user_id',$user_id)->where('created_at','>=',$lastYear)->get();
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data fetched successfully.',
|
||||
'authorisation' => [
|
||||
'user_data' => $data
|
||||
]
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("User data listing Failed : " . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something Went wrong.',
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function resetPoints(){
|
||||
|
||||
$currentDate = date('Y-m-d');
|
||||
$activityData = ActivityMaster::orderBy('id','desc')->first();
|
||||
if($activityData){
|
||||
$start_date = $activityData->start_date;
|
||||
if($currentDate < $start_date){
|
||||
$leaderBoaradData = LeaderboardMaster::all();
|
||||
// dd($leaderBoaradData);
|
||||
foreach($leaderBoaradData as $data){
|
||||
LeaderboardMaster::where('user_id',$data->user_id)->update(['total_score' => 0]);
|
||||
}
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Reset Succefully'
|
||||
],200);
|
||||
}else{
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Season is not end yet!'
|
||||
],201);
|
||||
}
|
||||
}else{
|
||||
return response()->json([
|
||||
'success' => flase,
|
||||
'message' => 'No Activity Found'
|
||||
],404);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
20
app/Http/Controllers/API/ViewDevicesOneSignalController.php
Normal file
20
app/Http/Controllers/API/ViewDevicesOneSignalController.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ViewDevicesOneSignalController extends Controller
|
||||
{
|
||||
function fetchDevices() {
|
||||
$client = new \GuzzleHttp\Client();
|
||||
$response = $client->request('GET', 'https://onesignal.com/api/v1/players?app_id=1be4b99b-8faa-45b8-ad82-c66225d77bf4&limit=10&offset=0', [
|
||||
'headers' => [
|
||||
'Authorization' => 'Basic MWM2NGEyODUtN2U5MS00MzlkLWJhYmItZGUyODRjYTlmNGJm',
|
||||
'accept' => 'text/plain',
|
||||
],
|
||||
]);
|
||||
return $response->getBody();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user