Skip to content

Commit

Permalink
feat: add text variations
Browse files Browse the repository at this point in the history
  • Loading branch information
Khodl committed Sep 12, 2024
1 parent bf30eec commit 828c27f
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 2 deletions.
33 changes: 33 additions & 0 deletions migrations/Version20240912162538.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 Version20240912162538 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 resource_collection ADD short_description TEXT DEFAULT NULL');
$this->addSql('ALTER TABLE resource_collection ADD title VARCHAR(255) DEFAULT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE resource_collection DROP short_description');
$this->addSql('ALTER TABLE resource_collection DROP title');
}
}
7 changes: 7 additions & 0 deletions src/DataFixtures/ResourceFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ public function load(ObjectManager $manager): void
$collection->setName($category);
$collection->setDescription("The best $category services");
$collection->setEmoji("🔒");
if(rand(0,1)){
$collection->setTitle("The best $category services");
}

if(rand(0,1)){
$collection->setShortDescription("The short text for best $category services");
}

foreach ($resources as $title => $url) {
$resource = new Resource();
Expand Down
33 changes: 33 additions & 0 deletions src/Entity/Resource/ResourceCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ class ResourceCollection
#[ORM\Column(length: 20)]
private ?string $emoji = null;

#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $shortDescription = null;

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

public function __construct()
{
$this->resources = new ArrayCollection();
Expand Down Expand Up @@ -112,4 +118,31 @@ public function setEmoji(string $emoji): static

return $this;
}

public function getShortDescription(): ?string
{
if($t = $this->shortDescription)
return $t;

return $this->getDescription();
}

public function setShortDescription(?string $shortDescription): static
{
$this->shortDescription = $shortDescription;

return $this;
}

public function getTitle(): ?string
{
return $this->title;
}

public function setTitle(?string $title): static
{
$this->title = $title;

return $this;
}
}
2 changes: 1 addition & 1 deletion templates/resource/collection.html.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'base.html.twig' %}

{% block title %}{{ collection.name }}{% endblock %}
{% block title %}{{ collection.title ?? collection.name }}{% endblock %}

{% block body %}

Expand Down
2 changes: 1 addition & 1 deletion templates/resource/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</a>
</h2>

{{ collection.description|markdown_to_html }}
{{ collection.shortDescription|markdown_to_html }}

</div>
{% endfor %}
Expand Down

0 comments on commit 828c27f

Please sign in to comment.