refactor(Core): refactor and optimize code

This commit is contained in:
2026-05-06 00:54:24 +03:30
parent 32c065e4b6
commit dec4e67b9e
20 changed files with 1787 additions and 361 deletions

View File

@@ -0,0 +1,48 @@
<?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'
]);
}
}