Skip to content

Commit e91742c

Browse files
committed
owner entity
1 parent 1225b55 commit e91742c

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

src/Domain/Subscription/Model/SubscribePage.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Doctrine\ORM\Mapping as ORM;
88
use PhpList\Core\Domain\Common\Model\Interfaces\DomainModel;
99
use PhpList\Core\Domain\Common\Model\Interfaces\Identity;
10+
use PhpList\Core\Domain\Identity\Model\Administrator;
1011
use PhpList\Core\Domain\Subscription\Repository\SubscriberPageRepository;
1112

1213
#[ORM\Entity(repositoryClass: SubscriberPageRepository::class)]
@@ -24,8 +25,9 @@ class SubscribePage implements DomainModel, Identity
2425
#[ORM\Column(name: 'active', type: 'boolean', options: ['default' => 0])]
2526
private bool $active = false;
2627

27-
#[ORM\Column(name: 'owner', type: 'integer', nullable: true)]
28-
private ?int $owner = null;
28+
#[ORM\ManyToOne(targetEntity: Administrator::class)]
29+
#[ORM\JoinColumn(name: 'owner', referencedColumnName: 'id', nullable: true)]
30+
private ?Administrator $owner = null;
2931

3032
public function getId(): ?int
3133
{
@@ -42,7 +44,7 @@ public function isActive(): bool
4244
return $this->active;
4345
}
4446

45-
public function getOwner(): ?int
47+
public function getOwner(): ?Administrator
4648
{
4749
return $this->owner;
4850
}
@@ -59,7 +61,7 @@ public function setActive(bool $active): self
5961
return $this;
6062
}
6163

62-
public function setOwner(?int $owner): self
64+
public function setOwner(?Administrator $owner): self
6365
{
6466
$this->owner = $owner;
6567
return $this;

src/Domain/Subscription/Repository/SubscriberPageDataRepository.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@
77
use PhpList\Core\Domain\Common\Repository\AbstractRepository;
88
use PhpList\Core\Domain\Common\Repository\CursorPaginationTrait;
99
use PhpList\Core\Domain\Common\Repository\Interfaces\PaginatableRepositoryInterface;
10+
use PhpList\Core\Domain\Subscription\Model\SubscribePage;
11+
use PhpList\Core\Domain\Subscription\Model\SubscribePageData;
1012

1113
class SubscriberPageDataRepository extends AbstractRepository implements PaginatableRepositoryInterface
1214
{
1315
use CursorPaginationTrait;
16+
17+
public function findByPageAndName(SubscribePage $page, string $name): ?SubscribePageData
18+
{
19+
return $this->findOneBy(['id' => $page->getId(), 'name' => $name]);
20+
}
1421
}

src/Domain/Subscription/Service/Manager/SubscribePageManager.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace PhpList\Core\Domain\Subscription\Service\Manager;
66

77
use Doctrine\ORM\EntityManagerInterface;
8+
use PhpList\Core\Domain\Identity\Model\Administrator;
89
use PhpList\Core\Domain\Subscription\Model\SubscribePage;
910
use PhpList\Core\Domain\Subscription\Model\SubscribePageData;
1011
use PhpList\Core\Domain\Subscription\Repository\SubscriberPageDataRepository;
@@ -20,7 +21,7 @@ public function __construct(
2021
) {
2122
}
2223

23-
public function createPage(string $title, bool $active = false, ?int $owner = null): SubscribePage
24+
public function createPage(string $title, bool $active = false, ?Administrator $owner = null): SubscribePage
2425
{
2526
$page = new SubscribePage();
2627
$page->setTitle($title)
@@ -43,8 +44,12 @@ public function getPage(int $id): SubscribePage
4344
return $page;
4445
}
4546

46-
public function updatePage(SubscribePage $page, ?string $title = null, ?bool $active = null, ?int $owner = null): SubscribePage
47-
{
47+
public function updatePage(
48+
SubscribePage $page,
49+
?string $title = null,
50+
?bool $active = null,
51+
?Administrator $owner = null
52+
): SubscribePage {
4853
if ($title !== null) {
4954
$page->setTitle($title);
5055
}
@@ -74,14 +79,14 @@ public function deletePage(SubscribePage $page): void
7479
public function getPageData(SubscribePage $page, string $name): ?string
7580
{
7681
/** @var SubscribePageData|null $data */
77-
$data = $this->pageDataRepository->findOneBy(['id' => $page->getId(), 'name' => $name]);
82+
$data = $this->pageDataRepository->findByPageAndName($page, $name);
7883
return $data?->getData();
7984
}
8085

8186
public function setPageData(SubscribePage $page, string $name, ?string $value): SubscribePageData
8287
{
8388
/** @var SubscribePageData|null $data */
84-
$data = $this->pageDataRepository->findOneBy(['id' => $page->getId(), 'name' => $name]);
89+
$data = $this->pageDataRepository->findByPageAndName($page, $name);
8590

8691
if (!$data) {
8792
$data = (new SubscribePageData())

0 commit comments

Comments
 (0)