feat: add plugin model

initial implementation of playlist

feat: added support for playlists
This commit is contained in:
Benjamin Nussbaum 2025-03-11 22:34:28 +01:00
parent 276511fc98
commit 4195269414
17 changed files with 669 additions and 15 deletions

View file

@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Device extends Model
{
@ -50,4 +51,29 @@ class Device extends Model
return 3; // Strong signal (3 bars)
}
}
public function playlists(): HasMany
{
return $this->hasMany(Playlist::class);
}
public function getNextPlaylistItem(): ?PlaylistItem
{
// Get all active playlists
$playlists = $this->playlists()
->where('is_active', true)
->get();
// Find the first active playlist with an available item
foreach ($playlists as $playlist) {
if ($playlist->isActiveNow()) {
$nextItem = $playlist->getNextPlaylistItem();
if ($nextItem) {
return $nextItem;
}
}
}
return null;
}
}