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


class DBWorkFachAdr extends DBWorkGenerated
{
  public function __construct($pDBTyp = 1, $pNewInstance = false)
  {
    parent::__construct($pDBTyp, $pNewInstance);
    $this->select = 'nr, kennz';
    $this->_dataModulFields = array('nr', 'kennz');
  }

  
  public function getNewObject()
  {
    return new FachAdr();
  }

  public function getTableName(): string
  {
    return 'fach_adr';
  }

  public function getAllQuery(): \SelectQueryBuilder
  {
    return $this->getSelectQueryBuilder()
      ->select($this->select)
      ->from($this->getTableName(), 'fa');
  }

  
  public function findByKennzQuery($pFachKennzeichen): \SelectQueryBuilder
  {
    return $this->getAllQuery()
      ->and($this->dboperation->dbparser->caseInsensitiveLike('fa.', 'kennz', ':fachKennz:'))
      ->paramStringNoQuotes('fachKennz', $pFachKennzeichen . '%');
  }

  
  public function findByKennz($pFachKennzeichen)
  {
    $builder = $this->findByKennzQuery($pFachKennzeichen);
    $this->dboperation->clear();
    $this->dboperation->query($builder->getSQL());

    return $this->getAllRows();
  }

  
  public function findByKennzBereich($pFachKennzeichenFrom, $pFachKennzeichenTo)
  {
    $cleanKennzFrom = $this->dboperation->getString4Sql($pFachKennzeichenFrom);
    $cleanKennztTo = $this->dboperation->getString4Sql($pFachKennzeichenTo);

    $sql = 'SELECT ' . $this->select . ' FROM ' . $this->getTableName() . ' fa'
           . ' WHERE ' . $this->dboperation->dbparser->caseInsensitiveBetween('fa.', 'kennz', $cleanKennzFrom, $cleanKennztTo);

    $this->dboperation->clear();
    $this->dboperation->query($sql);

    return $this->getAllRows();
  }
}