From e506e1eb5f428e9fc93ece16d8ca80162d24396c Mon Sep 17 00:00:00 2001 From: tsmr Date: Tue, 15 Nov 2022 11:52:08 +0100 Subject: [PATCH] Bump version 2.1.1 --- hook.php | 2 +- inc/preference.class.php | 502 ++++++++++++++++--------------- mydashboard.xml | 5 + reports/reports_funnel.class.php | 1 - setup.php | 2 +- 5 files changed, 265 insertions(+), 247 deletions(-) diff --git a/hook.php b/hook.php index 9107d65..aaec926 100644 --- a/hook.php +++ b/hook.php @@ -64,7 +64,7 @@ function plugin_mydashboard_install() $mig = new Migration("1.0.3"); $dbu = new DbUtils(); $configs = $dbu->getAllDataFromTable("glpi_plugin_mydashboard_configs"); - $replace_central = 1; + $replace_central = 0; //Basically there is only one config for Dashboard (this foreach may be useless) foreach ($configs as $config) { $replace_central = $config['replace_central']; diff --git a/inc/preference.class.php b/inc/preference.class.php index ff1627e..7d81a65 100644 --- a/inc/preference.class.php +++ b/inc/preference.class.php @@ -27,264 +27,278 @@ /** * Class PluginMydashboardPreference */ -class PluginMydashboardPreference extends CommonDBTM { - - /** - * @return bool - */ - static function canCreate() { - return Session::haveRightsOr('plugin_mydashboard', [CREATE, UPDATE, READ]); - } - - /** - * @return bool - */ - static function canView() { - return Session::haveRightsOr('plugin_mydashboard', [CREATE, UPDATE, READ]); - } - - /** - * @return bool|booleen - */ - static function canUpdate() { - return self::canCreate(); - } - - - /** - * @param CommonGLPI $item - * @param int $withtemplate - * - * @return string|translated - */ - function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { - if ($item->getType() == 'Preference') { - return __('My Dashboard', 'mydashboard'); - } - return ''; - } +class PluginMydashboardPreference extends CommonDBTM +{ + /** + * @return bool + */ + public static function canCreate() + { + return Session::haveRightsOr('plugin_mydashboard', [CREATE, UPDATE, READ]); + } + + /** + * @return bool + */ + public static function canView() + { + return Session::haveRightsOr('plugin_mydashboard', [CREATE, UPDATE, READ]); + } /** - * @return string - */ - static function getIcon() { - return PluginMydashboardMenu::getIcon(); - } + * @return bool|booleen + */ + public static function canUpdate() + { + return self::canCreate(); + } + + + /** + * @param CommonGLPI $item + * @param int $withtemplate + * + * @return string|translated + */ + public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) + { + if ($item->getType() == 'Preference') { + return __('My Dashboard', 'mydashboard'); + } + return ''; + } + + /** + * @return string + */ + public static function getIcon() + { + return PluginMydashboardMenu::getIcon(); + } - /** - * @param CommonGLPI $item - * @param int $tabnum - * @param int $withtemplate - * - * @return bool - */ - static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { - $pref = new PluginMydashboardPreference(); - $pref->showPreferencesForm(Session::getLoginUserID()); - return true; - } - - /** - * @param $user_id - */ - function showPreferencesForm($user_id) { - //If user has no preferences yet, we set default values - if (!$this->getFromDB($user_id)) { - $this->initPreferences($user_id); - $this->getFromDB($user_id); - } - - //Preferences are not deletable - $options['candel'] = false; - $options['colspan'] = 1; - - $this->showFormHeader($options); - - echo "" . __("Automatic refreshing of the widgets that can be refreshed", "mydashboard") . ""; - echo ""; - Dropdown::showYesNo("automatic_refresh", $this->fields['automatic_refresh']); - echo ""; - echo ""; - - echo "" . __("Refresh every ", "mydashboard") . ""; - echo ""; - Dropdown::showFromArray("automatic_refresh_delay", [1 => 1, 2 => 2, 5 => 5, 10 => 10, 30 => 30, 60 => 60], - ["value" => $this->fields['automatic_refresh_delay']]); - echo " " . __('minute(s)', "mydashboard"); - echo ""; - echo ""; - //Since 1.0.3 replace_central is now a preference - echo "" . __("Replace central interface", "mydashboard") . ""; - echo ""; - Dropdown::showYesNo("replace_central", $this->fields['replace_central']); - echo ""; - echo ""; - - if (Session::getCurrentInterface() - && Session::getCurrentInterface() == 'central') { - echo "" . __("My prefered groups for widget", "mydashboard") . ""; - echo ""; - $params = ['name' => 'prefered_group', - 'value' => $this->fields['prefered_group'], - 'entity' => $_SESSION['glpiactiveentities'], - 'condition' => '`is_assign`']; - - $dbu = new DbUtils(); - $result = $dbu->getAllDataFromTable(Group::getTable(), ['is_assign' => 1]); - $pref = json_decode($this->fields['prefered_group']); + /** + * @param CommonGLPI $item + * @param int $tabnum + * @param int $withtemplate + * + * @return bool + */ + public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) + { + $pref = new PluginMydashboardPreference(); + $pref->showPreferencesForm(Session::getLoginUserID()); + return true; + } + + /** + * @param $user_id + */ + public function showPreferencesForm($user_id) + { + //If user has no preferences yet, we set default values + if (!$this->getFromDB($user_id)) { + $this->initPreferences($user_id); + $this->getFromDB($user_id); + } + + //Preferences are not deletable + $options['candel'] = false; + $options['colspan'] = 1; + + $this->showFormHeader($options); + + echo "" . __("Automatic refreshing of the widgets that can be refreshed", "mydashboard") . ""; + echo ""; + Dropdown::showYesNo("automatic_refresh", $this->fields['automatic_refresh']); + echo ""; + echo ""; + + echo "" . __("Refresh every ", "mydashboard") . ""; + echo ""; + Dropdown::showFromArray( + "automatic_refresh_delay", + [1 => 1, 2 => 2, 5 => 5, 10 => 10, 30 => 30, 60 => 60], + ["value" => $this->fields['automatic_refresh_delay']] + ); + echo " " . __('minute(s)', "mydashboard"); + echo ""; + echo ""; + //Since 1.0.3 replace_central is now a preference + echo "" . __("Replace central interface", "mydashboard") . ""; + echo ""; + Dropdown::showYesNo("replace_central", $this->fields['replace_central']); + echo ""; + echo ""; + + if (Session::getCurrentInterface() + && Session::getCurrentInterface() == 'central') { + echo "" . __("My prefered groups for widget", "mydashboard") . ""; + echo ""; + $params = ['name' => 'prefered_group', + 'value' => $this->fields['prefered_group'], + 'entity' => $_SESSION['glpiactiveentities'], + 'condition' => '`is_assign`']; + + $dbu = new DbUtils(); + $result = $dbu->getAllDataFromTable(Group::getTable(), ['is_assign' => 1]); + $pref = json_decode($this->fields['prefered_group']); // $opt['technicians_groups_id'] = is_array($opt['technicians_groups_id']) ? $opt['technicians_groups_id'] : [$opt['technicians_groups_id']]; - $temp = []; - foreach ($result as $item) { - $temp[$item['id']] = $item['name']; - } + $temp = []; + foreach ($result as $item) { + $temp[$item['id']] = $item['name']; + } - $params = [ - "name" => 'prefered_group', - 'entity' => $_SESSION['glpiactiveentities'], - "display" => false, - "multiple" => true, - "width" => '200px', - 'values' => isset($pref) ? $pref : [], - 'display_emptychoice' => true - ]; + $params = [ + "name" => 'prefered_group', + 'entity' => $_SESSION['glpiactiveentities'], + "display" => false, + "multiple" => true, + "width" => '200px', + 'values' => isset($pref) ? $pref : [], + 'display_emptychoice' => true + ]; - $dropdown = Dropdown::showFromArray("prefered_group", $temp, $params); + $dropdown = Dropdown::showFromArray("prefered_group", $temp, $params); - echo $dropdown; + echo $dropdown; // Group::dropdown($params); - echo ""; - echo ""; - } - echo "" . __("My requester prefered groups for widget", "mydashboard") . ""; - echo ""; - $params = ['name' => 'requester_prefered_group', - 'value' => $this->fields['requester_prefered_group'], - 'entity' => $_SESSION['glpiactiveentities'], - 'condition' => '`is_requester`']; - - $dbu = new DbUtils(); - $result = $dbu->getAllDataFromTable(Group::getTable(), ['is_requester' => 1]); - $pref = json_decode($this->fields['requester_prefered_group']); + echo ""; + echo ""; + } + echo "" . __("My requester prefered groups for widget", "mydashboard") . ""; + echo ""; + $params = ['name' => 'requester_prefered_group', + 'value' => $this->fields['requester_prefered_group'], + 'entity' => $_SESSION['glpiactiveentities'], + 'condition' => '`is_requester`']; + + $dbu = new DbUtils(); + $result = $dbu->getAllDataFromTable(Group::getTable(), ['is_requester' => 1]); + $pref = json_decode($this->fields['requester_prefered_group']); // $opt['technicians_groups_id'] = is_array($opt['technicians_groups_id']) ? $opt['technicians_groups_id'] : [$opt['technicians_groups_id']]; - $temp = []; - foreach ($result as $item) { - $temp[$item['id']] = $item['name']; - } - - $params = [ - "name" => 'requester_prefered_group', - 'entity' => $_SESSION['glpiactiveentities'], - "display" => false, - "multiple" => true, - "width" => '200px', - 'values' => isset($pref) ? $pref : [], - 'display_emptychoice' => true - ]; - - $dropdown = Dropdown::showFromArray("requester_prefered_group", $temp, $params); - - echo $dropdown; + $temp = []; + foreach ($result as $item) { + $temp[$item['id']] = $item['name']; + } + + $params = [ + "name" => 'requester_prefered_group', + 'entity' => $_SESSION['glpiactiveentities'], + "display" => false, + "multiple" => true, + "width" => '200px', + 'values' => isset($pref) ? $pref : [], + 'display_emptychoice' => true + ]; + + $dropdown = Dropdown::showFromArray("requester_prefered_group", $temp, $params); + + echo $dropdown; // Group::dropdown($params); - echo ""; - echo ""; - - echo "" . __("My prefered entity for widget", "mydashboard") . ""; - echo ""; - $params = ['name' => 'prefered_entity', - 'value' => $this->fields['prefered_entity'], - 'entity' => $_SESSION['glpiactiveentities']]; - Entity::dropdown($params); - echo ""; - echo ""; - - echo "" . __("My prefered type for widget", "mydashboard") . ""; - echo ""; - $params = ['value' => $this->fields['prefered_type'],'toadd' =>[0 => Dropdown::EMPTY_VALUE]]; - Ticket::dropdownType('prefered_type', $params); - echo ""; - echo ""; - - echo "" . __("Palette color", "mydashboard") . ""; - echo ""; - echo Html::select( - 'color_palette', - $this->getPalettes(), - [ - 'id' => 'theme-selector', - 'selected' => $this->fields['color_palette'] - ] - ); - echo ""; - echo ""; - - - $this->showFormButtons($options); - - if (PluginMydashboardHelper::getDisplayPlugins()) { - $blacklist = new PluginMydashboardPreferenceUserBlacklist(); - $blacklist->showUserForm(Session::getLoginUserID()); - } - } - - public function getPalettes() { - $themes_files = scandir(PLUGIN_MYDASHBOARD_DIR . "/lib/echarts/theme"); - $themes = []; - foreach ($themes_files as $file) { - if (strpos($file, ".js") !== false) { - $name = substr($file, 0, -3); - $themes[$name] = ucfirst($name); - } + echo ""; + echo ""; + + echo "" . __("My prefered entity for widget", "mydashboard") . ""; + echo ""; + $params = ['name' => 'prefered_entity', + 'value' => $this->fields['prefered_entity'], + 'entity' => $_SESSION['glpiactiveentities']]; + Entity::dropdown($params); + echo ""; + echo ""; + + echo "" . __("My prefered type for widget", "mydashboard") . ""; + echo ""; + $params = ['value' => $this->fields['prefered_type'],'toadd' =>[0 => Dropdown::EMPTY_VALUE]]; + Ticket::dropdownType('prefered_type', $params); + echo ""; + echo ""; + + echo "" . __("Palette color", "mydashboard") . ""; + echo ""; + echo Html::select( + 'color_palette', + $this->getPalettes(), + [ + 'id' => 'theme-selector', + 'selected' => $this->fields['color_palette'] + ] + ); + echo ""; + echo ""; + + + $this->showFormButtons($options); + + if (PluginMydashboardHelper::getDisplayPlugins()) { + $blacklist = new PluginMydashboardPreferenceUserBlacklist(); + $blacklist->showUserForm(Session::getLoginUserID()); + } + } + + public function getPalettes() + { + $themes_files = scandir(PLUGIN_MYDASHBOARD_DIR . "/lib/echarts/theme"); + $themes = []; + foreach ($themes_files as $file) { + if (strpos($file, ".js") !== false) { + $name = substr($file, 0, -3); + $themes[$name] = ucfirst($name); + } + } + return $themes; + } + + /** + * @param $users_id + */ + public function initPreferences($users_id) + { + $input = []; + $input['id'] = $users_id; + $input['automatic_refresh'] = "0"; + $input['automatic_refresh_delay'] = "10"; + $input['nb_widgets_width'] = "3"; + $input['replace_central'] = "0"; + $input['prefered_group'] = "[]"; + $input['requester_prefered_group'] = "[]"; + $input['prefered_entity'] = "0"; + $input['color_palette'] = ""; + $input['edit_mode'] = "0"; + $input['drag_mode'] = "0"; + $this->add($input); + } + + public static function checkEditMode($users_id) + { + return self::checkPreferenceValue('edit_mode', $users_id); + } + + public static function checkDragMode($users_id) + { + return self::checkPreferenceValue('drag_mode', $users_id); + } + + public static function checkPreferenceValue($field, $users_id = 0) + { + $dbu = new DbUtils(); + $data = $dbu->getAllDataFromTable($dbu->getTableForItemType(__CLASS__), ["id" => $users_id]); + if (!empty($data)) { + $first = array_pop($data); + return $first[$field]; + } else { + return 0; } - return $themes; } - /** - * @param $users_id - */ - public function initPreferences($users_id) { - - $input = []; - $input['id'] = $users_id; - $input['automatic_refresh'] = "0"; - $input['automatic_refresh_delay'] = "10"; - $input['nb_widgets_width'] = "3"; - $input['replace_central'] = "0"; - $input['prefered_group'] = "[]"; - $input['requester_prefered_group'] = "[]"; - $input['prefered_entity'] = "0"; - $input['color_palette'] = ""; - $input['edit_mode'] = "0"; - $input['drag_mode'] = "0"; - $this->add($input); - - } - - public static function checkEditMode($users_id) { - return self::checkPreferenceValue('edit_mode', $users_id); - } - - public static function checkDragMode($users_id) { - return self::checkPreferenceValue('drag_mode', $users_id); - } - - public static function checkPreferenceValue($field, $users_id = 0) { - $dbu = new DbUtils(); - $data = $dbu->getAllDataFromTable($dbu->getTableForItemType(__CLASS__), ["id" => $users_id]); - if (!empty($data)) { - $first = array_pop($data); - return $first[$field]; - } else { - return 0; - } - } - - /** - * @return mixed - */ - public static function getPalette($users_id) { - return self::checkPreferenceValue('color_palette', $users_id); - } + /** + * @return mixed + */ + public static function getPalette($users_id) + { + return self::checkPreferenceValue('color_palette', $users_id); + } } diff --git a/mydashboard.xml b/mydashboard.xml index 80654d1..78f4a10 100644 --- a/mydashboard.xml +++ b/mydashboard.xml @@ -23,6 +23,11 @@ Infotel + + 2.1.1 + ~10.0 + https://github.com/InfotelGLPI/mydashboard/releases/download/2.1.1/glpi-mydashboard-2.1.1.tar.bz2 + 2.1.0 ~10.0 diff --git a/reports/reports_funnel.class.php b/reports/reports_funnel.class.php index a0399bd..7836cc7 100644 --- a/reports/reports_funnel.class.php +++ b/reports/reports_funnel.class.php @@ -217,7 +217,6 @@ public function getWidgetContentForItem($widgetId, $opt = []) __('Without buy date', 'mydashboard')]; $i = 0; while ($data = $DB->fetchArray($results)) { - $tabnames[] = $ages[$i]; $tabdate[] = $data['AgeCrit']; $tabage[] = ['value' => $data['Total'], 'name' => $ages[$i]]; diff --git a/setup.php b/setup.php index bf0ee45..bbfc745 100644 --- a/setup.php +++ b/setup.php @@ -24,7 +24,7 @@ -------------------------------------------------------------------------- */ -define('PLUGIN_MYDASHBOARD_VERSION', '2.1.0'); +define('PLUGIN_MYDASHBOARD_VERSION', '2.1.1'); if (!defined("PLUGIN_MYDASHBOARD_DIR")) { define("PLUGIN_MYDASHBOARD_DIR", Plugin::getPhpDir("mydashboard"));