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

namespace Kufer\KuferTools\Basis\Kursdetails\DetailsReiter\Dozenten;

abstract class DozentenVerlinktUseCase extends \Kufer\KuferTools\Basis\UseCase\EinzelKursUseCase
{
  
  abstract protected function getDozentenUebersichtHelper(): ?\Kufer\KuferTools\Utils\DatamodulHelper\DozentenHelper\DozentenHelper;

  
  abstract protected function getDozentenUebersichtToolId(): ?int;

  protected function addDozInfoLinksToDozent($honorare)
  {
    $helper = $this->getDozentenUebersichtHelper();
    if (\is_null($helper)) {
      return $honorare;
    }

    $allowedDnrs = $helper->getIdsOhneFilter();
    $currentUrl = urlencode($this->getRefererURL());
    $currentReferer = urlencode(\StringOperations::htmlentities('Reiter Dozenten'));
    foreach ($honorare as $honorar) {
      $dnr = $honorar->getVarValueEx('id', 'dozent');
      if (\in_array($dnr, $allowedDnrs)) {
        $doz = $honorar->getDatamodulByName('dozent');
        $link = 'index.php?tool_id=' . $this->getDozentenUebersichtToolId() . '&action=dozentdetails&dnr=' . $dnr . '&dguid=' . ((string)$doz->guid);
        $doz->dozinfoLink = $link;
        $doz->referer = $currentUrl;
        $doz->refererLabel = $currentReferer;
      }
    }

    return $honorare;
  }

  protected function getRefererURL()
  {
    $url = \URL::loadCurrent();
    $url->setParameterValue('action', 'kursdetails');

    return $url->getUrlRelative();
  }
}