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']); } }