1
<?php
2
defined('ABSPATH') || exit;
3
require_once __DIR__ . '/elementor-widget-base.php';
4
if (!class_exists('FRESH_OO_Field_Group_Widget') && class_exists('FRESH_OO_Widget_Base')) {
5
class FRESH_OO_Field_Group_Widget extends FRESH_OO_Widget_Base {
6
public function get_name(): string { return 'fresh-oo-field-group'; }
7
public function get_title(): string { return 'onOffice Feldgruppe'; }
8
public function get_icon(): string { return 'eicon-icon-list'; }
9
public function get_keywords(): array { return ['onoffice','facts','icons','fields','immobilie']; }
10
protected function register_controls(): void {
11
$this->start_controls_section('content',['label'=>'Felder']);
12
$r=new \Elementor\Repeater();
13
$r->add_control('field',['label'=>'Feld','type'=>\Elementor\Controls_Manager::SELECT2,'options'=>$this->field_options(true),'label_block'=>true]);
14
$r->add_control('label',['label'=>'Label','type'=>\Elementor\Controls_Manager::TEXT,'placeholder'=>'Automatisch']);
15
$r->add_control('format',['label'=>'Format','type'=>\Elementor\Controls_Manager::SELECT,'default'=>'auto','options'=>['auto'=>'Automatisch','text'=>'Text','integer'=>'Ganzzahl','number'=>'Zahl','year'=>'Jahr','date'=>'Datum','price'=>'Preis','area'=>'Fläche','energy'=>'Energie','boolean'=>'Ja / Nein']]);
16
$r->add_control('icon',['label'=>'Icon','type'=>\Elementor\Controls_Manager::ICONS]);
17
$r->add_control('suffix',['label'=>'Zusatz-Suffix','type'=>\Elementor\Controls_Manager::TEXT]);
18
$this->add_control('items',['label'=>'Felder','type'=>\Elementor\Controls_Manager::REPEATER,'fields'=>$r->get_controls(),'default'=>[
19
['field'=>'oo_wohnflaeche','label'=>'Wohnfläche','icon'=>['value'=>'fas fa-ruler-combined','library'=>'fa-solid']],
20
['field'=>'oo_anzahl_zimmer','label'=>'Zimmer','icon'=>['value'=>'far fa-square','library'=>'fa-regular']],
21
['field'=>'oo_anzahl_schlafzimmer','label'=>'Schlafzimmer','icon'=>['value'=>'fas fa-bed','library'=>'fa-solid']],
22
['field'=>'oo_anzahl_badezimmer','label'=>'Bäder','icon'=>['value'=>'fas fa-bath','library'=>'fa-solid']],
23
],'title_field'=>'{{{ label || field }}}']);
24
$this->add_control('show_labels',['label'=>'Labels anzeigen','type'=>\Elementor\Controls_Manager::SWITCHER,'default'=>'yes']);
25
$this->add_control('hide_empty',['label'=>'Leere Felder ausblenden','type'=>\Elementor\Controls_Manager::SWITCHER,'default'=>'yes']);
26
$this->end_controls_section();
27
$this->start_controls_section('layout',['label'=>'Layout']);
28
$this->add_responsive_control('columns',['label'=>'Spalten','type'=>\Elementor\Controls_Manager::SELECT,'default'=>'4','tablet_default'=>'2','mobile_default'=>'2','options'=>['1'=>'1','2'=>'2','3'=>'3','4'=>'4','5'=>'5','6'=>'6'],'selectors'=>['{{WRAPPER}} .fresh-oo-field-group'=>'grid-template-columns: repeat({{VALUE}}, minmax(0,1fr));']]);
29
$this->add_responsive_control('align',['label'=>'Ausrichtung','type'=>\Elementor\Controls_Manager::CHOOSE,'options'=>['flex-start'=>['title'=>'Links','icon'=>'eicon-text-align-left'],'center'=>['title'=>'Mitte','icon'=>'eicon-text-align-center'],'flex-end'=>['title'=>'Rechts','icon'=>'eicon-text-align-right']],'default'=>'flex-start','selectors'=>['{{WRAPPER}} .fresh-oo-field-group__item'=>'justify-content:{{VALUE}};']]);
30
$this->add_responsive_control('gap',['label'=>'Abstand','type'=>\Elementor\Controls_Manager::SLIDER,'range'=>['px'=>['min'=>0,'max'=>80]],'default'=>['size'=>16],'selectors'=>['{{WRAPPER}} .fresh-oo-field-group'=>'gap: {{SIZE}}{{UNIT}};']]);
31
$this->end_controls_section();
32
$this->start_controls_section('style_item',['label'=>'Karten','tab'=>\Elementor\Controls_Manager::TAB_STYLE]);
33
$this->add_common_card_style_controls('item','{{WRAPPER}} .fresh-oo-field-group__item');
34
$this->add_control('icon_color',['label'=>'Icon-Farbe','type'=>\Elementor\Controls_Manager::COLOR,'selectors'=>['{{WRAPPER}} .fresh-oo-field-group__icon'=>'color: {{VALUE}};']]);
35
$this->add_responsive_control('icon_size',['label'=>'Icon-Größe','type'=>\Elementor\Controls_Manager::SLIDER,'range'=>['px'=>['min'=>10,'max'=>80]],'selectors'=>['{{WRAPPER}} .fresh-oo-field-group__icon svg'=>'width:{{SIZE}}{{UNIT}};height:{{SIZE}}{{UNIT}};']]);
36
$this->add_control('label_color',['label'=>'Label','type'=>\Elementor\Controls_Manager::COLOR,'selectors'=>['{{WRAPPER}} .fresh-oo-field-group__label'=>'color:{{VALUE}};']]);
37
$this->add_group_control(\Elementor\Group_Control_Typography::get_type(),['name'=>'label_typo','selector'=>'{{WRAPPER}} .fresh-oo-field-group__label']);
38
$this->add_control('value_color',['label'=>'Wert','type'=>\Elementor\Controls_Manager::COLOR,'selectors'=>['{{WRAPPER}} .fresh-oo-field-group__value'=>'color:{{VALUE}};']]);
39
$this->add_group_control(\Elementor\Group_Control_Typography::get_type(),['name'=>'value_typo','selector'=>'{{WRAPPER}} .fresh-oo-field-group__value']);
40
$this->end_controls_section();
41
}
42
protected function render(): void {
43
$s=$this->get_settings_for_display(); $out=[]; $defs=$this->field_definitions();
44
foreach (($s['items']??[]) as $item) { $key=(string)($item['field']??''); if(!$key)continue; $v=$this->meta($key); if(!$this->meaningful_value($v,$key,true)&&($s['hide_empty']??'yes')==='yes')continue; $fmt=($item['format']??'auto')==='auto'?$this->inferred_format($key):$item['format']; $d=$this->pretty_value($v,$key,$fmt); if($d==='')continue; $out[]=[$item,$d,trim((string)($item['label']??''))?:($defs[$key][0]??$key)]; }
45
if(!$out){$this->editor_empty('Für die gewählten Felder gibt es aktuell keine Werte.');return;}
46
echo '<div class="fresh-oo-field-group">'; foreach($out as [$item,$display,$label]) { echo '<div class="fresh-oo-field-group__item">';$this->render_selected_icon($item['icon']??[],'fresh-oo-field-group__icon'); echo '<div class="fresh-oo-field-group__text">';if(($s['show_labels']??'yes')==='yes')echo '<span class="fresh-oo-field-group__label">'.esc_html($label).'</span>';echo '<span class="fresh-oo-field-group__value">'.esc_html($display).esc_html((string)($item['suffix']??'')).'</span></div></div>'; } echo '</div>';
47
}
48
}
49
}
50