60 lines
1.6 KiB
PHP
60 lines
1.6 KiB
PHP
<?php
|
|
|
|
use app\models\Articles;
|
|
|
|
$lg = \Yii::$app->language;
|
|
|
|
$articles = Articles::find();
|
|
|
|
$data = [];
|
|
$page = $_GET['page'] ?? 1;
|
|
$per_page = 10;
|
|
$condition = ['and'];
|
|
//$condition['is_active'] = 1;
|
|
if (!empty($_GET['type']) && $_GET['type'] != 'default')
|
|
$condition[] = ['=', 'art_table', $_GET['type']];
|
|
//region [Articles]
|
|
|
|
if (!empty($_GET['token'])) {
|
|
/** @var \app\models\UserPublic $user */
|
|
$user = \app\services\Auth::getUserByToken($_GET['token']);
|
|
if ($user) {
|
|
$partner_ids = [];
|
|
foreach ($user->qrValidators as $qrValidator) {
|
|
$partner_ids[] = $qrValidator->partner_id;
|
|
}
|
|
if (sizeof($partner_ids) > 0) {
|
|
$articles->innerJoinWith('events');
|
|
|
|
$condition[] = ['=', 'type', 'booking'];
|
|
$condition[] = ['IN', 'events.partner_id', $partner_ids];
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
$articles->where($condition);
|
|
|
|
$articles->orderBy(['publish_date' => SORT_DESC])
|
|
->offset($page * $per_page - $per_page)->limit($per_page);
|
|
|
|
$count = $articles->count();
|
|
$lastPage = ceil($count / $per_page);
|
|
|
|
foreach ($articles->all() as $article) {
|
|
if ($article->article) {
|
|
$model = new \stdClass();
|
|
$model->title = $lg == 'en' ? $article->title_en ?? $article->title : $article->title;
|
|
$model->type = $article->art_table;
|
|
$model->img = $article->article->image() ?? \Yii::$app->params['portal'] . '/_public/images/empty-169.png';
|
|
$model->id = $article->id;
|
|
$data[] = $model;
|
|
}
|
|
}
|
|
|
|
header('Content-type: application/json');
|
|
echo json_encode(['data' => $data, 'lastPage' => $lastPage, 'count' => $count]);
|
|
exit;
|