PluginProbe
WP Directory Kit / 1.2.7
WP Directory Kit v1.2.7
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 1.4.0 All 36 releases
wpdirectorykit / elementor-elements / classes / wdk-listing-related-listings-table.php

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

509 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
171 echo $this->view('wdk-listing-related-listings-table', $this->data);
172 }
173
174 private function generate_controls_conf()
175 {
176
177 $this->start_controls_section(
178 'tab_conf_main_section_subslistings',
179 [
180 'label' => esc_html__('Related Listings', 'wpdirectorykit'),
181 'tab' => 'tab_conf',
182 ]
183 );
184
185 $WMVC = &wdk_get_instance();
186 $WMVC->model('field_m');
187 $fields_data = $WMVC->field_m->get();
188 $fields_list = array('' => esc_html__('Not Selected', 'wpdirectorykit'));
189 $order_i = 0;
190
191 $fields_list [(++$order_i).'__section'] = esc_html__('-- Section Custom fields --', 'wpdirectorykit');
192 $fields_list [(++$order_i).'__idlisting'] = esc_html__('Id listing', 'wpdirectorykit');
193 $fields_list [(++$order_i).'__post_id'] = esc_html__('Post Id', 'wpdirectorykit');
194 $fields_list [(++$order_i).'__counter_views'] = esc_html__('Views counter', 'wpdirectorykit');
195 $fields_list [(++$order_i).'__lat'] = esc_html__('Gps Lat', 'wpdirectorykit');
196 $fields_list [(++$order_i).'__lng'] = esc_html__('Gps Lng', 'wpdirectorykit');
197 $fields_list [(++$order_i).'__date'] = esc_html__('Date', 'wpdirectorykit');
198 $fields_list [(++$order_i).'__date_modified'] = esc_html__('Date Modified', 'wpdirectorykit');
199 $fields_list [(++$order_i).'__post_title'] = esc_html__('WP Title', 'wpdirectorykit');
200 $fields_list [(++$order_i).'__post_content'] = esc_html__('WP Content', 'wpdirectorykit');
201 $fields_list [(++$order_i).'__address'] = esc_html__('Address', 'wpdirectorykit');
202 $fields_list [(++$order_i).'__category_id'] = esc_html__('Category', 'wpdirectorykit');
203 $fields_list [(++$order_i).'__location_id'] = esc_html__('Location', 'wpdirectorykit');
204
205 foreach($fields_data as $field)
206 {
207 if(wmvc_show_data('field_type', $field) == 'SECTION') {
208 $fields_list [(++$order_i).'section__'.wmvc_show_data('idfield', $field)] = '-- '.esc_html__('Section', 'wpdirectorykit').' '.wmvc_show_data('field_label', $field).' --';
209 } else {
210 $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).']';
211 }
212 }
213
214 $this->add_responsive_control(
215 'related_fields_header',
216 [
217 'label' => esc_html__('Fields', 'wpdirectorykit'),
218 'type' => Controls_Manager::HEADING,
219 ]
220 );
221
222 $this->add_control(
223 'related_fields_header_hr',
224 [
225 'type' => \Elementor\Controls_Manager::DIVIDER,
226 ]
227 );
228
229 $repeater_sublistings_fields = new Repeater();
230 $repeater_sublistings_fields->start_controls_tabs( 'related_fields' );
231 $repeater_sublistings_fields->add_control(
232 'field',
233 [
234 'label' => __( 'Field', 'wpdirectorykit' ),
235 'type' => \Elementor\Controls_Manager::SELECT,
236 'options' => $fields_list,
237 ]
238 );
239
240 $repeater_sublistings_fields->add_control(
241 'is_stars',
242 [
243 'label' => __( 'Show like stars', 'wpdirectorykit' ),
244 'type' => \Elementor\Controls_Manager::SWITCHER,
245 'label_on' => __( 'On', 'wpdirectorykit' ),
246 'label_off' => __( 'Off', 'wpdirectorykit' ),
247 'return_value' => 'yes',
248 'default' => '',
249 'description' => esc_html__( 'Numeric values required', 'wpdirectorykit' ),
250 ]
251 );
252
253 $repeater_sublistings_fields->add_control(
254 'is_link',
255 [
256 'label' => __( 'Set field like link', 'wpdirectorykit' ),
257 'type' => \Elementor\Controls_Manager::SWITCHER,
258 'label_on' => __( 'On', 'wpdirectorykit' ),
259 'label_off' => __( 'Off', 'wpdirectorykit' ),
260 'return_value' => 'yes',
261 'default' => 'yes',
262 ]
263 );
264
265
266 $repeater_sublistings_fields->add_control(
267 'field_prefix',
268 [
269 'label' => __( 'Text prefix', 'wpdirectorykit' ),
270 'type' => \Elementor\Controls_Manager::TEXT,
271 'default' => '',
272 ]
273 );
274
275 $repeater_sublistings_fields->add_control(
276 'field_suffix',
277 [
278 'label' => __( 'Text suffix', 'wpdirectorykit' ),
279 'type' => \Elementor\Controls_Manager::TEXT,
280 'default' => '',
281 ]
282 );
283
284 $repeater_sublistings_fields->end_controls_tabs();
285
286 $this->add_control(
287 'related_fields_list',
288 [
289 'label' => esc_html__('Fields For Query Similar Listings', 'wpdirectorykit'),
290 'type' => Controls_Manager::REPEATER,
291 'fields' => $repeater_sublistings_fields->get_controls(),
292 'default' => [
293 [
294 'field' => '63',
295 'is_stars' => 'yes',
296 'is_link' => '',
297 ],
298 [
299 'field' => 'post_title',
300 'is_link' => 'yes',
301 ],
302 [
303 'field' => '64',
304 'is_link' => '',
305 'field_suffix' => esc_html__('(persons)', 'wpdirectorykit'),
306 ],
307 ],
308 'title_field' => '{{{ field }}}',
309 ]
310 );
311
312
313 $this->end_controls_section();
314
315 }
316
317 private function generate_controls_layout()
318 {
319 }
320
321 private function generate_controls_styles()
322 {
323
324 $this->start_controls_section(
325 'colors_sections',
326 [
327 'label' => esc_html__('Styles', 'wpdirectorykit'),
328 'tab' => '1'
329 ]
330 );
331
332 $this->add_control(
333 'border_color',
334 [
335 'label' => __('Border Color', 'wpdirectorykit'),
336 'type' => \Elementor\Controls_Manager::COLOR,
337 'selectors' => [
338 '{{WRAPPER}} .wdk-listing-related-listings-table' => '--border_color:{{VALUE}}',
339 ],
340 ]
341 );
342
343 $this->add_control(
344 'border_width',
345 [
346 'label' => __('Border Width', 'wpdirectorykit'),
347 'type' => Controls_Manager::SLIDER,
348 'size_units' => ['px'],
349 'range' => [
350 'px' => [
351 'min' => 0,
352 'max' => 5,
353 'step' => 1,
354 ],
355 ],
356 'selectors' => [
357 '{{WRAPPER}} .wdk-listing-related-listings-table' => '--border_width: {{SIZE}}{{UNIT}};',
358 ],
359 ]
360 );
361
362
363 $this->add_responsive_control(
364 'tr_hover_color',
365 [
366 'label' => esc_html__( 'Line Hover Color', 'wpdirectorykit' ),
367 'type' => Controls_Manager::COLOR,
368 'selectors' => [
369 '{{WRAPPER}} .wdk-listing-related-listings-table table.wdk-table tr:hover' => 'background-color: {{VALUE}};',
370 ],
371 ]
372 );
373 $this->add_control(
374 'related_fields_header_hr1_0',
375 [
376 'type' => \Elementor\Controls_Manager::DIVIDER,
377 ]
378 );
379 $this->add_control(
380 'related_fields_star_image',
381 [
382 'label' => esc_html__('Image', 'wpdirectorykit'),
383 'type' => Controls_Manager::HEADING,
384 ]
385 );
386
387 $this->add_control(
388 'related_fields_header_hr1',
389 [
390 'type' => \Elementor\Controls_Manager::DIVIDER,
391 ]
392 );
393 $this->add_responsive_control(
394 'hide_image',
395 [
396 'label' => esc_html__( 'Hide Image', 'wpdirectorykit' ),
397 'type' => Controls_Manager::SWITCHER,
398 'none' => esc_html__( 'Hide', 'wpdirectorykit' ),
399 'block' => esc_html__( 'Show', 'wpdirectorykit' ),
400 'return_value' => 'none',
401 'default' => '',
402 'selectors' => [
403 '{{WRAPPER}} .wdk-listing-related-listings-table table.wdk-table td:first-child' => 'display: {{VALUE}};',
404 ],
405 ]
406 );
407
408 $selectors = array(
409 'normal' => '{{WRAPPER}} .wdk-listing-related-listings-table .wdk-image',
410 );
411 $this->generate_renders_tabs($selectors, 'image_dynamic', ['margin','border','border_radius','padding','shadow','image_size_control','image_fit_control', 'css_filters']);
412
413
414 $this->add_control(
415 'related_fields_header_hr2_0',
416 [
417 'type' => \Elementor\Controls_Manager::DIVIDER,
418 ]
419 );
420 $this->add_responsive_control(
421 'related_fields_styles',
422 [
423 'label' => esc_html__('Styles Content', 'wpdirectorykit'),
424 'type' => Controls_Manager::HEADING,
425 ]
426 );
427 $this->add_control(
428 'related_fields_header_hr2',
429 [
430 'type' => \Elementor\Controls_Manager::DIVIDER,
431 ]
432 );
433
434 $selectors = array(
435 'normal' => '{{WRAPPER}} .wdk-sublistings-part a, {{WRAPPER}} .wdk-sublistings-part span',
436 'hover'=>'{{WRAPPER}} .wdk-sublistings-part a%1$s'
437 );
438 $this->generate_renders_tabs($selectors, 'related_fields_dynamic', ['color','typo','padding','shadow','transition']);
439
440
441 $this->add_control(
442 'related_fields_header_hr5_0',
443 [
444 'type' => \Elementor\Controls_Manager::DIVIDER,
445 ]
446 );
447 $this->add_control(
448 'related_fields_star_styles',
449 [
450 'label' => esc_html__('Stars', 'wpdirectorykit'),
451 'type' => Controls_Manager::HEADING,
452 ]
453 );
454
455 $this->add_control(
456 'related_fields_header_hr5',
457 [
458 'type' => \Elementor\Controls_Manager::DIVIDER,
459 ]
460 );
461
462 $selectors = array(
463 'active' => '{{WRAPPER}} .wdk-sublistings-part .stars-lst span i.star-active',
464 );
465 $this->generate_renders_tabs($selectors, 'related_fields_star_dynamic', ['margin','padding','font-size', 'color']);
466
467 $this->add_control(
468 'related_fields_header_hr6_0',
469 [
470 'type' => \Elementor\Controls_Manager::DIVIDER,
471 ]
472 );
473 $this->add_control(
474 'related_fields_star_button',
475 [
476 'label' => esc_html__('Button', 'wpdirectorykit'),
477 'type' => Controls_Manager::HEADING,
478 ]
479 );
480
481 $this->add_control(
482 'related_fields_header_hr6',
483 [
484 'type' => \Elementor\Controls_Manager::DIVIDER,
485 ]
486 );
487
488 $selectors = array(
489 'normal' => '{{WRAPPER}} .wdk-listing-related-listings-table table.wdk-table .wdk-btn',
490 'hover'=>'{{WRAPPER}} ..wdk-listing-related-listings-table table.wdk-table .wdk-btn%1$s'
491 );
492 $this->generate_renders_tabs($selectors, 'button_dynamic', ['margin','typo','color','background','border','border_radius','padding','shadow','transition','background_group']);
493
494 $this->end_controls_section();
495
496 }
497
498 private function generate_controls_content()
499 {
500 }
501
502 public function enqueue_styles_scripts() {
503 wp_enqueue_style('wdk-listing-related-listings-table');
504
505 wp_enqueue_style('wdk-notify');
506 wp_enqueue_script('wdk-notify');
507 }
508 }
509