|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
-
- namespace Lc\ShopBundle\Repository;
-
- use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface;
- use Doctrine\ORM\EntityManager;
- use Doctrine\ORM\EntityRepository;
- use Lc\ShopBundle\Context\DefaultRepositoryInterface;
- use Lc\ShopBundle\Context\FilterMerchantInterface;
- use Lc\ShopBundle\Context\GlobalParamInterface;
- use Lc\ShopBundle\Context\StatusInterface;
- use Symfony\Component\Security\Core\Security;
-
- class BaseRepository extends EntityRepository implements ServiceEntityRepositoryInterface
- {
- public $globalParam;
-
- /**
- * @param string $entityClass The class name of the entity this repository manages
- */
- public function __construct(EntityManager $entityManager, GlobalParamInterface $globalParam)
- {
- $this->globalParam = $globalParam;
- parent::__construct($entityManager, $entityManager->getClassMetadata($this->getInterfaceClass()));
- }
-
-
- public function findByMerchantQuery($merchant)
- {
- return $this->createQueryBuilder('e')
- ->where('e.merchant = :currentMerchant')
- ->setParameter('currentMerchant', $merchant->getId()) ;
- }
-
- public function findAll()
- {
- return $this->findBy(array());
- }
-
- public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
- {
- $className = $this->getClassMetadata()->getName();
- $entity = new $className;
-
- if($entity instanceof StatusInterface){
- if (!isset($criteria['status'])) $criteria['status'] = 1;
- if ($criteria['status'] === false) unset($criteria['status']);
- }
-
- if($entity instanceof FilterMerchantInterface){
- if (!isset($criteria['merchant'])) $criteria['merchant'] = $this->globalParam->getCurrentMerchant();
- if ($criteria['merchant'] === false) unset($criteria['merchant']);
- }
-
-
- return parent::findBy($criteria, $orderBy, $limit, $offset);
-
- }
-
- public function findOneBy(array $criteria, array $orderBy = null)
- {
-
- $className = $this->getClassMetadata()->getName();
- $entity = new $className;
-
- if($entity instanceof StatusInterface){
- if (!isset($criteria['status'])) $criteria['status'] = 1;
- if ($criteria['status'] === false) unset($criteria['status']);
- }
-
- if($entity instanceof FilterMerchantInterface){
- if (!isset($criteria['merchant'])) $criteria['merchant'] = $this->globalParam->getCurrentMerchant();
- if ($criteria['merchant'] === false) unset($criteria['merchant']);
- }
-
- return parent::findOneBy($criteria, $orderBy);
- }
-
- }
|