11
11
use App \Model \Program \ProgramRepository ;
12
12
use App \Model \Settings \Settings ;
13
13
use App \Model \Settings \SettingsRepository ;
14
+ use App \Model \Structure \SubeventRepository ;
14
15
use App \Model \User \User ;
15
16
use App \Model \User \UserRepository ;
16
17
use Nette ;
@@ -37,6 +38,12 @@ class BlockForm extends Nette\Object
37
38
*/
38
39
private $ block ;
39
40
41
+ /**
42
+ * Počet vytvořených podakcí.
43
+ * @var int
44
+ */
45
+ private $ subeventsCount ;
46
+
40
47
/** @var BaseForm */
41
48
private $ baseFormFactory ;
42
49
@@ -55,6 +62,9 @@ class BlockForm extends Nette\Object
55
62
/** @var ProgramRepository */
56
63
private $ programRepository ;
57
64
65
+ /** @var SubeventRepository */
66
+ private $ subeventRepository ;
67
+
58
68
59
69
/**
60
70
* BlockForm constructor.
@@ -67,14 +77,16 @@ class BlockForm extends Nette\Object
67
77
*/
68
78
public function __construct (BaseForm $ baseFormFactory , BlockRepository $ blockRepository ,
69
79
UserRepository $ userRepository , CategoryRepository $ categoryRepository ,
70
- SettingsRepository $ settingsRepository , ProgramRepository $ programRepository )
80
+ SettingsRepository $ settingsRepository , ProgramRepository $ programRepository ,
81
+ SubeventRepository $ subeventRepository )
71
82
{
72
83
$ this ->baseFormFactory = $ baseFormFactory ;
73
84
$ this ->blockRepository = $ blockRepository ;
74
85
$ this ->userRepository = $ userRepository ;
75
86
$ this ->categoryRepository = $ categoryRepository ;
76
87
$ this ->settingsRepository = $ settingsRepository ;
77
88
$ this ->programRepository = $ programRepository ;
89
+ $ this ->subeventRepository = $ subeventRepository ;
78
90
}
79
91
80
92
/**
@@ -88,13 +100,21 @@ public function create($id, $userId)
88
100
$ this ->block = $ this ->blockRepository ->findById ($ id );
89
101
$ this ->user = $ this ->userRepository ->findById ($ userId );
90
102
103
+ $ this ->subeventsCount = $ this ->subeventRepository ->countExplicitSubevents ();
104
+
91
105
$ form = $ this ->baseFormFactory ->create ();
92
106
93
107
$ form ->addHidden ('id ' );
94
108
95
109
$ form ->addText ('name ' , 'admin.program.blocks_name ' )
96
110
->addRule (Form::FILLED , 'admin.program.blocks_name_empty ' );
97
111
112
+ if ($ this ->subeventsCount > 0 ) {
113
+ $ form ->addSelect ('subevent ' , 'admin.program.blocks_subevent ' , $ this ->subeventRepository ->getSubeventsOptions ())
114
+ ->setPrompt ('' )
115
+ ->addRule (Form::FILLED , 'admin.program.blocks_subevent_empty ' );
116
+ }
117
+
98
118
$ form ->addSelect ('category ' , 'admin.program.blocks_category ' , $ this ->categoryRepository ->getCategoriesOptions ())
99
119
->setPrompt ('' );
100
120
@@ -162,6 +182,12 @@ public function create($id, $userId)
162
182
'description ' => $ this ->block ->getDescription (),
163
183
'tools ' => $ this ->block ->getTools ()
164
184
]);
185
+
186
+ if ($ this ->subeventsCount > 0 ) {
187
+ $ form ->setDefaults ([
188
+ 'subevent ' => $ this ->block ->getSubevent () ? $ this ->block ->getSubevent ()->getId () : NULL
189
+ ]);
190
+ }
165
191
} else {
166
192
$ form ['name ' ]->addRule (Form::IS_NOT_IN , 'admin.program.blocks_name_exists ' , $ this ->blockRepository ->findAllNames ());
167
193
}
@@ -189,6 +215,7 @@ public function processForm(Form $form, \stdClass $values)
189
215
190
216
$ oldMandatory = $ this ->block ->getMandatory ();
191
217
$ oldCategory = $ this ->block ->getCategory ();
218
+ $ oldSubevent = $ this ->block ->getSubevent ();
192
219
193
220
$ category = $ values ['category ' ] != '' ? $ this ->categoryRepository ->findById ($ values ['category ' ]) : NULL ;
194
221
$ lector = $ values ['lector ' ] != '' ? $ this ->userRepository ->findById ($ values ['lector ' ]) : NULL ;
@@ -204,6 +231,14 @@ public function processForm(Form $form, \stdClass $values)
204
231
$ this ->block ->setDescription ($ values ['description ' ]);
205
232
$ this ->block ->setTools ($ values ['tools ' ]);
206
233
234
+ if ($ this ->subeventsCount > 0 ) {
235
+ $ subevent = $ values ['subevent ' ] != '' ? $ this ->subeventRepository ->findById ($ values ['subevent ' ]) : NULL ;
236
+ $ this ->block ->setSubevent ($ subevent );
237
+ }
238
+ else {
239
+ $ this ->block ->setSubevent ($ this ->subeventRepository ->findImplicit ());
240
+ }
241
+
207
242
$ this ->blockRepository ->save ($ this ->block );
208
243
209
244
//odstraneni ucastniku, pokud se odstrani automaticke prihlasovani
@@ -220,8 +255,10 @@ public function processForm(Form $form, \stdClass $values)
220
255
}
221
256
}
222
257
223
- //aktualizace ucastniku pri zmene kategorie
224
- if ($ oldMandatory == $ this ->block ->getMandatory () && $ this ->block ->getCategory () != $ oldCategory ) {
258
+ //aktualizace ucastniku pri zmene kategorie nebo podakce
259
+ if ($ oldMandatory == $ this ->block ->getMandatory () && (
260
+ $ this ->block ->getCategory () !== $ oldCategory ) || ($ this ->block ->getSubevent () !== $ oldSubevent )
261
+ ) {
225
262
$ this ->programRepository ->updateUsersPrograms ($ this ->userRepository ->findAll ());
226
263
}
227
264
0 commit comments