File: D:/HostingSpaces/SBogers10/wingssprayer.komma.pro/app/Questions/Models/Question.php
<?php
/**
*
*
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
namespace App\Questions\Models;
use App\Components\Component\ComponentableInterface;
use App\Components\Component\ComponentableTrait;
use Illuminate\Support\Str;
use Komma\KMS\Documents\DocumentsTrait;
use Komma\KMS\Documents\Kms\DocumentableInterface;
use Komma\KMS\Core\Entities\DisplayNameInterface;
use Komma\KMS\Core\Entities\DisplayNameTrait;
use Komma\KMS\Globalization\Languages\Models\Language;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Komma\KMS\Core\Tree\NestedSets\Nodes\AbstractTranslatableTreeModel;
use Komma\KMS\Helpers\KommaHelpers;
/**
* Class Question
*
* @package App\Questions\Models
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Globalization\Languages\Models\Language[] $languages
* @property-read \App\Questions\Models\QuestionTranslation $translation
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Questions\Models\QuestionTranslation[] $translations
* @mixin \Eloquent
* @property int $id
* @property int $active
* @property int|null $lft
* @property int|null $rgt
* @property int|null $tree
* @property \Carbon\Carbon|null $created_at
* @property \Carbon\Carbon|null $updated_at
* @method static \Illuminate\Database\Eloquent\Builder|\App\Questions\Models\Question whereActive($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Questions\Models\Question whereCodeName($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Questions\Models\Question whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Questions\Models\Question whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Questions\Models\Question whereLft($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Questions\Models\Question whereRgt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Questions\Models\Question whereSiteId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Questions\Models\Question whereTree($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Questions\Models\Question whereUpdatedAt($value)
* @property-read \Illuminate\Database\Eloquent\Collection|\Komma\KMS\Documents\Models\Document[] $documents
* @property-read \Illuminate\Database\Eloquent\Collection|\Komma\KMS\Documents\Models\Document[] $images
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Components\Component\Component[] $components
* @method static \Illuminate\Database\Eloquent\Builder|\App\Questions\Models\Question newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Questions\Models\Question newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Questions\Models\Question query()
* @property int|null $site_id
* @property int $in_shortlist
* @property-read int|null $languages_count
* @property-read \App\Site\Site|null $site
* @property-read int|null $translations_count
* @method static \Illuminate\Database\Eloquent\Builder|Question whereInShortlist($value)
*/
final class Question extends AbstractTranslatableTreeModel implements DisplayNameInterface
{
use DisplayNameTrait;
protected $class = Question::class;
protected $fillable = ['active', 'in_shortlist', 'site_id', 'lft', 'rgt', 'tree'];
/**
* Gets the translation models for this model
*
* @return HasMany that resolves to AbstractTranslationModel instances
*/
public function translations(): HasMany
{
return $this->hasMany(QuestionTranslation::class);
}
public function languages(): BelongsToMany
{
return $this->belongsToMany(Language::class, 'question_translations')
->withPivot('slug', 'name', 'description')
->withTimestamps();
}
public function __get($key)
{
if($key == "parent_id") {
if($this::find($this->id))
return $this->getParentId();
}
return parent::__get($key);
}
/**
* @return string
*/
public function getSidebarName():string
{
// If there is no name defined generate a generic name
if(!$sidebarName = $this->getDisplayName()){
return __('kms/questions.entity') . ' '.$this->id;
}
return $sidebarName;
}
}