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

namespace Kufer\Web\KuferTools\Basis\Presenter;


abstract class WssSammelEinzelnFormularPresenter extends MitRahmenPresenter
{
  public function getContent()
  {
    $datamoduls = $this->getDatamodulsFromUseCaseResponse();
    
    $view = $this->getView();
    if ($this->isDatamodulAryEmpty($datamoduls)) {
      return $view->getNoData();
    } else {
      return $view->getHeader()
        . $this->renderWssContentWithDatamoduls($view, $datamoduls)
        . $view->getFooter();
    }
  }

  
  protected function renderWssContentWithDatamoduls($view, array $datamoduls): string
  {
    $result = '';

    foreach ($datamoduls as $datamodul) {
      $key = $this->getKeyFromDatamodul($datamodul);
      $result .= $this->renderDescriptionContent($key, $datamodul)
        . $this->renderFormContent($key, $datamodul)
        . $view->getBody();
    }

    return $result;
  }

  
  abstract protected function renderDescriptionContent($key, \Datamodul $datamodul): string;

  
  abstract protected function renderFormContent($key, \Datamodul $datamodul): string;

  
  public function getKeyFromDatamodul(\Datamodul $datamodul)
  {
    return $datamodul->id;
  }

  
  public function getDatamodulsFromUseCaseResponse(): array
  {
    return $this->useCaseResponse->datamoduls;
  }

  
  public function getDescriptionColumnsFromUseCaseResponse(): array
  {
    return $this->useCaseResponse->columnsDescription;
  }

  
  public function getFormColumnFromUseCaseResponse(): array
  {
    return $this->useCaseResponse->columnsForm;
  }
}