Files
gutachten_t3/packages/gutachten/Classes/DB/Select/Select.php
T

322 lines
11 KiB
PHP

<?php
namespace HermannTelser\Gutachten\DB\Select;
// composer dump-autoload -o
use HermannTelser\Gutachten\DB\DbFunction;
use TYPO3\CMS\Core\Utility\GeneralUtility;
class Select
{
public static function select_table($table, $select_id = 0, $_id_as_key = 0, $_casting = [])
{
if ($select_id) {
$tmp = DbFunction::select($table, '*', ['id' => $select_id]);
} else {
$tmp = DbFunction::select($table, '*');
}
$arr = [];
foreach ($tmp as $key => $value) {
$value['id'] = (int) $value['id'];
foreach ($_casting as $field => $cast) {
if ($key == $field) {
switch ($cast) {
case 'int':
$value[$key] = (int) $value[$key];
break;
case 'double':
$value[$key] = (float) $value[$key];
break;
case 'string':
$value[$key] = (string) $value[$key];
break;
}
}
}
if ($_id_as_key) {
$arr[$value['id']] = $value;
} else {
$arr[] = $value;
}
}
return $arr;
}
// $sql = "SELECT a.*, b.zunutzwert FROM tt_raume_all a, tt_raume_generell b
// WHERE a.tt_raumart_id IN (2,8)
// AND a.tt_raume_basis_id = $tt_raume_basis_id
// AND a.raum=b.raum
// AND a.pid = $pid
// AND b.pid = $pid
// ORDER BY a.raum";
public static function orientierung_select()
{
$_orientierung = DbFunction::select('tx_gutachten_orientierung', ['id', 'orientierung'], ['ORDER' => 'sortierung']);
$arr = [];
foreach ($_orientierung as $key => $value) {
$tmp = [];
$tmp['id'] = $value['orientierung'];
$tmp['orientierung'] = $value['orientierung'];
$tmp['label'] = '<span class="dijitReset dijitMenuItem select_orientierung">'.$value['orientierung'].'</span>';
$arr[] = $tmp;
}
return $arr;
}
public static function projekte($projektid = 0)
{
$mode = GeneralUtility::_GP('mode');
$_gutachter = self::select_table('tx_gutachten_gutachter', 0, 1);
$_auftraggeber = self::select_table('tx_gutachten_auftraggeber', 0, 1);
$_active = self::projekte_active_user();
$_projekte = self::select_table('tx_gutachten_projekte', $projektid);
$arr = [];
foreach ($_projekte as $key => $value) {
$value['gutachter'] = $_gutachter[$value['gutachter_id']]['kennung'];
$value['auftraggeber'] = $_auftraggeber[$value['auftraggeber_id']]['kennung'];
$value['active'] = \in_array($value['id'], $_active) ? 1 : 0;
$arr[] = $value;
}
return $arr;
}
public static function aufstellung()
{
return self::select_table('tx_gutachten_aufstellung');
}
public static function text_art()
{
$result = DbFunction::select('tx_gutachten_textart', ['id', 'txt'],[ 'ORDER' => 'id']);
$arr = [];
$arr[0]['id'] = (int) 0;
$arr[0]['name'] = "0 - Bitte Wählen";
foreach ($result as $key => $value) {
$id = (int) $value['id'];
$arr[$id]['id'] = $id;
$arr[$id]['name'] = $id . " - " . ucwords($value['txt']);
}
return $arr;
}
public static function projekte_active_user()
{
return DbFunction::select('tx_gutachten_freigabe', 'projektid', ['userid' => $GLOBALS['TSFE']->fe_user->user['uid']]);
}
public static function raume_all($projektid, $tt_raume_basis_id, $tt_raumart_id, $out=0, $in=0)
{
/**
* Exepiton (in/out) info in mail from 08.01.2025 from Marie
* Fragestellung ist folgende:
* beim WE-Objekt KIGA (Kindergarten) gibt es einen Raum „Garten-Lager EG", der nur über den Garten EG erreicht wird.
* Der Garten ist ein Zubehör-Objekt zum KIGA (Methode 4).
* Der Raum „Garten-Lager EG“ soll nun dem Garten zugeordnet werden (quasi als Zuschlag zum Zubehör), und darunter angeführt werden.
* Siehe Anhang pdf auf Seite 15. (attachment in email)
* */
$where = [];
$where['AND']['pid'] = $projektid;
$where['AND']['tt_raume_basis_id'] = $tt_raume_basis_id;
if ($in) {
$where['AND']['OR']['id'] = [$in];
$where['AND']['OR']['tt_raumart_id'] = $tt_raumart_id;
}
else if ($out) {
$where['AND']['tt_raumart_id'] = $tt_raumart_id;
$where['AND']['id[!]'] = [$out];
}
else {
$where['AND']['tt_raumart_id'] = $tt_raumart_id;
}
$where['ORDER']['raum'] = 'ASC';
// if($in){
// $res = DbFunction::select(
// 'tx_gutachten_raume_all',
// '*',
// $where
// );
// print_r($res);
// exit;
// }
return DbFunction::select(
'tx_gutachten_raume_all',
'*',
$where
);
}
public static function methoden_by_raumart($raumart)
{
$tmp = DbFunction::select('tx_gutachten_raumart', 'id', ['raumart' => $raumart]);
if (isset($tmp[0]['id'])) {
return $tmp[0]['id'];
}
return 0;
}
public static function raeume_alle_orientierung($projektid)
{
// DbFunction::$debug = 1;
$res = DbFunction::select('tx_gutachten_orientierung', ['id', 'orientierung'], ['ORDER' => 'sortierung']);
$map = [];
foreach ($res as $field => $value) {
$map[$value['id']] = $value['orientierung'];
}
// $basis_stellplaetze = DbFunction::select('tx_gutachten_raume_all', 'tt_raume_basis_id', ['pid' => $projektid, 'raum' => ['Stellplatz+', 'Stellplatz']]);
$arr = DbFunction::select('tx_gutachten_raume_basis', '*', ['pid' => $projektid, 'noDispInOrientierung' => 0, 'ORDER' => 'topNr']);
foreach ($arr as $key => $value) {
$arr[$key]['orientierung'] = $map[$value['tt_orientierung_id']];
}
// $_range = range("a","u");
foreach ($arr as $key => $value) {
// foreach ($_range as $k => $char) {
// $arr[$key][$char] = (double) $value[$char];
// }
$arr[$key]['id'] = (int) $value['id'];
$arr[$key]['pid'] = (int) $value['pid'];
$arr[$key]['uid'] = (int) $value['uid'];
$arr[$key]['GNO'] = (int) $value['GNO'];
$arr[$key]['tt_orientierung_id'] = (int) $value['tt_orientierung_id'];
$arr[$key]['noDispInOrientierung'] = (int) $value['noDispInOrientierung'];
// $arr[$key]['bewertung'] = (double) $value['bewertung'];
// $arr[$key]['factor'] = (double) $value['factor'];
// $arr[$key]['qmM1'] = (double) $value['qmM1'];
// $arr[$key]['qmM1uM2'] = (double) $value['qmM1uM2'];
// $arr[$key]['qmM1uM2bis'] = (double) $value['qmM1uM2bis'];
// $arr[$key]['NWM1uM2'] = (double) $value['NWM1uM2'];
// $arr[$key]['qmM1uM2'] = (double) $value['qmM1uM2'];raume_all
// $arr[$key]['summe_az'] = (double) $value['summe_az'];
}
return $arr;
}
public static function raume_basis()
{
// $fields = ' a.id,
// a.topNr,
// b.geschoss,
// a.typ,
// 0 as nutzflaeche,
// 0 as logia,
// 0 as gesammtnutzflaeche,
// '.$title_list.',
// a.summe_az,
// a.bewertung';
//
// $from = 'tx_gutachten_raume_basis a, tx_gutachten_raume_all b';
// $where = 'b.tt_raume_basis_id = a.id';
// $where .= " and a.noDispInOrientierung=0 and b.tt_raumart_id = 1 and a.pid = $projektid";
$_fields = [
'tx_gutachten_raume_basis.id',
'tx_gutachten_raume_basis.topNr',
'tx_gutachten_raume_basis.typ',
'tx_gutachten_raume_basis.summe_az',
'tx_gutachten_raume_basis.bewertung',
'tx_gutachten_raume_all.geschoss',
];
$_titles = DbFunction::select('tx_gutachten_help', 'colid', ['pid' => $projektid]);
foreach ($_titles as $key => $colid) {
$_fields[] = 'tx_gutachten_raume_basis.'.$colid;
}
$arr = DbFunction::selectJoin(
'tx_gutachten_raume_basis',
['[>]tx_gutachten_raume_all' => ['tx_gutachten_raume_basis.id' => 'tt_raume_basis_id']],
$_fields,
[
'tx_gutachten_raume_basis.pid' => 17,
'GROUP' => 'tx_gutachten_raume_basis.id',
'ORDER' => ['tx_gutachten_raume_basis.topNr' => 'DESC'],
]
);
foreach ($arr as $key => $value) {
$arr[$key]['nutzflaeche'] = 0;
$arr[$key]['logia'] = 0;
$arr[$key]['gesammtnutzflaeche'] = 0;
}
return $arr;
}
public static function orientierung_typen_column_einzel()
{
$projektid = GeneralUtility::_GP('id');
if (!is_numeric($projektid)) {
return [];
}
$arr = DbFunction::select('tx_gutachten_help', ['id', 'colid', 'coltitel'], ['pid' => $projektid, 'ORDER' => 'colid']);
foreach ($arr as $key => $value) {
$arr[$key]['id'] = (int) $value['id'];
$arr[$key]['pos'] = (int) $key + 1;
}
return $arr;
}
public static function platzhalter($projektid)
{
$arr = Projekte::projekt_standards($projektid);
$_platzhalter = [];
foreach ($arr as $key => $value) {
preg_match_all('/###(.*)###/U', $value['txt'], $pat_array);
$_platzhalter = array_merge($_platzhalter, $pat_array[0]);
}
$_platzhalter = array_unique($_platzhalter);
DbFunction::delete('tx_gutachten_projekteplatzhalter', ['AND' => ['pid' => $projektid, 'code[!]' => $_platzhalter]]);
foreach ($_platzhalter as $key => $code) {
$arr = DbFunction::select('tx_gutachten_projekteplatzhalter', ['id', 'code', 'txt'], ['AND' => ['pid' => $projektid, 'code' => $code]]);
if (0 == \count($arr)) {
$_value_array = [];
$_value_array['code'] = $code;
$_value_array['pid'] = $projektid;
DbFunction::secureInsert('tx_gutachten_projekteplatzhalter', $_value_array);
} elseif (\count($arr) > 1) {
foreach ($arr as $key => $value) {
if ($key > 0) {
DbFunction::delete('tx_gutachten_projekteplatzhalter', ['id' => $value['id']]);
}
}
}
}
$arr = DbFunction::select('tx_gutachten_projekteplatzhalter', ['id', 'code', 'txt'], ['AND' => ['pid' => $projektid, 'code' => $_platzhalter]]);
foreach ($arr as $key => $value) {
$arr[$key]['code'] = html_entity_decode($value['code']);
$arr[$key]['txt'] = html_entity_decode($value['txt']);
}
return $arr;
}
}