PersonAddressPostal.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. namespace AppBundle\Entity\Person;
  3. use AppBundle\Annotation\ExportSplitFields;
  4. use AppBundle\Entity\Core\AddressPostal;
  5. use AppBundle\Enum\Core\AddressPostalTypeEnum;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Dunglas\ApiBundle\Annotation\Iri;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use AppBundle\Entity\Traits\TimestampableEntity;
  11. use AppBundle\Entity\Traits\CreatorUpdaterEntity;
  12. /**
  13. * Lien entre une Person et une AdressPostal, associé à un type
  14. *
  15. * @Iri("http://schema.org/PersonAddressPostal")
  16. */
  17. #[ORM\Entity]
  18. #[Assert\Callback(['AppBundle\Validator\Constraints\Core\PersonAddressPostalValidator', 'validate'])]
  19. class PersonAddressPostal
  20. {
  21. use TimestampableEntity;
  22. use CreatorUpdaterEntity;
  23. /**
  24. * @var int
  25. */
  26. #[ORM\Column(type: 'integer')]
  27. #[ORM\Id]
  28. #[ORM\GeneratedValue(strategy: 'AUTO')]
  29. #[Groups(['personaddresspostal', 'access_details_guardians', 'student_registration_person', 'student_registration_guardians', 'accesses_list_person', 'student_list_person', 'guardians_list_person', 'teachers_list_person', 'adherent_list_person', 'personnels_list_person', 'morals_list_person', 'ca_list_person', 'othercontact_list_person', 'board_list_person', 'networkmanagers_list_person', 'sepa_debit_mandate_person', 'equipment_availability_form_borrower', 'online_registration_access_details_person'])]
  30. private $id;
  31. /**
  32. * @var Person
  33. */
  34. #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Person\Person', inversedBy: 'personAddressPostal')]
  35. #[ORM\JoinColumn(nullable: false)]
  36. #[Assert\NotNull]
  37. #[Groups(['personaddresspostal'])]
  38. private $person;
  39. /**
  40. * @var AddressPostal
  41. */
  42. #[Assert\Valid]
  43. #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Core\AddressPostal', cascade: ['persist'], inversedBy: 'personAddressPostal', fetch: 'EAGER')]
  44. #[ORM\JoinColumn(nullable: false)]
  45. #[Assert\NotNull]
  46. #[Groups(['personaddresspostal', 'access_details_person', 'morals_list_person', 'report_card_person', 'report_card_guardians', 'access_details_guardians', 'student_registration_person', 'student_registration_guardians', 'accesses_list_person', 'student_list_person', 'education_student_next_year_access', 'guardians_list_person', 'all_accesses_list_person', 'teachers_list_person', 'adherent_list_person', 'personnels_list_person', 'ca_list_person', 'othercontact_list_person', 'access_duplicate_control_list_person', 'board_list_person', 'networkmanagers_list_person', 'payer_list_person', 'sepa_debit_mandate_person', 'student_list_guardians', 'equipment_availability_form_borrower', 'view_from_manager_create_person', 'online_registration_access_details_person', 'build_bills_access'])]
  47. private $addressPostal;
  48. /**
  49. * @var string
  50. */
  51. #[ORM\Column(type: 'string')]
  52. #[Assert\Type(type: 'string')]
  53. #[Assert\NotNull]
  54. #[Assert\Choice(callback: ['AppBundle\Enum\Core\AddressPostalTypeEnum', 'toArray'])]
  55. #[Groups(['personaddresspostal', 'access_details_person', 'report_card_person', 'report_card_guardians', 'student_registration_person', 'student_registration_guardians', 'accesses_list_person', 'student_list_person', 'education_student_next_year_access', 'guardians_list_person', 'teachers_list_person', 'adherent_list_person', 'personnels_list_person', 'morals_list_person', 'ca_list_person', 'othercontact_list_person', 'access_duplicate_control_list_person', 'board_list_person', 'networkmanagers_list_person', 'payer_list_person', 'sepa_debit_mandate_person', 'equipment_availability_form_borrower', 'view_from_manager_create_person', 'online_registration_access_details_person', 'build_bills_access'])]
  56. private $type;
  57. /**
  58. * @var string
  59. * @ExportSplitFields({"addressPostal.streetAddress","addressPostal.streetAddressSecond","addressPostal.streetAddressThird","addressPostal.postalCode","addressPostal.addressCity"})
  60. */
  61. #[Groups(['template'])]
  62. private $fullLabelTemplate;
  63. /**
  64. * @var string
  65. */
  66. #[Groups(['template'])]
  67. private $fullLabelExportPrincipalTemplate;
  68. /**
  69. * @var string
  70. */
  71. #[Groups(['template'])]
  72. private $fullLabelExportPrincipalStreetTemplate;
  73. /**
  74. * Sets id.
  75. *
  76. * @param int $id
  77. *
  78. * @return $this
  79. */
  80. public function setId($id)
  81. {
  82. $this->id = $id;
  83. return $this;
  84. }
  85. /**
  86. * Gets id.
  87. *
  88. * @return int
  89. */
  90. public function getId()
  91. {
  92. return $this->id;
  93. }
  94. /**
  95. * Sets person.
  96. *
  97. * @param Person $person
  98. *
  99. * @return $this
  100. */
  101. public function setPerson(Person $person)
  102. {
  103. $this->person = $person;
  104. return $this;
  105. }
  106. /**
  107. * Gets person.
  108. *
  109. * @return Person
  110. */
  111. public function getPerson()
  112. {
  113. return $this->person;
  114. }
  115. /**
  116. * Sets address postal.
  117. *
  118. * @param AddressPostal $addressPostal
  119. *
  120. * @return $this
  121. */
  122. public function setAddressPostal(AddressPostal $addressPostal)
  123. {
  124. $addressPostal->addPersonAddressPostal($this);
  125. $this->addressPostal = $addressPostal;
  126. return $this;
  127. }
  128. /**
  129. * Gets address postal.
  130. *
  131. * @return AddressPostal
  132. */
  133. public function getAddressPostal()
  134. {
  135. return $this->addressPostal;
  136. }
  137. /**
  138. * Sets type.
  139. *
  140. * @param string $type
  141. *
  142. * @return $this
  143. */
  144. public function setType($type)
  145. {
  146. $this->type = $type;
  147. return $this;
  148. }
  149. /**
  150. * Gets type.
  151. *
  152. * @return string
  153. */
  154. public function getType()
  155. {
  156. return $this->type;
  157. }
  158. /**
  159. * Gets full label.
  160. *
  161. * @return array
  162. */
  163. public function getFullLabelTemplate()
  164. {
  165. return [
  166. $this->getAddressPostal()->getStreetAddress(),
  167. $this->getAddressPostal()->getStreetAddressSecond(),
  168. $this->getAddressPostal()->getStreetAddressThird(),
  169. $this->getAddressPostal()->getPostalCode(),
  170. $this->getAddressPostal()->getAddressCity()
  171. ];
  172. }
  173. public function getFullLabelExportPrincipalTemplate(){
  174. $addressLabel = [];
  175. if($this->type === AddressPostalTypeEnum::ADDRESS_PRINCIPAL){
  176. $addressLabel = $this->getFullLabelTemplate();
  177. }
  178. return $addressLabel;
  179. }
  180. public function getFullLabelExportPrincipalStreetTemplate(){
  181. $addressLabel = [];
  182. $addressLabel[] = ['value' => $this->getAddressPostal()->getStreetAddress(), 'separator' => ' / '];
  183. $addressLabel[] = ['value' => $this->getAddressPostal()->getStreetAddressSecond(), 'separator' => ' / '];
  184. $addressLabel[] = ['value' => $this->getAddressPostal()->getStreetAddressThird(), 'separator' => ' / '];
  185. return $addressLabel;
  186. }
  187. }