point-tools/src/Skobkin/Bundle/PointToolsBundle/Entity/User.php

230 lines
5.0 KiB
PHP
Raw Normal View History

<?php
namespace Skobkin\Bundle\PointToolsBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="users", schema="users", indexes={
* @ORM\Index(name="idx_user_login", columns={"login"}),
* @ORM\Index(name="idx_user_public", columns={"public"}),
* @ORM\Index(name="idx_user_removed", columns={"is_removed"})
* })
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\UserRepository")
2015-05-28 17:36:52 +00:00
* @ORM\HasLifecycleCallbacks
*/
class User
{
public const AVATAR_SIZE_SMALL = '24';
public const AVATAR_SIZE_MEDIUM = '40';
public const AVATAR_SIZE_LARGE = '80';
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
*/
private $id;
/**
* @var string
*
2015-10-01 18:15:49 +00:00
* @ORM\Column(name="login", type="string", length=255, nullable=false)
*/
private $login;
/**
2017-01-12 18:49:38 +00:00
* @var string|null
*
2015-05-28 17:36:52 +00:00
* @ORM\Column(name="name", type="string", length=255, nullable=true)
*/
private $name;
2015-05-28 17:36:52 +00:00
/**
* @var \DateTime
*
* @ORM\Column(name="created_at", type="datetime")
*/
private $createdAt;
/**
* @var \DateTime
*
2016-03-23 21:29:57 +00:00
* @ORM\Column(name="updated_at", type="datetime", nullable=true)
*/
private $updatedAt;
/**
* @var bool
*
* @ORM\Column(name="public", type="boolean", nullable=false, options={"default": false})
*/
private $public = false;
/**
* @var bool
*
* @ORM\Column(name="whitelist_only", type="boolean", nullable=false, options={"default": false})
*/
private $whitelistOnly = false;
/**
2017-01-09 18:29:39 +00:00
* @var ArrayCollection|Subscription[]
*
2017-01-04 22:36:30 +00:00
* @ORM\OneToMany(targetEntity="Subscription", mappedBy="author", fetch="EXTRA_LAZY")
*/
private $subscribers;
/**
2017-01-09 18:29:39 +00:00
* @var ArrayCollection|Subscription[]
*
2017-01-04 22:36:30 +00:00
* @ORM\OneToMany(targetEntity="Subscription", mappedBy="subscriber", fetch="EXTRA_LAZY")
*/
private $subscriptions;
2015-03-23 15:39:00 +00:00
/**
2017-01-09 18:29:39 +00:00
* @var ArrayCollection|SubscriptionEvent[]
2017-01-17 21:58:53 +00:00
*
* @ORM\OneToMany(targetEntity="SubscriptionEvent", mappedBy="author", fetch="EXTRA_LAZY")
2015-03-23 15:39:00 +00:00
*/
private $newSubscriberEvents;
2017-01-17 21:58:53 +00:00
/**
* @var bool
*
* @ORM\Column(name="is_removed", type="boolean", options={"default": false})
*/
private $removed = false;
2017-01-17 21:58:53 +00:00
public function __construct(int $id, \DateTime $createdAt = null, string $login = null, string $name = null)
{
$this->id = $id;
$this->login = $login;
$this->name = $name;
2017-01-17 21:58:53 +00:00
$this->createdAt = $createdAt ?: new \DateTime();
$this->subscribers = new ArrayCollection();
$this->subscriptions = new ArrayCollection();
2015-03-23 15:39:00 +00:00
$this->newSubscriberEvents = new ArrayCollection();
}
/**
* @ORM\PreUpdate
*/
public function preUpdate(): void
{
$this->updatedAt = new \DateTime();
}
public function getId(): int
{
return $this->id;
}
2017-01-17 01:36:35 +00:00
public function getLogin(): string
{
2017-01-17 01:36:35 +00:00
return $this->login;
}
2017-01-17 21:58:53 +00:00
public function getName(): ?string
{
2017-01-17 21:58:53 +00:00
return $this->name;
}
2017-01-17 21:58:53 +00:00
public function updateLoginAndName(string $login, ?string $name): self
2017-01-17 01:36:35 +00:00
{
2017-01-17 21:58:53 +00:00
$this->login = $login;
$this->name = $name;
return $this;
2017-01-17 01:36:35 +00:00
}
public function addSubscriber(Subscription $subscribers): self
{
$this->subscribers[] = $subscribers;
return $this;
}
public function removeSubscriber(Subscription $subscribers)
{
$this->subscribers->removeElement($subscribers);
}
/**
2015-06-02 02:39:09 +00:00
* @return Subscription[]|ArrayCollection
*/
public function getSubscribers(): iterable
{
return $this->subscribers;
}
/**
* @return Subscription[]|ArrayCollection
*/
public function getSubscriptions(): iterable
{
return $this->subscriptions;
}
2015-03-23 15:39:00 +00:00
public function addNewSubscriberEvent(SubscriptionEvent $newSubscriberEvents): self
2015-03-23 15:39:00 +00:00
{
$this->newSubscriberEvents[] = $newSubscriberEvents;
return $this;
}
/**
* @return SubscriptionEvent[]|ArrayCollection
2015-03-23 15:39:00 +00:00
*/
public function getNewSubscriberEvents(): iterable
2015-03-23 15:39:00 +00:00
{
return $this->newSubscriberEvents;
}
2015-05-28 17:36:52 +00:00
public function getCreatedAt(): \DateTime
2015-05-28 17:36:52 +00:00
{
return $this->createdAt;
}
2017-01-17 21:58:53 +00:00
public function getUpdatedAt(): ?\DateTime
2015-05-28 17:36:52 +00:00
{
2017-01-17 21:58:53 +00:00
return $this->updatedAt;
}
public function updatePrivacy(?bool $public, ?bool $whitelistOnly): void
{
$this->public = $public;
$this->whitelistOnly = $whitelistOnly;
}
public function isPublic(): ?bool
{
return $this->public;
}
public function isWhitelistOnly(): ?bool
{
return $this->whitelistOnly;
}
2017-01-17 21:58:53 +00:00
public function isRemoved(): bool
{
2017-01-17 23:42:06 +00:00
return $this->removed;
2015-05-28 17:36:52 +00:00
}
2017-01-17 21:58:53 +00:00
public function markAsRemoved(): void
{
2017-01-17 21:58:53 +00:00
$this->removed = true;
}
2017-01-18 01:06:55 +00:00
public function restore(): void
{
$this->removed = false;
}
}