<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;

class News extends Model
{

    use Notifiable;
    
    protected $fillable = [
        'section_id',
        'region_1_id',
        'region_2_id',
        'page_id',
        'event_id',
        'title',
        'title_region_1',
        'title_region_2',
        'text_short',
        'text',
        'image',
        'online',
        'homepage',
        'date',
        'slug',
        'meta_title',
        'meta_description',
        'meta_keywords',
        'live',
        'image1',
        'image2',
        'image3',
        'image4',
        'image5',
        'video',
        'pdf',
        'breaking_news',
        'clicks',
        'section_position',
        'region_1_position',
        'region_2_position',
        'published'
    ];

    public function section()
    {
        return $this->belongsTo('App\Section');
    }

    public function region_1()
    {
        return $this->belongsTo('App\Section');
    }

    public function region_2()
    {
        return $this->belongsTo('App\Section');
    }

    public function event()
    {
        return $this->belongsTo('App\Event');
    }

    public function page()
    {
        return $this->belongsTo('App\Page');
    }

    public function user()
    {
        return $this->belongsTo('App\User');
    }

    public function getCurrentTitle($section_id)
    {

        $title = '';

        if ($this->section_id == $section_id)
            $title = $this->title;
        if ($this->region_1_id == $section_id)
            $title = $this->title_region_1;
        if ($this->region_2_id == $section_id)
            $title = $this->title_region_2;
        
        if ($title == '')
            $title = $this->title;

        return $title;

    }

}
