src/Entity/DailyAdvice.php line 49

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use ApiPlatform\Core\Annotation\ApiFilter;
  5. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  7. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  8. use App\Repository\DailyAdviceRepository;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. /**
  13.  * @ORM\Entity(repositoryClass=DailyAdviceRepository::class)
  14.  * @ApiResource(
  15.  *     denormalizationContext={
  16.  *          "groups"={"daily_advice:write"}
  17.  *     },
  18.  *     normalizationContext={
  19.  *          "groups"={"daily_advice:read"}
  20.  *     },
  21.  *     collectionOperations={
  22.  *              "post"={"security"="is_granted('ROLE_ADMIN')"},
  23.  *              "get"={"security"="is_granted('ROLE_ADMIN')"},
  24.  *              "get_current_advice"={
  25.  *                  "security"="is_granted('ROLE_USER')",
  26.  *                  "method"="GET",
  27.  *                  "path"="/daily_advices/current",
  28.  *                  "controller"="App\Controller\Api\DailyAdviceController::current"
  29.  *              },
  30.  *     },
  31.  *     itemOperations={
  32.  *              "get"={"security"="is_granted('ROLE_USER')"},
  33.  *              "delete"={"security"="is_granted('ROLE_ADMIN')"},
  34.  *              "patch"={"security"="is_granted('ROLE_ADMIN')"},
  35.  *     },
  36.  * )
  37.  * @ApiFilter(SearchFilter::class, properties={"field":"partial", "value":"partial", "display":"exact"})
  38.  * @ApiFilter(OrderFilter::class, properties={"id", "field", "value", "display"})
  39.  * @ApiFilter(PropertyFilter::class, 
  40.  *      arguments={
  41.  *          "parameterName"="fields", 
  42.  *          "overrideDefaultProperties"=true
  43.  *     }
  44.  * )
  45.  */
  46. class DailyAdvice extends TvConfiguration
  47. {
  48.     /**
  49.      * @var string
  50.      * @Groups({"daily_advice:write", "daily_advice:read"})
  51.      * @Assert\Type(type="string")
  52.      */
  53.     private $name '';
  54.     /**
  55.      * @var string
  56.      * @Groups({"daily_advice:write","daily_advice:read"})
  57.      * @Assert\Type(type="string")
  58.      */
  59.     private $advice '';
  60.     public function __construct() 
  61.     {
  62.         $this->name '';
  63.         $this->field '';
  64.         $this->display true;
  65.     }
  66.     /**
  67.      * @return string
  68.      */
  69.     public function getName()
  70.     {
  71.         if ($this->name == null){
  72.             $this->name $this->field;
  73.         }
  74.         return $this->name;
  75.     }
  76.     /**
  77.      * @return string
  78.      */
  79.     public function getAdvice(): string
  80.     {
  81.         if ($this->advice == null){
  82.             $this->advice $this->value;
  83.         }
  84.         return $this->advice;
  85.     }
  86.     /**
  87.      * @param string $advice
  88.      * @return DailyAdvice
  89.      */
  90.     public function setAdvice(string $advice): DailyAdvice
  91.     {
  92.         $this->advice $advice;
  93.         $this->value $advice;
  94.         return $this;
  95.     }
  96.     /**
  97.      * @param string $name
  98.      * @return DailyAdvice
  99.      */
  100.     public function setName(string $name) :DailyAdvice
  101.     {
  102.         $this->name $name;
  103.         $this->field "$name";
  104.         return $this;
  105.     }
  106.     public function getField(): ?string
  107.     {
  108.         return $this->field;
  109.     }
  110.     public function setField(string $field): TvConfiguration
  111.     {
  112.         $this->field $field;
  113.         $this->name intval($field);
  114.         return $this;
  115.     }
  116.     public function getValue(): ?string
  117.     {
  118.         return $this->value;
  119.     }
  120.     public function setValue(string $value): TvConfiguration
  121.     {
  122.         $this->value $value;
  123.         $this->advice $value;
  124.         return $this;
  125.     }
  126. }