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

namespace Kufer\KuferTools\Mitarbeiter\DozentenInfo\Detailsreiter\Kurse\PdfListen\DruckListen\PrintDruckListen;


class PrintDruckListenBySettingsController extends \Kufer\KuferTools\Basis\PdfListen\PrintPdfListen\PrintPdfListenBySettingsController
{
  protected function getUseCase(): \Kufer\KuferTools\Basis\UseCase\UseCase
  {
    return new PrintDruckListenBySettingsUseCase(
      $this->getRequestObj()
    );
  }

  protected function getToolId()
  {
    return PrintDruckListenBySettingsUseCase::getToolId();
  }

  protected function getId()
  {
    return \RequestOperations::getVarValue('nr');
  }

  
  protected function _getPostSettings()
  {
    
    $settingsObj = $this->_getDruckSettingsObject();
    
    $settingsObj->title1 = '';
    if (\PostOperations::isDefined('ueberschrift')) {
      $settingsObj->title1 = \PostOperations::getVarValue('ueberschrift');
    }
    
    $settingsObj->title2 = '';
    if (\PostOperations::isDefined('subtitle')) {
      $settingsObj->title2 = \PostOperations::getVarValue('subtitle');
    }
    
    $settingsObj->endbem = '';
    if (\PostOperations::isDefined('endbemerkung')) {
      $settingsObj->endbem = \PostOperations::getVarValue('endbemerkung');
    }

    
    
    if (\PostOperations::isDefined('format')) {
      
      $settingsObj->druckbereich->hochformat = \PostOperations::getVarValue('format') == 'H';
    }

    
    $settingsObj->kurstage->von = \PostOperations::getVarValue('kt_von');
    $settingsObj->kurstage->bis = \PostOperations::getVarValue('kt_bis');


    
    if ($this->listName === 'Kursstammblattliste' || $this->listName === 'Lehrplanliste' || $this->listName === 'Lehrplantabelle') {
      $vars = get_object_vars($settingsObj->einstellDarstellung);
      foreach ($vars as $name => $wert) {
        $optionName = $name;
        if ($this->listName === 'Kursstammblattliste') {
          $optionName = 'ein_' . $name;
        }
        $settingsObj->einstellDarstellung->{$name} = \PostOperations::isDefined($optionName);
      }
    }

    return $settingsObj;
  }

  

  
  protected function _getDruckSettingsObject()
  {
    if ($this->listName === 'Kursstammblattliste') {
      $settingsObj = new \webtools\drucklisten\StammblattListSettings();
    } elseif ($this->listName === 'Lehrplanliste') {
      $settingsObj = new \webtools\drucklisten\LehrplanlisteSettings();
    } elseif ($this->listName === 'Lehrplantabelle') {
      $settingsObj = new \webtools\drucklisten\LehrplantabelleSettings();
    } else {
      $settingsObj = new \webtools\drucklisten\DruckSheetSettings();
    }

    return $settingsObj;
  }
}