Skip to content

Commit 18ddde9

Browse files
committed
feat: update and reorganize search options
1 parent 2127630 commit 18ddde9

5 files changed

Lines changed: 198 additions & 41 deletions

File tree

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?php
2+
3+
/**
4+
* -------------------------------------------------------------------------
5+
* Carbon plugin for GLPI
6+
*
7+
* @copyright Copyright (C) 2024-2025 Teclib' and contributors.
8+
* @license https://www.gnu.org/licenses/gpl-3.0.txt GPLv3+
9+
* @link https://github.com/pluginsGLPI/carbon
10+
*
11+
* -------------------------------------------------------------------------
12+
*
13+
* LICENSE
14+
*
15+
* This file is part of Carbon plugin for GLPI.
16+
*
17+
* This program is free software: you can redistribute it and/or modify
18+
* it under the terms of the GNU General Public License as published by
19+
* the Free Software Foundation, either version 3 of the License, or
20+
* (at your option) any later version.
21+
*
22+
* This program is distributed in the hope that it will be useful,
23+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
24+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25+
* GNU General Public License for more details.
26+
*
27+
* You should have received a copy of the GNU General Public License
28+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
29+
*
30+
* -------------------------------------------------------------------------
31+
*/
32+
33+
use GlpiPlugin\Carbon\EmbodiedImpact;
34+
35+
/** @var DBmysql $DB */
36+
/** @var Migration $migration */
37+
38+
$display_pref = new DisplayPreference();
39+
40+
$plugin_so_base = 128000;
41+
$group_base = 1200;
42+
43+
//
44+
// EmbodiedImpact search options
45+
//
46+
47+
$rows = $display_pref->find([
48+
'itemtype' => EmbodiedImpact::class,
49+
'num' => 5 // Was GWP, now recalculate flag
50+
]);
51+
$id = $plugin_so_base + $group_base;
52+
foreach ($rows as $row) {
53+
$row['num'] = $id;
54+
$display_pref->update($row);
55+
}
56+
57+
$id = $plugin_so_base + $group_base + 2;
58+
$rows = $display_pref->find([
59+
'itemtype' => EmbodiedImpact::class,
60+
'num' => 6 // Was ADP, now recalculate flag
61+
]);
62+
foreach ($rows as $row) {
63+
$row['num'] = $id;
64+
$display_pref->update($row);
65+
}
66+
67+
$id = $plugin_so_base + $group_base + 4;
68+
$rows = $display_pref->find([
69+
'itemtype' => EmbodiedImpact::class,
70+
'num' => 7 // Was PE, now recalculate flag
71+
]);
72+
foreach ($rows as $row) {
73+
$row['num'] = 1204;
74+
$display_pref->update($row);
75+
}
76+
77+
//
78+
// UsageImpact search options
79+
//
80+
$rows = $display_pref->find([
81+
'itemtype' => EmbodiedImpact::class,
82+
'num' => 128701 // usage GWP
83+
]);
84+
$id = $plugin_so_base + $group_base;
85+
foreach ($rows as $row) {
86+
$row['num'] = $id;
87+
$display_pref->update($row);
88+
}
89+
90+
$rows = $display_pref->find([
91+
'itemtype' => EmbodiedImpact::class,
92+
'num' => 128702 // usage GWP qiality
93+
]);
94+
$id = $plugin_so_base + $group_base + 1;
95+
foreach ($rows as $row) {
96+
$row['num'] = $id;
97+
$display_pref->update($row);
98+
}
99+
100+
$rows = $display_pref->find([
101+
'itemtype' => EmbodiedImpact::class,
102+
'num' => 128703 // usage ADP
103+
]);
104+
$id = $plugin_so_base + $group_base + 2;
105+
foreach ($rows as $row) {
106+
$row['num'] = $id;
107+
$display_pref->update($row);
108+
}
109+
110+
$rows = $display_pref->find([
111+
'itemtype' => EmbodiedImpact::class,
112+
'num' => 128704 // usage ADP qiality
113+
]);
114+
$id = $plugin_so_base + $group_base + 3;
115+
foreach ($rows as $row) {
116+
$row['num'] = $id;
117+
$display_pref->update($row);
118+
}
119+
120+
$rows = $display_pref->find([
121+
'itemtype' => EmbodiedImpact::class,
122+
'num' => 128705 // usage PE
123+
]);
124+
$id = $plugin_so_base + $group_base + 4;
125+
foreach ($rows as $row) {
126+
$row['num'] = $id;
127+
$display_pref->update($row);
128+
}
129+
130+
$rows = $display_pref->find([
131+
'itemtype' => EmbodiedImpact::class,
132+
'num' => 128706 // usage PE qiality
133+
]);
134+
$id = $plugin_so_base + $group_base + 5;
135+
foreach ($rows as $row) {
136+
$row['num'] = $id;
137+
$display_pref->update($row);
138+
}

