/** * @param ListingItem $listingItem * @param int $position * @return mixed * @throws ListingItemNotFoundException */ public function getAdjacentItem(ListingItem $listingItem, $position) { $day = $listingItem->day; switch ($position) { case self::ITEM_LOWER: $day += self::ITEM_LOWER; break; case self::ITEM_UPPER: $day += self::ITEM_UPPER; break; default: throw new InvalidArgumentException('Invalid argument $position.'); } $itemQuery = $this->getBasicDQL($listingItem->getListing()); $itemQuery->andWhere('li.day = :day')->setParameter('day', $day); try { return $itemQuery->getQuery()->getSingleResult(); } catch (NoResultException $e) { throw new ListingItemNotFoundException(); } }
/** * @param array $newValues * @param ListingItem|null $listingItem * @return ListingItem * @throws OtherHoursZeroTimeException * @throws NegativeResultOfTimeCalcException * @throws ShiftEndBeforeStartException */ public function prepareListingItemByFormsData(array $newValues, ListingItem $listingItem = null) { $workedHours = new WorkedHours($newValues['workStart'], $newValues['workEnd'], $newValues['lunch'], $newValues['otherHours']); $locality = new Locality($newValues['locality'], $newValues['user']); if (isset($listingItem)) { if (!$listingItem->getWorkedHours()->hasSameValuesAs($workedHours)) { $workedHours = $this->workedHoursProvider->setupWorkedHoursEntity($workedHours); $listingItem->setWorkedTime($workedHours, $newValues['descOtherHours']); } if (!$listingItem->getLocality()->isSameAs($locality)) { $locality = $this->localityProvider->setupLocalityEntity($locality); $listingItem->setLocality($locality); } $listingItem->setDescription($newValues['description']); } else { $day = $newValues['day']; if (!$newValues['listing'] instanceof Listing) { throw new InvalidArgumentException('Argument $newValues must have member "listing " of type ' . Listing::class); } $listing = $newValues['listing']; $locality = $this->localityProvider->setupLocalityEntity($locality); $workedHours = $this->workedHoursProvider->setupWorkedHoursEntity($workedHours); $listingItem = new ListingItem($day, $listing, $workedHours, $locality, $newValues['description'], $newValues['descOtherHours']); } return $listingItem; }
public function onSuccessItemPersist(Entities\ListingItem $listingItem) { $this->flashMessage('Položka byla uložena.', 'success'); $this->redirect('Listing:detail#' . $listingItem->day, ['id' => $listingItem->getListing()->getId()]); }
/** * @param ListingItem $listingItem * @return ListingItem * @throws ListingItemNotFoundException */ private function provideItemForDownShifting(ListingItem $listingItem) { // we do NOT want to shift the last item if ($listingItem->day >= $listingItem->getListing()->getNumberOfDaysInMonth()) { throw new ShiftItemDownException(); } return $this->listingItemReader->getAdjacentItem($listingItem, ListingItemsReader::ITEM_LOWER); }
public function compare(ListingItem $listingItem) { if ($this->day != $listingItem->day) { return false; } if ($this->locality->getId() != $listingItem->getLocality()->getId()) { return false; } if ($this->workedHours->getId() != $listingItem->getWorkedHours()->getId()) { return false; } return true; }
public function areWorkedHoursWithoutLunchZero() { return $this->listingItem->areWorkedHoursWithoutLunchZero(); }