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

if (!defined('BASEDIR')) {
  include_once '..' . DIRECTORY_SEPARATOR . 'constants.php';
}



class DBWorkMspKurse extends DBWorkGenerated
{
  public function __construct($pDBTyp = 1, $pNewInstance = false)
  {
    parent::__construct($pDBTyp, $pNewInstance);
    $this->select = 'id, sprache, feldname, knr, inhalt';
    $this->_dataModulFields = array('feldname', 'knr', 'inhalt', 'sprache', 'id');
  }

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

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

  
  public function getByLangId($pIds, $pLangId)
  {
    if (!is_array($pIds) || count($pIds) === 0) {
      return array();
    }
    $idStr = '(';
    foreach ($pIds as $id) {
      $idStr .= '\'' . $id . '\',';
    }
    
    $idStr = StringOperations::substr($idStr, 0, -1) . ')';

    $sql = 'SELECT ' . $this->select . ' FROM ' . $this->getTableName()
            . ' WHERE sprache=\'' . $pLangId . '\' and knr in ' . $idStr . ' order by knr';

    $this->dboperation->clear();
    $this->dboperation->query($sql);
    $result = array();
    foreach ($pIds as $id) {
      $result[$id] = array();
    }

    $rowCount = $this->dboperation->rowcount();

    for ($i = 0; $i < $rowCount; $i++) {
      $this->dboperation->selectrow($i);
      $id = $this->getDatamodulValue('knr');
      $result[$id][\StringOperations::strtolower($this->getDatamodulValue('feldname'))] = $this->getDatamodulValue('inhalt');
    }

    return $result;
  }

  
}