コード例 #1
0
ファイル: ListingFacade.php プロジェクト: blitzik/vycetky
 /**
  * @param Listing $listing
  * @param WorkedHours $workedHours
  * @param bool $createNewListing
  * @param array $selectedItemsIDsToChange
  * @return array
  * @throws \DibiException
  * @throws NegativeResultOfTimeCalcException
  */
 public function changeItemsInListing(Listing $listing, WorkedHours $workedHours, $createNewListing = true, array $selectedItemsIDsToChange)
 {
     $this->checkListingValidity($listing);
     Validators::assert($createNewListing, 'boolean');
     if (empty($selectedItemsIDsToChange)) {
         throw new InvalidArgumentException('Argument $selectedItemsIDsToChange must not be empty array!');
     }
     $listingItems = $listing->listingItems;
     $itemsToChange = [];
     $itemsToCopy = [];
     // items that won't change
     $selectedItemsToChange = array_flip($selectedItemsIDsToChange);
     foreach ($listingItems as $listingItem) {
         if (array_key_exists($listingItem->listingItemID, $selectedItemsToChange)) {
             $itemsToChange[] = $listingItem;
         } else {
             $itemsToCopy[] = $listingItem;
         }
     }
     try {
         $this->transaction->begin();
         // amount of Items is same all the time
         $numberOfItemsToChange = count($itemsToChange);
         if ($createNewListing === true) {
             $listing = $this->establishListingCopy($listing, false);
             if (count($itemsToCopy) > 0) {
                 $itemsToCopy = $this->getItemsCopies($listing, $itemsToCopy);
             }
             if ($numberOfItemsToChange > 0) {
                 $itemsToChange = $this->getItemsCopies($listing, $itemsToChange);
             }
         }
         if ($numberOfItemsToChange > 0) {
             $workedHours = $this->itemFacade->setupWorkedHoursEntity($workedHours);
             $whInSecs = $workedHours->otherHours->toSeconds();
             foreach ($itemsToChange as $item) {
                 $descOtherHours = null;
                 if (isset($item->descOtherHours) and $whInSecs > 0) {
                     $descOtherHours = $item->descOtherHours;
                 }
                 $item->setWorkedTime($workedHours, $descOtherHours);
             }
         }
         if ($createNewListing === true) {
             $allItems = array_merge($itemsToChange, $itemsToCopy);
             $this->listingItemRepository->saveListingItems($allItems);
         } else {
             $this->listingItemRepository->updateListingItemsWorkedHours($itemsToChange, $workedHours);
         }
         $this->transaction->commit();
         return ['listing' => $listing, 'changedItems' => $itemsToChange];
     } catch (\DibiException $e) {
         $this->transaction->rollback();
         Debugger::log($e, Debugger::ERROR);
         throw $e;
     }
 }
コード例 #2
0
ファイル: ItemsTableControl.php プロジェクト: blitzik/vycetky
 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();
 }
コード例 #3
0
ファイル: ListingPresenter.php プロジェクト: blitzik/vycetky
 public function generatePdf(SubmitButton $button)
 {
     $values = $button->getForm()->getValues();
     $template = $this->createTemplate()->setFile(__DIR__ . '/../templates/Listing/pdf.latte');
     $template->itemsCollection = $this->itemFacade->generateEntireTable($this->listing);
     $template->listing = $this->listing;
     $template->username = $values['name'] == null ?: $values['name'];
     $template->employer = $values['employer'];
     $template->employeeName = $values['name'];
     $template->wage = $values['wage'];
     $template->otherHours = $values['otherHours'];
     $template->workedHours = $values['workedHours'];
     $template->lunchHours = $values['lunch'];
     $pdf = new \PdfResponse\PdfResponse($template);
     $this->presenter->sendResponse($pdf);
 }
コード例 #4
0
ファイル: ItemPresenter.php プロジェクト: blitzik/vycetky
 public function processSaveItem(Form $form, $values)
 {
     try {
         $workedHours = new Entities\WorkedHours($values['workStart'], $values['workEnd'], $values['lunch'], $values['otherHours']);
         $this->itemFacade->setupWorkedHoursEntity($workedHours);
         $locality = new Entities\Locality($values['locality']);
         $this->itemFacade->setupLocalityEntity($locality);
         if (is_null($this->listingItem)) {
             $this->listingItem = new Entities\ListingItem($this->date->format('j'), $this->listing, $workedHours, $locality, $values['description'], $values['descOtherHours']);
         } else {
             $this->listingItem->setWorkedTime($workedHours, $values['descOtherHours']);
             $this->listingItem->setLocality($locality);
         }
         $this->listingItem->description = $values['description'];
         $listingItem = $this->itemFacade->saveListingItem($this->listingItem);
     } catch (Runtime\OtherHoursZeroTimeException $zt) {
         $form->addError(ItemUpdateFormFactory::OTHER_HOURS_ZERO_TIME_ERROR_MSG);
         return;
     } catch (Runtime\NegativeResultOfTimeCalcException $b) {
         $form->addError('Položku nelze uložit. Musíte mít odpracováno více hodin,
              než kolik strávíte obědem.');
         return;
     } catch (Runtime\ShiftEndBeforeStartException $c) {
         $form->addError('Nelze skončit směnu dřív než začne. Zkontrolujte si začátek
              a konec směny.');
         return;
     } catch (Runtime\ListingItemDayAlreadyExistsException $d) {
         $form->addError('Položku nelze uložit, protože výčetka již obsahuje záznam
              z tohoto dne.');
         return;
     } catch (\DibiException $e) {
         $form->addError('Položka nebyla uložena. Zkuste akci opakovat později.');
         return;
     }
     $this->flashMessage('Položka byla uložena.', 'success');
     $this->redirect('Listing:detail#' . $listingItem->listingItemID, ['id' => $this->listing->listingID]);
 }
コード例 #5
0
 /**
  * @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);
     }
 }