171 lines
6.0 KiB
PHP
171 lines
6.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Frontend;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use App\Models\Frontend\User;
|
|
use App\Models\Frontend\volunteer_profile_document;
|
|
use App\Models\Profile;
|
|
use Mollie\Laravel\Facades\Mollie;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use App\Models\Admin\faq;
|
|
use App\Models\Frontend\payment_transaction_master;
|
|
use App\Models\Admin\blog_category;
|
|
use App\Models\Admin\blog;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class ProfileController extends Controller
|
|
{
|
|
public function view_profile()
|
|
{
|
|
if (session()->has("transaction_id")) {
|
|
$transaction_id = session("transaction_id");
|
|
$payment = payment_transaction_master::where(
|
|
"transaction_id",
|
|
$transaction_id
|
|
)->first();
|
|
if (!$payment) {
|
|
$payment_details = Mollie::api()
|
|
->payments()
|
|
->get($transaction_id);
|
|
// dd($payment_details);
|
|
// Process the payment status
|
|
if ($payment_details->isPaid()) {
|
|
$payment = new payment_transaction_master();
|
|
$payment->programs_xid = $payment_details->metadata->prog_id;
|
|
$pay_start_date = $payment_details->metadata->prog_start_date;
|
|
$newDateFormat = Carbon::createFromFormat('m/d/Y', $pay_start_date)->format('Y-m-d');
|
|
$payment->start_date = $newDateFormat;
|
|
$payment->duration = $payment_details->metadata->prog_week;
|
|
$payment->principal_xid = auth()->user()->id;
|
|
$payment->transaction_id = $payment_details->id;
|
|
$payment->amount = $payment_details->amount->value;
|
|
$payment->payment_status = 2;
|
|
if ($payment_details->amount->currency == "USD") {
|
|
$currency = "1";
|
|
} elseif ($payment_details->amount->currency == "GBP") {
|
|
$currency = "2";
|
|
} else {
|
|
$currency = "3";
|
|
}
|
|
$payment->currency = $currency;
|
|
$payment->save();
|
|
}
|
|
}
|
|
}
|
|
|
|
$users = auth()->user();
|
|
$users->load([
|
|
'paymentTransactions.Programs.programe_acomadation',
|
|
'paymentTransactions.Programs.programe_country'
|
|
]);
|
|
|
|
$users_data = $users->toArray();
|
|
$latestFaqs = FAQ::latest()
|
|
->limit(4)
|
|
->get()
|
|
->toArray();
|
|
|
|
return view("Frontend.Pages.User_profile.profile")->with([
|
|
"user" => $users_data,
|
|
"faq" => $latestFaqs,
|
|
]);
|
|
}
|
|
|
|
public function clear_volunteer(Request $request) {
|
|
$request->session()->forget('transaction_id');
|
|
return response()->json(['success' => true]);
|
|
}
|
|
|
|
public function detail_profile()
|
|
{
|
|
$users = auth()->user();
|
|
$users->load("user_documents");
|
|
$users->toArray();
|
|
|
|
$latestFaqs = FAQ::latest()
|
|
->limit(4)
|
|
->get()
|
|
->toArray();
|
|
|
|
$blog_three = blog::latest()->limit(3)->get();
|
|
$blog_categ = blog_category::latest()->limit(2)->get()->toArray();
|
|
|
|
return view("Frontend.Pages.User_profile.my_profile")->with([
|
|
"user" => $users,
|
|
"faq" => $latestFaqs,
|
|
'blog_muilti' => $blog_three,
|
|
'blog_category' => $blog_categ,
|
|
]);
|
|
}
|
|
|
|
public function update_profile(Request $request)
|
|
{
|
|
$user = User::find($request->profile_id);
|
|
$user->first_name = $request->input("first_name");
|
|
$user->last_name = $request->input("last_name");
|
|
$user->date_of_birth = $request->input("birth_date");
|
|
$user->gender = $request->input("gender");
|
|
|
|
if ($request->hasFile("profile_photo")) {
|
|
// Handle profile photo upload
|
|
$profilePhoto = $request->file("profile_photo");
|
|
$profilePhotoName = $request->profile_id . '_' . time() . '.' . $profilePhoto->getClientOriginalExtension();
|
|
$profilePhotoPath = public_path('assets/uploads/profile_images/');
|
|
$profilePhoto->move($profilePhotoPath, $profilePhotoName);
|
|
$user->profile_photo = $profilePhotoName;
|
|
}
|
|
|
|
$user->save();
|
|
|
|
// Handle image removal
|
|
$imagesToRemove = $request->input('images_to_remove')[0];
|
|
|
|
if (!empty($imagesToRemove)) {
|
|
$imagesToRemoveJson = json_decode($imagesToRemove);
|
|
|
|
foreach ($imagesToRemoveJson as $imageId) {
|
|
$userFile = volunteer_profile_document::find($imageId);
|
|
|
|
if ($userFile) {
|
|
$file_path = public_path($userFile->profile_documents);
|
|
|
|
if (file_exists($file_path)) {
|
|
unlink($file_path);
|
|
}
|
|
|
|
$userFile->delete();
|
|
}
|
|
}
|
|
}
|
|
|
|
// Handle multiple image uploads
|
|
if ($request->hasFile("images")) {
|
|
$number = 0;
|
|
foreach ($request->file("images") as $file) {
|
|
// Handle each uploaded file
|
|
$ext = $file->extension();
|
|
$imageName = $request->profile_id . '_' . time() . "_" . $number++ . "." . $ext;
|
|
$file_path = public_path("assets/uploads/profile_images/user_documents/");
|
|
|
|
if ($ext === "pdf") {
|
|
$file_path = public_path("assets/uploads/profile_images/user_pdf/");
|
|
}
|
|
|
|
$file->move($file_path, $imageName);
|
|
|
|
// Save the file details to the "users" table
|
|
$userFile = new volunteer_profile_document();
|
|
$userFile->principal_xid = auth()->user()->id; // Assuming this is the user ID
|
|
$userFile->profile_documents = "assets/uploads/" . ($ext === "pdf" ? "profile_images/user_pdf/" : "profile_images/user_documents/") . $imageName;
|
|
$userFile->document_type = $ext;
|
|
$userFile->save();
|
|
}
|
|
}
|
|
|
|
return response()->json(["success" => true, "status" => 200]);
|
|
}
|
|
|
|
}
|