From be5444a1954bba69e96d24dc076110beabe81b56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Wed, 4 Nov 2020 10:39:32 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20personne=20rattach=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #4 --- .gitignore | 1 + config/packages/sonata_admin.yaml | 36 ++- config/services.yaml | 7 + migrations/Version20201104092500.php | 32 +++ migrations/Version20201104093109.php | 31 +++ src/Admin/PersonneRattacheeAdmin.php | 108 ++++++++ src/Admin/UserAdmin.php | 20 +- src/Entity/PersonneRattachee.php | 241 ++++++++++++++++++ src/Entity/User.php | 96 ++++++- .../PersonneRattacheeRepository.php | 50 ++++ 10 files changed, 613 insertions(+), 9 deletions(-) create mode 100644 migrations/Version20201104092500.php create mode 100644 migrations/Version20201104093109.php create mode 100644 src/Admin/PersonneRattacheeAdmin.php create mode 100644 src/Entity/PersonneRattachee.php create mode 100644 src/Repository/PersonneRattacheeRepository.php diff --git a/.gitignore b/.gitignore index 13039b3..dabd2ba 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ /vendor/ .idea ###< symfony/framework-bundle ### +/public/uploads/ \ No newline at end of file diff --git a/config/packages/sonata_admin.yaml b/config/packages/sonata_admin.yaml index 5521138..687b33b 100644 --- a/config/packages/sonata_admin.yaml +++ b/config/packages/sonata_admin.yaml @@ -3,7 +3,41 @@ sonata_admin: dashboard: blocks: - - { type: sonata.admin.block.admin_list, position: left } + - { type: sonata.admin.block.admin_list, position: right } + - { type: sonata.block.service.text, position: left, settings: { content: "

Bienvenue dans Admin Chouettos !

+ +

Admin Chouettos est l’annuaire des Chouettos.

+

+ Il permet d’autoriser l’accès aux outils de La Chouette Coop (passage en caisse, espace membres, …) à un·e Chouettos. +

+

+ Pour celà : sa fiche doit être créée dans Admin Chouettos, + ET sa fiche doit être activée (en cochant la case « Membre ? »). +

+

+ Admin Chouettos permet également de stocker les données recueillies pour chaque Chouettos ou personne + s'étant déclarée intéréssée par le projet (lors d'une réunion d'acceuil par exemple). +

+ +

Quand et pour quelle opération utiliser Admin Chouettos ?

