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


class DBWorkVeranstaltungsart extends DBWork
{
  public $select;

  public $orderby;

  public $angehakt;

  public function __construct($pDBnr = 1, $pNewInstance = false)
  {
    parent::__construct($pDBnr, $pNewInstance);
    $this->select = 'id, kennz, text, webfilter, webtext, webstdfilter';
    $this->angehakt = 'W';
    $this->orderby = 'id DESC';
  }

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

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

  public function getVeranstaltungsart($pId)
  {
    $id = $this->dboperation->getInt4Sql($pId);
    $this->dboperation->clear();
    $this->dboperation->query('SELECT ' . $this->select . ' FROM veranart WHERE id = \'' . $id . "'");

    return $this->getFirstRow();
  }

  
  public function getVeranstaltungsartByKennz($pKennz)
  {
    $kennz = $this->dboperation->getString4Sql($pKennz);
    $this->dboperation->clear();
    $this->dboperation->query('SELECT ' . $this->select . ' FROM veranart WHERE kennz = \'' . $kennz . '\'');

    return $this->getFirstRow();
  }

  
  public function getCurrentRow($pRefreshCache = false)
  {
    $ret = $this->getNewObject();
    $ret->id = $this->getDatamodulValue('id');
    $ret->kennz = $this->getDatamodulValue('kennz');
    $ret->text = $this->getDatamodulValue('text');
    $ret->webfilter = ($this->getDatamodulValue('webfilter') == $this->angehakt);
    $ret->webtext = $this->getDatamodulValue('webtext');
    $ret->webstdfilter = ($this->getDatamodulValue('webstdfilter') == $this->angehakt);

    return $ret;
  }

  
  public function getVeranstaltungsarten()
  {
    $this->dboperation->clear();
    $this->dboperation->query('SELECT ' . $this->select . ' FROM veranart order by ' . $this->orderby);

    return $this->getAllRows();
  }

  public function translateVarName($varname)
  {
    switch ($varname) {
      case 'kennzeichen': return 'kennz';
      default: return parent::translateVarName($varname);
     }
  }

  
  public function getSuchKriterien()
  {
    $this->angehakt = $this->dboperation->getString4Sql($this->angehakt);
    $sql = 'SELECT ' . $this->select . ' FROM veranart WHERE webfilter = \''
        . $this->angehakt . '\' order by ' . $this->orderby;
    $this->dboperation->clear();
    $this->dboperation->query($sql);

    return $this->getAllRows();
  }
}