<?php
/**
 * @copyright (c) Kufer Software GmbH, Oderstraße 7, D-84453 Mühldorf
 */

namespace Kufer\Web\KuferTools\Dozent\Anwesenheiten\KurstageUebersicht;

class KurstageUebersichtPresenter extends \Kufer\Web\KuferTools\Basis\Uebersicht\UebersichtMitWssPresenter
{
  protected function getBlaetternAction()
  {
    return 'kurstageuebersicht';
  }

  protected function getSeitenTitel(): string
  {
    return 'Meine Kurstage am ' . $this->useCaseResponse->datum;
  }

  protected function getPanelTitle($kurstag): string
  {
    return $kurstag->kurs->getVarValue('nr_anzeige') . ' - ' . $kurstag->kurs->getVarValue('kurzbez');
  }

  protected function getPanelButtons($kurstag)
  {
    return $this->getButtonsAlsHtml($kurstag);
  }

  protected function getDatamodulFuerUeberschriftszeile()
  {
    $dbw = new \DBWorkKurseTage();

    return $dbw->getNewObject();
  }

  protected function getView()
  {
    return new KurstageUebersichtView($this->getViewModel());
  }

  protected function getViewModel()
  {
    $viewModel = new KurstageUebersichtViewModel();
    $viewModel->datum = $this->useCaseResponse->datum;
    $viewModel->datumzurueck = $this->useCaseResponse->datumzurueck;
    $viewModel->datumvor = $this->useCaseResponse->datumvor;
    $viewModel->dateOutOfRange = $this->useCaseResponse->dateOutOfRange;
    $viewModel->isDateOutOfRange = $this->useCaseResponse->isDateOutOfRange;
    $viewModel->backLink = $this->useCaseResponse->backLink;
    $viewModel->backButtonLabel = $this->useCaseResponse->backButtonLabel;
    $viewModel->showBackLink = $this->useCaseResponse->showBackLink;
    $viewModel->uebersichtAlsTabelle = $this->useCaseResponse->uebersichtAlsTabelle;

    return $viewModel;
  }

  protected function getButtonsAlsHtml($pDatamodul)
  {
    $buttons = $this->getButtons($pDatamodul);
    $buttonleiste = new \Kufer\Web\KuferTools\Basis\Button\Buttonleiste();

    return $buttonleiste->getHtmlButtonleiste($buttons);
  }

  protected function getButtons($pDatamodul)
  {
    $buttons4ViewModel = array();
    $buttons = call_user_func($this->useCaseResponse->buttons, $pDatamodul);

    $buttonFactory = new \Kufer\Web\KuferTools\Basis\Button\ButtonFactory();

    if (isset($buttons['anwesenheiten'])) {
      $buttons4ViewModel[] = array($buttonFactory->getAnwesenheitenButton(18, $pDatamodul->id, $buttons['anwesenheiten']));
    }
    if (isset($buttons['noten'])) {
      $buttons4ViewModel[] = array($buttonFactory->getNotenButton(18, $pDatamodul->kurs->id, $this->useCaseResponse->datum, $buttons['noten']));
    }
    if (isset($buttons['feedback'])) {
      $allgSettings = \AllgSettingsAPI::getAllgSettings();
      $title = 'Nachricht an ' . $allgSettings->vhsname . ' senden';
      $buttons4ViewModel[] = array($buttonFactory->getFeedbackButton(18, $pDatamodul->id, $buttons['feedback'], $title));
    }

    return $buttons4ViewModel;
  }

  
}