<?php

namespace App;

use App\News;

use Illuminate\Database\Eloquent\Model;

class Home extends Model
{

    protected $table = 'home';

    protected $fillable = [
        'slide1',
        'slide2',
        'slide3',
        'slide4',
        'slide5',
        'left',
        'left1',
        'left2',
        'left3',
        'left4',
        'left5',
        'right',
        'right1',
        'right2',
        'right3',
        'right4',
        'right5',
        'image',
        'url',
        'banner_top',
        'banner_top_url',
        'banner_top_google',
        'banner_middle',
        'banner_middle_url',
        'banner_middle_google',
        'banner_first',
        'banner_first_url',
        'banner_first_google',
        'radio1_url',
        'radio2_url',
        'radio3_url',
        'radio1_file',
        'radio2_file',
        'radio3_file',
        'radio1_title',
        'radio2_title',
        'radio3_title',
        'image_2',
        'image_3',
        'url_2',
        'url_3',
        'banner_underb',
        'banner_underb_url',
        'banner_underb_2',
        'banner_underb_url_2',
        'banner_underb_3',
        'banner_underb_url_3',
        'banner_underb_4',
        'banner_underb_url_4',
        'banner_underb_5',
        'banner_underb_url_5',
        'banner_underb_google',
        'banner_top_2',
        'banner_top_2_url',
        'banner_middle_2',
        'banner_middle_2_url',
        'banner_first_2',
        'banner_first_2_url',
        'banner_top_3',
        'banner_top_3_url',
        'banner_top_4',
        'banner_top_4_url',
        'banner_top_5',
        'banner_top_5_url',
        'banner_middle_3',
        'banner_middle_3_url',
        'banner_middle_4',
        'banner_middle_4_url',
        'banner_middle_5',
        'banner_middle_5_url',
        'banner_first_3',
        'banner_first_3_url',
        'banner_first_4',
        'banner_first_4_url',
        'banner_first_5',
        'banner_first_5_url',
        'banner_right_top',
        'banner_right_top_url',
        'banner_right_top_2',
        'banner_right_top_2_url',
        'banner_right_top_3',
        'banner_right_top_3_url',
        'banner_right_top_4',
        'banner_right_top_4_url',
        'banner_right_top_5',
        'banner_right_top_5_url',
        'banner_right_top_google',
        'banner_right_bottom',
        'banner_right_bottom_url',
        'banner_right_bottom_2',
        'banner_right_bottom_2_url',
        'banner_right_bottom_3',
        'banner_right_bottom_3_url',
        'banner_right_bottom_4',
        'banner_right_bottom_4_url',
        'banner_right_bottom_5',
        'banner_right_bottom_5_url',
        'banner_right_bottom_google',
        'banner_right_big',
        'banner_right_big_url',
        'banner_right_big_2',
        'banner_right_big_2_url',
        'banner_right_big_3',
        'banner_right_big_3_url',
        'banner_right_big_4',
        'banner_right_big_4_url',
        'banner_right_big_5',
        'banner_right_big_5_url',
        'banner_right_big_google',
    ];

    function loadData()
    {

        $this->data = $this;
        if ($this->slide1 != '')
            $this->slide1 = @News::where('id', '=', $this->slide1)->first();
        if ($this->slide2 != '')
            $this->slide2 = @News::where('id', '=', $this->slide2)->first();
        if ($this->slide3 != '')
            $this->slide3 = @News::where('id', '=', $this->slide3)->first();
        if ($this->slide4 != '')
            $this->slide4 = @News::where('id', '=', $this->slide4)->first();
        if ($this->slide5 != '')
            $this->slide5 = @News::where('id', '=', $this->slide5)->first();
        if ($this->left != '')
            $this->left = @News::where('id', '=', $this->left)->first();
        if ($this->left1 != '')
            $this->left1 = @News::where('id', '=', $this->left1)->first();
        if ($this->left2 != '')
            $this->left2 = @News::where('id', '=', $this->left2)->first();
        if ($this->left3 != '')
            $this->left3 = @News::where('id', '=', $this->left3)->first();
        if ($this->left4 != '')
            $this->left4 = @News::where('id', '=', $this->left4)->first();
        if ($this->left5 != '')
            $this->left5 = @News::where('id', '=', $this->left5)->first();
        if ($this->right1 != '')
            $this->right1 = @News::where('id', '=', $this->right1)->first();
        if ($this->right2 != '')
            $this->right2 = @News::where('id', '=', $this->right2)->first();
        if ($this->right3 != '')
            $this->right3 = @News::where('id', '=', $this->right3)->first();
        if ($this->right4 != '')
            $this->right4 = @News::where('id', '=', $this->right4)->first();
        if ($this->right5 != '')
            $this->right5 = @News::where('id', '=', $this->right5)->first();

    }

    function hasSlider($type)
    {
        $tot = 0;
        if ($type == 'left')
        {
            if(isset($this->left1) && $this->left1 != '')
                $tot += 1;
            if(isset($this->left2) && $this->left2 != '')
                $tot += 1;
            if(isset($this->left3) && $this->left3 != '')
                $tot += 1;
            if(isset($this->left4) && $this->left4 != '')
                $tot += 1;
            if(isset($this->left5) && $this->left5 != '')
                $tot += 1;
        }
        if ($type == 'right')
        {
            if(isset($this->right1) && $this->right1 != '')
                $tot += 1;
            if(isset($this->right2) && $this->right2 != '')
                $tot += 1;
            if(isset($this->right3) && $this->right3 != '')
                $tot += 1;
            if(isset($this->right4) && $this->right4 != '')
                $tot += 1;
            if(isset($this->right5) && $this->right5 != '')
                $tot += 1;
        }
        return $tot > 1;
    }

}
