/** * Handling request for user who is not logged in into to site * @param $request */ public function handleRequestForExternalUser($request, $next) { $userProfileVisiting = UserProfile::find($request->route()->parameter('id')); if (strtolower($request->method()) == "get" && (SiteConstants::isManager($userProfileVisiting->user_type) || SiteConstants::isAdmin($userProfileVisiting->user_type))) { return redirect('/'); } return $next($request); }
/** * Display all videos of a user on the page. * * @return Response */ public function index($id) { if ($this->checkIfGuestDoNotHavePermission($id, UserSettings::PRIVACY_TYPE_VIDEOS)) { return redirect('/'); } $videos = null; $userProfile = null; $youtube = new Youtube(array('key' => Dotenv::findEnvironmentVariable("GOOGLE_API_KEY_YOUTUBE"))); try { $userProfile = UserProfile::findOrFail($id); $userProfile->getMutatedData = false; $videos = $userProfile->videos; } catch (ModelNotFoundException $e) { return abort(404); } return view('profile.userMedia.videos', compact('videos', 'userProfile', 'youtube')); }
/** *Requesting recommendation from the person as specified in the form * @param Request $request */ public function request(HttpRequest $request) { $validator = Validator::make($request->all(), ['name' => 'required', 'email' => 'required|email', 'recommender_type' => 'required|in:' . SiteConstants::RECOMMENDER_COACH . "," . SiteConstants::RECOMMENDER_ATHLETE]); if ($validator->fails()) { return redirect()->back()->withErrors($validator->errors()); } $recommendation = new Recommendations(); $recommendation->user_id = Session::get(SiteSessions::USER_ID); $recommendation->status = SiteConstants::RECOMMENDATION_STATUS_WAITING; $recommendation->name = $request->get("name"); $recommendation->email = $request->get("email"); $recommendation->recommender_type = SiteConstants::getRecommenderType()[$request->get("recommender_type")]; $recommendation->save(); $userProfile = UserProfile::find(Session::get(SiteSessions::USER_ID)); //Send Mail to the Desired Person for recommendation Event::fire(new SendMail(SendMail::MAIL_TYPE_REQUEST_RECOMMENDATION, $recommendation->email, [], ["recommendation" => $recommendation, "userProfile" => $userProfile])); Session::flash('recommendation_request_status', 'success'); return redirect()->back(); }
/** * Storing videos of a user on the page. * * @return Response */ public function store(Request $request) { if (!$request->hasFile("image")) { return redirect()->back()->withErrors(["imageUploaded" => 'image not found']); } $validator = Validator::make($request->all(), ['image' => 'required', 'title' => 'required', 'descriptions' => 'required']); $imageFile = $request->file('image'); $imageExt = $imageFile->getClientOriginalExtension(); if (array_search(strtolower($imageExt), ['jpg', 'jpeg', 'png', 'gif'])) { return redirect()->back()->withErrors(["imageUploaded" => 'File extension is not supported.']); } if ($validator->fails()) { $errors = $validator->errors(); return redirect()->back()->withErrors($validator->errors()); } $fileName = hash("md5", $imageFile->getClientOriginalName() . Session::get(SiteSessions::USER_ID) . Session::get(SiteSessions::USER_NAME)) . "." . $imageFile->getClientOriginalExtension(); $userProfile = UserProfile::find(Session::get(SiteSessions::USER_ID)); //Saving Image // $image = Image::canvas(300, 300); // $image_updated = Image::make($imageFile)->resize(300, 300,function($constraint){ // $constraint->aspectRatio(); // }); // $image->insert($image_updated, 'center'); $image = Image::make($imageFile); $fileName = hash("md5", time() . Session::get(SiteSessions::USER_ID) . Session::get(SiteSessions::USER_NAME)) . "." . $imageFile->getClientOriginalExtension(); $this->createImageSourceDirectories(StorageLocationsRepository::USER_DIRECTORY_TYPE_SPORT_IMAGES); $image->save(public_path() . StorageLocationsRepository::USER_SPORT_IMAGES_STORAGE_PATH . $fileName); $imageRecord = new Images(); $imageRecord->user_id = Session::get(SiteSessions::USER_ID); $imageRecord->title = $request->get("title"); $imageRecord->descriptions = $request->get("descriptions"); $imageRecord->image_url = url(StorageLocationsRepository::USER_SPORT_IMAGES_STORAGE_PATH . $fileName); $imageRecord->added_on = Carbon::now(); $imageRecord->save(); return redirect('profile/' . Session::get(SiteSessions::USER_ID) . '/Images'); }
/** *View the page for general Settings */ public function generalSettings() { $userProfile = UserProfile::find(Session::get(SiteSessions::USER_ID)); return view('profile.settings.general_settings', compact('userProfile')); }
/** *Posting a message to a user */ public function sendMessage(Request $request) { if (!Auth::check()) { return response()->json(['status' => 'error', 'type' => 'user_not_logged_in']); } $validator = Validator::make($request->all(), ['user_id' => 'required', 'to_user_id' => 'required', 'subject' => 'required', 'message' => 'required']); if ($validator->fails()) { return response()->json(['status' => 'error', 'type' => 'validation_error']); } try { $userProfile = UserProfile::find($request->user_id); $userProfile->messages()->attach($request->to_user_id, ['subject' => $request->subject, 'message' => $request->message, 'sent_on' => Carbon::now(), 'from_user_message_status' => self::MESSAGE_STATUS_READ, 'to_user_message_status' => self::MESSAGE_STATUS_UNREAD]); $userProfile->save(); } catch (ModelNotFoundException $e) { return response()->json(['status' => 'error', 'type' => 'user_not_found']); } return response()->json(['status' => 'successful']); }
/** * Opportunities for Sport Talent - either Aspiring professional or Student * @param $state * @param $institution_tye * @param $gender * @param $sport_type */ public function talentOpportunities($state = null, $institution_type = null, $gender = null, $sport_type = null, $country = null) { $talent_management_level = Session::get(SiteSessions::USER_MANAGEMENT_LEVEL); $managers = null; switch ($talent_management_level) { case SiteConstants::USER_TALENT_MANAGEMENT_LEVEL_STUDENT: //Management level and Gender requested by the user. $managerManagementLevel = null; //If Institution type is "High School" if ($institution_type == 1) { $managerManagementLevel = SiteConstants::USER_MANAGER_MANAGEMENT_LEVEL_HIGH_SCHOOL; } else { if ($institution_type == 2) { $managerManagementLevel = SiteConstants::USER_MANAGER_MANAGEMENT_LEVEL_UNIVERSITY; } } $managers = ManagersDatabase::managerType(SiteConstants::USER_MANAGER_COACH)->managementLevel($managerManagementLevel)->state($state)->sportGender($gender)->sport($sport_type)->paginate(25); break; case SiteConstants::USER_TALENT_MANAGEMENT_LEVEL_ASPIRING_PRO: $managers = ManagersDatabase::country($country)->sport($sport_type)->sportGender($gender)->whereIn('management_level', [SiteConstants::USER_MANAGER_MANAGEMENT_LEVEL_AMATEUR, SiteConstants::USER_MANAGER_MANAGEMENT_LEVEL_PRO, SiteConstants::USER_MANAGER_MANAGEMENT_LEVEL_SEMI_PRO])->paginate(25); break; } $managers_already_contacted = DB::table("managers_contacted")->where('user_id', '=', Session::get(SiteSessions::USER_ID))->lists('manager_id'); $userProfile = UserProfile::find(Session::get(SiteSessions::USER_ID)); $userProfile->getMutatedData = false; $sport_gender = array_map('ucfirst', array_merge(['0' => '-- Select Option --'], SportsRepository::getSportsGender())); $state = array_map('ucfirst', array_merge(['0' => "-- Select State --"], BasicSiteRepository::getAmericanState())); $institution_type = array_map('ucfirst', UserProfileRepository::getInstituteType()); $country = array_map('ucfirst', BasicSiteRepository::getListOfCountries()); return view('database.talent_database_search_result', compact('managers', 'managers_already_contacted', 'userProfile', 'sport_gender', 'state', 'institution_type', 'country')); }
/** * Setting uploaded Image position - Either Cover Image or Profile Image * @param $id */ public function uploadedImageSetting($id) { $image_type = Session::has('image_type') ? Session::get('image_type') : ""; $userProfile = UserProfile::find(Session::get(SiteSessions::USER_ID)); return view('profile.configure_cover_image', compact('userProfile', 'image_type')); }