public function update(Request $request, $locationID)
 {
     if (!Auth::check() || !Auth::user()->is_admin) {
         return response(view('errors.403', ['error' => $this->errorMessages['incorrect_permissions']]), 403);
     }
     $data = $request->only(['name', 'latitude', 'longitude', 'capacity', 'featured_image']);
     // Validate all input
     $validator = Validator::make($data, ['name' => 'required', 'latitude' => 'required|numeric|between:-85.05,85.05', 'longitude' => 'required|numeric|between:-180,180', 'capacity' => 'required', 'featured_image' => 'image|sometimes']);
     if ($validator->fails()) {
         // If validation fails, redirect back to
         // registration form with errors
         return Redirect::back()->withErrors($validator)->withInput();
     }
     if ($request->hasFile('featured_image')) {
         $data['featured_image'] = MediaController::uploadImage($request->file('featured_image'), time(), $directory = "news_images", $bestFit = true, $fitDimensions = [1920, 1080]);
     } else {
         unset($data['featured_image']);
     }
     $location = Location::find($locationID);
     $location->update($data);
     return Redirect::route('locations.edit', [$location->id]);
 }
Beispiel #2
0
 public function update(Request $request, $newsID)
 {
     if (!Auth::check() || !Auth::user()->is_admin) {
         return response(view('errors.403', ['error' => $this->errorMessages['incorrect_permissions']]), 403);
     }
     $data = $request->only(['mce_0', 'mce_1', 'tags', 'featured_image']);
     // Validate all input
     $validator = Validator::make($data, ['mce_0' => 'required', 'mce_1' => 'required', 'featured_image' => 'image|sometimes']);
     if ($validator->fails()) {
         // If validation fails, redirect back to
         // registration form with errors
         return Redirect::back()->withErrors($validator)->withInput();
     }
     if ($request->hasFile('featured_image')) {
         $data['featured_image'] = MediaController::uploadImage($request->file('featured_image'), time(), $directory = "news_images", $bestFit = true, $fitDimensions = [1920, 1080]);
     } else {
         unset($data['featured_image']);
     }
     $data['title'] = $data['mce_0'];
     $data['content'] = $data['mce_1'];
     $news = News::find($newsID);
     $news->update($data);
     return Redirect::route('news.edit', [$news->id]);
 }
 public function update($partnerID, Request $request)
 {
     if (!Auth::check() || !Auth::user()->is_admin) {
         return response(view('errors.403', ['error' => $this->errorMessages['incorrect_permissions']]), 403);
     }
     $data = $request->only(['name', 'type', 'price', 'location_id', 'description', 'email', 'featured_image']);
     // Validate all input
     $validator = Validator::make($data, ['featured_image' => 'image|sometimes']);
     if ($validator->fails()) {
         // If validation fails, redirect back to
         // registration form with errors
         return Redirect::back()->withErrors($validator)->withInput();
     }
     if ($request->hasFile('featured_image')) {
         $data['featured_image'] = MediaController::uploadImage($request->file('featured_image'), time(), $directory = "partner_images", $bestFit = true, $fitDimensions = [1920, 1080]);
     } else {
         unset($data['featured_image']);
     }
     $partner = Partner::find($partnerID);
     $partner->update($data);
     $partner->events()->detach();
     $distance;
     foreach ($data['event_id'] as $event_id) {
         $distance = getMapsMatrixDistance(Event::find($event_id)->location, $partner->location);
         $partner->events()->attach($event_id, ['distance' => $distance]);
     }
     return Redirect::route('partners.edit', [$partner->id]);
 }
Beispiel #4
0
 /**
  *   Test function for updating user information
  *	@param Request $request
  *	@param $encryptedID		The users encryped id
  *	@return Redirect
  */
 public function updateUserInfo(Request $request, $encryptedID)
 {
     $data = $request->only(['name', 'bio', 'password', 'profile_picture', 'language', 'city', 'country', 'username']);
     $userID = Crypt::decrypt($encryptedID);
     $user = User::find($userID);
     $validatorData = ['name' => 'required|min:3', 'bio' => 'required', 'password' => 'sometimes|min:5', 'profile_picture' => 'sometimes', 'language' => 'required', 'city' => 'required', 'country' => 'required'];
     if ($user->facebook_id == $user->username) {
         $validatorData["username"] = "******";
     }
     if ($data['username'] == '') {
         unset($data['username']);
     }
     $validator = Validator::make($data, $validatorData);
     if ($validator->fails()) {
         // If validation fails, redirect back to
         // registration form with errors
         return Redirect::back()->withErrors($validator)->withInput();
     }
     if ($request->hasFile('profile_picture')) {
         $data['profile_picture'] = MediaController::uploadImage($request->file('profile_picture'), time(), $directory = "user", $bestFit = true, $fitDimensions = [500, 500]);
     } else {
         $data['profile_picture'] = $user->profile_picture;
     }
     if (isset($data['password']) && $data['password'] != '') {
         $data['password'] = Hash::make($data['password']);
     } else {
         if (isset($data['password'])) {
             unset($data['password']);
         }
     }
     $update = $user->update($data);
     if (isset($data['username'])) {
         $from = Session::get('fb_logged_in_from', "/");
         return Redirect::to($from)->with('message', 'Great! Your profile is ready. Feel free to browse the site.');
     }
     return Redirect::route('user/show', $userID);
 }
