Skip to content

Commit

Permalink
Merge pull request #704 from jan-stanek/omezujici-podminky-rozvrhu
Browse files Browse the repository at this point in the history
kontrola vyuziti lektoru pri sestavovani rozvrhu
  • Loading branch information
jan-stanek authored Feb 22, 2020
2 parents a2bcd7f + 999b1b1 commit 494da00
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/ApiModule/Services/ScheduleService.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,20 @@ public function saveProgram(ProgramSaveDto $programSaveDto) : ResponseDto
$start = $programSaveDto->getStart();
$end = $start->add(new DateInterval('PT' . $block->getDuration() . 'M'));

$overlappingLecturersProgram = false;
foreach ($block->getLectors() as $lector) {
if ($this->userRepository->hasOverlappingLecturersProgram($lector, $programId, $start, $end)) {
$overlappingLecturersProgram = true;
break;
}
}

if (! $this->user->isAllowed(SrsResource::PROGRAM, Permission::MANAGE_SCHEDULE)) {
$responseDto->setMessage($this->translator->translate('common.api.schedule_user_not_allowed_manage'));
} elseif (! $this->settingsService->getBoolValue(Settings::IS_ALLOWED_MODIFY_SCHEDULE)) {
$responseDto->setMessage($this->translator->translate('common.api.schedule_not_allowed_modfify'));
} elseif ($overlappingLecturersProgram) {
$responseDto->setMessage($this->translator->translate('common.api.schedule_lector_has_another_program'));
} elseif ($room && $this->roomRepository->hasOverlappingProgram($room, $programId, $start, $end)) {
$responseDto->setMessage($this->translator->translate('common.api.schedule_room_occupied', null, ['name' => $room->getName()]));
} elseif ($block->getMandatory() === ProgramMandatoryType::AUTO_REGISTERED && $this->programRepository->hasOverlappingProgram($programId, $start, $end)) {
Expand Down
24 changes: 24 additions & 0 deletions app/Model/User/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Model\Acl\Role;
use App\Model\Enums\ApplicationState;
use App\Model\Program\Block;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
Expand Down Expand Up @@ -278,6 +279,29 @@ public function getLectorsOptions() : array
return $options;
}

/**
* Má lektor jiný program ve stejný čas?
*/
public function hasOverlappingLecturersProgram(User $lector, ?int $programId, DateTimeImmutable $start, DateTimeImmutable $end) : bool
{
$qb = $this->createQueryBuilder('u')
->select('u.id')
->join('u.lecturersBlocks', 'b')
->join('b.programs', 'p')
->where($this->createQueryBuilder('u')->expr()->orX(
"(p.start < :end) AND (DATE_ADD(p.start, (b.duration * 60), 'second') > :start)",
"(p.start < :end) AND (:start < (DATE_ADD(p.start, (b.duration * 60), 'second')))"
))
->andWhere('u.id = :uid')
->andWhere('(p.id != :pid) or (:pid IS NULL)')
->setParameter('start', $start)
->setParameter('end', $end)
->setParameter('uid', $lector->getId())
->setParameter('pid', $programId);

return ! empty($qb->getQuery()->getResult());
}

/**
* Uloží uživatele.
*
Expand Down
1 change: 1 addition & 0 deletions app/lang/common.cs_CZ.neon
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ api:
program_registered: "Program byl úspěšně přihlášen."
schedule_program_not_registered: "Na tento program jste nebyli přihlášeni."
program_unregistered: "Program byl úspěšně odhlášen."
schedule_lector_has_another_program: "Lektor má v tuto dobu již jiný program."
schedule_room_occupied: "Místnost \"%name%\" je v tuto dobu již obsazena."
schedule_auto_registered_not_allowed: "Automaticky přihlašovaný program nesmí být ve stejnou dobu jako jiný program."

Expand Down

0 comments on commit 494da00

Please sign in to comment.