Advertisement
Guest User

Untitled

a guest
Aug 11th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. <?php
  2.  
  3. namespace CosmeticBundle\Entity;
  4.  
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Doctrine\ORM\Mapping\ManyToMany;
  8. use Doctrine\ORM\Mapping\OneToMany;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10.  
  11. /**
  12. * Users
  13. *
  14. * @ORM\Table(name="users")
  15. * @ORM\Entity(repositoryClass="CosmeticBundle\Repository\UserRepository")
  16. */
  17. class User implements \Symfony\Component\Security\Core\User\UserInterface
  18. {
  19. /**
  20. * @var int
  21. *
  22. * @ORM\Column(name="id", type="integer")
  23. * @ORM\Id
  24. * @ORM\GeneratedValue(strategy="AUTO")
  25. */
  26. private $id;
  27.  
  28. /**
  29. * @Assert\NotBlank
  30. * @Assert\Email(
  31. * message = "The email '{{ value }}' is not a valid email.",
  32. * checkMX = false
  33. * )
  34. *
  35. * @var string
  36. *
  37. * @ORM\Column(name="email", type="string", length=255, unique=true)
  38. * checkMX = true
  39. */
  40. private $email;
  41.  
  42. /**
  43. * @Assert\NotBlank
  44. * @Assert\Length(
  45. * min = 6,
  46. * max = 20,
  47. * minMessage = "Your first name must be at least {{ limit }} characters long",
  48. * maxMessage = "Your first name cannot be longer than {{ limit }} characters"
  49. * )
  50. *
  51. * @var string
  52. *
  53. * @ORM\Column(name="password", type="string", length=255)
  54. */
  55. private $password;
  56. /**
  57. * @var ArrayCollection
  58. *
  59. * @ManyToMany (targetEntity="CosmeticBundle\Entity\Role")
  60. * @ORM\JoinTable(name="users_roles",
  61. * joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
  62. * inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")}
  63. * )
  64. */
  65. private $roles;
  66.  
  67. /**
  68. * @var ArrayCollection
  69. * @OneToMany (targetEntity="CosmeticBundle\Entity\Brand", mappedBy="authorId")
  70. */
  71. private $brands;
  72.  
  73. public function __construct()
  74. {
  75. $this->roles = new ArrayCollection();
  76. $this->brands = new ArrayCollection();
  77. }
  78.  
  79. /**
  80. * @return ArrayCollection
  81. */
  82. public function getBrands()
  83. {
  84. return $this->brands;
  85. }
  86.  
  87. /**
  88. * @param Brand $brand
  89. * @return User
  90. */
  91. public function addBrands(Brand $brand)
  92. {
  93. $this->brands[] = $brand;
  94. return $this;
  95. }
  96.  
  97.  
  98. /**
  99. * Get id
  100. *
  101. * @return int
  102. */
  103. public function getId()
  104. {
  105. return $this->id;
  106. }
  107.  
  108. /**
  109. * Set email
  110. *
  111. * @param string $email
  112. *
  113. * @return User
  114. */
  115. public function setEmail($email)
  116. {
  117. $this->email = $email;
  118.  
  119. return $this;
  120. }
  121.  
  122. /**
  123. * Get email
  124. *
  125. * @return string
  126. */
  127. public function getEmail()
  128. {
  129. return $this->email;
  130. }
  131.  
  132. /**
  133. * Set password
  134. *
  135. * @param string $password
  136. *
  137. * @return User
  138. */
  139. public function setPassword($password)
  140. {
  141. $this->password = $password;
  142.  
  143. return $this;
  144. }
  145.  
  146. /**
  147. * Get password
  148. *
  149. * @return string
  150. */
  151. public function getPassword()
  152. {
  153. return $this->password;
  154. }
  155. /**
  156. * @return array (Role |string)[]
  157. */
  158. public function getRoles()
  159. {
  160. $strRoles = [];
  161. /**
  162. * @var Role $role
  163. */
  164. foreach ($this->roles as $role) {
  165. $strRoles[] = $role->getRole();
  166. }
  167. return $strRoles;
  168. }
  169.  
  170. /**
  171. * @param Role $role
  172. * @return User
  173. */
  174. public function addRole(Role $role)
  175. {
  176. $this->roles [] = $role;
  177. return $this;
  178. }
  179.  
  180. /**
  181. * @return bool
  182. */
  183. public function isAdmin()
  184. {
  185. return in_array("ROLE_ADMIN", $this->getRoles());
  186. }
  187. /**
  188. * @return bool
  189. */
  190. public function isManager()
  191. {
  192. return in_array("ROLE_MANAGER", $this->getRoles());
  193. }
  194. public function isUser()
  195. {
  196. return in_array("ROLE_USER", $this->getRoles());
  197. }
  198. /**
  199. * @param Brand $brand
  200. * @return bool
  201. */
  202. public function isAuthor(Brand $brand)
  203. {
  204. return $brand->getAuthor()->getId() == $this->getId();
  205. }
  206.  
  207. public function getSalt()
  208. {
  209. // TODO: Implement getSalt() method.
  210. }
  211.  
  212. public function getUsername()
  213. {
  214. // TODO: Implement getUsername() method.
  215. }
  216.  
  217. public function eraseCredentials()
  218. {
  219. // TODO: Implement eraseCredentials() method.
  220. }
  221. }
  222.  
  223.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement