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 Illuminate\Database\Eloquent\Model as BaseModel; |
15
|
|
|
use Tinyissue\Model\Project; |
16
|
|
|
use Tinyissue\Model\Traits\Project\Issue\Attachment\CrudTrait; |
17
|
|
|
use Tinyissue\Model\Traits\Project\Issue\Attachment\RelationTrait; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Attachment is model class for project attachments. |
21
|
|
|
* |
22
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
23
|
|
|
* |
24
|
|
|
* @property int $id |
25
|
|
|
* @property int $uploaded_by |
26
|
|
|
* @property int $issue_id |
27
|
|
|
* @property int $comment_id |
28
|
|
|
* @property string $filename |
29
|
|
|
* @property string $fileextension |
30
|
|
|
* @property int $filesize |
31
|
|
|
* @property string $upload_token |
32
|
|
|
* @property Project\Issue $issue |
33
|
|
|
*/ |
34
|
|
|
class Attachment extends BaseModel |
35
|
|
|
{ |
36
|
|
|
use CrudTrait, |
37
|
|
|
RelationTrait; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Timestamp enabled. |
41
|
|
|
* |
42
|
|
|
* @var bool |
43
|
|
|
*/ |
44
|
|
|
public $timestamps = true; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Name of database table. |
48
|
|
|
* |
49
|
|
|
* @var string |
50
|
|
|
*/ |
51
|
|
|
protected $table = 'projects_issues_attachments'; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* List of allowed columns to be used in $this->fill(). |
55
|
|
|
* |
56
|
|
|
* @var array |
57
|
|
|
*/ |
58
|
|
|
protected $fillable = [ |
59
|
|
|
'uploaded_by', |
60
|
|
|
'filename', |
61
|
|
|
'fileextension', |
62
|
|
|
'filesize', |
63
|
|
|
'upload_token', |
64
|
|
|
]; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Whether or not the file extension is supported image type. |
68
|
|
|
* |
69
|
|
|
* @return bool |
70
|
|
|
*/ |
71
|
3 |
|
public function isImage() |
72
|
|
|
{ |
73
|
3 |
|
return in_array($this->fileextension, [ |
74
|
3 |
|
'jpg', |
75
|
3 |
|
'jpeg', |
76
|
3 |
|
'JPG', |
77
|
3 |
|
'JPEG', |
78
|
3 |
|
'png', |
79
|
3 |
|
'PNG', |
80
|
3 |
|
'gif', |
81
|
3 |
|
'GIF', |
82
|
3 |
|
]); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Url to attachment download. |
87
|
|
|
* |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
3 |
|
public function download() |
91
|
|
|
{ |
92
|
3 |
|
return \URL::to('project/' . $this->issue->project_id . '/issue/' . $this->issue_id . '/download/' . $this->id); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Url to display attachment. |
97
|
|
|
* |
98
|
|
|
* @return string |
99
|
|
|
*/ |
100
|
|
|
public function display() |
101
|
|
|
{ |
102
|
|
|
return \URL::to('project/' . $this->issue->project_id . '/issue/' . $this->issue_id . '/display/' . $this->id); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|