Initial import
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace app\models;
|
||||
|
||||
use app\models\parsed\ArticleParsedInterface;
|
||||
use app\services\ViewReg;
|
||||
|
||||
/**
|
||||
* Class Campaigns
|
||||
* @package app\models
|
||||
* @property $id
|
||||
* @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 $partner_id
|
||||
* @property Partner $partner
|
||||
* @property $event_dates
|
||||
* @property $is_for_publish
|
||||
* @property $article_key
|
||||
*/
|
||||
class Campaigns extends _Base implements ArticleParsedInterface
|
||||
{
|
||||
public function getPartner() {
|
||||
return $this->hasOne(Partner::class, ['id' => 'partner_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;
|
||||
}
|
||||
|
||||
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_campaigns_image', $rez);
|
||||
}
|
||||
|
||||
public function images($rez = null)
|
||||
{
|
||||
return $this->getSrcOfMultipleImages('campaigns_images', $rez);
|
||||
}
|
||||
|
||||
public function relation()
|
||||
{
|
||||
return ViewReg::generateDirectDetailPageUrl($this, 'campaigns');
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user