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;