Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
# Conflicts:
#	reports/reports_bar.class.php
  • Loading branch information
tsmr committed Oct 9, 2023
2 parents 4030dcf + e98005f commit 32894f2
Show file tree
Hide file tree
Showing 10 changed files with 1,956 additions and 390 deletions.
88 changes: 67 additions & 21 deletions inc/helper.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -793,29 +793,49 @@ public static function manageCriterias($params)
$crit['crit']['status'] = $status;
}
}
//TYPE
//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['opt']["itilcategorielvl1"])
if (isset($params['preferences']['prefered_category'])
&& $params['preferences']['prefered_category'] > 0 && !isset($params['opt']['itilcategorielvl1'])) {
$opt['itilcategorielvl1'] = $params['preferences']['prefered_category'];
} else if (isset($params['opt']["itilcategorielvl1"])
&& $params['opt']["itilcategorielvl1"] > 0) {
$opt['itilcategorielvl1'] = $params['opt']['itilcategorielvl1'];
$categorie = new ITILCategory();
$catlvl2 = $categorie->find(['itilcategories_id' => $opt['itilcategorielvl1']]);
$i = 0;
$listcat = "";
foreach ($catlvl2 as $cat) {
if ($i != 0) {
$listcat .= "," . $cat['id'];
} else {
$listcat .= $cat['id'];
}
$i++;
}
if (empty($listcat)) {
$listcat = "0";
}
$category = new ITILCategory();
$catlvl2 = $category->find(['itilcategories_id' => $opt['itilcategorielvl1'], 'is_request' => 1, 'is_incident' => 1]);
$listcat = [];
$listcat[] = $opt['itilcategorielvl1'];
foreach ($catlvl2 as $cat) {
$listcat[] = $cat['id'];
}
$categories = implode(",", $listcat);
if (empty($listcat)) {
$listcat = "0";
}
$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'] . " ";
}
$crit['crit']['itilcategorielvl1'] = " AND `glpi_tickets`.`itilcategories_id` IN ( " . $listcat . ") ";
} else {
$crit['crit']['itilcategory'] = " AND 1 = 1 ";
}
}

Expand Down Expand Up @@ -981,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 @@ -1098,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 @@ -1754,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 @@ -1769,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
20 changes: 20 additions & 0 deletions inc/preference.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,25 @@ public function showPreferencesForm($user_id)
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td>" . __('My favorite category for widgets', 'mydashboard') . "</td>";
echo "<td>";

$params = [
'name' => 'prefered_category',
'value' => $this->fields['prefered_category'],
'multiple' => false,
'display' => false,
'width' => '200px',
'entity' => $_SESSION['glpiactiveentities'],
'display_emptychoice' => true,
'condition' => [['OR' => ['is_request' => 1, 'is_incident' => 1]]]
];

$dropdownCategory = ITILCategory::dropdown($params);
echo $dropdownCategory;
echo "</td>";
echo "</tr>";
echo "<tr class='tab_bg_1'><td>" . __("My prefered type for widget", "mydashboard") . "</td>";
echo "<td>";
$params = ['value' => $this->fields['prefered_type'],'toadd' =>[0 => Dropdown::EMPTY_VALUE]];
Expand Down Expand Up @@ -263,6 +282,7 @@ public function initPreferences($users_id)
$input['replace_central'] = "0";
$input['prefered_group'] = "[]";
$input['requester_prefered_group'] = "[]";
$input['prefered_group'] = "[]";
$input['prefered_entity'] = "0";
$input['color_palette'] = "";
$input['edit_mode'] = "0";
Expand Down
1 change: 1 addition & 0 deletions install/sql/empty-2.1.2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ CREATE TABLE `glpi_plugin_mydashboard_preferences`
`automatic_refresh` tinyint NOT NULL DEFAULT '0',
`automatic_refresh_delay` int unsigned NOT NULL DEFAULT '10',
`nb_widgets_width` int unsigned NOT NULL DEFAULT '3',
`prefered_category` int unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;

Expand Down
1 change: 1 addition & 0 deletions install/sql/update-2.1.2.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ALTER TABLE `glpi_plugin_mydashboard_configs` DROP `display_plugin_widget`;
ALTER TABLE `glpi_plugin_mydashboard_configs` DROP `google_api_key`;
ALTER TABLE `glpi_plugin_mydashboard_preferences` ADD `prefered_category` INT unsigned NOT NULL DEFAULT '0';
Loading

0 comments on commit 32894f2

Please sign in to comment.