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


class DBWorkKursplanungDokumente extends DBWorkGenerated
{
  public function __construct($pDBTyp = 1, $pNewInstance = false)
  {
    parent::__construct($pDBTyp, $pNewInstance);
    $this->select = 'id, kursplanung_id, dokument, dateiname, bemerkung, beschreibung';
    $this->_dataModulFields = array('kursplanung_id', 'dateiname', 'dokument', 'beschreibung', 'bemerkung', 'id');
    $this->orderby = 'dateiname';
  }

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

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

  public function getDokumenteByKursplanungIds($pKursplanungIds)
  {
    if (count($pKursplanungIds) === 0) {
      return array();
    }

    $query = $this->getSelectQueryBuilder();
    $query->select($this->select)
          ->from($this->getTableName())
          ->where('kursplanung_id IN (:kursplanungids:)')
          ->paramIntArray('kursplanungids', $pKursplanungIds);
    $this->dboperation->clear();
    $this->dboperation->query($query->getSQL());

    return $this->getAllRows();
  }

  
  public function deleteDokumenteByKursplanungId($pKursplanungId)
  {
    $cleanPlanungId = $this->dboperation->getInt4Sql($pKursplanungId);

    $this->dboperation->clear();
    $this->dboperation->execute('DELETE FROM ' . $this->getTableName() . ' WHERE kursplanung_id=' . $cleanPlanungId);
  }

  public function insertOne($pDatamodul, $pDummyField, string $pIdFieldName = 'id', bool $pDontProtocol = false, bool $pDmzBetrieb = false): int
  {
    $inserter = new \DBInserterOhneGenTable($this, $this->getTableName(), $this->_dataModulFields);
    $pDatamodul->id = $inserter->insert($pDatamodul, $pIdFieldName, $pDontProtocol, $pDmzBetrieb);

    return $pDatamodul->id;
  }
}