2025-07-05 02:19:59 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @method static create(array $validated)
|
2025-07-05 18:26:04 +02:00
|
|
|
* @method static findMany(mixed $channel_ids)
|
|
|
|
|
* @property integer $id
|
|
|
|
|
* @property integer $platform_instance_id
|
2025-07-05 02:19:59 +02:00
|
|
|
* @property PlatformInstance $platformInstance
|
2025-07-05 18:26:04 +02:00
|
|
|
* @property integer $channel_id
|
|
|
|
|
* @property string $name
|
|
|
|
|
* @property int $language_id
|
|
|
|
|
* @property Language $language
|
|
|
|
|
* @property boolean $is_active
|
2025-07-05 02:19:59 +02:00
|
|
|
*/
|
2025-07-05 02:29:50 +02:00
|
|
|
class PlatformChannel extends Model
|
2025-07-05 02:19:59 +02:00
|
|
|
{
|
2025-07-05 02:29:50 +02:00
|
|
|
protected $table = 'platform_channels';
|
2025-07-05 18:26:04 +02:00
|
|
|
|
2025-07-05 02:19:59 +02:00
|
|
|
protected $fillable = [
|
|
|
|
|
'platform_instance_id',
|
|
|
|
|
'name',
|
|
|
|
|
'display_name',
|
2025-07-05 02:29:50 +02:00
|
|
|
'channel_id',
|
2025-07-05 02:19:59 +02:00
|
|
|
'description',
|
2025-07-05 18:26:04 +02:00
|
|
|
'language_id',
|
2025-07-05 02:19:59 +02:00
|
|
|
'is_active'
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'is_active' => 'boolean'
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public function platformInstance(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(PlatformInstance::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function platformAccounts(): BelongsToMany
|
|
|
|
|
{
|
2025-07-05 02:29:50 +02:00
|
|
|
return $this->belongsToMany(PlatformAccount::class, 'platform_account_channels')
|
2025-07-05 02:19:59 +02:00
|
|
|
->withPivot(['is_active', 'priority'])
|
|
|
|
|
->withTimestamps();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getFullNameAttribute(): string
|
|
|
|
|
{
|
2025-07-05 02:29:50 +02:00
|
|
|
// For Lemmy, use /c/ prefix. Other platforms may use different formats
|
|
|
|
|
$prefix = $this->platformInstance->platform === 'lemmy' ? '/c/' : '/';
|
|
|
|
|
return $this->platformInstance->url . $prefix . $this->name;
|
2025-07-05 02:19:59 +02:00
|
|
|
}
|
2025-07-05 18:26:04 +02:00
|
|
|
|
|
|
|
|
public function feeds(): BelongsToMany
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(Feed::class, 'feed_platform_channels')
|
|
|
|
|
->withPivot(['is_active', 'priority', 'filters'])
|
|
|
|
|
->withTimestamps();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function activeFeeds(): BelongsToMany
|
|
|
|
|
{
|
|
|
|
|
return $this->feeds()
|
|
|
|
|
->wherePivot('is_active', true)
|
|
|
|
|
->orderByPivot('priority', 'desc');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function language(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Language::class);
|
|
|
|
|
}
|
2025-07-05 02:19:59 +02:00
|
|
|
}
|