1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
4
|
|
|
* |
5
|
|
|
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics) |
6
|
|
|
* |
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU Affero General Public License as published |
9
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU Affero General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU Affero General Public License |
18
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
declare(strict_types=1); |
22
|
|
|
|
23
|
|
|
namespace App\Entity\Attachments; |
24
|
|
|
|
25
|
|
|
use App\Entity\Base\AbstractStructuralDBElement; |
26
|
|
|
use App\Entity\Parameters\AttachmentTypeParameter; |
27
|
|
|
use App\Validator\Constraints\ValidFileFilter; |
28
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
29
|
|
|
use Doctrine\Common\Collections\Collection; |
30
|
|
|
use Doctrine\ORM\Mapping as ORM; |
31
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Class AttachmentType. |
35
|
|
|
* |
36
|
|
|
* @ORM\Entity(repositoryClass="App\Repository\StructuralDBElementRepository") |
37
|
|
|
* @ORM\Table(name="`attachment_types`") |
38
|
|
|
*/ |
39
|
|
|
class AttachmentType extends AbstractStructuralDBElement |
40
|
|
|
{ |
41
|
|
|
/** |
42
|
|
|
* @ORM\OneToMany(targetEntity="AttachmentType", mappedBy="parent", cascade={"persist"}) |
43
|
|
|
* @ORM\OrderBy({"name" = "ASC"}) |
44
|
|
|
*/ |
45
|
|
|
protected $children; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @ORM\ManyToOne(targetEntity="AttachmentType", inversedBy="children") |
49
|
|
|
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id") |
50
|
|
|
*/ |
51
|
|
|
protected $parent; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var string |
55
|
|
|
* @ORM\Column(type="text") |
56
|
|
|
* @ValidFileFilter |
57
|
|
|
*/ |
58
|
|
|
protected $filetype_filter = ''; |
59
|
|
|
/** |
60
|
|
|
* @var Collection<int, AttachmentTypeAttachment> |
61
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\AttachmentTypeAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true) |
62
|
|
|
* @ORM\OrderBy({"name" = "ASC"}) |
63
|
|
|
* @Assert\Valid() |
64
|
|
|
*/ |
65
|
|
|
protected $attachments; |
66
|
|
|
|
67
|
|
|
/** @var Collection<int, AttachmentTypeParameter> |
68
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Parameters\AttachmentTypeParameter", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true) |
69
|
|
|
* @ORM\OrderBy({"group" = "ASC" ,"name" = "ASC"}) |
70
|
|
|
* @Assert\Valid() |
71
|
|
|
*/ |
72
|
|
|
protected $parameters; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @var Collection<int, Attachment> |
76
|
|
|
* @ORM\OneToMany(targetEntity="Attachment", mappedBy="attachment_type") |
77
|
|
|
*/ |
78
|
|
|
protected $attachments_with_type; |
79
|
|
|
|
80
|
|
|
public function __construct() |
81
|
|
|
{ |
82
|
|
|
parent::__construct(); |
83
|
|
|
$this->attachments = new ArrayCollection(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Get all attachments ("Attachment" objects) with this type. |
88
|
|
|
* |
89
|
|
|
* @return Collection|Attachment[] all attachments with this type, as a one-dimensional array of Attachments |
90
|
|
|
* (sorted by their names) |
91
|
|
|
*/ |
92
|
|
|
public function getAttachmentsForType(): Collection |
93
|
|
|
{ |
94
|
|
|
return $this->attachments; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Gets an filter, which file types are allowed for attachment files. |
99
|
|
|
* Must be in the format of <input type=file> accept attribute |
100
|
|
|
* (See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#Unique_file_type_specifiers). |
101
|
|
|
*/ |
102
|
|
|
public function getFiletypeFilter(): string |
103
|
|
|
{ |
104
|
|
|
return $this->filetype_filter; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Sets the filetype filter pattern. |
109
|
|
|
* |
110
|
|
|
* @param string $filetype_filter The new filetype filter |
111
|
|
|
* |
112
|
|
|
* @return $this |
113
|
|
|
*/ |
114
|
|
|
public function setFiletypeFilter(string $filetype_filter): self |
115
|
|
|
{ |
116
|
|
|
$this->filetype_filter = $filetype_filter; |
117
|
|
|
|
118
|
|
|
return $this; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
} |
122
|
|
|
|