Initial import
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
use app\models\Articles;
|
||||
use app\models\Expositions;
|
||||
|
||||
$lg = Yii::$app->language;
|
||||
$per_page = 10;
|
||||
$page = $_GET['page'] ?? 1
|
||||
/**
|
||||
* @var \yii\web\View $this
|
||||
*/
|
||||
?>
|
||||
|
||||
<?php
|
||||
|
||||
$condition = [];
|
||||
|
||||
$condition['is_active'] = 1;
|
||||
|
||||
$expositions = Expositions::find()->where($condition);
|
||||
|
||||
$expositions = $expositions->offset($per_page * $page - $per_page)->limit($per_page);
|
||||
|
||||
if (!empty($_GET['category']))
|
||||
$expositions = $expositions->andWhere(['category_id' => $_GET['category']]);
|
||||
|
||||
if (!empty($_GET['tags'])) {
|
||||
$tags = explode('_', $_GET['tags']);
|
||||
if (sizeof($tags) > 0)
|
||||
$expositions->joinWith('expositionTags')->andWhere(['IN', 'exposition_tag_id', $tags]);
|
||||
}
|
||||
$count = $expositions->count();
|
||||
$expositions->orderBy(['publish_date' => SORT_DESC]);
|
||||
$data = [];
|
||||
foreach ($expositions->all() as $exposition) {
|
||||
$model = new \stdClass();
|
||||
$model->title = $exposition->title();
|
||||
$model->type = 'exposition';
|
||||
$model->img = $exposition->getImg();
|
||||
$model->id = $exposition->id;
|
||||
$data[] = $model;
|
||||
}
|
||||
header('Content-type: application/json');
|
||||
echo json_encode(['data' => $data, 'lastPage' => ceil($count/$per_page), 'count' => $count]);
|
||||
exit;
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user