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

namespace Kufer\Web\KuferTools\Basis\Kursdetails\Detailsreiter\Dozenten;

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

  
  abstract protected function getDozentenUebersichtToolId(): ?int;

  
  protected function addDozInfoLinksToDozent(array $honorare): array
  {
    $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();
  }
}