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

namespace Kufer\Web\KuferTools\Teilnehmer\Visitenkarten\VisitenkartenUebersicht;

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

  public static function getToolSectionId()
  {
    return 495;
  }

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

  protected function getResponse()
  {
    parent::getResponse();
    $this->response->datamodule = $this->response->visitenkarten;
    $this->response->statusCode = $this->request->statusCode;

    return $this->response;
  }

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

  protected function getUeberschrift()
  {
    return 'Übersicht über die Visitenkarten';
  }

  protected function getDatamoduleProSeite()
  {
    $anzahlVisitenkartenProSeite = parent::getDatamoduleProSeite();
    if ($this->toolSettings->visitenkartenproseite > 0) {
      $anzahlVisitenkartenProSeite = $this->toolSettings->visitenkartenproseite;
    }

    return $anzahlVisitenkartenProSeite;
  }

  protected function verlinkePanelHeaderAllowed()
  {
    return true;
  }

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

    $buttons[] = array($buttonFactory->getVisitenkarteErstellenButton($this->getToolId()));

    return $buttons;
  }

  protected function getPanelButtonCallBacks()
  {
    $buttons = array();
    $buttonFactory = new \Kufer\KuferTools\Basis\Button\ButtonFactory();
    $buttons[] = function($visitenkarte) use ($buttonFactory) {
      return $buttonFactory->getVisitenkartenBearbeitenButton($this->getToolId(), $visitenkarte->id);
    };
    $buttons[] = function($visitenkarte) use ($buttonFactory) {
      return $buttonFactory->getVisitenkartenLoeschenButton($this->getToolId(), $visitenkarte->id);
    };

    return $buttons;
  }

  private function getDbwVisitenkartenWeb()
  {
    return \DBWorkVisitenkartenWeb::getDefaultInstance(1, true);
  }

  protected function getAlleIds()
  {
    $tnr = $this->getUser()->tnr;
    $nurAktive = false;
    $dbWorkVisitenkarten = $this->getDbwVisitenkartenWeb();
    $visitenkarten = $dbWorkVisitenkarten->getVisitenkartenByTnr($tnr, $nurAktive);

    $visitenkartenIds = array();
    foreach ($visitenkarten as $visitenkarte) {
      $visitenkartenIds[] = $visitenkarte->id;
    }

    return $visitenkartenIds;
  }
}