1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Copyright 2016 Arnaud Bienvenu |
4
|
|
|
* |
5
|
|
|
* This file is part of Kyela. |
6
|
|
|
|
7
|
|
|
* Kyela is free software: you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU Affero General Public License as published by |
9
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
|
12
|
|
|
* Kyela is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU Affero General Public License for more details. |
16
|
|
|
|
17
|
|
|
* You should have received a copy of the GNU Affero General Public License |
18
|
|
|
* along with Kyela. If not, see <http://www.gnu.org/licenses/>. |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace Abienvenu\KyelaBundle\Controller; |
23
|
|
|
|
24
|
|
|
use Abienvenu\KyelaBundle\Entity\Poll; |
25
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
26
|
|
|
use Symfony\Component\HttpFoundation\Request; |
27
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
28
|
|
|
|
29
|
|
|
abstract class PollSetterController extends Controller |
30
|
|
|
{ |
31
|
|
|
/** @var Poll $poll */ |
32
|
|
|
protected $poll; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Set poll from Url or session |
36
|
|
|
*/ |
37
|
|
|
public function setPollFromRequest(Request $request) |
38
|
|
|
{ |
39
|
|
|
$em = $this->getDoctrine()->getManager(); |
40
|
|
|
$pollUrl = $request->get('pollUrl'); |
41
|
|
|
if ($pollUrl) { |
42
|
|
|
$request->getSession()->set('pollUrl', $pollUrl); |
43
|
|
|
} |
44
|
|
|
else { |
45
|
|
|
$pollUrl = $request->getSession()->get('pollUrl'); |
46
|
|
|
} |
47
|
|
|
if ($pollUrl) { |
48
|
|
|
$repository = $em->getRepository('KyelaBundle:Poll'); |
49
|
|
|
$this->poll = $repository->findOneByUrl($pollUrl); |
|
|
|
|
50
|
|
|
if (!$this->poll) |
51
|
|
|
{ |
52
|
|
|
$this->unsetPoll($request); |
53
|
|
|
throw new NotFoundHttpException('Poll object not found.'); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
protected function unsetPoll(Request $request) |
59
|
|
|
{ |
60
|
|
|
$this->poll = null; |
61
|
|
|
$request->getSession()->remove('pollUrl'); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.