PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 2.4.5
Fluent Support – Helpdesk & Customer Support Ticket System v2.4.5
2.4.5 2.4.0 2.3.2 2.3.1 2.3.0 2.2.1 2.2.0 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.4.0 1.4.1 1.4.2 1.4.5 1.4.6 1.4.7 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 All 69 releases
fluent-support / app / Services / Notifications / RecipientResolver.php

RecipientResolver.php in Fluent Support – Helpdesk & Customer Support Ticket System 2.4.5, at app/Services/Notifications/RecipientResolver.php

82 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentSupport\App\Services\Notifications;
4
5 use FluentSupport\App\Models\Agent;
6 use FluentSupport\App\Models\Ticket;
7
8 class RecipientResolver
9 {
10 /**
11 * @param array $agentIds
12 * @param int|null $excludePersonId
13 * @return \FluentSupport\Framework\Support\Collection
14 */
15 public function resolveMentionedAgents(array $agentIds, $excludePersonId = null)
16 {
17 $agentIds = array_values(array_unique(array_filter(array_map('intval', $agentIds))));
18
19 if (!$agentIds) {
20 return Agent::whereIn('id', [0])->get();
21 }
22
23 $query = Agent::whereIn('id', $agentIds);
24
25 if ($excludePersonId) {
26 $query->where('id', '!=', (int) $excludePersonId);
27 }
28
29 return $query->get();
30 }
31
32 /**
33 * The ticket's assigned agent, unless that agent is $excludePersonId.
34 *
35 * @param \FluentSupport\App\Models\Ticket $ticket
36 * @param int|null $excludePersonId
37 * @return \FluentSupport\App\Models\Agent|null
38 */
39 public function resolveAssignedAgent(Ticket $ticket, $excludePersonId = null)
40 {
41 if (!$ticket->agent_id) {
42 return null;
43 }
44
45 $query = Agent::where('id', $ticket->agent_id);
46
47 if ($excludePersonId) {
48 $query->where('id', '!=', $excludePersonId);
49 }
50
51 return $query->first();
52 }
53
54 /**
55 * Unique person IDs from $recipients, minus $excludePersonId.
56 *
57 * @param iterable $recipients
58 * @param int|null $excludePersonId
59 * @return array
60 */
61 public function extractRecipientPersonIds($recipients, $excludePersonId = null)
62 {
63 $ids = [];
64
65 foreach ($recipients as $recipient) {
66 if (!$recipient || empty($recipient->id)) {
67 continue;
68 }
69
70 $recipientId = (int) $recipient->id;
71
72 if ($excludePersonId && $recipientId === (int) $excludePersonId) {
73 continue;
74 }
75
76 $ids[] = $recipientId;
77 }
78
79 return array_values(array_unique($ids));
80 }
81 }
82