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;
|
2020-02-07 14:57:12 +00:00
|
|
|
use Illuminate\Support\Facades\Config;
|
2019-09-28 07:05:26 +00:00
|
|
|
use Illuminate\Support\Facades\DB;
|
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;
|
2018-12-15 11:45:08 +00:00
|
|
|
use \Backpack\CRUD\CrudTrait;
|
2018-09-18 09:43:40 +00:00
|
|
|
protected $dates = ['start_date', 'end_date', 'on_sale_date'];
|
|
|
|
|
|
2016-03-14 16:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* The validation rules.
|
|
|
|
|
*
|
2018-10-04 03:42:46 +00:00
|
|
|
* @return array $rules
|
|
|
|
|
*/
|
|
|
|
|
public function rules()
|
|
|
|
|
{
|
|
|
|
|
$format = config('attendize.default_datetime_format');
|
|
|
|
|
return [
|
2020-02-08 10:53:00 +00:00
|
|
|
'title_ru' => 'required',
|
|
|
|
|
'description_ru' => 'required',
|
2019-11-02 10:32:23 +00:00
|
|
|
'venue_id' => 'required',
|
|
|
|
|
// 'location_venue_name' => 'required_without:venue_name_full',
|
|
|
|
|
// 'venue_name_full' => 'required_without:location_venue_name',
|
2018-10-04 03:42:46 +00:00
|
|
|
'start_date' => 'required|date_format:"'.$format.'"',
|
|
|
|
|
'end_date' => 'required|date_format:"'.$format.'"',
|
|
|
|
|
'organiser_name' => 'required_without:organiser_id',
|
|
|
|
|
'event_image' => 'mimes:jpeg,jpg,png|max:3000',
|
|
|
|
|
];
|
|
|
|
|
}
|
2016-03-14 16:37:38 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The validation error messages.
|
|
|
|
|
*
|
|
|
|
|
* @var array $messages
|
|
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
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)',
|
2018-09-18 09:43:40 +00:00
|
|
|
'event_image.max' => 'Please 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-14 16:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* The questions associated with the event.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
|
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
public function questions()
|
|
|
|
|
{
|
2016-10-07 22:48:54 +00:00
|
|
|
return $this->belongsToMany(\App\Models\Question::class, 'event_question');
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-07 13:33:07 +00:00
|
|
|
/**
|
|
|
|
|
* The questions associated with the event.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
|
|
|
|
*/
|
2016-10-07 10:46:35 +00:00
|
|
|
public function questions_with_trashed()
|
2016-04-07 13:33:07 +00:00
|
|
|
{
|
2016-10-07 22:48:54 +00:00
|
|
|
return $this->belongsToMany(\App\Models\Question::class, 'event_question')->withTrashed();
|
2016-04-07 13:33:07 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-14 16:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* The attendees associated with the event.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
public function attendees()
|
|
|
|
|
{
|
2020-05-13 12:09:57 +00:00
|
|
|
return $this->hasMany(\App\Models\Attendee::class)
|
2020-05-14 11:37:10 +00:00
|
|
|
->where('attendees.is_cancelled',false)
|
|
|
|
|
->where('attendees.is_refunded',false);
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
2016-03-05 00:18:10 +00:00
|
|
|
|
2016-03-14 16:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* The images associated with the event.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
public function images()
|
|
|
|
|
{
|
2016-10-07 22:48:54 +00:00
|
|
|
return $this->hasMany(\App\Models\EventImage::class);
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
2016-03-05 00:18:10 +00:00
|
|
|
|
2016-03-14 16:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* The messages associated with the event.
|
|
|
|
|
*
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
public function messages()
|
|
|
|
|
{
|
2016-10-07 22:48:54 +00:00
|
|
|
return $this->hasMany(\App\Models\Message::class)->orderBy('created_at', 'DESC');
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-14 16:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* The tickets associated with the event.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
public function tickets()
|
|
|
|
|
{
|
2016-10-07 22:51:04 +00:00
|
|
|
return $this->hasMany(\App\Models\Ticket::class);
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
2016-03-05 00:18:10 +00:00
|
|
|
|
2019-09-28 07:05:26 +00:00
|
|
|
public function starting_ticket(){
|
|
|
|
|
return $this->tickets()
|
|
|
|
|
->select('id','ticket_date','event_id','price')
|
2019-11-05 12:28:51 +00:00
|
|
|
->where('ticket_date','>=',Carbon::now(\config('app.timezone')))
|
2019-09-28 07:05:26 +00:00
|
|
|
->orderBy('ticket_date')
|
|
|
|
|
->orderBy('price')
|
|
|
|
|
->limit(2); // limit 1 returns null ???
|
|
|
|
|
}
|
2016-03-14 16:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* The stats associated with the event.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
public function stats()
|
|
|
|
|
{
|
2016-10-07 22:48:54 +00:00
|
|
|
return $this->hasMany(\App\Models\EventStats::class);
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
2016-03-05 00:18:10 +00:00
|
|
|
|
2019-09-28 07:05:26 +00:00
|
|
|
public function views(){
|
|
|
|
|
return $this->stats()->sum('views');
|
|
|
|
|
}
|
2016-03-14 16:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* The affiliates associated with the event.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
public function affiliates()
|
|
|
|
|
{
|
2016-10-07 22:48:54 +00:00
|
|
|
return $this->hasMany(\App\Models\Affiliate::class);
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-14 16:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* The orders associated with the event.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
public function orders()
|
|
|
|
|
{
|
2016-10-07 22:48:54 +00:00
|
|
|
return $this->hasMany(\App\Models\Order::class);
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
2019-08-28 06:34:37 +00:00
|
|
|
/**
|
|
|
|
|
* The access codes associated with the event.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
|
*/
|
|
|
|
|
public function access_codes()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(\App\Models\EventAccessCodes::class, 'event_id', 'id');
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-14 16:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* The account associated with the event.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
public function account()
|
|
|
|
|
{
|
2016-10-07 22:48:54 +00:00
|
|
|
return $this->belongsTo(\App\Models\Account::class);
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-14 16:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* The currency associated with the event.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
public function currency()
|
|
|
|
|
{
|
2016-10-07 22:48:54 +00:00
|
|
|
return $this->belongsTo(\App\Models\Currency::class);
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-14 16:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* The organizer associated with the event.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
public function organiser()
|
|
|
|
|
{
|
2016-10-07 22:48:54 +00:00
|
|
|
return $this->belongsTo(\App\Models\Organiser::class);
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
2016-03-05 00:18:10 +00:00
|
|
|
|
2019-08-24 06:55:14 +00:00
|
|
|
/**
|
|
|
|
|
* Tags associated with the event
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
|
*/
|
|
|
|
|
public function tags(){
|
|
|
|
|
return $this->belongsToMany(\App\Models\Tag::class);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-02 10:32:23 +00:00
|
|
|
public function venue(){
|
|
|
|
|
return $this->belongsTo(Venue::class);
|
|
|
|
|
}
|
2019-08-24 06:55:14 +00:00
|
|
|
/**
|
|
|
|
|
* Category associated with the event
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
|
*/
|
|
|
|
|
public function mainCategory(){
|
|
|
|
|
return $this->belongsTo(Category::class,'category_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sub category associated with the event
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
|
*/
|
|
|
|
|
public function subCategory(){
|
|
|
|
|
return $this->belongsTo(Category::class,'sub_category_id');
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-07 14:57:12 +00:00
|
|
|
public function getTitleAttribute(){
|
|
|
|
|
|
|
|
|
|
return $this->{'title_'.Config::get('app.locale')};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getDescriptionAttribute(){
|
|
|
|
|
|
2020-03-28 15:17:30 +00:00
|
|
|
return $this->{'description_'.Config::get('app.locale')} ?? 'No translation';
|
2020-02-07 14:57:12 +00:00
|
|
|
}
|
2016-03-14 16:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* Get the embed url.
|
|
|
|
|
*
|
|
|
|
|
* @return mixed
|
2016-02-29 15:59:36 +00:00
|
|
|
*/
|
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-14 16:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* Get the fixed fee.
|
|
|
|
|
*
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
public function getFixedFeeAttribute()
|
|
|
|
|
{
|
2020-02-26 11:15:02 +00:00
|
|
|
return config('settings.booking_fee_fixed') + $this->organiser_fee_fixed;
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
2016-03-05 00:18:10 +00:00
|
|
|
|
2016-03-14 16:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* Get the percentage fee.
|
|
|
|
|
*
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
public function getPercentageFeeAttribute()
|
|
|
|
|
{
|
2020-02-26 11:15:02 +00:00
|
|
|
return config('settings.booking_fee_percentage') + $this->organiser_fee_percentage;
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
2016-03-05 00:18:10 +00:00
|
|
|
|
2018-09-18 09:43:40 +00:00
|
|
|
/**
|
|
|
|
|
* Parse start_date to a Carbon instance
|
|
|
|
|
*
|
|
|
|
|
* @param string $date DateTime
|
|
|
|
|
*/
|
|
|
|
|
public function setStartDateAttribute($date)
|
|
|
|
|
{
|
2018-10-04 03:42:46 +00:00
|
|
|
$format = config('attendize.default_datetime_format');
|
|
|
|
|
$this->attributes['start_date'] = Carbon::createFromFormat($format, $date);
|
2018-09-18 09:43:40 +00:00
|
|
|
}
|
|
|
|
|
|
2018-10-04 03:42:11 +00:00
|
|
|
/**
|
|
|
|
|
* Format start date from user preferences
|
|
|
|
|
* @return String Formatted date
|
|
|
|
|
*/
|
|
|
|
|
public function startDateFormatted()
|
|
|
|
|
{
|
|
|
|
|
return $this->start_date->format(config('attendize.default_datetime_format'));
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-18 09:43:40 +00:00
|
|
|
/**
|
|
|
|
|
* Parse end_date to a Carbon instance
|
|
|
|
|
*
|
|
|
|
|
* @param string $date DateTime
|
|
|
|
|
*/
|
|
|
|
|
public function setEndDateAttribute($date)
|
|
|
|
|
{
|
2018-10-04 03:42:46 +00:00
|
|
|
$format = config('attendize.default_datetime_format');
|
|
|
|
|
$this->attributes['end_date'] = Carbon::createFromFormat($format, $date);
|
2018-09-18 09:43:40 +00:00
|
|
|
}
|
|
|
|
|
|
2018-10-04 03:42:11 +00:00
|
|
|
/**
|
|
|
|
|
* Format end date from user preferences
|
|
|
|
|
* @return String Formatted date
|
|
|
|
|
*/
|
|
|
|
|
public function endDateFormatted()
|
|
|
|
|
{
|
|
|
|
|
return $this->end_date->format(config('attendize.default_datetime_format'));
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-14 16:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* Indicates whether the event is currently happening.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
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
|
|
|
|
2016-03-14 16:37:38 +00:00
|
|
|
/**
|
2016-05-12 10:43:04 +00:00
|
|
|
* Get the currency symbol.
|
2016-03-14 16:37:38 +00:00
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Support\Collection
|
|
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
public function getCurrencySymbolAttribute()
|
|
|
|
|
{
|
2019-09-23 10:35:40 +00:00
|
|
|
return $this->currency->symbol_left ?? '';
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
2016-03-05 00:18:10 +00:00
|
|
|
|
2016-03-14 16:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* Get the currency code.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Support\Collection
|
|
|
|
|
*/
|
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
|
|
|
|
2016-08-11 12:19:59 +00:00
|
|
|
/**
|
|
|
|
|
* Return an array of attendees and answers they gave to questions at checkout
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function getSurveyAnswersAttribute()
|
|
|
|
|
{
|
|
|
|
|
$rows[] = array_merge([
|
|
|
|
|
'Order Ref',
|
|
|
|
|
'Attendee Name',
|
|
|
|
|
'Attendee Email',
|
|
|
|
|
'Attendee Ticket'
|
2018-08-15 11:26:10 +00:00
|
|
|
], $this->questions->pluck('title')->toArray());
|
2016-08-11 12:19:59 +00:00
|
|
|
|
|
|
|
|
$attendees = $this->attendees()->has('answers')->get();
|
|
|
|
|
|
|
|
|
|
foreach ($attendees as $attendee) {
|
|
|
|
|
$answers = [];
|
|
|
|
|
|
|
|
|
|
foreach ($this->questions as $question) {
|
2018-09-02 16:01:53 +00:00
|
|
|
if (in_array($question->id, $attendee->answers->pluck('question_id')->toArray())) {
|
2016-08-11 12:19:59 +00:00
|
|
|
$answers[] = $attendee->answers->where('question_id', $question->id)->first()->answer_text;
|
|
|
|
|
} else {
|
|
|
|
|
$answers[] = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$rows[] = array_merge([
|
|
|
|
|
$attendee->order->order_reference,
|
|
|
|
|
$attendee->full_name,
|
|
|
|
|
$attendee->email,
|
|
|
|
|
$attendee->ticket->title
|
|
|
|
|
], $answers);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $rows;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-14 16:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* Get the embed html code.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
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-->
|
2016-08-11 12:19:59 +00:00
|
|
|
<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>
|
2016-02-29 15:59:36 +00:00
|
|
|
<!--/Attendize.com Ticketing Embed Code-->";
|
|
|
|
|
}
|
2016-03-05 00:18:10 +00:00
|
|
|
|
2016-03-14 16:37:38 +00:00
|
|
|
/**
|
2016-02-29 15:59:36 +00:00
|
|
|
* Get a usable address for embedding Google Maps
|
2016-03-14 16:37:38 +00:00
|
|
|
*
|
2016-02-29 15:59:36 +00:00
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
public function getMapAddressAttribute()
|
|
|
|
|
{
|
2016-08-11 12:19:59 +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
|
|
|
|
2016-03-14 16:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* Get the big image url.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
public function getBgImageUrlAttribute()
|
|
|
|
|
{
|
2016-08-11 12:19:59 +00:00
|
|
|
return URL::to('/') . '/' . $this->bg_image_path;
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
2016-03-05 00:18:10 +00:00
|
|
|
|
2016-03-14 16:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* Get the url of the event.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
public function getEventUrlAttribute()
|
|
|
|
|
{
|
(localization) Several big changes:
1) Added localization components to the package. They allow usage of localized routes, like http://attendize.site/en/login
2) Added English and Polish localization files. They are ugly, repetitive, but mostly true to the original and relevant. It required rewriting several phrases, and certainly required editing most of the views and controllers.
3) Edited routes to accomodate point 1
4) Rewritten several rules regarding dates. In most cases using English notation (with English names for months) is bad in all other languages. I used environment wide date format that is used.
5) Updated installer. Haven't tested it yet, but should work. Rewrites .env.example file instead of creating it from scratch (by concatenating strings).
There are some minor changes that were simple fixes or other funky requirements from my employer that kinda make sense:
1) QR code reader wasn't working in firefox, fixed it. Works in chrome/firefox on mobile on https sites.
2) Added subscript text in some instances: below ticket registration, below ticket. It is kinda dumb, but in most cases is necessary to receive less complaints from clients.
3) Fixed geocoding api by adding api key in env file. At some point in 2016-2017 it was required by google to use API key from developer console and this requirement wasn't challenged in the code.
4) Ticket has been displaying either flyer or site logo on the side. Now displays both (which may affect 1d barcode - it might need some fixin). Regarding the same issue - description of an event contained the flyer image on the side, it was removed, cause it didn't fit in here.
5) Ticket style was updated, because of the above and because it didn't fit longer character strings. Now it's slightly uglier, but works in all cases.
and other.
There are also some inconveniences, like:
1) Unfinished translations. It was impossible for me to create translations based on strings located inside of a database, which I ignored (I think it's only at one place - surveys).
2) Ugly translation files. At some point I thought it is going to be easier to locate when I try translating vased by file name. Later I divided it by topics, and then I segmented it even more. It might require some serious clean-up.
3) Redundancy. In some cases there are several definitions for the same phrase in my localization files. I used it mostly to protect myself from different contexts for the phrase usage in different languages.
4) File division. There are several files that are placed in dedicated language directory (in /view/, like /view/pl/ or /view/en/). These files don't use language phrases, but they are translated as a whole. Mostly because using language phrases would make those view files unreadable.
5) Localzation helper marks some phrases as obsolete (in file "basic"), because they are used in app/Helpers folder (where this plugin doesn't reach)
2018-05-03 21:41:22 +00:00
|
|
|
return route("showEventPage", ["event_id"=>$this->id, "event_slug"=>Str::slug($this->title)]);
|
|
|
|
|
//return URL::to('/') . '/e/' . $this->id . '/' . Str::slug($this->title);
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-14 16:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* Get the sales and fees volume.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Support\Collection|mixed|static
|
|
|
|
|
*/
|
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-08-11 12:19:59 +00:00
|
|
|
|
2019-08-28 06:34:37 +00:00
|
|
|
public function getViewsCountAttribute(){
|
|
|
|
|
return $this->stats()->sum('views');
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-30 06:50:33 +00:00
|
|
|
public function getStartingTicketPriceAttribute(){
|
|
|
|
|
$ticket = $this->tickets()
|
|
|
|
|
->where('is_hidden',0)
|
|
|
|
|
->orderBy('price','asc')
|
|
|
|
|
->first();
|
|
|
|
|
if(!empty($ticket))
|
|
|
|
|
return $ticket->total_price;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-14 16:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* The attributes that should be mutated to dates.
|
|
|
|
|
*
|
2016-09-06 19:33:19 +00:00
|
|
|
* @return array $dates
|
2016-03-14 16:37:38 +00:00
|
|
|
*/
|
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
|
|
|
}
|
2016-09-11 15:49:27 +00:00
|
|
|
|
|
|
|
|
public function getIcsForEvent()
|
|
|
|
|
{
|
|
|
|
|
$siteUrl = URL::to('/');
|
|
|
|
|
$eventUrl = $this->getEventUrlAttribute();
|
|
|
|
|
|
2018-09-18 09:43:40 +00:00
|
|
|
$start_date = $this->start_date;
|
|
|
|
|
$end_date = $this->end_date;
|
2016-09-11 15:49:27 +00:00
|
|
|
$timestamp = new Carbon();
|
|
|
|
|
|
|
|
|
|
$icsTemplate = <<<ICSTemplate
|
|
|
|
|
BEGIN:VCALENDAR
|
|
|
|
|
VERSION:2.0
|
|
|
|
|
PRODID:{$siteUrl}
|
|
|
|
|
BEGIN:VEVENT
|
|
|
|
|
UID:{$eventUrl}
|
|
|
|
|
DTSTAMP:{$timestamp->format('Ymd\THis\Z')}
|
|
|
|
|
DTSTART:{$start_date->format('Ymd\THis\Z')}
|
|
|
|
|
DTEND:{$end_date->format('Ymd\THis\Z')}
|
|
|
|
|
SUMMARY:$this->title
|
|
|
|
|
LOCATION:{$this->venue_name}
|
|
|
|
|
DESCRIPTION:{$this->description}
|
|
|
|
|
END:VEVENT
|
|
|
|
|
END:VCALENDAR
|
|
|
|
|
ICSTemplate;
|
|
|
|
|
|
|
|
|
|
return $icsTemplate;
|
|
|
|
|
}
|
2019-08-28 06:34:37 +00:00
|
|
|
|
2019-09-23 10:35:40 +00:00
|
|
|
public function getSeansCount(){
|
2019-09-23 14:07:27 +00:00
|
|
|
$seans = $this->tickets()->distinct()->orderBy('ticket_date')->count();
|
|
|
|
|
return $seans != 0 ? $seans. ' seansa' : ''; //todo get from translate
|
2019-09-23 10:35:40 +00:00
|
|
|
}
|
2019-08-28 06:34:37 +00:00
|
|
|
/**
|
|
|
|
|
* @param integer $accessCodeId
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function hasAccessCode($accessCodeId)
|
|
|
|
|
{
|
|
|
|
|
return (is_null($this->access_codes()->where('id', $accessCodeId)->first()) === false);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 10:40:03 +00:00
|
|
|
public function scopeOnLive($query, $start_date = null, $end_date = null){
|
2019-10-02 14:08:07 +00:00
|
|
|
//if date is null carbon creates now date instance
|
2020-02-11 08:53:32 +00:00
|
|
|
//todo what if only end date is null??
|
2020-01-09 12:54:13 +00:00
|
|
|
if(!empty($start_date) && !empty($end_date))
|
2020-01-09 12:53:05 +00:00
|
|
|
{
|
2019-11-05 12:28:51 +00:00
|
|
|
$query->where('start_date','<',$end_date)
|
|
|
|
|
->where('end_date','>',$start_date);
|
2020-01-09 12:53:05 +00:00
|
|
|
}
|
2020-02-11 08:53:32 +00:00
|
|
|
else
|
|
|
|
|
$query->where('end_date','>',Carbon::now(config('app.timezone')));
|
2019-10-03 09:18:21 +00:00
|
|
|
|
|
|
|
|
return $query->where('is_live',1)
|
2019-09-28 07:05:26 +00:00
|
|
|
->withCount(['images as image_url' => function($q){
|
|
|
|
|
$q->select(DB::raw("image_path as imgurl"))
|
|
|
|
|
->orderBy('created_at','desc')
|
2020-02-25 13:07:07 +00:00
|
|
|
->take(1);
|
2019-09-28 07:05:26 +00:00
|
|
|
}] );
|
2019-08-28 06:34:37 +00:00
|
|
|
}
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|