Display registration should use pending Registrations.

fixes PHRAS-551
This commit is contained in:
Benoît Burnichon
2015-06-02 11:14:35 +02:00
parent 9008529952
commit 89df907285
3 changed files with 36 additions and 8 deletions

View File

@@ -356,14 +356,19 @@ class UserController extends Controller
$userRegistrations = [];
/** @var RegistrationRepository $registrationRepository */
$registrationRepository = $this->app['repo.registrations'];
foreach (
$registrationRepository->getUserRegistrations(
$authenticatedUser,
$this->getAclForConnectedUser()->get_granted_base(['canadmin'])
) as $registration) {
$collections = $this->getAclForConnectedUser()->get_granted_base(['canadmin']);
$authenticatedUserId = $authenticatedUser->getId();
foreach ($registrationRepository->getPendingRegistrations($collections) as $registration) {
$user = $registration->getUser();
$userRegistrations[$user->getId()]['user'] = $user;
$userRegistrations[$user->getId()]['registrations'][$registration->getBaseid()] = $registration;
$userId = $user->getId();
// Can not handle self registration.
if ($authenticatedUserId == $userId) {
continue;
}
if (!isset($userRegistrations[$userId])) {
$userRegistrations[$userId] = ['user' => $user, 'registrations' => []];
}
$userRegistrations[$userId]['registrations'][$registration->getBaseid()] = $registration;
}
return $this->render('admin/user/registrations.html.twig', [

View File

@@ -644,7 +644,7 @@ SQL;
* Return an instance of native cache query for default ORM
* @todo return an instance of NativeQueryProvider for given orm;
*/
$app['orm.orm.em.native-query'] = $app->share(function ($app) {
$app['orm.em.native-query'] = $app->share(function ($app) {
return new NativeQueryProvider($app['orm.em']);
});

View File

@@ -49,6 +49,29 @@ class RegistrationRepository extends EntityRepository
return $qb->getQuery()->getResult();
}
/**
* Get Current pending registrations.
*
* @param \collection[] $collections
* @return Registration[]
*/
public function getPendingRegistrations(array $collections)
{
$builder = $this->createQueryBuilder('r');
$builder->where('r.pending = 1');
if (!empty($collections)) {
$builder->andWhere('r.baseId IN (:bases)');
$builder->setParameter('bases', array_map(function (\collection $collection) {
return $collection->get_base_id();
}, $collections));
}
$builder->orderBy('r.created', 'DESC');
return $builder->getQuery()->getResult();
}
/**
* Gets registration registrations for a user.
*