PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.5.4
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.5.4
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.5.4, at includes/admin/email-notifications/class-wpsc-en-assign-agent.php

146 lines 3.5 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 // macro attachments.
90 $en->attachments = array_merge( $en->attachments, WPSC_Macros::$attachments );
91 WPSC_Macros::$attachments = array();
92
93 $en = apply_filters( 'wpsc_en_before_sending', $en );
94
95 // send an email.
96 $attachment_ids = array();
97 foreach ( $en->attachments as $attachment ) {
98 $attachment_ids[] = $attachment->id;
99 }
100
101 WPSC_Background_Email::insert(
102 array(
103 'from_name' => $en->from_name,
104 'from_email' => $en->from_email,
105 'reply_to' => $gs['reply-to'],
106 'subject' => $en->subject,
107 'body' => $en->body,
108 'to_email' => implode( '|', $en->to ),
109 'cc_email' => implode( '|', $en->cc ),
110 'bcc_email' => implode( '|', $en->bcc ),
111 'attachments' => implode( '|', $attachment_ids ),
112 'priority' => 2,
113 )
114 );
115 }
116 }
117
118 /**
119 * Check for previous assignee general recipient option
120 *
121 * @param array $gr - general recepients.
122 * @param string $recipient - recipient.
123 * @param WPSC_Email_Notifications $en - email notification.
124 * @return array
125 */
126 public static function add_prev_assignee( $gr, $recipient, $en ) {
127
128 if ( $recipient != 'prev-assignee' ) {
129 return $gr;
130 }
131
132 $en->prev = apply_filters( 'wpsc_en_assign_agent_prev_assignees', $en->prev, $en );
133
134 foreach ( $en->prev as $agent ) {
135 if ( ! $agent->is_active || $agent->is_agentgroup ) {
136 continue;
137 }
138 $gr[] = $agent->customer->email;
139 }
140 return $gr;
141 }
142 }
143 endif;
144
145 WPSC_EN_Assign_Agent::init();
146