1
<?php
2
defined('ABSPATH') || exit;
3
require_once __DIR__ . '/elementor-widget-base.php';
4
if (!class_exists('FRESH_OO_Features_Widget') && class_exists('FRESH_OO_Widget_Base')) {
5
class FRESH_OO_Features_Widget extends FRESH_OO_Widget_Base {
6
public function get_name(): string { return 'fresh-oo-features'; }
7
public function get_title(): string { return 'onOffice Ausstattung'; }
8
public function get_icon(): string { return 'eicon-check-circle'; }
9
10
public static function default_items(): array {
11
return [
12
['field'=>'oo_balkon','label'=>'Balkon','icon'=>['value'=>'fas fa-building','library'=>'fa-solid'],'mode'=>'truthy'],
13
['field'=>'oo_terrasse','label'=>'Terrasse','icon'=>['value'=>'fas fa-umbrella-beach','library'=>'fa-solid'],'mode'=>'truthy'],
14
['field'=>'oo_fahrstuhl','label'=>'Fahrstuhl','icon'=>['value'=>'fas fa-arrows-alt-v','library'=>'fa-solid'],'mode'=>'truthy'],
15
['field'=>'oo_keller','label'=>'Keller','icon'=>['value'=>'fas fa-box','library'=>'fa-solid'],'mode'=>'truthy'],
16
['field'=>'oo_gartennutzung','label'=>'Garten','icon'=>['value'=>'fas fa-leaf','library'=>'fa-solid'],'mode'=>'truthy'],
17
['field'=>'oo_gaestewc','label'=>'Gäste-WC','icon'=>['value'=>'fas fa-restroom','library'=>'fa-solid'],'mode'=>'truthy'],
18
['field'=>'oo_barrierefrei','label'=>'Barrierefrei','icon'=>['value'=>'fas fa-universal-access','library'=>'fa-solid'],'mode'=>'truthy'],
19
['field'=>'oo_kabel_sat_tv','label'=>'Kabel / Sat-TV','icon'=>['value'=>'fas fa-satellite-dish','library'=>'fa-solid'],'mode'=>'truthy'],
20
['field'=>'oo_kamin','label'=>'Kamin','icon'=>['value'=>'fas fa-fire','library'=>'fa-solid'],'mode'=>'truthy'],
21
['field'=>'oo_klimatisiert','label'=>'Klimatisiert','icon'=>['value'=>'fas fa-snowflake','library'=>'fa-solid'],'mode'=>'truthy'],
22
['field'=>'oo_sauna','label'=>'Sauna','icon'=>['value'=>'fas fa-hot-tub','library'=>'fa-solid'],'mode'=>'truthy'],
23
['field'=>'oo_whirlpool','label'=>'Whirlpool','icon'=>['value'=>'fas fa-hot-tub','library'=>'fa-solid'],'mode'=>'truthy'],
24
['field'=>'oo_wintergarten','label'=>'Wintergarten','icon'=>['value'=>'fas fa-sun','library'=>'fa-solid'],'mode'=>'truthy'],
25
['field'=>'oo_einliegerwohnung','label'=>'Einliegerwohnung','icon'=>['value'=>'fas fa-home','library'=>'fa-solid'],'mode'=>'truthy'],
26
['field'=>'oo_denkmalgeschuetzt','label'=>'Denkmalschutz','icon'=>['value'=>'fas fa-landmark','library'=>'fa-solid'],'mode'=>'truthy'],
27
['field'=>'oo_unterkellert','label'=>'Unterkellert','icon'=>['value'=>'fas fa-box-open','library'=>'fa-solid'],'mode'=>'truthy'],
28
['field'=>'oo_warmwasserenthalten','label'=>'Warmwasser enthalten','icon'=>['value'=>'fas fa-tint','library'=>'fa-solid'],'mode'=>'truthy'],
29
['field'=>'oo_boden','label'=>'Boden','icon'=>['value'=>'fas fa-layer-group','library'=>'fa-solid'],'mode'=>'nonempty'],
30
['field'=>'oo_heizungsart','label'=>'Heizungsart','icon'=>['value'=>'fas fa-temperature-high','library'=>'fa-solid'],'mode'=>'nonempty'],
31
['field'=>'oo_befeuerung','label'=>'Befeuerung','icon'=>['value'=>'fas fa-fire-alt','library'=>'fa-solid'],'mode'=>'nonempty'],
32
['field'=>'oo_stellplatzart','label'=>'Stellplatz','icon'=>['value'=>'fas fa-parking','library'=>'fa-solid'],'mode'=>'nonempty'],
33
['field'=>'oo_multiparkinglot','label'=>'Stellplätze','icon'=>['value'=>'fas fa-car','library'=>'fa-solid'],'mode'=>'nonempty'],
34
['field'=>'oo_ausstattungsqualitaet','label'=>'Ausstattungsqualität','icon'=>['value'=>'fas fa-star','library'=>'fa-solid'],'mode'=>'nonempty'],
35
['field'=>'oo_internetaccesstype','label'=>'Internet','icon'=>['value'=>'fas fa-wifi','library'=>'fa-solid'],'mode'=>'nonempty'],
36
['field'=>'oo_haustiere','label'=>'Haustiere','icon'=>['value'=>'fas fa-paw','library'=>'fa-solid'],'mode'=>'truthy'],
37
['field'=>'oo_accessibility','label'=>'Zugänglichkeit','icon'=>['value'=>'fas fa-wheelchair','library'=>'fa-solid'],'mode'=>'nonempty'],
38
['field'=>'oo_facadetype','label'=>'Fassade','icon'=>['value'=>'fas fa-building','library'=>'fa-solid'],'mode'=>'nonempty'],
39
['field'=>'oo_angeschl_gastronomie','label'=>'Angeschlossene Gastronomie','icon'=>['value'=>'fas fa-utensils','library'=>'fa-solid'],'mode'=>'truthy'],
40
['field'=>'oo_bebaubar_nach','label'=>'Bebaubar nach','icon'=>['value'=>'fas fa-ruler-combined','library'=>'fa-solid'],'mode'=>'nonempty'],
41
['field'=>'oo_bebaubar_mit','label'=>'Bebaubar mit','icon'=>['value'=>'fas fa-drafting-compass','library'=>'fa-solid'],'mode'=>'nonempty'],
42
['field'=>'oo_erschliessung','label'=>'Erschließung','icon'=>['value'=>'fas fa-road','library'=>'fa-solid'],'mode'=>'nonempty'],
43
];
44
}
45
46
47
protected function feature_display_value(string $key, $value): string {
48
if ($key === 'oo_multiparkinglot') {
49
if (is_string($value) && is_serialized($value)) $value = maybe_unserialize($value);
50
if (!is_array($value)) return '';
51
$labels = [
52
'carport' => ['Carport','Carports'],
53
'duplex' => ['Doppelparker','Doppelparker'],
54
'parkingSpace' => ['Außenstellplatz','Außenstellplätze'],
55
'garage' => ['Garage','Garagen'],
56
'multiStoryGarage' => ['Parkhaus-Stellplatz','Parkhaus-Stellplätze'],
57
'undergroundGarage' => ['Tiefgaragenstellplatz','Tiefgaragenstellplätze'],
58
'otherParkingLot' => ['Sonstiger Stellplatz','Sonstige Stellplätze'],
59
];
60
$parts = [];
61
foreach ($value as $type => $data) {
62
if (!is_array($data)) continue;
63
$count = isset($data['Count']) && is_numeric($data['Count']) ? (int)$data['Count'] : 0;
64
if ($count < 1) continue;
65
$names = $labels[$type] ?? [ucwords(trim(preg_replace('/(?<!^)[A-Z]/', ' $0', (string)$type))), ucwords(trim(preg_replace('/(?<!^)[A-Z]/', ' $0', (string)$type)))];
66
$parts[] = $count . ' ' . ($count === 1 ? $names[0] : $names[1]);
67
}
68
return implode(', ', $parts);
69
}
70
if ($key === 'oo_haustiere') {
71
return $this->is_truthy($value) ? 'Ja' : '';
72
}
73
return $this->pretty_value($value, $key, $this->inferred_format($key));
74
}
75
76
protected function register_controls(): void {
77
$this->start_controls_section('content',['label'=>'Ausstattungsmerkmale']);
78
$r=new \Elementor\Repeater();
79
$r->add_control('field',['label'=>'Feld','type'=>\Elementor\Controls_Manager::SELECT2,'options'=>$this->field_options(true),'label_block'=>true]);
80
$r->add_control('label',['label'=>'Label','type'=>\Elementor\Controls_Manager::TEXT]);
81
$r->add_control('icon',['label'=>'Icon','type'=>\Elementor\Controls_Manager::ICONS]);
82
$r->add_control('mode',['label'=>'Anzeigen wenn','type'=>\Elementor\Controls_Manager::SELECT,'default'=>'truthy','options'=>['truthy'=>'Ja / vorhanden','nonempty'=>'Wert vorhanden','always'=>'Immer']]);
83
$this->add_control('items',['label'=>'Merkmale','type'=>\Elementor\Controls_Manager::REPEATER,'fields'=>$r->get_controls(),'default'=>self::default_items(),'title_field'=>'{{{ label || field }}}']);
84
$this->add_control('show_value',['label'=>'Wert zusätzlich anzeigen','type'=>\Elementor\Controls_Manager::SWITCHER,'default'=>'yes']);
85
$this->add_responsive_control('columns',['label'=>'Spalten','type'=>\Elementor\Controls_Manager::SELECT,'default'=>'3','tablet_default'=>'2','mobile_default'=>'1','options'=>['1'=>'1','2'=>'2','3'=>'3','4'=>'4','5'=>'5','6'=>'6'],'selectors'=>['{{WRAPPER}} .fresh-oo-features'=>'grid-template-columns:repeat({{VALUE}},minmax(0,1fr));']]);
86
$this->end_controls_section();
87
$this->start_controls_section('style',['label'=>'Styling','tab'=>\Elementor\Controls_Manager::TAB_STYLE]);
88
$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-features__item'=>'justify-content:{{VALUE}};']]);
89
$this->add_responsive_control('gap',['label'=>'Abstand','type'=>\Elementor\Controls_Manager::SLIDER,'range'=>['px'=>['min'=>0,'max'=>60]],'selectors'=>['{{WRAPPER}} .fresh-oo-features'=>'gap:{{SIZE}}{{UNIT}};']]);
90
$this->add_common_card_style_controls('item','{{WRAPPER}} .fresh-oo-features__item');
91
$this->add_control('icon_color',['label'=>'Icon','type'=>\Elementor\Controls_Manager::COLOR,'selectors'=>['{{WRAPPER}} .fresh-oo-features__icon'=>'color:{{VALUE}};']]);
92
$this->add_responsive_control('icon_size',['label'=>'Icon-Größe','type'=>\Elementor\Controls_Manager::SLIDER,'range'=>['px'=>['min'=>8,'max'=>72]],'selectors'=>['{{WRAPPER}} .fresh-oo-features__icon'=>'font-size:{{SIZE}}{{UNIT}};','{{WRAPPER}} .fresh-oo-features__icon svg'=>'width:{{SIZE}}{{UNIT}};height:{{SIZE}}{{UNIT}};']]);
93
$this->add_control('text_color',['label'=>'Text','type'=>\Elementor\Controls_Manager::COLOR,'selectors'=>['{{WRAPPER}} .fresh-oo-features__label'=>'color:{{VALUE}};']]);
94
$this->add_group_control(\Elementor\Group_Control_Typography::get_type(),['name'=>'text_typo','selector'=>'{{WRAPPER}} .fresh-oo-features__label']);
95
$this->end_controls_section();
96
}
97
98
protected function render(): void {
99
$s=$this->get_settings_for_display();
100
$defs=$this->field_definitions();
101
$rows=[];
102
foreach(($s['items']??[]) as $item){
103
$key=(string)($item['field']??'');
104
if(!$key) continue;
105
$v=$this->meta($key);
106
$mode=$item['mode']??'truthy';
107
$show=$mode==='always'||($mode==='nonempty'&&($key==='oo_multiparkinglot' ? $this->feature_display_value($key,$v)!=='' : $this->meaningful_value($v,$key,true)))||($mode==='truthy'&&$this->is_truthy($v));
108
if(!$show) continue;
109
$rows[]=[$item,$v,trim((string)($item['label']??''))?:($defs[$key][0]??$key),$key];
110
}
111
// Empty means empty: no placeholder, notice or frontend markup.
112
if(!$rows) return;
113
echo '<ul class="fresh-oo-features">';
114
foreach($rows as [$item,$v,$label,$key]){
115
echo '<li class="fresh-oo-features__item">';
116
$this->render_selected_icon($item['icon']??[],'fresh-oo-features__icon');
117
echo '<span class="fresh-oo-features__label">'.esc_html($label);
118
$type=$defs[$key][1]??'';
119
if(($s['show_value']??'')==='yes'&&$type!=='boolean') {
120
$display=$this->feature_display_value($key,$v);
121
if($display!=='') echo ' <small>'.esc_html($display).'</small>';
122
}
123
echo '</span></li>';
124
}
125
echo '</ul>';
126
}
127
}
128
}
129