<?php

namespace App\Models;

use Cviebrock\EloquentSluggable\Sluggable;
use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\TravelMagazine
 *
 * @property int $id
 * @property string $name
 * @property string $slug
 * @property string|null $text
 * @property string|null $full_text
 * @property string|null $meta_title
 * @property string|null $meta_description
 * @property string|null $meta_keywords
 * @property int|null $pos
 * @property int $scope
 * @property int $active
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelMagazine findSimilarSlugs($attribute, $config, $slug)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelMagazine whereActive($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelMagazine whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelMagazine whereFullText($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelMagazine whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelMagazine whereMetaDescription($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelMagazine whereMetaKeywords($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelMagazine whereMetaTitle($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelMagazine whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelMagazine wherePos($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelMagazine whereScope($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelMagazine whereSlug($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelMagazine whereText($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelMagazine whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class TravelMagazine extends Model
{

    use Sluggable;


    //use the connection to sec. Datebase sterntours
    protected $connection = 'mysql_stern';

    protected $table = 'travel_magazines';


    protected static $scopes = [
        0 => 'Kurze Version',
        1 => 'Lange Version',
    ];

    protected $fillable = [
        'name', 'slug', 'text', 'full_text', 'meta_title', 'meta_description', 'meta_keywords', 'pos', 'scope', 'active',
    ];

    public function sluggable()
    {
        return [
            'slug' => [
                'source' => 'name'
            ]
        ];
    }

    public static function getScopeOptions($setKey = false){
        $options = self::$scopes;
        $ret = "";
        foreach ($options as $key => $option){
            $attr = ($key == $setKey) ? 'selected="selected"' : '';
            $ret .= '<option value="'.$key.'" '.$attr.'>'.$option.'</option>\n';
        }
        return $ret;
    }
    public function getScopeName($key = 0){
        return isset(self::$scopes[$key]) ? self::$scopes[$key] : '';
    }



}
