fixed ticket display
This commit is contained in:
@@ -316,21 +316,15 @@ final class TicketShow extends Component
|
|||||||
]) ?? $ticket;
|
]) ?? $ticket;
|
||||||
|
|
||||||
$this->hydrateTicketUsers($ticket);
|
$this->hydrateTicketUsers($ticket);
|
||||||
|
$comments = $ticket->comments()
|
||||||
$comments = Comment::query()
|
->active()
|
||||||
->where('ticket_id', $ticket->id)
|
|
||||||
->when(Schema::hasColumn('helpdesk_comments', 'deleted_at'), static function ($query): void {
|
|
||||||
$query->whereNull('deleted_at');
|
|
||||||
})
|
|
||||||
->when(Schema::hasColumn('helpdesk_comments', 'tombstoned_at'), static function ($query): void {
|
|
||||||
$query->whereNull('tombstoned_at');
|
|
||||||
})
|
|
||||||
->when(! $this->canSeeInternalNotes(), static function ($query): void {
|
->when(! $this->canSeeInternalNotes(), static function ($query): void {
|
||||||
$query->where('is_internal', false);
|
$query->where('is_internal', false);
|
||||||
})
|
})
|
||||||
->with(['user.company', 'attachments'])
|
->with(['user.company', 'attachments', 'replies.user.company', 'replies.attachments'])
|
||||||
->oldest()
|
->oldest()
|
||||||
->get();
|
->get();
|
||||||
|
$ticket->setRelation('comments', $comments);
|
||||||
|
|
||||||
$ticket->setAttribute('public_replies_count', $comments->where('is_internal', false)->count());
|
$ticket->setAttribute('public_replies_count', $comments->where('is_internal', false)->count());
|
||||||
$ticket->setAttribute('time_spent_minutes', $this->sumCommentMinutes($comments));
|
$ticket->setAttribute('time_spent_minutes', $this->sumCommentMinutes($comments));
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use App\Models\User;
|
|||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
|
||||||
final class Comment extends Model
|
final class Comment extends Model
|
||||||
{
|
{
|
||||||
@@ -64,7 +65,9 @@ final class Comment extends Model
|
|||||||
/** @return HasMany<Comment> */
|
/** @return HasMany<Comment> */
|
||||||
public function replies(): HasMany
|
public function replies(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(self::class, 'parent_id')->oldest();
|
return $this->hasMany(self::class, 'parent_id')
|
||||||
|
->active()
|
||||||
|
->oldest();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return BelongsTo<User, Comment> */
|
/** @return BelongsTo<User, Comment> */
|
||||||
@@ -84,4 +87,15 @@ final class Comment extends Model
|
|||||||
{
|
{
|
||||||
return $this->hasMany(Attachment::class, 'comment_id');
|
return $this->hasMany(Attachment::class, 'comment_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @param Builder<Comment> $query */
|
||||||
|
|
||||||
|
public function scopeActive(Builder $query): Builder
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
return $query->whereNull('tombstoned_at');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user