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

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