2016-03-05 00:18:10 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
2016-02-29 15:59:36 +00:00
|
|
|
|
2018-07-09 16:13:23 +00:00
|
|
|
use Illuminate\Auth\Authenticatable;
|
2016-11-19 23:19:54 +00:00
|
|
|
use Illuminate\Http\UploadedFile;
|
2018-07-09 16:13:23 +00:00
|
|
|
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
|
2016-02-29 15:59:36 +00:00
|
|
|
use Str;
|
2016-11-19 23:19:54 +00:00
|
|
|
use Image;
|
2016-02-29 15:59:36 +00:00
|
|
|
|
2018-07-09 16:13:23 +00:00
|
|
|
class Organiser extends MyBaseModel implements AuthenticatableContract
|
2016-03-05 00:18:10 +00:00
|
|
|
{
|
2018-07-09 16:13:23 +00:00
|
|
|
use Authenticatable;
|
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
|
|
|
|
2018-07-09 16:13:23 +00:00
|
|
|
protected $extra_rules = [
|
|
|
|
|
'tax_name' => ['required','max:15'],
|
|
|
|
|
'tax_value' => ['required','numeric'],
|
|
|
|
|
'tax_id' => ['required','max:100'],
|
|
|
|
|
];
|
|
|
|
|
|
2018-02-27 18:26:23 +00:00
|
|
|
/**
|
|
|
|
|
* The validation rules for the model.
|
|
|
|
|
*
|
2018-03-04 14:49:35 +00:00
|
|
|
* @var array $attributes
|
2018-02-27 18:26:23 +00:00
|
|
|
*/
|
|
|
|
|
protected $attributes = [
|
2018-07-09 16:13:23 +00:00
|
|
|
'tax_name' => 'Tax Name',
|
|
|
|
|
'tax_value' => 'Tax Rate',
|
|
|
|
|
'tax_id' => 'Tax ID',
|
2018-02-27 18:26:23 +00:00
|
|
|
];
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
2016-10-07 22:48:54 +00:00
|
|
|
return $this->belongsTo(\App\Models\Account::class);
|
2016-05-12 10:43:04 +00:00
|
|
|
}
|
|
|
|
|
|
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-10-07 22:48:54 +00:00
|
|
|
return $this->hasMany(\App\Models\Event::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 attendees associated with the organizer.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
|
|
|
|
|
*/
|
2016-03-05 00:18:10 +00:00
|
|
|
public function attendees()
|
|
|
|
|
{
|
2016-10-07 22:48:54 +00:00
|
|
|
return $this->hasManyThrough(\App\Models\Attendee::class, \App\Models\Event::class);
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
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()
|
|
|
|
|
{
|
2016-10-07 22:48:54 +00:00
|
|
|
return $this->hasManyThrough(\App\Models\Order::class, \App\Models\Event::class);
|
2016-04-26 13:36:43 +00:00
|
|
|
}
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
2016-09-06 20:39:27 +00:00
|
|
|
if ($this->logo_path && (file_exists(config('attendize.cdn_url_user_assets') . '/' . $this->logo_path) || file_exists(public_path($this->logo_path)))) {
|
|
|
|
|
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
|
|
|
}
|
2016-11-19 23:19:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set a new Logo for the Organiser
|
|
|
|
|
*
|
|
|
|
|
* @param \Illuminate\Http\UploadedFile $file
|
|
|
|
|
*/
|
|
|
|
|
public function setLogo(UploadedFile $file)
|
|
|
|
|
{
|
|
|
|
|
$filename = str_slug($this->name).'-logo-'.$this->id.'.'.strtolower($file->getClientOriginalExtension());
|
|
|
|
|
|
|
|
|
|
// Image Directory
|
|
|
|
|
$imageDirectory = public_path() . '/' . config('attendize.organiser_images_path');
|
|
|
|
|
|
|
|
|
|
// Paths
|
|
|
|
|
$relativePath = config('attendize.organiser_images_path').'/'.$filename;
|
|
|
|
|
$absolutePath = public_path($relativePath);
|
|
|
|
|
|
|
|
|
|
$file->move($imageDirectory, $filename);
|
|
|
|
|
|
|
|
|
|
$img = Image::make($absolutePath);
|
|
|
|
|
|
|
|
|
|
$img->resize(250, 250, function ($constraint) {
|
|
|
|
|
$constraint->aspectRatio();
|
|
|
|
|
$constraint->upsize();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$img->save($absolutePath);
|
|
|
|
|
|
|
|
|
|
if (file_exists($absolutePath)) {
|
|
|
|
|
$this->logo_path = $relativePath;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-07-09 16:13:23 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Adds extra validator rules to the organiser object depending on whether tax is required or not
|
|
|
|
|
*/
|
|
|
|
|
public function addExtraValidationRules() {
|
|
|
|
|
$this->rules = $this->rules + $this->extra_rules;
|
|
|
|
|
}
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
2018-03-04 16:30:09 +00:00
|
|
|
|