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,345 @@
<?php
namespace app\controllers;
use app\models\Articles;
use app\models\Expositions;
use app\models\Navigation;
use app\models\News;
use app\models\Pages;
use app\models\parsed\SearchResultModel;
use app\models\Projects;
use app\models\register\Collections;
use app\models\register\CollectionsObjects;
use app\models\register\Partner;
use app\models\RegisterObjects;
use app\models\Ts;
use app\models\UserFavorites;
use app\models\UserSession;
use app\services\Auth;
use app\services\Formatter;
use app\services\GeoService;
use app\services\ViewReg;
class RemoteController extends BaseController
{
public function beforeAction($action)
{
if (!empty($_GET['partner_id'])) {
$partner = Partner::findOne($_GET['partner_id']);
$this->partnerSlug = Formatter::encodeId($partner->id) . '-' . Formatter::cyrillicTrans($partner->getTsName());
}
return parent::beforeAction($action); // TODO: Change the autogenerated stub
}
public function actionGetArticles()
{
Ts::set([12, 13, 14]);
return $this->renderPartial('list_article');
}
public function actionGetProjects()
{
return $this->renderPartial('list_project');
}
public function actionGetELibrary()
{
Ts::set([155, 162, 163, 164, 165]);
return $this->renderPartial('list_e_library_new');
}
public function actionGetCollections()
{
Ts::set([12, 13, 14, 155, 162, 163, 164, 165, 184]);
return $this->renderPartial('list_collection');
}
public function actionGetCollectionObjects()
{
return $this->renderPartial('list_collection_objects');
}
public function actionGetExpositionObjects()
{
return $this->renderPartial('list_exposition_objects');
}
public function actionGetExpositions()
{
Ts::set([12, 13, 14]);
return $this->renderPartial('list_exposition');
}
public function actionGetObjectsVideos()
{
return $this->renderPartial('list_collection_objects_videos', ['object_id' => $_GET['object_id']]);
}
public function actionGetObjectsModels()
{
return $this->renderPartial('list_collection_objects_models', ['object_id' => $_GET['object_id']]);
}
public function actionGetSpecificFilter()
{
if (!empty($_GET['parent_id'])) {
return $this->renderPartial('specific_filter', ['parent_id' => $_GET['parent_id'], 'content_lib_type' => null]);
}
}
public function actionSearch()
{
Ts::set([185, 186, 187, 117, 118, 170, 188, 189]);
$lg = \Yii::$app->language;
$data = [];
$q = $_GET['q'];
//$_GET['q'] = '&#x42F;в&#x43E;р&#x43E;в,%20&#x41F;ей&#x43E;%20&#x41A;рач&#x43E;&#x43B;&#x43E;в';
//region [INTERNAL PAGES]
$pages = Pages::find()->andWhere(['or', ['LIKE', 'name', $_GET['q']], ['LIKE', 'name_en', $_GET['q']]])->limit(20)->all();
foreach ($pages as $page) {
$model = new SearchResultModel();
$model->text = $lg == 'en' ? $page->name_en ?? $page->name : $page->name;
$model->type = $lg == 'en' ? 'Web page' : 'Вътрешна страница';
$model->url = '/' . $lg . '/' . ($lg == 'en' ? $page->slug_en : $page->slug) . '/';
$model->id = $page->id;
if ($model->text)
$data[] = $model;
}
//endregion
//region [EXTERNAL PAGES]
$links = Navigation::find()
->where(['IS NOT', 'url', NULL])
->andWhere(['or', ['LIKE', 'name', $_GET['q']], ['LIKE', 'ts_en_name', $_GET['q']]])->limit(20)->all();
$bufferDuplicates = [];
foreach ($links as $link) {
if ($link->url) {
$model = new SearchResultModel();
$model->text = $lg == 'en' ? $link->ts_en_name ?? $link->name : $link->name;
$model->type = $lg == 'en' ? 'External web page' : 'Външна страница';
$model->url = $link->url;
$model->id = $link->id;
$buffer = (object)[$model->text, $link->url];
if (!in_array($buffer, $bufferDuplicates)) {
$bufferDuplicates[] = $buffer;
if ($model->text)
$data[] = $model;
}
}
}
//endregion
//region [Articles]
$articles = Articles::find()->where(['is_active' => 1])->andWhere(['or', ['LIKE', 'title', $_GET['q']], ['LIKE', 'title_en', $_GET['q']]])->limit(20)->all();
foreach ($articles as $article) {
if ($article->article) {
$title_en = $article->title_en ?? $article->title;
$model = new SearchResultModel();
$model->text = $lg == 'en' ? $title_en : $article->title;
$model->type = $article->getSingleArticleLabel();
$model->url = ViewReg::generateDetailPageUrl($article);
$model->id = $article->id;
if ($model->text)
$data[] = $model;
}
}
//endregion
//region [Collection]
$collections = Collections::find()->where(['published' => 1, 'deleted' => 0])->andWhere(['or', ['LIKE', 'name', $_GET['q']], ['LIKE', 'name_en', $_GET['q']]])->limit(20)->all();
foreach ($collections as $collection) {
$model = new SearchResultModel();
$model->text = $lg == 'en' ? $collection->name_en ?? $collection->name : $collection->name;
$model->type = Ts::get(117);
$model->url = $collection->getUrl();
$model->id = $collection->id;
if ($model->text)
$data[] = $model;
}
//endregion
//region [Expositions]
$expositions = Expositions::find()->where(['is_active' => 1])->andWhere(['or', ['LIKE', 'name', $_GET['q']], ['LIKE', 'ts_en_name', $_GET['q']]])->limit(20)->all();
foreach ($expositions as $exposition) {
$model = new SearchResultModel();
$model->text = $lg == 'en' ? $exposition->ts_en_name ?? $exposition->name : $exposition->name;
$model->type = Ts::get(188);
$model->url = $exposition->getUrl();
$model->id = $exposition->id;
if ($model->text)
$data[] = $model;
}
//endregion
//region [Objects]
$objects = RegisterObjects::find()
->where(['is_active' => 1, 'lib_type' => 1])
->andWhere(['or',
['LIKE', 'created_by', $q],
['LIKE', 'name', $q],
['LIKE', 'ts_en_name', $q]
])
->limit(20)->all();
foreach ($objects as $object) {
$model = new SearchResultModel();
$name_en = !empty($object->ts_en_name) ? $object->ts_en_name : $object->name;
$model->text = $lg == 'en' ? $name_en : $object->name;
$model->type = Ts::get(118);
$model->url = $object->getUrl();
$model->id = $object->id;
if ($model->text)
$data[] = $model;
}
//endregion
//region [E-library]
$objects = RegisterObjects::find()
->where(['is_active' => 1, 'lib_type' => 2])
->andWhere(['or',
['LIKE', 'created_by', $_GET['q']],
['LIKE', 'name', $_GET['q']],
['LIKE', 'ts_en_name', $_GET['q']]
])->limit(20)->all();
foreach ($objects as $object) {
$model = new SearchResultModel();
$name_en = !empty($object->ts_en_name) ? $object->ts_en_name : $object->name;
$model->text = $lg == 'en' ? $name_en : $object->name;
$model->type = Ts::get(170);
$model->url = $object->getLibraryUrl();
$model->id = $object->id;
//if ($model->text)
$data[] = $model;
}
//endregion
//region [Projects]
$projects = Projects::find()->where(['is_active' => 1])->andWhere(['or', ['LIKE', 'title', $_GET['q']], ['LIKE', 'ts_en_title', $_GET['q']]])->limit(20)->all();
foreach ($projects as $project) {
$title_en = $project->ts_en_title ?? $project->title;
$model = new SearchResultModel();
$model->text = $lg == 'en' ? $title_en : $project->title;
$model->type = Ts::get(189);
$model->url = ViewReg::generateDefaultDetailUrl('projects', $project->id, $project->title());
$model->id = $project->id;
if ($model->text)
$data[] = $model;
}
//endregion
return $this->renderPartial('search-result', ['data' => $data]);
}
public function actionFavorites()
{
$data = json_decode(\Yii::$app->request->getRawBody());
$user = Auth::getUser();
if (!empty($data->fid) && !empty($data->table) && $user) {
$fav = UserFavorites::find()->where(['fid' => $data->fid, 'table' => $data->table, 'user_id' => $user->id])->one();
if ($fav) {
$data->{'action'} = 'remove';
$fav->delete();
} else {
$fav = new UserFavorites();
$fav->fid = $data->fid;
$fav->table = $data->table;
$fav->user_id = $user->id;
$fav->date_added = date('Y-m-d H:i:s');
$fav->save();
$data->{'action'} = 'add';
}
}
return $this->asJson($data);
}
public function actionCheckActivity()
{
$user = Auth::getUser();
if ($user && $user->open_id) {
$us = UserSession::find()->where(['sub' => $user->open_id])->one();
if (!$us) {
Auth::setUser();
return $this->asJson(['status' => 'inactive', 'redirect' => \Yii::$app->goHome()]);
} else {
return $this->asJson(['status' => 'active']);
}
} else if (!empty($_SESSION['register_user'])) {
$us = UserSession::find()->where(['sub' => $_SESSION['register_user']])->one();
if (!$us) {
unset($_SESSION['register_user']);
return $this->asJson(['status' => 'inactive', 'redirect' => \Yii::$app->goHome()]);
} else {
return $this->asJson(['status' => 'active']);
}
}
}
public function actionGetNearestObjects()
{
if (!empty($_GET['lat']) && !empty($_GET['lon']) && !empty($_GET['dist'])) {
$lat = $_GET['lat'];
$lon = $_GET['lon'];
$dist = $_GET['dist'];
if (empty($_GET['explorer'])) {
return $this->asJson(GeoService::getNearestObjects($lat, $lon, $dist)['data']);
} else {
$nearest = GeoService::getNearestObjects($lat, $lon, $dist);
return $this->asJson(GeoService::orderList($nearest));
}
}
}
public function actionUserCardEnable()
{
$user = Auth::getUser();
if ($user) {
$user->club_card = 1;
$user->save();
echo json_encode(['success' => 1]);
} else {
echo json_encode(['success' => 0]);
}
exit;
}
public function actionUserCardDisable()
{
$user = Auth::getUser();
if ($user) {
$user->club_card = null;
$user->save();
echo json_encode(['success' => 1]);
} else {
echo json_encode(['success' => 0]);
}
exit;
}
public function actionObjectGallery()
{
if (!empty($_GET['object_id']))
return $this->renderPartial('object_gallery_preview');
exit;
}
}