From 9d46a9c561f8f5f92ba2433b1960870c6e9c54a4 Mon Sep 17 00:00:00 2001 From: Xbird Date: Mon, 31 Oct 2022 14:09:53 +0000 Subject: [PATCH] Add Wanted Page + fixs --- .env | 4 +-- config/packages/security.yaml | 1 + migrations/Version20221031135251.php | 31 +++++++++++++++++++++++ src/Controller/GroupController.php | 3 ++- src/Controller/WantedController.php | 22 +++++++++++++++++ src/Entity/Directory.php | 26 +++++++++++++++++--- src/Form/DirectoryType.php | 1 + src/Repository/DirectoryRepository.php | 6 +++++ templates/wanted/index.html.twig | 34 ++++++++++++++++++++++++++ translations/messages+intl-icu.en.yaml | 1 + translations/messages+intl-icu.fr.yaml | 1 + visionversion.json | 2 +- 12 files changed, 124 insertions(+), 8 deletions(-) create mode 100644 migrations/Version20221031135251.php create mode 100644 src/Controller/WantedController.php create mode 100644 templates/wanted/index.html.twig diff --git a/.env b/.env index d293315..ef0afda 100644 --- a/.env +++ b/.env @@ -19,6 +19,6 @@ MAILER_SENDER=noreply@vision # IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml # # DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db" -# DATABASE_URL="mysql://db_user:db_password@127.0.0.1:3306/db_name?serverVersion=5.7&charset=utf8mb4" -DATABASE_URL="postgresql://symfony:ChangeMe@127.0.0.1:5432/app?serverVersion=13&charset=utf8" +DATABASE_URL="mysql://db_user:db_password@127.0.0.1:3306/db_name?serverVersion=5.7&charset=utf8mb4" +# DATABASE_URL="postgresql://symfony:ChangeMe@127.0.0.1:5432/app?serverVersion=13&charset=utf8" ###< doctrine/doctrine-bundle ### \ No newline at end of file diff --git a/config/packages/security.yaml b/config/packages/security.yaml index dd72fe7..939219f 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -43,6 +43,7 @@ security: - { path: ^/verify/password, roles: PUBLIC_ACCESS } - { path: ^/reset-password, roles: PUBLIC_ACCESS } - { path: ^/share, roles: PUBLIC_ACCESS } + - { path: ^/wanted, roles: PUBLIC_ACCESS } - { path: ^/admin, roles: ROLE_ADMIN } - { path: ^/directory/history, roles: ROLE_ADMIN } - { path: ^/, roles: IS_AUTHENTICATED_REMEMBERED } #IS_AUTHENTICATED_REMEMBERED= user is logged, with form or with cookie diff --git a/migrations/Version20221031135251.php b/migrations/Version20221031135251.php new file mode 100644 index 0000000..18a900f --- /dev/null +++ b/migrations/Version20221031135251.php @@ -0,0 +1,31 @@ +addSql('ALTER TABLE directory ADD wanted_public_display TINYINT(1) DEFAULT \'0\' NOT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE directory DROP wanted_public_display'); + } +} diff --git a/src/Controller/GroupController.php b/src/Controller/GroupController.php index 0ef6987..a4e09c5 100644 --- a/src/Controller/GroupController.php +++ b/src/Controller/GroupController.php @@ -85,7 +85,8 @@ class GroupController extends AbstractController } if ( - $User->getMainRank()->getPower() >= $currentUser->getMainRank()->getPower() + null != $User->getMainRank() + && $User->getMainRank()->getPower() >= $currentUser->getMainRank()->getPower() && !$currentUser->getAdminMode() ) { $this->addFlash('danger', 'alert_error_cant_fire_superior_or_same_rank'); diff --git a/src/Controller/WantedController.php b/src/Controller/WantedController.php new file mode 100644 index 0000000..89ae1d3 --- /dev/null +++ b/src/Controller/WantedController.php @@ -0,0 +1,22 @@ +render('wanted/index.html.twig', [ + 'controller_name' => 'WantedController', + 'wanted' => + $DirectoryRepository->list()->notDead()->wanted()->wantedPublicDisplay()->getResult(), + 'shared' => true + ]); + } +} diff --git a/src/Entity/Directory.php b/src/Entity/Directory.php index 4410629..c923730 100644 --- a/src/Entity/Directory.php +++ b/src/Entity/Directory.php @@ -421,6 +421,12 @@ class Directory */ private $wantedDisplay = true; + /** + * @ORM\Column(type="boolean", options={"default":"0"}) + * @Gedmo\Versioned + */ + private $wantedPublicDisplay = false; + /** * @ORM\OneToMany(targetEntity=Infringement::class, mappedBy="directory", orphanRemoval=true) * @ORM\OrderBy({"createdAt" = "DESC"}) @@ -709,9 +715,9 @@ class Directory } /** - * - * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $backImageFile - */ + * + * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $backImageFile + */ public function setBackImageFile(?File $backImageFile = null): void { $this->backImageFile = $backImageFile; @@ -748,7 +754,7 @@ class Directory return $this->backImageSize; } -/** + /** * * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $leftImageFile */ @@ -1358,6 +1364,18 @@ class Directory return $this; } + public function getWantedPublicDisplay(): ?bool + { + return $this->wantedPublicDisplay; + } + + public function setWantedPublicDisplay(bool $wantedPublicDisplay): self + { + $this->wantedPublicDisplay = $wantedPublicDisplay; + + return $this; + } + /** * @return Collection|Infringement[] */ diff --git a/src/Form/DirectoryType.php b/src/Form/DirectoryType.php index b098dde..7e64dee 100644 --- a/src/Form/DirectoryType.php +++ b/src/Form/DirectoryType.php @@ -68,6 +68,7 @@ class DirectoryType extends AbstractType ->add('wanted', null, ['label' => 'form_label_wanted']) ->add('wantedReason', null, ['label' => 'form_label_wantedReason', 'help' => 'form_help_wantedReason']) ->add('wantedDisplay', null, ['label' => 'form_label_wantedDisplay']) + ->add('wantedPublicDisplay', null, ['label' => 'form_label_wantedPublicDisplay']) ; } diff --git a/src/Repository/DirectoryRepository.php b/src/Repository/DirectoryRepository.php index 278a697..1a3a9ca 100644 --- a/src/Repository/DirectoryRepository.php +++ b/src/Repository/DirectoryRepository.php @@ -83,6 +83,12 @@ class DirectoryRepository extends ServiceEntityRepository return $this; } + public function wantedPublicDisplay() + { + $this->qb->andWhere('d.wantedPublicDisplay = 1'); + return $this; + } + public function wantedNotDisplay() { $this->qb->andWhere('d.wantedDisplay = 0'); diff --git a/templates/wanted/index.html.twig b/templates/wanted/index.html.twig new file mode 100644 index 0000000..e056f7f --- /dev/null +++ b/templates/wanted/index.html.twig @@ -0,0 +1,34 @@ +{% extends 'base.html.twig' %} + +{% block title %}{% trans %}title_wanted{% endtrans %}{% endblock %} + +{% block body %} + {% if wanted %} +
+ {% for i in wanted %} + {% set path_directories_uploads = 'uploads/directories' %} + {% if i.faceImageSize != 0 %}{% set faceImage = path_directories_uploads ~ '/' ~ i.faceImageName + %}{% else %}{% set faceImage = 'img/nophoto.jpg' %}{% endif %} +
+
+
+
+
+
{% trans %}title_wanted{% endtrans %}
+

