Files
citrus-cms/app/Functions/value-hints.php
T
2026-04-28 21:14:25 +03:00

70 lines
2.7 KiB
PHP

<?php
use Illuminate\Support\Facades\Cache;
function get_value_hints($tableName) {
// Tables that use value hints
$weldingRelatedTables = [
'weld_logs', 'w_p_s', 'prosedure_qualification_records',
'naks_certificates', 'naks_welders', 'welding_equipment',
'fit_up_welding_follow_ups', 'deleted_joints', 'repair_logs',
'radiographic_tests', 'ultrasonic_tests', 'magnetic_tests',
'dye_penetrant_tests', 'hardness_tests', 'p_m_i_tests', 'p_w_h_t_s', 'ferrits',
'v_t_logs', 'p_t_logs', 'nde_matrices'
];
// Columns that show hints
$hintColumns = [
'joint_type', 'joint_type_ru', 'type_of_joint', 'type_of_welds',
'welding_method', 'welding_process', 'process'
];
if (!in_array($tableName, $weldingRelatedTables)) {
return ['hints' => [], 'columns' => []];
}
$hints = Cache::remember('value_hints_data', 3600, function() {
$data = [];
// Joint types: short_name_en/ru -> definition_en + definition_ru + title
$jointTypes = db("joint_types")->whereNotNull("short_name_en")->get();
foreach($jointTypes as $jt) {
$hint = [];
if(!empty($jt->definition_en)) $hint[] = $jt->definition_en;
if(!empty($jt->definition_ru)) $hint[] = $jt->definition_ru;
if(!empty($jt->title)) $hint[] = $jt->title;
if(!empty($hint) && !empty($jt->short_name_en)) {
$data[$jt->short_name_en] = implode(' / ', array_unique($hint));
}
if(!empty($jt->short_name_ru) && !empty($hint)) {
$data[$jt->short_name_ru] = implode(' / ', array_unique($hint));
}
}
// Welding methods: iso_short_name/aws_short_name/ru_short_name -> definitions
$weldingMethods = db("welding_methods")->get();
foreach($weldingMethods as $wm) {
$hint = [];
if(!empty($wm->iso_4063_definition)) $hint[] = $wm->iso_4063_definition;
if(!empty($wm->russian_definition)) $hint[] = $wm->russian_definition;
if(!empty($hint)) {
if(!empty($wm->iso_short_name)) $data[$wm->iso_short_name] = implode(' / ', $hint);
if(!empty($wm->aws_short_name)) $data[$wm->aws_short_name] = implode(' / ', $hint);
if(!empty($wm->ru_short_name)) $data[$wm->ru_short_name] = implode(' / ', $hint);
if(!empty($wm->en_welding_number)) $data[$wm->en_welding_number] = implode(' / ', $hint);
}
}
return $data;
});
return ['hints' => $hints, 'columns' => $hintColumns];
}
function clear_value_hints_cache() {
Cache::forget('value_hints_data');
}