328 lines
10 KiB
PHP
328 lines
10 KiB
PHP
<?php
|
|
|
|
|
|
namespace app\models;
|
|
|
|
use app\models\parsed\CartInterface;
|
|
use app\models\parsed\CartModel;
|
|
use app\models\register\CityList;
|
|
use app\models\register\ObjectTags;
|
|
use app\models\register\Partner as RegisterPartner;
|
|
use app\models\register\CollectionsObjects;
|
|
use app\services\Cart;
|
|
use app\services\Formatter;
|
|
use app\services\IdServer;
|
|
use app\services\ViewReg;
|
|
|
|
|
|
/**
|
|
* Class RegisterObjects
|
|
* @package app\models
|
|
* @property $ref_num
|
|
* @property $city_id
|
|
* @property $is_payable
|
|
* @property $price
|
|
* @property $lib_type
|
|
* @property $infocenter_email
|
|
* @property $infocenter_website
|
|
* @property $administrative_latitude
|
|
* @property $administrative_longitude
|
|
* @property $partner_id
|
|
* @property $created_year
|
|
* @property $created_by
|
|
* @property $name
|
|
* @property $annotation
|
|
* @property $description
|
|
* @property $short_description
|
|
* @property $location_description
|
|
* @property $admistrative_address
|
|
* @property $temporary_address
|
|
* @property $infocenter_name
|
|
* @property $infocenter_address
|
|
* @property $ts_en_name
|
|
* @property $ts_en_annotation
|
|
* @property $ts_en_description
|
|
* @property $ts_en_short_description
|
|
* @property $ts_en_location_description
|
|
* @property $ts_en_admistrative_address
|
|
* @property $ts_en_temporary_address
|
|
* @property $ts_en_infocenter_name
|
|
* @property $ts_en_infocenter_address
|
|
* @property \app\models\RegisterObjectFields[] $registerObjectFields
|
|
* @property \app\models\RegisterObjectFiles[] $registerObjectFiles
|
|
* @property \app\models\RegisterObjectFiles[] $registerObjectImages
|
|
* @property $date_added
|
|
* @property $date_updated
|
|
* @property $publish_date
|
|
* @property $is_active
|
|
* @property $mainImgFile
|
|
* @property $object_thumbnail_url
|
|
* @property RegisterPartner $partner
|
|
* @property CityList $city
|
|
* @property \app\models\register\CollectionsObjects $collectionsObject
|
|
* @property \app\models\RegisterObjectFiles[] $pdfDocuments
|
|
* @property $pdf
|
|
* @property $cartKey
|
|
* @property $library
|
|
* @property ObjectTags[] $tags
|
|
*/
|
|
class RegisterObjects extends _Base implements CartInterface
|
|
{
|
|
|
|
public function getRegisterObjectFields()
|
|
{
|
|
return $this->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 = '<br>') {
|
|
$tags = [];
|
|
foreach ($this->tags as $objectTag) {
|
|
if($objectTag->tag)
|
|
$tags[] = $objectTag->tag->text;
|
|
}
|
|
return implode($separator, $tags);
|
|
}
|
|
}
|