vendor/sulu/sulu/src/Sulu/Bundle/ContactBundle/Entity/SocialMediaProfileType.php line 25

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\ExclusionPolicy;
  14. use JMS\Serializer\Annotation\Groups;
  15. use JMS\Serializer\Annotation\SerializedName;
  16. use JMS\Serializer\Annotation\VirtualProperty;
  17. /**
  18. * Type of social media profile (i.e. Facebook,...).
  19. */
  20. #[ExclusionPolicy('All')]
  21. class SocialMediaProfileType implements \JsonSerializable
  22. {
  23. /**
  24. * @var int
  25. */
  26. private $id;
  27. /**
  28. * @var string
  29. */
  30. private $name;
  31. /**
  32. * @var Collection|SocialMediaProfile[]
  33. */
  34. private $socialMediaProfiles;
  35. /**
  36. * Constructor.
  37. */
  38. public function __construct()
  39. {
  40. $this->socialMediaProfiles = new ArrayCollection();
  41. }
  42. /**
  43. * To force id = 1 in load fixtures.
  44. *
  45. * @param int $id
  46. */
  47. public function setId($id)
  48. {
  49. $this->id = $id;
  50. }
  51. /**
  52. * @return int
  53. */
  54. #[VirtualProperty]
  55. #[SerializedName('id')]
  56. #[Groups(['fullAccount', 'fullContact', 'frontend'])]
  57. public function getId()
  58. {
  59. return $this->id;
  60. }
  61. /**
  62. * @param string $name
  63. *
  64. * @return SocialMediaProfileType
  65. */
  66. public function setName($name)
  67. {
  68. // Limit to maximal sql column length.
  69. $this->name = \substr($name, 0, 100);
  70. return $this;
  71. }
  72. /**
  73. * @return string
  74. */
  75. #[VirtualProperty]
  76. #[SerializedName('name')]
  77. #[Groups(['fullAccount', 'fullContact', 'frontend'])]
  78. public function getName()
  79. {
  80. return $this->name;
  81. }
  82. /**
  83. * @return SocialMediaProfileType
  84. */
  85. public function addSocialMediaProfile(SocialMediaProfile $socialMediaProfile)
  86. {
  87. $this->socialMediaProfiles[] = $socialMediaProfile;
  88. return $this;
  89. }
  90. public function removeSocialMediaProfile(SocialMediaProfile $socialMediaProfile)
  91. {
  92. $this->socialMediaProfiles->removeElement($socialMediaProfile);
  93. }
  94. /**
  95. * @return Collection|SocialMediaProfile[]
  96. */
  97. public function getSocialMediaProfiles()
  98. {
  99. return $this->socialMediaProfiles;
  100. }
  101. /**
  102. * Specify data which should be serialized to JSON.
  103. *
  104. * @see http://php.net/manual/en/jsonserializable.jsonserialize.php
  105. *
  106. * @return mixed data which can be serialized by <b>json_encode</b>,
  107. * which is a value of any type other than a resource
  108. */
  109. #[\ReturnTypeWillChange]
  110. public function jsonSerialize()
  111. {
  112. return [
  113. 'id' => $this->getId(),
  114. 'name' => $this->getName(),
  115. ];
  116. }
  117. }