Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
23.81% |
5 / 21 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
ConformiteOrganisationExtension | |
23.81% |
5 / 21 |
|
50.00% |
2 / 4 |
36.31 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getFunctions | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
getConformitesWithProcessusAndQuestions | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 | |||
getQuestionsOrderedByPosition | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace App\Domain\Registry\Twig\Extension; |
4 | |
5 | use App\Domain\Registry\Model\ConformiteOrganisation\Conformite; |
6 | use App\Domain\Registry\Model\ConformiteOrganisation\Reponse; |
7 | use App\Domain\Registry\Repository\ConformiteOrganisation\Processus; |
8 | use Symfony\Component\Form\FormView; |
9 | use Twig\Extension\AbstractExtension; |
10 | use Twig\TwigFunction; |
11 | |
12 | class ConformiteOrganisationExtension extends AbstractExtension |
13 | { |
14 | /** |
15 | * @var Processus |
16 | */ |
17 | private $processusRepository; |
18 | |
19 | public function __construct(Processus $processusRepository) |
20 | { |
21 | $this->processusRepository = $processusRepository; |
22 | } |
23 | |
24 | /** |
25 | * @return array|TwigFunction[] |
26 | */ |
27 | public function getFunctions() |
28 | { |
29 | return [ |
30 | new TwigFunction('getConformitesWithProcessusAndQuestions', [$this, 'getConformitesWithProcessusAndQuestions']), |
31 | new TwigFunction('getQuestionsOrderedByPosition', [$this, 'getQuestionsOrderedByPosition']), |
32 | ]; |
33 | } |
34 | |
35 | public function getConformitesWithProcessusAndQuestions(FormView $formView) |
36 | { |
37 | $ordered = []; |
38 | foreach ($formView->children as $formViewReponse) { |
39 | $conformite = $formViewReponse->vars['value']; |
40 | if (!$conformite instanceof Conformite) { |
41 | continue; |
42 | } |
43 | |
44 | $ordered[$conformite->getProcessus()->getPosition()][] = $formViewReponse; |
45 | } |
46 | |
47 | \ksort($ordered); |
48 | |
49 | return $ordered; |
50 | } |
51 | |
52 | public function getQuestionsOrderedByPosition(FormView $formView) |
53 | { |
54 | $ordered = []; |
55 | foreach ($formView->children as $formViewReponse) { |
56 | $reponse = $formViewReponse->vars['value']; |
57 | if (!$reponse instanceof Reponse) { |
58 | continue; |
59 | } |
60 | |
61 | $ordered[$reponse->getQuestion()->getPosition()] = $formViewReponse; |
62 | } |
63 | |
64 | \ksort($ordered); |
65 | |
66 | return $ordered; |
67 | } |
68 | } |