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

namespace Kufer\Web\KuferTools\Teilnehmer\KursUebersicht\Detailsreiter\FeedbackBogen;

class FeedbackBogenUseCase extends \Kufer\Web\KuferTools\Basis\Kursdetails\Detailsreiter\FeedbackBogen\FeedbackBogenUseCase
{
  private $belegHelper;

  public function __construct($pRequest)
  {
    parent::__construct($pRequest);
    $user = $this->getUser();
    $this->userNr = $user->tnr;
    
    $this->belegHelper = new \Kufer\Web\KuferTools\Utils\DatamodulHelper\Belegungen\TeilnehmerBelegungen($this->toolSettings, $this->userNr);

    
    $this->doAnonym = $this->toolSettings->erfasseFeedbackBogenAnonym;
  }

  public static function getToolId()
  {
    return \ToolsAPI::TOOL_TN; 
  }

  public static function getToolSectionId()
  {
    return 335;
  }

  protected function getRechteKey()
  {
    
    return $this->getToolSectionId() . '.0.8';
  }

  
  protected function getBogenTyp()
  {
    return 'T';
  }

  
  
  protected function getRequestedId()
  {
    return $this->request->belegId;
  }

  protected function getAllowedIds()
  {
    return $this->belegHelper->getIdsOhneFilter();
  }

  
  protected function getAnzahlGesendeteFeedbackBoegen($pKursNr, $pBogenId = 0)
  {
    $anzahl = 0;
    $tool0Settings = \ToolSettingsAPI::getToolSettings(0);
    
    
    
    $feedbackCode = \FeedBackAPI::getNewCode(
      $this->request->belegId,
      $pBogenId,
      $this->doAnonym,
      $tool0Settings->direktMaKuerzel,
      $this->shouldOnlyUseWebDatabase() ? \FeedBackAPI::FEEDBACK_DATA_ONLY_WEB : \FeedBackAPI::FEEDBACK_DATA_DEFAULT
    );

    if (!empty($feedbackCode) && $feedbackCode->isCodeRedeemed()) {
      $anzahl = 1;
    }

    return $anzahl;
  }

  
  protected function getForwardBackwardLink()
  {
    return 'index.php?tool_id=' . $this->getToolId() . '&amp;action=showFeedbackBogen&amp;knr=' . $this->request->knr
           . '&amp;belid=' . $this->request->belegId;
  }

  protected function getBackToStartLink()
  {
    return 'index.php?tool_id=' . $this->getToolId() . '&amp;action=kursdetails&amp;knr=' . $this->request->knr
           . '&amp;belid=' . $this->request->belegId;
  }

  
  protected function getFormularSendAction()
  {
    $xsrf = new \Xsrf();
    $xsrfKey = $xsrf->generateKey4Action('sendFeedbackBogenFragen', $this->request->belegId);
    
    return 'index.php?tool_id=' . $this->getToolId() . '&amp;action=sendFeedbackBogenFragen&amp;knr=' . $this->request->knr
                  . '&amp;belid=' . $this->request->belegId . '&amp;xsrf=' . $xsrfKey;
  }
}


class FeedbackBogenRequest extends \Kufer\Web\KuferTools\Basis\Kursdetails\Detailsreiter\FeedbackBogen\FeedbackBogenRequest
{
  
  public $belegId;
}