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

namespace Kufer\Web\KuferTools\Dozent\SammelVertraege\Drucken;

use Kufer\Web\KuferTools\Basis\Presenter\BasePresenter;

class SammelVertragDruckenPresenter implements BasePresenter
{
  protected $decoded;
  protected $datDoc;

  public function __construct($useCaseResponse)
  {
    $this->datDoc = $useCaseResponse->datDoc;
    $this->decoded = base64_decode($useCaseResponse->datDoc->ContentBase64);
  }

  public function present()
  {
    return $this->decoded;
  }

  public function setRequestHeader()
  {
    header('Content-Length: ' . strlen($this->decoded));
    header('Content-Type: application/octetstream');
    $ext = \ArrayOperations::lastValue(explode('.', $this->datDoc->DateiName));
    if ($ext === '') {
      $ext = 'pdf';
    }
    header('Content-Disposition: inline; filename="' . rawurlencode('Sammelvertrag.' . $ext) . '"');
  }

  public function getEncoding()
  {
    return UTF_8;
  }

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