-
Notifications
You must be signed in to change notification settings - Fork 177
/
Copy pathUserController.php
64 lines (53 loc) · 1.77 KB
/
UserController.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
<?php
declare(strict_types=1);
namespace Bolt\Controller\Backend;
use Bolt\Controller\TwigAwareController;
use Bolt\Repository\UserRepository;
use Bolt\Storage\Query;
use Pagerfanta\Adapter\ArrayAdapter;
use Pagerfanta\Pagerfanta;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* Display the list of users, along with buttons to change them.
*
* @Security("is_granted('user:list')")
*/
class UserController extends TwigAwareController implements BackendZoneInterface
{
/** @var UserRepository */
private $users;
private const PAGESIZE = 20;
public function __construct(UserRepository $users)
{
$this->users = $users;
}
/**
* @Route("/users", name="bolt_users")
*/
public function users(Query $query): Response
{
$order = 'username';
if ($this->request->get('sortBy')) {
$order = $this->getFromRequest('sortBy');
}
$like = '';
if ($this->request->get('filter')) {
$like = '%' . $this->getFromRequest('filter') . '%';
}
$users = new ArrayAdapter($this->users->findUsers($like, $order));
$currentPage = (int) $this->getFromRequest('page', '1');
$users = new Pagerfanta($users);
$users->setMaxPerPage(self::PAGESIZE)
->setCurrentPage($currentPage);
$twigVars = [
'title' => 'controller.user.title',
'subtitle' => 'controller.user.subtitle',
'users' => $users,
'sortBy' => $this->getFromRequest('sortBy'),
'filterValue' => $this->getFromRequest('filter'),
];
return $this->render('@bolt/users/listing.html.twig', $twigVars);
}
}