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

namespace Kufer\Web\KuferTools\Mitarbeiter\RaumUebersicht\RaumDetails\Detailsreiter\Termine;

class ReiterTerminePresenter extends \Kufer\Web\KuferTools\Basis\Raumbelegung\Raumdetails\Detailsreiter\Termine\ReiterTerminePresenter
{
  protected function getLinkZuKursdetails($datamodul)
  {
    return in_array($datamodul->knr, $this->useCaseResponse->kursIdsAry4User)
      ? '<a href="index.php?tool_id=8&amp;action=kursdetails&amp;knr=' . $datamodul->knr
            . '&amp;referer=' . urlencode('index.php?tool_id=34&action=raumdetails&rnr=' . $this->useCaseResponse->kursort->id)
            . '&amp;refererLabel=' . urlencode(\StringOperations::htmlentities('Zurück zu den Raumdetails'))
            . '" title="Kursdetails" alt="Kursdetails">
        <i class="hm_termine fa fa-search-plus" aria-hidden="true"></i>
      </a>'
    : '';
  }

  protected function getView4AnderenContent($viewModel)
  {
    return new TerminRowView($viewModel);
  }

  
  protected function setColumnHyperLink($pDatamodul, $pColumn)
  {
    $linkToOtherTool = '';
    if ($this->isKursLink($pDatamodul, $pColumn)) {
      $knr = $pDatamodul->getVarValue('knr');
      if ($knr != 'Sperrzeit' && !empty($knr)) {
        $linkToOtherTool = 'index.php?tool_id=' . \ToolsAPI::TOOL_KURSPLANUNG_MA . '&action=kursdetails&knr=' . $knr;
        $pColumn->textfarbe = '#00275B';
      }
    } 
    elseif ($this->isDozentenLink($pColumn)) {
      $dozNr = $pDatamodul->getVarValue('dnr');
      $linkToOtherTool = 'index.php?tool_id=' . \ToolsAPI::TOOL_DOZENTENINFO_MA . '&action=dozentdetails&dnr=' . $dozNr;
    } 
    elseif ($this->isAdressLink($pColumn)) {
      $adressNr = $pDatamodul->getVarValueEx('hausmadrnr', 'kursort');
      
      
      if ($adressNr > 0) {
        $linkToOtherTool = 'index.php?tool_id=' . \ToolsAPI::TOOL_ADRESSINFO_MA . '&action=adressdetails&anr=' . $adressNr;
      }
    } 

    
    if ($linkToOtherTool != '') {
      $pColumn->hyperlink = $linkToOtherTool . '&referer=' . urlencode('index.php?tool_id=34&action=raumdetails&rnr='
          . $this->useCaseResponse->kursort->id) . '&refererLabel=' . urlencode(\StringOperations::htmlentities('Zurück zu den Raumdetails'));
    }
  }

  

  
  protected function isKursLink($pDataModul, $pColumn)
  {
    return (in_array($pDataModul->knr, $this->useCaseResponse->kursIdsAry4User)
       && (($pColumn->fieldname == 'knr' && $pColumn->datamodul == 'kurstag')));
  }

  

  
  protected function isDozentenLink($pColumn)
  {
    return $this->useCaseResponse->isAllowedToolDozInfo
          && ($pColumn->fieldname == 'namevorname' && $pColumn->datamodul == 'dozent');
  }

  

  
  protected function isAdressLink($pColumn)
  {
    return $this->useCaseResponse->isAllowedToolAdresse
          && ($pColumn->datamodul == 'kursort' && $pColumn->fieldname == 'hausmeister1');
  }

  

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