{{i.fullname}}

+
+
+ {{ i.fullname}} +
+
+
+
+
+ {% endfor %} +
+ {% endif %} +{% endblock %} \ No newline at end of file diff --git a/translations/messages+intl-icu.en.yaml b/translations/messages+intl-icu.en.yaml index 70d918a..236cc68 100644 --- a/translations/messages+intl-icu.en.yaml +++ b/translations/messages+intl-icu.en.yaml @@ -363,6 +363,7 @@ form_label_vehicle_type: Vehicle type form_label_versus: Versus form_label_wanted: This person is wanted form_label_wantedDisplay: Display wanted card on homepage +form_label_wantedPublicDisplay: Show on public wanted page form_label_wantedReason: Reason for searching for this person form_placeholder_email: Email form_placeholder_firstname: First name diff --git a/translations/messages+intl-icu.fr.yaml b/translations/messages+intl-icu.fr.yaml index 28e2cec..3a4d006 100644 --- a/translations/messages+intl-icu.fr.yaml +++ b/translations/messages+intl-icu.fr.yaml @@ -363,6 +363,7 @@ form_label_vehicle_type: Type de véhicule form_label_versus: Contre form_label_wanted: Cette personne est recherchée form_label_wantedDisplay: Afficher la recherche sur l'accueil +form_label_wantedPublicDisplay: Afficher la recherche sur la page publique form_label_wantedReason: Raison de la recherche de cette personne form_placeholder_email: Email form_placeholder_firstname: Prénom diff --git a/visionversion.json b/visionversion.json index d9c2009..42be9b0 100644 --- a/visionversion.json +++ b/visionversion.json @@ -1,3 +1,3 @@ { - "version": "0.2.17" + "version": "0.2.18" }