2024-10-16 17:54:33 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace app\modules\module_shop\controllers;
|
|
|
|
|
|
|
|
use app\modules\module_shop\models\ModuleShop;
|
2024-10-23 16:16:47 +03:00
|
|
|
use kernel\Request;
|
2024-10-16 17:54:33 +03:00
|
|
|
use kernel\RestController;
|
|
|
|
|
|
|
|
class ModuleShopRestController extends RestController
|
|
|
|
{
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->model = new ModuleShop();
|
|
|
|
}
|
|
|
|
|
2024-10-23 16:16:47 +03:00
|
|
|
public function actionIndex(): void
|
|
|
|
{
|
|
|
|
$request = new Request();
|
|
|
|
$page = $request->get('page') ?? 1;
|
|
|
|
$perPage = $request->get('per_page') ?? 10;
|
|
|
|
$query = $this->model->query();
|
|
|
|
|
|
|
|
if ($page > 1) {
|
|
|
|
$query->skip(($page - 1) * $perPage)->take($perPage);
|
|
|
|
} else {
|
|
|
|
$query->take($perPage);
|
|
|
|
}
|
|
|
|
|
|
|
|
$query->groupBy("slug")->orderBy("id", "ASC");
|
|
|
|
$expand = $this->expand();
|
|
|
|
$expandParams = explode( ",", $request->get('expand') ?? "");
|
|
|
|
$finalExpand = array_intersect($expandParams, $expand);
|
|
|
|
if ($finalExpand) {
|
|
|
|
$res = $query->get()->load($finalExpand)->toArray();
|
|
|
|
} else {
|
|
|
|
$res = $query->get()->toArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->renderApi($res);
|
|
|
|
}
|
|
|
|
|
2024-10-16 17:54:33 +03:00
|
|
|
}
|