/
DATKAI
/
ITCUP
Обзор
Документация
Войти
/
DATKAI
/
ITCUP
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
app/Models/JournalEntry.php
116 строк
3 KB
DATKAI
feat(journal): журнал инцидентов и работ ИТ-службы
03 июл 2026, 06:58
03 июл 2026, 06:58
8a04f3e
Код
Авторство
О чём код?
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\MorphTo; class JournalEntry extends Model { protected $fillable = [ 'title', 'description', 'kind', 'severity', 'status', 'branch_id', 'location_id', 'started_at', 'resolved_at', 'source', 'subject_type', 'subject_id', 'user_id', 'resolution', ]; protected $casts = [ 'started_at' => 'datetime', 'resolved_at' => 'datetime', ]; public const KINDS = [ 'incident' => 'Инцидент', 'maintenance' => 'Плановые работы', 'change' => 'Изменение', 'note' => 'Заметка', ]; public const KIND_COLORS = [ 'incident' => 'danger', 'maintenance' => 'info', 'change' => 'warning', 'note' => 'gray', ]; public const KIND_ICONS = [ 'incident' => 'heroicon-o-exclamation-triangle', 'maintenance' => 'heroicon-o-wrench-screwdriver', 'change' => 'heroicon-o-arrows-right-left', 'note' => 'heroicon-o-pencil-square', ]; public const SEVERITIES = [ 'critical' => 'Критический', 'high' => 'Высокий', 'medium' => 'Средний', 'low' => 'Низкий', ]; public const SEVERITY_COLORS = [ 'critical' => 'danger', 'high' => 'warning', 'medium' => 'info', 'low' => 'gray', ]; public const STATUSES = [ 'open' => 'Открыто', 'in_progress' => 'В работе', 'resolved' => 'Решено', ]; public const STATUS_COLORS = [ 'open' => 'danger', 'in_progress' => 'warning', 'resolved' => 'success', ]; public const SOURCES = [ 'manual' => 'Вручную', 'monitoring' => 'Мониторинг', ]; public function branch(): BelongsTo { return $this->belongsTo(Branch::class); } public function location(): BelongsTo { return $this->belongsTo(Location::class); } public function user(): BelongsTo { return $this->belongsTo(User::class); } public function subject(): MorphTo { return $this->morphTo(); } /** Длительность (человекочитаемо): от начала до решения или до сейчас */ public function durationHuman(): ?string { if (!$this->started_at) { return null; } $end = $this->resolved_at ?? now(); return $this->started_at->diffForHumans($end, true, false, 2); } /** Пометить решённым */ public function resolve(?string $resolution = null): void { $this->update([ 'status' => 'resolved', 'resolved_at' => $this->resolved_at ?? now(), 'resolution' => $resolution ?: $this->resolution, ]); } }