89 lines
2.2 KiB
PHP
89 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Database\Factories\ProjectFactory;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
|
use Illuminate\Support\Str;
|
|
|
|
#[Fillable(['name', 'key', 'show_story_points'])]
|
|
class Project extends Model
|
|
{
|
|
/** @use HasFactory<ProjectFactory> */
|
|
use HasFactory;
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'show_story_points' => 'boolean',
|
|
];
|
|
}
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::deleting(function (self $project): void {
|
|
$project->permissionAssignments()->delete();
|
|
});
|
|
}
|
|
|
|
protected function key(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
set: fn (string $value): string => Str::upper(trim($value)),
|
|
);
|
|
}
|
|
|
|
public function permissionAssignments(): MorphMany
|
|
{
|
|
return $this->morphMany(PermissionAssignment::class, 'scope');
|
|
}
|
|
|
|
public function boardColumns(): HasMany
|
|
{
|
|
return $this->hasMany(BoardColumn::class)
|
|
->orderBy('position');
|
|
}
|
|
|
|
public function ticketFieldDefinitions(): HasMany
|
|
{
|
|
return $this->hasMany(TicketFieldDefinition::class)
|
|
->orderBy('position');
|
|
}
|
|
|
|
public function ticketPriorities(): HasMany
|
|
{
|
|
return $this->hasMany(TicketPriority::class)
|
|
->orderBy('position');
|
|
}
|
|
|
|
public function ticketLinkTypes(): HasMany
|
|
{
|
|
return $this->hasMany(TicketLinkType::class)
|
|
->orderBy('position');
|
|
}
|
|
|
|
public function ticketTypes(): HasMany
|
|
{
|
|
return $this->hasMany(TicketType::class)
|
|
->orderBy('position');
|
|
}
|
|
|
|
public function repositoryConnections(): HasMany
|
|
{
|
|
return $this->hasMany(RepositoryConnection::class)
|
|
->orderBy('provider')
|
|
->orderBy('repository_full_name');
|
|
}
|
|
|
|
public function tickets(): HasMany
|
|
{
|
|
return $this->hasMany(Ticket::class)
|
|
->orderByDesc('sequence_number');
|
|
}
|
|
}
|