app/Customize/Repository/BrandRepository.php line 44

Open in your IDE?
  1. <?php
  2. namespace Customize\Repository;
  3. use Customize\Entity\Brand;
  4. use Doctrine\Persistence\ManagerRegistry as RegistryInterface;
  5. class BrandRepository extends \Eccube\Repository\AbstractRepository
  6. {
  7.     public function __construct(RegistryInterface $registry)
  8.     {
  9.         parent::__construct($registryBrand::class);
  10.     }
  11.     /**
  12.      * ブランドを保存する.
  13.      *
  14.      * @param  Brand $brand ブランド
  15.      */
  16.     public function save($brand)
  17.     {
  18.         if (!$brand->getId()) {
  19.             $sortNoTop $this->findOneBy([], ['sort_no' => 'DESC']);
  20.             $sort_no 0;
  21.             if (!is_null($sortNoTop)) {
  22.                 $sort_no $sortNoTop->getSortNo();
  23.             }
  24.             $brand->setSortNo($sort_no 1);
  25.         }
  26.         $em $this->getEntityManager();
  27.         $em->persist($brand);
  28.         $em->flush();
  29.     }
  30.     public function getList()
  31.     {
  32.         $qb $this->createQueryBuilder('b');
  33.         
  34.         $Brands $qb->getQuery()
  35.             ->useResultCache(true$this->getCacheLifetime())
  36.             ->getResult();
  37.         return $Brands;
  38.     }
  39.     /**
  40.      * ブランドを削除する.
  41.      *
  42.      * @param  Brand $Brand 削除対象のタグ
  43.      */
  44.     public function delete($Brand)
  45.     {
  46.         $em $this->getEntityManager();
  47.         $em->beginTransaction();
  48.         $em->createQuery("DELETE \Customize\Entity\Brand b WHERE b.id = :brand")->execute(['brand' => $Brand]);
  49.         $this
  50.             ->createQueryBuilder('b')
  51.             ->update()
  52.             ->set('b.sort_no''b.sort_no - 1')
  53.             ->where('b.sort_no > :sort_no')
  54.             ->setParameter('sort_no'$Brand->getSortNo())
  55.             ->getQuery()
  56.             ->execute();
  57.         $em->remove($Brand);
  58.         $em->flush();
  59.         $em->commit();
  60.     }
  61. }