| @@ -5,29 +5,20 @@ | ||
| 5 | 5 | use FluentSupport\App\Models\Activity; |
| 6 | 6 | use FluentSupport\App\Services\Helper; |
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | - * ActivityLogger class for Hooks | |
| 10 | - * | |
| 11 | - * @package FluentSupport\App\Hooks\Handlers | |
| 12 | - * | |
| 13 | - * @version 1.0.0 | |
| 9 | + * Writes ticket lifecycle events to the activity log. | |
| 14 | 10 | */ |
| 15 | 11 | |
| 16 | 12 | class ActivityLogger |
| 17 | 13 | { |
| 18 | 14 | |
| 19 | - /** | |
| 20 | - * init method will register all action hooks related to ticket creation, ticket response, response by agent, note by agent, ticket closed or reopen | |
| 21 | - */ | |
| 22 | 15 | public function init() |
| 23 | 16 | { |
| 24 | - // Check if activity logs are disabled - if so, don't register any hooks | |
| 25 | 17 | if (Helper::areLogsDisabled('_activity_settings')) { |
| 26 | 18 | return; |
| 27 | 19 | } |
| 28 | 20 | |
| 29 | - // Ticket Related activities | |
| 30 | 21 | add_action('fluent_support/ticket_created', function ($ticket, $customer) { |
| 31 | 22 | |
| 32 | 23 | $customer->last_response_at = current_time('mysql'); |
| 33 | 24 | $customer->save(); |
| @@ -60,9 +51,8 @@ | ||
| 60 | 51 | |
| 61 | 52 | Activity::create($log); |
| 62 | 53 | }, 20, 2); |
| 63 | 54 | |
| 64 | - //Response added by customer in a ticket | |
| 65 | 55 | add_action('fluent_support/response_added_by_customer', function ($response, $ticket, $person) { |
| 66 | 56 | |
| 67 | 57 | $person->last_response_at = current_time('mysql'); |
| 68 | 58 | $person->save(); |
| @@ -80,9 +70,8 @@ | ||
| 80 | 70 | |
| 81 | 71 | Activity::create($log); |
| 82 | 72 | }, 20, 3); |
| 83 | 73 | |
| 84 | - //Response added by agent in a ticket | |
| 85 | 74 | add_action('fluent_support/response_added_by_agent', function ($response, $ticket, $person) { |
| 86 | 75 | $description = sprintf('%1$s added a response on %2$s via %3$s', $this->getPersonMarkup($person), $this->getTicketMarkup($ticket), $response->source); |
| 87 | 76 | |
| 88 | 77 | $log = [ |
| @@ -96,9 +85,8 @@ | ||
| 96 | 85 | |
| 97 | 86 | Activity::create($log); |
| 98 | 87 | }, 20, 3); |
| 99 | 88 | |
| 100 | - //Note added by agent to a ticket | |
| 101 | 89 | add_action('fluent_support/note_added_by_agent', function ($response, $ticket, $person) { |
| 102 | 90 | $description = sprintf('%1$s added a note on %2$s via %3$s', $this->getPersonMarkup($person), $this->getTicketMarkup($ticket), $response->source); |
| 103 | 91 | |
| 104 | 92 | $log = [ |
| @@ -112,9 +100,8 @@ | ||
| 112 | 100 | |
| 113 | 101 | Activity::create($log); |
| 114 | 102 | }, 20, 3); |
| 115 | 103 | |
| 116 | - //Ticket closed by customer or agent | |
| 117 | 104 | add_action('fluent_support/ticket_closed', function ($ticket, $person) { |
| 118 | 105 | |
| 119 | 106 | if ($person->person_type == 'customer') { |
| 120 | 107 | $person->last_response_at = current_time('mysql'); |
| @@ -134,9 +121,8 @@ | ||
| 134 | 121 | |
| 135 | 122 | Activity::create($log); |
| 136 | 123 | }, 20, 2); |
| 137 | 124 | |
| 138 | - //Ticket reopen by customer or agent. | |
| 139 | 125 | add_action('fluent_support/ticket_reopen', function ($ticket, $person) { |
| 140 | 126 | |
| 141 | 127 | if ($person->person_type == 'customer') { |
| 142 | 128 | $person->last_response_at = current_time('mysql'); |
| @@ -156,9 +142,8 @@ | ||
| 156 | 142 | |
| 157 | 143 | Activity::create($log); |
| 158 | 144 | }, 20, 2); |
| 159 | 145 | |
| 160 | - // Ticket Assigned by agent | |
| 161 | 146 | add_action('fluent_support/agent_assigned_to_ticket', function ($assignedAgent, $ticket, $assigner) { |
| 162 | 147 | |
| 163 | 148 | $description = sprintf('Assign %1$s ticket to %2$s by %3$s', $this->getTicketMarkup($ticket), $this->getPersonMarkup($assignedAgent), $this->getPersonMarkup($assigner)); |
| 164 | 149 | |
| @@ -193,11 +178,10 @@ | ||
| 193 | 178 | }, 20, 2); |
| 194 | 179 | } |
| 195 | 180 | |
| 196 | 181 | /** |
| 197 | - * getTicketMarkup method will generate hyperlink to view the ticket details | |
| 198 | 182 | * @param $ticket |
| 199 | - * @param false $ticketText | |
| 183 | + * @param string|false $ticketText | |
| 200 | 184 | * @return string |
| 201 | 185 | */ |
| 202 | 186 | public function getTicketMarkup($ticket, $ticketText = false) |
| 203 | 187 | { |
| @@ -209,9 +193,8 @@ | ||
| 209 | 193 | return '<a class="fs_link_trans fs_tk" href="#view_ticket">' . $ticketText . '</a>'; |
| 210 | 194 | } |
| 211 | 195 | |
| 212 | 196 | /** |
| 213 | - * getPersonMarkup method will generate hyperlink to view a customer or agent | |
| 214 | 197 | * @param $person |
| 215 | 198 | * @return string |
| 216 | 199 | */ |
| 217 | 200 | public function getPersonMarkup($person) |