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

namespace Kufer\KuferTools\Dozent\KursUebersicht\Detailsreiter\Dokumente\DokumenteDownload;

class DokumenteDownloadUseCase extends \Kufer\Web\KuferTools\Basis\Kursdetails\DetailsReiter\Dokumente\DokumenteDownload\DokumenteDownloadUseCase
{
  public static function getToolId()
  {
    return \ToolsAPI::TOOL_KURSUEBERSICHT_DOZ;
  }

  public static function getToolSectionId()
  {
    return 593;
  }

  public function hasAccess($pToolSectionId = null)
  {
    if (!parent::hasAccess()) {
      return false;
    }
    if (!$this->isRechtAllowed('334.1.9')) {
      return false;
    }

    return true;
  }

  protected function getKursId(): string
  {
    return $this->request->knr;
  }

  protected function getDatDocObject()
  {
    $datDoc = parent::getDatDocObject();
    
    if (\DBWorkBASysSettings::isMVHS()) {
      
      
      $currentDozent = \SessionOperations::getCurrentWebToolsDozent();
      $datDoc->lfdnr = $this->request->lfdnr;
      $datDoc->nr = $currentDozent->id;
      $datDoc->typ = 'TNL_D';

      return $datDoc;
    }
    $currentDozent = \SessionOperations::getCurrentWebToolsDozent();
    $datDoc->lfdnr = $this->request->lfdnr;
    $datDoc->freigabe_doz_tools = true;
    $datDoc->nr_oder_jeder = $currentDozent->id; 
    $datDoc->typen = implode(',', \DatDocAPI::getDatDocDocumentTypes4KurseAndDozenten());

    return $datDoc;
  }
}

class DokumenteDownloadRequest extends \Kufer\Web\KuferTools\Basis\Kursdetails\DetailsReiter\Dokumente\DokumenteDownload\DokumenteDownloadRequest
{
  public $knr;
}