PluginProbe
WP Directory Kit / 1.5.9
WP Directory Kit v1.5.9
1.5.9 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.8 All 37 releases
wpdirectorykit / elementor-elements / classes / wdk-listing-related-listings-table.php

wdk-listing-related-listings-table.php in WP Directory Kit 1.5.9, at elementor-elements/classes/wdk-listing-related-listings-table.php

506 lines 16.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Wdk\Elementor\Widgets;
4
5 use Wdk\Elementor\Widgets\WdkElementorBase;
6 use Elementor\Widget_Base;
7 use Elementor\Controls_Manager;
8 use Elementor\Utils;
9 use Elementor\Typography;
10 use Elementor\Editor;
11 use Elementor\Plugin;
12 use Elementor\Repeater;
13 use Elementor\Core\Schemes;
14 use Elementor\Icons_Manager;
15 use Elementor\Group_Control_Typography;
16 use Elementor\Group_Control_Border;
17 use Elementor\Group_Control_Box_Shadow;
18
19 if (!defined('ABSPATH'))
20 exit; // Exit if accessed directly
21
22 /**
23 * @since 1.1.0
24 */
25 class WdkListingRelatedListingsTable extends WdkElementorBase {
26
27 public function __construct($data = array(), $args = null) {
28
29 \Elementor\Controls_Manager::add_tab(
30 'tab_conf',
31 esc_html__('Settings', 'wpdirectorykit')
32 );
33
34 \Elementor\Controls_Manager::add_tab(
35 'tab_layout',
36 esc_html__('Layout', 'wpdirectorykit')
37 );
38
39 \Elementor\Controls_Manager::add_tab(
40 'tab_content',
41 esc_html__('Main', 'wpdirectorykit')
42 );
43
44 if ($this->is_edit_mode_load()) {
45 $this->enqueue_styles_scripts();
46 }
47
48 parent::__construct($data, $args);
49 }
50
51 /**
52 * Retrieve the widget name.
53 *
54 * @since 1.1.0
55 *
56 * @access public
57 *
58 * @return string Widget name.
59 */
60 public function get_name() {
61 return 'wdk-listing-related-listings-table';
62 }
63
64 /**
65 * Retrieve the list of categories the widget belongs to.
66 *
67 * Used to determine where to display the widget in the editor.
68 *
69 * Note that currently Elementor supports only one category.
70 * When multiple categories passed, Elementor uses the first one.
71 *
72 * @since 1.1.0
73 *
74 * @access public
75 *
76 * @return array Widget categories.
77 */
78 public function get_categories() {
79 return [ 'wdk-elementor-listing-preview' ];
80 }
81
82 /**
83 * Retrieve the widget title.
84 *
85 * @since 1.1.0
86 *
87 * @access public
88 *
89 * @return string Widget title.
90 */
91 public function get_title() {
92 return esc_html__('Wdk Related Listings Table', 'wpdirectorykit');
93 }
94
95 /**
96 * Retrieve the widget icon.
97 *
98 * @since 1.1.0
99 *
100 * @access public
101 *
102 * @return string Widget icon.
103 */
104 public function get_icon() {
105 return 'eicon-products';
106 }
107
108 /**
109 * Register the widget controls.
110 *
111 * Adds different input fields to allow the user to change and customize the widget settings.
112 *
113 * @since 1.1.0
114 *
115 * @access protected
116 */
117 protected function register_controls() {
118 $this->generate_controls_conf();
119 $this->generate_controls_layout();
120 $this->generate_controls_styles();
121 $this->generate_controls_content();
122
123 $this->insert_pro_message('tab_conf');
124 parent::register_controls();
125 }
126
127 /**
128 * Render the widget output on the frontend.
129 *
130 * Written in PHP and used to generate the final HTML.
131 *
132 * @since 1.1.0
133 *
134 * @access protected
135 */
136 protected function render() {
137 parent::render();
138 global $wdk_listing_id;
139
140 $this->data['id_element'] = $this->get_id();
141 $this->data['settings'] = $this->get_settings();
142
143 $this->data['listings_count'] = 0;
144 $this->data['results'] = array();
145 $this->data['pagination_output'] = '';
146
147 if(Plugin::$instance->editor->is_edit_mode()) {
148 $this->data['results'] = $this->WMVC->listing_m->get_pagination(6, 0, array('is_activated' => 1,'is_approved'=>1));
149 } else {
150 if(!wdk_get_option('wdk_sub_listings_enable')) {
151 return false;
152 }
153
154 if(empty(wdk_field_value('listing_related_ids', $wdk_listing_id))) {
155 return false;
156 }
157
158 $this->WMVC->db->where( $this->WMVC->db->prefix.'wdk_listings.post_id IN(' . wdk_field_value('listing_related_ids', $wdk_listing_id) . ')', null, false);
159 $this->WMVC->db->where(array('is_activated' => 1, 'is_approved'=>1));
160 $this->WMVC->db->order_by('FIELD('.$this->WMVC->db->prefix.'wdk_listings.post_id, '. wdk_field_value('listing_related_ids', $wdk_listing_id) . ')');
161
162 $this->data['results'] = $this->WMVC->listing_m->get();
163 }
164
165
166 $this->data['is_edit_mode'] = false;
167 if(Plugin::$instance->editor->is_edit_mode())
168 $this->data['is_edit_mode'] = true;
169
170 $this->view('wdk-listing-related-listings-table', $this->data, true);
171 }
172
173 private function generate_controls_conf()
174 {
175
176 $this->start_controls_section(
177 'tab_conf_main_section_subslistings',
178 [
179 'label' => esc_html__('Related Listings', 'wpdirectorykit'),
180 'tab' => 'tab_conf',
181 ]
182 );
183
184 $fields_data = wdk_cached_field_get();
185 $fields_list = array('' => esc_html__('Not Selected', 'wpdirectorykit'));
186 $order_i = 0;
187
188 $fields_list [(++$order_i).'__section'] = esc_html__('-- Section Custom fields --', 'wpdirectorykit');
189 $fields_list [(++$order_i).'__idlisting'] = esc_html__('Id listing', 'wpdirectorykit');
190 $fields_list [(++$order_i).'__post_id'] = esc_html__('Post Id', 'wpdirectorykit');
191 $fields_list [(++$order_i).'__counter_views'] = esc_html__('Views counter', 'wpdirectorykit');
192 $fields_list [(++$order_i).'__lat'] = esc_html__('Gps Lat', 'wpdirectorykit');
193 $fields_list [(++$order_i).'__lng'] = esc_html__('Gps Lng', 'wpdirectorykit');
194 $fields_list [(++$order_i).'__date'] = esc_html__('Date', 'wpdirectorykit');
195 $fields_list [(++$order_i).'__date_modified'] = esc_html__('Date Modified', 'wpdirectorykit');
196 $fields_list [(++$order_i).'__post_title'] = esc_html__('WP Title', 'wpdirectorykit');
197 $fields_list [(++$order_i).'__post_content'] = esc_html__('WP Content', 'wpdirectorykit');
198 $fields_list [(++$order_i).'__address'] = esc_html__('Address', 'wpdirectorykit');
199 $fields_list [(++$order_i).'__category_id'] = esc_html__('Category', 'wpdirectorykit');
200 $fields_list [(++$order_i).'__location_id'] = esc_html__('Location', 'wpdirectorykit');
201
202 foreach($fields_data as $field)
203 {
204 if(wmvc_show_data('field_type', $field) == 'SECTION') {
205 $fields_list [(++$order_i).'section__'.wmvc_show_data('idfield', $field)] = '-- '.esc_html__('Section', 'wpdirectorykit').' '.wmvc_show_data('field_label', $field).' --';
206 } else {
207 $fields_list[(++$order_i).'__'.wmvc_show_data('idfield', $field)] = '#'.wmvc_show_data('idfield', $field).' '.wmvc_show_data('field_label', $field).'['.wmvc_show_data('field_type', $field).']';
208 }
209 }
210
211 $this->add_responsive_control(
212 'related_fields_header',
213 [
214 'label' => esc_html__('Fields', 'wpdirectorykit'),
215 'type' => Controls_Manager::HEADING,
216 ]
217 );
218
219 $this->add_control(
220 'related_fields_header_hr',
221 [
222 'type' => \Elementor\Controls_Manager::DIVIDER,
223 ]
224 );
225
226 $repeater_sublistings_fields = new Repeater();
227 $repeater_sublistings_fields->start_controls_tabs( 'related_fields' );
228 $repeater_sublistings_fields->add_control(
229 'field',
230 [
231 'label' => __( 'Field', 'wpdirectorykit' ),
232 'type' => \Elementor\Controls_Manager::SELECT2,
233 'options' => $fields_list,
234 ]
235 );
236
237 $repeater_sublistings_fields->add_control(
238 'is_stars',
239 [
240 'label' => __( 'Show like stars', 'wpdirectorykit' ),
241 'type' => \Elementor\Controls_Manager::SWITCHER,
242 'label_on' => __( 'On', 'wpdirectorykit' ),
243 'label_off' => __( 'Off', 'wpdirectorykit' ),
244 'return_value' => 'yes',
245 'default' => '',
246 'description' => esc_html__( 'Numeric values required', 'wpdirectorykit' ),
247 ]
248 );
249
250 $repeater_sublistings_fields->add_control(
251 'is_link',
252 [
253 'label' => __( 'Set field like link', 'wpdirectorykit' ),
254 'type' => \Elementor\Controls_Manager::SWITCHER,
255 'label_on' => __( 'On', 'wpdirectorykit' ),
256 'label_off' => __( 'Off', 'wpdirectorykit' ),
257 'return_value' => 'yes',
258 'default' => 'yes',
259 ]
260 );
261
262
263 $repeater_sublistings_fields->add_control(
264 'field_prefix',
265 [
266 'label' => __( 'Text prefix', 'wpdirectorykit' ),
267 'type' => \Elementor\Controls_Manager::TEXT,
268 'default' => '',
269 ]
270 );
271
272 $repeater_sublistings_fields->add_control(
273 'field_suffix',
274 [
275 'label' => __( 'Text suffix', 'wpdirectorykit' ),
276 'type' => \Elementor\Controls_Manager::TEXT,
277 'default' => '',
278 ]
279 );
280
281 $repeater_sublistings_fields->end_controls_tabs();
282
283 $this->add_control(
284 'related_fields_list',
285 [
286 'label' => esc_html__('Fields For Query Similar Listings', 'wpdirectorykit'),
287 'type' => Controls_Manager::REPEATER,
288 'fields' => $repeater_sublistings_fields->get_controls(),
289 'default' => [
290 [
291 'field' => '63',
292 'is_stars' => 'yes',
293 'is_link' => '',
294 ],
295 [
296 'field' => 'post_title',
297 'is_link' => 'yes',
298 ],
299 [
300 'field' => '64',
301 'is_link' => '',
302 'field_suffix' => esc_html__('(persons)', 'wpdirectorykit'),
303 ],
304 ],
305 'title_field' => '{{{ field }}}',
306 ]
307 );
308
309
310 $this->end_controls_section();
311
312 }
313
314 private function generate_controls_layout()
315 {
316 }
317
318 private function generate_controls_styles()
319 {
320
321 $this->start_controls_section(
322 'colors_sections',
323 [
324 'label' => esc_html__('Styles', 'wpdirectorykit'),
325 'tab' => '1'
326 ]
327 );
328
329 $this->add_control(
330 'border_color',
331 [
332 'label' => __('Border Color', 'wpdirectorykit'),
333 'type' => \Elementor\Controls_Manager::COLOR,
334 'selectors' => [
335 '{{WRAPPER}} .wdk-listing-related-listings-table' => '--border_color:{{VALUE}}',
336 ],
337 ]
338 );
339
340 $this->add_control(
341 'border_width',
342 [
343 'label' => __('Border Width', 'wpdirectorykit'),
344 'type' => Controls_Manager::SLIDER,
345 'size_units' => ['px'],
346 'range' => [
347 'px' => [
348 'min' => 0,
349 'max' => 5,
350 'step' => 1,
351 ],
352 ],
353 'selectors' => [
354 '{{WRAPPER}} .wdk-listing-related-listings-table' => '--border_width: {{SIZE}}{{UNIT}};',
355 ],
356 ]
357 );
358
359
360 $this->add_responsive_control(
361 'tr_hover_color',
362 [
363 'label' => esc_html__( 'Line Hover Color', 'wpdirectorykit' ),
364 'type' => Controls_Manager::COLOR,
365 'selectors' => [
366 '{{WRAPPER}} .wdk-listing-related-listings-table table.wdk-table tr:hover' => 'background-color: {{VALUE}};',
367 ],
368 ]
369 );
370 $this->add_control(
371 'related_fields_header_hr1_0',
372 [
373 'type' => \Elementor\Controls_Manager::DIVIDER,
374 ]
375 );
376 $this->add_control(
377 'related_fields_star_image',
378 [
379 'label' => esc_html__('Image', 'wpdirectorykit'),
380 'type' => Controls_Manager::HEADING,
381 ]
382 );
383
384 $this->add_control(
385 'related_fields_header_hr1',
386 [
387 'type' => \Elementor\Controls_Manager::DIVIDER,
388 ]
389 );
390 $this->add_responsive_control(
391 'hide_image',
392 [
393 'label' => esc_html__( 'Hide Image', 'wpdirectorykit' ),
394 'type' => Controls_Manager::SWITCHER,
395 'none' => esc_html__( 'Hide', 'wpdirectorykit' ),
396 'block' => esc_html__( 'Show', 'wpdirectorykit' ),
397 'return_value' => 'none',
398 'default' => '',
399 'selectors' => [
400 '{{WRAPPER}} .wdk-listing-related-listings-table table.wdk-table td:first-child' => 'display: {{VALUE}};',
401 ],
402 ]
403 );
404
405 $selectors = array(
406 'normal' => '{{WRAPPER}} .wdk-listing-related-listings-table .wdk-image',
407 );
408 $this->generate_renders_tabs($selectors, 'image_dynamic', ['margin','border','border_radius','padding','shadow','image_size_control','image_fit_control', 'css_filters']);
409
410
411 $this->add_control(
412 'related_fields_header_hr2_0',
413 [
414 'type' => \Elementor\Controls_Manager::DIVIDER,
415 ]
416 );
417 $this->add_responsive_control(
418 'related_fields_styles',
419 [
420 'label' => esc_html__('Styles Content', 'wpdirectorykit'),
421 'type' => Controls_Manager::HEADING,
422 ]
423 );
424 $this->add_control(
425 'related_fields_header_hr2',
426 [
427 'type' => \Elementor\Controls_Manager::DIVIDER,
428 ]
429 );
430
431 $selectors = array(
432 'normal' => '{{WRAPPER}} .wdk-sublistings-part a, {{WRAPPER}} .wdk-sublistings-part span',
433 'hover'=>'{{WRAPPER}} .wdk-sublistings-part a%1$s'
434 );
435 $this->generate_renders_tabs($selectors, 'related_fields_dynamic', ['color','typo','padding','shadow','transition']);
436
437
438 $this->add_control(
439 'related_fields_header_hr5_0',
440 [
441 'type' => \Elementor\Controls_Manager::DIVIDER,
442 ]
443 );
444 $this->add_control(
445 'related_fields_star_styles',
446 [
447 'label' => esc_html__('Stars', 'wpdirectorykit'),
448 'type' => Controls_Manager::HEADING,
449 ]
450 );
451
452 $this->add_control(
453 'related_fields_header_hr5',
454 [
455 'type' => \Elementor\Controls_Manager::DIVIDER,
456 ]
457 );
458
459 $selectors = array(
460 'active' => '{{WRAPPER}} .wdk-sublistings-part .stars-lst span i.star-active',
461 );
462 $this->generate_renders_tabs($selectors, 'related_fields_star_dynamic', ['margin','padding','font-size', 'color']);
463
464 $this->add_control(
465 'related_fields_header_hr6_0',
466 [
467 'type' => \Elementor\Controls_Manager::DIVIDER,
468 ]
469 );
470 $this->add_control(
471 'related_fields_star_button',
472 [
473 'label' => esc_html__('Button', 'wpdirectorykit'),
474 'type' => Controls_Manager::HEADING,
475 ]
476 );
477
478 $this->add_control(
479 'related_fields_header_hr6',
480 [
481 'type' => \Elementor\Controls_Manager::DIVIDER,
482 ]
483 );
484
485 $selectors = array(
486 'normal' => '{{WRAPPER}} .wdk-listing-related-listings-table table.wdk-table .wdk-btn',
487 'hover'=>'{{WRAPPER}} ..wdk-listing-related-listings-table table.wdk-table .wdk-btn%1$s'
488 );
489 $this->generate_renders_tabs($selectors, 'button_dynamic', ['margin','typo','color','background','border','border_radius','padding','shadow','transition','background_group']);
490
491 $this->end_controls_section();
492
493 }
494
495 private function generate_controls_content()
496 {
497 }
498
499 public function enqueue_styles_scripts() {
500 wp_enqueue_style('wdk-listing-related-listings-table');
501
502 wp_enqueue_style('wdk-notify');
503 wp_enqueue_script('wdk-notify');
504 }
505 }
506