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

namespace Kufer\KuferTools\Basis\Ics;

class IcsKalenderPresenter extends \Kufer\KuferTools\Basis\Presenter\Presenter
{
  public function present()
  {
    

    return $this->getIcsFile();
  }

  public function setRequestHeader()
  {
    if (count($this->useCaseResponse->kursnummern) == 1) {
      $filename = $this->useCaseResponse->kursnummern[0] . '_' . $this->useCaseResponse->timestamp;
    } else {
      $filename = 'mehrereKurse_' . $this->useCaseResponse->timestamp;
    }

    header('Content-Type: text/calendar');
    header('Content-Disposition: attachment; filename="' . $filename . '.ics"');
  }

  public function getEncoding()
  {
    return UTF_8;
  }

  public function getExternalEncoding()
  {
    return $this->getEncoding();
  }

  private function getIcsFile()
  {
    return \IcsAPI::getIcsContentKurstage($this->useCaseResponse->kurstage);
  }

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

  protected function getViewModel()
  {
    $viewModel = new IcsAuswahlViewModel();
    $viewModel->kursnummern = $this->useCaseResponse->kursnummern;
    $viewModel->vonDat = $this->useCaseResponse->vondat;
    $viewModel->bisDat = $this->useCaseResponse->bisdat;

    return $viewModel;
  }
}