src/Entity/UserGroup.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Dictionary\UserGroupJoinMode;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use JMS\Serializer\Annotation as Serializer;
  6. use JMS\Serializer\Annotation\Groups;
  7. /**
  8.  * @ORM\Table("Usergroup")
  9.  *
  10.  * @ORM\HasLifecycleCallbacks()
  11.  *
  12.  * @ORM\Entity(repositoryClass="App\Repository\UserGroupRepository")
  13.  */
  14. class UserGroup
  15. {
  16.     /**
  17.      * @Groups({"adminindex", "grouplist", "groupdetails"})
  18.      *
  19.      * @ORM\Id()
  20.      *
  21.      * @ORM\GeneratedValue()
  22.      *
  23.      * @ORM\Column(type="integer")
  24.      */
  25.     private $id;
  26.     /**
  27.      * @Groups({"adminindex", "grouplist", "groupdetails"})
  28.      *
  29.      * @ORM\Column(type="string", length=64)
  30.      */
  31.     private $name;
  32.     /**
  33.      * @Groups({"adminindex", "grouplist", "groupdetails"})
  34.      *
  35.      * @ORM\Column(type="string", length=64, nullable=true)
  36.      */
  37.     private $slug;
  38.     /**
  39.      * @Groups({"grouplist", "groupdetails"})
  40.      *
  41.      * @ORM\Column(type="text")
  42.      */
  43.     private $description;
  44.     /**
  45.      * @Groups({"grouplist", "groupdetails"})
  46.      *
  47.      * @ORM\Column(type="smallint")
  48.      */
  49.     private $category;
  50.     /**
  51.      * @Groups({"grouplist", "groupdetails"})
  52.      *
  53.      * @ORM\ManyToOne(targetEntity="App\Entity\Member", cascade={"persist"})
  54.      *
  55.      * @ORM\JoinColumn(name="founder_id", referencedColumnName="id", onDelete="SET NULL")
  56.      */
  57.     private $founder;
  58.     /**
  59.      * @Groups({"groupdetails"})
  60.      *
  61.      * @ORM\ManyToOne(targetEntity="App\Entity\Member", cascade={"persist"})
  62.      *
  63.      * @ORM\JoinColumn(name="owner_id", referencedColumnName="id", onDelete="SET NULL")
  64.      */
  65.     private $owner;
  66.     /**
  67.      * @ORM\ManyToOne(targetEntity="App\Entity\MemberMedia",cascade={"persist"}, fetch="EAGER")
  68.      *
  69.      * @ORM\JoinColumn(name="photo_id", referencedColumnName="id", onDelete="SET NULL")
  70.      */
  71.     private $photo;
  72.     /**
  73.      * /**
  74.      * @Groups({"grouplist"})
  75.      *
  76.      * @ORM\Column(type="boolean")
  77.      */
  78.     private $is_active false;
  79.     /**
  80.      * @Groups({"grouplist"})
  81.      *
  82.      * @ORM\Column(type="string", length=32)
  83.      */
  84.     private $seo_robots 'index, follow';
  85.     /**
  86.      * @Groups({"grouplist", "groupdetails", "membergrouplist"})
  87.      *
  88.      * @ORM\Column(type="smallint")
  89.      */
  90.     private $join_mode UserGroupJoinMode::PUBLIC;
  91.     /**
  92.      * @Groups({"grouplist", "groupdetails"})
  93.      *
  94.      * @ORM\Column(type="datetime")
  95.      */
  96.     private $created_at;
  97.     /**
  98.      * @Groups({"grouplist"})
  99.      *
  100.      * @ORM\OneToOne(targetEntity="App\Entity\UserGroupStat", mappedBy="userGroup", cascade={"persist", "remove"})
  101.      */
  102.     private $userGroupStat;
  103.     /**
  104.      * @ORM\PrePersist()
  105.      */
  106.     public function prePersistValues()
  107.     {
  108.         if (!$this->getCreatedAt()) {
  109.             $this->setCreatedAt(new \DateTime());
  110.         }
  111.     }
  112.     public function getId()
  113.     {
  114.         return $this->id;
  115.     }
  116.     public function getName(): ?string
  117.     {
  118.         return $this->name;
  119.     }
  120.     public function setName(string $name): self
  121.     {
  122.         $this->name $name;
  123.         return $this;
  124.     }
  125.     public function getSlug(): ?string
  126.     {
  127.         return $this->slug;
  128.     }
  129.     /**
  130.      * @return $this
  131.      */
  132.     public function setSlug(?string $slug): self
  133.     {
  134.         if (!empty($slug)) {
  135.             $slug str_replace(' ''-'$slug);
  136.             $slug trim(strtolower($slug));
  137.         }
  138.         $this->slug $slug;
  139.         return $this;
  140.     }
  141.     public function getDescription(): ?string
  142.     {
  143.         return $this->description;
  144.     }
  145.     public function setDescription(string $description): self
  146.     {
  147.         $this->description $description;
  148.         return $this;
  149.     }
  150.     public function getCategory(): ?int
  151.     {
  152.         return $this->category;
  153.     }
  154.     public function setCategory(int $category): self
  155.     {
  156.         $this->category $category;
  157.         return $this;
  158.     }
  159.     public function getFounder(): ?Member
  160.     {
  161.         return $this->founder;
  162.     }
  163.     public function setFounder(?Member $founder): self
  164.     {
  165.         $this->founder $founder;
  166.         return $this;
  167.     }
  168.     public function getOwner(): ?Member
  169.     {
  170.         return $this->owner;
  171.     }
  172.     public function setOwner(?Member $owner): self
  173.     {
  174.         $this->owner $owner;
  175.         return $this;
  176.     }
  177.     public function getPhoto(): ?MemberMedia
  178.     {
  179.         return $this->photo;
  180.     }
  181.     public function setPhoto(?MemberMedia $photo): self
  182.     {
  183.         $this->photo $photo;
  184.         return $this;
  185.     }
  186.     /**
  187.      * @return $this
  188.      */
  189.     public function setPhotoUrl(string $url): self
  190.     {
  191.         $this->photoUrl $url;
  192.         return $this;
  193.     }
  194.     public function getIsActive(): ?bool
  195.     {
  196.         return $this->is_active;
  197.     }
  198.     public function setIsActive(bool $is_active): self
  199.     {
  200.         $this->is_active $is_active;
  201.         return $this;
  202.     }
  203.     public function getSeoRobots(): ?string
  204.     {
  205.         return $this->seo_robots;
  206.     }
  207.     public function setSeoRobots(string $seo_robots): self
  208.     {
  209.         $this->seo_robots $seo_robots;
  210.         return $this;
  211.     }
  212.     public function getJoinMode(): ?int
  213.     {
  214.         return $this->join_mode;
  215.     }
  216.     public function setJoinMode(int $join_mode): self
  217.     {
  218.         $this->join_mode $join_mode;
  219.         return $this;
  220.     }
  221.     public function getCreatedAt(): ?\DateTimeInterface
  222.     {
  223.         return $this->created_at;
  224.     }
  225.     public function setCreatedAt(\DateTimeInterface $created_at): self
  226.     {
  227.         $this->created_at $created_at;
  228.         return $this;
  229.     }
  230.     public function getUserGroupStat(): ?UserGroupStat
  231.     {
  232.         return $this->userGroupStat;
  233.     }
  234.     public function setUserGroupStat(UserGroupStat $userGroupStat): self
  235.     {
  236.         $this->userGroupStat $userGroupStat;
  237.         // set the owning side of the relation if necessary
  238.         if ($this !== $userGroupStat->getUserGroup()) {
  239.             $userGroupStat->setUserGroup($this);
  240.         }
  241.         return $this;
  242.     }
  243.     /**
  244.      * @Serializer\VirtualProperty()
  245.      *
  246.      * @Groups({"grouplist", "groupdetails"})
  247.      */
  248.     public function getPhotoUrl(?string $filter null): ?string
  249.     {
  250.         if ($this->photo instanceof MemberMedia) {
  251.             return $this->photo->getUrl($filter);
  252.         }
  253.         return null;
  254.     }
  255.     /**
  256.      * @Serializer\VirtualProperty()
  257.      *
  258.      * @Groups({"grouplist", "groupdetails"})
  259.      */
  260.     public function getPixelatedPhotoUrl(?string $filter null): ?string
  261.     {
  262.         if ($this->photo instanceof MemberMedia) {
  263.             return $this->photo->getPixelatedUrl($filter);
  264.         }
  265.         return null;
  266.     }
  267.     /**
  268.      * @Serializer\VirtualProperty()
  269.      *
  270.      * @Groups({"grouplist", "groupdetails"})
  271.      */
  272.     public function getPhotoIsHardcore(): bool
  273.     {
  274.         if ($this->photo instanceof MemberMedia) {
  275.             return $this->photo->getIsHardcore() ?? false;
  276.         }
  277.         return false;
  278.     }
  279. }