From 3afb1777abf830b7c5510b1e1677db0b7d0eaf7e Mon Sep 17 00:00:00 2001 From: barillote Date: Thu, 3 Oct 2024 15:53:15 +0200 Subject: [PATCH 01/14] Supprimer .idea/.gitignore --- .idea/.gitignore | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 .idea/.gitignore diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 13566b8..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml From 9573cfea915139958059a1c0c1248e379445e8bf Mon Sep 17 00:00:00 2001 From: barillote Date: Thu, 3 Oct 2024 15:53:19 +0200 Subject: [PATCH 02/14] Supprimer .idea/HegreSphere.iml --- .idea/HegreSphere.iml | 141 ------------------------------------------ 1 file changed, 141 deletions(-) delete mode 100644 .idea/HegreSphere.iml diff --git a/.idea/HegreSphere.iml b/.idea/HegreSphere.iml deleted file mode 100644 index f4221e4..0000000 --- a/.idea/HegreSphere.iml +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From d9ce22834c7eaa87f18860e021598b83b15a6dd2 Mon Sep 17 00:00:00 2001 From: barillote Date: Thu, 3 Oct 2024 15:53:23 +0200 Subject: [PATCH 03/14] Supprimer .idea/modules.xml --- .idea/modules.xml | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 .idea/modules.xml diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 76fffc5..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file From b3321fc76d511f9b9e42c205a7f72efacdf02f28 Mon Sep 17 00:00:00 2001 From: barillote Date: Thu, 3 Oct 2024 15:53:26 +0200 Subject: [PATCH 04/14] Supprimer .idea/php.xml --- .idea/php.xml | 159 -------------------------------------------------- 1 file changed, 159 deletions(-) delete mode 100644 .idea/php.xml diff --git a/.idea/php.xml b/.idea/php.xml deleted file mode 100644 index e89704b..0000000 --- a/.idea/php.xml +++ /dev/null @@ -1,159 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From ceb8edafe602974caa6955dc7f72923c74f27738 Mon Sep 17 00:00:00 2001 From: barillote Date: Thu, 3 Oct 2024 15:53:30 +0200 Subject: [PATCH 05/14] Supprimer .idea/phpunit.xml --- .idea/phpunit.xml | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 .idea/phpunit.xml diff --git a/.idea/phpunit.xml b/.idea/phpunit.xml deleted file mode 100644 index 4f8104c..0000000 --- a/.idea/phpunit.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - \ No newline at end of file From e9c7395d867d405a3394dba21884962fb7feee8a Mon Sep 17 00:00:00 2001 From: barillote Date: Thu, 3 Oct 2024 15:53:34 +0200 Subject: [PATCH 06/14] Supprimer .idea/vcs.xml --- .idea/vcs.xml | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 .idea/vcs.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From a949b7b3901482c704c511b45c0eaa718c1e47ff Mon Sep 17 00:00:00 2001 From: barillote Date: Thu, 17 Oct 2024 17:52:40 +0200 Subject: [PATCH 07/14] =?UTF-8?q?remise=20=C3=A0=20z=20de=20la=20branche?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.gitignore | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .idea/.gitignore diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml From 071fcb41b48caca48f4ba07fcaa9ddd9885866c3 Mon Sep 17 00:00:00 2001 From: allavenavr Date: Thu, 17 Oct 2024 17:56:46 +0200 Subject: [PATCH 08/14] ya des entite tkt --- .gitignore | 5 +- composer.json | 3 +- migrations/Version20241017134137.php | 67 +++++++++ migrations/Version20241017142722.php | 52 +++++++ migrations/Version20241017152949.php | 46 +++++++ src/Entity/Announcement.php | 156 +++++++++++++++++++++ src/Entity/Company.php | 161 ++++++++++++++++++++++ src/Entity/Employee.php | 26 ++++ src/Entity/Intern.php | 143 +++++++++++++++++++ src/Entity/Obtaining.php | 36 +++++ src/Entity/Skill.php | 75 ++++++++++ src/Entity/Status.php | 78 +++++++++++ src/Entity/{User.php => UserApp.php} | 7 +- src/Repository/AnnouncementRepository.php | 43 ++++++ src/Repository/CompanyRepository.php | 43 ++++++ src/Repository/EmployeeRepository.php | 43 ++++++ src/Repository/InternRepository.php | 43 ++++++ src/Repository/ObtainingRepository.php | 43 ++++++ src/Repository/SkillRepository.php | 43 ++++++ src/Repository/StatusRepository.php | 43 ++++++ src/Repository/UserRepository.php | 12 +- 21 files changed, 1155 insertions(+), 13 deletions(-) create mode 100644 migrations/Version20241017134137.php create mode 100644 migrations/Version20241017142722.php create mode 100644 migrations/Version20241017152949.php create mode 100644 src/Entity/Announcement.php create mode 100644 src/Entity/Company.php create mode 100644 src/Entity/Employee.php create mode 100644 src/Entity/Intern.php create mode 100644 src/Entity/Obtaining.php create mode 100644 src/Entity/Skill.php create mode 100644 src/Entity/Status.php rename src/Entity/{User.php => UserApp.php} (92%) create mode 100644 src/Repository/AnnouncementRepository.php create mode 100644 src/Repository/CompanyRepository.php create mode 100644 src/Repository/EmployeeRepository.php create mode 100644 src/Repository/InternRepository.php create mode 100644 src/Repository/ObtainingRepository.php create mode 100644 src/Repository/SkillRepository.php create mode 100644 src/Repository/StatusRepository.php diff --git a/.gitignore b/.gitignore index 2b08932..7540fb1 100644 --- a/.gitignore +++ b/.gitignore @@ -14,13 +14,10 @@ .phpunit.result.cache ###< phpunit/phpunit ### -###> symfony/phpunit-bridge ### -.phpunit.result.cache -/phpunit.xml ###< symfony/phpunit-bridge ### ###> symfony/asset-mapper ### /public/assets/ /assets/vendor/ ###< symfony/asset-mapper ### -./idea \ No newline at end of file +.idea \ No newline at end of file diff --git a/composer.json b/composer.json index 6cda857..62f30c7 100644 --- a/composer.json +++ b/composer.json @@ -43,7 +43,8 @@ "symfony/web-link": "7.1.*", "symfony/yaml": "7.1.*", "twig/extra-bundle": "^2.12|^3.0", - "twig/twig": "^2.12|^3.0" + "twig/twig": "^2.12|^3.0", + "ext-http": "*" }, "config": { "allow-plugins": { diff --git a/migrations/Version20241017134137.php b/migrations/Version20241017134137.php new file mode 100644 index 0000000..0dc3e3c --- /dev/null +++ b/migrations/Version20241017134137.php @@ -0,0 +1,67 @@ +addSql('CREATE SEQUENCE announcement_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE company_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE SEQUENCE userApp_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE TABLE announcement (id INT NOT NULL, title VARCHAR(255) NOT NULL, description VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE TABLE company (id INT NOT NULL, name VARCHAR(255) NOT NULL, address VARCHAR(255) NOT NULL, tel VARCHAR(255) NOT NULL, mail VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE TABLE employee (id INT NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE TABLE intern (id INT NOT NULL, cover_letter TEXT NOT NULL, resume VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE TABLE userApp (id INT NOT NULL, nickname VARCHAR(180) NOT NULL, roles JSON NOT NULL, password VARCHAR(255) NOT NULL, first_name VARCHAR(255) NOT NULL, last_name VARCHAR(255) NOT NULL, tel VARCHAR(255) NOT NULL, address VARCHAR(255) NOT NULL, mail VARCHAR(255) NOT NULL, DISCRIMINATOR VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_IDENTIFIER_NICKNAME ON userApp (nickname)'); + $this->addSql('CREATE TABLE messenger_messages (id BIGSERIAL NOT NULL, body TEXT NOT NULL, headers TEXT NOT NULL, queue_name VARCHAR(190) NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, available_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, delivered_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX IDX_75EA56E0FB7336F0 ON messenger_messages (queue_name)'); + $this->addSql('CREATE INDEX IDX_75EA56E0E3BD61CE ON messenger_messages (available_at)'); + $this->addSql('CREATE INDEX IDX_75EA56E016BA31DB ON messenger_messages (delivered_at)'); + $this->addSql('COMMENT ON COLUMN messenger_messages.created_at IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('COMMENT ON COLUMN messenger_messages.available_at IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('COMMENT ON COLUMN messenger_messages.delivered_at IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('CREATE OR REPLACE FUNCTION notify_messenger_messages() RETURNS TRIGGER AS $$ + BEGIN + PERFORM pg_notify(\'messenger_messages\', NEW.queue_name::text); + RETURN NEW; + END; + $$ LANGUAGE plpgsql;'); + $this->addSql('DROP TRIGGER IF EXISTS notify_trigger ON messenger_messages;'); + $this->addSql('CREATE TRIGGER notify_trigger AFTER INSERT OR UPDATE ON messenger_messages FOR EACH ROW EXECUTE PROCEDURE notify_messenger_messages();'); + $this->addSql('ALTER TABLE employee ADD CONSTRAINT FK_5D9F75A1BF396750 FOREIGN KEY (id) REFERENCES userApp (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE intern ADD CONSTRAINT FK_A5795F36BF396750 FOREIGN KEY (id) REFERENCES userApp (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('CREATE SCHEMA public'); + $this->addSql('DROP SEQUENCE announcement_id_seq CASCADE'); + $this->addSql('DROP SEQUENCE company_id_seq CASCADE'); + $this->addSql('DROP SEQUENCE userApp_id_seq CASCADE'); + $this->addSql('ALTER TABLE employee DROP CONSTRAINT FK_5D9F75A1BF396750'); + $this->addSql('ALTER TABLE intern DROP CONSTRAINT FK_A5795F36BF396750'); + $this->addSql('DROP TABLE announcement'); + $this->addSql('DROP TABLE company'); + $this->addSql('DROP TABLE employee'); + $this->addSql('DROP TABLE intern'); + $this->addSql('DROP TABLE userApp'); + $this->addSql('DROP TABLE messenger_messages'); + } +} diff --git a/migrations/Version20241017142722.php b/migrations/Version20241017142722.php new file mode 100644 index 0000000..73818a8 --- /dev/null +++ b/migrations/Version20241017142722.php @@ -0,0 +1,52 @@ +addSql('CREATE SEQUENCE status_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE TABLE status (id INT NOT NULL, label VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('ALTER TABLE announcement ADD company_id INT NOT NULL'); + $this->addSql('ALTER TABLE announcement ADD status_id INT NOT NULL'); + $this->addSql('ALTER TABLE announcement ADD CONSTRAINT FK_4DB9D91C979B1AD6 FOREIGN KEY (company_id) REFERENCES company (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE announcement ADD CONSTRAINT FK_4DB9D91C6BF700BD FOREIGN KEY (status_id) REFERENCES status (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE INDEX IDX_4DB9D91C979B1AD6 ON announcement (company_id)'); + $this->addSql('CREATE INDEX IDX_4DB9D91C6BF700BD ON announcement (status_id)'); + $this->addSql('ALTER TABLE employee ADD company_id INT NOT NULL'); + $this->addSql('ALTER TABLE employee ADD CONSTRAINT FK_5D9F75A1979B1AD6 FOREIGN KEY (company_id) REFERENCES company (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE INDEX IDX_5D9F75A1979B1AD6 ON employee (company_id)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('CREATE SCHEMA public'); + $this->addSql('ALTER TABLE announcement DROP CONSTRAINT FK_4DB9D91C6BF700BD'); + $this->addSql('DROP SEQUENCE status_id_seq CASCADE'); + $this->addSql('DROP TABLE status'); + $this->addSql('ALTER TABLE announcement DROP CONSTRAINT FK_4DB9D91C979B1AD6'); + $this->addSql('DROP INDEX IDX_4DB9D91C979B1AD6'); + $this->addSql('DROP INDEX IDX_4DB9D91C6BF700BD'); + $this->addSql('ALTER TABLE announcement DROP company_id'); + $this->addSql('ALTER TABLE announcement DROP status_id'); + $this->addSql('ALTER TABLE employee DROP CONSTRAINT FK_5D9F75A1979B1AD6'); + $this->addSql('DROP INDEX IDX_5D9F75A1979B1AD6'); + $this->addSql('ALTER TABLE employee DROP company_id'); + } +} diff --git a/migrations/Version20241017152949.php b/migrations/Version20241017152949.php new file mode 100644 index 0000000..1282d23 --- /dev/null +++ b/migrations/Version20241017152949.php @@ -0,0 +1,46 @@ +addSql('CREATE TABLE favorites (intern_id INT NOT NULL, announcement_id INT NOT NULL, PRIMARY KEY(intern_id, announcement_id))'); + $this->addSql('CREATE INDEX IDX_E46960F5525DD4B4 ON favorites (intern_id)'); + $this->addSql('CREATE INDEX IDX_E46960F5913AEA17 ON favorites (announcement_id)'); + $this->addSql('CREATE TABLE applications (intern_id INT NOT NULL, announcement_id INT NOT NULL, PRIMARY KEY(intern_id, announcement_id))'); + $this->addSql('CREATE INDEX IDX_F7C966F0525DD4B4 ON applications (intern_id)'); + $this->addSql('CREATE INDEX IDX_F7C966F0913AEA17 ON applications (announcement_id)'); + $this->addSql('ALTER TABLE favorites ADD CONSTRAINT FK_E46960F5525DD4B4 FOREIGN KEY (intern_id) REFERENCES intern (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE favorites ADD CONSTRAINT FK_E46960F5913AEA17 FOREIGN KEY (announcement_id) REFERENCES announcement (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE applications ADD CONSTRAINT FK_F7C966F0525DD4B4 FOREIGN KEY (intern_id) REFERENCES intern (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE applications ADD CONSTRAINT FK_F7C966F0913AEA17 FOREIGN KEY (announcement_id) REFERENCES announcement (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('CREATE SCHEMA public'); + $this->addSql('ALTER TABLE favorites DROP CONSTRAINT FK_E46960F5525DD4B4'); + $this->addSql('ALTER TABLE favorites DROP CONSTRAINT FK_E46960F5913AEA17'); + $this->addSql('ALTER TABLE applications DROP CONSTRAINT FK_F7C966F0525DD4B4'); + $this->addSql('ALTER TABLE applications DROP CONSTRAINT FK_F7C966F0913AEA17'); + $this->addSql('DROP TABLE favorites'); + $this->addSql('DROP TABLE applications'); + } +} diff --git a/src/Entity/Announcement.php b/src/Entity/Announcement.php new file mode 100644 index 0000000..41bcf91 --- /dev/null +++ b/src/Entity/Announcement.php @@ -0,0 +1,156 @@ + + */ + #[ORM\ManyToMany(targetEntity: Intern::class, mappedBy: 'favorites')] + private Collection $internsfav; + + /** + * @var Collection + */ + #[ORM\ManyToMany(targetEntity: Intern::class, mappedBy: 'applications')] + private Collection $applicants; + + public function __construct() + { + $this->internsfav = new ArrayCollection(); + $this->applicants = new ArrayCollection(); + } + + public function getId(): ?int + { + return $this->id; + } + + public function getTitle(): ?string + { + return $this->title; + } + + public function setTitle(string $title): static + { + $this->title = $title; + + return $this; + } + + public function getDescription(): ?string + { + return $this->description; + } + + public function setDescription(string $description): static + { + $this->description = $description; + + return $this; + } + + public function getCompany(): ?Company + { + return $this->company; + } + + public function setCompany(?Company $company): static + { + $this->company = $company; + + return $this; + } + + public function getStatus(): ?Status + { + return $this->status; + } + + public function setStatus(?Status $status): static + { + $this->status = $status; + + return $this; + } + + /** + * @return Collection + */ + public function getInternsfav(): Collection + { + return $this->internsfav; + } + + public function addInternfav(Intern $intern): static + { + if (!$this->internsfav->contains($intern)) { + $this->internsfav->add($intern); + $intern->addFavorite($this); + } + + return $this; + } + + public function removeInternfav(Intern $intern): static + { + if ($this->internsfav->removeElement($intern)) { + $intern->removeFavorite($this); + } + + return $this; + } + + /** + * @return Collection + */ + public function getApplicants(): Collection + { + return $this->applicants; + } + + public function addApplicant(Intern $applicant): static + { + if (!$this->applicants->contains($applicant)) { + $this->applicants->add($applicant); + $applicant->addApplication($this); + } + + return $this; + } + + public function removeApplicant(Intern $applicant): static + { + if ($this->applicants->removeElement($applicant)) { + $applicant->removeApplication($this); + } + + return $this; + } +} diff --git a/src/Entity/Company.php b/src/Entity/Company.php new file mode 100644 index 0000000..ae8ccaa --- /dev/null +++ b/src/Entity/Company.php @@ -0,0 +1,161 @@ + + */ + #[ORM\OneToMany(targetEntity: Employee::class, mappedBy: 'company')] + private Collection $employees; + + /** + * @var Collection + */ + #[ORM\OneToMany(targetEntity: Announcement::class, mappedBy: 'company')] + private Collection $announcements; + + public function __construct() + { + $this->employees = new ArrayCollection(); + $this->announcements = new ArrayCollection(); + } + + public function getId(): ?int + { + return $this->id; + } + + public function getName(): ?string + { + return $this->name; + } + + public function setName(string $name): static + { + $this->name = $name; + + return $this; + } + + public function getAddress(): ?string + { + return $this->address; + } + + public function setAddress(string $address): static + { + $this->address = $address; + + return $this; + } + + public function getTel(): ?string + { + return $this->tel; + } + + public function setTel(string $tel): static + { + $this->tel = $tel; + + return $this; + } + + public function getMail(): ?string + { + return $this->mail; + } + + public function setMail(string $mail): static + { + $this->mail = $mail; + + return $this; + } + + /** + * @return Collection + */ + public function getEmployees(): Collection + { + return $this->employees; + } + + public function addEmployee(Employee $employee): static + { + if (!$this->employees->contains($employee)) { + $this->employees->add($employee); + $employee->setCompany($this); + } + + return $this; + } + + public function removeEmployee(Employee $employee): static + { + if ($this->employees->removeElement($employee)) { + // set the owning side to null (unless already changed) + if ($employee->getCompany() === $this) { + $employee->setCompany(null); + } + } + + return $this; + } + + /** + * @return Collection + */ + public function getAnnouncements(): Collection + { + return $this->announcements; + } + + public function addAnnouncement(Announcement $announcement): static + { + if (!$this->announcements->contains($announcement)) { + $this->announcements->add($announcement); + $announcement->setCompany($this); + } + + return $this; + } + + public function removeAnnouncement(Announcement $announcement): static + { + if ($this->announcements->removeElement($announcement)) { + // set the owning side to null (unless already changed) + if ($announcement->getCompany() === $this) { + $announcement->setCompany(null); + } + } + + return $this; + } + +} diff --git a/src/Entity/Employee.php b/src/Entity/Employee.php new file mode 100644 index 0000000..393a529 --- /dev/null +++ b/src/Entity/Employee.php @@ -0,0 +1,26 @@ +company; + } + + public function setCompany(?Company $company): static + { + $this->company = $company; + + return $this; + } +} diff --git a/src/Entity/Intern.php b/src/Entity/Intern.php new file mode 100644 index 0000000..b03dcd8 --- /dev/null +++ b/src/Entity/Intern.php @@ -0,0 +1,143 @@ + + */ + #[ORM\ManyToMany(targetEntity: Announcement::class, inversedBy: 'interns')] + #[ORM\JoinTable(name: 'favorites')] + private Collection $favorites; + + /** + * @var Collection + */ + #[ORM\ManyToMany(targetEntity: Announcement::class, inversedBy: 'applicants')] + #[ORM\JoinTable(name: 'applications')] + private Collection $applications; + + /** + * @var Collection + */ + #[ORM\ManyToMany(targetEntity: Skill::class, inversedBy: 'interns')] + private Collection $skills; + + public function __construct() + { + $this->favorites = new ArrayCollection(); + $this->applications = new ArrayCollection(); + $this->skills = new ArrayCollection(); + } + + public function getCoverLetter(): ?string + { + return $this->coverLetter; + } + + public function setCoverLetter(string $coverLetter): static + { + $this->coverLetter = $coverLetter; + + return $this; + } + + public function getResume(): ?string + { + return $this->resume; + } + + public function setResume(string $resume): static + { + $this->resume = $resume; + + return $this; + } + + /** + * @return Collection + */ + public function getFavorites(): Collection + { + return $this->favorites; + } + + public function addFavorite(Announcement $favorite): static + { + if (!$this->favorites->contains($favorite)) { + $this->favorites->add($favorite); + } + + return $this; + } + + public function removeFavorite(Announcement $favorite): static + { + $this->favorites->removeElement($favorite); + + return $this; + } + + /** + * @return Collection + */ + public function getApplications(): Collection + { + return $this->applications; + } + + public function addApplication(Announcement $application): static + { + if (!$this->applications->contains($application)) { + $this->applications->add($application); + } + + return $this; + } + + public function removeApplication(Announcement $application): static + { + $this->applications->removeElement($application); + + return $this; + } + + /** + * @return Collection + */ + public function getSkills(): Collection + { + return $this->skills; + } + + public function addSkill(Skill $skill): static + { + if (!$this->skills->contains($skill)) { + $this->skills->add($skill); + } + + return $this; + } + + public function removeSkill(Skill $skill): static + { + $this->skills->removeElement($skill); + + return $this; + } +} diff --git a/src/Entity/Obtaining.php b/src/Entity/Obtaining.php new file mode 100644 index 0000000..cecb3c1 --- /dev/null +++ b/src/Entity/Obtaining.php @@ -0,0 +1,36 @@ +id; + } + + public function getDate(): ?\DateTimeInterface + { + return $this->date; + } + + public function setDate(\DateTimeInterface $date): static + { + $this->date = $date; + + return $this; + } +} diff --git a/src/Entity/Skill.php b/src/Entity/Skill.php new file mode 100644 index 0000000..47bea20 --- /dev/null +++ b/src/Entity/Skill.php @@ -0,0 +1,75 @@ + + */ + #[ORM\ManyToMany(targetEntity: Intern::class, mappedBy: 'skills')] + private Collection $interns; + + public function __construct() + { + $this->interns = new ArrayCollection(); + } + + public function getId(): ?int + { + return $this->id; + } + + public function getLabel(): ?string + { + return $this->label; + } + + public function setLabel(string $label): static + { + $this->label = $label; + + return $this; + } + + /** + * @return Collection + */ + public function getInterns(): Collection + { + return $this->interns; + } + + public function addIntern(Intern $intern): static + { + if (!$this->interns->contains($intern)) { + $this->interns->add($intern); + $intern->addSkill($this); + } + + return $this; + } + + public function removeIntern(Intern $intern): static + { + if ($this->interns->removeElement($intern)) { + $intern->removeSkill($this); + } + + return $this; + } +} diff --git a/src/Entity/Status.php b/src/Entity/Status.php new file mode 100644 index 0000000..e672f8c --- /dev/null +++ b/src/Entity/Status.php @@ -0,0 +1,78 @@ + + */ + #[ORM\OneToMany(targetEntity: Announcement::class, mappedBy: 'status')] + private Collection $announcements; + + public function __construct() + { + $this->announcements = new ArrayCollection(); + } + + public function getId(): ?int + { + return $this->id; + } + + public function getLabel(): ?string + { + return $this->label; + } + + public function setLabel(string $label): static + { + $this->label = $label; + + return $this; + } + + /** + * @return Collection + */ + public function getAnnouncements(): Collection + { + return $this->announcements; + } + + public function addAnnouncement(Announcement $announcement): static + { + if (!$this->announcements->contains($announcement)) { + $this->announcements->add($announcement); + $announcement->setStatus($this); + } + + return $this; + } + + public function removeAnnouncement(Announcement $announcement): static + { + if ($this->announcements->removeElement($announcement)) { + // set the owning side to null (unless already changed) + if ($announcement->getStatus() === $this) { + $announcement->setStatus(null); + } + } + + return $this; + } +} diff --git a/src/Entity/User.php b/src/Entity/UserApp.php similarity index 92% rename from src/Entity/User.php rename to src/Entity/UserApp.php index 4536d5c..fe10006 100644 --- a/src/Entity/User.php +++ b/src/Entity/UserApp.php @@ -8,9 +8,12 @@ use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; use Symfony\Component\Security\Core\User\UserInterface; #[ORM\Entity(repositoryClass: UserRepository::class)] -#[ORM\Table(name: '`user`')] +#[ORM\Table(name: 'userApp')] +#[ORM\InheritanceType('JOINED')] +#[ORM\DiscriminatorColumn(name: 'DISCRIMINATOR', type: 'string')] +#[ORM\DiscriminatorMap(['employee' => Employee::class, 'intern' => Intern::class])] #[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_NICKNAME', fields: ['nickname'])] -class User implements UserInterface, PasswordAuthenticatedUserInterface +class UserApp implements UserInterface, PasswordAuthenticatedUserInterface { #[ORM\Id] #[ORM\GeneratedValue] diff --git a/src/Repository/AnnouncementRepository.php b/src/Repository/AnnouncementRepository.php new file mode 100644 index 0000000..36813af --- /dev/null +++ b/src/Repository/AnnouncementRepository.php @@ -0,0 +1,43 @@ + + */ +class AnnouncementRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Announcement::class); + } + + // /** + // * @return Announcement[] Returns an array of Announcement objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('a') + // ->andWhere('a.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('a.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?Announcement + // { + // return $this->createQueryBuilder('a') + // ->andWhere('a.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/src/Repository/CompanyRepository.php b/src/Repository/CompanyRepository.php new file mode 100644 index 0000000..c0140b5 --- /dev/null +++ b/src/Repository/CompanyRepository.php @@ -0,0 +1,43 @@ + + */ +class CompanyRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Company::class); + } + + // /** + // * @return Company[] Returns an array of Company objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('c') + // ->andWhere('c.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('c.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?Company + // { + // return $this->createQueryBuilder('c') + // ->andWhere('c.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/src/Repository/EmployeeRepository.php b/src/Repository/EmployeeRepository.php new file mode 100644 index 0000000..5606e30 --- /dev/null +++ b/src/Repository/EmployeeRepository.php @@ -0,0 +1,43 @@ + + */ +class EmployeeRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Employee::class); + } + + // /** + // * @return Employee[] Returns an array of Employee objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('e') + // ->andWhere('e.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('e.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?Employee + // { + // return $this->createQueryBuilder('e') + // ->andWhere('e.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/src/Repository/InternRepository.php b/src/Repository/InternRepository.php new file mode 100644 index 0000000..dde6e54 --- /dev/null +++ b/src/Repository/InternRepository.php @@ -0,0 +1,43 @@ + + */ +class InternRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Intern::class); + } + + // /** + // * @return Intern[] Returns an array of Intern objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('i') + // ->andWhere('i.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('i.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?Intern + // { + // return $this->createQueryBuilder('i') + // ->andWhere('i.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/src/Repository/ObtainingRepository.php b/src/Repository/ObtainingRepository.php new file mode 100644 index 0000000..fe6723e --- /dev/null +++ b/src/Repository/ObtainingRepository.php @@ -0,0 +1,43 @@ + + */ +class ObtainingRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Obtaining::class); + } + + // /** + // * @return Obtaining[] Returns an array of Obtaining objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('o') + // ->andWhere('o.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('o.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?Obtaining + // { + // return $this->createQueryBuilder('o') + // ->andWhere('o.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/src/Repository/SkillRepository.php b/src/Repository/SkillRepository.php new file mode 100644 index 0000000..dd659e5 --- /dev/null +++ b/src/Repository/SkillRepository.php @@ -0,0 +1,43 @@ + + */ +class SkillRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Skill::class); + } + + // /** + // * @return Skill[] Returns an array of Skill objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('s') + // ->andWhere('s.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('s.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?Skill + // { + // return $this->createQueryBuilder('s') + // ->andWhere('s.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/src/Repository/StatusRepository.php b/src/Repository/StatusRepository.php new file mode 100644 index 0000000..ea2e260 --- /dev/null +++ b/src/Repository/StatusRepository.php @@ -0,0 +1,43 @@ + + */ +class StatusRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Status::class); + } + +// /** +// * @return Status[] Returns an array of Status objects +// */ +// public function findByExampleField($value): array +// { +// return $this->createQueryBuilder('v') +// ->andWhere('v.exampleField = :val') +// ->setParameter('val', $value) +// ->orderBy('v.id', 'ASC') +// ->setMaxResults(10) +// ->getQuery() +// ->getResult() +// ; +// } + +// public function findOneBySomeField($value): ?Status +// { +// return $this->createQueryBuilder('v') +// ->andWhere('v.exampleField = :val') +// ->setParameter('val', $value) +// ->getQuery() +// ->getOneOrNullResult() +// ; +// } +} diff --git a/src/Repository/UserRepository.php b/src/Repository/UserRepository.php index 4f2804e..b502329 100644 --- a/src/Repository/UserRepository.php +++ b/src/Repository/UserRepository.php @@ -2,7 +2,7 @@ namespace App\Repository; -use App\Entity\User; +use App\Entity\UserApp; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; use Symfony\Component\Security\Core\Exception\UnsupportedUserException; @@ -10,13 +10,13 @@ use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; use Symfony\Component\Security\Core\User\PasswordUpgraderInterface; /** - * @extends ServiceEntityRepository + * @extends ServiceEntityRepository */ class UserRepository extends ServiceEntityRepository implements PasswordUpgraderInterface { public function __construct(ManagerRegistry $registry) { - parent::__construct($registry, User::class); + parent::__construct($registry, UserApp::class); } /** @@ -24,7 +24,7 @@ class UserRepository extends ServiceEntityRepository implements PasswordUpgrader */ public function upgradePassword(PasswordAuthenticatedUserInterface $user, string $newHashedPassword): void { - if (!$user instanceof User) { + if (!$user instanceof UserApp) { throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', $user::class)); } @@ -34,7 +34,7 @@ class UserRepository extends ServiceEntityRepository implements PasswordUpgrader } // /** - // * @return User[] Returns an array of User objects + // * @return UserApp[] Returns an array of UserApp objects // */ // public function findByExampleField($value): array // { @@ -48,7 +48,7 @@ class UserRepository extends ServiceEntityRepository implements PasswordUpgrader // ; // } - // public function findOneBySomeField($value): ?User + // public function findOneBySomeField($value): ?UserApp // { // return $this->createQueryBuilder('u') // ->andWhere('u.exampleField = :val') From a8b80273a7c23eaa0635a27f0e2720cd571573ba Mon Sep 17 00:00:00 2001 From: Romain Date: Sun, 10 Nov 2024 15:41:01 +0100 Subject: [PATCH 09/14] ajout diplome et message + gestion des relations --- src/Entity/Announcement.php | 90 ++++++----- src/Entity/Degree.php | 78 ++++++++++ src/Entity/Intern.php | 147 ++++++++++++------ src/Entity/InternApplication.php | 66 ++++++++ src/Entity/InternDegree.php | 66 ++++++++ src/Entity/InternFavorite.php | 50 ++++++ src/Entity/InternSkill.php | 50 ++++++ src/Entity/Message.php | 81 ++++++++++ src/Entity/Skill.php | 17 +- src/Repository/DegreeRepository.php | 43 +++++ .../InternApplicationRepository.php | 43 +++++ src/Repository/InternDegreeRepository.php | 43 +++++ src/Repository/InternFavoriteRepository.php | 43 +++++ src/Repository/InternSkillRepository.php | 43 +++++ src/Repository/MessageRepository.php | 43 +++++ 15 files changed, 807 insertions(+), 96 deletions(-) create mode 100644 src/Entity/Degree.php create mode 100644 src/Entity/InternApplication.php create mode 100644 src/Entity/InternDegree.php create mode 100644 src/Entity/InternFavorite.php create mode 100644 src/Entity/InternSkill.php create mode 100644 src/Entity/Message.php create mode 100644 src/Repository/DegreeRepository.php create mode 100644 src/Repository/InternApplicationRepository.php create mode 100644 src/Repository/InternDegreeRepository.php create mode 100644 src/Repository/InternFavoriteRepository.php create mode 100644 src/Repository/InternSkillRepository.php create mode 100644 src/Repository/MessageRepository.php diff --git a/src/Entity/Announcement.php b/src/Entity/Announcement.php index 41bcf91..5cf1c55 100644 --- a/src/Entity/Announcement.php +++ b/src/Entity/Announcement.php @@ -30,21 +30,21 @@ class Announcement private ?Status $status = null; /** - * @var Collection + * @var Collection */ - #[ORM\ManyToMany(targetEntity: Intern::class, mappedBy: 'favorites')] - private Collection $internsfav; + #[ORM\OneToMany(targetEntity: InternApplication::class, mappedBy: 'application')] + private Collection $applicants; /** - * @var Collection + * @var Collection */ - #[ORM\ManyToMany(targetEntity: Intern::class, mappedBy: 'applications')] - private Collection $applicants; + #[ORM\OneToMany(targetEntity: InternFavorite::class, mappedBy: 'announcement')] + private Collection $favoritesInterns; public function __construct() { - $this->internsfav = new ArrayCollection(); $this->applicants = new ArrayCollection(); + $this->favoritesInterns = new ArrayCollection(); } public function getId(): ?int @@ -101,54 +101,60 @@ class Announcement } /** - * @return Collection - */ - public function getInternsfav(): Collection - { - return $this->internsfav; - } - - public function addInternfav(Intern $intern): static - { - if (!$this->internsfav->contains($intern)) { - $this->internsfav->add($intern); - $intern->addFavorite($this); - } - - return $this; - } - - public function removeInternfav(Intern $intern): static - { - if ($this->internsfav->removeElement($intern)) { - $intern->removeFavorite($this); - } - - return $this; - } - - /** - * @return Collection + * @return Collection */ public function getApplicants(): Collection { return $this->applicants; } - public function addApplicant(Intern $applicant): static + public function addApplicants(InternApplication $applicants): static { - if (!$this->applicants->contains($applicant)) { - $this->applicants->add($applicant); - $applicant->addApplication($this); + if (!$this->applicants->contains($applicants)) { + $this->applicants->add($applicants); + $applicants->setApplication($this); } return $this; } - public function removeApplicant(Intern $applicant): static + public function removeApplicants(InternApplication $applicants): static { - if ($this->applicants->removeElement($applicant)) { - $applicant->removeApplication($this); + if ($this->applicants->removeElement($applicants)) { + // set the owning side to null (unless already changed) + if ($applicants->getApplication() === $this) { + $applicants->setApplication(null); + } + } + + return $this; + } + + /** + * @return Collection + */ + public function getFavoritesInterns(): Collection + { + return $this->favoritesInterns; + } + + public function addFavoritesIntern(InternFavorite $favoritesIntern): static + { + if (!$this->favoritesInterns->contains($favoritesIntern)) { + $this->favoritesInterns->add($favoritesIntern); + $favoritesIntern->setAnnouncement($this); + } + + return $this; + } + + public function removeFavoritesIntern(InternFavorite $favoritesIntern): static + { + if ($this->favoritesInterns->removeElement($favoritesIntern)) { + // set the owning side to null (unless already changed) + if ($favoritesIntern->getAnnouncement() === $this) { + $favoritesIntern->setAnnouncement(null); + } } return $this; diff --git a/src/Entity/Degree.php b/src/Entity/Degree.php new file mode 100644 index 0000000..228a32d --- /dev/null +++ b/src/Entity/Degree.php @@ -0,0 +1,78 @@ + + */ + #[ORM\OneToMany(targetEntity: InternDegree::class, mappedBy: 'degree')] + private Collection $interns; + + public function __construct() + { + $this->interns = new ArrayCollection(); + } + + public function getId(): ?int + { + return $this->id; + } + + public function getLabel(): ?string + { + return $this->label; + } + + public function setLabel(string $label): static + { + $this->label = $label; + + return $this; + } + + /** + * @return Collection + */ + public function getInterns(): Collection + { + return $this->interns; + } + + public function addIntern(InternDegree $intern): static + { + if (!$this->interns->contains($intern)) { + $this->interns->add($intern); + $intern->setDegree($this); + } + + return $this; + } + + public function removeIntern(InternDegree $intern): static + { + if ($this->interns->removeElement($intern)) { + // set the owning side to null (unless already changed) + if ($intern->getDegree() === $this) { + $intern->setDegree(null); + } + } + + return $this; + } +} diff --git a/src/Entity/Intern.php b/src/Entity/Intern.php index b03dcd8..2ca1f8e 100644 --- a/src/Entity/Intern.php +++ b/src/Entity/Intern.php @@ -19,30 +19,35 @@ class Intern extends UserApp private ?string $resume = null; /** - * @var Collection + * @var Collection */ - #[ORM\ManyToMany(targetEntity: Announcement::class, inversedBy: 'interns')] - #[ORM\JoinTable(name: 'favorites')] - private Collection $favorites; + #[ORM\OneToMany(targetEntity: InternDegree::class, mappedBy: 'intern')] + private Collection $degrees; /** - * @var Collection + * @var Collection */ - #[ORM\ManyToMany(targetEntity: Announcement::class, inversedBy: 'applicants')] - #[ORM\JoinTable(name: 'applications')] + #[ORM\OneToMany(targetEntity: InternSkill::class, mappedBy: 'intern')] + private Collection $skills; + + /** + * @var Collection + */ + #[ORM\OneToMany(targetEntity: InternApplication::class, mappedBy: 'intern')] private Collection $applications; /** - * @var Collection + * @var Collection */ - #[ORM\ManyToMany(targetEntity: Skill::class, inversedBy: 'interns')] - private Collection $skills; + #[ORM\OneToMany(targetEntity: InternFavorite::class, mappedBy: 'intern')] + private Collection $favorites; public function __construct() { - $this->favorites = new ArrayCollection(); - $this->applications = new ArrayCollection(); + $this->degrees = new ArrayCollection(); $this->skills = new ArrayCollection(); + $this->applications = new ArrayCollection(); + $this->favorites = new ArrayCollection(); } public function getCoverLetter(): ?string @@ -70,73 +75,121 @@ class Intern extends UserApp } /** - * @return Collection + * @return Collection */ - public function getFavorites(): Collection + public function getDegrees(): Collection { - return $this->favorites; + return $this->degrees; } - public function addFavorite(Announcement $favorite): static + public function addDegree(InternDegree $degree): static { - if (!$this->favorites->contains($favorite)) { - $this->favorites->add($favorite); + if (!$this->degrees->contains($degree)) { + $this->degrees->add($degree); + $degree->setIntern($this); } return $this; } - public function removeFavorite(Announcement $favorite): static + public function removeDegree(InternDegree $degree): static { - $this->favorites->removeElement($favorite); - - return $this; - } - - /** - * @return Collection - */ - public function getApplications(): Collection - { - return $this->applications; - } - - public function addApplication(Announcement $application): static - { - if (!$this->applications->contains($application)) { - $this->applications->add($application); + if ($this->degrees->removeElement($degree)) { + // set the owning side to null (unless already changed) + if ($degree->getIntern() === $this) { + $degree->setIntern(null); + } } return $this; } - public function removeApplication(Announcement $application): static - { - $this->applications->removeElement($application); - - return $this; - } - /** - * @return Collection + * @return Collection */ public function getSkills(): Collection { return $this->skills; } - public function addSkill(Skill $skill): static + public function addSkill(InternSkill $skill): static { if (!$this->skills->contains($skill)) { $this->skills->add($skill); + $skill->setIntern($this); } return $this; } - public function removeSkill(Skill $skill): static + public function removeSkill(InternSkill $skill): static { - $this->skills->removeElement($skill); + if ($this->skills->removeElement($skill)) { + // set the owning side to null (unless already changed) + if ($skill->getIntern() === $this) { + $skill->setIntern(null); + } + } + + return $this; + } + + /** + * @return Collection + */ + public function getApplications(): Collection + { + return $this->applications; + } + + public function addApplication(InternApplication $application): static + { + if (!$this->applications->contains($application)) { + $this->applications->add($application); + $application->setIntern($this); + } + + return $this; + } + + public function removeApplication(InternApplication $application): static + { + if ($this->applications->removeElement($application)) { + // set the owning side to null (unless already changed) + if ($application->getIntern() === $this) { + $application->setIntern(null); + } + } + + return $this; + } + + /** + * @return Collection + */ + public function getFavorites(): Collection + { + return $this->favorites; + } + + public function addFavorite(InternFavorite $favorite): static + { + if (!$this->favorites->contains($favorite)) { + $this->favorites->add($favorite); + $favorite->setIntern($this); + } + + return $this; + } + + public function removeFavorite(InternFavorite $favorite): static + { + if ($this->favorites->removeElement($favorite)) { + // set the owning side to null (unless already changed) + if ($favorite->getIntern() === $this) { + $favorite->setIntern(null); + } + } return $this; } diff --git a/src/Entity/InternApplication.php b/src/Entity/InternApplication.php new file mode 100644 index 0000000..484a6ea --- /dev/null +++ b/src/Entity/InternApplication.php @@ -0,0 +1,66 @@ +id; + } + + public function getApplication(): ?Announcement + { + return $this->application; + } + + public function setApplication(?Announcement $application): static + { + $this->application = $application; + + return $this; + } + + public function getIntern(): ?Intern + { + return $this->intern; + } + + public function setIntern(?Intern $intern): static + { + $this->intern = $intern; + + return $this; + } + + public function getApplicationDate(): ?\DateTimeInterface + { + return $this->applicationDate; + } + + public function setApplicationDate(\DateTimeInterface $applicationDate): static + { + $this->applicationDate = $applicationDate; + + return $this; + } +} diff --git a/src/Entity/InternDegree.php b/src/Entity/InternDegree.php new file mode 100644 index 0000000..01be94b --- /dev/null +++ b/src/Entity/InternDegree.php @@ -0,0 +1,66 @@ +id; + } + + public function getDegree(): ?Degree + { + return $this->degree; + } + + public function setDegree(?Degree $degree): static + { + $this->degree = $degree; + + return $this; + } + + public function getIntern(): ?Intern + { + return $this->intern; + } + + public function setIntern(?Intern $intern): static + { + $this->intern = $intern; + + return $this; + } + + public function getGraduationDate(): ?\DateTimeInterface + { + return $this->graduationDate; + } + + public function setGraduationDate(\DateTimeInterface $graduationDate): static + { + $this->graduationDate = $graduationDate; + + return $this; + } +} diff --git a/src/Entity/InternFavorite.php b/src/Entity/InternFavorite.php new file mode 100644 index 0000000..8dd915b --- /dev/null +++ b/src/Entity/InternFavorite.php @@ -0,0 +1,50 @@ +id; + } + + public function getAnnouncement(): ?Announcement + { + return $this->announcement; + } + + public function setAnnouncement(?Announcement $announcement): static + { + $this->announcement = $announcement; + + return $this; + } + + public function getIntern(): ?Intern + { + return $this->intern; + } + + public function setIntern(?Intern $intern): static + { + $this->intern = $intern; + + return $this; + } +} diff --git a/src/Entity/InternSkill.php b/src/Entity/InternSkill.php new file mode 100644 index 0000000..89d8cfa --- /dev/null +++ b/src/Entity/InternSkill.php @@ -0,0 +1,50 @@ +id; + } + + public function getSkill(): ?Skill + { + return $this->skill; + } + + public function setSkill(?Skill $skill): static + { + $this->skill = $skill; + + return $this; + } + + public function getIntern(): ?Intern + { + return $this->intern; + } + + public function setIntern(?Intern $intern): static + { + $this->intern = $intern; + + return $this; + } +} diff --git a/src/Entity/Message.php b/src/Entity/Message.php new file mode 100644 index 0000000..b9e9969 --- /dev/null +++ b/src/Entity/Message.php @@ -0,0 +1,81 @@ +id; + } + + public function getSender(): ?UserApp + { + return $this->sender; + } + + public function setSender(?UserApp $sender): static + { + $this->sender = $sender; + + return $this; + } + + public function getReceiver(): ?UserApp + { + return $this->receiver; + } + + public function setReceiver(?UserApp $receiver): static + { + $this->receiver = $receiver; + + return $this; + } + + public function getContent(): ?string + { + return $this->content; + } + + public function setContent(string $content): static + { + $this->content = $content; + + return $this; + } + + public function getSendingDate(): ?\DateTimeInterface + { + return $this->sendingDate; + } + + public function setSendingDate(\DateTimeInterface $sendingDate): static + { + $this->sendingDate = $sendingDate; + + return $this; + } +} diff --git a/src/Entity/Skill.php b/src/Entity/Skill.php index 47bea20..7752cfe 100644 --- a/src/Entity/Skill.php +++ b/src/Entity/Skill.php @@ -19,9 +19,9 @@ class Skill private ?string $label = null; /** - * @var Collection + * @var Collection */ - #[ORM\ManyToMany(targetEntity: Intern::class, mappedBy: 'skills')] + #[ORM\OneToMany(targetEntity: InternSkill::class, mappedBy: 'skill')] private Collection $interns; public function __construct() @@ -47,27 +47,30 @@ class Skill } /** - * @return Collection + * @return Collection */ public function getInterns(): Collection { return $this->interns; } - public function addIntern(Intern $intern): static + public function addIntern(InternSkill $intern): static { if (!$this->interns->contains($intern)) { $this->interns->add($intern); - $intern->addSkill($this); + $intern->setSkill($this); } return $this; } - public function removeIntern(Intern $intern): static + public function removeIntern(InternSkill $intern): static { if ($this->interns->removeElement($intern)) { - $intern->removeSkill($this); + // set the owning side to null (unless already changed) + if ($intern->getSkill() === $this) { + $intern->setSkill(null); + } } return $this; diff --git a/src/Repository/DegreeRepository.php b/src/Repository/DegreeRepository.php new file mode 100644 index 0000000..474fbe7 --- /dev/null +++ b/src/Repository/DegreeRepository.php @@ -0,0 +1,43 @@ + + */ +class DegreeRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Degree::class); + } + + // /** + // * @return Degree[] Returns an array of Degree objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('d') + // ->andWhere('d.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('d.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?Degree + // { + // return $this->createQueryBuilder('d') + // ->andWhere('d.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/src/Repository/InternApplicationRepository.php b/src/Repository/InternApplicationRepository.php new file mode 100644 index 0000000..b2957e1 --- /dev/null +++ b/src/Repository/InternApplicationRepository.php @@ -0,0 +1,43 @@ + + */ +class InternApplicationRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, InternApplication::class); + } + + // /** + // * @return InternApplication[] Returns an array of InternApplication objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('i') + // ->andWhere('i.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('i.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?InternApplication + // { + // return $this->createQueryBuilder('i') + // ->andWhere('i.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/src/Repository/InternDegreeRepository.php b/src/Repository/InternDegreeRepository.php new file mode 100644 index 0000000..7c7dafb --- /dev/null +++ b/src/Repository/InternDegreeRepository.php @@ -0,0 +1,43 @@ + + */ +class InternDegreeRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, InternDegree::class); + } + + // /** + // * @return InternDegree[] Returns an array of InternDegree objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('i') + // ->andWhere('i.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('i.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?InternDegree + // { + // return $this->createQueryBuilder('i') + // ->andWhere('i.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/src/Repository/InternFavoriteRepository.php b/src/Repository/InternFavoriteRepository.php new file mode 100644 index 0000000..ff5b296 --- /dev/null +++ b/src/Repository/InternFavoriteRepository.php @@ -0,0 +1,43 @@ + + */ +class InternFavoriteRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, InternFavorite::class); + } + + // /** + // * @return InternFavorite[] Returns an array of InternFavorite objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('i') + // ->andWhere('i.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('i.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?InternFavorite + // { + // return $this->createQueryBuilder('i') + // ->andWhere('i.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/src/Repository/InternSkillRepository.php b/src/Repository/InternSkillRepository.php new file mode 100644 index 0000000..fd0d1af --- /dev/null +++ b/src/Repository/InternSkillRepository.php @@ -0,0 +1,43 @@ + + */ +class InternSkillRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, InternSkill::class); + } + + // /** + // * @return InternSkill[] Returns an array of InternSkill objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('i') + // ->andWhere('i.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('i.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?InternSkill + // { + // return $this->createQueryBuilder('i') + // ->andWhere('i.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/src/Repository/MessageRepository.php b/src/Repository/MessageRepository.php new file mode 100644 index 0000000..e7f1849 --- /dev/null +++ b/src/Repository/MessageRepository.php @@ -0,0 +1,43 @@ + + */ +class MessageRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Message::class); + } + + // /** + // * @return Message[] Returns an array of Message objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('m') + // ->andWhere('m.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('m.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?Message + // { + // return $this->createQueryBuilder('m') + // ->andWhere('m.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} From 80b7c64aafd1924548b93746740ba72082cb1985 Mon Sep 17 00:00:00 2001 From: Romain Date: Mon, 11 Nov 2024 16:00:51 +0100 Subject: [PATCH 10/14] ajout FAQ + premiers controller / vues / formulaire pour annonce --- src/Controller/AnnouncementController.php | 84 +++++++++++++++++++++++ src/Entity/Announcement.php | 24 +++++-- src/Entity/FAQ.php | 66 ++++++++++++++++++ src/Entity/Obtaining.php | 36 ---------- src/Form/AnnouncementType.php | 39 +++++++++++ src/Repository/FAQRepository.php | 43 ++++++++++++ templates/announcement/add.html.twig | 14 ++++ templates/announcement/index.html.twig | 20 ++++++ templates/announcement/list.html.twig | 21 ++++++ 9 files changed, 307 insertions(+), 40 deletions(-) create mode 100644 src/Controller/AnnouncementController.php create mode 100644 src/Entity/FAQ.php delete mode 100644 src/Entity/Obtaining.php create mode 100644 src/Form/AnnouncementType.php create mode 100644 src/Repository/FAQRepository.php create mode 100644 templates/announcement/add.html.twig create mode 100644 templates/announcement/index.html.twig create mode 100644 templates/announcement/list.html.twig diff --git a/src/Controller/AnnouncementController.php b/src/Controller/AnnouncementController.php new file mode 100644 index 0000000..9ca78fc --- /dev/null +++ b/src/Controller/AnnouncementController.php @@ -0,0 +1,84 @@ +createForm(AnnouncementType::class, $announcement); + $form->handleRequest($request); + + if($form->isSubmitted() && $form->isValid()) + { + //met la date de création de l'annonce au moment où le formulaire est envoyé + $announcement->setCreationDate(new \DateTime()); + + $this->entityManager->persist($announcement); + $this->entityManager->flush(); + + $this->addFlash('success', 'Annonce créée avec succès.'); + return $this->redirectToRoute('app_announcement_list'); + } + + return $this->render('announcement/add.html.twig', [ + 'announcementForm' => $form, + ]); + } + + #[Route('/list', name: '_list')] + public function list(): Response + { + $announcements = $this->announcementRepository->findAll(); + + return $this->render('announcement/list.html.twig', [ + 'announcements' => $announcements, + ]); + } + + #[Route('/update/{id}', name: '_update')] + public function update(int $id, Request $request): Response + { + $announcement = $this->announcementRepository->find($id); + $form = $this->createForm(AnnouncementType::class, $announcement); + $form->handleRequest($request); + + if($form->isSubmitted() && $form->isValid()) + { + $this->entityManager->persist($announcement); + $this->entityManager->flush(); + } + + return $this->render('announcement/add.html.twig', [ + 'formAdd' => $form, + ]); + } + + #[Route('/delete/{id}', name: '_delete')] + public function delete(int $id): Response + { + $announcement = $this->announcementRepository->find($id); + $this->entityManager->remove($announcement); + $this->entityManager->flush(); + + return $this->redirectToRoute('app_announcement_list'); + } +} diff --git a/src/Entity/Announcement.php b/src/Entity/Announcement.php index 5cf1c55..94cf1a6 100644 --- a/src/Entity/Announcement.php +++ b/src/Entity/Announcement.php @@ -5,6 +5,7 @@ namespace App\Entity; use App\Repository\AnnouncementRepository; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity(repositoryClass: AnnouncementRepository::class)] @@ -30,16 +31,19 @@ class Announcement private ?Status $status = null; /** - * @var Collection + * @var ?Collection */ #[ORM\OneToMany(targetEntity: InternApplication::class, mappedBy: 'application')] - private Collection $applicants; + private ?Collection $applicants; /** - * @var Collection + * @var ?Collection */ #[ORM\OneToMany(targetEntity: InternFavorite::class, mappedBy: 'announcement')] - private Collection $favoritesInterns; + private ?Collection $favoritesInterns; + + #[ORM\Column(type: Types::DATE_MUTABLE)] + private ?\DateTimeInterface $creationDate = null; public function __construct() { @@ -159,4 +163,16 @@ class Announcement return $this; } + + public function getCreationDate(): ?\DateTimeInterface + { + return $this->creationDate; + } + + public function setCreationDate(\DateTimeInterface $creationDate): static + { + $this->creationDate = $creationDate; + + return $this; + } } diff --git a/src/Entity/FAQ.php b/src/Entity/FAQ.php new file mode 100644 index 0000000..986bc05 --- /dev/null +++ b/src/Entity/FAQ.php @@ -0,0 +1,66 @@ +id; + } + + public function getQuestion(): ?string + { + return $this->question; + } + + public function setQuestion(string $question): static + { + $this->question = $question; + + return $this; + } + + public function getAnswer(): ?string + { + return $this->answer; + } + + public function setAnswer(?string $answer): static + { + $this->answer = $answer; + + return $this; + } + + public function getUpdateDate(): ?\DateTimeInterface + { + return $this->updateDate; + } + + public function setUpdateDate(\DateTimeInterface $updateDate): static + { + $this->updateDate = $updateDate; + + return $this; + } +} diff --git a/src/Entity/Obtaining.php b/src/Entity/Obtaining.php deleted file mode 100644 index cecb3c1..0000000 --- a/src/Entity/Obtaining.php +++ /dev/null @@ -1,36 +0,0 @@ -id; - } - - public function getDate(): ?\DateTimeInterface - { - return $this->date; - } - - public function setDate(\DateTimeInterface $date): static - { - $this->date = $date; - - return $this; - } -} diff --git a/src/Form/AnnouncementType.php b/src/Form/AnnouncementType.php new file mode 100644 index 0000000..ef1255f --- /dev/null +++ b/src/Form/AnnouncementType.php @@ -0,0 +1,39 @@ +add('title') + ->add('description') + ->add('company', EntityType::class, [ + 'class' => Company::class, + 'choice_label' => 'id', + ]) + ->add('status', EntityType::class, [ + 'class' => Status::class, + 'choice_label' => 'id', + ]) + ->add('submit', SubmitType::class) + ; + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => Announcement::class, + ]); + } +} diff --git a/src/Repository/FAQRepository.php b/src/Repository/FAQRepository.php new file mode 100644 index 0000000..228a85f --- /dev/null +++ b/src/Repository/FAQRepository.php @@ -0,0 +1,43 @@ + + */ +class FAQRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, FAQ::class); + } + + // /** + // * @return FAQ[] Returns an array of FAQ objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('f') + // ->andWhere('f.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('f.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?FAQ + // { + // return $this->createQueryBuilder('f') + // ->andWhere('f.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/templates/announcement/add.html.twig b/templates/announcement/add.html.twig new file mode 100644 index 0000000..6171d29 --- /dev/null +++ b/templates/announcement/add.html.twig @@ -0,0 +1,14 @@ +{% extends 'base.html.twig' %} + +{% block title %}Hello AnnouncementController!{% endblock %} + +{% block body %} + + + {{ form(announcementForm) }} + + +{% endblock %} \ No newline at end of file diff --git a/templates/announcement/index.html.twig b/templates/announcement/index.html.twig new file mode 100644 index 0000000..aca0c93 --- /dev/null +++ b/templates/announcement/index.html.twig @@ -0,0 +1,20 @@ +{% extends 'base.html.twig' %} + +{% block title %}Hello AnnouncementController!{% endblock %} + +{% block body %} + + +
+

