-
-
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
03546f6
9527d77
229df2d
5189366
6ea86c0
3567cf2
2fffe40
9b63ed3
4357a91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1647,6 +1647,15 @@ public function getAllDasboardCards($force = false): array | |||||
| 'filters' => Filter::getAppliableFilters(\Computer::getTable()), | ||||||
| ]; | ||||||
|
|
||||||
| $cards["ticket_by_group_and_status"] = [ | ||||||
| 'widgettype' => ['hBars', 'stackedHBars'], | ||||||
| 'itemtype' => "\\Ticket", | ||||||
| 'group' => __('Assistance'), | ||||||
| 'label' => __("Number of opened and closed tickets by group"), | ||||||
|
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.
Suggested change
From the code, the "closed tickets" part is actually solved + closed tickets: With that in mind, I think "solved" would be a more precise label here. |
||||||
| 'provider' => "Glpi\\Dashboard\\Provider::ticketsByGroupAndStatus", | ||||||
| 'filters' => Filter::getAppliableFilters(Ticket::getTable()), | ||||||
| ]; | ||||||
|
|
||||||
| $cards["RemindersList"] = [ | ||||||
| 'widgettype' => ["articleList"], | ||||||
| 'label' => sprintf(__('List of %s'), Reminder::getTypeName(Session::getPluralNumber())), | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1175,6 +1175,99 @@ public static function computersByOperatingSystem(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]); | ||||||||||
|
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.
Suggested change
I think you forget |
||||||||||
| $closed_statuses = implode(',', [Ticket::SOLVED, Ticket::CLOSED]); | ||||||||||
|
|
||||||||||
| Profiler::getInstance()->start(__METHOD__ . ' build SQL criteria'); | ||||||||||
| $criteria = array_merge_recursive( | ||||||||||
| [ | ||||||||||
| 'SELECT' => [ | ||||||||||
| "$group_table.name AS group_name", | ||||||||||
| "$group_table.id AS group_id", | ||||||||||
|
Herafia marked this conversation as resolved.
Outdated
|
||||||||||
| new QueryExpression("COUNT(CASE WHEN $ticket_table.status IN ($opened_statuses) THEN $ticket_table.id END) AS opened"), | ||||||||||
| new QueryExpression("COUNT(CASE WHEN $ticket_table.status IN ($closed_statuses) THEN $ticket_table.id END) AS closed"), | ||||||||||
|
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.
Suggested change
I have some duplicated results when testing, adding For example, in a database with only one ticket attached to two groups and using these groups as a filter I would get 2 results:
|
||||||||||
| ], | ||||||||||
| '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, | ||||||||||
| ] + getEntitiesRestrictCriteria($ticket_table), | ||||||||||
| 'GROUPBY' => "$group_table.id", | ||||||||||
|
Herafia marked this conversation as resolved.
|
||||||||||
| ], | ||||||||||
| 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) { | ||||||||||
| $group_name = $result['group_name'] ?? null; | ||||||||||
|
Herafia marked this conversation as resolved.
Outdated
|
||||||||||
|
|
||||||||||
| if (!$group_name) { | ||||||||||
| continue; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| $data['labels'][] = $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) | ||||||||||
| * | ||||||||||
|
|
||||||||||




Uh oh!
There was an error while loading. Please reload this page.