src/Entity/SaleEvent.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Criteria;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Serializer\Annotation\Groups;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. /**
  9.  * @ORM\Entity(repositoryClass="App\Repository\SaleEventRepository")
  10.  *
  11.  * @ORM\Table(name="sale_event")
  12.  */
  13. class SaleEvent
  14. {
  15.     public const PERIOD_AM 'am';
  16.     public const PERIOD_PM 'pm';
  17.     public const PERIOD_UNDEFINED 'nc';
  18.     /**
  19.      * @ORM\Id
  20.      *
  21.      * @ORM\GeneratedValue(strategy="AUTO")
  22.      *
  23.      * @ORM\Column(type="bigint")
  24.      *
  25.      * @Groups({"read_sale_event"})
  26.      */
  27.     protected $id;
  28.     /**
  29.      * @ORM\Column(type="string")
  30.      *
  31.      * @Assert\NotBlank(groups={"api_rms_saleevent"})
  32.      *
  33.      * @Groups({"read_sale_event"})
  34.      */
  35.     protected $startTime;
  36.     /**
  37.      * @ORM\ManyToOne(targetEntity="App\Entity\SaleEventTitle", cascade={"persist"})
  38.      *
  39.      * @ORM\JoinColumn(name="sale_event_title_id", referencedColumnName="id", nullable=true)
  40.      *
  41.      * @Groups({"read_sale_event"})
  42.      */
  43.     private $title;
  44.     /**
  45.      * @ORM\Column(type="string")
  46.      *
  47.      * @Assert\NotBlank(groups={"api_rms_saleevent"})
  48.      *
  49.      * @Groups({"read_sale_event"})
  50.      */
  51.     private $period;
  52.     /**
  53.      * @ORM\ManyToOne(targetEntity="App\Entity\Sale", inversedBy="events", fetch="EAGER", cascade={"persist"})
  54.      *
  55.      * @ORM\JoinColumn(nullable=false)
  56.      *
  57.      * @Groups({"read_sale_event"})
  58.      */
  59.     private $sale;
  60.     /**
  61.      * @ORM\OneToMany(targetEntity="App\Entity\Vehicle", mappedBy="event", cascade={"persist"})
  62.      */
  63.     private $vehicles;
  64.     /**
  65.      * @ORM\Column(type="boolean", nullable=true)
  66.      */
  67.     private $lotsImport;
  68.     public function __construct()
  69.     {
  70.         $this->vehicles = new ArrayCollection();
  71.         $this->lotsImport 0;
  72.     }
  73.     public function getId()
  74.     {
  75.         return $this->id;
  76.     }
  77.     public function getStartTime()
  78.     {
  79.         return $this->startTime;
  80.     }
  81.     public function setStartTime($startTime): void
  82.     {
  83.         $this->startTime $startTime;
  84.     }
  85.     public function getTitle()
  86.     {
  87.         return $this->title;
  88.     }
  89.     public function setTitle($title): void
  90.     {
  91.         $this->title $title;
  92.     }
  93.     public function getPeriod()
  94.     {
  95.         return $this->period;
  96.     }
  97.     public function setPeriod($period): void
  98.     {
  99.         $this->period $period;
  100.     }
  101.     public function setSale(Sale $sale): void
  102.     {
  103.         $this->sale $sale;
  104.     }
  105.     public function getSale()
  106.     {
  107.         return $this->sale;
  108.     }
  109.     public function addVehicle(Vehicle $vehicle)
  110.     {
  111.         $this->vehicles[] = $vehicle;
  112.         $vehicle->setEvent($this);
  113.         return $this;
  114.     }
  115.     public function removeVehicle(Vehicle $vehicle): void
  116.     {
  117.         $this->vehicles->removeElement($vehicle);
  118.     }
  119.     public function getVehicles()
  120.     {
  121.         return $this->vehicles;
  122.     }
  123.     public function isLotsImport()
  124.     {
  125.         return (bool) $this->lotsImport;
  126.     }
  127.     public function setLotsImport($lotsImport): void
  128.     {
  129.         $this->lotsImport $lotsImport;
  130.     }
  131.     public function getActiveVehicles()
  132.     {
  133.         $criteria Criteria::create();
  134.         $criteria->where(
  135.             Criteria::expr()->neq('salingState'Vehicle::SALING_STATE_EXCLUS)
  136.         )
  137.         ->andWhere(
  138.             Criteria::expr()->neq('salingState'Vehicle::SALING_STATE_SUPPRIME)
  139.         )
  140.         ->andWhere(
  141.             Criteria::expr()->neq('salingState'Vehicle::SALING_STATE_NO_STARTING_PRICE)
  142.         );
  143.         return $this->getVehicles()->matching($criteria);
  144.     }
  145.     public function getLabel()
  146.     {
  147.         return $this->getTitle()->getName();
  148.     }
  149.     public function getStartDateTime()
  150.     {
  151.         return new \DateTime($this->sale->getStartDate()->format('Y-m-d').' '.$this->startTime);
  152.     }
  153.     public function isEmpty()
  154.     {
  155.         if (=== count($this->getVehicles())) {
  156.             return true;
  157.         }
  158.         $criteria Criteria::create();
  159.         $criteria
  160.             ->where(
  161.                 Criteria::expr()->eq('salingState'Vehicle::SALING_STATE_SUPPRIME)
  162.             )
  163.         ;
  164.         return count($this->getVehicles()) === count($this->getVehicles()->matching($criteria));
  165.     }
  166. }