Selaa lähdekoodia

individual form backoffice

v1
Charly 3 vuotta sitten
vanhempi
commit
b7b3051ee0
13 muutettua tiedostoa jossa 447 lisäystä ja 37 poistoa
  1. +32
    -0
      migrations/Version20210826134725.php
  2. +31
    -0
      migrations/Version20210826144820.php
  3. +31
    -0
      migrations/Version20210826145431.php
  4. +31
    -0
      migrations/Version20210826151431.php
  5. +24
    -11
      src/Controller/Admin/DashboardController.php
  6. +68
    -16
      src/Controller/Admin/IndividualDataCrudController.php
  7. +26
    -0
      src/Controller/Admin/SubthematicCrudController.php
  8. +1
    -2
      src/Controller/Admin/ThematicCrudController.php
  9. +28
    -8
      src/Entity/IndividualData.php
  10. +64
    -0
      src/Entity/Subthematic.php
  11. +43
    -0
      src/Entity/Thematic.php
  12. +50
    -0
      src/Repository/SubthematicRepository.php
  13. +18
    -0
      translations/admin.fr.yaml

+ 32
- 0
migrations/Version20210826134725.php Näytä tiedosto

@@ -0,0 +1,32 @@
<?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 Version20210826134725 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('CREATE TABLE subthematic (id INT AUTO_INCREMENT NOT NULL, thematic_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, INDEX IDX_778C62FB2395FCED (thematic_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE subthematic ADD CONSTRAINT FK_778C62FB2395FCED FOREIGN KEY (thematic_id) REFERENCES thematic (id)');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP TABLE subthematic');
}
}

+ 31
- 0
migrations/Version20210826144820.php Näytä tiedosto

@@ -0,0 +1,31 @@
<?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 Version20210826144820 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 individual_data DROP email, DROP intro_question, DROP intro_answer');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE individual_data ADD email VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, ADD intro_question VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, ADD intro_answer VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_unicode_ci`');
}
}

+ 31
- 0
migrations/Version20210826145431.php Näytä tiedosto

@@ -0,0 +1,31 @@
<?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 Version20210826145431 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 individual_data ADD email VARCHAR(255) NOT NULL, ADD intro_question VARCHAR(255) NOT NULL, ADD intro_answer 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 individual_data DROP email, DROP intro_question, DROP intro_answer');
}
}

+ 31
- 0
migrations/Version20210826151431.php Näytä tiedosto

