167 lines
4.5 KiB
PHP
167 lines
4.5 KiB
PHP
<?php
|
|
|
|
|
|
namespace app\models;
|
|
|
|
use app\services\Formatter;
|
|
use app\services\ViewReg;
|
|
use yii\base\BaseObject;
|
|
|
|
/** Class Expositions
|
|
* @package app\models
|
|
* @property $id
|
|
* @property $name
|
|
* @property $annotation
|
|
* @property $description
|
|
* @property $info_center
|
|
* @property $info_center_address
|
|
* @property $ts_en_name
|
|
* @property $ts_en_annotation
|
|
* @property $ts_en_description
|
|
* @property $ts_en_info_center
|
|
* @property $ts_en_info_center_address
|
|
* @property $media_key
|
|
* @property $publish_date
|
|
* @property $category_id
|
|
* @property $is_active
|
|
* @property $on_partner_page
|
|
* @property $partner_id
|
|
* @property $is_selected
|
|
* @property \app\models\ExpositionsTagsExpositions[] $expositionsTags
|
|
* @property \app\models\ExpositionsObjects[] $objectList
|
|
* @property \app\models\ExpositionsTagsExpositions[] $expositionTags;
|
|
*/
|
|
class Expositions extends _Base
|
|
{
|
|
public function getPartner()
|
|
{
|
|
return $this->hasOne(Partner::class, ['id' => 'partner_id']);
|
|
}
|
|
|
|
public function title()
|
|
{
|
|
if (\Yii::$app->language == 'en') {
|
|
return $this->ts_en_name;
|
|
} else {
|
|
return $this->name;
|
|
}
|
|
}
|
|
|
|
public function textShort()
|
|
{
|
|
if (\Yii::$app->language == 'en') {
|
|
return $this->ts_en_annotation;
|
|
} else {
|
|
return $this->annotation;
|
|
}
|
|
}
|
|
|
|
public function textDescription()
|
|
{
|
|
if (\Yii::$app->language == 'en') {
|
|
return $this->ts_en_description;
|
|
} else {
|
|
return $this->description;
|
|
}
|
|
}
|
|
|
|
public function getImg()
|
|
{
|
|
if ($this->media_key) {
|
|
return $this->getSrcOfFirstImage('title_expositions_images', '16:11');
|
|
}
|
|
return '/_public/images/empty.png';
|
|
}
|
|
|
|
public function getSqImg()
|
|
{
|
|
if ($this->media_key) {
|
|
return $this->getSrcOfFirstImage('title_expositions_images', '1:1') . '?time='.time();
|
|
}
|
|
return '/_public/images/empty.png';
|
|
}
|
|
|
|
public function images()
|
|
{
|
|
if ($this->media_key) {
|
|
return $this->getSrcOfMultipleImages('title_expositions_images', '16:11');
|
|
}
|
|
return ['/_public/images/empty.png'];
|
|
}
|
|
|
|
public function imagesObjectArray()
|
|
{
|
|
if ($this->media_key) {
|
|
$images = [];
|
|
foreach ($this->getSrcOfMultipleImages('title_expositions_images', '16:11') as $id => $img) {
|
|
$images[] = (object)[
|
|
'id' => $id + 1,
|
|
'img' => $img
|
|
];
|
|
}
|
|
return $images;
|
|
}
|
|
return ['id'=> 1, 'img' => '/_public/images/empty.png'];
|
|
}
|
|
|
|
public function getUrl()
|
|
{
|
|
$slug = \Yii::$app->language == 'bg' ? 'ekspozitsii' : 'expositions';
|
|
return '/' . \Yii::$app->language . '/' . ViewReg::partnerSite() . $slug . '/' . Formatter::encodeId($this->id) . '-' . Formatter::cyrillicTrans($this->name);
|
|
}
|
|
|
|
|
|
public function getExpositionsTags()
|
|
{
|
|
return $this->hasMany(ExpositionsTagsExpositions::class, ['exposition_id' => 'id']);
|
|
}
|
|
|
|
public function getObjectList()
|
|
{
|
|
return $this->hasMany(ExpositionsObjects::class, ['exposition_id' => 'id']);
|
|
}
|
|
|
|
public static function getTagList()
|
|
{
|
|
$selected = [];
|
|
$tags = [];
|
|
foreach (ExpositionsTags::find()->orderBy([\Yii::$app->language == 'en' ? 'name_en' : 'name' => SORT_ASC])->all() as $objectTemplate) {
|
|
$tags[] = [
|
|
'id' => $objectTemplate->id,
|
|
'name' => \Yii::$app->language == 'en' ? $objectTemplate->name_en : $objectTemplate->name,
|
|
'selected' => in_array($objectTemplate->id, $selected) ? 'selected' : ''
|
|
];
|
|
}
|
|
return $tags;
|
|
}
|
|
|
|
public function updateExpositionTags($tag_list = [])
|
|
{
|
|
$related = ExpositionsTagsExpositions::find()->where(['exposition_id' => $this->id])->all();
|
|
$remain = [];
|
|
foreach ($related as $etx) {
|
|
if (in_array($etx->id, $tag_list)) {
|
|
$remain[] = $etx->id;
|
|
} else {
|
|
$etx->delete();
|
|
}
|
|
}
|
|
foreach ($tag_list as $id) {
|
|
if (!in_array($id, $remain)) {
|
|
$new = new ExpositionsTagsExpositions();
|
|
$new->exposition_id = $this->id;
|
|
$new->exposition_tag_id = $id;
|
|
$new->save();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public function getExpositionTags()
|
|
{
|
|
return $this->hasMany(ExpositionsTagsExpositions::class, ['exposition_id' => 'id']);
|
|
}
|
|
|
|
|
|
}
|