src/Entity/CreditCategory.php line 48

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\CreditCategoryRepository;
  8. use App\Entity\Interfaces\ClientMappedInterface;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  12. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  13. use Locastic\ApiPlatformTranslationBundle\Model\AbstractTranslatable;
  14. use Locastic\ApiPlatformTranslationBundle\Model\TranslationInterface;
  15. /**
  16.  * @ApiResource(
  17.  *      attributes={"security"="is_granted('ROLE_SUPER_ADMIN')", "filters"={"translation.groups"}},
  18.  *      normalizationContext={"groups"={"CreditCategory:Read"}, "skip_null_values"=false},
  19.  *      denormalizationContext={"groups"={"CreditCategory:Write"}},
  20.  *      collectionOperations={
  21.  *          "get"={
  22.  *              "security"="is_granted('IS_AUTHENTICATED_FULLY')",
  23.  *              "pagination_enabled"=false
  24.  *          },
  25.  *          "get_for_public_page"={
  26.  *              "route_name"="api_pub_credit_categories_get_for_public_page_collection",
  27.  *              "method"="GET",
  28.  *              "security"="is_granted('PUBLIC_ACCESS')",
  29.  *              "normalization_context"={"groups"={"CreditCategory:PRead"}, "skip_null_values"=false},
  30.  *              "pagination_enabled"=false
  31.  *          },
  32.  *          "post"
  33.  *      },
  34.  *      itemOperations={
  35.  *          "get",
  36.  *          "put",
  37.  *          "patch",
  38.  *          "delete"
  39.  *     }
  40.  * )
  41.  * @ApiFilter(SearchFilter::class, properties={"id": "exact", "client.id": "exact", "translations.name": "partial"})
  42.  * @ApiFilter(OrderFilter::class, properties={"ord": "ASC", "translations.name"})
  43.  * @ORM\Entity(repositoryClass=CreditCategoryRepository::class)
  44.  */
  45. class CreditCategory extends AbstractTranslatable implements ClientMappedInterface
  46. {
  47.     /**
  48.      * Hook timestampable behavior
  49.      * updates createdAt, updatedAt fields
  50.      */
  51.     use TimestampableEntity;
  52.     /**
  53.      * @ORM\OneToMany(targetEntity="CreditCategoryTranslation", mappedBy="translatable", fetch="EXTRA_LAZY", indexBy="locale", cascade={"PERSIST"}, orphanRemoval=true)
  54.      *
  55.      * @Groups({"CreditCategory:Write", "CreditCategoryTranslationGroup"})
  56.      * @Assert\Valid()
  57.      */
  58.     protected $translations;
  59.     /**
  60.      * @Groups({"CreditCategory:Read", "CreditCategory:PRead", "Conference:Read", "Conference:PRead", "ElCourse:Read", "ElCourse:PRead", "Certificate:Read"})
  61.      */
  62.     private $name;
  63.     /**
  64.      * @ORM\Id
  65.      * @ORM\GeneratedValue
  66.      * @ORM\Column(type="integer")
  67.      * @Groups({"CreditCategory:Read", "CreditCategory:PRead"})
  68.      */
  69.     private $id;
  70.     /**
  71.      * @ORM\ManyToOne(targetEntity=Client::class)
  72.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  73.      * @Groups({"CreditCategory:Read", "CreditCategory:Write"})
  74.      */
  75.     private $client;
  76.     public function __construct()
  77.     {
  78.         parent::__construct();
  79.     }
  80.     protected function createTranslation(): TranslationInterface
  81.     {
  82.         return new CreditCategoryTranslation();
  83.     }
  84.     public function getName(): ?string
  85.     {
  86.         return $this->getTranslation()->getName();
  87.     }
  88.     public function setName(string $name): self
  89.     {
  90.         $this->getTranslation()->setName($name);
  91.         return $this;
  92.     }
  93.     public function getId(): ?int
  94.     {
  95.         return $this->id;
  96.     }
  97.     public function getClient(): ?Client
  98.     {
  99.         return $this->client;
  100.     }
  101.     public function setClient(?Client $client): self
  102.     {
  103.         $this->client $client;
  104.         return $this;
  105.     }
  106. }