-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add/dashboard report tickets by group and status #25146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Herafia
wants to merge
9
commits into
glpi-project:main
Choose a base branch
from
Herafia:add/dashboard-report-ticketsByGroupAndStatus
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
03546f6
Add (Dashboard) report tcketsByGroupAndStatus
Herafia 9527d77
fix sql and tests
Herafia 229df2d
lint
Herafia 5189366
trigger CI
Herafia 6ea86c0
fix
Herafia 3567cf2
fix
Herafia 2fffe40
fix filter, ui
Herafia 9b63ed3
rebase
Herafia 4357a91
fix test
Herafia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1270,6 +1270,104 @@ public static function ticketsByCategoryAndEntity(array $params = []): array | |
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * count number of opened and closed tickets grouped by their assigned group | ||
| * @param array<string, mixed> $params | ||
| * @return array<string, mixed> | ||
| */ | ||
| public static function ticketsByGroupAndStatus(array $params = []): array | ||
| { | ||
| $DB = DBConnection::getReadConnection(); | ||
|
|
||
| $default_params = [ | ||
| 'label' => "", | ||
| 'icon' => Ticket::getIcon(), | ||
| 'apply_filters' => [], | ||
| ]; | ||
| $params = array_merge($default_params, $params); | ||
|
|
||
| $ticket_table = Ticket::getTable(); | ||
| $group_ticket_table = Group_Ticket::getTable(); | ||
| $group_table = Group::getTable(); | ||
|
|
||
| $opened_statuses = implode(',', [Ticket::INCOMING, Ticket::ASSIGNED, Ticket::PLANNED, Ticket::WAITING]); | ||
| $closed_statuses = implode(',', [Ticket::SOLVED, Ticket::CLOSED]); | ||
|
|
||
| // Restrict our own grouping to the groups selected by the "technician | ||
| // group" filter, not just which tickets are included (see | ||
| // extractActorFilterIds() doc for why this is needed). | ||
| $filtered_group_ids = self::extractActorFilterIds( | ||
| GroupTechFilter::class, | ||
| 'gl_' . GroupTechFilter::getId() . '.groups_id', | ||
| $ticket_table, | ||
| $params['apply_filters'] | ||
| ); | ||
|
|
||
| Profiler::getInstance()->start(__METHOD__ . ' build SQL criteria'); | ||
| $criteria = array_merge_recursive( | ||
| [ | ||
| 'SELECT' => [ | ||
| "$group_table.name AS group_name", | ||
| new QueryExpression("COUNT(DISTINCT CASE WHEN $ticket_table.status IN ($opened_statuses) THEN $ticket_table.id END) AS opened"), | ||
| new QueryExpression("COUNT(DISTINCT CASE WHEN $ticket_table.status IN ($closed_statuses) THEN $ticket_table.id END) AS closed"), | ||
| ], | ||
| 'FROM' => $ticket_table, | ||
| 'INNER JOIN' => [ | ||
| $group_ticket_table => [ | ||
| 'ON' => [ | ||
| $group_ticket_table => 'tickets_id', | ||
| $ticket_table => 'id', | ||
| [ | ||
| 'AND' => [ | ||
| "$group_ticket_table.type" => Group_Ticket::ASSIGN, | ||
| ], | ||
| ], | ||
| ], | ||
| ], | ||
| $group_table => [ | ||
| 'ON' => [ | ||
| $group_table => 'id', | ||
| $group_ticket_table => 'groups_id', | ||
| ], | ||
| ], | ||
| ], | ||
| 'WHERE' => [ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| "$ticket_table.is_deleted" => 0, | ||
| ] + ($filtered_group_ids !== null ? ["$group_table.id" => $filtered_group_ids] : []) | ||
| + getEntitiesRestrictCriteria($ticket_table), | ||
| 'GROUPBY' => "$group_table.id", | ||
|
Herafia marked this conversation as resolved.
|
||
| 'ORDERBY' => "$group_table.name", | ||
| ], | ||
| Ticket::getCriteriaFromProfile(), | ||
| self::getFiltersCriteria($ticket_table, $params['apply_filters']) | ||
| ); | ||
| $iterator = $DB->request($criteria); | ||
| Profiler::getInstance()->stop(__METHOD__ . ' build SQL criteria'); | ||
|
|
||
| $data = [ | ||
| 'labels' => [], | ||
| 'series' => [ | ||
| ['name' => __('Opened'), 'data' => []], | ||
| ['name' => __('Closed'), 'data' => []], | ||
|
Comment on lines
+1350
to
+1351
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ], | ||
| ]; | ||
| foreach ($iterator as $result) { | ||
| $data['labels'][] = $result['group_name']; | ||
| $data['series'][0]['data'][] = (int) $result['opened']; | ||
| $data['series'][1]['data'][] = (int) $result['closed']; | ||
| } | ||
|
|
||
| if (count($data['labels']) === 0) { | ||
| $data['nodata'] = true; | ||
| } | ||
|
|
||
| return [ | ||
| 'data' => $data, | ||
| 'label' => $params['label'], | ||
| 'icon' => $params['icon'], | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * Get a list of article for an compatible item (with date,name,text fields) | ||
| * | ||
|
|
@@ -2213,6 +2311,29 @@ final public static function getSearchFiltersCriteria(string $table = "", array | |
| return ['criteria' => $s_criteria]; | ||
| } | ||
|
|
||
| /** | ||
| * Extracts an actor filter's resolved ids (e.g. selected group ids) so a | ||
| * provider can restrict its own GROUP BY, not just gate ticket inclusion. | ||
| * Also unsets the filter from $apply_filters to avoid a redundant join later. | ||
| * | ||
| * @param array<string, mixed> $apply_filters | ||
| * | ||
| * @return int[]|null | ||
| */ | ||
| private static function extractActorFilterIds( | ||
| string $filter_class, | ||
| string $where_key, | ||
| string $table, | ||
| array &$apply_filters | ||
| ): ?array { | ||
| $value = $apply_filters[$filter_class::getId()] ?? null; | ||
| unset($apply_filters[$filter_class::getId()]); | ||
|
|
||
| $ids = $value !== null ? ($filter_class::getCriteria($table, $value)['WHERE'][$where_key] ?? null) : null; | ||
|
|
||
| return $ids === null ? null : (array) $ids; | ||
| } | ||
|
|
||
| /** | ||
| * @param string $table | ||
| * @param array $apply_filters | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you forget
Ticket::APPROVAL(unless it is missing on purpose?), if that is the case you can usegetNotSolvedStatusArray()so you are sure to not miss anything ;)