<?php
namespace App\Entity\Declaration;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use DateTime;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Timestampable\Traits\Timestampable;
use Roothirsch\CoreBundle\Entity\Traits\TimetrackedTrait;
use Roothirsch\CoreBundle\UserAware\UserAwareInterface;
use Roothirsch\CoreBundle\UserAware\UserAwareTrait;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ORM\Entity
* @ORM\Table(name="brunex_declaration_declaration")
* @ApiResource(
* routePrefix="/brunex/declaration",
* normalizationContext={"groups"={"declaration:list"}},
* collectionOperations={
* "duplicate"={"method"="POST", "path"="/declarations/{id}/duplicate", "requirements"={"id"=".+"}},
* "get",
* "post"
* },
* attributes={
* "order"={"createdAt": "DESC"}
* }
* )
* @ApiFilter(OrderFilter::class, properties={"createdAt"}, arguments={"orderParameterName"="order"})
*/
class Declaration implements UserAwareInterface
{
use UserAwareTrait;
use TimetrackedTrait;
/**
* @var int
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"declaration", "declaration:list"})
*/
protected $id;
/**
* @var Product
* @ORM\ManyToOne(targetEntity="Product", inversedBy="declarations")
* @Groups({"declaration", "declaration:list"})
*/
protected $product;
/**
* @var Collection<Usage>
* @ORM\OneToMany(targetEntity="Usage", mappedBy="declaration", cascade={"persist"})
* _ORM\OrderBy({"name" = "ASC"})
* @Groups({"declaration"})
*/
protected $usages;
/**
* @var string
* @ORM\Column(type="text")
* @Groups({"declaration"})
*/
protected $company = '';
/**
* @var string
* @ORM\Column(type="text")
* @Groups({"declaration"})
*/
protected $name = '';
/**
* @var string
* @ORM\Column(type="text")
* @Groups({"declaration"})
*/
protected $street = '';
/**
* @var string
* @ORM\Column(type="integer")
* @Groups({"declaration"})
*/
protected $zip;
/**
* @var string
* @ORM\Column(type="text")
* @Groups({"declaration"})
*/
protected $city = '';
/**
* @var string
* @ORM\Column(type="text")
* @Groups({"declaration"})
*/
protected $phone = '';
/**
* @var string
* @ORM\Column(type="text")
* @Groups({"declaration"})
*/
protected $email = '';
/**
* @var string
* @ORM\Column(type="integer")
* @Groups({"declaration", "declaration:list"})
*/
protected $kaNumber;
/**
* @var string
* @ORM\Column(type="text")
* @Groups({"declaration", "declaration:list"})
*/
protected $customId;
/**
* @var string
* @ORM\Column(type="text")
* @Groups({"declaration", "declaration:list"})
*/
protected $position = '';
public function __toString() {
return $this->getKaNummerAndPosition();
}
/**
* @param int $id
*/
public function setId($id): void
{
$this->id = $id;
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @return Product
*/
public function getProduct()
{
return $this->product;
}
/**
* @param Product $product
*
* @return Declaration
*/
public function setProduct($product)
{
$this->product = $product;
return $this;
}
/**
* @return Collection
*/
public function getUsages()
{
return $this->usages;
}
/**
* @param Collection $usages
*
* @return Declaration
*/
public function setUsages($usages)
{
$this->usages = $usages;
return $this;
}
public function addUsage($usage)
{
$this->usages->add($usage);
$usage->setDeclaration($this);
}
/**
* @return string
*/
public function getCompany()
{
return $this->company;
}
/**
* @param string $company
*
* @return Declaration
*/
public function setCompany($company)
{
$this->company = $company;
return $this;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*
* @return Declaration
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* @return string
*/
public function getStreet()
{
return $this->street;
}
/**
* @param string $street
*
* @return Declaration
*/
public function setStreet($street)
{
$this->street = $street;
return $this;
}
/**
* @return string
*/
public function getZip()
{
return $this->zip;
}
/**
* @param string $zip
*
* @return Declaration
*/
public function setZip($zip)
{
$this->zip = $zip;
return $this;
}
/**
* @return string
*/
public function getCity()
{
return $this->city;
}
/**
* @param string $city
*
* @return Declaration
*/
public function setCity($city)
{
$this->city = $city;
return $this;
}
/**
* @return string
*/
public function getPhone()
{
return $this->phone;
}
/**
* @param string $phone
*
* @return Declaration
*/
public function setPhone($phone)
{
$this->phone = $phone;
return $this;
}
/**
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* @param string $email
*
* @return Declaration
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* @return string
*/
public function getKaNumber()
{
return $this->kaNumber;
}
/**
* @param string $kaNumber
*
* @return Declaration
*/
public function setKaNumber($kaNumber)
{
$this->kaNumber = $kaNumber;
return $this;
}
/**
* @return string
*/
public function getCustomId()
{
return $this->customId;
}
/**
* @param string $customId
*
* @return Declaration
*/
public function setCustomId($customId)
{
$this->customId = $customId;
return $this;
}
/**
* @return string
*/
public function getKaNummerAndPosition()
{
return 'KA-' . $this->kaNumber . ' | ' . $this->position;
}
/**
* @return string
*/
public function getPosition()
{
return $this->position;
}
/**
* @param string $position
*
* @return Declaration
*/
public function setPosition($position)
{
$this->position = $position;
return $this;
}
public function isAvcp1()
{
/** @var Usage $usage */
foreach ($this->getUsages() as $usage) {
if ($usage->getField()->isExap() && $usage->getValue()) {
return true;
}
}
return false;
}
public function __construct()
{
$this->usages = new \Doctrine\Common\Collections\ArrayCollection();
}
}