1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Domains\FileLinks; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Log; |
6
|
|
|
|
7
|
|
|
use App\FileLinks; |
8
|
|
|
use App\FileLinkFiles; |
9
|
|
|
|
10
|
|
|
use App\Http\Resources\FileLinks as FileLinksResource; |
11
|
|
|
|
12
|
|
|
class GetFileLinkDetails |
13
|
|
|
{ |
14
|
|
|
protected $linkID, $linkDetails; |
15
|
|
|
|
16
|
|
|
// Constructor will set the ID of the link if it is available |
17
|
38 |
|
public function __construct($linkID = null) |
18
|
|
|
{ |
19
|
38 |
|
$this->linkID = $linkID; |
20
|
38 |
|
if($this->linkID) |
21
|
|
|
{ |
22
|
12 |
|
$this->linkDetails = FileLinks::find($this->linkID); |
23
|
|
|
} |
24
|
38 |
|
} |
25
|
|
|
|
26
|
|
|
// Return the details of the file link |
27
|
4 |
|
public function execute($collection = false) |
28
|
|
|
{ |
29
|
4 |
|
Log::debug('File link details gathered for '.$this->linkID.'. Data gathered - ', array($this->linkDetails)); |
30
|
4 |
|
if($collection) |
31
|
|
|
{ |
32
|
2 |
|
return new FileLinksResource($this->linkDetails); |
33
|
|
|
} |
34
|
|
|
|
35
|
2 |
|
return $this->linkDetails; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
// Determines if the link is actually valid or not |
39
|
4 |
|
public function isLinkValid() |
40
|
|
|
{ |
41
|
4 |
|
return $this->linkDetails ? true : false; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
// Determines if there is a customer attached to the link |
45
|
6 |
|
public function getLinkCustomer() |
46
|
|
|
{ |
47
|
6 |
|
return $this->linkDetails->cust_id; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
// Retrieves the instructions assigned to the link |
51
|
8 |
|
public function getLinkInstructions() |
52
|
|
|
{ |
53
|
8 |
|
return $this->linkDetails->note; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
// Retrieves the ID of the link based on the URL hash provided |
57
|
26 |
|
public function getLinkID($hash) |
58
|
|
|
{ |
59
|
26 |
|
$data = FileLinks::where('link_hash', $hash)->first(); |
60
|
|
|
|
61
|
26 |
|
if($data) |
62
|
|
|
{ |
63
|
24 |
|
$this->linkID = $data->link_id; |
64
|
24 |
|
$this->linkDetails = $data; |
65
|
24 |
|
Log::debug('File link details gathered for '.$this->linkID.'. Data gathered - ', array($this->linkDetails)); |
66
|
24 |
|
return $this->linkID; |
67
|
|
|
} |
68
|
|
|
|
69
|
2 |
|
return false; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
// Determine if the link has expired or not |
73
|
10 |
|
public function isLinkExpired() |
74
|
|
|
{ |
75
|
10 |
|
return $this->linkDetails->expire <= date('Y-m-d'); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
// Determine if the link has files availabe for guest to download |
79
|
8 |
|
public function hasGuestFiles() |
80
|
|
|
{ |
81
|
8 |
|
$files = FileLinkFiles::where('link_id', $this->linkID)->where('upload', false)->count(); |
82
|
8 |
|
return $files > 0 ? true : false; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
// Determine if the guest can upload a file or not |
86
|
8 |
|
public function canGuestUpload() |
87
|
|
|
{ |
88
|
8 |
|
return $this->linkDetails->allow_upload === 'Yes' ? true : false; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
// Determine if the link has no files to download, and the guest cannot upload files |
92
|
8 |
|
public function isLinkDead() |
93
|
|
|
{ |
94
|
8 |
|
if(!$this->hasGuestFiles() && !$this->canGuestUpload()) |
95
|
|
|
{ |
96
|
2 |
|
return true; |
97
|
|
|
} |
98
|
|
|
|
99
|
6 |
|
return false; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|