File: D:/HostingSpaces/netwerkbrabant/netwerkbrabant.nl/app/KommaApp/Courses/Models/Course.php
<?php
/**
*
*
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
namespace App\KommaApp\Courses\Models;
use App\KommaApp\Documents\DocumentsTrait;
use App\KommaApp\Documents\Kms\DocumentableInterface;
use App\KommaApp\CourseSignUps\Models\CourseSignUp;
use App\KommaApp\CourseTypes\Models\CourseType;
use App\KommaApp\Kms\Core\AbstractTranslatableModel;
use App\KommaApp\Kms\Core\Entities\DisplayNameTrait;
use App\KommaApp\Languages\Models\Language;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Str;
use Laravel\Scout\Searchable;
/**
* Class Course
*
* @package App\KommaApp\Courses\Models
* @property-read \Illuminate\Database\Eloquent\Collection|\App\KommaApp\Images\Models\Image[] $images
* @property-read \Illuminate\Database\Eloquent\Collection|\App\KommaApp\Languages\Models\Language[] $languages
* @property-read \App\KommaApp\Sites\Models\Site $site
* @property-read \Illuminate\Database\Eloquent\Collection|\App\KommaApp\Courses\Models\CourseTranslation[] $translations
* @mixin \Eloquent
* @property int $id
* @property int $site_id
* @property int|null $region_id
* @property int $active
* @property string $time
* @property string $location_name
* @property string $location_postal
* @property string $location_city
* @property string $location_address
* @property \Carbon\Carbon|null $created_at
* @property \Carbon\Carbon|null $updated_at
* @property \Carbon\Carbon|null $date
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Courses\Models\Course whereActive($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Courses\Models\Course whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Courses\Models\Course whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Courses\Models\Course whereSiteId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Courses\Models\Course whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Courses\Models\Course whereDate($value)
*/
class Course extends AbstractTranslatableModel implements DocumentableInterface
{
use DocumentsTrait;
use DisplayNameTrait;
use Searchable;
use SoftDeletes;
protected $table = 'courses';
protected $class = Course::class;
protected $fillable = ['active',
'course_type_id',
'date',
'time',
'price',
'price_amount',
'location_name',
'location_postal',
'location_city',
'location_address',
'digital',
'online_url',
'calendar_start_time',
'calendar_end_time',
'with_invoicing',
'with_invoicing',
'wefact_modified_at',
'wefact_description',
'wefact_name',
'wefact_code',
'organisation_name',
'organisation_site',
'organisation_email',
'organisation_phone',
];
protected $dates = ['date', 'wefact_modified_at'];
/*
* Transient properties on Eloquent models
* These are not saved to database.
*/
public $thumbnail = false;
public function toSearchableArray()
{
return $this->only('id','location_name', 'location_city', 'location_address');
}
/**
* Gets the translation models for this model
*
* @return HasMany that resolves to AbstractTranslationModel instances
*/
public function translations(): HasMany
{
return $this->hasMany(CourseTranslation::class);
}
/**
* Gets the signups for this course
*
* @return HasMany that resolves to AbstractTranslationModel instances
*/
public function signUps(): HasMany
{
return $this->hasMany(CourseSignUp::class);
}
public function languages(): BelongsToMany
{
return $this->belongsToMany(Language::class, 'course_translations')
->withPivot('description')
->withTimestamps();
}
public function type(): BelongsTo
{
return $this->belongsTo(CourseType::class, 'course_type_id');
}
public function getSideBarName(): ?string
{
// If there is no name defined generate a generic name
if(!$sideBarName = $this->getDisplayName()){
$sideBarName = trans( 'kms/'.Str::camel($this->table).'.entity') . ' ' . $this->id;
}
$sideBarName .= '<br/><sub>' . $this->date->format('d-m-Y') . '</sub>';
return $sideBarName;
}
}