Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AdherentFormation] Add category field
Browse files Browse the repository at this point in the history
Remg committed Oct 2, 2024
1 parent 1ab43fe commit 5309a6a
Showing 5 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions features/api/adherent_formations.feature
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ Feature:
{
"title": "New formation",
"description": "New formation description",
"category": "Category 1",
"content_type": "link",
"link": "https://renaissance.code/",
"published": true,
@@ -27,6 +28,7 @@ Feature:
"uuid": "@uuid@",
"title": "New formation",
"description": "@string@",
"category": "Category 1",
"content_type": "link",
"file_path": null,
"link": "https://renaissance.code/",
@@ -67,6 +69,7 @@ Feature:
"uuid": "ebdbafa2-c0b0-40ff-adbd-745f48f48c42",
"title": "Première formation du 77",
"description": "@string@",
"category": null,
"content_type": "file",
"file_path": "@string@.isUrl()",
"link": null,
@@ -84,6 +87,7 @@ Feature:
"uuid": "366c1da2-f833-4172-883a-c10a41588766",
"title": "Deuxième formation du 77",
"description": "@string@",
"category": null,
"content_type": "link",
"file_path": null,
"link": "http://renaissance.code/",
24 changes: 24 additions & 0 deletions migrations/Version20241002132246.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Migrations;

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

final class Version20241002132246 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE adherent_formation ADD category VARCHAR(255) DEFAULT NULL');
}

public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE adherent_formation DROP category');
}
}
11 changes: 11 additions & 0 deletions src/Admin/FormationAdmin.php
Original file line number Diff line number Diff line change
@@ -35,6 +35,10 @@ protected function configureFormFields(FormMapper $form): void
'required' => false,
'help' => 'Optionnelle. Sera affichée aux utilisateurs',
])
->add('category', TextType::class, [
'label' => 'Catégorie',
'required' => false,
])
->end()
->with('Visibilité', ['class' => 'col-md-6'])
->add('published', CheckboxType::class, [
@@ -82,6 +86,10 @@ protected function configureDatagridFilters(DatagridMapper $filter): void
'label' => 'Titre',
'show_filter' => true,
])
->add('category', null, [
'label' => 'Catégorie',
'show_filter' => true,
])
->add('published', null, [
'label' => 'Publiée',
'show_filter' => true,
@@ -95,6 +103,9 @@ protected function configureListFields(ListMapper $list): void
->addIdentifier('title', null, [
'label' => 'Titre',
])
->add('category', null, [
'label' => 'Catégorie',
])
->add('printCount', null, [
'label' => 'Nb de téléchargements',
])
3 changes: 3 additions & 0 deletions src/DataFixtures/ORM/LoadAdherentFormationData.php
Original file line number Diff line number Diff line change
@@ -38,16 +38,19 @@ public function load(ObjectManager $manager)
$administrator = $this->getReference('administrator-renaissance');

$formation = $this->createNationalFormation(self::FORMATION_1_UUID, $administrator, 'Première formation nationale');
$formation->setCategory('Catégorie 1');
$formation->setContentType(FormationContentTypeEnum::FILE);
$this->createFile($formation);
$manager->persist($formation);

$formation = $this->createNationalFormation(self::FORMATION_2_UUID, $administrator, 'Formation sans description', false);
$formation->setCategory('Catégorie 1');
$formation->setContentType(FormationContentTypeEnum::LINK);
$formation->setLink('http://enmarche.code/');
$manager->persist($formation);

$formation = $this->createNationalFormation(self::FORMATION_3_UUID, $administrator, 'Formation non publiée', true, false);
$formation->setCategory('Catégorie 2');
$formation->setContentType(FormationContentTypeEnum::FILE);
$this->createFile($formation);
$manager->persist($formation);
14 changes: 14 additions & 0 deletions src/Entity/AdherentFormation/Formation.php
Original file line number Diff line number Diff line change
@@ -107,6 +107,10 @@ class Formation implements EntityScopeVisibilityWithZoneInterface, EntityAdheren
#[ORM\Column(type: 'text', nullable: true)]
private ?string $description = null;

#[Groups(['formation_read', 'formation_list_read', 'formation_write'])]
#[ORM\Column(nullable: true)]
private ?string $category = null;

#[Assert\Choice(choices: FormationContentTypeEnum::ALL)]
#[Assert\NotBlank]
#[Groups(['formation_read', 'formation_list_read', 'formation_write'])]
@@ -184,6 +188,16 @@ public function setContentType(string $contentType): void
$this->contentType = $contentType;
}

public function getCategory(): ?string
{
return $this->category;
}

public function setCategory(?string $category): void
{
$this->category = $category;
}

public function isFileContent(): bool
{
return FormationContentTypeEnum::FILE === $this->contentType;

0 comments on commit 5309a6a

Please sign in to comment.