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