Advertisement
Guest User

Untitled

a guest
Jul 29th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. <?php
  2.  
  3. namespace RFC\UserBundle\Entity;
  4.  
  5. use Doctrine\ORM\Mapping as ORM;
  6. use FOS\UserBundle\Model\User as BaseUser;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. use Gedmo\Timestampable\Traits\TimestampableEntity;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12.  
  13. /**
  14. * User
  15. *
  16. * @ORM\Table()
  17. * @ORM\Entity
  18. * @UniqueEntity("favoriteNumber", message="user.fav_number.not_unique", ignoreNull=true)
  19. */
  20. class User extends BaseUser
  21. {
  22.  
  23. /**
  24. * Hook timestampable behavior
  25. * updates createdAt, updatedAt fields
  26. */
  27. use TimestampableEntity;
  28. /**
  29. * @ORM\Column(name="id", type="integer")
  30. * @ORM\Id
  31. * @ORM\GeneratedValue(strategy="AUTO")
  32. */
  33. protected $id;
  34.  
  35. /**
  36. * @ORM\Column(name="firstName", type="string", length=255, nullable=true)
  37. */
  38. protected $firstName;
  39.  
  40. /**
  41. * @ORM\Column(name="lastName", type="string", length=255, nullable=true)
  42. */
  43. protected $lastName;
  44.  
  45. /**
  46. * @ORM\Column(name="age", type="integer", nullable=true)
  47. */
  48. protected $age;
  49.  
  50. /**
  51. * @ORM\Column(name="avatarUrl", type="string", length=255, nullable=true)
  52. */
  53. protected $avatarUrl;
  54.  
  55. /**
  56. * @ORM\Column(name="favoriteNumber", type="integer", nullable=true, unique=true)
  57. * @Assert\GreaterThan( value = 0, message="constraint.positive" )
  58. *
  59. */
  60. protected $favoriteNumber;
  61.  
  62. /**
  63. * @ORM\Column(name="locale", type="string", length=5)
  64. *
  65. */
  66. protected $locale;
  67.  
  68. public function __construct()
  69. {
  70. parent::__construct();
  71. }
  72.  
  73. public function eraseCredentials()
  74. {
  75.  
  76. }
  77.  
  78. /**
  79. * Set firstName
  80. *
  81. * @param string $firstName
  82. * @return User
  83. */
  84. public function setFirstName($firstName)
  85. {
  86. $this->firstName = $firstName;
  87.  
  88. return $this;
  89. }
  90.  
  91. /**
  92. * Get firstName
  93. *
  94. * @return string
  95. */
  96. public function getFirstName()
  97. {
  98. return $this->firstName;
  99. }
  100.  
  101. /**
  102. * Set lastName
  103. *
  104. * @param string $lastName
  105. * @return User
  106. */
  107. public function setLastName($lastName)
  108. {
  109. $this->lastName = $lastName;
  110.  
  111. return $this;
  112. }
  113.  
  114. /**
  115. * Get lastName
  116. *
  117. * @return string
  118. */
  119. public function getLastName()
  120. {
  121. return $this->lastName;
  122. }
  123.  
  124. /**
  125. * Set age
  126. *
  127. * @param integer $age
  128. * @return User
  129. */
  130. public function setAge($age)
  131. {
  132. $this->age = $age;
  133.  
  134. return $this;
  135. }
  136.  
  137. /**
  138. * Get age
  139. *
  140. * @return integer
  141. */
  142. public function getAge()
  143. {
  144. return $this->age;
  145. }
  146.  
  147. /**
  148. * Set avatarUrl
  149. *
  150. * @param string $avatarUrl
  151. * @return User
  152. */
  153. public function setAvatarUrl($avatarUrl)
  154. {
  155. $this->avatarUrl = $avatarUrl;
  156.  
  157. return $this;
  158. }
  159.  
  160. /**
  161. * Get avatarUrl
  162. *
  163. * @return string
  164. */
  165. public function getAvatarUrl()
  166. {
  167. return $this->avatarUrl;
  168. }
  169.  
  170. function getFavoriteNumber()
  171. {
  172. return $this->favoriteNumber;
  173. }
  174.  
  175. function setFavoriteNumber($favoriteNumber)
  176. {
  177. $this->favoriteNumber = $favoriteNumber;
  178. return $this;
  179. }
  180.  
  181. public function getLocale()
  182. {
  183. return $this->locale;
  184. }
  185.  
  186. /**
  187. * @param string $locale
  188. */
  189. public function setLocale($locale)
  190. {
  191. $this->locale = $locale;
  192. }
  193.  
  194. public function isRoleAdmin()
  195. {
  196. return $this->hasRole('ROLE_ADMIN');
  197. }
  198.  
  199. public function isRoleCertifiedManager()
  200. {
  201. return $this->hasRole('ROLE_CERTIFIED_MANAGER');
  202. }
  203.  
  204. public function isRoleManager()
  205. {
  206. return $this->hasRole('ROLE_MANAGER');
  207. }
  208.  
  209. public function isRoleUser()
  210. {
  211. return $this->hasRole('ROLE_USER');
  212. }
  213.  
  214. public function getHighestRole()
  215. {
  216. $role = 'ROLE_BANNED';
  217. if ($this->isRoleUser()) {
  218. $role = 'ROLE_USER';
  219. }
  220. if ($this->isRoleManager()) {
  221. $role = 'ROLE_MANAGER';
  222. }
  223. if ($this->isRoleCertifiedManager()) {
  224. $role = 'ROLE_CERTIFIED_MANAGER';
  225. }
  226. if ($this->isRoleAdmin()) {
  227. $role = 'ROLE_ADMIN';
  228. }
  229. return $role;
  230. }
  231. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement