PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.4.9
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.4.9
3.5.4 3.5.3 3.5.2 3.5.1 3.4.9 3.5.0 3.4.8 3.4.7 trunk 2.3.1 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6
supportcandy / includes / admin / email-notifications / class-wpsc-en-assign-agent.php

class-wpsc-en-assign-agent.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 3.4.9, at includes/admin/email-notifications/class-wpsc-en-assign-agent.php

136 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly!
4 }
5
6 if ( ! class_exists( 'WPSC_EN_Assign_Agent' ) ) :
7
8 final class WPSC_EN_Assign_Agent extends WPSC_Email_Notifications {
9
10 /**
11 * Slug for this event (must be unique)
12 *
13 * @var string
14 */
15 private static $slug = 'change-assignee';
16
17 /**
18 * Ticket object
19 *
20 * @var WPSC_Ticket
21 */
22 public $ticket;
23
24 /**
25 * Array of agent model
26 *
27 * @var array
28 */
29 public $prev;
30
31 /**
32 * Array of agent model
33 *
34 * @var array
35 */
36 public $new;
37
38 /**
39 * Initialize this class
40 */
41 public static function init() {
42
43 // process event.
44 add_action( 'wpsc_change_assignee', array( __CLASS__, 'process_event' ), 200, 4 );
45
46 // filter for previous assignee.
47 add_filter( 'wpsc_en_get_to_addresses', array( __CLASS__, 'add_prev_assignee' ), 10, 3 );
48 add_filter( 'wpsc_en_get_cc_addresses', array( __CLASS__, 'add_prev_assignee' ), 10, 3 );
49 add_filter( 'wpsc_en_get_bcc_addresses', array( __CLASS__, 'add_prev_assignee' ), 10, 3 );
50 }
51
52 /**
53 * Process emails for this event
54 *
55 * @param WPSC_Ticket $ticket -ticket info.
56 * @param array $prev - array of agent models.
57 * @param array $new - array of agent models.
58 * @param integer $customer_id - ID of customer model.
59 * @return void
60 */
61 public static function process_event( $ticket, $prev, $new, $customer_id ) {
62
63 $gs = get_option( 'wpsc-en-general' );
64 $email_templates = get_option( 'wpsc-email-templates', array() );
65
66 foreach ( $email_templates as $key => $et ) {
67
68 if ( $et['event'] != self::$slug ) {
69 continue;
70 }
71
72 // email notification object.
73 $en = new self();
74
75 // set properties.
76 $en->ticket = $ticket;
77 $en->prev = $prev;
78 $en->new = $new;
79
80 // set template.
81 $en->template = $et;
82 $en->template_key = $key;
83
84 // check whether conditions matches (if any).
85 if ( ! $en->is_valid() ) {
86 continue;
87 }
88
89 $en = apply_filters( 'wpsc_en_before_sending', $en );
90
91 // send an email.
92 WPSC_Background_Email::insert(
93 array(
94 'from_name' => $en->from_name,
95 'from_email' => $en->from_email,
96 'reply_to' => $gs['reply-to'],
97 'subject' => $en->subject,
98 'body' => $en->body,
99 'to_email' => implode( '|', $en->to ),
100 'cc_email' => implode( '|', $en->cc ),
101 'bcc_email' => implode( '|', $en->bcc ),
102 'priority' => 2,
103 )
104 );
105 }
106 }
107
108 /**
109 * Check for previous assignee general recipient option
110 *
111 * @param array $gr - general recepients.
112 * @param string $recipient - recipient.
113 * @param WPSC_Email_Notifications $en - email notification.
114 * @return array
115 */
116 public static function add_prev_assignee( $gr, $recipient, $en ) {
117
118 if ( $recipient != 'prev-assignee' ) {
119 return $gr;
120 }
121
122 $en->prev = apply_filters( 'wpsc_en_assign_agent_prev_assignees', $en->prev, $en );
123
124 foreach ( $en->prev as $agent ) {
125 if ( ! $agent->is_active || $agent->is_agentgroup ) {
126 continue;
127 }
128 $gr[] = $agent->customer->email;
129 }
130 return $gr;
131 }
132 }
133 endif;
134
135 WPSC_EN_Assign_Agent::init();
136