mein-sterntours/app/Models/IQContentTreeNode.php
Phase-1-Rollback-Agent e3dc1afd8e WIP: Sicherheitsnetz vor Phase-1-R\u00fcckbau
Enth\u00e4lt gemischt: Laravel-10-Upgrade + Phase 1 (Contacts-Modul, Duplicats-Commands,
Soft-Delete+Merge-Fields) + Phase 2 Code-Umstellungen (inquiry_id, $table='contacts'/'inquiries')
+ Offers-Modul (Migrationen, Models, offer_id in Booking, offer-Disk in filesystems.php).

Phase 2 + Offers werden im folgenden Commit nach dev/backups/phase2-offers-2026-04-17/
verschoben, damit der Workspace auf Phase-1-only (= Test-System-Stand) reduziert ist
und direkt auf Live deploybar wird.

Tarball-Backup zus\u00e4tzlich unter: ../backups-safety/workspace-pre-phase1-rollback-2026-04-17.tar.gz

Made-with: Cursor
2026-04-17 13:40:31 +00:00

190 lines
7.6 KiB
PHP

<?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()
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\IQContentSite[] $iq_content_site
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\IQContentSite[] $iq_content_sites
* @property-read int|null $iq_content_sites_count
* @property-read int|null $iq_content_tree_node_childs_count
* @property string|null $title
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IQContentTreeNode whereTitle($value)
* @property array|null $image
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IQContentTreeNode whereImage($value)
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\IQContentFaq[] $iq_content_faq
* @property-read int|null $iq_content_faq_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\IQContentFaq[] $iq_content_faqs
* @property-read int|null $iq_content_faqs_count
* @method static \Illuminate\Database\Eloquent\Builder|IQContentTreeNode withUniqueSlugConstraints(\Illuminate\Database\Eloquent\Model $model, string $attribute, array $config, string $slug)
* @mixin \Eloquent
*/
class IQContentTreeNode extends Model
{
use Sluggable;
use SoftDeletes;
protected $connection = 'mysql_stern';
protected $table = 'i_q_content_tree_nodes';
protected $fillable = [
'tree_id', 'parent_id', 'lvl', 'name', 'identifier', 'title', 'description', 'settings', 'image', 'pos', 'active',
];
protected $casts = ['settings' => 'array', 'image' => 'array',
'deleted_at' => 'datetime',
];
public function sluggable(): array
{
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')->orderBy('pos', 'ASC');
}
public function iq_content_sites()
{
return $this->hasMany('App\Models\IQContentSite', 'tree_node_id', 'id');
}
public function iq_content_faqs()
{
return $this->hasMany('App\Models\IQContentFaq', 'tree_node_id', 'id');
}
public function iq_content_site_first()
{
foreach ($this->iq_content_sites as $iq_content_site) {
if (isset($iq_content_site->travel_guide) && $iq_content_site->travel_guide->active) {
return $iq_content_site->travel_guide;
}
}
}
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 getUrl(){
return config('app.url_stern')."/".$this->getUri();
}
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."/";
}
}
public function getImage($key){
if(isset($this->image[$key])){
return $this->image[$key];
}
return "";
}
public static function getTreeNodeOptions($tree_id, $id = false, $html = true, $choose = true) {
$values = [];
$ret = "";
$models = IQContentTreeNode::where('tree_id', $tree_id)->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 . '</option>\n';
}
return $ret;
}else{
foreach ($models as $model) {
$values[$model->id] = $model->name;
}
return $values;
}
return false;
}
//
}