From e79cc6209b8ea373722812541d95a7e16ea4ddfd Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Mon, 31 Mar 2025 10:04:25 +0200 Subject: [PATCH 01/24] phpstan5 --- ajax/dropdownGraphs.php | 10 +- composer.json | 3 +- front/central.php | 6 +- front/config.form.php | 2 +- front/config.php | 3 + front/profile.form.php | 3 + hook.php | 27 +- inc/baseclass.class.php | 8 +- inc/common.class.php | 254 ++++++------------- inc/config.class.php | 73 +++--- inc/dashboard.class.php | 2 - inc/graphcsv.class.php | 2 + inc/graphpng.class.php | 4 +- inc/helpdesk.class.php | 60 +++-- inc/helpdeskplus.class.php | 56 ++-- inc/inventory.class.php | 33 ++- inc/notification.class.php | 10 +- inc/notificationevent.class.php | 2 +- inc/notificationtargetnotification.class.php | 11 +- inc/other.class.php | 33 +-- inc/pdf.class.php | 7 +- inc/preference.class.php | 11 +- inc/profile.class.php | 24 +- inc/tag.class.php | 6 +- phpstan.neon | 19 ++ setup.php | 4 + 26 files changed, 343 insertions(+), 330 deletions(-) create mode 100644 phpstan.neon diff --git a/ajax/dropdownGraphs.php b/ajax/dropdownGraphs.php index aee6349f..7b97329d 100644 --- a/ajax/dropdownGraphs.php +++ b/ajax/dropdownGraphs.php @@ -38,11 +38,9 @@ if ($_POST['graphname'] != -1) { $test = explode(';', $_POST['graphname']); - if (isset($test[0])) { - $_POST['classname'] = $test[0]; - $_POST['name'] = $test[1]; + $_POST['classname'] = $test[0]; + $_POST['name'] = $test[1]; - $config = new PluginMreportingConfig(); - echo " " . __('Send') . ''; - } + $config = new PluginMreportingConfig(); + echo " " . __('Send') . ''; } diff --git a/composer.json b/composer.json index 8c81a59a..9e806f99 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,8 @@ "glpi-project/tools": "^0.7", "php-parallel-lint/php-parallel-lint": "^1.4", "phpstan/extension-installer": "^1.4", - "phpstan/phpstan": "^2.1" + "phpstan/phpstan": "^2.1", + "phpstan/phpstan-deprecation-rules": "^2.0" }, "config": { "optimize-autoloader": true, diff --git a/front/central.php b/front/central.php index 1ad8dece..38d237b7 100644 --- a/front/central.php +++ b/front/central.php @@ -47,8 +47,10 @@ if (count($tabs) > 0) { //foreach tabs foreach ($tabs as $tab) { + /** @var \DBmysql $DB */ global $DB; - $params = (isset($tab['params']) ? $tab['params'] : ''); + + $params = $tab['params']; //we get the classname $classname = str_replace('target=' . $_SERVER['PHP_SELF'] . '&classname=', '', $params); @@ -61,7 +63,7 @@ AND `glpi_plugin_mreporting_profiles`.`profiles_id` = ' . $_SESSION['glpiactiveprofile']['id']; //for this classname if current user have no right on any reports - if ($result = $DB->query($query)) { + if ($result = $DB->doQuery($query)) { if ($DB->numrows($result) == 0) { //we unset the index unset($tabs[$classname]); diff --git a/front/config.form.php b/front/config.form.php index 7f7d267e..a8d6cbec 100644 --- a/front/config.form.php +++ b/front/config.form.php @@ -48,7 +48,7 @@ $config->update($_POST); Html::back(); } elseif (isset($_POST['delete'])) { - $config->delete($_POST, 1); + $config->delete($_POST, true); Html::redirect('./config.form.php'); } else { Html::header(__('More Reporting', 'mreporting'), '', 'tools', 'PluginMreportingCommon', 'config'); diff --git a/front/config.php b/front/config.php index 38285486..80a3de48 100644 --- a/front/config.php +++ b/front/config.php @@ -46,6 +46,9 @@ Search::show('PluginMreportingConfig'); } } else { + /** @var array $CFG_GLPI */ + global $CFG_GLPI; + Html::header(__('Setup'), '', 'config', 'plugins'); echo "
"; echo '

'; diff --git a/front/profile.form.php b/front/profile.form.php index 65232f4e..a7ef9ce0 100644 --- a/front/profile.form.php +++ b/front/profile.form.php @@ -32,6 +32,9 @@ Session::checkRight('profile', READ); +/** @var DBmysql $DB */ +global $DB; + $config = new PluginMreportingConfig(); $res = $config->find(); $profil = new PluginMreportingProfile(); diff --git a/hook.php b/hook.php index 244d101f..af80339f 100644 --- a/hook.php +++ b/hook.php @@ -35,6 +35,7 @@ */ function plugin_mreporting_install() { + /** @var \DBmysql $DB */ global $DB; $version = plugin_version_mreporting(); @@ -98,7 +99,7 @@ function plugin_mreporting_install() $query_display_pref = "SELECT id FROM glpi_displaypreferences WHERE itemtype = 'PluginMreportingConfig'"; - $res_display_pref = $DB->query($query_display_pref); + $res_display_pref = $DB->doQuery($query_display_pref); if ($DB->numrows($res_display_pref) == 0) { $queries[] = "INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginMreportingConfig','2','2','0');"; @@ -130,7 +131,7 @@ function plugin_mreporting_install() ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; foreach ($queries as $query) { - $DB->query($query); + $DB->doQuery($query); } // == Update to 2.1 == @@ -152,7 +153,7 @@ function plugin_mreporting_install() //truncate profile table $query = 'TRUNCATE TABLE `glpi_plugin_mreporting_profiles`'; - $DB->query($query); + $DB->doQuery($query); //migration of field $migration->addField('glpi_plugin_mreporting_profiles', 'right', 'char'); @@ -175,16 +176,16 @@ function plugin_mreporting_install() // == UPDATE to 0.84+1.0 == $query = 'UPDATE `glpi_plugin_mreporting_profiles` pr SET pr.right = ' . READ . " WHERE pr.right = 'r'"; - $DB->query($query); + $DB->doQuery($query); if (!isIndex('glpi_plugin_mreporting_profiles', 'profiles_id_reports')) { $query = 'ALTER TABLE glpi_plugin_mreporting_profiles ADD UNIQUE INDEX `profiles_id_reports` (`profiles_id`, `reports`)'; - $DB->query($query); + $DB->doQuery($query); } // Remove GLPI graphtype to fix compatibility with GLPI 9.2.2+ $query = "UPDATE `glpi_plugin_mreporting_configs` SET `graphtype` = 'SVG' WHERE `graphtype` = 'GLPI'"; - $DB->query($query); + $DB->doQuery($query); //== Create directories $rep_files_mreporting = GLPI_PLUGIN_DOC_DIR . '/mreporting'; @@ -224,8 +225,6 @@ function plugin_mreporting_install() */ function plugin_mreporting_uninstall() { - global $DB; - $migration = new Migration('2.3.0'); $tables = ['glpi_plugin_mreporting_profiles', 'glpi_plugin_mreporting_configs', @@ -267,6 +266,7 @@ function plugin_mreporting_getDatabaseRelations() function plugin_mreporting_giveItem($type, $ID, $data, $num) { + /** @var array $LANG */ global $LANG; $searchopt = &Search::getOptions($type); @@ -288,13 +288,11 @@ function plugin_mreporting_giveItem($type, $ID, $data, $num) } return $out; - break; case 'glpi_plugin_mreporting_configs.name': $out = ' '; if (!empty($data['raw']["ITEM_$num"])) { $title_func = ''; $short_classname = ''; - $f_name = ''; $inc_dir = Plugin::getPhpDir('mreporting') . '/inc'; //parse inc dir to search report classes @@ -312,10 +310,8 @@ function plugin_mreporting_giveItem($type, $ID, $data, $num) continue; } - $gtype = strtolower($ex_func[1]); - if ($data['raw']["ITEM_$num"] == $funct_name) { - if (!empty($classname) && !empty($funct_name)) { + if (!empty($classname)) { $short_classname = str_replace('PluginMreporting', '', $classname); if (isset($LANG['plugin_mreporting'][$short_classname][$funct_name]['title'])) { $title_func = $LANG['plugin_mreporting'][$short_classname][$funct_name]['title']; @@ -329,11 +325,9 @@ function plugin_mreporting_giveItem($type, $ID, $data, $num) } return $out; - break; } return ''; - break; } return ''; @@ -351,8 +345,6 @@ function plugin_mreporting_MassiveActionsFieldsDisplay($options = []) PluginMreportingConfig::dropdownLabel('show_label'); return true; - break; - case 'glpi_plugin_mreporting_configs.graphtype': Dropdown::showFromArray( 'graphtype', @@ -360,7 +352,6 @@ function plugin_mreporting_MassiveActionsFieldsDisplay($options = []) ); return true; - break; } } diff --git a/inc/baseclass.class.php b/inc/baseclass.class.php index 4b9d9e5f..eb51e6b0 100644 --- a/inc/baseclass.class.php +++ b/inc/baseclass.class.php @@ -48,14 +48,18 @@ class PluginMreportingBaseclass public function __construct($config = []) { + /** + * @var DBmysql $DB + * @var array $LANG + */ global $DB, $LANG; //force MySQL DATE_FORMAT in user locale $query = "SET lc_time_names = '" . $_SESSION['glpilanguage'] . "'"; - $DB->query($query); + $DB->doQuery($query); if (empty($config)) { - return true; + return; } $this->filters = [ diff --git a/inc/common.class.php b/inc/common.class.php index 0342ffeb..af95c9c0 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -59,8 +59,6 @@ public static function canCreate() public static function getMenuContent() { - global $CFG_GLPI; - $web_full_dir = Plugin::getWebDir('mreporting'); $img_db = " 0) { $select .= ''; foreach ($graphs as $cat => $graph) { - if (count($graph) > 0) { - $select .= ""; - - usort( - $graph, - function ($a, $b) { - $a_title = $a['title']; - $b_title = $b['title']; - - return strcmp($a_title, $b_title); - }, - ); - - foreach ($graph as $key => $value) { - if ($value['right']) { - if ($value['is_active']) { - $comment = ''; - if (isset($value['desc'])) { - $comment = $value['desc']; - } - $option_value = $value['url_graph']; - if ($setIdInOptionsValues) { - $option_value = $value['id']; - } - $icon = self::getReportIcon($value['function']); - $select .= "'; + $select .= ""; + + usort( + $graph, + function ($a, $b) { + $a_title = $a['title']; + $b_title = $b['title']; + + return strcmp($a_title, $b_title); + }, + ); + + foreach ($graph as $key => $value) { + if ($value['right']) { + if ($value['is_active']) { + $comment = ''; + if (isset($value['desc'])) { + $comment = $value['desc']; } + $option_value = $value['url_graph']; + if ($setIdInOptionsValues) { + $option_value = $value['id']; + } + $icon = self::getReportIcon($value['function']); + $select .= "'; } } - - $select .= ''; } + + $select .= ''; } $select .= ''; } @@ -609,7 +606,8 @@ public static function initGraphParams($params) */ public function showGraph($opt, $export = false, $forceFormat = null) { - global $LANG, $CFG_GLPI; + /** @var array $LANG */ + global $LANG; if (!isset($opt['hide_title'])) { self::title($opt); @@ -681,8 +679,6 @@ public function showGraph($opt, $export = false, $forceFormat = null) public static function dropdownExt($options = []) { - global $DB; - $p['myname'] = ''; $p['value'] = ''; $p['ajax_page'] = ''; @@ -735,102 +731,35 @@ public static function dropdownExt($options = []) */ public static function endGraph($options, $dashboard = false) { - global $CFG_GLPI; - - $opt = []; - $export = false; - $datas = []; - $unit = ''; - $labels2 = []; - $flip_data = false; - foreach ($options as $k => $v) { $$k = $v; } $randname = false; - if (isset($opt['randname']) && $opt['randname'] !== false) { - $randname = $opt['randname']; - $_REQUEST['short_classname'] = $opt['short_classname']; - $_REQUEST['f_name'] = $opt['f_name']; - $_REQUEST['gtype'] = $opt['gtype']; - $_REQUEST['randname'] = $opt['randname']; - - //End Script for graph display - //if $randname exists - - $config = PluginMreportingConfig::initConfigParams( - $opt['f_name'], - 'PluginMreporting' . $opt['short_classname'], - ); - if (!$export) { - if ($config['graphtype'] == 'SVG') { - echo "} - showGraph$randname(); - "; - } - echo '
'; - } - } if (!$dashboard) { - $request_string = self::getRequestString($_REQUEST); - - if ($export != 'odtall') { - if ($randname !== false && !$export) { - $show_graph = PluginMreportingConfig::showGraphConfigValue($opt['f_name'], $opt['class']); - self::showGraphDatas($datas, $unit, $labels2, $flip_data, $show_graph); - } - if (!$export) { - if (isset($_REQUEST['f_name']) && $_REQUEST['f_name'] != 'test') { - echo "
"; - echo ""; - echo '

'; - self::showNavigation(); - echo '
'; - echo ""; - if (Session::haveRight('config', UPDATE)) { - echo '' . PluginMreportingConfig::getTypeName() . ' : '; - echo " "; - echo ""; - } - if ($randname !== false) { - echo '

'; - - echo "
"; - - echo '' . __('Export') . ' : '; - $params = ['myname' => 'ext', - 'ajax_page' => Plugin::getWebDir('mreporting') . '/ajax/dropdownExport.php', - 'class' => __CLASS__, - 'span' => 'show_ext', - 'gtype' => $_REQUEST['gtype'], - 'show_graph' => $show_graph, - 'display_svg' => ($config['graphtype'] != 'PNG'), - 'randname' => $randname, - ]; - - self::dropdownExt($params); - - echo ""; - Html::closeForm(); - } - echo ''; - } - echo "
"; - echo '
'; - - if (isset($_REQUEST['f_name']) && $_REQUEST['f_name'] != 'test') { - echo ''; - } + if (isset($_REQUEST['f_name']) && $_REQUEST['f_name'] != 'test') { + echo "
"; + echo ""; + echo '

'; + self::showNavigation(); + echo '
'; + echo ""; + if (Session::haveRight('config', UPDATE)) { + echo '' . PluginMreportingConfig::getTypeName() . ' : '; + echo " "; + echo ""; } + echo ''; + } + echo "
"; + echo '
'; - if ($randname == false) { - echo ''; - } + if (isset($_REQUEST['f_name']) && $_REQUEST['f_name'] != 'test') { + echo ''; } + + echo ''; } //destroy specific palette @@ -922,6 +851,7 @@ public static function showGraphDatas( $flip_data = false, $show_graph = false ) { + /** @var array $CFG_GLPI */ global $CFG_GLPI; $simpledatas = false; @@ -1013,8 +943,6 @@ public static function showGraphDatas( echo '' . $label2 . ''; if ($simpledatas) { //simple array echo "" . $cols . ' ' . $unit . ''; - } elseif ($treedatas) { //multiple array - self::showGraphTreeDatas($cols, $flip_data); } else { //multiple array foreach ($cols as $date => $nb) { if (!is_array($nb)) { @@ -1071,6 +999,7 @@ public static function showGraphTreeDatas($cols, $flip_data = false) */ public function export($opt) { + /** @var array $LANG */ global $LANG; switch ($opt['switchto']) { @@ -1259,6 +1188,7 @@ public function export($opt) public static function generateOdt($params) { + /** @var array $LANG */ global $LANG; $config = ['PATH_TO_TMP' => GLPI_DOC_DIR . '/_tmp']; @@ -1272,9 +1202,9 @@ public static function generateOdt($params) } $odf = new Odf('../templates/template.odt', $config); - $odf->setVars('category', $category, ENT_NOQUOTES, 'utf-8'); - $odf->setVars('title', $params[0]['title'], ENT_NOQUOTES, 'utf-8'); - $odf->setVars('description', $description, ENT_NOQUOTES, 'utf-8'); + $odf->setVars('category', $category, (bool)ENT_NOQUOTES, 'utf-8'); + $odf->setVars('title', $params[0]['title'], (bool)ENT_NOQUOTES, 'utf-8'); + $odf->setVars('description', $description, (bool)ENT_NOQUOTES, 'utf-8'); $path = GLPI_PLUGIN_DOC_DIR . '/mreporting/' . $params[0]['f_name'] . '.png'; @@ -1282,7 +1212,7 @@ public static function generateOdt($params) list($image_width, $image_height) = @getimagesize($path); $image_width *= Odf::PIXEL_TO_CM; $image_height *= Odf::PIXEL_TO_CM * 17 / $image_width; - $odf->setImage('image', $path, -1, 17, $image_height); + $odf->setImage('image', $path, -1, 17, (int)$image_height); } else { $odf->setVars('image', '', true, 'UTF-8'); } @@ -1301,25 +1231,12 @@ public static function generateOdt($params) $multipledatas->setVars('datas_title', mb_strtoupper(__('data', 'mreporting')), ENT_NOQUOTES, 'utf-8'); foreach ($datas as $key => $value) { - $multipledatas->subtitle->datas_subtitle(mb_strtoupper($key), ENT_NOQUOTES, 'utf-8'); - $multipledatas->subtitle->merge(); - - foreach ($value as $col => $val) { - $multipledatas->datas->row($col, ENT_NOQUOTES, 'utf-8'); - $multipledatas->datas->value($val, ENT_NOQUOTES, 'utf-8'); - $multipledatas->datas->merge(); - } $multipledatas->merge(); } // Simples graph } else { $singledatas->setVars('datas_title', mb_strtoupper(__('data', 'mreporting')), ENT_NOQUOTES, 'utf-8'); - foreach ($datas as $key => $value) { - $singledatas->datas->row($key, ENT_NOQUOTES, 'utf-8'); - $singledatas->datas->value($value, ENT_NOQUOTES, 'utf-8'); - $singledatas->datas->merge(); - } $singledatas->merge(); } } @@ -1332,8 +1249,6 @@ public static function generateOdt($params) public static function selectorForMultipleGroups($field, $condition = [], $label = '') { - global $DB; - echo '
' . $label . ' :
'; $values = []; @@ -1427,6 +1342,10 @@ public static function selectorUserassign() */ public static function selectorAllSlasWithTicket() { + /** + * @var array $LANG + * @var DBmysql $DB + */ global $LANG, $DB; echo '' . $LANG['plugin_mreporting']['Helpdeskplus']['selector']['slas'] . ' :
'; @@ -1441,7 +1360,7 @@ public static function selectorAllSlasWithTicket() ) . ") AND t.is_deleted = '0' ORDER BY s.name ASC"; - $result = $DB->query($query); + $result = $DB->doQuery($query); $values = []; while ($data = $DB->fetchAssoc($result)) { @@ -1458,6 +1377,7 @@ public static function selectorAllSlasWithTicket() public static function selectorPeriod($period = 'day') { + /** @var array $LANG */ global $LANG; echo '' . $LANG['plugin_mreporting']['Helpdeskplus']['period'] . ' :
'; @@ -1491,6 +1411,7 @@ public static function selectorType() public static function selectorCategory($type = true) { + /** @var array $CFG_GLPI */ global $CFG_GLPI; echo '
' . _n('Ticket category', 'Ticket categories', 2) . ' :
'; @@ -1596,12 +1517,10 @@ public static function selectorDateinterval() /** * Show entity level selector. - * @return display selector + * @return integer|string selector */ public static function selectorEntityLevel() { - global $DB; - echo '' . __('Max depth entity level', 'mreporting') . ' :
'; $default_level = self::getActiveEntityLevel(); @@ -1666,6 +1585,7 @@ public static function getActiveEntityLevel() */ public static function getMaxEntityLevel() { + /** @var \DBmysql $DB */ global $DB; if (count($_SESSION['glpiactiveentities']) > 1) { @@ -1678,7 +1598,7 @@ public static function getMaxEntityLevel() FROM glpi_entities WHERE {$restrict}"; - $result = $DB->query($query); + $result = $DB->doQuery($query); if ($DB->numrows($result) > 0) { return $DB->result($result, 0, 'maxlevel'); } else { @@ -1720,13 +1640,14 @@ public static function getRequestString($var) /** * Show a date selector - * @param datetime $date1 date of start - * @param datetime $date2 date of ending + * @param string $date1 date of start + * @param string $date2 date of ending * @param string $randname random string (to prevent conflict in js selection) * @return void */ public static function showSelector($date1, $date2, $randname) { + /** @var array $CFG_GLPI */ global $CFG_GLPI; if (!isset($_REQUEST['f_name'])) { @@ -1752,6 +1673,7 @@ public static function showSelector($date1, $date2, $randname) } $_SERVER['REQUEST_URI'] .= '&date1' . $randname . '=' . $date1 . '&date2' . $randname . '=' . $date2; + /* @phpstan-ignore-next-line */ SavedSearch::showSaveButton(SavedSearch::URI, __CLASS__); //If there's no selector for the report, there's no need for a reset button ! @@ -1879,12 +1801,10 @@ public static function saveSelectors($graphname, $config = []) public static function getSelectorValuesByUser() { - global $DB; - $myvalues = (isset($_SESSION['mreporting_values']) ? $_SESSION['mreporting_values'] : []); $selectors = PluginMreportingPreference::checkPreferenceValue('selectors', Session::getLoginUserID()); if ($selectors) { - $values = json_decode(stripslashes($selectors), true); + $values = json_decode(stripslashes((string)$selectors), true); if (isset($_REQUEST['f_name']) && isset($values[$_REQUEST['f_name']])) { foreach ($values[$_REQUEST['f_name']] as $key => $value) { $myvalues[$key] = $value; @@ -1905,13 +1825,14 @@ public static function addToSelector() public static function resetSelectorsForReport($report_name) { + /** @var \DBmysql $DB */ global $DB; $users_id = Session::getLoginUserID(); $selectors = PluginMreportingPreference::checkPreferenceValue('selectors', $users_id); if ($selectors) { - $values = json_decode(stripslashes($selectors), true); + $values = json_decode(stripslashes((string)$selectors), true); if (isset($values[$report_name])) { unset($values[$report_name]); } @@ -1920,7 +1841,7 @@ public static function resetSelectorsForReport($report_name) $query = "UPDATE `glpi_plugin_mreporting_preferences` SET `selectors`='$selector' WHERE `users_id`='$users_id'"; - $DB->query($query); + $DB->doQuery($query); } } @@ -1942,10 +1863,10 @@ public static function getSQLDate($field = '`glpi_tickets`.`date`', $delay = 365 } $date_array1 = explode('-', $_SESSION['mreporting_values']['date1' . $randname]); - $time1 = mktime(0, 0, 0, $date_array1[1], $date_array1[2], $date_array1[0]); + $time1 = mktime(0, 0, 0, (int)$date_array1[1], (int)$date_array1[2], (int)$date_array1[0]); $date_array2 = explode('-', $_SESSION['mreporting_values']['date2' . $randname]); - $time2 = mktime(0, 0, 0, $date_array2[1], $date_array2[2], $date_array2[0]); + $time2 = mktime(0, 0, 0, (int)$date_array2[1], (int)$date_array2[2], (int)$date_array2[0]); //if data inverted, reverse it if ($time1 > $time2) { @@ -1965,17 +1886,13 @@ public static function getSQLDate($field = '`glpi_tickets`.`date`', $delay = 365 /** * Get the max value of a multidimensionnal array - * @param array() $array the array to compute + * @param array $array the array to compute * @return number the sum */ public static function getArrayMaxValue($array) { $max = 0; - if (!is_array($array)) { - return $array; - } - foreach ($array as $value) { if (is_array($value)) { $sub_max = self::getArrayMaxValue($value); @@ -1994,17 +1911,13 @@ public static function getArrayMaxValue($array) /** * Computes the sum of a multidimensionnal array - * @param array() $array the array where to seek + * @param array $array the array where to seek * @return number the sum */ public static function getArraySum($array) { $sum = 0; - if (!is_array($array)) { - return $array; - } - foreach ($array as $value) { if (is_array($value)) { $sum += self::getArraySum($value); @@ -2018,7 +1931,7 @@ public static function getArraySum($array) /** * Get the depth of a multidimensionnal array - * @param array() $array the array where to seek + * @param array $array the array where to seek * @return number the sum */ public static function getArrayDepth($array) @@ -2053,7 +1966,8 @@ public static function buildTree($flat_array) /** * Transform a flat array to a tree array (without keys changes) - * @param array $flat_array the flat array. Format : array('id', 'parent', 'name', 'count') + * @param array $elements the flat array. Format : array('id', 'parent', 'name', 'count') + * @param integer $parentId * @return array the tree array. Format : array(orginal_keys, children => array(...) */ public static function mapTree(array &$elements, $parentId = 0) @@ -2075,7 +1989,7 @@ public static function mapTree(array &$elements, $parentId = 0) /** * Transform a tree array to a tree array (with clean keyss) - * @param array $flat_array the tree array. + * @param array $raw_tree the tree array. * Format : array('id', 'parent', 'name', 'count', children => array(...) * @return array the tree array. * Format : array(name => array(name2 => array(count), ...) diff --git a/inc/config.class.php b/inc/config.class.php index b5537176..039591ca 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -186,12 +186,10 @@ public static function getSpecificValueToDisplay($field, $values, array $options switch ($field) { case 'graphtype': return $values[$field]; - break; case 'show_label': $labels = self::getLabelTypes(); return $labels[$values[$field]]; - break; } return parent::getSpecificValueToDisplay($field, $values, $options); @@ -204,6 +202,7 @@ public static function getSpecificValueToDisplay($field, $values, array $options * @param $name (default '') * @param $values (default '') * @param $options array + * @return string|void|integer **/ public static function getSpecificValueToSelect($field, $name = '', $values = '', array $options = []) { @@ -219,10 +218,8 @@ public static function getSpecificValueToSelect($field, $name = '', $values = '' ['PNG' => 'PNG', 'SVG' => 'SVG'], $options, ); - break; case 'show_label': return self::dropdownLabel($name, $options); - break; } return parent::getSpecificValueToSelect($field, $name, $values, $options); @@ -230,6 +227,7 @@ public static function getSpecificValueToSelect($field, $name = '', $values = '' public function getFromDBByFunctionAndClassname($function, $classname) { + /** @var \DBmysql $DB */ global $DB; $query = 'SELECT * @@ -237,7 +235,7 @@ public function getFromDBByFunctionAndClassname($function, $classname) WHERE `name` = '" . addslashes($function) . "' AND `classname` = '" . addslashes($classname) . "'"; - if ($result = $DB->query($query)) { + if ($result = $DB->doQuery($query)) { if ($DB->numrows($result) != 1) { return false; } @@ -256,8 +254,6 @@ public function getFromDBByFunctionAndClassname($function, $classname) **/ public static function addFirstconfigLink() { - global $CFG_GLPI; - $buttons = []; $title = ''; @@ -280,6 +276,7 @@ public function createFirstConfig() { //$reports = array(); $classConfig = false; + $classObject = null; $inc_dir = Plugin::getPhpDir('mreporting') . '/inc'; //parse inc dir to search report classes @@ -322,7 +319,7 @@ public function createFirstConfig() $input['firstconfig'] = 1; unset($input['id']); - $newid = $this->add($input); + $this->add($input); } } } @@ -330,7 +327,7 @@ public function createFirstConfig() /** * Preconfig datas for standard system * @graphname internal name of graph - *@return void + * @return array|boolean **/ public function preconfig($funct_name, $classname) { @@ -404,7 +401,7 @@ public function preconfig($funct_name, $classname) * show not used Graphs dropdown * @name name of dropdown * @options array example $value - *@return void + *@return int **/ public static function dropdownGraph($name, $options = []) { @@ -425,37 +422,32 @@ public static function dropdownGraph($name, $options = []) } if (isset($graphs[$classname])) { - $count = count($graphs[$classname]); - if ($count > 0) { - $select .= ''; - - $count = count($graphs[$classname]); - if ($count > 0) { - foreach ($graphs[$classname] as $cat => $graph) { - $select .= ''; - - foreach ($graph as $k => $v) { - $comment = ''; - if (isset($v['desc'])) { - $comment = $v['desc']; - $desc = ' (' . $comment . ')'; - } - - $select .= ''; - - $i++; - } - $select .= ''; + $select .= ''; + + foreach ($graphs[$classname] as $cat => $graph) { + $select .= ''; + + foreach ($graph as $k => $v) { + $comment = ''; + $desc = ''; + if (isset($v['desc'])) { + $comment = $v['desc']; + $desc = ' (' . $comment . ')'; } + + $select .= ''; + + $i++; } $select .= ''; } + $select .= ''; } } @@ -470,7 +462,7 @@ public static function dropdownGraph($name, $options = []) * show Label dropdown * @name name of dropdown * @options array example $value - *@return void + *@return integer|string **/ public static function dropdownLabel($name, $options = [], $notall = false) { @@ -603,7 +595,7 @@ public function prepareInputForUpdate($input) $object = new $input['classname']([]); $checkConfig = $object->checkConfig($input); if (!$checkConfig['result']) { - Session::addMessageAfterRedirect($checkConfig['message'], ERROR, true); + Session::addMessageAfterRedirect($checkConfig['message'], false, ERROR); return []; } @@ -614,6 +606,7 @@ public function prepareInputForUpdate($input) public function showForm($ID, $options = []) { + /** @var array $LANG */ global $LANG; $this->initForm($ID, $options); @@ -857,6 +850,7 @@ public static function initConfigParams($name, $classname) $crit['randname'] = $classname . $name; } + /* @phpstan-ignore-next-line */ if (DEBUG_MREPORTING) { $crit['show_graph'] = 1; } @@ -872,6 +866,7 @@ public static function initConfigParams($name, $classname) **/ public static function showGraphConfigValue($name, $classname) { + /* @phpstan-ignore-next-line */ if (DEBUG_MREPORTING) { return true; } diff --git a/inc/dashboard.class.php b/inc/dashboard.class.php index de554370..4dc60d4a 100644 --- a/inc/dashboard.class.php +++ b/inc/dashboard.class.php @@ -44,8 +44,6 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { - global $CFG_GLPI; - if ( get_class($item) == 'Central' && PluginMreportingCommon::canAccessAtLeastOneReport($_SESSION['glpiactiveprofile']['id']) diff --git a/inc/graphcsv.class.php b/inc/graphcsv.class.php index 9c4ea04b..a19866af 100644 --- a/inc/graphcsv.class.php +++ b/inc/graphcsv.class.php @@ -42,6 +42,7 @@ public function initGraph($options) public function showHbar($params, $dashboard = false, $width = false) { + /** @var array $CFG_GLPI */ global $CFG_GLPI; $criterias = PluginMreportingCommon::initGraphParams($params); @@ -104,6 +105,7 @@ public function showPie($params, $dashboard = false, $width = false) public function showHgbar($params, $dashboard = false, $width = false) { + /** @var array $CFG_GLPI */ global $CFG_GLPI; $criterias = PluginMreportingCommon::initGraphParams($params); diff --git a/inc/graphpng.class.php b/inc/graphpng.class.php index 9de584de..c6d43894 100644 --- a/inc/graphpng.class.php +++ b/inc/graphpng.class.php @@ -58,7 +58,8 @@ public function __construct() */ public function initGraph($options) { - global $LANG, $CFG_GLPI; + /** @var array $LANG */ + global $LANG; $randname = $options['randname']; @@ -122,6 +123,7 @@ public function initGraph($options) public function showImage($contents, $export = 'png') { + /** @var array $CFG_GLPI */ global $CFG_GLPI; if ($export != 'odt' && $export != 'odtall') { diff --git a/inc/helpdesk.class.php b/inc/helpdesk.class.php index 54bba47f..f87df80b 100644 --- a/inc/helpdesk.class.php +++ b/inc/helpdesk.class.php @@ -39,6 +39,7 @@ public function reportPieTicketNumberByEntity($config = []) public function reportHbarTicketNumberByEntity($config = []) { + /** @var \DBmysql $DB */ global $DB; $_SESSION['mreporting_selector']['reportHbarTicketNumberByEntity'] = ['dateinterval', @@ -70,7 +71,7 @@ public function reportHbarTicketNumberByEntity($config = []) LIMIT 0, "; $query .= (isset($_REQUEST['glpilist_limit'])) ? $_REQUEST['glpilist_limit'] : 20; - $result = $DB->query($query); + $result = $DB->doQuery($query); while ($ticket = $DB->fetchAssoc($result)) { if (empty($ticket['name'])) { @@ -86,6 +87,7 @@ public function reportHbarTicketNumberByEntity($config = []) public function reportHgbarTicketNumberByCatAndEntity($config = []) { + /** @var \DBmysql $DB */ global $DB; $_SESSION['mreporting_selector']['reportHgbarTicketNumberByCatAndEntity'] @@ -116,7 +118,7 @@ public function reportHgbarTicketNumberByCatAndEntity($config = []) $query_cat .= "AND glpi_tickets.is_deleted = '0' ORDER BY glpi_itilcategories.id ASC"; - $res_cat = $DB->query($query_cat); + $res_cat = $DB->doQuery($query_cat); $categories = []; while ($data = $DB->fetchAssoc($res_cat)) { @@ -152,7 +154,7 @@ public function reportHgbarTicketNumberByCatAndEntity($config = []) AND glpi_tickets.is_deleted = '0' GROUP BY glpi_entities.name, glpi_tickets.itilcategories_id ORDER BY glpi_entities.name ASC, glpi_tickets.itilcategories_id ASC"; - $res = $DB->query($query); + $res = $DB->doQuery($query); while ($data = $DB->fetchAssoc($res)) { if (empty($data['entity'])) { $data['entity'] = __('Root entity'); @@ -188,6 +190,7 @@ public function reportHgbarTicketNumberByCatAndEntity($config = []) public function reportPieTicketOpenedAndClosed($config = []) { + /** @var \DBmysql $DB */ global $DB; $_SESSION['mreporting_selector']['reportPieTicketOpenedAndClosed'] @@ -212,8 +215,8 @@ public function reportPieTicketOpenedAndClosed($config = []) $query .= "AND glpi_tickets.is_deleted = '0' AND glpi_tickets.status IN('" . implode("', '", array_keys($filter['status'])) . "')"; - $result = $DB->query($query); - $datas[$filter['label']] = $DB->result($result, 0, 0); + $result = $DB->doQuery($query); + $datas[$filter['label']] = $DB->result($result, 0, "0"); } return ['datas' => $datas]; @@ -221,8 +224,11 @@ public function reportPieTicketOpenedAndClosed($config = []) public function reportPieTicketOpenedbyStatus($config = []) { + /** @var \DBmysql $DB */ global $DB; + $status_to_show = []; + $_SESSION['mreporting_selector']['reportPieTicketOpenedbyStatus'] = ['dateinterval', 'allstates']; @@ -254,7 +260,7 @@ public function reportPieTicketOpenedbyStatus($config = []) AND glpi_tickets.is_deleted = '0' AND glpi_tickets.entities_id IN ({$this->where_entities}) AND glpi_tickets.status ='{$key}'"; - $result = $DB->query($query); + $result = $DB->doQuery($query); while ($ticket = $DB->fetchAssoc($result)) { $datas['datas'][$val] = $ticket['count']; @@ -267,6 +273,7 @@ public function reportPieTicketOpenedbyStatus($config = []) public function reportPieTopTenAuthor($config = []) { + /** @var \DBmysql $DB */ global $DB; $_SESSION['mreporting_selector']['reportPieTopTenAuthor'] @@ -278,7 +285,7 @@ public function reportPieTopTenAuthor($config = []) $config['delay'], $config['randname'], ); - $this->sql_closedate = PluginMreportingCommon::getSQLDate( + $this->sql_date_closed = PluginMreportingCommon::getSQLDate( 'glpi_tickets.closedate', $config['delay'], $config['randname'], @@ -290,13 +297,13 @@ public function reportPieTopTenAuthor($config = []) LEFT JOIN glpi_tickets_users ON (glpi_tickets_users.tickets_id = glpi_tickets.id AND glpi_tickets_users.type =1) WHERE {$this->sql_date} - AND {$this->sql_closedate} + AND {$this->sql_date_closed} AND glpi_tickets.entities_id IN ({$this->where_entities}) AND glpi_tickets.is_deleted = '0' GROUP BY glpi_tickets_users.users_id ORDER BY count DESC LIMIT 10"; - $result = $DB->query($query); + $result = $DB->doQuery($query); while ($ticket = $DB->fetchAssoc($result)) { if ($ticket['users_id'] == 0) { $label = __('Undefined', 'mreporting'); @@ -327,6 +334,7 @@ public function reportHgbarCloseTicketNumberByCategoryAndByType($config = []) private function reportHgbarTicketNumberByCategoryAndByType(array $config, $filter) { + /** @var \DBmysql $DB */ global $DB; $_SESSION['mreporting_selector']['reportHgbarTicketNumberByCategoryAndByType'] @@ -354,11 +362,11 @@ private function reportHgbarTicketNumberByCategoryAndByType(array $config, $filt AND glpi_tickets.is_deleted = '0' GROUP BY glpi_itilcategories.id, glpi_tickets.type ORDER BY glpi_itilcategories.name"; - $result = $DB->query($query); + $result = $DB->doQuery($query); $datas['datas'] = []; while ($ticket = $DB->fetchAssoc($result)) { - if (is_null($ticket['category_id'])) { + if (is_empty($ticket['category_id'])) { $ticket['category_id'] = 0; $ticket['category_name'] = __('None'); } @@ -376,6 +384,7 @@ private function reportHgbarTicketNumberByCategoryAndByType(array $config, $filt public function reportHgbarTicketNumberByService($config = []) { + /** @var \DBmysql $DB */ global $DB; $_SESSION['mreporting_selector']['reportHgbarTicketNumberByService'] @@ -402,9 +411,9 @@ public function reportHgbarTicketNumberByService($config = []) AND glpi_tickets.entities_id IN (' . $this->where_entities . ") AND {$this->sql_date} AND status IN('" . implode("', '", array_keys($filter['status'])) . "')"; - $result = $DB->query($query); + $result = $DB->doQuery($query); - $datas['datas'][__('None')][$filter['label']] = $DB->result($result, 0, 0); + $datas['datas'][__('None')][$filter['label']] = $DB->result($result, 0, "0"); $query = "SELECT glpi_groups.name as group_name, COUNT(glpi_tickets.id) as count @@ -418,7 +427,7 @@ public function reportHgbarTicketNumberByService($config = []) AND glpi_tickets.status IN('" . implode("', '", array_keys($filter['status'])) . "') GROUP BY glpi_groups.id ORDER BY glpi_groups.name"; - $result = $DB->query($query); + $result = $DB->doQuery($query); while ($ticket = $DB->fetchAssoc($result)) { $datas['datas'][$ticket['group_name']][$filter['label']] = $ticket['count']; @@ -430,12 +439,14 @@ public function reportHgbarTicketNumberByService($config = []) public function reportHgbarOpenedTicketNumberByCategory($config = []) { + /** @var \DBmysql $DB */ global $DB; $_SESSION['mreporting_selector']['reportHgbarOpenedTicketNumberByCategory'] = ['dateinterval', 'allstates']; $datas = []; + $status_to_show = []; //Init delay value $this->sql_date = PluginMreportingCommon::getSQLDate( @@ -471,7 +482,7 @@ public function reportHgbarOpenedTicketNumberByCategory($config = []) AND status IN (" . implode(',', $status_to_show) . ') GROUP BY glpi_itilcategories.id, glpi_tickets.status ORDER BY glpi_itilcategories.name'; - $result = $DB->query($query); + $result = $DB->doQuery($query); while ($ticket = $DB->fetchAssoc($result)) { if (is_null($ticket['category_name'])) { @@ -508,6 +519,7 @@ public function reportLineNbTicket($config = []) public function reportAreaNbTicket($config = [], $area = true) { + /** @var \DBmysql $DB */ global $DB; $_SESSION['mreporting_selector']['reportAreaNbTicket'] = ['dateinterval', 'period']; @@ -531,7 +543,7 @@ public function reportAreaNbTicket($config = [], $area = true) AND glpi_tickets.is_deleted = '0' GROUP BY period ORDER BY period"; - $res = $DB->query($query); + $res = $DB->doQuery($query); while ($data = $DB->fetchAssoc($res)) { $datas['datas'][$data['period_name']] = $data['nb']; } @@ -555,6 +567,7 @@ public function reportGareaNbTicket($config = []) public function reportGlineNbTicket($config = [], $area = false) { + /** @var \DBmysql $DB */ global $DB; $_SESSION['mreporting_selector']['reportGlineNbTicket'] @@ -591,7 +604,7 @@ public function reportGlineNbTicket($config = [], $area = false) AND `glpi_tickets`.`is_deleted` = '0' AND status IN(" . implode(',', $status_to_show) . ') ORDER BY `date` ASC'; - $res_date = $DB->query($query_date); + $res_date = $DB->doQuery($query_date); $dates = []; while ($data = $DB->fetchAssoc($res_date)) { $dates[$data['period']] = $data['period']; @@ -614,7 +627,7 @@ public function reportGlineNbTicket($config = [], $area = false) AND status IN(" . implode(',', $status_to_show) . ') GROUP BY period, status ORDER BY period, status'; - $res = $DB->query($query); + $res = $DB->doQuery($query); while ($data = $DB->fetchAssoc($res)) { $status = Ticket::getStatus($data['status']); $datas['labels2'][$data['period']] = $data['period_name']; @@ -640,6 +653,7 @@ public function reportGlineNbTicket($config = [], $area = false) public function reportSunburstTicketByCategories($config = []) { + /** @var \DBmysql $DB */ global $DB; $_SESSION['mreporting_selector']['reportSunburstTicketByCategories'] = ['dateinterval']; @@ -666,7 +680,7 @@ public function reportSunburstTicketByCategories($config = []) AND glpi_tickets.is_deleted = '0' GROUP BY glpi_itilcategories.id ORDER BY glpi_itilcategories.name"; - $res = $DB->query($query); + $res = $DB->doQuery($query); while ($data = $DB->fetchAssoc($res)) { $flat_datas[$data['id']] = $data; } @@ -697,6 +711,7 @@ public function reportSunburstTicketByCategories($config = []) public function reportVstackbarTicketStatusByTechnician($config = []) { + /** @var \DBmysql $DB */ global $DB; $_SESSION['mreporting_selector']['reportVstackbarTicketStatusByTechnician'] = ['dateinterval']; @@ -727,7 +742,7 @@ public function reportVstackbarTicketStatusByTechnician($config = []) AND glpi_tickets.entities_id IN ({$this->where_entities}) AND glpi_tickets.is_deleted = '0' ORDER BY fullname, username"; - $result = $DB->query($query); + $result = $DB->doQuery($query); while ($technician = $DB->fetchAssoc($result)) { $technicians[] = ['username' => $technician['username'], @@ -764,7 +779,7 @@ public function reportVstackbarTicketStatusByTechnician($config = []) AND glpi_tickets.is_deleted = '0' GROUP BY status, technician ORDER BY technician, username"; - $result = $DB->query($query); + $result = $DB->doQuery($query); while ($ticket = $DB->fetchAssoc($result)) { if (is_null($ticket['technician'])) { @@ -778,6 +793,7 @@ public function reportVstackbarTicketStatusByTechnician($config = []) public function reportHbarTicketNumberByLocation($config = []) { + /** @var \DBmysql $DB */ global $DB; $_SESSION['mreporting_selector']['reportHbarTicketNumberByLocation'] @@ -809,7 +825,7 @@ public function reportHbarTicketNumberByLocation($config = []) LIMIT 0, "; $query .= (isset($_REQUEST['glpilist_limit'])) ? $_REQUEST['glpilist_limit'] : 20; - $result = $DB->query($query); + $result = $DB->doQuery($query); while ($ticket = $DB->fetchAssoc($result)) { if (empty($ticket['name'])) { diff --git a/inc/helpdeskplus.class.php b/inc/helpdeskplus.class.php index b93bad98..15b6ac8d 100644 --- a/inc/helpdeskplus.class.php +++ b/inc/helpdeskplus.class.php @@ -47,6 +47,8 @@ class PluginMreportingHelpdeskplus extends PluginMreportingBaseclass protected $sql_join_gt; protected $sql_join_gtr; protected $sql_select_sla; + protected $lcl_slaok; + protected $lcl_slako; public function __construct($config = []) { @@ -135,6 +137,11 @@ public function __construct($config = []) public function reportGlineBacklogs($config = []) { + /** + * @var \DBmysql $DB + * @var array $LANG + */ + global $DB, $LANG; $_SESSION['mreporting_selector']['reportGlineBacklogs'] = ['dateinterval', 'period', 'backlogstates', 'multiplegrouprequest', @@ -318,6 +325,7 @@ public function reportGlineBacklogs($config = []) public function reportVstackbarLifetime($config = []) { + /** @var \DBmysql $DB */ global $DB; $tab = $datas = $labels2 = []; @@ -352,7 +360,7 @@ public function reportVstackbarLifetime($config = []) AND {$this->sql_user_assign} GROUP BY period ORDER BY period"; - $res = $DB->query($sql_status); + $res = $DB->doQuery($sql_status); while ($data = $DB->fetchAssoc($res)) { $tab[$data['period']][$status_name] = $data['nb']; $labels2[$data['period']] = $data['period_name']; @@ -371,6 +379,7 @@ public function reportVstackbarLifetime($config = []) public function reportVstackbarTicketsgroups($config = []) { + /** @var \DBmysql $DB */ global $DB; $_SESSION['mreporting_selector']['reportVstackbarTicketsgroups'] = ['dateinterval', 'allstates', 'multiplegroupassign', 'category']; @@ -400,7 +409,7 @@ public function reportVstackbarTicketsgroups($config = []) AND {$this->sql_group_assign} GROUP BY group_name ORDER BY group_name"; - $res = $DB->query($sql_status); + $res = $DB->doQuery($sql_status); while ($data = $DB->fetchAssoc($res)) { if (empty($data['group_name'])) { $data['group_name'] = __('None'); @@ -421,6 +430,7 @@ public function reportVstackbarTicketsgroups($config = []) public function reportVstackbarTicketstech($config = []) { + /** @var \DBmysql $DB */ global $DB; $_SESSION['mreporting_selector']['reportVstackbarTicketstech'] @@ -457,7 +467,7 @@ public function reportVstackbarTicketstech($config = []) AND {$this->sql_itilcat} GROUP BY name ORDER BY name"; - $res = $DB->query($sql_create); + $res = $DB->doQuery($sql_create); while ($data = $DB->fetchAssoc($res)) { $data['name'] = empty($data['completename']) ? __('None') : $data['completename']; @@ -481,6 +491,7 @@ public function reportVstackbarTicketstech($config = []) public function reportHbarTopcategory($config = []) { + /** @var \DBmysql $DB */ global $DB; $_SESSION['mreporting_selector']['reportHbarTopcategory'] @@ -510,7 +521,7 @@ public function reportHbarTopcategory($config = []) $sql_create .= (isset($_SESSION['mreporting_values']['glpilist_limit'])) ? $_SESSION['mreporting_values']['glpilist_limit'] : 20; - $res = $DB->query($sql_create); + $res = $DB->doQuery($sql_create); while ($data = $DB->fetchAssoc($res)) { if (empty($data['completename'])) { $data['completename'] = __('None'); @@ -523,6 +534,7 @@ public function reportHbarTopcategory($config = []) public function reportHbarTopapplicant($config = []) { + /** @var \DBmysql $DB */ global $DB; $_SESSION['mreporting_selector']['reportHbarTopapplicant'] = ['dateinterval', 'limit', 'type']; @@ -546,7 +558,7 @@ public function reportHbarTopapplicant($config = []) $sql_create .= (isset($_SESSION['mreporting_values']['glpilist_limit'])) ? $_SESSION['mreporting_values']['glpilist_limit'] : 20; - $res = $DB->query($sql_create); + $res = $DB->doQuery($sql_create); while ($data = $DB->fetchAssoc($res)) { if (empty($data['completename'])) { $data['completename'] = __('None'); @@ -559,6 +571,7 @@ public function reportHbarTopapplicant($config = []) public function reportVstackbarGroupChange($config = []) { + /** @var \DBmysql $DB */ global $DB; $_SESSION['mreporting_selector']['reportVstackbarGroupChange'] @@ -597,7 +610,7 @@ public function reportVstackbarGroupChange($config = []) ) as ticc GROUP BY ticc.nb_add_group"; - $result = $DB->query($query); + $result = $DB->doQuery($query); $datas['datas'] = []; while ($ticket = $DB->fetchAssoc($result)) { @@ -610,6 +623,7 @@ public function reportVstackbarGroupChange($config = []) public function reportLineActiontimeVsSolvedelay($config = []) { + /** @var \DBmysql $DB */ global $DB; $_SESSION['mreporting_selector']['reportLineActiontimeVsSolvedelay'] = ['dateinterval', 'period', 'multiplegrouprequest', @@ -657,6 +671,7 @@ public function reportLineActiontimeVsSolvedelay($config = []) public function reportGlineNbTicketBySla($config = []) { + /** @var \DBmysql $DB */ global $DB; $area = false; @@ -681,7 +696,7 @@ public function reportGlineNbTicketBySla($config = []) AND `glpi_tickets`.`is_deleted` = '0' AND `glpi_slas`.id IN (" . implode(',', $_SESSION['mreporting_values']['slas']) . ') ORDER BY `glpi_tickets`.`date` ASC'; - $res_date = $DB->query($query_date); + $res_date = $DB->doQuery($query_date); $dates = []; while ($data = $DB->fetchAssoc($res_date)) { @@ -711,7 +726,7 @@ public function reportGlineNbTicketBySla($config = []) } $query .= 'GROUP BY `glpi_slas`.name, period, respected_sla'; - $result = $DB->query($query); + $result = $DB->doQuery($query); while ($data = $DB->fetchAssoc($result)) { $datas['labels2'][$data['period']] = $data['period_name']; if ($data['respected_sla'] == 'ok') { @@ -734,6 +749,7 @@ public function reportGlineNbTicketBySla($config = []) public function reportHgbarRespectedSlasByTopCategory($config = []) { + /** @var \DBmysql $DB */ global $DB; $area = false; @@ -770,7 +786,7 @@ public function reportHgbarRespectedSlasByTopCategory($config = []) ORDER BY nb DESC LIMIT " . $category_limit; - $result_categories = $DB->query($query_categories); + $result_categories = $DB->doQuery($query_categories); while ($data = $DB->fetchAssoc($result_categories)) { $categories[] = $data['id']; } @@ -796,7 +812,7 @@ public function reportHgbarRespectedSlasByTopCategory($config = []) $query .= ' GROUP BY respected_sla, `glpi_itilcategories`.id ORDER BY nb DESC'; - $result = $DB->query($query); + $result = $DB->doQuery($query); while ($data = $DB->fetchAssoc($result)) { $value = ($data['respected_sla'] == 'ok') ? $this->lcl_slaok : $this->lcl_slako; @@ -817,6 +833,7 @@ public function reportHgbarRespectedSlasByTopCategory($config = []) public function reportHgbarRespectedSlasByTechnician($config = []) { + /** @var \DBmysql $DB */ global $DB; $area = false; @@ -843,7 +860,7 @@ public function reportHgbarRespectedSlasByTechnician($config = []) GROUP BY respected_sla, `glpi_users`.id ORDER BY nb DESC"; - $result = $DB->query($query); + $result = $DB->doQuery($query); while ($data = $DB->fetchAssoc($result)) { if ($data['respected_sla'] == 'ok') { $value = $this->lcl_slaok; @@ -894,6 +911,7 @@ public function fillStatusMissingValues($tab, $labels2 = []) public static function selectorBacklogstates() { + /** @var array $LANG */ global $LANG; echo '
' . $LANG['plugin_mreporting']['Helpdeskplus']['backlogstatus'] . ' :
'; @@ -943,6 +961,10 @@ public static function selectorBacklogstates() public function reportVstackbarRespectedSlasByGroup($config = []) { + /** + * @var \DBmysql $DB + * @var array $LANG + */ global $DB, $LANG; $datas = []; @@ -976,11 +998,11 @@ public function reportVstackbarRespectedSlasByGroup($config = []) AND `glpi_tickets`.is_deleted = '0' AND `glpi_slas`.id IN (" . implode(',', $_SESSION['mreporting_values']['slas']) . ') GROUP BY `glpi_groups_tickets`.groups_id, respected_sla;'; - $result = $DB->query($query); + $result = $DB->doQuery($query); while ($data = $DB->fetchAssoc($result)) { $gp = new Group(); - $gp->getFromDB($data['groups_id']); + $gp->getFromDB((int)$data['groups_id']); $datas['labels2'][$gp->fields['name']] = $gp->fields['name']; @@ -1025,10 +1047,12 @@ public function reportVstackbarRespectedSlasByGroup($config = []) public function reportVstackbarNbTicketBySla($config = []) { + /** + * @var \DBmysql $DB + * @var array $LANG + */ global $DB, $LANG; - $area = false; - $_SESSION['mreporting_selector']['reportVstackbarNbTicketBySla'] = ['dateinterval', 'allSlasWithTicket']; $datas = []; @@ -1056,7 +1080,7 @@ public function reportVstackbarNbTicketBySla($config = []) AND `glpi_slas`.id IN (" . implode(',', $_SESSION['mreporting_values']['slas']) . ') GROUP BY `glpi_slas`.name, respected_sla;'; - $result = $DB->query($query); + $result = $DB->doQuery($query); while ($data = $DB->fetchAssoc($result)) { $tmp_datas[$data['name']][$data['respected_sla']] = $data['nb']; } diff --git a/inc/inventory.class.php b/inc/inventory.class.php index 8ba9031f..c8b2dea2 100644 --- a/inc/inventory.class.php +++ b/inc/inventory.class.php @@ -38,8 +38,6 @@ public static function selectorMultipleStates() public static function selectorForMultipleStates($field, $condition = [], $label = '') { - global $DB; - $selected_states = []; if (isset($_SESSION['mreporting_values'][$field])) { $selected_states = $_SESSION['mreporting_values'][$field]; @@ -63,6 +61,7 @@ public static function selectorForMultipleStates($field, $condition = [], $label public static function getDefaultState() { + /** @var \DBmysql $DB */ global $DB; $states = []; @@ -113,6 +112,7 @@ public function reportHbarComputersByFabricant($config = []) public function computersByFabricant($config = []) { + /** @var \DBmysql $DB */ global $DB; $sql_entities = " AND c.`entities_id` IN ({$this->where_entities})"; @@ -137,7 +137,7 @@ public function computersByFabricant($config = []) AND c.`is_template` = 0 GROUP BY m.`name` ORDER BY Total DESC"; - $result = $DB->query($query); + $result = $DB->doQuery($query); $datas = []; while ($computer = $DB->fetchAssoc($result)) { @@ -167,6 +167,7 @@ public function reportHbarComputersByType($config = []) public function computersByType($config = []) { + /** @var \DBmysql $DB */ global $DB; $sql_entities = " AND c.`entities_id` IN ({$this->where_entities})"; @@ -190,7 +191,7 @@ public function computersByType($config = []) AND c.`is_template` = 0 GROUP BY t.`name` ORDER BY Total DESC"; - $result = $DB->query($query); + $result = $DB->doQuery($query); $datas = []; while ($computer = $DB->fetchAssoc($result)) { $percent = round($computer['Percent'], 2); @@ -217,6 +218,7 @@ public function reportHbarComputersByAge($config = []) public function computersByAge($config = []) { + /** @var \DBmysql $DB */ global $DB; $sql_entities = " AND c.`entities_id` IN ({$this->where_entities})"; @@ -315,7 +317,7 @@ public function computersByAge($config = []) AND i.`warranty_date` IS NULL $sql_entities $sql_states"; - $result = $DB->query($query); + $result = $DB->doQuery($query); while ($computer = $DB->fetchAssoc($result)) { $percent = round($computer['Percent'], 2); @@ -343,6 +345,7 @@ public function reportHbarComputersByOS($config = []) public function computersByOS($config = []) { + /** @var \DBmysql $DB */ global $DB; $sql_entities = " AND c.`entities_id` IN ({$this->where_entities})"; @@ -411,7 +414,7 @@ public function computersByOS($config = []) $sql_states"; $query .= ' ORDER BY Total DESC'; - $result = $DB->query($query); + $result = $DB->doQuery($query); $datas = []; while ($computer = $DB->fetchAssoc($result)) { @@ -426,6 +429,7 @@ public function computersByOS($config = []) public function reportHbarWindows($config = []) { + /** @var \DBmysql $DB */ global $DB; $_SESSION['mreporting_selector']['reportHbarWindows'] = ['multiplestates']; @@ -495,6 +499,7 @@ public function reportHbarWindows($config = []) public function reportHbarLinux($config = []) { + /** @var \DBmysql $DB */ global $DB; $_SESSION['mreporting_selector']['reportHbarLinux'] = ['multiplestates']; @@ -553,6 +558,7 @@ public function reportHbarLinux($config = []) public function reportHbarLinuxDistro($config = []) { + /** @var \DBmysql $DB */ global $DB; $_SESSION['mreporting_selector']['reportHbarLinuxDistro'] = ['multiplestates']; @@ -594,6 +600,7 @@ public function reportHbarLinuxDistro($config = []) public function reportHbarMac($config = []) { + /** @var \DBmysql $DB */ global $DB; $_SESSION['mreporting_selector']['reportHbarMac'] = ['multiplestates']; @@ -650,6 +657,7 @@ public function reportHbarMac($config = []) public function reportHbarMacFamily($config = []) { + /** @var \DBmysql $DB */ global $DB; $_SESSION['mreporting_selector']['reportHbarMacFamily'] = ['multiplestates']; @@ -730,6 +738,7 @@ public function reportHbarFusionInventory($config = []) public function fusionInventory($config = []) { + /** @var \DBmysql $DB */ global $DB; $plugin = new Plugin(); @@ -769,6 +778,7 @@ public function fusionInventory($config = []) /* ==== MONITOR REPORST ==== */ public function reportHbarMonitors($config = []) { + /** @var \DBmysql $DB */ global $DB; $_SESSION['mreporting_selector']['reportHbarMonitors'] = ['multiplestates']; @@ -800,6 +810,7 @@ public function reportHbarMonitors($config = []) /* ==== COMPUTER'S STATE REPORTS ==== */ public function reportHbarComputersByStatus($config = []) { + /** @var \DBmysql $DB */ global $DB; $query = "SELECT t.`name` status, count(*) Total, count(*) * 100 / (SELECT count(*) @@ -816,7 +827,7 @@ public function reportHbarComputersByStatus($config = []) AND c.`is_deleted` = 0 AND c.`is_template` = 0 GROUP BY t.`name`"; - $result = $DB->query($query); + $result = $DB->doQuery($query); $datas = []; while ($computer = $DB->fetchAssoc($result)) { $percent = round($computer['Percent'], 2); @@ -828,6 +839,7 @@ public function reportHbarComputersByStatus($config = []) public function reportHbarPrintersByStatus($config = []) { + /** @var \DBmysql $DB */ global $DB; $datas = []; @@ -842,7 +854,7 @@ public function reportHbarPrintersByStatus($config = []) FROM glpi_printers c, glpi_states t WHERE c.states_id = t.id $condition AND c.`is_deleted`=0 AND c.`is_template`=0 GROUP BY t.name"; - $result = $DB->query($query); + $result = $DB->doQuery($query); while ($printer = $DB->fetchAssoc($result)) { $pourcentage = round($printer['Pourcentage'], 2); @@ -855,6 +867,7 @@ public function reportHbarPrintersByStatus($config = []) /* ==== COMPUTER'S ENTITIES REPORTS ==== */ public function reportHbarComputersByEntity($config = []) { + /** @var \DBmysql $DB */ global $DB, $CFG_GLPI; $_SESSION['mreporting_selector']['reportHbarComputersByEntity'] = ['multiplestates', @@ -873,7 +886,7 @@ public function reportHbarComputersByEntity($config = []) FROM `glpi_entities` WHERE {$this->where_entities_level} ORDER BY `name`"; - $result = $DB->query($query); + $result = $DB->doQuery($query); while ($data = $DB->fetchAssoc($result)) { $entities_first_level[$data['id']] = $data['name']; @@ -890,7 +903,7 @@ public function reportHbarComputersByEntity($config = []) WHERE `entities_id` ' . $restrict . ' AND `is_deleted` = 0 AND `is_template` = 0'; - $result = $DB->query($query); + $result = $DB->doQuery($query); while ($computer = $DB->fetchAssoc($result)) { $datas['tmp'][$entities_name . ' (pourcentage %)'] = $computer['Total']; diff --git a/inc/notification.class.php b/inc/notification.class.php index 169155bd..aabcfd7f 100644 --- a/inc/notification.class.php +++ b/inc/notification.class.php @@ -39,7 +39,7 @@ class PluginMreportingNotification extends CommonDBTM * Return the localized name of the current Type (PluginMreporting) * * @see CommonGLPI::getTypeName() - * @param string $nb + * @param integer $nb * @return string name of the plugin */ public static function getTypeName($nb = 0) @@ -54,6 +54,7 @@ public static function getTypeName($nb = 0) */ public static function install($migration) { + /** @var \DBmysql $DB */ global $DB; // Création du template de la notification @@ -101,7 +102,7 @@ public static function install($migration) ], ); - $DB->query('INSERT INTO glpi_notificationtargets (items_id, type, notifications_id) + $DB->doQuery('INSERT INTO glpi_notificationtargets (items_id, type, notifications_id) VALUES (1, 1, ' . $notification_id . ');'); } @@ -115,6 +116,7 @@ public static function install($migration) */ public static function uninstall() { + /** @var \DBmysql $DB */ global $DB; $queries = []; @@ -140,7 +142,7 @@ public static function uninstall() } foreach ($queries as $query) { - $DB->query($query); + $DB->doQuery($query); } return ['success' => true]; @@ -177,7 +179,7 @@ public static function send($mailing_options, $additional_options) * * @param CronTask $task Object of CronTask class for log / stat * - * @return interger + * @return integer * >0 : done * <0 : to be run again (not finished) * 0 : nothing to do diff --git a/inc/notificationevent.class.php b/inc/notificationevent.class.php index fd75020c..b9d7b956 100644 --- a/inc/notificationevent.class.php +++ b/inc/notificationevent.class.php @@ -121,7 +121,7 @@ public static function raiseEvent($event, $item, $options = [], $label = '') PluginMreportingNotification::send( $template->getDataToSend( $notificationtarget, - $tid, + (string)$tid, $users_infos[$eventClass::getTargetFieldName()], $users_infos, $options, diff --git a/inc/notificationtargetnotification.class.php b/inc/notificationtargetnotification.class.php index 89b94dbe..33d78c12 100644 --- a/inc/notificationtargetnotification.class.php +++ b/inc/notificationtargetnotification.class.php @@ -49,6 +49,7 @@ public function getTags() public function addDataForTemplate($event, $options = []) { + /** @var array $CFG_GLPI */ global $CFG_GLPI; $file_name = $this->buildPDF(mt_rand() . '_'); @@ -64,11 +65,15 @@ public function addDataForTemplate($event, $options = []) /** * Generate a PDF file (with mreporting reports) to be send in the notifications * - * @return string hash Name of the created file + * @return string|boolean hash Name of the created file */ private function buildPDF($user_name = '') { - global $CFG_GLPI, $DB, $LANG; + /** + * @var DBmysql $DB + * @var DBmysql $LANG + */ + global $DB, $LANG; $dir = GLPI_PLUGIN_DOC_DIR . '/mreporting/notifications'; @@ -82,7 +87,7 @@ private function buildPDF($user_name = '') $images = []; - $result = $DB->query('SELECT id, name, classname, default_delay + $result = $DB->doQuery('SELECT id, name, classname, default_delay FROM glpi_plugin_mreporting_configs WHERE is_notified = 1 AND is_active = 1'); diff --git a/inc/other.class.php b/inc/other.class.php index 05726003..4570105e 100644 --- a/inc/other.class.php +++ b/inc/other.class.php @@ -32,6 +32,7 @@ class PluginMreportingOther extends PluginMreportingBaseclass { public function reportHbarLogs($configs = []) { + /** @var \DBmysql $DB */ global $DB; //Init delay value @@ -71,22 +72,22 @@ public function reportHbarLogs($configs = []) $datas = []; - $result = $DB->query($query_computer_software); + $result = $DB->doQuery($query_computer_software); $datas['datas'][__('Add/remove software on a computer', 'mreporting')] = $DB->result($result, 0, 'cpt'); - $result = $DB->query($query_software_version); + $result = $DB->doQuery($query_software_version); $datas['datas'][__('Add/remove version on a software', 'mreporting')] = $DB->result($result, 0, 'cpt'); - $result = $DB->query($query_add_infocom); + $result = $DB->doQuery($query_add_infocom); $datas['datas'][__('Add infocom', 'mreporting')] = $DB->result($result, 0, 'cpt'); - $result = $DB->query($query_user_profiles); + $result = $DB->doQuery($query_user_profiles); $datas['datas'][__('Add/remove profile on a user', 'mreporting')] = $DB->result($result, 0, 'cpt'); - $result = $DB->query($query_user_groups); + $result = $DB->doQuery($query_user_groups); $datas['datas'][__('Add/remove group on a user', 'mreporting')] = $DB->result($result, 0, 'cpt'); - $result = $DB->query($query_user_deleted); + $result = $DB->doQuery($query_user_deleted); $datas['datas'][__('User deleted from LDAP', 'mreporting')] = $DB->result($result, 0, 'cpt'); $plugin = new Plugin(); @@ -94,23 +95,23 @@ public function reportHbarLogs($configs = []) $query_webservice = "$prefix `itemtype`='PluginWebservicesClient'"; // Display this information is not usefull if webservices is not activated - $result = $DB->query($query_webservice); + $result = $DB->doQuery($query_webservice); $datas['datas'][__('Webservice logs', 'mreporting')] = $DB->result($result, 0, 'cpt'); } - $result = $DB->query($query_ocs); + $result = $DB->doQuery($query_ocs); $datas['datas'][__('OCS Infos', 'mreporting')] = $DB->result($result, 0, 'cpt'); - $result = $DB->query($query_device); + $result = $DB->doQuery($query_device); $datas['datas'][__('Add/update/remove device', 'mreporting')] = $DB->result($result, 0, 'cpt'); - $result = $DB->query($query_relation); + $result = $DB->doQuery($query_relation); $datas['datas'][__('Add/remove relation', 'mreporting')] = $DB->result($result, 0, 'cpt'); - $result = $DB->query($query_item); + $result = $DB->doQuery($query_item); $datas['datas'][__('Add/remove item', 'mreporting')] = $DB->result($result, 0, 'cpt'); - $result = $DB->query($query_other); + $result = $DB->doQuery($query_other); $datas['datas'][__('Comments & date_mod changes', 'mreporting')] = $DB->result($result, 0, 'cpt'); $plugin = new Plugin(); @@ -118,7 +119,7 @@ public function reportHbarLogs($configs = []) $query_genericobject = "$prefix `itemtype` LIKE '%PluginGenericobject%'"; // Display this information is not usefull if genericobject is not activated - $result = $DB->query($query_genericobject); + $result = $DB->doQuery($query_genericobject); $datas['datas'][__('Genericobject plugin logs', 'mreporting')] = $DB->result($result, 0, 'cpt'); } @@ -128,10 +129,10 @@ public function reportHbarLogs($configs = []) /** * Preconfig datas with your values when init config is done * - * @param type $funct_name - * @param type $classname + * @param string|int $funct_name + * @param string $classname * @param PluginMreportingConfig $config - * @return $config + * @return array|boolean $config */ public function preconfig($funct_name, $classname, PluginMreportingConfig $config) { diff --git a/inc/pdf.class.php b/inc/pdf.class.php index 91139d72..3c31738e 100644 --- a/inc/pdf.class.php +++ b/inc/pdf.class.php @@ -41,6 +41,7 @@ class PluginMreportingPdf extends TCPDF public function Init() { // @codingStandardsIgnoreEnd + /** @var array $CFG_GLPI */ global $CFG_GLPI; $title = __('GLPI statistics reports', 'mreporting'); @@ -83,10 +84,10 @@ public function Content($images) } $h = floor(($image['height'] * $w) / $image['width']); - $this->Image($file, '', '', $w, $h); + $this->Image($file, null, null, $w, $h); $this->Ln($h); - $this->writeHTMLCell('', '', '', '', $image['title'], 0, 1, false, true, 'C'); + $this->writeHTMLCell(0., 0., null, null, $image['title'], 0, 1, false, true, 'C'); if ($i < $images_lengh) { $this->AddPage(); } @@ -101,6 +102,6 @@ public function Footer() { $this->SetY(-15); $this->SetFontSize(8); - $this->writeHTMLCell('', '', '', '', date('Y-m-d H:i:s'), 0, 0, false, true, 'R'); + $this->writeHTMLCell(0., 0., null, null, date('Y-m-d H:i:s'), 0, 0, false, true, 'R'); } } diff --git a/inc/preference.class.php b/inc/preference.class.php index b7cd8b24..159b77b6 100644 --- a/inc/preference.class.php +++ b/inc/preference.class.php @@ -52,9 +52,9 @@ public function addDefaultPreference($users_id) /** * * Get a preference for an user - * @param unknown_type preference field to get - * @param unknown_type user ID - * @return preference value or 0 + * @param string $field preference field to get + * @param int $users_id user ID + * @return int value or 0 */ public static function checkPreferenceValue($field, $users_id = 0) { @@ -113,7 +113,7 @@ public static function dropdownListFiles($name, $extension, $directory, $value = /** * * Check if at least one template exists - * @return true if at least one template exists, false otherwise + * @return bool if at least one template exists, false otherwise */ public static function atLeastOneTemplateExists() { @@ -153,6 +153,7 @@ public function showForm($ID, array $options = []) echo ''; echo ''; Html::closeForm(); + return true; } public static function getFiles($directory, $ext) @@ -196,7 +197,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { switch (get_class($item)) { case 'Preference': - return [1 => __('More Reporting', 'mreporting')]; + return __('More Reporting', 'mreporting'); default: return ''; } diff --git a/inc/profile.class.php b/inc/profile.class.php index d7dca786..46425547 100644 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -64,8 +64,9 @@ public static function purgeProfilesByReports(PluginMreportingConfig $config) public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { + /** @var CommonDBTM $item */ if ($item->getField('interface') == 'helpdesk') { - return false; + return ''; } switch ($item->getType()) { @@ -80,10 +81,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { - global $CFG_GLPI; - - if ($item->getType() == 'Profile' && $item->getField('interface') != 'helpdesk') { - $ID = $item->getField('id'); + if ($item instanceof Profile && $item->getField('interface') != 'helpdesk') { $prof = new self(); if (!$prof->getFromDBByProfile($item->getField('id'))) { @@ -100,11 +98,12 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $ public function getFromDBByProfile($profiles_id) { + /** @var \DBmysql $DB */ global $DB; $query = "SELECT * FROM `{$this->getTable()}` WHERE `profiles_id` = '" . $profiles_id . "'"; - if ($result = $DB->query($query)) { + if ($result = $DB->doQuery($query)) { if ($DB->numrows($result) != 1) { return false; } @@ -121,6 +120,7 @@ public function getFromDBByProfile($profiles_id) */ public static function addRightToAllProfiles() { + /** @var \DBmysql $DB */ global $DB; $result_config = $DB->request('SELECT `id` FROM `glpi_plugin_mreporting_configs`'); @@ -140,6 +140,7 @@ public static function addRightToAllProfiles() public static function getRight() { + /** @var \DBmysql $DB */ global $DB; $query = 'SELECT `profiles_id` @@ -160,6 +161,7 @@ public static function getRight() */ public static function addRightToProfile($idProfile) { + /** @var \DBmysql $DB */ global $DB; //get all reports @@ -184,6 +186,7 @@ public static function addRightToProfile($idProfile) */ public function addRightToReports($report_id) { + /** @var \DBmysql $DB */ global $DB; $reportProfile = new self(); @@ -219,6 +222,10 @@ public static function changeProfile() */ public function showForm($ID, $options = []) { + /** + * @var array $LANG + * @var array $CFG_GLPI + */ global $LANG, $CFG_GLPI; if (!Session::haveRight('profile', READ)) { @@ -290,6 +297,7 @@ public function showForm($ID, $options = []) echo ''; echo ''; Html::closeForm(); + return true; } /** @@ -298,6 +306,10 @@ public function showForm($ID, $options = []) */ public function showFormForManageProfile($items, $options = []) { + /** + * @var \DBmysql $DB + * @var array $CFG_GLPI + */ global $DB, $CFG_GLPI; if (!Session::haveRight('config', READ)) { diff --git a/inc/tag.class.php b/inc/tag.class.php index 6d45b3e5..2195b9e2 100644 --- a/inc/tag.class.php +++ b/inc/tag.class.php @@ -39,6 +39,7 @@ class PluginMreportingTag extends PluginMreportingBaseclass */ public function reportPieTag($config = []) { + /** @var \DBmysql $DB */ global $DB; if (!Plugin::isPluginActive('tag')) { @@ -49,7 +50,7 @@ public function reportPieTag($config = []) $datas = []; - $result = $DB->query('SELECT COUNT(*) as count_tag, glpi_plugin_tag_tags.name as name + $result = $DB->doQuery('SELECT COUNT(*) as count_tag, glpi_plugin_tag_tags.name as name FROM glpi_plugin_tag_tagitems LEFT JOIN glpi_plugin_tag_tags ON plugin_tag_tags_id = glpi_plugin_tag_tags.id GROUP BY plugin_tag_tags_id @@ -71,6 +72,7 @@ public function reportPieTag($config = []) */ public function reportPieTagOnTicket($config = []) { + /** @var \DBmysql $DB */ global $DB; if (!Plugin::isPluginActive('tag')) { @@ -84,7 +86,7 @@ public function reportPieTagOnTicket($config = []) $datas = []; - $result = $DB->query("SELECT COUNT(*) as count_tag, glpi_plugin_tag_tags.name + $result = $DB->doQuery("SELECT COUNT(*) as count_tag, glpi_plugin_tag_tags.name FROM glpi_plugin_tag_tagitems LEFT JOIN glpi_plugin_tag_tags ON plugin_tag_tags_id = glpi_plugin_tag_tags.id LEFT JOIN glpi_tickets ON glpi_tickets.id = glpi_plugin_tag_tagitems.items_id diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 00000000..cda32ecf --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,19 @@ +parameters: + parallel: + maximumNumberOfProcesses: 2 + level: 4 + bootstrapFiles: + - ../../inc/based_config.php + paths: + - inc + - front + - ajax + - hook.php + - setup.php + scanDirectories: + - ../../inc + - ../../src + stubFiles: + - ../../stubs/glpi_constants.php +rules: + - GlpiProject\Tools\PHPStan\Rules\GlobalVarTypeRule \ No newline at end of file diff --git a/setup.php b/setup.php index 5fea9201..be88378d 100644 --- a/setup.php +++ b/setup.php @@ -67,6 +67,10 @@ */ function plugin_init_mreporting() { + /** + * @var array $PLUGIN_HOOKS + * @var array $CFG_GLPI + */ global $PLUGIN_HOOKS, $CFG_GLPI; $PLUGIN_HOOKS['csrf_compliant']['mreporting'] = true; From c66299b55cea4e0f6f911aca07f7e4d3ce67d7ca Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Mon, 31 Mar 2025 10:14:49 +0200 Subject: [PATCH 02/24] Composer.lock --- composer.lock | 61 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/composer.lock b/composer.lock index ba7d9ea6..8b2f95e8 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5d8e4db6338de1a88c045c9c9c277424", + "content-hash": "6df73811807d78a601dcd3d340500992", "packages": [ { "name": "masnathan/odtphp", @@ -466,16 +466,16 @@ }, { "name": "friendsofphp/php-cs-fixer", - "version": "v3.76.0", + "version": "v3.74.0", "source": { "type": "git", "url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git", - "reference": "0e3c484cef0ae9314b0f85986a36296087432c40" + "reference": "6b7cb12a6cf592fd9a2b46a2d5d4c3b44003973d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/0e3c484cef0ae9314b0f85986a36296087432c40", - "reference": "0e3c484cef0ae9314b0f85986a36296087432c40", + "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/6b7cb12a6cf592fd9a2b46a2d5d4c3b44003973d", + "reference": "6b7cb12a6cf592fd9a2b46a2d5d4c3b44003973d", "shasum": "" }, "require": { @@ -559,7 +559,7 @@ ], "support": { "issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues", - "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.76.0" + "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.74.0" }, "funding": [ { @@ -567,7 +567,7 @@ "type": "github" } ], - "time": "2025-06-30T14:15:06+00:00" + "time": "2025-03-27T22:31:30+00:00" }, { "name": "glpi-project/tools", @@ -792,6 +792,53 @@ ], "time": "2025-05-21T20:55:28+00:00" }, + { + "name": "phpstan/phpstan-deprecation-rules", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan-deprecation-rules.git", + "reference": "1cc1259cb91ee4cfbb5c39bca9f635f067c910b4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/1cc1259cb91ee4cfbb5c39bca9f635f067c910b4", + "reference": "1cc1259cb91ee4cfbb5c39bca9f635f067c910b4", + "shasum": "" + }, + "require": { + "php": "^7.4 || ^8.0", + "phpstan/phpstan": "^2.0" + }, + "require-dev": { + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/phpstan-phpunit": "^2.0", + "phpunit/phpunit": "^9.6" + }, + "type": "phpstan-extension", + "extra": { + "phpstan": { + "includes": [ + "rules.neon" + ] + } + }, + "autoload": { + "psr-4": { + "PHPStan\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan rules for detecting usage of deprecated classes, methods, properties, constants and traits.", + "support": { + "issues": "https://github.com/phpstan/phpstan-deprecation-rules/issues", + "source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/2.0.1" + }, + "time": "2024-11-28T21:56:36+00:00" + }, { "name": "psr/container", "version": "1.1.2", From ec793642f50027fdbcd536f2c7aac5460d453814 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Tue, 1 Apr 2025 15:51:56 +0200 Subject: [PATCH 03/24] phpstan5 --- inc/common.class.php | 23 ----------------------- inc/config.class.php | 2 +- inc/dashboard.class.php | 8 +++----- inc/graph.class.php | 8 +++++++- inc/helpdesk.class.php | 21 +++++++++++---------- inc/inventory.class.php | 11 ++++++----- inc/notificationevent.class.php | 2 +- 7 files changed, 29 insertions(+), 46 deletions(-) diff --git a/inc/common.class.php b/inc/common.class.php index af95c9c0..8f00ee44 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -1106,28 +1106,6 @@ public function export($opt) } } } - if ( - isset($_SESSION['glpi_plugin_mreporting_odtarray']) && !empty($_SESSION['glpi_plugin_mreporting_odtarray']) - ) { - if (PluginMreportingPreference::atLeastOneTemplateExists()) { - $template = PluginMreportingPreference::checkPreferenceTemplateValue(Session::getLoginUserID()); - if ($template) { - self::generateOdt($_SESSION['glpi_plugin_mreporting_odtarray']); - } else { - Html::popHeader(__('General Report - ODT', 'mreporting'), $_SERVER['PHP_SELF']); - echo "

" . __('Please, select a model in your preferences', 'mreporting') . '

'; - Html::displayBackLink(); - echo '
'; - Html::popFooter(); - } - } else { - Html::popHeader(__('General Report - ODT', 'mreporting'), $_SERVER['PHP_SELF']); - echo "

" . __('No model available', 'mreporting') . '

'; - Html::displayBackLink(); - echo '
'; - Html::popFooter(); - } - } } else { //no selected data Html::popHeader(__('General Report - ODT', 'mreporting'), $_SERVER['PHP_SELF']); echo "

" . __('No graphic selected', 'mreporting') . '

'; @@ -1673,7 +1651,6 @@ public static function showSelector($date1, $date2, $randname) } $_SERVER['REQUEST_URI'] .= '&date1' . $randname . '=' . $date1 . '&date2' . $randname . '=' . $date2; - /* @phpstan-ignore-next-line */ SavedSearch::showSaveButton(SavedSearch::URI, __CLASS__); //If there's no selector for the report, there's no need for a reset button ! diff --git a/inc/config.class.php b/inc/config.class.php index 039591ca..ef503c09 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -318,7 +318,6 @@ public function createFirstConfig() } $input['firstconfig'] = 1; - unset($input['id']); $this->add($input); } } @@ -871,6 +870,7 @@ public static function showGraphConfigValue($name, $classname) return true; } + /* @phpstan-ignore-next-line */ $self = new self(); if ($self->getFromDBByFunctionAndClassname($name, $classname)) { return $self->fields['show_graph']; diff --git a/inc/dashboard.class.php b/inc/dashboard.class.php index 4dc60d4a..5d0c2255 100644 --- a/inc/dashboard.class.php +++ b/inc/dashboard.class.php @@ -67,15 +67,12 @@ function resizeIframe(obj) { public function showDashBoard($show_reports_dropdown = true) { + /** @var array $LANG */ global $LANG; $root_ajax = Plugin::getWebDir('mreporting') . '/ajax/dashboard.php'; - if (isset($options['target'])) { - $target = $options['target']; - } else { - $target = $this->getFormURL(); - } + $target = $this->getFormURL(); $_REQUEST['f_name'] = 'option'; PluginMreportingCommon::getSelectorValuesByUser(); @@ -278,6 +275,7 @@ public static function removeReportFromDashboard($id) public static function updateWidget($idreport) { + /** @var array $LANG */ global $LANG; $dashboard = new self(); diff --git a/inc/graph.class.php b/inc/graph.class.php index 92eefe4e..61b1b4dd 100644 --- a/inc/graph.class.php +++ b/inc/graph.class.php @@ -40,7 +40,8 @@ class PluginMreportingGraph */ public function initGraph($options) { - global $LANG, $CFG_GLPI; + /** @var array $LANG */ + global $LANG; $width = $this->width + 100; $randname = $options['randname']; @@ -131,6 +132,11 @@ public function initGraph($options) */ public function showHbar($params, $dashboard = false, $width = false) { + $opt = [ + 'f_name' => '', + 'class' => '', + ]; + ob_start(); if ($width !== false) { $this->width = $width; diff --git a/inc/helpdesk.class.php b/inc/helpdesk.class.php index f87df80b..35e48eaa 100644 --- a/inc/helpdesk.class.php +++ b/inc/helpdesk.class.php @@ -366,7 +366,7 @@ private function reportHgbarTicketNumberByCategoryAndByType(array $config, $filt $datas['datas'] = []; while ($ticket = $DB->fetchAssoc($result)) { - if (is_empty($ticket['category_id'])) { + if (empty($ticket['category_id'])) { $ticket['category_id'] = 0; $ticket['category_name'] = __('None'); } @@ -485,7 +485,7 @@ public function reportHgbarOpenedTicketNumberByCategory($config = []) $result = $DB->doQuery($query); while ($ticket = $DB->fetchAssoc($result)) { - if (is_null($ticket['category_name'])) { + if (empty($ticket['category_name'])) { $ticket['category_name'] = __('None'); } @@ -583,6 +583,7 @@ public function reportGlineNbTicket($config = [], $area = false) $config['randname'], ); + $status_to_show = []; // Get status to show if (isset($_POST['status_1'])) { foreach ($_POST as $key => $value) { @@ -782,7 +783,7 @@ public function reportVstackbarTicketStatusByTechnician($config = []) $result = $DB->doQuery($query); while ($ticket = $DB->fetchAssoc($result)) { - if (is_null($ticket['technician'])) { + if (empty($ticket['technician'])) { $ticket['technician'] = __('None'); } $datas['datas'][$status[$ticket['status']]][$ticket['username']] = $ticket['count']; @@ -844,10 +845,10 @@ public function reportHbarTicketNumberByLocation($config = []) * You can configure your dates for the Allodt export * * @param array $opt : contains the dates - * @param type $functionname - * @return $opt + * @param string $functionname + * @return array $opt */ - public function customExportDates(array $opt, $functionname) + public function customExportDates(array $opt, string $functionname) { $config = PluginMreportingConfig::initConfigParams($functionname, __CLASS__); @@ -859,12 +860,12 @@ public function customExportDates(array $opt, $functionname) /** * Preconfig datas with your values when init config is done * - * @param type $funct_name - * @param type $classname + * @param string $funct_name + * @param string $classname * @param PluginMreportingConfig $config - * @return $config + * @return array|bool $config */ - public function preconfig($funct_name, $classname, PluginMreportingConfig $config) + public function preconfig(string $funct_name, string $classname, PluginMreportingConfig $config) { if ($funct_name != -1 && $classname) { $ex_func = preg_split('/(?<=\\w)(?=[A-Z])/', $funct_name); diff --git a/inc/inventory.class.php b/inc/inventory.class.php index c8b2dea2..bc1c477f 100644 --- a/inc/inventory.class.php +++ b/inc/inventory.class.php @@ -490,7 +490,7 @@ public function reportHbarWindows($config = []) $key = $version['os_name'] . ' ' . $version['os_version'] . ' (' . round($version['os_qty'] / $total_computers * 100) . '%)'; $data['datas'][$key] = $version['os_qty']; } - if (isset($data['datas']) && !empty($data['datas'])) { + if (!empty($data['datas'])) { arsort($data['datas']); } @@ -549,7 +549,7 @@ public function reportHbarLinux($config = []) } } } - if (isset($data['datas']) && !empty($data['datas'])) { + if (!empty($data['datas'])) { arsort($data['datas']); } @@ -591,7 +591,7 @@ public function reportHbarLinuxDistro($config = []) $data['datas'][$os['name']] = $number; } } - if (isset($data['datas']) && !empty($data['datas'])) { + if (!empty($data['datas'])) { arsort($data['datas']); } @@ -714,7 +714,7 @@ public function reportHbarMacFamily($config = []) } } } - if (isset($data['datas']) && count($data['datas'])) { + if (!empty($data['datas'])) { arsort($data['datas']); } @@ -868,6 +868,7 @@ public function reportHbarPrintersByStatus($config = []) public function reportHbarComputersByEntity($config = []) { /** @var \DBmysql $DB */ + /** @var array $CFG_GLPI */ global $DB, $CFG_GLPI; $_SESSION['mreporting_selector']['reportHbarComputersByEntity'] = ['multiplestates', @@ -915,7 +916,7 @@ public function reportHbarComputersByEntity($config = []) if ($value == 0) { $percent = 0; } else { - $percent = round((100 * $value) / $total); + $percent = round((100 * (int) $value) / $total); } $ent_id = $entities[$key]; $key = str_replace('pourcentage', $percent, $key); diff --git a/inc/notificationevent.class.php b/inc/notificationevent.class.php index b9d7b956..ecccd36f 100644 --- a/inc/notificationevent.class.php +++ b/inc/notificationevent.class.php @@ -126,7 +126,7 @@ public static function raiseEvent($event, $item, $options = [], $label = '') $users_infos, $options, ), - $notificationtarget->additionalData, + [], ); } else { $notificationtarget->getFromDB($target['id']); From 842b3b5a5c8652d266a963e3685c4316ac79f2e8 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Tue, 1 Apr 2025 17:18:16 +0200 Subject: [PATCH 04/24] phpstan5 --- inc/common.class.php | 152 +++++++++++++++++++++++++++++++---------- inc/graphpng.class.php | 80 +++++++++++----------- 2 files changed, 157 insertions(+), 75 deletions(-) diff --git a/inc/common.class.php b/inc/common.class.php index 8f00ee44..0331d63b 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -731,35 +731,97 @@ public static function dropdownExt($options = []) */ public static function endGraph($options, $dashboard = false) { - foreach ($options as $k => $v) { - $$k = $v; - } + $opt = $options['opt']; + $export = $options['export']; + $datas = $options['datas']; + $unit = $options['unit']; + $labels2 = []; + $flip_data = false; $randname = false; + if (isset($opt['randname']) && $opt['randname'] !== false) { + $randname = $opt['randname']; + $_REQUEST['short_classname'] = $opt['short_classname']; + $_REQUEST['f_name'] = $opt['f_name']; + $_REQUEST['gtype'] = $opt['gtype']; + $_REQUEST['randname'] = $opt['randname']; - if (!$dashboard) { - if (isset($_REQUEST['f_name']) && $_REQUEST['f_name'] != 'test') { - echo "
"; - echo ""; - echo '

'; - self::showNavigation(); - echo '
'; - echo ""; - if (Session::haveRight('config', UPDATE)) { - echo '' . PluginMreportingConfig::getTypeName() . ' : '; - echo " "; - echo ""; + //End Script for graph display + //if $randname exists + + $config = PluginMreportingConfig::initConfigParams( + $opt['f_name'], + 'PluginMreporting' . $opt['short_classname'], + ); + if (!$export) { + if ($config['graphtype'] == 'SVG') { + echo "} + showGraph$randname(); + "; } - echo ''; + echo '
'; } - echo "
"; - echo '
'; + } - if (isset($_REQUEST['f_name']) && $_REQUEST['f_name'] != 'test') { - echo ''; - } + if (!$dashboard) { + $request_string = self::getRequestString($_REQUEST); - echo ''; + if ($export != 'odtall') { + $show_graph = false; + if ($randname !== false && !$export) { + $show_graph = PluginMreportingConfig::showGraphConfigValue($opt['f_name'], $opt['class']); + self::showGraphDatas($datas, $unit, $labels2, $flip_data, $show_graph); + } + if (!$export) { + if (isset($_REQUEST['f_name']) && $_REQUEST['f_name'] != 'test') { + echo "
"; + echo ""; + echo '

'; + self::showNavigation(); + echo '
'; + echo ""; + if (Session::haveRight('config', UPDATE)) { + echo '' . PluginMreportingConfig::getTypeName() . ' : '; + echo " "; + echo ""; + } + if ($randname !== false) { + echo '

'; + + echo ""; + + echo '' . __('Export') . ' : '; + $params = ['myname' => 'ext', + 'ajax_page' => Plugin::getWebDir('mreporting') . '/ajax/dropdownExport.php', + 'class' => __CLASS__, + 'span' => 'show_ext', + 'gtype' => $_REQUEST['gtype'], + 'show_graph' => $show_graph, + 'display_svg' => ($config['graphtype'] != 'PNG'), + 'randname' => $randname, + ]; + + self::dropdownExt($params); + + echo ""; + Html::closeForm(); + } + echo '
'; + } + echo "
"; + echo '
'; + + if (isset($_REQUEST['f_name']) && $_REQUEST['f_name'] != 'test') { + echo ''; + } + } + + if ($randname == false) { + echo ''; + } + } } //destroy specific palette @@ -1180,9 +1242,9 @@ public static function generateOdt($params) } $odf = new Odf('../templates/template.odt', $config); - $odf->setVars('category', $category, (bool)ENT_NOQUOTES, 'utf-8'); - $odf->setVars('title', $params[0]['title'], (bool)ENT_NOQUOTES, 'utf-8'); - $odf->setVars('description', $description, (bool)ENT_NOQUOTES, 'utf-8'); + $odf->setVars('category', $category, ENT_NOQUOTES, 'utf-8'); + $odf->setVars('title', $params[0]['title'], ENT_NOQUOTES, 'utf-8'); + $odf->setVars('description', $description, ENT_NOQUOTES, 'utf-8'); $path = GLPI_PLUGIN_DOC_DIR . '/mreporting/' . $params[0]['f_name'] . '.png'; @@ -1190,7 +1252,7 @@ public static function generateOdt($params) list($image_width, $image_height) = @getimagesize($path); $image_width *= Odf::PIXEL_TO_CM; $image_height *= Odf::PIXEL_TO_CM * 17 / $image_width; - $odf->setImage('image', $path, -1, 17, (int)$image_height); + $odf->setImage('image', $path, -1, 17, $image_height); } else { $odf->setVars('image', '', true, 'UTF-8'); } @@ -1209,12 +1271,25 @@ public static function generateOdt($params) $multipledatas->setVars('datas_title', mb_strtoupper(__('data', 'mreporting')), ENT_NOQUOTES, 'utf-8'); foreach ($datas as $key => $value) { + $multipledatas->subtitle->datas_subtitle(mb_strtoupper($key), ENT_NOQUOTES, 'utf-8'); + $multipledatas->subtitle->merge(); + + foreach ($value as $col => $val) { + $multipledatas->datas->row($col, ENT_NOQUOTES, 'utf-8'); + $multipledatas->datas->value($val, ENT_NOQUOTES, 'utf-8'); + $multipledatas->datas->merge(); + } $multipledatas->merge(); } // Simples graph } else { $singledatas->setVars('datas_title', mb_strtoupper(__('data', 'mreporting')), ENT_NOQUOTES, 'utf-8'); + foreach ($datas as $key => $value) { + $singledatas->datas->row($key, ENT_NOQUOTES, 'utf-8'); + $singledatas->datas->value($value, ENT_NOQUOTES, 'utf-8'); + $singledatas->datas->merge(); + } $singledatas->merge(); } } @@ -1322,7 +1397,7 @@ public static function selectorAllSlasWithTicket() { /** * @var array $LANG - * @var DBmysql $DB + * @var \DBmysql $DB */ global $LANG, $DB; @@ -1781,7 +1856,7 @@ public static function getSelectorValuesByUser() $myvalues = (isset($_SESSION['mreporting_values']) ? $_SESSION['mreporting_values'] : []); $selectors = PluginMreportingPreference::checkPreferenceValue('selectors', Session::getLoginUserID()); if ($selectors) { - $values = json_decode(stripslashes((string)$selectors), true); + $values = json_decode(stripslashes($selectors), true); if (isset($_REQUEST['f_name']) && isset($values[$_REQUEST['f_name']])) { foreach ($values[$_REQUEST['f_name']] as $key => $value) { $myvalues[$key] = $value; @@ -1809,7 +1884,7 @@ public static function resetSelectorsForReport($report_name) $selectors = PluginMreportingPreference::checkPreferenceValue('selectors', $users_id); if ($selectors) { - $values = json_decode(stripslashes((string)$selectors), true); + $values = json_decode(stripslashes($selectors), true); if (isset($values[$report_name])) { unset($values[$report_name]); } @@ -1840,10 +1915,10 @@ public static function getSQLDate($field = '`glpi_tickets`.`date`', $delay = 365 } $date_array1 = explode('-', $_SESSION['mreporting_values']['date1' . $randname]); - $time1 = mktime(0, 0, 0, (int)$date_array1[1], (int)$date_array1[2], (int)$date_array1[0]); + $time1 = mktime(0, 0, 0, $date_array1[1], $date_array1[2], $date_array1[0]); $date_array2 = explode('-', $_SESSION['mreporting_values']['date2' . $randname]); - $time2 = mktime(0, 0, 0, (int)$date_array2[1], (int)$date_array2[2], (int)$date_array2[0]); + $time2 = mktime(0, 0, 0, $date_array2[1], $date_array2[2], $date_array2[0]); //if data inverted, reverse it if ($time1 > $time2) { @@ -1863,13 +1938,17 @@ public static function getSQLDate($field = '`glpi_tickets`.`date`', $delay = 365 /** * Get the max value of a multidimensionnal array - * @param array $array the array to compute + * @param array|int $array the array to compute * @return number the sum */ public static function getArrayMaxValue($array) { $max = 0; + if (!is_array($array)) { + return $array; + } + foreach ($array as $value) { if (is_array($value)) { $sub_max = self::getArrayMaxValue($value); @@ -1888,13 +1967,17 @@ public static function getArrayMaxValue($array) /** * Computes the sum of a multidimensionnal array - * @param array $array the array where to seek + * @param array|int $array the array where to seek * @return number the sum */ public static function getArraySum($array) { $sum = 0; + if (!is_array($array)) { + return $array; + } + foreach ($array as $value) { if (is_array($value)) { $sum += self::getArraySum($value); @@ -1908,7 +1991,7 @@ public static function getArraySum($array) /** * Get the depth of a multidimensionnal array - * @param array $array the array where to seek + * @param array() $array the array where to seek * @return number the sum */ public static function getArrayDepth($array) @@ -1944,7 +2027,6 @@ public static function buildTree($flat_array) /** * Transform a flat array to a tree array (without keys changes) * @param array $elements the flat array. Format : array('id', 'parent', 'name', 'count') - * @param integer $parentId * @return array the tree array. Format : array(orginal_keys, children => array(...) */ public static function mapTree(array &$elements, $parentId = 0) diff --git a/inc/graphpng.class.php b/inc/graphpng.class.php index c6d43894..ac326db2 100644 --- a/inc/graphpng.class.php +++ b/inc/graphpng.class.php @@ -156,57 +156,57 @@ public function showImage($contents, $export = 'png') public function generateImage($params) { // Default values of parameters - $image = ''; - $export = 'png'; - $f_name = ''; - $class = ''; - $title = ''; - $unit = ''; - $raw_datas = []; - $withdata = 0; - - foreach ($params as $key => $val) { - $$key = $val; - } + $default_params = [ + 'image' => '', + 'export' => 'png', + 'f_name' => '', + 'class' => '', + 'title' => '', + 'unit' => '', + 'raw_datas' => [], + 'withdata' => 0, + ]; + + $params = array_merge($default_params, $params); ob_start(); - if ($export == 'odt') { - $show_graph = PluginMreportingConfig::showGraphConfigValue($f_name, $class); + if ($params['export'] == 'odt') { + $show_graph = PluginMreportingConfig::showGraphConfigValue($params['f_name'], $params['class']); if ($show_graph) { - $path = GLPI_PLUGIN_DOC_DIR . '/mreporting/' . $f_name . '.png'; - imagepng($image, $path); + $path = GLPI_PLUGIN_DOC_DIR . '/mreporting/' . $params['f_name'] . '.png'; + imagepng($params['image'], $path); } $common = new PluginMreportingCommon(); - $options[] = ['title' => $title, - 'f_name' => $f_name, - 'class' => $class, - 'randname' => $randname, - 'raw_datas' => $raw_datas, - 'withdata' => $withdata, + $options[] = ['title' => $params['title'], + 'f_name' => $params['f_name'], + 'class' => $params['class'], + 'randname' => $params['randname'], + 'raw_datas' => $params['raw_datas'], + 'withdata' => $params['withdata'], ]; $common->generateOdt($options); return true; - } elseif ($export == 'odtall') { - $show_graph = PluginMreportingConfig::showGraphConfigValue($f_name, $class); + } elseif ($params['export'] == 'odtall') { + $show_graph = PluginMreportingConfig::showGraphConfigValue($params['f_name'], $params['class']); if ($show_graph) { - $path = GLPI_PLUGIN_DOC_DIR . '/mreporting/' . $f_name . '.png'; - imagepng($image, $path); - } - if (isset($raw_datas['datas'])) { - $_SESSION['glpi_plugin_mreporting_odtarray'][] = ['title' => $title, - 'f_name' => $f_name, - 'class' => $class, - 'randname' => $randname, - 'raw_datas' => $raw_datas, - 'withdata' => $withdata, + $path = GLPI_PLUGIN_DOC_DIR . '/mreporting/' . $params['f_name'] . '.png'; + imagepng($params['image'], $path); + } + if (isset($params['raw_datas']['datas'])) { + $_SESSION['glpi_plugin_mreporting_odtarray'][] = ['title' => $params['title'], + 'f_name' => $params['f_name'], + 'class' => $params['class'], + 'randname' => $params['randname'], + 'raw_datas' => $params['raw_datas'], + 'withdata' => $params['withdata'], ]; } return true; } else { - imagepng($image); + imagepng($params['image']); $contents = ob_get_contents(); ob_end_clean(); @@ -415,8 +415,8 @@ public function imageSmoothAlphaLine($image, $x1, $y1, $x2, $y2, $dcol) imagecolorallocatealpha( $image, round($tcr * $ya + $icr * $yb), - ($tcg * $ya + $icg * $yb), - ($tcb * $ya + $icb * $yb), + (int) ($tcg * $ya + $icg * $yb), + (int) ($tcb * $ya + $icb * $yb), hexdec($alpha), ), ); @@ -495,7 +495,7 @@ public function imageSmoothAlphaLine($image, $x1, $y1, $x2, $y2, $dcol) public function imageSmoothAlphaLineLarge($image, $x1, $y1, $x2, $y2, $color) { - imageline($image, $x1, $y1, $x2, $y2, hexdec($color)); + imageline($image, (int) $x1, (int) $y1, (int) $x2, (int) $y2, hexdec($color)); $this->imageSmoothAlphaLine($image, $x1 - 1, $y1 - 1, $x2 - 1, $y2 - 1, $color); $this->imageSmoothAlphaLine($image, $x1 + 1, $y1 + 1, $x2 + 1, $y2 + 1, $color); $this->imageSmoothAlphaLine($image, $x1, $y1 + 1, $x2, $y2 + 1, $color); @@ -2008,7 +2008,7 @@ public function showArea($params, $dashboard = false, $width = false) $yaxis = $height - 30 - $xstep * $i; //grey lines - imageLine($image, 30, $yaxis, 30 + $width_line * ($nb - 1), $yaxis, hexdec($this->grey)); + imageLine($image, 30, (int) $yaxis, 30 + (int) $width_line * ($nb - 1), (int) $yaxis, hexdec($this->grey)); //value labels $val = round($i * $max / 12); @@ -2029,7 +2029,7 @@ public function showArea($params, $dashboard = false, $width = false) //draw y-axis grey step line for ($i = 0; $i < $nb; $i++) { $xaxis = 30 + $width_line * $i; - imageLine($image, $xaxis, 50, $xaxis, $height - 25, hexdec($this->grey)); + imageLine($image, (int) $xaxis, 50, (int) $xaxis, $height - 25, hexdec($this->grey)); } //draw y-axis From e0a2e7fb432c04c90494ca543ce07a2c80ccf981 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Wed, 2 Apr 2025 16:31:27 +0200 Subject: [PATCH 05/24] phpstan5 --- inc/common.class.php | 39 ++++--- inc/config.class.php | 17 ++- inc/graph.class.php | 203 +++++++++++++++++++++-------------- inc/graphcsv.class.php | 70 ++++++------ inc/graphpng.class.php | 237 +++++++++++++++++++++++++---------------- phpstan.neon | 1 + setup.php | 2 +- 7 files changed, 349 insertions(+), 220 deletions(-) diff --git a/inc/common.class.php b/inc/common.class.php index 0331d63b..260589e1 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -574,22 +574,33 @@ public function initParams($params, $export = false) } /** - * init Params for graph function + * Initialize parameters for the graph function. * - * @params - */ - public static function initGraphParams($params) + * @param array $params Input parameters that override default values. + * + * @return array{ + * raw_datas: array, + * title: string, + * desc: string, + * root: string, + * export: bool, + * opt: array + * } + */ + public static function initGraphParams(array $params): array { - $crit = []; - // Default values of parameters - $raw_datas = []; - $title = ''; - $desc = ''; - $root = ''; - - $export = false; - $opt = []; + $crit = [ + 'raw_datas' => [], + 'title' => '', + 'desc' => '', + 'root' => '', + 'export' => false, + 'opt' => [ + 'f_name' => '', + 'class' => '', + ], + ]; foreach ($params as $key => $val) { $crit[$key] = $val; @@ -835,6 +846,8 @@ public static function endGraph($options, $dashboard = false) * @param $datas, ex : array( 'test1' => 15, 'test2' => 25) * @param $unit, ex : '%', 'Kg' (optionnal) * @if percent, return new datas + * + * @return array */ public static function compileDatasForUnit($values, $unit = '') { diff --git a/inc/config.class.php b/inc/config.class.php index ef503c09..131e469d 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -820,7 +820,20 @@ public function showForm($ID, $options = []) * * @param $name of graph * @param $classname of graph - **/ + * + * @return array{ + * area: bool, + * spline: bool, + * flip_data: bool, + * unit: string, + * show_label: string, + * delay: string, + * condition: string, + * show_graph: bool, + * randname: int, + * graphtype: string + * } + **/ public static function initConfigParams($name, $classname) { $crit = ['area' => false, @@ -851,7 +864,7 @@ public static function initConfigParams($name, $classname) /* @phpstan-ignore-next-line */ if (DEBUG_MREPORTING) { - $crit['show_graph'] = 1; + $crit['show_graph'] = true; } return $crit; diff --git a/inc/graph.class.php b/inc/graph.class.php index 61b1b4dd..97789295 100644 --- a/inc/graph.class.php +++ b/inc/graph.class.php @@ -128,29 +128,30 @@ public function initGraph($options) * @param $show_label : behavior of the graph labels, * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) - * @return void + * @return void|bool */ public function showHbar($params, $dashboard = false, $width = false) { - $opt = [ - 'f_name' => '', - 'class' => '', - ]; - ob_start(); if ($width !== false) { $this->width = $width; } - $criterias = PluginMreportingCommon::initGraphParams($params); - foreach ($criterias as $key => $val) { - $$key = $val; - } + [ + 'raw_datas' => $raw_datas, + 'title' => $title, + 'desc' => $desc, + 'export' => $export, + 'opt' => $opt + ] = PluginMreportingCommon::initGraphParams($params); - $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); - foreach ($configs as $k => $v) { - $$k = $v; - } + [ + 'unit' => $unit, + 'show_label' => $show_label, + 'delay' => $delay, + 'show_graph' => $show_graph, + 'randname' => $randname, + ] = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); $options = ['title' => $title, 'desc' => $desc, @@ -333,7 +334,7 @@ public function showHbar($params, $dashboard = false, $width = false) * @param $show_label : behavior of the graph labels, * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) - * @return void + * @return void|bool */ public function showPie($params, $dashboard = false, $width = false) { @@ -342,17 +343,21 @@ public function showPie($params, $dashboard = false, $width = false) $this->width = $width; } - $criterias = PluginMreportingCommon::initGraphParams($params); + [ + 'raw_datas' => $raw_datas, + 'title' => $title, + 'desc' => $desc, + 'export' => $export, + 'opt' => $opt + ] = PluginMreportingCommon::initGraphParams($params); - foreach ($criterias as $key => $val) { - $$key = $val; - } - - $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); - - foreach ($configs as $k => $v) { - $$k = $v; - } + [ + 'unit' => $unit, + 'show_label' => $show_label, + 'delay' => $delay, + 'show_graph' => $show_graph, + 'randname' => $randname, + ] = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); $options = ['title' => $title, 'desc' => $desc, @@ -529,7 +534,7 @@ public function showPie($params, $dashboard = false, $width = false) * @param $show_label : behavior of the graph labels, * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) - * @return void + * @return void|bool */ public function showSunburst($params, $dashboard = false, $width = false) { @@ -537,17 +542,23 @@ public function showSunburst($params, $dashboard = false, $width = false) if ($width !== false) { $this->width = $width; } - $criterias = PluginMreportingCommon::initGraphParams($params); - - foreach ($criterias as $key => $val) { - $$key = $val; - } - $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); + [ + 'raw_datas' => $raw_datas, + 'title' => $title, + 'desc' => $desc, + 'export' => $export, + 'opt' => $opt + ] = PluginMreportingCommon::initGraphParams($params); - foreach ($configs as $k => $v) { - $$k = $v; - } + [ + 'flip_data' => $flip_data, + 'unit' => $unit, + 'show_label' => $show_label, + 'delay' => $delay, + 'show_graph' => $show_graph, + 'randname' => $randname, + ] = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); $options = ['title' => $title, 'desc' => $desc, @@ -800,24 +811,31 @@ function getLevelNbNode(node) { * @param $show_label : behavior of the graph labels, * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) - * @return void + * @return void|bool */ public function showHgbar($params, $dashboard = false, $width = false) { - $criterias = PluginMreportingCommon::initGraphParams($params); ob_start(); if ($width !== false) { $this->width = $width; } - foreach ($criterias as $key => $val) { - $$key = $val; - } - $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); + [ + 'raw_datas' => $raw_datas, + 'title' => $title, + 'desc' => $desc, + 'export' => $export, + 'opt' => $opt + ] = PluginMreportingCommon::initGraphParams($params); - foreach ($configs as $k => $v) { - $$k = $v; - } + [ + 'flip_data' => $flip_data, + 'unit' => $unit, + 'show_label' => $show_label, + 'delay' => $delay, + 'show_graph' => $show_graph, + 'randname' => $randname, + ] = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); $options = ['title' => $title, 'desc' => $desc, @@ -1022,7 +1040,7 @@ public function showHgbar($params, $dashboard = false, $width = false) * @param $show_label : behavior of the graph labels, * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) - * @return void + * @return void|bool */ public function showVstackbar($params, $dashboard = false, $width = false) { @@ -1030,17 +1048,23 @@ public function showVstackbar($params, $dashboard = false, $width = false) if ($width !== false) { $this->width = $width; } - $criterias = PluginMreportingCommon::initGraphParams($params); - foreach ($criterias as $key => $val) { - $$key = $val; - } - - $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); + [ + 'raw_datas' => $raw_datas, + 'title' => $title, + 'desc' => $desc, + 'export' => $export, + 'opt' => $opt + ] = PluginMreportingCommon::initGraphParams($params); - foreach ($configs as $k => $v) { - $$k = $v; - } + [ + 'flip_data' => $flip_data, + 'unit' => $unit, + 'show_label' => $show_label, + 'delay' => $delay, + 'show_graph' => $show_graph, + 'randname' => $randname, + ] = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); $options = ['title' => $title, 'desc' => $desc, @@ -1250,7 +1274,7 @@ public function showVstackbar($params, $dashboard = false, $width = false) * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) * @param $area : show plain chart instead only a line (optionnal) - * @return void + * @return void|bool */ public function showArea($params, $dashboard = false, $width = false) { @@ -1259,17 +1283,23 @@ public function showArea($params, $dashboard = false, $width = false) $this->width = $width; } - $criterias = PluginMreportingCommon::initGraphParams($params); - - foreach ($criterias as $key => $val) { - $$key = $val; - } - - $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); - - foreach ($configs as $k => $v) { - $$k = $v; - } + [ + 'raw_datas' => $raw_datas, + 'title' => $title, + 'desc' => $desc, + 'export' => $export, + 'opt' => $opt + ] = PluginMreportingCommon::initGraphParams($params); + + [ + 'area' => $area, + 'spline' => $spline, + 'unit' => $unit, + 'show_label' => $show_label, + 'delay' => $delay, + 'show_graph' => $show_graph, + 'randname' => $randname, + ] = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); $area = true; if (isset($params['area'])) { @@ -1479,7 +1509,7 @@ public function showArea($params, $dashboard = false, $width = false) * @param $show_label : behavior of the graph labels, * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) - * @return void + * @return void|bool|null */ public function showLine($params, $dashboard = false, $width = false) { @@ -1503,7 +1533,7 @@ public function showLine($params, $dashboard = false, $width = false) * @param $show_label : behavior of the graph labels, * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) - * @return void + * @return void|bool */ public function showGarea($params, $dashboard = false, $width = false) { @@ -1511,16 +1541,26 @@ public function showGarea($params, $dashboard = false, $width = false) if ($width !== false) { $this->width = $width; } - $criterias = PluginMreportingCommon::initGraphParams($params); - - foreach ($criterias as $key => $val) { - $$key = $val; - } - $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); - foreach ($configs as $k => $v) { - $$k = $v; - } + [ + 'raw_datas' => $raw_datas, + 'title' => $title, + 'desc' => $desc, + 'root' => $root, + 'export' => $export, + 'opt' => $opt + ] = PluginMreportingCommon::initGraphParams($params); + + [ + 'area' => $area, + 'spline' => $spline, + 'flip_data' => $flip_data, + 'unit' => $unit, + 'show_label' => $show_label, + 'delay' => $delay, + 'show_graph' => $show_graph, + 'randname' => $randname, + ] = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); $options = ['title' => $title, 'desc' => $desc, @@ -1747,7 +1787,7 @@ public function showGarea($params, $dashboard = false, $width = false) * @param $show_label : behavior of the graph labels, * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) - * @return void + * @return void|bool|null */ public function showGline($params, $dashboard = false, $width = false) { @@ -1764,7 +1804,8 @@ public function showGline($params, $dashboard = false, $width = false) * * @param $datas, ex : array( 'test1' => 15, 'test2' => 25) * @param $unit, ex : '%', 'Kg' (optionnal) - * @return void + * + * @return array */ public function initDatasSimple($datas, $unit = '', $links = []) { @@ -1816,7 +1857,7 @@ public function initDatasSimple($datas, $unit = '', $links = []) * @param $labels2 * @param $unit, ex : '%', 'Kg' (optionnal) * @param $stacked : if stacked graph, option to compile the max value - * @return void + * @return array */ public function initDatasMultiple($datas, $labels2, $unit = '', $stacked = false) { @@ -1902,7 +1943,7 @@ public function initDatasMultiple($datas, $labels2, $unit = '', $stacked = false * 'key2' => array('key2.1' => val, 'key2.2' => val, 'key2.3' => val) * ) * @param $unit, ex : '%', 'Kg' (optionnal) - * @return void + * @return array */ public function initDatasTree($datas, $unit = '') { diff --git a/inc/graphcsv.class.php b/inc/graphcsv.class.php index a19866af..1c97922e 100644 --- a/inc/graphcsv.class.php +++ b/inc/graphcsv.class.php @@ -34,6 +34,7 @@ class PluginMreportingGraphcsv extends PluginMreportingGraph public function initGraph($options) { + /* @phpstan-ignore-next-line */ if (!self::DEBUG_CSV) { header('Content-type: application/csv'); header('Content-Disposition: inline; filename=export.csv'); @@ -45,12 +46,16 @@ public function showHbar($params, $dashboard = false, $width = false) /** @var array $CFG_GLPI */ global $CFG_GLPI; - $criterias = PluginMreportingCommon::initGraphParams($params); - foreach ($criterias as $key => $val) { - $$key = $val; - } + [ + 'raw_datas' => $raw_datas, + 'title' => $title, + 'desc' => $desc, + 'export' => $export, + 'opt' => $opt + ] = PluginMreportingCommon::initGraphParams($params); // Write in Log + /* @phpstan-ignore-next-line */ if (self::DEBUG_CSV && isset($raw_datas)) { Toolbox::logdebug($raw_datas); } @@ -61,11 +66,10 @@ public function showHbar($params, $dashboard = false, $width = false) return false; } - $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); - - foreach ($configs as $k => $v) { - $$k = $v; - } + [ + 'unit' => $unit, + 'randname' => $randname, + ] = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); if ($unit == '%') { $datas = PluginMreportingCommon::compileDatasForUnit($datas, $unit); @@ -108,13 +112,16 @@ public function showHgbar($params, $dashboard = false, $width = false) /** @var array $CFG_GLPI */ global $CFG_GLPI; - $criterias = PluginMreportingCommon::initGraphParams($params); - - foreach ($criterias as $key => $val) { - $$key = $val; - } + [ + 'raw_datas' => $raw_datas, + 'title' => $title, + 'desc' => $desc, + 'export' => $export, + 'opt' => $opt + ] = PluginMreportingCommon::initGraphParams($params); // Write in log + /* @phpstan-ignore-next-line */ if (self::DEBUG_CSV && isset($raw_datas)) { Toolbox::logdebug($raw_datas); } @@ -125,11 +132,10 @@ public function showHgbar($params, $dashboard = false, $width = false) return false; } - $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); - - foreach ($configs as $k => $v) { - $$k = $v; - } + [ + 'unit' => $unit, + 'randname' => $randname, + ] = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); if ($unit == '%') { $datas = PluginMreportingCommon::compileDatasForUnit($datas, $unit); @@ -191,12 +197,15 @@ public function showGarea($params, $dashboard = false, $width = false) public function showSunburst($params, $dashboard = false, $width = false) { - $criterias = PluginMreportingCommon::initGraphParams($params); - - foreach ($criterias as $key => $val) { - $$key = $val; - } - + [ + 'raw_datas' => $raw_datas, + 'title' => $title, + 'desc' => $desc, + 'export' => $export, + 'opt' => $opt + ] = PluginMreportingCommon::initGraphParams($params); + + /* @phpstan-ignore-next-line */ if (self::DEBUG_CSV && isset($raw_datas)) { Toolbox::logdebug($raw_datas); } @@ -211,11 +220,10 @@ public function showSunburst($params, $dashboard = false, $width = false) return false; } - $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); - - foreach ($configs as $k => $v) { - $$k = $v; - } + [ + 'unit' => $unit, + 'randname' => $randname, + ] = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); if ($unit == '%') { $datas = PluginMreportingCommon::compileDatasForUnit($datas, $unit); @@ -237,6 +245,8 @@ public function showSunburst($params, $dashboard = false, $width = false) public function sunburstLevel($datas, $level = 0) { + /** @var array $CFG_GLPI */ + global $CFG_GLPI; $out = ''; $i = 0; diff --git a/inc/graphpng.class.php b/inc/graphpng.class.php index ac326db2..558c2e0f 100644 --- a/inc/graphpng.class.php +++ b/inc/graphpng.class.php @@ -357,12 +357,12 @@ public static function lighter($color, $factor = 50) * function imageSmoothAlphaLine() - version 1.0 * Draws a smooth line with alpha-functionality * - * @param image the image to draw on - * @param integer x1 - * @param integer y1 - * @param integer x2 - * @param integer y2 - * @param color color created by imagecolorallocatealpha + * @param mixed $image the image to draw on + * @param integer $x1 + * @param integer $y1 + * @param integer $x2 + * @param integer $y2 + * @param string $dcol created by imagecolorallocatealpha * * @access public * @@ -508,9 +508,9 @@ public function imageSmoothAlphaLineLarge($image, $x1, $y1, $x2, $y2, $color) * function imageCubicSmoothLine() - * Draws a smooth line * - * @param image the image to draw on - * @param color color created by imagecolorallocatealpha - * @param coords array with points coordinates (x1 => y1, x2 => y2, etc) + * @param mixed $image the image to draw on + * @param string $color created by imagecolorallocatealpha + * @param array $coords array with points coordinates (x1 => y1, x2 => y2, etc) * */ public function imageCubicSmoothLine($image, $color, $coords) @@ -556,7 +556,7 @@ public function imageCubicSmoothLine($image, $color, $coords) * @param $show_label : behavior of the graph labels, * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) - * @return void + * @return void|bool */ public function showHbar($params, $dashboard = false, $width = false) { @@ -564,20 +564,25 @@ public function showHbar($params, $dashboard = false, $width = false) $this->width = $width + 50; } - $criterias = PluginMreportingCommon::initGraphParams($params); - - foreach ($criterias as $key => $val) { - $$key = $val; - } + [ + 'raw_datas' => $raw_datas, + 'title' => $title, + 'desc' => $desc, + 'export' => $export, + 'opt' => $opt + ] = PluginMreportingCommon::initGraphParams($params); //$rand = $opt['rand']; - $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); - - foreach ($configs as $k => $v) { - $$k = $v; - } + [ + 'unit' => $unit, + 'show_label' => $show_label, + 'delay' => $delay, + 'show_graph' => $show_graph, + 'randname' => $randname, + ] = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); + /* @phpstan-ignore-next-line */ if (self::DEBUG_GRAPH && isset($raw_datas)) { Toolbox::logdebug($raw_datas); } @@ -754,26 +759,31 @@ public function showHbar($params, $dashboard = false, $width = false) * @param $show_label : behavior of the graph labels, * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) - * @return void + * @return void|bool */ public function showPie($params, $dashboard = false, $width = false) { - $criterias = PluginMreportingCommon::initGraphParams($params); - - foreach ($criterias as $key => $val) { - $$key = $val; - } + [ + 'raw_datas' => $raw_datas, + 'title' => $title, + 'desc' => $desc, + 'export' => $export, + 'opt' => $opt + ] = PluginMreportingCommon::initGraphParams($params); if ($width !== false) { $this->width = $width; } - $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); - - foreach ($configs as $k => $v) { - $$k = $v; - } + [ + 'unit' => $unit, + 'show_label' => $show_label, + 'delay' => $delay, + 'show_graph' => $show_graph, + 'randname' => $randname, + ] = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); + /* @phpstan-ignore-next-line */ if (self::DEBUG_GRAPH && isset($raw_datas)) { Toolbox::logdebug($raw_datas); } @@ -996,19 +1006,27 @@ public function showPie($params, $dashboard = false, $width = false) * @param $show_label : behavior of the graph labels, * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) - * @return void + * @return void|bool */ public function showSunburst($params, $dashboard = false, $width = false) { - $criterias = PluginMreportingCommon::initGraphParams($params); - foreach ($criterias as $key => $val) { - $$key = $val; - } - $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); - foreach ($configs as $k => $v) { - $$k = $v; - } - + [ + 'raw_datas' => $raw_datas, + 'title' => $title, + 'desc' => $desc, + 'export' => $export, + 'opt' => $opt + ] = PluginMreportingCommon::initGraphParams($params); + + [ + 'flip_data' => $flip_data, + 'unit' => $unit, + 'delay' => $delay, + 'show_graph' => $show_graph, + 'randname' => $randname, + ] = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); + + /* @phpstan-ignore-next-line */ if (self::DEBUG_GRAPH && isset($raw_datas)) { Toolbox::logdebug($raw_datas); } @@ -1153,13 +1171,13 @@ public function drawSunburstLevel($image, $datas, $params = []) $darkerpalette = self::getDarkerPalette(50); foreach ($datas as $key => $data) { + $sum = PluginMreportingCommon::getArraySum($data); if (is_array($data)) { arsort($data); $params2 = []; $params2 = $params; - $sum = PluginMreportingCommon::getArraySum($data); $angle = ($params['max_angle'] * $sum) / $gsum; $params2['max_angle'] = $angle; @@ -1324,7 +1342,7 @@ public function drawSunburstLevel($image, $datas, $params = []) * @param $show_label : behavior of the graph labels, * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) - * @return void + * @return void|bool */ public function showHgbar($params, $dashboard = false, $width = false) { @@ -1332,20 +1350,26 @@ public function showHgbar($params, $dashboard = false, $width = false) $this->width = $width; } - $criterias = PluginMreportingCommon::initGraphParams($params); - - foreach ($criterias as $key => $val) { - $$key = $val; - } + [ + 'raw_datas' => $raw_datas, + 'title' => $title, + 'desc' => $desc, + 'export' => $export, + 'opt' => $opt + ] = PluginMreportingCommon::initGraphParams($params); //$rand = $opt['rand']; - $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); - - foreach ($configs as $k => $v) { - $$k = $v; - } + [ + 'flip_data' => $flip_data, + 'unit' => $unit, + 'show_label' => $show_label, + 'delay' => $delay, + 'show_graph' => $show_graph, + 'randname' => $randname, + ] = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); + /* @phpstan-ignore-next-line */ if (self::DEBUG_GRAPH && isset($raw_datas)) { Toolbox::logdebug($raw_datas); } @@ -1572,7 +1596,7 @@ public function showHgbar($params, $dashboard = false, $width = false) * @param $show_label : behavior of the graph labels, * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) - * @return void + * @return void|bool */ public function showVstackbar($params, $dashboard = false, $width = false) { @@ -1580,20 +1604,26 @@ public function showVstackbar($params, $dashboard = false, $width = false) $this->width = $width; } - $criterias = PluginMreportingCommon::initGraphParams($params); - - foreach ($criterias as $key => $val) { - $$key = $val; - } + [ + 'raw_datas' => $raw_datas, + 'title' => $title, + 'desc' => $desc, + 'export' => $export, + 'opt' => $opt + ] = PluginMreportingCommon::initGraphParams($params); //$rand = $opt['rand']; - $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); - - foreach ($configs as $k => $v) { - $$k = $v; - } + [ + 'flip_data' => $flip_data, + 'unit' => $unit, + 'show_label' => $show_label, + 'delay' => $delay, + 'show_graph' => $show_graph, + 'randname' => $randname, + ] = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); + /* @phpstan-ignore-next-line */ if (self::DEBUG_GRAPH && isset($raw_datas)) { Toolbox::logdebug($raw_datas); } @@ -1688,6 +1718,7 @@ public function showVstackbar($params, $dashboard = false, $width = false) //longueur du texte en dessous des barres $index = 0; + $textwidth = []; foreach ($labels2 as $label) { $lx = 55 + $index * $width_bar; $box = @imageTTFBbox($this->fontsize - 1, $this->fontangle, $this->font, $label); @@ -1910,7 +1941,7 @@ public function showVstackbar($params, $dashboard = false, $width = false) * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) * @param $area : show plain chart instead only a line (optionnal) - * @return void + * @return void|bool */ public function showArea($params, $dashboard = false, $width = false) { @@ -1918,20 +1949,27 @@ public function showArea($params, $dashboard = false, $width = false) $this->width = $width; } - $criterias = PluginMreportingCommon::initGraphParams($params); - - foreach ($criterias as $key => $val) { - $$key = $val; - } + [ + 'raw_datas' => $raw_datas, + 'title' => $title, + 'desc' => $desc, + 'export' => $export, + 'opt' => $opt + ] = PluginMreportingCommon::initGraphParams($params); //$rand = $opt['rand']; - $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); - - foreach ($configs as $k => $v) { - $$k = $v; - } - + [ + 'area' => $area, + 'spline' => $spline, + 'unit' => $unit, + 'show_label' => $show_label, + 'delay' => $delay, + 'show_graph' => $show_graph, + 'randname' => $randname, + ] = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); + + /* @phpstan-ignore-next-line */ if (self::DEBUG_GRAPH && isset($raw_datas)) { Toolbox::logdebug($raw_datas); } @@ -2066,6 +2104,7 @@ public function showArea($params, $dashboard = false, $width = false) $index = 0; $old_data = 0; $aCoords = []; + foreach ($datas as $label => $data) { //if first index, continue if ($index == 0) { @@ -2074,6 +2113,10 @@ public function showArea($params, $dashboard = false, $width = false) continue; } + //defaults values + $x2 = 0; + $y2 = 0; + // determine coords $x1 = $index * $width_line - $width_line + 30; $y1 = $height - 30 - $old_data * ($height - 85) / $max; @@ -2102,7 +2145,7 @@ public function showArea($params, $dashboard = false, $width = false) } //if curved spline activated, draw cubic spline for the current line - if ($spline) { + if ($spline && isset($x2) && isset($y2)) { $aCoords[$x2] = $y2; $this->imageCubicSmoothLine($image, $palette[0], $aCoords); } @@ -2166,7 +2209,7 @@ public function showArea($params, $dashboard = false, $width = false) } //display last value, dot and axis label - if (isset($x2)) { + if (isset($x2) && isset($y2) && isset($data)) { imagettftext( $image, $this->fontsize - 1, @@ -2188,7 +2231,7 @@ public function showArea($params, $dashboard = false, $width = false) $height - 10, hexdec($this->black), $this->font, - $label, + isset($label) ? $label : '', ); imageline($image, $x2, $height - 30, $x2, $height - 27, hexdec($darkerpalette[0])); } @@ -2228,7 +2271,7 @@ public function showArea($params, $dashboard = false, $width = false) * @param $show_label : behavior of the graph labels, * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) - * @return void + * @return void|bool */ public function showGArea($params, $dashboard = false, $width = false) { @@ -2236,20 +2279,28 @@ public function showGArea($params, $dashboard = false, $width = false) $this->width = $width; } - $criterias = PluginMreportingCommon::initGraphParams($params); - - foreach ($criterias as $key => $val) { - $$key = $val; - } + [ + 'raw_datas' => $raw_datas, + 'title' => $title, + 'desc' => $desc, + 'export' => $export, + 'opt' => $opt + ] = PluginMreportingCommon::initGraphParams($params); //$rand = $opt['rand']; - $configs = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); - - foreach ($configs as $k => $v) { - $$k = $v; - } - + [ + 'area' => $area, + 'spline' => $spline, + 'flip_data' => $flip_data, + 'unit' => $unit, + 'show_label' => $show_label, + 'delay' => $delay, + 'show_graph' => $show_graph, + 'randname' => $randname, + ] = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); + + /* @phpstan-ignore-next-line */ if (self::DEBUG_GRAPH && isset($raw_datas)) { Toolbox::logdebug($raw_datas); } @@ -2480,13 +2531,13 @@ public function showGArea($params, $dashboard = false, $width = false) } //if curved spline activated, draw cubic spline for the current line - if ($spline) { + if ($spline && isset($x2) && isset($y2)) { $aCoords[$x2] = $y2; $this->imageCubicSmoothLine($image, $palette[$index1], $aCoords); } // display last value - if (isset($x2)) { + if (isset($x2) && isset($y2)) { //trace dots $color_rbg = self::colorHexToRGB($darkerpalette[$index1]); imageSmoothArc($image, $x2 - 1, $y2 - 1, 7, 7, $color_rbg, 0, 2 * M_PI); diff --git a/phpstan.neon b/phpstan.neon index cda32ecf..804efb06 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -13,6 +13,7 @@ parameters: scanDirectories: - ../../inc - ../../src + - ./lib stubFiles: - ../../stubs/glpi_constants.php rules: diff --git a/setup.php b/setup.php index be88378d..588ba52e 100644 --- a/setup.php +++ b/setup.php @@ -31,7 +31,7 @@ define('PLUGIN_MREPORTING_VERSION', '1.8.7'); // Minimal GLPI version, inclusive -define('PLUGIN_MREPORTING_MIN_GLPI', '10.0.0'); +define('PLUGIN_MREPORTING_MIN_GLPI', '10.0.11'); // Maximum GLPI version, exclusive define('PLUGIN_MREPORTING_MAX_GLPI', '10.0.99'); From 345d5e831b2f8574fa41612c6a4dde2e76ace459 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Wed, 2 Apr 2025 16:49:42 +0200 Subject: [PATCH 06/24] phpstan5 --- inc/common.class.php | 2 +- inc/dashboard.class.php | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/inc/common.class.php b/inc/common.class.php index 260589e1..89d2a796 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -647,7 +647,7 @@ public function showGraph($opt, $export = false, $forceFormat = null) if (!isset($_SESSION['mreporting_values']['date1' . $config['randname']])) { $_SESSION['mreporting_values']['date1' . $config['randname']] = date( 'Y-m-d', - time() - ($config['delay'] * 24 * 60 * 60), + time() - ((intval($config['delay'])) * 24 * 60 * 60), ); } if (!isset($_SESSION['mreporting_values']['date2' . $config['randname']])) { diff --git a/inc/dashboard.class.php b/inc/dashboard.class.php index 5d0c2255..9665821a 100644 --- a/inc/dashboard.class.php +++ b/inc/dashboard.class.php @@ -299,14 +299,6 @@ public static function updateWidget($idreport) $short_classname = str_replace('PluginMreporting', '', $report->fields['classname']); - if (!empty($short_classname) && !empty($f_name)) { - if (isset($LANG['plugin_mreporting'][$short_classname][$f_name]['title'])) { - $opt = ['short_classname' => $short_classname , 'f_name' => $f_name , 'gtype' => $gtype]; - $dash = new PluginMreportingDashboard(); - $out = $dash->showGraphOnDashboard($opt); - } - } - echo $out; } From a5234f4809298cc057bed3ee77c922e3167925db Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Wed, 2 Apr 2025 16:51:16 +0200 Subject: [PATCH 07/24] php-cs-fixer --- inc/graph.class.php | 16 ++++++++-------- inc/graphcsv.class.php | 6 +++--- inc/graphpng.class.php | 14 +++++++------- inc/helpdeskplus.class.php | 2 +- inc/notificationevent.class.php | 2 +- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/inc/graph.class.php b/inc/graph.class.php index 97789295..f796f2a2 100644 --- a/inc/graph.class.php +++ b/inc/graph.class.php @@ -40,7 +40,7 @@ class PluginMreportingGraph */ public function initGraph($options) { - /** @var array $LANG */ + /** @var array $LANG */ global $LANG; $width = $this->width + 100; @@ -142,7 +142,7 @@ public function showHbar($params, $dashboard = false, $width = false) 'title' => $title, 'desc' => $desc, 'export' => $export, - 'opt' => $opt + 'opt' => $opt, ] = PluginMreportingCommon::initGraphParams($params); [ @@ -348,7 +348,7 @@ public function showPie($params, $dashboard = false, $width = false) 'title' => $title, 'desc' => $desc, 'export' => $export, - 'opt' => $opt + 'opt' => $opt, ] = PluginMreportingCommon::initGraphParams($params); [ @@ -548,7 +548,7 @@ public function showSunburst($params, $dashboard = false, $width = false) 'title' => $title, 'desc' => $desc, 'export' => $export, - 'opt' => $opt + 'opt' => $opt, ] = PluginMreportingCommon::initGraphParams($params); [ @@ -825,7 +825,7 @@ public function showHgbar($params, $dashboard = false, $width = false) 'title' => $title, 'desc' => $desc, 'export' => $export, - 'opt' => $opt + 'opt' => $opt, ] = PluginMreportingCommon::initGraphParams($params); [ @@ -1054,7 +1054,7 @@ public function showVstackbar($params, $dashboard = false, $width = false) 'title' => $title, 'desc' => $desc, 'export' => $export, - 'opt' => $opt + 'opt' => $opt, ] = PluginMreportingCommon::initGraphParams($params); [ @@ -1288,7 +1288,7 @@ public function showArea($params, $dashboard = false, $width = false) 'title' => $title, 'desc' => $desc, 'export' => $export, - 'opt' => $opt + 'opt' => $opt, ] = PluginMreportingCommon::initGraphParams($params); [ @@ -1548,7 +1548,7 @@ public function showGarea($params, $dashboard = false, $width = false) 'desc' => $desc, 'root' => $root, 'export' => $export, - 'opt' => $opt + 'opt' => $opt, ] = PluginMreportingCommon::initGraphParams($params); [ diff --git a/inc/graphcsv.class.php b/inc/graphcsv.class.php index 1c97922e..5a29ca40 100644 --- a/inc/graphcsv.class.php +++ b/inc/graphcsv.class.php @@ -51,7 +51,7 @@ public function showHbar($params, $dashboard = false, $width = false) 'title' => $title, 'desc' => $desc, 'export' => $export, - 'opt' => $opt + 'opt' => $opt, ] = PluginMreportingCommon::initGraphParams($params); // Write in Log @@ -117,7 +117,7 @@ public function showHgbar($params, $dashboard = false, $width = false) 'title' => $title, 'desc' => $desc, 'export' => $export, - 'opt' => $opt + 'opt' => $opt, ] = PluginMreportingCommon::initGraphParams($params); // Write in log @@ -202,7 +202,7 @@ public function showSunburst($params, $dashboard = false, $width = false) 'title' => $title, 'desc' => $desc, 'export' => $export, - 'opt' => $opt + 'opt' => $opt, ] = PluginMreportingCommon::initGraphParams($params); /* @phpstan-ignore-next-line */ diff --git a/inc/graphpng.class.php b/inc/graphpng.class.php index 558c2e0f..7510105e 100644 --- a/inc/graphpng.class.php +++ b/inc/graphpng.class.php @@ -569,7 +569,7 @@ public function showHbar($params, $dashboard = false, $width = false) 'title' => $title, 'desc' => $desc, 'export' => $export, - 'opt' => $opt + 'opt' => $opt, ] = PluginMreportingCommon::initGraphParams($params); //$rand = $opt['rand']; @@ -768,7 +768,7 @@ public function showPie($params, $dashboard = false, $width = false) 'title' => $title, 'desc' => $desc, 'export' => $export, - 'opt' => $opt + 'opt' => $opt, ] = PluginMreportingCommon::initGraphParams($params); if ($width !== false) { @@ -1015,7 +1015,7 @@ public function showSunburst($params, $dashboard = false, $width = false) 'title' => $title, 'desc' => $desc, 'export' => $export, - 'opt' => $opt + 'opt' => $opt, ] = PluginMreportingCommon::initGraphParams($params); [ @@ -1355,7 +1355,7 @@ public function showHgbar($params, $dashboard = false, $width = false) 'title' => $title, 'desc' => $desc, 'export' => $export, - 'opt' => $opt + 'opt' => $opt, ] = PluginMreportingCommon::initGraphParams($params); //$rand = $opt['rand']; @@ -1609,7 +1609,7 @@ public function showVstackbar($params, $dashboard = false, $width = false) 'title' => $title, 'desc' => $desc, 'export' => $export, - 'opt' => $opt + 'opt' => $opt, ] = PluginMreportingCommon::initGraphParams($params); //$rand = $opt['rand']; @@ -1954,7 +1954,7 @@ public function showArea($params, $dashboard = false, $width = false) 'title' => $title, 'desc' => $desc, 'export' => $export, - 'opt' => $opt + 'opt' => $opt, ] = PluginMreportingCommon::initGraphParams($params); //$rand = $opt['rand']; @@ -2284,7 +2284,7 @@ public function showGArea($params, $dashboard = false, $width = false) 'title' => $title, 'desc' => $desc, 'export' => $export, - 'opt' => $opt + 'opt' => $opt, ] = PluginMreportingCommon::initGraphParams($params); //$rand = $opt['rand']; diff --git a/inc/helpdeskplus.class.php b/inc/helpdeskplus.class.php index 15b6ac8d..34ffcdd2 100644 --- a/inc/helpdeskplus.class.php +++ b/inc/helpdeskplus.class.php @@ -1002,7 +1002,7 @@ public function reportVstackbarRespectedSlasByGroup($config = []) while ($data = $DB->fetchAssoc($result)) { $gp = new Group(); - $gp->getFromDB((int)$data['groups_id']); + $gp->getFromDB((int) $data['groups_id']); $datas['labels2'][$gp->fields['name']] = $gp->fields['name']; diff --git a/inc/notificationevent.class.php b/inc/notificationevent.class.php index ecccd36f..4142c11f 100644 --- a/inc/notificationevent.class.php +++ b/inc/notificationevent.class.php @@ -121,7 +121,7 @@ public static function raiseEvent($event, $item, $options = [], $label = '') PluginMreportingNotification::send( $template->getDataToSend( $notificationtarget, - (string)$tid, + (string) $tid, $users_infos[$eventClass::getTargetFieldName()], $users_infos, $options, From 5dba054d2be277ff580f9983d404e82a194fa0ba Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Thu, 3 Apr 2025 11:14:11 +0200 Subject: [PATCH 08/24] phpstan5 --- inc/common.class.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/inc/common.class.php b/inc/common.class.php index 89d2a796..6468cf75 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -1284,13 +1284,17 @@ public static function generateOdt($params) $multipledatas->setVars('datas_title', mb_strtoupper(__('data', 'mreporting')), ENT_NOQUOTES, 'utf-8'); foreach ($datas as $key => $value) { - $multipledatas->subtitle->datas_subtitle(mb_strtoupper($key), ENT_NOQUOTES, 'utf-8'); - $multipledatas->subtitle->merge(); + if (property_exists($multipledatas, 'subtitle') && $multipledatas->subtitle !== null) { + $multipledatas->subtitle->datas_subtitle(mb_strtoupper($key), ENT_NOQUOTES, 'utf-8'); + $multipledatas->subtitle->merge(); + } foreach ($value as $col => $val) { - $multipledatas->datas->row($col, ENT_NOQUOTES, 'utf-8'); - $multipledatas->datas->value($val, ENT_NOQUOTES, 'utf-8'); - $multipledatas->datas->merge(); + if (property_exists($multipledatas, 'datas') && $multipledatas->datas !== null) { + $multipledatas->datas->row($col, ENT_NOQUOTES, 'utf-8'); + $multipledatas->datas->value($val, ENT_NOQUOTES, 'utf-8'); + $multipledatas->datas->merge(); + } } $multipledatas->merge(); } @@ -1299,9 +1303,11 @@ public static function generateOdt($params) } else { $singledatas->setVars('datas_title', mb_strtoupper(__('data', 'mreporting')), ENT_NOQUOTES, 'utf-8'); foreach ($datas as $key => $value) { - $singledatas->datas->row($key, ENT_NOQUOTES, 'utf-8'); - $singledatas->datas->value($value, ENT_NOQUOTES, 'utf-8'); - $singledatas->datas->merge(); + if (property_exists($singledatas, 'datas') && $singledatas->datas !== null) { + $singledatas->datas->row($key, ENT_NOQUOTES, 'utf-8'); + $singledatas->datas->value($value, ENT_NOQUOTES, 'utf-8'); + $singledatas->datas->merge(); + } } $singledatas->merge(); } @@ -2004,7 +2010,7 @@ public static function getArraySum($array) /** * Get the depth of a multidimensionnal array - * @param array() $array the array where to seek + * @param array $array the array where to seek * @return number the sum */ public static function getArrayDepth($array) From ac34d1f9fab99189c957c71c1250a29813e6c37a Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Thu, 3 Apr 2025 11:18:50 +0200 Subject: [PATCH 09/24] update dependencies --- composer.lock | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.lock b/composer.lock index 8b2f95e8..1f609c64 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6df73811807d78a601dcd3d340500992", + "content-hash": "71b413b917a096d0030738b7446ab66a", "packages": [ { "name": "masnathan/odtphp", @@ -466,16 +466,16 @@ }, { "name": "friendsofphp/php-cs-fixer", - "version": "v3.74.0", + "version": "v3.75.0", "source": { "type": "git", "url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git", - "reference": "6b7cb12a6cf592fd9a2b46a2d5d4c3b44003973d" + "reference": "399a128ff2fdaf4281e4e79b755693286cdf325c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/6b7cb12a6cf592fd9a2b46a2d5d4c3b44003973d", - "reference": "6b7cb12a6cf592fd9a2b46a2d5d4c3b44003973d", + "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/399a128ff2fdaf4281e4e79b755693286cdf325c", + "reference": "399a128ff2fdaf4281e4e79b755693286cdf325c", "shasum": "" }, "require": { @@ -559,7 +559,7 @@ ], "support": { "issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues", - "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.74.0" + "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.75.0" }, "funding": [ { @@ -567,7 +567,7 @@ "type": "github" } ], - "time": "2025-03-27T22:31:30+00:00" + "time": "2025-03-31T18:40:42+00:00" }, { "name": "glpi-project/tools", @@ -3047,5 +3047,5 @@ "platform-overrides": { "php": "7.4.0" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } From 99b75f462543d45ea9abf2bb9254b724c59ec329 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Mon, 7 Apr 2025 14:34:52 +0200 Subject: [PATCH 10/24] phpstan5 --- inc/common.class.php | 13 ++-- inc/graphpng.class.php | 118 ++++++++++++++++++------------------- inc/helpdesk.class.php | 6 +- inc/helpdeskplus.class.php | 4 +- inc/inventory.class.php | 14 ++--- inc/preference.class.php | 2 +- phpstan.neon | 7 ++- 7 files changed, 83 insertions(+), 81 deletions(-) diff --git a/inc/common.class.php b/inc/common.class.php index 6468cf75..35fff38f 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -1255,9 +1255,9 @@ public static function generateOdt($params) } $odf = new Odf('../templates/template.odt', $config); - $odf->setVars('category', $category, ENT_NOQUOTES, 'utf-8'); - $odf->setVars('title', $params[0]['title'], ENT_NOQUOTES, 'utf-8'); - $odf->setVars('description', $description, ENT_NOQUOTES, 'utf-8'); + $odf->setVars('category', $category, (bool) ENT_NOQUOTES, 'utf-8'); + $odf->setVars('title', $params[0]['title'], (bool) ENT_NOQUOTES, 'utf-8'); + $odf->setVars('description', $description, (bool) ENT_NOQUOTES, 'utf-8'); $path = GLPI_PLUGIN_DOC_DIR . '/mreporting/' . $params[0]['f_name'] . '.png'; @@ -1265,7 +1265,7 @@ public static function generateOdt($params) list($image_width, $image_height) = @getimagesize($path); $image_width *= Odf::PIXEL_TO_CM; $image_height *= Odf::PIXEL_TO_CM * 17 / $image_width; - $odf->setImage('image', $path, -1, 17, $image_height); + $odf->setImage('image', $path, -1, 17, intval($image_height)); } else { $odf->setVars('image', '', true, 'UTF-8'); } @@ -1745,6 +1745,7 @@ public static function showSelector($date1, $date2, $randname) } $_SERVER['REQUEST_URI'] .= '&date1' . $randname . '=' . $date1 . '&date2' . $randname . '=' . $date2; + /* @phpstan-ignore-next-line */ SavedSearch::showSaveButton(SavedSearch::URI, __CLASS__); //If there's no selector for the report, there's no need for a reset button ! @@ -1934,10 +1935,10 @@ public static function getSQLDate($field = '`glpi_tickets`.`date`', $delay = 365 } $date_array1 = explode('-', $_SESSION['mreporting_values']['date1' . $randname]); - $time1 = mktime(0, 0, 0, $date_array1[1], $date_array1[2], $date_array1[0]); + $time1 = mktime(0, 0, 0, intval($date_array1[1]), intval($date_array1[2]), intval($date_array1[0])); $date_array2 = explode('-', $_SESSION['mreporting_values']['date2' . $randname]); - $time2 = mktime(0, 0, 0, $date_array2[1], $date_array2[2], $date_array2[0]); + $time2 = mktime(0, 0, 0, intval($date_array2[1]), intval($date_array2[2]), intval($date_array2[0])); //if data inverted, reverse it if ($time1 > $time2) { diff --git a/inc/graphpng.class.php b/inc/graphpng.class.php index 7510105e..bd53004b 100644 --- a/inc/graphpng.class.php +++ b/inc/graphpng.class.php @@ -315,7 +315,7 @@ public static function darker($color, $factor = 50) $amount = round($amount * $factor); $new_decimal = $v - $amount; - $new_hex_component = dechex($new_decimal); + $new_hex_component = dechex((int) $new_decimal); if (strlen($new_hex_component) < 2) { $new_hex_component = '0' . $new_hex_component; } @@ -343,7 +343,7 @@ public static function lighter($color, $factor = 50) $amount = round($amount * $factor); $new_decimal = $v + $amount; - $new_hex_component = dechex($new_decimal); + $new_hex_component = dechex((int) $new_decimal); if (strlen($new_hex_component) < 2) { $new_hex_component = '0' . $new_hex_component; } @@ -404,36 +404,36 @@ public function imageSmoothAlphaLine($image, $x1, $y1, $x2, $y2, $dcol) continue; } - $trgb = ImageColorAt($image, $x, floor($y)); + $trgb = ImageColorAt($image, $x, (int) floor($y)); $tcr = ($trgb >> 16) & 0xFF; $tcg = ($trgb >> 8) & 0xFF; $tcb = $trgb & 0xFF; imagesetpixel( $image, $x, - floor($y), + (int) floor($y), imagecolorallocatealpha( $image, - round($tcr * $ya + $icr * $yb), + (int) round($tcr * $ya + $icr * $yb), (int) ($tcg * $ya + $icg * $yb), (int) ($tcb * $ya + $icb * $yb), hexdec($alpha), ), ); - $trgb = ImageColorAt($image, $x, ceil($y)); + $trgb = ImageColorAt($image, $x, (int) ceil($y)); $tcr = ($trgb >> 16) & 0xFF; $tcg = ($trgb >> 8) & 0xFF; $tcb = $trgb & 0xFF; imagesetpixel( $image, $x, - ceil($y), + (int) ceil($y), imagecolorallocatealpha( $image, - round($tcr * $yb + $icr * $ya), - round($tcg * $yb + $icg * $ya), - round($tcb * $yb + $icb * $ya), + (int) round($tcr * $yb + $icr * $ya), + (int) round($tcg * $yb + $icg * $ya), + (int) round($tcb * $yb + $icb * $ya), hexdec($alpha), ), ); @@ -454,36 +454,36 @@ public function imageSmoothAlphaLine($image, $x1, $y1, $x2, $y2, $dcol) continue; } - $trgb = ImageColorAt($image, floor($x), $y); + $trgb = ImageColorAt($image, (int) floor($x), $y); $tcr = ($trgb >> 16) & 0xFF; $tcg = ($trgb >> 8) & 0xFF; $tcb = $trgb & 0xFF; imagesetpixel( $image, - floor($x), + (int) floor($x), $y, imagecolorallocatealpha( $image, - round($tcr * $xa + $icr * $xb), - round($tcg * $xa + $icg * $xb), - round($tcb * $xa + $icb * $xb), + (int) round($tcr * $xa + $icr * $xb), + (int) round($tcg * $xa + $icg * $xb), + (int) round($tcb * $xa + $icb * $xb), hexdec($alpha), ), ); - $trgb = ImageColorAt($image, ceil($x), $y); + $trgb = ImageColorAt($image, (int) ceil($x), $y); $tcr = ($trgb >> 16) & 0xFF; $tcg = ($trgb >> 8) & 0xFF; $tcb = $trgb & 0xFF; imagesetpixel( $image, - ceil($x), + (int) ceil($x), $y, imagecolorallocatealpha( $image, - round($tcr * $xb + $icr * $xa), - round($tcg * $xb + $icg * $xa), - round($tcb * $xb + $icb * $xa), + (int) round($tcr * $xb + $icr * $xa), + (int) round($tcg * $xb + $icg * $xa), + (int) round($tcb * $xb + $icb * $xa), hexdec($alpha), ), ); @@ -685,9 +685,9 @@ public function showHbar($params, $dashboard = false, $width = false) $by2 = $by1 + $height_bar; //createbar - ImageFilledRectangle($image, $bx1, $by1, $bx2, $by2, hexdec($palette[$index])); - imagerectangle($image, $bx1, $by1 - 1, $bx2 + 1, $by2 + 1, hexdec($darkerpalette[$index])); - imagerectangle($image, $bx1, $by1 - 2, $bx2 + 2, $by2 + 2, hexdec($darkerpalette[$index])); + ImageFilledRectangle($image, $bx1, (int) $by1, (int) $bx2, (int) $by2, hexdec($palette[$index])); + imagerectangle($image, $bx1, (int) $by1 - 1, (int) $bx2 + 1, (int) $by2 + 1, hexdec($darkerpalette[$index])); + imagerectangle($image, $bx1, (int) $by1 - 2, (int) $bx2 + 2, (int) $by2 + 2, hexdec($darkerpalette[$index])); //create data label if ($show_label == 'always' || $show_label == 'hover') { @@ -695,8 +695,8 @@ public function showHbar($params, $dashboard = false, $width = false) $image, $this->fontsize, $this->fontangle, - $bx2 + 6, - $by1 + 14, + (int) $bx2 + 6, + (int) $by1 + 14, hexdec($darkerpalette[$index]), $this->font, Toolbox::stripTags($data . $unit), @@ -711,7 +711,7 @@ public function showHbar($params, $dashboard = false, $width = false) $this->fontsize, $this->fontangle, 245 - $textwidth, - $by1 + 14, + (int) $by1 + 14, hexdec($this->black), $this->font, Toolbox::stripTags($labels[$index]), @@ -926,8 +926,8 @@ public function showPie($params, $dashboard = false, $width = false) $image, $this->fontsize, $this->fontangle, - $xtext, - $ytext, + (int) $xtext, + (int) $ytext, hexdec($darkerpalette[$index]), $this->font, Toolbox::stripTags($data . $unit), @@ -1284,8 +1284,8 @@ public function drawSunburstLevel($image, $datas, $params = []) $image, $this->fontsize, $this->fontangle, - $xtext, - $ytext, + (int) $xtext, + (int) $ytext, hexdec($darkercolor), $this->font, $key, @@ -1315,8 +1315,8 @@ public function drawSunburstLevel($image, $datas, $params = []) $image, $this->fontsize, $this->fontangle, - $xtext, - $ytext, + (int) $xtext, + (int) $ytext, hexdec($this->black), $this->font, (is_array($data)) ? $sum : $data, @@ -1505,9 +1505,9 @@ public function showHgbar($params, $dashboard = false, $width = false) $by2 = $by1 + 16; //createbar - ImageFilledRectangle($image, $bx1, $by1, $bx2, $by2, hexdec($palette[$index2])); - imagerectangle($image, $bx1, $by1 - 1, $bx2 + 1, $by2 + 1, hexdec($darkerpalette[$index2])); - imagerectangle($image, $bx1, $by1 - 2, $bx2 + 2, $by2 + 2, hexdec($darkerpalette[$index2])); + ImageFilledRectangle($image, $bx1, $by1, (int) $bx2, $by2, hexdec($palette[$index2])); + imagerectangle($image, $bx1, $by1 - 1, (int) $bx2 + 1, $by2 + 1, hexdec($darkerpalette[$index2])); + imagerectangle($image, $bx1, $by1 - 2, (int) $bx2 + 2, $by2 + 2, hexdec($darkerpalette[$index2])); //create data label if ($show_label == 'always' || $show_label == 'hover') { @@ -1515,7 +1515,7 @@ public function showHgbar($params, $dashboard = false, $width = false) $image, $this->fontsize, $this->fontangle, - $bx2 + 6, + (int) $bx2 + 6, $by1 + 14, hexdec($darkerpalette[$index2]), $this->font, @@ -1749,35 +1749,35 @@ public function showVstackbar($params, $dashboard = false, $width = false) $xstep = round(($height - $legend_height - $x_labels_height) / 12); for ($i = 0; $i <= 12; $i++) { $yaxis = $height - $x_labels_height - $xstep * $i; - imageLine($image, .9 * $y_labels_width, $yaxis, 0.95 * $this->width, $yaxis, hexdec($this->grey)); + imageLine($image, (int) (.9 * $y_labels_width), (int) $yaxis, (int) (0.95 * $this->width), (int) $yaxis, hexdec($this->grey)); //value label $val = round($i * $cum / 12, 1); - $box = @imageTTFBbox($this->fontsize, $this->fontangle, $this->font, $val); + $box = @imageTTFBbox($this->fontsize, $this->fontangle, $this->font, strval($val)); $textwidth = abs($box[4] - $box[0]); imagettftext( $image, $this->fontsize, $this->fontangle, - $y_labels_width - 2 - $textwidth, - $yaxis + 5, + (int) ($y_labels_width - 2 - $textwidth), + (int) $yaxis + 5, hexdec($this->darkgrey), $this->font, - $val, + strval($val), ); } //draw y-axis - imageLine($image, $y_labels_width, $legend_height, $y_labels_width, $height - 28, hexdec($this->black)); + imageLine($image, (int) $y_labels_width, $legend_height, (int) $y_labels_width, $height - 28, hexdec($this->black)); //draw x-axis imageline( $image, - .9 * $y_labels_width, - $height - $x_labels_height, - 0.95 * $this->width, - $height - $x_labels_height, + (int) (.9 * $y_labels_width), + (int) ($height - $x_labels_height), + (int) (0.95 * $this->width), + (int) ($height - $x_labels_height), hexdec($this->black), ); @@ -1821,8 +1821,8 @@ public function showVstackbar($params, $dashboard = false, $width = false) $bx2 = $bx1 + $width_bar; if ($by1 != $by2) { // no draw for empty datas - imagefilledrectangle($image, $bx1, $by1, $bx2, $by2, hexdec($alphapalette[$index2])); - imagerectangle($image, $bx1, $by1, $bx2, $by2, hexdec($darkerpalette[$index2])); + imagefilledrectangle($image, (int) $bx1, (int) $by1, (int) $bx2, (int) $by2, hexdec($alphapalette[$index2])); + imagerectangle($image, (int) $bx1, (int) $by1, (int) $bx2, (int) $by2, hexdec($darkerpalette[$index2])); //create data label // Affichage des données à côté des barres if (($show_label == 'always' || $show_label == 'hover') && $subdata > 0) { @@ -1833,8 +1833,8 @@ public function showVstackbar($params, $dashboard = false, $width = false) $image, $this->fontsize - 1, $this->fontangle, - $bx1 + ($width_bar / 2) - ($textwidth / 2) - 4, - $by1 - ($by1 - $by2) / 2 + 5, + (int) ($bx1 + ($width_bar / 2) - ($textwidth / 2) - 4), + (int) ($by1 - ($by1 - $by2) / 2 + 5), hexdec($darkerpalette[$index2]), $this->font, $subdata . $unit, @@ -1855,8 +1855,8 @@ public function showVstackbar($params, $dashboard = false, $width = false) $image, $this->fontsize - 1, -45, - $lx, - $height - $x_labels_height + 9, + (int) $lx, + (int) ($height - $x_labels_height + 9), hexdec($this->black), $this->font, Toolbox::stripTags($labels2[$label]), @@ -2050,17 +2050,17 @@ public function showArea($params, $dashboard = false, $width = false) //value labels $val = round($i * $max / 12); - $box = @imageTTFBbox($this->fontsize, $this->fontangle, $this->font, $val); + $box = @imageTTFBbox($this->fontsize, $this->fontangle, $this->font, strval($val)); $textwidth = abs($box[4] - $box[0]); imagettftext( $image, $this->fontsize, $this->fontangle, 28 - $textwidth, - $yaxis + 5, + (int) ($yaxis + 5), hexdec($this->darkgrey), $this->font, - $val, + strval($val), ); } @@ -2397,7 +2397,7 @@ public function showGArea($params, $dashboard = false, $width = false) $yaxis = $height - $x_labels_height - $xstep * $i; //horizontal grey lines - imageLine($image, $x_bar, $yaxis, $x_bar + $width_line * ($nb - 1), $yaxis, hexdec($this->grey)); + imageLine($image, $x_bar, (int) $yaxis, $x_bar + $width_line * ($nb - 1), (int) $yaxis, hexdec($this->grey)); //value ticks if ($i * $max / 12 < 10) { @@ -2406,7 +2406,7 @@ public function showGArea($params, $dashboard = false, $width = false) $val = round($i * $max / 12); } - $box = @imageTTFBbox($this->fontsize - 1, $this->fontangle, $this->font, $val); + $box = @imageTTFBbox($this->fontsize - 1, $this->fontangle, $this->font, strval($val)); $textwidth = abs($box[4] - $box[0]); imagettftext( @@ -2414,10 +2414,10 @@ public function showGArea($params, $dashboard = false, $width = false) $this->fontsize - 1, $this->fontangle, 25 - $textwidth, - $yaxis + 5, + (int) $yaxis + 5, hexdec($this->darkgrey), $this->font, - $val, + strval($val), ); } diff --git a/inc/helpdesk.class.php b/inc/helpdesk.class.php index 35e48eaa..cd7e9404 100644 --- a/inc/helpdesk.class.php +++ b/inc/helpdesk.class.php @@ -373,7 +373,7 @@ private function reportHgbarTicketNumberByCategoryAndByType(array $config, $filt if ($ticket['type'] == 0) { $type = __('Undefined', 'mreporting'); } else { - $type = Ticket::getTicketTypeName($ticket['type']); + $type = Ticket::getTicketTypeName(intval($ticket['type'])); } $datas['labels2'][$type] = $type; $datas['datas'][$ticket['category_name']][$type] = $ticket['count']; @@ -630,7 +630,7 @@ public function reportGlineNbTicket($config = [], $area = false) ORDER BY period, status'; $res = $DB->doQuery($query); while ($data = $DB->fetchAssoc($res)) { - $status = Ticket::getStatus($data['status']); + $status = Ticket::getStatus(intval($data['status'])); $datas['labels2'][$data['period']] = $data['period_name']; $datas['datas'][$status][$data['period']] = $data['nb']; } @@ -693,7 +693,7 @@ public function reportSunburstTicketByCategories($config = []) if (!isset($flat_datas[$current_datas['parent']])) { if ( $current_datas['parent'] != 0 - && $itilcategory->getFromDB($current_datas['parent']) + && $itilcategory->getFromDB(intval($current_datas['parent'])) ) { $flat_datas[$current_datas['parent']] = [ 'id' => $current_datas['parent'], diff --git a/inc/helpdeskplus.class.php b/inc/helpdeskplus.class.php index 34ffcdd2..5373b3f5 100644 --- a/inc/helpdeskplus.class.php +++ b/inc/helpdeskplus.class.php @@ -216,10 +216,10 @@ public function reportGlineBacklogs($config = []) */ if ($search_backlogs) { $date_array1 = explode('-', $_SESSION['mreporting_values']['date1' . $config['randname']]); - $time1 = mktime(0, 0, 0, $date_array1[1], $date_array1[2], $date_array1[0]); + $time1 = mktime(0, 0, 0, intval($date_array1[1]), intval($date_array1[2]), intval($date_array1[0])); $date_array2 = explode('-', $_SESSION['mreporting_values']['date2' . $config['randname']]); - $time2 = mktime(0, 0, 0, $date_array2[1], $date_array2[2], $date_array2[0]); + $time2 = mktime(0, 0, 0, intval($date_array2[1]), intval($date_array2[2]), intval($date_array2[0])); //if data inverted, reverse it if ($time1 > $time2) { diff --git a/inc/inventory.class.php b/inc/inventory.class.php index bc1c477f..d1444abf 100644 --- a/inc/inventory.class.php +++ b/inc/inventory.class.php @@ -142,7 +142,7 @@ public function computersByFabricant($config = []) $datas = []; while ($computer = $DB->fetchAssoc($result)) { if ($computer['Total']) { - $percent = round($computer['Percent'], 2); + $percent = round(floatval($computer['Percent']), 2); $datas['datas'][$computer['Manufacturer'] . " ($percent %)"] = $computer['Total']; } } @@ -194,7 +194,7 @@ public function computersByType($config = []) $result = $DB->doQuery($query); $datas = []; while ($computer = $DB->fetchAssoc($result)) { - $percent = round($computer['Percent'], 2); + $percent = round(floatval($computer['Percent']), 2); $datas['datas'][$computer['Type'] . " ($percent %)"] = $computer['Total']; } @@ -320,7 +320,7 @@ public function computersByAge($config = []) $result = $DB->doQuery($query); while ($computer = $DB->fetchAssoc($result)) { - $percent = round($computer['Percent'], 2); + $percent = round(floatval($computer['Percent']), 2); $datas['datas'][__($computer['Age'], 'mreporting') . " ($percent %)"] = $computer['Total']; } @@ -418,7 +418,7 @@ public function computersByOS($config = []) $datas = []; while ($computer = $DB->fetchAssoc($result)) { - $percent = round($computer['Percent'], 2); + $percent = round(floatval($computer['Percent']), 2); if ($computer['Total']) { $datas['datas'][$computer['OS'] . " ($percent %)"] = $computer['Total']; } @@ -830,7 +830,7 @@ public function reportHbarComputersByStatus($config = []) $result = $DB->doQuery($query); $datas = []; while ($computer = $DB->fetchAssoc($result)) { - $percent = round($computer['Percent'], 2); + $percent = round(floatval($computer['Percent']), 2); $datas['datas'][$computer['status'] . " ($percent %)"] = $computer['Total']; } @@ -857,7 +857,7 @@ public function reportHbarPrintersByStatus($config = []) $result = $DB->doQuery($query); while ($printer = $DB->fetchAssoc($result)) { - $pourcentage = round($printer['Pourcentage'], 2); + $pourcentage = round(floatval($printer['Pourcentage']), 2); $datas['datas'][$printer['status'] . " ($pourcentage %)"] = $printer['Total']; } @@ -919,7 +919,7 @@ public function reportHbarComputersByEntity($config = []) $percent = round((100 * (int) $value) / $total); } $ent_id = $entities[$key]; - $key = str_replace('pourcentage', $percent, $key); + $key = str_replace('pourcentage', (string) $percent, $key); $datas['datas'][$key] = $value; $type = 'under'; if ($ent_id == $_SESSION['glpiactive_entity']) { diff --git a/inc/preference.class.php b/inc/preference.class.php index 159b77b6..496a36cb 100644 --- a/inc/preference.class.php +++ b/inc/preference.class.php @@ -54,7 +54,7 @@ public function addDefaultPreference($users_id) * Get a preference for an user * @param string $field preference field to get * @param int $users_id user ID - * @return int value or 0 + * @return int|string value or 0 */ public static function checkPreferenceValue($field, $users_id = 0) { diff --git a/phpstan.neon b/phpstan.neon index 804efb06..6a7d4bd5 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,14 +1,15 @@ parameters: parallel: maximumNumberOfProcesses: 2 - level: 4 + level: 5 bootstrapFiles: - ../../inc/based_config.php paths: - - inc - - front - ajax + - front + - inc - hook.php + - index.php - setup.php scanDirectories: - ../../inc From 96abe2f820fb7e16c08b2dcc0aafa2de23e1988e Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Tue, 22 Apr 2025 11:54:40 +0200 Subject: [PATCH 11/24] review --- hook.php | 12 ++++++------ inc/common.class.php | 18 ++++++++++-------- inc/notification.class.php | 28 ++++++++++++++++------------ 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/hook.php b/hook.php index af80339f..a4f713a4 100644 --- a/hook.php +++ b/hook.php @@ -99,7 +99,7 @@ function plugin_mreporting_install() $query_display_pref = "SELECT id FROM glpi_displaypreferences WHERE itemtype = 'PluginMreportingConfig'"; - $res_display_pref = $DB->doQuery($query_display_pref); + $res_display_pref = $DB->doQueryOrDie($query_display_pref); if ($DB->numrows($res_display_pref) == 0) { $queries[] = "INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginMreportingConfig','2','2','0');"; @@ -131,7 +131,7 @@ function plugin_mreporting_install() ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; foreach ($queries as $query) { - $DB->doQuery($query); + $DB->doQueryOrDie($query); } // == Update to 2.1 == @@ -153,7 +153,7 @@ function plugin_mreporting_install() //truncate profile table $query = 'TRUNCATE TABLE `glpi_plugin_mreporting_profiles`'; - $DB->doQuery($query); + $DB->doQueryOrDie($query); //migration of field $migration->addField('glpi_plugin_mreporting_profiles', 'right', 'char'); @@ -176,16 +176,16 @@ function plugin_mreporting_install() // == UPDATE to 0.84+1.0 == $query = 'UPDATE `glpi_plugin_mreporting_profiles` pr SET pr.right = ' . READ . " WHERE pr.right = 'r'"; - $DB->doQuery($query); + $DB->doQueryOrDie($query); if (!isIndex('glpi_plugin_mreporting_profiles', 'profiles_id_reports')) { $query = 'ALTER TABLE glpi_plugin_mreporting_profiles ADD UNIQUE INDEX `profiles_id_reports` (`profiles_id`, `reports`)'; - $DB->doQuery($query); + $DB->doQueryOrDie($query); } // Remove GLPI graphtype to fix compatibility with GLPI 9.2.2+ $query = "UPDATE `glpi_plugin_mreporting_configs` SET `graphtype` = 'SVG' WHERE `graphtype` = 'GLPI'"; - $DB->doQuery($query); + $DB->doQueryOrDie($query); //== Create directories $rep_files_mreporting = GLPI_PLUGIN_DOC_DIR . '/mreporting'; diff --git a/inc/common.class.php b/inc/common.class.php index 35fff38f..d508048a 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -1255,9 +1255,9 @@ public static function generateOdt($params) } $odf = new Odf('../templates/template.odt', $config); - $odf->setVars('category', $category, (bool) ENT_NOQUOTES, 'utf-8'); - $odf->setVars('title', $params[0]['title'], (bool) ENT_NOQUOTES, 'utf-8'); - $odf->setVars('description', $description, (bool) ENT_NOQUOTES, 'utf-8'); + $odf->setVars('category', $category, true, 'utf-8'); + $odf->setVars('title', $params[0]['title'], true, 'utf-8'); + $odf->setVars('description', $description, true, 'utf-8'); $path = GLPI_PLUGIN_DOC_DIR . '/mreporting/' . $params[0]['f_name'] . '.png'; @@ -1745,7 +1745,6 @@ public static function showSelector($date1, $date2, $randname) } $_SERVER['REQUEST_URI'] .= '&date1' . $randname . '=' . $date1 . '&date2' . $randname . '=' . $date2; - /* @phpstan-ignore-next-line */ SavedSearch::showSaveButton(SavedSearch::URI, __CLASS__); //If there's no selector for the report, there's no need for a reset button ! @@ -1910,10 +1909,13 @@ public static function resetSelectorsForReport($report_name) } $selector = addslashes(json_encode($values)); - $query = "UPDATE `glpi_plugin_mreporting_preferences` - SET `selectors`='$selector' - WHERE `users_id`='$users_id'"; - $DB->doQuery($query); + $DB->buildUpdate( + 'glpi_plugin_mreporting_preferences', + ['selectors' => $selector], + [ + 'WHERE' => ['users_id' => $users_id] + ] + ); } } diff --git a/inc/notification.class.php b/inc/notification.class.php index aabcfd7f..083d17d8 100644 --- a/inc/notification.class.php +++ b/inc/notification.class.php @@ -102,8 +102,12 @@ public static function install($migration) ], ); - $DB->doQuery('INSERT INTO glpi_notificationtargets (items_id, type, notifications_id) - VALUES (1, 1, ' . $notification_id . ');'); + $notification_target = new NotificationTarget(); + $notification_target->add([ + 'items_id' => 1, + 'type' => 1, + 'notifications_id' => $notification_id + ]); } return ['success' => true]; @@ -123,26 +127,26 @@ public static function uninstall() // Remove NotificationTargets and Notifications $notification = new Notification(); + $notification_target = new NotificationTarget(); $result = $notification->find(['itemtype' => 'PluginMreportingNotification']); foreach ($result as $row) { $notification_id = $row['id']; - $queries[] = 'DELETE FROM glpi_notificationtargets WHERE notifications_id = ' . $notification_id; - $queries[] = 'DELETE FROM glpi_notifications WHERE id = ' . $notification_id; + $notification->delete(['id' => $notification_id]); + $notification_target->deleteByCriteria([ + 'notifications_id' => $notification_id + ]); } // Remove NotificationTemplateTranslations and NotificationTemplates $template = new NotificationTemplate(); + $notification_translation = new NotificationTemplateTranslation(); $result = $template->find(['itemtype' => 'PluginMreportingNotification']); foreach ($result as $row) { $template_id = $row['id']; - $queries[] = 'DELETE FROM glpi_notificationtemplatetranslations - WHERE notificationtemplates_id = ' . $template_id; - $queries[] = 'DELETE FROM glpi_notificationtemplates - WHERE id = ' . $template_id; - } - - foreach ($queries as $query) { - $DB->doQuery($query); + $notification_translation->deleteByCriteria([ + 'notificationtemplates_id' => $template_id, + ]); + $template->delete(['id' => $template_id]); } return ['success' => true]; From 0215cc515d977e8161a33b3fe7e81b00d7553c23 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Tue, 22 Apr 2025 13:59:07 +0200 Subject: [PATCH 12/24] php-cs-fixer --- inc/common.class.php | 4 ++-- inc/notification.class.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/inc/common.class.php b/inc/common.class.php index d508048a..d2b1cc54 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -1913,8 +1913,8 @@ public static function resetSelectorsForReport($report_name) 'glpi_plugin_mreporting_preferences', ['selectors' => $selector], [ - 'WHERE' => ['users_id' => $users_id] - ] + 'WHERE' => ['users_id' => $users_id], + ], ); } } diff --git a/inc/notification.class.php b/inc/notification.class.php index 083d17d8..788c10d4 100644 --- a/inc/notification.class.php +++ b/inc/notification.class.php @@ -106,7 +106,7 @@ public static function install($migration) $notification_target->add([ 'items_id' => 1, 'type' => 1, - 'notifications_id' => $notification_id + 'notifications_id' => $notification_id, ]); } @@ -133,7 +133,7 @@ public static function uninstall() $notification_id = $row['id']; $notification->delete(['id' => $notification_id]); $notification_target->deleteByCriteria([ - 'notifications_id' => $notification_id + 'notifications_id' => $notification_id, ]); } From 3b42a10d590a9071930b8ad6e77e5e8a84609035 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Mon, 5 May 2025 11:17:43 +0200 Subject: [PATCH 13/24] change doQuery --- front/central.php | 31 ++++++---- inc/common.class.php | 76 +++++++++++++++++++++---- inc/config.class.php | 21 ++----- inc/helpdesk.class.php | 126 +++++++++++++++++++++++++++-------------- 4 files changed, 172 insertions(+), 82 deletions(-) diff --git a/front/central.php b/front/central.php index 38d237b7..b86708c4 100644 --- a/front/central.php +++ b/front/central.php @@ -55,19 +55,28 @@ $classname = str_replace('target=' . $_SERVER['PHP_SELF'] . '&classname=', '', $params); //we found all reports for classname where current profil have right - $query = "SELECT * - FROM `glpi_plugin_mreporting_configs`,`glpi_plugin_mreporting_profiles` - WHERE `glpi_plugin_mreporting_configs`.`id` = `glpi_plugin_mreporting_profiles`.`reports` - AND `glpi_plugin_mreporting_configs`.`classname` = '$classname' - AND `glpi_plugin_mreporting_profiles`.`right` = " . READ . ' - AND `glpi_plugin_mreporting_profiles`.`profiles_id` = ' . $_SESSION['glpiactiveprofile']['id']; + $result = $DB->request([ + 'SELECT' => '*', + 'FROM' => 'glpi_plugin_mreporting_configs', + 'LEFT JOIN' => [ + 'glpi_plugin_mreporting_profiles' => [ + 'ON' => [ + 'glpi_plugin_mreporting_configs' => 'id', + 'glpi_plugin_mreporting_profiles' => 'reports' + ] + ] + ], + 'WHERE' => [ + 'glpi_plugin_mreporting_configs.classname' => $classname, + 'glpi_plugin_mreporting_profiles.right' => READ, + 'glpi_plugin_mreporting_profiles.profiles_id' => $_SESSION['glpiactiveprofile']['id'], + ], + ]); //for this classname if current user have no right on any reports - if ($result = $DB->doQuery($query)) { - if ($DB->numrows($result) == 0) { - //we unset the index - unset($tabs[$classname]); - } + if ($result->numrows() == 0) { + //we unset the index + unset($tabs[$classname]); } } diff --git a/inc/common.class.php b/inc/common.class.php index d2b1cc54..cb8a29f2 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -1422,20 +1422,30 @@ public static function selectorAllSlasWithTicket() echo '' . $LANG['plugin_mreporting']['Helpdeskplus']['selector']['slas'] . ' :
'; - $query = 'SELECT DISTINCT s.id, - s.name - FROM glpi_slas s - INNER JOIN glpi_tickets t ON s.id = t.slas_id_ttr - WHERE t.status IN (' . implode( - ',', - array_merge(Ticket::getSolvedStatusArray(), Ticket::getClosedStatusArray()), - ) . ") - AND t.is_deleted = '0' - ORDER BY s.name ASC"; - $result = $DB->doQuery($query); + $result = $DB->request([ + 'SELECT' => [ + 'glpi_slas.id', + 'glpi_slas.name' + ], + 'DISTINCT' => true, + 'FROM' => 'glpi_slas', + 'INNER JOIN' => [ + 'glpi_tickets' => [ + 'ON' => [ + 'glpi_slas' => 'id', + 'glpi_tickets' => 'slas_id_ttr' + ] + ] + ], + 'WHERE' => [ + 'glpi_tickets.status' => array_merge(Ticket::getSolvedStatusArray(), Ticket::getClosedStatusArray()), + 'glpi_tickets.is_deleted' => 0 + ], + 'ORDERBY' => 'glpi_slas.name ASC' + ]); $values = []; - while ($data = $DB->fetchAssoc($result)) { + foreach ($result as $data) { $values[$data['id']] = $data['name']; } @@ -1958,6 +1968,48 @@ public static function getSQLDate($field = '`glpi_tickets`.`date`', $delay = 365 return "($field >= '$begin' AND $field <= ADDDATE('$end', INTERVAL 1 DAY) )"; } + /** + * Generate a criteria date test with $_REQUEST date fields + * @param string $field the sql table field to compare + * @param integer $delay if $_REQUET date fields not provided, + * generate them from $delay (in days) + * @param string $randname random string (to prevent conflict in js selection) + * @return string The sql test to insert in your query + */ + public static function getCriteriaDate($field = '`glpi_tickets`.`date`', $delay = 365, $randname = '') + { + if (empty($_SESSION['mreporting_values']['date1' . $randname])) { + $_SESSION['mreporting_values']['date1' . $randname] = date('Y-m-d', time() - ($delay * 24 * 60 * 60)); + } + if (empty($_SESSION['mreporting_values']['date2' . $randname])) { + $_SESSION['mreporting_values']['date2' . $randname] = date('Y-m-d'); + } + + $date_array1 = explode('-', $_SESSION['mreporting_values']['date1' . $randname]); + $time1 = mktime(0, 0, 0, intval($date_array1[1]), intval($date_array1[2]), intval($date_array1[0])); + + $date_array2 = explode('-', $_SESSION['mreporting_values']['date2' . $randname]); + $time2 = mktime(0, 0, 0, intval($date_array2[1]), intval($date_array2[2]), intval($date_array2[0])); + + //if data inverted, reverse it + if ($time1 > $time2) { + list($time1, $time2) = [$time2, $time1]; + list($_SESSION['mreporting_values']['date1' . $randname], + $_SESSION['mreporting_values']['date2' . $randname]) = [ + $_SESSION['mreporting_values']['date2' . $randname], + $_SESSION['mreporting_values']['date1' . $randname], + ]; + } + + $begin = date('Y-m-d H:i:s', $time1); + $end = date('Y-m-d H:i:s', $time2); + $endPlusOne = date('Y-m-d', strtotime($end . ' +1 day')); + return [ + [$field => ['>=', $begin]], + [$field => ['<=', $endPlusOne]], + ]; + } + /** * Get the max value of a multidimensionnal array * @param array|int $array the array to compute diff --git a/inc/config.class.php b/inc/config.class.php index 131e469d..d3a21cb8 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -230,22 +230,10 @@ public function getFromDBByFunctionAndClassname($function, $classname) /** @var \DBmysql $DB */ global $DB; - $query = 'SELECT * - FROM `' . $this->getTable() . "` - WHERE `name` = '" . addslashes($function) . "' - AND `classname` = '" . addslashes($classname) . "'"; - - if ($result = $DB->doQuery($query)) { - if ($DB->numrows($result) != 1) { - return false; - } - $this->fields = $DB->fetchAssoc($result); - if (is_array($this->fields) && count($this->fields)) { - return true; - } - } - - return false; + return $this->getFromDBByCrit([ + 'name' => $function, + 'classname' => $classname + ]); } /** @@ -318,6 +306,7 @@ public function createFirstConfig() } $input['firstconfig'] = 1; + unset($input['id']); $this->add($input); } } diff --git a/inc/helpdesk.class.php b/inc/helpdesk.class.php index cd7e9404..1b14ad4f 100644 --- a/inc/helpdesk.class.php +++ b/inc/helpdesk.class.php @@ -55,23 +55,34 @@ public function reportHbarTicketNumberByEntity($config = []) $datas = []; - $query = "SELECT COUNT(glpi_tickets.id) as count, - glpi_entities.name as name - FROM glpi_tickets - LEFT JOIN glpi_entities - ON (glpi_tickets.entities_id = glpi_entities.id) - WHERE {$this->sql_date} "; + $query_params = [ + 'SELECT' => ['glpi_entities.name AS name'], + 'FROM' => 'glpi_tickets', + 'COUNT' => 'glpi_tickets.id AS count', + 'LEFT JOIN' => [ + 'glpi_entities' => [ + 'ON' => [ + 'glpi_tickets' => 'entities_id', + 'glpi_entities' => 'id', + ] + ] + ], + 'WHERE' => [ + $this->sql_date, + 'glpi_tickets.is_deleted' => '0' + ], + 'GROUP BY' => 'glpi_entities.name', + 'ORDER BY' => 'count DESC', + 'LIMIT' => (isset($_REQUEST['glpilist_limit'])) ? (int)$_REQUEST['glpilist_limit'] : 20 + ]; + // Si le mode multi-entités est activé, on ajoute la condition supplémentaire if (Session::isMultiEntitiesMode()) { - $query .= 'AND glpi_entities.id IN (' . $this->where_entities . ') '; + $query_params['WHERE']['glpi_entities.id'] = $this->where_entities; } - $query .= "AND glpi_tickets.is_deleted = '0' - GROUP BY glpi_entities.name - ORDER BY count DESC - LIMIT 0, "; - $query .= (isset($_REQUEST['glpilist_limit'])) ? $_REQUEST['glpilist_limit'] : 20; - $result = $DB->doQuery($query); + // Exécution de la requête + $result = $DB->request($query_params); while ($ticket = $DB->fetchAssoc($result)) { if (empty($ticket['name'])) { @@ -103,25 +114,38 @@ public function reportHgbarTicketNumberByCatAndEntity($config = []) $config['randname'], ); - //get categories used in this period - $query_cat = "SELECT DISTINCT(glpi_tickets.itilcategories_id) as itilcategories_id, - glpi_itilcategories.completename as category - FROM glpi_tickets - LEFT JOIN glpi_itilcategories - ON glpi_tickets.itilcategories_id = glpi_itilcategories.id - WHERE {$this->sql_date} "; + $delay = PluginMreportingCommon::getCriteriaDate('glpi_tickets.date', $config['delay'], $config['randname']); + + $query = [ + 'SELECT' => [Ticket::getTable() . '.itilcategories_id as itilcategories_id', ITILCategory::getTable() . '.completename as category'], + 'DISTINCT' => true, + 'FROM' => Ticket::getTable(), + 'LEFT JOIN' => [ + ITILCategory::getTable() => [ + 'ON' => [ + Ticket::getTable() => 'itilcategories_id', + ITILCategory::getTable() => 'id' + ] + ] + ], + 'WHERE' => [ + Ticket::getTable() . '.entities_id' => 0, + Ticket::getTable() . '.is_deleted' => 0, + ], + 'ORDER' => ["glpi_itilcategories.id ASC"] + ]; + + $query['WHERE']['AND'] = $delay; + // Si le mode multi-entités est activé, on ajoute la condition supplémentaire if (Session::isMultiEntitiesMode()) { - $query_cat .= 'AND glpi_tickets.entities_id IN (' . $this->where_entities . ') '; + $query_params['WHERE']['glpi_entities.id'] = $this->where_entities; } - $query_cat .= "AND glpi_tickets.is_deleted = '0' - ORDER BY glpi_itilcategories.id ASC"; - - $res_cat = $DB->doQuery($query_cat); + $result = $DB->request($query); $categories = []; - while ($data = $DB->fetchAssoc($res_cat)) { + foreach ($result as $data) { if (empty($data['category'])) { $data['category'] = __('None'); } @@ -135,27 +159,43 @@ public function reportHgbarTicketNumberByCatAndEntity($config = []) $tmp_cat[] = "cat_$id"; } $cat_str = "'" . implode("', '", array_values($categories)) . "'"; + $cat_ids = array_values($categories); //count ticket by entity and categories previously selected - $query = "SELECT - COUNT(glpi_tickets.id) as nb, - glpi_entities.name as entity, - glpi_tickets.itilcategories_id as cat_id - FROM glpi_tickets - LEFT JOIN glpi_entities - ON glpi_tickets.entities_id = glpi_entities.id - WHERE glpi_tickets.itilcategories_id IN ($cat_str) "; + $query = [ + 'SELECT' => [ + 'COUNT(' . Ticket::getTable() . '.id) as nb', + Entity::getTable() . '.name as nb', + Ticket::getTable() . '.itilcategories_id as cat_id', + ], + 'FROM' => Ticket::getTable(), + 'LEFT JOIN' => [ + Entity::getTable() => [ + 'ON' => [ + Ticket::getTable() . '.entities_id', + Entity::getTable() . '.id', + ] + ] + ], + 'WHERE' => [ + Ticket::getTable() . '.itilcategories_id' => $cat_ids, + Ticket::getTable() . '.is_deleted' => 0, + ], + 'GROUPBY' => [ + Entity::getTable() . '.name', + Ticket::getTable() . '.itilcategories_id', + ], + 'ORDER' => ['glpi_entities.name ASC', 'glpi_tickets.itilcategories_id ASC'] + ]; - if (Session::isMultiEntitiesMode()) { - $query .= 'AND glpi_tickets.entities_id IN (' . $this->where_entities . ')'; - } + $query['WHERE']['AND'] = $delay; - $query .= 'AND ' . $this->sql_date . " - AND glpi_tickets.is_deleted = '0' - GROUP BY glpi_entities.name, glpi_tickets.itilcategories_id - ORDER BY glpi_entities.name ASC, glpi_tickets.itilcategories_id ASC"; - $res = $DB->doQuery($query); - while ($data = $DB->fetchAssoc($res)) { + /*if (Session::isMultiEntitiesMode()) { + $query['WHERE']['glpi_entities.id'] = $this->where_entities; + }*/ + + $result = $DB->request($query); + foreach ($result as $data) { if (empty($data['entity'])) { $data['entity'] = __('Root entity'); } From 8d93380eec32a2f27704b224e3529d78aa8d76e9 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Thu, 22 May 2025 13:51:40 +0200 Subject: [PATCH 14/24] Helpdesk tabs --- inc/common.class.php | 26 ++ inc/helpdesk.class.php | 729 +++++++++++++++++++++++++---------------- 2 files changed, 472 insertions(+), 283 deletions(-) diff --git a/inc/common.class.php b/inc/common.class.php index cb8a29f2..c49905ac 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -2010,6 +2010,32 @@ public static function getCriteriaDate($field = '`glpi_tickets`.`date`', $delay ]; } + /** + * Format where_entities field for criteria + * @param string $where_entities entities string + * + * @return array formatted array + */ + public static function formatWhereEntitiesArray($where_entities) + { + preg_match_all('/\d+/', $where_entities, $matches); + return array_map('intval', $matches[0]); + } + + public static function convertDateFormatSQLtoPHP(string $format): string { + return strtr($format, [ + '%Y' => 'Y', + '%y' => 'y', + '%m' => 'm', + '%d' => 'd', + '%H' => 'H', + '%i' => 'i', + '%s' => 's', + '%M' => 'F', + '%b' => 'M', + ]); + } + /** * Get the max value of a multidimensionnal array * @param array|int $array the array to compute diff --git a/inc/helpdesk.class.php b/inc/helpdesk.class.php index 1b14ad4f..dc17a388 100644 --- a/inc/helpdesk.class.php +++ b/inc/helpdesk.class.php @@ -47,44 +47,45 @@ public function reportHbarTicketNumberByEntity($config = []) ]; //Init delay value - $this->sql_date = PluginMreportingCommon::getSQLDate( - '`glpi_tickets`.`date`', - $config['delay'], - $config['randname'], - ); + $delay = PluginMreportingCommon::getCriteriaDate('glpi_tickets.date', $config['delay'], $config['randname']); $datas = []; - $query_params = [ - 'SELECT' => ['glpi_entities.name AS name'], - 'FROM' => 'glpi_tickets', - 'COUNT' => 'glpi_tickets.id AS count', + $query = [ + 'SELECT' => [ + Entity::getTable() . '.name as name', + ], + 'COUNT' => 'count', + 'FROM' => Ticket::getTable(), 'LEFT JOIN' => [ - 'glpi_entities' => [ + Entity::getTable() => [ 'ON' => [ - 'glpi_tickets' => 'entities_id', - 'glpi_entities' => 'id', + Ticket::getTable() . '.entities_id', + Entity::getTable() . '.id', ] ] ], - 'WHERE' => [ - $this->sql_date, - 'glpi_tickets.is_deleted' => '0' + 'WHERE' => [ + Ticket::getTable() . '.is_deleted' => 0, + ], + 'GROUPBY' => [ + Entity::getTable() . '.name', ], - 'GROUP BY' => 'glpi_entities.name', - 'ORDER BY' => 'count DESC', + 'ORDER' => ['glpi_entities.name ASC', 'glpi_tickets.itilcategories_id ASC'], 'LIMIT' => (isset($_REQUEST['glpilist_limit'])) ? (int)$_REQUEST['glpilist_limit'] : 20 ]; + $query['WHERE']['AND'] = $delay; + // Si le mode multi-entités est activé, on ajoute la condition supplémentaire if (Session::isMultiEntitiesMode()) { - $query_params['WHERE']['glpi_entities.id'] = $this->where_entities; + $query['WHERE']['glpi_entities.id'] = PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities); } // Exécution de la requête - $result = $DB->request($query_params); + $result = $DB->request($query); - while ($ticket = $DB->fetchAssoc($result)) { + foreach ($result as $ticket) { if (empty($ticket['name'])) { $label = __('Root entity'); } else { @@ -108,12 +109,6 @@ public function reportHgbarTicketNumberByCatAndEntity($config = []) $tmp_datas = []; //Init delay value - $this->sql_date = PluginMreportingCommon::getSQLDate( - 'glpi_tickets.date', - $config['delay'], - $config['randname'], - ); - $delay = PluginMreportingCommon::getCriteriaDate('glpi_tickets.date', $config['delay'], $config['randname']); $query = [ @@ -139,7 +134,7 @@ public function reportHgbarTicketNumberByCatAndEntity($config = []) // Si le mode multi-entités est activé, on ajoute la condition supplémentaire if (Session::isMultiEntitiesMode()) { - $query_params['WHERE']['glpi_entities.id'] = $this->where_entities; + $query['WHERE'][Ticket::getTable() . '.entities_id'] = PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities); } $result = $DB->request($query); @@ -164,10 +159,10 @@ public function reportHgbarTicketNumberByCatAndEntity($config = []) //count ticket by entity and categories previously selected $query = [ 'SELECT' => [ - 'COUNT(' . Ticket::getTable() . '.id) as nb', - Entity::getTable() . '.name as nb', + Entity::getTable() . '.name', Ticket::getTable() . '.itilcategories_id as cat_id', ], + 'COUNT' => 'nb', 'FROM' => Ticket::getTable(), 'LEFT JOIN' => [ Entity::getTable() => [ @@ -190,9 +185,9 @@ public function reportHgbarTicketNumberByCatAndEntity($config = []) $query['WHERE']['AND'] = $delay; - /*if (Session::isMultiEntitiesMode()) { - $query['WHERE']['glpi_entities.id'] = $this->where_entities; - }*/ + if (Session::isMultiEntitiesMode()) { + $query['WHERE']['glpi_entities.id'] = PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities); + } $result = $DB->request($query); foreach ($result as $data) { @@ -237,26 +232,29 @@ public function reportPieTicketOpenedAndClosed($config = []) = ['dateinterval']; //Init delay value - $this->sql_date = PluginMreportingCommon::getSQLDate( - 'glpi_tickets.date', - $config['delay'], - $config['randname'], - ); + $delay = PluginMreportingCommon::getCriteriaDate('glpi_tickets.date', $config['delay'], $config['randname']); $datas = []; foreach ($this->filters as $filter) { - $query = 'SELECT COUNT(*) - FROM glpi_tickets - WHERE ' . $this->sql_date . ' '; + $query = [ + 'FROM' => Ticket::getTable(), + 'COUNT' => 'count', + 'WHERE' => [ + Ticket::getTable() . '.is_deleted' => 0, + Ticket::getTable() . '.status' => array_keys($filter['status']), + ], + ]; if (Session::isMultiEntitiesMode()) { - $query .= 'AND glpi_tickets.entities_id IN (' . $this->where_entities . ')'; + $query['WHERE'][Ticket::getTable() . '.entities_id'] = PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities); } - $query .= "AND glpi_tickets.is_deleted = '0' - AND glpi_tickets.status IN('" . implode("', '", array_keys($filter['status'])) . "')"; - $result = $DB->doQuery($query); - $datas[$filter['label']] = $DB->result($result, 0, "0"); + $query['WHERE']['AND'] = $delay; + $result = $DB->request($query); + $datas[$filter['label']] = 0; + if ($row = $result->current()) { + $datas[$filter['label']] = $row['count']; + } } return ['datas' => $datas]; @@ -273,11 +271,7 @@ public function reportPieTicketOpenedbyStatus($config = []) = ['dateinterval', 'allstates']; //Init delay value - $this->sql_date = PluginMreportingCommon::getSQLDate( - 'glpi_tickets.date', - $config['delay'], - $config['randname'], - ); + $delay = PluginMreportingCommon::getCriteriaDate('glpi_tickets.date', $config['delay'], $config['randname']); // Get status to show if (isset($_POST['status_1'])) { @@ -294,15 +288,21 @@ public function reportPieTicketOpenedbyStatus($config = []) $status = $this->filters['open']['status'] + $this->filters['close']['status']; foreach ($status as $key => $val) { if (in_array($key, $status_to_show)) { - $query = "SELECT COUNT(glpi_tickets.id) as count - FROM glpi_tickets - WHERE {$this->sql_date} - AND glpi_tickets.is_deleted = '0' - AND glpi_tickets.entities_id IN ({$this->where_entities}) - AND glpi_tickets.status ='{$key}'"; - $result = $DB->doQuery($query); - - while ($ticket = $DB->fetchAssoc($result)) { + $query = [ + 'COUNT' => 'count', + 'FROM' => Ticket::getTable(), + 'WHERE' => [ + Ticket::getTable() . '.is_deleted' => 0, + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Ticket::getTable() . '.status' => $key, + ] + ]; + + $query['WHERE']['AND'] = $delay; + + $result = $DB->request($query); + + foreach ($result as $ticket) { $datas['datas'][$val] = $ticket['count']; } } @@ -320,31 +320,43 @@ public function reportPieTopTenAuthor($config = []) = ['dateinterval']; //Init delay value - $this->sql_date = PluginMreportingCommon::getSQLDate( - 'glpi_tickets.date', - $config['delay'], - $config['randname'], - ); - $this->sql_date_closed = PluginMreportingCommon::getSQLDate( - 'glpi_tickets.closedate', - $config['delay'], - $config['randname'], - ); + $delay = PluginMreportingCommon::getCriteriaDate('glpi_tickets.date', $config['delay'], $config['randname']); + $delay_closed = PluginMreportingCommon::getCriteriaDate('glpi_tickets.closedate', $config['delay'], $config['randname']); $datas = []; - $query = "SELECT COUNT(glpi_tickets.id) as count, glpi_tickets_users.users_id as users_id - FROM glpi_tickets - LEFT JOIN glpi_tickets_users - ON (glpi_tickets_users.tickets_id = glpi_tickets.id AND glpi_tickets_users.type =1) - WHERE {$this->sql_date} - AND {$this->sql_date_closed} - AND glpi_tickets.entities_id IN ({$this->where_entities}) - AND glpi_tickets.is_deleted = '0' - GROUP BY glpi_tickets_users.users_id - ORDER BY count DESC - LIMIT 10"; - $result = $DB->doQuery($query); - while ($ticket = $DB->fetchAssoc($result)) { + + $query = [ + 'SELECT' => [ + Ticket_User::getTable() . '.users_id as users_id' + ], + 'COUNT' => 'count', + 'FROM' => Ticket::getTable(), + 'LEFT JOIN' => [ + Ticket_User::getTable() => [ + 'ON' => [ + Ticket_User::getTable() . '.tickets_id', + Ticket::getTable() . '.id', + [ + 'AND' => [ + Ticket_User::getTable() . '.type' => Ticket_User::REQUESTER + ] + ] + ] + ] + ], + 'WHERE' => [ + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Ticket::getTable() . '.is_deleted' => 0, + ], + 'GROUPBY' => [Ticket_User::getTable() . '.users_id'], + 'ORDER' => ['count DESC'], + 'LIMIT' => 10, + ]; + + $query['WHERE']['AND'] = array_merge($delay, $delay_closed); + + $result = $DB->request($query); + foreach ($result as $ticket) { if ($ticket['users_id'] == 0) { $label = __('Undefined', 'mreporting'); } else { @@ -383,29 +395,40 @@ private function reportHgbarTicketNumberByCategoryAndByType(array $config, $filt $datas = []; //Init delay value - $this->sql_date = PluginMreportingCommon::getSQLDate( - 'glpi_tickets.date', - $config['delay'], - $config['randname'], - ); + $delay = PluginMreportingCommon::getCriteriaDate('glpi_tickets.date', $config['delay'], $config['randname']); - $query = "SELECT glpi_itilcategories.id as category_id, - glpi_itilcategories.completename as category_name, - glpi_tickets.type as type, - COUNT(glpi_tickets.id) as count - FROM glpi_tickets - LEFT JOIN glpi_itilcategories - ON glpi_itilcategories.id = glpi_tickets.itilcategories_id - WHERE {$this->sql_date} - AND glpi_tickets.entities_id IN ({$this->where_entities}) - AND glpi_tickets.status IN('" . implode("', '", array_keys($this->filters[$filter]['status'])) . "') - AND glpi_tickets.is_deleted = '0' - GROUP BY glpi_itilcategories.id, glpi_tickets.type - ORDER BY glpi_itilcategories.name"; - $result = $DB->doQuery($query); + $query = [ + 'SELECT' => [ + ITILCategory::getTable() . '.id as category_id', + ITILCategory::getTable() . '.completename as category_name', + Ticket::getTable() . '.type as type', + ], + 'COUNT' => 'count', + 'FROM' => Ticket::getTable(), + 'LEFT JOIN' => [ + ITILCategory::getTable() => [ + 'ON' => [ + ITILCategory::getTable() . '.id', + Ticket::getTable() . '.itilcategories_id', + ] + ] + ], + 'WHERE' => [ + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Ticket::getTable() . '.status' => array_keys($this->filters[$filter]['status']), + Ticket::getTable() . '.is_deleted' => 0, + ], + 'GROUPBY' => [ + ITILCategory::getTable() . '.id', + Ticket::getTable() . '.type', + ], + 'ORDER' => [ITILCategory::getTable() . '.name'] + ]; + $query['WHERE']['AND'] = $delay; + $result = $DB->request($query); $datas['datas'] = []; - while ($ticket = $DB->fetchAssoc($result)) { + foreach ($result as $ticket) { if (empty($ticket['category_id'])) { $ticket['category_id'] = 0; $ticket['category_name'] = __('None'); @@ -439,37 +462,83 @@ public function reportHgbarTicketNumberByService($config = []) $config['randname'], ); + $delay = PluginMreportingCommon::getCriteriaDate('glpi_tickets.date', $config['delay'], $config['randname']); + foreach ($this->filters as $class => $filter) { + $query = [ + 'SELECT' => [ + Ticket::getTable() . '.id', + ], + 'FROM' => Ticket::getTable(), + 'WHERE' => [ + Ticket::getTable() . '.type' => 1, + ], + ]; + + $result = $DB->request($query); $datas['labels2'][$filter['label']] = $filter['label']; - $query = 'SELECT COUNT(*) - FROM glpi_tickets - WHERE id NOT IN ( - SELECT tickets_id - FROM glpi_groups_tickets - WHERE glpi_groups_tickets.type = 1 - ) - AND glpi_tickets.entities_id IN (' . $this->where_entities . ") - AND {$this->sql_date} - AND status IN('" . implode("', '", array_keys($filter['status'])) . "')"; - $result = $DB->doQuery($query); - - $datas['datas'][__('None')][$filter['label']] = $DB->result($result, 0, "0"); - - $query = "SELECT glpi_groups.name as group_name, - COUNT(glpi_tickets.id) as count - FROM glpi_tickets, glpi_groups_tickets, glpi_groups - WHERE glpi_tickets.id = glpi_groups_tickets.tickets_id - AND glpi_tickets.entities_id IN ({$this->where_entities}) - AND glpi_groups_tickets.groups_id = glpi_groups.id - AND glpi_groups_tickets.type = 1 - AND glpi_tickets.is_deleted = '0' - AND {$this->sql_date} - AND glpi_tickets.status IN('" . implode("', '", array_keys($filter['status'])) . "') - GROUP BY glpi_groups.id - ORDER BY glpi_groups.name"; - $result = $DB->doQuery($query); - - while ($ticket = $DB->fetchAssoc($result)) { + + $ticket_ids = []; + foreach ($result as $ticket) { + $ticket_ids[] = $ticket['id']; + } + + $query = [ + 'COUNT' => 'count', + 'FROM' => Ticket::getTable(), + 'WHERE' => [ + [ + 'NOT' => [ + Ticket::getTable() . '.id' => $ticket_ids + ], + ], + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Ticket::getTable() . '.status' => array_keys($filter['status']), + ], + ]; + $query['WHERE']['AND'] = $delay; + + $result = $DB->request($query); + foreach ($result as $ticket) { + $datas['datas'][__('None')][$filter['label']] = $ticket['count']; + } + + $query = [ + 'SELECT' => [ + Group::getTable() . '.name as group_name', + ], + 'COUNT' => 'count', + 'FROM' => Ticket::getTable(), + 'LEFT JOIN' => [ + Group_Ticket::getTable() => [ + 'ON' => [ + Group_Ticket::getTable() . '.tickets_id', + Ticket::getTable() . '.id', + ] + ], + Group::getTable() => [ + 'ON' => [ + Group::getTable() . '.id', + Group_Ticket::getTable() . '.groups_id', + ] + ] + ], + 'WHERE' => [ + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Group_Ticket::getTable() . '.type' => 1, + Ticket::getTable() . '.is_deleted' => 0, + Ticket::getTable() . '.status' => array_keys($filter['status']), + ], + 'GROUPBY' => [ + Group::getTable() . '.id', + ], + 'ORDER' => [Group::getTable() . '.name'] + ]; + $query['WHERE']['AND'] = $delay; + + $result = $DB->request($query); + + foreach ($result as $ticket) { $datas['datas'][$ticket['group_name']][$filter['label']] = $ticket['count']; } } @@ -489,11 +558,7 @@ public function reportHgbarOpenedTicketNumberByCategory($config = []) $status_to_show = []; //Init delay value - $this->sql_date = PluginMreportingCommon::getSQLDate( - 'glpi_tickets.date', - $config['delay'], - $config['randname'], - ); + $delay = PluginMreportingCommon::getCriteriaDate('glpi_tickets.date', $config['delay'], $config['randname']); // Get status to show if (isset($_POST['status_1'])) { @@ -509,22 +574,38 @@ public function reportHgbarOpenedTicketNumberByCategory($config = []) $status = $this->filters['open']['status'] + $this->filters['close']['status']; $status_keys = array_keys($status); - $query = "SELECT glpi_tickets.status, - glpi_itilcategories.completename as category_name, - COUNT(glpi_tickets.id) as count - FROM glpi_tickets - LEFT JOIN glpi_itilcategories - ON glpi_itilcategories.id = glpi_tickets.itilcategories_id - WHERE {$this->sql_date} - AND glpi_tickets.entities_id IN (" . $this->where_entities . ") - AND glpi_tickets.status IN('" . implode("', '", $status_keys) . "') - AND glpi_tickets.is_deleted = '0' - AND status IN (" . implode(',', $status_to_show) . ') - GROUP BY glpi_itilcategories.id, glpi_tickets.status - ORDER BY glpi_itilcategories.name'; - $result = $DB->doQuery($query); - - while ($ticket = $DB->fetchAssoc($result)) { + $query = [ + 'SELECT' => [ + Ticket::getTable() . '.status', + ITILCategory::getTable() . '.completename as category_name', + ], + 'COUNT' => 'count', + 'FROM' => Ticket::getTable(), + 'LEFT JOIN' => [ + ITILCategory::getTable() => [ + 'ON' => [ + ITILCategory::getTable() . '.id', + Ticket::getTable() . '.itilcategories_id', + ] + ] + ], + 'WHERE' => [ + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Ticket::getTable() . '.status' => $status_keys, + Ticket::getTable() . '.is_deleted' => 0, + Ticket::getTable() . '.status' => $status_to_show, + ], + 'GROUPBY' => [ + ITILCategory::getTable() . '.id', + Ticket::getTable() . '.status', + ], + 'ORDER' => [ITILCategory::getTable() . '.name'] + ]; + $query['WHERE']['AND'] = $delay; + + $result = $DB->request($query); + + foreach ($result as $ticket) { if (empty($ticket['category_name'])) { $ticket['category_name'] = __('None'); } @@ -567,24 +648,28 @@ public function reportAreaNbTicket($config = [], $area = true) $datas = []; //Init delay value - $this->sql_date = PluginMreportingCommon::getSQLDate( - 'glpi_tickets.date', - $config['delay'], - $config['randname'], - ); + $delay = PluginMreportingCommon::getCriteriaDate('glpi_tickets.date', $config['delay'], $config['randname']); + + $query = [ + 'SELECT' => [ + new QueryExpression("DATE_FORMAT(" . Ticket::getTable() . ".date, " . $DB->quoteValue($this->period_sort) . ") as period"), + new QueryExpression("DATE_FORMAT(" . Ticket::getTable() . ".date, " . $DB->quoteValue($this->period_label) . ") as period_name"), + ], + 'COUNT' => 'nb', + 'FROM' => Ticket::getTable(), + 'WHERE' => [ + Ticket::getTable() . '.is_deleted' => 0, + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities) + ], + 'GROUPBY' => ['period'], + 'ORDER' => ['period'], + ]; + + $query['WHERE']['AND'] = $delay; - $query = "SELECT - DISTINCT DATE_FORMAT(date, '" . $this->period_sort . "') as period, - DATE_FORMAT(date, '" . $this->period_label . "') as period_name, - COUNT(id) as nb - FROM glpi_tickets - WHERE {$this->sql_date} - AND glpi_tickets.entities_id IN ({$this->where_entities}) - AND glpi_tickets.is_deleted = '0' - GROUP BY period - ORDER BY period"; - $res = $DB->doQuery($query); - while ($data = $DB->fetchAssoc($res)) { + $result = $DB->request($query); + + foreach ($result as $data) { $datas['datas'][$data['period_name']] = $data['nb']; } @@ -614,14 +699,9 @@ public function reportGlineNbTicket($config = [], $area = false) = ['dateinterval', 'period', 'allstates']; $datas = []; - $tmp_datas = []; //Init delay value - $this->sql_date = PluginMreportingCommon::getSQLDate( - 'glpi_tickets.date', - $config['delay'], - $config['randname'], - ); + $delay = PluginMreportingCommon::getCriteriaDate('glpi_tickets.date', $config['delay'], $config['randname']); $status_to_show = []; // Get status to show @@ -636,18 +716,26 @@ public function reportGlineNbTicket($config = [], $area = false) } //get dates used in this period - $query_date = "SELECT DISTINCT - DATE_FORMAT(`date`, '" . $this->period_sort . "') AS period, - DATE_FORMAT(`date`, '" . $this->period_label . "') AS period_name - FROM `glpi_tickets` - WHERE " . $this->sql_date . ' - AND `glpi_tickets`.`entities_id` IN (' . $this->where_entities . ") - AND `glpi_tickets`.`is_deleted` = '0' - AND status IN(" . implode(',', $status_to_show) . ') - ORDER BY `date` ASC'; - $res_date = $DB->doQuery($query_date); + $query = [ + 'SELECT' => [ + new QueryExpression("DATE_FORMAT(" . Ticket::getTable() . ".date, " . $DB->quoteValue($this->period_sort) . ") as period"), + new QueryExpression("DATE_FORMAT(" . Ticket::getTable() . ".date, " . $DB->quoteValue($this->period_label) . ") as period_name"), + ], + 'DISTINCT' => true, + 'FROM' => Ticket::getTable(), + 'WHERE' => [ + Ticket::getTable() . '.is_deleted' => 0, + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Ticket::getTable() . '.status' => $status_to_show, + ], + 'ORDER' => [Ticket::getTable() . '.date ASC'] + ]; + + $query['WHERE']['AND'] = $delay; + + $result = $DB->request($query); $dates = []; - while ($data = $DB->fetchAssoc($res_date)) { + foreach ($result as $data) { $dates[$data['period']] = $data['period']; } @@ -656,20 +744,28 @@ public function reportGlineNbTicket($config = [], $area = false) $tmp_date[] = $id; } - $query = "SELECT DISTINCT - DATE_FORMAT(date, '" . $this->period_sort . "') as period, - DATE_FORMAT(date, '" . $this->period_label . "') as period_name, - status, - COUNT(id) as nb - FROM glpi_tickets - WHERE " . $this->sql_date . ' - AND glpi_tickets.entities_id IN (' . $this->where_entities . ") - AND glpi_tickets.is_deleted = '0' - AND status IN(" . implode(',', $status_to_show) . ') - GROUP BY period, status - ORDER BY period, status'; - $res = $DB->doQuery($query); - while ($data = $DB->fetchAssoc($res)) { + $query = [ + 'SELECT' => [ + new QueryExpression("DATE_FORMAT(" . Ticket::getTable() . ".date, " . $DB->quoteValue($this->period_sort) . ") as period"), + new QueryExpression("DATE_FORMAT(" . Ticket::getTable() . ".date, " . $DB->quoteValue($this->period_label) . ") as period_name"), + Ticket::getTable() . '.status', + ], + 'COUNT' => 'nb', + 'FROM' => Ticket::getTable(), + 'WHERE' => [ + Ticket::getTable() . '.is_deleted' => 0, + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Ticket::getTable() . '.status' => $status_to_show, + ], + 'ORDER' => [Ticket::getTable() . '.date ASC'], + 'GROUPBY' => ['period', Ticket::getTable() . '.status'], + 'ORDER' => ['period', Ticket::getTable() . '.status'], + ]; + + $query['WHERE']['AND'] = $delay; + + $result = $DB->request($query); + foreach ($result as $data) { $status = Ticket::getStatus(intval($data['status'])); $datas['labels2'][$data['period']] = $data['period_name']; $datas['datas'][$status][$data['period']] = $data['nb']; @@ -700,29 +796,39 @@ public function reportSunburstTicketByCategories($config = []) $_SESSION['mreporting_selector']['reportSunburstTicketByCategories'] = ['dateinterval']; //Init delay value - $this->sql_date = PluginMreportingCommon::getSQLDate( - 'glpi_tickets.date', - $config['delay'], - $config['randname'], - ); + $delay = PluginMreportingCommon::getCriteriaDate('glpi_tickets.date', $config['delay'], $config['randname']); $flat_datas = []; $datas = []; - $query = "SELECT glpi_tickets.itilcategories_id as id, - glpi_itilcategories.name as name, - glpi_itilcategories.itilcategories_id as parent, - COUNT(glpi_tickets.id) as count - FROM glpi_tickets - LEFT JOIN glpi_itilcategories - ON glpi_itilcategories.id = glpi_tickets.itilcategories_id - WHERE {$this->sql_date} - AND glpi_tickets.entities_id IN ({$this->where_entities}) - AND glpi_tickets.is_deleted = '0' - GROUP BY glpi_itilcategories.id - ORDER BY glpi_itilcategories.name"; - $res = $DB->doQuery($query); - while ($data = $DB->fetchAssoc($res)) { + $query = [ + 'SELECT' => [ + Ticket::getTable() . '.itilcategories_id as id', + ITILCategory::getTable() . '.name as name', + ITILCategory::getTable() . '.itilcategories_id as parent', + ], + 'COUNT' => 'count', + 'FROM' => Ticket::getTable(), + 'LEFT JOIN' => [ + ITILCategory::getTable() => [ + 'ON' => [ + ITILCategory::getTable() . '.id', + Ticket::getTable() . '.itilcategories_id', + ] + ] + ], + 'WHERE' => [ + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Ticket::getTable() . '.is_deleted' => 0, + ], + 'ORDER' => [ITILCategory::getTable() . '.name'], + 'GROUPBY' => [ITILCategory::getTable() . '.id'], + ]; + + $query['WHERE']['AND'] = $delay; + + $result = $DB->request($query); + foreach ($result as $data) { $flat_datas[$data['id']] = $data; } @@ -759,33 +865,50 @@ public function reportVstackbarTicketStatusByTechnician($config = []) $datas = []; //Init delay value - $this->sql_date = PluginMreportingCommon::getSQLDate( - 'glpi_tickets.date', - $config['delay'], - $config['randname'], - ); + $delay = PluginMreportingCommon::getCriteriaDate('glpi_tickets.date', $config['delay'], $config['randname']); $status = $this->filters['open']['status'] + $this->filters['close']['status']; $status_keys = array_keys($status); //get technician list $technicians = []; - $query = "SELECT - CONCAT(glpi_users.firstname, ' ', glpi_users.realname) as fullname, - glpi_users.name as username - FROM glpi_tickets - INNER JOIN glpi_tickets_users - ON glpi_tickets_users.tickets_id = glpi_tickets.id - AND glpi_tickets_users.type = 2 - INNER JOIN glpi_users - ON glpi_users.id = glpi_tickets_users.users_id - WHERE {$this->sql_date} - AND glpi_tickets.entities_id IN ({$this->where_entities}) - AND glpi_tickets.is_deleted = '0' - ORDER BY fullname, username"; - $result = $DB->doQuery($query); - - while ($technician = $DB->fetchAssoc($result)) { + + $query = [ + 'SELECT' => [ + new QueryExpression("CONCAT(" . User::getTable() . ".firstname, ' ', " . User::getTable() . ".realname) as fullname"), + User::getTable() . ".name as username", + ], + 'FROM' => Ticket::getTable(), + 'INNER JOIN' => [ + Ticket_User::getTable() => [ + 'FKEY' => [ + Ticket_User::getTable() . '.tickets_id', + Ticket::getTable() . '.id', + [ + 'AND' => [ + Ticket_User::getTable() . '.type' => Ticket_User::ASSIGN + ] + ] + ] + ], + User::getTable() => [ + 'FKEY' => [ + User::getTable() . '.id', + Ticket_User::getTable() . '.users_id', + ] + ] + ], + 'WHERE' => [ + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Ticket::getTable() . '.is_deleted' => 0, + ], + 'ORDER' => ['fullname, username'] + ]; + + $query['WHERE']['AND'] = $delay; + + $result = $DB->request($query); + foreach ($result as $technician) { $technicians[] = ['username' => $technician['username'], 'fullname' => $technician['fullname'], ]; @@ -805,24 +928,45 @@ public function reportVstackbarTicketStatusByTechnician($config = []) } } - $query = "SELECT glpi_tickets.status, - CONCAT(glpi_users.firstname, ' ', glpi_users.realname) as technician, - glpi_users.name as username, - COUNT(glpi_tickets.id) as count - FROM glpi_tickets - INNER JOIN glpi_tickets_users - ON glpi_tickets_users.tickets_id = glpi_tickets.id - AND glpi_tickets_users.type = 2 - INNER JOIN glpi_users - ON glpi_users.id = glpi_tickets_users.users_id - WHERE {$this->sql_date} - AND glpi_tickets.entities_id IN ({$this->where_entities}) - AND glpi_tickets.is_deleted = '0' - GROUP BY status, technician - ORDER BY technician, username"; - $result = $DB->doQuery($query); - - while ($ticket = $DB->fetchAssoc($result)) { + $query = [ + "SELECT" => [ + Ticket::getTable() . '.status', + new QueryExpression("CONCAT(" . User::getTable() . ".firstname, ' ', " . User::getTable() . ".realname) as technician"), + User::getTable() . '.name as username', + ], + 'COUNT' => 'count', + 'FROM' => Ticket::getTable(), + 'INNER JOIN' => [ + Ticket_User::getTable() => [ + 'FKEY' => [ + Ticket_User::getTable() . '.tickets_id', + Ticket::getTable() . '.id', + [ + 'AND' => [ + Ticket_User::getTable() . '.type' => Ticket_User::ASSIGN + ] + ] + ] + ], + User::getTable() => [ + 'FKEY' => [ + User::getTable() . '.id', + Ticket_User::getTable() . '.users_id', + ] + ] + ], + 'WHERE' => [ + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Ticket::getTable() . '.is_deleted' => 0, + ], + 'GROUPBY' => [Ticket::getTable() . '.status', 'username'], + 'ORDER' => ['technician', 'username'], + ]; + + $query['WHERE']['AND'] = $delay; + + $result = $DB->request($query); + foreach ($result as $ticket) { if (empty($ticket['technician'])) { $ticket['technician'] = __('None'); } @@ -841,34 +985,53 @@ public function reportHbarTicketNumberByLocation($config = []) = ['dateinterval', 'limit']; //Init delay value - $this->sql_date = PluginMreportingCommon::getSQLDate( - '`glpi_tickets`.`date`', - $config['delay'], - $config['randname'], - ); + $delay = PluginMreportingCommon::getCriteriaDate('glpi_tickets.date', $config['delay'], $config['randname']); $datas = []; + $limit = (isset($_REQUEST['glpilist_limit'])) ? $_REQUEST['glpilist_limit'] : 20; + + $query = [ + "SELECT" => [ + Location::getTable() . '.name', + ], + 'COUNT' => 'count', + 'FROM' => Ticket::getTable(), + 'LEFT JOIN' => [ + Ticket_User::getTable() => [ + 'FKEY' => [ + Ticket_User::getTable() . '.tickets_id', + Ticket::getTable() . '.id', + [ + 'AND' => [ + Ticket_User::getTable() . '.type' => Ticket_User::REQUESTER + ], + ], + ], + ], + User::getTable() => [ + 'FKEY' => [ + User::getTable() . '.id', + Ticket_User::getTable() . '.users_id', + ], + ], + Location::getTable() => [ + 'FKEY' => [ + Location::getTable() . '.id', + User::getTable() . '.locations_id', + ], + ], + ], + 'WHERE' => [ + Ticket::getTable() . '.is_deleted' => 0, + ], + 'GROUPBY' => [Location::getTable() . '.name'], + 'ORDER' => ['count DESC'], + 'LIMIT' => '0, ' . $limit, + ]; + $query['WHERE']['AND'] = $delay; - $query = "SELECT COUNT(glpi_tickets.id) as count, - glpi_locations.name as name - FROM glpi_tickets - LEFT JOIN glpi_tickets_users - ON (glpi_tickets.id = glpi_tickets_users.tickets_id - AND glpi_tickets_users.type = 1) - LEFT JOIN glpi_users - ON (glpi_tickets_users.users_id = glpi_users.id) - LEFT JOIN glpi_locations - ON (glpi_locations.id = glpi_users.locations_id) - WHERE {$this->sql_date} - AND glpi_tickets.is_deleted = '0' - GROUP BY glpi_locations.name - ORDER BY count DESC - LIMIT 0, "; - $query .= (isset($_REQUEST['glpilist_limit'])) ? $_REQUEST['glpilist_limit'] : 20; - - $result = $DB->doQuery($query); - - while ($ticket = $DB->fetchAssoc($result)) { + $result = $DB->request($query); + foreach ($result as $ticket) { if (empty($ticket['name'])) { $label = __('None'); } else { From 2abd7ac13295a9fb47398accdedba6117d4b492b Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Tue, 27 May 2025 16:48:46 +0200 Subject: [PATCH 15/24] change doQuery --- inc/common.class.php | 21 ++ inc/helpdeskplus.class.php | 475 +++++++++++++++++-------- inc/inventory.class.php | 686 +++++++++++++++++++++++-------------- inc/other.class.php | 238 ++++++++++--- 4 files changed, 977 insertions(+), 443 deletions(-) diff --git a/inc/common.class.php b/inc/common.class.php index c49905ac..0ee7ac55 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -1645,6 +1645,27 @@ public static function getSQLEntityLevel($field = '`glpi_entities`.`level`') return $where_entities_level; } + /** + * Get criteria condition to filter entity depth by level. + * @param string $field the sql table field to compare + * @return string sql condition + */ + public static function getCriteriaEntityLevel($field = '`glpi_entities`.`level`') + { + if (isset($_SESSION['mreporting_values']['entitylevel'])) { + $maxlevel = $_SESSION['mreporting_values']['entitylevel']; + } else { + $maxlevel = self::getMaxEntityLevel(); + } + + $default_level = self::getActiveEntityLevel(); + + return [ + $field => ['<=', $maxlevel], + $field => ['>=', $default_level], + ]; + } + /** * Get active entity level according to GLPi SESSION * @return integer default entity level diff --git a/inc/helpdeskplus.class.php b/inc/helpdeskplus.class.php index 5373b3f5..8fc9e8c4 100644 --- a/inc/helpdeskplus.class.php +++ b/inc/helpdeskplus.class.php @@ -35,17 +35,28 @@ class PluginMreportingHelpdeskplus extends PluginMreportingBaseclass { protected $sql_group_assign; + protected $criteria_group_assign; protected $sql_group_request; + protected $criteria_group_request; protected $sql_user_assign; + protected $criteria_user_assign; protected $sql_type; + protected $criteria_type; protected $sql_itilcat; + protected $criteria_itilcat; protected $sql_join_cat; + protected $criteria_join_cat; protected $sql_join_g; + protected $criteria_join_g; protected $sql_join_u; + protected $criteria_join_u; protected $sql_join_tt; protected $sql_join_tu; + protected $criteria_join_tu; protected $sql_join_gt; + protected $criteria_join_gt; protected $sql_join_gtr; + protected $criteria_join_gtr; protected $sql_select_sla; protected $lcl_slaok; protected $lcl_slako; @@ -55,27 +66,100 @@ public function __construct($config = []) /** @var array $LANG */ global $LANG; $this->sql_group_assign = '1=1'; + $this->criteria_group_assign = []; $this->sql_group_request = '1=1'; + $this->criteria_group_request = []; $this->sql_user_assign = '1=1'; - $this->sql_type = 'glpi_tickets.type IN (' . Ticket::INCIDENT_TYPE . ', ' . Ticket::DEMAND_TYPE . ')'; + $this->criteria_user_assign = []; + $this->sql_type = 'glpi_tickets.type IN (' . Ticket::INCIDENT_TYPE . ', ' . Ticket::DEMAND_TYPE . ')'; + $this->criteria_type = [ + Ticket::getTable() . '.type' => [ + Ticket::INCIDENT_TYPE, + Ticket::DEMAND_TYPE + ], + ]; $this->sql_itilcat = '1=1'; + $this->criteria_itilcat = []; $this->sql_join_cat = 'LEFT JOIN glpi_itilcategories cat ON glpi_tickets.itilcategories_id = cat.id'; + $this->criteria_join_cat = [ + ITILCategory::getTable() => [ + 'FKEY' => [ + ITILCategory::getTable() . '.id', + Ticket::getTable() . '.itilcategories_id', + ], + ], + ]; $this->sql_join_g = 'LEFT JOIN glpi_groups g ON gt.groups_id = g.id'; + $this->criteria_join_g = [ + Group::getTable() => [ + 'FKEY' => [ + Group::getTable() . '.id', + Group_Ticket::getTable() . '.groups_id', + ], + ], + ]; $this->sql_join_u = 'LEFT JOIN glpi_users u ON tu.users_id = u.id'; + $this->criteria_join_u = [ + User::getTable() => [ + 'FKEY' => [ + User::getTable() . '.id', + Ticket_User::getTable() . '.users_id', + ], + ], + ]; $this->sql_join_tt = 'LEFT JOIN glpi_tickettasks tt ON tt.tickets_id = glpi_tickets.id'; $this->sql_join_tu = 'LEFT JOIN glpi_tickets_users tu ON tu.tickets_id = glpi_tickets.id AND tu.type = ' . Ticket_User::ASSIGN; + $this->criteria_join_tu = [ + Ticket_User::getTable() => [ + 'FKEY' => [ + Ticket_User::getTable() . '.tickets_id', + Ticket::getTable() . '.id', + [ + 'AND' => [ + Ticket_User::getTable() . '.type' => Ticket_User::ASSIGN + ], + ], + ], + ], + ]; $this->sql_join_gt = 'LEFT JOIN glpi_groups_tickets gt ON gt.tickets_id = glpi_tickets.id AND gt.type = ' . Group_Ticket::ASSIGN; + $this->criteria_join_gt = [ + Group_Ticket::getTable() => [ + 'FKEY' => [ + Group_Ticket::getTable() . '.tickets_id', + Ticket::getTable() . '.id', + [ + 'AND' => [ + Group_Ticket::getTable() . '.type' => Group_Ticket::ASSIGN + ], + ], + ], + ], + ]; $this->sql_join_gtr = 'LEFT JOIN glpi_groups_tickets gtr ON gtr.tickets_id = glpi_tickets.id AND gtr.type = ' . Group_Ticket::REQUESTER; + $this->criteria_join_gtr = [ + Group_Ticket::getTable() => [ + 'FKEY' => [ + Group_Ticket::getTable() . '.tickets_id', + Ticket::getTable() . '.id', + [ + 'AND' => [ + Group_Ticket::getTable() . '.type' => Group_Ticket::REQUESTER + ], + ], + ], + ], + ]; $this->sql_select_sla = "CASE WHEN glpi_slas.definition_time = 'day' AND glpi_tickets.solve_delay_stat <= glpi_slas.number_time * 86400 THEN 'ok' @@ -102,6 +186,9 @@ public function __construct($config = []) } elseif ($mr_values['groups_assign_id'] > 0) { $this->sql_group_assign = 'gt.groups_id = ' . $mr_values['groups_assign_id']; } + $this->criteria_group_assign = [ + Group_Ticket::getTable() . '.groups_id' => $mr_values['groups_assign_id'], + ]; } if (isset($mr_values['groups_request_id'])) { @@ -111,6 +198,9 @@ public function __construct($config = []) } elseif ($mr_values['groups_request_id'] > 0) { $this->sql_group_request = 'gt.groups_id = ' . $mr_values['groups_request_id']; } + $this->criteria_group_assign = [ + Group_Ticket::getTable() . '.groups_id' => $mr_values['groups_request_id'], + ]; } if ( @@ -118,6 +208,9 @@ public function __construct($config = []) && $mr_values['users_assign_id'] > 0 ) { $this->sql_user_assign = 'tu.users_id = ' . $mr_values['users_assign_id']; + $this->criteria_user_assign = [ + Ticket_User::getTable() . '.users_id' => $mr_values['users_assign_id'], + ]; } if ( @@ -125,6 +218,9 @@ public function __construct($config = []) && $mr_values['type'] > 0 ) { $this->sql_type = 'glpi_tickets.type = ' . $mr_values['type']; + $this->criteria_type = [ + Ticket::getTable() . '.type' => $mr_values['type'] + ]; } if ( @@ -132,6 +228,9 @@ public function __construct($config = []) && $mr_values['itilcategories_id'] > 0 ) { $this->sql_itilcat = 'glpi_tickets.itilcategories_id = ' . $mr_values['itilcategories_id']; + $this->criteria_itilcat = [ + Ticket::getTable() . '.itilcategories_id' => $mr_values['itilcategories_id'], + ]; } } @@ -338,30 +437,66 @@ public function reportVstackbarLifetime($config = []) $_SESSION['mreporting_values']['date2' . $config['randname']] = date('Y-m-d'); } + //Init delay value + $delay = PluginMreportingCommon::getCriteriaDate('glpi_tickets.date', $config['delay'], $config['randname']); + foreach ($this->status as $current_status) { if ($_SESSION['mreporting_values']['status_' . $current_status] == '1') { $status_name = Ticket::getStatus($current_status); - $sql_status = "SELECT - DISTINCT DATE_FORMAT(date, '{$this->period_sort}') as period, - DATE_FORMAT(date, '{$this->period_label}') as period_name, - COUNT(DISTINCT glpi_tickets.id) as nb - FROM glpi_tickets - {$this->sql_join_tu} - {$this->sql_join_gt} - {$this->sql_join_gtr} - WHERE {$this->sql_date_create} - AND glpi_tickets.entities_id IN ({$this->where_entities}) - AND glpi_tickets.is_deleted = '0' - AND glpi_tickets.status = $current_status - AND {$this->sql_type} - AND {$this->sql_itilcat} - AND {$this->sql_group_assign} - AND {$this->sql_group_request} - AND {$this->sql_user_assign} - GROUP BY period - ORDER BY period"; - $res = $DB->doQuery($sql_status); - while ($data = $DB->fetchAssoc($res)) { + + $query = [ + "SELECT" => [ + new QueryExpression("DATE_FORMAT(" . Ticket::getTable() . ".date, " . $DB->quoteValue($this->period_sort) . ") as period"), + new QueryExpression("DATE_FORMAT(" . Ticket::getTable() . ".date, " . $DB->quoteValue($this->period_label) . ") as period_name"), + ], + 'COUNT' => 'nb', + 'FROM' => Ticket::getTable(), + 'LEFT JOIN' => [ + Ticket_User::getTable() => [ + 'FKEY' => [ + Ticket_User::getTable() . '.tickets_id', + Ticket::getTable() . '.id', + [ + 'AND' => [ + Ticket_User::getTable() . '.type' => Ticket_User::ASSIGN + ], + ], + ], + ], + Group_Ticket::getTable() => [ + 'FKEY' => [ + Group_Ticket::getTable() . '.tickets_id', + Ticket::getTable() . '.id', + [ + 'AND' => [ + 'OR' => [ + Group_Ticket::getTable() . '.type' => Group_Ticket::REQUESTER, + Group_Ticket::getTable() . '.type' => Group_Ticket::ASSIGN, + ], + ], + ], + ], + ], + ], + 'WHERE' => array_merge( + [ + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Ticket::getTable() . '.is_deleted' => 0, + Ticket::getTable() . '.status' => $current_status, + ], + $this->criteria_type, + $this->criteria_itilcat, + $this->criteria_group_assign, + $this->criteria_group_request, + $this->criteria_user_assign, + ), + 'GROUPBY' => ['period'], + 'ORDER' => ['period'], + ]; + $query['WHERE']['AND'] = $delay; + + $result = $DB->request($query); + foreach ($result as $data) { $tab[$data['period']][$status_name] = $data['nb']; $labels2[$data['period']] = $data['period_name']; } @@ -391,26 +526,40 @@ public function reportVstackbarTicketsgroups($config = []) $_SESSION['mreporting_values']['date2' . $config['randname']] = date('Y-m-d'); } + //Init delay value + $delay = PluginMreportingCommon::getCriteriaDate('glpi_tickets.date', $config['delay'], $config['randname']); + foreach ($this->status as $current_status) { if ($_SESSION['mreporting_values']['status_' . $current_status] == '1') { $status_name = Ticket::getStatus($current_status); - $sql_status = "SELECT - DISTINCT g.completename AS group_name, - COUNT(DISTINCT glpi_tickets.id) AS nb - FROM glpi_tickets - {$this->sql_join_gt} - {$this->sql_join_g} - WHERE {$this->sql_date_create} - AND glpi_tickets.entities_id IN ({$this->where_entities}) - AND glpi_tickets.is_deleted = '0' - AND glpi_tickets.status = $current_status - AND {$this->sql_type} - AND {$this->sql_itilcat} - AND {$this->sql_group_assign} - GROUP BY group_name - ORDER BY group_name"; - $res = $DB->doQuery($sql_status); - while ($data = $DB->fetchAssoc($res)) { + + $query = [ + "SELECT" => [ + Group::getTable() . '.completename as group_name' + ], + 'COUNT' => 'nb', + 'FROM' => Ticket::getTable(), + 'LEFT JOIN' => array_merge( + $this->criteria_join_gt, + $this->criteria_join_g + ), + 'WHERE' => array_merge( + [ + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Ticket::getTable() . '.is_deleted' => 0, + Ticket::getTable() . '.status' => $current_status, + ], + $this->criteria_type, + $this->criteria_itilcat, + $this->criteria_group_assign, + ), + 'GROUPBY' => ['group_name'], + 'ORDER' => ['group_name'], + ]; + $query['WHERE']['AND'] = $delay; + + $result = $DB->request($query); + foreach ($result as $data) { if (empty($data['group_name'])) { $data['group_name'] = __('None'); } @@ -447,28 +596,37 @@ public function reportVstackbarTicketstech($config = []) if ($_SESSION['mreporting_values']['status_' . $current_status] == '1') { $status_name = Ticket::getStatus($current_status); - $sql_create = "SELECT - DISTINCT CONCAT(u.firstname, ' ', u.realname) AS completename, - u.name as name, - u.id as u_id, - COUNT(DISTINCT glpi_tickets.id) AS nb - FROM glpi_tickets - {$this->sql_join_tu} - {$this->sql_join_gt} - {$this->sql_join_gtr} - {$this->sql_join_u} - WHERE {$this->sql_date_create} - AND glpi_tickets.entities_id IN ({$this->where_entities}) - AND glpi_tickets.is_deleted = '0' - AND glpi_tickets.status = $current_status - AND {$this->sql_group_assign} - AND {$this->sql_group_request} - AND {$this->sql_type} - AND {$this->sql_itilcat} - GROUP BY name - ORDER BY name"; - $res = $DB->doQuery($sql_create); - while ($data = $DB->fetchAssoc($res)) { + $query = [ + "SELECT" => [ + new QueryExpression("CONCAT(" . User::getTable() . ".firstname, ' ', " . User::getTable() . ".realname) as completename"), + User::getTable() . '.name as name', + User::getTable() . '.id as u_id', + ], + 'COUNT' => 'nb', + 'FROM' => Ticket::getTable(), + 'LEFT JOIN' => array_merge( + $this->criteria_join_tu, + $this->criteria_join_gt, + $this->criteria_join_gtr, + $this->criteria_join_u, + ), + 'WHERE' => array_merge( + [ + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Ticket::getTable() . '.is_deleted' => 0, + Ticket::getTable() . '.status' => $current_status, + ], + $this->criteria_group_assign, + $this->criteria_group_request, + $this->criteria_type, + $this->criteria_itilcat, + ), + 'GROUPBY' => ['name'], + 'ORDER' => ['name'], + ]; + + $result = $DB->request($query); + foreach ($result as $data) { $data['name'] = empty($data['completename']) ? __('None') : $data['completename']; if (!isset($tab[$data['name']][$status_name])) { @@ -497,32 +655,44 @@ public function reportHbarTopcategory($config = []) $_SESSION['mreporting_selector']['reportHbarTopcategory'] = ['dateinterval', 'limit', 'userassign', 'multiplegrouprequest', 'multiplegroupassign', 'type']; - $tab = []; $datas = []; - $sql_create = "SELECT DISTINCT glpi_tickets.itilcategories_id, - COUNT(DISTINCT glpi_tickets.id) as nb, - cat.completename - FROM glpi_tickets - {$this->sql_join_cat} - {$this->sql_join_tu} - {$this->sql_join_gt} - {$this->sql_join_gtr} - WHERE {$this->sql_date_create} - AND glpi_tickets.entities_id IN ({$this->where_entities}) - AND glpi_tickets.is_deleted = '0' - AND {$this->sql_type} - AND {$this->sql_group_assign} - AND {$this->sql_group_request} - AND {$this->sql_user_assign} - GROUP BY cat.completename - ORDER BY nb DESC - LIMIT 0, "; - $sql_create .= (isset($_SESSION['mreporting_values']['glpilist_limit'])) - ? $_SESSION['mreporting_values']['glpilist_limit'] : 20; - - $res = $DB->doQuery($sql_create); - while ($data = $DB->fetchAssoc($res)) { + //Init delay value + $delay = PluginMreportingCommon::getCriteriaDate('glpi_tickets.date', $config['delay'], $config['randname']); + $limit = isset($_SESSION['mreporting_values']['glpilist_limit']) ? '0, ' . $_SESSION['mreporting_values']['glpilist_limit'] : '0, 20'; + + $query = [ + "SELECT" => [ + Ticket::getTable() . '.itilcategories_id', + ITILCategory::getTable() . '.completename', + ], + 'COUNT' => 'nb', + 'FROM' => Ticket::getTable(), + 'LEFT JOIN' => array_merge( + $this->criteria_join_cat, + $this->criteria_join_tu, + $this->criteria_join_gt, + $this->criteria_join_gtr, + ), + 'WHERE' => array_merge( + [ + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Ticket::getTable() . '.is_deleted' => 0, + ], + $this->criteria_type, + $this->criteria_group_assign, + $this->criteria_group_request, + $this->criteria_itilcat, + $this->criteria_user_assign, + ), + 'GROUPBY' => [ITILCategory::getTable() . '.completename'], + 'ORDER' => ['nb DESC'], + 'LIMIT' => $limit, + ]; + $query['WHERE']['AND'] = $delay; + + $result = $DB->request($query); + foreach ($result as $data) { if (empty($data['completename'])) { $data['completename'] = __('None'); } @@ -539,27 +709,38 @@ public function reportHbarTopapplicant($config = []) $_SESSION['mreporting_selector']['reportHbarTopapplicant'] = ['dateinterval', 'limit', 'type']; - $tab = []; $datas = []; - $sql_create = "SELECT DISTINCT gt.groups_id, - COUNT(DISTINCT glpi_tickets.id) AS nb, - g.completename - FROM glpi_tickets - {$this->sql_join_gt} - {$this->sql_join_g} - WHERE {$this->sql_date_create} - AND {$this->sql_type} - AND glpi_tickets.entities_id IN ({$this->where_entities}) - AND glpi_tickets.is_deleted = '0' - GROUP BY g.completename - ORDER BY nb DESC - LIMIT 0, "; - $sql_create .= (isset($_SESSION['mreporting_values']['glpilist_limit'])) - ? $_SESSION['mreporting_values']['glpilist_limit'] : 20; - - $res = $DB->doQuery($sql_create); - while ($data = $DB->fetchAssoc($res)) { + //Init delay value + $delay = PluginMreportingCommon::getCriteriaDate('glpi_tickets.date', $config['delay'], $config['randname']); + $limit = isset($_SESSION['mreporting_values']['glpilist_limit']) ? '0, ' . $_SESSION['mreporting_values']['glpilist_limit'] : '0, 20'; + + $query = [ + "SELECT" => [ + Group_Ticket::getTable() . '.groups_id', + Group::getTable() . '.completename', + ], + 'COUNT' => 'nb', + 'FROM' => Ticket::getTable(), + 'LEFT JOIN' => array_merge( + $this->criteria_join_gt, + $this->criteria_join_g, + ), + 'WHERE' => array_merge( + [ + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Ticket::getTable() . '.is_deleted' => 0, + ], + $this->criteria_type, + ), + 'GROUPBY' => [Group::getTable() . '.completename'], + 'ORDER' => ['nb DESC'], + 'LIMIT' => $limit, + ]; + $query['WHERE']['AND'] = $delay; + + $result = $DB->request($query); + foreach ($result as $data) { if (empty($data['completename'])) { $data['completename'] = __('None'); } @@ -581,39 +762,63 @@ public function reportVstackbarGroupChange($config = []) $datas = []; - $query = "SELECT COUNT(DISTINCT ticc.id) as nb_ticket, - ticc.nb_add_group - 1 as nb_add_group - FROM ( - SELECT - glpi_tickets.id, - COUNT(glpi_tickets.id) as nb_add_group - FROM glpi_tickets - LEFT JOIN glpi_logs logs_tic - ON logs_tic.itemtype = 'Ticket' - AND logs_tic.items_id = glpi_tickets.id - AND logs_tic.itemtype_link = 'Group' - AND logs_tic.linked_action = 15 /* add action */ - {$this->sql_join_cat} - {$this->sql_join_tu} - {$this->sql_join_gt} - {$this->sql_join_gtr} - WHERE {$this->sql_date_create} - AND glpi_tickets.entities_id IN ({$this->where_entities}) - AND glpi_tickets.is_deleted = '0' - AND {$this->sql_type} - AND {$this->sql_group_assign} - AND {$this->sql_group_request} - AND {$this->sql_user_assign} - AND {$this->sql_itilcat} - GROUP BY glpi_tickets.id - HAVING nb_add_group > 0 - ) as ticc - GROUP BY ticc.nb_add_group"; - - $result = $DB->doQuery($query); + //Init delay value + $delay = PluginMreportingCommon::getCriteriaDate('glpi_tickets.date', $config['delay'], $config['randname']); + + $subquery = [ + "SELECT" => [ + Ticket::getTable() . '.id', + ], + 'COUNT' => 'nb_add_group', + 'FROM' => Ticket::getTable(), + 'LEFT JOIN' => array_merge( + [ + Log::getTable() => [ + 'FKEY' => [ + Log::getTable() . '.items_id', + Ticket::getTable() . '.id', + [ + 'AND' => [ + Log::getTable() . '.itemtype' => 'Ticket', + Log::getTable() . '.itemtype_link' => Group::class, + log::getTable() . '.linked_action' => 15, + ] + ], + ], + ], + ], + $this->criteria_join_cat, + $this->criteria_join_tu, + $this->criteria_join_gt, + $this->criteria_join_gtr, + ), + 'WHERE' => array_merge( + [ + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Ticket::getTable() . '.is_deleted' => 0, + ], + $this->criteria_type, + $this->criteria_group_assign, + $this->criteria_group_request, + $this->criteria_user_assign, + $this->criteria_itilcat, + ), + 'GROUPBY' => [Ticket::getTable() . '.id'], + 'HAVING' => [ + 'nb_add_group' => ['>', 0], + ], + ]; + $subquery['WHERE']['AND'] = $delay; + $query = [ + 'SELECT' => [new QueryExpression('ticc.nb_add_group - 1 as nb_add_group')], + 'COUNT' => 'nb_ticket', + 'FROM' => new \QuerySubQuery($subquery, 'ticc'), + 'GROUPBY' => ['ticc.nb_add_group'], + ]; + $result = $DB->request($query); $datas['datas'] = []; - while ($ticket = $DB->fetchAssoc($result)) { + foreach ($result as $ticket) { $datas['labels2'][$ticket['nb_add_group']] = $ticket['nb_add_group']; $datas['datas'][__('Number of tickets')][$ticket['nb_add_group']] = $ticket['nb_ticket']; } diff --git a/inc/inventory.class.php b/inc/inventory.class.php index d1444abf..ca280341 100644 --- a/inc/inventory.class.php +++ b/inc/inventory.class.php @@ -1,5 +1,7 @@ $_SESSION['mreporting_values']['states_id']]; + } + + return []; + } + /* ==== MANUFACTURERS REPORTS ==== */ public function reportPieComputersByFabricant($config = []) { @@ -115,32 +126,60 @@ public function computersByFabricant($config = []) /** @var \DBmysql $DB */ global $DB; - $sql_entities = " AND c.`entities_id` IN ({$this->where_entities})"; - $sql_states = self::getStateCondition('c.states_id'); - - $query = "SELECT m.`name` as Manufacturer, - count(*) as Total, - count(*) * 100 / (SELECT count(*) - FROM glpi_computers as c, - glpi_manufacturers as m - WHERE c.`is_deleted` = 0 - AND c.`is_template` = 0 - AND c.`manufacturers_id` = m.`id` - $sql_entities - $sql_states) as Percent - FROM glpi_computers as c, - glpi_manufacturers as m - WHERE c.`manufacturers_id` = m.`id` - $sql_entities - $sql_states - AND c.`is_deleted` = 0 - AND c.`is_template` = 0 - GROUP BY m.`name` - ORDER BY Total DESC"; - $result = $DB->doQuery($query); + $criteria_states = self::getCriteriaStateCondition(Computer::getTable() . '.states_id'); + + $subquery = [ + 'SELECT' => [ + new QueryExpression("COUNT(*)"), + ], + 'FROM' => Computer::getTable(), + 'LEFT JOIN' => [ + Manufacturer::getTable() => [ + 'ON' => [ + Manufacturer::getTable() . '.id', + Computer::getTable() . '.manufacturers_id', + ] + ] + ], + 'WHERE' => array_merge( + [ + Computer::getTable() . '.is_template' => 0, + Computer::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + ], $criteria_states + ), + ]; + + $query = [ + 'SELECT' => [ + Manufacturer::getTable() . '.name as Manufacturer', + new QueryExpression("COUNT(*) * 100 / " . new QuerySubQuery($subquery, 'Percent')), + ], + 'COUNT' => 'Total', + 'FROM' => Computer::getTable(), + 'LEFT JOIN' => [ + Manufacturer::getTable() => [ + 'ON' => [ + Manufacturer::getTable() . '.id', + Computer::getTable() . '.manufacturers_id', + ] + ] + ], + 'WHERE' => array_merge( + [ + Computer::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Computer::getTable() . '.is_deleted' => 0, + Computer::getTable() . '.is_template' => 0, + ], + $criteria_states), + 'GROUPBY' => [ + Manufacturer::getTable() . '.name', + ], + 'ORDER' => ['Total DESC'], + ]; + $result = $DB->request($query); $datas = []; - while ($computer = $DB->fetchAssoc($result)) { + foreach ($result as $computer) { if ($computer['Total']) { $percent = round(floatval($computer['Percent']), 2); $datas['datas'][$computer['Manufacturer'] . " ($percent %)"] = $computer['Total']; @@ -170,30 +209,60 @@ public function computersByType($config = []) /** @var \DBmysql $DB */ global $DB; - $sql_entities = " AND c.`entities_id` IN ({$this->where_entities})"; - $sql_states = self::getStateCondition('c.states_id'); - $query = "SELECT t.`name` as Type, - count(*) as Total, - count(*) * 100 / (SELECT count(*) - FROM glpi_computers as c, - glpi_computertypes as t - WHERE c.`is_deleted` = 0 - AND c.`is_template` = 0 - AND c.`computertypes_id` = t.`id` - $sql_entities - $sql_states) as Percent - FROM glpi_computers as c, - glpi_computertypes as t - WHERE c.`computertypes_id` = t.`id` - $sql_entities - $sql_states - AND c.`is_deleted` = 0 - AND c.`is_template` = 0 - GROUP BY t.`name` - ORDER BY Total DESC"; - $result = $DB->doQuery($query); + $criteria_states = self::getCriteriaStateCondition(Computer::getTable() . '.states_id'); + + $subquery = [ + 'SELECT' => [ + new QueryExpression("COUNT(*)"), + ], + 'FROM' => Computer::getTable(), + 'LEFT JOIN' => [ + ComputerType::getTable() => [ + 'ON' => [ + ComputerType::getTable() . '.id', + Computer::getTable() . '.computertypes_id', + ] + ] + ], + 'WHERE' => array_merge( + [ + Computer::getTable() . '.is_template' => 0, + Computer::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + ], $criteria_states + ), + ]; + + $query = [ + 'SELECT' => [ + ComputerType::getTable() . '.name as Type', + new QueryExpression("COUNT(*) * 100 / " . new QuerySubQuery($subquery, 'Percent')), + ], + 'COUNT' => 'Total', + 'FROM' => Computer::getTable(), + 'LEFT JOIN' => [ + ComputerType::getTable() => [ + 'ON' => [ + ComputerType::getTable() . '.id', + Computer::getTable() . '.computertypes_id', + ] + ] + ], + 'WHERE' => array_merge( + [ + Computer::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Computer::getTable() . '.is_deleted' => 0, + Computer::getTable() . '.is_template' => 0, + ], + $criteria_states), + 'GROUPBY' => [ + ComputerType::getTable() . '.name', + ], + 'ORDER' => ['Total DESC'], + ]; + $result = $DB->request($query); + $datas = []; - while ($computer = $DB->fetchAssoc($result)) { + foreach ($result as $computer) { $percent = round(floatval($computer['Percent']), 2); $datas['datas'][$computer['Type'] . " ($percent %)"] = $computer['Total']; } @@ -221,105 +290,86 @@ public function computersByAge($config = []) /** @var \DBmysql $DB */ global $DB; - $sql_entities = " AND c.`entities_id` IN ({$this->where_entities})"; - $sql_states = self::getStateCondition('c.states_id'); + $criteria_states = self::getCriteriaStateCondition(Computer::getTable() . '.states_id'); $datas = []; - $query = "SELECT '< 1 year' Age, count(*) Total, count(*) * 100 / (SELECT count(*) - FROM glpi_computers as c, - glpi_infocoms as i - WHERE c.`id` = i.`items_id` - AND c.`is_deleted` = 0 - AND c.`is_template` = 0 - AND itemtype = 'Computer' - $sql_entities - $sql_states) Percent - FROM glpi_computers as c, - glpi_infocoms as i - WHERE c.`id` = i.`items_id` - AND c.`is_deleted` = 0 - AND c.`is_template` = 0 - AND itemtype = 'Computer' - AND i.`warranty_date` > CURRENT_DATE - INTERVAL 1 YEAR - $sql_entities - $sql_states - UNION - SELECT '1-3 years' Age, count(*) Total, count(*) * 100 / (SELECT count(*) - FROM glpi_computers c, glpi_infocoms i - WHERE c.`id` = i.`items_id` - AND c.`is_deleted` = 0 - AND c.`is_template` = 0 - AND itemtype = 'Computer' - $sql_entities - $sql_states) Percent - FROM glpi_computers as c, - glpi_infocoms as i - WHERE c.`id` = i.`items_id` - AND c.`is_deleted` = 0 - AND c.`is_template` = 0 - AND itemtype = 'Computer' - AND i.`warranty_date` <= CURRENT_DATE - INTERVAL 1 YEAR - AND i.`warranty_date` > CURRENT_DATE - INTERVAL 3 YEAR - $sql_entities - $sql_states - UNION - SELECT '3-5 years' Age, count(*) Total, count(*) * 100 / (SELECT count(*) - FROM glpi_computers c, glpi_infocoms i - WHERE c.`id` = i.`items_id` - AND c.`is_deleted` = 0 - AND c.`is_template` = 0 - AND itemtype = 'Computer' - $sql_entities - $sql_states) Percent - FROM glpi_computers as c, - glpi_infocoms as i - WHERE c.`id` = i.`items_id` - AND c.`is_deleted` = 0 - AND c.`is_template` = 0 - AND itemtype = 'Computer' - AND i.`warranty_date` <= CURRENT_DATE - INTERVAL 3 YEAR - AND i.`warranty_date` > CURRENT_DATE - INTERVAL 5 YEAR - $sql_entities - $sql_states - UNION - SELECT '> 5 years' Age, count(*) Total, count(*) * 100 / (SELECT count(*) - FROM glpi_computers c, glpi_infocoms i - WHERE c.`id` = i.`items_id` - AND c.`is_deleted` = 0 - AND c.`is_template` = 0 - AND itemtype = 'Computer' - $sql_entities - $sql_states) Percent - FROM glpi_computers as c, - glpi_infocoms as i - WHERE c.`id` = i.`items_id` - AND c.`is_deleted` = 0 - AND c.`is_template` = 0 - AND itemtype = 'Computer' - AND i.`warranty_date` <= CURRENT_DATE - INTERVAL 5 YEAR - $sql_entities - $sql_states - UNION - SELECT 'Undefined' Age, count(*) Total, count(*) * 100 / (SELECT count(*) - FROM glpi_computers c, glpi_infocoms i - WHERE c.`id` = i.`items_id` - AND c.`is_deleted` = 0 - AND c.`is_template` = 0 - AND itemtype = 'Computer' - $sql_entities - $sql_states) Percent - FROM glpi_computers as c, - glpi_infocoms as i - WHERE c.`id` = i.`items_id` - AND c.`is_deleted` = 0 - AND c.`is_template` = 0 - AND itemtype = 'Computer' - AND i.`warranty_date` IS NULL - $sql_entities - $sql_states"; - $result = $DB->doQuery($query); - - while ($computer = $DB->fetchAssoc($result)) { + $param_requests = [ + "'< 1 year' AS Age" => [ + ['>', new QueryExpression('CURRENT_DATE - INTERVAL 1 YEAR')], + ], + "'1-3 year' AS Age" => [ + ['<=', new QueryExpression('CURRENT_DATE - INTERVAL 1 YEAR')], + ['>', new QueryExpression('CURRENT_DATE - INTERVAL 3 YEAR')], + ], + "'3-5 year' AS Age" => [ + ['<=', new QueryExpression('CURRENT_DATE - INTERVAL 3 YEAR')], + ['>', new QueryExpression('CURRENT_DATE - INTERVAL 5 YEAR')], + ], + "'> 5 year' AS Age" => [ + ['<=', new QueryExpression('CURRENT_DATE - INTERVAL 5 YEAR')], + ], + "'Undefined' AS Age" => [ + new QueryExpression(Infocom::getTable() . '.warranty_date IS NULL'), + ], + ]; + + $subquery = [ + 'SELECT' => [ + new QueryExpression("COUNT(*)"), + ], + 'FROM' => Computer::getTable(), + 'LEFT JOIN' => [ + Infocom::getTable() => [ + 'ON' => [ + Infocom::getTable() . '.items_id', + Computer::getTable() . '.id', + ] + ] + ], + 'WHERE' => array_merge( + [ + Computer::getTable() . '.is_deleted' => 0, + Computer::getTable() . '.is_template' => 0, + Infocom::getTable() . '.itemtype' => 'Computer', + Computer::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + ], $criteria_states + ), + ]; + + $queries = []; + + foreach ($param_requests as $label => $criterias) { + $query_union = [ + 'SELECT' => [ + new QueryExpression($label), + new QueryExpression("COUNT(*) * 100 / " . new QuerySubQuery($subquery, 'Percent')), + ], + 'COUNT' => 'Total', + 'FROM' => Computer::getTable(), + 'LEFT JOIN' => [ + Infocom::getTable() => [ + 'ON' => [ + Infocom::getTable() . '.items_id', + Computer::getTable() . '.id', + ] + ] + ], + 'WHERE' => [ + Computer::getTable() . '.is_deleted' => 0, + Computer::getTable() . '.is_template' => 0, + Infocom::getTable() . '.itemtype' => 'Computer', + ], + ]; + foreach ($criterias as $criteria) { + $query_union['WHERE'] = array_merge($query_union['WHERE'], [Infocom::getTable() . '.warranty_date' => $criteria]); + } + $queries[] = $query_union; + } + + $query = new \QueryUnion($queries); + $result = $DB->request($query); + + foreach ($result as $computer) { $percent = round(floatval($computer['Percent']), 2); $datas['datas'][__($computer['Age'], 'mreporting') . " ($percent %)"] = $computer['Total']; @@ -348,8 +398,7 @@ public function computersByOS($config = []) /** @var \DBmysql $DB */ global $DB; - $sql_entities = " AND c.`entities_id` IN ({$this->where_entities})"; - $sql_states = self::getStateCondition('c.states_id'); + $criteria_states = self::getCriteriaStateCondition(Computer::getTable() . '.states_id'); $oses = ['Windows' => 'Windows', 'Linux' => 'Linux|Ubuntu|openSUSE', 'Solaris' => 'Solaris', @@ -360,64 +409,107 @@ public function computersByOS($config = []) 'Android' => 'Android', 'HP-UX' => 'HP-UX', ]; - $query = ''; - $first = true; - $notlike = ''; + $notlike = []; + + $queries = []; + + $subquery = [ + 'SELECT' => [ + new QueryExpression("COUNT(*)") + ], + 'FROM' => Computer::getTable(), + 'LEFT JOIN' => [ + Item_OperatingSystem::getTable() => [ + 'ON' => [ + Item_OperatingSystem::getTable() . '.items_id', + Computer::getTable() . '.id', + ] + ], + OperatingSystem::getTable() => [ + 'ON' => [ + OperatingSystem::getTable() . '.id', + Item_OperatingSystem::getTable() . '.operatingsystems_id', + ] + ], + ], + 'WHERE' => array_merge([ + Computer::getTable() . '.is_deleted' => 0, + Computer::getTable() . '.is_template' => 0, + Item_OperatingSystem::getTable() . '.itemtype' => 'Computer', + Computer::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + ], $criteria_states), + ]; + foreach ($oses as $os => $search) { - $query .= (!$first ? ' UNION ' : '') - . "\n SELECT '$os' AS OS, count(*) AS Total, count(*) * 100 / (SELECT count(*) - FROM glpi_computers as c, - glpi_operatingsystems as os, - glpi_items_operatingsystems as ios - WHERE c.`is_deleted`='0' AND c.`is_template`='0' - AND ios.`operatingsystems_id` = os.`id` - AND ios.items_id = c.id - AND ios.itemtype = 'Computer' - $sql_entities - $sql_states) AS Percent - FROM glpi_computers as c, - glpi_operatingsystems as os, - glpi_items_operatingsystems as ios - WHERE ios.`operatingsystems_id` = os.`id` - AND ios.items_id = c.id - AND ios.itemtype = 'Computer' - AND c.`is_deleted`='0' - AND c.`is_template`='0' - AND os.`name` REGEXP '$search' - $sql_entities - $sql_states"; - - $notlike .= " AND os.`name` NOT REGEXP '$search'"; - $first = false; + $queries[] = [ + 'SELECT' => [ + new QueryExpression("'$os'" . " AS OS"), + new QueryExpression("COUNT(*) * 100 / " . new QuerySubQuery($subquery, 'Percent')), + ], + 'COUNT' => 'Total', + 'FROM' => Computer::getTable(), + 'LEFT JOIN' => [ + Item_OperatingSystem::getTable() => [ + 'ON' => [ + Item_OperatingSystem::getTable() . '.items_id', + Computer::getTable() . '.id', + ] + ], + OperatingSystem::getTable() => [ + 'ON' => [ + OperatingSystem::getTable() . '.id', + Item_OperatingSystem::getTable() . '.operatingsystems_id', + ] + ], + ], + 'WHERE' => array_merge([ + Item_OperatingSystem::getTable() . '.itemtype' => 'Computer', + Computer::getTable() . '.is_deleted' => 0, + Computer::getTable() . '.is_template' => 0, + new QueryExpression(OperatingSystem::getTable() . ".name REGEXP '" . $search . "'"), + Computer::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + ], $criteria_states), + ]; + + $notlike[] = new QueryExpression(OperatingSystem::getTable() . ".name NOT REGEXP '" . $search . "'"); } - $query .= " UNION - SELECT '" . __('Others') . "' AS OS, count(*) Total, count(*) * 100 / (SELECT count(*) - FROM glpi_computers as c, - glpi_operatingsystems as os, - glpi_items_operatingsystems as ios - WHERE c.`is_deleted`= 0 - AND c.`is_template`=0 - AND ios.`operatingsystems_id` = os.`id` - AND ios.items_id = c.id - $sql_entities - $sql_states) as Percent - FROM glpi_computers as c, - glpi_operatingsystems as os, - glpi_items_operatingsystems as ios - WHERE ios.`operatingsystems_id` = os.`id` - AND ios.items_id = c.id - AND ios.itemtype = 'Computer' - AND c.`is_deleted` = 0 - AND c.`is_template`=0 - $notlike - $sql_entities - $sql_states"; - - $query .= ' ORDER BY Total DESC'; - $result = $DB->doQuery($query); + + $queries[] = [ + 'SELECT' => [ + new QueryExpression("'" . __('Others') . "' AS OS"), + new QueryExpression("COUNT(*) * 100 / " . new QuerySubQuery($subquery, 'Percent')), + ], + 'COUNT' => 'Total', + 'FROM' => Computer::getTable(), + 'LEFT JOIN' => [ + Item_OperatingSystem::getTable() => [ + 'ON' => [ + Item_OperatingSystem::getTable() . '.items_id', + Computer::getTable() . '.id', + ] + ], + OperatingSystem::getTable() => [ + 'ON' => [ + OperatingSystem::getTable() . '.id', + Item_OperatingSystem::getTable() . '.operatingsystems_id', + ] + ], + ], + 'WHERE' => array_merge([ + Item_OperatingSystem::getTable() . '.itemtype' => 'Computer', + Computer::getTable() . '.is_deleted' => 0, + Computer::getTable() . '.is_template' => 0, + Computer::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + $notlike, + ], $criteria_states), + 'ORDER' => ['Total DESC'], + ]; + + $query = new \QueryUnion($queries); + $result = $DB->request($query); $datas = []; - while ($computer = $DB->fetchAssoc($result)) { + foreach ($result as $computer) { $percent = round(floatval($computer['Percent']), 2); if ($computer['Total']) { $datas['datas'][$computer['OS'] . " ($percent %)"] = $computer['Total']; @@ -782,19 +874,29 @@ public function reportHbarMonitors($config = []) global $DB; $_SESSION['mreporting_selector']['reportHbarMonitors'] = ['multiplestates']; - $sql_states = self::getStateCondition('c.`states_id`'); - - $query = "SELECT COUNT(*) AS cpt - FROM `glpi_computers_items` AS ci, - `glpi_computers` AS c - WHERE `ci`.`itemtype` = 'Monitor' - AND `c`.`is_deleted` = '0' - AND `ci`.`computers_id` = c.`id` - AND `c`.`is_template` = '0' - AND c.`entities_id` IN ({$this->where_entities}) - $sql_states - GROUP BY `ci`.`computers_id` - ORDER BY `cpt`"; + $criteria_states = self::getCriteriaStateCondition(Computer::getTable() . '.states_id'); + + $query = [ + 'COUNT' => 'cpt', + 'FROM' => Computer::getTable(), + 'LEFT JOIN' => [ + Computer_Item::getTable() => [ + 'ON' => [ + Computer_Item::getTable() . '.computers_id', + Computer::getTable() . '.id', + ] + ] + ], + 'WHERE' => array_merge([ + Computer_Item::getTable() . '.itemtype' => 'Monitor', + Computer::getTable() . '.is_deleted' => 0, + Computer::getTable() . '.is_template' => '0', + Computer::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + ], $criteria_states), + 'GROUPBY' => [Computer_Item::getTable() . '.computers_id'], + 'ORDER' => ['cpt'], + ]; + $data = []; foreach ($DB->request($query) as $result) { $label = $result['cpt'] . ' ' . _n('Monitor', 'Monitors', $result['cpt']); @@ -813,23 +915,52 @@ public function reportHbarComputersByStatus($config = []) /** @var \DBmysql $DB */ global $DB; - $query = "SELECT t.`name` status, count(*) Total, count(*) * 100 / (SELECT count(*) - FROM glpi_computers as c, - glpi_states as t - WHERE c.`states_id` = t.`id` - AND c.`entities_id` IN ({$this->where_entities}) - AND c.`is_deleted` = 0 - AND c.`is_template` = 0) Percent - FROM glpi_computers as c, - glpi_states as t - WHERE c.`states_id` = t.`id` - AND c.`entities_id` IN ({$this->where_entities}) - AND c.`is_deleted` = 0 - AND c.`is_template` = 0 - GROUP BY t.`name`"; - $result = $DB->doQuery($query); + $subquery = [ + 'SELECT' => [ + new QueryExpression("COUNT(*)") + ], + 'FROM' => Computer::getTable(), + 'LEFT JOIN' => [ + State::getTable() => [ + 'ON' => [ + State::getTable() . '.id', + Computer::getTable() . '.states_id', + ] + ] + ], + 'WHERE' => [ + Computer::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Computer::getTable() . '.is_deleted' => 0, + Computer::getTable() . '.is_template' => 0, + ], + ]; + + $query = [ + 'SELECT' => [ + State::getTable() . '.name as status', + new QueryExpression("COUNT(*) * 100 / " . new QuerySubQuery($subquery, 'Percent')), + ], + 'COUNT' => 'Total', + 'FROM' => Computer::getTable(), + 'LEFT JOIN' => [ + State::getTable() => [ + 'ON' => [ + State::getTable() . '.id', + Computer::getTable() . '.states_id', + ] + ] + ], + 'WHERE' => [ + Computer::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Computer::getTable() . '.is_deleted' => 0, + Computer::getTable() . '.is_template' => 0, + ], + 'GROUPBY' => [State::getTable() . '.name'], + ]; + + $result = $DB->request($query); $datas = []; - while ($computer = $DB->fetchAssoc($result)) { + foreach ($result as $computer) { $percent = round(floatval($computer['Percent']), 2); $datas['datas'][$computer['status'] . " ($percent %)"] = $computer['Total']; } @@ -846,17 +977,52 @@ public function reportHbarPrintersByStatus($config = []) $condition = ' AND c.entities_id IN (' . $this->where_entities . ')'; - $query = "SELECT t.name status, count(*) Total, count(*)*100/( - SELECT count(*) - FROM glpi_printers c, glpi_states t - WHERE c.`is_deleted`=0 AND c.`is_template`=0 - AND c.states_id = t.id $condition) Pourcentage - FROM glpi_printers c, glpi_states t - WHERE c.states_id = t.id $condition AND c.`is_deleted`=0 AND c.`is_template`=0 - GROUP BY t.name"; - $result = $DB->doQuery($query); - - while ($printer = $DB->fetchAssoc($result)) { + $subquery = [ + 'SELECT' => [ + new QueryExpression("COUNT(*)") + ], + 'FROM' => Printer::getTable(), + 'LEFT JOIN' => [ + State::getTable() => [ + 'ON' => [ + State::getTable() . '.id', + Printer::getTable() . '.states_id', + ] + ] + ], + 'WHERE' => [ + Printer::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Printer::getTable() . '.is_deleted' => 0, + Printer::getTable() . '.is_template' => 0, + ], + ]; + + $query = [ + 'SELECT' => [ + State::getTable() . '.name as status', + new QueryExpression("COUNT(*) * 100 / " . new QuerySubQuery($subquery, 'Pourcentage')), + ], + 'COUNT' => 'Total', + 'FROM' => Printer::getTable(), + 'LEFT JOIN' => [ + State::getTable() => [ + 'ON' => [ + State::getTable() . '.id', + Printer::getTable() . '.states_id', + ] + ] + ], + 'WHERE' => [ + Printer::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Printer::getTable() . '.is_deleted' => 0, + Printer::getTable() . '.is_template' => 0, + ], + 'GROUPBY' => [State::getTable() . '.name'], + ]; + + $result = $DB->request($query); + + foreach ($result as $printer) { $pourcentage = round(floatval($printer['Pourcentage']), 2); $datas['datas'][$printer['status'] . " ($pourcentage %)"] = $printer['Total']; } @@ -875,7 +1041,7 @@ public function reportHbarComputersByEntity($config = []) 'entityLevel', ]; - $this->where_entities_level = PluginMreportingCommon::getSQLEntityLevel('`glpi_entities`.`level`'); + $entities_level = PluginMreportingCommon::getCriteriaEntityLevel('`glpi_entities`.`level`'); $datas = []; @@ -883,13 +1049,19 @@ public function reportHbarComputersByEntity($config = []) $entity->getFromDB($_SESSION['glpiactive_entity']); $entities_first_level = [$_SESSION['glpiactive_entity'] => $entity->getName()]; - $query = "SELECT `id`, `name` - FROM `glpi_entities` - WHERE {$this->where_entities_level} - ORDER BY `name`"; - $result = $DB->doQuery($query); + $query = [ + 'SELECT' => [ + Entity::getTable() . '.id', + Entity::getTable() . '.name', + ], + 'FROM' => Entity::getTable(), + 'WHERE' => $entities_level, + 'ORDER' => ['name'], + ]; + + $result = $DB->request($query); - while ($data = $DB->fetchAssoc($result)) { + foreach ($result as $data) { $entities_first_level[$data['id']] = $data['name']; } $entities = []; @@ -899,14 +1071,18 @@ public function reportHbarComputersByEntity($config = []) } else { $restrict = 'IN (' . implode(',', getSonsOf('glpi_entities', $entities_id)) . ')'; } - $query = 'SELECT count(*) Total - FROM `glpi_computers` - WHERE `entities_id` ' . $restrict . ' - AND `is_deleted` = 0 - AND `is_template` = 0'; - $result = $DB->doQuery($query); - - while ($computer = $DB->fetchAssoc($result)) { + $query = [ + 'COUNT' => 'Total', + 'FROM' => Computer::getTable(), + 'WHERE' => [ + Computer::getTable() . '.entities_id' => getSonsOf(Entity::getTable(), $entities_id), + Computer::getTable() . '.is_deleted' => 0, + Computer::getTable() . '.is_template' => 0, + ], + ]; + $result = $DB->request($query); + + foreach ($result as $computer) { $datas['tmp'][$entities_name . ' (pourcentage %)'] = $computer['Total']; $entities[$entities_name . ' (pourcentage %)'] = $entities_id; } diff --git a/inc/other.class.php b/inc/other.class.php index 4570105e..4b0ee040 100644 --- a/inc/other.class.php +++ b/inc/other.class.php @@ -1,5 +1,7 @@ 'cpt', + 'FROM' => Log::getTable(), + ]; //Add/remove a software on a computer - $query_computer_software = "$prefix `linked_action` IN (4,5)"; - - $query_software_version = "$prefix `itemtype`='Software' - AND `itemtype_link`='SoftwareVersion' - AND `linked_action` IN (17, 18, 19)"; - $query_add_infocom = "$prefix `itemtype`='Software' - AND `itemtype_link`='Infocom' - AND `linked_action` IN (17)"; - $query_user_profiles = "$prefix `itemtype`='User' - AND `itemtype_link`='Profile_User' - AND `linked_action` IN (17, 18, 19)"; - $query_user_groups = "$prefix `itemtype`='User' - AND `itemtype_link`='Group_User' - AND `linked_action` IN (17, 18, 19)"; - - $query_user_deleted = "$prefix `itemtype`='User' AND `linked_action` IN (12)"; - - $query_ocs = "$prefix `linked_action` IN (8, 9, 10, 11)"; - $query_device = "$prefix `linked_action` IN (1, 2, 3, 6, 7)"; - $query_relation = "$prefix `linked_action` IN (15, 16)"; - $query_item = "$prefix `linked_action` IN (13, 14, 17, 18, 19, 20)"; - $query_other = "$prefix `id_search_option` IN (16, 19)"; + $query_computer_software = array_merge( + $prefix2, + [ + 'WHERE' => [ + Log::getTable() . '.linked_action' => [4, 5], + ] + ], + ); + + $query_software_version = array_merge( + $prefix2, + [ + 'WHERE' => [ + Log::getTable() . '.itemtype' => 'Software', + Log::getTable() . '.itemtype_link' => 'SoftwareVersion', + Log::getTable() . '.linked_action' => [17, 18, 19], + ] + ], + ); + + $query_add_infocom = array_merge( + $prefix2, + [ + 'WHERE' => [ + Log::getTable() . '.itemtype' => 'Software', + Log::getTable() . '.itemtype_link' => 'Infocom', + Log::getTable() . '.linked_action' => [17], + ] + ], + ); + + $query_user_profiles = array_merge( + $prefix2, + [ + 'WHERE' => [ + Log::getTable() . '.itemtype' => 'User', + Log::getTable() . '.itemtype_link' => 'Profile_User', + Log::getTable() . '.linked_action' => [17, 18, 19], + ] + ], + ); + + $query_user_groups = array_merge( + $prefix2, + [ + 'WHERE' => [ + Log::getTable() . '.itemtype' => 'User', + Log::getTable() . '.itemtype_link' => 'Group_User', + Log::getTable() . '.linked_action' => [17, 18, 19], + ] + ], + ); + + $query_user_deleted = array_merge( + $prefix2, + [ + 'WHERE' => [ + Log::getTable() . '.itemtype' => 'User', + Log::getTable() . '.linked_action' => [12], + ] + ], + ); + + $query_ocs = array_merge( + $prefix2, + [ + 'WHERE' => [ + Log::getTable() . '.linked_action' => [8, 9, 10, 11], + ] + ], + ); + + $query_device = array_merge( + $prefix2, + [ + 'WHERE' => [ + Log::getTable() . '.linked_action' => [1, 2, 3, 6, 7], + ] + ], + ); + + $query_relation = array_merge( + $prefix2, + [ + 'WHERE' => [ + Log::getTable() . '.linked_action' => [15, 16], + ] + ], + ); + + $query_item = array_merge( + $prefix2, + [ + 'WHERE' => [ + Log::getTable() . '.linked_action' => [13, 14, 17, 18, 19, 20], + ] + ], + ); + + $query_other = array_merge( + $prefix2, + [ + 'WHERE' => [ + Log::getTable() . '.id_search_option' => [16, 19], + ] + ], + ); $datas = []; - $result = $DB->doQuery($query_computer_software); - $datas['datas'][__('Add/remove software on a computer', 'mreporting')] = $DB->result($result, 0, 'cpt'); + $result = $DB->request($query_computer_software); + foreach ($result as $data) { + $datas['datas'][__('Add/remove software on a computer', 'mreporting')] = $data['cpt']; + } - $result = $DB->doQuery($query_software_version); - $datas['datas'][__('Add/remove version on a software', 'mreporting')] = $DB->result($result, 0, 'cpt'); + $result = $DB->request($query_software_version); + foreach ($result as $data) { + $datas['datas'][__('Add/remove version on a software', 'mreporting')] = $data['cpt']; + } - $result = $DB->doQuery($query_add_infocom); - $datas['datas'][__('Add infocom', 'mreporting')] = $DB->result($result, 0, 'cpt'); + $result = $DB->request($query_add_infocom); + foreach ($result as $data) { + $datas['datas'][__('Add infocom', 'mreporting')] = $data['cpt']; + } - $result = $DB->doQuery($query_user_profiles); - $datas['datas'][__('Add/remove profile on a user', 'mreporting')] = $DB->result($result, 0, 'cpt'); + $result = $DB->request($query_user_profiles); + foreach ($result as $data) { + $datas['datas'][__('Add/remove profile on a user', 'mreporting')] = $data['cpt']; + } - $result = $DB->doQuery($query_user_groups); - $datas['datas'][__('Add/remove group on a user', 'mreporting')] = $DB->result($result, 0, 'cpt'); + $result = $DB->request($query_user_groups); + foreach ($result as $data) { + $datas['datas'][__('Add/remove group on a user', 'mreporting')] = $data['cpt']; + } - $result = $DB->doQuery($query_user_deleted); - $datas['datas'][__('User deleted from LDAP', 'mreporting')] = $DB->result($result, 0, 'cpt'); + $result = $DB->request($query_user_deleted); + foreach ($result as $data) { + $datas['datas'][__('User deleted from LDAP', 'mreporting')] = $data['cpt']; + } $plugin = new Plugin(); if ($plugin->isActivated('webservices')) { $query_webservice = "$prefix `itemtype`='PluginWebservicesClient'"; + $query_webservice = array_merge( + $prefix2, + [ + 'WHERE' => [ + Log::getTable() . ".itemtype = 'PluginWebservicesClient'" + ] + ], + ); // Display this information is not usefull if webservices is not activated - $result = $DB->doQuery($query_webservice); - $datas['datas'][__('Webservice logs', 'mreporting')] = $DB->result($result, 0, 'cpt'); + $result = $DB->request($query_webservice); + foreach ($result as $data) { + $datas['datas'][__('Webservice logs', 'mreporting')] = $data['cpt']; + } } - $result = $DB->doQuery($query_ocs); - $datas['datas'][__('OCS Infos', 'mreporting')] = $DB->result($result, 0, 'cpt'); + $result = $DB->request($query_ocs); + foreach ($result as $data) { + $datas['datas'][__('OCS Infos', 'mreporting')] = $data['cpt']; + } - $result = $DB->doQuery($query_device); - $datas['datas'][__('Add/update/remove device', 'mreporting')] = $DB->result($result, 0, 'cpt'); + $result = $DB->request($query_device); + foreach ($result as $data) { + $datas['datas'][__('Add/update/remove device', 'mreporting')] = $data['cpt']; + } - $result = $DB->doQuery($query_relation); - $datas['datas'][__('Add/remove relation', 'mreporting')] = $DB->result($result, 0, 'cpt'); + $result = $DB->request($query_relation); + foreach ($result as $data) { + $datas['datas'][__('Add/remove relation', 'mreporting')] = $data['cpt']; + } - $result = $DB->doQuery($query_item); - $datas['datas'][__('Add/remove item', 'mreporting')] = $DB->result($result, 0, 'cpt'); + $result = $DB->request($query_item); + foreach ($result as $data) { + $datas['datas'][__('Add/remove item', 'mreporting')] = $data['cpt']; + } - $result = $DB->doQuery($query_other); - $datas['datas'][__('Comments & date_mod changes', 'mreporting')] = $DB->result($result, 0, 'cpt'); + $result = $DB->request($query_other); + foreach ($result as $data) { + $datas['datas'][__('Comments & date_mod changes', 'mreporting')] = $data['cpt']; + } $plugin = new Plugin(); if ($plugin->isActivated('genericobject')) { - $query_genericobject = "$prefix `itemtype` LIKE '%PluginGenericobject%'"; + $query_genericobject = array_merge( + $prefix2, + [ + 'WHERE' => [ + new QueryExpression( + Log::getTable() . ".itemtype LIKE '%PluginGenericobject%'" + ), + ] + ], + ); // Display this information is not usefull if genericobject is not activated - $result = $DB->doQuery($query_genericobject); - $datas['datas'][__('Genericobject plugin logs', 'mreporting')] = $DB->result($result, 0, 'cpt'); + $result = $DB->request($query_genericobject); + foreach ($result as $data) { + $datas['datas'][__('Genericobject plugin logs', 'mreporting')] = $data['cpt']; + } } return $datas; From 515fec2c698897f863193b8b02197647c38c7b0b Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Wed, 28 May 2025 16:17:52 +0200 Subject: [PATCH 16/24] change doQuery --- hook.php | 32 +- inc/common.class.php | 48 +- inc/helpdeskplus.class.php | 482 ++++++++++++------- inc/notificationtargetnotification.class.php | 18 +- inc/profile.class.php | 14 +- inc/tag.class.php | 78 ++- 6 files changed, 432 insertions(+), 240 deletions(-) diff --git a/hook.php b/hook.php index a4f713a4..445927b1 100644 --- a/hook.php +++ b/hook.php @@ -96,11 +96,18 @@ function plugin_mreporting_install() ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; // add display preferences - $query_display_pref = "SELECT id - FROM glpi_displaypreferences - WHERE itemtype = 'PluginMreportingConfig'"; - $res_display_pref = $DB->doQueryOrDie($query_display_pref); - if ($DB->numrows($res_display_pref) == 0) { + $query_display_pref = [ + 'SELECT' => [ + 'id', + ], + 'FROM' => DisplayPreference::getTable(), + 'WHERE' => [ + 'itemtype' => 'PluginMreportingConfig', + ], + ]; + + $res_display_pref = $DB->request($query_display_pref); + if ($res_display_pref->numrows() == 0) { $queries[] = "INSERT INTO `glpi_displaypreferences` VALUES (NULL,'PluginMreportingConfig','2','2','0');"; $queries[] = "INSERT INTO `glpi_displaypreferences` @@ -175,8 +182,12 @@ function plugin_mreporting_install() } // == UPDATE to 0.84+1.0 == - $query = 'UPDATE `glpi_plugin_mreporting_profiles` pr SET pr.right = ' . READ . " WHERE pr.right = 'r'"; - $DB->doQueryOrDie($query); + //$query = 'UPDATE `glpi_plugin_mreporting_profiles` pr SET pr.right = ' . READ . " WHERE pr.right = 'r'"; + $DB->updateOrDie( + 'glpi_plugin_mreporting_profiles', + ['right' => READ], + ['right' => 'r'], + ); if (!isIndex('glpi_plugin_mreporting_profiles', 'profiles_id_reports')) { $query = 'ALTER TABLE glpi_plugin_mreporting_profiles ADD UNIQUE INDEX `profiles_id_reports` (`profiles_id`, `reports`)'; @@ -184,8 +195,11 @@ function plugin_mreporting_install() } // Remove GLPI graphtype to fix compatibility with GLPI 9.2.2+ - $query = "UPDATE `glpi_plugin_mreporting_configs` SET `graphtype` = 'SVG' WHERE `graphtype` = 'GLPI'"; - $DB->doQueryOrDie($query); + $DB->updateOrDie( + 'glpi_plugin_mreporting_configs', + ['graphtype' => 'SVG'], + ['graphtype' => 'GLPI'], + ); //== Create directories $rep_files_mreporting = GLPI_PLUGIN_DOC_DIR . '/mreporting'; diff --git a/inc/common.class.php b/inc/common.class.php index 0ee7ac55..016e8750 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -1621,30 +1621,6 @@ public static function selectorEntityLevel() return Dropdown::showFromArray('entitylevel', $values, ['value' => $selected]); } - /** - * Get SQL condition to filter entity depth by level. - * @param string $field the sql table field to compare - * @return string sql condition - */ - public static function getSQLEntityLevel($field = '`glpi_entities`.`level`') - { - if (isset($_SESSION['mreporting_values']['entitylevel'])) { - $maxlevel = $_SESSION['mreporting_values']['entitylevel']; - } else { - $maxlevel = self::getMaxEntityLevel(); - } - - $default_level = self::getActiveEntityLevel(); - - $where_entities_level = "({$field} = {$default_level}"; - for ($i = ($default_level + 1); $i <= $maxlevel; $i++) { - $where_entities_level .= " OR {$field} = {$i}"; - } - $where_entities_level .= ')'; - - return $where_entities_level; - } - /** * Get criteria condition to filter entity depth by level. * @param string $field the sql table field to compare @@ -1691,19 +1667,19 @@ public static function getMaxEntityLevel() /** @var \DBmysql $DB */ global $DB; - if (count($_SESSION['glpiactiveentities']) > 1) { - $restrict = " `id` IN ({$_SESSION['glpiactiveentities_string']})"; - } else { - $restrict = " `id` = {$_SESSION['glpiactiveentities_string']}"; - } - - $query = "SELECT MAX(level) AS 'maxlevel' - FROM glpi_entities - WHERE {$restrict}"; + $query = [ + 'SELECT' => [ + new QueryExpression('MAX(level) as maxlevel'), + ], + 'FROM' => Entity::getTable(), + 'WHERE' => [ + Entity::getTable() . '.id' => $_SESSION['glpiactiveentities'], + ], + ]; - $result = $DB->doQuery($query); - if ($DB->numrows($result) > 0) { - return $DB->result($result, 0, 'maxlevel'); + $result = $DB->request($query); + if ($result->numrows() > 0) { + return $result->current()['maxlevel']; } else { return 0; } diff --git a/inc/helpdeskplus.class.php b/inc/helpdeskplus.class.php index 8fc9e8c4..36e44ef6 100644 --- a/inc/helpdeskplus.class.php +++ b/inc/helpdeskplus.class.php @@ -51,6 +51,7 @@ class PluginMreportingHelpdeskplus extends PluginMreportingBaseclass protected $sql_join_u; protected $criteria_join_u; protected $sql_join_tt; + protected $criteria_join_tt; protected $sql_join_tu; protected $criteria_join_tu; protected $sql_join_gt; @@ -58,6 +59,7 @@ class PluginMreportingHelpdeskplus extends PluginMreportingBaseclass protected $sql_join_gtr; protected $criteria_join_gtr; protected $sql_select_sla; + protected $criteria_select_sla; protected $lcl_slaok; protected $lcl_slako; @@ -112,6 +114,14 @@ public function __construct($config = []) ]; $this->sql_join_tt = 'LEFT JOIN glpi_tickettasks tt ON tt.tickets_id = glpi_tickets.id'; + $this->criteria_join_tt = [ + 'glpi_tickettasks' => [ + 'FKEY' => [ + 'glpi_tickettasks.tickets_id', + Ticket::getTable() . '.id', + ], + ], + ]; $this->sql_join_tu = 'LEFT JOIN glpi_tickets_users tu ON tu.tickets_id = glpi_tickets.id AND tu.type = ' . Ticket_User::ASSIGN; @@ -171,6 +181,19 @@ public function __construct($config = []) THEN 'ok' ELSE 'nok' END AS respected_sla"; + $this->criteria_select_sla = new QueryExpression( + "CASE WHEN glpi_slas.definition_time = 'day' + AND glpi_tickets.solve_delay_stat <= glpi_slas.number_time * 86400 + THEN 'ok' + WHEN glpi_slas.definition_time = 'hour' + AND glpi_tickets.solve_delay_stat <= glpi_slas.number_time * 3600 + THEN 'ok' + WHEN glpi_slas.definition_time = 'minute' + AND glpi_tickets.solve_delay_stat <= glpi_slas.number_time * 60 + THEN 'ok' + ELSE 'nok' + END AS respected_sla" + ); parent::__construct($config); @@ -835,36 +858,58 @@ public function reportLineActiontimeVsSolvedelay($config = []) 'userassign', 'category', 'multiplegroupassign', ]; - $query = "SELECT - DATE_FORMAT(glpi_tickets.date, '{$this->period_sort}') as period, - DATE_FORMAT(glpi_tickets.date, '{$this->period_label}') as period_name, - ROUND(AVG(actiontime_vs_solvedelay.time_percent), 1) as time_percent - FROM glpi_tickets - LEFT JOIN ( - SELECT - glpi_tickets.id AS tickets_id, - (SUM(tt.actiontime) * 100) / glpi_tickets.solve_delay_stat as time_percent - FROM glpi_tickets - {$this->sql_join_tt} - {$this->sql_join_tu} - {$this->sql_join_gt} - {$this->sql_join_gtr} - WHERE glpi_tickets.solve_delay_stat > 0 - AND tt.actiontime IS NOT NULL - AND glpi_tickets.entities_id IN ({$this->where_entities}) - AND glpi_tickets.is_deleted = '0' - AND {$this->sql_date_create} - AND {$this->sql_type} - AND {$this->sql_group_assign} - AND {$this->sql_group_request} - AND {$this->sql_user_assign} - AND {$this->sql_itilcat} - GROUP BY glpi_tickets.id - ) AS actiontime_vs_solvedelay - ON actiontime_vs_solvedelay.tickets_id = glpi_tickets.id - WHERE {$this->sql_date_create} - GROUP BY period - ORDER BY period"; + //Init delay value + $delay = PluginMreportingCommon::getCriteriaDate('glpi_tickets.date', $config['delay'], $config['randname']); + + $subquery = [ + 'SELECT' => [ + Ticket::getTable() . '.id AS tickets_id', + new QueryExpression("SUM(" . TicketTask::getTable() . ".actiontime) * 100 / " . Ticket::getTable() . ".solve_delay_stat as time_percent"), + ], + 'FROM' => Ticket::getTable(), + 'LEFT JOIN' => array_merge( + $this->criteria_join_tt, + $this->criteria_join_tu, + $this->criteria_join_gt, + $this->criteria_join_gtr, + ), + 'WHERE' => array_merge( + [ + Ticket::getTable() . '.solve_delay_stat' => ['>', 0], + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Ticket::getTable() . '.is_deleted' => 0, + ], + $this->criteria_type, + $this->criteria_group_assign, + $this->criteria_group_request, + $this->criteria_user_assign, + $this->criteria_itilcat, + ), + 'GROUPBY' => [Ticket::getTable() . '.id'], + ]; + $subquery['WHERE']['AND'] = $delay; + + $query = [ + 'SELECT' => [ + new QueryExpression("DATE_FORMAT(" . Ticket::getTable() . ".date, " . $DB->quoteValue($this->period_sort) . ") as period"), + new QueryExpression("DATE_FORMAT(" . Ticket::getTable() . ".date, " . $DB->quoteValue($this->period_label) . ") as period_name"), + new QueryExpression("ROUND(AVG(actiontime_vs_solvedelay.time_percent), 1) as time_percent"), + ], + 'FROM' => new \QuerySubQuery($subquery, 'actiontime_vs_solvedelay'), + 'LEFT JOIN' => [ + Ticket::getTable() => [ + 'FKEY' => [ + 'actiontime_vs_solvedelay.tickets_id', + Ticket::getTable() . '.id', + ], + ], + ], + 'WHERE' => [], + 'GROUPBY' => ['period'], + 'ORDER' => ['period'], + ]; + $query['WHERE']['AND'] = $delay; + $data = []; foreach ($DB->request($query) as $result) { $data['datas'][$result['period_name']] = floatval($result['time_percent']); @@ -879,32 +924,46 @@ public function reportGlineNbTicketBySla($config = []) /** @var \DBmysql $DB */ global $DB; - $area = false; $datas = []; $_SESSION['mreporting_selector']['reportGlineNbTicketBySla'] = ['dateinterval', 'period', 'allSlasWithTicket']; + //Init delay value + $delay = PluginMreportingCommon::getCriteriaDate('glpi_tickets.date', $config['delay'], $config['randname']); + if ( isset($_SESSION['mreporting_values']['slas']) && !empty($_SESSION['mreporting_values']['slas']) ) { //get dates used in this period - $query_date = "SELECT DISTINCT DATE_FORMAT(`glpi_tickets`.`date`, '{$this->period_sort}') AS period, - DATE_FORMAT(`glpi_tickets`.`date`, '{$this->period_label}') AS period_name - FROM `glpi_tickets` - INNER JOIN `glpi_slas` - ON `glpi_tickets`.slas_id_ttr = `glpi_slas`.id - WHERE {$this->sql_date_create} - AND `glpi_tickets`.status IN (" . implode(',', array_merge(Ticket::getSolvedStatusArray(), Ticket::getClosedStatusArray())) . ') - AND `glpi_tickets`.`entities_id` IN (' . $this->where_entities . ") - AND `glpi_tickets`.`is_deleted` = '0' - AND `glpi_slas`.id IN (" . implode(',', $_SESSION['mreporting_values']['slas']) . ') - ORDER BY `glpi_tickets`.`date` ASC'; - $res_date = $DB->doQuery($query_date); + $query_date = [ + 'SELECT' => [ + new QueryExpression("DATE_FORMAT(" . Ticket::getTable() . ".date, " . $DB->quoteValue($this->period_sort) . ") as period"), + new QueryExpression("DATE_FORMAT(" . Ticket::getTable() . ".date, " . $DB->quoteValue($this->period_label) . ") as period_name"), + ], + 'FROM' => Ticket::getTable(), + 'INNER JOIN' => [ + SLA::getTable() => [ + 'FKEY' => [ + SLA::getTable() . '.id', + Ticket::getTable() . '.slas_id_ttr', + ], + ], + ], + 'WHERE' => [ + Ticket::getTable() . '.status' => array_merge(Ticket::getSolvedStatusArray(), Ticket::getClosedStatusArray()), + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Ticket::getTable() . '.is_deleted' => 0, + SLA::getTable() . '.id' => $_SESSION['mreporting_values']['slas'], + ], + 'ORDER' => [Ticket::getTable() . '.date ASC'], + ]; + $query_date['WHERE']['AND'] = $delay; + $result = $DB->request($query_date); $dates = []; - while ($data = $DB->fetchAssoc($res_date)) { + foreach ($result as $data) { $dates[$data['period']] = $data['period']; } @@ -913,26 +972,34 @@ public function reportGlineNbTicketBySla($config = []) $tmp_date[] = $id; } - $query = "SELECT DISTINCT - DATE_FORMAT(`glpi_tickets`.`date`, '{$this->period_sort}') AS period, - DATE_FORMAT(`glpi_tickets`.`date`, '{$this->period_label}') AS period_name, - count(`glpi_tickets`.id) AS nb, - `glpi_slas`.name, - {$this->sql_select_sla} - FROM `glpi_tickets` - INNER JOIN `glpi_slas` - ON `glpi_tickets`.slas_id_ttr = `glpi_slas`.id - WHERE {$this->sql_date_create} - AND `glpi_tickets`.status IN (" . implode(',', array_merge(Ticket::getSolvedStatusArray(), Ticket::getClosedStatusArray())) . ') - AND `glpi_tickets`.entities_id IN (' . $this->where_entities . ") - AND `glpi_tickets`.is_deleted = '0'"; - if (isset($_SESSION['mreporting_values']['slas'])) { - $query .= ' AND `glpi_slas`.id IN (' . implode(',', $_SESSION['mreporting_values']['slas']) . ') '; - } - $query .= 'GROUP BY `glpi_slas`.name, period, respected_sla'; + $query = [ + 'SELECT' => [ + new QueryExpression("DATE_FORMAT(" . Ticket::getTable() . ".date, " . $DB->quoteValue($this->period_sort) . ") as period"), + new QueryExpression("DATE_FORMAT(" . Ticket::getTable() . ".date, " . $DB->quoteValue($this->period_label) . ") as period_name"), + SLA::getTable() . '.name', + $this->criteria_select_sla + ], + 'COUNT' => 'nb', + 'FROM' => Ticket::getTable(), + 'INNER JOIN' => [ + SLA::getTable() => [ + 'FKEY' => [ + SLA::getTable() . '.id', + Ticket::getTable() . '.slas_id_ttr', + ], + ], + ], + 'WHERE' => [ + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Ticket::getTable() . '.is_deleted' => 0, + Ticket::getTable() . '.status' => array_merge(Ticket::getSolvedStatusArray(), Ticket::getClosedStatusArray()), + SLA::getTable() . '.id' => $_SESSION['mreporting_values']['slas'] ?? [], + ], + 'GROUPBY' => [SLA::getTable() . '.name', 'period', 'respected_sla'], + ]; - $result = $DB->doQuery($query); - while ($data = $DB->fetchAssoc($result)) { + $result = $DB->request($query); + foreach ($result as $data) { $datas['labels2'][$data['period']] = $data['period_name']; if ($data['respected_sla'] == 'ok') { $value = $this->lcl_slaok; @@ -957,8 +1024,6 @@ public function reportHgbarRespectedSlasByTopCategory($config = []) /** @var \DBmysql $DB */ global $DB; - $area = false; - $_SESSION['mreporting_selector']['reportHgbarRespectedSlasByTopCategory'] = ['dateinterval', 'limit', 'categories']; @@ -976,49 +1041,76 @@ public function reportHgbarRespectedSlasByTopCategory($config = []) $_SESSION['glpilist_limit'] = $category_limit; if (!$category) { - $query_categories = 'SELECT - count(`glpi_tickets`.id) as nb, - `glpi_itilcategories`.id - FROM `glpi_tickets` - INNER JOIN `glpi_slas` - ON `glpi_tickets`.slas_id_ttr = `glpi_slas`.id - INNER JOIN `glpi_itilcategories` - ON `glpi_tickets`.itilcategories_id = `glpi_itilcategories`.id - WHERE ' . $this->sql_date_create . ' - AND `glpi_tickets`.entities_id IN (' . $this->where_entities . ") - AND `glpi_tickets`.is_deleted = '0' - GROUP BY `glpi_itilcategories`.id - ORDER BY nb DESC - LIMIT " . $category_limit; - - $result_categories = $DB->doQuery($query_categories); - while ($data = $DB->fetchAssoc($result_categories)) { + $query_categories = [ + 'SELECT' => [ + ITILCategory::getTable() . '.id', + ], + 'COUNT' => 'nb', + 'FROM' => Ticket::getTable(), + 'INNER JOIN' => [ + SLA::getTable() => [ + 'FKEY' => [ + SLA::getTable() . '.id', + Ticket::getTable() . '.slas_id_ttr', + ], + ], + ITILCategory::getTable() => [ + 'FKEY' => [ + ITILCategory::getTable() . '.id', + Ticket::getTable() . '.itilcategories_id', + ], + ], + ], + 'WHERE' => array_merge( + [ + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Ticket::getTable() . '.is_deleted' => 0, + ], + ), + 'GROUPBY' => [ITILCategory::getTable() . '.id'], + 'ORDER' => ['nb DESC'], + 'LIMIT' => $category_limit, + ]; + + $result_categories = $DB->request($query_categories); + foreach ($result_categories as $data) { $categories[] = $data['id']; } } - $query = "SELECT COUNT(`glpi_tickets`.id) as nb, - {$this->sql_select_sla}, - `glpi_itilcategories`.id, - `glpi_itilcategories`.name - FROM `glpi_tickets` - INNER JOIN `glpi_slas` - ON `glpi_tickets`.slas_id_ttr = `glpi_slas`.id - INNER JOIN `glpi_itilcategories` - ON `glpi_tickets`.itilcategories_id = `glpi_itilcategories`.id - WHERE " . $this->sql_date_create . ' - AND `glpi_tickets`.entities_id IN (' . $this->where_entities . ") - AND `glpi_tickets`.is_deleted = '0'"; - if ($category) { - $query .= ' AND `glpi_itilcategories`.id = ' . $category; - } elseif (!empty($categories)) { - $query .= ' AND `glpi_itilcategories`.id IN (' . implode(',', $categories) . ')'; - } - $query .= ' GROUP BY respected_sla, `glpi_itilcategories`.id - ORDER BY nb DESC'; + $query = [ + 'SELECT' => [ + $this->criteria_select_sla, + ITILCategory::getTable() . '.id', + ITILCategory::getTable() . '.name', + ], + 'COUNT' => 'nb', + 'FROM' => Ticket::getTable(), + 'INNER JOIN' => [ + SLA::getTable() => [ + 'FKEY' => [ + SLA::getTable() . '.id', + Ticket::getTable() . '.slas_id_ttr', + ], + ], + ITILCategory::getTable() => [ + 'FKEY' => [ + ITILCategory::getTable() . '.id', + Ticket::getTable() . '.itilcategories_id', + ], + ], + ], + 'WHERE' => [ + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Ticket::getTable() . '.is_deleted' => 0, + ITILCategory::getTable() . '.id' => $category ? $category : $categories, + ], + 'GROUPBY' => ['respected_sla', ITILCategory::getTable() . '.id'], + 'ORDER' => ['nb DESC'], + ]; - $result = $DB->doQuery($query); - while ($data = $DB->fetchAssoc($result)) { + $result = $DB->request($query); + foreach ($result as $data) { $value = ($data['respected_sla'] == 'ok') ? $this->lcl_slaok : $this->lcl_slako; $datas['datas'][$data['name']][$value] = $data['nb']; @@ -1041,32 +1133,59 @@ public function reportHgbarRespectedSlasByTechnician($config = []) /** @var \DBmysql $DB */ global $DB; - $area = false; $datas = []; $_SESSION['mreporting_selector']['reportHgbarRespectedSlasByTechnician'] = ['dateinterval']; - $query = "SELECT - CONCAT(`glpi_users`.firstname, ' ', `glpi_users`.realname) as fullname, - `glpi_users`.id, - COUNT(`glpi_tickets`.id) as nb, - {$this->sql_select_sla} - FROM `glpi_tickets` - INNER JOIN `glpi_slas` - ON `glpi_tickets`.slas_id_ttr = `glpi_slas`.id - INNER JOIN `glpi_tickets_users` - ON `glpi_tickets_users`.tickets_id = `glpi_tickets`.id - AND `glpi_tickets_users`.type = " . Ticket_User::ASSIGN . ' - INNER JOIN `glpi_users` - ON `glpi_users`.id = `glpi_tickets_users`.users_id - WHERE ' . $this->sql_date_create . " - AND `glpi_tickets`.entities_id IN ({$this->where_entities}) - AND `glpi_tickets`.is_deleted = '0' - GROUP BY respected_sla, `glpi_users`.id - ORDER BY nb DESC"; - - $result = $DB->doQuery($query); - while ($data = $DB->fetchAssoc($result)) { + //Init delay value + $delay = PluginMreportingCommon::getCriteriaDate('glpi_tickets.date', $config['delay'], $config['randname']); + + $query = [ + 'SELECT' => [ + new QueryExpression("CONCAT(" . User::getTable() . ".firstname, ' ', " . User::getTable() . ".realname) as fullname"), + User::getTable() . '.id', + $this->criteria_select_sla, + ], + 'COUNT' => 'nb', + 'FROM' => Ticket::getTable(), + 'INNER JOIN' => [ + SLA::getTable() => [ + 'FKEY' => [ + SLA::getTable() . '.id', + Ticket::getTable() . '.slas_id_ttr', + ], + ], + Ticket_User::getTable() => [ + 'FKEY' => [ + Ticket_User::getTable() . '.tickets_id', + Ticket::getTable() . '.id', + [ + 'AND' => [ + Ticket_User::getTable() . '.type' => Ticket_User::ASSIGN, + ], + ], + ], + ], + User::getTable() => [ + 'FKEY' => [ + User::getTable() . '.id', + Ticket_User::getTable() . '.users_id', + ], + ], + ], + 'WHERE' => array_merge( + [ + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Ticket::getTable() . '.is_deleted' => 0, + ], + ), + 'GROUPBY' => [User::getTable() . '.id', 'respected_sla'], + 'ORDER' => ['nb DESC'], + ]; + $query['WHERE']['AND'] = $delay; + + $result = $DB->request($query); + foreach ($result as $data) { if ($data['respected_sla'] == 'ok') { $value = $this->lcl_slaok; } else { @@ -1177,35 +1296,52 @@ public function reportVstackbarRespectedSlasByGroup($config = []) $_SESSION['mreporting_selector']['reportVstackbarRespectedSlasByGroup'] = ['dateinterval', 'allSlasWithTicket']; - $this->sql_date_create = PluginMreportingCommon::getSQLDate( - '`glpi_tickets`.date', - $config['delay'], - $config['randname'], - ); + //Init delay value + $delay = PluginMreportingCommon::getCriteriaDate('glpi_tickets.date', $config['delay'], $config['randname']); if ( isset($_SESSION['mreporting_values']['slas']) && !empty($_SESSION['mreporting_values']['slas']) ) { - $query = "SELECT COUNT(`glpi_tickets`.id) AS nb, - `glpi_groups_tickets`.groups_id as groups_id, - `glpi_slas`.name, - {$this->sql_select_sla} - FROM `glpi_tickets` - INNER JOIN `glpi_groups_tickets` - ON `glpi_groups_tickets`.tickets_id = `glpi_tickets`.id - AND `glpi_groups_tickets`.type = " . CommonITILActor::ASSIGN . " - INNER JOIN `glpi_slas` - ON `glpi_tickets`.slas_id_ttr = `glpi_slas`.id - WHERE {$this->sql_date_create} - AND `glpi_tickets`.status IN (" . implode(',', array_merge(Ticket::getSolvedStatusArray(), Ticket::getClosedStatusArray())) . ") - AND `glpi_tickets`.entities_id IN ({$this->where_entities}) - AND `glpi_tickets`.is_deleted = '0' - AND `glpi_slas`.id IN (" . implode(',', $_SESSION['mreporting_values']['slas']) . ') - GROUP BY `glpi_groups_tickets`.groups_id, respected_sla;'; - $result = $DB->doQuery($query); - - while ($data = $DB->fetchAssoc($result)) { + $query = [ + 'SELECT' => [ + Group_Ticket::getTable() . '.groups_id as groups_id', + SLA::getTable() . '.name', + $this->sql_select_sla, + ], + 'COUNT' => 'nb', + 'FROM' => Ticket::getTable(), + 'INNER JOIN' => [ + Group_Ticket::getTable() => [ + 'FKEY' => [ + Group_Ticket::getTable() . '.tickets_id', + Ticket::getTable() . '.id', + [ + 'AND' => [ + Group_Ticket::getTable() . '.type' => CommonITILActor::ASSIGN, + ], + ], + ], + ], + SLA::getTable() => [ + 'FKEY' => [ + SLA::getTable() . '.id', + Ticket::getTable() . '.slas_id_ttr', + ], + ], + ], + 'WHERE' => [ + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Ticket::getTable() . '.is_deleted' => 0, + Ticket::getTable() . '.status' => array_merge(Ticket::getSolvedStatusArray(), Ticket::getClosedStatusArray()), + SLA::getTable() . '.id' => $_SESSION['mreporting_values']['slas'], + ], + 'GROUPBY' => ['glpi_groups_tickets.groups_id', 'respected_sla'], + ]; + $query['WHERE']['AND'] = $delay; + + $request = $DB->request($query); + foreach ($request as $data) { $gp = new Group(); $gp->getFromDB((int) $data['groups_id']); @@ -1263,30 +1399,40 @@ public function reportVstackbarNbTicketBySla($config = []) $datas = []; $tmp_datas = []; - $this->sql_date_create = PluginMreportingCommon::getSQLDate( - '`glpi_tickets`.date', - $config['delay'], - $config['randname'], - ); + //Init delay value + $delay = PluginMreportingCommon::getCriteriaDate('glpi_tickets.date', $config['delay'], $config['randname']); if ( isset($_SESSION['mreporting_values']['slas']) && !empty($_SESSION['mreporting_values']['slas']) ) { - $query = "SELECT count(`glpi_tickets`.id) AS nb, `glpi_slas`.name, - {$this->sql_select_sla} - FROM `glpi_tickets` - INNER JOIN `glpi_slas` - ON `glpi_tickets`.slas_id_ttr = `glpi_slas`.id - WHERE {$this->sql_date_create} - AND `glpi_tickets`.status IN (" . implode(',', array_merge(Ticket::getSolvedStatusArray(), Ticket::getClosedStatusArray())) . ") - AND `glpi_tickets`.entities_id IN ({$this->where_entities}) - AND `glpi_tickets`.is_deleted = '0' - AND `glpi_slas`.id IN (" . implode(',', $_SESSION['mreporting_values']['slas']) . ') - GROUP BY `glpi_slas`.name, respected_sla;'; - - $result = $DB->doQuery($query); - while ($data = $DB->fetchAssoc($result)) { + $query = [ + 'SELECT' => [ + SLA::getTable() . '.name', + $this->sql_select_sla, + ], + 'COUNT' => 'nb', + 'FROM' => Ticket::getTable(), + 'INNER JOIN' => [ + SLA::getTable() => [ + 'FKEY' => [ + SLA::getTable() . '.id', + Ticket::getTable() . '.slas_id_ttr', + ], + ], + ], + 'WHERE' => [ + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Ticket::getTable() . '.is_deleted' => 0, + Ticket::getTable() . '.status' => array_merge(Ticket::getSolvedStatusArray(), Ticket::getClosedStatusArray()), + SLA::getTable() . '.id' => $_SESSION['mreporting_values']['slas'], + ], + 'GROUPBY' => [SLA::getTable() . '.name', 'respected_sla'], + ]; + $query['WHERE']['AND'] = $delay; + + $result = $DB->request($query); + foreach ($result as $data) { $tmp_datas[$data['name']][$data['respected_sla']] = $data['nb']; } diff --git a/inc/notificationtargetnotification.class.php b/inc/notificationtargetnotification.class.php index 33d78c12..744c30d9 100644 --- a/inc/notificationtargetnotification.class.php +++ b/inc/notificationtargetnotification.class.php @@ -87,13 +87,21 @@ private function buildPDF($user_name = '') $images = []; - $result = $DB->doQuery('SELECT id, name, classname, default_delay - FROM glpi_plugin_mreporting_configs - WHERE is_notified = 1 - AND is_active = 1'); + $query = [ + 'SELECT' => [ + 'id', 'name', 'classname', 'default_delay', + ], + 'FROM' => PluginMreportingConfig::getTable(), + 'WHERE' => [ + 'is_notified' => 1, + 'is_active' => 1, + ], + ]; + + $result = $DB->request($query); $graphs = []; - while ($graph = $result->fetch_array()) { + foreach ($result as $graph) { $type = preg_split('/(?<=\\w)(?=[A-Z])/', $graph['name']); $graphs[] = [ diff --git a/inc/profile.class.php b/inc/profile.class.php index 46425547..9ecddd34 100644 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -101,13 +101,17 @@ public function getFromDBByProfile($profiles_id) /** @var \DBmysql $DB */ global $DB; - $query = "SELECT * FROM `{$this->getTable()}` - WHERE `profiles_id` = '" . $profiles_id . "'"; - if ($result = $DB->doQuery($query)) { - if ($DB->numrows($result) != 1) { + $query = [ + 'FROM' => $this->getTable(), + 'WHERE' => [ + 'profiles_id' => $profiles_id, + ], + ]; + if ($result = $DB->request($query)) { + if ($result->numrows() != 1) { return false; } - $this->fields = $DB->fetchAssoc($result); + $this->fields = $result->current(); return (is_array($this->fields) && count($this->fields)); } diff --git a/inc/tag.class.php b/inc/tag.class.php index 2195b9e2..d633808b 100644 --- a/inc/tag.class.php +++ b/inc/tag.class.php @@ -50,12 +50,26 @@ public function reportPieTag($config = []) $datas = []; - $result = $DB->doQuery('SELECT COUNT(*) as count_tag, glpi_plugin_tag_tags.name as name - FROM glpi_plugin_tag_tagitems - LEFT JOIN glpi_plugin_tag_tags ON plugin_tag_tags_id = glpi_plugin_tag_tags.id - GROUP BY plugin_tag_tags_id - ORDER BY count_tag DESC'); - while ($datas_tag = $DB->fetchAssoc($result)) { + $query = [ + 'SELECT' => [ + PluginTagTag::getTable() . '.name AS name', + ], + 'COUNT' => 'count_tag', + 'FROM' => PluginTagTagItem::getTable(), + 'LEFT JOIN' => [ + PluginTagTag::getTable() => [ + 'ON' => [ + PluginTagTag::getTable() . '.id', + PluginTagTagItem::getTable() . '.plugin_tag_tags_id', + ] + ], + ], + 'GROUPBY' => PluginTagTagItem::getTable() . '.plugin_tag_tags_id', + 'ORDERBY' => 'count_tag DESC', + ]; + + $result = $DB->request($query); + foreach ($result as $datas_tag) { $label = $datas_tag['name']; $datas['datas'][$label] = $datas_tag['count_tag']; } @@ -81,20 +95,50 @@ public function reportPieTagOnTicket($config = []) $_SESSION['mreporting_selector'][__FUNCTION__] = ['category']; - $sql_itilcat = isset($_SESSION['mreporting_values']['itilcategories_id']) && $_SESSION['mreporting_values']['itilcategories_id'] > 0 ? - ' AND glpi_tickets.itilcategories_id = ' . $_SESSION['mreporting_values']['itilcategories_id'] : ''; + $criteria_cat = []; + if ( + isset($_SESSION['mreporting_values']['itilcategories_id']) && + $_SESSION['mreporting_values']['itilcategories_id'] > 0 + ) { + $criteria_cat = [ + Ticket::getTable() . '.itilcategories_id' => $_SESSION['mreporting_values']['itilcategories_id'], + ]; + } $datas = []; - $result = $DB->doQuery("SELECT COUNT(*) as count_tag, glpi_plugin_tag_tags.name - FROM glpi_plugin_tag_tagitems - LEFT JOIN glpi_plugin_tag_tags ON plugin_tag_tags_id = glpi_plugin_tag_tags.id - LEFT JOIN glpi_tickets ON glpi_tickets.id = glpi_plugin_tag_tagitems.items_id - WHERE itemtype = 'Ticket' - $sql_itilcat - GROUP BY plugin_tag_tags_id - ORDER BY count_tag DESC"); - while ($datas_tag = $DB->fetchAssoc($result)) { + $query = [ + 'SELECT' => [ + PluginTagTag::getTable() . '.name AS name', + ], + 'COUNT' => 'count_tag', + 'FROM' => PluginTagTagItem::getTable(), + 'LEFT JOIN' => [ + PluginTagTag::getTable() => [ + 'ON' => [ + PluginTagTag::getTable() . '.id', + PluginTagTagItem::getTable() . '.plugin_tag_tags_id', + ] + ], + Ticket::getTable() => [ + 'ON' => [ + Ticket::getTable() . '.id', + PluginTagTagItem::getTable() . '.items_id', + ] + ], + ], + 'WHERE' => array_merge( + [ + 'itemtype' => Ticket::getType(), + ], + $criteria_cat + ), + 'GROUPBY' => PluginTagTagItem::getTable() . '.plugin_tag_tags_id', + 'ORDERBY' => 'count_tag DESC', + ]; + + $result = $DB->request($query); + foreach ($result as $datas_tag) { $label = $datas_tag['name']; $datas['datas'][$label] = $datas_tag['count_tag']; } From 7b403ac144f06c24083ebac9c44b11dc2f8e3689 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Wed, 28 May 2025 16:24:01 +0200 Subject: [PATCH 17/24] php cs fixer --- front/central.php | 6 +-- inc/common.class.php | 19 ++++---- inc/config.class.php | 2 +- inc/helpdesk.class.php | 92 +++++++++++++++++++------------------- inc/helpdeskplus.class.php | 22 ++++----- inc/inventory.class.php | 77 ++++++++++++++++--------------- inc/other.class.php | 84 ++++++++++++---------------------- inc/tag.class.php | 8 ++-- 8 files changed, 145 insertions(+), 165 deletions(-) diff --git a/front/central.php b/front/central.php index b86708c4..27b487b6 100644 --- a/front/central.php +++ b/front/central.php @@ -62,9 +62,9 @@ 'glpi_plugin_mreporting_profiles' => [ 'ON' => [ 'glpi_plugin_mreporting_configs' => 'id', - 'glpi_plugin_mreporting_profiles' => 'reports' - ] - ] + 'glpi_plugin_mreporting_profiles' => 'reports', + ], + ], ], 'WHERE' => [ 'glpi_plugin_mreporting_configs.classname' => $classname, diff --git a/inc/common.class.php b/inc/common.class.php index 016e8750..f8499d12 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -1425,7 +1425,7 @@ public static function selectorAllSlasWithTicket() $result = $DB->request([ 'SELECT' => [ 'glpi_slas.id', - 'glpi_slas.name' + 'glpi_slas.name', ], 'DISTINCT' => true, 'FROM' => 'glpi_slas', @@ -1433,15 +1433,15 @@ public static function selectorAllSlasWithTicket() 'glpi_tickets' => [ 'ON' => [ 'glpi_slas' => 'id', - 'glpi_tickets' => 'slas_id_ttr' - ] - ] + 'glpi_tickets' => 'slas_id_ttr', + ], + ], ], 'WHERE' => [ 'glpi_tickets.status' => array_merge(Ticket::getSolvedStatusArray(), Ticket::getClosedStatusArray()), - 'glpi_tickets.is_deleted' => 0 + 'glpi_tickets.is_deleted' => 0, ], - 'ORDERBY' => 'glpi_slas.name ASC' + 'ORDERBY' => 'glpi_slas.name ASC', ]); $values = []; @@ -1965,7 +1965,7 @@ public static function getSQLDate($field = '`glpi_tickets`.`date`', $delay = 365 return "($field >= '$begin' AND $field <= ADDDATE('$end', INTERVAL 1 DAY) )"; } - /** + /** * Generate a criteria date test with $_REQUEST date fields * @param string $field the sql table field to compare * @param integer $delay if $_REQUET date fields not provided, @@ -2007,7 +2007,7 @@ public static function getCriteriaDate($field = '`glpi_tickets`.`date`', $delay ]; } - /** + /** * Format where_entities field for criteria * @param string $where_entities entities string * @@ -2019,7 +2019,8 @@ public static function formatWhereEntitiesArray($where_entities) return array_map('intval', $matches[0]); } - public static function convertDateFormatSQLtoPHP(string $format): string { + public static function convertDateFormatSQLtoPHP(string $format): string + { return strtr($format, [ '%Y' => 'Y', '%y' => 'y', diff --git a/inc/config.class.php b/inc/config.class.php index d3a21cb8..fb71530f 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -232,7 +232,7 @@ public function getFromDBByFunctionAndClassname($function, $classname) return $this->getFromDBByCrit([ 'name' => $function, - 'classname' => $classname + 'classname' => $classname, ]); } diff --git a/inc/helpdesk.class.php b/inc/helpdesk.class.php index dc17a388..f4845214 100644 --- a/inc/helpdesk.class.php +++ b/inc/helpdesk.class.php @@ -62,8 +62,8 @@ public function reportHbarTicketNumberByEntity($config = []) 'ON' => [ Ticket::getTable() . '.entities_id', Entity::getTable() . '.id', - ] - ] + ], + ], ], 'WHERE' => [ Ticket::getTable() . '.is_deleted' => 0, @@ -72,7 +72,7 @@ public function reportHbarTicketNumberByEntity($config = []) Entity::getTable() . '.name', ], 'ORDER' => ['glpi_entities.name ASC', 'glpi_tickets.itilcategories_id ASC'], - 'LIMIT' => (isset($_REQUEST['glpilist_limit'])) ? (int)$_REQUEST['glpilist_limit'] : 20 + 'LIMIT' => (isset($_REQUEST['glpilist_limit'])) ? (int) $_REQUEST['glpilist_limit'] : 20, ]; $query['WHERE']['AND'] = $delay; @@ -119,15 +119,15 @@ public function reportHgbarTicketNumberByCatAndEntity($config = []) ITILCategory::getTable() => [ 'ON' => [ Ticket::getTable() => 'itilcategories_id', - ITILCategory::getTable() => 'id' - ] - ] + ITILCategory::getTable() => 'id', + ], + ], ], 'WHERE' => [ Ticket::getTable() . '.entities_id' => 0, Ticket::getTable() . '.is_deleted' => 0, ], - 'ORDER' => ["glpi_itilcategories.id ASC"] + 'ORDER' => ["glpi_itilcategories.id ASC"], ]; $query['WHERE']['AND'] = $delay; @@ -169,8 +169,8 @@ public function reportHgbarTicketNumberByCatAndEntity($config = []) 'ON' => [ Ticket::getTable() . '.entities_id', Entity::getTable() . '.id', - ] - ] + ], + ], ], 'WHERE' => [ Ticket::getTable() . '.itilcategories_id' => $cat_ids, @@ -180,7 +180,7 @@ public function reportHgbarTicketNumberByCatAndEntity($config = []) Entity::getTable() . '.name', Ticket::getTable() . '.itilcategories_id', ], - 'ORDER' => ['glpi_entities.name ASC', 'glpi_tickets.itilcategories_id ASC'] + 'ORDER' => ['glpi_entities.name ASC', 'glpi_tickets.itilcategories_id ASC'], ]; $query['WHERE']['AND'] = $delay; @@ -295,7 +295,7 @@ public function reportPieTicketOpenedbyStatus($config = []) Ticket::getTable() . '.is_deleted' => 0, Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), Ticket::getTable() . '.status' => $key, - ] + ], ]; $query['WHERE']['AND'] = $delay; @@ -327,7 +327,7 @@ public function reportPieTopTenAuthor($config = []) $query = [ 'SELECT' => [ - Ticket_User::getTable() . '.users_id as users_id' + Ticket_User::getTable() . '.users_id as users_id', ], 'COUNT' => 'count', 'FROM' => Ticket::getTable(), @@ -338,11 +338,11 @@ public function reportPieTopTenAuthor($config = []) Ticket::getTable() . '.id', [ 'AND' => [ - Ticket_User::getTable() . '.type' => Ticket_User::REQUESTER - ] - ] - ] - ] + Ticket_User::getTable() . '.type' => Ticket_User::REQUESTER, + ], + ], + ], + ], ], 'WHERE' => [ Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), @@ -410,8 +410,8 @@ private function reportHgbarTicketNumberByCategoryAndByType(array $config, $filt 'ON' => [ ITILCategory::getTable() . '.id', Ticket::getTable() . '.itilcategories_id', - ] - ] + ], + ], ], 'WHERE' => [ Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), @@ -422,7 +422,7 @@ private function reportHgbarTicketNumberByCategoryAndByType(array $config, $filt ITILCategory::getTable() . '.id', Ticket::getTable() . '.type', ], - 'ORDER' => [ITILCategory::getTable() . '.name'] + 'ORDER' => [ITILCategory::getTable() . '.name'], ]; $query['WHERE']['AND'] = $delay; @@ -489,7 +489,7 @@ public function reportHgbarTicketNumberByService($config = []) 'WHERE' => [ [ 'NOT' => [ - Ticket::getTable() . '.id' => $ticket_ids + Ticket::getTable() . '.id' => $ticket_ids, ], ], Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), @@ -514,14 +514,14 @@ public function reportHgbarTicketNumberByService($config = []) 'ON' => [ Group_Ticket::getTable() . '.tickets_id', Ticket::getTable() . '.id', - ] ], + ], Group::getTable() => [ 'ON' => [ Group::getTable() . '.id', Group_Ticket::getTable() . '.groups_id', - ] - ] + ], + ], ], 'WHERE' => [ Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), @@ -532,7 +532,7 @@ public function reportHgbarTicketNumberByService($config = []) 'GROUPBY' => [ Group::getTable() . '.id', ], - 'ORDER' => [Group::getTable() . '.name'] + 'ORDER' => [Group::getTable() . '.name'], ]; $query['WHERE']['AND'] = $delay; @@ -586,8 +586,8 @@ public function reportHgbarOpenedTicketNumberByCategory($config = []) 'ON' => [ ITILCategory::getTable() . '.id', Ticket::getTable() . '.itilcategories_id', - ] - ] + ], + ], ], 'WHERE' => [ Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), @@ -599,7 +599,7 @@ public function reportHgbarOpenedTicketNumberByCategory($config = []) ITILCategory::getTable() . '.id', Ticket::getTable() . '.status', ], - 'ORDER' => [ITILCategory::getTable() . '.name'] + 'ORDER' => [ITILCategory::getTable() . '.name'], ]; $query['WHERE']['AND'] = $delay; @@ -659,7 +659,7 @@ public function reportAreaNbTicket($config = [], $area = true) 'FROM' => Ticket::getTable(), 'WHERE' => [ Ticket::getTable() . '.is_deleted' => 0, - Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities) + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), ], 'GROUPBY' => ['period'], 'ORDER' => ['period'], @@ -728,7 +728,7 @@ public function reportGlineNbTicket($config = [], $area = false) Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), Ticket::getTable() . '.status' => $status_to_show, ], - 'ORDER' => [Ticket::getTable() . '.date ASC'] + 'ORDER' => [Ticket::getTable() . '.date ASC'], ]; $query['WHERE']['AND'] = $delay; @@ -814,8 +814,8 @@ public function reportSunburstTicketByCategories($config = []) 'ON' => [ ITILCategory::getTable() . '.id', Ticket::getTable() . '.itilcategories_id', - ] - ] + ], + ], ], 'WHERE' => [ Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), @@ -886,23 +886,23 @@ public function reportVstackbarTicketStatusByTechnician($config = []) Ticket::getTable() . '.id', [ 'AND' => [ - Ticket_User::getTable() . '.type' => Ticket_User::ASSIGN - ] - ] - ] + Ticket_User::getTable() . '.type' => Ticket_User::ASSIGN, + ], + ], + ], ], User::getTable() => [ 'FKEY' => [ User::getTable() . '.id', Ticket_User::getTable() . '.users_id', - ] - ] + ], + ], ], 'WHERE' => [ Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), Ticket::getTable() . '.is_deleted' => 0, ], - 'ORDER' => ['fullname, username'] + 'ORDER' => ['fullname, username'], ]; $query['WHERE']['AND'] = $delay; @@ -943,17 +943,17 @@ public function reportVstackbarTicketStatusByTechnician($config = []) Ticket::getTable() . '.id', [ 'AND' => [ - Ticket_User::getTable() . '.type' => Ticket_User::ASSIGN - ] - ] - ] + Ticket_User::getTable() . '.type' => Ticket_User::ASSIGN, + ], + ], + ], ], User::getTable() => [ 'FKEY' => [ User::getTable() . '.id', Ticket_User::getTable() . '.users_id', - ] - ] + ], + ], ], 'WHERE' => [ Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), @@ -1003,7 +1003,7 @@ public function reportHbarTicketNumberByLocation($config = []) Ticket::getTable() . '.id', [ 'AND' => [ - Ticket_User::getTable() . '.type' => Ticket_User::REQUESTER + Ticket_User::getTable() . '.type' => Ticket_User::REQUESTER, ], ], ], diff --git a/inc/helpdeskplus.class.php b/inc/helpdeskplus.class.php index 36e44ef6..9296ac81 100644 --- a/inc/helpdeskplus.class.php +++ b/inc/helpdeskplus.class.php @@ -77,7 +77,7 @@ public function __construct($config = []) $this->criteria_type = [ Ticket::getTable() . '.type' => [ Ticket::INCIDENT_TYPE, - Ticket::DEMAND_TYPE + Ticket::DEMAND_TYPE, ], ]; $this->sql_itilcat = '1=1'; @@ -132,7 +132,7 @@ public function __construct($config = []) Ticket::getTable() . '.id', [ 'AND' => [ - Ticket_User::getTable() . '.type' => Ticket_User::ASSIGN + Ticket_User::getTable() . '.type' => Ticket_User::ASSIGN, ], ], ], @@ -148,7 +148,7 @@ public function __construct($config = []) Ticket::getTable() . '.id', [ 'AND' => [ - Group_Ticket::getTable() . '.type' => Group_Ticket::ASSIGN + Group_Ticket::getTable() . '.type' => Group_Ticket::ASSIGN, ], ], ], @@ -164,7 +164,7 @@ public function __construct($config = []) Ticket::getTable() . '.id', [ 'AND' => [ - Group_Ticket::getTable() . '.type' => Group_Ticket::REQUESTER + Group_Ticket::getTable() . '.type' => Group_Ticket::REQUESTER, ], ], ], @@ -192,7 +192,7 @@ public function __construct($config = []) AND glpi_tickets.solve_delay_stat <= glpi_slas.number_time * 60 THEN 'ok' ELSE 'nok' - END AS respected_sla" + END AS respected_sla", ); parent::__construct($config); @@ -242,7 +242,7 @@ public function __construct($config = []) ) { $this->sql_type = 'glpi_tickets.type = ' . $mr_values['type']; $this->criteria_type = [ - Ticket::getTable() . '.type' => $mr_values['type'] + Ticket::getTable() . '.type' => $mr_values['type'], ]; } @@ -481,7 +481,7 @@ public function reportVstackbarLifetime($config = []) Ticket::getTable() . '.id', [ 'AND' => [ - Ticket_User::getTable() . '.type' => Ticket_User::ASSIGN + Ticket_User::getTable() . '.type' => Ticket_User::ASSIGN, ], ], ], @@ -558,13 +558,13 @@ public function reportVstackbarTicketsgroups($config = []) $query = [ "SELECT" => [ - Group::getTable() . '.completename as group_name' + Group::getTable() . '.completename as group_name', ], 'COUNT' => 'nb', 'FROM' => Ticket::getTable(), 'LEFT JOIN' => array_merge( $this->criteria_join_gt, - $this->criteria_join_g + $this->criteria_join_g, ), 'WHERE' => array_merge( [ @@ -805,7 +805,7 @@ public function reportVstackbarGroupChange($config = []) Log::getTable() . '.itemtype' => 'Ticket', Log::getTable() . '.itemtype_link' => Group::class, log::getTable() . '.linked_action' => 15, - ] + ], ], ], ], @@ -977,7 +977,7 @@ public function reportGlineNbTicketBySla($config = []) new QueryExpression("DATE_FORMAT(" . Ticket::getTable() . ".date, " . $DB->quoteValue($this->period_sort) . ") as period"), new QueryExpression("DATE_FORMAT(" . Ticket::getTable() . ".date, " . $DB->quoteValue($this->period_label) . ") as period_name"), SLA::getTable() . '.name', - $this->criteria_select_sla + $this->criteria_select_sla, ], 'COUNT' => 'nb', 'FROM' => Ticket::getTable(), diff --git a/inc/inventory.class.php b/inc/inventory.class.php index ca280341..52d32f0f 100644 --- a/inc/inventory.class.php +++ b/inc/inventory.class.php @@ -138,14 +138,15 @@ public function computersByFabricant($config = []) 'ON' => [ Manufacturer::getTable() . '.id', Computer::getTable() . '.manufacturers_id', - ] - ] + ], + ], ], 'WHERE' => array_merge( [ Computer::getTable() . '.is_template' => 0, Computer::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), - ], $criteria_states + ], + $criteria_states, ), ]; @@ -161,8 +162,8 @@ public function computersByFabricant($config = []) 'ON' => [ Manufacturer::getTable() . '.id', Computer::getTable() . '.manufacturers_id', - ] - ] + ], + ], ], 'WHERE' => array_merge( [ @@ -170,7 +171,8 @@ public function computersByFabricant($config = []) Computer::getTable() . '.is_deleted' => 0, Computer::getTable() . '.is_template' => 0, ], - $criteria_states), + $criteria_states, + ), 'GROUPBY' => [ Manufacturer::getTable() . '.name', ], @@ -221,14 +223,15 @@ public function computersByType($config = []) 'ON' => [ ComputerType::getTable() . '.id', Computer::getTable() . '.computertypes_id', - ] - ] + ], + ], ], 'WHERE' => array_merge( [ Computer::getTable() . '.is_template' => 0, Computer::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), - ], $criteria_states + ], + $criteria_states, ), ]; @@ -244,8 +247,8 @@ public function computersByType($config = []) 'ON' => [ ComputerType::getTable() . '.id', Computer::getTable() . '.computertypes_id', - ] - ] + ], + ], ], 'WHERE' => array_merge( [ @@ -253,7 +256,8 @@ public function computersByType($config = []) Computer::getTable() . '.is_deleted' => 0, Computer::getTable() . '.is_template' => 0, ], - $criteria_states), + $criteria_states, + ), 'GROUPBY' => [ ComputerType::getTable() . '.name', ], @@ -323,8 +327,8 @@ public function computersByAge($config = []) 'ON' => [ Infocom::getTable() . '.items_id', Computer::getTable() . '.id', - ] - ] + ], + ], ], 'WHERE' => array_merge( [ @@ -332,7 +336,8 @@ public function computersByAge($config = []) Computer::getTable() . '.is_template' => 0, Infocom::getTable() . '.itemtype' => 'Computer', Computer::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), - ], $criteria_states + ], + $criteria_states, ), ]; @@ -351,8 +356,8 @@ public function computersByAge($config = []) 'ON' => [ Infocom::getTable() . '.items_id', Computer::getTable() . '.id', - ] - ] + ], + ], ], 'WHERE' => [ Computer::getTable() . '.is_deleted' => 0, @@ -415,7 +420,7 @@ public function computersByOS($config = []) $subquery = [ 'SELECT' => [ - new QueryExpression("COUNT(*)") + new QueryExpression("COUNT(*)"), ], 'FROM' => Computer::getTable(), 'LEFT JOIN' => [ @@ -423,13 +428,13 @@ public function computersByOS($config = []) 'ON' => [ Item_OperatingSystem::getTable() . '.items_id', Computer::getTable() . '.id', - ] + ], ], OperatingSystem::getTable() => [ 'ON' => [ OperatingSystem::getTable() . '.id', Item_OperatingSystem::getTable() . '.operatingsystems_id', - ] + ], ], ], 'WHERE' => array_merge([ @@ -453,13 +458,13 @@ public function computersByOS($config = []) 'ON' => [ Item_OperatingSystem::getTable() . '.items_id', Computer::getTable() . '.id', - ] + ], ], OperatingSystem::getTable() => [ 'ON' => [ OperatingSystem::getTable() . '.id', Item_OperatingSystem::getTable() . '.operatingsystems_id', - ] + ], ], ], 'WHERE' => array_merge([ @@ -486,13 +491,13 @@ public function computersByOS($config = []) 'ON' => [ Item_OperatingSystem::getTable() . '.items_id', Computer::getTable() . '.id', - ] + ], ], OperatingSystem::getTable() => [ 'ON' => [ OperatingSystem::getTable() . '.id', Item_OperatingSystem::getTable() . '.operatingsystems_id', - ] + ], ], ], 'WHERE' => array_merge([ @@ -884,8 +889,8 @@ public function reportHbarMonitors($config = []) 'ON' => [ Computer_Item::getTable() . '.computers_id', Computer::getTable() . '.id', - ] - ] + ], + ], ], 'WHERE' => array_merge([ Computer_Item::getTable() . '.itemtype' => 'Monitor', @@ -917,7 +922,7 @@ public function reportHbarComputersByStatus($config = []) $subquery = [ 'SELECT' => [ - new QueryExpression("COUNT(*)") + new QueryExpression("COUNT(*)"), ], 'FROM' => Computer::getTable(), 'LEFT JOIN' => [ @@ -925,8 +930,8 @@ public function reportHbarComputersByStatus($config = []) 'ON' => [ State::getTable() . '.id', Computer::getTable() . '.states_id', - ] - ] + ], + ], ], 'WHERE' => [ Computer::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), @@ -947,8 +952,8 @@ public function reportHbarComputersByStatus($config = []) 'ON' => [ State::getTable() . '.id', Computer::getTable() . '.states_id', - ] - ] + ], + ], ], 'WHERE' => [ Computer::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), @@ -979,7 +984,7 @@ public function reportHbarPrintersByStatus($config = []) $subquery = [ 'SELECT' => [ - new QueryExpression("COUNT(*)") + new QueryExpression("COUNT(*)"), ], 'FROM' => Printer::getTable(), 'LEFT JOIN' => [ @@ -987,8 +992,8 @@ public function reportHbarPrintersByStatus($config = []) 'ON' => [ State::getTable() . '.id', Printer::getTable() . '.states_id', - ] - ] + ], + ], ], 'WHERE' => [ Printer::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), @@ -1009,8 +1014,8 @@ public function reportHbarPrintersByStatus($config = []) 'ON' => [ State::getTable() . '.id', Printer::getTable() . '.states_id', - ] - ] + ], + ], ], 'WHERE' => [ Printer::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), diff --git a/inc/other.class.php b/inc/other.class.php index 4b0ee040..3a427de7 100644 --- a/inc/other.class.php +++ b/inc/other.class.php @@ -32,7 +32,7 @@ class PluginMreportingOther extends PluginMreportingBaseclass { - public function reportHbarLogs($configs = []) + public function reportHbarLogs($configs = []) { /** @var \DBmysql $DB */ global $DB; @@ -56,7 +56,7 @@ public function reportHbarLogs($configs = []) [ 'WHERE' => [ Log::getTable() . '.linked_action' => [4, 5], - ] + ], ], ); @@ -67,7 +67,7 @@ public function reportHbarLogs($configs = []) Log::getTable() . '.itemtype' => 'Software', Log::getTable() . '.itemtype_link' => 'SoftwareVersion', Log::getTable() . '.linked_action' => [17, 18, 19], - ] + ], ], ); @@ -78,7 +78,7 @@ public function reportHbarLogs($configs = []) Log::getTable() . '.itemtype' => 'Software', Log::getTable() . '.itemtype_link' => 'Infocom', Log::getTable() . '.linked_action' => [17], - ] + ], ], ); @@ -89,7 +89,7 @@ public function reportHbarLogs($configs = []) Log::getTable() . '.itemtype' => 'User', Log::getTable() . '.itemtype_link' => 'Profile_User', Log::getTable() . '.linked_action' => [17, 18, 19], - ] + ], ], ); @@ -100,7 +100,7 @@ public function reportHbarLogs($configs = []) Log::getTable() . '.itemtype' => 'User', Log::getTable() . '.itemtype_link' => 'Group_User', Log::getTable() . '.linked_action' => [17, 18, 19], - ] + ], ], ); @@ -110,7 +110,7 @@ public function reportHbarLogs($configs = []) 'WHERE' => [ Log::getTable() . '.itemtype' => 'User', Log::getTable() . '.linked_action' => [12], - ] + ], ], ); @@ -119,7 +119,7 @@ public function reportHbarLogs($configs = []) [ 'WHERE' => [ Log::getTable() . '.linked_action' => [8, 9, 10, 11], - ] + ], ], ); @@ -128,7 +128,7 @@ public function reportHbarLogs($configs = []) [ 'WHERE' => [ Log::getTable() . '.linked_action' => [1, 2, 3, 6, 7], - ] + ], ], ); @@ -137,7 +137,7 @@ public function reportHbarLogs($configs = []) [ 'WHERE' => [ Log::getTable() . '.linked_action' => [15, 16], - ] + ], ], ); @@ -146,7 +146,7 @@ public function reportHbarLogs($configs = []) [ 'WHERE' => [ Log::getTable() . '.linked_action' => [13, 14, 17, 18, 19, 20], - ] + ], ], ); @@ -155,41 +155,29 @@ public function reportHbarLogs($configs = []) [ 'WHERE' => [ Log::getTable() . '.id_search_option' => [16, 19], - ] + ], ], ); $datas = []; $result = $DB->request($query_computer_software); - foreach ($result as $data) { - $datas['datas'][__('Add/remove software on a computer', 'mreporting')] = $data['cpt']; - } + $datas['datas'][__('Add/remove software on a computer', 'mreporting')] = $result->current()['cpt']; $result = $DB->request($query_software_version); - foreach ($result as $data) { - $datas['datas'][__('Add/remove version on a software', 'mreporting')] = $data['cpt']; - } + $datas['datas'][__('Add/remove version on a software', 'mreporting')] = $result->current()['cpt']; $result = $DB->request($query_add_infocom); - foreach ($result as $data) { - $datas['datas'][__('Add infocom', 'mreporting')] = $data['cpt']; - } + $datas['datas'][__('Add infocom', 'mreporting')] = $result->current()['cpt']; $result = $DB->request($query_user_profiles); - foreach ($result as $data) { - $datas['datas'][__('Add/remove profile on a user', 'mreporting')] = $data['cpt']; - } + $datas['datas'][__('Add/remove profile on a user', 'mreporting')] = $result->current()['cpt']; $result = $DB->request($query_user_groups); - foreach ($result as $data) { - $datas['datas'][__('Add/remove group on a user', 'mreporting')] = $data['cpt']; - } + $datas['datas'][__('Add/remove group on a user', 'mreporting')] = $result->current()['cpt']; $result = $DB->request($query_user_deleted); - foreach ($result as $data) { - $datas['datas'][__('User deleted from LDAP', 'mreporting')] = $data['cpt']; - } + $datas['datas'][__('User deleted from LDAP', 'mreporting')] = $result->current()['cpt']; $plugin = new Plugin(); if ($plugin->isActivated('webservices')) { @@ -198,42 +186,30 @@ public function reportHbarLogs($configs = []) $prefix2, [ 'WHERE' => [ - Log::getTable() . ".itemtype = 'PluginWebservicesClient'" - ] + Log::getTable() . ".itemtype = 'PluginWebservicesClient'", + ], ], ); // Display this information is not usefull if webservices is not activated $result = $DB->request($query_webservice); - foreach ($result as $data) { - $datas['datas'][__('Webservice logs', 'mreporting')] = $data['cpt']; - } + $datas['datas'][__('Webservice logs', 'mreporting')] = $result->current()['cpt']; } $result = $DB->request($query_ocs); - foreach ($result as $data) { - $datas['datas'][__('OCS Infos', 'mreporting')] = $data['cpt']; - } + $datas['datas'][__('OCS Infos', 'mreporting')] = $result->current()['cpt']; $result = $DB->request($query_device); - foreach ($result as $data) { - $datas['datas'][__('Add/update/remove device', 'mreporting')] = $data['cpt']; - } + $datas['datas'][__('Add/update/remove device', 'mreporting')] = $result->current()['cpt']; $result = $DB->request($query_relation); - foreach ($result as $data) { - $datas['datas'][__('Add/remove relation', 'mreporting')] = $data['cpt']; - } + $datas['datas'][__('Add/remove relation', 'mreporting')] = $result->current()['cpt']; $result = $DB->request($query_item); - foreach ($result as $data) { - $datas['datas'][__('Add/remove item', 'mreporting')] = $data['cpt']; - } + $datas['datas'][__('Add/remove item', 'mreporting')] = $result->current()['cpt']; $result = $DB->request($query_other); - foreach ($result as $data) { - $datas['datas'][__('Comments & date_mod changes', 'mreporting')] = $data['cpt']; - } + $datas['datas'][__('Comments & date_mod changes', 'mreporting')] = $result->current()['cpt']; $plugin = new Plugin(); if ($plugin->isActivated('genericobject')) { @@ -242,17 +218,15 @@ public function reportHbarLogs($configs = []) [ 'WHERE' => [ new QueryExpression( - Log::getTable() . ".itemtype LIKE '%PluginGenericobject%'" + Log::getTable() . ".itemtype LIKE '%PluginGenericobject%'", ), - ] + ], ], ); // Display this information is not usefull if genericobject is not activated $result = $DB->request($query_genericobject); - foreach ($result as $data) { - $datas['datas'][__('Genericobject plugin logs', 'mreporting')] = $data['cpt']; - } + $datas['datas'][__('Genericobject plugin logs', 'mreporting')] = $result->current()['cpt']; } return $datas; diff --git a/inc/tag.class.php b/inc/tag.class.php index d633808b..aa5f52e5 100644 --- a/inc/tag.class.php +++ b/inc/tag.class.php @@ -61,7 +61,7 @@ public function reportPieTag($config = []) 'ON' => [ PluginTagTag::getTable() . '.id', PluginTagTagItem::getTable() . '.plugin_tag_tags_id', - ] + ], ], ], 'GROUPBY' => PluginTagTagItem::getTable() . '.plugin_tag_tags_id', @@ -118,20 +118,20 @@ public function reportPieTagOnTicket($config = []) 'ON' => [ PluginTagTag::getTable() . '.id', PluginTagTagItem::getTable() . '.plugin_tag_tags_id', - ] + ], ], Ticket::getTable() => [ 'ON' => [ Ticket::getTable() . '.id', PluginTagTagItem::getTable() . '.items_id', - ] + ], ], ], 'WHERE' => array_merge( [ 'itemtype' => Ticket::getType(), ], - $criteria_cat + $criteria_cat, ), 'GROUPBY' => PluginTagTagItem::getTable() . '.plugin_tag_tags_id', 'ORDERBY' => 'count_tag DESC', From bc2dac0f7116c5cfacdd356196f6510df7bfcb99 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Tue, 3 Jun 2025 10:30:48 +0200 Subject: [PATCH 18/24] phpstan --- inc/baseclass.class.php | 26 +++ inc/common.class.php | 4 +- inc/config.class.php | 4 + inc/graphcsv.class.php | 4 + inc/graphpng.class.php | 7 + inc/helpdesk.class.php | 1 - inc/helpdeskplus.class.php | 323 ++++++++++++++++++------------------- inc/profile.class.php | 13 +- inc/tag.class.php | 26 +-- 9 files changed, 222 insertions(+), 186 deletions(-) diff --git a/inc/baseclass.class.php b/inc/baseclass.class.php index eb51e6b0..6d46d591 100644 --- a/inc/baseclass.class.php +++ b/inc/baseclass.class.php @@ -44,6 +44,8 @@ class PluginMreportingBaseclass protected $period_label; protected $period_interval; protected $sql_list_date; + protected $criteria_list_date; + protected $criteria_list_date2; protected $status; public function __construct($config = []) @@ -128,6 +130,12 @@ public function __construct($config = []) $this->period_label = '%d %b'; $this->period_interval = 'DAY'; $this->sql_list_date = "DISTINCT DATE_FORMAT(`date` , '{$this->period_datetime}') as period_l"; + $this->criteria_list_date = new QueryExpression( + "DATE_FORMAT(`date`, '{$this->period_datetime}') as period_l", + ); + $this->criteria_list_date2 = new QueryExpression( + "DATE_FORMAT(`solvedate`, '{$this->period_datetime}') as period_l", + ); break; case 'week': $this->period_sort = '%x%v'; @@ -136,6 +144,12 @@ public function __construct($config = []) $this->period_label = 'S%v %x'; $this->period_interval = 'WEEK'; $this->sql_list_date = "DISTINCT DATE_FORMAT(`date` - INTERVAL (WEEKDAY(`date`)) DAY, '{$this->period_datetime}') as period_l"; + $this->criteria_list_date = new QueryExpression( + "DATE_FORMAT(`date` - INTERVAL (WEEKDAY(`date`)) DAY, '{$this->period_datetime}') as period_l", + ); + $this->criteria_list_date2 = new QueryExpression( + "DATE_FORMAT(`date` - INTERVAL (WEEKDAY(`solvedate`)) DAY, '{$this->period_datetime}') as period_l", + ); break; case 'month': $this->period_sort = '%y%m'; @@ -144,6 +158,12 @@ public function __construct($config = []) $this->period_label = '%b %Y'; $this->period_interval = 'MONTH'; $this->sql_list_date = "DISTINCT CONCAT(LAST_DAY(DATE_FORMAT(`date` , '{$this->period_datetime}')), ' 23:59:59') as period_l"; + $this->criteria_list_date = new QueryExpression( + "CONCAT(LAST_DAY(DATE_FORMAT(`date` , '{$this->period_datetime}')), ' 23:59:59') as period_l", + ); + $this->criteria_list_date2 = new QueryExpression( + "CONCAT(LAST_DAY(DATE_FORMAT(`solvedate` , '{$this->period_datetime}')), ' 23:59:59') as period_l", + ); break; case 'year': $this->period_sort = '%Y'; @@ -152,6 +172,12 @@ public function __construct($config = []) $this->period_label = '%Y'; $this->period_interval = 'YEAR'; $this->sql_list_date = "DISTINCT DATE_FORMAT(`date` , '{$this->period_datetime}') as period_l"; + $this->criteria_list_date = new QueryExpression( + "DATE_FORMAT(`date` , '{$this->period_datetime}') as period_l", + ); + $this->criteria_list_date2 = new QueryExpression( + "DATE_FORMAT(`solvedate` , '{$this->period_datetime}') as period_l", + ); break; default: $this->period_sort = '%y%u'; diff --git a/inc/common.class.php b/inc/common.class.php index f8499d12..27413bbe 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -1624,7 +1624,7 @@ public static function selectorEntityLevel() /** * Get criteria condition to filter entity depth by level. * @param string $field the sql table field to compare - * @return string sql condition + * @return array sql condition */ public static function getCriteriaEntityLevel($field = '`glpi_entities`.`level`') { @@ -1971,7 +1971,7 @@ public static function getSQLDate($field = '`glpi_tickets`.`date`', $delay = 365 * @param integer $delay if $_REQUET date fields not provided, * generate them from $delay (in days) * @param string $randname random string (to prevent conflict in js selection) - * @return string The sql test to insert in your query + * @return array The sql test to insert in your query */ public static function getCriteriaDate($field = '`glpi_tickets`.`date`', $delay = 365, $randname = '') { diff --git a/inc/config.class.php b/inc/config.class.php index fb71530f..cfcd994e 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -300,6 +300,7 @@ public function createFirstConfig() $input = []; if ($classConfig) { // If a preconfig exists in class we do it + /** @var null|PluginMreportingOther|PluginMreportingHelpdesk $classObject */ $input = $classObject->preconfig($funct_name, $classname, $this); } else {// Else we get the default preconfig $input = $this->preconfig($funct_name, $classname); @@ -851,6 +852,7 @@ public static function initConfigParams($name, $classname) $crit['randname'] = $classname . $name; } + // DEBUG_MREPORTING is constant. It is true if debug mode is enabled, false otherwise. For PHPStan, this constant is always true or false. /* @phpstan-ignore-next-line */ if (DEBUG_MREPORTING) { $crit['show_graph'] = true; @@ -867,11 +869,13 @@ public static function initConfigParams($name, $classname) **/ public static function showGraphConfigValue($name, $classname) { + // DEBUG_MREPORTING is constant. It is true if debug mode is enabled, false otherwise. For PHPStan, this constant is always true or false. /* @phpstan-ignore-next-line */ if (DEBUG_MREPORTING) { return true; } + // DEBUG_MREPORTING is constant. It is true if debug mode is enabled, false otherwise. For PHPStan, this constant is always true or false. /* @phpstan-ignore-next-line */ $self = new self(); if ($self->getFromDBByFunctionAndClassname($name, $classname)) { diff --git a/inc/graphcsv.class.php b/inc/graphcsv.class.php index 5a29ca40..d34b02e3 100644 --- a/inc/graphcsv.class.php +++ b/inc/graphcsv.class.php @@ -34,6 +34,7 @@ class PluginMreportingGraphcsv extends PluginMreportingGraph public function initGraph($options) { + // DEBUG_CSV is constant. It is used to debug csv file. It is always false for PHPStan. /* @phpstan-ignore-next-line */ if (!self::DEBUG_CSV) { header('Content-type: application/csv'); @@ -55,6 +56,7 @@ public function showHbar($params, $dashboard = false, $width = false) ] = PluginMreportingCommon::initGraphParams($params); // Write in Log + // DEBUG_CSV is constant. It is used to debug csv file. It is always false for PHPStan. /* @phpstan-ignore-next-line */ if (self::DEBUG_CSV && isset($raw_datas)) { Toolbox::logdebug($raw_datas); @@ -121,6 +123,7 @@ public function showHgbar($params, $dashboard = false, $width = false) ] = PluginMreportingCommon::initGraphParams($params); // Write in log + // DEBUG_CSV is constant. It is used to debug csv file. It is always false for PHPStan. /* @phpstan-ignore-next-line */ if (self::DEBUG_CSV && isset($raw_datas)) { Toolbox::logdebug($raw_datas); @@ -205,6 +208,7 @@ public function showSunburst($params, $dashboard = false, $width = false) 'opt' => $opt, ] = PluginMreportingCommon::initGraphParams($params); + // DEBUG_CSV is constant. It is used to debug csv file. It is always false for PHPStan. /* @phpstan-ignore-next-line */ if (self::DEBUG_CSV && isset($raw_datas)) { Toolbox::logdebug($raw_datas); diff --git a/inc/graphpng.class.php b/inc/graphpng.class.php index bd53004b..a620f1f4 100644 --- a/inc/graphpng.class.php +++ b/inc/graphpng.class.php @@ -582,6 +582,7 @@ public function showHbar($params, $dashboard = false, $width = false) 'randname' => $randname, ] = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); + // DEBUG_GRAPH is constant. It is used to debug graph. It is always false for PHPStan. /* @phpstan-ignore-next-line */ if (self::DEBUG_GRAPH && isset($raw_datas)) { Toolbox::logdebug($raw_datas); @@ -783,6 +784,7 @@ public function showPie($params, $dashboard = false, $width = false) 'randname' => $randname, ] = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); + // DEBUG_GRAPH is constant. It is used to debug graph. It is always false for PHPStan. /* @phpstan-ignore-next-line */ if (self::DEBUG_GRAPH && isset($raw_datas)) { Toolbox::logdebug($raw_datas); @@ -1026,6 +1028,7 @@ public function showSunburst($params, $dashboard = false, $width = false) 'randname' => $randname, ] = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); + // DEBUG_GRAPH is constant. It is used to debug graph. It is always false for PHPStan. /* @phpstan-ignore-next-line */ if (self::DEBUG_GRAPH && isset($raw_datas)) { Toolbox::logdebug($raw_datas); @@ -1369,6 +1372,7 @@ public function showHgbar($params, $dashboard = false, $width = false) 'randname' => $randname, ] = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); + // DEBUG_GRAPH is constant. It is used to debug graph. It is always false for PHPStan. /* @phpstan-ignore-next-line */ if (self::DEBUG_GRAPH && isset($raw_datas)) { Toolbox::logdebug($raw_datas); @@ -1623,6 +1627,7 @@ public function showVstackbar($params, $dashboard = false, $width = false) 'randname' => $randname, ] = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); + // DEBUG_GRAPH is constant. It is used to debug graph. It is always false for PHPStan. /* @phpstan-ignore-next-line */ if (self::DEBUG_GRAPH && isset($raw_datas)) { Toolbox::logdebug($raw_datas); @@ -1969,6 +1974,7 @@ public function showArea($params, $dashboard = false, $width = false) 'randname' => $randname, ] = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); + // DEBUG_GRAPH is constant. It is used to debug graph. It is always false for PHPStan. /* @phpstan-ignore-next-line */ if (self::DEBUG_GRAPH && isset($raw_datas)) { Toolbox::logdebug($raw_datas); @@ -2300,6 +2306,7 @@ public function showGArea($params, $dashboard = false, $width = false) 'randname' => $randname, ] = PluginMreportingConfig::initConfigParams($opt['f_name'], $opt['class']); + // DEBUG_GRAPH is constant. It is used to debug graph. It is always false for PHPStan. /* @phpstan-ignore-next-line */ if (self::DEBUG_GRAPH && isset($raw_datas)) { Toolbox::logdebug($raw_datas); diff --git a/inc/helpdesk.class.php b/inc/helpdesk.class.php index f4845214..b810066c 100644 --- a/inc/helpdesk.class.php +++ b/inc/helpdesk.class.php @@ -757,7 +757,6 @@ public function reportGlineNbTicket($config = [], $area = false) Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), Ticket::getTable() . '.status' => $status_to_show, ], - 'ORDER' => [Ticket::getTable() . '.date ASC'], 'GROUPBY' => ['period', Ticket::getTable() . '.status'], 'ORDER' => ['period', Ticket::getTable() . '.status'], ]; diff --git a/inc/helpdeskplus.class.php b/inc/helpdeskplus.class.php index 9296ac81..73ee942a 100644 --- a/inc/helpdeskplus.class.php +++ b/inc/helpdeskplus.class.php @@ -34,31 +34,18 @@ class PluginMreportingHelpdeskplus extends PluginMreportingBaseclass { - protected $sql_group_assign; protected $criteria_group_assign; - protected $sql_group_request; protected $criteria_group_request; - protected $sql_user_assign; protected $criteria_user_assign; - protected $sql_type; protected $criteria_type; - protected $sql_itilcat; protected $criteria_itilcat; - protected $sql_join_cat; protected $criteria_join_cat; - protected $sql_join_g; protected $criteria_join_g; - protected $sql_join_u; protected $criteria_join_u; - protected $sql_join_tt; protected $criteria_join_tt; - protected $sql_join_tu; protected $criteria_join_tu; - protected $sql_join_gt; protected $criteria_join_gt; - protected $sql_join_gtr; protected $criteria_join_gtr; - protected $sql_select_sla; protected $criteria_select_sla; protected $lcl_slaok; protected $lcl_slako; @@ -67,23 +54,16 @@ public function __construct($config = []) { /** @var array $LANG */ global $LANG; - $this->sql_group_assign = '1=1'; $this->criteria_group_assign = []; - $this->sql_group_request = '1=1'; $this->criteria_group_request = []; - $this->sql_user_assign = '1=1'; $this->criteria_user_assign = []; - $this->sql_type = 'glpi_tickets.type IN (' . Ticket::INCIDENT_TYPE . ', ' . Ticket::DEMAND_TYPE . ')'; $this->criteria_type = [ Ticket::getTable() . '.type' => [ Ticket::INCIDENT_TYPE, Ticket::DEMAND_TYPE, ], ]; - $this->sql_itilcat = '1=1'; $this->criteria_itilcat = []; - $this->sql_join_cat = 'LEFT JOIN glpi_itilcategories cat - ON glpi_tickets.itilcategories_id = cat.id'; $this->criteria_join_cat = [ ITILCategory::getTable() => [ 'FKEY' => [ @@ -92,8 +72,6 @@ public function __construct($config = []) ], ], ]; - $this->sql_join_g = 'LEFT JOIN glpi_groups g - ON gt.groups_id = g.id'; $this->criteria_join_g = [ Group::getTable() => [ 'FKEY' => [ @@ -102,8 +80,6 @@ public function __construct($config = []) ], ], ]; - $this->sql_join_u = 'LEFT JOIN glpi_users u - ON tu.users_id = u.id'; $this->criteria_join_u = [ User::getTable() => [ 'FKEY' => [ @@ -112,8 +88,6 @@ public function __construct($config = []) ], ], ]; - $this->sql_join_tt = 'LEFT JOIN glpi_tickettasks tt - ON tt.tickets_id = glpi_tickets.id'; $this->criteria_join_tt = [ 'glpi_tickettasks' => [ 'FKEY' => [ @@ -122,9 +96,6 @@ public function __construct($config = []) ], ], ]; - $this->sql_join_tu = 'LEFT JOIN glpi_tickets_users tu - ON tu.tickets_id = glpi_tickets.id - AND tu.type = ' . Ticket_User::ASSIGN; $this->criteria_join_tu = [ Ticket_User::getTable() => [ 'FKEY' => [ @@ -138,9 +109,6 @@ public function __construct($config = []) ], ], ]; - $this->sql_join_gt = 'LEFT JOIN glpi_groups_tickets gt - ON gt.tickets_id = glpi_tickets.id - AND gt.type = ' . Group_Ticket::ASSIGN; $this->criteria_join_gt = [ Group_Ticket::getTable() => [ 'FKEY' => [ @@ -154,9 +122,6 @@ public function __construct($config = []) ], ], ]; - $this->sql_join_gtr = 'LEFT JOIN glpi_groups_tickets gtr - ON gtr.tickets_id = glpi_tickets.id - AND gtr.type = ' . Group_Ticket::REQUESTER; $this->criteria_join_gtr = [ Group_Ticket::getTable() => [ 'FKEY' => [ @@ -170,17 +135,6 @@ public function __construct($config = []) ], ], ]; - $this->sql_select_sla = "CASE WHEN glpi_slas.definition_time = 'day' - AND glpi_tickets.solve_delay_stat <= glpi_slas.number_time * 86400 - THEN 'ok' - WHEN glpi_slas.definition_time = 'hour' - AND glpi_tickets.solve_delay_stat <= glpi_slas.number_time * 3600 - THEN 'ok' - WHEN glpi_slas.definition_time = 'minute' - AND glpi_tickets.solve_delay_stat <= glpi_slas.number_time * 60 - THEN 'ok' - ELSE 'nok' - END AS respected_sla"; $this->criteria_select_sla = new QueryExpression( "CASE WHEN glpi_slas.definition_time = 'day' AND glpi_tickets.solve_delay_stat <= glpi_slas.number_time * 86400 @@ -203,24 +157,12 @@ public function __construct($config = []) $mr_values = $_SESSION['mreporting_values']; if (isset($mr_values['groups_assign_id'])) { - if (is_array($mr_values['groups_assign_id'])) { - $this->sql_group_assign = 'gt.groups_id IN (' . - implode(',', $mr_values['groups_assign_id']) . ')'; - } elseif ($mr_values['groups_assign_id'] > 0) { - $this->sql_group_assign = 'gt.groups_id = ' . $mr_values['groups_assign_id']; - } $this->criteria_group_assign = [ Group_Ticket::getTable() . '.groups_id' => $mr_values['groups_assign_id'], ]; } if (isset($mr_values['groups_request_id'])) { - if (is_array($mr_values['groups_request_id'])) { - $this->sql_group_request = 'gtr.groups_id IN (' . - implode(',', $mr_values['groups_request_id']) . ')'; - } elseif ($mr_values['groups_request_id'] > 0) { - $this->sql_group_request = 'gt.groups_id = ' . $mr_values['groups_request_id']; - } $this->criteria_group_assign = [ Group_Ticket::getTable() . '.groups_id' => $mr_values['groups_request_id'], ]; @@ -230,7 +172,6 @@ public function __construct($config = []) isset($mr_values['users_assign_id']) && $mr_values['users_assign_id'] > 0 ) { - $this->sql_user_assign = 'tu.users_id = ' . $mr_values['users_assign_id']; $this->criteria_user_assign = [ Ticket_User::getTable() . '.users_id' => $mr_values['users_assign_id'], ]; @@ -240,7 +181,6 @@ public function __construct($config = []) isset($mr_values['type']) && $mr_values['type'] > 0 ) { - $this->sql_type = 'glpi_tickets.type = ' . $mr_values['type']; $this->criteria_type = [ Ticket::getTable() . '.type' => $mr_values['type'], ]; @@ -250,7 +190,6 @@ public function __construct($config = []) isset($mr_values['itilcategories_id']) && $mr_values['itilcategories_id'] > 0 ) { - $this->sql_itilcat = 'glpi_tickets.itilcategories_id = ' . $mr_values['itilcategories_id']; $this->criteria_itilcat = [ Ticket::getTable() . '.itilcategories_id' => $mr_values['itilcategories_id'], ]; @@ -282,52 +221,78 @@ public function reportGlineBacklogs($config = []) $search_closed = (isset($_SESSION['mreporting_values']['show_closed']) && ($_SESSION['mreporting_values']['show_closed'] == '1')) ? true : false; + //Init delay value + $delay_created = PluginMreportingCommon::getCriteriaDate('glpi_tickets.date', $config['delay'], $config['randname']); + $delay_solved = PluginMreportingCommon::getCriteriaDate('glpi_tickets.solvedate', $config['delay'], $config['randname']); + $delay_closed = PluginMreportingCommon::getCriteriaDate('glpi_tickets.closedate', $config['delay'], $config['randname']); + if ($search_new) { - $sql_create = "SELECT - DISTINCT DATE_FORMAT(date, '{$this->period_sort}') as period, - DATE_FORMAT(date, '{$this->period_label}') as period_name, - COUNT(DISTINCT glpi_tickets.id) as nb - FROM glpi_tickets - {$this->sql_join_tu} - {$this->sql_join_gt} - {$this->sql_join_gtr} - WHERE {$this->sql_date_create} - AND glpi_tickets.entities_id IN ({$this->where_entities}) - AND glpi_tickets.is_deleted = '0' - AND {$this->sql_date_create} - AND {$this->sql_type} - AND {$this->sql_group_assign} - AND {$this->sql_group_request} - AND {$this->sql_user_assign} - AND {$this->sql_itilcat} - GROUP BY period - ORDER BY period"; - foreach ($DB->request($sql_create) as $data) { + $query = [ + "SELECT" => [ + new QueryExpression("DATE_FORMAT(" . Ticket::getTable() . ".date, " . $DB->quoteValue($this->period_sort) . ") as period"), + new QueryExpression("DATE_FORMAT(" . Ticket::getTable() . ".date, " . $DB->quoteValue($this->period_label) . ") as period_name"), + ], + 'COUNT' => 'nb', + 'FROM' => Ticket::getTable(), + 'LEFT JOIN' => array_merge( + $this->criteria_join_tu, + $this->criteria_join_gt, + $this->criteria_join_gtr, + ), + 'WHERE' => array_merge( + [ + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Ticket::getTable() . '.is_deleted' => 0, + ], + $this->criteria_type, + $this->criteria_group_assign, + $this->criteria_group_request, + $this->criteria_user_assign, + $this->criteria_itilcat, + ), + 'GROUPBY' => ['period'], + 'ORDER' => ['period'], + ]; + + $query['WHERE']['AND'] = $delay_created; + + foreach ($DB->request($query) as $data) { $tab[$data['period']]['open'] = $data['nb']; $tab[$data['period']]['period_name'] = $data['period_name']; } } if ($search_solved) { - $sql_solved = "SELECT - DISTINCT DATE_FORMAT(solvedate, '{$this->period_sort}') as period, - DATE_FORMAT(solvedate, '{$this->period_label}') as period_name, - COUNT(DISTINCT glpi_tickets.id) as nb - FROM glpi_tickets - {$this->sql_join_tu} - {$this->sql_join_gt} - {$this->sql_join_gtr} - WHERE {$this->sql_date_solve} - AND glpi_tickets.entities_id IN ({$this->where_entities}) - AND glpi_tickets.is_deleted = '0' - AND {$this->sql_type} - AND {$this->sql_group_assign} - AND {$this->sql_group_request} - AND {$this->sql_user_assign} - AND {$this->sql_itilcat} - GROUP BY period - ORDER BY period"; - foreach ($DB->request($sql_solved) as $data) { + + $query = [ + "SELECT" => [ + new QueryExpression("DATE_FORMAT(" . Ticket::getTable() . ".solvedate, " . $DB->quoteValue($this->period_sort) . ") as period"), + new QueryExpression("DATE_FORMAT(" . Ticket::getTable() . ".solvedate, " . $DB->quoteValue($this->period_label) . ") as period_name"), + ], + 'COUNT' => 'nb', + 'FROM' => Ticket::getTable(), + 'LEFT JOIN' => array_merge( + $this->criteria_join_tu, + $this->criteria_join_gt, + $this->criteria_join_gtr, + ), + 'WHERE' => array_merge( + [ + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Ticket::getTable() . '.is_deleted' => 0, + ], + $this->criteria_type, + $this->criteria_group_assign, + $this->criteria_group_request, + $this->criteria_user_assign, + $this->criteria_itilcat, + ), + 'GROUPBY' => ['period'], + 'ORDER' => ['period'], + ]; + $query['WHERE']['AND'] = $delay_solved; + + foreach ($DB->request($query) as $data) { $tab[$data['period']]['solved'] = $data['nb']; $tab[$data['period']]['period_name'] = $data['period_name']; } @@ -352,73 +317,107 @@ public function reportGlineBacklogs($config = []) ]; } - $sql_itilcat_backlog = isset($_SESSION['mreporting_values']['itilcategories_id']) - && $_SESSION['mreporting_values']['itilcategories_id'] > 0 - ? ' AND tic.itilcategories_id = ' . $_SESSION['mreporting_values']['itilcategories_id'] - : ''; - $begin = date($this->period_sort_php, $time1); $end = date($this->period_sort_php, $time2); - $sql_date_backlog = "DATE_FORMAT(list_date.period_l, '{$this->period_sort}') >= '$begin' - AND DATE_FORMAT(list_date.period_l, '{$this->period_sort}') <= '$end'"; - $sql_list_date2 = str_replace('date', 'solvedate', $this->sql_list_date); - $sql_backlog = "SELECT - DISTINCT(DATE_FORMAT(list_date.period_l, '$this->period_sort')) as period, - DATE_FORMAT(list_date.period_l, '$this->period_label') as period_name, - COUNT(DISTINCT(glpi_tickets.id)) as nb - FROM ( - SELECT DISTINCT period_l - FROM ( - SELECT - {$this->sql_list_date} - FROM glpi_tickets - UNION - SELECT - $sql_list_date2 - FROM glpi_tickets - ) as list_date_union - ) as list_date - LEFT JOIN glpi_tickets - ON glpi_tickets.date <= list_date.period_l - AND (glpi_tickets.solvedate > list_date.period_l OR glpi_tickets.solvedate IS NULL) - {$this->sql_join_tu} - {$this->sql_join_gt} - {$this->sql_join_gtr} - WHERE glpi_tickets.entities_id IN ({$this->where_entities}) - AND glpi_tickets.is_deleted = '0' - AND {$this->sql_type} - AND {$this->sql_group_assign} - AND {$this->sql_group_request} - AND {$this->sql_user_assign} - AND {$this->sql_itilcat} - AND $sql_date_backlog - GROUP BY period"; - foreach ($DB->request($sql_backlog) as $data) { + + $subqueries = []; + + $subqueries[] = [ + 'SELECT' => [$this->criteria_list_date], + 'FROM' => Ticket::getTable(), + ]; + + $subqueries[] = [ + 'SELECT' => [$this->criteria_list_date2], + 'FROM' => Ticket::getTable(), + ]; + + $union = new QueryUnion($subqueries, false, 'list_date_union'); + + $list_date_table = [ + 'SELECT' => ['period_l'], + 'FROM' => $union, + 'DISTINCT' => true, + ]; + + $query = [ + 'SELECT' => [ + new QueryExpression("DATE_FORMAT(list_date.period_l, '{$this->period_sort}') as period"), + new QueryExpression("DATE_FORMAT(list_date.period_l, '{$this->period_label}') as period_name"), + ], + 'COUNT' => 'nb', + 'FROM' => new QuerySubQuery($list_date_table, 'list_date'), + 'LEFT JOIN' => array_merge( + [ + Ticket::getTable() => [ + 'FKEY' => [ + Ticket::getTable() . '.date', + 'list_date.period_l', + [ + 'AND' => [ + Ticket::getTable() . '.solvedate > list_date.period_l', + new QueryExpression(Ticket::getTable() . '.solvedate IS NULL'), + ], + ], + ], + ] + ], + $this->criteria_join_tu, + $this->criteria_join_gt, + $this->criteria_join_gtr, + ), + 'WHERE' => array_merge( + [ + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Ticket::getTable() . '.is_deleted' => 0, + new QueryExpression("DATE_FORMAT(list_date.period_l, '{$this->period_sort}') >= '$begin'"), + new QueryExpression("DATE_FORMAT(list_date.period_l, '{$this->period_sort}') <= '$end'"), + ], + $this->criteria_type, + $this->criteria_group_assign, + $this->criteria_group_request, + $this->criteria_user_assign, + $this->criteria_itilcat, + ), + 'GROUPBY' => ['period'], + ]; + + foreach ($DB->request($query) as $data) { $tab[$data['period']]['backlog'] = $data['nb']; $tab[$data['period']]['period_name'] = $data['period_name']; } } if ($search_closed) { - $sql_closed = "SELECT - DISTINCT DATE_FORMAT(closedate, '{$this->period_sort}') as period, - DATE_FORMAT(closedate, '{$this->period_label}') as period_name, - COUNT(DISTINCT glpi_tickets.id) as nb - FROM glpi_tickets - {$this->sql_join_tu} - {$this->sql_join_gt} - {$this->sql_join_gtr} - WHERE {$this->sql_date_closed} - AND glpi_tickets.entities_id IN ({$this->where_entities}) - AND glpi_tickets.is_deleted = '0' - AND {$this->sql_type} - AND {$this->sql_group_assign} - AND {$this->sql_group_request} - AND {$this->sql_user_assign} - AND {$this->sql_itilcat} - GROUP BY period - ORDER BY period"; - foreach ($DB->request($sql_closed) as $data) { + $query = [ + "SELECT" => [ + new QueryExpression("DATE_FORMAT(" . Ticket::getTable() . ".closedate, " . $DB->quoteValue($this->period_sort) . ") as period"), + new QueryExpression("DATE_FORMAT(" . Ticket::getTable() . ".closedate, " . $DB->quoteValue($this->period_label) . ") as period_name"), + ], + 'COUNT' => 'nb', + 'FROM' => Ticket::getTable(), + 'LEFT JOIN' => array_merge( + $this->criteria_join_tu, + $this->criteria_join_gt, + $this->criteria_join_gtr, + ), + 'WHERE' => array_merge( + [ + Ticket::getTable() . '.entities_id' => PluginMreportingCommon::formatWhereEntitiesArray($this->where_entities), + Ticket::getTable() . '.is_deleted' => 0, + ], + $this->criteria_type, + $this->criteria_group_assign, + $this->criteria_group_request, + $this->criteria_user_assign, + $this->criteria_itilcat, + ), + 'GROUPBY' => ['period'], + 'ORDER' => ['period'], + ]; + $query['WHERE']['AND'] = $delay_closed; + + foreach ($DB->request($query) as $data) { $tab[$data['period']]['closed'] = $data['nb']; $tab[$data['period']]['period_name'] = $data['period_name']; } @@ -804,7 +803,7 @@ public function reportVstackbarGroupChange($config = []) 'AND' => [ Log::getTable() . '.itemtype' => 'Ticket', Log::getTable() . '.itemtype_link' => Group::class, - log::getTable() . '.linked_action' => 15, + Log::getTable() . '.linked_action' => 15, ], ], ], @@ -1307,7 +1306,7 @@ public function reportVstackbarRespectedSlasByGroup($config = []) 'SELECT' => [ Group_Ticket::getTable() . '.groups_id as groups_id', SLA::getTable() . '.name', - $this->sql_select_sla, + $this->criteria_select_sla, ], 'COUNT' => 'nb', 'FROM' => Ticket::getTable(), @@ -1409,7 +1408,7 @@ public function reportVstackbarNbTicketBySla($config = []) $query = [ 'SELECT' => [ SLA::getTable() . '.name', - $this->sql_select_sla, + $this->criteria_select_sla, ], 'COUNT' => 'nb', 'FROM' => Ticket::getTable(), diff --git a/inc/profile.class.php b/inc/profile.class.php index 9ecddd34..a496a1ac 100644 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -107,16 +107,13 @@ public function getFromDBByProfile($profiles_id) 'profiles_id' => $profiles_id, ], ]; - if ($result = $DB->request($query)) { - if ($result->numrows() != 1) { - return false; - } - $this->fields = $result->current(); - - return (is_array($this->fields) && count($this->fields)); + $result = $DB->request($query); + if ($result->numrows() != 1) { + return false; } + $this->fields = $result->current(); - return false; + return (is_array($this->fields) && count($this->fields)); } /** diff --git a/inc/tag.class.php b/inc/tag.class.php index aa5f52e5..e23640bb 100644 --- a/inc/tag.class.php +++ b/inc/tag.class.php @@ -52,19 +52,19 @@ public function reportPieTag($config = []) $query = [ 'SELECT' => [ - PluginTagTag::getTable() . '.name AS name', + 'glpi_plugin_tag_tags.name AS name', ], 'COUNT' => 'count_tag', - 'FROM' => PluginTagTagItem::getTable(), + 'FROM' => 'glpi_plugin_tag_tagitems', 'LEFT JOIN' => [ - PluginTagTag::getTable() => [ + 'glpi_plugin_tag_tags' => [ 'ON' => [ - PluginTagTag::getTable() . '.id', - PluginTagTagItem::getTable() . '.plugin_tag_tags_id', + 'glpi_plugin_tag_tags.id', + 'glpi_plugin_tag_tagitems.plugin_tag_tags_id', ], ], ], - 'GROUPBY' => PluginTagTagItem::getTable() . '.plugin_tag_tags_id', + 'GROUPBY' => 'glpi_plugin_tag_tagitems.plugin_tag_tags_id', 'ORDERBY' => 'count_tag DESC', ]; @@ -109,21 +109,21 @@ public function reportPieTagOnTicket($config = []) $query = [ 'SELECT' => [ - PluginTagTag::getTable() . '.name AS name', + 'glpi_plugin_tag_tags.name AS name', ], 'COUNT' => 'count_tag', - 'FROM' => PluginTagTagItem::getTable(), + 'FROM' => 'glpi_plugin_tag_tagitems', 'LEFT JOIN' => [ - PluginTagTag::getTable() => [ + 'glpi_plugin_tag_tags' => [ 'ON' => [ - PluginTagTag::getTable() . '.id', - PluginTagTagItem::getTable() . '.plugin_tag_tags_id', + 'glpi_plugin_tag_tags.id', + 'glpi_plugin_tag_tagitems.plugin_tag_tags_id', ], ], Ticket::getTable() => [ 'ON' => [ Ticket::getTable() . '.id', - PluginTagTagItem::getTable() . '.items_id', + 'glpi_plugin_tag_tagitems.items_id', ], ], ], @@ -133,7 +133,7 @@ public function reportPieTagOnTicket($config = []) ], $criteria_cat, ), - 'GROUPBY' => PluginTagTagItem::getTable() . '.plugin_tag_tags_id', + 'GROUPBY' => 'glpi_plugin_tag_tagitems.plugin_tag_tags_id', 'ORDERBY' => 'count_tag DESC', ]; From 516b22852a121a687bf8fc9b43cc1f2522c33fbd Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Tue, 3 Jun 2025 16:33:55 +0200 Subject: [PATCH 19/24] fix graph error --- inc/helpdeskplus.class.php | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/inc/helpdeskplus.class.php b/inc/helpdeskplus.class.php index 73ee942a..537b082a 100644 --- a/inc/helpdeskplus.class.php +++ b/inc/helpdeskplus.class.php @@ -350,17 +350,12 @@ public function reportGlineBacklogs($config = []) 'LEFT JOIN' => array_merge( [ Ticket::getTable() => [ - 'FKEY' => [ - Ticket::getTable() . '.date', - 'list_date.period_l', - [ - 'AND' => [ - Ticket::getTable() . '.solvedate > list_date.period_l', - new QueryExpression(Ticket::getTable() . '.solvedate IS NULL'), - ], - ], + 'OR' => [ + Ticket::getTable() . '.solvedate > list_date.period_l', + new QueryExpression(Ticket::getTable() . '.solvedate IS NULL'), + Ticket::getTable() . '.date' => ['<=', 'list_date.period_l'], ], - ] + ], ], $this->criteria_join_tu, $this->criteria_join_gt, @@ -382,7 +377,9 @@ public function reportGlineBacklogs($config = []) 'GROUPBY' => ['period'], ]; - foreach ($DB->request($query) as $data) { + $result = $DB->request($query); + + foreach ($result as $data) { $tab[$data['period']]['backlog'] = $data['nb']; $tab[$data['period']]['period_name'] = $data['period_name']; } From 7c2246779bfb20bb4a9bc6171bf51023bacc9834 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Fri, 13 Jun 2025 11:33:18 +0200 Subject: [PATCH 20/24] phpstan 5 --- front/central.php | 1 - front/graph.php | 2 +- hook.php | 59 ++++++++++++++++++++++++++++++------------ inc/common.class.php | 2 +- inc/graph.class.php | 24 ++++++++--------- inc/graphcsv.class.php | 4 +-- inc/graphpng.class.php | 28 ++++++++++---------- 7 files changed, 72 insertions(+), 48 deletions(-) diff --git a/front/central.php b/front/central.php index 27b487b6..972dd046 100644 --- a/front/central.php +++ b/front/central.php @@ -56,7 +56,6 @@ //we found all reports for classname where current profil have right $result = $DB->request([ - 'SELECT' => '*', 'FROM' => 'glpi_plugin_mreporting_configs', 'LEFT JOIN' => [ 'glpi_plugin_mreporting_profiles' => [ diff --git a/front/graph.php b/front/graph.php index e02b0c9b..e384ee2a 100644 --- a/front/graph.php +++ b/front/graph.php @@ -9,7 +9,7 @@ * * This file is part of Mreporting. * - * Mreporting is free software; you can redistribute it and/or modify + * Mreporting is free software; you can redistribute it and/o.clr modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. diff --git a/hook.php b/hook.php index 445927b1..19cccb44 100644 --- a/hook.php +++ b/hook.php @@ -108,18 +108,43 @@ function plugin_mreporting_install() $res_display_pref = $DB->request($query_display_pref); if ($res_display_pref->numrows() == 0) { - $queries[] = "INSERT INTO `glpi_displaypreferences` - VALUES (NULL,'PluginMreportingConfig','2','2','0');"; - $queries[] = "INSERT INTO `glpi_displaypreferences` - VALUES (NULL,'PluginMreportingConfig','3','3','0');"; - $queries[] = "INSERT INTO `glpi_displaypreferences` - VALUES (NULL,'PluginMreportingConfig','4','4','0');"; - $queries[] = "INSERT INTO `glpi_displaypreferences` - VALUES (NULL,'PluginMreportingConfig','5','5','0');"; - $queries[] = "INSERT INTO `glpi_displaypreferences` - VALUES (NULL,'PluginMreportingConfig','6','6','0');"; - $queries[] = "INSERT INTO `glpi_displaypreferences` - VALUES (NULL,'PluginMreportingConfig','8','8','0');"; + $display_preference = new DisplayPreference(); + $display_preference->add([ + 'itemtype' => 'PluginMreportingConfig', + 'num' => '2', + 'rank' => '2', + 'users_id' => 0, + ]); + $display_preference->add([ + 'itemtype' => 'PluginMreportingConfig', + 'num' => '3', + 'rank' => '3', + 'users_id' => 0, + ]); + $display_preference->add([ + 'itemtype' => 'PluginMreportingConfig', + 'num' => '4', + 'rank' => '4', + 'users_id' => 0, + ]); + $display_preference->add([ + 'itemtype' => 'PluginMreportingConfig', + 'num' => '5', + 'rank' => '5', + 'users_id' => 0, + ]); + $display_preference->add([ + 'itemtype' => 'PluginMreportingConfig', + 'num' => '6', + 'rank' => '6', + 'users_id' => 0, + ]); + $display_preference->add([ + 'itemtype' => 'PluginMreportingConfig', + 'num' => '8', + 'rank' => '8', + 'users_id' => 0, + ]); } $queries[] = "CREATE TABLE IF NOT EXISTS `glpi_plugin_mreporting_notifications` ( @@ -138,7 +163,7 @@ function plugin_mreporting_install() ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; foreach ($queries as $query) { - $DB->doQueryOrDie($query); + $DB->doQuery($query); } // == Update to 2.1 == @@ -160,7 +185,7 @@ function plugin_mreporting_install() //truncate profile table $query = 'TRUNCATE TABLE `glpi_plugin_mreporting_profiles`'; - $DB->doQueryOrDie($query); + $DB->doQuery($query); //migration of field $migration->addField('glpi_plugin_mreporting_profiles', 'right', 'char'); @@ -183,7 +208,7 @@ function plugin_mreporting_install() // == UPDATE to 0.84+1.0 == //$query = 'UPDATE `glpi_plugin_mreporting_profiles` pr SET pr.right = ' . READ . " WHERE pr.right = 'r'"; - $DB->updateOrDie( + $DB->update( 'glpi_plugin_mreporting_profiles', ['right' => READ], ['right' => 'r'], @@ -191,11 +216,11 @@ function plugin_mreporting_install() if (!isIndex('glpi_plugin_mreporting_profiles', 'profiles_id_reports')) { $query = 'ALTER TABLE glpi_plugin_mreporting_profiles ADD UNIQUE INDEX `profiles_id_reports` (`profiles_id`, `reports`)'; - $DB->doQueryOrDie($query); + $DB->doQuery($query); } // Remove GLPI graphtype to fix compatibility with GLPI 9.2.2+ - $DB->updateOrDie( + $DB->update( 'glpi_plugin_mreporting_configs', ['graphtype' => 'SVG'], ['graphtype' => 'GLPI'], diff --git a/inc/common.class.php b/inc/common.class.php index 27413bbe..2647cd97 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -647,7 +647,7 @@ public function showGraph($opt, $export = false, $forceFormat = null) if (!isset($_SESSION['mreporting_values']['date1' . $config['randname']])) { $_SESSION['mreporting_values']['date1' . $config['randname']] = date( 'Y-m-d', - time() - ((intval($config['delay'])) * 24 * 60 * 60), + time() - (intval($config['delay']) * 24 * 60 * 60), ); } if (!isset($_SESSION['mreporting_values']['date2' . $config['randname']])) { diff --git a/inc/graph.class.php b/inc/graph.class.php index f796f2a2..1431997e 100644 --- a/inc/graph.class.php +++ b/inc/graph.class.php @@ -534,7 +534,7 @@ public function showPie($params, $dashboard = false, $width = false) * @param $show_label : behavior of the graph labels, * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) - * @return void|bool + * @return void|string */ public function showSunburst($params, $dashboard = false, $width = false) { @@ -586,7 +586,7 @@ public function showSunburst($params, $dashboard = false, $width = false) $end['opt']['class'] = $opt['class']; PluginMreportingCommon::endGraph($end, $dashboard); - return false; + return ''; } $datas = $raw_datas['datas']; @@ -811,7 +811,7 @@ function getLevelNbNode(node) { * @param $show_label : behavior of the graph labels, * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) - * @return void|bool + * @return void|string */ public function showHgbar($params, $dashboard = false, $width = false) { @@ -857,7 +857,7 @@ public function showHgbar($params, $dashboard = false, $width = false) $end['opt']['class'] = $opt['class']; PluginMreportingCommon::endGraph($end, $dashboard); - return false; + return ''; } if (empty($unit) && !empty($raw_datas['unit'])) { @@ -1040,7 +1040,7 @@ public function showHgbar($params, $dashboard = false, $width = false) * @param $show_label : behavior of the graph labels, * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) - * @return void|bool + * @return void|string */ public function showVstackbar($params, $dashboard = false, $width = false) { @@ -1086,7 +1086,7 @@ public function showVstackbar($params, $dashboard = false, $width = false) $end['opt']['class'] = $opt['class']; PluginMreportingCommon::endGraph($end, $dashboard); - return false; + return ''; } if (empty($unit) && !empty($raw_datas['unit'])) { @@ -1274,7 +1274,7 @@ public function showVstackbar($params, $dashboard = false, $width = false) * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) * @param $area : show plain chart instead only a line (optionnal) - * @return void|bool + * @return void|string */ public function showArea($params, $dashboard = false, $width = false) { @@ -1326,7 +1326,7 @@ public function showArea($params, $dashboard = false, $width = false) $end['opt']['class'] = $opt['class']; PluginMreportingCommon::endGraph($end, $dashboard); - return false; + return ''; } if (empty($unit) && !empty($raw_datas['unit'])) { @@ -1509,7 +1509,7 @@ public function showArea($params, $dashboard = false, $width = false) * @param $show_label : behavior of the graph labels, * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) - * @return void|bool|null + * @return void|string */ public function showLine($params, $dashboard = false, $width = false) { @@ -1533,7 +1533,7 @@ public function showLine($params, $dashboard = false, $width = false) * @param $show_label : behavior of the graph labels, * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) - * @return void|bool + * @return void|string */ public function showGarea($params, $dashboard = false, $width = false) { @@ -1582,7 +1582,7 @@ public function showGarea($params, $dashboard = false, $width = false) $end['opt']['class'] = $opt['class']; PluginMreportingCommon::endGraph($end, $dashboard); - return false; + return ''; } $area = true; @@ -1787,7 +1787,7 @@ public function showGarea($params, $dashboard = false, $width = false) * @param $show_label : behavior of the graph labels, * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) - * @return void|bool|null + * @return void|string */ public function showGline($params, $dashboard = false, $width = false) { diff --git a/inc/graphcsv.class.php b/inc/graphcsv.class.php index d34b02e3..5068c9f0 100644 --- a/inc/graphcsv.class.php +++ b/inc/graphcsv.class.php @@ -132,7 +132,7 @@ public function showHgbar($params, $dashboard = false, $width = false) $datas = isset($raw_datas['datas']) ? $raw_datas['datas'] : []; if (count($datas) <= 0) { - return false; + return ''; } [ @@ -221,7 +221,7 @@ public function showSunburst($params, $dashboard = false, $width = false) } if (count($datas) <= 0) { - return false; + return ''; } [ diff --git a/inc/graphpng.class.php b/inc/graphpng.class.php index a620f1f4..64440a77 100644 --- a/inc/graphpng.class.php +++ b/inc/graphpng.class.php @@ -556,7 +556,7 @@ public function imageCubicSmoothLine($image, $color, $coords) * @param $show_label : behavior of the graph labels, * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) - * @return void|bool + * @return void|string */ public function showHbar($params, $dashboard = false, $width = false) { @@ -615,7 +615,7 @@ public function showHbar($params, $dashboard = false, $width = false) PluginMreportingCommon::endGraph($end); } - return false; + return ''; } if (empty($unit) && !empty($raw_datas['unit'])) { @@ -760,7 +760,7 @@ public function showHbar($params, $dashboard = false, $width = false) * @param $show_label : behavior of the graph labels, * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) - * @return void|bool + * @return void|string */ public function showPie($params, $dashboard = false, $width = false) { @@ -817,7 +817,7 @@ public function showPie($params, $dashboard = false, $width = false) PluginMreportingCommon::endGraph($end); } - return false; + return ''; } if (empty($unit) && !empty($raw_datas['unit'])) { @@ -1008,7 +1008,7 @@ public function showPie($params, $dashboard = false, $width = false) * @param $show_label : behavior of the graph labels, * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) - * @return void|bool + * @return void|string */ public function showSunburst($params, $dashboard = false, $width = false) { @@ -1061,7 +1061,7 @@ public function showSunburst($params, $dashboard = false, $width = false) PluginMreportingCommon::endGraph($end); } - return false; + return ''; } $labels2 = []; @@ -1345,7 +1345,7 @@ public function drawSunburstLevel($image, $datas, $params = []) * @param $show_label : behavior of the graph labels, * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) - * @return void|bool + * @return void|string */ public function showHgbar($params, $dashboard = false, $width = false) { @@ -1405,7 +1405,7 @@ public function showHgbar($params, $dashboard = false, $width = false) PluginMreportingCommon::endGraph($end); } - return false; + return ''; } $labels2 = $raw_datas['labels2']; @@ -1600,7 +1600,7 @@ public function showHgbar($params, $dashboard = false, $width = false) * @param $show_label : behavior of the graph labels, * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) - * @return void|bool + * @return void|string */ public function showVstackbar($params, $dashboard = false, $width = false) { @@ -1660,7 +1660,7 @@ public function showVstackbar($params, $dashboard = false, $width = false) PluginMreportingCommon::endGraph($end); } - return false; + return ''; } $labels2 = $raw_datas['labels2']; @@ -1946,7 +1946,7 @@ public function showVstackbar($params, $dashboard = false, $width = false) * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) * @param $area : show plain chart instead only a line (optionnal) - * @return void|bool + * @return void|string */ public function showArea($params, $dashboard = false, $width = false) { @@ -2007,7 +2007,7 @@ public function showArea($params, $dashboard = false, $width = false) PluginMreportingCommon::endGraph($end); } - return false; + return ''; } if (empty($unit) && !empty($raw_datas['unit'])) { @@ -2277,7 +2277,7 @@ public function showArea($params, $dashboard = false, $width = false) * @param $show_label : behavior of the graph labels, * values : 'hover', 'never', 'always' (optionnal) * @param $export : keep only svg to export (optionnal) - * @return void|bool + * @return void|string */ public function showGArea($params, $dashboard = false, $width = false) { @@ -2339,7 +2339,7 @@ public function showGArea($params, $dashboard = false, $width = false) PluginMreportingCommon::endGraph($end); } - return false; + return ''; } $labels2 = $raw_datas['labels2']; From 666d80ac6693f57ecc8f6e2ff0426f9952d664fc Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Wed, 18 Jun 2025 09:57:17 +0200 Subject: [PATCH 21/24] fix herder --- front/graph.php | 2 +- inc/inventory.class.php | 2 -- inc/other.class.php | 2 -- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/front/graph.php b/front/graph.php index e384ee2a..e02b0c9b 100644 --- a/front/graph.php +++ b/front/graph.php @@ -9,7 +9,7 @@ * * This file is part of Mreporting. * - * Mreporting is free software; you can redistribute it and/o.clr modify + * Mreporting is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. diff --git a/inc/inventory.class.php b/inc/inventory.class.php index 52d32f0f..12c31860 100644 --- a/inc/inventory.class.php +++ b/inc/inventory.class.php @@ -1,7 +1,5 @@ Date: Wed, 18 Jun 2025 15:56:56 +0200 Subject: [PATCH 22/24] phpstan5 --- hook.php | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/hook.php b/hook.php index 19cccb44..73fecd47 100644 --- a/hook.php +++ b/hook.php @@ -48,18 +48,17 @@ function plugin_mreporting_install() $default_key_sign = DBConnection::getDefaultPrimaryKeySignOption(); //create profiles table - $queries = []; - $queries[] = "CREATE TABLE IF NOT EXISTS `glpi_plugin_mreporting_profiles` ( + $DB->doQuery("CREATE TABLE IF NOT EXISTS `glpi_plugin_mreporting_profiles` ( `id` INT {$default_key_sign} NOT NULL AUTO_INCREMENT, `profiles_id` VARCHAR(45) NOT NULL, `reports` CHAR(1), PRIMARY KEY (`id`), UNIQUE `profiles_id_reports` (`profiles_id`, `reports`) ) - ENGINE = InnoDB;"; + ENGINE = InnoDB;"); //create configuration table - $queries[] = "CREATE TABLE IF NOT EXISTS `glpi_plugin_mreporting_configs` ( + $DB->doQuery("CREATE TABLE IF NOT EXISTS `glpi_plugin_mreporting_configs` ( `id` int {$default_key_sign} NOT NULL auto_increment, `name` varchar(255) default NULL, `classname` varchar(255) default NULL, @@ -76,24 +75,24 @@ function plugin_mreporting_install() `graphtype` VARCHAR(255) default 'SVG', PRIMARY KEY (`id`), KEY `is_active` (`is_active`) - ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; + ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"); //create configuration table - $queries[] = "CREATE TABLE IF NOT EXISTS `glpi_plugin_mreporting_dashboards` ( + $DB->doQuery("CREATE TABLE IF NOT EXISTS `glpi_plugin_mreporting_dashboards` ( `id` int {$default_key_sign} NOT NULL auto_increment, `users_id` int {$default_key_sign} NOT NULL, `reports_id`int {$default_key_sign} NOT NULL, `configuration` VARCHAR(500) default NULL, PRIMARY KEY (`id`) - ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; + ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"); - $queries[] = "CREATE TABLE IF NOT EXISTS `glpi_plugin_mreporting_preferences` ( + $DB->doQuery("CREATE TABLE IF NOT EXISTS `glpi_plugin_mreporting_preferences` ( `id` int {$default_key_sign} NOT NULL auto_increment, `users_id` int {$default_key_sign} NOT NULL default 0, `template` varchar(255) default NULL, PRIMARY KEY (`id`), KEY `users_id` (`users_id`) - ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; + ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"); // add display preferences $query_display_pref = [ @@ -147,7 +146,7 @@ function plugin_mreporting_install() ]); } - $queries[] = "CREATE TABLE IF NOT EXISTS `glpi_plugin_mreporting_notifications` ( + $DB->doQuery("CREATE TABLE IF NOT EXISTS `glpi_plugin_mreporting_notifications` ( `id` int {$default_key_sign} NOT NULL auto_increment, `entities_id` int {$default_key_sign} NOT NULL default '0', `is_recursive` tinyint NOT NULL default '0', @@ -160,11 +159,7 @@ function plugin_mreporting_install() `date_mod` timestamp NULL default NULL, `is_deleted` tinyint NOT NULL default '0', PRIMARY KEY (`id`) - ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; - - foreach ($queries as $query) { - $DB->doQuery($query); - } + ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"); // == Update to 2.1 == $migration->addField( @@ -207,7 +202,6 @@ function plugin_mreporting_install() } // == UPDATE to 0.84+1.0 == - //$query = 'UPDATE `glpi_plugin_mreporting_profiles` pr SET pr.right = ' . READ . " WHERE pr.right = 'r'"; $DB->update( 'glpi_plugin_mreporting_profiles', ['right' => READ], From 4e44463ccdee7e7f263f7cdd117aaed3c75842f0 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Wed, 2 Jul 2025 14:11:58 +0200 Subject: [PATCH 23/24] review --- inc/helpdeskplus.class.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/inc/helpdeskplus.class.php b/inc/helpdeskplus.class.php index 537b082a..df032566 100644 --- a/inc/helpdeskplus.class.php +++ b/inc/helpdeskplus.class.php @@ -323,13 +323,15 @@ public function reportGlineBacklogs($config = []) $subqueries = []; $subqueries[] = [ - 'SELECT' => [$this->criteria_list_date], - 'FROM' => Ticket::getTable(), + 'SELECT' => [$this->criteria_list_date], + 'DISTINCT' => true, + 'FROM' => Ticket::getTable(), ]; $subqueries[] = [ - 'SELECT' => [$this->criteria_list_date2], - 'FROM' => Ticket::getTable(), + 'SELECT' => [$this->criteria_list_date2], + 'DISTINCT' => true, + 'FROM' => Ticket::getTable(), ]; $union = new QueryUnion($subqueries, false, 'list_date_union'); From 94d3d2f0586302e016322121563cb8461484bac0 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Wed, 2 Jul 2025 14:15:22 +0200 Subject: [PATCH 24/24] rebase --- composer.lock | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/composer.lock b/composer.lock index 1f609c64..5f338a67 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "71b413b917a096d0030738b7446ab66a", + "content-hash": "1fc15070b1ae5a5dd502fb56e3d8dc67", "packages": [ { "name": "masnathan/odtphp", @@ -466,16 +466,16 @@ }, { "name": "friendsofphp/php-cs-fixer", - "version": "v3.75.0", + "version": "v3.76.0", "source": { "type": "git", "url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git", - "reference": "399a128ff2fdaf4281e4e79b755693286cdf325c" + "reference": "0e3c484cef0ae9314b0f85986a36296087432c40" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/399a128ff2fdaf4281e4e79b755693286cdf325c", - "reference": "399a128ff2fdaf4281e4e79b755693286cdf325c", + "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/0e3c484cef0ae9314b0f85986a36296087432c40", + "reference": "0e3c484cef0ae9314b0f85986a36296087432c40", "shasum": "" }, "require": { @@ -559,7 +559,7 @@ ], "support": { "issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues", - "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.75.0" + "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.76.0" }, "funding": [ { @@ -567,7 +567,7 @@ "type": "github" } ], - "time": "2025-03-31T18:40:42+00:00" + "time": "2025-06-30T14:15:06+00:00" }, { "name": "glpi-project/tools", @@ -794,21 +794,21 @@ }, { "name": "phpstan/phpstan-deprecation-rules", - "version": "2.0.1", + "version": "2.0.3", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-deprecation-rules.git", - "reference": "1cc1259cb91ee4cfbb5c39bca9f635f067c910b4" + "reference": "468e02c9176891cc901143da118f09dc9505fc2f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/1cc1259cb91ee4cfbb5c39bca9f635f067c910b4", - "reference": "1cc1259cb91ee4cfbb5c39bca9f635f067c910b4", + "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/468e02c9176891cc901143da118f09dc9505fc2f", + "reference": "468e02c9176891cc901143da118f09dc9505fc2f", "shasum": "" }, "require": { "php": "^7.4 || ^8.0", - "phpstan/phpstan": "^2.0" + "phpstan/phpstan": "^2.1.15" }, "require-dev": { "php-parallel-lint/php-parallel-lint": "^1.2", @@ -835,9 +835,9 @@ "description": "PHPStan rules for detecting usage of deprecated classes, methods, properties, constants and traits.", "support": { "issues": "https://github.com/phpstan/phpstan-deprecation-rules/issues", - "source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/2.0.1" + "source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/2.0.3" }, - "time": "2024-11-28T21:56:36+00:00" + "time": "2025-05-14T10:56:57+00:00" }, { "name": "psr/container",