/** * @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(); } }
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); }