|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Presenters; |
|
4
|
|
|
|
|
5
|
|
|
use App\Components\Forms\AnnotationForm; |
|
6
|
|
|
use App\Components\Forms\Factories\IAnnotationFormFactory; |
|
7
|
|
|
use App\Models\MeetingModel; |
|
8
|
|
|
use App\Services\AnnotationService; |
|
9
|
|
|
use \Exception; |
|
10
|
|
|
|
|
11
|
|
|
class AnnotationPresenter extends BasePresenter |
|
12
|
|
|
{ |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var IAnnotationFormFactory |
|
16
|
|
|
*/ |
|
17
|
|
|
private $annotationFormFactory; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var AnnotationService |
|
21
|
|
|
*/ |
|
22
|
|
|
private $annotationService; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var MeetingModel |
|
26
|
|
|
*/ |
|
27
|
|
|
private $meetingModel; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param AnnotationService $service |
|
31
|
|
|
* @param MeetingModel $model |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct(AnnotationService $service, MeetingModel $model) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->setAnnotationService($service); |
|
36
|
|
|
$this->setMeetingModel($model); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param IAnnotationFormFactory $factory |
|
41
|
|
|
*/ |
|
42
|
|
|
public function injectAnnotationFormFactory(IAnnotationFormFactory $factory) |
|
43
|
|
|
{ |
|
44
|
|
|
$this->annotationFormFactory = $factory; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param string $id |
|
|
|
|
|
|
49
|
|
|
* @param string $type |
|
50
|
|
|
*/ |
|
51
|
|
|
public function renderEdit(string $guid, string $type) |
|
52
|
|
|
{ |
|
53
|
|
|
$template = $this->getTemplate(); |
|
54
|
|
|
|
|
55
|
|
|
$annotation = $this->getAnnotationService()->findByType($guid, $type); |
|
56
|
|
|
|
|
57
|
|
|
$template->guid = $guid; |
|
|
|
|
|
|
58
|
|
|
$template->annotation = $annotation; |
|
|
|
|
|
|
59
|
|
|
$template->meeting = $this->getMeetingModel()->find($this->getMeetingId()); |
|
|
|
|
|
|
60
|
|
|
$template->program = $this->getAnnotationService()->findParentProgram($annotation); |
|
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
$this['annotationForm']->setDefaults($annotation->toArray()); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @return AnnotationFormControl |
|
67
|
|
|
*/ |
|
68
|
|
|
protected function createComponentAnnotationForm(): AnnotationForm |
|
69
|
|
|
{ |
|
70
|
|
|
$control = $this->annotationFormFactory->create(); |
|
71
|
|
|
$control->setMeetingId($this->getMeetingId()); |
|
72
|
|
|
$type = $this->getParameter('type'); |
|
73
|
|
|
$control->onAnnotationSave[] = function(AnnotationForm $control, $annotation) use ($type) { |
|
74
|
|
|
try { |
|
75
|
|
|
$result = $this->getAnnotationService()->updateByType($type, $annotation); |
|
76
|
|
|
|
|
77
|
|
|
$this->logInfo('Modification of annotation id %s with data %s successfull, result: %s', [ |
|
78
|
|
|
$annotation->guid, |
|
79
|
|
|
json_encode($annotation), |
|
80
|
|
|
json_encode($result), |
|
81
|
|
|
]); |
|
82
|
|
|
|
|
83
|
|
|
$this->flashSuccess('Položka byla úspěšně upravena'); |
|
84
|
|
|
} catch(Exception $e) { |
|
85
|
|
|
$this->logError("Modification of annotation id {$annotation->guid} failed, result: {$e->getMessage()}"); |
|
86
|
|
|
|
|
87
|
|
|
$this->flashError("Modification of annotation id {$annotation->guid} failed, result: {$e->getMessage()}"); |
|
88
|
|
|
} |
|
89
|
|
|
}; |
|
90
|
|
|
|
|
91
|
|
|
return $control; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return AnnotationService |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getAnnotationService(): AnnotationService |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->annotationService; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @param AnnotationService $annotationService |
|
104
|
|
|
* |
|
105
|
|
|
* @return self |
|
106
|
|
|
*/ |
|
107
|
|
|
public function setAnnotationService(AnnotationService $annotationService): self |
|
108
|
|
|
{ |
|
109
|
|
|
$this->annotationService = $annotationService; |
|
110
|
|
|
|
|
111
|
|
|
return $this; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @return MeetingModel |
|
116
|
|
|
*/ |
|
117
|
|
|
public function getMeetingModel(): MeetingModel |
|
118
|
|
|
{ |
|
119
|
|
|
return $this->meetingModel; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @param MeetingModel $meetingModel |
|
124
|
|
|
* |
|
125
|
|
|
* @return self |
|
126
|
|
|
*/ |
|
127
|
|
|
public function setMeetingModel(MeetingModel $meetingModel): self |
|
128
|
|
|
{ |
|
129
|
|
|
$this->meetingModel = $meetingModel; |
|
130
|
|
|
|
|
131
|
|
|
return $this; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
} |
|
135
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.