Attendize/app/Http/Controllers/EventCustomizeController.php

310 lines
9.9 KiB
PHP
Raw Normal View History

2016-03-05 00:18:10 +00:00
<?php
2016-02-29 15:59:36 +00:00
2016-03-05 00:18:10 +00:00
namespace App\Http\Controllers;
2016-02-29 15:59:36 +00:00
2016-03-05 00:18:10 +00:00
use App\Models\Event;
use File;
2016-09-06 20:39:27 +00:00
use Illuminate\Http\Request;
2016-03-05 00:18:10 +00:00
use Image;
use Validator;
class EventCustomizeController extends MyBaseController
{
/**
* Show the event customize page
*
* @param string $event_id
* @param string $tab
* @return \Illuminate\View\View
*/
2016-03-05 00:18:10 +00:00
public function showCustomize($event_id = '', $tab = '')
{
2016-02-29 15:59:36 +00:00
$data = $this->getEventViewData($event_id, [
'available_bg_images' => $this->getAvailableBackgroundImages(),
2016-02-29 15:59:36 +00:00
'available_bg_images_thumbs' => $this->getAvailableBackgroundImagesThumbs(),
'tab' => $tab,
2016-02-29 15:59:36 +00:00
]);
2016-03-05 00:18:10 +00:00
return view('ManageEvent.Customize', $data);
2016-02-29 15:59:36 +00:00
}
/**
* get an array of available event background images
*
* @return array
*/
2016-03-05 00:18:10 +00:00
public function getAvailableBackgroundImages()
{
2016-02-29 15:59:36 +00:00
$images = [];
$files = File::files(public_path() . '/' . config('attendize.event_bg_images'));
2016-02-29 15:59:36 +00:00
foreach ($files as $image) {
$images[] = str_replace(public_path(), '', $image);
}
return $images;
}
/**
* Get an array of event bg image thumbnails
*
* @return array
*/
2016-03-05 00:18:10 +00:00
public function getAvailableBackgroundImagesThumbs()
{
2016-02-29 15:59:36 +00:00
$images = [];
$files = File::files(public_path() . '/' . config('attendize.event_bg_images') . '/thumbs');
2016-02-29 15:59:36 +00:00
foreach ($files as $image) {
$images[] = str_replace(public_path(), '', $image);
}
return $images;
}
2016-03-05 00:18:10 +00:00
/**
* Edit social settings of an event
*
* @param Request $request
* @param $event_id
* @return \Illuminate\Http\JsonResponse
*/
public function postEditEventSocial(Request $request, $event_id)
2016-03-05 00:18:10 +00:00
{
2016-02-29 15:59:36 +00:00
$event = Event::scope()->findOrFail($event_id);
$rules = [
2016-06-15 02:31:24 +00:00
'social_share_text' => ['max:3000'],
'social_show_facebook' => ['boolean'],
'social_show_twitter' => ['boolean'],
'social_show_linkedin' => ['boolean'],
'social_show_email' => ['boolean'],
2016-03-05 00:18:10 +00:00
'social_show_googleplus' => ['boolean'],
2016-02-29 15:59:36 +00:00
];
2016-02-29 15:59:36 +00:00
$messages = [
'social_share_text.max' => 'Please keep the text under 3000 characters.',
2016-02-29 15:59:36 +00:00
];
$validator = Validator::make($request->all(), $rules, $messages);
2016-02-29 15:59:36 +00:00
if ($validator->fails()) {
return response()->json([
'status' => 'error',
'messages' => $validator->messages()->toArray(),
2016-03-05 00:18:10 +00:00
]);
2016-02-29 15:59:36 +00:00
}
$event->social_share_text = $request->get('social_share_text');
$event->social_show_facebook = $request->get('social_show_facebook');
$event->social_show_linkedin = $request->get('social_show_linkedin');
$event->social_show_twitter = $request->get('social_show_twitter');
$event->social_show_email = $request->get('social_show_email');
$event->social_show_googleplus = $request->get('social_show_googleplus');
$event->social_show_whatsapp = $request->get('social_show_whatsapp');
2016-02-29 15:59:36 +00:00
$event->save();
return response()->json([
'status' => 'success',
'message' => 'Social Settings Successfully Updated',
]);
}
/**
* Update ticket details
*
* @param Request $request
* @param $event_id
* @return mixed
*/
public function postEditEventTicketDesign(Request $request, $event_id)
{
$event = Event::scope()->findOrFail($event_id);
$rules = [
2016-06-15 02:31:24 +00:00
'ticket_border_color' => ['required'],
'ticket_bg_color' => ['required'],
'ticket_text_color' => ['required'],
'ticket_sub_text_color' => ['required'],
'is_1d_barcode_enabled' => ['required'],
];
$messages = [
'ticket_bg_color.required' => 'Please enter a background color.',
];
$validator = Validator::make($request->all(), $rules, $messages);
if ($validator->fails()) {
return response()->json([
'status' => 'error',
'messages' => $validator->messages()->toArray(),
]);
}
$event->ticket_border_color = $request->get('ticket_border_color');
$event->ticket_bg_color = $request->get('ticket_bg_color');
$event->ticket_text_color = $request->get('ticket_text_color');
$event->ticket_sub_text_color = $request->get('ticket_sub_text_color');
$event->is_1d_barcode_enabled = $request->get('is_1d_barcode_enabled');
$event->save();
return response()->json([
'status' => 'success',
'message' => 'Ticket Settings Updated',
2016-02-29 15:59:36 +00:00
]);
}
2016-03-05 00:18:10 +00:00
/**
* Edit fees of an event
*
* @param Request $request
* @param $event_id
* @return \Illuminate\Http\JsonResponse
*/
public function postEditEventFees(Request $request, $event_id)
2016-03-05 00:18:10 +00:00
{
2016-02-29 15:59:36 +00:00
$event = Event::scope()->findOrFail($event_id);
$rules = [
'organiser_fee_percentage' => ['numeric', 'between:0,100'],
2016-06-15 02:31:24 +00:00
'organiser_fee_fixed' => ['numeric', 'between:0,100'],
2016-02-29 15:59:36 +00:00
];
$messages = [
'organiser_fee_percentage.numeric' => 'Please enter a value between 0 and 100',
2016-06-15 02:31:24 +00:00
'organiser_fee_fixed.numeric' => 'Please check the format. It should be in the format 0.00.',
'organiser_fee_fixed.between' => 'Please enter a value between 0 and 100.',
2016-02-29 15:59:36 +00:00
];
$validator = Validator::make($request->all(), $rules, $messages);
2016-02-29 15:59:36 +00:00
if ($validator->fails()) {
return response()->json([
'status' => 'error',
'messages' => $validator->messages()->toArray(),
2016-03-05 00:18:10 +00:00
]);
2016-02-29 15:59:36 +00:00
}
$event->organiser_fee_percentage = $request->get('organiser_fee_percentage');
$event->organiser_fee_fixed = $request->get('organiser_fee_fixed');
2016-02-29 15:59:36 +00:00
$event->save();
return response()->json([
'status' => 'success',
'message' => 'Order Page Successfully Updated',
2016-02-29 15:59:36 +00:00
]);
}
/**
* Edit the event order page settings
*
* @param Request $request
* @param $event_id
* @return \Illuminate\Http\JsonResponse
*/
public function postEditEventOrderPage(Request $request, $event_id)
2016-03-05 00:18:10 +00:00
{
2016-02-29 15:59:36 +00:00
$event = Event::scope()->findOrFail($event_id);
// Just plain text so no validation needed (hopefully)
$rules = [];
$messages = [];
$validator = Validator::make($request->all(), $rules, $messages);
2016-02-29 15:59:36 +00:00
if ($validator->fails()) {
return response()->json([
'status' => 'error',
'messages' => $validator->messages()->toArray(),
2016-03-05 00:18:10 +00:00
]);
2016-02-29 15:59:36 +00:00
}
$event->pre_order_display_message = trim($request->get('pre_order_display_message'));
$event->post_order_display_message = trim($request->get('post_order_display_message'));
$event->offline_payment_instructions = trim($request->get('offline_payment_instructions'));
2016-09-06 20:39:27 +00:00
$event->enable_offline_payments = (int)$request->get('enable_offline_payments');
2016-02-29 15:59:36 +00:00
$event->save();
return response()->json([
'status' => 'success',
'message' => 'Order Page Successfully Updated',
2016-02-29 15:59:36 +00:00
]);
}
/**
* Edit event page design/colors etc.
*
* @param Request $request
* @param $event_id
* @return \Illuminate\Http\JsonResponse
*/
public function postEditEventDesign(Request $request, $event_id)
2016-03-05 00:18:10 +00:00
{
2016-02-29 15:59:36 +00:00
$event = Event::scope()->findOrFail($event_id);
$rules = [
2016-03-05 00:18:10 +00:00
'bg_image_path' => ['mimes:jpeg,jpg,png', 'max:4000'],
2016-02-29 15:59:36 +00:00
];
$messages = [
'bg_image_path.mimes' => 'Please ensure you are uploading an image (JPG, PNG, JPEG)',
2016-06-15 02:31:24 +00:00
'bg_image_path.max' => 'Please ensure the image is not larger than 2.5MB',
2016-02-29 15:59:36 +00:00
];
$validator = Validator::make($request->all(), $rules, $messages);
2016-02-29 15:59:36 +00:00
if ($validator->fails()) {
return response()->json([
'status' => 'error',
'messages' => $validator->messages()->toArray(),
2016-03-05 00:18:10 +00:00
]);
2016-02-29 15:59:36 +00:00
}
if ($request->get('bg_image_path_custom') && $request->get('bg_type') == 'image') {
$event->bg_image_path = $request->get('bg_image_path_custom');
2016-02-29 15:59:36 +00:00
$event->bg_type = 'image';
}
if ($request->get('bg_color') && $request->get('bg_type') == 'color') {
$event->bg_color = $request->get('bg_color');
2016-02-29 15:59:36 +00:00
$event->bg_type = 'color';
}
/*
* Not in use for now.
*/
if ($request->hasFile('bg_image_path') && $request->get('bg_type') == 'custom_image') {
$path = public_path() . '/' . config('attendize.event_images_path');
$filename = 'event_bg-' . md5($event->id) . '.' . strtolower($request->file('bg_image_path')->getClientOriginalExtension());
2016-02-29 15:59:36 +00:00
$file_full_path = $path . '/' . $filename;
2016-02-29 15:59:36 +00:00
$request->file('bg_image_path')->move($path, $filename);
2016-02-29 15:59:36 +00:00
$img = Image::make($file_full_path);
$img->resize(1400, null, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
$img->save($file_full_path, 75);
$event->bg_image_path = config('attendize.event_images_path') . '/' . $filename;
2016-02-29 15:59:36 +00:00
$event->bg_type = 'custom_image';
\Storage::put(config('attendize.event_images_path') . '/' . $filename, file_get_contents($file_full_path));
2016-02-29 15:59:36 +00:00
}
$event->save();
return response()->json([
'status' => 'success',
'message' => 'Event Page Successfully Updated',
'runThis' => 'document.getElementById(\'previewIframe\').contentWindow.location.reload(true);',
2016-02-29 15:59:36 +00:00
]);
}
}