Beispiel #5
0
 /**
  * Upload a company logo during the installation process
  * @param  Image $image
  * @return string        The URLs for the normal and white versions of the logo
  */
 public static function uploadLogo($image)
 {
     // Get the file from the request
     $file = $image;
     $folder = '/company/';
     $destination_path = storage_path() . $folder;
     $file_name = 'company_logo.' . $file->getClientOriginalExtension();
     $file_name_white = 'company_logo_white.' . $file->getClientOriginalExtension();
     // Move the file to our server
     $movement = $image->move($destination_path, $file_name);
     MediaController::whiteOverlay($destination_path . $file_name, $destination_path . $file_name_white);
     return ["normal" => (string) $folder . $file_name, "white" => (string) $folder . $file_name_white];
 }
Beispiel #6
0
 /**
  * Process an API upload request for images
  * @param  Request $request
  * @param  string  $encryptedEventID
  * @return JSON
  */
 public function uploadMedia(Request $request, $encryptedEventID)
 {
     $eventID = Crypt::decrypt($encryptedEventID);
     $data = $request->only(['file']);
     // Validate all input
     $validator = Validator::make($data, ['file' => 'image']);
     // If validation fails;
     if ($validator->fails()) {
         // Redirect back to registration form with errors
         return Response::json(['error' => $this->errorMessages['not_an_image']]);
     }
     if ($request->hasFile('file')) {
         $file_location = MediaController::uploadImage($request->file('file'), $data['file']->getClientOriginalName() . time(), $directory = "event-photos/" . hexdec(Hash::make($eventID)));
         $media = Media::create(['file_location' => $file_location, 'event_id' => $eventID, 'name' => $data['file']->getClientOriginalName(), 'user_id' => Auth::user()->id]);
         return Response::json(['file_location' => $file_location, 'media_id' => $media->id]);
     }
     return Response::json(['error' => $this->errorMessages['no_file']]);
 }
 public function update($id, Request $request)
 {
     // Ensure the user is logged in as an admin
     if (!Auth::check() || !Auth::user()->is_admin) {
         return response(view('errors.403', ['error' => $this->errorMessages['incorrect_permissions']]), 403);
     }
     // Try to retrieve the model for updating from the database
     try {
         $event = Event::findOrFail($id);
     } catch (ModelNotFoundException $e) {
         return Redirect::back()->withErrors(['message' => $this->errorMessages['event_not_found']]);
     }
     // Get the required fields from the form
     $data = $request->only(['title', 'tagline', 'description', 'partner_id', 'featured_image', 'start_date', 'end_date', 'start_time', 'end_time', 'location_id', 'price']);
     // Validate the data
     $validator = Validator::make($data, ['title' => 'required', 'tagline' => 'required', 'description' => 'required', 'start_date' => 'required', 'end_date' => 'required', 'start_time' => 'required', 'end_time' => 'required', 'location_id' => 'required', 'price' => 'required|numeric|min:0', 'featured_image' => 'image|sometimes']);
     // If validation fails;
     if ($validator->fails()) {
         // Redirect back to registration form with errors
         return Redirect::back()->withErrors($validator)->withInput();
     }
     // Format the start and end datetime properly
     // for storage in the database
     $start_datetime = $data['start_date'] . ' ' . $data['start_time'] . ':' . '00';
     $end_datetime = $data['end_date'] . ' ' . $data['end_time'] . ':' . '00';
     $newData = array("title" => $data["title"], "tagline" => $data["tagline"], "description" => $data["description"], "start_datetime" => $start_datetime, "end_datetime" => $end_datetime, "location_id" => $data["location_id"], "price" => $data["price"]);
     // Only if the user updated the photo;
     if ($request->hasFile('featured_image')) {
         // Upload the image
         $data['featured_image'] = MediaController::uploadImage($request->file('featured_image'), time(), $directory = "event_photos", $bestFit = true, $fitDimensions = [1920, 1080]);
         // Store the new image
         $event->featured_image = $data['featured_image'];
     } else {
         unset($data['featured_image']);
     }
     // Store the values from the form in event
     $event->update($newData);
     // Detach all partners and attach new partners to event
     $event->partners()->detach();
     $distance;
     if (isset($data['partner_id']) && $data['partner_id'] != '') {
         foreach ($data['partner_id'] as $partner_id) {
             $distance = LocationController::getMapsMatrixDistance(Partner::find($partner_id)->location, $event->location);
             $event->partners()->attach($partner_id, ['distance' => $distance]);
         }
     }
     // Save the event to the database
     $event->save();
     // Return to the events index
     return Redirect::route('events.show', $event->id);
 }