3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Galette Slim middleware to navigate beetween members
10 * Copyright © 2020 The Galette Team
12 * This file is part of Galette (http://galette.tuxfamily.org).
14 * Galette is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * Galette is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2020 The Galette Team
32 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
33 * @link http://galette.tuxfamily.org
34 * @since Available since 0.9.4dev - 2020-05-06
37 namespace Galette\Middleware
;
39 use Psr\Http\Message\ServerRequestInterface
as Request
;
40 use Psr\Http\Message\ResponseInterface
as Response
;
41 use Galette\Entity\Adherent
;
42 use Galette\Filters\MembersList
;
43 use Galette\Repository\Members
;
46 * Galette Slim middleware to navigate beetween members
48 * @category Middleware
49 * @name MembersNavigate
51 * @author Johan Cwiklinski <johan@x-tnd.be>
52 * @copyright 2020 The Galette Team
53 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
54 * @link http://galette.tuxfamily.org
55 * @since Available since 0.9.4dev - 2020-05-06
60 * @var Galette\Core\Login
71 * @param Slim\Container $container Container instance
73 public function __construct(\Slim\Container
$container)
75 $this->login
= $container->get('login');
76 $this->session
= $container->get('session');
77 $this->view
= $container->get('view');
81 * Middleware invokable class
83 * @param \Psr\Http\Message\ServerRequestInterface $request PSR7 request
84 * @param \Psr\Http\Message\ResponseInterface $response PSR7 response
85 * @param callable $next Next middleware
87 * @return \Psr\Http\Message\ResponseInterface
89 public function __invoke(Request
$request, Response
$response, $next) :Response
92 $route = $request->getAttribute('route');
93 $args = $route->getArguments();
95 if (!isset($args['id'])) {
96 //not viewing an exiting member
97 return $next($request, $response);
100 if (isset($this->session
->filter_members
)) {
101 $filters = $this->session
->filter_members
;
103 $filters = new MembersList();
106 if ($this->login
->isAdmin()
107 ||
$this->login
->isStaff()
108 ||
$this->login
->isGroupManager()
110 $m = new Members($filters);
111 $ids = $m->getList(false, array(Adherent
::PK
, 'nom_adh', 'prenom_adh'));
112 $ids = $ids->toArray();
113 foreach ($ids as $k => $m) {
114 if ($m['id_adh'] == $args['id']) {
116 'cur' => $m['id_adh'],
117 'count' => count($ids),
121 $navigate['prev'] = $ids[$k - 1]['id_adh'];
123 if ($k < count($ids) - 1) {
124 $navigate['next'] = $ids[$k +
1]['id_adh'];
130 $this->view
->getSmarty()->assign('navigate', $navigate);
132 return $next($request, $response);