summaryrefslogtreecommitdiffstats
path: root/inc/dashboard.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2016-04-28 21:31:15 +0200
committerSimon Rettberg2016-04-28 21:31:15 +0200
commit95db8e184b378534db0ac08d14ae8500ee5090c3 (patch)
treef39cee8160ef4266e49dbe04d3e8fe6400ce2133 /inc/dashboard.inc.php
parentMerge branch 'master' into modularization (diff)
downloadslx-admin-95db8e184b378534db0ac08d14ae8500ee5090c3.tar.gz
slx-admin-95db8e184b378534db0ac08d14ae8500ee5090c3.tar.xz
slx-admin-95db8e184b378534db0ac08d14ae8500ee5090c3.zip
Implemented new menu, added logic for defining dependencies, move translation files around
Diffstat (limited to 'inc/dashboard.inc.php')
-rw-r--r--inc/dashboard.inc.php71
1 files changed, 71 insertions, 0 deletions
diff --git a/inc/dashboard.inc.php b/inc/dashboard.inc.php
new file mode 100644
index 00000000..ef8be110
--- /dev/null
+++ b/inc/dashboard.inc.php
@@ -0,0 +1,71 @@
+<?php
+
+class Dashboard
+{
+
+ private static $iconCache = array();
+
+ public static function createMenu()
+ {
+ $modulesAssoc = array();
+ $all = Module::getEnabled();
+ foreach ($all as $module) {
+ $cat = $module->getCategory();
+ if ($cat === false)
+ continue;
+ $modulesAssoc[$cat][] = $module;
+ }
+ $modulesArray = array();
+ foreach ($modulesAssoc as $id => $list) {
+ $momomo = array();
+ foreach ($list as $module) {
+ $momomo[] = array(
+ 'displayName' => $module->getDisplayName(),
+ 'identifier' => $module->getIdentifier(),
+ 'className' => ($module->getIdentifier() === Page::getModule()->getIdentifier()) ? 'active' : ''
+ );
+ }
+ $modulesArray[] = array(
+ 'icon' => self::getCategoryIcon($id),
+ 'displayName' => Dictionary::getCategoryName($id),
+ 'modules' => $momomo
+ );
+ }
+ Render::setDashboard(array(
+ 'categories' => $modulesArray,
+ 'url' => urlencode($_SERVER['REQUEST_URI']),
+ 'langs' => Dictionary::getLanguages(true),
+ 'dbupdate' => Database::needSchemaUpdate(),
+ 'user' => User::getName(),
+ 'warning' => User::getName() !== false && User::getLastSeenEvent() < Property::getLastWarningId(),
+ 'needsSetup' => User::getName() !== false && Property::getNeedsSetup()
+ ));
+ }
+
+ public static function getCategoryIcon($category)
+ {
+ if ($category === false) {
+ return '';
+ }
+ if (!preg_match('/^(\w+)\.(\w+)$/', $category, $out)) {
+ error_log('Requested category icon for invalid category "' . $category . '"');
+ return '';
+ }
+ $module = $out[1];
+ $icon = $out[2];
+ if (!isset(self::$iconCache[$module])) {
+ $path = 'modules/' . $module . '/category-icons.json';
+ $data = json_decode(file_get_contents($path), true);
+ if (!is_array($data)) {
+ return '';
+ }
+ self::$iconCache[$module] =& $data;
+ }
+ if (!isset(self::$iconCache[$module][$icon])) {
+ error_log('Icon "' . $icon . '" not found in module "' . $module . '"');
+ return '';
+ }
+ return 'glyphicon glyphicon-' . self::$iconCache[$module][$icon];
+ }
+
+} \ No newline at end of file