Tree Travel Guide

This commit is contained in:
Kevin Adametz 2019-07-20 15:55:00 +02:00
parent a1ca534f55
commit 1f340e96fa
78 changed files with 4133 additions and 1027 deletions

View file

@ -0,0 +1,127 @@
<?php
namespace App\Models;
use Cviebrock\EloquentSluggable\Sluggable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Str;
/**
* App\Models\IQContentTreeNode
*
* @property int $id
* @property int $tree_id
* @property int|null $parent_id
* @property int $lvl
* @property string $name
* @property string $identifier
* @property string $slug
* @property string|null $description
* @property array|null $settings
* @property int $pos
* @property int $active
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property \Illuminate\Support\Carbon|null $deleted_at
* @property-read \App\Models\IQContentTree $iq_content_tree
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\IQContentTreeNode[] $iq_content_tree_node_childs
* @property-read \App\Models\IQContentTreeNode|null $iq_content_tree_node_parent
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IQContentTreeNode findSimilarSlugs($attribute, $config, $slug)
* @method static bool|null forceDelete()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IQContentTreeNode newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IQContentTreeNode newQuery()
* @method static \Illuminate\Database\Query\Builder|\App\Models\IQContentTreeNode onlyTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IQContentTreeNode query()
* @method static bool|null restore()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IQContentTreeNode whereActive($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IQContentTreeNode whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IQContentTreeNode whereDeletedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IQContentTreeNode whereDescription($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IQContentTreeNode whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IQContentTreeNode whereIdentifier($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IQContentTreeNode whereLvl($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IQContentTreeNode whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IQContentTreeNode whereParentId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IQContentTreeNode wherePos($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IQContentTreeNode whereSettings($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IQContentTreeNode whereSlug($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IQContentTreeNode whereTreeId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IQContentTreeNode whereUpdatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\App\Models\IQContentTreeNode withTrashed()
* @method static \Illuminate\Database\Query\Builder|\App\Models\IQContentTreeNode withoutTrashed()
* @mixin \Eloquent
*/
class IQContentTreeNode extends Model
{
use Sluggable;
use SoftDeletes;
protected $connection = 'mysql_stern';
protected $dates = ['deleted_at'];
protected $table = 'i_q_content_tree_nodes';
protected $fillable = [
'tree_id', 'parent_id', 'lvl', 'name', 'identifier', 'description', 'settings', 'pos', 'active',
];
protected $casts = ['settings' => 'array'];
public function sluggable()
{
return [
'slug' => [
'source' => 'name'
]
];
}
public function iq_content_tree()
{
return $this->belongsTo('App\Models\IQContentTree', 'tree_id');
}
public function iq_content_tree_node_parent()
{
return $this->belongsTo('App\Models\IQContentTreeNode', 'parent_id');
}
public function iq_content_tree_node_childs()
{
return $this->hasMany('App\Models\IQContentTreeNode', 'parent_id', 'id');
}
public function travel_guides()
{
return $this->hasMany('App\Models\TravelGuide', 'tree_node_id', 'id');
}
public function setIdentifierAttribute( $value ) {
if(!isset($value) || $value == ""){
$this->attributes['identifier'] = Str::slug(pre_slug($this->name), '-');
}else{
$this->attributes['identifier'] = Str::slug(pre_slug($value), '-');
}
}
public function getUri(){
$root = $this->iq_content_tree->identifier."/";
$ret = $this->getParentIdentifier();
return $root.$ret.$this->identifier."/";
}
public function getParentIdentifier(){
if($node_parent = $this->iq_content_tree_node_parent){
$ret = $node_parent->getParentIdentifier();
return $ret.$node_parent->identifier."/";
}
}
//
}