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

  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|null
  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|null
  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.     /**
  251.      * @return string|null
  252.      */
  253.     public function getMiddleName()
  254.     {
  255.         return $this->middleName;
  256.     }
  257.     public function setLastName($lastName)
  258.     {
  259.         $this->lastName $lastName;
  260.         return $this;
  261.     }
  262.     public function setAvatar($avatar)
  263.     {
  264.         $this->avatar $avatar;
  265.     }
  266.     public function getLastName()
  267.     {
  268.         return $this->lastName;
  269.     }
  270.     /**
  271.      * @VirtualProperty
  272.      * @SerializedName("fullName")
  273.      *
  274.      * @return string
  275.      */
  276.     public function getFullName()
  277.     {
  278.         return $this->firstName ' ' $this->lastName;
  279.     }
  280.     public function setTitle($title)
  281.     {
  282.         $this->title $title;
  283.         return $this;
  284.     }
  285.     public function getTitle()
  286.     {
  287.         return $this->title;
  288.     }
  289.     public function setPosition($position)
  290.     {
  291.         $mainAccountContact $this->getMainAccountContact();
  292.         if ($mainAccountContact) {
  293.             $mainAccountContact->setPosition($position);
  294.         }
  295.         return $this;
  296.     }
  297.     /**
  298.      * @VirtualProperty
  299.      * @Groups({"fullContact"})
  300.      */
  301.     public function getPosition()
  302.     {
  303.         $mainAccountContact $this->getMainAccountContact();
  304.         if ($mainAccountContact) {
  305.             return $mainAccountContact->getPosition();
  306.         }
  307.         return null;
  308.     }
  309.     public function setBirthday($birthday)
  310.     {
  311.         $this->birthday $birthday;
  312.         return $this;
  313.     }
  314.     public function getBirthday()
  315.     {
  316.         return $this->birthday;
  317.     }
  318.     public function getCreated()
  319.     {
  320.         return $this->created;
  321.     }
  322.     public function getChanged()
  323.     {
  324.         return $this->changed;
  325.     }
  326.     public function addLocale(ContactLocale $locale)
  327.     {
  328.         $this->locales[] = $locale;
  329.         return $this;
  330.     }
  331.     public function removeLocale(ContactLocale $locale)
  332.     {
  333.         $this->locales->removeElement($locale);
  334.     }
  335.     public function getLocales()
  336.     {
  337.         return $this->locales;
  338.     }
  339.     /**
  340.      * Set changer.
  341.      *
  342.      * @param UserInterface $changer
  343.      *
  344.      * @return Contact
  345.      */
  346.     public function setChanger(UserInterface $changer null)
  347.     {
  348.         $this->changer $changer;
  349.         return $this;
  350.     }
  351.     public function getChanger()
  352.     {
  353.         return $this->changer;
  354.     }
  355.     /**
  356.      * Set creator.
  357.      *
  358.      * @param UserInterface $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. }