Initial import

This commit is contained in:
Admin Nasledstvo
2026-05-01 20:52:04 +03:00
commit ac168868ee
10028 changed files with 2337954 additions and 0 deletions
@@ -0,0 +1,14 @@
<?php
namespace app\models;
/**
* Class AboutProject
* @package app\models
* @property $id
* @property $text_bg
* @property $text_en
* @property $media_key
*/
class AboutProject extends _Base {
}
@@ -0,0 +1,88 @@
<?php
namespace app\models;
use app\services\Formatter;
/**
* Class Articles
* @package app\models
* @property $id
* @property $key
* @property $art_table
* @property News $news;
* @property Events $events;
* @property Campaigns $campaigns;
* @property $title
* @property $title_en
* @property $is_active
* @property $publish_date
* @property \app\models\parsed\ArticleParsedInterface $article
* @property $label
* @property $partner_id
* @property $partner_page_selected
*/
class Articles extends _Base
{
public function getNews()
{
return $this->hasOne(News::class, ['article_key' => 'key']);
}
public function getEvents()
{
return $this->hasOne(Events::class, ['article_key' => 'key']);
}
public function getCampaigns()
{
return $this->hasOne(Campaigns::class, ['article_key' => 'key']);
}
public function getArticle() {
switch ($this->art_table) {
case 'news':
return $this->news;
case 'events':
return $this->events;
case 'campaigns':
return $this->campaigns;
}
}
public function getLabel() {
switch ($this->art_table) {
case 'news':
return Ts::get(12);
case 'events':
return Ts::get(13);
case 'campaigns':
return Ts::get(14);
}
}
public static function getArticleBySlug($slug) {
$slugArr = explode('-', $slug);
if(!empty($slugArr[0])) {
$id = Formatter::decodeId($slugArr[0]);
$article = Articles::findOne($id);
if($article) return $article;
}
return null;
}
public function getSingleArticleLabel() {
switch ($this->art_table) {
case 'news':
return Ts::get(185);
case 'events':
return Ts::get(186);
case 'campaigns':
return Ts::get(187);
}
}
}
@@ -0,0 +1,99 @@
<?php
namespace app\models;
use app\models\parsed\ArticleParsedInterface;
use app\services\ViewReg;
/**
* Class Campaigns
* @package app\models
* @property $id
* @property $location
* @property $title
* @property $text
* @property $text_short
* @property $ts_en_location
* @property $ts_en_title
* @property $ts_en_text
* @property $ts_en_text_short
* @property $media_key
* @property $stream_url
* @property $stream_access
* @property $partner_id
* @property Partner $partner
* @property $event_dates
* @property $is_for_publish
* @property $article_key
*/
class Campaigns extends _Base implements ArticleParsedInterface
{
public function getPartner() {
return $this->hasOne(Partner::class, ['id' => 'partner_id']);
}
public function id() {
return $this->id;
}
public function title($lg = null)
{
$lg = $lg ?? \Yii::$app->language;
return $lg == 'en' ? $this->ts_en_title : $this->title;
}
public function text()
{
return \Yii::$app->language == 'en' ? $this->ts_en_text : $this->text;
}
public function textShort()
{
return \Yii::$app->language == 'en' ? $this->ts_en_text_short : $this->text_short;
}
public function image($rez = null)
{
return $this->getSrcOfSingleImage('title_campaigns_image', $rez);
}
public function images($rez = null)
{
return $this->getSrcOfMultipleImages('campaigns_images', $rez);
}
public function relation()
{
return ViewReg::generateDirectDetailPageUrl($this, 'campaigns');
}
public function getFormattedDates()
{
$dates = explode(',', $this->event_dates);
sort($dates);
$first = date_create($dates[0]);
$last = date_create($dates[sizeof($dates) - 1]);
//return $first->format('d.m.Y');
$interval = date_diff($first, $last);
$days = (int)$interval->format('%a') - 1;
if ($days == sizeof($dates) - 2) {
if ($first->format('d.m.Y') == $last->format('d.m.Y')) {
return $first->format('d.m.Y');
}
{
return $first->format('d.m.Y') . ' - ' . $last->format('d.m.Y');
}
} else {
$reorder = [];
foreach ($dates as $date) {
$reorder[] = date_create($date)->format('d.m.Y');
}
return implode(', ', $reorder);
}
}
}
@@ -0,0 +1,51 @@
<?php
namespace app\models;
/**
* Class Collections
* @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 $is_active
* @property $is_selected
* @property $partner_id
* @property \app\models\Partner $partner
* @property $publish_date
*/
class Collections extends _Base
{
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 getPartner() {
return $this->hasOne(Partner::class, ['id' => 'partner_id']);
}
public function image($rez = null) {
return $this->getSrcOfSingleImage('title_collection_image', $rez);
}
}
@@ -0,0 +1,18 @@
<?php
namespace app\models;
/**
* Class CollectionsObjects
* @package app\models
* @property $id
* @property $object_id
* @property $collection_id
* @property $category_id
* @property Collections $collection
*/
class CollectionsObjects extends _Base {
public function getCollection() {
return $this->hasOne(Collections::class, ['id' => 'collection_id']);
}
}
@@ -0,0 +1,27 @@
<?php
namespace app\models;
/**
* Class Contacts
* @package app\models
* @property $phone
* @property $email
* @property $website
* @property $address
* @property $address_en
* @property $managing_authority
* @property $managing_authority_en
* @property $page_id
*/
class Contacts extends _Base
{
public function getAddress() {
return \Yii::$app->language == 'en' ? $this->address_en : $this->address;
}
public function getManagingAuthority() {
return \Yii::$app->language == 'en' ? $this->managing_authority_en : $this->managing_authority;
}
}
@@ -0,0 +1,22 @@
<?php
namespace app\models;
/**
* Class DocsCms
* @package app\models
* @property $id
* @property $document_key
* @property $name
* @property $name_en
* @property $file_name
* @property $file_name_en
* @property $extension
* @property $extension_en
* @property $document_type
*/
class DocsCms extends _Base
{
}
@@ -0,0 +1,218 @@
<?php
namespace app\models;
use app\models\parsed\ArticleParsedInterface;
use app\models\parsed\CartInterface;
use app\models\parsed\CartModel;
use app\services\ViewReg;
/**
* Class Events
* @package app\models
* @property $type
* @property $location
* @property $title
* @property $text
* @property $text_short
* @property $ts_en_location
* @property $ts_en_title
* @property $ts_en_text
* @property $ts_en_text_short
* @property $media_key
* @property $stream_url
* @property $stream_access
* @property $stream_purchase_type
* @property $stream_price
* @property $partner_id
* @property Partner $partner
* @property $event_dates
* @property $is_for_publish
* @property $max_visitors
* @property $daily_open_time
* @property $price_objects
* @property $article_key
*/
class Events extends _Base implements ArticleParsedInterface
{
public function getPartner()
{
return $this->hasOne(Partner::class, ['id' => 'partner_id']);
}
public static function eventTypes($type = null, $locale = null)
{
$types = [
'simple' => 'Обикновенно събитие',
'online' => 'Дигитално събитие',
'booking' => 'Събитие на място с резервация'
];
if ($locale == 'en') {
$types = [
'simple' => 'Simple event',
'online' => 'Digital event',
'booking' => 'Event on site with reservation'
];
}
if ($type)
return mb_strtolower($types[$type]) ?? null;
return $types;
}
public function getEventType($text = false)
{
$type = $this->type ?? ($_GET['type'] ?? null);
if ($text)
$type = self::eventTypes($type);
return $type;
}
public static function getModel()
{
if (!empty($_GET['id'])) {
return self::findOne($_GET['id']);
} else {
return new Events();
}
}
public function get_stream_purchase_type()
{
return $this->stream_purchase_type ?? 'individual_price';
}
public function get_stream_access()
{
return $this->stream_access ?? 1;
}
public function getPrice_objects()
{
return $this->hasMany(PriceObject::class, ['event_id' => 'id']);
}
public function id()
{
return $this->id;
}
public function title($lg = null)
{
$lg = $lg ?? \Yii::$app->language;
return $lg == 'en' ? ($this->ts_en_title ?? $this->title) : $this->title;
}
public function text()
{
return \Yii::$app->language == 'en' ? $this->ts_en_text : $this->text;
}
public function textShort()
{
return \Yii::$app->language == 'en' ? $this->ts_en_text_short : $this->text_short;
}
public function image($rez = null)
{
return $this->getSrcOfSingleImage('title_event_image', $rez);
}
public function images($rez = null)
{
return $this->getSrcOfMultipleImages('event_images', $rez);
}
public function relation()
{
return ViewReg::generateDirectDetailPageUrl($this, 'events');
}
public function getFormattedDates()
{
$dates = explode(',', $this->event_dates);
sort($dates);
$first = date_create($dates[0]);
$last = date_create($dates[sizeof($dates) - 1]);
//return $first->format('d.m.Y');
$interval = date_diff($first, $last);
$days = (int)$interval->format('%a') - 1;
if ($days == sizeof($dates) - 2) {
if ($first->format('d.m.Y') == $last->format('d.m.Y')) {
return $first->format('d.m.Y');
}
{
return $first->format('d.m.Y') . ' - ' . $last->format('d.m.Y');
}
} else {
$reorder = [];
foreach ($dates as $date) {
$reorder[] = date_create($date)->format('d.m.Y');
}
return implode(', ', $reorder);
}
}
public function getPlace()
{
return \Yii::$app->language == 'en' ? $this->ts_en_location : $this->location;
}
public function isBookingAvailable()
{
if ($this->event_dates) {
$dates = explode(',', $this->event_dates);
sort($dates);
$lastDate = date_create($dates[sizeof($dates) - 1]. ' 22:36:00');
if(date_create() <= $lastDate) {
return true;
}
}
}
public function eventDatesArray()
{
if ($this->event_dates) {
$dates = explode(',', $this->event_dates);
sort($dates);
return $dates;
}
}
public function eventTimesArray() {
if($this->daily_open_time) {
$times = explode('-', $this->daily_open_time);
$start = explode(':', $times[0]);
$end = explode(':', $times[1]);
$start_h = (int)$start[0];
$start_i = (int)$start[1];
$end_h = (int)$end[0];
$end_i = (int)$end[1];
$minute_step = 5;
$steps = [$times[0]];
while (true) {
if($start_i < 60) {
$h = sprintf('%02d', $start_h);
$i = sprintf('%02d', $start_i);
$steps[] = "$h:$i";
$start_i += $minute_step;
} else {
$start_h++;
$start_i = 0;
}
if($start_h == $end_h && $start_i == $end_i) {
array_shift($steps);
return $steps;
}
}
}
}
}
@@ -0,0 +1,20 @@
<?php
namespace app\models;
/**
* Class ExplorerObjects
* @package app\models
* @property $id
* @property $tour_object_id
* @property $points
* @property $media_key
* @property \app\models\TourObjects $tourObject
*/
class ExplorerObjects extends _Base
{
public function getTourObject() {
return $this->hasOne(TourObjects::class, ['id' => 'tour_object_id']);
}
}
@@ -0,0 +1,166 @@
<?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']);
}
}
@@ -0,0 +1,39 @@
<?php
namespace app\models;
/**
* Class ExpositionsCategories
* @package app\models
* @property $id
* @property $name
* @property $name_en
*/
class ExpositionsCategories extends _Base
{
public function getExpositions()
{
return $this->hasMany(Expositions::class, ['category_id' => 'id']);
}
public static function dropDownList($id = null)
{
$list = [];
foreach (self::find()->all() as $category) {
$list[] = (object)[
'id' => $category->id,
'name' => $category->name,
'selected' => $category->id == $id ? 'selected' : ''
];
}
return $list;
}
public static function listActive() {
return self::find()->joinWith('expositions')->where(['IS NOT','category_id', NULL])->all();
}
public function title() {
return \Yii::$app->language == 'en' ? $this->name_en : $this->name;
}
}
@@ -0,0 +1,15 @@
<?php
namespace app\models;
/**
* Class ExpositionsObjects
* @package app\models
* @property $exposition_id
* @property $object_id
* @property \app\models\RegisterObjects $object
*/
class ExpositionsObjects extends _Base {
public function getObject() {
return $this->hasOne(RegisterObjects::class, ['id' => 'object_id']);
}
}
@@ -0,0 +1,34 @@
<?php
namespace app\models;
/**
* Class ExpositionsCategories
* @package app\models
* @property $id
* @property $name
* @property $name_en
*/
class ExpositionsTags extends _Base
{
/*
public function getExpositions()
{
return $this->hasMany(Expositions::class, ['category_id' => 'id']);
}
public static function dropDownList($id = null)
{
$list = [];
foreach (self::find()->all() as $category) {
$list[] = (object)[
'id' => $category->id,
'name' => $category->name,
'selected' => $category->id == $id ? 'selected' : ''
];
}
return $list;
}
*/
}
@@ -0,0 +1,11 @@
<?php
namespace app\models;
/**
* Class ExpositionsTagsExpositions
* @package app\models
* @property $exposition_id
* @property $exposition_tag_id
*/
class ExpositionsTagsExpositions extends _Base {
}
@@ -0,0 +1,25 @@
<?php
namespace app\models;
/**
* Class FileImage
* @package app\models
* @property $id
* @property string $media_key
* @property string $object_key
* @property string $file_name
* @property string $file_type
* @property string $file_extension
* @property string $file_size
* @property string $date_time
* @property string $resolutions
* @property array $resolutionArray
* @property int $order_index
* @property boolean $has_article
*/
class FileCms extends _Base
{
}
@@ -0,0 +1,16 @@
<?php
namespace app\models;
/**
* Class Inquiries
* @package app\models
* @property $id
* @property $name
* @property $email
* @property $operation
* @property $error
* @property $date_time
*/
class Inquiries extends _Base {
}
@@ -0,0 +1,19 @@
<?php
namespace app\models;
/**
* Class JoinToUs
* @package app\models
* @property $id
* @property $name
* @property $name_en
* @property $text
* @property $text_en
* @property $external_link
*/
class JoinToUs extends _Base
{
}
@@ -0,0 +1,47 @@
<?php
namespace app\models;
/**
* Class Library
* @package app\models
*
* @property $object_id;
* @property $lib_variant
* @property $lib_format
* @property $lib_identifier_isbn_print
* @property $lib_identifier_isbn_online
* @property $lib_identifier_issn_print
* @property $lib_identifier_issn_online
* @property $lib_identifier_doi
* @property $lib_identifier_ismn
* @property $lib_identifier_isan
* @property $lib_author_compiler
* @property $lib_author_translator
* @property $lib_author_editor
* @property $lib_author_reviewer
* @property $lib_author_ilustrator
* @property $lib_language
* @property $lib_title_information
* @property $lib_title_parallel
* @property $lib_edition
* @property $lib_publication_place
* @property $lib_publication_date
* @property $lib_publisher_name
* @property $lib_series
* @property $lib_url
* @property $lib_article_source
* @property $lib_article_pages
* @property $lib_volume_source
* @property $lib_periodical_dimensions
* @property $lib_pages
* @property $lib_citation_apa
* @property $lib_citation_harvard
*/
class Library extends _Base
{
}
@@ -0,0 +1,41 @@
<?php
namespace app\models;
use app\models\parsed\NavigationParsed;
/**
* Class Navigation
* @package app\models
* @property string $menu_type
* @property string $name
* @property string $ts_en_name
* @property int $order_index
* @property int $page_id
* @property $url
* @property $url_authorised
* @property $relation_type
* [relations]
* @property Pages $page
* @property NavigationParsed $parsed
* @property $partner_page
* @property $is_active
* @property $in_submenu
*/
class Navigation extends _Base
{
public function getPage() {
return $this->hasOne(Pages::class, ['id' => 'page_id']);
}
public function getParsed()
{
return new NavigationParsed($this);
}
public static function getLinkById($id)
{
$link = self::findOne($id);
return $link ? $link->parsed->relation : "#";
}
}
@@ -0,0 +1,65 @@
<?php
namespace app\models;
use app\models\parsed\ArticleParsedInterface;
use app\services\ViewReg;
/**
* Class News
* @package app\models
* @property $title
* @property $text
* @property $text_short
* @property $ts_en_title
* @property $ts_en_text
* @property $ts_en_text_short
* @property $media_key
* @property $stream_url
* @property $stream_access
* @property $partner_id
* @property Partner $partner
* @property $is_for_publish
* @property $article_key
*/
class News extends _Base implements ArticleParsedInterface
{
public function getPartner() {
return $this->hasOne(Partner::class, ['id' => 'partner_id']);
}
public function id() {
return $this->id;
}
public function title($lg = null)
{
$lg = $lg ?? \Yii::$app->language;
return $lg == 'en' ? $this->ts_en_title : $this->title;
}
public function text()
{
return \Yii::$app->language == 'en' ? $this->ts_en_text : $this->text;
}
public function textShort()
{
return \Yii::$app->language == 'en' ? $this->ts_en_text_short : $this->text_short;
}
public function image($rez = null)
{
return $this->getSrcOfSingleImage('title_news_image', $rez);
}
public function images($rez = null)
{
return $this->getSrcOfMultipleImages('news_images', $rez);
}
public function relation()
{
return ViewReg::generateDirectDetailPageUrl($this, 'news');
}
}
@@ -0,0 +1,165 @@
<?php
namespace app\models;
use yii\base\BaseObject;
/**
* Class Objects
* @package app\models
* @property int $sc_id
* @property int $ot_id
* @property int $partner_id
* @property string $name
* @property string $annotation
* @property string $description
* [RELATIONS]
* @property ObjectTemplate $objectTemplate
* @property Categories $subCategory
* @property ObjectsField[] $objectFields
* @property Partner $partner
* @property \app\models\History $history
* @property \app\models\CollectionsObjects[] $collections
* @property string $collectionConcatList
*/
class Objects extends _Base
{
public function getHistory()
{
return $this->hasMany(History::class, ['history_id' => 'id'])->where(['table_name' => 'objects', 'action' => 1])->one();
}
public function getObjectTemplate()
{
return $this->hasOne(ObjectTemplate::class, ['id' => 'ot_id']);
}
public function getPartner()
{
return $this->hasOne(Partner::class, ['id' => 'partner_id']);
}
public function getSubCategory()
{
return $this->hasOne(Categories::class, ['id' => 'sc_id']);
}
public function getObjectFields()
{
return $this->hasMany(ObjectsField::class, ['object_id' => 'id'])
->joinWith('objectTemplateField')
->orderBy(['order_index' => SORT_ASC])
->all();
}
public function setObjectFields($p)
{
if ($this->ot_id) {
if (empty($_GET['id'])) {
foreach ($this->objectTemplate->objectTemplateFields as $templateField) {
$objectField = new ObjectsField();
$objectField->object_id = $this->id;
$objectField->object_tf_id = $templateField->id;
$objectField->save();
}
} else {
if (empty($p->{'new_object_fields'})) {
$obf = $p->{'obf'};
$idsToUpdate = (array_keys($obf));
$objectFields = ObjectsField::find()->where(['IN', 'id', $idsToUpdate])->all();
foreach ($objectFields as $objectField) {
if (!empty($obf{$objectField->id}{'option_tf_id'})) $objectField->option_tf_id = $obf{$objectField->id}{'option_tf_id'};
if (!empty($obf{$objectField->id}{'value'})) $objectField->value = $obf{$objectField->id}{'value'};
if (!empty($obf{$objectField->id}{'value_en'})) $objectField->value_en = $obf{$objectField->id}{'value_en'};
if (!empty($obf{$objectField->id}{'date'})) $objectField->date = $obf{$objectField->id}{'date'};
if (!empty($obf{$objectField->id}{'geo_lon'})) $objectField->geo_lon = $obf{$objectField->id}{'geo_lon'};
if (!empty($obf{$objectField->id}{'geo_lat'})) $objectField->geo_lat = $obf{$objectField->id}{'geo_lat'};
if (!empty($obf{$objectField->id}{'settlement_id'})) $objectField->settlement_id = $obf{$objectField->id}{'settlement_id'};
if (!empty($obf{$objectField->id}{'common_field_id'})) $objectField->common_field_id = $obf{$objectField->id}{'common_field_id'};
$objectField->save();
}
} else {
foreach ($this->newTemplateFields() as $id => $field) {
$newObjectField = new ObjectsField();
$newObjectField->object_tf_id = $id;
$newObjectField->object_id = $this->id;
$newObjectField->save();
}
}
}
}
}
public function newTemplateFields()
{
$objectFieldIds = [];
$missing = [];
foreach ($this->objectFields as $field) $objectFieldIds[] = $field->object_tf_id;
foreach ($this->objectTemplate->objectTemplateFields as $templateField) {
if (!in_array($templateField->id, $objectFieldIds)) {
$userInterface = ObjectTemplateField::userInterfaceType($templateField->user_interface_type, false);
$missing[$templateField->id] = [
'name' => $templateField->name,
'type' => $userInterface
];
}
}
return $missing;
}
public function setCollections($p)
{
$ids = $p->{'collections'} ?? [];
$related = CollectionsObjects::find()->where(['object_id' => $this->id])->all();
$remain = [];
foreach ($related as $cto) {
if(in_array($cto->id, $ids)) {
$remain[] = $cto->id;
} else {
$cto->delete();
}
}
foreach ($ids as $id) {
if(!in_array($id, $remain)) {
$newCto = new CollectionsObjects();
$newCto->object_id = $this->id;
$newCto->collection_id = $id;
$newCto->category_id = $this->subCategory->id;
$newCto->save();
}
}
}
public function getCollections()
{
return $this->hasMany(CollectionsObjects::class, ['object_id' => 'id']);
}
public function getCollectionsSelectList()
{
$ids = [];
foreach ($this->collections as $collection) {
$ids[] = $collection->collection_id;
}
$list = [];
foreach (Collections::find()->all() as $item) {
$list[$item->id] = [
'name' => $item->name,
'selected' => in_array($item->id, $ids)
];
}
return $list;
}
public function getCollectionConcatList() {
$collections = [];
foreach ($this->collections as $collection) {
$collections[] = $collection->collection->name;
}
return implode(', ', $collections);
}
}
@@ -0,0 +1,129 @@
<?php
namespace app\models;
use app\models\parsed\CartModel;
use app\models\register\Collections;
use app\services\Cart;
/**
* Class Order
* @package app\models
* @property $id
* @property $user_id
* @property $order_date
* @property $total_price
* @property $user_name
* @property $user_email
* @property \app\models\UserPublic $user
* @property \app\models\OrderPayment $payment
* @property \app\models\OrderBooking[] $booking
* @property \app\models\OrderProduct[] $subscriptions
* @property \app\models\OrderProduct[] $collections
* @property \app\models\RegisterObjects[] $publications
*/
class Order extends _Base
{
public function getUser()
{
return $this->hasOne(UserPublic::class, ['id' => 'user_id']);
}
/**
* @param $data
* @param \app\models\UserPublic $user
* @return \app\models\Order
*/
public static function record($data, $user)
{
$cart_data = json_decode($data['cart_data']);
$invoice_data = json_decode($data['invoice_data']);
if (sizeof($cart_data) == 0) {
header('Location: /');
exit;
}
$order = new Order();
$order->user_id = $user->id;
$order->order_date = date('Y-m-d H:i:s');
$order->user_email = $user->email;
$order->user_name = $user->full_name;
$order->save();
$totalPrice = 0;
foreach ($cart_data as $cartElement) {
$cartObject = Cart::decodeKey($cartElement);
if ($cartObject->model == OrderBooking::class) {
$booking = OrderBooking::findOne($cartObject->id);
if ($booking) {
$booking->order_id = $order->id;
$booking->save();
$totalPrice += $booking->single_price;
}
} else {
/** @var RegisterObjects|\app\models\register\Collections|Subscriptions $modelClass */
$modelClass = $cartObject->model;
$model = $modelClass::findOne($cartObject->id);
if ($model) {
$cartModel = $model->setCart(new CartModel());
$product = new OrderProduct();
$product->name_bg = $cartModel->name_bg;
$product->name_en = $cartModel->name_en;
$product->text_bg = $cartModel->text_bg;
$product->text_en = $cartModel->text_en;
$product->order_id = $order->id;
$product->price = $cartModel->price;
$product->model_class = $modelClass;
$product->model_id = $model->id;
$product->save();
$totalPrice += $cartModel->price;
}
}
}
OrderInvoice::record($invoice_data, $order->id);
$order->total_price = $totalPrice;
$order->save();
return $order;
}
public function getDescription()
{
return 'HeritageBG order';
}
public function getPayment()
{
return $this->hasOne(OrderPayment::class, ['order_id' => 'id']);
}
public function getBooking()
{
return $this->hasMany(OrderBooking::class, ['order_id' => 'id']);
}
public function getSubscriptions() {
return $this->hasMany(OrderProduct::class, ['order_id' => 'id'])->where(['model_class' => Subscriptions::class])->orderBy(['id' => SORT_DESC])->all();
}
public function getCollections() {
return $this->hasMany(OrderProduct::class, ['order_id' => 'id'])->where(['model_class' => Collections::class])->orderBy(['id' => SORT_DESC])->all();
}
public function getPublications() {
return $this->hasMany(OrderProduct::class, ['order_id' => 'id'])->where(['model_class' => RegisterObjects::class])->orderBy(['id' => SORT_DESC])->all();
}
public function statusStr()
{
$lg = \Yii::$app->language;
if($this->payment && $this->payment->status == 'PAID') {
return $lg == 'en' ? 'Paid' : 'Платено';
}
return $lg == 'en' ? 'Payment pending' : 'В очакване на плащане';
}
}
@@ -0,0 +1,114 @@
<?php
namespace app\models;
use app\models\parsed\CartInterface;
use app\models\parsed\CartModel;
use app\services\Cart;
use app\services\Formatter;
use app\services\JWT;
use Prophecy\Comparator\Factory;
/**
* Class OrderBooking
* @package app\models
* @property $id
* @property $datetime
* @property $name_bg
* @property $name_en
* @property $description_bg
* @property $description_en
* @property $single_price
* @property $tickets_count
* @property $validated_count
* @property $last_validation_time
* @property $event_id
* @property $ticket_id
* @property \app\models\PriceObject $ticketType
* @property $order_id
* @property $cart_key
* @property \app\models\Events $event
* @property \app\models\Order $order
*/
class OrderBooking extends _Base implements CartInterface
{
public function getEvent()
{
return $this->hasOne(Events::class, ['id' => 'event_id']);
}
public function getTicketType()
{
return $this->hasOne(PriceObject::class, ['id' => 'ticket_id']);
}
public function getCartKey()
{
return Cart::encodeKey('OrderBooking', $this->id);
}
public function setCart(CartModel $model)
{
$model->title = $this->{'description_' . \Yii::$app->language};;
$model->subTitle = Ts::get(176);
$model->description = $this->{'name_' . \Yii::$app->language};
$model->singlePrice = number_format($this->single_price, 2, '.', ' ') . ' лв.';
$model->price = $this->single_price;
$model->availableQuantity = 100;
if ($this->datetime)
$model->datetime = date_create($this->datetime)->format('d.m.Y H:i');
return $model;
}
public function formatedHtmlDate()
{
if ($this->datetime)
$datetime = date_create($this->datetime);
return $datetime->format('d.m.Y H:i');
}
public function getHashedId()
{
return 'qrnasledstvo_'.base64_encode('nasledsto-ticket_' . $this->id);
}
public static function getBookingByHashId($hashId)
{
$idStr = base64_decode($hashId);
$exp = explode('_', $idStr);
$id = $exp[1] ?? null;
if ($id) {
$booking = OrderBooking::findOne($id);
if ($booking)
return $booking;
}
return null;
}
public function responseData()
{
$lg = \Yii::$app->language;
return [
'id' => $this->id,
'ticket_type' => $this->{'name_' . $lg},
'event' => $this->event->title(),
'event_img' => $this->event->image('16:11'),
'single_price' => $this->single_price,
'datetime' => $this->formatedHtmlDate(),
'hashed_id' => $this->getHashedId(),
'tickets_count' => $this->tickets_count,
'validated' => $this->validated_count ?? 0,
'to_validate' => $this->tickets_count - $this->validated_count,
'last_validation_time' => date('d.m.Y H:i:s')
];
}
public function getOrder() {
return $this->hasOne(Order::class, ['id' => 'order_id']);
}
}
@@ -0,0 +1,69 @@
<?php
namespace app\models;
/**
* Class OrderInvoice
* @package app\models
* @property $id;
* @property $order_id
* @property $invoice_data_type
* @property $first_name
* @property $last_name
* @property $country
* @property $post_code
* @property $city
* @property $address
* @property $company_name
* @property $eik
* @property $mol
* @property $is_by_vat
*/
class OrderInvoice extends _Base
{
public static function record($data, $order_id)
{
$invoice = new OrderInvoice();
$invoice->order_id = $order_id;
if (!empty($data->{'invoice_data_type'}))
$invoice->invoice_data_type = $data->{'invoice_data_type'};
if (!empty($data->{'first_name'}))
$invoice->first_name = $data->{'first_name'};
if (!empty($data->{'last_name'}))
$invoice->last_name = $data->{'last_name'};
if (!empty($data->{'country'}))
$invoice->country = $data->{'country'};
if (!empty($data->{'post_code'}))
$invoice->post_code = $data->{'post_code'};
if (!empty($data->{'city'}))
$invoice->city = $data->{'city'};
if (!empty($data->{'address'}))
$invoice->address = $data->{'address'};
if (!empty($data->{'company_name'}))
$invoice->company_name = $data->{'company_name'};
if (!empty($data->{'eik'}))
$invoice->eik = $data->{'eik'};
if (!empty($data->{'mol'}))
$invoice->mol = $data->{'mol'};
if (!empty($data->{'is_by_vat'}))
$invoice->is_by_vat = $data->{'is_by_vat'};
$invoice->save();
}
}
@@ -0,0 +1,24 @@
<?php
namespace app\models;
/**
* Class OrderPayment
* @package app\models
* @property $id
* @property $order_id
* @property $payment_method
* @property $client_email
* @property $amount
* @property $status
* @property $response_message
* @property $response_time
* @property Order $order
*/
class OrderPayment extends _Base
{
public function getOrder() {
return $this->hasOne(Order::class, ['id' => 'order_id']);
}
}
@@ -0,0 +1,14 @@
<?php
namespace app\models;
/**
* Class OrderPaymentNotification
* @package app\models
* @property $id;
* @property $message
* @property $date
*/
class OrderPaymentNotification extends _Base
{
}
@@ -0,0 +1,25 @@
<?php
namespace app\models;
/**
* Class OrderModel
* @package app\models
* @property $id
* @property $order_id
* @property $name_bg
* @property $name_en
* @property $text_bg
* @property $text_en
* @property $price
* @property $model_class
* @property $model_id
* @property \app\models\Order $order
*/
class OrderProduct extends _Base
{
public function getOrder() {
return $this->hasOne(Order::class, ['id' => 'order_id']);
}
}
@@ -0,0 +1,54 @@
<?php
namespace app\models;
use app\models\parsed\Page;
use app\services\Formatter;
/**
* Class Pages
* @package app\models
* @property $name
* @property $name_en
* @property $slug
* @property $slug_en
* @property $id
* @property \app\models\Contacts $contacts
*/
class Pages extends _Base implements Page
{
public function getContacts() {
return $this->hasOne(Contacts::class, ['page_id' => 'id']);
}
public static function getList($id = null)
{
$pages = [];
foreach (self::find()->all() as $page) {
$pages[$page->id] = $page->name;
}
if ($id && !empty($pages[$id]))
return $pages[$id];
return $pages;
}
public function headerImage($rez = null)
{
return $this->getSrcOfSingleImage('header_page_image', $rez);
}
public function headerTitle()
{
return \Yii::$app->language == 'en' ? $this->name_en : $this->name;
}
public function text() {
return \Yii::$app->language == 'en' ? $this->text_en : $this->text;
}
public function getUrl() {
return '/' . \Yii::$app->language . '/' . Formatter::cyrillicTrans($this->headerTitle()) . '/';
}
}
@@ -0,0 +1,21 @@
<?php
namespace app\models;
/**
* Class Partner
* @package app\models
* @property int $id
* @property string $name
* @property string $key
* @property $is_active
*/
class Partner extends _Base
{
public static function partnerList() {
$partnerList = [];
foreach (self::find()->all() as $partner) {
$partnerList[$partner->id] = $partner->name;
}
return $partnerList;
}
}
@@ -0,0 +1,55 @@
<?php
namespace app\models;
use app\models\parsed\ArticleParsedInterface;
/**
* Class Positions
* @package app\models
* @property $id
* @property $group_name
* @property $class_name
* @property $group_id
* @property $position_article_key
* @property Positions[] $positions
* @property int $positionsCount
* @property ArticleParsedInterface $article
* @property Articles $articleModel
*/
class Positions extends _Base
{
public function getPositions()
{
return $this->hasMany(Positions::class, ['group_id' => 'id'])->orderBy(['order_index' => SORT_ASC])->all();
}
public function getPositionsCount()
{
return $this->hasMany(Positions::class, ['group_id' => 'id'])->count();
}
public function getArticleModel()
{
return $this->hasOne(Articles::class, ['key' => 'position_article_key']);
}
public function getArticle()
{
if ($this->position_article_key) {
$table = explode('_', $this->position_article_key);
switch ($table[0]) {
case 'news':
return $this->articleModel->news;
case 'events':
return $this->articleModel->events;
case 'campaigns':
return $this->articleModel->campaigns;
}
}
}
}
@@ -0,0 +1,27 @@
<?php
namespace app\models;
use app\models\parsed\CartInterface;
use app\models\parsed\CartModel;
use app\services\Cart;
/**
* Class PriceObject
* @package app\models
* @property $id
* @property $text_bg
* @property $text_en
* @property $price
* @property $event_id
* @property $cartKey
* @property \app\models\Events $event
*/
class PriceObject extends _Base
{
public function getEvent()
{
return $this->hasOne(Events::class, ['id' => 'event_id']);
}
}
@@ -0,0 +1,151 @@
<?php
namespace app\models;
/**
* Class Projects
* @package app\models
* @property $id
* @property $title
* @property $text
* @property $text_short
* @property $text_contract
* @property $ts_en_title
* @property $ts_en_text
* @property $ts_en_text_short
* @property $ts_en_text_contract
* @property $period
* @property $website
* @property $publications
* @property $media_key
* @property $document_key
* @property $projectPartners
* @property $publish_date
* @property $docs
* @property $partner_id
*/
class Projects extends _Base
{
public function getProjectPartners()
{
return $this->hasMany(ProjectsPartner::class, ['project_id' => 'id']);
}
public function getDocs()
{
return $this->hasMany(DocsCms::class, ['document_key' => 'document_key']);
}
public function getDocsList()
{
$domain = \Yii::$app->params['media_server'];
$docsList = [];
/** @var \app\models\DocsCms $doc */
foreach ($this->docs as $doc) {
if ($doc->document_type == 'ppt' || $doc->document_type == 'pptx')
continue;
if (\Yii::$app->language == 'bg' && $doc->file_name && $doc->name) {
$docsList[] = (object)[
'download' => $domain . $doc->file_name,
'name' => $doc->name
];
}
if (\Yii::$app->language == 'en' && $doc->file_name_en && $doc->name_en) {
$docsList[] = (object)[
'download' => $domain . $doc->file_name_en,
'name' => $doc->name_en
];
}
}
return $docsList;
}
public function getPresentationList()
{
$domain = \Yii::$app->params['media_server'];
$docsList = [];
/** @var \app\models\DocsCms $doc */
foreach ($this->docs as $doc) {
if ($doc->document_type == 'ppt' || $doc->document_type == 'pptx') {
if (\Yii::$app->language == 'bg' && $doc->file_name && $doc->name) {
$docsList[] = (object)[
'download' => $domain . $doc->file_name,
'name' => $doc->name
];
}
if (\Yii::$app->language == 'en' && $doc->file_name_en && $doc->name_en) {
$docsList[] = (object)[
'download' => $domain . $doc->file_name_en,
'name' => $doc->name_en
];
}
}
}
return $docsList;
}
public function partnersIds()
{
$ids = [];
/** @var \app\models\ProjectsPartner $partner */
foreach ($this->projectPartners as $partner) {
$ids[] = $partner->partner_id;
}
return $ids;
}
public function title()
{
if (\Yii::$app->language == 'en') {
return $this->ts_en_title;
} else {
return $this->title;
}
}
public function textContract()
{
if (\Yii::$app->language == 'en') {
return $this->ts_en_text_contract;
} else {
return $this->text_contract;
}
}
public function textShort()
{
if (\Yii::$app->language == 'en') {
return $this->ts_en_text_short;
} else {
return $this->text_short;
}
}
public function textLong()
{
if (\Yii::$app->language == 'en') {
return $this->ts_en_text;
} else {
return $this->text;
}
}
public function videoList()
{
return [];
}
public function audioList()
{
return [];
}
public function getPublications()
{
return [];
}
}
@@ -0,0 +1,39 @@
<?php
namespace app\models;
use yii\base\BaseObject;
/**
* Class ProjectsPartner
* @package app\models
* @property $id
* @property $project_id
* @property $partner_id
* @property \app\models\Partner $partner
*/
class ProjectsPartner extends _Base {
public function getPartner() {
return $this->hasOne(\app\models\register\Partner::class, ['id' => 'partner_id']);
}
public static function updateRecords($ids, $data) {
$related = self::find()->where([$data[1] => $data[2]])->all();
$remain = [];
foreach ($related as $cto) {
if(in_array($cto->id, $ids)) {
$remain[] = $cto->id;
} else {
$cto->delete();
}
}
foreach ($ids as $id) {
if(!in_array($id, $remain)) {
$newCto = new self();
$newCto->{$data[1]} = $data[2];
$newCto->{$data[0]} = $id;
$newCto->save();
}
}
}
}
@@ -0,0 +1,25 @@
<?php
namespace app\models;
use app\models\register\Partner;
/**
* Class QrValidators
* @package app\models
* @property $user_id
* @property $partner_id
* @property \app\models\register\Partner $partner
* @property \app\models\UserPublic $user
*/
class QrValidators extends _Base
{
public function getPartner() {
return $this->hasOne(Partner::class, ['id' => 'partner_id']);
}
public function getUser() {
return $this->hasOne(UserPublic::class, ['id' => 'user_id']);
}
}
@@ -0,0 +1,29 @@
<?php
namespace app\models;
use app\models\register\Fields;
use app\models\register\FieldsValues;
/**
* Class RegisterObjectFields
* @package app\models
* @property $object_id
* @property $ref_num
* @property $field_id
* @property $value_id
* @property $value_text
* @property Fields $field
* @property FieldsValues $fieldValue
*/
class RegisterObjectFields extends _Base
{
public function getField() {
return $this->hasOne(Fields::class, ['id' => 'field_id']);
}
public function getFieldValue() {
return $this->hasOne(FieldsValues::class, ['id' => 'value_id']);
}
}
@@ -0,0 +1,124 @@
<?php
namespace app\models;
use app\services\IdServer;
use yii\db\Exception;
/**
* Class RegisterObjectFiles
* @package app\models
* @property $file_url
* @property $streaming_url
* @property $extension
* @property $size
* @property $file_ref_num
* @property $object_id
* @property $video_thumbnail
* @property $video_title
* @property $file_content_type
* @property $video_duration
*/
class RegisterObjectFiles extends _Base
{
public function getObject()
{
return $this->hasOne(RegisterObjects::class, ['id' => 'object_id']);
}
public function videoThumbnail()
{
if ($this->video_thumbnail)
return IdServer::getVideoThumb($this->id);
return '/_public/images/empty.png';
}
public function getResizedImg($direct = false, $wm = false)
{
// if ($direct)
//return IdServer::getImgToResize($this->id);
$file = $_SERVER['DOCUMENT_ROOT'] . '/_files/thumbnails/' . $this->id . '.jpg';
if (!file_exists($file)) {
$delivery = $this->file_url; //IdServer::getImgToResize($this->id);
//$headers = @get_headers($delivery);
//if ($headers && strpos($headers[0], '200')) {
$this->compressImage($delivery, $file, 70, $wm);
//x}
}
return \Yii::$app->params['portal'] . '/_files/thumbnails/' . $this->id . '.jpg';
}
public function getCopyImg($object_dir)
{
$inputFile = $this->file_url;
$outputFile = $object_dir . '/' . $this->id . '.jpg';
if (!file_exists($outputFile))
$this->copyImage($inputFile, $outputFile);
return $outputFile;
}
private function compressImage($tempPath, $originalPath, $imageQuality, $waterMark = false)
{
// Get image info
$imgInfo = getimagesize($tempPath);
$mime = $imgInfo['mime'];
// Create a new image from file
switch ($mime) {
case 'image/jpeg':
$image = imagecreatefromjpeg($tempPath);
break;
case 'image/png':
$image = imagecreatefrompng($tempPath);
break;
case 'image/gif':
$image = imagecreatefromgif($tempPath);
break;
default:
$image = imagecreatefromjpeg($tempPath);
}
$imgResized = imagescale($image, 350);
if ($waterMark) {
$stamp = imagecreatefrompng($_SERVER['DOCUMENT_ROOT'] . '/_public/images/watermark.png');
imagecopy($imgResized, $stamp, 75, 0, 0, 0, 200, 200);
}
// Save image
imagejpeg($imgResized, $originalPath, $imageQuality);
imagedestroy($imgResized);
// Return compressed image
return $originalPath;
}
private function copyImage($tempPath, $originalPath)
{
// Get image info
$imgInfo = getimagesize($tempPath);
$mime = $imgInfo['mime'];
// Create a new image from file
switch ($mime) {
case 'image/jpeg':
$image = imagecreatefromjpeg($tempPath);
break;
case 'image/png':
$image = imagecreatefrompng($tempPath);
break;
case 'image/gif':
$image = imagecreatefromgif($tempPath);
break;
default:
$image = imagecreatefromjpeg($tempPath);
}
// Save image
imagejpeg($image, $originalPath, 100);
imagedestroy($image);
// Return compressed image
return $originalPath;
}
}
@@ -0,0 +1,327 @@
<?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);
}
}
@@ -0,0 +1,36 @@
<?php
namespace app\models;
/**
* Class SeoManagement
* @package app\models
* @property $id
* @property $title
* @property $title_en
* @property $key_words
* @property $key_words_en
* @property $text
* @property $text_en
* @property $page_id
* @property \app\models\Pages $page
*/
class SeoManagement extends _Base
{
public function getPage()
{
return $this->hasOne(Pages::class, ['id' => 'page_id']);
}
public function getTitle() {
return \Yii::$app->language == 'en' ? $this->title_en : $this->title;
}
public function getDescription() {
return \Yii::$app->language == 'en' ? $this->text : $this->text_en;
}
public function getKeyWords() {
return \Yii::$app->language == 'en' ? $this->key_words : $this->key_words_en;
}
}
@@ -0,0 +1,26 @@
<?php
namespace app\models;
use app\models\parsed\SlidesParsed;
/**
* Class Slides
* @package app\models
* @property string $title
* @property string $text
* @property string $ts_en_title
* @property string $ts_en_text
* @property string $media_key
* @property integer $order_index
* @property $relation
* @property $ts_en_relation
* @property SlidesParsed $parsed
*/
class Slides extends _Base
{
public function getParsed() {
return new SlidesParsed($this);
}
}
@@ -0,0 +1,99 @@
<?php
namespace app\models;
use app\models\parsed\CartInterface;
use app\models\parsed\CartModel;
use app\services\Cart;
/**
* Class Subscriptions
* @package app\models
* @property $price
* @property $name
* @property $name_en
* @property $text
* @property $text_en
* @property $months
* @property $cartKey
*/
class Subscriptions extends _Base implements CartInterface
{
public static function allSelectedSubscriptions()
{
$selected = [];
if (!empty($_COOKIE['cart_data'])) {
$cart_data = json_decode($_COOKIE['cart_data']);
foreach (self::find()->all() as $sb) {
if (in_array($sb->cartKey, $cart_data)) {
$selected[] = $sb->cartKey;
}
}
}
return $selected;
}
public function getTitle()
{
return \Yii::$app->language == 'en' ? $this->name_en : $this->name;
}
public function getDescription()
{
return \Yii::$app->language == 'en' ? $this->text : $this->text_en;
}
public function getFormatedPrice()
{
return number_format($this->price, 2, '.', ' ') . ' лв.';
}
public function getMonthLabel()
{
if ($this->months > 1 || $this->months == 0) {
return Ts::get(86);
} else {
return Ts::get(85);
}
}
public function isInCart()
{
if (!empty($_COOKIE['cart_data']) && in_array($this->cartKey, json_decode($_COOKIE['cart_data'])))
return true;
return false;
}
public function isBtnDisabled()
{
$selected = self::allSelectedSubscriptions();
if (sizeof($selected) > 0 && !in_array($this->cartKey, $selected)) {
return 'disabled';
}
return '';
}
public function getCartKey()
{
return Cart::encodeKey('Subscriptions', $this->id);
}
public function setCart(CartModel $model)
{
$model->title = Ts::get(97) . ' - ' . $this->getTitle();
$model->subTitle = $this->months . ' ' . $this->getMonthLabel();
$model->description = $this->getDescription();
$model->singlePrice = $this->getFormatedPrice();
$model->price = $this->price;
$model->availableQuantity = 1;
/********************************/
$model->name_bg = $this->name . ' (абонамент)';
$model->name_en = $this->name_en. ' (subscription)';
$model->text_bg = $this->text. " ($this->months м)";
$model->text_en = $this->text_en. " ($this->months m)";
return $model;
}
}
@@ -0,0 +1,20 @@
<?php
namespace app\models;
/**
* Class TourStories
* @package app\models\register
* @property $id
* @property $name
* @property $name_en
* @property $text
* @property $text_en
* @property $longitude
* @property $latitude
* @property $partner_id
*/
class TourObjects extends _Base
{
}
+45
View File
@@ -0,0 +1,45 @@
<?php
namespace app\models;
/**
* Class Translation
* @package app\models
* @property $id
* @property $name
* @property $name_en
*/
class Ts extends _Base
{
public static function tableName() {
return 'translation';
}
private static function retrieve($ids) {
$phrases = [];
foreach (self::find()->where(['IN', 'id', $ids])->all() as $ts) {
switch (\Yii::$app->language){
default:
$phrases[$ts->id] = $ts->name;
break;
case 'en':
$phrases[$ts->id] = $ts->name_en;
break;
}
}
return $phrases;
}
public static function set($ids) {
\Yii::$app->params['ts'] = self::retrieve($ids);
}
public static function get($id) {
if(!empty(\Yii::$app->params['ts'])) {
if(!empty(\Yii::$app->params['ts'][$id])){
return \Yii::$app->params['ts'][$id];
}
}
return "id:$id";
}
}
@@ -0,0 +1,18 @@
<?php
namespace app\models;
/**
* Class UserExplorerObjects
* @package app\models
* @property $explorer_object_id
* @property $user_id
* @property $date_visit
* @property ExplorerObjects $exploreObject
*/
class UserExplorerObjects extends _Base
{
public function getExplorerObject()
{
return $this->hasOne(ExplorerObjects::class, ['id' => 'explorer_object_id']);
}
}
@@ -0,0 +1,18 @@
<?php
namespace app\models;
/**
* Class UserFavorites
* @package app\models
* @property $id
* @property $fid
* @property $table
* @property $user_id
* @property $date_added
*/
class UserFavorites extends _Base
{
}
@@ -0,0 +1,117 @@
<?php
namespace app\models;
/**
* Class UserPublic
* @package app\models
* @property $id
* @property $full_name
* @property $email
* @property $password
* @property $password_hash
* @property $club_card
* @property $has_double_auth
* @property $has_newsletter
* @property $open_id
* @property $is_active
* @property $is_mobile_user
* @property $user_agent
* @property $device_id
* @property $date_registered
* @property $favorites
* @property Order[] $orders;
* @property \app\models\QrValidators[] $qrValidators
*/
class UserPublic extends _Base
{
public function setPasswordHash($password)
{
$this->password_hash = password_hash($password, PASSWORD_DEFAULT);
}
public function getExplorerObjectsSumPoints()
{
return $this->hasMany(UserExplorerObjects::class, ['user_id' => 'id'])
->joinWith('explorerObject')->sum('points');
}
public function getExplorerObjectsIds()
{
$visited = UserExplorerObjects::find()->where(['user_id' => $this->id])->select('explorer_object_id')->all();
$visitedIds = [];
foreach ($visited as $v) {
$visitedIds[] = $v->explorer_object_id;
}
return $visitedIds;
}
public function profileData()
{
$lg = \Yii::$app->language;
$userData = [
'id' => $this->id,
'email' => $this->email,
'club_card' => $this->club_card,
'full_name' => $this->full_name,
'points' => $this->getExplorerObjectsSumPoints()
];
if (sizeof($this->qrValidators) > 0) {
$partners = [];
foreach ($this->qrValidators as $qrValidator) {
if ($qrValidator->partner) {
$partners[] = [
'id' => $qrValidator->partner_id,
'name' => $qrValidator->partner->{'name' . ($lg == 'en' ? '_en' : '')}
];
}
}
$userData['associate_partners'] = $partners;
}
return (object)$userData;
}
public function getOrders()
{
return $this->hasMany(Order::class, ['user_id' => 'id'])->orderBy(['order_date' => SORT_DESC])->all();
}
public function getQrValidators()
{
return $this->hasMany(QrValidators::class, ['user_id' => 'id']);
}
public function groupOrderItems() {
$order_bookings = [];
$order_publications = [];
$order_subscriptions = [];
$order_collections = [];
foreach ($this->orders as $order) {
foreach ($order->booking as $b) {
$order_bookings[$order->id][] = $b;
}
foreach ($order->subscriptions as $subscription) {
$order_subscriptions[$order->id][] = $subscription;
}
foreach ($order->collections as $collection) {
$order_collections[$order->id][] = $collection;
}
foreach ($order->publications as $publication) {
$order_publications[$order->id][] = $publication;
}
}
return [
'bookings' => $order_bookings,
'subscriptions' => $order_subscriptions,
'collections' => $order_collections,
'publications' => $order_publications
];
}
}
@@ -0,0 +1,32 @@
<?php
namespace app\models;
use yii\base\BaseObject;
/**
* Class UserSession
* @package app\models
* @property $id
* @property $user_type
* @property $result
* @property $session_type
* @property $sub
* @property $date_logged
*/
class UserSession extends _Base {
public static function log($session_type, $user_type, $sub) {
$userSession = UserSession::find()->where(['sub' => $sub])->one();
if($userSession) {
$userSession->date_logged = date('Y-m-d H:i:s');
$userSession->save();
} else {
$userSession = new UserSession();
$userSession->sub = $sub;
$userSession->session_type = $session_type;
$userSession->user_type = $user_type;
$userSession->date_logged = date('Y-m-d H:i:s');
$userSession->save();
}
}
}
@@ -0,0 +1,109 @@
<?php
namespace app\models;
use app\models\parsed\CartInterface;
use app\models\parsed\CartModel;
use yii\db\ActiveRecord;
/**
* Class _Base
* @package app\models
* @property $media_key
* @property $id
* @property $is_active
*/
class _Base extends ActiveRecord
{
public static function DOMAIN()
{
return \Yii::$app->params['media_server'];
}
public function getTableName() {
return self::getTableSchema()->name;
}
/**
* @param $object_key
* @param $rez
* @return string|null
*/
public function getSrcOfSingleImage($object_key, $rez = null, $default = null)
{
if ($this->media_key) {
/** @var FileCms $image */
$image = $this->hasOne(FileCms::class, ['media_key' => 'media_key'])
->where(['object_key' => $object_key])->orderBy(['order_index' => SORT_ASC])->one();
if ($image) {
$ready = self::DOMAIN() . '/_files/ready/' . $this->media_key . '/' . $image->object_key . '/' . $rez . '/' . $image->file_name;
if ($rez && $this->check_image_url($ready)) {
return $ready;
} else {
return self::DOMAIN() . '/_files/raw/' . $this->media_key . '/' . $image->object_key . '/' . $image->file_name;
}
}
}
return $default;
}
/**
* @param $object_key
* @param $rez
* @return array
*/
public function getSrcOfMultipleImages($object_key, $rez = null)
{
$srcArr = [];
if ($this->media_key) {
$images = $this->hasMany(FileCms::class, ['media_key' => 'media_key'])
->where(['object_key' => $object_key])->orderBy(['order_index' => SORT_ASC])->all();
/** @var FileCms $image */
foreach ($images as $image) {
if ($image) {
$ready = self::DOMAIN() . '/_files/ready/' . $this->media_key . '/' . $image->object_key . '/' . $rez . '/' . $image->file_name;
if ($rez && $this->check_image_url($ready)) {
$srcArr[] = $ready;
} else {
$srcArr[] = self::DOMAIN() . '/_files/raw/' . $this->media_key . '/' . $image->object_key . '/' . $image->file_name;
}
}
}
}
return $srcArr;
}
private function check_image_url($image_url) {
$headers = @get_headers($image_url);
if ($headers && strpos($headers[0], '200 OK') !== false) {
return true;
} else {
return false;
}
}
/**
* @param $object_key
* @param $rez
* @return string
*/
public function getSrcOfFirstImage($object_key, $rez = null)
{
if ($this->media_key) {
$image = $this->hasMany(FileCms::class, ['media_key' => 'media_key'])
->where(['object_key' => $object_key])->orderBy(['order_index' => SORT_ASC])->one();
/** @var FileCms $image */
if ($image) {
$ready = self::DOMAIN() . '/_files/ready/' . $this->media_key . '/' . $image->object_key . '/' . $rez . '/' . $image->file_name;
if ($rez && $this->check_image_url($ready)) {
return $ready;
} else {
return self::DOMAIN() . '/_files/raw/' . $this->media_key . '/' . $image->object_key . '/' . $image->file_name;
}
}
}
return '/_public/images/empty.png';
}
}
@@ -0,0 +1,15 @@
<?php
namespace app\models\parsed;
interface ArticleParsedInterface
{
public function id();
public function title($lg = null);
public function text();
public function textShort();
public function image($rez = null);
public function images($rez = null);
public function relation();
}
@@ -0,0 +1,10 @@
<?php
namespace app\models\parsed;
interface CartInterface
{
public function setCart(CartModel $model);
}
@@ -0,0 +1,22 @@
<?php
namespace app\models\parsed;
class CartModel
{
public $title;
public $subTitle;
public $description;
public $quantity;
public $singlePrice;
public $price;
public $datetime;
public $availableQuantity;
public $cartKey;
public $name_bg;
public $name_en;
public $text_bg;
public $text_en;
}
@@ -0,0 +1,12 @@
<?php
namespace app\models\parsed;
class FavoriteModel
{
public $name;
public $url;
public $img;
}
@@ -0,0 +1,49 @@
<?php
namespace app\models\parsed;
use app\models\Navigation;
use app\services\Auth;
use function GuzzleHttp\Psr7\str;
class NavigationParsed
{
public $name;
public $relation;
public function __construct(Navigation $model)
{
$lg = \Yii::$app->language;
$urlParams = \Yii::$app->request->get();
$partnerUrlAddition = '';
if (\Yii::$app->controller->id == 'partner') {
$partner = $lg == 'en' ? 'partner' : 'partnjor';
$partnerUrlAddition = $partner . '/' . $urlParams['partnerSlug'] . '/';
}
switch ($lg) {
default:
$this->name = $model->name;
if ($model->page_id) {
$this->relation = '/' . $lg . '/' . $partnerUrlAddition . $model->page->slug . '/';
} else {
$this->relation = $model->url ?? '#';
if(!empty($model->url_authorised) && (Auth::getUser() || !empty($_SESSION['register_user']))) {
$this->relation = $model->url_authorised;
}
}
break;
case 'en':
$this->name = $model->ts_en_name;
if ($model->page_id) {
$this->relation = '/' . $lg . '/' . $partnerUrlAddition . $model->page->slug_en . '/';
} else {
$this->relation = $model->url ?? '#';
if($model->url_authorised && (Auth::getUser() || !empty($_SESSION['register_user']))) {
$this->relation = $model->url_authorised;
}
}
}
}
}
@@ -0,0 +1,11 @@
<?php
namespace app\models\parsed;
interface Page
{
public function headerImage($rez = null);
public function headerTitle();
}
@@ -0,0 +1,13 @@
<?php
namespace app\models\parsed;
class SearchResultModel
{
public $id;
public $url;
public $text;
public $type;
}
@@ -0,0 +1,33 @@
<?php
namespace app\models\parsed;
use app\models\Slides;
class SlidesParsed
{
public $title;
public $text;
public $relation;
public $image;
public function __construct(Slides $model)
{
switch (\Yii::$app->language) {
default:
$this->title = $model->title;
$this->text = $model->text;
$this->relation = $model->relation;
break;
case 'en':
$this->title = $model->ts_en_title;
$this->text = $model->ts_en_text;
$this->relation = $model->ts_en_relation;
}
$this->image = $model->getSrcOfSingleImage('slide_home_page_image', '16:10');
}
}
@@ -0,0 +1,24 @@
<?php
namespace app\models\register;
/**
* Class CityList
* @package app\models\register
* @property $place
* @property CityOblast $cityOblast
* @property string $type
* @property string $name
*/
class CityList extends _BaseRegister
{
public function getPlace()
{
return $this->type . ' '.$this->name. ', обл. ' . $this->cityOblast->name;
}
public function getCityOblast() {
return $this->hasOne(CityOblast::class, ['oblast' => 'oblast']);
}
}
@@ -0,0 +1,14 @@
<?php
namespace app\models\register;
/**
* Class CityOblast
* @package app\models\register
* @property $name
*/
class CityOblast extends _BaseRegister
{
}
@@ -0,0 +1,10 @@
<?php
namespace app\models\register;
class CityObshtina extends _BaseRegister
{
}
@@ -0,0 +1,147 @@
<?php
namespace app\models\register;
use app\models\parsed\CartInterface;
use app\models\parsed\CartModel;
use app\models\Ts;
use app\services\Cart;
use app\services\Formatter;
use app\services\ViewReg;
/**
* Class Collection
* @package app\models\register
* @property $id
* @property $type
* @property $name
* @property $name_en
* @property $annotation
* @property $annotation_en
* @property $description
* @property $description_en
* @property $thumbnail
* @property $partner_id
* @property $published
* @property $active
* @property $deleted
* @property $added_on
* @property $added_by
* @property $modified_on
* @property $modified_by
* @property $is_selected
* @property $private
* @property $is_payable
* @property $cartKey
* @property \app\models\register\CollectionsObjects[] $collectionsObjects
*/
class Collections extends _BaseRegister implements CartInterface
{
public function getPartner()
{
return $this->hasOne(Partner::class, ['id' => 'partner_id']);
}
public function title()
{
if (\Yii::$app->language == 'en') {
return $this->name_en;
} else {
return $this->name;
}
}
public function textShort()
{
if (\Yii::$app->language == 'en') {
return $this->annotation_en;
} else {
return $this->annotation;
}
}
public function textDescription()
{
if (\Yii::$app->language == 'en') {
return $this->description_en;
} else {
return $this->description;
}
}
public function getImg($empty = null)
{
if ($this->thumbnail)
return \Yii::$app->params['register'].'/uploads/collections/' . $this->thumbnail;
return $empty ?? '/_public/images/empty.png';
}
public function getHeaderImg($empty = null)
{
if ($this->header_image)
return \Yii::$app->params['register'].'/uploads/collections/' . $this->header_image;
return $empty ?? '/_public/images/empty.png';
}
public function getUrl()
{
$slug = \Yii::$app->language == 'bg' ? 'kolektsii' : 'collections';
return '/' . \Yii::$app->language . '/' . ViewReg::partnerSite() . $slug . '/' . Formatter::encodeId($this->id) . '-' . Formatter::cyrillicTrans($this->name);
}
public function getCollectionsObjects()
{
return $this->hasMany(CollectionsObjects::class, ['collection_id' => 'id']);
}
public function getObjectsCount()
{
return sizeof($this->collectionsObjects);
}
public function objectCountLabel()
{
$count = $this->getObjectsCount();
$single = Ts::get(118);
$plural = Ts::get(47);
return $count == 1 ? $count . ' ' . $single : $count . ' ' . $plural;
}
public function imageCountLabel() {
$count = 0;
foreach ($this->collectionsObjects as $collectionsObject) {
$count += sizeof($collectionsObject->object->registerObjectImages);
}
$label = $count == 1 ? Ts::get(120) : Ts::get(121);
return $count . ' ' . $label;
}
public function getCartKey() {
return Cart::encodeKey('register\Collections', $this->id);
}
public function setCart(CartModel $model)
{
$model->title = $this->title();
$model->subTitle = Ts::get(117);//$this->months . ' ' . $this->getMonthLabel();
$model->description = $this->textShort(); // $this->getDescription();
$model->singlePrice = number_format($this->price, 2, '.', ' ') . ' лв.';
$model->price = $this->price;
$model->availableQuantity = 1;
/********************************/
$model->name_bg = $this->name . ' (колекция)';
$model->name_en = $this->name_en . ' (collection)';
$model->text_bg = $this->description;
$model->text_en = $this->description_en;
return $model;
}
}
@@ -0,0 +1,28 @@
<?php
namespace app\models\register;
use app\models\RegisterObjects;
/**
* Class CollectionsObjects
* @package app\models\register
* @property $id
* @property $collection_id
* @property $object_id
* @property $added_on
* @property $added_by
* @property RegisterObjects $object
* @property \app\models\register\Collections $collection
*/
class CollectionsObjects extends _BaseRegister
{
public function getCollection() {
return $this->hasOne(Collections::class, ['id' => 'collection_id']);
}
public function getObject() {
return $this->hasOne(RegisterObjects::class, ['ref_num' => 'object_id']);
}
}
@@ -0,0 +1,27 @@
<?php
namespace app\models\register;
/**
* Class Fields
* @package app\models\register
* @property $name
* @property $name_en
* @property \app\models\register\FieldsValues[] $fieldsValues
*
*/
class Fields extends _BaseRegister
{
public function getFieldsValues()
{
return $this->hasMany(FieldsValues::class, ['field_id' => 'id']);
}
public function getFieldValuesRelation() {
return $this->hasMany(FieldsValuesRelations::class, ['parent_field_id' => 'parent_id']);
}
public function getNameByLocale() {
return \Yii::$app->language == 'en' ? $this->name_en : $this->name;
}
}
@@ -0,0 +1,20 @@
<?php
namespace app\models\register;
/**
* Class FieldsValues
* @package app\models\register
* @property $name
* @property $name_en
* @property $option_id
*/
class FieldsValues extends _BaseRegister
{
public function getNameByLocale() {
return \Yii::$app->language == 'en' ? $this->name_en : $this->name;
}
}
@@ -0,0 +1,6 @@
<?php
namespace app\models\register;
class FieldsValuesRelations extends _BaseRegister {
}
@@ -0,0 +1,26 @@
<?php
namespace app\models\register;
/**
* Class ObjectTags
* @package app\models\register
* @property $id
* @property $object_id
* @property $tag_id
* @property $description
* @property $active
* @property $deleted
* @property $added_on
* @property $added_by
* @property $modified_on
* @property $modified_by
* @property \app\models\register\Tags $tag
*/
class ObjectTags extends _BaseRegister
{
public function getTag() {
return $this->hasOne(Tags::class, ['id' => 'tag_id']);
}
}
@@ -0,0 +1,66 @@
<?php
namespace app\models\register;
use app\services\Formatter;
/**
* Class Partner
* @package app\models\register
*
* @property $id
* @property $type
* @property $name_short
* @property $name
* @property $name_en
* @property $phone
* @property $email
* @property $website
* @property $contact_person
* @property $description
* @property $description_en
* @property $address
* @property $address_en
* @property $active
* @property $deleted
*/
class Partner extends _BaseRegister
{
public static function partnerList() {
$partnerList = [];
foreach (self::find()->all() as $partner) {
$partnerList[$partner->id] = $partner->getTsName();
}
return $partnerList;
}
public function getUrl() {
$lg = \Yii::$app->language;
$partners = $lg == 'en' ? 'partner' : 'partnjor';
$id = Formatter::encodeId($this->id);
return "/$lg/$partners/$id-" . Formatter::cyrillicTrans($this->getTsName());
}
public static function getPartnerBySlug($slug) {
$encodeId = explode('-', $slug)[0];
$id = Formatter::decodeId($encodeId);
/** @var \app\models\register\Partner $model */
return \app\models\register\Partner::findOne($id);
}
public function getTsName() {
$lg = \Yii::$app->language;
return $lg == 'en' ? $this->name_en : $this->name;
}
public function getDescription() {
$lg = \Yii::$app->language;
return $lg == 'en' ? $this->description_en : $this->description;
}
public function getAddress() {
$lg = \Yii::$app->language;
return $lg == 'en' ? $this->address_en : $this->address;
}
}
@@ -0,0 +1,35 @@
<?php
namespace app\models\register;
/**
* Class PhplistUserUser
* @package app\models\register
* @property $id
* @property $email
* @property $htmlemail
* @property $modified
* @property $entered
* @property $uniqid
*/
class PhplistUserUser extends _BasePhpList
{
public static function add($email) {
$phpListUser = PhplistUserUser::find()->where(['email' => $email])->one();
if(!$phpListUser) {
$phpListUser = new PhplistUserUser();
$phpListUser->email = $email;
$phpListUser->htmlemail = 1;
$phpListUser->entered = date('Y-m-d H:i:s');
$phpListUser->uniqid = uniqid();
} else {
$phpListUser->modified = date('Y-m-d H:i:s');
}
$phpListUser->save();
}
}
@@ -0,0 +1,34 @@
<?php
namespace app\models\register;
/**
* Class Tags
* @package app\models\register
*
* @property $id
* @property $lib_type
* @property $parent_id
* @property $level
* @property $text
* @property $text_en
* @property $active
* @property $deleted
* @property $added_on
* @property $added_by
* @property $modified_on
* @property $modified_by
* @property $objects
*/
class Tags extends _BaseRegister
{
public function getName() {
return \Yii::$app->language == 'en' ? $this->text_en : $this->text;
}
public function getObjects() {
return $this->hasMany(ObjectTags::class, ['tag_id' => 'id']);
}
}
@@ -0,0 +1,15 @@
<?php
namespace app\models\register;
use app\models\_Base;
class _BasePhpList extends _Base
{
public static function getDb()
{
return \Yii::$app->get('db_phplist');
}
}
@@ -0,0 +1,15 @@
<?php
namespace app\models\register;
use app\models\_Base;
class _BaseRegister extends _Base
{
public static function getDb()
{
return \Yii::$app->get('db_register');
}
}