<?php
/**
* Copyright (c) 2019, MND Next GmbH - www.mndnext.de
*/
namespace App\Entity\WinWOP;
use App\Entity\WinWOP\File\Documentation;
use App\Entity\WinWOP\File\InstallDoc;
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;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity
* @ORM\HasLifecycleCallbacks()
* @ORM\Table(name="win_wop_updates")
* @Vich\Uploadable
*/
class Update
{
/**
* @var string
* @ORM\Id
* @ORM\Column(type="string", length=190)
*/
protected $version;
/**
* @var \DateTime
* @ORM\Column(name="release_date", type="datetime", nullable=false)
*/
private $release;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="update_file", fileNameProperty="path")
*
* @var File
*/
private $file;
/**
* @ORM\Column(name="file", type="string", length=255)
*
* @var string
*/
private $path;
/**
* @ORM\OneToMany(targetEntity="App\Entity\WinWOP\File\Documentation", mappedBy="winwop", cascade={"persist"})
* @ORM\OrderBy({"created" = "DESC"})
*/
private $docuFiles;
/**
* @ORM\OneToMany(targetEntity="App\Entity\WinWOP\File\InstallDoc", mappedBy="winwop", cascade={"persist"})
* @ORM\OrderBy({"created" = "DESC"})
*/
private $installDocFiles;
/**
* @var string
* @ORM\Column(name="compatibility", type="string", length=255, nullable=true)
*/
private $compatibility;
/**
* @ORM\OneToMany(targetEntity="License", mappedBy="version", cascade={"persist", "refresh"})
*/
private $licenses;
/**
* @ORM\Column(name="public", type="boolean", nullable=false)
*/
private $public;
/**
* @ORM\Column(name="notified", type="boolean", nullable=false)
*/
private $notified;
/**
* Constructor
*/
public function __construct()
{
$this->licenses = new ArrayCollection();
$this->docuFiles = new ArrayCollection();
$this->installDocFiles = new ArrayCollection();
$this->release = new \DateTime();
$this->public = false;
$this->notified = false;
}
public function getVersion(): ?string
{
return $this->version;
}
public function setVersion($version)
{
$this->version = $version;
return $this;
}
public function getRelease(): ?\DateTime
{
return $this->release;
}
public function setRelease($release)
{
$this->release = $release;
return $this;
}
/**
* 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->release = new \DateTimeImmutable();
}
}
public function getFile(): ?File
{
return $this->file;
}
public function addDocuFile(?Documentation $file = null): void
{
$this->docuFiles->add($file);
}
public function removeDocuFile(?Documentation $file = null): void
{
$this->docuFiles->removeElement($file);
}
public function getDocuFiles(): Collection
{
return $this->docuFiles;
}
public function addInstallDocFile(?InstallDoc $file = null): void
{
$this->installDocFiles->add($file);
}
public function removeInstallDocFile(?InstallDoc $file = null): void
{
$this->installDocFiles->removeElement($file);
}
/**
* @return Collection|InstallDoc[]
*/
public function getInstallDocFiles(): Collection
{
return $this->installDocFiles;
}
public function setPath($path)
{
$this->path = $path;
return $this;
}
public function getPath(): ?string
{
return $this->path;
}
public function setCompatibility($compatibility)
{
$this->compatibility = $compatibility;
return $this;
}
public function getCompatibility()
{
return $this->compatibility;
}
public function setPublic($public)
{
$this->public = $public?true:false;
return $this;
}
public function isPublic()
{
return $this->public;
}
public function setNotified($notified)
{
$this->notified = $notified?true:false;
return $this;
}
public function isNotified()
{
return $this->notified;
}
/**
* @return Collection|License[]
*/
public function getLicenses() : Collection
{
return $this->licenses;
}
public function __toString()
{
return $this->getVersion();
}
}