|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Superdesk Web Publisher Bridge 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
|
|
|
|
|
15
|
|
|
namespace SWP\Component\Bridge\Model; |
|
16
|
|
|
|
|
17
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
18
|
|
|
use Doctrine\Common\Collections\Collection; |
|
19
|
|
|
use SWP\Component\Common\Model\EnableableTrait; |
|
20
|
|
|
use SWP\Component\Common\Model\SoftDeletableTrait; |
|
21
|
|
|
use SWP\Component\Common\Model\TimestampableTrait; |
|
22
|
|
|
|
|
23
|
|
|
class Package extends BaseContent implements PackageInterface |
|
24
|
|
|
{ |
|
25
|
|
|
use TimestampableTrait; |
|
26
|
|
|
use SoftDeletableTrait; |
|
27
|
|
|
use EnableableTrait; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var Collection |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $items; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $body; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var Collection |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $externalData; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var Collection |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $groups; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var ItemInterface[]|Collection |
|
51
|
|
|
*/ |
|
52
|
|
|
protected $relatedItems; |
|
53
|
|
|
|
|
54
|
|
|
public function __construct() |
|
55
|
|
|
{ |
|
56
|
|
|
parent::__construct(); |
|
57
|
|
|
|
|
58
|
|
|
$this->items = new ArrayCollection(); |
|
59
|
|
|
$this->groups = new ArrayCollection(); |
|
60
|
|
|
$this->externalData = new ArrayCollection(); |
|
61
|
|
|
$this->relatedItems = new ArrayCollection(); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function getItemsArray(): array |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->items->toArray(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function getGroupsArray(): array |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->groups->toArray(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function getItems(): Collection |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->items; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function setItems(Collection $items) |
|
80
|
|
|
{ |
|
81
|
|
|
$this->items = $items; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function addItem(\SWP\Component\Bridge\Model\Item $item) |
|
85
|
|
|
{ |
|
86
|
|
|
if (!$this->items->contains($item)) { |
|
87
|
|
|
$this->items->add($item); |
|
88
|
|
|
$item->setPackage($this); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
return $this; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function removeItem(\SWP\Component\Bridge\Model\Item $item) |
|
95
|
|
|
{ |
|
96
|
|
|
if ($this->items->contains($item)) { |
|
97
|
|
|
$this->items->removeElement($item); |
|
98
|
|
|
$item->setPackage(null); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function getBody() |
|
103
|
|
|
{ |
|
104
|
|
|
return $this->body; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function setBody($body) |
|
108
|
|
|
{ |
|
109
|
|
|
$this->body = $body; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
public function getExternalData(): ?Collection |
|
113
|
|
|
{ |
|
114
|
|
|
return $this->externalData; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
public function setExternalData(Collection $externalData): void |
|
118
|
|
|
{ |
|
119
|
|
|
$this->externalData = $externalData; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function getGroups(): ?Collection |
|
123
|
|
|
{ |
|
124
|
|
|
return $this->groups; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
public function removeGroup(GroupInterface $group): void |
|
128
|
|
|
{ |
|
129
|
|
|
if ($this->groups->contains($group)) { |
|
130
|
|
|
$group->setPackage(null); |
|
131
|
|
|
$this->groups->removeElement($group); |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
public function addGroup(GroupInterface $group): void |
|
136
|
|
|
{ |
|
137
|
|
|
if (!$this->groups->contains($group)) { |
|
138
|
|
|
$group->setPackage($this); |
|
139
|
|
|
$this->groups->add($group); |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
public function setGroups(?Collection $groups): void |
|
144
|
|
|
{ |
|
145
|
|
|
$this->groups = $groups; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
public function getRelatedItems(): Collection |
|
149
|
|
|
{ |
|
150
|
|
|
return $this->relatedItems; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
public function setRelatedItems(Collection $relatedItems): void |
|
154
|
|
|
{ |
|
155
|
|
|
$this->relatedItems = $relatedItems; |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
|