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

namespace Kufer\KuferTools\Veranstalter\KursUebersichtDerMitarbeiter\KursUebersicht;


class KursUebersichtUseCase extends \Kufer\KuferTools\Basis\Uebersicht\UebersichtMitWssUseCase
{
  public function __construct($request)
  {
    parent::__construct($request, new KursUebersichtResponse());
  }

  protected function getDatamoduleProSeite()
  {
    return $this->toolSettings->kurseproseite;
  }

  public static function getToolId()
  {
    return 61;
  }

  public static function getToolSectionId()
  {
    return 721;
  }

  protected function getButtons()
  {
    $buttonFactory = new \Kufer\KuferTools\Basis\Button\ButtonFactory();
    $buttons = array();

    if ($this->isRechtAllowed('721.0.4')) {
      $anzahlEintraege = count($this->response->kurse);
      
      $this->addFilterButton($buttons, $buttonFactory, $anzahlEintraege, 'Filter');
    }

    return $buttons;
  }

  protected function isFilterGesetzt()
  {
    $suchApi = new \KurssuchAPI();

    return $suchApi->isFilterGesetzt($this->getToolId());
  }

  protected function checkboxNeeded()
  {
    return false;
  }

  protected function verlinkePanelHeaderAllowed()
  {
    return ($this->isRechtAllowed('721.0.6')
            && \ToolsAPI::rechteOR(array('722.1.1', '722.1.2', '722.1.3', '722.1.4' . '722.1.5', '722.1.6', '722.1.7'), $this->getToolId()));
  }

  protected function getAlleIds()
  {
    $user = $this->getUser();

    $searchAPI = new \KurssuchAPIwSearch();
    $searchAPI->getSearchParamsFromReqToSession('tool' . $this->getToolId());

    $kurshelper = new \Kufer\KuferTools\Utils\DatamodulHelper\KursHelper\VeranstalterKurseDerMitarbeiter($this->toolSettings, $user);

    return $kurshelper->getIdsMitFilter($this->getToolId());
  }

  protected function getUeberschrift()
  {
    return 'Aktuell von uns gebuchte Seminare mit folgenden Mitarbeitern:';
  }

  protected function getResponse()
  {
    parent::getResponse();
    $this->response->datamodule = $this->response->kurse;
    $this->response->uebersichtAlsTabelle = $this->toolSettings->kursUebersichtAlsTabelle;

    return $this->response;
  }

  protected function getTnStatus()
  {
    $tnStatus = $this->toolSettings->tnstatus;
    if ($this->toolSettings->tnstatus == '') {
      $tnStatus = '-ATP';
    }
    $tnStatus = str_replace('-', ' ', $tnStatus);
    $tnStatus = \StringOperations::convertArray2InList(\StringOperations::str_split($tnStatus));
    if (\StringOperations::strpos($tnStatus, 'A') !== false) {
      $tnStatus .= ", ' ', ''";
    }

    return $tnStatus;
  }

  protected function getDatamodulOnCurrentPage()
  {
    return new \Kufer\KuferTools\Utils\ResponseStrategies\ResponseKurseOnCurrentPage($this);
  }
}

class KursUebersichtRequest extends \Kufer\KuferTools\Basis\Uebersicht\UebersichtMitWssRequest
{
}

class KursUebersichtResponse extends \Kufer\KuferTools\Basis\Uebersicht\UebersichtMitWssResponse
{
  public $kurse = array();
  public $uebersichtAlsTabelle;
}