Skip to content

Commit d81308f

Browse files
author
Jan Staněk
authored
Merge pull request #527 from jan-stanek/vzdelavaci-akce-opravy
Vzdelavaci akce opravy
2 parents bf854d5 + edaeb84 commit d81308f

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed

app/AdminModule/ConfigurationModule/forms/SkautIsEventForm.php

+21-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
use App\Model\Settings\SettingsRepository;
1010
use App\Model\SkautIs\SkautIsCourse;
1111
use App\Model\SkautIs\SkautIsCourseRepository;
12+
use App\Model\Structure\SubeventRepository;
1213
use App\Services\SkautIsEventEducationService;
1314
use App\Services\SkautIsEventGeneralService;
15+
use Doctrine\Common\Collections\ArrayCollection;
1416
use Nette;
1517
use Nette\Application\UI\Form;
1618

@@ -40,6 +42,9 @@ class SkautIsEventForm
4042
/** @var SkautIsEventEducationService */
4143
private $skautIsEventEducationService;
4244

45+
/** @var SubeventRepository */
46+
private $subeventRepository;
47+
4348

4449
/**
4550
* SkautIsEventForm constructor.
@@ -48,17 +53,20 @@ class SkautIsEventForm
4853
* @param SkautIsCourseRepository $skautIsCourseRepository
4954
* @param SkautIsEventGeneralService $skautIsEventGeneralService
5055
* @param SkautIsEventEducationService $skautIsEventEducationService
56+
* @param SubeventRepository $subeventRepository
5157
*/
5258
public function __construct(BaseForm $baseForm, SettingsRepository $settingsRepository,
5359
SkautIsCourseRepository $skautIsCourseRepository,
5460
SkautIsEventGeneralService $skautIsEventGeneralService,
55-
SkautIsEventEducationService $skautIsEventEducationService)
61+
SkautIsEventEducationService $skautIsEventEducationService,
62+
SubeventRepository $subeventRepository)
5663
{
5764
$this->baseFormFactory = $baseForm;
5865
$this->settingsRepository = $settingsRepository;
5966
$this->skautIsCourseRepository = $skautIsCourseRepository;
6067
$this->skautIsEventGeneralService = $skautIsEventGeneralService;
6168
$this->skautIsEventEducationService = $skautIsEventEducationService;
69+
$this->subeventRepository = $subeventRepository;
6270
}
6371

6472
/**
@@ -105,6 +113,7 @@ public function create(): Form
105113
* @param Form $form
106114
* @param \stdClass $values
107115
* @throws \App\Model\Settings\SettingsException
116+
* @throws \Doctrine\ORM\NonUniqueResultException
108117
*/
109118
public function processForm(Form $form, \stdClass $values): void
110119
{
@@ -122,13 +131,22 @@ public function processForm(Form $form, \stdClass $values): void
122131
$eventId = $values['skautisEventEducation'];
123132
$eventName = $this->skautIsEventEducationService->getEventDisplayName($eventId);
124133

125-
foreach ($this->skautIsEventEducationService->getEventCourses($eventId) as $course) {
134+
$courses = $this->skautIsEventEducationService->getEventCourses($eventId);
135+
136+
foreach ($courses as $course) {
126137
$skautIsCourse = new SkautIsCourse();
127138
$skautIsCourse->setSkautIsCourseId($course->ID);
128-
$skautIsCourse->setName($course->DisplayName);
139+
$skautIsCourseName = $course->EventEducationType . (!empty($course->DisplayName) ? ' (' . $course->DisplayName . ')' : '');
140+
$skautIsCourse->setName($skautIsCourseName);
129141
$this->skautIsCourseRepository->save($skautIsCourse);
130142
}
131143

144+
if (count($courses) == 1 && !$this->subeventRepository->explicitSubeventsExists()) {
145+
$subevent = $this->subeventRepository->findImplicit();
146+
$subevent->setSkautIsCourses(new ArrayCollection($this->skautIsCourseRepository->findAll()));
147+
$this->subeventRepository->save($subevent);
148+
}
149+
132150
break;
133151
}
134152

app/AdminModule/components/UsersGridControl.php

+4
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,10 @@ public function groupInsertIntoSkautIs(array $ids, $value)
619619

620620
case SkautIsEventType::EDUCATION:
621621
$skautIsEventService = $this->skautIsEventEducationService;
622+
if (!$skautIsEventService->isSubeventConnected()) {
623+
$p->flashMessage('admin.users.users_group_action_insert_into_skaut_is_error_subevent_not_connected', 'danger');
624+
$this->redirect('this');
625+
}
622626
break;
623627

624628
default:

app/lang/admin.cs_CZ.neon

+1
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ users:
341341
users_group_action_change_roles_error_capacity: "Role nebyly nastaveny, byla by překročena kapacita některé role."
342342
users_group_action_insert_into_skaut_is: "Vložit účastníky do skautIS"
343343
users_group_action_insert_into_skaut_is_error_not_connected: "Účastníci nebyli vloženi do skautIS, systém není propojen se žádnou akcí."
344+
users_group_action_insert_into_skaut_is_error_subevent_not_connected: "Účastníci nebyli vloženi do skautIS, žádná podakce není propojena s žádným kurzem."
344345
users_group_action_insert_into_skaut_is_error_not_draft: "Účastníci nebyli vloženi do skautIS, akce byla uzavřena."
345346
users_group_action_insert_into_skaut_is_error_skaut_is: "Účastníci nebyli vloženi do skautIS, zkontrolujte, že pracujete v roli s právem přidávat účastníky akce."
346347
users_group_action_insert_into_skaut_is_error_not_draft_successful: "Účastníci byli úspěšně vloženi do skautIS."

app/services/SkautIsEventEducationService.php

+21-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Services;
44
use App\Model\SkautIs\SkautIsCourseRepository;
5+
use App\Model\Structure\SubeventRepository;
56
use App\Model\User\User;
67
use Doctrine\Common\Collections\Collection;
78
use Skautis\Skautis;
@@ -18,17 +19,23 @@ class SkautIsEventEducationService extends SkautIsEventService
1819
/** @var SkautIsCourseRepository */
1920
private $skautIsCourseRepository;
2021

22+
/** @var SubeventRepository */
23+
private $subeventRepository;
24+
2125

2226
/**
2327
* SkautIsEventEducationService constructor.
2428
* @param Skautis $skautIs
2529
* @param SkautIsCourseRepository $skautIsCourseRepository
30+
* @param SubeventRepository $subeventRepository
2631
*/
27-
public function __construct(Skautis $skautIs, SkautIsCourseRepository $skautIsCourseRepository)
32+
public function __construct(Skautis $skautIs, SkautIsCourseRepository $skautIsCourseRepository,
33+
SubeventRepository $subeventRepository)
2834
{
2935
parent::__construct($skautIs);
3036

3137
$this->skautIsCourseRepository = $skautIsCourseRepository;
38+
$this->subeventRepository = $subeventRepository;
3239
}
3340

3441
/**
@@ -117,6 +124,19 @@ public function getEventCourses(int $eventId)
117124
]);
118125
}
119126

127+
/**
128+
* Je nastaveno propojení alespoň jedné podakce se skautIS kurzem?
129+
* @return bool
130+
*/
131+
public function isSubeventConnected()
132+
{
133+
foreach ($this->subeventRepository->findAll() as $subevent) {
134+
if (!$subevent->getSkautIsCourses()->isEmpty())
135+
return TRUE;
136+
}
137+
return FALSE;
138+
}
139+
120140
/**
121141
* Vrací přihlášené účastníky kurzu.
122142
* @param $eventId

0 commit comments

Comments
 (0)