Skip to content

Commit

Permalink
Add category filter on all itilcategories level and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sthivet committed Sep 4, 2023
1 parent 568287c commit 5b8aee2
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 14 deletions.
57 changes: 52 additions & 5 deletions inc/helper.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -793,9 +793,9 @@ public static function manageCriterias($params)
$crit['crit']['status'] = $status;
}
}
//ITILCATEGORY
//ITILCATEGORY_LVL1
$opt['itilcategorielvl1'] = 0;
$crit['crit']['itilcategorielvl1'] = "AND 1 = 1";
$crit['crit']['itilcategorielvl1'] = " AND 1 = 1 ";
if (in_array("itilcategorielvl1", $criterias)) {
if (isset($params['preferences']['prefered_category'])
&& $params['preferences']['prefered_category'] > 0 && !isset($params['opt']['itilcategorielvl1'])) {
Expand All @@ -818,6 +818,27 @@ public static function manageCriterias($params)
$crit['crit']['itilcategorielvl1'] = " AND `glpi_tickets`.`itilcategories_id` IN ( " . $categories . ") ";
}

//ITILCATEGORY
$opt['itilcategory'] = 0;
$crit['crit']['itilcategory'] = " AND 1 = 1";
if (in_array("itilcategory", $criterias)) {
if (isset($params['preferences']['prefered_category'])
&& $params['preferences']['prefered_category'] > 0 && !isset($params['opt']['itilcategory'])) {
$opt['itilcategory'] = $params['preferences']['prefered_category'];
} else if (isset($params['opt']["itilcategory"])
&& $params['opt']["itilcategory"] > 0) {
$opt['itilcategory'] = $params['opt']['itilcategory'];
}
if ($opt['itilcategory'] > 0) {
$category = new ITILCategory();
if ($category->getFromDB($opt['itilcategory'])) {
$crit['crit']['itilcategory'] = " AND `glpi_tickets`.`itilcategories_id` = " . $opt['itilcategory'] . " ";
}
} else {
$crit['crit']['itilcategory'] = " AND 1 = 1 ";
}
}

//TAG
$opt['tag'] = 0;
$crit['crit']['tag'] = "AND 1 = 1";
Expand Down Expand Up @@ -980,6 +1001,10 @@ public static function getFormHeader($widgetId, $gsid, $onsubmit = false, $opt =
$form .= " / " . __("Category", 'mydashobard') . " : " . Dropdown::getDropdownName('glpi_itilcategories', $opt['itilcategorielvl1']);
}

if (isset($opt['itilcategory']) && $opt['itilcategory'] > 0) {
$form .= " / " . __("Category", 'mydashobard') . " : " . Dropdown::getDropdownName('glpi_itilcategories', $opt['itilcategory']);
}

$form .= "</span>";
$form .= "</div>";
$form .= "<div class='plugin_mydashboard_menuWidget' id='plugin_mydashboard_see_criteria$rand'>";
Expand Down Expand Up @@ -1097,7 +1122,6 @@ public static function getForm($widgetId, $opt, $criterias, $onsubmit = false)
$dropdown = Dropdown::showFromArray("multiple_locations_id", $temp, $params);

$form .= $dropdown;

$form .= "</span>";
if ($count > 1) {
$form .= "</br></br>";
Expand Down Expand Up @@ -1753,11 +1777,34 @@ public static function getForm($widgetId, $opt, $criterias, $onsubmit = false)
}
}

//ITILCATEGORY LVL1
if (in_array("itilcategorielvl1", $criterias)) {
$form .= "<span class='md-widgetcrit'>";

$form .= __('Category', 'mydashboard');
$form .= "&nbsp;";
$dbu = new DbUtils();
if (isset($_POST["params"]['entities_id'])) {
$restrict = $dbu->getEntitiesRestrictCriteria('glpi_entities', '', $_POST["params"]['entities_id'], $_POST["params"]['sons']);
} else {
$restrict = $dbu->getEntitiesRestrictCriteria('glpi_entities', '', $opt['entities_id'], $opt['sons']);
}

//
$dropdown = ITILCategory::dropdown(['name' => 'itilcategorielvl1', 'value' => $opt['itilcategorielvl1'], 'display' => false, 'condition' => ['level' => 1, ['OR' => ['is_request' => 1, 'is_incident' => 1]]]] + $restrict);

$form .= $dropdown;

$form .= "</span>";


if ($count > 1) {
$form .= "</br></br>";
}
}

//ITILCATEGORY
if (in_array("itilcategory", $criterias)) {
$form .= "<span class='md-widgetcrit'>";

$form .= __('Category', 'mydashboard');
$form .= "&nbsp;";
Expand All @@ -1768,7 +1815,7 @@ public static function getForm($widgetId, $opt, $criterias, $onsubmit = false)
$restrict = $dbu->getEntitiesRestrictCriteria('glpi_entities', '', $opt['entities_id'], $opt['sons']);
}

$dropdown = ITILCategory::dropdown(['name' => 'itilcategorielvl1', 'value' => $opt['itilcategorielvl1'], 'display' => false, 'condition' => ['level' => 1, ['OR' => ['is_request' => 1, 'is_incident' => 1]]]] + $restrict);
$dropdown = ITILCategory::dropdown(['name' => 'itilcategory', 'value' => $opt['itilcategory'], 'display' => false, 'condition' => ['OR' => ['is_request' => 1, 'is_incident' => 1]]] + $restrict);

