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

namespace Kufer\KuferTools\Utils\Dozenteninfo;

class DozenteninfoHelper
{
  protected $toolId;
  protected $toolSettings;
  protected $requestSuchParameter;
  protected $allowSearch;
  
  public function __construct($pToolId, $pToolSettings, $pRequestSuchParameter = null, $allowSearch = true)
  {
    $this->toolId = $pToolId;
    $this->toolSettings = $pToolSettings;
    $this->requestSuchParameter = $pRequestSuchParameter;
    $this->allowSearch = $allowSearch;
  }
  
  
  public function initDbw($dbwDozenten)
  {
    $dbwDozenten->newSearch();
    $dbwDozenten->setPersonenOrderBySettings($this->toolSettings, 'doz');
    $searchAPI = new \DozentensuchAPI();
    if(!is_null($this->requestSuchParameter)) {
     
        $searchAPI->setSearchParamsToSession($this->requestSuchParameter);
    
    }
    
    if ($this->allowSearch) {
      $dbwDozenten->fromobject = $searchAPI->getFromObjectBySession($dbwDozenten->fromobject, 'tool'.$this->toolId);
      $dbwDozenten->toobject = $searchAPI->getToObjectBySession($dbwDozenten->toobject, 'tool'.$this->toolId);
    }
    
    $dbwDozenten->fromobject->inaktiv = $this->toolSettings->inaktiveDozentenAusblenden;
    
    
    
    $doztypAry = strlen($this->toolSettings->doztyp) == 0 ? array() : \StringOperations::str_split($this->toolSettings->doztyp);
    
    $doztypAry = \ArrayOperations::replace($doztypAry, '-', '');
    $dbwDozenten->fromobject->typ = $doztypAry;
    
    
    if (!isset($dbwDozenten->toobject->idary)) {
      $dbwDozenten->toobject->idary = array();
    }
    
    $dbwDozenten->toobject->idary[] = 0;
  }
}