<?php
/**
 * @copyright (c) Kufer Software GmbH, Oderstraße 7, D-84453 Mühldorf
 */

if (!defined('BASEDIR')) {
  include_once '..' . DIRECTORY_SEPARATOR . 'constants.php';
}


class DBWorkFpKontingent extends DBWorkGenerated
{
  public function __construct($pDBTyp = 1, $pNewInstance = false)
  {
    parent::__construct($pDBTyp, $pNewInstance);
    $this->select = 'id, tnr, kat_id, kontingent, aktiv';
    $this->_dataModulFields = array('tnr', 'kat_id', 'kontingent', 'aktiv', 'id');
  }

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

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

  public function getSearchSQL($pPraeffix)
  {
    $praeffix = $this->dboperation->getString4Sql($pPraeffix);
    if (StringOperations::strlen($praeffix) > 0 && !(new StringObj($praeffix))->endsWith('.')) {
      $praeffix .= '.';
    }
    $sql = '';
    if (isset($this->fromobject)) {
      if (isset($this->fromobject->tnr) && $this->fromobject->tnr > 0) {
        $sql .= ' AND ' . $praeffix . 'tnr = ' . $this->dboperation->getInt4Sql($this->fromobject->tnr);
      }
      if (isset($this->fromobject->kat_id) && $this->fromobject->kat_id > 0) {
        $sql .= ' AND ' . $praeffix . 'kat_id = ' . $this->dboperation->getInt4Sql($this->fromobject->kat_id);
      }
    }
    if (isset($this->fromobject) && $this->fromobject->aktiv != '') {
      $sql .= ' AND ' . $praeffix . 'aktiv = ' . $this->dboperation->getInt4Sql($this->fromobject->aktiv);
    } else {
      $sql .= ' AND ' . $praeffix . 'aktiv = 1';
    }

    return $sql;
  }
}