mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-23 18:02:18 +00:00
Merge branch 'feature-24647/Konfigurierbare_Dashboards' into feature-25999/C4
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
<?php
|
||||
defined('BASEPATH') || exit('No direct script access allowed');
|
||||
|
||||
use \stdClass as stdClass;
|
||||
|
||||
/**
|
||||
* Description of DashboardLib
|
||||
*
|
||||
@@ -14,7 +17,7 @@ class DashboardLib
|
||||
|
||||
private $_ci; // CI instance
|
||||
|
||||
public function __construct($params=null)
|
||||
public function __construct()
|
||||
{
|
||||
// Loads CI instance
|
||||
$this->_ci =& get_instance();
|
||||
@@ -24,28 +27,27 @@ class DashboardLib
|
||||
$this->_ci->load->model('dashboard/Dashboard_Override_model', 'DashboardOverrideModel');
|
||||
}
|
||||
|
||||
public function generateWidgetId($dashboard_kurzbz='')
|
||||
public function generateWidgetId($dashboard_kurzbz = '')
|
||||
{
|
||||
$dashboard_kurzbz = (!empty($dashboard_kurzbz)) ? $dashboard_kurzbz
|
||||
: self::DEFAULT_DASHBOARD_KURZBZ;
|
||||
$widgetid_input = time() . '_' . $dashboard_kurzbz . '_'
|
||||
. bin2hex(random_bytes(self::WIDGET_ID_RANDOM_BYTES));
|
||||
$dashboard_kurzbz = (!empty($dashboard_kurzbz)) ? $dashboard_kurzbz : self::DEFAULT_DASHBOARD_KURZBZ;
|
||||
$widgetid_input = time() . '_' . $dashboard_kurzbz . '_' . bin2hex(random_bytes(self::WIDGET_ID_RANDOM_BYTES));
|
||||
$widgetid = md5($widgetid_input);
|
||||
return $widgetid;
|
||||
}
|
||||
|
||||
public function getDashboardByKurzbz($dashboard_kurzbz)
|
||||
public function getDashboardByKurzbz($dashboard_kurzbz)
|
||||
{
|
||||
$dashboard = null;
|
||||
$result = $this->_ci->DashboardModel->getDashboardByKurzbz($dashboard_kurzbz);
|
||||
if( isSuccess($result) && ($dashboards = getData($result)) )
|
||||
|
||||
if (hasData($result))
|
||||
{
|
||||
$dashboard = $dashboards[0];
|
||||
return current(getData($result));
|
||||
}
|
||||
return $dashboard;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getMergedConfig($dashboard_id, $uid)
|
||||
public function getMergedConfig($dashboard_id, $uid)
|
||||
{
|
||||
$defaultconfig = $this->getDefaultConfig($dashboard_id, $uid);
|
||||
$userconfig = $this->getUserConfig($dashboard_id, $uid);
|
||||
@@ -60,15 +62,15 @@ class DashboardLib
|
||||
$res_presets = $this->_ci->DashboardPresetModel->getPresets($dashboard_id, $uid);
|
||||
$defaultconfig = array();
|
||||
|
||||
if( isSuccess($res_presets) && hasData($res_presets) )
|
||||
if (hasData($res_presets))
|
||||
{
|
||||
$presets = getData($res_presets);
|
||||
foreach ($presets as $presetobj)
|
||||
{
|
||||
if( null !== ($preset = json_decode($presetobj->preset, true)) )
|
||||
$preset = json_decode($presetobj->preset, true);
|
||||
if (null !== $preset)
|
||||
{
|
||||
$defaultconfig = array_replace_recursive($defaultconfig,
|
||||
$preset);
|
||||
$defaultconfig = array_replace_recursive($defaultconfig, $preset);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,25 +81,25 @@ class DashboardLib
|
||||
public function getUserConfig($dashboard_id, $uid)
|
||||
{
|
||||
$res_userconfig = $this->_ci->DashboardOverrideModel->getOverride($dashboard_id, $uid);
|
||||
$userconfig = array();
|
||||
|
||||
if( isSuccess($res_userconfig) && hasData($res_userconfig) )
|
||||
if (hasData($res_userconfig))
|
||||
{
|
||||
$data = getData($res_userconfig);
|
||||
if( null !== ($decodedconfig = json_decode($data[0]->override, true)) )
|
||||
$decodedconfig = json_decode(current($data)->override, true);
|
||||
if (null !== $decodedconfig)
|
||||
{
|
||||
$userconfig = $decodedconfig;
|
||||
return $decodedconfig;
|
||||
}
|
||||
}
|
||||
|
||||
return $userconfig;
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getOverrideOrCreateEmptyOverride($dashboard_kurzbz, $uid)
|
||||
public function getOverrideOrCreateEmptyOverride($dashboard_kurzbz, $uid)
|
||||
{
|
||||
$override = $this->getOverride($dashboard_kurzbz, $uid);
|
||||
if( null !== $override ) {
|
||||
return $override;
|
||||
if (null !== $override) {
|
||||
return $override;
|
||||
}
|
||||
|
||||
$dashboard = $this->getDashboardByKurzbz($dashboard_kurzbz);
|
||||
@@ -110,11 +112,13 @@ class DashboardLib
|
||||
return $emptyoverride;
|
||||
}
|
||||
|
||||
public function getPresetOrCreateEmptyPreset($dashboard_kurzbz, $funktion_kurzbz)
|
||||
public function getPresetOrCreateEmptyPreset($dashboard_kurzbz, $funktion_kurzbz)
|
||||
{
|
||||
if ($funktion_kurzbz === self::SECTION_IF_FUNKTION_KURZBZ_IS_NULL)
|
||||
$funktion_kurzbz = null;
|
||||
$preset = $this->getPreset($dashboard_kurzbz, $funktion_kurzbz);
|
||||
if( null !== $preset ) {
|
||||
return $preset;
|
||||
if (null !== $preset) {
|
||||
return $preset;
|
||||
}
|
||||
|
||||
$dashboard = $this->getDashboardByKurzbz($dashboard_kurzbz);
|
||||
@@ -123,50 +127,49 @@ class DashboardLib
|
||||
$emptypreset->dashboard_id = $dashboard->dashboard_id;
|
||||
$emptypreset->funktion_kurzbz = $funktion_kurzbz;
|
||||
$section = ($funktion_kurzbz !== null) ? $funktion_kurzbz : self::SECTION_IF_FUNKTION_KURZBZ_IS_NULL;
|
||||
$emptypreset->preset = '{"widgets": {"' . $funktion_kurzbz . '": {}}}';
|
||||
$emptypreset->preset = '{"widgets": {"' . $section . '": {}}}';
|
||||
|
||||
return $emptypreset;
|
||||
}
|
||||
|
||||
public function getPreset($dashboard_kurzbz, $section)
|
||||
public function getPreset($dashboard_kurzbz, $section)
|
||||
{
|
||||
$dashboard = $this->getDashboardByKurzbz($dashboard_kurzbz);
|
||||
$preset = null;
|
||||
|
||||
$funktion_kurzbz = ($section === self::SECTION_IF_FUNKTION_KURZBZ_IS_NULL) ? null : $section;
|
||||
$result = $this->_ci->DashboardPresetModel
|
||||
->getPresetByDashboardAndFunktion($dashboard->dashboard_id, $funktion_kurzbz);
|
||||
|
||||
if( isSuccess($result) && hasData($result) && ($presets = getData($result)) )
|
||||
if (hasData($result))
|
||||
{
|
||||
$preset = $presets[0];
|
||||
return current(getData($result));
|
||||
}
|
||||
|
||||
return $preset;
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getOverride($dashboard_kurzbz, $uid)
|
||||
public function getOverride($dashboard_kurzbz, $uid)
|
||||
{
|
||||
$dashboard = $this->getDashboardByKurzbz($dashboard_kurzbz);
|
||||
$override = null;
|
||||
|
||||
$result = $this->_ci->DashboardOverrideModel
|
||||
->getOverride($dashboard->dashboard_id, $uid);
|
||||
|
||||
if( isSuccess($result) && hasData($result) && ($overrides = getData($result)) )
|
||||
if (hasData($result))
|
||||
{
|
||||
$override = $overrides[0];
|
||||
return current(getData($result));
|
||||
}
|
||||
|
||||
return $override;
|
||||
return null;
|
||||
}
|
||||
|
||||
public function insertOrUpdatePreset($preset)
|
||||
public function insertOrUpdatePreset($preset)
|
||||
{
|
||||
if( isset($preset->preset_id) && $preset->preset_id > 0 )
|
||||
if (isset($preset->preset_id) && $preset->preset_id > 0)
|
||||
{
|
||||
$result = $this->_ci->DashboardPresetModel->update($preset->preset_id, $preset);
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $this->_ci->DashboardPresetModel->insert($preset);
|
||||
}
|
||||
@@ -174,12 +177,13 @@ class DashboardLib
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function insertOrUpdateOverride($override)
|
||||
public function insertOrUpdateOverride($override)
|
||||
{
|
||||
if( isset($override->override_id) && $override->override_id > 0 )
|
||||
if (isset($override->override_id) && $override->override_id > 0)
|
||||
{
|
||||
$result = $this->_ci->DashboardOverrideModel->update($override->override_id, $override);
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $this->_ci->DashboardOverrideModel->insert($override);
|
||||
}
|
||||
@@ -199,10 +203,10 @@ class DashboardLib
|
||||
}
|
||||
}
|
||||
|
||||
public function addWidgetToWidgets(&$widgets, $section, $widget, $widgetid)
|
||||
public function addWidgetToWidgets(&$widgets, $section, $widget, $widgetid)
|
||||
{
|
||||
$section = ($section !== null) ? $section : self::SECTION_IF_FUNKTION_KURZBZ_IS_NULL;
|
||||
if( !isset($widgets[$section]) || !is_array($widgets[$section]) )
|
||||
if (!isset($widgets[$section]) || !is_array($widgets[$section]))
|
||||
{
|
||||
$widgets[$section] = array();
|
||||
}
|
||||
@@ -210,10 +214,10 @@ class DashboardLib
|
||||
$widgets[$section][$widgetid] = $widget;
|
||||
}
|
||||
|
||||
public function removeWidgetFromWidgets(&$widgets, $section, $widgetid)
|
||||
public function removeWidgetFromWidgets(&$widgets, $section, $widgetid)
|
||||
{
|
||||
$section = ($section !== null) ? $section : self::SECTION_IF_FUNKTION_KURZBZ_IS_NULL;
|
||||
if(isset($widgets[$section]) && isset($widgets[$section][$widgetid]) )
|
||||
$section = ($section !== null) ? $section : self::SECTION_IF_FUNKTION_KURZBZ_IS_NULL;
|
||||
if (isset($widgets[$section]) && isset($widgets[$section][$widgetid]))
|
||||
{
|
||||
unset($widgets[$section][$widgetid]);
|
||||
if(empty($widgets[$section]) && $section !== self::USEROVERRIDE_SECTION) {
|
||||
|
||||
Reference in New Issue
Block a user