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

namespace Kufer\KuferTools\Basis\Raumbelegung\Raumdetails\Detailsreiter\Termine;

abstract class ReiterTerminePresenter extends \Kufer\KuferTools\Basis\Presenter\Presenter
{
  abstract protected function getLinkZuKursdetails($pDatamodul);

  abstract protected function getView4AnderenContent($pViewModel);

  abstract protected function setColumnHyperLink($pDatamodul, $pColumn);

  abstract protected function isKursLink($pDataModul, $pColumn);

  abstract protected function isDozentenLink($pColumn);

  abstract protected function isAdressLink($pColumn);

  public function present()
  {
    $emptyDataObj = $this->getEmptyDataObj();
    $data = \array_merge(array($emptyDataObj), $this->useCaseResponse->data);

    return $this->getAnderenContentAlsBody($data);
  }

  
  protected function getEmptyDataObj()
  {
    
    $dbwObj = new \DBWorkKurseTageWT();

    return $dbwObj->getNewObject();
  }

  protected function isDatamodulAryEmpty($datamodulArray)
  {
    return count($datamodulArray) <= 1;
  }

  
  protected function getAnderenContent($datamodul, $key)
  {
    $viewModel = new TerminViewModel();
    
    $viewModel->columns = $this->getHyperlink4Columns($datamodul, $this->useCaseResponse->columns);
    $viewModel->termin = $datamodul;
    
    $viewModel->termin->linkZuKursdetails = $this->getLinkZuKursdetails($datamodul);

    $viewModel->index = $key;
    $terminView = $this->getView4AnderenContent($viewModel);

    return $terminView->show();
  }

  
  protected function getHyperlink4Columns($datamodul, $columns)
  {
    $columnsCopy = array();
    $colorEvent = new \ColorEvent('#FF0000', 'A', 'ausfall', 'kurstag');
    $color = $colorEvent->getTextColor($datamodul);

    $columnsCount = count($columns);

    
    for ($i = 0; $i < $columnsCount; $i++) {
      $columnsCopy[$i] = clone $columns[$i];

      
      if ($color !== true) {
        $columnsCopy[$i]->textfarbe = $color;
      }
      
      $this->setColumnHyperLink($datamodul, $columnsCopy[$i]);
    } 

    return $columnsCopy;
  }

  protected function getViewModel()
  {
    $viewModel = new ReiterTermineViewModel();
    $viewModel->kursort = $this->useCaseResponse->kursort;
    $viewModel->kursort->reiterButtons = $this->getButtonHtml();

    return $viewModel;
  }

  protected function getButtonHtml()
  {
    $buttonleiste = new \Kufer\KuferTools\Basis\Button\Buttonleiste();

    return $buttonleiste->getHtmlButtonleiste($this->useCaseResponse->reiterButtons, 'raumreiter_buttons');
  }
}