src/Containers/CompanySection/EmployeeContainer/Entities/EmployeeEntity.php line 108

Open in your IDE?
  1. <?php
  2. namespace App\Containers\CompanySection\EmployeeContainer\Entities;
  3. use ApiPlatform\Metadata\ApiFilter;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use ApiPlatform\Metadata\Delete;
  6. use ApiPlatform\Metadata\Get;
  7. use ApiPlatform\Metadata\GetCollection;
  8. use ApiPlatform\Metadata\Patch;
  9. use ApiPlatform\Metadata\Post;
  10. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  11. use ApiPlatform\Metadata\ApiProperty;
  12. use App\Ship\Entities\UserEntity;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use Doctrine\DBAL\Types\Types;
  15. use Gedmo\Mapping\Annotation as Gedmo;
  16. use Symfony\Component\Serializer\Annotation\Groups;
  17. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  18. use Symfony\Component\Serializer\Annotation\MaxDepth;
  19. use App\Ship\Utils\FormattingUtil;
  20. use App\Containers\CompanySection\EmployeeContainer\Data\Repositories\EmployeeRepository;
  21. use App\Containers\CompanySection\StructureContainer\Entities\StructureEntity;
  22. use App\Containers\CompanySection\IndexContainer\Entities\TranslationEntity;
  23. use App\Ship\ApiPlatform\Filter\SimpleSearchFilter;
  24. use App\Ship\ApiPlatform\Filter\FilterLogic;
  25. use App\Containers\CompanySection\EmployeeContainer\UI\ApiPlatform\Controllers\PostSetAvatarByBinaryController;
  26. use App\Ship\Entities\MediaEntity;
  27. /** 
  28.  * Сотрудники
  29. */
  30. #[ApiResource(
  31.     routePrefix'/company',
  32.     normalizationContext: ['groups' => 'read''enable_max_depth' => true],
  33.     operations: [
  34.         new Get(
  35.             uriTemplate'/employees/{id}'requirements: ['id' => '\d+'],
  36.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_READONLY')"
  37.         ),
  38.         new Patch(
  39.             uriTemplate'/employees/{id}'requirements: ['id' => '\d+'],
  40.             security"is_granted('ROLE_ADMIN')"
  41.         ),
  42.         new Post(
  43.             uriTemplate'/employees',
  44.             security"is_granted('ROLE_ADMIN')"
  45.         ),
  46.         new Post(
  47.             uriTemplate'/employee/set_avatar_by_binary',
  48.             controllerPostSetAvatarByBinaryController::class,
  49.             deserializefalse
  50.             validationContext: ['groups' => ['read''media_object_create']], 
  51.             openapiContext: [
  52.                 'requestBody' => [
  53.                     'content' => [
  54.                         'multipart/form-data' => [
  55.                             'schema' => [
  56.                                 'type' => 'object'
  57.                                 'properties' => [
  58.                                     'file' => [
  59.                                         'type' => 'string'
  60.                                         'format' => 'binary'
  61.                                     ]
  62.                                 ],
  63.                                 'required' => [
  64.                                     'file'
  65.                                 ]
  66.                             ]
  67.                         ]
  68.                     ]
  69.                 ]
  70.             ],
  71.             security"is_granted('ROLE_ADMIN')"
  72.         ),
  73.         new Delete(
  74.             uriTemplate'/employees/{id}'requirements: ['id' => '\d+'],
  75.             security"is_granted('ROLE_ADMIN')"
  76.         ),
  77.         new GetCollection(
  78.             uriTemplate'/employees',
  79.             security"is_granted('ROLE_ADMIN') or is_granted('ROLE_READONLY')"
  80.         ),
  81.     ],
  82.     shortName'Company_Employees'
  83. )]
  84. #[ORM\Entity(repositoryClassEmployeeRepository::class)]
  85. #[ORM\Table(name'`company_employee`')]
  86. #[ApiFilter(SearchFilter::class, properties: [
  87.     'id' => 'exact',
  88.     'name' => 'partial',
  89.     'lastName' => 'partial',
  90.     'patronymic' => 'partial',
  91.     'structure' => 'exact',
  92.     'workPhone' => 'partial',
  93.     'internalPhone' => 'partial'
  94. ])]
  95. #[ApiFilter(filterClassSimpleSearchFilter::class, properties: [
  96.     'name',
  97.     'lastName',
  98.     'patronymic',
  99.     'email',
  100.     'workPhone',
  101.     'internalPhone'
  102. ])]
  103. #[ApiFilter(FilterLogic::class)]
  104. #[Gedmo\TranslationEntity(class: TranslationEntity::class)]
  105. class EmployeeEntity extends UserEntity implements PasswordAuthenticatedUserInterface
  106. {
  107.     // Пароль
  108.     #[ORM\Column(typeTypes::STRINGlength255nullablefalse)]
  109.     private string $password;
  110.     // Активность
  111.     #[ORM\Column(typeTypes::BOOLEAN)]
  112.     #[Groups(['read'])]
  113.     private bool $isActive false;
  114.     // Имя
  115.     #[ORM\Column(typeTypes::STRINGlength150)]
  116.     #[Gedmo\Translatable]
  117.     #[Groups(['read'])]
  118.     private string $name;
  119.     
  120.     // Фамилия
  121.     #[ORM\Column(typeTypes::STRINGlength150)]
  122.     #[Gedmo\Translatable]
  123.     #[Groups(['read'])]
  124.     private string $lastName;
  125.     // Отчество
  126.     #[ORM\Column(typeTypes::STRINGlength150nullabletrue)]
  127.     #[Gedmo\Translatable]
  128.     #[Groups(['read'])]
  129.     private ?string $patronymic null;
  130.     // Фото
  131.     #[ORM\ManyToOne(targetEntityMediaEntity::class)]
  132.     #[ORM\JoinColumn(name'photo_id'referencedColumnName'id'nullabletrue)]
  133.     private ?MediaEntity $photo null;
  134.     #[ApiProperty(types: ['https://schema.org/contentUrl'])]
  135.     #[Groups(['read''media_object:read'])]
  136.     public ?string $photoUrl null;
  137.     // Рабочий телефон
  138.     #[ORM\Column(typeTypes::STRINGlength150nullablefalseuniquetrue)]
  139.     #[Groups(['read'])]
  140.     private string $workPhone;
  141.     // Внутренний номер телефона
  142.     #[ORM\Column(typeTypes::STRINGlength50nullabletrueuniquetrue)]
  143.     #[Groups(['read'])]
  144.     private ?string $internalPhone null;
  145.     
  146.     // Должность
  147.     #[ORM\Column(typeTypes::STRINGlength150nullabletrue)]
  148.     #[Gedmo\Translatable]
  149.     #[Groups(['read'])]
  150.     private ?string $position null;
  151.     // Структура
  152.     #[ORM\ManyToOne(targetEntityStructureEntity::class)]
  153.     #[ORM\JoinColumn(name'structure_id'referencedColumnName'id'nullabletrue)]
  154.     #[Groups(['read'])]
  155.     #[MaxDepth(1)]
  156.     private ?StructureEntity $structure null;
  157.     #[ORM\Column(typeTypes::JSONlength150nullabletrue)]
  158.     #[Groups(['read'])]
  159.     #[ApiProperty(
  160.         security"is_granted('ROLE_ADMIN')"
  161.     )]
  162.     private $accessProperties = [];
  163.     /**
  164.      * Used locale to override Translation listener`s locale
  165.      * this is not a mapped field of entity metadata, just a simple property
  166.      */
  167.     #[Gedmo\Locale]
  168.     private $locale;
  169.     
  170.     public function getPassword(): string
  171.     {
  172.         return (string) $this->password;
  173.     }
  174.     public function setPassword(string $password): void
  175.     {
  176.         $this->password $password;
  177.     }
  178.     public function getName()
  179.     {
  180.         return $this->name;
  181.     }
  182.     public function setName($name)
  183.     {
  184.         $this->name $name;
  185.         return $this;
  186.     }
  187.  
  188.     public function getLastName()
  189.     {
  190.         return $this->lastName;
  191.     }
  192.     public function setLastName($lastName)
  193.     {
  194.         $this->lastName $lastName;
  195.         return $this;
  196.     }
  197.     public function getPatronymic()
  198.     {
  199.         return $this->patronymic;
  200.     }
  201.     public function setPatronymic($patronymic)
  202.     {
  203.         $this->patronymic $patronymic;
  204.         return $this;
  205.     }
  206.     public function getRoles(): array
  207.     {
  208.         $roles $this->roles;
  209.         // guarantee every user at least has ROLE_USER
  210.         $roles[] = 'ROLE_USER';
  211.         return \array_unique($roles);
  212.     }
  213.     public function getPhoto()
  214.     {
  215.         return $this->photo;
  216.     }
  217.     public function setPhoto($photo)
  218.     {
  219.         $this->photo $photo;
  220.         return $this;
  221.     }
  222.     public function getWorkPhone()
  223.     {
  224.         return $this->workPhone;
  225.     }
  226.     public function setWorkPhone($value)
  227.     {
  228.         $this->workPhone = (!empty($value))
  229.             ? FormattingUtil::phoneNumber($value)
  230.             : $value;
  231.         return $this;
  232.     }
  233.     public function getInternalPhone()
  234.     {
  235.         return $this->internalPhone;
  236.     }
  237.     public function setInternalPhone($value)
  238.     {
  239.         $this->internalPhone = (!empty($value))
  240.             ? FormattingUtil::phoneNumber($value)
  241.             : $value;
  242.         return $this;
  243.     }
  244.     public function getPosition()
  245.     {
  246.         return $this->position;
  247.     }
  248.     public function setPosition($position)
  249.     {
  250.         $this->position $position;
  251.         return $this;
  252.     }
  253.     public function getIsActive()
  254.     {
  255.         return $this->isActive;
  256.     }
  257.  
  258.     public function setIsActive($isActive)
  259.     {
  260.         $this->isActive $isActive;
  261.         return $this;
  262.     }
  263.     public function getStructure()
  264.     {
  265.         return $this->structure;
  266.     }
  267.     public function setStructure($structure)
  268.     {
  269.         $this->structure $structure;
  270.         return $this;
  271.     }
  272.     public function setTranslatableLocale($locale)
  273.     {
  274.         $this->locale $locale;
  275.     }
  276.     /**
  277.      * Get the value of accessProperties
  278.      */ 
  279.     public function getAccessProperties()
  280.     {
  281.         return $this->accessProperties;
  282.     }
  283.     /**
  284.      * Set the value of accessProperties
  285.      *
  286.      * @return  self
  287.      */ 
  288.     public function setAccessProperties($accessProperties)
  289.     {
  290.         $this->accessProperties $accessProperties;
  291.         return $this;
  292.     }
  293. }