Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.18 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Entity;
  4.  
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Gedmo\Timestampable\Traits\TimestampableEntity;
  9. use Gedmo\Mapping\Annotation as Gedmo;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11.  
  12. /**
  13.  * @ORM\Entity(repositoryClass="App\Repository\PostRepository")
  14.  */
  15. class Post
  16. {
  17.     const FILES_IMAGES_LOCATION = "/upload/post/";
  18.  
  19.     use TimestampableEntity;
  20.     /**
  21.      * @ORM\Id()
  22.      * @ORM\GeneratedValue()
  23.      * @ORM\Column(type="integer")
  24.      */
  25.     private $id;
  26.  
  27.     /**
  28.      * @ORM\Column(type="string", length=255, nullable=true)
  29.      */
  30.     private $title;
  31.  
  32.     /**
  33.      * @ORM\Column(type="text", nullable=true)
  34.      */
  35.     private $description;
  36.     /**
  37.      * @ORM\Column(type="string", length=355, nullable=true)
  38.      */
  39.     private $source;
  40.     /**
  41.      * @ORM\Column(type="text", nullable=true)
  42.      */
  43.     private $extension;
  44.     /**
  45.      * @ORM\Column(type="integer")
  46.      */
  47.     private $views = 0;
  48.     /**
  49.      * @ORM\Column(type="integer")
  50.      */
  51.     private $voteUp = 0;
  52.     /**
  53.      * @ORM\Column(type="integer")
  54.      */
  55.     private $voteDown = 0;
  56.     /**
  57.      * @ORM\Column(type="boolean")
  58.      */
  59.     private $isDeleted = false;
  60.     /**
  61.      * @ORM\Column(type="boolean")
  62.      */
  63.     private $isHide = false;
  64.  
  65.     /**
  66.      * @Gedmo\Slug(fields={"title"})
  67.      * @ORM\Column(length=90, unique=false)
  68.      */
  69.     private $slug;
  70.     /**
  71.      * @ORM\Column(type="boolean", nullable=false)
  72.      */
  73.     private $isImageFromDisc = false;
  74.  
  75.     /**
  76.      * @ORM\Column(type="boolean", nullable=false)
  77.      */
  78.     private $isImageFromLink = false;
  79.     /**
  80.      * @ORM\Column(type="boolean", nullable=false)
  81.      */
  82.     private $isYotubeLink = false;
  83.     /**
  84.      * @ORM\Column(type="string",length=100)
  85.      */
  86.     private $youtubeID = '';
  87.     /**
  88.      * @ORM\Column(type="boolean")
  89.      */
  90.     private $isConfirm = false;
  91.     /**
  92.      * @ORM\Column(type="boolean")
  93.      */
  94.     private $isGraphic = false;
  95.  
  96.     /**
  97.      * @ORM\Column(type="boolean")
  98.      */
  99.     private $isPost = false;
  100.     /**
  101.      * @ORM\Column(type="boolean")
  102.      */
  103.     private $isWaitingRoom = true;
  104.     /**
  105.      * @ORM\OneToMany(targetEntity="App\Entity\Category", mappedBy="post")
  106.      */
  107.     private $categories;
  108.  
  109.     /**
  110.      * @ORM\OneToMany(targetEntity="App\Entity\Vote", mappedBy="post")
  111.      */
  112.     private $votes;
  113.  
  114.     /**
  115.      * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="posts")
  116.      */
  117.     private $author;
  118.  
  119.     /**
  120.      * @ORM\OneToMany(targetEntity="App\Entity\Comment", mappedBy="post")
  121.      */
  122.     private $comments;
  123.  
  124.     /**
  125.      * @ORM\OneToMany(targetEntity="App\Entity\Notification", mappedBy="post")
  126.      */
  127.     private $notifications;
  128.  
  129.     /**
  130.      * @ORM\OneToMany(targetEntity="App\Entity\Report", mappedBy="post")
  131.      */
  132.     private $reports;
  133.  
  134.  
  135.  
  136.  
  137.     public function __construct()
  138.     {
  139.         $this->categories = new ArrayCollection();
  140.         $this->votes = new ArrayCollection();
  141.         $this->comments = new ArrayCollection();
  142.         $this->notifications = new ArrayCollection();
  143.         $this->reports = new ArrayCollection();
  144.     }
  145.  
  146.     public function getVoteValue(){
  147.         return $this->getVoteUp() - $this->getVoteDown();
  148.     }
  149.     public function getImageUrl($type = false)
  150.     {
  151.         if (!$type) {
  152.             return self::FILES_IMAGES_LOCATION . $this->getId() . '.' . $this->getExtension();
  153.         } else {
  154.             return self::FILES_IMAGES_LOCATION . $this->getId() . '-' . $type . '.' . $this->getExtension();
  155.         }
  156.     }
  157.  
  158.     public function isPostVoted($id)
  159.     {
  160.         $resultArray = [];
  161.         foreach ($this->votes as $v) {
  162.             $resultArray[$v->getPost()->getId()] = $v;
  163.         }
  164.  
  165.         return array_key_exists($id, $resultArray) ? $resultArray{$id} : null;
  166.     }
  167.  
  168.     public function getId(): ?int
  169.     {
  170.         return $this->id;
  171.     }
  172.  
  173.     public function getTitle(): ?string
  174.     {
  175.         return $this->title;
  176.     }
  177.  
  178.     public function setTitle(?string $title): self
  179.     {
  180.         $this->title = $title;
  181.  
  182.         return $this;
  183.     }
  184.  
  185.     public function getDescription(): ?string
  186.     {
  187.         return $this->description;
  188.     }
  189.  
  190.     public function setDescription(?string $description): self
  191.     {
  192.         $this->description = $description;
  193.  
  194.         return $this;
  195.     }
  196.  
  197.     public function getExtension(): ?string
  198.     {
  199.         return $this->extension;
  200.     }
  201.  
  202.     public function setExtension(?string $extension): self
  203.     {
  204.         $this->extension = $extension;
  205.  
  206.         return $this;
  207.     }
  208.  
  209.     public function getViews(): ?int
  210.     {
  211.         return $this->views;
  212.     }
  213.  
  214.     public function setViews(int $views): self
  215.     {
  216.         $this->views = $views;
  217.  
  218.         return $this;
  219.     }
  220.  
  221.  
  222.     public function getIsDeleted(): ?bool
  223.     {
  224.         return $this->isDeleted;
  225.     }
  226.  
  227.     public function setIsDeleted(bool $isDeleted): self
  228.     {
  229.         $this->isDeleted = $isDeleted;
  230.  
  231.         return $this;
  232.     }
  233.  
  234.     public function getSlug(): ?string
  235.     {
  236.         return $this->slug;
  237.     }
  238.  
  239.     public function setSlug(string $slug): self
  240.     {
  241.         $this->slug = $slug;
  242.  
  243.         return $this;
  244.     }
  245.  
  246.     public function getIsImageFromDisc(): ?bool
  247.     {
  248.         return $this->isImageFromDisc;
  249.     }
  250.  
  251.     public function setIsImageFromDisc(bool $isImageFromDisc): self
  252.     {
  253.         $this->isImageFromDisc = $isImageFromDisc;
  254.  
  255.         return $this;
  256.     }
  257.  
  258.     public function getIsImageFromLink(): ?bool
  259.     {
  260.         return $this->isImageFromLink;
  261.     }
  262.  
  263.     public function setIsImageFromLink(bool $isImageFromLink): self
  264.     {
  265.         $this->isImageFromLink = $isImageFromLink;
  266.  
  267.         return $this;
  268.     }
  269.  
  270.     public function getIsYotubeLink(): ?bool
  271.     {
  272.         return $this->isYotubeLink;
  273.     }
  274.  
  275.     public function setIsYotubeLink(bool $isYotubeLink): self
  276.     {
  277.         $this->isYotubeLink = $isYotubeLink;
  278.  
  279.         return $this;
  280.     }
  281.  
  282.     public function getYoutubeID(): ?string
  283.     {
  284.         return $this->youtubeID;
  285.     }
  286.  
  287.     public function setYoutubeID(string $youtubeID): self
  288.     {
  289.         $this->youtubeID = $youtubeID;
  290.  
  291.         return $this;
  292.     }
  293.  
  294.     public function getIsConfirm(): ?bool
  295.     {
  296.         return $this->isConfirm;
  297.     }
  298.  
  299.     public function setIsConfirm(bool $isConfirm): self
  300.     {
  301.         $this->isConfirm = $isConfirm;
  302.  
  303.         return $this;
  304.     }
  305.  
  306.     /**
  307.      * @return Collection|Category[]
  308.      */
  309.     public function getCategories(): Collection
  310.     {
  311.         return $this->categories;
  312.     }
  313.  
  314.     public function addCategory(Category $category): self
  315.     {
  316.         if (!$this->categories->contains($category)) {
  317.             $this->categories[] = $category;
  318.             $category->setPost($this);
  319.         }
  320.  
  321.         return $this;
  322.     }
  323.  
  324.     public function removeCategory(Category $category): self
  325.     {
  326.         if ($this->categories->contains($category)) {
  327.             $this->categories->removeElement($category);
  328.             // set the owning side to null (unless already changed)
  329.             if ($category->getPost() === $this) {
  330.                 $category->setPost(null);
  331.             }
  332.         }
  333.  
  334.         return $this;
  335.     }
  336.  
  337.     /**
  338.      * @return Collection|Vote[]
  339.      */
  340.     public function getVotes(): Collection
  341.     {
  342.         return $this->votes;
  343.     }
  344.  
  345.     public function addVote(Vote $vote): self
  346.     {
  347.         if (!$this->votes->contains($vote)) {
  348.             $this->votes[] = $vote;
  349.             $vote->setPost($this);
  350.         }
  351.  
  352.         return $this;
  353.     }
  354.  
  355.     public function removeVote(Vote $vote): self
  356.     {
  357.         if ($this->votes->contains($vote)) {
  358.             $this->votes->removeElement($vote);
  359.             // set the owning side to null (unless already changed)
  360.             if ($vote->getPost() === $this) {
  361.                 $vote->setPost(null);
  362.             }
  363.         }
  364.  
  365.         return $this;
  366.     }
  367.  
  368.     public function getAuthor(): ?User
  369.     {
  370.         return $this->author;
  371.     }
  372.  
  373.     public function setAuthor(?User $author): self
  374.     {
  375.         $this->author = $author;
  376.  
  377.         return $this;
  378.     }
  379.  
  380.     /**
  381.      * @return Collection|Comment[]
  382.      */
  383.     public function getComments(): Collection
  384.     {
  385.         return $this->comments;
  386.     }
  387.  
  388.     public function addComment(Comment $comment): self
  389.     {
  390.         if (!$this->comments->contains($comment)) {
  391.             $this->comments[] = $comment;
  392.             $comment->setPost($this);
  393.         }
  394.  
  395.         return $this;
  396.     }
  397.  
  398.     public function removeComment(Comment $comment): self
  399.     {
  400.         if ($this->comments->contains($comment)) {
  401.             $this->comments->removeElement($comment);
  402.             // set the owning side to null (unless already changed)
  403.             if ($comment->getPost() === $this) {
  404.                 $comment->setPost(null);
  405.             }
  406.         }
  407.  
  408.         return $this;
  409.     }
  410.  
  411.     /**
  412.      * @return Collection|Notification[]
  413.      */
  414.     public function getNotifications(): Collection
  415.     {
  416.         return $this->notifications;
  417.     }
  418.  
  419.     public function addNotification(Notification $notification): self
  420.     {
  421.         if (!$this->notifications->contains($notification)) {
  422.             $this->notifications[] = $notification;
  423.             $notification->setPost($this);
  424.         }
  425.  
  426.         return $this;
  427.     }
  428.  
  429.     public function removeNotification(Notification $notification): self
  430.     {
  431.         if ($this->notifications->contains($notification)) {
  432.             $this->notifications->removeElement($notification);
  433.             // set the owning side to null (unless already changed)
  434.             if ($notification->getPost() === $this) {
  435.                 $notification->setPost(null);
  436.             }
  437.         }
  438.  
  439.         return $this;
  440.     }
  441.  
  442.     public function getIsGraphic(): ?bool
  443.     {
  444.         return $this->isGraphic;
  445.     }
  446.  
  447.     public function setIsGraphic(bool $isGraphic): self
  448.     {
  449.         $this->isGraphic = $isGraphic;
  450.  
  451.         return $this;
  452.     }
  453.  
  454.     public function getIsPost(): ?bool
  455.     {
  456.         return $this->isPost;
  457.     }
  458.  
  459.     public function setIsPost(bool $isPost): self
  460.     {
  461.         $this->isPost = $isPost;
  462.  
  463.         return $this;
  464.     }
  465.    
  466.  
  467.     public function getVoteUp(): ?int
  468.     {
  469.         return $this->voteUp;
  470.     }
  471.  
  472.     public function setVoteUp(int $voteUp): self
  473.     {
  474.         $this->voteUp = $voteUp;
  475.  
  476.         return $this;
  477.     }
  478.  
  479.     public function getVoteDown(): ?int
  480.     {
  481.         return $this->voteDown;
  482.     }
  483.  
  484.     public function setVoteDown(int $voteDown): self
  485.     {
  486.         $this->voteDown = $voteDown;
  487.  
  488.         return $this;
  489.     }
  490.  
  491.     /**
  492.      * @return Collection|Report[]
  493.      */
  494.     public function getReports(): Collection
  495.     {
  496.         return $this->reports;
  497.     }
  498.  
  499.     public function addReport(Report $report): self
  500.     {
  501.         if (!$this->reports->contains($report)) {
  502.             $this->reports[] = $report;
  503.             $report->setPost($this);
  504.         }
  505.  
  506.         return $this;
  507.     }
  508.  
  509.     public function removeReport(Report $report): self
  510.     {
  511.         if ($this->reports->contains($report)) {
  512.             $this->reports->removeElement($report);
  513.             // set the owning side to null (unless already changed)
  514.             if ($report->getPost() === $this) {
  515.                 $report->setPost(null);
  516.             }
  517.         }
  518.  
  519.         return $this;
  520.     }
  521.  
  522.     public function getIsWaitingRoom(): ?bool
  523.     {
  524.         return $this->isWaitingRoom;
  525.     }
  526.  
  527.     public function setIsWaitingRoom(bool $isWaitingRoom): self
  528.     {
  529.         $this->isWaitingRoom = $isWaitingRoom;
  530.  
  531.         return $this;
  532.     }
  533.  
  534.     public function getIsHide(): ?bool
  535.     {
  536.         return $this->isHide;
  537.     }
  538.  
  539.     public function setIsHide(bool $isHide): self
  540.     {
  541.         $this->isHide = $isHide;
  542.  
  543.         return $this;
  544.     }
  545.  
  546.     public function getSource(): ?string
  547.     {
  548.         return $this->source;
  549.     }
  550.  
  551.     public function setSource(?string $source): self
  552.     {
  553.         $this->source = $source;
  554.  
  555.         return $this;
  556.     }
  557.  
  558.  
  559. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement