# fluent-support/1.5.4/app/Hooks/Handlers/ActivityLogger.php

Fluent Support – Helpdesk &amp; Customer Support Ticket System, version 1.5.4. 141 lines.

- Page: https://pluginprobe.com/plugins/fluent-support/1.5.4/code/app/Hooks/Handlers/ActivityLogger.php
- Raw: https://pluginprobe.com/plugins/fluent-support/1.5.4/raw/app/Hooks/Handlers/ActivityLogger.php
- Modified: 2021-11-12T14:57:38+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/fluent-support/1.5.4/code/app/Hooks/Handlers/ActivityLogger.php#L10-L20`.

```php
<?php

namespace FluentSupport\App\Hooks\Handlers;

use FluentSupport\App\Models\Activity;

class ActivityLogger
{
    public function init()
    {
        // Ticket Related activities
        add_action('fluent_support/ticket_created', function ($ticket, $customer) {

            $customer->last_response_at = current_time('mysql');
            $customer->save();

            $description = sprintf('%1$s created a %2$s via %3$s', $this->getPersonMarkup($customer), $this->getTicketMarkup($ticket), $ticket->source);

            $log = [
                'event_type' => 'fluent_support/ticket_created',
                'person_id' => $customer->id,
                'person_type' => $customer->person_type,
                'object_id' => $ticket->id,
                'object_type' => 'ticket',
                'description' => $description
            ];

            Activity::create($log);
        }, 20, 2);

        add_action('fluent_support/response_added_by_customer', function ($response, $ticket, $person) {

            $person->last_response_at = current_time('mysql');
            $person->save();

            $description = sprintf('Customer %1$s added a response on %2$s via %3$s', $this->getPersonMarkup($person), $this->getTicketMarkup($ticket), $response->source);

            $log = [
                'event_type' => 'fluent_support/response_added_by_customer',
                'person_id' => $person->id,
                'person_type' => $person->person_type,
                'object_id' => $ticket->id,
                'object_type' => 'ticket',
                'description' => $description
            ];

            Activity::create($log);
        }, 20, 3);

        add_action('fluent_support/response_added_by_agent', function ($response, $ticket, $person) {
            $description = sprintf('%1$s added a response on %2$s via %3$s', $this->getPersonMarkup($person), $this->getTicketMarkup($ticket), $response->source);

            $log = [
                'event_type' => 'fluent_support/response_added_by_agent',
                'person_id' => $person->id,
                'person_type' => $person->person_type,
                'object_id' => $ticket->id,
                'object_type' => 'ticket',
                'description' => $description
            ];

            Activity::create($log);
        }, 20, 3);

        add_action('fluent_support/note_added_by_agent', function ($response, $ticket, $person) {
            $description = sprintf('%1$s added a note on %2$s via %3$s', $this->getPersonMarkup($person), $this->getTicketMarkup($ticket), $response->source);

            $log = [
                'event_type' => 'fluent_support/note_added_by_agent',
                'person_id' => $person->id,
                'person_type' => $person->person_type,
                'object_id' => $ticket->id,
                'object_type' => 'ticket',
                'description' => $description
            ];

            Activity::create($log);
        }, 20, 3);

        add_action('fluent_support/ticket_closed', function ($ticket, $person) {

            if ($person->person_type == 'customer') {
                $person->last_response_at = current_time('mysql');
                $person->save();
            }

            $description = sprintf('%1$s closed %2$s', $this->getPersonMarkup($person), $this->getTicketMarkup($ticket));

            $log = [
                'event_type' => 'fluent_support/ticket_closed',
                'person_id' => $person->id,
                'person_type' => $person->person_type,
                'object_id' => $ticket->id,
                'object_type' => 'ticket',
                'description' => $description
            ];

            Activity::create($log);
        }, 20, 2);

        add_action('fluent_support/ticket_reopen', function ($ticket, $person) {

            if ($person->person_type == 'customer') {
                $person->last_response_at = current_time('mysql');
                $person->save();
            }

            $description = sprintf('%1$s reopened on %2$s', $this->getPersonMarkup($person), $this->getTicketMarkup($ticket));

            $log = [
                'event_type' => 'fluent_support/ticket_reopen',
                'person_id' => $person->id,
                'person_type' => $person->person_type,
                'object_id' => $ticket->id,
                'object_type' => 'ticket',
                'description' => $description
            ];

            Activity::create($log);
        }, 20, 2);
    }

    public function getTicketMarkup($ticket, $ticketText = false)
    {
        if (!$ticketText) {
            $ticketText = sprintf(__('Ticket: %s', 'fluent-support'), $ticket->title);
        }

        return '<a class="fs_link_trans fs_tk" href="#view_ticket">' . $ticketText . '</a>';
    }

    public function getPersonMarkup($person)
    {
        $route = 'view_agent';
        if ($person->person_type == 'customer') {
            $route = 'view_customer';
        }
        return '<a class="fs_link_trans fs_pr" href="#' . $route . '">' . $person->full_name . '</a>';
    }
}

```
