src/Repository/MediaRepository.php line 247

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: adv
  5.  * Date: 22.12.15
  6.  * Time: 11:45
  7.  */
  8. namespace Slivki\Repository;
  9. use Doctrine\ORM\EntityRepository;
  10. use Slivki\Entity\Category;
  11. use Slivki\Entity\Comment;
  12. use Slivki\Entity\Media;
  13. use Slivki\Entity\MediaType;
  14. class MediaRepository extends EntityRepository {
  15.     /**
  16.      * @return null|\Slivki\Entity\Media
  17.      */
  18.     public function getMedia($entityID$typeID) {
  19.         return $this->findBy(
  20.             array (
  21.                 "entityID" => $entityID,
  22.                 "typeID" => $typeID
  23.             ),
  24.             array (
  25.                 "sortOrder" => 'ASC'
  26.             )
  27.         );
  28.     }
  29.     public function getOneMediaByEntity($entityID$typeID) {
  30.         $medias $this->findBy(['entityID' => $entityID'typeID' => $typeID], ['sortOrder' => 'asc']);
  31.         return $medias $medias[0] : false;
  32.     }
  33.     public function getSaleIconMedia($saleID) {
  34.         $mediaList $this->getMedia($saleIDMediaType::TYPE_SALE_ICON_ID);
  35.         if (!$mediaList) {
  36.             return null;
  37.         }
  38.         return $mediaList[0];
  39.     }
  40.     public function getSaleAlternativeIconMedia($saleID) {
  41.         $mediaList $this->getMedia($saleIDMediaType::TYPE_SALE_ALTERNATIVE_ICON_ID);
  42.         if (!$mediaList) {
  43.             return null;
  44.         }
  45.         return $mediaList[0];
  46.     }
  47.     public function getOfferAdditionalTeaserMedia($offerID) {
  48.         $mediaList $this->getMedia($offerIDMediaType::TYPE_OFFER_ADDITIONAL_TEASER_ID);
  49.         if (!$mediaList) {
  50.             return null;
  51.         }
  52.         return $mediaList[0];
  53.     }
  54.     public function getOfferHotFeedIconMedia($offerID) {
  55.         $mediaList $this->getMedia($offerIDMediaType::TYPE_HOT_FEED_OFFER_ICON_IMAGE_ID);
  56.         if (!$mediaList) {
  57.             return null;
  58.         }
  59.         return $mediaList[0];
  60.     }
  61.     public function getGalleryImageMedia($saleID) {
  62.         $mediaList $this->getMedia($saleIDMediaType::TYPE_SALE_GALLERY_IMAGE_ID);
  63.         if(!$mediaList) {
  64.             return null;
  65.         }
  66.         return $mediaList[0];
  67.     }
  68.     public function getFlierImageMedia($saleID) {
  69.         $mediaList $this->getMedia($saleIDMediaType::TYPE_SALE_FLIER_ID);
  70.         if(!$mediaList) {
  71.             return null;
  72.         }
  73.         return $mediaList[0];
  74.     }
  75.     public function getFlierLogoImageMedia($saleID) {
  76.         $mediaList $this->getMedia($saleIDMediaType::TYPE_SALE_FLIER_LOGO_ID);
  77.         if(!$mediaList) {
  78.             return null;
  79.         }
  80.         return $mediaList[0];
  81.     }
  82.     public function getFlierMapLogoImageMedia($saleID) {
  83.         $mediaList $this->getMedia($saleIDMediaType::TYPE_SALE_FLIER_MAP_LOGO_ID);
  84.         if(!$mediaList) {
  85.             return null;
  86.         }
  87.         return $mediaList[0];
  88.     }
  89.     public function getFlierMapIconImageMedia($saleID) {
  90.         $mediaList $this->getMedia($saleIDMediaType::TYPE_HOT_FEED_OFFER_ICON_IMAGE_ID);
  91.         if(!$mediaList) {
  92.             return null;
  93.         }
  94.         return $mediaList[0];
  95.     }
  96.     public function getFlierSaleCarouselLogoMedia($saleID) {
  97.         $mediaList $this->getMedia($saleIDMediaType::TYPE_SALE_FLIER_CAROUSEL_LOGO_ID);
  98.         if(!$mediaList) {
  99.             return null;
  100.         }
  101.         return $mediaList[0];
  102.     }
  103.     public function getŠ”ategoryLandingImageMedia($categoryID) {
  104.         $mediaList $this->getMedia($categoryIDMediaType::TYPE_CATEGORY_LANDING_IMAGE_ID);
  105.         if(!$mediaList) {
  106.             return null;
  107.         }
  108.         return $mediaList[0];
  109.     }
  110.     public function getŠ”ategoryHotFeedImageMedia($categoryID) {
  111.         $mediaList $this->getMedia($categoryIDMediaType::TYPE_CATEGORY_HOT_FEED_IMAGE_ID);
  112.         if(!$mediaList) {
  113.             return null;
  114.         }
  115.         return $mediaList[0];
  116.     }
  117.     public function getŠ”ategoryHotFeedIconMedia($categoryID) {
  118.         $mediaList $this->getMedia($categoryIDMediaType::TYPE_HOT_FEED_CATEGORY_ICON_IMAGE_ID);
  119.         if(!$mediaList) {
  120.             return null;
  121.         }
  122.         return $mediaList[0];
  123.     }
  124.     public function getSaleMainIconMedia($saleID) {
  125.         $mediaList $this->getMedia($saleIDMediaType::TYPE_SALE_MAIN_ICON_ID);
  126.         if (!$mediaList) {
  127.             return null;
  128.         }
  129.         return $mediaList[0];
  130.     }
  131.     public function getSupplierLogo($supplierID) {
  132.         $mediaList $this->getMedia($supplierIDMediaType::TYPE_PARTNER_LOGO_ID);
  133.         if (!$mediaList) {
  134.             return null;
  135.         }
  136.         return $mediaList[0];
  137.     }
  138.     public function getDirectorLogo($directorID) {
  139.         $mediaList $this->getMedia($directorIDMediaType::TYPE_DIRECTOR_LOGO_ID);
  140.         if (!$mediaList) {
  141.             return null;
  142.         }
  143.         return $mediaList[0];
  144.     }
  145.     public function getOfferTeaserLogo($offerID) {
  146.         $mediaList $this->getMedia($offerIDMediaType::TYPE_OFFER_TEASER_LOGO_ID);
  147.         if (!$mediaList) {
  148.             return null;
  149.         }
  150.         return $mediaList[0];
  151.     }
  152.     public function getOfferCommentMediaListByCategoryID($categoryID$offset 0$limit 10) {
  153.         $dql "select comment, media from Slivki:Comment comment
  154.             inner join Slivki:Offer offer with offer.ID = comment.entityID
  155.             inner join offer.categories category
  156.             inner join comment.medias media 
  157.             where comment.typeID = :commentTypeID
  158.               and comment.hidden = false
  159.               and comment.confirmedPhone = true
  160.               and (comment.deleted = false or comment.deleted is null)
  161.               and offer.active = true
  162.               and category.ID = :categoryID
  163.             order by comment.ID desc";
  164.         $comments $this->getEntityManager()->createQuery($dql)
  165.             ->setParameter('commentTypeID'Comment::TYPE_OFFER_COMMENT)
  166.             ->setParameter('categoryID'$categoryID)
  167.             ->setMaxResults($limit)
  168.             ->setFirstResult($offset)
  169.             ->getResult();
  170.         return $comments;
  171.     }
  172.     public function getOfferCommentMediaListByOfferID($offerID$offset 0$limit 10) {
  173.         $dql "select comment, media from Slivki:Comment comment
  174.             inner join comment.medias media 
  175.             inner join Slivki:Offer offer with offer.ID = comment.entityID
  176.             where comment.typeID = :commentTypeID
  177.               and comment.hidden = false
  178.               and comment.confirmedPhone = true
  179.               and (comment.deleted = false or comment.deleted is null)
  180.               and offer.active = true
  181.               and offer.ID = :offerID
  182.             order by comment.ID desc";
  183.         $comments $this->getEntityManager()->createQuery($dql)
  184.             ->setParameter('commentTypeID'Comment::TYPE_OFFER_COMMENT)
  185.             ->setParameter('offerID'$offerID)
  186.             ->setMaxResults($limit)
  187.             ->setFirstResult($offset)
  188.             ->getResult();
  189.         return $comments;
  190.     }
  191.     public function getOfferCommentMediaList($offset 0$limit 10) {
  192.         $dql "select comment, media from Slivki:Comment comment
  193.             inner join comment.medias media 
  194.             inner join Slivki:Offer offer with offer.ID = comment.entityID
  195.             where comment.typeID = :commentTypeID and comment.hidden = false and offer.active = true and comment.confirmedPhone = true
  196.             and (comment.deleted = false or comment.deleted is null)
  197.             order by comment.ID desc";
  198.         $comments $this->getEntityManager()->createQuery($dql)
  199.             ->setParameter('commentTypeID'Comment::TYPE_OFFER_COMMENT)
  200.             ->setMaxResults($limit)
  201.             ->setFirstResult($offset)
  202.             ->getResult();
  203.         return $comments;
  204.     }
  205.     /**
  206.      * @deprecated use Repository/Media/ShopMediaRepositoryInterface
  207.      */
  208.     public function getOfferShopMedias($offerID) {
  209.         return $this->getMedia($offerIDMediaType::TYPE_OFFER_SHOP_PHOTO_ID);
  210.     }
  211.     public function getDirectorPhotoMedias($directorID) {
  212.         return $this->getMedia($directorIDMediaType::TYPE_SUPPLIER_PHOTO_ID);
  213.     }
  214.     public function getOfferDetailMedias($offerID) {
  215.         return $this->getMedia($offerIDMediaType::TYPE_OFFER_DETAIL_PHOTO_ID);
  216.     }
  217.     public function getLandingCategoryMedia(Category $category) {
  218.         $mediaList $this->getMedia($category->getID(), MediaType::TYPE_CATEGORY_LANDING_IMAGE_ID);
  219.         if (count($mediaList) == 0) {
  220.             foreach ($category->getParentCategories() as $parentCategory) {
  221.                 $mediaList $this->getMedia($parentCategory->getID(), MediaType::TYPE_CATEGORY_LANDING_IMAGE_ID);
  222.                 if (count($mediaList) > 0) {
  223.                     break;
  224.                 }
  225.             }
  226.         }
  227.         return count($mediaList) > $mediaList[0] : null;
  228.     }
  229.     public function save(Media\AbstractMediaBase $media): void
  230.     {
  231.         $entityManager $this->getEntityManager();
  232.         $entityManager->persist($media);
  233.         $entityManager->flush();
  234.     }
  235. }