src/AbstractImpact.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,18 @@ public function rawSearchOptions()
7474
'datatype' => 'itemtypename',
7575
];
7676

77-
$id = 5;
78-
foreach (Type::getImpactTypes() as $type) {
77+
$tab[] = [
78+
'id' => '5',
79+
'table' => $this->getTable(),
80+
'field' => 'recalculate',
81+
'name' => __('', 'carbon'),
82+
'massiveaction' => false,
83+
'datatype' => 'bool',
84+
];
85+
86+
$id = SearchOptions::IMPACT_BASE;
87+
foreach (Type::getImpactTypes() as $type_id => $type) {
88+
$id = SearchOptions::IMPACT_BASE + $type_id * 2;
7989
$tab[] = [
8090
'id' => $id,
8191
'table' => $this->getTable(),
@@ -86,24 +96,34 @@ public function rawSearchOptions()
8696
'unit' => implode(' ', Type::getImpactUnit($type)),
8797
];
8898
$id++;
99+
100+
$tab[] = [
101+
'id' => $id,
102+
'table' => $this->getTable(),
103+
'field' => "{$type}_quality",
104+
'name' => Type::getEmbodiedImpactLabel($type),
105+
'massiveaction' => false,
106+
'datatype' => 'number',
107+
'unit' => implode(' ', Type::getImpactUnit($type)),
108+
];
89109
}
90110

91111
$tab[] = [
92-
'id' => SearchOptions::CARBON_EMISSION_CALC_DATE,
112+
'id' => SearchOptions::CALCULATION_DATE,
93113
'table' => self::getTable(),
94114
'field' => 'date_mod',
95115
'name' => __('Date of evaluation', 'carbon')
96116
];
97117

98118
$tab[] = [
99-
'id' => SearchOptions::CARBON_EMISSION_ENGINE,
119+
'id' => SearchOptions::CALCULATION_ENGINE,
100120
'table' => self::getTable(),
101121
'field' => 'engine',
102122
'name' => __('Engine', 'carbon')
103123
];
104124

105125
$tab[] = [
106-
'id' => SearchOptions::CARBON_EMISSION_ENGINE_VER,
126+
'id' => SearchOptions::CALCULATION_ENGINE_VERSION,
107127
'table' => self::getTable(),
108128
'field' => 'engine_version',
109129
'name' => __('Engine version', 'carbon')

src/CarbonEmission.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,21 +145,21 @@ public function rawSearchOptions()
145145
];
146146

147147
$tab[] = [
148-
'id' => SearchOptions::CARBON_EMISSION_CALC_DATE,
148+
'id' => SearchOptions::CALCULATION_DATE,
149149
'table' => self::getTable(),
150150
'field' => 'date_mod',
151151
'name' => __('Date of evaluation', 'carbon')
152152
];
153153

154154
$tab[] = [
155-
'id' => SearchOptions::CARBON_EMISSION_ENGINE,
155+
'id' => SearchOptions::CALCULATION_ENGINE,
156156
'table' => self::getTable(),
157157
'field' => 'engine',
158158
'name' => __('Engine', 'carbon')
159159
];
160160

161161
$tab[] = [
162-
'id' => SearchOptions::CARBON_EMISSION_ENGINE_VER,
162+
'id' => SearchOptions::CALCULATION_ENGINE_VERSION,
163163
'table' => self::getTable(),
164164
'field' => 'engine_version',
165165
'name' => __('Engine version', 'carbon')

src/Impact/Type.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,28 @@ class Type
3737
{
3838
private const BASE_URL = 'https://glpi-plugins.readthedocs.io/%s/latest/carbon';
3939

40-
const IMPACT_GWP = 1; // Global warming potential
41-
const IMPACT_ADP = 2; // Abiotic Depletion Potential
42-
const IMPACT_PE = 3; // Primary Energy
43-
const IMPACT_GWPPB = 4;
44-
const IMPACT_GWPPF = 5;
45-
const IMPACT_GWPPLU = 6;
46-
const IMPACT_IR = 7;
47-
const IMPACT_LU = 8;
48-
const IMPACT_ODP = 9;
49-
const IMPACT_PM = 10;
50-
const IMPACT_POCP = 11;
51-
const IMPACT_WU = 12;
52-
const IMPACT_MIPS = 13;
53-
const IMPACT_ADPE = 14;
54-
const IMPACT_ADPF = 15;
55-
const IMPACT_AP = 16;
56-
const IMPACT_CTUE = 17;
57-
// const IMPACT_CTUHC = 18;
58-
// const IMPACT_CTUHNC = 19;
59-
const IMPACT_EPF = 20;
60-
const IMPACT_EPM = 21;
61-
const IMPACT_EPT = 22;
40+
const IMPACT_GWP = 0; // Global warming potential
41+
const IMPACT_ADP = 1; // Abiotic Depletion Potential
42+
const IMPACT_PE = 2; // Primary Energy
43+
const IMPACT_GWPPB = 3;
44+
const IMPACT_GWPPF = 4;
45+
const IMPACT_GWPPLU = 5;
46+
const IMPACT_IR = 6;
47+
const IMPACT_LU = 7;
48+
const IMPACT_ODP = 8;
49+
const IMPACT_PM = 9;
50+
const IMPACT_POCP = 10;
51+
const IMPACT_WU = 11;
52+
const IMPACT_MIPS = 12;
53+
const IMPACT_ADPE = 13;
54+
const IMPACT_ADPF = 14;
55+
const IMPACT_AP = 15;
56+
const IMPACT_CTUE = 16;
57+
// const IMPACT_CTUHC = 17;
58+
// const IMPACT_CTUHNC = 18;
59+
const IMPACT_EPF = 19;
60+
const IMPACT_EPM = 20;
61+
const IMPACT_EPT = 21;
6262

6363
private static array $impact_types = [
6464
self::IMPACT_GWP => 'gwp',

src/SearchOptions.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,9 @@ class SearchOptions
8989
public const CARBON_EMISSION_PER_DAY = self::SEARCH_OPTION_BASE + 602;
9090
public const CARBON_EMISSION_ENERGY_QUALITY = self::SEARCH_OPTION_BASE + 603;
9191
public const CARBON_EMISSION_EMISSION_QUALITY = self::SEARCH_OPTION_BASE + 604;
92-
public const CARBON_EMISSION_CALC_DATE = self::SEARCH_OPTION_BASE + 605;
93-
public const CARBON_EMISSION_ENGINE = self::SEARCH_OPTION_BASE + 606;
94-
public const CARBON_EMISSION_ENGINE_VER = self::SEARCH_OPTION_BASE + 607;
95-
96-
public const USAGE_IMPACT_DATE = self::SEARCH_OPTION_BASE + 700;
97-
public const USAGE_IMPACT_GWP = self::SEARCH_OPTION_BASE + 701;
98-
public const USAGE_IMPACT_GWP_QUALITY = self::SEARCH_OPTION_BASE + 702;
99-
public const USAGE_IMPACT_ADP = self::SEARCH_OPTION_BASE + 703;
100-
public const USAGE_IMPACT_ADP_QUALITY = self::SEARCH_OPTION_BASE + 704;
101-
public const USAGE_IMPACT_PE = self::SEARCH_OPTION_BASE + 705;
102-
public const USAGE_IMPACT_PE_QUALITY = self::SEARCH_OPTION_BASE + 706;
92+
public const CALCULATION_DATE = self::SEARCH_OPTION_BASE + 605;
93+
public const CALCULATION_ENGINE = self::SEARCH_OPTION_BASE + 606;
94+
public const CALCULATION_ENGINE_VERSION = self::SEARCH_OPTION_BASE + 607;
10395

10496
public const COMPUTER_TYPE_CATEGORY = self::SEARCH_OPTION_BASE + 800;
10597
public const COMPUTER_TYPE_IS_IGNORED = self::SEARCH_OPTION_BASE + 801;
@@ -110,6 +102,13 @@ class SearchOptions
110102

111103
public const NETEQUIP_TYPE_IS_IGNORED = self::SEARCH_OPTION_BASE + 1100;
112104

105+
// First search option ID for all imapcts
106+
// Impacts are numbered accross several consecutive IDs
107+
// - impact type
108+
// - impact quality
109+
// @see AbstractImpact::rawSearchOption
110+
public const IMPACT_BASE = self::SEARCH_OPTION_BASE + 1200;
111+
113112
public const EMBODIED_IMPACT_GWP = self::SEARCH_OPTION_BASE + 1200;
114113
public const EMBODIED_IMPACT_GWP_SOURCE = self::SEARCH_OPTION_BASE + 1201;
115114
public const EMBODIED_IMPACT_GWP_QUALITY = self::SEARCH_OPTION_BASE + 1202;

0 commit comments

Comments
 (0)