src/Entity/User.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\Collection;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use FOS\UserBundle\Model\User as BaseUser;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. /**
  13.  * User
  14.  *
  15.  * @ORM\Table(name="user")
  16.  * @ORM\Entity
  17.  * 
  18.  * @UniqueEntity("email", message="W systemie już istnieje użytkownik o takim adresie e-mail")
  19.  * @UniqueEntity("username", message="W systemie już istnieje użytkownik o takiej nazwie.")
  20.  */
  21. class User extends BaseUser
  22. {
  23.     /**
  24.      * @var integer
  25.      *
  26.      * @ORM\Column(name="id", type="integer")
  27.      * @ORM\Id
  28.      * @ORM\GeneratedValue(strategy="AUTO")
  29.      */
  30.     protected $id;
  31.     /**
  32.      * @Assert\NotBlank()
  33.      */
  34.     protected $username;
  35.     /**
  36.      * @Assert\NotBlank()
  37.      * @Assert\Email()
  38.      */
  39.     protected $email;
  40.     /**
  41.      * @var Company
  42.      * 
  43.      * @Assert\NotNull()
  44.      *
  45.      * @ORM\ManyToOne(targetEntity="Company", inversedBy="users")
  46.      * @ORM\JoinColumn(name="company_id", referencedColumnName="id", nullable=true, onDelete="CASCADE")
  47.      */
  48.     private $company;
  49.     
  50.     /**
  51.      * @var bool 
  52.      * 
  53.      * @ORM\Column(name="help", type="boolean", nullable=true)
  54.      */
  55.     private $help true;
  56.     
  57.     /**
  58.      * @var bool 
  59.      * 
  60.      * @ORM\Column(name="reload_map", type="boolean", nullable=true)
  61.      */
  62.     private $reloadMap false;
  63.     
  64.     /**
  65.      * @var ArrayCollection
  66.      * 
  67.      * @ORM\OneToMany(targetEntity="CableConnectionAction", mappedBy="user")
  68.      */
  69.     private $actions;
  70.     
  71.     /**
  72.      * @var ArrayCollection
  73.      *
  74.      * * @ORM\OneToMany(targetEntity="Payment", mappedBy="user")
  75.      */
  76.     protected $payments;
  77.     /**
  78.      * @var \DateTime
  79.      *
  80.      * @ORM\Column(name="created_at", type="datetime")
  81.      */
  82.     private $createdAt;
  83.     /**
  84.      * @var \DateTime
  85.      * 
  86.      * @Gedmo\Timestampable(on="update")
  87.      *
  88.      * @ORM\Column(name="updated_at", type="datetime")
  89.      */
  90.     private $updatedAt;
  91.     public function __construct()
  92.     {
  93.         parent::__construct();
  94.         $this->createdAt = new \DateTime();
  95.         $this->actions = new ArrayCollection();
  96.         $this->payments = new ArrayCollection();
  97.     }
  98.     /**
  99.      * @Assert\Callback
  100.      */
  101.     public function validate(ExecutionContextInterface $context): void
  102.     {
  103.         if ($this->plainPassword) {
  104.             $chars = [];
  105.             foreach (str_split($this->plainPassword) as $ch) {
  106.                 if (!in_array($ch$chars)) {
  107.                     $chars[] = $ch;
  108.                 }
  109.             }
  110.             if (count($chars) < 10) {
  111.                 $context->buildViolation('Hasło musi zawierać conajmniej 10 różnych znaków')
  112.                     ->atPath('plainPassword')
  113.                     ->addViolation();
  114.             }
  115.         }
  116.     }
  117.     /**
  118.      * Get id
  119.      *
  120.      * @return integer 
  121.      */
  122.     public function getId()
  123.     {
  124.         return $this->id;
  125.     }
  126.     /**
  127.      * Set createdAt
  128.      *
  129.      * @param \DateTime $createdAt
  130.      * @return User
  131.      */
  132.     public function setCreatedAt($createdAt)
  133.     {
  134.         $this->createdAt $createdAt;
  135.         return $this;
  136.     }
  137.     /**
  138.      * Get createdAt
  139.      *
  140.      * @return \DateTime 
  141.      */
  142.     public function getCreatedAt()
  143.     {
  144.         return $this->createdAt;
  145.     }
  146.     /**
  147.      * Set updatedAt
  148.      *
  149.      * @param \DateTime $updatedAt
  150.      * @return User
  151.      */
  152.     public function setUpdatedAt($updatedAt)
  153.     {
  154.         $this->updatedAt $updatedAt;
  155.         return $this;
  156.     }
  157.     /**
  158.      * Get updatedAt
  159.      *
  160.      * @return \DateTime 
  161.      */
  162.     public function getUpdatedAt()
  163.     {
  164.         return $this->updatedAt;
  165.     }
  166.     /**
  167.      * Set company
  168.      *
  169.      * @param Company $company
  170.      * @return User
  171.      */
  172.     public function setCompany(Company $company null)
  173.     {
  174.         $this->company $company;
  175.         return $this;
  176.     }
  177.     /**
  178.      * Get company
  179.      *
  180.      * @return Company 
  181.      */
  182.     public function getCompany()
  183.     {
  184.         return $this->company;
  185.     }
  186.     /**
  187.      * Add actions
  188.      *
  189.      * @param CableConnectionAction $actions
  190.      * @return User
  191.      */
  192.     public function addAction(CableConnectionAction $actions)
  193.     {
  194.         $this->actions[] = $actions;
  195.         return $this;
  196.     }
  197.     /**
  198.      * Remove actions
  199.      *
  200.      * @param CableConnectionAction $actions
  201.      */
  202.     public function removeAction(CableConnectionAction $actions): void
  203.     {
  204.         $this->actions->removeElement($actions);
  205.     }
  206.     /**
  207.      * Get actions
  208.      *
  209.      * @return Collection
  210.      */
  211.     public function getActions()
  212.     {
  213.         return $this->actions;
  214.     }
  215.     /**
  216.      * Set reloadMap
  217.      *
  218.      * @param boolean $reloadMap
  219.      * @return User
  220.      */
  221.     public function setReloadMap($reloadMap)
  222.     {
  223.         $this->reloadMap $reloadMap;
  224.         return $this;
  225.     }
  226.     /**
  227.      * Get reloadMap
  228.      *
  229.      * @return boolean 
  230.      */
  231.     public function getReloadMap()
  232.     {
  233.         return $this->reloadMap;
  234.     }
  235.     
  236.     /**
  237.      * {@inheritdoc}
  238.      *
  239.      * @return static
  240.      */
  241.     public function setPlainPassword($password)
  242.     {
  243.         $this->updatedAt = new \DateTime();
  244.         return parent::setPlainPassword($password);
  245.     }
  246.     /**
  247.      * Set help
  248.      *
  249.      * @param boolean $help
  250.      * @return User
  251.      */
  252.     public function setHelp($help)
  253.     {
  254.         $this->help $help;
  255.         return $this;
  256.     }
  257.     /**
  258.      * Get help
  259.      *
  260.      * @return boolean 
  261.      */
  262.     public function getHelp()
  263.     {
  264.         return $this->help;
  265.     }
  266.     
  267.     public function getRoles(): array
  268.     {
  269.         $roles parent::getRoles();
  270.         
  271.         if (!$company $this->getCompany()) {
  272.             return $roles;
  273.         }
  274.         foreach ($company->getGroups() as $group) {
  275.             $roles array_merge($roles$group->getRoles());
  276.         }
  277.         return array_unique($roles);
  278.     }
  279.     
  280.     public function getLocale(): string
  281.     {
  282.         return $this->getCompany()->getLanguage();
  283.     }
  284.     /**
  285.      * Add payment.
  286.      *
  287.      * @param Payment $payment
  288.      *
  289.      * @return User
  290.      */
  291.     public function addPayment(Payment $payment)
  292.     {
  293.         $this->payments[] = $payment;
  294.         return $this;
  295.     }
  296.     /**
  297.      * Remove payment.
  298.      *
  299.      * @param Payment $payment
  300.      *
  301.      * @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
  302.      */
  303.     public function removePayment(Payment $payment)
  304.     {
  305.         return $this->payments->removeElement($payment);
  306.     }
  307.     /**
  308.      * Get payments.
  309.      *
  310.      * @return Collection
  311.      */
  312.     public function getPayments()
  313.     {
  314.         return $this->payments;
  315.     }
  316. }