src/Entity/WinWOP/License.php line 22

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright (c) 2019, MND Next GmbH - www.mndnext.de
  4.  */
  5. namespace App\Entity\WinWOP;
  6. use App\Entity\Machine;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\HttpFoundation\File\File;
  10. use Symfony\Flex\Event\UpdateEvent;
  11. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. /**
  14.  * @ORM\Entity
  15.  * @ORM\HasLifecycleCallbacks()
  16.  * @ORM\Table(name="win_wop_licenses")
  17.  * @Vich\Uploadable
  18.  */
  19. class License
  20. {
  21.     /**
  22.      * @ORM\Id
  23.      * @ORM\Column(type="integer")
  24.      * @ORM\GeneratedValue(strategy="AUTO")
  25.      */
  26.     protected $id;
  27.     /**
  28.      * @var string
  29.      * @ORM\Column(name="number", type="string", length=255, nullable=false)
  30.      * @Assert\NotBlank(message="Bitte geben Sie eine Lizenznummer ein.")
  31.      */
  32.     private $number;
  33.     /**
  34.      * @var \DateTime
  35.      *
  36.      * @ORM\Column(name="created", type="datetime", nullable=false)
  37.      */
  38.     private $created;
  39.     /**
  40.      * @ORM\ManyToOne(targetEntity="Update", inversedBy="licenses", cascade={"persist", "refresh"})
  41.      * @ORM\JoinColumn(name="version", referencedColumnName="version")
  42.      */
  43.     private $version;
  44.     /**
  45.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  46.      *
  47.      * @Vich\UploadableField(mapping="license_file", fileNameProperty="localPath", originalName="originalPath")
  48.      *
  49.      * @var File
  50.      */
  51.     private $file;
  52.     /**
  53.      * @ORM\Column(name="local_file", type="string", length=40)
  54.      *
  55.      * @var string
  56.      */
  57.     private $localPath;
  58.     /**
  59.      * @ORM\Column(name="original_file", type="string", length=255)
  60.      *
  61.      * @var string
  62.      */
  63.     private $originalPath;
  64.     /**
  65.      * @ORM\ManyToOne(targetEntity="App\Entity\Machine", inversedBy="licenses", cascade={"persist"})
  66.      */
  67.     private $machine;
  68.     /**
  69.      * @ORM\ManyToMany(targetEntity="Module")
  70.      * @ORM\JoinTable(name="win_wop_licences_modules",
  71.      *      joinColumns={@ORM\JoinColumn(name="module_id", referencedColumnName="id")},
  72.      *      inverseJoinColumns={@ORM\JoinColumn(name="license_id", referencedColumnName="id")}
  73.      *      )
  74.      */
  75.     private $modules;
  76.     /**
  77.      * Constructor
  78.      */
  79.     public function __construct()
  80.     {
  81.         $this->modules = new \Doctrine\Common\Collections\ArrayCollection();
  82.         $this->created = new \DateTime();
  83.     }
  84.     public function getId()
  85.     {
  86.         return $this->id;
  87.     }
  88.     public function setNumber($number)
  89.     {
  90.         $this->number $number;
  91.         return $this;
  92.     }
  93.     public function getNumber()
  94.     {
  95.         return $this->number;
  96.     }
  97.     /**
  98.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  99.      * of 'UploadedFile' is injected into this setter to trigger the update. If this
  100.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  101.      * must be able to accept an instance of 'File' as the bundle will inject one here
  102.      * during Doctrine hydration.
  103.      *
  104.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $file
  105.      * @throws \Exception
  106.      */
  107.     public function setFile(?File $file null): void
  108.     {
  109.         $this->file $file;
  110.         if (null !== $file) {
  111.             // It is required that at least one field changes if you are using doctrine
  112.             // otherwise the event listeners won't be called and the file is lost
  113.             $this->created = new \DateTimeImmutable();
  114.         }
  115.     }
  116.     public function getFile(): ?File
  117.     {
  118.         return $this->file;
  119.     }
  120.     public function setCreated($created)
  121.     {
  122.         $this->created $created;
  123.         return $this;
  124.     }
  125.     public function getCreated()
  126.     {
  127.         return $this->created;
  128.     }
  129.     public function setLocalPath($localPath)
  130.     {
  131.         $this->localPath $localPath;
  132.         return $this;
  133.     }
  134.     public function getLocalPath()
  135.     {
  136.         return $this->localPath;
  137.     }
  138.     public function setOriginalPath(?string $name): void
  139.     {
  140.         $this->originalPath $name;
  141.     }
  142.     public function getOriginalPath(): ?string
  143.     {
  144.         return $this->originalPath;
  145.     }
  146.     public function setMachine(Machine $machine null)
  147.     {
  148.         $this->machine $machine;
  149.         $machine->addLicense($this);
  150.         return $this;
  151.     }
  152.     public function getMachine() : ?Machine
  153.     {
  154.         return $this->machine;
  155.     }
  156.     public function setVersion(Update $updateVersion null)
  157.     {
  158.         $this->version $updateVersion;
  159.         return $this;
  160.     }
  161.     public function getVersion() : ?Update
  162.     {
  163.         return $this->version;
  164.     }
  165.     /**
  166.      * alias getVersion
  167.      */
  168.     public function getWinWOP() : ?Update
  169.     {
  170.         return $this->version;
  171.     }
  172.     public function addModule(Module $module)
  173.     {
  174.         if (!$this->modules->contains($module)) {
  175.             $this->modules->add($module);
  176.         }
  177.     }
  178.     public function removeModule(Module $module)
  179.     {
  180.         if ($this->modules->contains($module)) {
  181.             $this->modules->removeElement($module);
  182.         }
  183.     }
  184.     /**
  185.      * @return Collection|Module[]
  186.      */
  187.     public function getModules() : Collection
  188.     {
  189.         return $this->modules;
  190.     }
  191.     public function __toString()
  192.     {
  193.         return $this->getNumber();
  194.     }
  195. }