HosipLan

Untitled

Sep 4th, 2011
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.29 KB | None | 0 0
  1. class UserDependentRepository extends Doctrine\ORM\EntityRepository implements Doctrine\Common\Persistence\ObjectRepository
  2. {
  3.  
  4.     public function __construct(Doctrine\ORM\EntityManager $em, Mapping\ClassMetadata $class, Identity $identity)
  5.     {
  6.         $this->repository = new Doctrine\ORM\EntityRepository($em, $class);
  7.         $this->identity = $identity;
  8.         $this->class = $class;
  9.         $this->em = $em;
  10.     }
  11.  
  12.     public function createQueryBuilder($alias)
  13.     {
  14.         return $this->repository->createQueryBuilder($alias)
  15.             ->where($alias . '.identity = :identity')
  16.             ->setParameter('identity', $this->identity->id);
  17.     }
  18.  
  19.     public function find($id)
  20.     {
  21.         $id = array_combine($this->class->identifier, (array)$id);
  22.         return $this->repository->findBy($id + array(
  23.             'identity' => $this->identity->id
  24.         ));
  25.     }
  26.  
  27.     public function findAll()
  28.     {
  29.         return $this->repository->findBy(array(
  30.             'identity' => $this->identity->id
  31.         ));
  32.     }
  33.  
  34.  
  35.     public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  36.     {
  37.         return $this->repository->findBy(array(
  38.             'identity' => $this->identity->id
  39.         ) + $criteria, $orderBy, $limit, $offset);
  40.     }
  41.  
  42.     public function findOneBy(array $criteria)
  43.     {
  44.         return $this->repository->findBy(array(
  45.             'identity' => $this->identity->id
  46.         ) + $criteria);
  47.     }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment