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


class DBWorkGebaeudeSmall extends DBWork
{ 
  public function __construct($pDBTyp = 1, $pNewInstance = false)
  {
    parent::__construct($pDBTyp, $pNewInstance);
    $this->select = 'id, name';
  }

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

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

  
  public function getSearchSQL($praeffix)
  {
    return '';
  }

  
  public function getSearchSQLINetAktiv($praeffix)
  {
    return ' ' . $this->dboperation->dbparser->isNull($praeffix . 'internetaktiv', '\'F\'') . ' = \'W\'';
  }

  
  public function getCurrentRow($pRefreshCache = false)
  {
    $tmp = $this->getNewObject();
    $tmp->id = $this->getDatamodulValue('id');
    $tmp->name = $this->getDatamodulValue('name');

    return $tmp;
  }

  public function getGebaeude()
  {
    $this->dboperation->clear();
    $sql = 'SELECT ' . $this->select . ' FROM gebaeude WHERE '
        . $this->getSearchSQLINetAktiv('') . ' ORDER BY sortierfeld, name';
    $this->dboperation->query($sql);

    return $this->getAllRows();
  }

  
  public function getGebaeudeByAussenst($pAussenst)
  {
    $aussenst = $this->dboperation->getString4Sql($pAussenst);
    $sql = 'SELECT ' . $this->select . ' FROM gebaeude g '
          . ' WHERE g.aussenstelle like \'' . $aussenst . '%\' AND ' . $this->getSearchSQLINetAktiv('g.')
          . ' ORDER by g.sortierfeld, g.name';
    $this->dboperation->query($sql);

    return $this->getAllRows();
  }
}