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


class SearchOperations
{
  
  public static function getArrayIndexbyfieldname($ary, $idfield, $idvalue)
  {
    
    $counter = count($ary);
    for ($i = 0; $i < $counter; $i++) {
      if ($ary[$i]->getVarValue($idfield) == $idvalue) {
        return $i;
      }
    }

    return -1;
  }

  
  public static function getArrayIndexbyfieldnameCount($ary, $idfield, $idvalue, $count = 1)
  {
    $c = 0;
    for ($i = 0; $i < count($ary); $i++) {
      if ($ary[$i]->getVarValue($idfield) == $idvalue) {
        $c++;
        if ($c == $count) {
          return $i;
        }
      }
    }

    return -1;
  }

  
  public static function getArrayIndexbyfieldnameUpper($ary, $idfield, $idvalue)
  {
    for ($i = 0; $i < count($ary); $i ++) {
      if (StringOperations::strtoupper($ary[$i]->getVarValue($idfield)) == StringOperations::strtoupper($idvalue)) {
        return $i;
      }
    }

    return -1;
  }
}