1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Tinyissue package. |
5
|
|
|
* |
6
|
|
|
* (c) Mohamed Alsharaf <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Tinyissue\Model\Project\Issue; |
13
|
|
|
|
14
|
|
|
use Tinyissue\Model\ModelAbstract; |
15
|
|
|
use Tinyissue\Model\Project; |
16
|
|
|
use Tinyissue\Model\User; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Attachment is model class for project attachments. |
20
|
|
|
* |
21
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
22
|
|
|
* |
23
|
|
|
* @property int $id |
24
|
|
|
* @property int $uploaded_by |
25
|
|
|
* @property int $issue_id |
26
|
|
|
* @property int $comment_id |
27
|
|
|
* @property string $filename |
28
|
|
|
* @property string $fileextension |
29
|
|
|
* @property int $filesize |
30
|
|
|
* @property string $upload_token |
31
|
|
|
* @property Project\Issue $issue |
32
|
|
|
* @property User $user |
33
|
|
|
* @property Comment $comment |
34
|
|
|
* |
35
|
|
|
* @method $this byUser($userOrId) |
36
|
|
|
* @method $this forToken($token) |
37
|
|
|
* @method $this filename($name) |
38
|
|
|
*/ |
39
|
|
|
class Attachment extends ModelAbstract |
40
|
|
|
{ |
41
|
|
|
use AttachmentRelations, AttachmentScopes; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Timestamp enabled. |
45
|
|
|
* |
46
|
|
|
* @var bool |
47
|
|
|
*/ |
48
|
|
|
public $timestamps = true; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Name of database table. |
52
|
|
|
* |
53
|
|
|
* @var string |
54
|
|
|
*/ |
55
|
|
|
protected $table = 'projects_issues_attachments'; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* List of allowed columns to be used in $this->fill(). |
59
|
|
|
* |
60
|
|
|
* @var array |
61
|
|
|
*/ |
62
|
|
|
protected $fillable = [ |
63
|
|
|
'uploaded_by', |
64
|
|
|
'filename', |
65
|
|
|
'fileextension', |
66
|
|
|
'filesize', |
67
|
|
|
'upload_token', |
68
|
|
|
]; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param User|null $user |
72
|
|
|
* |
73
|
|
|
* @return \Tinyissue\Repository\Project\Issue\Attachment\Updater |
74
|
|
|
*/ |
75
|
|
|
public function updater(User $user = null) |
76
|
|
|
{ |
77
|
|
|
return parent::updater($user); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Whether or not the file extension is supported image type. |
82
|
|
|
* |
83
|
|
|
* @return bool |
84
|
|
|
*/ |
85
|
|
|
public function isImage() |
86
|
|
|
{ |
87
|
|
|
return in_array($this->fileextension, [ |
88
|
|
|
'jpg', |
89
|
|
|
'jpeg', |
90
|
|
|
'JPG', |
91
|
|
|
'JPEG', |
92
|
|
|
'png', |
93
|
|
|
'PNG', |
94
|
|
|
'gif', |
95
|
|
|
'GIF', |
96
|
|
|
]); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Url to attachment download. |
101
|
|
|
* |
102
|
|
|
* @return string |
103
|
|
|
*/ |
104
|
|
|
public function download() |
105
|
|
|
{ |
106
|
|
|
return \URL::to('project/' . $this->issue->project_id . '/issue/' . $this->issue_id . '/download/' . $this->id); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Url to display attachment. |
111
|
|
|
* |
112
|
|
|
* @return string |
113
|
|
|
*/ |
114
|
|
|
public function display() |
115
|
|
|
{ |
116
|
|
|
return \URL::to('project/' . $this->issue->project_id . '/issue/' . $this->issue_id . '/display/' . $this->id); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Generate a URL to delete attachment. |
121
|
|
|
* |
122
|
|
|
* @return string |
123
|
|
|
*/ |
124
|
|
|
public function toDelete() |
125
|
|
|
{ |
126
|
|
|
return \URL::to('project/' . $this->issue->project_id . '/issue/' . $this->issue_id . '/delete/' . $this->id); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|