From 9d7455c05937c058aed8f91d31f07defe37ec53b Mon Sep 17 00:00:00 2001 From: Praesidiarius Date: Tue, 28 Jan 2020 10:34:22 +0100 Subject: [PATCH] daily stats widget --- module/Application/data/data.sql | 11 +++++- module/Application/data/structure.sql | 37 ++++++++++++++++++- .../src/Controller/ApiController.php | 22 +++++++++++ .../src/Controller/CoreController.php | 1 + 4 files changed, 69 insertions(+), 2 deletions(-) diff --git a/module/Application/data/data.sql b/module/Application/data/data.sql index f266d95..d1b8203 100644 --- a/module/Application/data/data.sql +++ b/module/Application/data/data.sql @@ -15,4 +15,13 @@ INSERT INTO `permission` (`permission_key`, `module`, `label`, `nav_label`, `nav ('index', 'Application\\Controller\\IndexController', 'Home', 'Home', '/', 0), ('update', 'Application\\Controller\\IndexController', 'Updates', '', '', 0), ('addtheme', 'Application\\Controller\\IndexController', 'Upload Theme', '', '/application/addtheme', 0), -('themes', 'Application\\Controller\\IndexController', 'Theme Selection', '', '/application/themes', 0); \ No newline at end of file +('themes', 'Application\\Controller\\IndexController', 'Theme Selection', '', '/application/themes', 0); + +-- +-- Default Widgets +-- +INSERT INTO `core_widget` (`Widget_ID`, `widget_name`, `label`, `permission`) VALUES +(NULL, 'manage_themes', 'Manage Themes', 'themes-Application\\Controller\\IndexController'), +(NULL, 'discover_modules', 'Discover Modules', 'update-Application\\Controller\\IndexController'), +(NULL, 'help_support', 'Help & Support', 'index-Application\\Controller\\IndexController'), +(NULL, 'welcome_default', 'Welcome Default', 'index-Application\\Controller\\IndexController'); \ No newline at end of file diff --git a/module/Application/data/structure.sql b/module/Application/data/structure.sql index 627e721..b873227 100644 --- a/module/Application/data/structure.sql +++ b/module/Application/data/structure.sql @@ -3,7 +3,9 @@ -- CREATE TABLE `core_form` ( `form_key` varchar(50) NOT NULL, - `label` varchar(100) NOT NULL + `label` varchar(100) NOT NULL, + `entity_class` varchar(255) NOT NULL, + `entity_tbl_class` varchar(255) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; ALTER TABLE `core_form` @@ -50,6 +52,23 @@ CREATE TABLE `core_form_tab` ( ALTER TABLE `core_form_tab` ADD PRIMARY KEY (`Tab_ID`); +-- +-- Core Widget +-- +CREATE TABLE `core_widget` ( + `Widget_ID` int(11) NOT NULL, + `widget_name` varchar(100) NOT NULL, + `label` varchar(255) NOT NULL, + `permission` varchar(255) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +ALTER TABLE `core_widget` + ADD PRIMARY KEY (`Widget_ID`), + ADD UNIQUE KEY `widget_name` (`widget_name`); + +ALTER TABLE `core_widget` + MODIFY `Widget_ID` int(11) NOT NULL AUTO_INCREMENT; + -- -- Core Index Table -- @@ -131,6 +150,22 @@ CREATE TABLE `settings` ( ALTER TABLE `settings` ADD PRIMARY KEY (`settings_key`); +-- +-- Statistics +-- +CREATE TABLE `core_statistic` ( + `Statistic_ID` int(11) NOT NULL, + `stats_key` varchar(100) NOT NULL, + `data` text NOT NULL, + `date` datetime NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +ALTER TABLE `core_statistic` + ADD PRIMARY KEY (`Statistic_ID`); + +ALTER TABLE `core_statistic` + MODIFY `Statistic_ID` int(11) NOT NULL AUTO_INCREMENT; + -- -- Save -- diff --git a/module/Application/src/Controller/ApiController.php b/module/Application/src/Controller/ApiController.php index 01e95e2..a3466ea 100644 --- a/module/Application/src/Controller/ApiController.php +++ b/module/Application/src/Controller/ApiController.php @@ -16,6 +16,7 @@ declare(strict_types=1); namespace Application\Controller; +use Laminas\ServiceManager\Exception\ServiceNotFoundException; use Laminas\View\Model\ViewModel; class ApiController extends CoreController { @@ -69,4 +70,25 @@ public function getAction() { $iID = $this->params()->fromRoute('id',0); return $this->redirect()->toRoute($sModule.'-api',['action'=>'get','id'=>$iID],['query'=>['authkey'=>$_REQUEST['authkey']]]); } + + public function gendailystatsAction() { + $this->layout('layout/json'); + + # Load all forms from database + $oFormsDB = CoreController::$aCoreTables['core-form']->select(); + if(count($oFormsDB) > 0) { + foreach($oFormsDB as $oForm) { + try { + $oLogTbl = CoreController::$oServiceManager->get($oForm->entity_tbl_class); + if(method_exists($oLogTbl,'generateDailyStats')) { + $oLogTbl->generateDailyStats(); + } + } catch (ServiceNotFoundException $e) { + + } + } + } + + return false; + } } diff --git a/module/Application/src/Controller/CoreController.php b/module/Application/src/Controller/CoreController.php index 0bbb517..1cd2eef 100644 --- a/module/Application/src/Controller/CoreController.php +++ b/module/Application/src/Controller/CoreController.php @@ -120,6 +120,7 @@ public function __construct(AdapterInterface $oDbAdapter,$oTableGateway = false, CoreController::$aCoreTables['user-xp-activity'] = new TableGateway('user_xp_activity', CoreController::$oDbAdapter); CoreController::$aCoreTables['core-widget'] = new TableGateway('core_widget',CoreController::$oDbAdapter); CoreController::$aCoreTables['user-widget'] = new TableGateway('core_widget_user',CoreController::$oDbAdapter); + CoreController::$aCoreTables['core-statistic'] = new TableGateway('core_statistic',CoreController::$oDbAdapter); $this->loadSettings(); }