Skip to content

Commit

Permalink
daily stats widget
Browse files Browse the repository at this point in the history
  • Loading branch information
Praesidiarius committed Jan 28, 2020
1 parent 23188a9 commit 9d7455c
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
11 changes: 10 additions & 1 deletion module/Application/data/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);
('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');
37 changes: 36 additions & 1 deletion module/Application/data/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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
--
Expand Down Expand Up @@ -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
--
Expand Down
22 changes: 22 additions & 0 deletions module/Application/src/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions module/Application/src/Controller/CoreController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 9d7455c

Please sign in to comment.