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

namespace Kufer\Web\KuferTools\Utils\ResponseStrategies;

use Kufer\Web\KuferTools\Utils\ResponseStrategies\ResponseStrategy;
use Kufer\Web\Classes\Db\DBWorkWunschtermine;
use Kufer\Web\Classes\Dbfilter\WunschtermineSQLFilter;


class ResponseWunschtermineOnCurrentPage extends ResponseStrategy
{
  public function extendResponse($pResponse)
  {
    $pResponse->datamodule = $this->getWunschtermine($pResponse);

    return $pResponse;
  }

  private function getWunschtermine($pResponse): array
  {
    $currentIds = $pResponse->blaettern->getItemsOnCurrentPage();
    $dbwWunschtermine = DBWorkWunschtermine::getDefaultInstance(1, true);
    $wunschtermine = $dbwWunschtermine->findByFilter(WunschtermineSQLFilter::create()->inId($currentIds));
    
    return \ArrayOperations::sortObjectsByValueArray($wunschtermine, $currentIds, 'id');
  }
}