mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-09-06 04:35:11 +02:00
131 lines
3.6 KiB
PHP
131 lines
3.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models\Wiki\Song;
|
|
|
|
use App\Concerns\Models\SoftDeletes;
|
|
use App\Concerns\Models\Submitable;
|
|
use App\Contracts\Models\SoftDeletable;
|
|
use App\Events\Wiki\Song\Membership\MembershipCreated;
|
|
use App\Events\Wiki\Song\Membership\MembershipDeleted;
|
|
use App\Events\Wiki\Song\Membership\MembershipDeleting;
|
|
use App\Events\Wiki\Song\Membership\MembershipRestored;
|
|
use App\Events\Wiki\Song\Membership\MembershipUpdated;
|
|
use App\Models\BaseModel;
|
|
use App\Models\Wiki\Artist;
|
|
use Database\Factories\Wiki\Song\MembershipFactory;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
|
use Illuminate\Support\Collection;
|
|
use OwenIt\Auditing\Auditable as HasAudits;
|
|
use OwenIt\Auditing\Contracts\Auditable;
|
|
|
|
/**
|
|
* @property int $membership_id
|
|
* @property string|null $alias
|
|
* @property string|null $as
|
|
* @property int $artist_id
|
|
* @property Artist $group
|
|
* @property int $member_id
|
|
* @property Artist $member
|
|
* @property Collection<int, Performance> $performances
|
|
*
|
|
* @method static MembershipFactory factory(...$parameters)
|
|
*/
|
|
class Membership extends BaseModel implements Auditable, SoftDeletable
|
|
{
|
|
use HasAudits;
|
|
use HasFactory;
|
|
use SoftDeletes;
|
|
use Submitable;
|
|
|
|
final public const string TABLE = 'memberships';
|
|
|
|
final public const string ATTRIBUTE_ID = 'membership_id';
|
|
final public const string ATTRIBUTE_ARTIST = 'artist_id';
|
|
final public const string ATTRIBUTE_ALIAS = 'alias';
|
|
final public const string ATTRIBUTE_AS = 'as';
|
|
final public const string ATTRIBUTE_MEMBER = 'member_id';
|
|
|
|
final public const string RELATION_GROUP = 'group';
|
|
final public const string RELATION_MEMBER = 'member';
|
|
final public const string RELATION_PERFORMANCES = 'performances';
|
|
|
|
/**
|
|
* The table associated with the model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $table = Membership::TABLE;
|
|
|
|
/**
|
|
* The primary key associated with the table.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $primaryKey = Membership::ATTRIBUTE_ID;
|
|
|
|
/**
|
|
* The event map for the model.
|
|
*
|
|
* Allows for object-based events for native Eloquent events.
|
|
*
|
|
* @var array<string, class-string>
|
|
*/
|
|
protected $dispatchesEvents = [
|
|
'created' => MembershipCreated::class,
|
|
'deleted' => MembershipDeleted::class,
|
|
'deleting' => MembershipDeleting::class,
|
|
'restored' => MembershipRestored::class,
|
|
'updated' => MembershipUpdated::class,
|
|
];
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected $fillable = [
|
|
Membership::ATTRIBUTE_ALIAS,
|
|
Membership::ATTRIBUTE_ARTIST,
|
|
Membership::ATTRIBUTE_AS,
|
|
Membership::ATTRIBUTE_MEMBER,
|
|
];
|
|
|
|
public function getName(): string
|
|
{
|
|
return strval($this->getKey());
|
|
}
|
|
|
|
public function getSubtitle(): string
|
|
{
|
|
return "Member {$this->member->getName()} of Group {$this->group->getName()}";
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Artist, $this>
|
|
*/
|
|
public function group(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Artist::class, Membership::ATTRIBUTE_ARTIST);
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Artist, $this>
|
|
*/
|
|
public function member(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Artist::class, Membership::ATTRIBUTE_MEMBER);
|
|
}
|
|
|
|
/**
|
|
* @return MorphMany<Performance, $this>
|
|
*/
|
|
public function performances(): MorphMany
|
|
{
|
|
return $this->morphMany(Performance::class, Performance::RELATION_ARTIST);
|
|
}
|
|
}
|