src/Eccube/Repository/NewsRepository.php line 76

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.   public function __construct(RegistryInterface $registry) {
  27.     parent::__construct($registryNews::class);
  28.   }
  29.   /**
  30.    * 新着情報を登録します.
  31.    *
  32.    * @param $News
  33.    */
  34.   public function save($News) {
  35.     $em $this->getEntityManager();
  36.     $em->persist($News);
  37.     $em->flush();
  38.   }
  39.   /**
  40.    * 新着情報を削除します.
  41.    *
  42.    * @param News $News
  43.    *
  44.    * @throws ForeignKeyConstraintViolationException 外部キー制約違反の場合
  45.    * @throws DriverException SQLiteの場合, 外部キー制約違反が発生すると, DriverExceptionをthrowします.
  46.    */
  47.   public function delete($News) {
  48.     $em $this->getEntityManager();
  49.     $em->remove($News);
  50.     $em->flush();
  51.   }
  52.   /**
  53.    * @return \Doctrine\ORM\QueryBuilder
  54.    */
  55.   public function getQueryBuilderAll() {
  56.     $qb $this->createQueryBuilder('n');
  57.     $qb->orderBy('n.publish_date''DESC')
  58.       ->addOrderBy('n.id''DESC');
  59.     return $qb;
  60.   }
  61.   /**
  62.    * @return News[]|ArrayCollection
  63.    */
  64.   public function getList($category_id,$num="") {
  65.     // second level cacheを効かせるためfindByで取得
  66.     $Results $this->findBy(['visible' => true,'news_category_id' => $category_id], ['publish_date' => 'DESC''id' => 'DESC']);
  67.     // 公開日時前のNewsをフィルター
  68.     $criteria Criteria::create();
  69.     $criteria->where(Criteria::expr()->lte('publish_date', new \DateTime()));
  70.     $News = new ArrayCollection($Results);
  71.     $rows $News->matching($criteria);
  72.     
  73.     return $rows;
  74.   }
  75. }