zend-blog-3-backend

Форк
0
/
EmailSubscriptionSettingsRepository.php 
38 строк · 1.0 Кб
1
<?php
2

3
namespace App\Repository;
4

5
use App\Entity\EmailSubscriptionSettings;
6
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
7
use Doctrine\Persistence\ManagerRegistry;
8

9
/**
10
 * @method EmailSubscriptionSettings|null findOneBy(array $criteria, array $orderBy = null)
11
 */
12
class EmailSubscriptionSettingsRepository extends ServiceEntityRepository
13
{
14
    /**
15
     * @param ManagerRegistry $registry
16
     */
17
    public function __construct(ManagerRegistry $registry)
18
    {
19
        parent::__construct($registry, EmailSubscriptionSettings::class);
20
    }
21

22
    public function findOrCreate(string $email, int $type): EmailSubscriptionSettings
23
    {
24
        $entity = $this->findOneBy(['email' => $email, 'type' => $type]);
25
        if (!$entity) {
26
            $entity = new EmailSubscriptionSettings();
27
            $entity
28
                ->setEmail($email)
29
                ->setType($type)
30
            ;
31

32
            $this->getEntityManager()->persist($entity);
33
            $this->getEntityManager()->flush();
34
        }
35

36
        return $entity;
37
    }
38
}
39

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.