Hello {{ controller_name }}! ✅

+ + This friendly message is coming from: +
    +
  • Your controller at C:/Users/csese/Romain/Phpstorm_projets/ProjetHegreSphere/hegresphere/src/Controller/AnnouncementController.php
  • +
  • Your template at C:/Users/csese/Romain/Phpstorm_projets/ProjetHegreSphere/hegresphere/templates/announcement/index.html.twig
  • +
+
+{% endblock %} diff --git a/templates/announcement/list.html.twig b/templates/announcement/list.html.twig new file mode 100644 index 0000000..d1d3c02 --- /dev/null +++ b/templates/announcement/list.html.twig @@ -0,0 +1,21 @@ +{% extends 'base.html.twig' %} + +{% block title %}Bienvenue sur Hegreshpere{% endblock %} + +{% block body %} + + +

Liste des annonces

+ {% for ann in announcements %} +

{{ ann.title }}

+

{{ ann.company.name }}

+

{{ ann.description }}

+ +

{{ ann.creationDate }}

+ {% endfor %} + + +{% endblock %} \ No newline at end of file From 95aca509fcc48aa806bd97e2aaf4a476d562bbf2 Mon Sep 17 00:00:00 2001 From: barillote Date: Thu, 21 Nov 2024 15:59:55 +0100 Subject: [PATCH 11/14] Login Register --- config/packages/security.yaml | 36 +++++++++-- migrations/Version20241017134137.php | 67 ------------------- migrations/Version20241017142722.php | 52 --------------- migrations/Version20241017152949.php | 46 ------------- migrations/Version20241121141451.php | 38 +++++++++++ migrations/Version20241121141722.php | 40 ++++++++++++ migrations/Version20241121141818.php | 31 +++++++++ migrations/Version20241121141912.php | 32 ++++++++++ migrations/Version20241121142119.php | 34 ++++++++++ migrations/Version20241121142432.php | 31 +++++++++ migrations/Version20241121145353.php | 32 ++++++++++ src/Controller/RegistrationController.php | 73 +++++++++++++++++++++ src/Controller/SecurityController.php | 32 ++++++++++ src/Entity/Announcement.php | 9 ++- src/Entity/Employee.php | 2 +- src/Entity/Intern.php | 4 +- src/Entity/Status.php | 78 ----------------------- src/Entity/UserApp.php | 29 +++++++-- src/Form/RegistrationFormType.php | 57 +++++++++++++++++ src/Repository/StatusRepository.php | 43 ------------- src/Security/EmailVerifier.php | 52 +++++++++++++++ templates/registration/register.html.twig | 19 ++++++ templates/security/login.html.twig | 41 ++++++++++++ 23 files changed, 573 insertions(+), 305 deletions(-) delete mode 100644 migrations/Version20241017134137.php delete mode 100644 migrations/Version20241017142722.php delete mode 100644 migrations/Version20241017152949.php create mode 100644 migrations/Version20241121141451.php create mode 100644 migrations/Version20241121141722.php create mode 100644 migrations/Version20241121141818.php create mode 100644 migrations/Version20241121141912.php create mode 100644 migrations/Version20241121142119.php create mode 100644 migrations/Version20241121142432.php create mode 100644 migrations/Version20241121145353.php create mode 100644 src/Controller/RegistrationController.php create mode 100644 src/Controller/SecurityController.php delete mode 100644 src/Entity/Status.php create mode 100644 src/Form/RegistrationFormType.php delete mode 100644 src/Repository/StatusRepository.php create mode 100644 src/Security/EmailVerifier.php create mode 100644 templates/registration/register.html.twig create mode 100644 templates/security/login.html.twig diff --git a/config/packages/security.yaml b/config/packages/security.yaml index 6b3167f..7c33053 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -1,21 +1,47 @@ security: # https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords password_hashers: - Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto' + Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'plaintext' # à mettre en auto pour sécuriser les mdp # https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider providers: # used to reload user from session & other features (e.g. switch_user) - app_user_provider: + app_intern_provider: entity: - class: App\Entity\User + class: App\Entity\Intern property: nickname + + app_employee_provider: + entity: + class: App\Entity\Employee + property: nickname + # used to reload user from session & other features (e.g. switch_user) + # used to reload user from session & other features (e.g. switch_user) firewalls: dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false - main: + intern: lazy: true - provider: app_user_provider + provider: app_intern_provider + form_login: + login_path: app_login + check_path: app_login + enable_csrf: true + logout: + path: app_logout + # where to redirect after logout + # target: app_any_route + employee: + lazy: true + provider: app_employee_provider + form_login: + login_path: app_login + check_path: app_login + enable_csrf: true + logout: + path: app_logout + # where to redirect after logout + # target: app_any_route # activate different ways to authenticate # https://symfony.com/doc/current/security.html#the-firewall diff --git a/migrations/Version20241017134137.php b/migrations/Version20241017134137.php deleted file mode 100644 index 0dc3e3c..0000000 --- a/migrations/Version20241017134137.php +++ /dev/null @@ -1,67 +0,0 @@ -addSql('CREATE SEQUENCE announcement_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE SEQUENCE company_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE SEQUENCE userApp_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE TABLE announcement (id INT NOT NULL, title VARCHAR(255) NOT NULL, description VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE TABLE company (id INT NOT NULL, name VARCHAR(255) NOT NULL, address VARCHAR(255) NOT NULL, tel VARCHAR(255) NOT NULL, mail VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE TABLE employee (id INT NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE TABLE intern (id INT NOT NULL, cover_letter TEXT NOT NULL, resume VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE TABLE userApp (id INT NOT NULL, nickname VARCHAR(180) NOT NULL, roles JSON NOT NULL, password VARCHAR(255) NOT NULL, first_name VARCHAR(255) NOT NULL, last_name VARCHAR(255) NOT NULL, tel VARCHAR(255) NOT NULL, address VARCHAR(255) NOT NULL, mail VARCHAR(255) NOT NULL, DISCRIMINATOR VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE UNIQUE INDEX UNIQ_IDENTIFIER_NICKNAME ON userApp (nickname)'); - $this->addSql('CREATE TABLE messenger_messages (id BIGSERIAL NOT NULL, body TEXT NOT NULL, headers TEXT NOT NULL, queue_name VARCHAR(190) NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, available_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, delivered_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))'); - $this->addSql('CREATE INDEX IDX_75EA56E0FB7336F0 ON messenger_messages (queue_name)'); - $this->addSql('CREATE INDEX IDX_75EA56E0E3BD61CE ON messenger_messages (available_at)'); - $this->addSql('CREATE INDEX IDX_75EA56E016BA31DB ON messenger_messages (delivered_at)'); - $this->addSql('COMMENT ON COLUMN messenger_messages.created_at IS \'(DC2Type:datetime_immutable)\''); - $this->addSql('COMMENT ON COLUMN messenger_messages.available_at IS \'(DC2Type:datetime_immutable)\''); - $this->addSql('COMMENT ON COLUMN messenger_messages.delivered_at IS \'(DC2Type:datetime_immutable)\''); - $this->addSql('CREATE OR REPLACE FUNCTION notify_messenger_messages() RETURNS TRIGGER AS $$ - BEGIN - PERFORM pg_notify(\'messenger_messages\', NEW.queue_name::text); - RETURN NEW; - END; - $$ LANGUAGE plpgsql;'); - $this->addSql('DROP TRIGGER IF EXISTS notify_trigger ON messenger_messages;'); - $this->addSql('CREATE TRIGGER notify_trigger AFTER INSERT OR UPDATE ON messenger_messages FOR EACH ROW EXECUTE PROCEDURE notify_messenger_messages();'); - $this->addSql('ALTER TABLE employee ADD CONSTRAINT FK_5D9F75A1BF396750 FOREIGN KEY (id) REFERENCES userApp (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE intern ADD CONSTRAINT FK_A5795F36BF396750 FOREIGN KEY (id) REFERENCES userApp (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('CREATE SCHEMA public'); - $this->addSql('DROP SEQUENCE announcement_id_seq CASCADE'); - $this->addSql('DROP SEQUENCE company_id_seq CASCADE'); - $this->addSql('DROP SEQUENCE userApp_id_seq CASCADE'); - $this->addSql('ALTER TABLE employee DROP CONSTRAINT FK_5D9F75A1BF396750'); - $this->addSql('ALTER TABLE intern DROP CONSTRAINT FK_A5795F36BF396750'); - $this->addSql('DROP TABLE announcement'); - $this->addSql('DROP TABLE company'); - $this->addSql('DROP TABLE employee'); - $this->addSql('DROP TABLE intern'); - $this->addSql('DROP TABLE userApp'); - $this->addSql('DROP TABLE messenger_messages'); - } -} diff --git a/migrations/Version20241017142722.php b/migrations/Version20241017142722.php deleted file mode 100644 index 73818a8..0000000 --- a/migrations/Version20241017142722.php +++ /dev/null @@ -1,52 +0,0 @@ -addSql('CREATE SEQUENCE status_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE TABLE status (id INT NOT NULL, label VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); - $this->addSql('ALTER TABLE announcement ADD company_id INT NOT NULL'); - $this->addSql('ALTER TABLE announcement ADD status_id INT NOT NULL'); - $this->addSql('ALTER TABLE announcement ADD CONSTRAINT FK_4DB9D91C979B1AD6 FOREIGN KEY (company_id) REFERENCES company (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE announcement ADD CONSTRAINT FK_4DB9D91C6BF700BD FOREIGN KEY (status_id) REFERENCES status (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('CREATE INDEX IDX_4DB9D91C979B1AD6 ON announcement (company_id)'); - $this->addSql('CREATE INDEX IDX_4DB9D91C6BF700BD ON announcement (status_id)'); - $this->addSql('ALTER TABLE employee ADD company_id INT NOT NULL'); - $this->addSql('ALTER TABLE employee ADD CONSTRAINT FK_5D9F75A1979B1AD6 FOREIGN KEY (company_id) REFERENCES company (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('CREATE INDEX IDX_5D9F75A1979B1AD6 ON employee (company_id)'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('CREATE SCHEMA public'); - $this->addSql('ALTER TABLE announcement DROP CONSTRAINT FK_4DB9D91C6BF700BD'); - $this->addSql('DROP SEQUENCE status_id_seq CASCADE'); - $this->addSql('DROP TABLE status'); - $this->addSql('ALTER TABLE announcement DROP CONSTRAINT FK_4DB9D91C979B1AD6'); - $this->addSql('DROP INDEX IDX_4DB9D91C979B1AD6'); - $this->addSql('DROP INDEX IDX_4DB9D91C6BF700BD'); - $this->addSql('ALTER TABLE announcement DROP company_id'); - $this->addSql('ALTER TABLE announcement DROP status_id'); - $this->addSql('ALTER TABLE employee DROP CONSTRAINT FK_5D9F75A1979B1AD6'); - $this->addSql('DROP INDEX IDX_5D9F75A1979B1AD6'); - $this->addSql('ALTER TABLE employee DROP company_id'); - } -} diff --git a/migrations/Version20241017152949.php b/migrations/Version20241017152949.php deleted file mode 100644 index 1282d23..0000000 --- a/migrations/Version20241017152949.php +++ /dev/null @@ -1,46 +0,0 @@ -addSql('CREATE TABLE favorites (intern_id INT NOT NULL, announcement_id INT NOT NULL, PRIMARY KEY(intern_id, announcement_id))'); - $this->addSql('CREATE INDEX IDX_E46960F5525DD4B4 ON favorites (intern_id)'); - $this->addSql('CREATE INDEX IDX_E46960F5913AEA17 ON favorites (announcement_id)'); - $this->addSql('CREATE TABLE applications (intern_id INT NOT NULL, announcement_id INT NOT NULL, PRIMARY KEY(intern_id, announcement_id))'); - $this->addSql('CREATE INDEX IDX_F7C966F0525DD4B4 ON applications (intern_id)'); - $this->addSql('CREATE INDEX IDX_F7C966F0913AEA17 ON applications (announcement_id)'); - $this->addSql('ALTER TABLE favorites ADD CONSTRAINT FK_E46960F5525DD4B4 FOREIGN KEY (intern_id) REFERENCES intern (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE favorites ADD CONSTRAINT FK_E46960F5913AEA17 FOREIGN KEY (announcement_id) REFERENCES announcement (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE applications ADD CONSTRAINT FK_F7C966F0525DD4B4 FOREIGN KEY (intern_id) REFERENCES intern (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE applications ADD CONSTRAINT FK_F7C966F0913AEA17 FOREIGN KEY (announcement_id) REFERENCES announcement (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('CREATE SCHEMA public'); - $this->addSql('ALTER TABLE favorites DROP CONSTRAINT FK_E46960F5525DD4B4'); - $this->addSql('ALTER TABLE favorites DROP CONSTRAINT FK_E46960F5913AEA17'); - $this->addSql('ALTER TABLE applications DROP CONSTRAINT FK_F7C966F0525DD4B4'); - $this->addSql('ALTER TABLE applications DROP CONSTRAINT FK_F7C966F0913AEA17'); - $this->addSql('DROP TABLE favorites'); - $this->addSql('DROP TABLE applications'); - } -} diff --git a/migrations/Version20241121141451.php b/migrations/Version20241121141451.php new file mode 100644 index 0000000..d51cde4 --- /dev/null +++ b/migrations/Version20241121141451.php @@ -0,0 +1,38 @@ +addSql('DROP SEQUENCE status_id_seq CASCADE'); + $this->addSql('DROP TABLE status'); + $this->addSql('ALTER TABLE userapp ADD is_verified BOOLEAN NOT NULL'); + $this->addSql('ALTER TABLE userapp ALTER roles SET NOT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('CREATE SCHEMA public'); + $this->addSql('CREATE SEQUENCE status_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE TABLE status (id INT NOT NULL, label VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); + $this->addSql('ALTER TABLE userApp DROP is_verified'); + $this->addSql('ALTER TABLE userApp ALTER roles DROP NOT NULL'); + } +} diff --git a/migrations/Version20241121141722.php b/migrations/Version20241121141722.php new file mode 100644 index 0000000..6259ec7 --- /dev/null +++ b/migrations/Version20241121141722.php @@ -0,0 +1,40 @@ +addSql('ALTER TABLE userapp ALTER first_name DROP NOT NULL'); + $this->addSql('ALTER TABLE userapp ALTER last_name DROP NOT NULL'); + $this->addSql('ALTER TABLE userapp ALTER tel DROP NOT NULL'); + $this->addSql('ALTER TABLE userapp ALTER address DROP NOT NULL'); + $this->addSql('ALTER TABLE userapp ALTER mail DROP NOT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('CREATE SCHEMA public'); + $this->addSql('ALTER TABLE userApp ALTER first_name SET NOT NULL'); + $this->addSql('ALTER TABLE userApp ALTER last_name SET NOT NULL'); + $this->addSql('ALTER TABLE userApp ALTER tel SET NOT NULL'); + $this->addSql('ALTER TABLE userApp ALTER address SET NOT NULL'); + $this->addSql('ALTER TABLE userApp ALTER mail SET NOT NULL'); + } +} diff --git a/migrations/Version20241121141818.php b/migrations/Version20241121141818.php new file mode 100644 index 0000000..7eb43e8 --- /dev/null +++ b/migrations/Version20241121141818.php @@ -0,0 +1,31 @@ +addSql('CREATE SCHEMA public'); + } +} diff --git a/migrations/Version20241121141912.php b/migrations/Version20241121141912.php new file mode 100644 index 0000000..fbc5345 --- /dev/null +++ b/migrations/Version20241121141912.php @@ -0,0 +1,32 @@ +addSql('ALTER TABLE userapp ALTER is_verified DROP NOT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('CREATE SCHEMA public'); + $this->addSql('ALTER TABLE userApp ALTER is_verified SET NOT NULL'); + } +} diff --git a/migrations/Version20241121142119.php b/migrations/Version20241121142119.php new file mode 100644 index 0000000..44746a0 --- /dev/null +++ b/migrations/Version20241121142119.php @@ -0,0 +1,34 @@ +addSql('ALTER TABLE intern ALTER cover_letter DROP NOT NULL'); + $this->addSql('ALTER TABLE intern ALTER resume DROP NOT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('CREATE SCHEMA public'); + $this->addSql('ALTER TABLE intern ALTER cover_letter SET NOT NULL'); + $this->addSql('ALTER TABLE intern ALTER resume SET NOT NULL'); + } +} diff --git a/migrations/Version20241121142432.php b/migrations/Version20241121142432.php new file mode 100644 index 0000000..8226230 --- /dev/null +++ b/migrations/Version20241121142432.php @@ -0,0 +1,31 @@ +addSql('CREATE SCHEMA public'); + } +} diff --git a/migrations/Version20241121145353.php b/migrations/Version20241121145353.php new file mode 100644 index 0000000..439bd80 --- /dev/null +++ b/migrations/Version20241121145353.php @@ -0,0 +1,32 @@ +addSql('ALTER TABLE employee ALTER company_id DROP NOT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('CREATE SCHEMA public'); + $this->addSql('ALTER TABLE employee ALTER company_id SET NOT NULL'); + } +} diff --git a/src/Controller/RegistrationController.php b/src/Controller/RegistrationController.php new file mode 100644 index 0000000..b078d9d --- /dev/null +++ b/src/Controller/RegistrationController.php @@ -0,0 +1,73 @@ +createForm(RegistrationFormType::class, $user); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + /** @var string $plainPassword */ + $plainPassword = $form->get('plainPassword')->getData(); + + // encode the plain password + $user->setPassword($userPasswordHasher->hashPassword($user, $plainPassword)); + + $entityManager->persist($user); + $entityManager->flush(); + + // do anything else you need here, like send an email + + return $security->login($user, 'form_login', 'intern'); + } + + return $this->render('registration/register.html.twig', [ + 'registrationForm' => $form, + ]); + } + + #[Route('/employee', name: '_employee')] + public function registerEmployee(Request $request, UserPasswordHasherInterface $userPasswordHasher, Security $security, EntityManagerInterface $entityManager): Response + { + $user = new Employee(); + $form = $this->createForm(RegistrationFormType::class, $user); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + /** @var string $plainPassword */ + $plainPassword = $form->get('plainPassword')->getData(); + + // encode the plain password + $user->setPassword($userPasswordHasher->hashPassword($user, $plainPassword)); + + $entityManager->persist($user); + $entityManager->flush(); + + // do anything else you need here, like send an email + + return $security->login($user, 'form_login', 'employee'); + } + + return $this->render('registration/register.html.twig', [ + 'registrationForm' => $form, + ]); + } +} diff --git a/src/Controller/SecurityController.php b/src/Controller/SecurityController.php new file mode 100644 index 0000000..76bf5c4 --- /dev/null +++ b/src/Controller/SecurityController.php @@ -0,0 +1,32 @@ +getLastAuthenticationError(); + + // last username entered by the user + $lastUsername = $authenticationUtils->getLastUsername(); + + return $this->render('security/login.html.twig', [ + 'last_username' => $lastUsername, + 'error' => $error, + ]); + } + + #[Route(path: '/logout', name: 'app_logout')] + public function logout(): void + { + throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.'); + } +} diff --git a/src/Entity/Announcement.php b/src/Entity/Announcement.php index 94cf1a6..10e9d9d 100644 --- a/src/Entity/Announcement.php +++ b/src/Entity/Announcement.php @@ -26,9 +26,8 @@ class Announcement #[ORM\JoinColumn(nullable: false)] private ?Company $company = null; - #[ORM\ManyToOne(inversedBy: 'announcements')] - #[ORM\JoinColumn(nullable: false)] - private ?Status $status = null; + #[ORM\Column(length: 255)] + private ?string $status = 'notVerified'; /** * @var ?Collection @@ -92,12 +91,12 @@ class Announcement return $this; } - public function getStatus(): ?Status + public function getStatus(): ?string { return $this->status; } - public function setStatus(?Status $status): static + public function setStatus(?string $status): static { $this->status = $status; diff --git a/src/Entity/Employee.php b/src/Entity/Employee.php index 393a529..42f71b3 100644 --- a/src/Entity/Employee.php +++ b/src/Entity/Employee.php @@ -9,7 +9,7 @@ use Doctrine\ORM\Mapping as ORM; class Employee extends UserApp { #[ORM\ManyToOne(inversedBy: 'employees')] - #[ORM\JoinColumn(nullable: false)] + #[ORM\JoinColumn(nullable: true)] private ?Company $company = null; public function getCompany(): ?Company diff --git a/src/Entity/Intern.php b/src/Entity/Intern.php index 2ca1f8e..daaf428 100644 --- a/src/Entity/Intern.php +++ b/src/Entity/Intern.php @@ -12,10 +12,10 @@ use Doctrine\ORM\Mapping as ORM; class Intern extends UserApp { - #[ORM\Column(type: Types::TEXT)] + #[ORM\Column(type: Types::TEXT,nullable: true)] private ?string $coverLetter = null; - #[ORM\Column(length: 255)] + #[ORM\Column(length: 255,nullable: true)] private ?string $resume = null; /** diff --git a/src/Entity/Status.php b/src/Entity/Status.php deleted file mode 100644 index e672f8c..0000000 --- a/src/Entity/Status.php +++ /dev/null @@ -1,78 +0,0 @@ - - */ - #[ORM\OneToMany(targetEntity: Announcement::class, mappedBy: 'status')] - private Collection $announcements; - - public function __construct() - { - $this->announcements = new ArrayCollection(); - } - - public function getId(): ?int - { - return $this->id; - } - - public function getLabel(): ?string - { - return $this->label; - } - - public function setLabel(string $label): static - { - $this->label = $label; - - return $this; - } - - /** - * @return Collection - */ - public function getAnnouncements(): Collection - { - return $this->announcements; - } - - public function addAnnouncement(Announcement $announcement): static - { - if (!$this->announcements->contains($announcement)) { - $this->announcements->add($announcement); - $announcement->setStatus($this); - } - - return $this; - } - - public function removeAnnouncement(Announcement $announcement): static - { - if ($this->announcements->removeElement($announcement)) { - // set the owning side to null (unless already changed) - if ($announcement->getStatus() === $this) { - $announcement->setStatus(null); - } - } - - return $this; - } -} diff --git a/src/Entity/UserApp.php b/src/Entity/UserApp.php index fe10006..8f87ba6 100644 --- a/src/Entity/UserApp.php +++ b/src/Entity/UserApp.php @@ -4,6 +4,7 @@ namespace App\Entity; use App\Repository\UserRepository; use Doctrine\ORM\Mapping as ORM; +use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; use Symfony\Component\Security\Core\User\UserInterface; @@ -13,6 +14,7 @@ use Symfony\Component\Security\Core\User\UserInterface; #[ORM\DiscriminatorColumn(name: 'DISCRIMINATOR', type: 'string')] #[ORM\DiscriminatorMap(['employee' => Employee::class, 'intern' => Intern::class])] #[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_NICKNAME', fields: ['nickname'])] +#[UniqueEntity(fields: ['nickname'], message: 'Il y a déjà un compte avec ces identifiants !')] class UserApp implements UserInterface, PasswordAuthenticatedUserInterface { #[ORM\Id] @@ -27,7 +29,7 @@ class UserApp implements UserInterface, PasswordAuthenticatedUserInterface * @var list The user roles */ #[ORM\Column] - private array $roles = []; + private array $roles = ["ROLE_USER"]; /** * @var string The hashed password @@ -35,21 +37,24 @@ class UserApp implements UserInterface, PasswordAuthenticatedUserInterface #[ORM\Column] private ?string $password = null; - #[ORM\Column(length: 255)] + #[ORM\Column(length: 255, nullable: true)] private ?string $firstName = null; - #[ORM\Column(length: 255)] + #[ORM\Column(length: 255, nullable: true)] private ?string $lastName = null; - #[ORM\Column(length: 255)] + #[ORM\Column(length: 255,nullable: true)] private ?string $tel = null; - #[ORM\Column(length: 255)] + #[ORM\Column(length: 255,nullable: true)] private ?string $address = null; - #[ORM\Column(length: 255)] + #[ORM\Column(length: 255,nullable: true)] private ?string $mail = null; + #[ORM\Column(nullable: true)] + private bool $isVerified = false; + public function getId(): ?int { return $this->id; @@ -184,6 +189,18 @@ class UserApp implements UserInterface, PasswordAuthenticatedUserInterface return $this; } + + public function isVerified(): bool + { + return $this->isVerified; + } + + public function setVerified(bool $isVerified): static + { + $this->isVerified = $isVerified; + + return $this; + } } diff --git a/src/Form/RegistrationFormType.php b/src/Form/RegistrationFormType.php new file mode 100644 index 0000000..264b544 --- /dev/null +++ b/src/Form/RegistrationFormType.php @@ -0,0 +1,57 @@ +add('nickname') + ->add('agreeTerms', CheckboxType::class, [ + 'mapped' => false, + 'constraints' => [ + new IsTrue([ + 'message' => 'Vous devez accepter les conditions d\'utilisation.', + ]), + ], + ]) + ->add('plainPassword', PasswordType::class, [ + // instead of being set onto the object directly, + // this is read and encoded in the controller + 'mapped' => false, + 'attr' => ['autocomplete' => 'new-password'], + 'constraints' => [ + new NotBlank([ + 'message' => 'Merci d\'entrer votre mot de passe.', + ]), + new Length([ + 'min' => 6, + 'minMessage' => 'Votre mot de passe doit avoir au moins {{ limit }} caractères', + // max length allowed by Symfony for security reasons + 'max' => 4096, + ]), + ], + ]) + ; + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => UserApp::class, + ]); + } +} diff --git a/src/Repository/StatusRepository.php b/src/Repository/StatusRepository.php deleted file mode 100644 index ea2e260..0000000 --- a/src/Repository/StatusRepository.php +++ /dev/null @@ -1,43 +0,0 @@ - - */ -class StatusRepository extends ServiceEntityRepository -{ - public function __construct(ManagerRegistry $registry) - { - parent::__construct($registry, Status::class); - } - -// /** -// * @return Status[] Returns an array of Status objects -// */ -// public function findByExampleField($value): array -// { -// return $this->createQueryBuilder('v') -// ->andWhere('v.exampleField = :val') -// ->setParameter('val', $value) -// ->orderBy('v.id', 'ASC') -// ->setMaxResults(10) -// ->getQuery() -// ->getResult() -// ; -// } - -// public function findOneBySomeField($value): ?Status -// { -// return $this->createQueryBuilder('v') -// ->andWhere('v.exampleField = :val') -// ->setParameter('val', $value) -// ->getQuery() -// ->getOneOrNullResult() -// ; -// } -} diff --git a/src/Security/EmailVerifier.php b/src/Security/EmailVerifier.php new file mode 100644 index 0000000..0768c22 --- /dev/null +++ b/src/Security/EmailVerifier.php @@ -0,0 +1,52 @@ +verifyEmailHelper->generateSignature( + $verifyEmailRouteName, + (string) $user->getId(), + (string) $user->getMail() + ); + + $context = $email->getContext(); + $context['signedUrl'] = $signatureComponents->getSignedUrl(); + $context['expiresAtMessageKey'] = $signatureComponents->getExpirationMessageKey(); + $context['expiresAtMessageData'] = $signatureComponents->getExpirationMessageData(); + + $email->context($context); + + $this->mailer->send($email); + } + + /** + * @throws VerifyEmailExceptionInterface + */ + public function handleEmailConfirmation(Request $request, UserApp $user): void + { + $this->verifyEmailHelper->validateEmailConfirmationFromRequest($request, (string) $user->getId(), (string) $user->getMail()); + + $user->setVerified(true); + + $this->entityManager->persist($user); + $this->entityManager->flush(); + } +} diff --git a/templates/registration/register.html.twig b/templates/registration/register.html.twig new file mode 100644 index 0000000..7b064ed --- /dev/null +++ b/templates/registration/register.html.twig @@ -0,0 +1,19 @@ +{% extends 'base.html.twig' %} + +{% block title %}Inscription{% endblock %} + +{% block body %} +

