Skip to content

Commit e748570

Browse files
committed
ISSUE-345: add relation to subscriber attributes
1 parent 628d9a3 commit e748570

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

src/Domain/Model/Subscription/Subscriber.php

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Doctrine\Common\Collections\Collection;
1010
use Doctrine\ORM\Mapping as ORM;
1111
use PhpList\Core\Domain\Repository\Subscription\SubscriberRepository;
12-
use Symfony\Component\Serializer\Annotation\Ignore;
1312
use Symfony\Component\Serializer\Annotation\SerializedName;
1413
use PhpList\Core\Domain\Model\Interfaces\CreationDate;
1514
use PhpList\Core\Domain\Model\Interfaces\DomainModel;
@@ -24,6 +23,7 @@
2423
* This class represents subscriber who can subscribe to multiple subscriber lists and can receive email messages from
2524
* campaigns for those subscriber lists.
2625
* @author Oliver Klee <[email protected]>
26+
* @author Tatevik Grigoryan <[email protected]>
2727
*/
2828
#[ORM\Entity(repositoryClass: SubscriberRepository::class)]
2929
#[ORM\Table(name: 'phplist_user_user')]
@@ -83,16 +83,28 @@ class Subscriber implements DomainModel, Identity, CreationDate, ModificationDat
8383
private ?string $extraData;
8484

8585
#[ORM\OneToMany(
86-
targetEntity: 'PhpList\Core\Domain\Model\Subscription\Subscription',
86+
targetEntity: Subscription::class,
8787
mappedBy: 'subscriber',
8888
cascade: ['remove'],
8989
orphanRemoval: true,
9090
)]
9191
private Collection $subscriptions;
9292

93+
/**
94+
* @var Collection<int, SubscriberAttribute>
95+
*/
96+
#[ORM\OneToMany(
97+
targetEntity: SubscriberAttribute::class,
98+
mappedBy: 'subscriber',
99+
cascade: ['persist', 'remove'],
100+
orphanRemoval: true
101+
)]
102+
private Collection $attributes;
103+
93104
public function __construct()
94105
{
95106
$this->subscriptions = new ArrayCollection();
107+
$this->attributes = new ArrayCollection();
96108
$this->extraData = '';
97109
}
98110

@@ -223,4 +235,24 @@ public function getSubscribedLists(): Collection
223235

224236
return $result;
225237
}
238+
239+
public function getAttributes(): Collection
240+
{
241+
return $this->attributes;
242+
}
243+
244+
public function addAttribute(SubscriberAttribute $attribute): self
245+
{
246+
if (!$this->attributes->contains($attribute)) {
247+
$this->attributes[] = $attribute;
248+
}
249+
250+
return $this;
251+
}
252+
253+
public function removeAttribute(SubscriberAttribute $attribute): self
254+
{
255+
$this->attributes->removeElement($attribute);
256+
return $this;
257+
}
226258
}

src/Domain/Model/Subscription/SubscriberAttribute.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
class SubscriberAttribute implements DomainModel
1616
{
1717
#[ORM\Id]
18-
#[ORM\Column(name: 'attributeid', type: 'integer', nullable: false)]
19-
private int $id;
18+
#[ORM\ManyToOne(targetEntity: SubscriberAttributeDefinition::class)]
19+
#[ORM\JoinColumn(name: 'attributeid', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
20+
private SubscriberAttributeDefinition $attributeDefinition;
2021

2122
#[ORM\Id]
2223
#[ORM\ManyToOne(targetEntity: Subscriber::class)]
@@ -26,15 +27,15 @@ class SubscriberAttribute implements DomainModel
2627
#[ORM\Column(name: 'value', type: 'text', nullable: true)]
2728
private ?string $value = null;
2829

29-
public function __construct(int $id, Subscriber $subscriber)
30+
public function __construct(SubscriberAttributeDefinition $attributeDefinition, Subscriber $subscriber)
3031
{
31-
$this->id = $id;
32+
$this->attributeDefinition = $attributeDefinition;
3233
$this->subscriber = $subscriber;
3334
}
3435

35-
public function getId(): int
36+
public function getAttributeDefinition(): SubscriberAttributeDefinition
3637
{
37-
return $this->id;
38+
return $this->attributeDefinition;
3839
}
3940

4041
public function getSubscriber(): Subscriber

src/Domain/Model/Identity/UserAttribute.php renamed to src/Domain/Model/Subscription/SubscriberAttributeDefinition.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace PhpList\Core\Domain\Model\Identity;
5+
namespace PhpList\Core\Domain\Model\Subscription;
66

77
use Doctrine\ORM\Mapping as ORM;
88
use PhpList\Core\Domain\Model\Interfaces\DomainModel;
@@ -13,7 +13,7 @@
1313
#[ORM\Table(name: 'phplist_user_attribute')]
1414
#[ORM\Index(name: 'idnameindex', columns: ['id', 'name'])]
1515
#[ORM\Index(name: 'nameindex', columns: ['name'])]
16-
class UserAttribute implements DomainModel, Identity
16+
class SubscriberAttributeDefinition implements DomainModel, Identity
1717
{
1818
use IdentityTrait;
1919

0 commit comments

Comments
 (0)