@@ -0,0 +1,31 @@
<?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 Version20210826151431 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 individual_data CHANGE firstname firstname VARCHAR(255) DEFAULT NULL, CHANGE lastname lastname VARCHAR(255) DEFAULT NULL, CHANGE email email VARCHAR(255) DEFAULT NULL, CHANGE intro_question intro_question 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 individual_data CHANGE firstname firstname VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE lastname lastname VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE email email VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, CHANGE intro_question intro_question VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`');
}
}

+ 24
- 11
src/Controller/Admin/DashboardController.php Näytä tiedosto

@@ -10,6 +10,7 @@ use App\Entity\ProjectBoost;
use App\Entity\ProjectInspiring;
use App\Entity\Revolt;
use App\Entity\Site\Page;
use App\Entity\Subthematic;
use App\Entity\Territory;
use App\Entity\Thematic;
use App\Entity\User\User;
@@ -53,7 +54,8 @@ class DashboardController extends SovDashboardController

$animators = $repoUser->findByRole(self::ROLE_ANIMATOR);

return $this->render('/adminlte/dashboard.html.twig',
return $this->render(
'/adminlte/dashboard.html.twig',
[
'nbFormUnvalid' => count($formUnvalid),
'nbFormValid' => count($formValid),
@@ -62,7 +64,8 @@ class DashboardController extends SovDashboardController
'nbProjectBoost' => count($projectBoost),
'nbProjectsInsp' => count($projectsInsp),
'nbAnimator' => count($animators)
]);
]
);
}

public function configureAssets(): Assets
@@ -79,7 +82,7 @@ class DashboardController extends SovDashboardController
$urlNewCollectif = $this->adminUrlGenerator
->setController(CollectifDataCrudController::class)
->setAction(Action::NEW)
->set('menuIndex', 3)
->set('menuIndex', 4)
->set('submenuIndex', 0)
->generateUrl();

@@ -87,7 +90,7 @@ class DashboardController extends SovDashboardController
->setController(CollectifDataCrudController::class)
->setAction(Action::INDEX)
->set('status', 1)
->set('menuIndex', 3)
->set('menuIndex', 4)
->set('submenuIndex', 2)
->generateUrl();

@@ -95,16 +98,23 @@ class DashboardController extends SovDashboardController
->setController(CollectifDataCrudController::class)
->setAction(Action::INDEX)
->set('status', 0)
->set('menuIndex', 3)
->set('menuIndex', 4)
->set('submenuIndex', 1)
->generateUrl();

$urlNewIndividuel = $this->adminUrlGenerator
->setController(IndividualDataCrudController::class)
->setAction(Action::NEW)
->set('menuIndex', 3)
->set('submenuIndex', 0)
->generateUrl();

$urlOnlineIndividuel = $this->adminUrlGenerator
->setController(IndividualDataCrudController::class)
->setAction(Action::INDEX)
->set('status', 1)
->set('menuIndex', 3)
->set('submenuIndex', 1)
->set('submenuIndex', 2)
->generateUrl();

$urlOfflineIndividuel = $this->adminUrlGenerator
@@ -112,7 +122,7 @@ class DashboardController extends SovDashboardController
->setAction(Action::INDEX)
->set('status', 0)
->set('menuIndex', 3)
->set('submenuIndex', 0)
->set('submenuIndex', 1)
->generateUrl();

$menuItems = [
@@ -126,14 +136,15 @@ class DashboardController extends SovDashboardController
),
MenuItem::linkToCrud('user', 'fas fa-users', User::class)
->setPermission(self::ROLE_ADMIN),
/*MenuItem::subMenu('data_individual', 'user')
MenuItem::subMenu('data_individual', 'fas fa-database')
->setPermission(self::ROLE_ADMIN)
->setSubItems(
[
MenuItem::linkToUrl('data_individual_waiting', '', $urlOfflineIndividuel),
MenuItem::linkToUrl('data_individual_validate', '', $urlOnlineIndividuel),
MenuItem::linkToUrl('data_individual_new', 'fas fa-plus', $urlNewIndividuel),
MenuItem::linkToUrl('data_individual_waiting', 'fas fa-hourglass-half', $urlOfflineIndividuel),
MenuItem::linkToUrl('data_individual_validate', 'fas fa-check', $urlOnlineIndividuel),
]
),*/
),
MenuItem::subMenu('data_collectif', 'fas fa-database')
->setPermission(self::ROLE_ADMIN)
->setSubItems(
@@ -145,6 +156,8 @@ class DashboardController extends SovDashboardController
),
MenuItem::linkToCrud('thematic', 'fas fa-book', Thematic::class)
->setPermission(self::ROLE_ADMIN),
MenuItem::linkToCrud('subthematic', 'fas fa-book', Subthematic::class)
->setPermission(self::ROLE_ADMIN),
MenuItem::linkToCrud('territory', 'far fa-copy', Territory::class)
->setPermission(self::ROLE_SUPER_ADMIN),
MenuItem::linkToCrud('configuration', 'far fa-copy', Configuration::class)

+ 68
- 16
src/Controller/Admin/IndividualDataCrudController.php Näytä tiedosto

@@ -4,6 +4,10 @@ namespace App\Controller\Admin;

use App\Entity\Configuration;
use App\Entity\IndividualData;
use App\Type\DreamType;
use App\Type\ProjectBoostType;
use App\Type\ProjectInspiringType;
use App\Type\RevoltType;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder;
use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
@@ -11,9 +15,13 @@ use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\HiddenField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
use Lc\SovBundle\Controller\AbstractAdminController as AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\SovBundle\Field\CollectionField;
use Lc\SovBundle\Field\StatusField;

class IndividualDataCrudController extends AbstractCrudController
@@ -25,27 +33,71 @@ class IndividualDataCrudController extends AbstractCrudController

public function configureFields(string $pageName): iterable
{
return [
TextField::new('firstname'),
TextField::new('lastname'),
EmailField::new('email'),
TextField::new('introAnswer'),
StatusField::new('status')->setRequired(false)
];
}
// TextField::new('firstname'),
// TextField::new('lastname'),
// EmailField::new('email'),
// TextField::new('introAnswer'),
$fields = array();

public function persistEntity(EntityManagerInterface $entityManager, $entityInstance): void
{
$configurationRepository = $this->getDoctrine()->getRepository(Configuration::class);
$fields[] = AssociationField::new('territory')
->setTemplatePath('crud/field/association.html.twig');
$fields[] = TextField::new('nbDream')
->onlyOnIndex();
$fields[] = TextField::new('nbRevolt')
->onlyOnIndex();
$fields[] = TextField::new('nbProjectBoost')
->onlyOnIndex();
$fields[] = TextField::new('nbProjectInspiring')
->onlyOnIndex();
$fields[] = CollectionField::new('revolt')
->setFormTypeOption('entry_type', RevoltType::class)
->setFormTypeOption('by_reference', false)
->setRequired(false)
->hideOnIndex();
$fields[] = CollectionField::new('dream')
->setFormTypeOption('entry_type', DreamType::class)
->setFormTypeOption('by_reference', false)
->setRequired(false)
->hideOnIndex();
$fields[] = CollectionField::new('projectBoost')
->setFormTypeOption('entry_type', ProjectBoostType::class)
->setFormTypeOption('by_reference', false)
->setRequired(false)
->hideOnIndex();
$fields[] = CollectionField::new('projectinspiring')
->setFormTypeOption('entry_type', ProjectInspiringType::class)
->setFormTypeOption('by_reference', false)
->setRequired(false)
->hideOnIndex();
$hasAccess = $this->isGranted('ROLE_ADMIN');
if ($hasAccess) {
$fields[] = StatusField::new('status')
->setFormTypeOption('data', 0)
->setFormTypeOption('choices', ['Validé' => 1, 'En attente' => 0])
->setCustomOption('toggle_label', 'Valider')
->hideOnIndex();
} else {
$fields[] = HiddenField::new('status')
->setFormTypeOption('data', 0)
->hideOnIndex();
}

$configuration = $configurationRepository->findOneByDevAlias('intro_question');
$entityInstance->setIntroQuestion($configuration->getValue());
$entityManager->persist($entityInstance);
$entityManager->flush();

parent::persistEntity($entityManager, $entityInstance); // TODO: Change the autogenerated stub
return $fields;
}

// public function persistEntity(EntityManagerInterface $entityManager, $entityInstance): void
// {
// $configurationRepository = $this->getDoctrine()->getRepository(Configuration::class);
//
// $configuration = $configurationRepository->findOneByDevAlias('intro_question');
// $entityInstance->setIntroQuestion($configuration->getValue());
// $entityManager->persist($entityInstance);
// $entityManager->flush();
//
// parent::persistEntity($entityManager, $entityInstance);
// }

public function createIndexQueryBuilder(
SearchDto $searchDto,
EntityDto $entityDto,

+ 26
- 0
src/Controller/Admin/SubthematicCrudController.php Näytä tiedosto

@@ -0,0 +1,26 @@
<?php

namespace App\Controller\Admin;

use App\Entity\Subthematic;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\SovBundle\Controller\AbstractAdminController as AbstractCrudController;

class SubthematicCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return Subthematic::class;
}

public function configureFields(string $pageName): iterable
{
return [
TextField::new('name'),
AssociationField::new('thematic')
->setTemplatePath('crud/field/association.html.twig')
];
}

}

+ 1
- 2
src/Controller/Admin/ThematicCrudController.php Näytä tiedosto

@@ -3,7 +3,6 @@
namespace App\Controller\Admin;

use App\Entity\Thematic;
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\SovBundle\Controller\AbstractAdminController as AbstractCrudController;

@@ -17,7 +16,7 @@ class ThematicCrudController extends AbstractCrudController
public function configureFields(string $pageName): iterable
{
return [
TextField::new('name'),
TextField::new('name')
];
}


+ 28
- 8
src/Entity/IndividualData.php Näytä tiedosto

@@ -25,22 +25,22 @@ class IndividualData implements StatusInterface, EntityInterface
private $id;

/**
* @ORM\Column(type="string", length=255)
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $firstname;

/**
* @ORM\Column(type="string", length=255)
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $lastname;

/**
* @ORM\Column(type="string", length=255)
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $email;

/**
* @ORM\Column(type="string", length=255)
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $introQuestion;

@@ -50,22 +50,22 @@ class IndividualData implements StatusInterface, EntityInterface
private $introAnswer;

/**
* @ORM\OneToMany(targetEntity=Revolt::class, mappedBy="individualData")
* @ORM\OneToMany(targetEntity=Revolt::class, mappedBy="individualData", cascade={"persist", "remove"})
*/
private $revolt;

/**
* @ORM\OneToMany(targetEntity=Dream::class, mappedBy="individualData")
* @ORM\OneToMany(targetEntity=Dream::class, mappedBy="individualData", cascade={"persist", "remove"})
*/
private $dream;

/**
* @ORM\OneToMany(targetEntity=ProjectBoost::class, mappedBy="individualData")
* @ORM\OneToMany(targetEntity=ProjectBoost::class, mappedBy="individualData", cascade={"persist", "remove"})
*/
private $projectBoost;

/**
* @ORM\OneToMany(targetEntity=ProjectInspiring::class, mappedBy="individualData")
* @ORM\OneToMany(targetEntity=ProjectInspiring::class, mappedBy="individualData", cascade={"persist", "remove"})
*/
private $projectInspiring;

@@ -87,6 +87,26 @@ class IndividualData implements StatusInterface, EntityInterface
return $this->firstname . " " . $this->lastname;
}

public function getNbDream(): string
{
return count($this->getDream());
}

public function getNbRevolt(): string
{
return count($this->getRevolt());
}

public function getNbProjectBoost(): string
{
return count($this->getProjectBoost());
}

public function getNbProjectInspiring(): string
{
return count($this->getProjectInspiring());
}

public function getId(): ?int
{
return $this->id;

+ 64
- 0
src/Entity/Subthematic.php Näytä tiedosto

@@ -0,0 +1,64 @@
<?php

namespace App\Entity;

use App\Repository\SubthematicRepository;
use Doctrine\ORM\Mapping as ORM;
use Lc\SovBundle\Doctrine\EntityInterface;

/**
* @ORM\Entity(repositoryClass=SubthematicRepository::class)
*/
class Subthematic implements EntityInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;

/**
* @ORM\Column(type="string", length=255)
*/
private $name;

/**
* @ORM\ManyToOne(targetEntity=Thematic::class, inversedBy="subthematic")
*/
private $thematic;

public function __toString()
{
return $this->name;
}

public function getId(): ?int
{
return $this->id;
}

public function getName(): ?string
{
return $this->name;
}

public function setName(string $name): self
{
$this->name = $name;

return $this;
}

public function getThematic(): ?Thematic
{
return $this->thematic;
}

public function setThematic(?Thematic $thematic): self
{
$this->thematic = $thematic;

return $this;
}
}

+ 43
- 0
src/Entity/Thematic.php Näytä tiedosto

@@ -3,6 +3,8 @@
namespace App\Entity;

use App\Repository\ThematicRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Lc\SovBundle\Doctrine\EntityInterface;

@@ -23,6 +25,17 @@ class Thematic implements EntityInterface
*/
private $name;

/**
* @ORM\OneToMany(targetEntity=Subthematic::class, mappedBy="thematic", cascade={"persist", "remove"})
*/
private $subthematic;


public function __construct()
{
$this->subthematic = new ArrayCollection();
}

public function __toString()
{
return $this->name;
@@ -44,4 +57,34 @@ class Thematic implements EntityInterface

return $this;
}

/**
* @return Collection|Subthematic[]
*/
public function getSubthematic(): Collection
{
return $this->subthematic;
}

public function addSubthematic(Subthematic $subthematic): self
{
if (!$this->subthematic->contains($subthematic)) {
$this->subthematic[] = $subthematic;
$subthematic->setThematic($this);
}

return $this;
}

public function removeSubthematic(Subthematic $subthematic): self
{
if ($this->subthematic->removeElement($subthematic)) {
// set the owning side to null (unless already changed)
if ($subthematic->getThematic() === $this) {
$subthematic->setThematic(null);
}
}

return $this;
}
}

+ 50
- 0
src/Repository/SubthematicRepository.php Näytä tiedosto

@@ -0,0 +1,50 @@
<?php

namespace App\Repository;

use App\Entity\Subthematic;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
* @method Subthematic|null find($id, $lockMode = null, $lockVersion = null)
* @method Subthematic|null findOneBy(array $criteria, array $orderBy = null)
* @method Subthematic[] findAll()
* @method Subthematic[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class SubthematicRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Subthematic::class);
}

// /**
// * @return Subthematic[] Returns an array of Subthematic objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('t')
->andWhere('t.exampleField = :val')
->setParameter('val', $value)
->orderBy('t.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/

/*
public function findOneBySomeField($value): ?Subthematic
{
return $this->createQueryBuilder('t')
->andWhere('t.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
}

+ 18
- 0
translations/admin.fr.yaml Näytä tiedosto

@@ -1,5 +1,6 @@
menu:
data_individual: Formulaire individuel
data_individual_new: Créer
data_individual_validate: Données validées
data_individual_waiting: Données en attente
data_collectif: Formulaire collectif
@@ -9,6 +10,7 @@ menu:
data_collectif_create: Formulaire collectif
territory: Territoires
thematic: Thématiques
subthematic: Sous-thémes
configuration: Configuration
entity:
User:
@@ -35,11 +37,27 @@ entity:
fields:
firstname: Prénom
lastname: Nom
territory: Territoire
revolt: Les révoltes
dream: Les rêves
projectBoost: Les projets boostés
projectinspiring: Les projets inspirants
resume: Résumé
nbDream: Rêve(s)
nbRevolt: Révolte(s)
nbProjectBoost: Projet(s) boosté(s)
nbProjectInspiring: Projet(s) inspirant(s)
Thematic:
label_plurial: Les thémes
label: Thématique
fields:
name: Nom
Subthematic:
label_plurial: Les sous-thémes
label: Sous-théme
fields:
name: Nom
thematic: Théme
Territory:
label_plurial: Les territoires
label: Territoire

Loading…
Peruuta
Tallenna