Inscription

+ + {{ form_errors(registrationForm) }} + + {{ form_start(registrationForm) }} + {{ form_row(registrationForm.nickname) }} + {{ form_row(registrationForm.plainPassword, { + label: 'Password' + }) }} + {{ form_row(registrationForm.agreeTerms) }} + + + {{ form_end(registrationForm) }} +{% endblock %} diff --git a/templates/security/login.html.twig b/templates/security/login.html.twig new file mode 100644 index 0000000..f711f6f --- /dev/null +++ b/templates/security/login.html.twig @@ -0,0 +1,41 @@ +{% extends 'base.html.twig' %} + +{% block title %}Connexion{% endblock %} + +{% block body %} +
+ {% if error %} +
{{ error.messageKey|trans(error.messageData, 'security') }}
+ {% endif %} + + {% if app.user %} +
+ You are logged in as {{ app.user.userIdentifier }}, Logout +
+ {% endif %} + +

Connexion à votre compte

+ + + + + + + + {# + Uncomment this section and add a remember_me option below your firewall to activate remember me functionality. + See https://symfony.com/doc/current/security/remember_me.html + +
+ + +
+ #} + + +
+{% endblock %} From fc222f516ce87d5e4c74ef36d1099ac254d220fd Mon Sep 17 00:00:00 2001 From: barillote Date: Thu, 21 Nov 2024 16:17:24 +0100 Subject: [PATCH 12/14] roles --- migrations/Version20241121151633.php | 31 +++++++++++++++++++++++ src/Controller/RegistrationController.php | 2 ++ src/Entity/UserApp.php | 2 +- 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 migrations/Version20241121151633.php diff --git a/migrations/Version20241121151633.php b/migrations/Version20241121151633.php new file mode 100644 index 0000000..b9a833a --- /dev/null +++ b/migrations/Version20241121151633.php @@ -0,0 +1,31 @@ +addSql('CREATE SCHEMA public'); + } +} diff --git a/src/Controller/RegistrationController.php b/src/Controller/RegistrationController.php index b078d9d..50e84c2 100644 --- a/src/Controller/RegistrationController.php +++ b/src/Controller/RegistrationController.php @@ -28,6 +28,7 @@ class RegistrationController extends AbstractController /** @var string $plainPassword */ $plainPassword = $form->get('plainPassword')->getData(); + $user->setRoles(['ROLE_INTERN']); // encode the plain password $user->setPassword($userPasswordHasher->hashPassword($user, $plainPassword)); @@ -55,6 +56,7 @@ class RegistrationController extends AbstractController /** @var string $plainPassword */ $plainPassword = $form->get('plainPassword')->getData(); + $user->setRoles(['ROLE_EMPLOYEE']); // encode the plain password $user->setPassword($userPasswordHasher->hashPassword($user, $plainPassword)); diff --git a/src/Entity/UserApp.php b/src/Entity/UserApp.php index 8f87ba6..7dabaa2 100644 --- a/src/Entity/UserApp.php +++ b/src/Entity/UserApp.php @@ -29,7 +29,7 @@ class UserApp implements UserInterface, PasswordAuthenticatedUserInterface * @var list The user roles */ #[ORM\Column] - private array $roles = ["ROLE_USER"]; + private array $roles = []; /** * @var string The hashed password From 39a8e592885d7761450490acdfd166f5b5e5264e Mon Sep 17 00:00:00 2001 From: barillote Date: Thu, 21 Nov 2024 17:07:24 +0100 Subject: [PATCH 13/14] login --- migrations/Version20241121141451.php | 38 -------------------------- migrations/Version20241121141722.php | 40 ---------------------------- migrations/Version20241121141818.php | 31 --------------------- migrations/Version20241121141912.php | 32 ---------------------- migrations/Version20241121142119.php | 34 ----------------------- migrations/Version20241121142432.php | 31 --------------------- migrations/Version20241121145353.php | 32 ---------------------- migrations/Version20241121151633.php | 31 --------------------- 8 files changed, 269 deletions(-) delete mode 100644 migrations/Version20241121141451.php delete mode 100644 migrations/Version20241121141722.php delete mode 100644 migrations/Version20241121141818.php delete mode 100644 migrations/Version20241121141912.php delete mode 100644 migrations/Version20241121142119.php delete mode 100644 migrations/Version20241121142432.php delete mode 100644 migrations/Version20241121145353.php delete mode 100644 migrations/Version20241121151633.php diff --git a/migrations/Version20241121141451.php b/migrations/Version20241121141451.php deleted file mode 100644 index d51cde4..0000000 --- a/migrations/Version20241121141451.php +++ /dev/null @@ -1,38 +0,0 @@ -addSql('DROP SEQUENCE status_id_seq CASCADE'); - $this->addSql('DROP TABLE status'); - $this->addSql('ALTER TABLE userapp ADD is_verified BOOLEAN NOT NULL'); - $this->addSql('ALTER TABLE userapp ALTER roles SET NOT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('CREATE SCHEMA public'); - $this->addSql('CREATE SEQUENCE status_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE TABLE status (id INT NOT NULL, label VARCHAR(255) NOT NULL, PRIMARY KEY(id))'); - $this->addSql('ALTER TABLE userApp DROP is_verified'); - $this->addSql('ALTER TABLE userApp ALTER roles DROP NOT NULL'); - } -} diff --git a/migrations/Version20241121141722.php b/migrations/Version20241121141722.php deleted file mode 100644 index 6259ec7..0000000 --- a/migrations/Version20241121141722.php +++ /dev/null @@ -1,40 +0,0 @@ -addSql('ALTER TABLE userapp ALTER first_name DROP NOT NULL'); - $this->addSql('ALTER TABLE userapp ALTER last_name DROP NOT NULL'); - $this->addSql('ALTER TABLE userapp ALTER tel DROP NOT NULL'); - $this->addSql('ALTER TABLE userapp ALTER address DROP NOT NULL'); - $this->addSql('ALTER TABLE userapp ALTER mail DROP NOT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('CREATE SCHEMA public'); - $this->addSql('ALTER TABLE userApp ALTER first_name SET NOT NULL'); - $this->addSql('ALTER TABLE userApp ALTER last_name SET NOT NULL'); - $this->addSql('ALTER TABLE userApp ALTER tel SET NOT NULL'); - $this->addSql('ALTER TABLE userApp ALTER address SET NOT NULL'); - $this->addSql('ALTER TABLE userApp ALTER mail SET NOT NULL'); - } -} diff --git a/migrations/Version20241121141818.php b/migrations/Version20241121141818.php deleted file mode 100644 index 7eb43e8..0000000 --- a/migrations/Version20241121141818.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('CREATE SCHEMA public'); - } -} diff --git a/migrations/Version20241121141912.php b/migrations/Version20241121141912.php deleted file mode 100644 index fbc5345..0000000 --- a/migrations/Version20241121141912.php +++ /dev/null @@ -1,32 +0,0 @@ -addSql('ALTER TABLE userapp ALTER is_verified DROP NOT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('CREATE SCHEMA public'); - $this->addSql('ALTER TABLE userApp ALTER is_verified SET NOT NULL'); - } -} diff --git a/migrations/Version20241121142119.php b/migrations/Version20241121142119.php deleted file mode 100644 index 44746a0..0000000 --- a/migrations/Version20241121142119.php +++ /dev/null @@ -1,34 +0,0 @@ -addSql('ALTER TABLE intern ALTER cover_letter DROP NOT NULL'); - $this->addSql('ALTER TABLE intern ALTER resume DROP NOT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('CREATE SCHEMA public'); - $this->addSql('ALTER TABLE intern ALTER cover_letter SET NOT NULL'); - $this->addSql('ALTER TABLE intern ALTER resume SET NOT NULL'); - } -} diff --git a/migrations/Version20241121142432.php b/migrations/Version20241121142432.php deleted file mode 100644 index 8226230..0000000 --- a/migrations/Version20241121142432.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('CREATE SCHEMA public'); - } -} diff --git a/migrations/Version20241121145353.php b/migrations/Version20241121145353.php deleted file mode 100644 index 439bd80..0000000 --- a/migrations/Version20241121145353.php +++ /dev/null @@ -1,32 +0,0 @@ -addSql('ALTER TABLE employee ALTER company_id DROP NOT NULL'); - } - - public function down(Schema $schema): void - { - // this down() migration is auto-generated, please modify it to your needs - $this->addSql('CREATE SCHEMA public'); - $this->addSql('ALTER TABLE employee ALTER company_id SET NOT NULL'); - } -} diff --git a/migrations/Version20241121151633.php b/migrations/Version20241121151633.php deleted file mode 100644 index b9a833a..0000000 --- a/migrations/Version20241121151633.php +++ /dev/null @@ -1,31 +0,0 @@ -addSql('CREATE SCHEMA public'); - } -} From e729450c6405da3173f14f08e230dab7b092c72d Mon Sep 17 00:00:00 2001 From: barillote Date: Thu, 21 Nov 2024 17:16:41 +0100 Subject: [PATCH 14/14] formregister --- migrations/Version20241121153037.php | 31 +++++++++++++++++ src/Entity/Announcement.php | 4 +-- src/Form/RegistrationFormType.php | 42 ++++++++++++++++++----- templates/registration/register.html.twig | 5 ++- 4 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 migrations/Version20241121153037.php diff --git a/migrations/Version20241121153037.php b/migrations/Version20241121153037.php new file mode 100644 index 0000000..9a792b8 --- /dev/null +++ b/migrations/Version20241121153037.php @@ -0,0 +1,31 @@ +addSql('CREATE SCHEMA public'); + } +} diff --git a/src/Entity/Announcement.php b/src/Entity/Announcement.php index 10e9d9d..757de84 100644 --- a/src/Entity/Announcement.php +++ b/src/Entity/Announcement.php @@ -26,8 +26,8 @@ class Announcement #[ORM\JoinColumn(nullable: false)] private ?Company $company = null; - #[ORM\Column(length: 255)] - private ?string $status = 'notVerified'; + #[ORM\Column(nullable: false)] + private ?string $status = null; /** * @var ?Collection diff --git a/src/Form/RegistrationFormType.php b/src/Form/RegistrationFormType.php index 264b544..012084f 100644 --- a/src/Form/RegistrationFormType.php +++ b/src/Form/RegistrationFormType.php @@ -3,11 +3,12 @@ namespace App\Form; use App\Entity\UserApp; -use Doctrine\DBAL\Types\StringType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; +use Symfony\Component\Form\Extension\Core\Type\EmailType; use Symfony\Component\Form\Extension\Core\Type\PasswordType; +use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Validator\Constraints\IsTrue; @@ -19,15 +20,38 @@ class RegistrationFormType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options): void { $builder - ->add('nickname') - ->add('agreeTerms', CheckboxType::class, [ - 'mapped' => false, - 'constraints' => [ - new IsTrue([ - 'message' => 'Vous devez accepter les conditions d\'utilisation.', - ]), - ], + ->add('nickname', TextType::class, [ + 'label' => 'Utilisateur : ', ]) + ->add('firstname', TextType::class, [ + 'label' => 'Prénom : ', + 'required' => true, + 'constraints' => [ + new NotBlank(), + ] + ]) + ->add('lastname', TextType::class, [ + 'label' => 'Nom : ', + 'required' => true, + 'constraints' => [ + new NotBlank(), + ] + ]) + ->add('mail', EmailType::class, [ + 'label' => 'Email : ', + 'required' => true, + 'constraints' => [ + new NotBlank(), + ] + ]) +// ->add('agreeTerms', CheckboxType::class, [ +// 'mapped' => false, +// 'constraints' => [ +// new IsTrue([ +// 'message' => 'Vous devez accepter les conditions d\'utilisation.', +// ]), +// ], +// ]) ->add('plainPassword', PasswordType::class, [ // instead of being set onto the object directly, // this is read and encoded in the controller diff --git a/templates/registration/register.html.twig b/templates/registration/register.html.twig index 7b064ed..38c6dc9 100644 --- a/templates/registration/register.html.twig +++ b/templates/registration/register.html.twig @@ -9,10 +9,13 @@ {{ form_start(registrationForm) }} {{ form_row(registrationForm.nickname) }} + {{ form_row(registrationForm.firstname) }} + {{ form_row(registrationForm.lastname) }} + {{ form_row(registrationForm.mail) }} {{ form_row(registrationForm.plainPassword, { label: 'Password' }) }} - {{ form_row(registrationForm.agreeTerms) }} +{# {{ form_row(registrationForm.agreeTerms) }}#} {{ form_end(registrationForm) }}