Skip to content

Commit

Permalink
Ref #326: Add shortLabel field for denomination and use it in tag gen…
Browse files Browse the repository at this point in the history
…eration
  • Loading branch information
Yann-BUTSCHER-EIRL committed Feb 4, 2024
1 parent 911e0a2 commit d7760b6
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/Entity/Denomination.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ class Denomination
*/
private $label;

/**
* @var string|null
*
* @Gedmo\Translatable
* @ORM\Column(name="short_label", type="string", length=255, nullable=true)
*/
private $shortLabel;

/**
* Class constructor
*/
Expand Down Expand Up @@ -72,4 +80,28 @@ public function getLabel()
{
return $this->label;
}

/**
* Set short label
*
* @param string $label The short version of this denomination's label.
*
* @return self
*/
public function setShortLabel(?string $shortLabel): self
{
$this->shortLabel = $shortLabel;

return $this;
}

/**
* Get shortLabel
*
* @return string|null
*/
public function getShortLabel(): ?string
{
return $this->shortLabel;
}
}
40 changes: 40 additions & 0 deletions src/Migrations/Version20240204132311.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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 Version20240204132311 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add short label for denomination';
}

public function up(Schema $schema): void
{
// Add short_label field
$this->addSql('ALTER TABLE denomination ADD short_label VARCHAR(255) DEFAULT NULL');

// Update existing denominations
$this->addSql("UPDATE denomination SET short_label = 'M.' WHERE label = 'Monsieur'");
$this->addSql("UPDATE denomination SET short_label = 'Mme' WHERE label = 'Madame'");
$this->addSql("UPDATE denomination SET short_label = 'Mx' WHERE label = 'Mix'");
$this->addSql("UPDATE denomination SET short_label = 'Dr' WHERE label = 'Docteur'");
$this->addSql("UPDATE denomination SET short_label = 'Me' WHERE label = 'Maître'");
$this->addSql("UPDATE denomination SET short_label = 'Sté' WHERE label = 'Société'");
$this->addSql("UPDATE denomination SET short_label = 'Assoc.' WHERE label = 'Association'");
}

public function down(Schema $schema): void
{
// Remove short_label field
$this->addSql('ALTER TABLE denomination DROP short_label');
}
}
2 changes: 1 addition & 1 deletion templates/PDF/Tag/_tag.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{% endif %}
<td class="tag">
<span class="font-weight-bold">
{{ person.denomination ? person.denomination.label : "" }}
{{ person.denomination ? (person.denomination.shortLabel ?? person.denomination.label) : "" }}
{{ person.lastname | upper }}
{{ person.firstname }}
</span>
Expand Down

0 comments on commit d7760b6

Please sign in to comment.