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






class DBWorkFieldGroups extends DBWork
{
  
  public function getNewObject()
  {
    return new FieldGroup();
  }

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

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

    return $tmp;
  }

  public function getFieldGroup($pGroup_Id)
  {
    $group_id = $this->dboperation->getInt4Sql($pGroup_Id);
    $this->dboperation->clear();
    $this->dboperation->query("SELECT fg.*\n
                               FROM web_fieldgroups fg \n
                               WHERE fg.id=" . $group_id);

    return $this->getFirstRow();
  }

  public function getFieldGroups()
  {
    $this->dboperation->clear();
    $this->dboperation->query('SELECT fg.* FROM web_fieldgroups fg');

    return $this->getAllRows();
  }

  public function getFieldGroupsbySightID($pSight_Id)
  {
    $sight_id = $this->dboperation->getInt4Sql($pSight_Id);
    $this->dboperation->clear();
    $this->dboperation->query("SELECT DISTINCT fg.* \n
                               FROM web_fieldgroups fg \n
                                    INNER JOIN web_fields f ON (f.fieldgroup_id=fg.id) \n
                                    INNER JOIN web_sights_fields wsf ON (f.id=wsf.field_id AND \n
                                                                         wsf.sight_id=" . $sight_id . ')
                               ORDER BY fg.description ASC');

    return $this->getAllRows();
  }
}