[ 'class' => AccessControl::class, 'rules' => [ [ 'allow' => true, 'roles' => ['@'], 'matchCallback' => function ($rule, $action) { return $this->getUserModule() ->getAuthorizationChecker() ->isGrantedAsAdministrator($this->getUserCurrent()); } ], ], ], ]; } public function actionIndex() { return $this->render('index', [ 'supportOnline' => $this->getSettingModule()->getAdminSettingBag()->get('supportOnline'), 'countUsersOnline' => $this->getUserModule()->getRepository()->countUsersOnline(), 'countTicketsAdminOpen' => $this->getTicketModule()->getRepository()->countTicketsAdminStatusOpen(), 'countTicketsAdminUnread' => $this->getTicketModule()->getRepository()->countTicketsAdminUnreadByUser($this->getUserCurrent()), 'usersWithStatusProducerOnlineArray' => $this->getUserModule()->getRepository()->findUsersWithStatusProducerAndOnline() //'statisticsCacheHtml' => \Yii::$app->cache->get('dashboard_statistics12') ?: '', ]); } public function actionSupportOnlineToggle(int $active) { $this->getSettingModule()->getAdminSettingBag()->set('supportOnline', $active); return $this->redirect('index'); } public function actionAjaxStatisticsHtml() { return \Yii::$app->cache->getOrSet('dashboard_statistics12', function () { $producerModule = $this->getProducerModule(); $pointSaleModule = $this->getPointSaleModule(); $userModule = $this->getUserModule(); $orderModule = $this->getOrderModule(); $countProducersActive = $producerModule->getRepository()->countProducersActiveWithTurnover(); $countPointSalesActive = $pointSaleModule->countPointSalesActiveLastThreeMonths(); $countUsersActive = $userModule->countUsersActiveLastThreeMonths(); $averageOrdersPerDay = $orderModule->countGlobalUserOrdersAverageLastSevenDays(); $turnoverLastThirtyDays = $orderModule->getRepository()->getTurnoverLastThirtyDays(); $resultMatomoApiVisitSummary = json_decode(file_get_contents(\Yii::$app->parameterBag->get('matomoApiVisitSummaryUrl'))); $numberVisitsDay = $resultMatomoApiVisitSummary->nb_uniq_visitors / 30; $amountBilledLastMonth = $producerModule->getRepository()->getAmountBilledLastMonth(); $amountToBillCurrentMonth = $producerModule->getRepository()->getAmountToBillCurrentMonth(); $amountProducerUnpaidInvoices = $producerModule->getDolibarrUtils()->getAmountProducerInvoicesUnpaid(); return $this->renderPartial('_statistics', [ 'amountBilledLastMonth' => $amountBilledLastMonth, 'amountToBillCurrentMonth' => $amountToBillCurrentMonth, 'amountProducerUnpaidInvoices' => $amountProducerUnpaidInvoices, 'countProducersActive' => $countProducersActive, 'countPointSalesActive' => $countPointSalesActive, 'countUsersActive' => $countUsersActive, 'averageOrdersPerDay' => $averageOrdersPerDay, 'turnoverLastThirtyDays' => $turnoverLastThirtyDays, 'numberVisitsDay' => $numberVisitsDay ]); }, 60 * 60 * 24); } }