<?php
namespace App\Entity;
use App\Dictionary\UserGroupJoinMode;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
use JMS\Serializer\Annotation\Groups;
/**
* @ORM\Table("Usergroup")
*
* @ORM\HasLifecycleCallbacks()
*
* @ORM\Entity(repositoryClass="App\Repository\UserGroupRepository")
*/
class UserGroup
{
/**
* @Groups({"adminindex", "grouplist", "groupdetails"})
*
* @ORM\Id()
*
* @ORM\GeneratedValue()
*
* @ORM\Column(type="integer")
*/
private $id;
/**
* @Groups({"adminindex", "grouplist", "groupdetails"})
*
* @ORM\Column(type="string", length=64)
*/
private $name;
/**
* @Groups({"adminindex", "grouplist", "groupdetails"})
*
* @ORM\Column(type="string", length=64, nullable=true)
*/
private $slug;
/**
* @Groups({"grouplist", "groupdetails"})
*
* @ORM\Column(type="text")
*/
private $description;
/**
* @Groups({"grouplist", "groupdetails"})
*
* @ORM\Column(type="smallint")
*/
private $category;
/**
* @Groups({"grouplist", "groupdetails"})
*
* @ORM\ManyToOne(targetEntity="App\Entity\Member", cascade={"persist"})
*
* @ORM\JoinColumn(name="founder_id", referencedColumnName="id", onDelete="SET NULL")
*/
private $founder;
/**
* @Groups({"groupdetails"})
*
* @ORM\ManyToOne(targetEntity="App\Entity\Member", cascade={"persist"})
*
* @ORM\JoinColumn(name="owner_id", referencedColumnName="id", onDelete="SET NULL")
*/
private $owner;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\MemberMedia",cascade={"persist"}, fetch="EAGER")
*
* @ORM\JoinColumn(name="photo_id", referencedColumnName="id", onDelete="SET NULL")
*/
private $photo;
/**
* /**
* @Groups({"grouplist"})
*
* @ORM\Column(type="boolean")
*/
private $is_active = false;
/**
* @Groups({"grouplist"})
*
* @ORM\Column(type="string", length=32)
*/
private $seo_robots = 'index, follow';
/**
* @Groups({"grouplist", "groupdetails", "membergrouplist"})
*
* @ORM\Column(type="smallint")
*/
private $join_mode = UserGroupJoinMode::PUBLIC;
/**
* @Groups({"grouplist", "groupdetails"})
*
* @ORM\Column(type="datetime")
*/
private $created_at;
/**
* @Groups({"grouplist"})
*
* @ORM\OneToOne(targetEntity="App\Entity\UserGroupStat", mappedBy="userGroup", cascade={"persist", "remove"})
*/
private $userGroupStat;
/**
* @ORM\PrePersist()
*/
public function prePersistValues()
{
if (!$this->getCreatedAt()) {
$this->setCreatedAt(new \DateTime());
}
}
public function getId()
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
/**
* @return $this
*/
public function setSlug(?string $slug): self
{
if (!empty($slug)) {
$slug = str_replace(' ', '-', $slug);
$slug = trim(strtolower($slug));
}
$this->slug = $slug;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function getCategory(): ?int
{
return $this->category;
}
public function setCategory(int $category): self
{
$this->category = $category;
return $this;
}
public function getFounder(): ?Member
{
return $this->founder;
}
public function setFounder(?Member $founder): self
{
$this->founder = $founder;
return $this;
}
public function getOwner(): ?Member
{
return $this->owner;
}
public function setOwner(?Member $owner): self
{
$this->owner = $owner;
return $this;
}
public function getPhoto(): ?MemberMedia
{
return $this->photo;
}
public function setPhoto(?MemberMedia $photo): self
{
$this->photo = $photo;
return $this;
}
/**
* @return $this
*/
public function setPhotoUrl(string $url): self
{
$this->photoUrl = $url;
return $this;
}
public function getIsActive(): ?bool
{
return $this->is_active;
}
public function setIsActive(bool $is_active): self
{
$this->is_active = $is_active;
return $this;
}
public function getSeoRobots(): ?string
{
return $this->seo_robots;
}
public function setSeoRobots(string $seo_robots): self
{
$this->seo_robots = $seo_robots;
return $this;
}
public function getJoinMode(): ?int
{
return $this->join_mode;
}
public function setJoinMode(int $join_mode): self
{
$this->join_mode = $join_mode;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeInterface $created_at): self
{
$this->created_at = $created_at;
return $this;
}
public function getUserGroupStat(): ?UserGroupStat
{
return $this->userGroupStat;
}
public function setUserGroupStat(UserGroupStat $userGroupStat): self
{
$this->userGroupStat = $userGroupStat;
// set the owning side of the relation if necessary
if ($this !== $userGroupStat->getUserGroup()) {
$userGroupStat->setUserGroup($this);
}
return $this;
}
/**
* @Serializer\VirtualProperty()
*
* @Groups({"grouplist", "groupdetails"})
*/
public function getPhotoUrl(?string $filter = null): ?string
{
if ($this->photo instanceof MemberMedia) {
return $this->photo->getUrl($filter);
}
return null;
}
/**
* @Serializer\VirtualProperty()
*
* @Groups({"grouplist", "groupdetails"})
*/
public function getPixelatedPhotoUrl(?string $filter = null): ?string
{
if ($this->photo instanceof MemberMedia) {
return $this->photo->getPixelatedUrl($filter);
}
return null;
}
/**
* @Serializer\VirtualProperty()
*
* @Groups({"grouplist", "groupdetails"})
*/
public function getPhotoIsHardcore(): bool
{
if ($this->photo instanceof MemberMedia) {
return $this->photo->getIsHardcore() ?? false;
}
return false;
}
}