Skip to content

Feature/qr config #15

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

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
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
33 changes: 33 additions & 0 deletions migrations/Version20250218134959.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250218134959 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->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');
}
}
28 changes: 28 additions & 0 deletions src/Controller/Admin/Field/ConfigField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Controller\Admin\Field;

use App\Form\Type\ConfigType;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldInterface;
use EasyCorp\Bundle\EasyAdminBundle\Field\FieldTrait;
use Symfony\Contracts\Translation\TranslatableInterface;

final class ConfigField implements FieldInterface
{
use FieldTrait;

/**
* @param TranslatableInterface|string|false|null $label
*/
public static function new(string $propertyName, $label = null): self
{
return (new self())
->setProperty($propertyName)
->setLabel($label)

->setTemplatePath('fields/config/config.html.twig')

->setFormType(ConfigType::class)
;
}
}
12 changes: 7 additions & 5 deletions src/Controller/Admin/QrCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -64,18 +66,17 @@ 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'))
->setDisabled(),
Field::new('customUrlButton', new TranslatableMessage('Open Resource'))
->setTemplatePath('fields/link/link.html.twig')
->hideOnForm(),
ConfigField::new('config', new TranslatableMessage('Configuration'))
];
}

Expand All @@ -96,6 +97,7 @@ public function configureFields(string $pageName): iterable
TextField::new('author', new TranslatableMessage('Author'))
->setDisabled()
->hideOnForm(),
ConfigField::new('qrConfig', new TranslatableMessage('Configuration'))
];
}

Expand Down
4 changes: 0 additions & 4 deletions src/Controller/QrCodePreviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions src/Entity/Qr.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
{
Expand Down
145 changes: 145 additions & 0 deletions src/Entity/QrConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\Embeddable;

#[Embeddable]
class QrConfig
{
#[ORM\Column(length: 255, nullable: true)]
private ?string $size = null;

#[ORM\Column(length: 255, nullable: true)]
private ?string $margin = null;

#[ORM\Column(length: 255, nullable: true)]
private ?string $codeBackground = null;

#[ORM\Column(length: 255, nullable: true)]
private ?string $codeColor = null;

#[ORM\Column(length: 255, nullable: true)]
private ?string $text = null;

#[ORM\Column(length: 255, nullable: true)]
private ?string $textColor = null;

#[ORM\Column(length: 255, nullable: true)]
private ?string $textMarginTop = null;

#[ORM\Column(length: 255, nullable: true)]
private ?string $textMarginBottom = null;

#[ORM\Column(length: 255, nullable: true)]
private ?string $errorCorrectionLevel = null;

public function getSize(): ?string
{
return $this->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;
}
}
53 changes: 53 additions & 0 deletions src/Form/Type/ConfigType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace App\Form\Type;

use App\Entity\QrConfig;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;

final class ConfigType extends AbstractType

Check failure on line 11 in src/Form/Type/ConfigType.php

View workflow job for this annotation

GitHub Actions / PHP - Code analysis

Class App\Form\Type\ConfigType extends generic class Symfony\Component\Form\AbstractType but does not specify its types: TData
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->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,
]);
}

}
Loading
Loading