public function renderEdit($id, $day) { $this->template->_form = $this['itemForm']; $workedHours = null; if ($this->listingItem instanceof Entities\ListingItem and !$this->listing->isDetached()) { $workedHours = $this->listingItem->workedHours->getHours(); } $this->template->itemDate = $this->date; $this->template->listing = $this->listing; $this->template->workedHours = $workedHours; $this->template->defaultWorkedHours = $this->itemUpdateFormFactory->getDefaultTimeValue('workedHours'); }
/** * @param Entities\ListingItem[] $listingItems * @param Entities\Listing $listing * @return array */ public function setListingForGivenItems(array $listingItems, Entities\Listing $listing) { if ($listing->isDetached()) { throw new InvalidArgumentException('Only attached(not detached) ' . Entities\Listing::class . ' entity can pass!'); } $newItemsCollection = []; foreach ($listingItems as $listingItem) { if (!$listingItem instanceof Entities\ListingItem) { throw new InvalidArgumentException('Only instances of ' . Entities\ListingItem::class . ' can pass.'); } $listingItem->setListing($listing); $newItemsCollection[] = $listingItem; } return $newItemsCollection; }
public function render() { $template = $this->getTemplate(); $template->setFile(__DIR__ . '/templates/table.latte'); if (!$this->presenter->isAjax()) { $this->items = $this->itemFacade->generateEntireTable($this->listing); } else { $this->items = $this->itemFacade->createListingItemDecoratorsCollection($this->items); } $template->itemsCollection = $this->items; $template->workedDays = $this->workedDays; $template->totalWorkedHours = $this->totalWorkedHours; $template->isTableCaptionVisible = $this->isTableCaptionVisible; $template->showCheckBoxes = $this->showCheckBoxes; $template->showActions = $this->showActions; $template->parameters = $this->parameters; $template->listing = $this->listing; $template->numberOfDaysInMonth = $this->listing->getNumberOfDaysInMonth(); $template->render(); }
/** * @param int $day Numeric representation of the day of the month * @secured */ public function handleCopyItem($day) { $noDays = $this->listing->getNumberOfDaysInMonth(); if (!is_numeric($day) or !($day >= 1 and $day <= $noDays)) { $this->redirect('this'); } $err = 0; try { $newListingItem = $this->itemFacade->shiftCopyOfListingItemDown($day, $this->listing); } catch (ListingItemNotFoundException $is) { $this->presenter->flashMessage('Řádek výčetky nemohl být zkopírován, protože nebyl nalezen.', 'error'); $err++; } catch (DayExceedCurrentMonthException $is) { $this->presenter->flashMessage('Nelze vytvořit kopii poslední položky ve výčetce.', 'error'); $err++; } catch (\DibiException $e) { $this->presenter->flashMessage('Kopie položky nemohla být založena. Zkuste akci opakovat později.', 'error'); $err++; } if ($err !== 0) { if ($this->presenter->isAjax()) { $this->presenter->redrawControl('flashMessages'); } else { $this->redirect('this'); } } if ($this->presenter->isAjax()) { $this->listing = $this->listingFacade->getEntireListingByID($this->listing->listingID); $this->itemsCollection = [$newListingItem]; $this['itemsTable']->redrawControl(); } else { $this->flashMessage('Řádek byl zkopírován.', 'success'); $this->redirect('this#' . $newListingItem->listingItemID); } }
/** * @param Listing $listing */ public function setListing(Listing $listing) { $listing->checkEntityState(); $listingDaysInMonth = $listing->getNumberOfDaysInMonth(); if (isset($this->day) and $this->day > $listingDaysInMonth) { throw new InvalidArgumentException('Day of ListingItem exceed last day in Listing period.'); } $this->assignEntityToProperty($listing, 'listing'); }
/** * @param Listing $listing * @return ListingItemDecorator[] */ public function generateEntireTable(Listing $listing) { $listing->checkEntityState(); $collectionOfDecorators = $this->createListingItemDecoratorsCollection($listing->listingItems); return $this->itemService->generateListingItemDecoratorsForEntireTable($collectionOfDecorators, $listing->getPeriod()); }
/** * @param Listing $listing * @throws InvalidArgumentException */ private function checkListingValidity(Listing $listing) { if ($listing->isDetached()) { throw new InvalidArgumentException('Argument $listing must be attached instance of ' . Listing::class); } }