144 lines
5.4 KiB
PHP
144 lines
5.4 KiB
PHP
<?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\TravelGuide findSimilarSlugs($attribute, $config, $slug)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelGuide whereActive($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelGuide whereCreatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelGuide whereFullText($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelGuide whereId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelGuide whereMetaDescription($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelGuide whereMetaKeywords($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelGuide whereMetaTitle($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelGuide whereName($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelGuide wherePos($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelGuide whereScope($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelGuide whereSlug($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelGuide whereText($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelGuide whereUpdatedAt($value)
|
|
* @mixin \Eloquent
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelGuide newModelQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelGuide newQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelGuide query()
|
|
* @property string|null $keyword
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\IQContentSite[] $iq_content_site
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelGuide whereKeyword($value)
|
|
* @property int|null $country_id
|
|
* @property string|null $box_image_url
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\IQContentSite[] $iq_content_sites
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelGuide whereBoxImageUrl($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelGuide whereCountryId($value)
|
|
* @property-read int|null $iq_content_sites_count
|
|
*/
|
|
class TravelGuide extends Model
|
|
{
|
|
|
|
use Sluggable;
|
|
|
|
|
|
//use the connection to sec. Datebase sterntours
|
|
protected $connection = 'mysql_stern';
|
|
|
|
protected $table = 'travel_guides';
|
|
|
|
|
|
protected static $scopes = [
|
|
0 => 'Kurze Version',
|
|
1 => 'Lange Version',
|
|
];
|
|
|
|
protected $fillable = [
|
|
'name', 'slug', 'text', 'full_text', 'author_id', 'keyword', 'meta_title', 'meta_description', 'meta_keywords', 'country_id', 'box_image_url', 'pos', 'scope', 'active',
|
|
];
|
|
|
|
|
|
public function sluggable()
|
|
{
|
|
return [
|
|
'slug' => [
|
|
'source' => 'name'
|
|
]
|
|
];
|
|
}
|
|
|
|
|
|
public function iq_content_sites()
|
|
{
|
|
return $this->hasMany('App\Models\IQContentSite', 'travel_guide_id', 'id');
|
|
}
|
|
|
|
public function iq_content_tree_node_first()
|
|
{
|
|
foreach ($this->iq_content_sites as $iq_content_site) {
|
|
if (isset($iq_content_site->iq_content_tree_node) && $iq_content_site->iq_content_tree_node->active) {
|
|
return $iq_content_site->iq_content_tree_node;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function author()
|
|
{
|
|
return $this->belongsTo('App\Models\Author', 'author_id', 'id');
|
|
}
|
|
|
|
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] : '';
|
|
}
|
|
|
|
|
|
public static function getSiteOptions($id = false, $html = true, $choose = true) {
|
|
|
|
$values = [];
|
|
$ret = "";
|
|
$models = TravelGuide::where('active', 1)->get();
|
|
|
|
if($html) {
|
|
if($choose){
|
|
$ret .= '<option value="">Bitte wählen</option>\n';
|
|
}
|
|
foreach ($models as $model) {
|
|
$attr = ($model->id == $id) ? ' selected="selected"' : '';
|
|
$ret .= '<option value="' . $model->id . '"' . $attr . '>' . $model->name . ' ('.$model->getScopeName($model->scope).')</option>\n';
|
|
}
|
|
return $ret;
|
|
}else{
|
|
foreach ($models as $model) {
|
|
$values[$model->id] = $model->name;
|
|
}
|
|
return $values;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
}
|