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


class DBWorkHLTNAusbildung extends DBWork
{
  public function __construct($pDBTyp = 1, $pNewInstance = false)
  {
    parent::__construct($pDBTyp, $pNewInstance);

    $fields = array('ID', 'Ausb_Stud', 'Fachrichtung', 'Abschluss');
    $this->select = \implode(', ', \array_map(\FunctionOperations::prefixString('hlaaus.'), $fields));
  }

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

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

  
  public function getCurrentRow($pRefreshCache = false)
  {
    $obj = $this->getNewObject();

    $obj->id = $this->getDatamodulValue('ID');
    $obj->ausb_stud = $this->getDatamodulValue('Ausb_Stud');
    $obj->fachrichtung = $this->getDatamodulValue('Fachrichtung');
    $obj->abschluss = $this->getDatamodulValue('Abschluss');

    return $obj;
  }

  protected function getAusbildungenQuery(): SelectQueryBuilder
  {
    $query = $this->getSelectQueryBuilder();

    return $query->select($this->select)
                   ->from($this->getTableName(), 'hlaaus');
  }

  public function getAusbildungen()
  {
    $query = $this->getAusbildungenQuery();

    $this->dboperation->clear();
    $this->dboperation->query($query->getSQL());

    return $this->getAllRows();
  }

  
  protected function getAusbildungQueryById($pID): SelectQueryBuilder
  {
    $query = $this->getAusbildungenQuery();

    return $query->and('hlaaus.ID = :pID:')
                   ->paramInt('pID', $pID);
  }

  
  protected function getAusbildungById($pID): HLTNAusbildung
  {
    $query = $this->getAusbildungQueryById($pID);

    $this->dboperation->clear();
    $this->dboperation->query($query->getSQL());

    return $this->getFirstRow();
  }
}