vendor/sulu/sulu/src/Sulu/Bundle/ContactBundle/Entity/Contact.php line 29

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of Sulu.
  4. *
  5. * (c) Sulu GmbH
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Sulu\Bundle\ContactBundle\Entity;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use JMS\Serializer\Annotation\Accessor;
  14. use JMS\Serializer\Annotation\Exclude;
  15. use JMS\Serializer\Annotation\Expose;
  16. use JMS\Serializer\Annotation\Groups;
  17. use JMS\Serializer\Annotation\SerializedName;
  18. use JMS\Serializer\Annotation\Type;
  19. use JMS\Serializer\Annotation\VirtualProperty;
  20. use Sulu\Bundle\CategoryBundle\Entity\CategoryInterface;
  21. use Sulu\Bundle\CoreBundle\Entity\ApiEntity;
  22. use Sulu\Bundle\MediaBundle\Entity\MediaInterface;
  23. use Sulu\Bundle\TagBundle\Tag\TagInterface;
  24. use Sulu\Component\Security\Authentication\UserInterface;
  25. class Contact extends ApiEntity implements ContactInterface
  26. {
  27. /**
  28. * @var int
  29. */
  30. #[Expose]
  31. #[Groups(['frontend', 'partialContact', 'fullContact'])]
  32. protected $id;
  33. /**
  34. * @var string
  35. */
  36. protected $firstName;
  37. /**
  38. * @var string|null
  39. */
  40. protected $middleName;
  41. /**
  42. * @var string
  43. */
  44. protected $lastName;
  45. /**
  46. * @var ContactTitle|null
  47. */
  48. protected $title;
  49. /**
  50. * @var \DateTime|null
  51. */
  52. protected $birthday;
  53. /**
  54. * @var \DateTime
  55. */
  56. protected $created;
  57. /**
  58. * @var \DateTime
  59. */
  60. protected $changed;
  61. /**
  62. * @var Collection<int, ContactLocale>
  63. */
  64. protected $locales;
  65. /**
  66. * @var UserInterface|null
  67. */
  68. #[Groups(['fullContact'])]
  69. protected $changer;
  70. /**
  71. * @var UserInterface|null
  72. */
  73. #[Groups(['fullContact'])]
  74. protected $creator;
  75. /**
  76. * @var string|null
  77. */
  78. protected $note;
  79. /**
  80. * @var Collection<int, Note>
  81. *
  82. * @deprecated
  83. */
  84. #[Groups(['fullContact'])]
  85. protected $notes;
  86. /**
  87. * @var Collection<int, Email>
  88. */
  89. #[Groups(['fullContact', 'partialContact'])]
  90. protected $emails;
  91. /**
  92. * @var Collection<int, Phone>
  93. */
  94. #[Groups(['fullContact'])]
  95. protected $phones;
  96. /**
  97. * @var Collection<int, Fax>
  98. */
  99. #[Groups(['fullContact'])]
  100. protected $faxes;
  101. /**
  102. * @var Collection<int, SocialMediaProfile>
  103. */
  104. #[Groups(['fullContact'])]
  105. protected $socialMediaProfiles;
  106. /**
  107. * @var int|null
  108. */
  109. protected $formOfAddress;
  110. /**
  111. * @var string|null
  112. */
  113. protected $salutation;
  114. /**
  115. * @var Collection<int, TagInterface>
  116. */
  117. #[Accessor(getter: 'getTagNameArray')]
  118. #[Groups(['fullContact'])]
  119. #[Type('array')]
  120. protected $tags;
  121. /**
  122. * main account.
  123. *
  124. * @var string
  125. */
  126. #[Accessor(getter: 'getMainAccount')]
  127. #[Groups(['fullContact'])]
  128. protected $account;
  129. /**
  130. * main account.
  131. *
  132. * @var string
  133. */
  134. #[Accessor(getter: 'getAddresses')]
  135. #[Groups(['fullContact'])]
  136. protected $addresses;
  137. /**
  138. * @var Collection<int, AccountContact>
  139. */
  140. #[Exclude]
  141. protected $accountContacts;
  142. /**
  143. * @var bool|null
  144. */
  145. protected $newsletter;
  146. /**
  147. * @var string|null
  148. */
  149. protected $gender;
  150. /**
  151. * @var string|null
  152. */
  153. protected $mainEmail;
  154. /**
  155. * @var string|null
  156. */
  157. protected $mainPhone;
  158. /**
  159. * @var string|null
  160. */
  161. protected $mainFax;
  162. /**
  163. * @var string|null
  164. */
  165. protected $mainUrl;
  166. /**
  167. * @var Collection<int, ContactAddress>
  168. */
  169. #[Exclude]
  170. protected $contactAddresses;
  171. /**
  172. * @var Collection<int, MediaInterface>
  173. */
  174. #[Groups(['fullContact'])]
  175. protected $medias;
  176. /**
  177. * @var Collection<int, CategoryInterface>
  178. */
  179. #[Groups(['fullContact'])]
  180. protected $categories;
  181. /**
  182. * @var Collection<int, Url>
  183. */
  184. #[Groups(['fullContact'])]
  185. protected $urls;
  186. /**
  187. * @var Collection<int, BankAccount>
  188. */
  189. #[Groups(['fullContact'])]
  190. protected $bankAccounts;
  191. /**
  192. * @var MediaInterface|null
  193. */
  194. protected $avatar;
  195. /**
  196. * Constructor.
  197. */
  198. public function __construct()
  199. {
  200. $this->locales = new ArrayCollection();
  201. $this->notes = new ArrayCollection();
  202. $this->emails = new ArrayCollection();
  203. $this->urls = new ArrayCollection();
  204. $this->addresses = new ArrayCollection();
  205. $this->phones = new ArrayCollection();
  206. $this->faxes = new ArrayCollection();
  207. $this->socialMediaProfiles = new ArrayCollection();
  208. $this->tags = new ArrayCollection();
  209. $this->categories = new ArrayCollection();
  210. $this->accountContacts = new ArrayCollection();
  211. $this->contactAddresses = new ArrayCollection();
  212. $this->bankAccounts = new ArrayCollection();
  213. $this->medias = new ArrayCollection();
  214. }
  215. public function getId()
  216. {
  217. return $this->id;
  218. }
  219. public function setFirstName($firstName)
  220. {
  221. $this->firstName = $firstName;
  222. return $this;
  223. }
  224. public function getFirstName()
  225. {
  226. return $this->firstName;
  227. }
  228. public function setMiddleName($middleName)
  229. {
  230. $this->middleName = $middleName;
  231. return $this;
  232. }
  233. /**
  234. * @return string|null
  235. */
  236. public function getMiddleName()
  237. {
  238. return $this->middleName;
  239. }
  240. public function setLastName($lastName)
  241. {
  242. $this->lastName = $lastName;
  243. return $this;
  244. }
  245. public function setAvatar($avatar)
  246. {
  247. $this->avatar = $avatar;
  248. }
  249. public function getLastName()
  250. {
  251. return $this->lastName;
  252. }
  253. /**
  254. * @return string
  255. */
  256. #[VirtualProperty]
  257. #[SerializedName('fullName')]
  258. public function getFullName()
  259. {
  260. return $this->firstName . ' ' . $this->lastName;
  261. }
  262. public function setTitle($title)
  263. {
  264. $this->title = $title;
  265. return $this;
  266. }
  267. public function getTitle()
  268. {
  269. return $this->title;
  270. }
  271. public function setPosition($position)
  272. {
  273. $mainAccountContact = $this->getMainAccountContact();
  274. if ($mainAccountContact) {
  275. $mainAccountContact->setPosition($position);
  276. }
  277. return $this;
  278. }
  279. #[VirtualProperty]
  280. #[Groups(['fullContact'])]
  281. public function getPosition()
  282. {
  283. $mainAccountContact = $this->getMainAccountContact();
  284. if ($mainAccountContact) {
  285. return $mainAccountContact->getPosition();
  286. }
  287. return null;
  288. }
  289. public function setBirthday($birthday)
  290. {
  291. $this->birthday = $birthday;
  292. return $this;
  293. }
  294. public function getBirthday()
  295. {
  296. return $this->birthday;
  297. }
  298. public function getCreated()
  299. {
  300. return $this->created;
  301. }
  302. public function getChanged()
  303. {
  304. return $this->changed;
  305. }
  306. public function addLocale(ContactLocale $locale)
  307. {
  308. $this->locales[] = $locale;
  309. return $this;
  310. }
  311. public function removeLocale(ContactLocale $locale)
  312. {
  313. $this->locales->removeElement($locale);
  314. }
  315. public function getLocales()
  316. {
  317. return $this->locales;
  318. }
  319. /**
  320. * Set changer.
  321. *
  322. * @return Contact
  323. */
  324. public function setChanger(?UserInterface $changer = null)
  325. {
  326. $this->changer = $changer;
  327. return $this;
  328. }
  329. public function getChanger()
  330. {
  331. return $this->changer;
  332. }
  333. /**
  334. * Set creator.
  335. *
  336. * @return Contact
  337. */
  338. public function setCreator(?UserInterface $creator = null)
  339. {
  340. $this->creator = $creator;
  341. return $this;
  342. }
  343. public function getCreator()
  344. {
  345. return $this->creator;
  346. }
  347. public function setNote(?string $note): ContactInterface
  348. {
  349. $this->note = $note;
  350. return $this;
  351. }
  352. public function getNote(): ?string
  353. {
  354. return $this->note;
  355. }
  356. public function addNote(Note $note)
  357. {
  358. $this->notes[] = $note;
  359. return $this;
  360. }
  361. public function removeNote(Note $note)
  362. {
  363. $this->notes->removeElement($note);
  364. }
  365. public function getNotes()
  366. {
  367. return $this->notes;
  368. }
  369. public function addEmail(Email $email)
  370. {
  371. $this->emails[] = $email;
  372. return $this;
  373. }
  374. public function removeEmail(Email $email)
  375. {
  376. $this->emails->removeElement($email);
  377. }
  378. public function getEmails()
  379. {
  380. return $this->emails;
  381. }
  382. public function addPhone(Phone $phone)
  383. {
  384. $this->phones[] = $phone;
  385. return $this;
  386. }
  387. public function removePhone(Phone $phone)
  388. {
  389. $this->phones->removeElement($phone);
  390. }
  391. public function getPhones()
  392. {
  393. return $this->phones;
  394. }
  395. public function addFax(Fax $fax)
  396. {
  397. $this->faxes[] = $fax;
  398. return $this;
  399. }
  400. public function removeFax(Fax $fax)
  401. {
  402. $this->faxes->removeElement($fax);
  403. }
  404. public function getFaxes()
  405. {
  406. return $this->faxes;
  407. }
  408. public function addSocialMediaProfile(SocialMediaProfile $socialMediaProfile)
  409. {
  410. $this->socialMediaProfiles[] = $socialMediaProfile;
  411. return $this;
  412. }
  413. public function removeSocialMediaProfile(SocialMediaProfile $socialMediaProfile)
  414. {
  415. $this->socialMediaProfiles->removeElement($socialMediaProfile);
  416. }
  417. public function getSocialMediaProfiles()
  418. {
  419. return $this->socialMediaProfiles;
  420. }
  421. public function addUrl(Url $url)
  422. {
  423. $this->urls[] = $url;
  424. return $this;
  425. }
  426. public function removeUrl(Url $url)
  427. {
  428. $this->urls->removeElement($url);
  429. }
  430. public function getUrls()
  431. {
  432. return $this->urls;
  433. }
  434. public function setFormOfAddress($formOfAddress)
  435. {
  436. $this->formOfAddress = $formOfAddress;
  437. return $this;
  438. }
  439. public function getFormOfAddress()
  440. {
  441. return $this->formOfAddress;
  442. }
  443. public function setSalutation($salutation)
  444. {
  445. $this->salutation = $salutation;
  446. return $this;
  447. }
  448. public function getSalutation()
  449. {
  450. return $this->salutation;
  451. }
  452. public function addTag(TagInterface $tag)
  453. {
  454. $this->tags[] = $tag;
  455. return $this;
  456. }
  457. public function removeTag(TagInterface $tag)
  458. {
  459. $this->tags->removeElement($tag);
  460. }
  461. public function getTags()
  462. {
  463. return $this->tags;
  464. }
  465. public function getTagNameArray()
  466. {
  467. $tags = [];
  468. foreach ($this->getTags() as $tag) {
  469. $tags[] = $tag->getName();
  470. }
  471. return $tags;
  472. }
  473. public function addAccountContact(AccountContact $accountContact)
  474. {
  475. $this->accountContacts[] = $accountContact;
  476. return $this;
  477. }
  478. public function removeAccountContact(AccountContact $accountContact)
  479. {
  480. $this->accountContacts->removeElement($accountContact);
  481. }
  482. public function getAccountContacts()
  483. {
  484. return $this->accountContacts;
  485. }
  486. public function setNewsletter($newsletter)
  487. {
  488. $this->newsletter = $newsletter;
  489. return $this;
  490. }
  491. /**
  492. * @return bool|null
  493. */
  494. public function getNewsletter()
  495. {
  496. return $this->newsletter;
  497. }
  498. public function setGender($gender)
  499. {
  500. $this->gender = $gender;
  501. return $this;
  502. }
  503. public function getGender()
  504. {
  505. return $this->gender;
  506. }
  507. public function getMainAccount()
  508. {
  509. $mainAccountContact = $this->getMainAccountContact();
  510. if (!\is_null($mainAccountContact)) {
  511. return $mainAccountContact->getAccount();
  512. }
  513. return null;
  514. }
  515. /**
  516. * Returns main account contact.
  517. */
  518. protected function getMainAccountContact()
  519. {
  520. $accountContacts = $this->getAccountContacts();
  521. /** @var AccountContact $accountContact */
  522. foreach ($accountContacts as $accountContact) {
  523. if ($accountContact->getMain()) {
  524. return $accountContact;
  525. }
  526. }
  527. return null;
  528. }
  529. public function getAddresses()
  530. {
  531. $contactAddresses = $this->getContactAddresses();
  532. $addresses = [];
  533. /** @var ContactAddress $contactAddress */
  534. foreach ($contactAddresses as $contactAddress) {
  535. $address = $contactAddress->getAddress();
  536. $address->setPrimaryAddress($contactAddress->getMain());
  537. $addresses[] = $address;
  538. }
  539. return $addresses;
  540. }
  541. public function setMainEmail($mainEmail)
  542. {
  543. $this->mainEmail = $mainEmail;
  544. return $this;
  545. }
  546. public function getMainEmail()
  547. {
  548. return $this->mainEmail;
  549. }
  550. public function setMainPhone($mainPhone)
  551. {
  552. $this->mainPhone = $mainPhone;
  553. return $this;
  554. }
  555. public function getMainPhone()
  556. {
  557. return $this->mainPhone;
  558. }
  559. public function setMainFax($mainFax)
  560. {
  561. $this->mainFax = $mainFax;
  562. return $this;
  563. }
  564. public function getMainFax()
  565. {
  566. return $this->mainFax;
  567. }
  568. public function setMainUrl($mainUrl)
  569. {
  570. $this->mainUrl = $mainUrl;
  571. return $this;
  572. }
  573. public function getMainUrl()
  574. {
  575. return $this->mainUrl;
  576. }
  577. public function addContactAddress(ContactAddress $contactAddress)
  578. {
  579. $this->contactAddresses[] = $contactAddress;
  580. return $this;
  581. }
  582. public function removeContactAddress(ContactAddress $contactAddress)
  583. {
  584. $this->contactAddresses->removeElement($contactAddress);
  585. }
  586. public function getContactAddresses()
  587. {
  588. return $this->contactAddresses;
  589. }
  590. public function getMainAddress()
  591. {
  592. $contactAddresses = $this->getContactAddresses();
  593. /** @var ContactAddress $contactAddress */
  594. foreach ($contactAddresses as $contactAddress) {
  595. if ($contactAddress->getMain()) {
  596. return $contactAddress->getAddress();
  597. }
  598. }
  599. return null;
  600. }
  601. public function addMedia(MediaInterface $media)
  602. {
  603. $this->medias[] = $media;
  604. return $this;
  605. }
  606. public function removeMedia(MediaInterface $media)
  607. {
  608. $this->medias->removeElement($media);
  609. }
  610. public function getMedias()
  611. {
  612. return $this->medias;
  613. }
  614. public function getAvatar()
  615. {
  616. return $this->avatar;
  617. }
  618. public function addCategory(CategoryInterface $category)
  619. {
  620. $this->categories[] = $category;
  621. return $this;
  622. }
  623. public function removeCategory(CategoryInterface $category)
  624. {
  625. $this->categories->removeElement($category);
  626. }
  627. public function getCategories()
  628. {
  629. return $this->categories;
  630. }
  631. public function addBankAccount(BankAccount $bankAccount)
  632. {
  633. $this->bankAccounts[] = $bankAccount;
  634. return $this;
  635. }
  636. public function removeBankAccount(BankAccount $bankAccounts)
  637. {
  638. $this->bankAccounts->removeElement($bankAccounts);
  639. }
  640. public function getBankAccounts()
  641. {
  642. return $this->bankAccounts;
  643. }
  644. /**
  645. * @return $this
  646. */
  647. public function setCreated(\DateTime $created)
  648. {
  649. $this->created = $created;
  650. return $this;
  651. }
  652. /**
  653. * @return $this
  654. */
  655. public function setChanged(\DateTime $changed)
  656. {
  657. $this->changed = $changed;
  658. return $this;
  659. }
  660. /**
  661. * @return mixed[]
  662. */
  663. public function toArray()
  664. {
  665. return [
  666. 'id' => $this->getId(),
  667. 'firstName' => $this->getFirstName(),
  668. 'middleName' => $this->getMiddleName(),
  669. 'lastName' => $this->getLastName(),
  670. 'title' => $this->getTitle(),
  671. 'position' => $this->getPosition(),
  672. 'birthday' => $this->getBirthday(),
  673. 'created' => $this->getCreated(),
  674. 'changed' => $this->getChanged(),
  675. ];
  676. }
  677. }