98 lines
2.2 KiB
PHP
98 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Database\Factories\TicketFactory;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
#[Fillable([
|
|
'acceptance_criteria',
|
|
'board_column_id',
|
|
'blocked_comment',
|
|
'description',
|
|
'is_blocked',
|
|
'parent_ticket_id',
|
|
'project_id',
|
|
'sequence_number',
|
|
'ticket_key',
|
|
'ticket_priority_id',
|
|
'ticket_type_id',
|
|
'title',
|
|
'story_points',
|
|
])]
|
|
class Ticket extends Model
|
|
{
|
|
/** @use HasFactory<TicketFactory> */
|
|
use HasFactory;
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'is_blocked' => 'boolean',
|
|
];
|
|
}
|
|
|
|
public function boardColumn(): BelongsTo
|
|
{
|
|
return $this->belongsTo(BoardColumn::class);
|
|
}
|
|
|
|
public function childTickets(): HasMany
|
|
{
|
|
return $this->hasMany(Ticket::class, 'parent_ticket_id')
|
|
->orderBy('sequence_number');
|
|
}
|
|
|
|
public function fieldValues(): HasMany
|
|
{
|
|
return $this->hasMany(TicketFieldValue::class)
|
|
->orderBy('ticket_field_definition_id');
|
|
}
|
|
|
|
public function parentTicket(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Ticket::class, 'parent_ticket_id');
|
|
}
|
|
|
|
public function ticketLinksAsSource(): HasMany
|
|
{
|
|
return $this->hasMany(TicketLink::class, 'source_ticket_id')
|
|
->orderBy('id');
|
|
}
|
|
|
|
public function ticketLinksAsTarget(): HasMany
|
|
{
|
|
return $this->hasMany(TicketLink::class, 'target_ticket_id')
|
|
->orderBy('id');
|
|
}
|
|
|
|
public function project(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Project::class);
|
|
}
|
|
|
|
public function ticketPriority(): BelongsTo
|
|
{
|
|
return $this->belongsTo(TicketPriority::class);
|
|
}
|
|
|
|
public function ticketType(): BelongsTo
|
|
{
|
|
return $this->belongsTo(TicketType::class);
|
|
}
|
|
|
|
public function worklogEntries(): HasMany
|
|
{
|
|
return $this->hasMany(TicketWorklogEntry::class)
|
|
->orderByDesc('created_at')
|
|
->orderByDesc('id');
|
|
}
|
|
}
|