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.      * @param UserInterface $changer
  340.      *
  341.      * @return Contact
  342.      */
  343.     public function setChanger(UserInterface $changer null)
  344.     {
  345.         $this->changer $changer;
  346.         return $this;
  347.     }
  348.     public function getChanger()
  349.     {
  350.         return $this->changer;
  351.     }
  352.     /**
  353.      * Set creator.
  354.      *
  355.      * @param UserInterface $creator
  356.      *
  357.      * @return Contact
  358.      */
  359.     public function setCreator(UserInterface $creator null)
  360.     {
  361.         $this->creator $creator;
  362.         return $this;
  363.     }
  364.     public function getCreator()
  365.     {
  366.         return $this->creator;
  367.     }
  368.     public function setNote(?string $note): ContactInterface
  369.     {
  370.         $this->note $note;
  371.         return $this;
  372.     }
  373.     public function getNote(): ?string
  374.     {
  375.         return $this->note;
  376.     }
  377.     public function addNote(Note $note)
  378.     {
  379.         $this->notes[] = $note;
  380.         return $this;
  381.     }
  382.     public function removeNote(Note $note)
  383.     {
  384.         $this->notes->removeElement($note);
  385.     }
  386.     public function getNotes()
  387.     {
  388.         return $this->notes;
  389.     }
  390.     public function addEmail(Email $email)
  391.     {
  392.         $this->emails[] = $email;
  393.         return $this;
  394.     }
  395.     public function removeEmail(Email $email)
  396.     {
  397.         $this->emails->removeElement($email);
  398.     }
  399.     public function getEmails()
  400.     {
  401.         return $this->emails;
  402.     }
  403.     public function addPhone(Phone $phone)
  404.     {
  405.         $this->phones[] = $phone;
  406.         return $this;
  407.     }
  408.     public function removePhone(Phone $phone)
  409.     {
  410.         $this->phones->removeElement($phone);
  411.     }
  412.     public function getPhones()
  413.     {
  414.         return $this->phones;
  415.     }
  416.     public function addFax(Fax $fax)
  417.     {
  418.         $this->faxes[] = $fax;
  419.         return $this;
  420.     }
  421.     public function removeFax(Fax $fax)
  422.     {
  423.         $this->faxes->removeElement($fax);
  424.     }
  425.     public function getFaxes()
  426.     {
  427.         return $this->faxes;
  428.     }
  429.     public function addSocialMediaProfile(SocialMediaProfile $socialMediaProfile)
  430.     {
  431.         $this->socialMediaProfiles[] = $socialMediaProfile;
  432.         return $this;
  433.     }
  434.     public function removeSocialMediaProfile(SocialMediaProfile $socialMediaProfile)
  435.     {
  436.         $this->socialMediaProfiles->removeElement($socialMediaProfile);
  437.     }
  438.     public function getSocialMediaProfiles()
  439.     {
  440.         return $this->socialMediaProfiles;
  441.     }
  442.     public function addUrl(Url $url)
  443.     {
  444.         $this->urls[] = $url;
  445.         return $this;
  446.     }
  447.     public function removeUrl(Url $url)
  448.     {
  449.         $this->urls->removeElement($url);
  450.     }
  451.     public function getUrls()
  452.     {
  453.         return $this->urls;
  454.     }
  455.     public function setFormOfAddress($formOfAddress)
  456.     {
  457.         $this->formOfAddress $formOfAddress;
  458.         return $this;
  459.     }
  460.     public function getFormOfAddress()
  461.     {
  462.         return $this->formOfAddress;
  463.     }
  464.     public function setSalutation($salutation)
  465.     {
  466.         $this->salutation $salutation;
  467.         return $this;
  468.     }
  469.     public function getSalutation()
  470.     {
  471.         return $this->salutation;
  472.     }
  473.     public function addTag(TagInterface $tag)
  474.     {
  475.         $this->tags[] = $tag;
  476.         return $this;
  477.     }
  478.     public function removeTag(TagInterface $tag)
  479.     {
  480.         $this->tags->removeElement($tag);
  481.     }
  482.     public function getTags()
  483.     {
  484.         return $this->tags;
  485.     }
  486.     public function getTagNameArray()
  487.     {
  488.         $tags = [];
  489.         foreach ($this->getTags() as $tag) {
  490.             $tags[] = $tag->getName();
  491.         }
  492.         return $tags;
  493.     }
  494.     public function addAccountContact(AccountContact $accountContact)
  495.     {
  496.         $this->accountContacts[] = $accountContact;
  497.         return $this;
  498.     }
  499.     public function removeAccountContact(AccountContact $accountContact)
  500.     {
  501.         $this->accountContacts->removeElement($accountContact);
  502.     }
  503.     public function getAccountContacts()
  504.     {
  505.         return $this->accountContacts;
  506.     }
  507.     public function setNewsletter($newsletter)
  508.     {
  509.         $this->newsletter $newsletter;
  510.         return $this;
  511.     }
  512.     public function getNewsletter()
  513.     {
  514.         return $this->newsletter;
  515.     }
  516.     public function setGender($gender)
  517.     {
  518.         $this->gender $gender;
  519.         return $this;
  520.     }
  521.     public function getGender()
  522.     {
  523.         return $this->gender;
  524.     }
  525.     public function getMainAccount()
  526.     {
  527.         $mainAccountContact $this->getMainAccountContact();
  528.         if (!\is_null($mainAccountContact)) {
  529.             return $mainAccountContact->getAccount();
  530.         }
  531.         return null;
  532.     }
  533.     /**
  534.      * Returns main account contact.
  535.      */
  536.     protected function getMainAccountContact()
  537.     {
  538.         $accountContacts $this->getAccountContacts();
  539.         /** @var AccountContact $accountContact */
  540.         foreach ($accountContacts as $accountContact) {
  541.             if ($accountContact->getMain()) {
  542.                 return $accountContact;
  543.             }
  544.         }
  545.         return null;
  546.     }
  547.     public function getAddresses()
  548.     {
  549.         $contactAddresses $this->getContactAddresses();
  550.         $addresses = [];
  551.         /** @var ContactAddress $contactAddress */
  552.         foreach ($contactAddresses as $contactAddress) {
  553.             $address $contactAddress->getAddress();
  554.             $address->setPrimaryAddress($contactAddress->getMain());
  555.             $addresses[] = $address;
  556.         }
  557.         return $addresses;
  558.     }
  559.     public function setMainEmail($mainEmail)
  560.     {
  561.         $this->mainEmail $mainEmail;
  562.         return $this;
  563.     }
  564.     public function getMainEmail()
  565.     {
  566.         return $this->mainEmail;
  567.     }
  568.     public function setMainPhone($mainPhone)
  569.     {
  570.         $this->mainPhone $mainPhone;
  571.         return $this;
  572.     }
  573.     public function getMainPhone()
  574.     {
  575.         return $this->mainPhone;
  576.     }
  577.     public function setMainFax($mainFax)
  578.     {
  579.         $this->mainFax $mainFax;
  580.         return $this;
  581.     }
  582.     public function getMainFax()
  583.     {
  584.         return $this->mainFax;
  585.     }
  586.     public function setMainUrl($mainUrl)
  587.     {
  588.         $this->mainUrl $mainUrl;
  589.         return $this;
  590.     }
  591.     public function getMainUrl()
  592.     {
  593.         return $this->mainUrl;
  594.     }
  595.     public function addContactAddress(ContactAddress $contactAddress)
  596.     {
  597.         $this->contactAddresses[] = $contactAddress;
  598.         return $this;
  599.     }
  600.     public function removeContactAddress(ContactAddress $contactAddress)
  601.     {
  602.         $this->contactAddresses->removeElement($contactAddress);
  603.     }
  604.     public function getContactAddresses()
  605.     {
  606.         return $this->contactAddresses;
  607.     }
  608.     public function getMainAddress()
  609.     {
  610.         $contactAddresses $this->getContactAddresses();
  611.         /** @var ContactAddress $contactAddress */
  612.         foreach ($contactAddresses as $contactAddress) {
  613.             if ($contactAddress->getMain()) {
  614.                 return $contactAddress->getAddress();
  615.             }
  616.         }
  617.         return null;
  618.     }
  619.     public function addMedia(MediaInterface $media)
  620.     {
  621.         $this->medias[] = $media;
  622.         return $this;
  623.     }
  624.     public function removeMedia(MediaInterface $media)
  625.     {
  626.         $this->medias->removeElement($media);
  627.     }
  628.     public function getMedias()
  629.     {
  630.         return $this->medias;
  631.     }
  632.     public function getAvatar()
  633.     {
  634.         return $this->avatar;
  635.     }
  636.     public function addCategory(CategoryInterface $category)
  637.     {
  638.         $this->categories[] = $category;
  639.         return $this;
  640.     }
  641.     public function removeCategory(CategoryInterface $category)
  642.     {
  643.         $this->categories->removeElement($category);
  644.     }
  645.     public function getCategories()
  646.     {
  647.         return $this->categories;
  648.     }
  649.     public function addBankAccount(BankAccount $bankAccount)
  650.     {
  651.         $this->bankAccounts[] = $bankAccount;
  652.         return $this;
  653.     }
  654.     public function removeBankAccount(BankAccount $bankAccounts)
  655.     {
  656.         $this->bankAccounts->removeElement($bankAccounts);
  657.     }
  658.     public function getBankAccounts()
  659.     {
  660.         return $this->bankAccounts;
  661.     }
  662.     /**
  663.      * @return $this
  664.      */
  665.     public function setCreated(\DateTime $created)
  666.     {
  667.         $this->created $created;
  668.         return $this;
  669.     }
  670.     /**
  671.      * @return $this
  672.      */
  673.     public function setChanged(\DateTime $changed)
  674.     {
  675.         $this->changed $changed;
  676.         return $this;
  677.     }
  678.     /**
  679.      * @return mixed[]
  680.      */
  681.     public function toArray()
  682.     {
  683.         return [
  684.             'id' => $this->getId(),
  685.             'firstName' => $this->getFirstName(),
  686.             'middleName' => $this->getMiddleName(),
  687.             'lastName' => $this->getLastName(),
  688.             'title' => $this->getTitle(),
  689.             'position' => $this->getPosition(),
  690.             'birthday' => $this->getBirthday(),
  691.             'created' => $this->getCreated(),
  692.             'changed' => $this->getChanged(),
  693.         ];
  694.     }
  695. }