312 lines
6 KiB
PHP
312 lines
6 KiB
PHP
<?php
|
|
|
|
namespace App\Entity;
|
|
|
|
use Catalyst\AuthBundle\Entity\User as BaseUser;
|
|
|
|
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 extends BaseUser implements 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\ManyToMany(targetEntity="Hub", inversedBy="users")
|
|
* @ORM\JoinTable(name="user_hubs")
|
|
*/
|
|
protected $hubs;
|
|
|
|
/**
|
|
* @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;
|
|
|
|
// partners made by this user
|
|
/**
|
|
* @ORM\OneToMany(targetEntity="Partner", mappedBy="created_by")
|
|
*/
|
|
protected $partners_created;
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
|
|
$this->hubs = new ArrayCollection();
|
|
$this->job_orders_created = new ArrayCollection();
|
|
$this->job_orders_assigned = new ArrayCollection();
|
|
$this->tickets = new ArrayCollection();
|
|
$this->partners_created = new ArrayCollection();
|
|
}
|
|
|
|
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 addHub(Hub $hub)
|
|
{
|
|
$this->hubs->add($hub);
|
|
return $this;
|
|
}
|
|
|
|
public function clearHubs()
|
|
{
|
|
$this->hubs->clear();
|
|
return $this;
|
|
}
|
|
|
|
public function getHubs()
|
|
{
|
|
$str_hubs = [];
|
|
foreach ($this->hubs as $hub)
|
|
$str_hubs[] = $hub->getID();
|
|
|
|
return $str_hubs;
|
|
}
|
|
|
|
public function getHubObjects()
|
|
{
|
|
return $this->hubs;
|
|
}
|
|
|
|
public function eraseCredentials()
|
|
{
|
|
return $this;
|
|
}
|
|
|
|
public function isAccountNonExpired()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function isAccountNonLocked()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function isCredentialsNonExpired()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
public function getPartnersCreated()
|
|
{
|
|
return $this->partners_created;
|
|
}
|
|
}
|