From b58b92bc3032251ef81fb8419837f95b2dd19c5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20=C3=81lvarez?= Date: Mon, 23 May 2022 20:40:22 +0200 Subject: [PATCH] sub --- composer.json | 2 +- migrations/Version20220523155141.php | 48 ++++++++++++++ migrations/Version20220523155631.php | 52 +++++++++++++++ src/Controller/IndexController.php | 35 ++++++++-- src/DataFixtures/MerFixtures.php | 83 +++++++++++++++--------- src/Entity/MerBeSub.php | 27 ++++++++ src/Entity/MerParaSub.php | 56 +--------------- src/Entity/MerSubBaseTrait.php | 80 +++++++++++++++++++++++ src/Enum/SubStatus.php | 12 ++++ src/Repository/MerBeSubRepository.php | 66 +++++++++++++++++++ src/Repository/MerParaSubRepository.php | 2 +- src/Repository/MerServiceRepository.php | 10 +++ templates/index/index.html.twig | 2 + templates/index/notificationDm.html.twig | 7 ++ 14 files changed, 390 insertions(+), 92 deletions(-) create mode 100644 migrations/Version20220523155141.php create mode 100644 migrations/Version20220523155631.php create mode 100644 src/Entity/MerBeSub.php create mode 100644 src/Entity/MerSubBaseTrait.php create mode 100644 src/Enum/SubStatus.php create mode 100644 src/Repository/MerBeSubRepository.php create mode 100644 templates/index/notificationDm.html.twig diff --git a/composer.json b/composer.json index c78c821..b633855 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "minimum-stability": "stable", "prefer-stable": true, "require": { - "php": ">=8.0.2", + "php": ">=8.1", "ext-ctype": "*", "ext-iconv": "*", "doctrine/doctrine-bundle": "^2.6", diff --git a/migrations/Version20220523155141.php b/migrations/Version20220523155141.php new file mode 100644 index 0000000..0ea8ad8 --- /dev/null +++ b/migrations/Version20220523155141.php @@ -0,0 +1,48 @@ +addSql('DROP INDEX IDX_E4F82A3DED5CA9E6'); + $this->addSql('CREATE TEMPORARY TABLE __temp__mer_para_sub AS SELECT id, service_id, sub_date, unsub_date, pin FROM mer_para_sub'); + $this->addSql('DROP TABLE mer_para_sub'); + $this->addSql('CREATE TABLE mer_para_sub (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, service_id INTEGER NOT NULL, sub_date DATETIME NOT NULL --(DC2Type:datetime_immutable) + , unsub_date DATETIME DEFAULT NULL --(DC2Type:datetime_immutable) + , pin INTEGER DEFAULT NULL, status INTEGER NOT NULL, CONSTRAINT FK_E4F82A3DED5CA9E6 FOREIGN KEY (service_id) REFERENCES mer_service (id) NOT DEFERRABLE INITIALLY IMMEDIATE)'); + $this->addSql('INSERT INTO mer_para_sub (id, service_id, sub_date, unsub_date, pin, status) SELECT id, service_id, sub_date, unsub_date, pin, 1 FROM __temp__mer_para_sub'); + $this->addSql('DROP TABLE __temp__mer_para_sub'); + $this->addSql('CREATE INDEX IDX_E4F82A3DED5CA9E6 ON mer_para_sub (service_id)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('DROP INDEX IDX_E4F82A3DED5CA9E6'); + $this->addSql('CREATE TEMPORARY TABLE __temp__mer_para_sub AS SELECT id, service_id, pin, sub_date, unsub_date FROM mer_para_sub'); + $this->addSql('DROP TABLE mer_para_sub'); + $this->addSql('CREATE TABLE mer_para_sub (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, service_id INTEGER NOT NULL, pin INTEGER DEFAULT NULL, sub_date DATETIME NOT NULL --(DC2Type:datetime_immutable) + , unsub_date DATETIME DEFAULT NULL --(DC2Type:datetime_immutable) + )'); + $this->addSql('INSERT INTO mer_para_sub (id, service_id, pin, sub_date, unsub_date) SELECT id, service_id, pin, sub_date, unsub_date FROM __temp__mer_para_sub'); + $this->addSql('DROP TABLE __temp__mer_para_sub'); + $this->addSql('CREATE INDEX IDX_E4F82A3DED5CA9E6 ON mer_para_sub (service_id)'); + } +} diff --git a/migrations/Version20220523155631.php b/migrations/Version20220523155631.php new file mode 100644 index 0000000..a692f3b --- /dev/null +++ b/migrations/Version20220523155631.php @@ -0,0 +1,52 @@ +addSql('CREATE TABLE mer_be_sub (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, service_id INTEGER NOT NULL, code VARCHAR(255) DEFAULT NULL, status INTEGER NOT NULL, sub_date DATETIME NOT NULL --(DC2Type:datetime_immutable) + , unsub_date DATETIME DEFAULT NULL --(DC2Type:datetime_immutable) + )'); + $this->addSql('CREATE INDEX IDX_CA4C3EB8ED5CA9E6 ON mer_be_sub (service_id)'); + $this->addSql('DROP INDEX IDX_E4F82A3DED5CA9E6'); + $this->addSql('CREATE TEMPORARY TABLE __temp__mer_para_sub AS SELECT id, service_id, sub_date, unsub_date, pin, status FROM mer_para_sub'); + $this->addSql('DROP TABLE mer_para_sub'); + $this->addSql('CREATE TABLE mer_para_sub (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, service_id INTEGER NOT NULL, sub_date DATETIME NOT NULL --(DC2Type:datetime_immutable) + , unsub_date DATETIME DEFAULT NULL --(DC2Type:datetime_immutable) + , pin INTEGER DEFAULT NULL, status INTEGER NOT NULL, CONSTRAINT FK_E4F82A3DED5CA9E6 FOREIGN KEY (service_id) REFERENCES mer_service (id) NOT DEFERRABLE INITIALLY IMMEDIATE)'); + $this->addSql('INSERT INTO mer_para_sub (id, service_id, sub_date, unsub_date, pin, status) SELECT id, service_id, sub_date, unsub_date, pin, status FROM __temp__mer_para_sub'); + $this->addSql('DROP TABLE __temp__mer_para_sub'); + $this->addSql('CREATE INDEX IDX_E4F82A3DED5CA9E6 ON mer_para_sub (service_id)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('DROP TABLE mer_be_sub'); + $this->addSql('DROP INDEX IDX_E4F82A3DED5CA9E6'); + $this->addSql('CREATE TEMPORARY TABLE __temp__mer_para_sub AS SELECT id, service_id, pin, status, sub_date, unsub_date FROM mer_para_sub'); + $this->addSql('DROP TABLE mer_para_sub'); + $this->addSql('CREATE TABLE mer_para_sub (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, service_id INTEGER NOT NULL, pin INTEGER DEFAULT NULL, status INTEGER NOT NULL, sub_date DATETIME NOT NULL --(DC2Type:datetime_immutable) + , unsub_date DATETIME DEFAULT NULL --(DC2Type:datetime_immutable) + )'); + $this->addSql('INSERT INTO mer_para_sub (id, service_id, pin, status, sub_date, unsub_date) SELECT id, service_id, pin, status, sub_date, unsub_date FROM __temp__mer_para_sub'); + $this->addSql('DROP TABLE __temp__mer_para_sub'); + $this->addSql('CREATE INDEX IDX_E4F82A3DED5CA9E6 ON mer_para_sub (service_id)'); + } +} diff --git a/src/Controller/IndexController.php b/src/Controller/IndexController.php index f175a53..15723ba 100644 --- a/src/Controller/IndexController.php +++ b/src/Controller/IndexController.php @@ -2,8 +2,11 @@ namespace App\Controller; +use App\Repository\MerBeSubRepository; use App\Repository\MerParaSubRepository; +use App\Repository\MerServiceRepository; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use App\Repository\Entity1Repository; @@ -11,18 +14,38 @@ use App\Repository\Entity1Repository; class IndexController extends AbstractController { #[Route('/', name: 'app_index')] - public function index(Entity1Repository $repo, MerParaSubRepository $subRepo): Response + public function index( + Entity1Repository $repo, + MerParaSubRepository $paraSubRepo, + MerBeSubRepository $beSubRepo + ): Response { // repo dummy $sm = $repo->getSchemaManager(); - $sub = $subRepo->findOne(); - dump($sub); - dump($sub->getService()); + foreach ($paraSubRepo->findAll() as $sub) { + dump($sub); + } + + dump('-------------------'); + + foreach ($beSubRepo->findAll() as $sub) { + dump($sub); + } return $this->render('index/index.html.twig', [ - 'controller_name' => 'IndexController', - 'schemaManager' => $sm + 'schemaManager' => $sm, + //'offer_id' => $sub->getService()->ge ]); } + + #[Route('/notification/dm', name: 'notification_dm')] + public function notificationDm(Request $request, MerServiceRepository $repo): Response + { + foreach ($repo->findByOfferId($request->query->get('offer_id')) as $sub) { + dump($sub); + } + + return $this->render('index/notificationDm.html.twig'); + } } diff --git a/src/DataFixtures/MerFixtures.php b/src/DataFixtures/MerFixtures.php index cf2e93a..84bd696 100644 --- a/src/DataFixtures/MerFixtures.php +++ b/src/DataFixtures/MerFixtures.php @@ -3,9 +3,11 @@ namespace App\DataFixtures; use App\Entity\MerBeDM; +use App\Entity\MerBeSub; use App\Entity\MerParaDM; use App\Entity\MerParaDT; use App\Entity\MerParaSub; +use App\Enum\SubStatus; use Doctrine\Bundle\FixturesBundle\Fixture; use Doctrine\Persistence\ObjectManager; @@ -13,42 +15,65 @@ class MerFixtures extends Fixture { public function load(ObjectManager $manager): void { - // service1 - $tmp = new MerParaDM(); - $tmp->setMccMnc(12345)->setOfferId(221)->setProductCode('code1'); - $manager->persist($tmp); + $ser1 = new MerParaDM(); + $ser1->setMccMnc(12345) + ->setOfferId(221) + ->setProductCode('code1'); - // sub - $sub = new MerParaSub(); - $sub->setService($tmp)->setPin(1122)->setSubDate(new \DateTimeImmutable('now')); - $manager->persist($sub); + $ser2 = new MerParaDM(); + $ser2->setMccMnc(12345) + ->setOfferId(223) + ->setProductCode('code2'); - // service 2 - $tmp = new MerParaDM(); - $tmp->setMccMnc(12345)->setOfferId(223)->setProductCode('code2'); - $manager->persist($tmp); + $ser3 = new MerParaDT(); + $ser3->setMccMnc(12345) + ->setServiceId('ser-vi-ce1') + ->setApiKey('api1'); - // sub - $sub = new MerParaSub(); - $sub->setService($tmp)->setPin(2211)->setSubDate(new \DateTimeImmutable('now')); - $manager->persist($sub); + $ser4 = new MerParaDT(); + $ser4->setMccMnc(12341) + ->setServiceId('ser-vi-ce2') + ->setApiKey('api2'); - $sub = new MerParaSub(); - $sub->setService($tmp)->setSubDate(new \DateTimeImmutable('now')); - $manager->persist($sub); + $ser5 = new MerBeDM(); + $ser5->setMccMnc(12341) + ->setOfferId(112) + ->setActivationCode('active1'); - // service 3 - $tmp = new MerParaDT(); - $tmp->setMccMnc(12345)->setServiceId('ser-vi-ce1')->setApiKey('api1'); - $manager->persist($tmp); + $sub1 = new MerParaSub(); + $sub1->setService($ser1) + ->setStatus(SubStatus::ACTIVE) + ->setPin(1122) + ->setSubDate(new \DateTimeImmutable('now')); - $tmp = new MerParaDT(); - $tmp->setMccMnc(12341)->setServiceId('ser-vi-ce2')->setApiKey('api2'); - $manager->persist($tmp); + $sub2 = new MerParaSub(); + $sub2->setService($ser3) + ->setStatus(SubStatus::PREREGISTERED) + ->setPin(2211) + ->setSubDate(new \DateTimeImmutable('now')); - $tmp = new MerBeDM(); - $tmp->setMccMnc(12341)->setOfferId(112)->setActivationCode('active1'); - $manager->persist($tmp); + $sub3 = new MerParaSub(); + $sub3->setService($ser3) + ->setStatus(SubStatus::CANCELLED) + ->setSubDate(new \DateTimeImmutable('yesterday')) + ->setUnsubDate(new \DateTimeImmutable('now')); + + $sub4 = new MerBeSub(); + $sub4->setService($ser5) + ->setStatus(SubStatus::REGISTERED) + ->setCode('CoDe') + ->setSubDate(new \DateTimeImmutable('now')); + + $manager->persist($ser1); + $manager->persist($ser2); + $manager->persist($ser3); + $manager->persist($ser4); + $manager->persist($ser5); + + $manager->persist($sub1); + $manager->persist($sub2); + $manager->persist($sub3); + $manager->persist($sub4); $manager->flush(); } diff --git a/src/Entity/MerBeSub.php b/src/Entity/MerBeSub.php new file mode 100644 index 0000000..18c7a74 --- /dev/null +++ b/src/Entity/MerBeSub.php @@ -0,0 +1,27 @@ +code; + } + + public function setCode(?string $code): self + { + $this->code = $code; + + return $this; + } +} diff --git a/src/Entity/MerParaSub.php b/src/Entity/MerParaSub.php index 95fa91c..cba1bfe 100644 --- a/src/Entity/MerParaSub.php +++ b/src/Entity/MerParaSub.php @@ -8,29 +8,11 @@ use Doctrine\ORM\Mapping as ORM; #[ORM\Entity(repositoryClass: MerParaSubRepository::class)] class MerParaSub { - #[ORM\Id] - #[ORM\GeneratedValue] - #[ORM\Column(type: 'integer')] - private $id; + use MerSubBaseTrait; #[ORM\Column(type: 'integer', nullable: true)] private $pin; - #[ORM\ManyToOne(targetEntity: MerService::class)] - #[ORM\JoinColumn(nullable: false)] - private MerService $service; - - #[ORM\Column(type: 'datetime_immutable')] - private $subDate; - - #[ORM\Column(type: 'datetime_immutable', nullable: true)] - private $unsubDate; - - public function getId(): ?int - { - return $this->id; - } - public function getPin(): ?int { return $this->pin; @@ -42,40 +24,4 @@ class MerParaSub return $this; } - - public function getService(): ?MerService - { - return $this->service; - } - - public function setService(?MerService $service): self - { - $this->service = $service; - - return $this; - } - - public function getSubDate(): ?\DateTimeImmutable - { - return $this->subDate; - } - - public function setSubDate(\DateTimeImmutable $subDate): self - { - $this->subDate = $subDate; - - return $this; - } - - public function getUnsubDate(): ?\DateTimeImmutable - { - return $this->unsubDate; - } - - public function setUnsubDate(?\DateTimeImmutable $unsubDate): self - { - $this->unsubDate = $unsubDate; - - return $this; - } } diff --git a/src/Entity/MerSubBaseTrait.php b/src/Entity/MerSubBaseTrait.php new file mode 100644 index 0000000..84a30c8 --- /dev/null +++ b/src/Entity/MerSubBaseTrait.php @@ -0,0 +1,80 @@ +id; + } + + public function getStatus(): SubStatus + { + return $this->status; + } + + public function setStatus(SubStatus $status): self + { + $this->status = $status; + + return $this; + } + + public function getService(): ?MerService + { + return $this->service; + } + + public function setService(?MerService $service): self + { + $this->service = $service; + + return $this; + } + + public function getSubDate(): ?\DateTimeImmutable + { + return $this->subDate; + } + + public function setSubDate(\DateTimeImmutable $subDate): self + { + $this->subDate = $subDate; + + return $this; + } + + public function getUnsubDate(): ?\DateTimeImmutable + { + return $this->unsubDate; + } + + public function setUnsubDate(?\DateTimeImmutable $unsubDate): self + { + $this->unsubDate = $unsubDate; + + return $this; + } +} diff --git a/src/Enum/SubStatus.php b/src/Enum/SubStatus.php new file mode 100644 index 0000000..1548c6d --- /dev/null +++ b/src/Enum/SubStatus.php @@ -0,0 +1,12 @@ + + * + * @method MerBeSub|null find($id, $lockMode = null, $lockVersion = null) + * @method MerBeSub|null findOneBy(array $criteria, array $orderBy = null) + * @method MerBeSub[] findAll() + * @method MerBeSub[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + */ +class MerBeSubRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, MerBeSub::class); + } + + public function add(MerBeSub $entity, bool $flush = false): void + { + $this->getEntityManager()->persist($entity); + + if ($flush) { + $this->getEntityManager()->flush(); + } + } + + public function remove(MerBeSub $entity, bool $flush = false): void + { + $this->getEntityManager()->remove($entity); + + if ($flush) { + $this->getEntityManager()->flush(); + } + } + +// /** +// * @return MerBeSub[] Returns an array of MerBeSub objects +// */ +// public function findByExampleField($value): array +// { +// return $this->createQueryBuilder('m') +// ->andWhere('m.exampleField = :val') +// ->setParameter('val', $value) +// ->orderBy('m.id', 'ASC') +// ->setMaxResults(10) +// ->getQuery() +// ->getResult() +// ; +// } + + public function findOne(): ?MerBeSub + { + return $this->createQueryBuilder('m') + ->orderBy('m.id', 'ASC') + ->setMaxResults(1) + ->getQuery() + ->getOneOrNullResult() + ; + } +} diff --git a/src/Repository/MerParaSubRepository.php b/src/Repository/MerParaSubRepository.php index 71c0549..59ee9cc 100644 --- a/src/Repository/MerParaSubRepository.php +++ b/src/Repository/MerParaSubRepository.php @@ -67,7 +67,7 @@ class MerParaSubRepository extends ServiceEntityRepository public function findOne(): ?MerParaSub { return $this->createQueryBuilder('m') - ->orderBy('m.id', 'DESC') + ->orderBy('m.id', 'ASC') ->setMaxResults(1) ->getQuery() ->getOneOrNullResult() diff --git a/src/Repository/MerServiceRepository.php b/src/Repository/MerServiceRepository.php index aba062d..2b62ea5 100644 --- a/src/Repository/MerServiceRepository.php +++ b/src/Repository/MerServiceRepository.php @@ -62,4 +62,14 @@ class MerServiceRepository extends ServiceEntityRepository // ->getOneOrNullResult() // ; // } + + public function findByOfferId(int $offerId) + { + return $this->createQueryBuilder('s') + ->andWhere('s.offer_id = :offer_id') + ->setParameter('offer_id', $offerId) + ->getQuery() + ->getResult() + ; + } } diff --git a/templates/index/index.html.twig b/templates/index/index.html.twig index d9c7049..b676769 100644 --- a/templates/index/index.html.twig +++ b/templates/index/index.html.twig @@ -32,4 +32,6 @@ {% endfor %} + +

dm notification

{% endblock %} diff --git a/templates/index/notificationDm.html.twig b/templates/index/notificationDm.html.twig new file mode 100644 index 0000000..e54b2df --- /dev/null +++ b/templates/index/notificationDm.html.twig @@ -0,0 +1,7 @@ +{% extends 'base.html.twig' %} + +{% block title %}notif dm!{% endblock %} + +{% block body %} +

check profiler output

+{% endblock %}