Attendize/app/Http/Controllers/EventViewController.php

140 lines
4.0 KiB
PHP
Raw Normal View History

2016-03-05 00:18:10 +00:00
<?php
namespace App\Http\Controllers;
2016-02-29 15:59:36 +00:00
use App\Attendize\Utils;
2016-02-29 15:59:36 +00:00
use App\Models\Affiliate;
2016-03-05 00:18:10 +00:00
use App\Models\Event;
2016-02-29 15:59:36 +00:00
use App\Models\EventStats;
2016-03-05 00:18:10 +00:00
use Auth;
use Cookie;
use Illuminate\Http\Request;
2016-03-05 00:18:10 +00:00
use Mail;
use Validator;
2016-02-29 15:59:36 +00:00
class EventViewController extends Controller
{
/**
* Show the homepage for an event
*
* @param Request $request
* @param $event_id
* @param string $slug
* @param bool $preview
* @return mixed
*/
public function showEventHome(Request $request, $event_id, $slug = '', $preview = false)
2016-02-29 15:59:36 +00:00
{
$event = Event::findOrFail($event_id);
if (!Utils::userOwns($event) && !$event->is_live) {
return view('Public.ViewEvent.EventNotLivePage');
2016-02-29 15:59:36 +00:00
}
$data = [
2016-03-05 00:18:10 +00:00
'event' => $event,
'tickets' => $event->tickets()->where('is_hidden', 0)->orderBy('sort_order', 'asc')->get(),
2016-03-05 00:18:10 +00:00
'is_embedded' => 0,
2016-02-29 15:59:36 +00:00
];
/*
* Don't record stats if we're previewing the event page from the backend or if we own the event.
*/
if (!$preview && !Auth::check()) {
2016-03-05 00:18:10 +00:00
$event_stats = new EventStats();
2016-02-29 15:59:36 +00:00
$event_stats->updateViewCount($event_id);
}
/*
* See if there is an affiliate referral in the URL
*/
if ($affiliate_ref = $request->get('ref')) {
2016-02-29 15:59:36 +00:00
$affiliate_ref = preg_replace("/\W|_/", '', $affiliate_ref);
if ($affiliate_ref) {
$affiliate = Affiliate::firstOrNew([
'name' => $request->get('ref'),
2016-03-05 00:18:10 +00:00
'event_id' => $event_id,
2016-02-29 15:59:36 +00:00
'account_id' => $event->account_id,
]);
++$affiliate->visits;
$affiliate->save();
2016-09-06 20:39:27 +00:00
Cookie::queue('affiliate_' . $event_id, $affiliate_ref, 60 * 24 * 60);
2016-02-29 15:59:36 +00:00
}
}
return view('Public.ViewEvent.EventPage', $data);
2016-02-29 15:59:36 +00:00
}
/**
* Show preview of event homepage / used for backend previewing
*
* @param $event_id
* @return mixed
*/
2016-02-29 15:59:36 +00:00
public function showEventHomePreview($event_id)
{
2016-03-05 00:18:10 +00:00
return showEventHome($event_id, true);
2016-02-29 15:59:36 +00:00
}
/**
* Sends a message to the organiser
*
* @param Request $request
* @param $event_id
* @return mixed
*/
public function postContactOrganiser(Request $request, $event_id)
2016-02-29 15:59:36 +00:00
{
$rules = [
2016-03-05 00:18:10 +00:00
'name' => 'required',
'email' => ['required', 'email'],
'message' => ['required'],
2016-02-29 15:59:36 +00:00
];
$validator = Validator::make($request->all(), $rules);
2016-02-29 15:59:36 +00:00
if ($validator->fails()) {
return response()->json([
2016-03-05 00:18:10 +00:00
'status' => 'error',
'messages' => $validator->messages()->toArray(),
]);
2016-02-29 15:59:36 +00:00
}
$event = Event::findOrFail($event_id);
$data = [
'sender_name' => $request->get('name'),
'sender_email' => $request->get('email'),
'message_content' => strip_tags($request->get('message')),
2016-03-05 00:18:10 +00:00
'event' => $event,
2016-02-29 15:59:36 +00:00
];
2016-11-15 13:26:37 +00:00
Mail::send('Emails.messageReceived', $data, function ($message) use ($event, $data) {
2016-02-29 15:59:36 +00:00
$message->to($event->organiser->email, $event->organiser->name)
->from(config('attendize.outgoing_email_noreply'), $data['sender_name'])
2016-02-29 15:59:36 +00:00
->replyTo($data['sender_email'], $data['sender_name'])
2016-09-06 20:39:27 +00:00
->subject('Message Regarding: ' . $event->title);
2016-02-29 15:59:36 +00:00
});
return response()->json([
2016-03-05 00:18:10 +00:00
'status' => 'success',
'message' => 'Message Successfully Sent',
]);
2016-02-29 15:59:36 +00:00
}
public function showCalendarIcs(Request $request, $event_id)
{
$event = Event::findOrFail($event_id);
$icsContent = $event->getIcsForEvent();
return response()->make($icsContent, 200, [
'Content-Type' => 'application/octet-stream',
'Content-Disposition' => 'attachment; filename="event.ics'
]);
}
2016-02-29 15:59:36 +00:00
}