Skip to content

Subscribepage #353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/services/managers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,7 @@ services:
PhpList\Core\Domain\Subscription\Service\Manager\SubscriberBlacklistManager:
autowire: true
autoconfigure: true

PhpList\Core\Domain\Subscription\Service\Manager\SubscribePageManager:
autowire: true
autoconfigure: true
10 changes: 10 additions & 0 deletions config/services/repositories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,13 @@ services:
parent: PhpList\Core\Domain\Common\Repository\AbstractRepository
arguments:
- PhpList\Core\Domain\Subscription\Model\UserBlacklistData

PhpList\Core\Domain\Subscription\Repository\SubscriberPageRepository:
parent: PhpList\Core\Domain\Common\Repository\AbstractRepository
arguments:
- PhpList\Core\Domain\Subscription\Model\SubscribePage

PhpList\Core\Domain\Subscription\Repository\SubscriberPageDataRepository:
parent: PhpList\Core\Domain\Common\Repository\AbstractRepository
arguments:
- PhpList\Core\Domain\Subscription\Model\SubscribePageData
10 changes: 6 additions & 4 deletions src/Domain/Subscription/Model/SubscribePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\ORM\Mapping as ORM;
use PhpList\Core\Domain\Common\Model\Interfaces\DomainModel;
use PhpList\Core\Domain\Common\Model\Interfaces\Identity;
use PhpList\Core\Domain\Identity\Model\Administrator;
use PhpList\Core\Domain\Subscription\Repository\SubscriberPageRepository;

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

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

public function getId(): ?int
{
Expand All @@ -42,7 +44,7 @@ public function isActive(): bool
return $this->active;
}

public function getOwner(): ?int
public function getOwner(): ?Administrator
{
return $this->owner;
}
Expand All @@ -59,7 +61,7 @@ public function setActive(bool $active): self
return $this;
}

public function setOwner(?int $owner): self
public function setOwner(?Administrator $owner): self
{
$this->owner = $owner;
return $this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,21 @@
use PhpList\Core\Domain\Common\Repository\AbstractRepository;
use PhpList\Core\Domain\Common\Repository\CursorPaginationTrait;
use PhpList\Core\Domain\Common\Repository\Interfaces\PaginatableRepositoryInterface;
use PhpList\Core\Domain\Subscription\Model\SubscribePage;
use PhpList\Core\Domain\Subscription\Model\SubscribePageData;

class SubscriberPageDataRepository extends AbstractRepository implements PaginatableRepositoryInterface
{
use CursorPaginationTrait;

public function findByPageAndName(SubscribePage $page, string $name): ?SubscribePageData
{
return $this->findOneBy(['id' => $page->getId(), 'name' => $name]);
}

/** @return SubscribePageData[] */
public function getByPage(SubscribePage $page): array
{
return $this->findBy(['id' => $page->getId()]);
}
}
16 changes: 16 additions & 0 deletions src/Domain/Subscription/Repository/SubscriberPageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,24 @@
use PhpList\Core\Domain\Common\Repository\AbstractRepository;
use PhpList\Core\Domain\Common\Repository\CursorPaginationTrait;
use PhpList\Core\Domain\Common\Repository\Interfaces\PaginatableRepositoryInterface;
use PhpList\Core\Domain\Subscription\Model\SubscribePage;
use PhpList\Core\Domain\Subscription\Model\SubscribePageData;

class SubscriberPageRepository extends AbstractRepository implements PaginatableRepositoryInterface
{
use CursorPaginationTrait;

/** @return array{page: SubscribePage, data: SubscribePageData}[] */
public function findPagesWithData(int $pageId): array
{
return $this->createQueryBuilder('p')
->select('p AS page, d AS data')
->from(SubscribePage::class, 'p')
->from(SubscribePageData::class, 'd')
->where('p.id = :id')
->andWhere('d.id = p.id')
->setParameter('id', $pageId)
->getQuery()
->getResult();
}
}
105 changes: 105 additions & 0 deletions src/Domain/Subscription/Service/Manager/SubscribePageManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

declare(strict_types=1);

namespace PhpList\Core\Domain\Subscription\Service\Manager;

use Doctrine\ORM\EntityManagerInterface;
use PhpList\Core\Domain\Identity\Model\Administrator;
use PhpList\Core\Domain\Subscription\Model\SubscribePage;
use PhpList\Core\Domain\Subscription\Model\SubscribePageData;
use PhpList\Core\Domain\Subscription\Repository\SubscriberPageDataRepository;
use PhpList\Core\Domain\Subscription\Repository\SubscriberPageRepository;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class SubscribePageManager
{
public function __construct(
private readonly SubscriberPageRepository $pageRepository,
private readonly SubscriberPageDataRepository $pageDataRepository,
private readonly EntityManagerInterface $entityManager,
) {
}

/**
* @SuppressWarnings("BooleanArgumentFlag")
*/
public function createPage(string $title, bool $active = false, ?Administrator $owner = null): SubscribePage
{
$page = new SubscribePage();
$page->setTitle($title)
->setActive($active)
->setOwner($owner);

$this->pageRepository->save($page);

return $page;
}

public function getPage(int $id): SubscribePage
{
/** @var SubscribePage|null $page */
$page = $this->pageRepository->find($id);
if (!$page) {
throw new NotFoundHttpException('Subscribe page not found');
}

return $page;
}

public function updatePage(
SubscribePage $page,
?string $title = null,
?bool $active = null,
?Administrator $owner = null
): SubscribePage {
if ($title !== null) {
$page->setTitle($title);
}
if ($active !== null) {
$page->setActive($active);
}
if ($owner !== null) {
$page->setOwner($owner);
}

$this->entityManager->flush();

return $page;
}

public function setActive(SubscribePage $page, bool $active): void
{
$page->setActive($active);
$this->entityManager->flush();
}

public function deletePage(SubscribePage $page): void
{
$this->pageRepository->remove($page);
}

/** @return SubscribePageData[] */
public function getPageData(SubscribePage $page): array
{
return $this->pageDataRepository->getByPage($page,);
}

public function setPageData(SubscribePage $page, string $name, ?string $value): SubscribePageData
{
/** @var SubscribePageData|null $data */
$data = $this->pageDataRepository->findByPageAndName($page, $name);

if (!$data) {
$data = (new SubscribePageData())
->setId((int)$page->getId())
->setName($name);
$this->entityManager->persist($data);
}

$data->setData($value);
$this->entityManager->flush();

return $data;
}
}
Loading
Loading