|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Domains\Customers; |
|
4
|
|
|
|
|
5
|
|
|
use App\CustomerFiles; |
|
6
|
|
|
use App\CustomerFileTypes; |
|
7
|
|
|
use App\Domains\Files\SetFiles; |
|
8
|
|
|
use Illuminate\Support\Facades\Auth; |
|
9
|
|
|
use Illuminate\Support\Facades\Log; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class setCustomerFiles extends SetFiles |
|
13
|
|
|
{ |
|
14
|
|
|
protected $custObj; |
|
15
|
|
|
|
|
16
|
10 |
|
public function __construct() |
|
17
|
|
|
{ |
|
18
|
10 |
|
$this->path = config('filesystems.paths.default'); |
|
19
|
10 |
|
$this->disk = 'local'; |
|
20
|
10 |
|
$this->custObj = new GetCustomerDetails; |
|
21
|
10 |
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function createFile($request, $userID) |
|
24
|
|
|
{ |
|
25
|
|
|
$this->path = config('filesystems.paths.customers').DIRECTORY_SEPARATOR.$request->cust_id; |
|
26
|
|
|
$filename = $this->getChunk($request); |
|
27
|
|
|
if(!$filename) |
|
28
|
|
|
{ |
|
29
|
|
|
return false; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
$fileID = $this->addDatabaseRow($filename, $this->path); |
|
33
|
|
|
$this->processCustFile($fileID, $userID, $request); |
|
34
|
|
|
|
|
35
|
|
|
return true; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
6 |
|
public function updateFile($request, $custFileID) |
|
39
|
|
|
{ |
|
40
|
6 |
|
$custID = $request->cust_id; |
|
41
|
6 |
|
if($request->shared) |
|
42
|
|
|
{ |
|
43
|
2 |
|
$parent = $this->custObj->getParentID($request->cust_id); |
|
44
|
2 |
|
if($parent) |
|
45
|
|
|
{ |
|
46
|
2 |
|
$custID = $parent; |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
6 |
|
CustomerFiles::find($custFileID)->update([ |
|
51
|
6 |
|
'cust_id' => $custID, |
|
52
|
6 |
|
'file_type_id' => $request->file_type_id, |
|
53
|
6 |
|
'shared' => $request->shared, |
|
54
|
6 |
|
'name' => $request->name, |
|
55
|
|
|
]); |
|
56
|
|
|
|
|
57
|
6 |
|
return true; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
4 |
|
public function deleteCustFile($custFileID) |
|
61
|
|
|
{ |
|
62
|
4 |
|
$file = CustomerFiles::find($custFileID); |
|
63
|
4 |
|
$fileID = $file->file_id; |
|
64
|
4 |
|
$file->delete(); |
|
65
|
|
|
|
|
66
|
4 |
|
$this->deleteFile($fileID); |
|
67
|
|
|
|
|
68
|
4 |
|
return true; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
protected function processCustFile($fileID, $userID, $fileData) |
|
72
|
|
|
{ |
|
73
|
|
|
$custID = $fileData->cust_id; |
|
74
|
|
|
if($fileData->shared) |
|
75
|
|
|
{ |
|
76
|
|
|
$parent = $this->custObj->getParentID($fileData->cust_id); |
|
77
|
|
|
if($parent) |
|
78
|
|
|
{ |
|
79
|
|
|
$custID = $parent; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$fileID = CustomerFiles::create([ |
|
84
|
|
|
'file_id' => $fileID, |
|
85
|
|
|
'file_type_id' => $fileData->file_type_id, |
|
86
|
|
|
'cust_id' => $custID, |
|
87
|
|
|
'user_id' => $userID, |
|
88
|
|
|
'shared' => $fileData->shared === 'true' ? true : false, |
|
89
|
|
|
'name' => $fileData->name, |
|
90
|
|
|
]); |
|
91
|
|
|
|
|
92
|
|
|
return $fileID->cust_file_id; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|