Attendize/app/Models/Attendee.php

121 lines
2.4 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 Illuminate\Database\Eloquent\SoftDeletes;
/*
Attendize.com - Event Management & Ticketing
*/
/**
2016-03-05 00:18:10 +00:00
* Description of Attendees.
2016-02-29 15:59:36 +00:00
*
* @author Dave
*/
2016-03-05 00:18:10 +00:00
class Attendee extends MyBaseModel
{
2016-03-14 16:37:38 +00:00
use SoftDeletes;
2016-03-14 16:37:38 +00:00
/**
* The attributes that are mass assignable.
*
* @var array $fillable
*/
protected $fillable = [
'first_name',
'last_name',
'email',
'event_id',
'order_id',
'ticket_id',
'account_id',
'reference',
2016-03-30 01:37:38 +00:00
'has_arrived',
'arrival_time'
];
/**
2016-03-14 16:37:38 +00:00
* Generate a private reference number for the attendee. Use for checking in the attendee.
*
*/
public static function boot()
{
parent::boot();
static::creating(function ($order) {
$order->private_reference_number = str_pad(rand(0, pow(10, 9) - 1), 9, '0', STR_PAD_LEFT);
});
}
2016-03-14 16:37:38 +00:00
/**
* The order associated with the attendee.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
2016-03-05 00:18:10 +00:00
public function order()
{
return $this->belongsTo('\App\Models\Order');
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 ticket associated with the attendee.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
2016-03-05 00:18:10 +00:00
public function ticket()
{
2016-02-29 15:59:36 +00:00
return $this->belongsTo('\App\Models\Ticket');
}
2016-03-05 00:18:10 +00:00
2016-03-14 16:37:38 +00:00
/**
* The event associated with the attendee.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
2016-03-05 00:18:10 +00:00
public function event()
{
return $this->belongsTo('\App\Models\Event');
2016-02-29 15:59:36 +00:00
}
2016-03-05 00:18:10 +00:00
2016-03-14 16:37:38 +00:00
/**
* Scope a query to return attendees that have not cancelled.
*
* @param $query
*
* @return mixed
*/
2016-03-05 00:18:10 +00:00
public function scopeWithoutCancelled($query)
{
2016-02-29 15:59:36 +00:00
return $query->where('attendees.is_cancelled', '=', 0);
}
2016-03-05 00:18:10 +00:00
//
2016-02-29 15:59:36 +00:00
// public function getReferenceAttribute() {
// return $this->order->order_reference
// }
2016-03-05 00:18:10 +00:00
2016-03-14 16:37:38 +00:00
/**
* Get the full name of the attendee.
*
* @return string
*/
public function getFullNameAttribute()
{
return $this->first_name.' '.$this->last_name;
}
2016-03-14 16:37:38 +00:00
/**
* The attributes that should be mutated to dates.
*
* @var array $dates
*/
2016-03-05 00:18:10 +00:00
public function getDates()
{
return ['created_at', 'updated_at', 'arrival_time'];
2016-02-29 15:59:36 +00:00
}
2016-02-29 15:59:36 +00:00
}