Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace CosmeticBundle\Entity;
- use Doctrine\Common\Collections\ArrayCollection;
- use Doctrine\ORM\Mapping as ORM;
- use Doctrine\ORM\Mapping\ManyToMany;
- use Doctrine\ORM\Mapping\OneToMany;
- use Symfony\Component\Validator\Constraints as Assert;
- /**
- * Users
- *
- * @ORM\Table(name="users")
- * @ORM\Entity(repositoryClass="CosmeticBundle\Repository\UserRepository")
- */
- class User implements \Symfony\Component\Security\Core\User\UserInterface
- {
- /**
- * @var int
- *
- * @ORM\Column(name="id", type="integer")
- * @ORM\Id
- * @ORM\GeneratedValue(strategy="AUTO")
- */
- private $id;
- /**
- * @Assert\NotBlank
- * @Assert\Email(
- * message = "The email '{{ value }}' is not a valid email.",
- * checkMX = false
- * )
- *
- * @var string
- *
- * @ORM\Column(name="email", type="string", length=255, unique=true)
- * checkMX = true
- */
- private $email;
- /**
- * @Assert\NotBlank
- * @Assert\Length(
- * min = 6,
- * max = 20,
- * minMessage = "Your first name must be at least {{ limit }} characters long",
- * maxMessage = "Your first name cannot be longer than {{ limit }} characters"
- * )
- *
- * @var string
- *
- * @ORM\Column(name="password", type="string", length=255)
- */
- private $password;
- /**
- * @var ArrayCollection
- *
- * @ManyToMany (targetEntity="CosmeticBundle\Entity\Role")
- * @ORM\JoinTable(name="users_roles",
- * joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
- * inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")}
- * )
- */
- private $roles;
- /**
- * @var ArrayCollection
- * @OneToMany (targetEntity="CosmeticBundle\Entity\Brand", mappedBy="authorId")
- */
- private $brands;
- public function __construct()
- {
- $this->roles = new ArrayCollection();
- $this->brands = new ArrayCollection();
- }
- /**
- * @return ArrayCollection
- */
- public function getBrands()
- {
- return $this->brands;
- }
- /**
- * @param Brand $brand
- * @return User
- */
- public function addBrands(Brand $brand)
- {
- $this->brands[] = $brand;
- return $this;
- }
- /**
- * Get id
- *
- * @return int
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * Set email
- *
- * @param string $email
- *
- * @return User
- */
- public function setEmail($email)
- {
- $this->email = $email;
- return $this;
- }
- /**
- * Get email
- *
- * @return string
- */
- public function getEmail()
- {
- return $this->email;
- }
- /**
- * Set password
- *
- * @param string $password
- *
- * @return User
- */
- public function setPassword($password)
- {
- $this->password = $password;
- return $this;
- }
- /**
- * Get password
- *
- * @return string
- */
- public function getPassword()
- {
- return $this->password;
- }
- /**
- * @return array (Role |string)[]
- */
- public function getRoles()
- {
- $strRoles = [];
- /**
- * @var Role $role
- */
- foreach ($this->roles as $role) {
- $strRoles[] = $role->getRole();
- }
- return $strRoles;
- }
- /**
- * @param Role $role
- * @return User
- */
- public function addRole(Role $role)
- {
- $this->roles [] = $role;
- return $this;
- }
- /**
- * @return bool
- */
- public function isAdmin()
- {
- return in_array("ROLE_ADMIN", $this->getRoles());
- }
- /**
- * @return bool
- */
- public function isManager()
- {
- return in_array("ROLE_MANAGER", $this->getRoles());
- }
- public function isUser()
- {
- return in_array("ROLE_USER", $this->getRoles());
- }
- /**
- * @param Brand $brand
- * @return bool
- */
- public function isAuthor(Brand $brand)
- {
- return $brand->getAuthor()->getId() == $this->getId();
- }
- public function getSalt()
- {
- // TODO: Implement getSalt() method.
- }
- public function getUsername()
- {
- // TODO: Implement getUsername() method.
- }
- public function eraseCredentials()
- {
- // TODO: Implement eraseCredentials() method.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement