response-added-by-agent.php
2 years ago
response-added-by-customer.php
2 years ago
ticket-closed-by-agent.php
2 years ago
ticket-closed-by-customer.php
2 years ago
ticket-closed-product.php
2 years ago
ticket-created-product.php
2 years ago
ticket-created.php
2 years ago
ticket-product-replied-agent.php
2 years ago
ticket-product-replied-customer.php
2 years ago
ticket-created.php
127 lines
| 1 | <?php |
| 2 | /** |
| 3 | * TicketCreatedFluentSupport. |
| 4 | * php version 5.6 |
| 5 | * |
| 6 | * @category TicketCreatedFluentSupport |
| 7 | * @package SureTriggers |
| 8 | * @author BSF <username@example.com> |
| 9 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3 |
| 10 | * @link https://www.brainstormforce.com/ |
| 11 | * @since 1.0.0 |
| 12 | */ |
| 13 | |
| 14 | namespace SureTriggers\Integrations\FluentSupport\Triggers; |
| 15 | |
| 16 | use SureTriggers\Controllers\AutomationController; |
| 17 | use SureTriggers\Traits\SingletonLoader; |
| 18 | use FluentSupport\App\Models\Ticket; |
| 19 | |
| 20 | if ( ! class_exists( 'TicketCreatedFluentSupport' ) ) : |
| 21 | |
| 22 | /** |
| 23 | * TicketCreatedFluentSupport |
| 24 | * |
| 25 | * @category TicketCreatedFluentSupport |
| 26 | * @package SureTriggers |
| 27 | * @author BSF <username@example.com> |
| 28 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3 |
| 29 | * @link https://www.brainstormforce.com/ |
| 30 | * @since 1.0.0 |
| 31 | * |
| 32 | * @psalm-suppress UndefinedTrait |
| 33 | */ |
| 34 | class TicketCreatedFluentSupport { |
| 35 | |
| 36 | /** |
| 37 | * Integration type. |
| 38 | * |
| 39 | * @var string |
| 40 | */ |
| 41 | public $integration = 'FluentSupport'; |
| 42 | |
| 43 | /** |
| 44 | * Trigger name. |
| 45 | * |
| 46 | * @var string |
| 47 | */ |
| 48 | public $trigger = 'ticket_created_fluent_support'; |
| 49 | |
| 50 | use SingletonLoader; |
| 51 | |
| 52 | /** |
| 53 | * Constructor |
| 54 | * |
| 55 | * @since 1.0.0 |
| 56 | */ |
| 57 | public function __construct() { |
| 58 | add_filter( 'sure_trigger_register_trigger', [ $this, 'register' ] ); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Register action. |
| 63 | * |
| 64 | * @param array $triggers trigger data. |
| 65 | * @return array |
| 66 | */ |
| 67 | public function register( $triggers ) { |
| 68 | $triggers[ $this->integration ][ $this->trigger ] = [ |
| 69 | 'label' => __( 'Ticket Created', 'suretriggers' ), |
| 70 | 'action' => 'ticket_created_fluent_support', |
| 71 | 'common_action' => 'fluent_support/ticket_created', |
| 72 | 'function' => [ $this, 'trigger_listener' ], |
| 73 | 'priority' => 10, |
| 74 | 'accepted_args' => 2, |
| 75 | ]; |
| 76 | |
| 77 | return $triggers; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Trigger listener |
| 82 | * |
| 83 | * @param object $ticket ticket. |
| 84 | * @param object $customer customer. |
| 85 | * |
| 86 | * @return void |
| 87 | */ |
| 88 | public function trigger_listener( $ticket, $customer ) { |
| 89 | |
| 90 | $context = array_merge( |
| 91 | [ |
| 92 | 'ticket' => $ticket, |
| 93 | 'customer' => $customer, |
| 94 | ] |
| 95 | ); |
| 96 | if ( property_exists( $ticket, 'mailbox_id' ) ) { |
| 97 | $context['mailbox_id'] = $ticket->mailbox_id; |
| 98 | } |
| 99 | |
| 100 | if ( ! class_exists( '\FluentSupport\App\Models\Ticket' ) ) { |
| 101 | return; |
| 102 | } |
| 103 | if ( $ticket instanceof Ticket ) { |
| 104 | if ( method_exists( $ticket, 'customData' ) ) { |
| 105 | $context['custom_fields'] = $ticket->customData(); |
| 106 | } |
| 107 | $context['ticket_link'] = admin_url( "admin.php?page=fluent-support#/tickets/{$ticket->id}/view" ); |
| 108 | } |
| 109 | |
| 110 | AutomationController::sure_trigger_handle_trigger( |
| 111 | [ |
| 112 | 'trigger' => $this->trigger, |
| 113 | 'context' => $context, |
| 114 | ] |
| 115 | ); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Ignore false positive |
| 121 | * |
| 122 | * @psalm-suppress UndefinedMethod |
| 123 | */ |
| 124 | TicketCreatedFluentSupport::get_instance(); |
| 125 | |
| 126 | endif; |
| 127 |