resq/src/Entity/CustomerUser.php
2023-05-04 18:26:57 +08:00

106 lines
2.1 KiB
PHP

<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Catalyst\ApiBundle\Entity\User as BaseUser;
/**
* @ORM\Entity
* @ORM\Table(name="customer_user")
*/
class CustomerUser extends BaseUser
{
// link to customer
/**
* @ORM\OneToOne(targetEntity="Customer", inversedBy="customer_user")
* @ORM\JoinColumn(name="customer_id", referencedColumnName="id", nullable=true)
*/
protected $customer;
// phone number
/**
* @ORM\Column(type="string", length=12)
*/
protected $phone_number;
/**
* @ORM\Column(type="json")
*/
protected $metadata;
// roles
/**
* @ORM\ManyToMany(targetEntity="Catalyst\ApiBundle\Entity\Role", indexBy="id")
* @ORM\JoinTable(name="customer_user_role")
*/
protected $roles;
// mobile sessions linked to this customer
/**
* @ORM\OneToMany(targetEntity="CustomerSession", mappedBy="customer_user")
*/
protected $sessions;
public function __construct()
{
parent::__construct();
$this->metadata = [];
$this->sessions = new ArrayCollection();
}
public function setMetadata($meta)
{
$this->metadata = $meta;
return $this;
}
public function getMetadata()
{
if ($this->metadata == null)
return [];
return $this->metadata;
}
public function setPhoneNumber($num)
{
$this->phone_number = $num;
return $this;
}
public function getPhoneNumber()
{
return $this->phone_number;
}
public function addMobileSession(MobileSession $session)
{
$this->sessions->add($session);
return $this;
}
public function clearMobileSessions()
{
$this->sessions->clear();
return $this;
}
public function getMobileSessions()
{
return $this->sessions;
}
public function setCustomer(Customer $cust = null)
{
$this->customer = $cust;
return $this;
}
public function getCustomer()
{
return $this->customer;
}
}