1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Core\Entity; |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
use Auth\Entity\UserInterface; |
9
|
|
|
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; |
10
|
|
|
|
11
|
|
|
trait FileMetadataTrait |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @ODM\Field(type="string", nullable=true) |
15
|
|
|
*/ |
16
|
|
|
protected ?string $contentType = null; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* owner of an attachment. Typically this is the candidate who applies for a job offer. |
20
|
|
|
* |
21
|
|
|
* @ODM\ReferenceOne(targetDocument="Auth\Entity\User", storeAs="id", cascade={"persist"}) |
22
|
|
|
*/ |
23
|
|
|
protected ?UserInterface $user = null; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @ODM\EmbedOne(targetDocument="Core\Entity\Permissions") |
27
|
|
|
*/ |
28
|
|
|
protected ?PermissionsInterface $permissions = null; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @ODM\Field(type="string", nullable=true) |
32
|
|
|
*/ |
33
|
|
|
protected ?string $name = null; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @return string |
37
|
|
|
*/ |
38
|
|
|
public function getResourceId() |
39
|
|
|
{ |
40
|
|
|
return 'Entity/File'; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return string|null |
45
|
|
|
*/ |
46
|
|
|
public function getContentType(): ?string |
47
|
|
|
{ |
48
|
|
|
return $this->contentType; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param string|null $contentType |
53
|
|
|
* @return $this |
54
|
|
|
*/ |
55
|
|
|
public function setContentType(?string $contentType) |
56
|
|
|
{ |
57
|
|
|
$this->contentType = $contentType; |
58
|
|
|
return $this; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return UserInterface|null |
63
|
|
|
*/ |
64
|
|
|
public function getUser(): ?UserInterface |
65
|
|
|
{ |
66
|
|
|
return $this->user; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function setUser(?UserInterface $user): self |
70
|
|
|
{ |
71
|
|
|
if ($this->user) { |
72
|
|
|
$this->getPermissions()->revoke($this->user, Permissions::PERMISSION_ALL, false); |
73
|
|
|
} |
74
|
|
|
$this->user = $user; |
75
|
|
|
$this->getPermissions()->grant($user, Permissions::PERMISSION_ALL); |
76
|
|
|
|
77
|
|
|
return $this; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return PermissionsInterface|null |
82
|
|
|
*/ |
83
|
|
|
public function getPermissions(): ?PermissionsInterface |
84
|
|
|
{ |
85
|
|
|
if (!$this->permissions) { |
86
|
|
|
$perms = new Permissions(); |
87
|
|
|
if ($this->user instanceof UserInterface) { |
88
|
|
|
$perms->grant($this->user, PermissionsInterface::PERMISSION_ALL); |
89
|
|
|
} |
90
|
|
|
$this->setPermissions($perms); |
91
|
|
|
} |
92
|
|
|
return $this->permissions; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function setPermissions(PermissionsInterface $permissions) |
96
|
|
|
{ |
97
|
|
|
$this->permissions = $permissions; |
98
|
|
|
return $this; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return string|null |
103
|
|
|
*/ |
104
|
|
|
public function getName(): ?string |
105
|
|
|
{ |
106
|
|
|
return $this->name; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function setName(?string $name) |
110
|
|
|
{ |
111
|
|
|
$this->name = $name; |
112
|
|
|
return $this; |
113
|
|
|
} |
114
|
|
|
} |