public function testRepeatedDrivingAssertionCRUD() { $driverCategory = $this->createDriverCategory('Zivildienst'); $address = Address::registerAddress('Burstrasse 22c', '6333', 'Baar', 'Schweiz'); $this->init->addressRepo->store($address); $driver = Driver::registerDriver('m', 'Max', 'Mühlemann', '041 222 32 32', $address, 'F3234141', $driverCategory, true, '', '*****@*****.**', new \DateTime(), new \DateTime(), 5, 'alles nur ein Test'); $this->init->driverRepo->store($driver); $shiftTypes[] = $this->createShiftType('Shift 1'); $shiftTypes[] = $this->createShiftType('Shift 2'); //weekly $repeatedDrivingAssertionWeekly = new RepeatedWeeklyDrivingAssertion(); $repeatedDrivingAssertionWeekly->setWeekday(1); $repeatedDrivingAssertionWeekly->setShiftTypes($shiftTypes); $this->init->repeatedDrivingAssertionRepo->store($repeatedDrivingAssertionWeekly); $repeatedDrivingAssertionPlan = RepeatedDrivingAssertionPlan::registerRepeatedAssertionPlan('test', new \DateTime(), 'weekly', true); $repeatedDrivingAssertionPlan->assignDriver($driver); $repeatedDrivingAssertionPlan->assignRepeatedDrivingAssertion($repeatedDrivingAssertionWeekly); $this->init->repeatedDrivingAssertionPlanRepo->store($repeatedDrivingAssertionPlan); $this->init->em->flush(); $find = $this->init->repeatedDrivingAssertionPlanRepo->find($repeatedDrivingAssertionPlan->getId()); $this->assertEquals($find, $repeatedDrivingAssertionPlan); //monthly $repeatedDrivingAssertionMonthly = new RepeatedMonthlyDrivingAssertion(); $repeatedDrivingAssertionMonthly->setRelativeWeekAsText('first'); $repeatedDrivingAssertionMonthly->setWeekdayAsText('monday'); $this->init->repeatedDrivingAssertionRepo->store($repeatedDrivingAssertionMonthly); $repeatedDrivingAssertionPlan = RepeatedDrivingAssertionPlan::registerRepeatedAssertionPlan('test', new \DateTime(), 'monthly', true); $repeatedDrivingAssertionPlan->assignDriver($driver); $repeatedDrivingAssertionPlan->assignRepeatedDrivingAssertion($repeatedDrivingAssertionMonthly); $this->init->repeatedDrivingAssertionPlanRepo->store($repeatedDrivingAssertionPlan); $this->init->em->flush(); $find = $this->init->repeatedDrivingAssertionPlanRepo->find($repeatedDrivingAssertionPlan->getId()); $this->assertEquals($find, $repeatedDrivingAssertionPlan); }
/** * @return mixed|void */ public function createFormRows() { /**@var $dto \Tixi\ApiBundle\Interfaces\DriverRegisterDTO */ $dto = $this->dto; $this->basicFormRows[] = new FormRowView('id', 'driver.field.id', $dto->person_id); $this->basicFormRows[] = new FormRowView('gender', 'person.field.gender', Person::constructGenderString($dto->gender)); $this->basicFormRows[] = new FormRowView('firstname', 'person.field.firstname', $dto->firstname); $this->basicFormRows[] = new FormRowView('lastname', 'person.field.lastname', $dto->lastname); $this->basicFormRows[] = new FormRowView('telephone', 'person.field.telephone', $dto->telephone); $this->basicFormRows[] = new FormRowView('email', 'person.field.email', $dto->email); $this->basicFormRows[] = new FormRowView('wheelChairAttendance', 'driver.field.wheelchair', Driver::constructWheelChairAttendanceString($dto->wheelChairAttendance)); $this->expandedFormRows[] = new FormRowView('address', 'address.field.lookahead', $dto->lookaheadaddress->addressDisplayName); if (!empty($dto->entryDate)) { $this->expandedFormRows[] = new FormRowView('entrydate', 'person.field.entrydate', $dto->entryDate->format('d.m.Y')); } if (!empty($dto->birthday)) { $this->expandedFormRows[] = new FormRowView('birthday', 'person.field.birthday', $dto->birthday->format('d.m.Y')); } if (!empty($dto->birthday)) { $this->expandedFormRows[] = new FormRowView('age', 'person.field.age', $this->getAge($dto->birthday)); } $this->expandedFormRows[] = new FormRowView('extraminutes', 'person.field.extraminutes', $dto->extraMinutes); }
/** * @param Driver $driver * @return bool */ public function isDriverAssociatedToThisShift(Driver $driver) { foreach ($this->getDrivingPools() as $drivingPool) { $poolDriver = $drivingPool->getDriver(); if ($poolDriver !== null) { if ($poolDriver->getId() === $driver->getId()) { return true; } } } return false; }
/** * @param AbsentRegisterDTO $absentDTO * @param Driver $driver */ protected function registerOrUpdateAbsentToDriver(AbsentRegisterDTO $absentDTO, Driver $driver) { $absentRepository = $this->get('absent_repository'); $assembler = $this->get('tixi_api.assemblerabsent'); /** @var DrivingAssertionManagement $drivingAssertionService */ $drivingAssertionService = $this->get('tixi_app.drivingassertionmanagement'); if (empty($absentDTO->id)) { $absent = $assembler->registerDTOtoNewAbsent($absentDTO); $driver->assignAbsent($absent); $absentRepository->store($absent); } else { $absent = $absentRepository->find($absentDTO->id); $assembler->registerDTOtoAbsent($absentDTO, $absent); } $drivingAssertionService->handleNewOrChangedAbsent($driver); }
/** ------------------------- * Create a driving assertion, assign driver and shift. * * @param Driver $driver * @param $swissDate * @param $shiftTypeName * @return bool */ private function registerUniqueDrivingAssertion(Driver $driver, $swissDate, $shiftTypeName) { /** @var DateTimeService $dateTimeService */ $dateTimeService = $this->container->get('tixi_api.datetimeservice'); $dt = $dateTimeService->convertDateTimeStringToUTCDateTime($swissDate . ' 00:00'); /** @var ShiftRepository $shiftRepository */ $shiftRepository = $this->container->get('shift_repository'); $shifts = $shiftRepository->findShiftsForDay($dt); /** @var Shift $shift */ foreach ($shifts as $shift) { if ($shift->getShiftType()->getName() == $shiftTypeName) { if (!$driver->hasDrivingAssertionForShift($shift)) { $drivingAssertion = DrivingAssertion::registerDrivingAssertion($driver, $shift); /** @var DrivingAssertionRepository $daRepository */ $daRepository = $this->container->get('drivingassertion_repository'); $daRepository->store($drivingAssertion); return true; /* success */ } } } return false; /* failure */ }
/** * Create (register) or update driving assertion plans * * @param RepeatedDrivingAssertionRegisterDTO $assertionDTO * @param Driver $driver * @return array * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ protected function registerOrUpdateAssertionPlan(RepeatedDrivingAssertionRegisterDTO $assertionDTO, Driver $driver) { /** @var RepeatedDrivingAssertionPlanRepositoryDoctrine $assertionPlanRepository */ $assertionPlanRepository = $this->get('repeateddrivingassertionplan_repository'); /** @var RepeatedDrivingAssertionRepositoryDoctrine $assertionRepository */ $assertionRepository = $this->get('repeateddrivingassertion_repository'); /** @var RepeatedDrivingAssertionAssembler $assembler*/ $assembler = $this->get('tixi_api.repeateddrivingassertionplanassembler'); /** @var DrivingAssertionManagement $damService */ $damService = $this->get('tixi_app.drivingassertionmanagement'); /** @var RepeatedDrivingAssertionPlan $assertionPlan*/ $assertionPlan = null; if (null === $assertionDTO->id) { //create new $assertionPlan = $assembler->repeatedRegisterDTOToNewDrivingAssertionPlan($assertionDTO); $driver->assignRepeatedDrivingAssertionPlan($assertionPlan); } else { //update $assertionPlan = $assertionPlanRepository->find($assertionDTO->id); $assembler->repeatedRegisterDTOToDrivingAssertionPlan($assertionPlan, $assertionDTO); foreach ($assertionPlan->getRepeatedDrivingAssertions() as $previousAssertions) { $assertionRepository->remove($previousAssertions); } } $repeatedAssertions = new ArrayCollection(); if ($assertionDTO->frequency === 'weekly') { $repeatedAssertions = $assembler->repeatedRegisterDTOtoWeeklyDrivingAssertions($assertionDTO); } else { if ($assertionDTO->frequency === 'monthly') { $repeatedAssertions = $assembler->repeatedRegisterDTOtoMonthlyDrivingAssertions($assertionDTO); } else { throw $this->createNotFoundException('Wrong frequency(' . $assertionDTO->frequency . ') found, expected "weekly" or "monthly".'); } } // check the driving assertion plan and it's repeated driving assertions $validationErrors = $damService->checkAssertionPlan($assertionPlan, $repeatedAssertions); if (count($validationErrors) != 0) { return $validationErrors; } // handle new and changed driving assertions /** @var RepeatedDrivingAssertion $repeatedAssertion */ foreach ($repeatedAssertions as $repeatedAssertion) { $repeatedAssertion->setAssertionPlan($assertionPlan); $assertionRepository->store($repeatedAssertion); } $assertionPlan->replaceRepeatedDrivingAssertions($repeatedAssertions); $assertionPlanRepository->store($assertionPlan); if (null === $assertionDTO->id) { $validationErrors = $damService->handleNewRepeatedDrivingAssertion($assertionPlan); } else { $validationErrors = $damService->handleChangeInRepeatedDrivingAssertion($assertionPlan); } return $validationErrors; }
/** * Remove Driver, delete all Associations * @param Driver $driver */ public static function removeDriver(Driver $driver) { foreach ($driver->getSupervisedVehicles() as $v) { $driver->removeSupervisedVehicle($v); } $driver->removePerson(); }
/** * @param Driver $driver * @return string */ private function getContradictingIdsFor(Driver $driver) { $contradictingIds = ''; $vehicleCategories = $driver->getContradictVehicleCategories(); /** @var VehicleCategory $vehicleCategory */ foreach ($vehicleCategories as $vehicleCategory) { $contradictingIds .= $contradictingIds === '' ? $vehicleCategory->getId() : ',' . $vehicleCategory->getId(); } return $contradictingIds; }
/** * @param Driver $driver */ public function assignDriver(Driver $driver) { $this->driver = $driver; $driver->assignDrivingAssertion($this); }
/** * @param Driver $driver * @return DriverListDTO */ public function driverToDriverListDTO(Driver $driver) { $driverListDTO = new DriverListDTO(); $driverListDTO->id = $driver->getId(); $driverListDTO->gender = $driver->getGenderAsString(); $driverListDTO->firstname = $driver->getFirstname(); $driverListDTO->telephone = $driver->getTelephone(); $driverListDTO->lastname = $driver->getLastname(); $driverListDTO->street = $driver->getAddress()->getStreet(); $driverListDTO->city = $driver->getAddress()->getCity(); $driverListDTO->driverCategory = $driver->getDriverCategory()->getName(); $driverListDTO->wheelChairAttendance = $driver->getWheelChairAttendanceAsString(); return $driverListDTO; }
private function driverRemove(Driver $driver) { $id = $driver->getId(); Driver::removeDriver($driver); $this->init->em->remove($driver); $this->init->em->flush(); $this->assertEquals(null, $this->init->driverRepo->find($id)); }