Attendize/app/Http/Controllers/EventViewController.php

107 lines
3.1 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\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 Input;
use Mail;
use Response;
use Validator;
use View;
2016-02-29 15:59:36 +00:00
class EventViewController extends Controller
{
2016-03-05 00:18:10 +00:00
public function showEventHome($event_id, $slug = '', $preview = false)
2016-02-29 15:59:36 +00:00
{
$event = Event::findOrFail($event_id);
2016-03-05 00:18:10 +00:00
if (!Auth::check() && !$event->is_live) {
2016-02-29 15:59:36 +00:00
return View::make('Public.ViewEvent.EventNotLivePage');
}
$data = [
2016-03-05 00:18:10 +00:00
'event' => $event,
'tickets' => $event->tickets()->orderBy('created_at', 'desc')->get(),
'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 = \Input::get('ref')) {
$affiliate_ref = preg_replace("/\W|_/", '', $affiliate_ref);
if ($affiliate_ref) {
$affiliate = Affiliate::firstOrNew([
2016-03-05 00:18:10 +00:00
'name' => Input::get('ref'),
'event_id' => $event_id,
2016-02-29 15:59:36 +00:00
'account_id' => $event->account_id,
]);
++$affiliate->visits;
$affiliate->save();
2016-03-05 00:18:10 +00:00
Cookie::queue('affiliate_'.$event_id, $affiliate_ref, 60 * 24 * 60);
2016-02-29 15:59:36 +00:00
}
}
return View::make('Public.ViewEvent.EventPage', $data);
}
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
}
public function postContactOrganiser($event_id)
{
$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(Input::all(), $rules);
if ($validator->fails()) {
2016-03-05 00:18:10 +00:00
return Response::json([
'status' => 'error',
'messages' => $validator->messages()->toArray(),
]);
2016-02-29 15:59:36 +00:00
}
$event = Event::findOrFail($event_id);
$data = [
2016-03-05 00:18:10 +00:00
'sender_name' => Input::get('name'),
'sender_email' => Input::get('email'),
2016-02-29 15:59:36 +00:00
'message_content' => strip_tags(Input::get('message')),
2016-03-05 00:18:10 +00:00
'event' => $event,
2016-02-29 15:59:36 +00:00
];
Mail::send('Emails.messageOrganiser', $data, function ($message) use ($event, $data) {
$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-03-05 00:18:10 +00:00
->subject('Message Regarding: '.$event->title);
2016-02-29 15:59:36 +00:00
});
2016-03-05 00:18:10 +00:00
return Response::json([
'status' => 'success',
'message' => 'Message Successfully Sent',
]);
2016-02-29 15:59:36 +00:00
}
}