/
Collection.php
85 lines (80 loc) · 2.92 KB
/
Collection.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
namespace App\Controller\Web\Donations;
use App\Entity\User as UserEntity;
use App\Form\Donations\Donations as Form;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use App\Controller\Web\Base as WebBase;
use App\Utils\Rxx;
use Symfony\Component\Routing\Annotation\Route; // Required for annotations
/**
* Class Donations
* @package App\Controller\Web\Donations
*/
class Collection extends WebBase
{
const defaultlimit = 100;
const defaultSorting = 'id';
const defaultOrder = 'd';
/**
* @Route(
* "/{_locale}/{system}/donations",
* requirements={
* "_locale": "de|en|es|fr",
* "system": "reu|rna|rww"
* },
* name="donations"
* )
* @param $_locale
* @param $system
* @param Request $request
* @param Form $form
* @return RedirectResponse|Response
*/
public function index(
$_locale,
$system,
Request $request,
Form $form
) {
if (!((int)$this->parameters['access'] & UserEntity::MASTER)) {
if ((int)$this->parameters['access'] === 0) {
$this->session->set('route', 'donations');
return $this->redirectToRoute('logon', ['system' => $system]);
}
throw $this->createAccessDeniedException('You do not have access to this page');
}
$this->session->set('route', '');
$this->session->set('lastMessage', '');
$this->session->set('lastError', '');
$args = [
'limit' => static::defaultlimit,
'order' => static::defaultOrder,
'page' => 0,
'sort' => static::defaultSorting,
'total' => $this->donationRepository->getCount()
];
$form = $form->buildForm($this->createFormBuilder(), $args);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$args = $form->getData() + $args;
}
$parameters = [
'args' => $args,
'columns' => $this->donationRepository->getColumns(),
'form' => $form->createView(),
'_locale' => $_locale,
'matched' => sprintf($this->i18n('of %s Donations'), $args['total']),
'mode' => $this->i18n('Donations'),
'records' => $this->donationRepository->getRecords($args),
'results' => [
'limit' => $args['limit'],
'page' => $args['page'],
'total' => $args['total']
],
'system' => $system
];
return $this->render('donations/index.html.twig', $this->getMergedParameters($parameters));
}
}