<?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 Symfony\Flex\Event\UpdateEvent;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
* @ORM\HasLifecycleCallbacks()
* @ORM\Table(name="win_wop_licenses")
* @Vich\Uploadable
*/
class License
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
* @ORM\Column(name="number", type="string", length=255, nullable=false)
* @Assert\NotBlank(message="Bitte geben Sie eine Lizenznummer ein.")
*/
private $number;
/**
* @var \DateTime
*
* @ORM\Column(name="created", type="datetime", nullable=false)
*/
private $created;
/**
* @ORM\ManyToOne(targetEntity="Update", inversedBy="licenses", cascade={"persist", "refresh"})
* @ORM\JoinColumn(name="version", referencedColumnName="version")
*/
private $version;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="license_file", fileNameProperty="localPath", originalName="originalPath")
*
* @var File
*/
private $file;
/**
* @ORM\Column(name="local_file", type="string", length=40)
*
* @var string
*/
private $localPath;
/**
* @ORM\Column(name="original_file", type="string", length=255)
*
* @var string
*/
private $originalPath;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Machine", inversedBy="licenses", cascade={"persist"})
*/
private $machine;
/**
* @ORM\ManyToMany(targetEntity="Module")
* @ORM\JoinTable(name="win_wop_licences_modules",
* joinColumns={@ORM\JoinColumn(name="module_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="license_id", referencedColumnName="id")}
* )
*/
private $modules;
/**
* Constructor
*/
public function __construct()
{
$this->modules = new \Doctrine\Common\Collections\ArrayCollection();
$this->created = new \DateTime();
}
public function getId()
{
return $this->id;
}
public function setNumber($number)
{
$this->number = $number;
return $this;
}
public function getNumber()
{
return $this->number;
}
/**
* 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 setOriginalPath(?string $name): void
{
$this->originalPath = $name;
}
public function getOriginalPath(): ?string
{
return $this->originalPath;
}
public function setMachine(Machine $machine = null)
{
$this->machine = $machine;
$machine->addLicense($this);
return $this;
}
public function getMachine() : ?Machine
{
return $this->machine;
}
public function setVersion(Update $updateVersion = null)
{
$this->version = $updateVersion;
return $this;
}
public function getVersion() : ?Update
{
return $this->version;
}
/**
* alias getVersion
*/
public function getWinWOP() : ?Update
{
return $this->version;
}
public function addModule(Module $module)
{
if (!$this->modules->contains($module)) {
$this->modules->add($module);
}
}
public function removeModule(Module $module)
{
if ($this->modules->contains($module)) {
$this->modules->removeElement($module);
}
}
/**
* @return Collection|Module[]
*/
public function getModules() : Collection
{
return $this->modules;
}
public function __toString()
{
return $this->getNumber();
}
}