Role.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace Entity;
  3. use Symfony\Component\Security\Core\Role\Role as SymfonyRole;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7. * @ORM\Table(name="roles")
  8. * @ORM\Entity()
  9. */
  10. class Role extends SymfonyRole implements \Serializable
  11. {
  12. /**
  13. * @ORM\Column(name="id", type="integer")
  14. * @ORM\Id()
  15. * @ORM\GeneratedValue(strategy="AUTO")
  16. */
  17. private $id;
  18. /**
  19. * @ORM\Column(name="name", type="string", length=255)
  20. */
  21. private $name;
  22. /**
  23. * @ORM\Column(name="role", type="string", length=255, unique=true)
  24. */
  25. private $role;
  26. /**
  27. * @ORM\ManyToMany(targetEntity="User", mappedBy="roles")
  28. * @ORM\JoinTable(name="users_roles",
  29. * joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="user_id")})
  30. */
  31. private $users;
  32. /**
  33. * @ORM\OneToMany(targetEntity="JuryMembers", mappedBy="role")
  34. **/
  35. private $rolesFromJury;
  36. public function __construct()
  37. {
  38. $this->users = new ArrayCollection();
  39. }
  40. /**
  41. * @see RoleInterface
  42. */
  43. public function getRole()
  44. {
  45. return $this->role;
  46. }
  47. /**
  48. * Get id
  49. *
  50. * @return integer
  51. */
  52. public function getId()
  53. {
  54. return $this->id;
  55. }
  56. /**
  57. * Set name
  58. *
  59. * @param string $name
  60. * @return Role
  61. */
  62. public function setName($name)
  63. {
  64. $this->name = $name;
  65. return $this;
  66. }
  67. /**
  68. * Get name
  69. *
  70. * @return string
  71. */
  72. public function getName()
  73. {
  74. return $this->name;
  75. }
  76. /**
  77. * Set name
  78. *
  79. * @param string $role
  80. * @return Role
  81. */
  82. public function setRole($role)
  83. {
  84. $this->role = $role;
  85. return $this;
  86. }
  87. /**
  88. * @see \Serializable::serialize()
  89. */
  90. public function serialize()
  91. {
  92. /*
  93. * ! Don't serialize $users field !
  94. */
  95. return \serialize(array(
  96. $this->id,
  97. $this->role
  98. ));
  99. }
  100. /**
  101. * @see \Serializable::unserialize()
  102. */
  103. public function unserialize($serialized)
  104. {
  105. list(
  106. $this->id,
  107. $this->role
  108. ) = \unserialize($serialized);
  109. }
  110. }