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


namespace Kufer\KuferTools\Veranstalter\KursUebersicht\Detailsreiter\Downloads\BearbeiteDoku;

use Kufer\KuferTools\Utils\Download\DokuHelper as DokuHelper;

class BearbeiteDokuFormularPresenter extends \Kufer\KuferTools\Basis\Presenter\JsonPresenter
{
  
  public function present()
  {
    $view = $this->getView();

    return \JsonOperations::encode4Ajax($this->getAjaxObject($view));
  }

  
  protected function getAjaxObject($pView)
  {
    $result = new \stdClass();
    $result->inhalt = $pView->show(); 
    
    $result->jsdeclarations = $this->getJSDeclarations();

    return $result;
  }

  
  protected function getJSDeclarations()
  {
    
    $dokuHelper = new DokuHelper();

    return $dokuHelper->getJSDeclarations($this->useCaseResponse->dokument);
  }

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

  protected function getViewModel()
  {
    $viewModel = new BearbeiteDokuFormularViewModel();
    $viewModel->toolId = $this->useCaseResponse->toolId;
    $viewModel->download = $this->useCaseResponse->dokument;
    $viewModel->freigabeNoetig = $this->useCaseResponse->freigabeNoetig;
    $viewModel->freigabeVon = $this->useCaseResponse->freigabeVon;
    $viewModel->freigabeAm = $this->useCaseResponse->freigabeAm;

    
    $viewModel->freigabeUserKuerzel = '';
    if ($viewModel->freigabeAm !== '') {
      $viewModel->freigabeUserKuerzel = \SessionOperations::getCurrentWebToolsUserKennung();
    }

    $viewModel->dokuOrigName = $this->useCaseResponse->dokuOrigName;
    $viewModel->dokumentId = $this->useCaseResponse->dokumentId;
    $viewModel->downloadTn = $this->useCaseResponse->downloadTn;

    return $viewModel;
  }
}