<?php
/**
* Copyright (c) 2019, MND Next GmbH - www.mndnext.de
*/
namespace App\Entity\WinWOP;
use App\Entity\Machine;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
* @ORM\HasLifecycleCallbacks()
* @ORM\Table(name="win_wop_license_requests")
* @Vich\Uploadable
*/
class LicenseRequest
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Machine", inversedBy="license_request", cascade={"persist"})
*/
private $machine;
/**
* @ORM\Column(name="manufacturer_name", type="string", length=190)
*
* @var string
*/
private $manufacturerName;
/**
* @ORM\Column(name="machine_name", type="string", length=190)
*
* @var string
*/
private $name;
/**
* @ORM\Column(name="machine_serial", type="string", length=190)
*
* @var string
*/
private $serial;
/**
* @ORM\Column(name="machine_control", type="string", length=190)
*
* @var string
*/
private $control = false;
/**
* @ORM\Column(name="license_number", type="string", length=190)
*
* @var string
*/
private $licenseNumber;
/**
* @var \DateTime
*
* @ORM\Column(name="created", type="datetime", nullable=false)
*/
private $created;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="license_request_file", fileNameProperty="localPath")
*
* @var File
*/
private $file;
/**
* @ORM\Column(name="local_file", type="string", length=255)
*
* @var string
*/
private $localPath;
/**
* Constructor
*/
public function __construct()
{
$this->created = new \DateTime();
$this->modules = new \Doctrine\Common\Collections\ArrayCollection();
}
public function getId()
{
return $this->id;
}
public function setManufacturerName($manufacturerName)
{
$this->manufacturerName = $manufacturerName;
return $this;
}
public function getManufacturerName()
{
return $this->manufacturerName;
}
public function setName($name)
{
$this->name = $name;
return $this;
}
public function getName()
{
return $this->name;
}
public function setSerial($serial)
{
$this->serial = $serial;
return $this;
}
public function getSerial()
{
return $this->serial;
}
public function setControl($control)
{
$this->control = $control;
return $this;
}
public function getControl()
{
return $this->control;
}
public function setLicenseNumber($licenseNumber)
{
$this->licenseNumber = $licenseNumber;
return $this;
}
public function getLicenseNumber()
{
return $this->licenseNumber;
}
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $file
* @throws \Exception
*/
public function setFile(?File $file = null): void
{
$this->file = $file;
if (null !== $file) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->created = new \DateTimeImmutable();
}
}
public function getFile(): ?File
{
return $this->file;
}
public function setCreated($created)
{
$this->created = $created;
return $this;
}
public function getCreated()
{
return $this->created;
}
public function setLocalPath($localPath)
{
$this->localPath = $localPath;
return $this;
}
public function getLocalPath()
{
return $this->localPath;
}
public function setMachine(Machine $machine = null)
{
$this->machine = $machine;
return $this;
}
public function getMachine() : ?Machine
{
return $this->machine;
}
public function __toString()
{
$date = $this->getCreated();
if ($date) {
return $date->format('d.m.Y H:i');
}
return '';
}
}