<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
use App\Repository\SurveyFormSurveyCompanyRepository;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ORM\Entity(repositoryClass=SurveyFormSurveyCompanyRepository::class)
*/
#[HasLifecycleCallbacks()]
#[ApiResource(
attributes: ['security' => "is_granted('ROLE_USER')"],
normalizationContext: ['groups' => ['sfsc:read']],
denormalizationContext: ['groups' => ['sfsc:write']],
collectionOperations: [
'get',
'post' => [
'security' => "is_granted('ROLE_ADMIN')",
],
],
itemOperations: [
'get',
'put' => ['security' => "is_granted('ROLE_ADMIN') or object.owner == user"],
],
)]
#[ApiFilter(SearchFilter::class, properties: ['id', 'surveyCompany' => 'exact', 'surveyForm' => 'exact'])]
#[ApiFilter(PropertyFilter::class)]
#[ApiFilter(OrderFilter::class, properties: ['id', 'surveyCompany.title', 'surveyForm.title'], arguments: ['orderParameterName' => 'order'])]
class SurveyFormSurveyCompany
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=SurveyForm::class, inversedBy="surveyCompanies")
* @ORM\JoinColumn(name="survey_form_id", referencedColumnName="id", nullable=false)
* @Groups({"sfsc:read","sfsc:write"})
*/
private $surveyForm;
/**
* @ORM\ManyToOne(targetEntity=SurveyCompany::class, inversedBy="forms")
* @ORM\JoinColumn(name="survey_company_id", referencedColumnName="id", nullable=false)
* @Groups({"sfsc:read","sfsc:write"})
*/
private $surveyCompany;
public function getId(): ?int
{
return $this->id;
}
public function getSurveyForm(): ?SurveyForm
{
return $this->surveyForm;
}
public function setSurveyForm(?SurveyForm $surveyForm): self
{
$this->surveyForm = $surveyForm;
return $this;
}
public function getSurveyCompany(): ?SurveyCompany
{
return $this->surveyCompany;
}
public function setSurveyCompany(?SurveyCompany $surveyCompany): self
{
$this->surveyCompany = $surveyCompany;
return $this;
}
}