resq/src/Entity/User.php

304 lines
5.9 KiB
PHP

<?php
namespace App\Entity;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Serializable;
/**
* @ORM\Entity
* @ORM\Table(name="user")
* @UniqueEntity("username")
* @UniqueEntity("email")
*/
class User implements AdvancedUserInterface, Serializable
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length=80, unique=true)
* @Assert\NotBlank()
*
*/
protected $username;
/**
* @ORM\Column(type="string", length=64)
*/
protected $password;
/**
* @ORM\ManyToMany(targetEntity="Role", inversedBy="users")
* @ORM\JoinTable(name="user_role")
*/
protected $roles;
/**
* @ORM\Column(type="boolean")
*/
protected $enabled;
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
protected $first_name;
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
protected $last_name;
/**
* @ORM\Column(type="string", length=20, nullable=true)
*/
protected $contact_num;
/**
* @ORM\Column(type="string", length=50, unique=true, nullable=true)
*/
protected $email;
// job orders made by this user
/**
* @ORM\OneToMany(targetEntity="JobOrder", mappedBy="created_by")
*/
protected $job_orders_created;
// job orders assigned by this user
/**
* @ORM\OneToMany(targetEntity="JobOrder", mappedBy="assigned_by")
*/
protected $job_orders_assigned;
// job orders processed or being processed by this user
/**
* @ORM\OneToMany(targetEntity="JobOrder", mappedBy="processed_by")
*/
protected $job_orders_processed;
// tickets made by this user
/**
* @ORM\OneToMany(targetEntity="Ticket", mappedBy="created_by")
*/
protected $tickets;
// invoices made by this user
/**
* @ORM\OneToMany(targetEntity="Invoice", mappedBy="created_by")
*/
protected $invoices;
public function __construct()
{
$this->roles = new ArrayCollection();
$this->job_orders_created = new ArrayCollection();
$this->job_orders_assigned = new ArrayCollection();
$this->tickets = new ArrayCollection();
$this->enabled = true;
}
public function getID()
{
return $this->id;
}
public function setUsername($username)
{
$this->username = $username;
return $this;
}
public function getUsername()
{
return $this->username;
}
public function setPassword($password)
{
$this->password = $password;
return $this;
}
public function getPassword()
{
return $this->password;
}
public function setSalt($salt)
{
// do nothing
return $this;
}
public function getSalt()
{
return null;
}
public function addRole(Role $role)
{
$this->roles->add($role);
return $this;
}
public function clearRoles()
{
$this->roles->clear();
return $this;
}
public function getRoles()
{
// has to return set of strings because symfony is trying to move away from role objects
$str_roles = [];
foreach ($this->roles as $role)
$str_roles[] = $role->getID();
return $str_roles;
}
public function getRoleObjects()
{
return $this->roles;
}
public function eraseCredentials()
{
return $this;
}
public function isAccountNonExpired()
{
return true;
}
public function isAccountNonLocked()
{
return true;
}
public function isCredentialsNonExpired()
{
return true;
}
public function setEnabled($enabled = true)
{
$this->enabled = $enabled;
return $this;
}
public function isEnabled()
{
return $this->enabled;
}
public function serialize()
{
return serialize([
$this->id,
$this->username,
$this->password,
$this->enabled,
]);
}
public function unserialize($serial)
{
list (
$this->id,
$this->username,
$this->password,
$this->enabled,
) = unserialize($serial);
}
public function setFirstName($name)
{
$this->first_name = $name;
return $this;
}
public function getFirstName()
{
return $this->first_name;
}
public function setLastName($name)
{
$this->last_name = $name;
return $this;
}
public function getLastName()
{
return $this->last_name;
}
public function getFullName()
{
return $this->first_name . ' ' . $this->last_name;
}
public function setContactNumber($num)
{
$this->contact_num = $num;
return $this;
}
public function getContactNumber()
{
return $this->contact_num;
}
public function setEmail($email = null)
{
$this->email = $email;
return $this;
}
public function getEmail()
{
return $this->email;
}
public function isSuperAdmin()
{
foreach ($this->roles as $role)
{
if ($role->isSuperAdmin())
return true;
}
return false;
}
public function getJobOrdersCreated()
{
return $this->job_orders_created;
}
public function getJobOrdersAssigned()
{
return $this->job_orders_assigned;
}
public function getTickets()
{
return $this->tickets;
}
public function getInvoices()
{
return $this->invoices;
}
}