Files
gestalt/kernel/app_modules/event/models/Event.php
2025-06-18 14:50:18 +03:00

110 lines
2.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace kernel\app_modules\event\models;
use DateTime;
use Illuminate\Database\Eloquent\Model;
use kernel\helpers\Debug;
// Добавить @property
/**
* @property int $id
* @property int $status
* @property int $hours_count
* @property string $title
* @property string $type
* @property string $date_start
* @property string $dateStartFormated
* @property string $dateStartFormatedToForm
* @property string $dateEndFormatedToForm
* @property string $dateEndFormated
* @property string $date_end
* @property string $place
* @property string $event_format
* @property string $description
* @property string $additional_info
*/
class Event extends Model
{
const DISABLE_STATUS = 0;
const ACTIVE_STATUS = 1;
protected $table = 'event';
protected $fillable = ['title', 'type', 'hours_count', 'date_start', 'date_end', 'place', 'event_format', 'description', 'additional_info', 'status'];
public static function labels(): array
{
return [
'title' => 'Название',
'type' => 'Тип',
'hours_count' => 'Количество часов',
'date_start' => 'Дата начала',
'date_end' => 'Дата окончания',
'place' => 'Место',
'event_format' => 'Формат',
'description' => 'Описание',
'additional_info' => 'Дополнительная информация',
'status' => 'Статус',
];
}
/**
* @return string[]
*/
public static function getStatus(): array
{
return [
self::DISABLE_STATUS => "Не активный",
self::ACTIVE_STATUS => "Активный",
];
}
public function contacts(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(EventContact::class);
}
/**
* @throws \Exception
*/
public function getDateStartFormatedAttribute(): string
{
$startDate = new DateTime($this->date_start);
return $startDate->format("d-m-Y");
}
/**
* @throws \Exception
*/
public function getDateStartFormatedToFormAttribute(): string
{
$startDate = new DateTime($this->date_start);
return $startDate->format("Y-m-d");
}
/**
* @throws \Exception
*/
public function getDateEndFormatedAttribute(): string
{
$endDate = new DateTime($this->date_end);
return $endDate->format("d-m-Y");
}
/**
* @throws \Exception
*/
public function getDateEndFormatedToFormAttribute(): string
{
$endDate = new DateTime($this->date_end);
return $endDate->format("Y-m-d");
}
}