src/CoreBundle/Model/Vehicles/UsedVehicle.php line 59

Open in your IDE?
  1. <?php
  2. /**
  3.  * @license proprietary
  4.  * This code is part of vidi portal application
  5.  */
  6. namespace CoreBundle\Model\Vehicles;
  7. use CoreBundle\Entity\Rate;
  8. use CoreBundle\Entity\Vehicles\Equipment;
  9. use CoreBundle\Entity\Vehicles\Variation;
  10. use CoreBundle\Entity\Vehicles\VariationCharacteristic;
  11. use CoreBundle\Entity\Vehicles\VehicleItem;
  12. class UsedVehicle extends AbstractVehicle
  13. {
  14.     private static $VehicleItems = [];
  15.     /**
  16.      * @param $locale
  17.      * @return array
  18.      */
  19.     public function getOptionsArray($locale)
  20.     {
  21.         $equipment $this->getVehicleEntity()->getEquipments()->first();
  22.         $options $equipment->getOptions();
  23.         $result = [];
  24.         /** @var \CoreBundle\Entity\Vehicles\EquipmentOptions $option */
  25.         foreach ($options as $option) {
  26.             $oneOption $option->getOption();
  27.             $oType $option->getOption()->getOptionType();
  28.             if (!isset($result[$oType])) {
  29.                 $result[$oType] = [
  30.                     'id' => $oType,
  31.                     'title' => EquipmentOptions::getTypeName($oType$locale),
  32.                     'options' => []
  33.                 ];
  34.             }
  35.             if (!isset($result[$oType]['options'][$oneOption->getId()])) {
  36.                 $opTitle = ($locale == 'ru') ? $oneOption->getTitleRu() : $oneOption->getTitleUa();
  37.                 $opValue = ($locale == 'ru') ? $option->getValueRu() : $option->getValueUa();
  38.                 $result[$oType]['options'][$oneOption->getId()] = [
  39.                     'id' => $oneOption->getId(),
  40.                     'title' => $opTitle,
  41.                     'value' => $opValue
  42.                 ];
  43.             }
  44.             $opValue = ($locale == 'ru') ? $option->getValueRu() : $option->getValueUa();
  45.             $result[$oType]['options'][$oneOption->getId()]['values'][] = [
  46.                 'price' => $option->getPrice(),
  47.                 'value' => $opValue,
  48.             ];
  49.         }
  50.         return $result;
  51.     }
  52.     public function getOptions($locale)
  53.     {
  54.         $options = [];
  55.         if ($this->getVehicleEntity()->getAutoRiaOptions()) {
  56.             $autoriaOptions $this->getVehicleEntity()->getAutoRiaOptions()->toArray();
  57.             foreach ($autoriaOptions as $option){
  58.                 $options[$option->getAutoriaId()] = $option->getTitle($locale);
  59.             }
  60.         }
  61.         if (!$options) {
  62.             $options json_decode($this->getVehicleEntity()->getRiaOptions(),true);
  63.         }
  64.         return $options;
  65.     }
  66.     /**
  67.      * @return float
  68.      */
  69.     public function getVehicleItemPrice()
  70.     {
  71.         return $this->getVehicleItem()->getPrice();
  72.     }
  73.     /**
  74.      * @return bool|VehicleItem
  75.      */
  76.     public function getVehicleItem()
  77.     {
  78.         $Vehicle $this->getVehicleEntity();
  79.         if (!isset(self::$VehicleItems[$Vehicle->getId()])) {
  80.             $VehicleItem $Vehicle->getVehicleItems()->first();
  81.             if (!$VehicleItem) {
  82.                 return false;
  83.             }
  84.             self::$VehicleItems[$Vehicle->getId()] = $VehicleItem;
  85.         }
  86.         return self::$VehicleItems[$Vehicle->getId()];
  87.     }
  88.     public function getRecommend()
  89.     {
  90.         return $this->getVehicleEntity()->getRecommend();
  91.     }
  92.     public function getSold()
  93.     {
  94.         return $this->getVehicleItem()->getSold();
  95.     }
  96.     public function getHasNds()
  97.     {
  98.         return $this->getVehicleItem()->getHasNds();
  99.     }
  100.     public function getDeposit()
  101.     {
  102.         return $this->getVehicleItem()->getDeposit();
  103.     }
  104.     public function hasDeposit()
  105.     {
  106.         return $this->getVehicleItem()->getDeposit();
  107.     }
  108.     public function getYear()
  109.     {
  110.         return $this->getVehicleItem()->getYear();
  111.     }
  112.     public function price()
  113.     {
  114.         $VehicleItem $this->getVehicleItem();
  115.         if (!$VehicleItem) {
  116.             return 0;
  117.         }
  118.         if($VehicleItem->getSold() && $VehicleItem->getPrice() < 20000) {
  119.             return  $VehicleItem->getPrice() * $VehicleItem->getVehicle()->getDealer()->getRate();
  120.         }
  121.         if ($VehicleItem->getAltPrice()) {
  122.             return $VehicleItem->getAltPrice();
  123.         }
  124.         //TODO костыль для JLR
  125.         if (in_array($VehicleItem->getVehicle()->getDealer()->getId(), [3233])) {
  126.             return $VehicleItem->calcPrice();
  127.             $rate $this->em->getRepository(Rate::class)->getBiggestRate()->getRate();
  128.             return ceil($VehicleItem->getPrice() * $rate);
  129.         }
  130.         return $VehicleItem->getPrice();
  131.     }
  132.     /**
  133.      * @return Variation
  134.      */
  135.     public function getVariation()
  136.     {
  137.         return $this->getVehicleItem()->getVariation();
  138.     }
  139.     /**
  140.      * @return Equipment
  141.      */
  142.     public function getEquipment()
  143.     {
  144.         return $this->getVehicleItem()->getEquipment();
  145.     }
  146.     public function fullPrice()
  147.     {
  148.         $VehicleItem $this->getVehicleItem();
  149.         //TODO костыль для JLR
  150.         if (in_array($VehicleItem->getVehicle()->getDealer()->getId(), [3233])) {
  151.             return ceil($VehicleItem->getPrice() * $VehicleItem->getVehicle()->getDealer()->getRate());
  152.         }
  153.         return $VehicleItem->getPrice();
  154.     }
  155.     public function hasActionPrice()
  156.     {
  157.         return $this->price() < $this->fullPrice();
  158.     }
  159.     public function getActionPercent()
  160.     {
  161.         if (!$this->hasActionPrice()) {
  162.             return 0;
  163.         }
  164.         return ceil(100 - ($this->price() * 100 $this->fullPrice()));
  165.     }
  166.     public function getSingleOwner()
  167.     {
  168.         $VehicleItem $this->getVehicleItem();
  169.         return $VehicleItem $VehicleItem->getSingleOwner() : false;
  170.     }
  171.     public function getNoAccident()
  172.     {
  173.         $VehicleItem $this->getVehicleItem();
  174.         return $VehicleItem $VehicleItem->getNoAccident() : false;
  175.     }
  176.     public function getBuyInUkraine()
  177.     {
  178.         $VehicleItem $this->getVehicleItem();
  179.         return $VehicleItem $VehicleItem->getBuyInUkraine() : false;
  180.     }
  181.     public function getServiceBook()
  182.     {
  183.         $VehicleItem $this->getVehicleItem();
  184.         return $VehicleItem $VehicleItem->getServiceBook() : false;
  185.     }
  186.     public function hasReserved()
  187.     {
  188.         return $this->getVehicleItem()->getIsReserved();
  189.     }
  190.     public function creditMinAmount()
  191.     {
  192.         $VehicleItem $this->getVehicleItem();
  193.         return $VehicleItem $VehicleItem->getCreditMinAmount() : false;
  194.     }
  195.     public function creditPercent()
  196.     {
  197.         $VehicleItem $this->getVehicleItem();
  198.         return $VehicleItem $VehicleItem->getCreditPercent() : false;
  199.     }
  200.     public function getProgram()
  201.     {
  202.         $VehicleItem $this->getVehicleItem();
  203.         return $VehicleItem $VehicleItem->getProgramm() : false;
  204.     }
  205.     public function characteristicByGroup($locale)
  206.     {
  207.         $variation $this->getVehicleItem()->getVariation();
  208.         $characteristic $variation->getCharacteristics();
  209.         $result = [];
  210.         /** @var VariationCharacteristic $vCharacteristic */
  211.         foreach ($characteristic as $vCharacteristic) {
  212.             if (!$vCharacteristic->getValue($locale)) {
  213.                 continue;
  214.             }
  215.             $char $vCharacteristic->getCharacteristic();
  216.             $group $char->getGroup();
  217.             //TODO move to config + rewrite
  218.             $groupId $group $group->getId() : 'other';
  219.             $groupTitle $group $group->getTitle($locale) : 'Другие характеристики';
  220.             if (!isset($result[$groupId])) {
  221.                 $result[$groupId] = [
  222.                     'id' => $groupId,
  223.                     'title' => $groupTitle,
  224.                     'characteristics' => [],
  225.                 ];
  226.             }
  227.             $result[$groupId]['characteristics'][] = [
  228.                 'title' => $char->getTitle($locale),
  229.                 'value' => $vCharacteristic->getValue($locale),
  230.             ];
  231.         }
  232.         return $result;
  233.     }
  234. }