1: <?php
2: /**
3: * Elementor Property Status Widget
4: *
5: * @package EPL
6: * @subpackage PageBuilders/Elementor/Widgets/Elements
7: * @since 3.6.0
8: */
9:
10: // Exit if accessed directly.
11: if ( ! defined( 'ABSPATH' ) ) {
12: exit;
13: }
14:
15: /**
16: * EPL_Elementor_Property_Status Class
17: *
18: * @since 3.6.0
19: */
20: class EPL_Elementor_Property_Status extends \Elementor\Widget_Base {
21: use EPL_Elementor_Dynamic_Widget;
22:
23: /**
24: * Get widget name.
25: *
26: * @return string
27: * @since 3.6.0 New: Elementor widgets (beta).
28: */
29: public function get_name() {
30: return 'epl-property-status';
31: }
32:
33: /**
34: * Get widget title.
35: *
36: * @return string
37: * @since 3.6.0 New: Elementor widgets (beta).
38: */
39: public function get_title() {
40: return esc_html__( 'Status', 'easy-property-listings' );
41: }
42:
43: /**
44: * Get widget icon.
45: *
46: * @return string
47: * @since 3.6.0 New: Elementor widgets (beta).
48: */
49: public function get_icon() {
50: return 'eicon-post-info';
51: }
52:
53: /**
54: * Get widget categories.
55: *
56: * @return array
57: * @since 3.6.0 New: Elementor widgets (beta).
58: */
59: public function get_categories() {
60: return array( 'epl-elements' );
61: }
62:
63: /**
64: * Get widget keywords.
65: *
66: * @return array
67: * @since 3.6.0 New: Elementor widgets (beta).
68: */
69: public function get_keywords() {
70: return array( 'property', 'status', 'stickers', 'sold', 'new', 'epl' );
71: }
72:
73: /**
74: * Register widget controls.
75: *
76: * @since 3.6.0 New: Elementor widgets (beta).
77: */
78: protected function register_controls() {
79: $this->start_controls_section(
80: 'section_labels',
81: array(
82: 'label' => esc_html__( 'Status Labels', 'easy-property-listings' ),
83: 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
84: )
85: );
86:
87: $labels = array(
88: 'current_sale_label' => array( __( 'Current Sale', 'easy-property-listings' ), __( 'For Sale', 'easy-property-listings' ) ),
89: 'current_rental_label' => array( __( 'Current Rental', 'easy-property-listings' ), __( 'For Lease', 'easy-property-listings' ) ),
90: 'current_com_sale_label' => array( __( 'Current Commercial Sale', 'easy-property-listings' ), __( 'For Sale', 'easy-property-listings' ) ),
91: 'current_com_lease_label' => array( __( 'Current Commercial Lease', 'easy-property-listings' ), __( 'For Lease', 'easy-property-listings' ) ),
92: 'current_com_both_label' => array( __( 'Current Commercial Sale/Lease', 'easy-property-listings' ), __( 'For Sale / Lease', 'easy-property-listings' ) ),
93: 'under_offer_label' => array( __( 'Under Offer', 'easy-property-listings' ), __( 'Under Offer', 'easy-property-listings' ) ),
94: 'sold_label' => array( __( 'Sold', 'easy-property-listings' ), __( 'Sold', 'easy-property-listings' ) ),
95: 'leased_label' => array( __( 'Leased', 'easy-property-listings' ), __( 'Leased', 'easy-property-listings' ) ),
96: 'withdrawn_label' => array( __( 'Withdrawn', 'easy-property-listings' ), __( 'Withdrawn', 'easy-property-listings' ) ),
97: 'offmarket_label' => array( __( 'Off Market', 'easy-property-listings' ), __( 'Off Market', 'easy-property-listings' ) ),
98: 'deleted_label' => array( __( 'Deleted', 'easy-property-listings' ), __( 'Deleted', 'easy-property-listings' ) ),
99: 'fallback_label' => array( __( 'Unknown Status', 'easy-property-listings' ), '' ),
100: );
101:
102: foreach ( $labels as $control => $label ) {
103: $this->add_control(
104: $control,
105: array(
106: 'label' => esc_html( $label[0] ),
107: 'type' => \Elementor\Controls_Manager::TEXT,
108: 'default' => esc_html( $label[1] ),
109: )
110: );
111: }
112:
113: $this->end_controls_section();
114:
115: // Style Section.
116: $this->start_controls_section(
117: 'section_style',
118: array(
119: 'label' => esc_html__( 'Style', 'easy-property-listings' ),
120: 'tab' => \Elementor\Controls_Manager::TAB_STYLE,
121: )
122: );
123:
124: $this->add_responsive_control(
125: 'margin',
126: array(
127: 'label' => esc_html__( 'Margin', 'easy-property-listings' ),
128: 'type' => \Elementor\Controls_Manager::DIMENSIONS,
129: 'size_units' => array( 'px', '%', 'em' ),
130: 'selectors' => array(
131: '{{WRAPPER}} .epl-property-status' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
132: ),
133: )
134: );
135:
136: $this->add_control(
137: 'text_color',
138: array(
139: 'label' => esc_html__( 'Text Color', 'easy-property-listings' ),
140: 'type' => \Elementor\Controls_Manager::COLOR,
141: 'selectors' => array( '{{WRAPPER}} .epl-property-status-label' => 'color: {{VALUE}};' ),
142: )
143: );
144:
145: $this->add_control(
146: 'background_color',
147: array(
148: 'label' => esc_html__( 'Default Background', 'easy-property-listings' ),
149: 'type' => \Elementor\Controls_Manager::COLOR,
150: 'selectors' => array( '{{WRAPPER}} .epl-property-status-label' => 'background-color: {{VALUE}};' ),
151: )
152: );
153:
154: $this->add_control(
155: 'background_heading',
156: array(
157: 'label' => esc_html__( 'Status Backgrounds', 'easy-property-listings' ),
158: 'type' => \Elementor\Controls_Manager::HEADING,
159: 'separator' => 'before',
160: )
161: );
162: $backgrounds = array(
163: 'current_sale_background' => array( 'Current Sale', 'current-sale' ),
164: 'current_rental_background' => array( 'Current Rental', 'current-rental' ),
165: 'current_com_sale_background' => array( 'Commercial Sale', 'current-commercial-sale' ),
166: 'current_com_lease_background' => array( 'Commercial Lease', 'current-commercial-lease' ),
167: 'current_com_both_background' => array( 'Commercial Sale/Lease', 'current-commercial-both' ),
168: 'under_offer_background' => array( 'Under Offer', 'under-offer' ),
169: 'sold_background' => array( 'Sold', 'sold' ),
170: 'leased_background' => array( 'Leased', 'leased' ),
171: 'withdrawn_background' => array( 'Withdrawn', 'withdrawn' ),
172: 'offmarket_background' => array( 'Off Market', 'offmarket' ),
173: 'deleted_background' => array( 'Deleted', 'deleted' ),
174: );
175: foreach ( $backgrounds as $control => $background ) {
176: $this->add_control(
177: $control,
178: array(
179: 'label' => esc_html( $background[0] ),
180: 'type' => \Elementor\Controls_Manager::COLOR,
181: 'selectors' => array( '{{WRAPPER}} .epl-property-status-kind-' . $background[1] . ' .epl-property-status-label' => 'background-color: {{VALUE}};' ),
182: )
183: );
184: }
185:
186: $this->add_responsive_control(
187: 'padding',
188: array(
189: 'label' => esc_html__( 'Padding', 'easy-property-listings' ),
190: 'type' => \Elementor\Controls_Manager::DIMENSIONS,
191: 'size_units' => array( 'px', 'em' ),
192: 'selectors' => array( '{{WRAPPER}} .epl-property-status-label' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ),
193: )
194: );
195:
196: $this->add_responsive_control(
197: 'border_radius',
198: array(
199: 'label' => esc_html__( 'Border Radius', 'easy-property-listings' ),
200: 'type' => \Elementor\Controls_Manager::DIMENSIONS,
201: 'size_units' => array( 'px', '%' ),
202: 'selectors' => array( '{{WRAPPER}} .epl-property-status-label' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ),
203: )
204: );
205:
206: $this->add_group_control(
207: \Elementor\Group_Control_Typography::get_type(),
208: array(
209: 'name' => 'typography',
210: 'selector' => '{{WRAPPER}} .epl-property-status-label',
211: )
212: );
213:
214: $this->add_responsive_control(
215: 'align',
216: array(
217: 'label' => esc_html__( 'Alignment', 'easy-property-listings' ),
218: 'type' => \Elementor\Controls_Manager::CHOOSE,
219: 'options' => array(
220: 'left' => array(
221: 'title' => esc_html__( 'Left', 'easy-property-listings' ),
222: 'icon' => 'eicon-text-align-left',
223: ),
224: 'center' => array(
225: 'title' => esc_html__( 'Center', 'easy-property-listings' ),
226: 'icon' => 'eicon-text-align-center',
227: ),
228: 'right' => array(
229: 'title' => esc_html__( 'Right', 'easy-property-listings' ),
230: 'icon' => 'eicon-text-align-right',
231: ),
232: ),
233: 'selectors' => array(
234: '{{WRAPPER}} .epl-property-status' => 'text-align: {{VALUE}};',
235: ),
236: )
237: );
238:
239: $this->end_controls_section();
240: }
241:
242: /**
243: * Render widget output.
244: *
245: * @since 3.6.0 New: Elementor widgets (beta).
246: * @since 3.6.0 Uses is_under_offer(), so its filter applies.
247: */
248: protected function render() {
249: $property = EPL_Elementor::setup_listing_context();
250: $is_editor = \Elementor\Plugin::$instance->editor->is_edit_mode();
251:
252: if ( ! $property ) {
253: if ( $is_editor ) {
254: echo '<div class="epl-elementor-placeholder">' . esc_html__( 'Property Status - No listings found.', 'easy-property-listings' ) . '</div>';
255: }
256: EPL_Elementor::restore_listing_context();
257: return;
258: }
259:
260: $settings = $this->get_settings_for_display();
261: $status = sanitize_key( (string) $property->get_property_meta( 'property_status' ) );
262: $status = $status ? $status : 'current';
263: $label = '';
264: $kind = $status;
265:
266: if ( 'current' === $status && $property->is_under_offer() ) {
267: $label = $settings['under_offer_label'];
268: $kind = 'under-offer';
269: } elseif ( 'current' === $status ) {
270: $post_type = $property->post->post_type;
271: if ( 'rental' === $post_type ) {
272: $label = $settings['current_rental_label'];
273: $kind = 'current-rental';
274: } elseif ( in_array( $post_type, array( 'commercial', 'commercial_land', 'business' ), true ) ) {
275: $listing_type = $property->get_property_meta( 'property_com_listing_type' );
276: if ( 'lease' === $listing_type ) {
277: $label = $settings['current_com_lease_label'];
278: $kind = 'current-commercial-lease';
279: } elseif ( 'both' === $listing_type ) {
280: $label = $settings['current_com_both_label'];
281: $kind = 'current-commercial-both';
282: } else {
283: $label = $settings['current_com_sale_label'];
284: $kind = 'current-commercial-sale';
285: }
286: } else {
287: $label = $settings['current_sale_label'];
288: $kind = 'current-sale';
289: }
290: } else {
291: $key = $status . '_label';
292: $label = isset( $settings[ $key ] ) ? $settings[ $key ] : $settings['fallback_label'];
293: }
294:
295: $label = apply_filters( 'epl_elementor_property_status_label', $label, $status, $property, $settings );
296: if ( '' !== trim( (string) $label ) ) {
297: echo '<div class="epl-property-status epl-property-status-' . esc_attr( $status ) . ' epl-property-status-kind-' . esc_attr( $kind ) . '"><span class="epl-property-status-label">' . esc_html( $label ) . '</span></div>';
298: }
299:
300: EPL_Elementor::restore_listing_context();
301: }
302: }
303: