src/CoreBundle/Model/Service/ServiceWork.php line 50

Open in your IDE?
  1. <?php
  2. namespace CoreBundle\Model\Service;
  3. use CoreBundle\Entity\Model;
  4. use CoreBundle\Services\MediaExtensionVidi;
  5. use DcSiteBundle\Entity\ServiceWorkGroup;
  6. use DcSiteBundle\Entity\WorkGroupRelation;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. class ServiceWork
  9. {
  10.     private $em;
  11.     const MAIN_SERVICE_ID 7447;
  12.     /**
  13.      * CallbackRequestLog constructor.
  14.      * @param EntityManagerInterface $entityManager
  15.      */
  16.     public function __construct(EntityManagerInterface $entityManagerMediaExtensionVidi  $mediaExtension)
  17.     {
  18.         $this->em $entityManager;
  19.         $this->mediaExtension $mediaExtension;
  20.     }
  21.     public function getModelsByGroupAndBrand($workGroup$brand)
  22.     {
  23.         $result $this->em->getRepository(WorkGroupRelation::class)->getWorksByGroup($workGroup);
  24.         $workIds = [];
  25.         foreach ($result as $el) {
  26.             $workIds[] = $el->getWork()->getId();
  27.         }
  28.         $models $this->em->getRepository(Model::class)->getModelByWorkGroup($workIds$brand);
  29.         return $models;
  30.     }
  31.     public function getTopGroup($workGroup$work)
  32.     {
  33.         if ($work->getUrl() == $workGroup){
  34.             return true;
  35.         } elseif ($work->getParent()){
  36.            return $this->getTopGroup($workGroup$work->getParent());
  37.         } else {
  38.             return false;
  39.         }
  40.     }
  41.     public function getWorksByModelOrBrand($workGroup$subGroup ''$model ''$brand)
  42.     {
  43.         $serviceWorks $this->em->getRepository(ServiceWork::class)->getWorksByModelAndBrand($model$brand);
  44.         $otherWorkGroups = [];
  45.         $selectGroup = [];
  46.         $prices = [];
  47.         if ($serviceWorks){
  48.             $subGroups $this->em->getRepository(ServiceWorkGroup::class)->getServiceGroupByParent($workGroup);
  49.             foreach ($subGroups as $group){
  50.                 foreach ($serviceWorks as $work){
  51.                     if ($this->getTopGroup($group->getUrl(), $work['work']->getGroup())){
  52.                         $prices[$group->GetId()][] = $work['min_price'];
  53.                     }
  54.                 }
  55.                 $otherWorkGroups[] = [
  56.                     'group' => $group,
  57.                     'min_price' => isset($prices[$group->GetId()]) ? min($prices[$group->GetId()]) : 0,
  58.                 ];
  59.             }
  60.             if ($subGroup){
  61.                 $group $this->em->getRepository(ServiceWorkGroup::class)->findOneBy(['url' => $subGroup]);
  62.                 foreach ($serviceWorks as $work){
  63.                     if ($this->getTopGroup($group->getUrl(), $work['work']->getGroup())){
  64.                         $prices[$group->GetId()][] = $work['min_price'];
  65.                     }
  66.                 }
  67.                 $selectGroup[] = [
  68.                     'group' => $group,
  69.                     'min_price' => isset($prices[$group->GetId()]) ? min($prices[$group->GetId()]) : 0,
  70.                 ];
  71.             }
  72.         }
  73.         $arRes = [
  74.             'otherGroups' => $otherWorkGroups,
  75.             'mainGroup' => $selectGroup
  76.         ];
  77.         return $arRes;
  78.     }
  79.     public function getGroupBrands($workGroup)
  80.     {
  81.         $result $this->em->getRepository(WorkGroupRelation::class)->getWorksByGroup($workGroup);
  82.         $brands = [];
  83.         foreach ($result as $el){
  84.             $brand $el->getWork()->getDealer()->getBrand();
  85.             $brands[$brand->getId()] = [
  86.                 'id' => $brand->getId(),
  87.                 'name' => $brand->getName(),
  88.                 'url' => $brand->getUrl(),
  89.                 'img' =>  $this->mediaExtension->getPath($brand->getLogo(), 'reference'),
  90.             ];
  91.         }
  92.         return $brands;
  93.     }
  94.     public function getMainService()
  95.     {
  96.         return $this->em->getRepository(ServiceWorkGroup::class)->find(self::MAIN_SERVICE_ID);
  97.     }
  98.     public function getSubGroupsByBrand($workGroup$brand)
  99.     {
  100.         $subGroups $this->em->getRepository(ServiceWorkGroup::class)->getServiceGroupByParent($workGroup);
  101.         $subGroupsIds = [];
  102.         foreach ($subGroups as $group){
  103.             $subGroupsIds[] = $group->getId();
  104.         }
  105.         $filtereSubGroups = [];
  106.         if ($subGroupsIds){
  107.             $result $this->em->getRepository(WorkGroupRelation::class)->getGroupByBrand($subGroupsIds$brand);
  108.             foreach ($result as $el){
  109.                 $filtereSubGroups[$el->getGroup()->getId()] = $el->getGroup();
  110.             }
  111.         }
  112.         return $filtereSubGroups;
  113.     }
  114. }