Untitled
unknown
plain_text
24 days ago
4.7 kB
1
Indexable
Never
<?php // src/Document/Clocking.php namespace App\Document; // Api use ApiPlatform\Doctrine\Odm\Filter\DateFilter; use ApiPlatform\Doctrine\Odm\Filter\OrderFilter; use ApiPlatform\Doctrine\Odm\Filter\SearchFilter; use ApiPlatform\Metadata\ApiFilter; use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\GraphQl\DeleteMutation; // GraphQL use ApiPlatform\Metadata\GraphQl\Mutation; use ApiPlatform\Metadata\GraphQl\Query; use ApiPlatform\Metadata\GraphQl\QueryCollection; use App\Resolver\AnomalyClockingResolver; use App\Resolver\CreateClockingResolver; use App\Resolver\UpdateClockingResolver; use App\Resolver\WeekClockingsResolver; // Trait use App\Trait\IdTrait; // Mapping use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; // Validator use Symfony\Component\Validator\Constraints as Assert; #[ODM\Document()] #[ApiResource( paginationType: 'page', paginationMaximumItemsPerPage: 10, paginationItemsPerPage: 10, graphQlOperations: [ new Query(), new QueryCollection(), new QueryCollection( name: "weekClockings", paginationEnabled: false, extraArgs: [ 'tagNumber' => ['type' => 'String!'], ], ), new Mutation( name: 'create', resolver: AnomalyClockingResolver::class, args: [ 'tagNumber' => ['type' => 'String!'], 'date' => ['type' => 'String!'], ] ), new Mutation( name: 'customCreate', resolver: CreateClockingResolver::class, args: [ 'allowed' => ['type' => 'Boolean!'], 'cause' => ['type' => 'String'], 'date' => ['type' => 'String!'], 'employee' => ['type' => 'ID!'], 'entry' => ['type' => 'Boolean!'], ] ), new DeleteMutation(name: 'delete'), new Mutation( name: 'update', resolver: UpdateClockingResolver::class, args: [ 'id' => ['type' => 'ID!'], 'allowed' => ['type' => 'Boolean!'], 'cause' => ['type' => 'String'], 'date' => ['type' => 'String!'], 'employee' => ['type' => 'ID!'], 'entry' => ['type' => 'Boolean!'], ] ), ] )] #[ApiFilter( SearchFilter::class, properties: [ 'employee' => 'exact', 'employee.tagNumber' => 'exact', ] )] #[ApiFilter( OrderFilter::class, properties: ['date' => 'DESC'] )] #[ApiFilter( DateFilter::class, properties: [ 'date', ] )] class Clocking { use IdTrait; #[ODM\ReferenceOne( targetDocument: Employee::class, storeAs: 'id', nullable: true, cascade: ['persist'] )] public ?Employee $employee = null; #[ODM\Field(type: 'date_immutable')] #[Assert\NotBlank(), Assert\Type(\DateTimeInterface::class)] public ?\DateTimeInterface $date = null; #[ODM\Field(type: 'bool')] public ?bool $entry = null; #[ODM\Field(type: 'string', nullable: true)] public ?string $cause = null; #[ODM\Field(type: 'bool')] public ?bool $allowed = true; public function __construct() { $this->date = new \DateTimeImmutable(); } /** * Return the value of date. */ public function __toString(): string { return $this->date->format('d-m-Y H:i:s'); } public function getDate(): ?\DateTimeInterface { return $this->date; } public function setDate(\DateTimeInterface $date): self { $this->date = $date; return $this; } public function setEmployee(Employee $employee): self { $this->employee = $employee; return $this; } public function getEmployee(): ?Employee { return $this->employee; } public function getEntry(): ?bool { return $this->entry; } public function setEntry(bool $entry): self { $this->entry = $entry; return $this; } public function getCause(): ?string { return $this->cause; } public function setCause(string $cause): self { $this->cause = $cause; return $this; } public function getAllowed(): ?bool { return $this->allowed; } public function setAllowed(bool $allowed): self { $this->allowed = $allowed; return $this; } }
Leave a Comment