|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TechWilk\Rota\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use DateTime; |
|
6
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
7
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
8
|
|
|
use TechWilk\Rota\EventQuery; |
|
9
|
|
|
use TechWilk\Rota\Group; |
|
10
|
|
|
use TechWilk\Rota\GroupQuery; |
|
11
|
|
|
|
|
12
|
|
|
class GroupController extends BaseController |
|
13
|
|
|
{ |
|
14
|
|
|
public function getGroup(ServerRequestInterface $request, ResponseInterface $response, $args) |
|
|
|
|
|
|
15
|
|
|
{ |
|
16
|
|
|
$this->logger->info("Fetch group GET '/group/".$args['id']."'"); |
|
17
|
|
|
$events = EventQuery::create() |
|
18
|
|
|
->useEventPersonQuery() |
|
19
|
|
|
->useUserRoleQuery() |
|
20
|
|
|
->useRoleQuery() |
|
21
|
|
|
->filterByGroupId($args['id']) |
|
22
|
|
|
->endUse() |
|
23
|
|
|
->endUse() |
|
24
|
|
|
->endUse() |
|
25
|
|
|
->filterByDate(['min' => new DateTime()]) |
|
26
|
|
|
->filterByRemoved(false) |
|
27
|
|
|
->orderByDate('asc') |
|
28
|
|
|
->distinct() |
|
29
|
|
|
->find(); |
|
30
|
|
|
|
|
31
|
|
|
$group = GroupQuery::create() |
|
32
|
|
|
->findPk($args['id']); |
|
33
|
|
|
|
|
34
|
|
|
return $this->view->render($response, 'group.twig', ['events' => $events, 'group' => $group]); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function getGroupRoles(ServerRequestInterface $request, ResponseInterface $response, $args) |
|
|
|
|
|
|
38
|
|
|
{ |
|
39
|
|
|
$this->logger->info("Fetch group roles GET '/group/".$args['id']."/roles'"); |
|
40
|
|
|
$events = EventQuery::create() |
|
|
|
|
|
|
41
|
|
|
->useEventPersonQuery() |
|
42
|
|
|
->useUserRoleQuery() |
|
43
|
|
|
->useRoleQuery() |
|
44
|
|
|
->filterByGroupId($args['id']) |
|
45
|
|
|
->endUse() |
|
46
|
|
|
->endUse() |
|
47
|
|
|
->endUse() |
|
48
|
|
|
->filterByDate(['min' => new DateTime()]) |
|
49
|
|
|
->filterByRemoved(false) |
|
50
|
|
|
->orderByDate('asc') |
|
51
|
|
|
->distinct() |
|
52
|
|
|
->find(); |
|
53
|
|
|
|
|
54
|
|
|
$group = GroupQuery::create() |
|
|
|
|
|
|
55
|
|
|
->useRoleQuery() |
|
56
|
|
|
->endUse() |
|
57
|
|
|
->distinct() |
|
58
|
|
|
->findPk($args['id']); |
|
59
|
|
|
|
|
60
|
|
|
// temporary redirect |
|
61
|
|
|
return $response->withStatus(302)->withHeader('Location', $this->router->pathFor('home').'old/roles.php'); |
|
62
|
|
|
|
|
63
|
|
|
return $this->view->render($response, 'group-roles.twig', ['events' => $events, 'group' => $group]); |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function postGroup(ServerRequestInterface $request, ResponseInterface $response, $args) |
|
67
|
|
|
{ |
|
68
|
|
|
$this->logger->info("Create/edit group POST '/group/".$args['id']."'"); |
|
69
|
|
|
|
|
70
|
|
|
$group = new Group(); |
|
71
|
|
|
|
|
72
|
|
|
if (!empty($args['id'])) { |
|
73
|
|
|
$group = GroupQuery::create()->findPk($args['id']); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
$data = $request->getParsedBody(); |
|
77
|
|
|
|
|
78
|
|
|
$group->setName($data['name']); |
|
79
|
|
|
$group->setDescription($data['description']); |
|
80
|
|
|
$group->save(); |
|
81
|
|
|
|
|
82
|
|
|
return $response->withStatus(302)->withHeader('Location', $this->router->pathFor('group', ['id' => $group->getId()])); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.