Files
Admin Nasledstvo ac168868ee Initial import
2026-05-01 20:52:04 +03:00

219 lines
5.6 KiB
PHP

<?php
namespace app\models;
use app\models\parsed\ArticleParsedInterface;
use app\models\parsed\CartInterface;
use app\models\parsed\CartModel;
use app\services\ViewReg;
/**
* Class Events
* @package app\models
* @property $type
* @property $location
* @property $title
* @property $text
* @property $text_short
* @property $ts_en_location
* @property $ts_en_title
* @property $ts_en_text
* @property $ts_en_text_short
* @property $media_key
* @property $stream_url
* @property $stream_access
* @property $stream_purchase_type
* @property $stream_price
* @property $partner_id
* @property Partner $partner
* @property $event_dates
* @property $is_for_publish
* @property $max_visitors
* @property $daily_open_time
* @property $price_objects
* @property $article_key
*/
class Events extends _Base implements ArticleParsedInterface
{
public function getPartner()
{
return $this->hasOne(Partner::class, ['id' => 'partner_id']);
}
public static function eventTypes($type = null, $locale = null)
{
$types = [
'simple' => 'Обикновенно събитие',
'online' => 'Дигитално събитие',
'booking' => 'Събитие на място с резервация'
];
if ($locale == 'en') {
$types = [
'simple' => 'Simple event',
'online' => 'Digital event',
'booking' => 'Event on site with reservation'
];
}
if ($type)
return mb_strtolower($types[$type]) ?? null;
return $types;
}
public function getEventType($text = false)
{
$type = $this->type ?? ($_GET['type'] ?? null);
if ($text)
$type = self::eventTypes($type);
return $type;
}
public static function getModel()
{
if (!empty($_GET['id'])) {
return self::findOne($_GET['id']);
} else {
return new Events();
}
}
public function get_stream_purchase_type()
{
return $this->stream_purchase_type ?? 'individual_price';
}
public function get_stream_access()
{
return $this->stream_access ?? 1;
}
public function getPrice_objects()
{
return $this->hasMany(PriceObject::class, ['event_id' => 'id']);
}
public function id()
{
return $this->id;
}
public function title($lg = null)
{
$lg = $lg ?? \Yii::$app->language;
return $lg == 'en' ? ($this->ts_en_title ?? $this->title) : $this->title;
}
public function text()
{
return \Yii::$app->language == 'en' ? $this->ts_en_text : $this->text;
}
public function textShort()
{
return \Yii::$app->language == 'en' ? $this->ts_en_text_short : $this->text_short;
}
public function image($rez = null)
{
return $this->getSrcOfSingleImage('title_event_image', $rez);
}
public function images($rez = null)
{
return $this->getSrcOfMultipleImages('event_images', $rez);
}
public function relation()
{
return ViewReg::generateDirectDetailPageUrl($this, 'events');
}
public function getFormattedDates()
{
$dates = explode(',', $this->event_dates);
sort($dates);
$first = date_create($dates[0]);
$last = date_create($dates[sizeof($dates) - 1]);
//return $first->format('d.m.Y');
$interval = date_diff($first, $last);
$days = (int)$interval->format('%a') - 1;
if ($days == sizeof($dates) - 2) {
if ($first->format('d.m.Y') == $last->format('d.m.Y')) {
return $first->format('d.m.Y');
}
{
return $first->format('d.m.Y') . ' - ' . $last->format('d.m.Y');
}
} else {
$reorder = [];
foreach ($dates as $date) {
$reorder[] = date_create($date)->format('d.m.Y');
}
return implode(', ', $reorder);
}
}
public function getPlace()
{
return \Yii::$app->language == 'en' ? $this->ts_en_location : $this->location;
}
public function isBookingAvailable()
{
if ($this->event_dates) {
$dates = explode(',', $this->event_dates);
sort($dates);
$lastDate = date_create($dates[sizeof($dates) - 1]. ' 22:36:00');
if(date_create() <= $lastDate) {
return true;
}
}
}
public function eventDatesArray()
{
if ($this->event_dates) {
$dates = explode(',', $this->event_dates);
sort($dates);
return $dates;
}
}
public function eventTimesArray() {
if($this->daily_open_time) {
$times = explode('-', $this->daily_open_time);
$start = explode(':', $times[0]);
$end = explode(':', $times[1]);
$start_h = (int)$start[0];
$start_i = (int)$start[1];
$end_h = (int)$end[0];
$end_i = (int)$end[1];
$minute_step = 5;
$steps = [$times[0]];
while (true) {
if($start_i < 60) {
$h = sprintf('%02d', $start_h);
$i = sprintf('%02d', $start_i);
$steps[] = "$h:$i";
$start_i += $minute_step;
} else {
$start_h++;
$start_i = 0;
}
if($start_h == $end_h && $start_i == $end_i) {
array_shift($steps);
return $steps;
}
}
}
}
}