|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the Superdesk Web Publisher MultiTenancy Component. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright 2016 Sourcefabric z.ú. and contributors. |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please see the |
|
9
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
|
10
|
|
|
* |
|
11
|
|
|
* @copyright 2016 Sourcefabric z.ú. |
|
12
|
|
|
* @license http://www.superdesk.org/license |
|
13
|
|
|
*/ |
|
14
|
|
|
namespace SWP\Component\MultiTenancy\Model; |
|
15
|
|
|
|
|
16
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
17
|
|
|
use Doctrine\Common\Collections\Collection; |
|
18
|
|
|
use SWP\Component\Common\Model\EnableableTrait; |
|
19
|
|
|
use SWP\Component\Common\Model\SoftDeletableTrait; |
|
20
|
|
|
use SWP\Component\Common\Model\TimestampableTrait; |
|
21
|
|
|
|
|
22
|
|
|
class Organization implements OrganizationInterface |
|
23
|
|
|
{ |
|
24
|
|
|
use SoftDeletableTrait, TimestampableTrait, EnableableTrait; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var mixed |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $id; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $name; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var string |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $code; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var Collection|TenantInterface[] |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $tenants; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Organization constructor. |
|
48
|
|
|
*/ |
|
49
|
|
|
public function __construct() |
|
50
|
|
|
{ |
|
51
|
|
|
$this->createdAt = new \DateTime(); |
|
52
|
|
|
$this->tenants = new ArrayCollection(); |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* {@inheritdoc} |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getId() |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->id; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* {@inheritdoc} |
|
65
|
|
|
*/ |
|
66
|
|
|
public function setId($id) |
|
67
|
|
|
{ |
|
68
|
|
|
$this->id = $id; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* {@inheritdoc} |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getName() |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->name; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* {@inheritdoc} |
|
81
|
|
|
*/ |
|
82
|
|
|
public function setName($name) |
|
83
|
|
|
{ |
|
84
|
|
|
$this->name = $name; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* {@inheritdoc} |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getCode() |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->code; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* {@inheritdoc} |
|
97
|
|
|
*/ |
|
98
|
|
|
public function setCode($code) |
|
99
|
|
|
{ |
|
100
|
|
|
if (null !== $this->code) { |
|
101
|
|
|
throw new \LogicException('The code is already set. Can not change it.'); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
$this->code = $code; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* {@inheritdoc} |
|
109
|
|
|
*/ |
|
110
|
|
|
public function getTenants() |
|
111
|
|
|
{ |
|
112
|
|
|
return $this->tenants; |
|
|
|
|
|
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* {@inheritdoc} |
|
117
|
|
|
*/ |
|
118
|
|
|
public function hasTenant(TenantInterface $tenant) |
|
119
|
|
|
{ |
|
120
|
|
|
return $this->tenants->contains($tenant); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* {@inheritdoc} |
|
125
|
|
|
*/ |
|
126
|
|
|
public function addTenant(TenantInterface $tenant) |
|
127
|
|
|
{ |
|
128
|
|
|
if (!$this->hasTenant($tenant)) { |
|
129
|
|
|
$this->tenants->add($tenant); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* {@inheritdoc} |
|
135
|
|
|
*/ |
|
136
|
|
|
public function removeTenant(TenantInterface $tenant) |
|
137
|
|
|
{ |
|
138
|
|
|
if ($this->hasTenant($tenant)) { |
|
139
|
|
|
$this->tenants->removeElement($tenant); |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..