src/Domain/Entities/Agent.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Domain\Entities;
  3. use DateTime;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Component\Security;
  6. use Symfony\Component\Security\Core\User\UserInterface;
  7. /**
  8.  * @ORM\Table(name="agents")
  9.  * @ORM\Entity(repositoryClass="App\Infrastructure\Persistence\DoctrineAgentRepository")
  10.  */
  11. class Agent implements Security\Core\User\UserInterfaceSecurity\Core\User\PasswordAuthenticatedUserInterfaceSecurity\Core\User\EquatableInterface
  12. {
  13.     /**
  14.      * @ORM\Column(name="idagent", type="integer", nullable=false)
  15.      * @ORM\Id
  16.      * @ORM\GeneratedValue(strategy="IDENTITY")
  17.      */
  18.     protected $id;
  19.     /**
  20.      * @var integer
  21.      *
  22.      * @ORM\Column(name="adminlevel", type="integer", nullable=false)
  23.      */
  24.     protected $adminlevel '5';
  25.     /**
  26.      * @var string
  27.      *
  28.      * @ORM\Column(name="username", type="string", length=60, nullable=false)
  29.      */
  30.     protected $username '';
  31.     /**
  32.      * @var string
  33.      *
  34.      * @ORM\Column(name="fname", type="string", length=30, nullable=false)
  35.      */
  36.     protected $firstName '';
  37.     /**
  38.      * @var string
  39.      *
  40.      * @ORM\Column(name="lname", type="string", length=30, nullable=false)
  41.      */
  42.     protected $lastName '';
  43.     /**
  44.      * @var integer
  45.      *
  46.      * @ORM\Column(name="genmgr", type="integer", nullable=false)
  47.      */
  48.     protected $genmgr '0';
  49.     /**
  50.      * @var integer
  51.      *
  52.      * @ORM\Column(name="mgr", type="integer", nullable=false)
  53.      */
  54.     protected $mgr '0';
  55.     /**
  56.      * @var boolean
  57.      *
  58.      * @ORM\Column(name="active", type="boolean", nullable=false)
  59.      */
  60.     protected $active '1';
  61.     /** @ORM\Column(name="bypass_agent_hierarchy", type="boolean", nullable=false, options={"default":0}) */
  62.     protected bool $bypassAgentHierarchy false;
  63.     /** @ORM\Column(name="client_access_bypass", type="boolean", nullable=false, options={"default":0}) */
  64.     protected bool $clientAccessBypass false;
  65.     /** @ORM\Column(name="production_report_admin", type="boolean", nullable=false, options={"default":0}) */
  66.     protected bool $productionReportAdmin false;
  67.     /** @ORM\Column(name="hide_agency_rates", type="boolean", nullable=false, options={"default":0}) */
  68.     protected bool $hideAgencyRates false;
  69.     /**
  70.      * @var string
  71.      *
  72.      * @ORM\Column(name="location", type="string", length=10, nullable=false)
  73.      */
  74.     protected $location;
  75.     /**
  76.      * @var boolean
  77.      *
  78.      * @ORM\Column(name="staff", type="boolean", nullable=false)
  79.      */
  80.     protected $staff '0';
  81.     /**
  82.      * @var string
  83.      *
  84.      * @ORM\Column(name="middle", type="string", length=3, nullable=false)
  85.      */
  86.     protected $middle;
  87.     /**
  88.      * @var string
  89.      *
  90.      * @ORM\Column(name="suffix", type="string", length=5, nullable=false)
  91.      */
  92.     protected $suffix;
  93.     /**
  94.      * @var string
  95.      *
  96.      * @ORM\Column(name="street", type="string", length=45, nullable=false)
  97.      */
  98.     protected $street;
  99.     /**
  100.      * @var string
  101.      *
  102.      * @ORM\Column(name="city", type="string", length=45, nullable=false)
  103.      */
  104.     protected $city;
  105.     /**
  106.      * @var string
  107.      *
  108.      * @ORM\Column(name="state", type="string", length=2, nullable=false)
  109.      */
  110.     protected $state;
  111.     /**
  112.      * @var string
  113.      *
  114.      * @ORM\Column(name="zip", type="string", length=10, nullable=false)
  115.      */
  116.     protected $zip;
  117.     /**
  118.      * @var string
  119.      *
  120.      * @ORM\Column(name="social", type="string", length=255, nullable=false)
  121.      */
  122.     protected $social;
  123.     /**
  124.      * @ORM\Column(name="dateOfBirth", type="date", nullable=true)
  125.      */
  126.     protected ?DateTime $dateOfBirth null;
  127.     /**
  128.      * @ORM\Column(name="startDate", type="date", nullable=true)
  129.      */
  130.     protected ?DateTime $startDate null;
  131.     /**
  132.      * @var string
  133.      *
  134.      * @ORM\Column(name="email", type="string", length=75, nullable=false)
  135.      */
  136.     protected $email;
  137.     /**
  138.      * @var integer
  139.      *
  140.      * @ORM\Column(name="subcontracted", type="integer", nullable=false)
  141.      */
  142.     protected $subcontracted '0';
  143.     /**
  144.      * @var integer
  145.      *
  146.      * @ORM\Column(name="closedhouse", type="integer", nullable=false)
  147.      */
  148.     protected $closedhouse;
  149.     /**
  150.      * @ORM\Column(name="lastDayWorked", type="date", nullable=true)
  151.      */
  152.     protected ?DateTime $lastDayWorked null;
  153.     /**
  154.      * @var boolean
  155.      *
  156.      * @ORM\Column(name="independent", type="boolean", nullable=false)
  157.      */
  158.     protected $independent '0';
  159.     /**
  160.      * @var Agent
  161.      *
  162.      * @ORM\ManyToOne(targetEntity="App\Domain\Entities\Agent")
  163.      * @ORM\JoinColumn(name="productionAgentId", referencedColumnName="idagent")
  164.      */
  165.     protected $productionAgent;
  166.     /**
  167.      * @ORM\Column(name="password", type="string", length=60, nullable=false)
  168.      */
  169.     protected string $password '';
  170.     public function gravatarHash(): string
  171.     {
  172.         return md5(strtolower(trim($this->email)));
  173.     }
  174.     public function getId()
  175.     {
  176.         return $this->id;
  177.     }
  178.     public function setFirstName($firstName)
  179.     {
  180.         $this->firstName $firstName;
  181.         return $this;
  182.     }
  183.     public function setLastName($lastName)
  184.     {
  185.         $this->lastName $lastName;
  186.         return $this;
  187.     }
  188.     public function getName()
  189.     {
  190.         return $this->firstName ' ' $this->lastName;
  191.     }
  192.     public function getShortName()
  193.     {
  194.         return $this->firstName;
  195.     }
  196.     public function getFormattedName()
  197.     {
  198.         return $this->lastName ", " $this->firstName;
  199.     }
  200.     /**
  201.      * Set productionAgent
  202.      *
  203.      * @param Agent $productionAgent
  204.      * @return Agent
  205.      */
  206.     public function setProductionAgent(Agent $productionAgent null)
  207.     {
  208.         $this->productionAgent $productionAgent;
  209.         return $this;
  210.     }
  211.     /**
  212.      * Get productionAgent
  213.      *
  214.      * @return Agent
  215.      */
  216.     public function getProductionAgent()
  217.     {
  218.         return $this->productionAgent;
  219.     }
  220.     public function getEmail()
  221.     {
  222.         return $this->email;
  223.     }
  224.     public function isActive(): bool
  225.     {
  226.         return (bool) $this->active;
  227.     }
  228.     public function canBypassAgentHierarchy(): bool
  229.     {
  230.         return $this->bypassAgentHierarchy;
  231.     }
  232.     public function hasClientAccessBypass(): bool
  233.     {
  234.         return $this->clientAccessBypass;
  235.     }
  236.     public function isProductionReportAdmin(): bool
  237.     {
  238.         return $this->productionReportAdmin;
  239.     }
  240.     public function shouldHideAgencyRates(): bool
  241.     {
  242.         return $this->hideAgencyRates;
  243.     }
  244.     public function isCallCenterOrTrainer(): bool
  245.     {
  246.         return strpos($this->firstName'CallCenter') !== false || $this->isTrainer();
  247.     }
  248.     public function isTrainer(): bool
  249.     {
  250.         return strpos($this->firstName'Trainer') !== false;
  251.     }
  252.     public function getPassword(): ?string
  253.     {
  254.         return $this->password ?: null;
  255.     }
  256.     public function setPassword(string $password): void
  257.     {
  258.         $this->password $password;
  259.     }
  260.     public function getRoles(): array
  261.     {
  262.         $roles = ['ROLE_USER'];
  263.         if ((int) $this->adminlevel <= 0) {
  264.             $roles[] = 'ROLE_SUPER_ADMIN';
  265.         } elseif ((int) $this->adminlevel <= 1) {
  266.             $roles[] = 'ROLE_ADMIN';
  267.         } elseif ((int) $this->adminlevel <= 2) {
  268.             $roles[] = 'ROLE_MANAGER';
  269.         } elseif ((int) $this->adminlevel <= 5) {
  270.             $roles[] = 'ROLE_AGENT';
  271.         }
  272.         // adminlevel > 5: no additional role beyond ROLE_USER
  273.         if ($this->isTrainer()) {
  274.             $roles[] = 'ROLE_TRAINER';
  275.         }
  276.         if (strpos($this->firstName'CallCenter') !== false) {
  277.             $roles[] = 'ROLE_CALL_CENTER';
  278.         }
  279.         return $roles;
  280.     }
  281.     public function getSalt()
  282.     {
  283.         return $this->username;
  284.     }
  285.     public function eraseCredentials() {}
  286.     public function getUsername()
  287.     {
  288.         return $this->username;
  289.     }
  290.     public function getUserIdentifier()
  291.     {
  292.         return $this->username;
  293.     }
  294.     public function sessionInformation(): array
  295.     {
  296.         return [
  297.             'userstamp' => $this->username,
  298.             'adminlevel' => $this->adminlevel,
  299.             'idagent' => $this->id,
  300.             'agentloc' => $this->location,
  301.             'user' => $this->firstName,
  302.         ];
  303.     }
  304.     public function identityInterest(): array
  305.     {
  306.         return [
  307.             'id' => $this->id,
  308.             'name' => $this->getName(),
  309.         ];
  310.     }
  311.     public function isEqualTo(UserInterface $user): bool
  312.     {
  313.         return $this->getUserIdentifier() == $user->getUserIdentifier();
  314.     }
  315.     public function isSuperAdmin(): bool
  316.     {
  317.         return $this->adminlevel == 0;
  318.     }
  319. }