123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?php
- /*
- * This file is part of the Sonata Project package.
- *
- * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Sonata\UserBundle\Entity;
- use FOS\UserBundle\Doctrine\UserManager as BaseUserManager;
- use Sonata\CoreBundle\Model\ManagerInterface;
- use Sonata\DatagridBundle\Pager\Doctrine\Pager;
- use Sonata\DatagridBundle\ProxyQuery\Doctrine\ProxyQuery;
- use Sonata\UserBundle\Model\UserManagerInterface;
- /**
- * @author Hugo Briand <briand@ekino.com>
- */
- class UserManager extends BaseUserManager implements UserManagerInterface, ManagerInterface
- {
- /**
- * {@inheritdoc}
- */
- public function findUsersBy(array $criteria = null, array $orderBy = null, $limit = null, $offset = null)
- {
- return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
- }
- /**
- * {@inheritdoc}
- */
- public function find($id)
- {
- return $this->repository->find($id);
- }
- /**
- * {@inheritdoc}
- */
- public function findAll()
- {
- return $this->repository->findAll();
- }
- /**
- * {@inheritdoc}
- */
- public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
- {
- return parent::findUsers($criteria, $orderBy, $limit, $offset);
- }
- /**
- * {@inheritdoc}
- */
- public function findOneBy(array $criteria, array $orderBy = null)
- {
- return parent::findUserBy($criteria);
- }
- /**
- * {@inheritdoc}
- */
- public function create()
- {
- return parent::createUser();
- }
- /**
- * {@inheritdoc}
- */
- public function save($entity, $andFlush = true)
- {
- parent::updateUser($entity, $andFlush);
- }
- /**
- * {@inheritdoc}
- */
- public function delete($entity, $andFlush = true)
- {
- parent::deleteUser($entity);
- }
- /**
- * {@inheritdoc}
- */
- public function getTableName()
- {
- return $this->objectManager->getClassMetadata($this->class)->table['name'];
- }
- /**
- * {@inheritdoc}
- */
- public function getConnection()
- {
- return $this->objectManager->getConnection();
- }
- /**
- * {@inheritdoc}
- */
- public function getPager(array $criteria, $page, $limit = 10, array $sort = array())
- {
- $query = $this->repository
- ->createQueryBuilder('u')
- ->select('u');
- $fields = $this->objectManager->getClassMetadata($this->class)->getFieldNames();
- foreach ($sort as $field => $direction) {
- if (!in_array($field, $fields)) {
- throw new \RuntimeException(sprintf("Invalid sort field '%s' in '%s' class", $field, $this->class));
- }
- }
- if (count($sort) == 0) {
- $sort = array('username' => 'ASC');
- }
- foreach ($sort as $field => $direction) {
- $query->orderBy(sprintf('u.%s', $field), strtoupper($direction));
- }
- if (isset($criteria['enabled'])) {
- $query->andWhere('u.enabled = :enabled');
- $query->setParameter('enabled', $criteria['enabled']);
- }
- if (isset($criteria['locked'])) {
- $query->andWhere('u.locked = :locked');
- $query->setParameter('locked', $criteria['locked']);
- }
- $pager = new Pager();
- $pager->setMaxPerPage($limit);
- $pager->setQuery(new ProxyQuery($query));
- $pager->setPage($page);
- $pager->init();
- return $pager;
- }
- }
|