refactor(Core): refactor and optimize code
This commit is contained in:
48
app/Controllers/DashboardController.php
Normal file
48
app/Controllers/DashboardController.php
Normal 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'
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user