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. /**
  216. * @return int
  217. */
  218. public function getId()
  219. {
  220. return $this->id;
  221. }
  222. /**
  223. * @param string $firstName
  224. *
  225. * @return $this
  226. */
  227. public function setFirstName($firstName)
  228. {
  229. $this->firstName = $firstName;
  230. return $this;
  231. }
  232. /**
  233. * @return string
  234. */
  235. public function getFirstName()
  236. {
  237. return $this->firstName;
  238. }
  239. /**
  240. * @param string|null $middleName
  241. *
  242. * @return $this
  243. */
  244. public function setMiddleName($middleName)
  245. {
  246. $this->middleName = $middleName;
  247. return $this;
  248. }
  249. /**
  250. * @return string|null
  251. */
  252. public function getMiddleName()
  253. {
  254. return $this->middleName;
  255. }
  256. /**
  257. * @param string $lastName
  258. *
  259. * @return $this
  260. */
  261. public function setLastName($lastName)
  262. {
  263. $this->lastName = $lastName;
  264. return $this;
  265. }
  266. public function setAvatar($avatar)
  267. {
  268. $this->avatar = $avatar;
  269. }
  270. /**
  271. * @return string
  272. */
  273. public function getLastName()
  274. {
  275. return $this->lastName;
  276. }
  277. /**
  278. * @return string
  279. */
  280. #[VirtualProperty]
  281. #[SerializedName('fullName')]
  282. public function getFullName()
  283. {
  284. return $this->firstName . ' ' . $this->lastName;
  285. }
  286. public function setTitle($title)
  287. {
  288. $this->title = $title;
  289. return $this;
  290. }
  291. public function getTitle()
  292. {
  293. return $this->title;
  294. }
  295. public function setPosition($position)
  296. {
  297. $mainAccountContact = $this->getMainAccountContact();
  298. if ($mainAccountContact) {
  299. $mainAccountContact->setPosition($position);
  300. }
  301. return $this;
  302. }
  303. #[VirtualProperty]
  304. #[Groups(['fullContact'])]
  305. public function getPosition()
  306. {
  307. $mainAccountContact = $this->getMainAccountContact();
  308. if ($mainAccountContact) {
  309. return $mainAccountContact->getPosition();
  310. }
  311. return null;
  312. }
  313. public function setBirthday($birthday)
  314. {
  315. $this->birthday = $birthday;
  316. return $this;
  317. }
  318. public function getBirthday()
  319. {
  320. return $this->birthday;
  321. }
  322. public function getCreated()
  323. {
  324. return $this->created;
  325. }
  326. public function getChanged()
  327. {
  328. return $this->changed;
  329. }
  330. public function addLocale(ContactLocale $locale)
  331. {
  332. $this->locales[] = $locale;
  333. return $this;
  334. }
  335. public function removeLocale(ContactLocale $locale)
  336. {
  337. $this->locales->removeElement($locale);
  338. }
  339. public function getLocales()
  340. {
  341. return $this->locales;
  342. }
  343. /**
  344. * Set changer.
  345. *
  346. * @return Contact
  347. */
  348. public function setChanger(?UserInterface $changer = null)
  349. {
  350. $this->changer = $changer;
  351. return $this;
  352. }
  353. public function getChanger()
  354. {
  355. return $this->changer;
  356. }
  357. /**
  358. * Set creator.
  359. *
  360. * @return Contact
  361. */
  362. public function setCreator(?UserInterface $creator = null)
  363. {
  364. $this->creator = $creator;
  365. return $this;
  366. }
  367. public function getCreator()
  368. {
  369. return $this->creator;
  370. }
  371. public function setNote(?string $note): ContactInterface
  372. {
  373. $this->note = $note;
  374. return $this;
  375. }
  376. public function getNote(): ?string
  377. {
  378. return $this->note;
  379. }
  380. public function addNote(Note $note)
  381. {
  382. $this->notes[] = $note;
  383. return $this;
  384. }
  385. public function removeNote(Note $note)
  386. {
  387. $this->notes->removeElement($note);
  388. }
  389. public function getNotes()
  390. {
  391. return $this->notes;
  392. }
  393. public function addEmail(Email $email)
  394. {
  395. $this->emails[] = $email;
  396. return $this;
  397. }
  398. public function removeEmail(Email $email)
  399. {
  400. $this->emails->removeElement($email);
  401. }
  402. public function getEmails()
  403. {
  404. return $this->emails;
  405. }
  406. public function addPhone(Phone $phone)
  407. {
  408. $this->phones[] = $phone;
  409. return $this;
  410. }
  411. public function removePhone(Phone $phone)
  412. {
  413. $this->phones->removeElement($phone);
  414. }
  415. public function getPhones()
  416. {
  417. return $this->phones;
  418. }
  419. public function addFax(Fax $fax)
  420. {
  421. $this->faxes[] = $fax;
  422. return $this;
  423. }
  424. public function removeFax(Fax $fax)
  425. {
  426. $this->faxes->removeElement($fax);
  427. }
  428. public function getFaxes()
  429. {
  430. return $this->faxes;
  431. }
  432. public function addSocialMediaProfile(SocialMediaProfile $socialMediaProfile)
  433. {
  434. $this->socialMediaProfiles[] = $socialMediaProfile;
  435. return $this;
  436. }
  437. public function removeSocialMediaProfile(SocialMediaProfile $socialMediaProfile)
  438. {
  439. $this->socialMediaProfiles->removeElement($socialMediaProfile);
  440. }
  441. public function getSocialMediaProfiles()
  442. {
  443. return $this->socialMediaProfiles;
  444. }
  445. public function addUrl(Url $url)
  446. {
  447. $this->urls[] = $url;
  448. return $this;
  449. }
  450. public function removeUrl(Url $url)
  451. {
  452. $this->urls->removeElement($url);
  453. }
  454. public function getUrls()
  455. {
  456. return $this->urls;
  457. }
  458. public function setFormOfAddress($formOfAddress)
  459. {
  460. $this->formOfAddress = $formOfAddress;
  461. return $this;
  462. }
  463. public function getFormOfAddress()
  464. {
  465. return $this->formOfAddress;
  466. }
  467. public function setSalutation($salutation)
  468. {
  469. $this->salutation = $salutation;
  470. return $this;
  471. }
  472. public function getSalutation()
  473. {
  474. return $this->salutation;
  475. }
  476. public function addTag(TagInterface $tag)
  477. {
  478. $this->tags[] = $tag;
  479. return $this;
  480. }
  481. public function removeTag(TagInterface $tag)
  482. {
  483. $this->tags->removeElement($tag);
  484. }
  485. public function getTags()
  486. {
  487. return $this->tags;
  488. }
  489. public function getTagNameArray()
  490. {
  491. $tags = [];
  492. foreach ($this->getTags() as $tag) {
  493. $tags[] = $tag->getName();
  494. }
  495. return $tags;
  496. }
  497. public function addAccountContact(AccountContact $accountContact)
  498. {
  499. $this->accountContacts[] = $accountContact;
  500. return $this;
  501. }
  502. public function removeAccountContact(AccountContact $accountContact)
  503. {
  504. $this->accountContacts->removeElement($accountContact);
  505. }
  506. public function getAccountContacts()
  507. {
  508. return $this->accountContacts;
  509. }
  510. public function setNewsletter($newsletter)
  511. {
  512. $this->newsletter = $newsletter;
  513. return $this;
  514. }
  515. /**
  516. * @return bool|null
  517. */
  518. public function getNewsletter()
  519. {
  520. return $this->newsletter;
  521. }
  522. public function setGender($gender)
  523. {
  524. $this->gender = $gender;
  525. return $this;
  526. }
  527. public function getGender()
  528. {
  529. return $this->gender;
  530. }
  531. public function getMainAccount()
  532. {
  533. $mainAccountContact = $this->getMainAccountContact();
  534. if (!\is_null($mainAccountContact)) {
  535. return $mainAccountContact->getAccount();
  536. }
  537. return null;
  538. }
  539. /**
  540. * Returns main account contact.
  541. */
  542. protected function getMainAccountContact()
  543. {
  544. $accountContacts = $this->getAccountContacts();
  545. /** @var AccountContact $accountContact */
  546. foreach ($accountContacts as $accountContact) {
  547. if ($accountContact->getMain()) {
  548. return $accountContact;
  549. }
  550. }
  551. return null;
  552. }
  553. public function getAddresses()
  554. {
  555. $contactAddresses = $this->getContactAddresses();
  556. $addresses = [];
  557. /** @var ContactAddress $contactAddress */
  558. foreach ($contactAddresses as $contactAddress) {
  559. $address = $contactAddress->getAddress();
  560. $address->setPrimaryAddress($contactAddress->getMain());
  561. $addresses[] = $address;
  562. }
  563. return $addresses;
  564. }
  565. public function setMainEmail($mainEmail)
  566. {
  567. $this->mainEmail = $mainEmail;
  568. return $this;
  569. }
  570. public function getMainEmail()
  571. {
  572. return $this->mainEmail;
  573. }
  574. public function setMainPhone($mainPhone)
  575. {
  576. $this->mainPhone = $mainPhone;
  577. return $this;
  578. }
  579. public function getMainPhone()
  580. {
  581. return $this->mainPhone;
  582. }
  583. public function setMainFax($mainFax)
  584. {
  585. $this->mainFax = $mainFax;
  586. return $this;
  587. }
  588. public function getMainFax()
  589. {
  590. return $this->mainFax;
  591. }
  592. public function setMainUrl($mainUrl)
  593. {
  594. $this->mainUrl = $mainUrl;
  595. return $this;
  596. }
  597. public function getMainUrl()
  598. {
  599. return $this->mainUrl;
  600. }
  601. public function addContactAddress(ContactAddress $contactAddress)
  602. {
  603. $this->contactAddresses[] = $contactAddress;
  604. return $this;
  605. }
  606. public function removeContactAddress(ContactAddress $contactAddress)
  607. {
  608. $this->contactAddresses->removeElement($contactAddress);
  609. }
  610. public function getContactAddresses()
  611. {
  612. return $this->contactAddresses;
  613. }
  614. public function getMainAddress()
  615. {
  616. $contactAddresses = $this->getContactAddresses();
  617. /** @var ContactAddress $contactAddress */
  618. foreach ($contactAddresses as $contactAddress) {
  619. if ($contactAddress->getMain()) {
  620. return $contactAddress->getAddress();
  621. }
  622. }
  623. return null;
  624. }
  625. public function addMedia(MediaInterface $media)
  626. {
  627. $this->medias[] = $media;
  628. return $this;
  629. }
  630. public function removeMedia(MediaInterface $media)
  631. {
  632. $this->medias->removeElement($media);
  633. }
  634. public function getMedias()
  635. {
  636. return $this->medias;
  637. }
  638. public function getAvatar()
  639. {
  640. return $this->avatar;
  641. }
  642. public function addCategory(CategoryInterface $category)
  643. {
  644. $this->categories[] = $category;
  645. return $this;
  646. }
  647. public function removeCategory(CategoryInterface $category)
  648. {
  649. $this->categories->removeElement($category);
  650. }
  651. public function getCategories()
  652. {
  653. return $this->categories;
  654. }
  655. public function addBankAccount(BankAccount $bankAccount)
  656. {
  657. $this->bankAccounts[] = $bankAccount;
  658. return $this;
  659. }
  660. public function removeBankAccount(BankAccount $bankAccounts)
  661. {
  662. $this->bankAccounts->removeElement($bankAccounts);
  663. }
  664. public function getBankAccounts()
  665. {
  666. return $this->bankAccounts;
  667. }
  668. /**
  669. * @return $this
  670. */
  671. public function setCreated(\DateTime $created)
  672. {
  673. $this->created = $created;
  674. return $this;
  675. }
  676. /**
  677. * @return $this
  678. */
  679. public function setChanged(\DateTime $changed)
  680. {
  681. $this->changed = $changed;
  682. return $this;
  683. }
  684. /**
  685. * @return mixed[]
  686. */
  687. public function toArray()
  688. {
  689. return [
  690. 'id' => $this->getId(),
  691. 'firstName' => $this->getFirstName(),
  692. 'middleName' => $this->getMiddleName(),
  693. 'lastName' => $this->getLastName(),
  694. 'title' => $this->getTitle(),
  695. 'position' => $this->getPosition(),
  696. 'birthday' => $this->getBirthday(),
  697. 'created' => $this->getCreated(),
  698. 'changed' => $this->getChanged(),
  699. ];
  700. }
  701. }