src/CoreBundle/Entity/Vehicles/Equipment.php line 11

Open in your IDE?
  1. <?php
  2. namespace CoreBundle\Entity\Vehicles;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. /**
  6.  * Equipment
  7.  */
  8. class Equipment
  9. {
  10.     //TODO need some documentation
  11.     const SORT_PRICE 99999999999999999;
  12.     /**
  13.      * @var integer
  14.      */
  15.     private $id;
  16.     /**
  17.      * @var integer
  18.      */
  19.     private $temp_id;
  20.     /**
  21.      * @var string
  22.      */
  23.     private $title;
  24.     /**
  25.      * @var integer
  26.      */
  27.     private $state;
  28.     /**
  29.      * @var integer
  30.      */
  31.     private $position 0;
  32.     /**
  33.      * @var Collection
  34.      */
  35.     private $options;
  36.     /**
  37.      * @var Vehicle
  38.      */
  39.     private $vehicle;
  40.     /**
  41.      * Constructor
  42.      */
  43.     public function __construct()
  44.     {
  45.         $this->options = new ArrayCollection();
  46.     }
  47.     /**
  48.      * Get id
  49.      *
  50.      * @return integer
  51.      */
  52.     public function getId()
  53.     {
  54.         return $this->id;
  55.     }
  56.     /**
  57.      * Set tempId
  58.      *
  59.      * @param integer $tempId
  60.      *
  61.      * @return Equipment
  62.      */
  63.     public function setTempId($tempId)
  64.     {
  65.         $this->temp_id $tempId;
  66.         return $this;
  67.     }
  68.     /**
  69.      * Get tempId
  70.      *
  71.      * @return integer
  72.      */
  73.     public function getTempId()
  74.     {
  75.         return $this->temp_id;
  76.     }
  77.     /**
  78.      * Set title
  79.      *
  80.      * @param string $title
  81.      *
  82.      * @return Equipment
  83.      */
  84.     public function setTitle($title)
  85.     {
  86.         $this->title $title;
  87.         return $this;
  88.     }
  89.     /**
  90.      * Get title
  91.      *
  92.      * @return string
  93.      */
  94.     public function getTitle()
  95.     {
  96.         return $this->title;
  97.     }
  98.     /**
  99.      * Set state
  100.      *
  101.      * @param integer $state
  102.      *
  103.      * @return Equipment
  104.      */
  105.     public function setState($state)
  106.     {
  107.         $this->state $state;
  108.         return $this;
  109.     }
  110.     /**
  111.      * Get state
  112.      *
  113.      * @return integer
  114.      */
  115.     public function getState()
  116.     {
  117.         return $this->state 0;
  118.     }
  119.     /**
  120.      * Set position
  121.      *
  122.      * @param integer $position
  123.      *
  124.      * @return Equipment
  125.      */
  126.     public function setPosition($position)
  127.     {
  128.         $this->position $position;
  129.         return $this;
  130.     }
  131.     /**
  132.      * Get position
  133.      *
  134.      * @return integer
  135.      */
  136.     public function getPosition()
  137.     {
  138.         return $this->position;
  139.     }
  140.     /**
  141.      * Add option
  142.      *
  143.      * @param EquipmentOptions $option
  144.      *
  145.      * @return Equipment
  146.      */
  147.     public function addOption(EquipmentOptions $option)
  148.     {
  149.         $this->options[] = $option;
  150.         return $this;
  151.     }
  152.     /**
  153.      * Remove option
  154.      *
  155.      * @param EquipmentOptions $option
  156.      */
  157.     public function removeOption(EquipmentOptions $option)
  158.     {
  159.         $this->options->removeElement($option);
  160.     }
  161.     /**
  162.      * Get options
  163.      *
  164.      * @return Collection
  165.      */
  166.     public function getOptions()
  167.     {
  168.         return $this->options;
  169.     }
  170.     /**
  171.      * Set vehicle
  172.      *
  173.      * @param Vehicle $vehicle
  174.      *
  175.      * @return Equipment
  176.      */
  177.     public function setVehicle(Vehicle $vehicle null)
  178.     {
  179.         $this->vehicle $vehicle;
  180.         return $this;
  181.     }
  182.     /**
  183.      * Get vehicle
  184.      *
  185.      * @return Vehicle
  186.      */
  187.     public function getVehicle()
  188.     {
  189.         return $this->vehicle;
  190.     }
  191.     /**
  192.      * @var Collection
  193.      */
  194.     private $vehicle_items;
  195.     /**
  196.      * Add vehicleItem
  197.      *
  198.      * @param VehicleItem $vehicleItem
  199.      *
  200.      * @return Equipment
  201.      */
  202.     public function addVehicleItem(VehicleItem $vehicleItem)
  203.     {
  204.         $this->vehicle_items[] = $vehicleItem;
  205.         return $this;
  206.     }
  207.     public function getAdminName()
  208.     {
  209.         $state $this->getState() ? '' ' (отключена)';
  210.         return $this->getTitle().$state;
  211.     }
  212.     /**
  213.      * Remove vehicleItem
  214.      *
  215.      * @param VehicleItem $vehicleItem
  216.      */
  217.     public function removeVehicleItem(VehicleItem $vehicleItem)
  218.     {
  219.         $this->vehicle_items->removeElement($vehicleItem);
  220.     }
  221.     /**
  222.      * Get vehicleItems
  223.      *
  224.      * @return Collection
  225.      */
  226.     public function getVehicleItems()
  227.     {
  228.         return $this->vehicle_items;
  229.     }
  230.     public function __toString()
  231.     {
  232.         return (string) $this->title;
  233.     }
  234.     public function minPrice()
  235.     {
  236.         $minItem $this->getMinVehicleItem();
  237.         if ($minItem) {
  238.             return $minItem->calcPrice();
  239.         }
  240.         return 0;
  241.     }
  242.     public function minFullPrice()
  243.     {
  244.         $minItem $this->getMinVehicleItem();
  245.         if(!$minItem) {
  246.             return 0;
  247.         }
  248.         return $minItem->fullPrice();
  249.     }
  250.     public function minPreOrderPrice()
  251.     {
  252.         $minItem $this->getMinVehicleItem();
  253.         if(!$minItem) {
  254.             return 0;
  255.         }
  256.         return $minItem->getPreorderPrice();
  257.     }
  258.     /**
  259.      * @return bool|VehicleItem|mixed
  260.      */
  261.     public function getMinVehicleItem()
  262.     {
  263.         $item false;
  264.         /** @var VehicleItem $vehicleItem */
  265.         foreach ($this->getVehicleItems() as $vehicleItem) {
  266.             if(!$vehicleItem->getState()) {
  267.                 continue;
  268.             }
  269.             if(!$vehicleItem->getEquipment()->getState()) {
  270.                 continue;
  271.             }
  272.             if($vehicleItem->calcPrice() == 0) {
  273.                 continue;
  274.             }
  275.             if(!$item || $vehicleItem->calcPrice() < $item->calcPrice()) {
  276.                 $item $vehicleItem;
  277.             }
  278.         }
  279.         return $item;
  280.     }
  281.     public function maxPrice()
  282.     {
  283.         $minItem $this->getMaxVehicleItem();
  284.         return $minItem $minItem->calcPrice() : 0;
  285.     }
  286.     /**
  287.      * @return bool|VehicleItem|mixed
  288.      */
  289.     public function getMaxVehicleItem()
  290.     {
  291.         $item false;
  292.         /** @var VehicleItem $vehicleItem */
  293.         foreach ($this->getVehicleItems() as $vehicleItem) {
  294.             if(!$vehicleItem->getState()) {
  295.                 continue;
  296.             }
  297.             if($vehicleItem->calcPrice() == 0) {
  298.                 continue;
  299.             }
  300.             if(!$item || $vehicleItem->calcPrice() > $item->calcPrice()) {
  301.                 $item $vehicleItem;
  302.             }
  303.         }
  304.         return $item;
  305.     }
  306. }