$form .= $dropdown;

Expand Down
2 changes: 1 addition & 1 deletion inc/preference.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public function showPreferencesForm($user_id)
'width' => '200px',
'entity' => $_SESSION['glpiactiveentities'],
'display_emptychoice' => true,
'condition' => ['level' => 1, ['OR' => ['is_request' => 1, 'is_incident' => 1]]]
'condition' => [['OR' => ['is_request' => 1, 'is_incident' => 1]]]
];

$dropdownCategory = ITILCategory::dropdown($params);
Expand Down
18 changes: 18 additions & 0 deletions reports/alert.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2969,6 +2969,24 @@ public static function displayIndicator($id, $type, $params = [], $iswidget = fa
$category_criteria = " AND `glpi_tickets`.`itilcategories_id` = " . $params['itilcategorielvl1'];
}
}

if(!isset($params['ititlcategory'])){
$params['ititlcategory'] = "";
if(isset($preferences['prefered_category'])){
if($preferences['prefered_category'] != 0){
$params['ititlcategory'] = $preferences['prefered_category'];
$category_criteria = " AND `glpi_tickets`.`itilcategories_id` = " . $preferences['prefered_category'];
} else {
$category_criteria = " AND 1=1";
}
}
} else {
if($params['ititlcategory'] == 0){
$category_criteria = " AND 1=1";
} else {
$category_criteria = " AND `glpi_tickets`.`itilcategories_id` = " . $params['ititlcategory'];
}
}
}
$params['entities_id'] = $_SESSION['glpiactive_entity'];
$params['sons'] = 0;
Expand Down
12 changes: 6 additions & 6 deletions reports/reports_bar.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ public function getWidgetContentForItem($widgetId, $opt = [])
'technicians_groups_id',
'group_is_recursive',
'group_is_recursive',
'itilcategorielvl1'];
'itilcategory'];
$onclick = 1;
}
if (isset($_SESSION['glpiactiveprofile']['interface'])
Expand All @@ -874,7 +874,7 @@ public function getWidgetContentForItem($widgetId, $opt = [])
$js_ancestors = $crit['ancestors'];
$technician_group = $opt['technicians_groups_id'];
$technician_groups_criteria = $crit['technicians_groups_id'];
$categories_criteria = $crit['itilcategorielvl1'];
$categories_criteria = $crit['itilcategory'];


$is_deleted = "`glpi_tickets`.`is_deleted` = 0";
Expand Down Expand Up @@ -1024,7 +1024,7 @@ public function getWidgetContentForItem($widgetId, $opt = [])
'type',
'technicians_groups_id',
'group_is_recursive',
'itilcategorielvl1'];
'itilcategory'];
$onclick = 1;
}
if (isset($_SESSION['glpiactiveprofile']['interface'])
Expand All @@ -1047,7 +1047,7 @@ public function getWidgetContentForItem($widgetId, $opt = [])
$is_deleted = "`glpi_tickets`.`is_deleted` = 0";
$technician_group = $opt['technicians_groups_id'];
$technician_groups_criteria = $crit['technicians_groups_id'];
$categories_criteria = $crit['itilcategorielvl1'];
$categories_criteria = $crit['itilcategory'];

$query = "SELECT DISTINCT
`priority`,
Expand Down Expand Up @@ -1127,7 +1127,7 @@ public function getWidgetContentForItem($widgetId, $opt = [])
'type',
'technicians_groups_id',
'group_is_recursive',
'itilcategorielvl1'];
'itilcategory'];
$onclick = 1;
}
if (isset($_SESSION['glpiactiveprofile']['interface'])
Expand All @@ -1150,7 +1150,7 @@ public function getWidgetContentForItem($widgetId, $opt = [])
$is_deleted = "`glpi_tickets`.`is_deleted` = 0";
$technician_group = $opt['technicians_groups_id'];
$technician_groups_criteria = $crit['technicians_groups_id'];
$categories_criteria = $crit['itilcategorielvl1'];
$categories_criteria = $crit['itilcategory'];

$query = "SELECT `glpi_tickets`.`status` AS status, COUNT(`glpi_tickets`.`id`) AS Total
FROM glpi_tickets
Expand Down
4 changes: 2 additions & 2 deletions reports/reports_table.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ public function getWidgetContentForItem($widgetId, $opt = [])
'is_recursive',
'technicians_groups_id',
'group_is_recursive',
'itilcategorielvl1'];
'itilcategory'];
}
if (isset($_SESSION['glpiactiveprofile']['interface'])
&& Session::getCurrentInterface() != 'central') {
Expand All @@ -592,7 +592,7 @@ public function getWidgetContentForItem($widgetId, $opt = [])
$options = PluginMydashboardHelper::manageCriterias($params);
$crit = $options['crit'];
$opt = $options['opt'];
$category_criteria = $crit['itilcategorielvl1'];
$category_criteria = $crit['itilcategory'];
$groups_sql_criteria = "";
$entities_criteria = $crit['entities_id'];
$technician_group = $opt['technicians_groups_id'];
Expand Down

0 comments on commit 5b8aee2

Please sign in to comment.