Initial import
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace app\models;
|
||||
|
||||
use app\models\register\Partner;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @property $event_first_date
|
||||
* @property $event_last_date
|
||||
*/
|
||||
class Events extends _Base
|
||||
{
|
||||
public function getPartner()
|
||||
{
|
||||
return $this->hasOne(Partner::class, ['id' => 'partner_id']);
|
||||
}
|
||||
|
||||
public static function eventTypes($type = null)
|
||||
{
|
||||
$types = [
|
||||
'simple' => 'Обикновено събитие',
|
||||
'online' => 'Дигитално събитие',
|
||||
'booking' => 'Събитие на място с резервация'
|
||||
];
|
||||
if ($type) {
|
||||
if (!empty($types[$type])) {
|
||||
return mb_strtolower($types[$type]) ?? null;
|
||||
} else {
|
||||
header('Location: /');
|
||||
}
|
||||
}
|
||||
return $types;
|
||||
}
|
||||
|
||||
public function getEventType($text = false)
|
||||
{
|
||||
$type = $this->type ?? ($_GET['type'] ?? null);
|
||||
$types = ['simple', 'online', 'booking'];
|
||||
if (!in_array($type, $types))
|
||||
header('Location: /');
|
||||
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 setFirstLast()
|
||||
{
|
||||
if ($this->event_dates) {
|
||||
$dates = explode(',', $this->event_dates);
|
||||
sort($dates);
|
||||
$this->event_first_date = $dates[0];
|
||||
$this->event_last_date = $dates[sizeof($dates) - 1];
|
||||
}
|
||||
}
|
||||
|
||||
public static function getList() {
|
||||
$list = [];
|
||||
foreach(self::find()->all() as $item) {
|
||||
$list[$item->id] = $item->title;
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user