src/Entity/ElCourseRating.php line 44

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use ApiPlatform\Core\Annotation\ApiFilter;
  5. use App\Entity\Traits\TimestampableEntity;
  6. use ApiPlatform\Core\Annotation\ApiResource;
  7. use App\Repository\ElCourseRatingRepository;
  8. use App\Entity\Interfaces\OwnerMappedInterface;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  11. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  12. /**
  13.  * @ApiResource(
  14.  *      normalizationContext={"groups"={"ElCourseRating:Read", "TZ:Read"}, "skip_null_values"=false},
  15.  *      denormalizationContext={"groups"={"ElCourseRating:Write"}},
  16.  *      collectionOperations={
  17.  *          "get"={
  18.  *              "security"="is_granted('IS_AUTHENTICATED_FULLY')"
  19.  *          },
  20.  *          "post"={
  21.  *              "security"="is_granted('IS_AUTHENTICATED_FULLY')"
  22.  *          }
  23.  *      },
  24.  *      itemOperations={
  25.  *          "get"={
  26.  *              "security"="is_granted('ROLE_ADMIN', object) || is_granted('IS_CO_ANY_SPE', object)"
  27.  *          },
  28.  *          "patch"={
  29.  *              "security"="is_granted('ROLE_ADMIN', object) || is_granted('IS_CO_ANY_SPE', object)"
  30.  *          },
  31.  *          "delete"={
  32.  *              "security"="is_granted('ROLE_ADMIN', object) || is_granted('IS_CO_ANY_SPE', object)"
  33.  *          }
  34.  *     }
  35.  * )
  36.  * @ApiFilter(SearchFilter::class, properties={"elCourse.id": "exact", "user.id": "exact", "comment": "partial"})
  37.  * @ApiFilter(OrderFilter::class, properties={"id": "desc", "createdAt", "rate"})
  38.  * @ORM\Entity(repositoryClass=ElCourseRatingRepository::class)
  39.  */
  40. class ElCourseRating implements OwnerMappedInterface
  41. {
  42.     /**
  43.      * Hook timestampable behavior
  44.      * updates createdAt, updatedAt fields
  45.      */
  46.     use TimestampableEntity;
  47.     /**
  48.      * @ORM\Id
  49.      * @ORM\GeneratedValue
  50.      * @ORM\Column(type="integer")
  51.      * @Groups({"ElCourseRating:Read"})
  52.      */
  53.     private $id;
  54.     /**
  55.      * @ORM\Column(type="integer")
  56.      * @Groups({"ElCourseRating:Read", "ElCourseRating:Write"})
  57.      */
  58.     private $rate;
  59.     /**
  60.      * @ORM\Column(type="text", nullable=true)
  61.      * @Groups({"ElCourseRating:Read", "ElCourseRating:Write"})
  62.      */
  63.     private $comment;
  64.     /**
  65.      * @ORM\ManyToOne(targetEntity=ElCourse::class, inversedBy="elCourseRatings")
  66.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  67.      * @Groups({"ElCourseRating:Write"})
  68.      */
  69.     private $elCourse;
  70.     /**
  71.      * @ORM\ManyToOne(targetEntity=User::class)
  72.      * @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
  73.      * @Groups({"ElCourseRating:Read"})
  74.      */
  75.     private $user;
  76.     public function getId(): ?int
  77.     {
  78.         return $this->id;
  79.     }
  80.     public function getRate(): ?int
  81.     {
  82.         return $this->rate;
  83.     }
  84.     public function setRate(int $rate): self
  85.     {
  86.         $this->rate $rate;
  87.         return $this;
  88.     }
  89.     public function getComment(): ?string
  90.     {
  91.         return $this->comment;
  92.     }
  93.     public function setComment(?string $comment): self
  94.     {
  95.         $this->comment $comment;
  96.         return $this;
  97.     }
  98.     public function getElCourse(): ?ElCourse
  99.     {
  100.         return $this->elCourse;
  101.     }
  102.     public function setElCourse(?ElCourse $elCourse): self
  103.     {
  104.         $this->elCourse $elCourse;
  105.         return $this;
  106.     }
  107.     public function getUser(): ?User
  108.     {
  109.         return $this->user;
  110.     }
  111.     public function setUser(?User $user): self
  112.     {
  113.         $this->user $user;
  114.         return $this;
  115.     }
  116. }