PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 1.5.5
Fluent Support – Helpdesk & Customer Support Ticket System v1.5.5
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 / UploaderController.php

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

96 lines 3.3 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\Attachment;
6 use FluentSupport\App\Models\Ticket;
7 use FluentSupport\App\Services\EmailNotification\Settings;
8 use FluentSupport\App\Services\Helper;
9 use FluentSupport\App\Services\Includes\FileSystem;
10 use FluentSupport\Framework\Request\Request;
11
12 /**
13 * UploaderController class is responsible for uploading file
14 * @package FluentSupport\App\Http\Controllers
15 *
16 * @version 1.0.0
17 */
18 class UploaderController extends Controller
19 {
20 /**
21 * uploadTicketFiles method will upload all the attached file in a ticket
22 * @param Request $request
23 * @return array[]
24 * @throws \FluentSupport\Framework\Validator\ValidationException
25 */
26 public function uploadTicketFiles(Request $request)
27 {
28 //get settings from settings table
29 $settings = (new Settings())->globalBusinessSettings();
30 $maxFileSize = absint($settings['max_file_size']);
31 $mimeHeadings = Helper::getAcceptedMimeHeadings();
32
33 $maxSizeBytes = $maxFileSize * 1024;
34
35 //Validate the file type and size
36 $files = $this->validate($this->request->files(), [
37 'file' => 'max:' . $maxSizeBytes . '|mimetypes:' . implode(',', Helper::ticketAcceptedFileMiles())
38 ], [
39 'file.mimetypes' => sprintf(__('Only %s files are allowed.', 'fluent-support'), implode(', ', $mimeHeadings)),
40 'file.max' => sprintf(__('The file can not be more than %dMB. Please upload somewhere like dropbox/google drive and paste the link in the response', 'fluent-support'), $maxFileSize)
41 ]);
42
43
44 //get ticket by ticket id
45 $ticketId = $request->get('ticket_id');
46
47 if ($ticketId == 'undefined') {
48 $ticketId = NULL;
49 }
50
51 //Get customer or agent
52 if ($ticketId && $request->get('intended_ticket_hash') && Helper::isPublicSignedTicketEnabled()) {
53 $ticket = Ticket::with(['customer'])->findOrFail($ticketId);
54 $person = $ticket->customer;
55 } else {
56 $person = Helper::getCurrentPerson();
57 }
58
59 //Check if customer has permission to uipload file
60 if ($person->person_type == 'customer') {
61 $disabledFields = apply_filters('fluent_support/disabled_ticket_fields', []);
62 if (in_array('file_upload', $disabledFields)) {
63 return $this->sendError([
64 'message' => __('You do not have permission to upload a file', 'fluent-support')
65 ]);
66 }
67 }
68 //Move file into the directory
69 $uploadedFiles = FileSystem::setSubDir('ticket_' . $ticketId)->put($files);
70
71 $attachments = [];
72 //Create records in attachment table
73 foreach ($uploadedFiles as $file) {
74
75 $fileData = [
76 'ticket_id' => $ticketId,
77 'person_id' => $person->id,
78 'file_type' => $file['type'],
79 'file_path' => $file['file_path'],
80 'full_url' => $file['url'],
81 'title' => $file['name'],
82 'driver' => 'local',
83 'status' => 'in-active'
84 ];
85
86 $attachment = Attachment::create($fileData);
87 $attachments[] = $attachment->file_hash;
88 }
89
90 return [
91 'attachments' => $attachments
92 ];
93
94 }
95 }
96