diff --git a/migrations/Version20250218134959.php b/migrations/Version20250218134959.php
new file mode 100644
index 0000000..dcf2f4a
--- /dev/null
+++ b/migrations/Version20250218134959.php
@@ -0,0 +1,33 @@
+addSql('ALTER TABLE qr ADD qr_config_size VARCHAR(255) DEFAULT NULL, ADD qr_config_margin VARCHAR(255) DEFAULT NULL, ADD qr_config_code_background VARCHAR(255) DEFAULT NULL, ADD qr_config_code_color VARCHAR(255) DEFAULT NULL, ADD qr_config_text VARCHAR(255) DEFAULT NULL, ADD qr_config_text_color VARCHAR(255) DEFAULT NULL, ADD qr_config_text_margin_top VARCHAR(255) DEFAULT NULL, ADD qr_config_text_margin_bottom VARCHAR(255) DEFAULT NULL, ADD qr_config_error_correction_level VARCHAR(255) DEFAULT NULL, CHANGE created_at created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', CHANGE updated_at updated_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\'');
+ $this->addSql('ALTER TABLE url CHANGE qr_id qr_id INT DEFAULT NULL');
+ }
+
+ public function down(Schema $schema): void
+ {
+ // this down() migration is auto-generated, please modify it to your needs
+ $this->addSql('ALTER TABLE url CHANGE qr_id qr_id INT NOT NULL');
+ $this->addSql('ALTER TABLE qr DROP qr_config_size, DROP qr_config_margin, DROP qr_config_code_background, DROP qr_config_code_color, DROP qr_config_text, DROP qr_config_text_color, DROP qr_config_text_margin_top, DROP qr_config_text_margin_bottom, DROP qr_config_error_correction_level, CHANGE created_at created_at DATETIME NOT NULL, CHANGE updated_at updated_at DATETIME NOT NULL');
+ }
+}
diff --git a/src/Controller/Admin/Field/ConfigField.php b/src/Controller/Admin/Field/ConfigField.php
new file mode 100644
index 0000000..c6f2694
--- /dev/null
+++ b/src/Controller/Admin/Field/ConfigField.php
@@ -0,0 +1,28 @@
+setProperty($propertyName)
+ ->setLabel($label)
+
+ ->setTemplatePath('fields/config/config.html.twig')
+
+ ->setFormType(ConfigType::class)
+ ;
+ }
+}
\ No newline at end of file
diff --git a/src/Controller/Admin/QrCrudController.php b/src/Controller/Admin/QrCrudController.php
index daefb98..08247a6 100644
--- a/src/Controller/Admin/QrCrudController.php
+++ b/src/Controller/Admin/QrCrudController.php
@@ -2,6 +2,7 @@
namespace App\Controller\Admin;
+use App\Controller\Admin\Field\ConfigField;
use App\Entity\Qr;
use App\Form\Type\UrlsType;
use App\Helper\DownloadHelper;
@@ -13,6 +14,7 @@
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Controller\CrudControllerInterface;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Dto\BatchActionDto;
+use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
use EasyCorp\Bundle\EasyAdminBundle\Field\CollectionField;
use EasyCorp\Bundle\EasyAdminBundle\Field\Field;
@@ -64,11 +66,9 @@ public function configureFields(string $pageName): iterable
return [
TextField::new('title', new TranslatableMessage('Title')),
TextEditorField::new('description', new TranslatableMessage('Description')),
- CollectionField::new('urls', new TranslatableMessage('URLs'))
- ->setFormTypeOption('entry_type', UrlsType::class)
- ->allowAdd()
- ->allowDelete()
- ->renderExpanded(),
+ AssociationField::new('urls')
+ ->setFormTypeOptions(['by_reference' => false])
+ ->setTemplatePath('fields/url/urls.html.twig'),
ChoiceField::new('mode', new TranslatableMessage('Mode'))
->renderAsNativeWidget(),
TextField::new('author', new TranslatableMessage('Author'))
@@ -76,6 +76,7 @@ public function configureFields(string $pageName): iterable
Field::new('customUrlButton', new TranslatableMessage('Open Resource'))
->setTemplatePath('fields/link/link.html.twig')
->hideOnForm(),
+ ConfigField::new('config', new TranslatableMessage('Configuration'))
];
}
@@ -96,6 +97,7 @@ public function configureFields(string $pageName): iterable
TextField::new('author', new TranslatableMessage('Author'))
->setDisabled()
->hideOnForm(),
+ ConfigField::new('qrConfig', new TranslatableMessage('Configuration'))
];
}
diff --git a/src/Controller/QrCodePreviewController.php b/src/Controller/QrCodePreviewController.php
index 40ac8c2..b6579e1 100644
--- a/src/Controller/QrCodePreviewController.php
+++ b/src/Controller/QrCodePreviewController.php
@@ -45,9 +45,6 @@ public function generateQrCode(Request $request): JsonResponse
$logo = null;
}
- // Build the data you want encoded in the QR code
- $qrString = 'https://www.google.dk';
-
// Get QR code settings or use defaults
$size = (int) min(400, $downloadSettings['size'] ?? 400);
$margin = (int) ($downloadSettings['margin'] ?? 0);
@@ -69,7 +66,6 @@ public function generateQrCode(Request $request): JsonResponse
// Generate the QR Code using Endroid QR Code Builder
$builder = new Builder();
$result = $builder->build(
- data: $qrString,
encoding: new Encoding('UTF-8'),
errorCorrectionLevel: $errorCorrectionLevel,
size: $size,
diff --git a/src/Entity/Qr.php b/src/Entity/Qr.php
index a38aa3b..0872c1a 100644
--- a/src/Entity/Qr.php
+++ b/src/Entity/Qr.php
@@ -11,6 +11,7 @@
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
+use Doctrine\ORM\Mapping\Embedded;
use Symfony\Component\Uid\Uuid;
use Symfony\Component\Uid\UuidV7;
use Symfony\Component\Validator\Constraints as Assert;
@@ -59,6 +60,9 @@ class Qr
#[ORM\Column(type: 'datetime_immutable')]
private \DateTimeImmutable $updatedAt;
+ #[Embedded(class: QrConfig::class)]
+ private QrConfig $qrConfig;
+
public function __construct()
{
$this->urls = new ArrayCollection();
@@ -198,6 +202,16 @@ public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
return $this;
}
+ public function setQrConfig(QrConfig $qrConfig): void
+ {
+ $this->qrConfig = $qrConfig;
+ }
+
+ public function getQrConfig(): QrConfig
+ {
+ return $this->qrConfig;
+ }
+
#[ORM\PrePersist]
public function onPrePersist(): void
{
diff --git a/src/Entity/QrConfig.php b/src/Entity/QrConfig.php
new file mode 100644
index 0000000..6e2cb13
--- /dev/null
+++ b/src/Entity/QrConfig.php
@@ -0,0 +1,145 @@
+size;
+ }
+
+ public function setSize(?string $size): static
+ {
+ $this->size = $size;
+
+ return $this;
+ }
+
+ public function getMargin(): ?string
+ {
+ return $this->margin;
+ }
+
+ public function setMargin(?string $margin): static
+ {
+ $this->margin = $margin;
+
+ return $this;
+ }
+
+ public function getCodeBackground(): ?string
+ {
+ return $this->codeBackground;
+ }
+
+ public function setCodeBackground(?string $codeBackground): static
+ {
+ $this->codeBackground = $codeBackground;
+
+ return $this;
+ }
+
+ public function getCodeColor(): ?string
+ {
+ return $this->codeColor;
+ }
+
+ public function setCodeColor(?string $codeColor): static
+ {
+ $this->codeColor = $codeColor;
+
+ return $this;
+ }
+
+ public function getText(): ?string
+ {
+ return $this->text;
+ }
+
+ public function setText(?string $text): static
+ {
+ $this->text = $text;
+
+ return $this;
+ }
+
+ public function getTextColor(): ?string
+ {
+ return $this->textColor;
+ }
+
+ public function setTextColor(?string $textColor): static
+ {
+ $this->textColor = $textColor;
+
+ return $this;
+ }
+
+ public function getTextMarginTop(): ?string
+ {
+ return $this->textMarginTop;
+ }
+
+ public function setTextMarginTop(?string $textMarginTop): static
+ {
+ $this->textMarginTop = $textMarginTop;
+
+ return $this;
+ }
+
+ public function getTextMarginBottom(): ?string
+ {
+ return $this->textMarginBottom;
+ }
+
+ public function setTextMarginBottom(?string $textMarginBottom): static
+ {
+ $this->textMarginBottom = $textMarginBottom;
+
+ return $this;
+ }
+
+ public function getErrorCorrectionLevel(): ?string
+ {
+ return $this->errorCorrectionLevel;
+ }
+
+ public function setErrorCorrectionLevel(?string $errorCorrectionLevel): static
+ {
+ $this->errorCorrectionLevel = $errorCorrectionLevel;
+
+ return $this;
+ }
+}
diff --git a/src/Form/Type/ConfigType.php b/src/Form/Type/ConfigType.php
new file mode 100644
index 0000000..fb30ab5
--- /dev/null
+++ b/src/Form/Type/ConfigType.php
@@ -0,0 +1,53 @@
+add('size', TextType::class, [
+ 'required' => false,
+ ])
+ ->add('margin', TextType::class, [
+ 'required' => false,
+ ])
+ ->add('code_background', TextType::class, [
+ 'required' => false,
+ ])
+ ->add('code_color', TextType::class, [
+ 'required' => false,
+ ])
+ ->add('text', TextType::class, [
+ 'required' => false,
+ ])
+ ->add('text_color', TextType::class, [
+ 'required' => false,
+ ])
+ ->add('text_margin_top', TextType::class, [
+ 'required' => false,
+ ])
+ ->add('text_margin_bottom', TextType::class, [
+ 'required' => false,
+ ])
+ ->add('error_correction_level', TextType::class, [
+ 'required' => false,
+ ])
+ ;
+ }
+
+ public function configureOptions(OptionsResolver $resolver): void
+ {
+ $resolver->setDefaults([
+ 'data_class' => QrConfig::class,
+ ]);
+ }
+
+}
diff --git a/src/Repository/QrConfigRepository.php b/src/Repository/QrConfigRepository.php
new file mode 100644
index 0000000..c2163ee
--- /dev/null
+++ b/src/Repository/QrConfigRepository.php
@@ -0,0 +1,43 @@
+
+ */
+class QrConfigRepository extends ServiceEntityRepository
+{
+ public function __construct(ManagerRegistry $registry)
+ {
+ parent::__construct($registry, QrConfig::class);
+ }
+
+ // /**
+ // * @return QrConfig[] Returns an array of QrConfig objects
+ // */
+ // public function findByExampleField($value): array
+ // {
+ // return $this->createQueryBuilder('q')
+ // ->andWhere('q.exampleField = :val')
+ // ->setParameter('val', $value)
+ // ->orderBy('q.id', 'ASC')
+ // ->setMaxResults(10)
+ // ->getQuery()
+ // ->getResult()
+ // ;
+ // }
+
+ // public function findOneBySomeField($value): ?QrConfig
+ // {
+ // return $this->createQueryBuilder('q')
+ // ->andWhere('q.exampleField = :val')
+ // ->setParameter('val', $value)
+ // ->getQuery()
+ // ->getOneOrNullResult()
+ // ;
+ // }
+}
diff --git a/templates/fields/config/config.html.twig b/templates/fields/config/config.html.twig
new file mode 100644
index 0000000..72943a1
--- /dev/null
+++ b/templates/fields/config/config.html.twig
@@ -0,0 +1 @@
+aaa
diff --git a/templates/fields/link/link.html.twig b/templates/fields/link/link.html.twig
index e0c594f..c115782 100644
--- a/templates/fields/link/link.html.twig
+++ b/templates/fields/link/link.html.twig
@@ -1,9 +1,9 @@
-{% set generate_qr_url = app_base_generate_path ~ app_base_redirect_path ~ entity.instance.uuid %}
+{% set generate_qr_url = app_base_redirect_path ~ entity.instance.uuid %}
-
+
View
-
+