1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Service; |
4
|
|
|
|
5
|
|
|
use App\Entity\Submission; |
6
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
7
|
|
|
use Ds\Component\Api\Api\Api; |
|
|
|
|
8
|
|
|
use Ds\Component\Entity\Service\EntityService; |
|
|
|
|
9
|
|
|
use Ds\Component\Form\Model\Form; |
|
|
|
|
10
|
|
|
use Ds\Component\Formio\Exception\ValidationException; |
|
|
|
|
11
|
|
|
use Ds\Component\Formio\Model\Submission as Model; |
|
|
|
|
12
|
|
|
use Ds\Component\Formio\Query\SubmissionParameters as Parameters; |
|
|
|
|
13
|
|
|
use Symfony\Component\Validator\ConstraintViolation; |
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class SubmissionService |
17
|
|
|
*/ |
18
|
|
|
final class SubmissionService extends EntityService |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var \App\Service\ScenarioService |
22
|
|
|
*/ |
23
|
|
|
private $scenarioService; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var \Ds\Component\Api\Api\Api |
27
|
|
|
*/ |
28
|
|
|
private $api; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Constructor |
32
|
|
|
* |
33
|
|
|
* @param \Doctrine\ORM\EntityManagerInterface $manager |
34
|
|
|
* @param \App\Service\ScenarioService $scenarioService |
35
|
|
|
* @param \Ds\Component\Api\Api\Api $api |
36
|
|
|
* @param string $entity |
37
|
|
|
*/ |
38
|
|
|
public function __construct(EntityManagerInterface $manager, ScenarioService $scenarioService, Api $api, string $entity = Submission::class) |
39
|
|
|
{ |
40
|
|
|
parent::__construct($manager, $entity); |
41
|
|
|
$this->scenarioService = $scenarioService; |
42
|
|
|
$this->api = $api; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Check if a submission is valid |
47
|
|
|
* |
48
|
|
|
* @param \App\Entity\Submission $submission |
49
|
|
|
* @param array $violations |
50
|
|
|
* @param boolean $overwrite |
51
|
|
|
* @return boolean |
52
|
|
|
*/ |
53
|
|
|
public function isValid(Submission $submission, array &$violations = [], $overwrite = true) |
54
|
|
|
{ |
55
|
|
|
$scenario = $submission->getScenario(); |
56
|
|
|
$form = $this->scenarioService->getForm($scenario); |
57
|
|
|
|
58
|
|
|
switch ($form->getType()) { |
59
|
|
|
case Form::TYPE_FORMIO: |
60
|
|
|
$model = new Model; |
61
|
|
|
$model |
62
|
|
|
->setForm($form->getId()) |
63
|
|
|
->setData((object) $submission->getData()); |
64
|
|
|
$parameters = new Parameters; |
65
|
|
|
|
66
|
|
|
try { |
67
|
|
|
$model = $this->api->get('formio.submission')->create($model, $parameters); |
68
|
|
|
|
69
|
|
|
if ($overwrite) { |
70
|
|
|
$submission->setData((array) $model->getData()); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return true; |
74
|
|
|
} catch (ValidationException $exception) { |
75
|
|
|
foreach ($exception->getErrors() as $error) { |
76
|
|
|
$message = $error->message; |
77
|
|
|
$path = 'data.'.array_shift($error->path); |
78
|
|
|
$template = '%s: %s'; |
79
|
|
|
$parameters = [$path, $message]; |
80
|
|
|
$root = ''; |
81
|
|
|
$value = null; |
82
|
|
|
$violations[] = new ConstraintViolation($message, $template, $parameters, $root, $path, $value); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
return false; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
break; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return true; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths