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


class DBWorkHLFreifeld extends DBWorkHLBasis
{
  public function __construct($pDBTyp = 1, $pNewInstance = false)
  {
    parent::__construct($pDBTyp, $pNewInstance);
    $this->select = 'id, typ, nr, text ';
    $this->orderby = ' id ';
  }

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

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

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

    return $tmp;
  }

  
  public function getFreifeldTextByTypAndNr($pTyp, $pNr)
  {
    $typ = $this->dboperation->getString4Sql($pTyp);
    $nr = $this->dboperation->getInt4Sql($pNr);
    $sql = 'select ' . $this->select . ' FROM hlfreifeld';
    $sql .= " WHERE typ = '" . $typ . "'";
    $sql .= " AND nr = '" . $nr . "'";
    $sql .= ' ORDER BY ' . $this->orderby;
    $this->dboperation->clear();
    $this->dboperation->query($sql);

    return $this->getAllRows();
  }

  
  public function getFreifeldTextByTyp($pTyp)
  {
    $typ = $this->dboperation->getString4Sql($pTyp);
    $sql = 'SELECT ' . $this->select . ' FROM hlfreifeld';
    $sql .= " WHERE typ = '" . $typ . "'";
    $sql .= ' ORDER BY nr ASC, id ASC';
    $this->dboperation->clear();
    $this->dboperation->query($sql);

    return $this->getAllRows();
  }
}