level funktion_kurzbz added to presets and overrides

This commit is contained in:
Harald Bamberger
2022-10-03 07:59:11 +02:00
parent ad369bbe44
commit d14608ed28
2 changed files with 44 additions and 16 deletions
+11 -13
View File
@@ -61,7 +61,8 @@ class Config extends Auth_Controller
$preset_decoded = json_decode($preset->preset, true);
$widgetid = $this->DashboardLib->generateWidgetId($dashboard_kurzbz);
$preset_decoded['widgets'][$widgetid['widgetid']] = $input->widget;
$this->DashboardLib->addWidgetToWidgets($preset_decoded['widgets'],
$funktion_kurzbz, $input->widget, $widgetid['widgetid']);
$preset->preset = json_encode($preset_decoded);
@@ -91,11 +92,8 @@ class Config extends Auth_Controller
$preset_decoded = json_decode($preset->preset, true);
if( isset($preset_decoded['widgets'][$widgetid]) )
{
unset($preset_decoded['widgets'][$widgetid]);
}
else
if( $this->DashboardLib->removeWidgetFromWidgets($preset_decoded['widgets'],
$funktion_kurzbz, $widgetid) )
{
http_response_code(404);
$this->terminateWithJsonError('widgetid ' . $widgetid . ' not found');
@@ -115,6 +113,7 @@ class Config extends Auth_Controller
{
$input = json_decode($this->input->raw_input_stream);
$dashboard_kurzbz = $input->db;
$funktion_kurzbz = $input->funktion_kurzbz;
$uid = $input->uid;
$override = $this->DashboardLib->getOverrideOrCreateEmptyOverride($dashboard_kurzbz, $uid);
@@ -122,8 +121,9 @@ class Config extends Auth_Controller
$override_decoded = json_decode($override->override, true);
$widgetid = isset($input->widgetid) ? array('widgetid' => $input->widgetid)
: $this->DashboardLib->generateWidgetId($dashboard_kurzbz);
$override_decoded['widgets'][$widgetid['widgetid']] = $input->widget;
$this->DashboardLib->addWidgetToWidgets($override_decoded['widgets'],
$funktion_kurzbz, $input->widget, $widgetid['widgetid']);
$override->override = json_encode($override_decoded);
@@ -140,6 +140,7 @@ class Config extends Auth_Controller
{
$input = json_decode($this->input->raw_input_stream);
$dashboard_kurzbz = $input->db;
$funktion_kurzbz = $input->funktion_kurzbz;
$uid = $input->uid;
$widgetid = $input->widgetid;
@@ -152,11 +153,8 @@ class Config extends Auth_Controller
$override_decoded = json_decode($override->override, true);
if( array_key_exists($widgetid, $override_decoded['widgets']) )
{
unset($override_decoded['widgets'][$widgetid]);
}
else
if( !$this->DashboardLib->removeWidgetFromWidgets($override_decoded['widgets'],
$funktion_kurzbz, $widgetid) )
{
http_response_code(404);
$this->terminateWithJsonError('widgetid ' . $widgetid . ' not found');
@@ -9,6 +9,8 @@ class DashboardLib
{
const WIDGET_ID_RANDOM_BYTES = 16;
const DEFAULT_DASHBOARD_KURZBZ = 'fhcomplete';
const SECTION_IF_FUNKTION_KURZBZ_IS_NULL = 'general';
const USEROVERRIDE_SECTION = 'custom';
private $_ci; // CI instance
@@ -106,7 +108,7 @@ class DashboardLib
$emptyoverride = new stdClass();
$emptyoverride->dashboard_id = $dashboard->dashboard_id;
$emptyoverride->uid = $uid;
$emptyoverride->override = '{"widgets": {}}';
$emptyoverride->override = '{"widgets": {"' . self::USEROVERRIDE_SECTION . '": {}}}';
return $emptyoverride;
}
@@ -123,7 +125,8 @@ class DashboardLib
$emptypreset = new stdClass();
$emptypreset->dashboard_id = $dashboard->dashboard_id;
$emptypreset->funktion_kurzbz = $funktion_kurzbz;
$emptypreset->preset = '{"widgets": {}}';
$section = ($funktion_kurzbz !== null) ? $funktion_kurzbz : self::SECTION_IF_FUNKTION_KURZBZ_IS_NULL;
$emptypreset->preset = '{"widgets": {"' . $funktion_kurzbz . '": {}}}';
return $emptypreset;
}
@@ -184,5 +187,32 @@ class DashboardLib
}
return $result;
}
}
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]) )
{
$widgets[$section] = array();
}
$widgets[$section][$widgetid] = $widget;
}
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]) )
{
unset($widgets[$section][$widgetid]);
if(empty($widgets[$section])) {
unset($widgets[$section]);
}
return true;
}
else {
return false;
}
}
}