Files
Admin Nasledstvo ac168868ee Initial import
2026-05-01 20:52:04 +03:00

49 lines
1.6 KiB
PHP

<?php
$data = [];
$favorite = false;
if (!empty($_GET['id'])) {
$user = \app\services\Auth::getUserByToken();
if($user) {
$favoriteExists = \app\models\UserFavorites::find()->where(['user_id' => $user->id, 'table' => 'collections', 'fid' => $_GET['id']])->exists();
if($favoriteExists)
$favorite = true;
}
$lg = \Yii::$app->language;
$condition = [];
$condition = ['and'];
$condition[] = ['=', 'active', 1];
$condition[] = ['=', 'published', 1];
$condition[] = ['=', 'id', $_GET['id']];
$collections = \app\models\register\Collections::find()->where($condition);
$collection = $collections->one();
if ($collection) {
$model = new \stdClass();
$model->title = $lg == 'en' ? $collection->name_en ?? $collection->name : $collection->name;
$model->type = 'collections';
$model->text = strip_tags($collection->textDescription());
$model->img = $collection->getImg(\Yii::$app->params['portal'] . '/_public/images/empty-169.png');
$model->id = $collection->id;
$model->isFavorite = $favorite;
$model->items = [];
foreach ($collection->collectionsObjects as $collectionsObject) {
$object = $collectionsObject->object;
$item = new stdClass();
$item->id = $object->id;
$item->title = $object->getTitle();
$item->image = $object->getImg();
$model->items[] = $item;
}
$data[] = $model;
}
}
header('Content-type: application/json');
echo json_encode(['data' => $data]);
exit;