Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
PlatformChannel
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 7
56
0.00% covered (danger)
0.00%
0 / 1
 platformInstance
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 platformAccounts
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 activePlatformAccounts
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getFullNameAttribute
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 feeds
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 activeFeeds
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 language
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace App\Models;
4
5use Database\Factories\PlatformChannelFactory;
6use Illuminate\Database\Eloquent\Factories\HasFactory;
7use Illuminate\Database\Eloquent\Model;
8use Illuminate\Database\Eloquent\Relations\BelongsTo;
9use Illuminate\Database\Eloquent\Relations\BelongsToMany;
10
11/**
12 * @method static findMany(mixed $channel_ids)
13 * @property integer $id
14 * @property integer $platform_instance_id
15 * @property PlatformInstance $platformInstance
16 * @property integer $channel_id
17 * @property string $name
18 * @property int $language_id
19 * @property Language|null $language
20 * @property boolean $is_active
21 */
22class PlatformChannel extends Model
23{
24    /** @use HasFactory<PlatformChannelFactory> */
25    use HasFactory;
26
27    protected $table = 'platform_channels';
28
29    protected $fillable = [
30        'platform_instance_id',
31        'name',
32        'display_name',
33        'channel_id',
34        'description',
35        'language_id',
36        'is_active'
37    ];
38
39    protected $casts = [
40        'is_active' => 'boolean'
41    ];
42
43    /**
44     * @return BelongsTo<PlatformInstance, $this>
45     */
46    public function platformInstance(): BelongsTo
47    {
48        return $this->belongsTo(PlatformInstance::class);
49    }
50
51    /**
52     * @return BelongsToMany<PlatformAccount, $this>
53     */
54    public function platformAccounts(): BelongsToMany
55    {
56        return $this->belongsToMany(PlatformAccount::class, 'platform_account_channels')
57            ->withPivot(['is_active', 'priority'])
58            ->withTimestamps();
59    }
60
61    /**
62     * @return BelongsToMany<PlatformAccount, $this>
63     */
64    public function activePlatformAccounts(): BelongsToMany
65    {
66        return $this->platformAccounts()->wherePivot('is_active', true);
67    }
68
69    public function getFullNameAttribute(): string
70    {
71        // For Lemmy, use /c/ prefix
72        return $this->platformInstance->url . '/c/' . $this->name;
73    }
74
75    /**
76     * @return BelongsToMany<Feed, $this, Route>
77     */
78    public function feeds(): BelongsToMany
79    {
80        return $this->belongsToMany(Feed::class, 'routes')
81            ->using(Route::class)
82            ->withPivot(['is_active', 'priority', 'filters'])
83            ->withTimestamps();
84    }
85
86    /**
87     * @return BelongsToMany<Feed, $this, Route>
88     */
89    public function activeFeeds(): BelongsToMany
90    {
91        return $this->feeds()
92            ->wherePivot('is_active', true)
93            ->orderByPivot('priority', 'desc');
94    }
95
96    /**
97     * @return BelongsTo<Language, $this>
98     */
99    public function language(): BelongsTo
100    {
101        return $this->belongsTo(Language::class);
102    }
103}