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

namespace Kufer\KuferTools\Utils\ResponseStrategies;


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

    return $pResponse;
  }

  private function getNews($pResponse)
  {
    $newsIdsAufSeite = $pResponse->blaettern->getItemsOnCurrentPage();
    $dbwAktuelles = new \DBWorkAktuellesWT(1, true);

    
    
    $newsAry = $dbwAktuelles->getAktuellesByIdsOrdered($newsIdsAufSeite);

    
    foreach ($newsAry as $news) {
      
      
      
      if (\DBWorkBASysSettings::isBFI() && \StringOperations::strpos($news->inhalt, 'toolsection_id') !== false) {
        $news->inhalt = str_replace(array('usertools.php', 'nr'), array('index.php', 'knr'), $news->inhalt);
        $news->inhalt = preg_replace('/toolsection_id=.*?[^&]*/', 'action=anwesenheiten', $news->inhalt);
      }
    }

    return $newsAry;
  }
}