hasMany(RegisterObjectFields::class, ['object_id' => 'id']); } public function getRegisterObjectFiles() { return $this->hasMany(RegisterObjectFiles::class, ['object_id' => 'id']); } public function getRegisterObjectImages() { return $this->hasMany(RegisterObjectFiles::class, ['object_id' => 'id'])->where(['file_content_type' => 2])->all(); } public function getMainImgFile($empty = null) { if($this->object_thumbnail_url) return $this->object_thumbnail_url; /** @var \app\models\RegisterObjectFiles $file */ $file = $this->hasMany(RegisterObjectFiles::class, ['object_id' => 'id']) ->where(['is_thumbnail' => 1]) ->orWhere(['extension' => 'jpg']) ->orWhere(['extension' => 'jpeg']) ->orWhere(['extension' => 'png']) ->orWhere(['extension' => 'tif']) ->one(); if($file) return $file->getResizedImg(); return $empty; //if ($file) return $file->file_url; } public function images($empty = null) { /** @var \app\models\RegisterObjectFiles[] $files */ $files = $this->hasMany(RegisterObjectFiles::class, ['object_id' => 'id']) ->orWhere(['extension' => 'jpg']) ->orWhere(['extension' => 'jpeg']) ->orWhere(['extension' => 'png']) ->orWhere(['extension' => 'tif']) ->all(); $list = []; foreach ($files as $file) { $list[] = IdServer::getImg($file->id) ?? '/_public/images/empty-169.png'; } return $list; } public function getPartner() { return $this->hasOne(RegisterPartner::class, ['id' => 'partner_id']); } public function getCity() { return $this->hasOne(CityList::class, ['id' => 'city_id']); } public function getCollectionsObject() { return $this->hasMany(CollectionsObjects::class, ['object_id' => 'ref_num']); } public function getCollectionsListStr() { $collections = []; /** @var \app\models\register\CollectionsObjects $collectionObject */ foreach ($this->collectionsObject as $collectionObject) { if ($collectionObject->collection) $collections[] = $collectionObject->collection->name; } return implode(',', $collections); } public function getTitle() { return \Yii::$app->language == 'en' ? $this->ts_en_name : $this->name; } public function getAnnotation() { return \Yii::$app->language == 'en' ? $this->ts_en_annotation : $this->annotation; } public function getLongText() { return \Yii::$app->language == 'en' ? $this->ts_en_description : $this->description; } public function getAdmAddress() { return \Yii::$app->language == 'en' ? $this->ts_en_admistrative_address : $this->admistrative_address; } public function getImg($emptyImg = null) { if ($this->getMainImgFile()) return $this->getMainImgFile(); return $emptyImg ? $emptyImg : '/_public/images/empty.png'; } public function getUrl($collection = null) { $lg = \Yii::$app->language; $objects = $lg == 'en' ? 'objects' : 'obekti'; $id = Formatter::encodeId($this->id); $str = "/$lg/" . ViewReg::partnerSite() . "$objects/$id-" . Formatter::cyrillicTrans($this->getTitle()); if ($collection && $collection->id) $str .= '?' . base64_encode($collection->id); return $str; } public function getLibraryUrl($collection = null) { $lg = \Yii::$app->language; $objects = $lg == 'en' ? 'e-library' : 'e-biblioteka'; $id = Formatter::encodeId($this->id); $str = "/$lg/" . ViewReg::partnerSite() . "$objects/$id-" . Formatter::cyrillicTrans($this->getTitle()); if ($collection && $collection->id) $str .= '?' . base64_encode($collection->id); return $str; } public function getCollectionUrl($collection = null) { $lg = \Yii::$app->language; $objects = $lg == 'en' ? 'collections-objects' : 'kolektsii-obekti'; $id = Formatter::encodeId($this->id); $str = "/$lg/" . ViewReg::partnerSite() . "$objects/$id-" . Formatter::cyrillicTrans($this->getTitle()); if ($collection && $collection->id) $str .= '?' . base64_encode($collection->id); return $str; } public function getExpositionUrl($exposition = null) { //return '/'.\Yii::$app->controller->partnerSlug; $lg = \Yii::$app->language; $objects = $lg == 'en' ? 'expositions-objects' : 'ekspozitsii-obekti'; $id = Formatter::encodeId($this->id); $str = "/$lg/" . ViewReg::partnerSite() . "$objects/$id-" . Formatter::cyrillicTrans($this->getTitle()); if ($exposition && $exposition->id) $str .= '?' . base64_encode($exposition->id); return $str; } /** @return RegisterObjectFiles[] */ public function getVideoList() { return $this->hasMany(RegisterObjectFiles::class, ['object_id' => 'id'])->where(['file_content_type' => 3])->all(); } /** @return RegisterObjectFiles[] */ public function get3DModelList() { return $this->hasMany(RegisterObjectFiles::class, ['object_id' => 'id'])->where(['file_content_type' => 4])->all(); } /** @return int */ public function getVideoCount() { return $this->hasMany(RegisterObjectFiles::class, ['object_id' => 'id'])->where(['file_content_type' => 3])->count(); } public function get3DModelCount() { return $this->hasMany(RegisterObjectFiles::class, ['object_id' => 'id'])->where(['file_content_type' => 4])->count(); } public function getPdfDocuments() { return $this->hasMany(RegisterObjectFiles::class, ['object_id' => 'id'])->where(['file_content_type' => 1, 'extension' => 'pdf'])->all(); } public function getInfocenter($key, $translated = true) { if ($translated) { return \Yii::$app->language == 'en' ? $this->{'ts_en_infocenter_' . $key} : $this->{'infocenter_' . $key}; } else { return $this->{'infocenter_' . $key}; } } public function getAnyInfocenter($keys) { $val = []; foreach ($keys as $key => $translated) { if ($translated) { if ($this->{'ts_en_infocenter_' . $key} != null && $this->{'ts_en_infocenter_' . $key} != '') $val[] = \Yii::$app->language == 'en' ? $this->{'ts_en_infocenter_' . $key} : $this->{'infocenter_' . $key}; } else { if ($this->{'infocenter_' . $key} != null && $this->{'infocenter_' . $key} != '') $val[] = $this->{'infocenter_' . $key}; } } return sizeof($val) > 0; } public function getPdf() { return $this->hasMany(RegisterObjectFiles::class, ['object_id' => 'id']) ->where(['file_content_type' => 1, 'extension' => 'pdf']) ->one(); } public function getCartKey() { return Cart::encodeKey('RegisterObjects', $this->id); } public function setCart(CartModel $model) { // TODO: Implement setCart() method. $model->title = $this->getTitle(); $model->subTitle = Ts::get(170); $model->description = $this->getAnnotation(); // $this->getDescription(); $model->singlePrice = number_format($this->price, 2, '.', ' ') . ' лв.'; $model->price = $this->price; $model->availableQuantity = 1; /********************************/ $model->name_bg = $this->name . ' (e-библилиотека)'; $model->name_en = $this->ts_en_name . ' (e-library)'; $model->text_bg = $this->description; $model->text_en = $this->ts_en_description; return $model; } public function getLibrary() { return $this->hasOne(Library::class, ['object_id' => 'id']); } public function getTags() { return $this->hasMany(ObjectTags::class, ['object_id' => 'ref_num']); } public function getTagsList($separator = '
') { $tags = []; foreach ($this->tags as $objectTag) { if($objectTag->tag) $tags[] = $objectTag->tag->text; } return implode($separator, $tags); } }