Skip to content

Commit

Permalink
přidání hlášky + automatické propojení, pokud je jen jedna podakce a …
Browse files Browse the repository at this point in the history
…jeden kurz
  • Loading branch information
jan-stanek committed May 1, 2018
1 parent 43e57fe commit edaeb84
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
21 changes: 19 additions & 2 deletions app/AdminModule/ConfigurationModule/forms/SkautIsEventForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
use App\Model\Settings\SettingsRepository;
use App\Model\SkautIs\SkautIsCourse;
use App\Model\SkautIs\SkautIsCourseRepository;
use App\Model\Structure\SubeventRepository;
use App\Services\SkautIsEventEducationService;
use App\Services\SkautIsEventGeneralService;
use Doctrine\Common\Collections\ArrayCollection;
use Nette;
use Nette\Application\UI\Form;

Expand Down Expand Up @@ -40,6 +42,9 @@ class SkautIsEventForm
/** @var SkautIsEventEducationService */
private $skautIsEventEducationService;

/** @var SubeventRepository */
private $subeventRepository;


/**
* SkautIsEventForm constructor.
Expand All @@ -48,17 +53,20 @@ class SkautIsEventForm
* @param SkautIsCourseRepository $skautIsCourseRepository
* @param SkautIsEventGeneralService $skautIsEventGeneralService
* @param SkautIsEventEducationService $skautIsEventEducationService
* @param SubeventRepository $subeventRepository
*/
public function __construct(BaseForm $baseForm, SettingsRepository $settingsRepository,
SkautIsCourseRepository $skautIsCourseRepository,
SkautIsEventGeneralService $skautIsEventGeneralService,
SkautIsEventEducationService $skautIsEventEducationService)
SkautIsEventEducationService $skautIsEventEducationService,
SubeventRepository $subeventRepository)
{
$this->baseFormFactory = $baseForm;
$this->settingsRepository = $settingsRepository;
$this->skautIsCourseRepository = $skautIsCourseRepository;
$this->skautIsEventGeneralService = $skautIsEventGeneralService;
$this->skautIsEventEducationService = $skautIsEventEducationService;
$this->subeventRepository = $subeventRepository;
}

/**
Expand Down Expand Up @@ -105,6 +113,7 @@ public function create(): Form
* @param Form $form
* @param \stdClass $values
* @throws \App\Model\Settings\SettingsException
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function processForm(Form $form, \stdClass $values): void
{
Expand All @@ -122,14 +131,22 @@ public function processForm(Form $form, \stdClass $values): void
$eventId = $values['skautisEventEducation'];
$eventName = $this->skautIsEventEducationService->getEventDisplayName($eventId);

foreach ($this->skautIsEventEducationService->getEventCourses($eventId) as $course) {
$courses = $this->skautIsEventEducationService->getEventCourses($eventId);

foreach ($courses as $course) {
$skautIsCourse = new SkautIsCourse();
$skautIsCourse->setSkautIsCourseId($course->ID);
$skautIsCourseName = $course->EventEducationType . (!empty($course->DisplayName) ? ' (' . $course->DisplayName . ')' : '');
$skautIsCourse->setName($skautIsCourseName);
$this->skautIsCourseRepository->save($skautIsCourse);
}

if (count($courses) == 1 && !$this->subeventRepository->explicitSubeventsExists()) {
$subevent = $this->subeventRepository->findImplicit();
$subevent->setSkautIsCourses(new ArrayCollection($this->skautIsCourseRepository->findAll()));
$this->subeventRepository->save($subevent);
}

break;
}

Expand Down
4 changes: 4 additions & 0 deletions app/AdminModule/components/UsersGridControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,10 @@ public function groupInsertIntoSkautIs(array $ids, $value)

case SkautIsEventType::EDUCATION:
$skautIsEventService = $this->skautIsEventEducationService;
if (!$skautIsEventService->isSubeventConnected()) {
$p->flashMessage('admin.users.users_group_action_insert_into_skaut_is_error_subevent_not_connected', 'danger');
$this->redirect('this');
}
break;

default:
Expand Down
1 change: 1 addition & 0 deletions app/lang/admin.cs_CZ.neon
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ users:
users_group_action_change_roles_error_capacity: "Role nebyly nastaveny, byla by překročena kapacita některé role."
users_group_action_insert_into_skaut_is: "Vložit účastníky do skautIS"
users_group_action_insert_into_skaut_is_error_not_connected: "Účastníci nebyli vloženi do skautIS, systém není propojen se žádnou akcí."
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."
users_group_action_insert_into_skaut_is_error_not_draft: "Účastníci nebyli vloženi do skautIS, akce byla uzavřena."
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."
users_group_action_insert_into_skaut_is_error_not_draft_successful: "Účastníci byli úspěšně vloženi do skautIS."
Expand Down
22 changes: 21 additions & 1 deletion app/services/SkautIsEventEducationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Services;
use App\Model\SkautIs\SkautIsCourseRepository;
use App\Model\Structure\SubeventRepository;
use App\Model\User\User;
use Doctrine\Common\Collections\Collection;
use Skautis\Skautis;
Expand All @@ -18,17 +19,23 @@ class SkautIsEventEducationService extends SkautIsEventService
/** @var SkautIsCourseRepository */
private $skautIsCourseRepository;

/** @var SubeventRepository */
private $subeventRepository;


/**
* SkautIsEventEducationService constructor.
* @param Skautis $skautIs
* @param SkautIsCourseRepository $skautIsCourseRepository
* @param SubeventRepository $subeventRepository
*/
public function __construct(Skautis $skautIs, SkautIsCourseRepository $skautIsCourseRepository)
public function __construct(Skautis $skautIs, SkautIsCourseRepository $skautIsCourseRepository,
SubeventRepository $subeventRepository)
{
parent::__construct($skautIs);

$this->skautIsCourseRepository = $skautIsCourseRepository;
$this->subeventRepository = $subeventRepository;
}

/**
Expand Down Expand Up @@ -117,6 +124,19 @@ public function getEventCourses(int $eventId)
]);
}

/**
* Je nastaveno propojení alespoň jedné podakce se skautIS kurzem?
* @return bool
*/
public function isSubeventConnected()
{
foreach ($this->subeventRepository->findAll() as $subevent) {
if (!$subevent->getSkautIsCourses()->isEmpty())
return TRUE;
}
return FALSE;
}

/**
* Vrací přihlášené účastníky kurzu.
* @param $eventId
Expand Down

0 comments on commit edaeb84

Please sign in to comment.