156 lines
3.0 KiB
PHP
156 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Entity;
|
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
/**
|
|
* @ORM\Entity
|
|
* @ORM\Table(
|
|
* name="user",
|
|
* indexes={
|
|
* @ORM\Index(name="contact_name", columns={"contact_name"}),
|
|
* @ORM\Index(name="contact_number", columns={"contact_number"}),
|
|
* @ORM\Index(name="when", columns={"when"}),
|
|
* @ORM\Index(name="direction", columns={"direction"})
|
|
* }
|
|
* )
|
|
*/
|
|
class User implements \JsonSerializable
|
|
{
|
|
/**
|
|
* @ORM\Id
|
|
* @ORM\Column(name="id", type="integer")
|
|
* @ORM\GeneratedValue(strategy="IDENTITY")
|
|
* @var int
|
|
*/
|
|
private $id;
|
|
|
|
/**
|
|
* @ORM\Column(name="name", type="string", length=200, nullable=false)
|
|
* @var string
|
|
*/
|
|
private $name;
|
|
|
|
/**
|
|
* @ORM\Column(name="hash_key", type="string", length=100, nullable=false)
|
|
* @var string
|
|
*/
|
|
private $hashKey;
|
|
|
|
/**
|
|
* @ORM\OneToMany(targetEntity="Fault", mappedBy="institute")
|
|
* @var Sms[]|ArrayCollection
|
|
*/
|
|
private $smsMessages;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->smsMessages = new ArrayCollection();
|
|
}
|
|
|
|
/**
|
|
* @return int
|
|
*/
|
|
public function getId(): int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
/**
|
|
* @param int $id
|
|
* @return User
|
|
*/
|
|
public function setId(int $id): User
|
|
{
|
|
$this->id = $id;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getName(): string
|
|
{
|
|
return $this->name;
|
|
}
|
|
|
|
/**
|
|
* @param string $name
|
|
* @return User
|
|
*/
|
|
public function setName(string $name): User
|
|
{
|
|
$this->name = $name;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getHashKey(): string
|
|
{
|
|
return $this->hashKey;
|
|
}
|
|
|
|
/**
|
|
* @param string $hashKey
|
|
* @return User
|
|
*/
|
|
public function setHashKey(string $hashKey): User
|
|
{
|
|
$this->hashKey = $hashKey;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Sms[]|ArrayCollection
|
|
*/
|
|
public function getSmsMessages(): ?ArrayCollection
|
|
{
|
|
return $this->smsMessages;
|
|
}
|
|
|
|
/**
|
|
* @param Sms[]|ArrayCollection $smsMessages
|
|
* @return User
|
|
*/
|
|
public function setSmsMessages(?ArrayCollection $smsMessages): User
|
|
{
|
|
$this->smsMessages = $smsMessages;
|
|
return $this;
|
|
}
|
|
|
|
public function addSmsMessage(Sms $sms): User
|
|
{
|
|
if(!$this->smsMessages->contains($sms)) {
|
|
$this->smsMessages->add($sms);
|
|
}
|
|
return $this;
|
|
}
|
|
|
|
public function removeSmsMessage(Sms $sms): User{
|
|
if($this->smsMessages->contains($sms)) {
|
|
$this->smsMessages->removeElement($sms);
|
|
}
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Specify data which should be serialized to JSON
|
|
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
|
|
* @return mixed data which can be serialized by <b>json_encode</b>,
|
|
* which is a value of any type other than a resource.
|
|
* @since 5.4.0
|
|
*/
|
|
public function jsonSerialize()
|
|
{
|
|
return [
|
|
'id' => $this->getId(),
|
|
'name' => $this->getName(),
|
|
// 'smsMessages' => $this->getSmsMessages()->getValues(),
|
|
];
|
|
}
|
|
}
|