Attendize/app/Models/Event.php

165 lines
4.6 KiB
PHP
Raw Normal View History

2016-03-05 00:18:10 +00:00
<?php
namespace App\Models;
2016-02-29 15:59:36 +00:00
use Carbon\Carbon;
use Illuminate\Database\Eloquent\SoftDeletes;
2016-03-05 00:18:10 +00:00
use Str;
use URL;
2016-02-29 15:59:36 +00:00
2016-03-05 00:18:10 +00:00
class Event extends MyBaseModel
{
2016-02-29 15:59:36 +00:00
use SoftDeletes;
2016-03-05 00:18:10 +00:00
protected $rules = [
'title' => ['required'],
'description' => ['required'],
'location_venue_name' => ['required_without:venue_name_full'],
'venue_name_full' => ['required_without:location_venue_name'],
'start_date' => ['required'],
'end_date' => ['required'],
'organiser_name' => ['required_without:organiser_id'],
'event_image' => ['mimes:jpeg,jpg,png', 'max:3000'],
];
protected $messages = [
'title.required' => 'You must at least give a title for your event.',
'organiser_name.required_without' => 'Please create an organiser or select an existing organiser.',
'event_image.mimes' => 'Please ensure you are uploading an image (JPG, PNG, JPEG)',
'event_image.max' => 'Pleae ensure the image is not larger then 3MB',
2016-02-29 15:59:36 +00:00
'location_venue_name.required_without' => 'Please enter a venue for your event',
2016-03-05 00:18:10 +00:00
'venue_name_full.required_without' => 'Please enter a venue for your event',
];
2016-02-29 15:59:36 +00:00
2016-03-05 00:18:10 +00:00
public function questions()
{
return $this->belongsToMany('\App\Models\Question', 'event_question');
2016-02-29 15:59:36 +00:00
}
2016-03-05 00:18:10 +00:00
public function attendees()
{
2016-02-29 15:59:36 +00:00
return $this->hasMany('\App\Models\Attendee');
}
2016-03-05 00:18:10 +00:00
public function images()
{
2016-02-29 15:59:36 +00:00
return $this->hasMany('\App\Models\EventImage');
}
2016-03-05 00:18:10 +00:00
public function messages()
{
2016-02-29 15:59:36 +00:00
return $this->hasMany('\App\Models\Message')->orderBy('created_at', 'DESC');
}
2016-03-05 00:18:10 +00:00
public function tickets()
{
2016-02-29 15:59:36 +00:00
return $this->hasMany('\App\Models\Ticket');
}
2016-03-05 00:18:10 +00:00
public function stats()
{
2016-02-29 15:59:36 +00:00
return $this->hasMany('\App\Models\EventStats');
}
2016-03-05 00:18:10 +00:00
public function affiliates()
{
2016-02-29 15:59:36 +00:00
return $this->hasMany('\App\Models\Affiliate');
}
2016-03-05 00:18:10 +00:00
public function orders()
{
2016-02-29 15:59:36 +00:00
return $this->hasMany('\App\Models\Order');
}
2016-03-05 00:18:10 +00:00
public function account()
{
2016-02-29 15:59:36 +00:00
return $this->belongsTo('\App\Models\Account');
}
2016-03-05 00:18:10 +00:00
public function currency()
{
2016-02-29 15:59:36 +00:00
return $this->belongsTo('\App\Models\Currency');
}
2016-03-05 00:18:10 +00:00
public function organiser()
{
2016-02-29 15:59:36 +00:00
return $this->belongsTo('\App\Models\Organiser');
}
2016-03-05 00:18:10 +00:00
2016-02-29 15:59:36 +00:00
/*
* Getters & Setters
*/
2016-03-05 00:18:10 +00:00
public function getEmbedUrlAttribute()
{
2016-02-29 15:59:36 +00:00
return str_replace(['http:', 'https:'], '', route('showEmbeddedEventPage', ['event' => $this->id]));
}
2016-03-05 00:18:10 +00:00
public function getFixedFeeAttribute()
{
return config('attendize.ticket_booking_fee_fixed') + $this->organiser_fee_fixed;
2016-02-29 15:59:36 +00:00
}
2016-03-05 00:18:10 +00:00
public function getPercentageFeeAttribute()
{
return config('attendize.ticket_booking_fee_percentage') + $this->organiser_fee_percentage;
2016-02-29 15:59:36 +00:00
}
2016-03-05 00:18:10 +00:00
public function getHappeningNowAttribute()
{
2016-02-29 15:59:36 +00:00
return Carbon::now()->between($this->start_date, $this->end_date);
}
2016-03-05 00:18:10 +00:00
public function getCurrencySymbolAttribute()
{
2016-02-29 15:59:36 +00:00
return $this->currency->symbol_left;
}
2016-03-05 00:18:10 +00:00
public function getCurrencyCodeAttribute()
{
2016-02-29 15:59:36 +00:00
return $this->currency->code;
}
2016-03-05 00:18:10 +00:00
public function getEmbedHtmlCodeAttribute()
{
2016-02-29 15:59:36 +00:00
return "<!--Attendize.com Ticketing Embed Code-->
<iframe style='overflow:hidden; min-height: 350px;' frameBorder='0' seamless='seamless' width='100%' height='100%' src='".$this->embed_url."' vspace='0' hspace='0' scrolling='auto' allowtransparency='true'></iframe>
<!--/Attendize.com Ticketing Embed Code-->";
}
2016-03-05 00:18:10 +00:00
2016-02-29 15:59:36 +00:00
/*
* Get a usable address for embedding Google Maps
*/
2016-03-05 00:18:10 +00:00
public function getMapAddressAttribute()
{
2016-02-29 15:59:36 +00:00
$string = $this->venue.','
.$this->location_street_number.','
.$this->location_address_line_1.','
.$this->location_address_line_2.','
.$this->location_state.','
.$this->location_post_code.','
.$this->location_country;
2016-03-05 00:18:10 +00:00
2016-02-29 15:59:36 +00:00
return urlencode($string);
}
2016-03-05 00:18:10 +00:00
public function getBgImageUrlAttribute()
{
2016-02-29 15:59:36 +00:00
return URL::to('/').'/'.$this->bg_image_path;
}
2016-03-05 00:18:10 +00:00
public function getEventUrlAttribute()
{
2016-02-29 15:59:36 +00:00
return URL::to('/').'/e/'.$this->id.'/'.Str::slug($this->title);
}
2016-03-05 00:18:10 +00:00
public function getSalesAndFeesVoulmeAttribute()
{
2016-02-29 15:59:36 +00:00
return $this->sales_volume + $this->organiser_fees_volume;
}
2016-03-05 00:18:10 +00:00
public function getDates()
{
return ['created_at', 'updated_at', 'start_date', 'end_date'];
2016-02-29 15:59:36 +00:00
}
}