mein-sterntours/app/Models/News.php
2025-04-01 10:40:14 +02:00

228 lines
10 KiB
PHP

<?php
namespace App\Models;
use Carbon\Carbon;
use HTMLHelper;
/**
* App\Models\News
*
* @property int $id
* @property int|null $owner
* @property string|null $model
* @property int|null $lvl
* @property int $owner_second
* @property int|null $catalog_id
* @property int|null $catalog_index
* @property string|null $slug
* @property int|null $travel_program
* @property int|null $status
* @property int|null $show_in_navi
* @property int|null $order
* @property string|null $title
* @property string|null $pagetitle
* @property string|null $description
* @property string|null $keywords
* @property string|null $content
* @property string|null $content_new
* @property string|null $buma_destination
* @property int|null $OLD_CatalogID
* @property int|null $OLD_OwnerID
* @property int|null $buma_gjr
* @property string|null $date
* @property int $price-tags
* @property string|null $text_right
* @property string|null $keyword
* @property string|null $canonical_url
* @property int|null $country_id
* @property string|null $template
* @property int|null $lft
* @property int|null $rgt
* @property int|null $tree_root
* @property int|null $parent_id
* @property string|null $real_url_path
* @property string|null $box_body
* @property string|null $box_image_url
* @property string|null $box_star
* @property string|null $box_discount
* @property string|null $cms_settings
* @property int|null $fewo_lodging
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\News[] $children
* @property-read \App\Models\News|null $parent
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereBoxBody($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereBoxDiscount($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereBoxImageUrl($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereBoxStar($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereBumaDestination($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereBumaGjr($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereCanonicalUrl($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereCatalogId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereCatalogIndex($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereCmsSettings($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereContent($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereContentNew($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereCountryId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereDescription($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereFewoLodging($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereKeyword($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereKeywords($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereLft($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereLvl($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereModel($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereOLDCatalogID($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereOLDOwnerID($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereOrder($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereOwner($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereOwnerSecond($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News wherePagetitle($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereParentId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News wherePriceTags($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereRealUrlPath($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereRgt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereShowInNavi($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereSlug($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereStatus($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereTemplate($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereTextRight($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereTitle($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereTravelProgram($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereTreeRoot($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereUpdatedAt($value)
* @property int|null $travel_guide_content_id
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News query()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereTravelGuideContentId($value)
* @property string|null $title_short
* @property string|null $before_title
* @property-read int|null $children_count
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereBeforeTitle($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\News whereTitleShort($value)
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Page> $child_pages
* @property-read int|null $child_pages_count
* @property-read \App\Models\Page|null $page
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Page> $pages
* @property-read int|null $pages_count
* @property-read \App\Models\Page|null $parent_page
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\TravelCountry> $travel_countries
* @property-read int|null $travel_countries_count
* @property-read \App\Models\TravelCountry|null $travel_country
* @property-read \App\Models\TravelGuide|null $travel_guide
* @property-read \App\Models\TravelProgram|null $travel_program_content
* @method static \Illuminate\Database\Eloquent\Builder|Page findSimilarSlugs(string $attribute, array $config, string $slug)
* @method static \Illuminate\Database\Eloquent\Builder|Page withUniqueSlugConstraints(\Illuminate\Database\Eloquent\Model $model, string $attribute, array $config, string $slug)
* @mixin \Eloquent
*/
class News extends Page
{
protected $table = 'page';
protected $fillable = [
'title', 'status', 'slug', 'date', 'content', 'content_new', 'box_body', 'description', 'pagetitle', 'keywords', 'order', 'active',
];
protected $casts = ['box_body' => 'array', 'date' => 'date', 'status' => 'boolean', 'active' => 'boolean'];
public static function boot()
{
parent::boot();
static::addGlobalScope(function ($query) {
$query->where('model', 'news');
$query->orderBy('lvl', 'ASC');
$query->orderBy('date', 'DESC');
});
}
public function parent()
{
return $this->belongsTo('App\Models\News', 'parent_id');
}
public function getParent()
{
if ($this->lvl == 1) {
$this->parent();
}
return false;
}
public function children()
{
return $this->hasMany('App\Models\News', 'parent_id');
}
public function setContentAttribute($value)
{
if (!$value) {
$this->attributes['content'] = $value;
} else {
$this->attributes['content'] = HTMLHelper::filterHTML($value, ['src' => ['removeHost']], true);
}
}
public function getContentAttribute()
{
return $this->attributes['content_new'] === null ? $this->attributes['content'] : $this->attributes['content_new'];
}
public function setContentNewAttribute($value)
{
if (!$value) {
$this->attributes['content_new'] = $value;
} else {
$this->attributes['content_new'] = HTMLHelper::filterHTML($value, ['src' => ['removeHost']], true);
}
}
public function getContentNewAttribute()
{
return $this->attributes['content_new'] === null ? $this->attributes['content'] : $this->attributes['content_new'];
}
public function getParentsArray(){
//lvl 0
return Page::where('model', 'News')->where('lvl', 1)->get()->pluck('title', 'id');
}
//$Newss = News::where('lvl', 1)->get();
public function getDateRow()
{
return$this->attributes['date'];
}
public function getDateAttribute()
{
return isset($this->attributes['date']) ? Carbon::parse($this->attributes['date'])->format("d.m.Y") : '';
}
public function setDateAttribute($value)
{
if (!$value) {
$this->attributes['date'] = null;
} else {
try {
$this->attributes['date']= Carbon::parse($value);
} catch (\Exception $e) {
$this->attributes['date'] = Carbon::now();
}
}
}
public function getImage($key){
//use box_body for images
if(isset($this->box_body[$key])){
return $this->box_body[$key];
}
return "";
}
}