181 lines
5.2 KiB
PHP
181 lines
5.2 KiB
PHP
<?php
|
|
|
|
|
|
namespace app\models;
|
|
|
|
use app\models\register\CityList;
|
|
use app\models\register\ObjectTags;
|
|
use app\models\register\Partner as RegisterPartner;
|
|
use app\models\register\CollectionsObjects;
|
|
|
|
/**
|
|
* Class RegisterObjects
|
|
* @package app\models
|
|
* @property $ref_num
|
|
* @property $city_id
|
|
* @property $lib_type
|
|
* @property $is_payable
|
|
* @property $price
|
|
* @property $infocenter_email
|
|
* @property $infocenter_website
|
|
* @property $administrative_latitude
|
|
* @property $administrative_longitude
|
|
* @property $partner_id
|
|
* @property $created_year
|
|
* @property $created_by
|
|
* @property $object_thumbnail_url
|
|
* @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 $date_added
|
|
* @property $date_updated
|
|
* @property $publish_date
|
|
* @property $is_active
|
|
* @property $mainImgFile
|
|
* @property RegisterPartner $partner
|
|
* @property CityList $city
|
|
* @property \app\models\register\CollectionsObjects $collectionsObject
|
|
* @property ObjectTags[] $tags
|
|
* @property RegisterObjectFiles $pdf
|
|
* @property Library $library
|
|
*/
|
|
class RegisterObjects extends _Base
|
|
{
|
|
|
|
public function getExpositions()
|
|
{
|
|
return $this->hasMany(ExpositionsObjects::class, ['object_id' => 'id']);
|
|
}
|
|
|
|
public function isInExposition($exposition_id)
|
|
{
|
|
if ($exposition_id) {
|
|
$exists = $this->hasMany(ExpositionsObjects::class, ['object_id' => 'id'])->where(['exposition_id' => $exposition_id])->exists();
|
|
return $exists;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function getRegisterObjectFields()
|
|
{
|
|
return $this->hasMany(RegisterObjectFields::class, ['object_id' => 'id']);
|
|
}
|
|
|
|
public function getRegisterObjectFiles()
|
|
{
|
|
return $this->hasMany(RegisterObjectFiles::class, ['object_id' => 'id']);
|
|
}
|
|
|
|
public function getMainImgFile()
|
|
{
|
|
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'])
|
|
->one();
|
|
if ($file) return $file->file_url;
|
|
}
|
|
|
|
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 CollectionsObjects $collectionObject */
|
|
foreach ($this->collectionsObject as $collectionObject) {
|
|
if ($collectionObject->collection)
|
|
$collections[] = $collectionObject->collection->name;
|
|
}
|
|
return implode(',', $collections);
|
|
}
|
|
|
|
public function getUrl()
|
|
{
|
|
return '/admin-global/web-portal/objects-register/?o=w&id=' . $this->id;
|
|
}
|
|
|
|
public function isAddedToExposition($id)
|
|
{
|
|
if ($this->isInExposition($id))
|
|
return '<div onclick="removeExpObject(this)" class="btn-rem btn-ib"><i class="la la-remove"></i> Премахни</div>';
|
|
return '<div onclick="addExpObject(this)" class="btn-ib btn-default"><i class="la la-plus-circle"></i> Добави</div>';
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
public function getPdf()
|
|
{
|
|
return $this->hasMany(RegisterObjectFiles::class, ['object_id' => 'id'])
|
|
->where(['file_content_type' => 1, 'extension' => 'pdf'])
|
|
->one();
|
|
}
|
|
|
|
public function getLibrary()
|
|
{
|
|
return $this->hasOne(Library::class, ['object_id' => 'id']);
|
|
}
|
|
|
|
|
|
public static function languageList()
|
|
{
|
|
return [1 => 'Български',
|
|
2 => 'Английски',
|
|
3 => 'Немски',
|
|
4 => 'Испански',
|
|
5 => 'Португалски',
|
|
6 => 'Португалски',
|
|
7 => 'Турски',
|
|
8 => 'Румънски',
|
|
9 => 'Румънски'
|
|
];
|
|
}
|
|
}
|