+ "} } templates: layout: 'standard_layout.html.twig' options: diff --git a/config/services.yaml b/config/services.yaml index fd26e0a..0beb9b9 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -91,3 +91,10 @@ services: - ~ calls: - [ setTranslationDomain, [ GlukoseAdminContactBundle ] ] + + admin.personne_rattachee: + class: App\Admin\PersonneRattacheeAdmin + arguments: [~, App\Entity\PersonneRattachee, ~] + tags: + - { name: sonata.admin, manager_type: orm, group: admin, label: PersonneRattachee } + public: true diff --git a/migrations/Version20201104092500.php b/migrations/Version20201104092500.php new file mode 100644 index 0000000..fbc21bd --- /dev/null +++ b/migrations/Version20201104092500.php @@ -0,0 +1,32 @@ +addSql('CREATE TABLE personne_rattachee (id INT AUTO_INCREMENT NOT NULL, user_id INT DEFAULT NULL, nom VARCHAR(255) NOT NULL, prenom VARCHAR(255) NOT NULL, photo VARCHAR(255) NOT NULL, date_de_naissance DATE DEFAULT NULL, email VARCHAR(255) DEFAULT NULL, telephone VARCHAR(255) DEFAULT NULL, updated DATETIME DEFAULT NULL, INDEX IDX_44AB1594A76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('ALTER TABLE personne_rattachee ADD CONSTRAINT FK_44AB1594A76ED395 FOREIGN KEY (user_id) REFERENCES fos_user (id)'); + } + + public function down(Schema $schema) : void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('DROP TABLE personne_rattachee'); + } +} diff --git a/migrations/Version20201104093109.php b/migrations/Version20201104093109.php new file mode 100644 index 0000000..967fbad --- /dev/null +++ b/migrations/Version20201104093109.php @@ -0,0 +1,31 @@ +addSql('ALTER TABLE personne_rattachee CHANGE photo photo 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 personne_rattachee CHANGE photo photo VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`'); + } +} diff --git a/src/Admin/PersonneRattacheeAdmin.php b/src/Admin/PersonneRattacheeAdmin.php new file mode 100644 index 0000000..4862fed --- /dev/null +++ b/src/Admin/PersonneRattacheeAdmin.php @@ -0,0 +1,108 @@ +manageFileUpload($user); + } + public function prePersist($user) + { + $this->manageFileUpload($user); + } + private function manageFileUpload($user) { + if ($user->getFile()) { + $user->refreshUpdated(); + } + } + + protected function configureFormFields(FormMapper $formMapper): void + { + $user = $this->getSubject(); + + $fileFieldOptions = array('required' => false); + if ($user && ($webPath = $user->getPhoto())) { + $fileFieldOptions['help'] = ''; + } + + $formMapper + ->with('Informations', array( + 'class' => 'col-md-6' + )) + + ->add('nom') + ->add('prenom') + ->add('dateDeNaissance', DatePickerType::class, array( + 'label' => 'Date de naissance', + 'required' => false, + 'format' => 'dd/MM/yyyy', + 'attr' => array( + 'data-date-format' => 'DD/MM/YYYY', + 'placeholder' => '31/01/1970' + ) + )) + ->add('email') + ->add('telephone') + ->end() + ->with('Photo', array( + 'class' => 'col-md-6' + )) + ->add('file', FileType::class, $fileFieldOptions) + ->end() + ; + } + + protected function configureDatagridFilters(DatagridMapper $datagridMapper): void + { + $datagridMapper + ->add('id') + ->add('nom') + ->add('prenom') + ->add('photo') + ->add('dateDeNaissance') + ->add('email') + ->add('telephone') + ; + } + + protected function configureListFields(ListMapper $listMapper): void + { + $listMapper + ->addIdentifier('id') + ->addIdentifier('nom') + ->add('prenom') + ->add('photo') + ->add('dateDeNaissance') + ->add('email') + ->add('telephone'); + } + + + + protected function configureShowFields(ShowMapper $showMapper): void + { + $showMapper + ->add('id') + ->add('nom') + ->add('prenom') + ->add('photo') + ->add('dateDeNaissance') + ->add('email') + ->add('telephone') + ->add('updated') + ; + } +} diff --git a/src/Admin/UserAdmin.php b/src/Admin/UserAdmin.php index a994ed5..8f3796a 100755 --- a/src/Admin/UserAdmin.php +++ b/src/Admin/UserAdmin.php @@ -90,7 +90,7 @@ public function preUpdate($user) $this->syncRelations($user); $em = $this->getModelManager()->getEntityManager($this->getClass()); $this->originalUserData = $em->getUnitOfWork()->getOriginalEntityData($user); - //$this->manageFileUpload($user); + $this->manageFileUpload($user); } public function syncRelations($user) @@ -182,7 +182,7 @@ protected function configureFormFields(FormMapper $formMapper) $fileFieldOptions = array('required' => false); if ($user && ($webPath = $user->getPhoto())) { - $fileFieldOptions['help'] = ''; + $fileFieldOptions['help'] = ''; } $formMapper @@ -277,6 +277,22 @@ protected function configureFormFields(FormMapper $formMapper) ) ) ->end() + ->with('Personne Ratachée', array( + 'class' => 'col-md-12', + 'description' => '' + )) + ->add( + 'personneRattachee', + CollectionType::class, + array( + 'required' => false, + ), + array( + 'edit' => 'inline', + 'inline' => 'table', + ) + ) + ->end() ->with('Paiements des parts sociales', array( 'class' => 'col-md-12', diff --git a/src/Entity/PersonneRattachee.php b/src/Entity/PersonneRattachee.php new file mode 100644 index 0000000..83f6498 --- /dev/null +++ b/src/Entity/PersonneRattachee.php @@ -0,0 +1,241 @@ +nom.' '.$this->prenom; + } + + /** + * Sets file. + * + * @param UploadedFile $file + */ + public function setFile(UploadedFile $file = null) + { + $this->file = $file; + } + + /** + * Get file. + * + * @return UploadedFile + */ + public function getFile() + { + return $this->file; + } + + /** + * Manages the copying of the file to the relevant place on the server + */ + public function upload() + { + // the file property can be empty if the field is not required + if (null === $this->getFile()) { + return; + } + + // we use the original file name here but you should + // sanitize it at least to avoid any security issues + + $filename =uniqid().'-'.$this->getFile()->getClientOriginalName(); + // move takes the target directory and target filename as params + $this->getFile()->move( + PersonneRattachee::SERVER_PATH_TO_IMAGE_FOLDER, + $filename + ); + + // set the path property to the filename where you've saved the file + $this->photo = $filename; + + // clean up the file property as you won't need it anymore + $this->setFile(null); + } + + /** + * @ORM\PrePersist + * @ORM\PreUpdate + */ + public function lifecycleFileUpload() { + $this->upload(); + } + + /** + * Updates the hash value to force the preUpdate and postUpdate events to fire + */ + public function refreshUpdated() { + $this->setUpdated(new \DateTime("now")); + } + + public function getId(): ?int + { + return $this->id; + } + + public function getNom(): ?string + { + return $this->nom; + } + + public function setNom(string $nom): self + { + $this->nom = $nom; + + return $this; + } + + public function getPrenom(): ?string + { + return $this->prenom; + } + + public function setPrenom(string $prenom): self + { + $this->prenom = $prenom; + + return $this; + } + + public function getPhoto(): ?string + { + return $this->photo; + } + + public function setPhoto(string $photo): self + { + $this->photo = $photo; + + return $this; + } + + public function getDateDeNaissance(): ?\DateTimeInterface + { + return $this->dateDeNaissance; + } + + public function setDateDeNaissance(?\DateTimeInterface $dateDeNaissance): self + { + $this->dateDeNaissance = $dateDeNaissance; + + return $this; + } + + public function getEmail(): ?string + { + return $this->email; + } + + public function setEmail(?string $email): self + { + $this->email = $email; + + return $this; + } + + public function getTelephone(): ?string + { + return $this->telephone; + } + + public function setTelephone(?string $telephone): self + { + $this->telephone = $telephone; + + return $this; + } + + public function getUser(): ?User + { + return $this->user; + } + + public function setUser(?User $user): self + { + $this->user = $user; + + return $this; + } + + public function getUpdated(): ?\DateTimeInterface + { + return $this->updated; + } + + public function setUpdated(?\DateTimeInterface $updated): self + { + $this->updated = $updated; + + return $this; + } +} diff --git a/src/Entity/User.php b/src/Entity/User.php index 97f105f..dceec93 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -7,6 +7,7 @@ use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use Gedmo\Mapping\Annotation as Gedmo; +use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\Security\Core\User\UserInterface; /** @@ -16,8 +17,7 @@ */ class User implements UserInterface { - //todo: change directory - const SERVER_PATH_TO_IMAGE_FOLDER = '/var/www/symfony/web/uploads/'; + const SERVER_PATH_TO_IMAGE_FOLDER = __DIR__.'/../../public/uploads/documents/'; /** * @ORM\Id @@ -200,6 +200,11 @@ class User implements UserInterface */ private $file; + /** + * @ORM\OneToMany(targetEntity=PersonneRattachee::class, mappedBy="user",cascade={"persist"}) + */ + private $personneRattachee; + public function __construct() @@ -207,6 +212,7 @@ public function __construct() $this->adresses = new ArrayCollection(); $this->adhesions = new ArrayCollection(); $this->paiements = new ArrayCollection(); + $this->personneRattachee = new ArrayCollection(); } public function getId(): ?int @@ -219,8 +225,22 @@ public function __toString() return $this->nom.' '.$this->prenom; } + + /** - * @return mixed + * Sets file. + * + * @param UploadedFile $file + */ + public function setFile(UploadedFile $file = null) + { + $this->file = $file; + } + + /** + * Get file. + * + * @return UploadedFile */ public function getFile() { @@ -228,11 +248,45 @@ public function getFile() } /** - * @param mixed $file + * Manages the copying of the file to the relevant place on the server */ - public function setFile($file): void + public function upload() { - $this->file = $file; + // the file property can be empty if the field is not required + if (null === $this->getFile()) { + return; + } + + // we use the original file name here but you should + // sanitize it at least to avoid any security issues + + $filename =uniqid().'-'.$this->getFile()->getClientOriginalName(); + // move takes the target directory and target filename as params + $this->getFile()->move( + User::SERVER_PATH_TO_IMAGE_FOLDER, + $filename + ); + + // set the path property to the filename where you've saved the file + $this->photo = $filename; + + // clean up the file property as you won't need it anymore + $this->setFile(null); + } + + /** + * @ORM\PrePersist + * @ORM\PreUpdate + */ + public function lifecycleFileUpload() { + $this->upload(); + } + + /** + * Updates the hash value to force the preUpdate and postUpdate events to fire + */ + public function refreshUpdated() { + $this->setUpdated(new \DateTime("now")); } public function getEmail(): ?string @@ -602,4 +656,34 @@ public function removePaiement(Paiement $paiement): self return $this; } + + /** + * @return Collection|PersonneRattachee[] + */ + public function getPersonneRattachee(): Collection + { + return $this->personneRattachee; + } + + public function addPersonneRattachee(PersonneRattachee $personneRattachee): self + { + if (!$this->personneRattachee->contains($personneRattachee)) { + $this->personneRattachee[] = $personneRattachee; + $personneRattachee->setUser($this); + } + + return $this; + } + + public function removePersonneRattachee(PersonneRattachee $personneRattachee): self + { + if ($this->personneRattachee->removeElement($personneRattachee)) { + // set the owning side to null (unless already changed) + if ($personneRattachee->getUser() === $this) { + $personneRattachee->setUser(null); + } + } + + return $this; + } } diff --git a/src/Repository/PersonneRattacheeRepository.php b/src/Repository/PersonneRattacheeRepository.php new file mode 100644 index 0000000..f900f41 --- /dev/null +++ b/src/Repository/PersonneRattacheeRepository.php @@ -0,0 +1,50 @@ +createQueryBuilder('p') + ->andWhere('p.exampleField = :val') + ->setParameter('val', $value) + ->orderBy('p.id', 'ASC') + ->setMaxResults(10) + ->getQuery() + ->getResult() + ; + } + */ + + /* + public function findOneBySomeField($value): ?PersonneRattachee + { + return $this->createQueryBuilder('p') + ->andWhere('p.exampleField = :val') + ->setParameter('val', $value) + ->getQuery() + ->getOneOrNullResult() + ; + } + */ +}