SHARE
TWEET

Untitled

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