Adds docblocks to models

This commit is contained in:
jncampbell 2016-03-14 16:37:38 +00:00
parent 0210beb20b
commit c6f01728be
22 changed files with 616 additions and 19 deletions

View File

@ -9,16 +9,36 @@ class Account extends MyBaseModel
{ {
use SoftDeletes; use SoftDeletes;
/**
* The validation rules
*
* @var array $rules
*/
protected $rules = [ protected $rules = [
'first_name' => ['required'], 'first_name' => ['required'],
'last_name' => ['required'], 'last_name' => ['required'],
'email' => ['required', 'email'], 'email' => ['required', 'email'],
]; ];
/**
* The attributes that should be mutated to dates.
*
* @var array $dates
*/
public $dates = ['deleted_at']; public $dates = ['deleted_at'];
/**
* The validation error messages.
*
* @var array $messages
*/
protected $messages = []; protected $messages = [];
/**
* The attributes that are mass assignable.
*
* @var array $fillable
*/
protected $fillable = [ protected $fillable = [
'first_name', 'first_name',
'last_name', 'last_name',
@ -47,21 +67,41 @@ class Account extends MyBaseModel
'stripe_data_raw' 'stripe_data_raw'
]; ];
/**
* The users associated with the account.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function users() public function users()
{ {
return $this->hasMany('\App\Models\User'); return $this->hasMany('\App\Models\User');
} }
/**
* The orders associated with the account.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function orders() public function orders()
{ {
return $this->hasMany('\App\Models\Order'); return $this->hasMany('\App\Models\Order');
} }
/**
* The currency associated with the account.
*
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function currency() public function currency()
{ {
return $this->hasOne('\App\Models\Currency'); return $this->hasOne('\App\Models\Currency');
} }
/**
* Get the stripe api key.
*
* @return \Illuminate\Support\Collection|mixed|static
*/
public function getStripeApiKeyAttribute() public function getStripeApiKeyAttribute()
{ {
if (Utils::isAttendize()) { if (Utils::isAttendize()) {

View File

@ -13,4 +13,5 @@ namespace App\Models;
*/ */
class Activity extends \Illuminate\Database\Eloquent\Model class Activity extends \Illuminate\Database\Eloquent\Model
{ {
//put your code here.
} }

View File

@ -8,8 +8,25 @@ namespace App\Models;
class Affiliate extends \Illuminate\Database\Eloquent\Model class Affiliate extends \Illuminate\Database\Eloquent\Model
{ {
protected $fillable = ['name', 'visits', 'tickets_sold', 'event_id', 'account_id', 'sales_volume']; /**
* The attributes that are mass assignable.
*
* @var array $fillable
*/
protected $fillable = [
'name',
'visits',
'tickets_sold',
'event_id',
'account_id',
'sales_volume'
];
/**
* The attributes that should be mutated to dates.
*
* @var array $dates
*/
public function getDates() public function getDates()
{ {
return ['created_at', 'updated_at']; return ['created_at', 'updated_at'];

View File

@ -15,9 +15,14 @@ use Illuminate\Database\Eloquent\SoftDeletes;
*/ */
class Attendee extends MyBaseModel class Attendee extends MyBaseModel
{ {
use SoftDeletes; use SoftDeletes;
/**
* The attributes that are mass assignable.
*
* @var array $fillable
*/
protected $fillable = [ protected $fillable = [
'first_name', 'first_name',
'last_name', 'last_name',
@ -30,7 +35,8 @@ class Attendee extends MyBaseModel
]; ];
/** /**
* Generate a private referennce number for the attendee. Use for checking in the attendee. * Generate a private reference number for the attendee. Use for checking in the attendee.
*
*/ */
public static function boot() public static function boot()
{ {
@ -41,21 +47,43 @@ class Attendee extends MyBaseModel
}); });
} }
/**
* The order associated with the attendee.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function order() public function order()
{ {
return $this->belongsTo('\App\Models\Order'); return $this->belongsTo('\App\Models\Order');
} }
/**
* The ticket associated with the attendee.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function ticket() public function ticket()
{ {
return $this->belongsTo('\App\Models\Ticket'); return $this->belongsTo('\App\Models\Ticket');
} }
/**
* The event associated with the attendee.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function event() public function event()
{ {
return $this->belongsTo('\App\Models\Event'); return $this->belongsTo('\App\Models\Event');
} }
/**
* Scope a query to return attendees that have not cancelled.
*
* @param $query
*
* @return mixed
*/
public function scopeWithoutCancelled($query) public function scopeWithoutCancelled($query)
{ {
return $query->where('attendees.is_cancelled', '=', 0); return $query->where('attendees.is_cancelled', '=', 0);
@ -66,11 +94,21 @@ class Attendee extends MyBaseModel
// return $this->order->order_reference // return $this->order->order_reference
// } // }
/**
* Get the full name of the attendee.
*
* @return string
*/
public function getFullNameAttribute() public function getFullNameAttribute()
{ {
return $this->first_name.' '.$this->last_name; return $this->first_name.' '.$this->last_name;
} }
/**
* The attributes that should be mutated to dates.
*
* @var array $dates
*/
public function getDates() public function getDates()
{ {
return ['created_at', 'updated_at', 'arrival_time']; return ['created_at', 'updated_at', 'arrival_time'];

View File

@ -13,11 +13,32 @@ namespace App\Models;
*/ */
class Currency extends \Illuminate\Database\Eloquent\Model class Currency extends \Illuminate\Database\Eloquent\Model
{ {
public $timestamps = false; /**
protected $softDelete = false; * The database table used by the model.
*
* @var string $table
*/
protected $table = 'currencies'; protected $table = 'currencies';
/**
* Indicates whether the model should be timestamped.
*
* @var bool $timestamps
*/
public $timestamps = false;
/**
* Indicates whether the model should use soft deletes.
*
* @var bool $softDelete
*/
protected $softDelete = false;
/**
* The event associated with the currency.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function event() public function event()
{ {
return $this->belongsTo('\App\Models\Event'); return $this->belongsTo('\App\Models\Event');

View File

@ -13,6 +13,17 @@ namespace App\Models;
*/ */
class DateFormat extends \Illuminate\Database\Eloquent\Model class DateFormat extends \Illuminate\Database\Eloquent\Model
{ {
/**
* Indicates whether the model should be timestamped.
*
* @var bool $timestamps
*/
public $timestamps = false; public $timestamps = false;
/**
* Indicates whether the model should use soft deletes.
*
* @var bool $softDelete
*/
protected $softDelete = false; protected $softDelete = false;
} }

View File

@ -13,8 +13,24 @@ namespace App\Models;
*/ */
class DateTimeFormat extends \Illuminate\Database\Eloquent\Model class DateTimeFormat extends \Illuminate\Database\Eloquent\Model
{ {
/**
* The database table used by the model.
*
* @var string $table
*/
protected $table = 'datetime_formats'; protected $table = 'datetime_formats';
/**
* Indicates whether the model should be timestamped.
*
* @var bool $timestamps
*/
public $timestamps = false; public $timestamps = false;
/**
* Indicates whether the model should use soft deletes.
*
* @var bool $softDelete
*/
protected $softDelete = false; protected $softDelete = false;
} }

View File

@ -11,6 +11,11 @@ class Event extends MyBaseModel
{ {
use SoftDeletes; use SoftDeletes;
/**
* The validation rules.
*
* @var array $rules
*/
protected $rules = [ protected $rules = [
'title' => ['required'], 'title' => ['required'],
'description' => ['required'], 'description' => ['required'],
@ -21,6 +26,12 @@ class Event extends MyBaseModel
'organiser_name' => ['required_without:organiser_id'], 'organiser_name' => ['required_without:organiser_id'],
'event_image' => ['mimes:jpeg,jpg,png', 'max:3000'], 'event_image' => ['mimes:jpeg,jpg,png', 'max:3000'],
]; ];
/**
* The validation error messages.
*
* @var array $messages
*/
protected $messages = [ protected $messages = [
'title.required' => 'You must at least give a title for your event.', '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.', 'organiser_name.required_without' => 'Please create an organiser or select an existing organiser.',
@ -30,95 +41,181 @@ class Event extends MyBaseModel
'venue_name_full.required_without' => 'Please enter a venue for your event', 'venue_name_full.required_without' => 'Please enter a venue for your event',
]; ];
/**
* The questions associated with the event.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function questions() public function questions()
{ {
return $this->belongsToMany('\App\Models\Question', 'event_question'); return $this->belongsToMany('\App\Models\Question', 'event_question');
} }
/**
* The attendees associated with the event.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function attendees() public function attendees()
{ {
return $this->hasMany('\App\Models\Attendee'); return $this->hasMany('\App\Models\Attendee');
} }
/**
* The images associated with the event.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function images() public function images()
{ {
return $this->hasMany('\App\Models\EventImage'); return $this->hasMany('\App\Models\EventImage');
} }
/**
* The messages associated with the event.
*
* @return mixed
*/
public function messages() public function messages()
{ {
return $this->hasMany('\App\Models\Message')->orderBy('created_at', 'DESC'); return $this->hasMany('\App\Models\Message')->orderBy('created_at', 'DESC');
} }
/**
* The tickets associated with the event.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function tickets() public function tickets()
{ {
return $this->hasMany('\App\Models\Ticket'); return $this->hasMany('\App\Models\Ticket');
} }
/**
* The stats associated with the event.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function stats() public function stats()
{ {
return $this->hasMany('\App\Models\EventStats'); return $this->hasMany('\App\Models\EventStats');
} }
/**
* The affiliates associated with the event.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function affiliates() public function affiliates()
{ {
return $this->hasMany('\App\Models\Affiliate'); return $this->hasMany('\App\Models\Affiliate');
} }
/**
* The orders associated with the event.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function orders() public function orders()
{ {
return $this->hasMany('\App\Models\Order'); return $this->hasMany('\App\Models\Order');
} }
/**
* The account associated with the event.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function account() public function account()
{ {
return $this->belongsTo('\App\Models\Account'); return $this->belongsTo('\App\Models\Account');
} }
/**
* The currency associated with the event.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function currency() public function currency()
{ {
return $this->belongsTo('\App\Models\Currency'); return $this->belongsTo('\App\Models\Currency');
} }
/**
* The organizer associated with the event.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function organiser() public function organiser()
{ {
return $this->belongsTo('\App\Models\Organiser'); return $this->belongsTo('\App\Models\Organiser');
} }
/* /**
* Getters & Setters * Get the embed url.
*
* @return mixed
*/ */
public function getEmbedUrlAttribute() public function getEmbedUrlAttribute()
{ {
return str_replace(['http:', 'https:'], '', route('showEmbeddedEventPage', ['event' => $this->id])); return str_replace(['http:', 'https:'], '', route('showEmbeddedEventPage', ['event' => $this->id]));
} }
/**
* Get the fixed fee.
*
* @return mixed
*/
public function getFixedFeeAttribute() public function getFixedFeeAttribute()
{ {
return config('attendize.ticket_booking_fee_fixed') + $this->organiser_fee_fixed; return config('attendize.ticket_booking_fee_fixed') + $this->organiser_fee_fixed;
} }
/**
* Get the percentage fee.
*
* @return mixed
*/
public function getPercentageFeeAttribute() public function getPercentageFeeAttribute()
{ {
return config('attendize.ticket_booking_fee_percentage') + $this->organiser_fee_percentage; return config('attendize.ticket_booking_fee_percentage') + $this->organiser_fee_percentage;
} }
/**
* Indicates whether the event is currently happening.
*
* @return bool
*/
public function getHappeningNowAttribute() public function getHappeningNowAttribute()
{ {
return Carbon::now()->between($this->start_date, $this->end_date); return Carbon::now()->between($this->start_date, $this->end_date);
} }
/**
* Get the currency sybol.
*
* @return \Illuminate\Support\Collection
*/
public function getCurrencySymbolAttribute() public function getCurrencySymbolAttribute()
{ {
return $this->currency->symbol_left; return $this->currency->symbol_left;
} }
/**
* Get the currency code.
*
* @return \Illuminate\Support\Collection
*/
public function getCurrencyCodeAttribute() public function getCurrencyCodeAttribute()
{ {
return $this->currency->code; return $this->currency->code;
} }
/**
* Get the embed html code.
*
* @return string
*/
public function getEmbedHtmlCodeAttribute() public function getEmbedHtmlCodeAttribute()
{ {
return "<!--Attendize.com Ticketing Embed Code--> return "<!--Attendize.com Ticketing Embed Code-->
@ -126,8 +223,9 @@ class Event extends MyBaseModel
<!--/Attendize.com Ticketing Embed Code-->"; <!--/Attendize.com Ticketing Embed Code-->";
} }
/* /**
* Get a usable address for embedding Google Maps * Get a usable address for embedding Google Maps
*
*/ */
public function getMapAddressAttribute() public function getMapAddressAttribute()
{ {
@ -142,21 +240,41 @@ class Event extends MyBaseModel
return urlencode($string); return urlencode($string);
} }
/**
* Get the big image url.
*
* @return string
*/
public function getBgImageUrlAttribute() public function getBgImageUrlAttribute()
{ {
return URL::to('/').'/'.$this->bg_image_path; return URL::to('/').'/'.$this->bg_image_path;
} }
/**
* Get the url of the event.
*
* @return string
*/
public function getEventUrlAttribute() public function getEventUrlAttribute()
{ {
return URL::to('/').'/e/'.$this->id.'/'.Str::slug($this->title); return URL::to('/').'/e/'.$this->id.'/'.Str::slug($this->title);
} }
/**
* Get the sales and fees volume.
*
* @return \Illuminate\Support\Collection|mixed|static
*/
public function getSalesAndFeesVoulmeAttribute() public function getSalesAndFeesVoulmeAttribute()
{ {
return $this->sales_volume + $this->organiser_fees_volume; return $this->sales_volume + $this->organiser_fees_volume;
} }
/**
* The attributes that should be mutated to dates.
*
* @var array $dates
*/
public function getDates() public function getDates()
{ {
return ['created_at', 'updated_at', 'start_date', 'end_date']; return ['created_at', 'updated_at', 'start_date', 'end_date'];

View File

@ -13,4 +13,5 @@ namespace App\Models;
*/ */
class EventImage extends MyBaseModel class EventImage extends MyBaseModel
{ {
//put your code here.
} }

View File

@ -7,14 +7,16 @@ use DB;
class EventStats extends \Illuminate\Database\Eloquent\Model class EventStats extends \Illuminate\Database\Eloquent\Model
{ {
/**
* Indicates if the model should be timestamped.
*
* @var bool $timestamps
*/
public $timestamps = false; public $timestamps = false;
public static $unguarded = true; public static $unguarded = true;
/** /**
* @todo This shouldn't be in a view. * @todo This shouldn't be in a view.
*/
/**
* Update the amount of revenue a ticket has earned. * Update the amount of revenue a ticket has earned.
* *
* @param int $ticket_id * @param int $ticket_id
@ -36,6 +38,13 @@ class EventStats extends \Illuminate\Database\Eloquent\Model
return $ticket->save(); return $ticket->save();
} }
/**
* Update the amount of views a ticket has earned.
*
* @param $event_id
*
* @return bool
*/
public function updateViewCount($event_id) public function updateViewCount($event_id)
{ {
$stats = $this->firstOrNew([ $stats = $this->firstOrNew([
@ -55,8 +64,10 @@ class EventStats extends \Illuminate\Database\Eloquent\Model
return $stats->save(); return $stats->save();
} }
/* /**
* TODO: Missing amount? * @todo: Missing amount?
* Updates the sales volume earned by an event.
*
*/ */
public function updateSalesVolume($event_id) public function updateSalesVolume($event_id)
{ {
@ -70,6 +81,14 @@ class EventStats extends \Illuminate\Database\Eloquent\Model
return $stats->save(); return $stats->save();
} }
/**
* Updates the number of tickets sold for the event.
*
* @param $event_id
* @param $count
*
* @return bool
*/
public function updateTicketsSoldCount($event_id, $count) public function updateTicketsSoldCount($event_id, $count)
{ {
$stats = $this->firstOrNew([ $stats = $this->firstOrNew([

View File

@ -13,18 +13,32 @@ namespace App\Models;
*/ */
class Message extends MyBaseModel class Message extends MyBaseModel
{ {
/**
* The attributes that are mass assignable.
*
* @var array $fillable
*/
protected $fillable = [ protected $fillable = [
'message', 'message',
'subject', 'subject',
'recipients', 'recipients',
]; ];
/**
* The event associated with the message.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function event() public function event()
{ {
return $this->belongsTo('\App\Models\Event'); return $this->belongsTo('\App\Models\Event');
} }
/**
* Get the recipient label of the model.
*
* @return string
*/
public function getRecipientsLabelAttribute() public function getRecipientsLabelAttribute()
{ {
if ($this->recipients == 0) { if ($this->recipients == 0) {
@ -36,6 +50,11 @@ class Message extends MyBaseModel
return 'Ticket: '.$ticket->title; return 'Ticket: '.$ticket->title;
} }
/**
* The attributes that should be mutated to dates.
*
* @var array $dates
*/
public function getDates() public function getDates()
{ {
return ['created_at', 'updated_at', 'sent_at']; return ['created_at', 'updated_at', 'sent_at'];

View File

@ -11,12 +11,48 @@ use Validator;
class MyBaseModel extends \Illuminate\Database\Eloquent\Model class MyBaseModel extends \Illuminate\Database\Eloquent\Model
{ {
/**
* Indicates whether the model uses soft deletes.
*
* @var bool $softDelete
*/
protected $softDelete = true; protected $softDelete = true;
/**
* Indicates if the model should be timestamped.
*
* @var bool $timestamps
*/
public $timestamps = true; public $timestamps = true;
/**
* The validation rules of the model.
*
* @var array $rules
*/
protected $rules = []; protected $rules = [];
/**
* The validation error messages of the model.
*
* @var array $messages
*/
protected $messages = []; protected $messages = [];
/**
* The validation errors of model.
*
* @var $errors
*/
protected $errors; protected $errors;
/**
* Validate the model instance.
*
* @param $data
*
* @return bool
*/
public function validate($data) public function validate($data)
{ {
$v = Validator::make($data, $this->rules, $this->messages); $v = Validator::make($data, $this->rules, $this->messages);
@ -31,12 +67,21 @@ class MyBaseModel extends \Illuminate\Database\Eloquent\Model
return true; return true;
} }
/**
* Gets the validation error messages.
*
* @param bool $returnArray
*
* @return mixed
*/
public function errors($returnArray = true) public function errors($returnArray = true)
{ {
return $returnArray ? $this->errors->toArray() : $this->errors; return $returnArray ? $this->errors->toArray() : $this->errors;
} }
/** /**
* Create a new model.
*
* @param int $account_id * @param int $account_id
* @param int $user_id * @param int $user_id
* @param bool $ignore_user_id * @param bool $ignore_user_id
@ -67,6 +112,14 @@ class MyBaseModel extends \Illuminate\Database\Eloquent\Model
return $entity; return $entity;
} }
/**
* Get a formatted date.
*
* @param $field
* @param string $format
*
* @return bool|null|string
*/
public function getFormatedDate($field, $format = 'd-m-Y H:i') public function getFormatedDate($field, $format = 'd-m-Y H:i')
{ {
return $this->$field === null ? null : date($format, strtotime($this->$field)); return $this->$field === null ? null : date($format, strtotime($this->$field));

View File

@ -10,57 +10,113 @@ class Order extends MyBaseModel
{ {
use SoftDeletes; use SoftDeletes;
/**
* The validation rules of the model.
*
* @var array $rules
*/
public $rules = [ public $rules = [
'order_first_name' => ['required'], 'order_first_name' => ['required'],
'order_last_name' => ['required'], 'order_last_name' => ['required'],
'order_email' => ['required', 'email'], 'order_email' => ['required', 'email'],
]; ];
/**
* The validation error messages.
*
* @var array $messages
*/
public $messages = [ public $messages = [
'order_first_name.required' => 'Please enter a valid first name', 'order_first_name.required' => 'Please enter a valid first name',
'order_last_name.required' => 'Please enter a valid last name', 'order_last_name.required' => 'Please enter a valid last name',
'order_email.email' => 'Please enter a valid email', 'order_email.email' => 'Please enter a valid email',
]; ];
/**
* The items associated with the order.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function orderItems() public function orderItems()
{ {
return $this->hasMany('\App\Models\OrderItem'); return $this->hasMany('\App\Models\OrderItem');
} }
/**
* The attendees associated with the order.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function attendees() public function attendees()
{ {
return $this->hasMany('\App\Models\Attendee'); return $this->hasMany('\App\Models\Attendee');
} }
/**
* The account associated with the order.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function account() public function account()
{ {
return $this->belongsTo('\App\Models\Account'); return $this->belongsTo('\App\Models\Account');
} }
/**
* The event associated with the order.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function event() public function event()
{ {
return $this->belongsTo('\App\Models\Event'); return $this->belongsTo('\App\Models\Event');
} }
/**
* The tickets associated with the order.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function tickets() public function tickets()
{ {
return $this->hasMany('\App\Models\Ticket'); return $this->hasMany('\App\Models\Ticket');
} }
/**
* The status associated with the order.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function orderStatus() public function orderStatus()
{ {
return $this->belongsTo('\App\Models\OrderStatus'); return $this->belongsTo('\App\Models\OrderStatus');
} }
/**
* Get the organizer fee of the order.
*
* @return \Illuminate\Support\Collection|mixed|static
*/
public function getOrganiserAmountAttribute() public function getOrganiserAmountAttribute()
{ {
return $this->amount + $this->organiser_booking_fee; return $this->amount + $this->organiser_booking_fee;
} }
/**
* Get the total amount of the order.
*
* @return \Illuminate\Support\Collection|mixed|static
*/
public function getTotalAmountAttribute() public function getTotalAmountAttribute()
{ {
return $this->amount + $this->organiser_booking_fee + $this->booking_fee; return $this->amount + $this->organiser_booking_fee + $this->booking_fee;
} }
/**
* Get the full name of the order.
*
* @return string
*/
public function getFullNameAttribute() public function getFullNameAttribute()
{ {
return $this->first_name.' '.$this->last_name; return $this->first_name.' '.$this->last_name;
@ -102,6 +158,9 @@ class Order extends MyBaseModel
return file_exists($pdf_file); return file_exists($pdf_file);
} }
/**
* Boot all of the bootable traits on the model.
*/
public static function boot() public static function boot()
{ {
parent::boot(); parent::boot();

View File

@ -13,5 +13,11 @@ namespace App\Models;
*/ */
class OrderItem extends MyBaseModel class OrderItem extends MyBaseModel
{ {
/**
* Indicates if the model should be timestamped.
*
* @var bool $timestamps
*/
public $timestamps = false; public $timestamps = false;
} }

View File

@ -13,4 +13,5 @@ namespace App\Models;
*/ */
class OrderStatus extends \Illuminate\Database\Eloquent\Model class OrderStatus extends \Illuminate\Database\Eloquent\Model
{ {
//put your code here
} }

View File

@ -6,11 +6,22 @@ use Str;
class Organiser extends MyBaseModel class Organiser extends MyBaseModel
{ {
/**
* The validation rules for the model.
*
* @var array $rules
*/
protected $rules = [ protected $rules = [
'name' => ['required'], 'name' => ['required'],
'email' => ['required', 'email'], 'email' => ['required', 'email'],
'organiser_logo' => ['mimes:jpeg,jpg,png', 'max:10000'], 'organiser_logo' => ['mimes:jpeg,jpg,png', 'max:10000'],
]; ];
/**
* The validation error messages for the model.
*
* @var array $messages
*/
protected $messages = [ protected $messages = [
'name.required' => 'You must at least give a name for the event organiser.', 'name.required' => 'You must at least give a name for the event organiser.',
'organiser_logo.max' => 'Please upload an image smaller than 10Mb', 'organiser_logo.max' => 'Please upload an image smaller than 10Mb',
@ -18,16 +29,31 @@ class Organiser extends MyBaseModel
'organiser_logo.mimes' => 'Please select a valid image type (jpeg, jpg, png)', 'organiser_logo.mimes' => 'Please select a valid image type (jpeg, jpg, png)',
]; ];
/**
* The events associated with the organizer.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function events() public function events()
{ {
return $this->hasMany('\App\Models\Event'); return $this->hasMany('\App\Models\Event');
} }
/**
* The attendees associated with the organizer.
*
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
*/
public function attendees() public function attendees()
{ {
return $this->hasManyThrough('\App\Models\Attendee', '\App\Models\Event'); return $this->hasManyThrough('\App\Models\Attendee', '\App\Models\Event');
} }
/**
* Get the full logo path of the organizer.
*
* @return mixed|string
*/
public function getFullLogoPathAttribute() public function getFullLogoPathAttribute()
{ {
if ($this->logo_path && (file_exists(config('attendize.cdn_url_user_assets').'/'.$this->logo_path) || file_exists(public_path($this->logo_path)))) { if ($this->logo_path && (file_exists(config('attendize.cdn_url_user_assets').'/'.$this->logo_path) || file_exists(public_path($this->logo_path)))) {
@ -37,6 +63,11 @@ class Organiser extends MyBaseModel
return config('attendize.fallback_organiser_logo_url'); return config('attendize.fallback_organiser_logo_url');
} }
/**
* Get the url of the organizer.
*
* @return string
*/
public function getOrganiserUrlAttribute() public function getOrganiserUrlAttribute()
{ {
return route('showOrganiserHome', [ return route('showOrganiserHome', [
@ -45,11 +76,19 @@ class Organiser extends MyBaseModel
]); ]);
} }
/**
* Get the sales volume of the organizer.
*
* @return mixed|number
*/
public function getOrganiserSalesVolumeAttribute() public function getOrganiserSalesVolumeAttribute()
{ {
return $this->events->sum('sales_volume'); return $this->events->sum('sales_volume');
} }
/**
* TODO:implement DailyStats method
*/
public function getDailyStats() public function getDailyStats()
{ {
} }

View File

@ -13,11 +13,21 @@ class Question extends MyBaseModel
{ {
use SoftDeletes; use SoftDeletes;
/**
* The events associated with the question.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function events() public function events()
{ {
return $this->belongsToMany('\App\Models\Event'); return $this->belongsToMany('\App\Models\Event');
} }
/**
* The type associated with the question.
*
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function question_types() public function question_types()
{ {
return $this->hasOne('\App\Models\QuestionType'); return $this->hasOne('\App\Models\QuestionType');

View File

@ -4,4 +4,5 @@ namespace App\Models;
class QuestionType extends \Illuminate\Database\Eloquent\Model class QuestionType extends \Illuminate\Database\Eloquent\Model
{ {
//put your code here
} }

View File

@ -13,4 +13,5 @@ namespace App\Models;
*/ */
class ReservedTickets extends \Illuminate\Database\Eloquent\Model class ReservedTickets extends \Illuminate\Database\Eloquent\Model
{ {
//put your code here
} }

View File

@ -8,6 +8,11 @@ class Ticket extends MyBaseModel
{ {
use SoftDeletes; use SoftDeletes;
/**
* The rules to validate the model.
*
* @var array $rules
*/
public $rules = [ public $rules = [
'title' => ['required'], 'title' => ['required'],
'price' => ['required', 'numeric', 'min:0'], 'price' => ['required', 'numeric', 'min:0'],
@ -15,45 +20,80 @@ class Ticket extends MyBaseModel
'end_sale_date' => ['date', 'after:start_sale_date'], 'end_sale_date' => ['date', 'after:start_sale_date'],
'quantity_available' => ['integer', 'min:0'], 'quantity_available' => ['integer', 'min:0'],
]; ];
/**
* The validation error messages.
*
* @var array $messages
*/
public $messages = [ public $messages = [
'price.numeric' => 'The price must be a valid number (e.g 12.50)', 'price.numeric' => 'The price must be a valid number (e.g 12.50)',
'title.required' => 'You must at least give a title for your ticket. (e.g Early Bird)', 'title.required' => 'You must at least give a title for your ticket. (e.g Early Bird)',
'quantity_available.integer' => 'Please ensure the quantity available is a number.', 'quantity_available.integer' => 'Please ensure the quantity available is a number.',
]; ];
/**
* The event associated with the ticket.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function event() public function event()
{ {
return $this->belongsTo('\App\Models\Event'); return $this->belongsTo('\App\Models\Event');
} }
/**
* The order associated with the ticket.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function order() public function order()
{ {
return $this->belongsToMany('\App\Models\Order'); return $this->belongsToMany('\App\Models\Order');
} }
/**
* The questions associated with the ticket.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function questions() public function questions()
{ {
return $this->belongsToMany('\App\Models\Question', 'ticket_question'); return $this->belongsToMany('\App\Models\Question', 'ticket_question');
} }
/**
* TODO:implement the reserved method.
*/
public function reserved() public function reserved()
{ {
} }
/**
* Scope a query to only include tickets that are sold out.
*
* @param $query
*/
public function scopeSoldOut($query) public function scopeSoldOut($query)
{ {
$query->where('remaining_tickets', '=', 0); $query->where('remaining_tickets', '=', 0);
} }
/* /**
* Getters & Setters * The attributes that should be mutated to dates.
*
* @var array $dates
*/ */
public function getDates() public function getDates()
{ {
return ['created_at', 'updated_at', 'start_sale_date', 'end_sale_date']; return ['created_at', 'updated_at', 'start_sale_date', 'end_sale_date'];
} }
/**
* Get the number of tickets remaining.
*
* @return \Illuminate\Support\Collection|int|mixed|static
*/
public function getQuantityRemainingAttribute() public function getQuantityRemainingAttribute()
{ {
if (is_null($this->quantity_available)) { if (is_null($this->quantity_available)) {
@ -63,6 +103,11 @@ class Ticket extends MyBaseModel
return $this->quantity_available - ($this->quantity_sold + $this->quantity_reserved); return $this->quantity_available - ($this->quantity_sold + $this->quantity_reserved);
} }
/**
* Get the number of tickets reserved.
*
* @return mixed
*/
public function getQuantityReservedAttribute() public function getQuantityReservedAttribute()
{ {
$reserved_total = \DB::table('reserved_tickets') $reserved_total = \DB::table('reserved_tickets')
@ -73,26 +118,51 @@ class Ticket extends MyBaseModel
return $reserved_total; return $reserved_total;
} }
/**
* Get the booking fee of the ticket.
*
* @return float|int
*/
public function getBookingFeeAttribute() public function getBookingFeeAttribute()
{ {
return (int) ceil($this->price) === 0 ? 0 : round(($this->price * (config('attendize.ticket_booking_fee_percentage') / 100)) + (config('attendize.ticket_booking_fee_fixed')), 2); return (int) ceil($this->price) === 0 ? 0 : round(($this->price * (config('attendize.ticket_booking_fee_percentage') / 100)) + (config('attendize.ticket_booking_fee_fixed')), 2);
} }
/**
* Get the organizer's booking fee.
*
* @return float|int
*/
public function getOrganiserBookingFeeAttribute() public function getOrganiserBookingFeeAttribute()
{ {
return (int) ceil($this->price) === 0 ? 0 : round(($this->price * ($this->event->organiser_fee_percentage / 100)) + ($this->event->organiser_fee_fixed), 2); return (int) ceil($this->price) === 0 ? 0 : round(($this->price * ($this->event->organiser_fee_percentage / 100)) + ($this->event->organiser_fee_fixed), 2);
} }
/**
* Get the total booking fee of the ticket.
*
* @return float|int
*/
public function getTotalBookingFeeAttribute() public function getTotalBookingFeeAttribute()
{ {
return $this->getBookingFeeAttribute() + $this->getOrganiserBookingFeeAttribute(); return $this->getBookingFeeAttribute() + $this->getOrganiserBookingFeeAttribute();
} }
/**
* Get the total price of the ticket.
*
* @return float|int
*/
public function getTotalPriceAttribute() public function getTotalPriceAttribute()
{ {
return $this->getTotalBookingFeeAttribute() + $this->price; return $this->getTotalBookingFeeAttribute() + $this->price;
} }
/**
* Get the maximum and minimum range of the ticket.
*
* @return array
*/
public function getTicketMaxMinRangAttribute() public function getTicketMaxMinRangAttribute()
{ {
$range = []; $range = [];
@ -104,6 +174,11 @@ class Ticket extends MyBaseModel
return $range; return $range;
} }
/**
* Indicates if the ticket is free.
*
* @return bool
*/
public function isFree() public function isFree()
{ {
return (int) ceil($this->price) === 0; return (int) ceil($this->price) === 0;

View File

@ -13,6 +13,18 @@ namespace App\Models;
*/ */
class Timezone extends \Illuminate\Database\Eloquent\Model class Timezone extends \Illuminate\Database\Eloquent\Model
{ {
/**
* Indicates if the model should be timestamped.
*
* @var bool $timestamps
*/
public $timestamps = false; public $timestamps = false;
/**
* Indicates if the model should use soft deletes.
*
* @var bool $softDelete
*/
protected $softDelete = false; protected $softDelete = false;
} }

View File

@ -20,7 +20,13 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
*/ */
protected $table = 'users'; protected $table = 'users';
/**
* The attributes that should be mutated to dates.
*
* @var array $dates
*/
public $dates = ['deleted_at']; public $dates = ['deleted_at'];
/** /**
* The attributes excluded from the model's JSON form. * The attributes excluded from the model's JSON form.
* *
@ -28,6 +34,11 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
*/ */
protected $hidden = ['password']; protected $hidden = ['password'];
/**
* The attributes that are mass assignable.
*
* @var array $fillable
*/
protected $fillable = [ protected $fillable = [
'account_id', 'account_id',
'first_name', 'first_name',
@ -42,11 +53,21 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
'remember_token' 'remember_token'
]; ];
/**
* The account associated with the user.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function account() public function account()
{ {
return $this->belongsTo('\App\Models\Account'); return $this->belongsTo('\App\Models\Account');
} }
/**
* The activity associated with the user.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function activity() public function activity()
{ {
return $this->hasMany('\App\Models\Activity'); return $this->hasMany('\App\Models\Activity');
@ -82,21 +103,39 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
return $this->email; return $this->email;
} }
/**
* Get the remember token for the user.
*
* @return \Illuminate\Support\Collection|mixed|static
*/
public function getRememberToken() public function getRememberToken()
{ {
return $this->remember_token; return $this->remember_token;
} }
/**
* Set the remember token for the user.
*
* @param string $value
*/
public function setRememberToken($value) public function setRememberToken($value)
{ {
$this->remember_token = $value; $this->remember_token = $value;
} }
/**
* Get the name of the remember token for the user.
*
* @return string
*/
public function getRememberTokenName() public function getRememberTokenName()
{ {
return 'remember_token'; return 'remember_token';
} }
/**
* Boot all of the bootable traits on the model.
*/
public static function boot() public static function boot()
{ {
parent::boot(); parent::boot();