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


class Buchungen
{
  
  public $_tnrs;

  
  public $_knrs;

  
  public function __construct()
  {
    $this->_tnrs = array();
    $this->_knrs = array();
  }

  
  public function addBuchung($pTnr, $pKnr)
  {
    $this->_tnrs[] = $pTnr;
    $this->_knrs[] = $pKnr;
  }

  
  public function getIndicesForKnr($pKnr)
  {
    $retour = array();
    foreach ($this->_knrs as $key => $knr) {
      if ($knr == $pKnr) {
        $retour[] = $key;
      }
    }

    return $retour;
  }

  
  public function getIndicesForTnr($pTnr)
  {
    $retour = array();
    foreach ($this->_tnrs as $key => $tnr) {
      if ($tnr == $pTnr) {
        $retour[] = $key;
      }
    }

    return $retour;
  }

  
  public function contains($pTnr, $pKnr)
  {
    if (!in_array($pTnr, $this->_tnrs) || !in_array($pKnr, $this->_knrs)) {
      return false;
    }
    $kind = $this->getIndicesForKnr($pKnr);
    if (count($kind) == 0) {
      return false;
    }
    $tind = $this->getIndicesForTnr($pTnr);
    if (count($tind) == 0) {
      return false;
    }
    $schnittmenge = array_intersect($tind, $kind);
    if (count($schnittmenge) == 0) {
      return false;
    } else {
      return true;
    }
  }
}