PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 1.10.1
Fluent Support – Helpdesk & Customer Support Ticket System v1.10.1
2.4.0 2.3.2 2.3.1 2.3.0 2.2.1 2.2.0 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.4.0 1.4.1 1.4.2 1.4.5 1.4.6 1.4.7 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 All 68 releases
fluent-support / app / Http / Controllers / MailBoxController.php

MailBoxController.php in Fluent Support – Helpdesk & Customer Support Ticket System 1.10.1, at app/Http/Controllers/MailBoxController.php

198 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentSupport\App\Http\Controllers;
4
5 use FluentSupport\App\Models\MailBox;
6 use FluentSupport\App\Services\EmailNotification\Settings;
7 use FluentSupport\App\Services\MailerInbox\MailBoxService;
8 use FluentSupport\Framework\Request\Request;
9
10 class MailBoxController extends Controller
11 {
12 /**
13 * index method will return the list of business inbox
14 * @param Request $request
15 * @return array
16 */
17 public function index(MailBoxService $mailboxService)
18 {
19 return $mailboxService->getMailBoxes();
20 }
21
22 /**
23 * get method will fetch and return information related to business box
24 * @param Request $request
25 * @param $id
26 * @return mixed
27 */
28 public function get( MailBox $mailBox, $id )
29 {
30 return [
31 'mailbox' => $mailBox->getMailBox( $id )
32 ];
33
34 }
35
36
37 /**
38 * Save method will create new business box
39 * @param Request $request
40 * @param MailBox $mailBox
41 * @return array
42 * @throws \FluentSupport\Framework\Validator\ValidationException
43 */
44 public function save(Request $request, MailBox $mailBox)
45 {
46 $data = wp_unslash( $request->getSafe('business') );
47
48 $this->validate($data, [
49 'name' => 'required',
50 'email' => 'required'
51 ]);
52
53 return [
54 'message' => __('Mailbox has been created successfully', 'fluent-support'),
55 'mailbox' => $mailBox->createMailBox( $data )
56 ];
57 }
58
59 /**
60 * This `update` method will update existing information for a business by mailbox id
61 * @param Request $request
62 * @param MailBox $mailBox
63 * @param int $id
64 * @return array
65 * @throws \Exception
66 */
67 public function update(Request $request, MailBox $mailBox, $id)
68 {
69 try{
70 $data = wp_unslash( $request->getSafe('business') );
71
72 $this->validate($data, [
73 'name' => 'required',
74 'email' => 'required'
75 ]);
76
77 return [
78 'message' => __( 'Mailbox has been saved', 'fluent-support' ),
79 'mailbox' => $mailBox->updateMailBox( $data, $id )
80 ];
81 }catch (\Exception $e){
82 return [
83 'message' => $e->getMessage(),
84 ];
85 }
86 }
87
88 /**
89 * This `delete` method will delete a business from mailbox and replaced with alternative
90 * @param Request $request
91 * @param MailBoxService $mailBoxService
92 * @param int $id
93 * @throws \Exception
94 * @return array
95 */
96 public function delete(Request $request, MailBoxService $mailBoxService, $id)
97 {
98 try {
99 return $mailBoxService->deleteMailBox( $id, $request->getSafe('fallback_id', 'intval') );
100 } catch (\Exception $e) {
101 return [
102 'message' => $e->getMessage(),
103 ];
104 }
105 }
106
107
108 /**
109 * This `moveTickets` method will move tickets from one mailbox to another
110 * @param Request $request
111 * @param MailBoxService $mailBoxService
112 * @param int $id
113 * @throws \Exception
114 * @return array
115 */
116 public function moveTickets(Request $request, MailBoxService $mailBoxService, $id)
117 {
118 try {
119 $data = $request->only(['ticket_ids', 'new_box_id', 'move_type']);
120 return $mailBoxService->moveTickets( $data, $id );
121 } catch (\Exception $e) {
122 return $this->sendError($e->getMessage());
123 }
124 }
125
126 /**
127 * This `getEmailSettings` method will get and return the mailbox email settings
128 * @param Request $request
129 * @param Settings $settings
130 * @param $id
131 * @return array
132 */
133 public function getEmailSettings(Request $request, Settings $settings, $id)
134 {
135 $box = MailBox::findOrFail($id);
136 $emailType = $request->getSafe('email_type', 'sanitize_text_field');
137
138 return [
139 'email_settings' => $settings->getBoxEmailSettings($box, $emailType)
140 ];
141 }
142
143 /**
144 * This `getEmailsSetups` method will return email settings for a business box by box id
145 * @param MailBoxService $mailBoxService
146 * @param $id
147 * @return array
148 */
149 public function getEmailsSetups( MailBoxService $mailBoxService, $id )
150 {
151 return $mailBoxService->getEmailsSetups($id);
152 }
153
154 /**
155 * This `saveEmailSettings` method will save the email settings for a business box using box id
156 * @param Request $request
157 * @param Settings $settings
158 * @param $id
159 * @return array
160 * @throws \FluentSupport\Framework\Validator\ValidationException
161 */
162 public function saveEmailSettings( Request $request, MailBoxService $mailBoxService, $id )
163 {
164 $data = wp_unslash($request->getSafe('email_settings'));
165 $emailType = $request->getSafe('email_type', 'sanitize_text_field');
166
167 $this->validate($data, [
168 'email_subject' => 'required',
169 'email_body' => 'required'
170 ]);
171
172 return $mailBoxService->saveEmailSettings( $emailType, $id, $data );
173 }
174
175 /**
176 * This `setAsDefault` method will set a business box as default
177 * @param MailBoxService $mailBoxService
178 * @param $id
179 * @return array
180 */
181 public function setAsDefault( MailBoxService $mailBoxService, $id )
182 {
183 return $mailBoxService->setAsDefault( $id );
184 }
185
186 /**
187 * This `getTickets` method will return the list of tickets for a business box
188 * @param Request $request
189 * @param MailBox $mailBox
190 * @param int $id
191 * @return array
192 */
193 public function getTickets(Request $request, MailBoxService $mailBoxService, $id)
194 {
195 return $mailBoxService->getTickets( $request->getSafe('filters'), $id );
196 }
197 }
198