src/Entity/Machine.php line 21

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright (c) 2019, MND Next GmbH - www.mndnext.de
  4.  */
  5. namespace App\Entity;
  6. use App\Entity\WinWOP\License;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\Common\Collections\Criteria;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. use Symfony\Component\Intl\Intl;
  13. /**
  14.  * @ORM\Entity
  15.  * @ORM\HasLifecycleCallbacks()
  16.  * @ORM\Table(name="machines")
  17.  */
  18. class Machine
  19. {
  20.     /**
  21.      * @ORM\Id
  22.      * @ORM\Column(type="integer")
  23.      * @ORM\GeneratedValue(strategy="AUTO")
  24.      */
  25.     protected $id;
  26.     /**
  27.      * @var string
  28.      * @ORM\Column(name="serialnumber", type="string", length=190, nullable=false)
  29.      * @Assert\NotBlank(message="Bitte geben Sie einen Seriennummer ein.")
  30.      */
  31.     private $serial;
  32.     /**
  33.      * @var string
  34.      * @ORM\Column(name="name", type="string", length=255, nullable=true)
  35.      */
  36.     private $name;
  37.     /**
  38.      * @var string
  39.      * @ORM\Column(name="control", type="string", length=255, nullable=true)
  40.      */
  41.     private $control;
  42.     /**
  43.      * @var string
  44.      * @ORM\Column(name="manufacturer_name", type="string", length=255, nullable=true)
  45.      */
  46.     private $manufacturerName;
  47.     /**
  48.      * @ORM\ManyToOne(targetEntity="Company", inversedBy="machines", cascade={"persist"})
  49.      */
  50.     private $company;
  51.     /**
  52.      * @var \DateTime
  53.      * @ORM\Column(name="launch", type="datetime", nullable=false)
  54.      */
  55.     private $launch;
  56.     /**
  57.      * @var string
  58.      * @ORM\Column(name="smc_name", type="string", length=255, nullable=true)
  59.      */
  60.     private $smc_name;
  61.     /**
  62.      * @var \DateTime
  63.      * @ORM\Column(name="smc_signing", type="date", nullable=true)
  64.      */
  65.     private $smc_signing;
  66.     /**
  67.      * @var \DateTime
  68.      * @ORM\Column(name="smc_begin", type="date", nullable=true)
  69.      */
  70.     private $smc_begin;
  71.     /**
  72.      * @var \DateTime
  73.      * @ORM\Column(name="smc_termination", type="date", nullable=true)
  74.      */
  75.     private $smc_termination;
  76.     /**
  77.      * @ORM\OneToMany(targetEntity="App\Entity\WinWOP\License", mappedBy="machine", cascade={"persist"})
  78.      * @ORM\OrderBy({"created" = "DESC"})
  79.      */
  80.     private $licenses;
  81.     /**
  82.      * @ORM\OneToOne(targetEntity="App\Entity\WinWOP\LicenseRequest", mappedBy="machine", cascade={"persist"})
  83.      */
  84.     private $license_request;
  85.     /**
  86.      * @ORM\OneToOne(targetEntity="App\Entity\WinWOP\ModulesRequest", mappedBy="machine", cascade={"persist"})
  87.      */
  88.     private $modules_request;
  89.     /**
  90.      * @ORM\OneToOne(targetEntity="App\Entity\WinWOP\SmcRequest", mappedBy="machine", cascade={"persist"})
  91.      */
  92.     private $smc_request;
  93.     /**
  94.      * Constructor
  95.      */
  96.     public function __construct()
  97.     {
  98.         $this->licenses = new \Doctrine\Common\Collections\ArrayCollection();
  99.         $this->launch = new \DateTime();
  100.     }
  101.     public function getId()
  102.     {
  103.         return $this->id;
  104.     }
  105.     public function setName($name)
  106.     {
  107.         $this->name $name;
  108.         return $this;
  109.     }
  110.     public function getName()
  111.     {
  112.         return $this->name;
  113.     }
  114.     public function setSerial($serial)
  115.     {
  116.         $this->serial $serial;
  117.         return $this;
  118.     }
  119.     public function getSerial()
  120.     {
  121.         return $this->serial;
  122.     }
  123.     public function setControl($control)
  124.     {
  125.         $this->control $control;
  126.         return $this;
  127.     }
  128.     public function getControl()
  129.     {
  130.         return $this->control;
  131.     }
  132.     public function setManufacturerName($name)
  133.     {
  134.         $this->manufacturerName $name;
  135.         return $this;
  136.     }
  137.     public function getManufacturerName()
  138.     {
  139.         return $this->manufacturerName;
  140.     }
  141.     /**
  142.      * get last used licensenumber
  143.      * @return string
  144.      */
  145.     public function getLicensenumber()
  146.     {
  147.         if ($this->getLicenseRequest()) {
  148.             return $this->getLicenseRequest()->getLicenseNumber();
  149.         }
  150.         $license $this->getCurrentLicense();
  151.         if ($license) {
  152.             return $license->getNumber();
  153.         }
  154.         return '';
  155.     }
  156.     public function setCompany(Company $company null)
  157.     {
  158.         $this->company $company;
  159.         return $this;
  160.     }
  161.     /**
  162.      * Get company
  163.      *
  164.      * @return Company|null
  165.      */
  166.     public function getCompany()
  167.     {
  168.         return $this->company;
  169.     }
  170.     public function setSmcName($name)
  171.     {
  172.         $this->smc_name $name;
  173.         return $this;
  174.     }
  175.     public function getSmcName()
  176.     {
  177.         return $this->smc_name;
  178.     }
  179.     public function setSmcSigning($dateTime)
  180.     {
  181.         $this->smc_signing $dateTime;
  182.         return $this;
  183.     }
  184.     public function getSmcSigning()
  185.     {
  186.         return $this->smc_signing;
  187.     }
  188.     public function setSmcBegin($dateTime)
  189.     {
  190.         $this->smc_begin $dateTime;
  191.         return $this;
  192.     }
  193.     public function getSmcBegin()
  194.     {
  195.         return $this->smc_begin;
  196.     }
  197.     public function setSmcTermination($dateTime)
  198.     {
  199.         $this->smc_termination $dateTime;
  200.         return $this;
  201.     }
  202.     public function getSmcTermination()
  203.     {
  204.         return $this->smc_termination;
  205.     }
  206.     public function setSmcRequest($request)
  207.     {
  208.         $this->smc_request $request;
  209.         return $this;
  210.     }
  211.     public function getSmcRequest()
  212.     {
  213.         return $this->smc_request;
  214.     }
  215.     public function setModulesRequest($request)
  216.     {
  217.         $this->modules_request $request;
  218.         return $this;
  219.     }
  220.     /**
  221.      * return if machine has active software maintenance contract
  222.      */
  223.     public function hasSmc()
  224.     {
  225.         $now = new \DateTime();
  226.         if (!empty($this->smc_begin) && $this->smc_begin <= $now) {
  227.             if (empty($this->smc_termination) || $this->smc_termination >= $now) {
  228.                 return true;
  229.             }
  230.         }
  231.         return false;
  232.     }
  233.     public function getModulesRequest()
  234.     {
  235.         return $this->modules_request;
  236.     }
  237.     public function setLicenseRequest($request)
  238.     {
  239.         $this->license_request $request;
  240.         return $this;
  241.     }
  242.     public function getLicenseRequest()
  243.     {
  244.         return $this->license_request;
  245.     }
  246.     public function setLaunch($launch)
  247.     {
  248.         $this->launch $launch;
  249.         return $this;
  250.     }
  251.     public function getLaunch()
  252.     {
  253.         return $this->launch;
  254.     }
  255.     /**
  256.      * @return Collection|WinWOP\License[]
  257.      */
  258.     public function getLicenses() : Collection
  259.     {
  260.         return $this->licenses;
  261.     }
  262.     public function addLicense(License $license)
  263.     {
  264.         if (!$this->licenses->contains($license)) {
  265.             $this->licenses->add($license);
  266.             $license->setMachine($this);
  267.         }
  268.     }
  269.     public function removeLicense(License $license)
  270.     {
  271.         //license removal not allowed!
  272.     }
  273.     /**
  274.      * @return License|null
  275.      */
  276.     public function getCurrentLicense() : ?License
  277.     {
  278.         $license $this->licenses->first();
  279.         if ($license) {
  280.             return $license;
  281.         }
  282.         return null;
  283.     }
  284.     /**
  285.      * @return Collection|WinWOP\Module[]|null
  286.      */
  287.     public function getCurrentLicensedModules() : ?Collection
  288.     {
  289.         if ($this->getCurrentLicense()) {
  290.             return $this->getCurrentLicense()->getModules();
  291.         }
  292.         return null;
  293.     }
  294.     public function __toString()
  295.     {
  296.         return $this->getSerial();
  297.     }
  298. }