<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */

namespace Kufer\KuferTools\Basis\AnwesenheitenKurs;

class AnwesenheitenPresenter extends \Kufer\KuferTools\Basis\Presenter\MitRahmenPresenter
{
  protected function getContent()
  {
    $view = $this->getView();

    if (count($this->useCaseResponse->belKtInfos) == 0) {
      $result = $view->getNoData();
    } else {
      $result = $view->getHeader();
      $result .= $view->getBody();
      $result .= $view->getFooter();
      $result .= $view->getNoColumn();
    }

    return $result;
  }

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

  protected function getViewModel()
  {
    $viewModel = new AnwesenheitenViewModel();
    $viewModel->toolId = $this->useCaseResponse->toolId;
    $viewModel->kurs = $this->useCaseResponse->kurs;
    $viewModel->kursTageInfo = $this->useCaseResponse->kursTageInfo;
    $viewModel->showFilterButton = $this->useCaseResponse->showFilterButton ? '1' : '0';
    $viewModel->zeigeUhrzeit = $this->useCaseResponse->zeigeUhrzeit ? '1' : '0';
    $viewModel->zeigeUE = $this->useCaseResponse->zeigeUE ? '1' : '0';
    $viewModel->zeigeDozent = $this->useCaseResponse->zeigeDozent ? '1' : '0';
    $viewModel->zeigeFaecher = $this->useCaseResponse->zeigeFaecher ? '1' : '0';
    $viewModel->zeigeBemerkung = $this->useCaseResponse->zeigeBemerkung ? '1' : '0';
    $viewModel->zeigeAnwInProzent = $this->useCaseResponse->zeigeAnwInProzent ? '1' : '0';
    $viewModel->zeigeAnwTage = $this->useCaseResponse->zeigeAnwTage ? '1' : '0';
    $viewModel->zeigeAbwTage = $this->useCaseResponse->zeigeAbwTage ? '1' : '0';
    $viewModel->isBearbeitbar = $this->useCaseResponse->isBearbeitbar;
    $viewModel->anwInZukunftBearbeitenErlaubt = $this->useCaseResponse->anwInZukunftBearbeitenErlaubt;
    $viewModel->anwVonAnderenDozentenBearbeitbar = $this->useCaseResponse->anwVonAnderenDozentenBearbeitbar;
    $viewModel->setFilter = $this->useCaseResponse->setFilter;

    $viewModel->messageSuccess = $this->getMessageStringSuccess();
    $viewModel->messageError = $this->getMessageStringError();
    $viewModel->messageWarning = $this->getMessageStringWarning();
    $viewModel->messageInfo = $this->getMessageStringInfo();

    $viewModel->backButtonLabel = $this->useCaseResponse->backButtonLabel;
    $viewModel->backButtonLink = $this->useCaseResponse->backButtonLink;

    $anwLegendeViewModel = new AnwesenheitenLegendeViewModel();
    $anwLegendeViewModel->anwGruendeLegende = $this->useCaseResponse->anwGruendeLegende;
    $viewModel->htmllegende = (new AnwesenheitenLegendeView($anwLegendeViewModel))->show();

    return $viewModel;
  }

  protected function getJsFilesSrcAryWeitere()
  {
    return array(
      $this->getJsFileFromSys('anwesenheitenFuerKurs.js'),
      $this->getJsFileFromSys('filter.js')
    );
  }

  
  protected function getJSDeclarations()
  {
    $result = parent::getJSDeclarations();
    $result .= \JsOperations::getDeclarationString('KuferTools.Knr', $this->useCaseResponse->kurs->id);
    $result .= \JsOperations::getDeclarationString('KuferTools.Dnr', $this->useCaseResponse->user->dnr);
    $result .= \JsOperations::getDeclarationString('KuferTools.Dguid', (string)$this->useCaseResponse->user->dnr_guid);

    $result .= \JsOperations::getDeclarationJson('KuferTools.KursTageInfo', $this->useCaseResponse->kursTageInfo);
    $result .= \JsOperations::getDeclarationJson('KuferTools.BelKtInfos', $this->useCaseResponse->belKtInfos);
    $result .= \JsOperations::getDeclarationJson('KuferTools.BelIdsOrder', \array_keys($this->useCaseResponse->belKtInfos));
    $result .= \JsOperations::getDeclarationJson('KuferTools.BelKtInfosOrig', $this->useCaseResponse->belKtInfos);
    $result .= \JsOperations::getDeclarationJson('KuferTools.AnwGruende', $this->useCaseResponse->anwGruende);
    $result .= \JsOperations::getDeclarationString('KuferTools.Xsrf', $this->useCaseResponse->xsrf);
    $result .= \JsOperations::getDeclarationBoolean('KuferTools.isBearbeitbar', $this->useCaseResponse->isBearbeitbar);
    $result .= \JsOperations::getDeclarationBoolean('KuferTools.anwInZukunftBearbeitenErlaubt', $this->useCaseResponse->anwInZukunftBearbeitenErlaubt);
    $result .= \JsOperations::getDeclarationBoolean('KuferTools.anwVonAnderenDozentenBearbeitbar', $this->useCaseResponse->anwVonAnderenDozentenBearbeitbar);
    $result .= \JsOperations::getDeclarationJson('KuferTools.BearbeiterKuferTools', $this->useCaseResponse->bearbeiterKuferTools);
    $result .= \JsOperations::getDeclarationBoolean('KuferTools.AnwesenheitenAusKuferSQLNichtBearbeitbar', $this->useCaseResponse->anwesenheitenAusKuferSQLNichtBearbeitbar);

    return $result;
  }

  private function getMessageStringSuccess()
  {
    if (isset($this->useCaseResponse->statusMessageContainer) && !is_null($this->useCaseResponse->statusMessageContainer)) {
      return $this->useCaseResponse->statusMessageContainer->getStatusMessage(MSG_BOX_SUCCESS);
    } else {
      return '';
    }
  }

  private function getMessageStringWarning()
  {
    if (isset($this->useCaseResponse->statusMessageContainer) && !is_null($this->useCaseResponse->statusMessageContainer)) {
      return $this->useCaseResponse->statusMessageContainer->getStatusMessage(MSG_BOX_WARNING);
    } else {
      return '';
    }
  }

  private function getMessageStringError()
  {
    if (isset($this->useCaseResponse->statusMessageContainer) && !is_null($this->useCaseResponse->statusMessageContainer)) {
      return $this->useCaseResponse->statusMessageContainer->getStatusMessage(MSG_BOX_ERROR);
    } else {
      return '';
    }
  }

  private function getMessageStringInfo()
  {
    if (isset($this->useCaseResponse->statusMessageContainer) && !is_null($this->useCaseResponse->statusMessageContainer)) {
      return $this->useCaseResponse->statusMessageContainer->getStatusMessage(MSG_BOX_INFO);
    } else {
      return '';
    }
  }
}