2016-03-05 00:18:10 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
2016-02-29 15:59:36 +00:00
|
|
|
|
|
|
|
|
use Str;
|
|
|
|
|
|
2016-03-05 00:18:10 +00:00
|
|
|
class Organiser extends MyBaseModel
|
|
|
|
|
{
|
2016-03-14 16:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* The validation rules for the model.
|
|
|
|
|
*
|
|
|
|
|
* @var array $rules
|
|
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
protected $rules = [
|
|
|
|
|
'name' => ['required'],
|
|
|
|
|
'email' => ['required', 'email'],
|
|
|
|
|
'organiser_logo' => ['mimes:jpeg,jpg,png', 'max:10000'],
|
|
|
|
|
];
|
2016-03-14 16:37:38 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The validation error messages for the model.
|
|
|
|
|
*
|
|
|
|
|
* @var array $messages
|
|
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
protected $messages = [
|
|
|
|
|
'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.size' => 'Please upload an image smaller than 10Mb',
|
|
|
|
|
'organiser_logo.mimes' => 'Please select a valid image type (jpeg, jpg, png)',
|
|
|
|
|
];
|
|
|
|
|
|
2016-05-12 10:43:04 +00:00
|
|
|
/**
|
|
|
|
|
* The account associated with the organiser
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
|
*/
|
|
|
|
|
public function account()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo('\App\Models\Account');
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-14 16:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* The events associated with the organizer.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
public function events()
|
|
|
|
|
{
|
2016-02-29 15:59:36 +00:00
|
|
|
return $this->hasMany('\App\Models\Event');
|
|
|
|
|
}
|
2016-03-05 00:18:10 +00:00
|
|
|
|
2016-03-14 16:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* The attendees associated with the organizer.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
|
|
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
public function attendees()
|
|
|
|
|
{
|
2016-02-29 15:59:36 +00:00
|
|
|
return $this->hasManyThrough('\App\Models\Attendee', '\App\Models\Event');
|
|
|
|
|
}
|
2016-03-05 00:18:10 +00:00
|
|
|
|
2016-04-26 13:36:43 +00:00
|
|
|
/**
|
|
|
|
|
* Get the orders related to an organiser
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
|
|
|
|
|
*/
|
|
|
|
|
public function orders()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasManyThrough('\App\Models\Order', '\App\Models\Event');
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-14 16:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* Get the full logo path of the organizer.
|
|
|
|
|
*
|
|
|
|
|
* @return mixed|string
|
|
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
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)))) {
|
2016-03-04 23:27:13 +00:00
|
|
|
return config('attendize.cdn_url_user_assets').'/'.$this->logo_path;
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
2016-03-05 00:18:10 +00:00
|
|
|
|
2016-03-04 23:27:13 +00:00
|
|
|
return config('attendize.fallback_organiser_logo_url');
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-14 16:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* Get the url of the organizer.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
public function getOrganiserUrlAttribute()
|
|
|
|
|
{
|
2016-02-29 15:59:36 +00:00
|
|
|
return route('showOrganiserHome', [
|
2016-03-05 00:18:10 +00:00
|
|
|
'organiser_id' => $this->id,
|
|
|
|
|
'organiser_slug' => Str::slug($this->oraganiser_name),
|
2016-02-29 15:59:36 +00:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-14 16:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* Get the sales volume of the organizer.
|
|
|
|
|
*
|
|
|
|
|
* @return mixed|number
|
|
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
public function getOrganiserSalesVolumeAttribute()
|
|
|
|
|
{
|
2016-02-29 15:59:36 +00:00
|
|
|
return $this->events->sum('sales_volume');
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-14 16:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* TODO:implement DailyStats method
|
|
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
public function getDailyStats()
|
|
|
|
|
{
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
|
|
|
|
}
|