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

namespace Kufer\Web\KuferTools\Dozent\Anwesenheiten\Anwesenheitseingabe\KursAbschliessen;

use Kufer\KuferTools\Basis\Presenter\Presenter;

class KursAbschliessenDialogPresenter extends Presenter
{
  public function present()
  {
    $view = $this->getView();

    if ($this->useCaseResponse->success) {
      $dialog = $view->show();
    } else {
      $dialog = $view->getNoData();
    }

    $json = new class() {
      public $success;
      public $dialog_msg;
    };

    $json->success = (bool)$this->useCaseResponse->success;
    $json->dialog_msg = \StringOperations::utf8_encode($dialog);

    return json_encode($json);
  }

  public function setRequestHeader()
  {
    header('Content-Type: application/json; charset=' . UTF_8);
  }

  protected function getViewModel()
  {
    $result = new KursAbschliessenDialogViewModel();
    $result->kurstag = $this->useCaseResponse->kurstag;

    return $result;
  }

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