|
|
@@ -9,11 +9,14 @@ use App\Entity\Core\AddressPostal;
|
|
|
use App\Entity\Core\ContactPoint;
|
|
|
use App\Entity\Organization\Organization;
|
|
|
use App\Entity\Organization\OrganizationAddressPostal;
|
|
|
+use App\Entity\Organization\TypeOfPractice;
|
|
|
use App\Enum\Core\ContactPointTypeEnum;
|
|
|
use App\Enum\Organization\AddressPostalOrganizationTypeEnum;
|
|
|
|
|
|
/**
|
|
|
- * Mapping des informations d'une Organization avec comme source un FreemiumOrganization.
|
|
|
+ * Class OrganizationMappingBuilder.
|
|
|
+ *
|
|
|
+ * Mapping class that maps information from a FreemiumOrganization to an Organization entity.
|
|
|
*/
|
|
|
class OrganizationMappingBuilder
|
|
|
{
|
|
|
@@ -28,6 +31,9 @@ class OrganizationMappingBuilder
|
|
|
// Mapping des infos principales
|
|
|
$this->mapOrganizationInformations($organization, $freemiumOrganization);
|
|
|
|
|
|
+ // Mapping des type de pratiques
|
|
|
+ $this->updateOrganizationTypeOfPractices($organization, $freemiumOrganization);
|
|
|
+
|
|
|
// Mapping des infos du point de contact principal
|
|
|
$this->mapContactPointInformations($this->getPrincipalContactPointOrCreateNewOne($organization), $freemiumOrganization);
|
|
|
|
|
|
@@ -44,6 +50,8 @@ class OrganizationMappingBuilder
|
|
|
protected function mapOrganizationInformations(Organization $organization, FreemiumOrganization $freemiumOrganization): void
|
|
|
{
|
|
|
$organization->setName($freemiumOrganization->name);
|
|
|
+ $organization->setPrincipalType($freemiumOrganization->principalType);
|
|
|
+ $organization->setLegalStatus($freemiumOrganization->legalStatus);
|
|
|
$organization->setDescription($freemiumOrganization->description);
|
|
|
$organization->setFacebook($freemiumOrganization->facebook);
|
|
|
$organization->setYoutube($freemiumOrganization->youtube);
|
|
|
@@ -53,6 +61,50 @@ class OrganizationMappingBuilder
|
|
|
$organization->setLogo($freemiumOrganization->logo);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Update the organization's type of practices based on the Freemium organization's type of practices.
|
|
|
+ *
|
|
|
+ * @param Organization $organization the organization to update the type of practices for
|
|
|
+ * @param FreemiumOrganization $freemiumOrganization the Freemium organization containing the desired type of practices
|
|
|
+ */
|
|
|
+ protected function updateOrganizationTypeOfPractices(Organization $organization, FreemiumOrganization $freemiumOrganization): void
|
|
|
+ {
|
|
|
+ foreach ($organization->getTypeOfPractices() as $organizationPractice) {
|
|
|
+ $this->removePracticeIfNotInFreemium($organization, $freemiumOrganization, $organizationPractice);
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($freemiumOrganization->typeOfPractices as $typeOfPractice) {
|
|
|
+ $this->addPracticeIfNotInOrganization($organization, $typeOfPractice);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Removes a practice from the organization if it is not in the freemium organization.
|
|
|
+ *
|
|
|
+ * @param Organization $organization the organization from which to remove the practice
|
|
|
+ * @param FreemiumOrganization $freemiumOrganization the freemium organization used for comparison
|
|
|
+ * @param TypeOfPractice $organizationPractice the practice to be removed if not in freemium organization
|
|
|
+ */
|
|
|
+ private function removePracticeIfNotInFreemium(Organization $organization, FreemiumOrganization $freemiumOrganization, TypeOfPractice $organizationPractice): void
|
|
|
+ {
|
|
|
+ if (!$freemiumOrganization->typeOfPractices->contains($organizationPractice)) {
|
|
|
+ $organization->removeTypeOfPractice($organizationPractice);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Adds the given TypeOfPractice to the Organization if it is not already associated with it.
|
|
|
+ *
|
|
|
+ * @param Organization $organization The organization to add the TypeOfPractice to
|
|
|
+ * @param TypeOfPractice $typeOfPractice The TypeOfPractice to add to the organization
|
|
|
+ */
|
|
|
+ private function addPracticeIfNotInOrganization(Organization $organization, TypeOfPractice $typeOfPractice): void
|
|
|
+ {
|
|
|
+ if (!$organization->getTypeOfPractices()->contains($typeOfPractice)) {
|
|
|
+ $organization->addTypeOfPractice($typeOfPractice);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Mapping des informations de ContactPoint depuis FreemiumOrganization.
|
|
|
*
|