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


class DBWorkHLSachgebiete extends DBWorkGenerated
{
  public function __construct($pDBTyp = 1, $pNewInstance = false)
  {
    parent::__construct($pDBTyp, $pNewInstance);
    $this->select = 'hl.id, hl.sachg, hl.text';
    $this->_dataModulFields = array('text', 'sachg', 'id');
  }

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

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

  
  public function getHLSachgebieteByTnr($pTnr)
  {
    $tnr = $this->dboperation->getInt4Sql($pTnr);
    if ($this->getTableName() == '') {
      throw new Exception('ungültiger Aufruf, ' . __CLASS__ . ' ist nicht dafür vorbereitet');
    }
    $sql = "SELECT $this->select FROM " . $this->getTableName() . ' '
           . 'INNER JOIN sachgebiete s ON hl.sachg = s.sachg '
           . "WHERE s.typ = 'T' AND s.nr = " . $tnr;
    if ($this->orderby != '') {
      $sql .= $this->getCompleteOrderByDefault($this->orderby);
    }
    $this->dboperation->clear();
    $this->dboperation->query($sql);

    return $this->getAllRows();
  }
}