113 lines
3.0 KiB
PHP
113 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace Modules\ManagementTools\Entities;
|
|
|
|
use App\User;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class MtUserTicket extends Model
|
|
{
|
|
public const STATUS_OPEN = 0;
|
|
|
|
public const STATUS_IN_PROGRESS = 1;
|
|
|
|
public const STATUS_RESOLVED = 2;
|
|
|
|
public const STATUS_CLOSED = 3;
|
|
|
|
protected $table = 'mt_user_tickets';
|
|
|
|
protected $guarded = ['id'];
|
|
|
|
protected $casts = [
|
|
'is_read_by_admin' => 'boolean',
|
|
'is_read_by_user' => 'boolean',
|
|
];
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function assignee()
|
|
{
|
|
return $this->belongsTo(User::class, 'assigned_to');
|
|
}
|
|
|
|
public function replies()
|
|
{
|
|
return $this->hasMany(MtUserTicketReply::class, 'ticket_id')->orderBy('created_at');
|
|
}
|
|
|
|
public function dailyReport()
|
|
{
|
|
return $this->belongsTo(MtDailyReport::class, 'daily_report_id');
|
|
}
|
|
|
|
public function scopeForBusiness($query, $business_id)
|
|
{
|
|
return $query->where('business_id', $business_id);
|
|
}
|
|
|
|
public function scopeOpen($query)
|
|
{
|
|
return $query->whereIn('status', [self::STATUS_OPEN, self::STATUS_IN_PROGRESS]);
|
|
}
|
|
|
|
public static function statuses(): array
|
|
{
|
|
return [
|
|
self::STATUS_OPEN => __('managementtools::lang.ticket_status_open'),
|
|
self::STATUS_IN_PROGRESS => __('managementtools::lang.ticket_status_in_progress'),
|
|
self::STATUS_RESOLVED => __('managementtools::lang.ticket_status_resolved'),
|
|
self::STATUS_CLOSED => __('managementtools::lang.ticket_status_closed'),
|
|
];
|
|
}
|
|
|
|
public static function priorities(): array
|
|
{
|
|
return [
|
|
'low' => __('managementtools::lang.ticket_priority_low'),
|
|
'normal' => __('managementtools::lang.ticket_priority_normal'),
|
|
'high' => __('managementtools::lang.ticket_priority_high'),
|
|
'urgent' => __('managementtools::lang.ticket_priority_urgent'),
|
|
];
|
|
}
|
|
|
|
public function getReferenceAttribute(): string
|
|
{
|
|
return 'TKT-'.str_pad((string) $this->id, 5, '0', STR_PAD_LEFT);
|
|
}
|
|
|
|
public function statusLabel(): string
|
|
{
|
|
return self::statuses()[$this->status] ?? (string) $this->status;
|
|
}
|
|
|
|
public function priorityLabel(): string
|
|
{
|
|
return self::priorities()[$this->priority] ?? $this->priority;
|
|
}
|
|
|
|
public function statusBadgeClass(): string
|
|
{
|
|
return match ((int) $this->status) {
|
|
self::STATUS_OPEN => 'label-warning',
|
|
self::STATUS_IN_PROGRESS => 'label-info',
|
|
self::STATUS_RESOLVED => 'label-success',
|
|
self::STATUS_CLOSED => 'label-default',
|
|
default => 'label-default',
|
|
};
|
|
}
|
|
|
|
public function priorityBadgeClass(): string
|
|
{
|
|
return match ($this->priority) {
|
|
'urgent' => 'label-danger',
|
|
'high' => 'label-warning',
|
|
'low' => 'label-default',
|
|
default => 'label-primary',
|
|
};
|
|
}
|
|
}
|