File: D:/HostingSpaces/SBogers10/inzigd.komma.pro/app/Komma/Workshops/Models/Workshop.php
<?php
/**
*
*
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
namespace App\Komma\Workshops\Models;
use App\Helpers\KommaHelpers;
use App\Komma\Categories\CategorizableInterface;
use App\Komma\Categories\Models\Category;
use App\Komma\Documents\DocumentsTrait;
use App\Komma\Documents\Kms\DocumentableInterface;
use App\Komma\Kms\Core\AbstractTranslatableModel;
use App\Komma\Kms\Core\Entities\DisplayNameInterface;
use App\Komma\Kms\Core\Entities\DisplayNameTrait;
use App\Komma\Kms\Core\Tree\NestedSets\Nodes\AbstractTranslatableTreeModel;
use App\Komma\Languages\Models\Language;
use App\Komma\Sites\HasSitesInterface;
use App\Komma\Sites\Models\Site;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Illuminate\Support\Str;
/**
* Class Page
*
* @package App\Komma\Pages\Models
* @property int site_id
* @property int lft
* @property int rgt
* @property int tree
* @property-read \Carbon $date
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Languages\Models\Language[] $languages
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Sites\Models\Site[] $sites
* @property-read \App\Komma\Workshops\Models\WorkshopTranslation $translation
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Workshops\Models\WorkshopTranslation[] $translations
* @mixin \Eloquent
* @property int $id
* @property int $active
* @property \Carbon\Carbon|null $created_at
* @property \Carbon\Carbon|null $updated_at
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Workshops\Models\Workshop whereActive($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Workshops\Models\Workshop whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Workshops\Models\Workshop whereDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Workshops\Models\Workshop whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Workshops\Models\Workshop whereUpdatedAt($value)
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Documents\Models\Document[] $documents
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Documents\Models\Document[] $images
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Workshops\Models\Workshop newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Workshops\Models\Workshop newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Workshops\Models\Workshop query()
*/
final class Workshop extends AbstractTranslatableTreeModel implements DocumentableInterface, DisplayNameInterface, CategorizableInterface
{
use DocumentsTrait;
use DisplayNameTrait;
protected $table = 'workshops';
protected $class = Workshop::class;
protected $fillable = ['site_id', 'lft', 'rgt', 'tree', 'active', 'duration'];
/**
* Gets the translation models for this model
*
* @return HasMany that resolves to AbstractTranslationModel instances
*/
public function translations(): HasMany
{
return $this->hasMany(WorkshopTranslation::class);
}
public function languages(): BelongsToMany
{
return $this->belongsToMany(Language::class, 'workshop_translations')
->withPivot('slug', 'name', 'description')
->withTimestamps();
}
public function category() : MorphToMany
{
return $this->morphToMany(Category::class,'categorable');
}
public function __get($key)
{
if($key == "parent_id") {
if($this::find($this->id))
return $this->getParentId();
}
return parent::__get($key);
}
/**
* Get the name for the sidebar
*
* @return string
*/
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;
}
if(strlen($sideBarName) > 50) $sideBarName = KommaHelpers::str_limit_full_word($sideBarName, 45);
if($this->category->isNotEmpty())
$sideBarName .= '<br/><sub>' . $this->category->first()->kms_name . '</sub>';
return $sideBarName;
}
}