src/Daikin/BaseBundle/Entity/User.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Daikin\BaseBundle\Entity;
  3. use App\Daikin\BaseBundle\Entity\EmergencyStock\Order;
  4. use App\Daikin\BaseBundle\Entity\EmergencyStock\Warehouse;
  5. use \DateTime;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Gedmo\Mapping\Annotation as Gedmo;
  10. use App\Daikin\BaseBundle\Validator\Constraints\UndeletedUniqueEntity as UniqueEntity;
  11. use EHC\HTMLIdableBundle\Interfaces\HTMLIdableInterface;
  12. use Symfony\Component\Security\Core\User\LegacyPasswordAuthenticatedUserInterface;
  13. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  14. use Symfony\Component\Security\Core\User\UserInterface;
  15. /**
  16.  * @ORM\Entity(repositoryClass="App\Daikin\BaseBundle\Repository\UserRepository")
  17.  * @ORM\Table(name="user")
  18.  * @UniqueEntity("email")
  19.  */
  20. class User extends AbstractDeleteableEntity implements UserInterfaceLegacyPasswordAuthenticatedUserInterfaceHTMLIdableInterface
  21. {
  22.     /**
  23.      * @ORM\Id
  24.      * @ORM\Column(type="integer")
  25.      * @ORM\GeneratedValue(strategy="AUTO")
  26.      *
  27.      * @var integer $id
  28.      */
  29.     protected $id;
  30.     /**
  31.      * @ORM\Column(type="integer", name="title")
  32.      *
  33.      * @var integer $title
  34.      */
  35.     protected $title;
  36.     /**
  37.      * @ORM\Column(name="firstname")
  38.      *
  39.      * @var string $firstname
  40.      */
  41.     protected $firstname;
  42.     /**
  43.      * @ORM\Column(name="lastname")
  44.      *
  45.      * @var string $lastname
  46.      */
  47.     protected $lastname;
  48.     /**
  49.      * @ORM\Column(name="email")
  50.      * @var string $email
  51.      */
  52.     protected $email;
  53.     /**
  54.      * @ORM\Column(name="password")
  55.      *
  56.      * @var string $password
  57.      */
  58.     protected $password;
  59.     private $ppassword;
  60.     /**
  61.      * @ORM\Column(length=32)
  62.      *
  63.      * @var string $salt
  64.      */
  65.     protected $salt;
  66.     /**
  67.      * @Gedmo\Timestampable(on="create")
  68.      * @ORM\Column(type="integer", name="created_at")
  69.      *
  70.      * @var integer $createdAt
  71.      */
  72.     protected $createdAt;
  73.     /**
  74.      * @Gedmo\Timestampable(on="update")
  75.      * @ORM\Column(type="integer", name="updated_at")
  76.      *
  77.      * @var integer $updatedAt
  78.      */
  79.     protected $updatedAt;
  80.     /**
  81.      * @ORM\Column(type="integer", name="approved_email")
  82.      *
  83.      * @var integer $approved_email
  84.      */
  85.     protected $approved_email;
  86.     /**
  87.      * @ORM\ManyToMany(targetEntity="Role", inversedBy="users")
  88.      * @ORM\JoinTable(name="user_role",
  89.      *     joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE")},
  90.      *     inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")}
  91.      * )
  92.      * @var Collection|Role[]
  93.      */
  94.     protected $userRoles;
  95.     /**
  96.      * @ORM\ManyToOne(targetEntity="Company", inversedBy="users")
  97.      * @ORM\JoinColumn(name="companyid", nullable=false, onDelete="CASCADE")
  98.      */
  99.     protected $company;
  100.     /**
  101.      * @ORM\Column(type="datetime", nullable=true)
  102.      */
  103.     protected $reset_requested_at;
  104.     /**
  105.      * @ORM\Column(length=32, nullable=true)
  106.      */
  107.     protected $reset_request_hash;
  108.     /**
  109.      * @ORM\Column(type="datetime", nullable=true)
  110.      */
  111.     protected $app_last_login;
  112.     /**
  113.      * @ORM\Column(type="datetime", nullable=true)
  114.      */
  115.     protected $portal_last_login;
  116.     /**
  117.      * @var Order[]
  118.      *
  119.      * @ORM\OneToMany(targetEntity="App\Daikin\BaseBundle\Entity\EmergencyStock\Order", mappedBy="customer")
  120.      */
  121.     private $orders;
  122.     /**
  123.      * @var Warehouse
  124.      *
  125.      * @ORM\ManyToOne(targetEntity="App\Daikin\BaseBundle\Entity\EmergencyStock\Warehouse")
  126.      * @ORM\JoinColumn()
  127.      */
  128.     private $warehouse;
  129.     /**
  130.      * @var DateTime
  131.      *
  132.      * @ORM\Column(type="datetime", nullable=true)
  133.      */
  134.     protected $converted_from_rotex;
  135.     /**
  136.      * @var int
  137.      *
  138.      * @ORM\Column(type="integer", nullable=true)
  139.      */
  140.     protected $converted_from_rotex_user_id;
  141.     /**
  142.      * Constructs a new instance of User
  143.      */
  144.     public function __construct()
  145.     {
  146.         parent::__construct();
  147.         $this->orders = new ArrayCollection();
  148.         $this->userRoles = new ArrayCollection();
  149.         $this->createdAt time();
  150.         $this->updatedAt time();
  151.         $this->approved_email 0;
  152.         $this->title 1;
  153.         $this->salt md5time() . uniqid() . rand() );
  154.     }
  155.     public function __toString()
  156.     {
  157.         return $this->firstname.' '.$this->lastname.' <'.$this->email.'>';
  158.     }
  159.     /**
  160.      * @see \Serializable::serialize()
  161.      */
  162.     public function serialize()
  163.     {
  164.         return serialize(array(
  165.             $this->id,
  166.         ));
  167.     }
  168.     /**
  169.      * @see \Serializable::unserialize()
  170.      * @param string $serialized
  171.      */
  172.     public function unserialize($serialized)
  173.     {
  174.         list (
  175.             $this->id,
  176.             ) = unserialize($serialized);
  177.     }
  178.     /**
  179.      * Gets the id.
  180.      *
  181.      * @return integer The id
  182.      */
  183.     public function getId()
  184.     {
  185.         return $this->id;
  186.     }
  187.     public function getHTMLId()
  188.     {
  189.         return 'user-'.$this->id;
  190.     }
  191.     /**
  192.      * Gets the id.
  193.      *
  194.      * @return integer The id
  195.      */
  196.     public function getApprovedEmail()
  197.     {
  198.         return $this->approved_email;
  199.     }
  200.     /**
  201.      * has the email address been verified?
  202.      *
  203.      * @return boolean
  204.      */
  205.     public function isEmailApproved()
  206.     {
  207.         return (bool)$this->approved_email;
  208.     }
  209.     /**
  210.      * Sets.
  211.      *
  212.      * @param integer $value
  213.      * @return User
  214.      */
  215.     public function setApprovedEmail$value ): self
  216.     {
  217.         $this->approved_email $value;
  218.         return $this;
  219.     }
  220.     /**
  221.      * Gets the user's title.
  222.      *
  223.      * @return string The title
  224.      */
  225.     public function getTitle()
  226.     {
  227.         return $this->title;
  228.     }
  229.     /**
  230.      * Sets the user's title.
  231.      *
  232.      * @param string $value The title
  233.      * @return User
  234.      */
  235.     public function setTitle$value )
  236.     {
  237.         $this->title $value;
  238.         return $this;
  239.     }
  240.     /**
  241.      * Gets the user's first name.
  242.      *
  243.      * @return string The first name
  244.      */
  245.     public function getFirstName()
  246.     {
  247.         return $this->firstname;
  248.     }
  249.     /**
  250.      * Sets the user's first name.
  251.      *
  252.      * @param string $value The first name
  253.      * @return User
  254.      */
  255.     public function setFirstName$value )
  256.     {
  257.         $this->firstname ucfirst$value );
  258.         return $this;
  259.     }
  260.     /**
  261.      * Gets the user's last name.
  262.      *
  263.      * @return string The last name
  264.      */
  265.     public function getLastName()
  266.     {
  267.         return $this->lastname;
  268.     }
  269.     /**
  270.      * Sets the user's last name.
  271.      *
  272.      * @param string $value The last name
  273.      * @return User
  274.      */
  275.     public function setLastName$value )
  276.     {
  277.         $this->lastname ucfirst$value );
  278.         return $this;
  279.     }
  280.     /**
  281.      * Gets the user's email address.
  282.      *
  283.      * @return string The email
  284.      */
  285.     public function getEmail()
  286.     {
  287.         return $this->email;
  288.     }
  289.     /**
  290.      * Sets the user's email address.
  291.      *
  292.      * @param string $value The email
  293.      * @return User
  294.      */
  295.     public function setEmail($value)
  296.     {
  297.         $this->email $value;
  298.         return $this;
  299.     }
  300.     /**
  301.      * @see PasswordAuthenticatedUserInterface
  302.      */
  303.     public function getPassword(): ?string
  304.     {
  305.         return $this->password;
  306.     }
  307.     /**
  308.      * Sets the user password.
  309.      *
  310.      * @param string $value The password.
  311.      * @return User
  312.      */
  313.     public function setPassword($value)
  314.     {
  315.         $this->password $value;
  316.         return $this;
  317.     }
  318.     /**
  319.      * set plain password
  320.      *
  321.      * @param string $ppass
  322.      * @return User
  323.      */
  324.     public function setPPassword($ppass null)
  325.     {
  326.         $this->ppassword = (null === $ppass) ? null : (string)$ppass;
  327.         return $this;
  328.     }
  329.     /**
  330.      * get plain password
  331.      * @return string
  332.      */
  333.     public function getPPassword()
  334.     {
  335.         return $this->ppassword;
  336.     }
  337.     /**
  338.      * update the encrypted password from plain password if it's set
  339.      *
  340.      * @return User
  341.      */
  342.     public function updateEncryptedPassword()
  343.     {
  344.         throw new \Exception('Fix me');
  345. //        if ($this->ppassword !== null)
  346. //        {
  347. //            $encoder = new MessageDigestPasswordEncoder('sha512', true, 10);
  348. //            $this->password = $encoder->encodePassword($this->ppassword, $this->getSalt());
  349. //        }
  350.         return $this;
  351.     }
  352.     /**
  353.      * Gets the user salt.
  354.      *
  355.      */
  356.     public function getSalt(): ?string
  357.     {
  358.         return $this->salt;
  359.     }
  360.     /**
  361.      * Gets an object representing the date and time the user was created.
  362.      *
  363.      * @return integer A DateTime object
  364.      */
  365.     public function getCreatedAt()
  366.     {
  367.         return $this->createdAt;
  368.     }
  369.     /**
  370.      * Gets an object representing the date and time the user was created.
  371.      *
  372.      * @return integer A DateTime object
  373.      */
  374.     public function getUpdatedAt()
  375.     {
  376.         return $this->updatedAt;
  377.     }
  378.     /**
  379.      * A visual identifier that represents this user.
  380.      *
  381.      * @see UserInterface
  382.      */
  383.     public function getUserIdentifier(): string
  384.     {
  385.         return (string) $this->email;
  386.     }
  387.     /**
  388.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  389.      */
  390.     public function getUsername(): string
  391.     {
  392.         return (string) $this->email;
  393.     }
  394.     /**
  395.      * Gets the full name of the user.
  396.      *
  397.      * @return string The full name
  398.      */
  399.     public function getFullName()
  400.     {
  401.         return sprintf('%s %s'$this->firstname$this->lastname);
  402.     }
  403.     /**
  404.      * @param Role $role
  405.      * @return $this
  406.      */
  407.     public function setRole(Role $role)
  408.     {
  409.         $this->getUserRoles()->clear();
  410.         $this->getUserRoles()->add($role);
  411.         return $this;
  412.     }
  413.     /**
  414.      * @return Role
  415.      */
  416.     public function getRole()
  417.     {
  418.         return $this->getUserRoles()->first();
  419.     }
  420.     /**
  421.      * Gets the user roles.
  422.      *
  423.      * @return Collection|Role[]
  424.      */
  425.     public function getUserRoles()
  426.     {
  427.         return $this->userRoles;
  428.     }
  429.     /**
  430.      * @see UserInterface
  431.      */
  432.     public function getRoles(): array
  433.     {
  434.         $roles = [];
  435.         // guarantee every user at least has ROLE_USER
  436.         $roles[] = Role::ROLE_USER;
  437.         $userRoles $this->getUserRoles();
  438.         foreach ($userRoles as $userRole) {
  439.             $roles[] = $userRole->getName();
  440.         }
  441.         return array_unique($roles);
  442.     }
  443.     public function isAdmin(): bool
  444.     {
  445.         return in_array(Role::ROLE_ADMIN$this->getRoles());
  446.     }
  447.     /**
  448.      * Gets an array of roles.
  449.      *
  450.      * @param bool|array $filterRoleNames
  451.      * @return array An array of Role objects
  452.      */
  453.     public function getRoleIds($filterRoleNames=false)
  454.     {
  455.         $ids = [];
  456.         $noFilterMode = !is_array($filterRoleNames);
  457.         /** @var Role $role */
  458.         foreach ($this->getUserRoles() as $role) {
  459.             if ($noFilterMode || in_array($role->getName(), $filterRoleNames)) {
  460.                 $ids[] = $role->getId();
  461.             }
  462.         }
  463.         return $ids;
  464.     }
  465.     /**
  466.      * this User has a given Role?
  467.      *
  468.      * @param mixed $role_names
  469.      * @return boolean
  470.      */
  471.     public function hasRole$role_names )
  472.     {
  473.         if ( ! is_array$role_names ) )
  474.             $role_names = array( $role_names );
  475.         foreach( $this->getUserRoles() as $role )
  476.         {
  477.             if ( in_array$role->getName(), $role_names ) )
  478.                 return true;
  479.         }
  480.         return false;
  481.     }
  482.     /**
  483.      * Set createdAt
  484.      *
  485.      * @param integer $createdAt
  486.      * @return User
  487.      */
  488.     public function setCreatedAt($createdAt)
  489.     {
  490.         $this->createdAt $createdAt;
  491.         return $this;
  492.     }
  493.     /**
  494.      * Set updatedAt
  495.      *
  496.      * @param integer $updatedAt
  497.      */
  498.     public function setUpdatedAt($updatedAt)
  499.     {
  500.         $this->updatedAt $updatedAt;
  501.     }
  502.     /**
  503.      * Set company
  504.      *
  505.      * @param Company $company
  506.      * @return User
  507.      */
  508.     public function setCompanyCompany $company )
  509.     {
  510.         $this->company $company;
  511.         return $this;
  512.     }
  513.     /**
  514.      * Get company
  515.      *
  516.      * @return Company
  517.      */
  518.     public function getCompany()
  519.     {
  520.         return $this->company;
  521.     }
  522.     /**
  523.      * set the DateTime a password reset request was made
  524.      *
  525.      * @param DateTime $rra
  526.      * @return User
  527.      */
  528.     public function setResetRequestedAtDateTime $rra )
  529.     {
  530.         $this->reset_requested_at $rra;
  531.         return $this;
  532.     }
  533.     /**
  534.      * get the DateTime a password reset request was made
  535.      *
  536.      * @return DateTime
  537.      */
  538.     public function getResetRequestedAt()
  539.     {
  540.         return $this->reset_requested_at;
  541.     }
  542.     /**
  543.      * set a hash required for a password reset
  544.      *
  545.      * @param string $hash
  546.      * @return User
  547.      */
  548.     public function setResetRequestHash$hash )
  549.     {
  550.         $this->reset_request_hash $hash;
  551.         return $this;
  552.     }
  553.     /**
  554.      * get the hash required for a password reset
  555.      *
  556.      * @return string
  557.      */
  558.     public function getResetRequestHash()
  559.     {
  560.         return $this->reset_request_hash;
  561.     }
  562.     /**
  563.      * reset the reset request (after success)
  564.      *
  565.      * @return User
  566.      */
  567.     public function resetResetRequest()
  568.     {
  569.         $this->reset_requested_at null;
  570.         $this->reset_request_hash null;
  571.         return $this;
  572.     }
  573.     /**
  574.      * @see Symfony\Component\Security\Core\User\UserInterface::eraseCredentials()
  575.      */
  576.     public function eraseCredentials()
  577.     {
  578.         $this->ppassword null;
  579.     }
  580.     /**
  581.      * @see Symfony\Component\Security\Core\User\AdvancedUserInterface::isAccountNonExpired()
  582.      */
  583.     public function isAccountNonExpired()
  584.     {
  585.         return true;
  586.     }
  587.     /**
  588.      * @see Symfony\Component\Security\Core\User\AdvancedUserInterface::isAccountNonLocked()
  589.      */
  590.     public function isAccountNonLocked()
  591.     {
  592.         return !$this->isDeleted();
  593.     }
  594.     /**
  595.      * @see Symfony\Component\Security\Core\User\AdvancedUserInterface::isCredentialsNonExpired()
  596.      */
  597.     public function isCredentialsNonExpired()
  598.     {
  599.         return true;
  600.     }
  601.     /**
  602.      * @see Symfony\Component\Security\Core\User\AdvancedUserInterface::isEnabled()
  603.      */
  604.     public function isEnabled()
  605.     {
  606.         return $this->isEmailApproved();
  607.     }
  608.     /**
  609.      * set the time the user last logged in through the mobile app
  610.      *
  611.      * @param DateTime $app_last_login
  612.      * @return User
  613.      */
  614.     public function setAppLastLoginDateTime $app_last_login )
  615.     {
  616.         $this->app_last_login $app_last_login;
  617.         return $this;
  618.     }
  619.     /**
  620.      * get the time the user last logged in through the mobile app
  621.      *
  622.      * @return DateTime
  623.      */
  624.     public function getAppLastLogin()
  625.     {
  626.         return $this->app_last_login;
  627.     }
  628.     /**
  629.      * set the time the user last logged in to the portal
  630.      *
  631.      * @param DateTime $portal_last_login
  632.      * @return User
  633.      */
  634.     public function setPortalLastLogin(DateTime $portal_last_login)
  635.     {
  636.         $this->portal_last_login $portal_last_login;
  637.         return $this;
  638.     }
  639.     /**
  640.      * get the time the user last logged in to the portal
  641.      *
  642.      * @return DateTime
  643.      */
  644.     public function getPortalLastLogin()
  645.     {
  646.         return $this->portal_last_login;
  647.     }
  648.     /**
  649.      * get the email address verification code
  650.      * This code is only used for resend-verification
  651.      *
  652.      * @return string
  653.      */
  654.     public function getVerificationCode()
  655.     {
  656.         return md5($this->getPassword() . $this->getCreatedAt() . $this->getSalt());
  657. //
  658. //        $md5 = md5($this->getEmail() . $this->getCreatedAt() . $this->getSalt());
  659. //        $offset = substr($this->getId(), -1, 1);
  660. //
  661. //        return substr($md5, $offset, 10);
  662.     }
  663.     /**
  664.      * @return EmergencyStock\Order[]
  665.      */
  666.     public function getOrders()
  667.     {
  668.         return $this->orders;
  669.     }
  670.     /**
  671.      * @param EmergencyStock\Order[] $orders
  672.      */
  673.     public function setOrders($orders)
  674.     {
  675.         $this->orders $orders;
  676.     }
  677.     public function addOrder(Order $order)
  678.     {
  679.         $this->orders->add($order);
  680.     }
  681.     public function removeOrder(Order $order)
  682.     {
  683.         $this->orders->removeElement($order);
  684.     }
  685.     /**
  686.      * @return Warehouse
  687.      */
  688.     public function getWarehouse()
  689.     {
  690.         return $this->warehouse;
  691.     }
  692.     /**
  693.      * @param Warehouse $warehouse
  694.      */
  695.     public function setWarehouse($warehouse)
  696.     {
  697.         $this->warehouse $warehouse;
  698.     }
  699.     /**
  700.      * @return DateTime
  701.      */
  702.     public function getConvertedFromRotex()
  703.     {
  704.         return $this->converted_from_rotex;
  705.     }
  706.     /**
  707.      * @param string $format
  708.      * @param string $default
  709.      * @return string
  710.      */
  711.     public function getConvertedFromRotexFormatted($format='d.m.Y H:i'$default='unknown')
  712.     {
  713.         if ($this->converted_from_rotex instanceof DateTime) {
  714.             return $this->converted_from_rotex->format($format);
  715.         }
  716.         return $default;
  717.     }
  718.     /**
  719.      * @param DateTime $converted_from_rotex
  720.      * @return User
  721.      */
  722.     public function setConvertedFromRotex(DateTime $converted_from_rotex)
  723.     {
  724.         $this->converted_from_rotex $converted_from_rotex;
  725.         return $this;
  726.     }
  727.     /*
  728.         BOF Rotex Account Import 9810
  729.         Kann nach der Konvertierung eigentlich wieder raus
  730.     */
  731.     /**
  732.      * @param string $salt
  733.      * @return User
  734.      */
  735.     public function setSalt($salt)
  736.     {
  737.         $this->salt $salt;
  738.         return $this;
  739.     }
  740.     /**
  741.      * @return int
  742.      */
  743.     public function getConvertedFromRotexUserId(): int
  744.     {
  745.         return $this->converted_from_rotex_user_id;
  746.     }
  747.     /**
  748.      * @return bool
  749.      */
  750.     public function isConvertedFromRotexUserId(): bool
  751.     {
  752.         return (int)$this->converted_from_rotex_user_id 0;
  753.     }
  754.     /**
  755.      * @param int $converted_from_rotex_user_id
  756.      * @return User
  757.      */
  758.     public function setConvertedFromRotexUserId(int $converted_from_rotex_user_id): User
  759.     {
  760.         $this->converted_from_rotex_user_id $converted_from_rotex_user_id;
  761.         return $this;
  762.     }
  763.     /* EOF Rotex Account Import 9810 */
  764. }