49 lines
1.5 KiB
PHP
49 lines
1.5 KiB
PHP
<?php
|
|
namespace Sodino\Controllers;
|
|
|
|
use Sodino\Repositories\EventRepository;
|
|
use Sodino\Repositories\RuleRepository;
|
|
use Sodino\Services\AnalyticsService;
|
|
|
|
/**
|
|
* Dashboard Controller
|
|
*/
|
|
class DashboardController extends BaseController {
|
|
private $analyticsService;
|
|
|
|
public function __construct(EventRepository $eventRepository, RuleRepository $ruleRepository) {
|
|
$this->analyticsService = new AnalyticsService($eventRepository, $ruleRepository);
|
|
}
|
|
|
|
/**
|
|
* Dashboard page
|
|
*/
|
|
public function index() {
|
|
$this->checkCapability();
|
|
|
|
$filters = [
|
|
'range' => $this->getQueryData('range', '7d'),
|
|
'start_date' => $this->getQueryData('start_date', ''),
|
|
'end_date' => $this->getQueryData('end_date', ''),
|
|
'product_id' => intval($this->getQueryData('product_id', 0)),
|
|
'category_id' => intval($this->getQueryData('category_id', 0)),
|
|
];
|
|
|
|
if (!empty($filters['product_id'])) {
|
|
$filters['product_ids'] = [$filters['product_id']];
|
|
}
|
|
|
|
$dashboardData = $this->analyticsService->getDashboardData($filters);
|
|
$productOptions = $this->analyticsService->getProductOptions();
|
|
$categoryOptions = $this->analyticsService->getCategoryOptions();
|
|
|
|
$this->render('dashboard', [
|
|
'dashboardData' => $dashboardData,
|
|
'productOptions' => $productOptions,
|
|
'categoryOptions' => $categoryOptions,
|
|
'filters' => $filters,
|
|
'current_page' => 'sodino-dashboard'
|
|
]);
|
|
}
|
|
}
|