src/Eccube/Repository/NewsRepository.php line 81

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Eccube\Repository;
  13. use Doctrine\Common\Collections\ArrayCollection;
  14. use Doctrine\Common\Collections\Criteria;
  15. use Doctrine\DBAL\Exception\DriverException;
  16. use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
  17. use Doctrine\Persistence\ManagerRegistry as RegistryInterface;
  18. use Eccube\Entity\News;
  19. /**
  20.  * NewsRepository
  21.  *
  22.  * This class was generated by the Doctrine ORM. Add your own custom
  23.  * repository methods below.
  24.  */
  25. class NewsRepository extends AbstractRepository
  26. {
  27.     public function __construct(RegistryInterface $registry)
  28.     {
  29.         parent::__construct($registryNews::class);
  30.     }
  31.     /**
  32.      * 新着情報を登録します.
  33.      *
  34.      * @param $News
  35.      */
  36.     public function save($News)
  37.     {
  38.         $em $this->getEntityManager();
  39.         $em->persist($News);
  40.         $em->flush();
  41.     }
  42.     /**
  43.      * 新着情報を削除します.
  44.      *
  45.      * @param News $News
  46.      *
  47.      * @throws ForeignKeyConstraintViolationException 外部キー制約違反の場合
  48.      * @throws DriverException SQLiteの場合, 外部キー制約違反が発生すると, DriverExceptionをthrowします.
  49.      */
  50.     public function delete($News)
  51.     {
  52.         $em $this->getEntityManager();
  53.         $em->remove($News);
  54.         $em->flush();
  55.     }
  56.     /**
  57.      * @return \Doctrine\ORM\QueryBuilder
  58.      */
  59.     public function getQueryBuilderAll()
  60.     {
  61.         $qb $this->createQueryBuilder('n');
  62.         $qb->orderBy('n.publish_date''DESC')
  63.             ->addOrderBy('n.id''DESC');
  64.         return $qb;
  65.     }
  66.     /**
  67.      * @return News[]|ArrayCollection
  68.      */
  69.     public function getList()
  70.     {
  71.         // second level cacheを効かせるためfindByで取得
  72.         $Results $this->findBy(['visible' => true], ['publish_date' => 'DESC''id' => 'DESC']);
  73.         // 公開日時前のNewsをフィルター
  74.         $criteria Criteria::create();
  75.         $criteria->where(Criteria::expr()->lte('publish_date', new \DateTime()));
  76.         $News = new ArrayCollection($Results);
  77.         return $News->matching($criteria);
  78.     }
  79. }