PluginProbe
WP Directory Kit / 1.5.5
WP Directory Kit v1.5.5
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-locations-grid.php

wdk-locations-grid.php in WP Directory Kit 1.5.5, at elementor-elements/classes/wdk-locations-grid.php

563 lines 20.3 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 WdkLocationsGrid 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
45 if ($this->is_edit_mode_load()) {
46 $this->enqueue_styles_scripts();
47 }
48
49 parent::__construct($data, $args);
50 }
51
52 /**
53 * Retrieve the widget name.
54 *
55 * @since 1.1.0
56 *
57 * @access public
58 *
59 * @return string Widget name.
60 */
61 public function get_name() {
62 return 'wdk-locations-grid';
63 }
64
65 /**
66 * Retrieve the widget title.
67 *
68 * @since 1.1.0
69 *
70 * @access public
71 *
72 * @return string Widget title.
73 */
74 public function get_title() {
75 return esc_html__('Wdk Locations Grid', 'wpdirectorykit');
76 }
77
78 /**
79 * Retrieve the widget icon.
80 *
81 * @since 1.1.0
82 *
83 * @access public
84 *
85 * @return string Widget icon.
86 */
87 public function get_icon() {
88 return 'eicon-product-related';
89 }
90
91 /**
92 * Register the widget controls.
93 *
94 * Adds different input fields to allow the user to change and customize the widget settings.
95 *
96 * @since 1.1.0
97 *
98 * @access protected
99 */
100 protected function register_controls() {
101 $this->generate_controls_conf();
102 $this->generate_controls_layout();
103 $this->generate_controls_styles();
104 $this->generate_controls_content();
105
106 $this->insert_pro_message('1');
107 parent::register_controls();
108 }
109
110 /**
111 * Render the widget output on the frontend.
112 *
113 * Written in PHP and used to generate the final HTML.
114 *
115 * @since 1.1.0
116 *
117 * @access protected
118 */
119 protected function render() {
120 parent::render();
121 $this->data['id_element'] = $this->get_id();
122 $this->data['settings'] = $this->get_settings();
123
124 $controller = 'location';
125 $this->WMVC->model($controller.'_m');
126 $this->WMVC->model('listing_m');
127
128 $this->data['results'] = false;
129
130 if($this->data['settings']['conf_results_type'] == 'custom_locations') {
131
132 $locations_ids = array();
133 foreach($this->data['settings']['conf_custom_results'] as $location) {
134 if(isset($location['location_id']) && !empty($location['location_id'])) {
135 $locations_ids [] = $location['location_id'];
136 }
137 }
138
139 /* where in */
140 if(!empty($locations_ids)){
141
142 $this->WMVC->db->select($this->WMVC->{$controller.'_m'}->_table_name.'.*, COUNT('.$this->WMVC->listing_m->_table_name.'.post_id) AS listings_counter');
143 $this->WMVC->db->join($this->WMVC->listing_m->_table_name.' ON '.$this->WMVC->listing_m->_table_name.'.location_id = '.$this->WMVC->{$controller.'_m'}->_table_name.'.idlocation', TRUE, 'LEFT');
144 $this->WMVC->db->where($this->WMVC->{$controller.'_m'}->_table_name.'.idlocation IN(' . implode(',', $locations_ids) . ')', null, false);
145 $this->WMVC->db->order_by('FIELD('.$this->WMVC->{$controller.'_m'}->_table_name.'.idlocation, '. implode(',', $locations_ids) . ')');
146 $this->WMVC->db->group_by($this->WMVC->{$controller.'_m'}->_primary_key);
147
148 $this->data['results'] = $this->WMVC->{$controller.'_m'}->get();
149 }
150
151 } else {
152 $order_by = NULL;
153 if(!empty($this->data['settings']['conf_order_by']))
154 $order_by = wdk_esc_sql($this->data['settings']['conf_order_by'].' '.$this->data['settings']['conf_order']);
155 $where = array();
156 if (!empty($this->data['settings']['only_root_enable']) && $this->data['settings']['only_root_enable'] == 'yes') {
157 $where['('.$this->WMVC->{$controller.'_m'}->_table_name.'.level = 0)'] = NULL;
158 }
159 $this->data['results'] = $this->WMVC->{$controller.'_m'}->get_pagination((!empty($this->data['settings']['conf_limit'])) ? $this->data['settings']['conf_limit'] : NULL, NULL, $where, $order_by);
160 }
161
162 $this->data['is_edit_mode']= false;
163 if(Plugin::$instance->editor->is_edit_mode())
164 $this->data['is_edit_mode']= true;
165
166 echo $this->view('wdk-locations-grid', $this->data);
167 }
168
169
170 private function generate_controls_conf() {
171 $this->start_controls_section(
172 'tab_conf_main_section',
173 [
174 'label' => esc_html__('Main', 'wpdirectorykit'),
175 'tab' => '1',
176 ]
177 );
178
179 $pages = array('' => __('Not Selected', 'wpdirectorykit'));
180 foreach(get_pages(array('sort_column' => 'post_title')) as $page)
181 {
182 $pages[$page->ID] = $page->post_title.' #'.$page->ID;
183 }
184
185 $this->add_control(
186 'conf_link',
187 [
188 'label' => __( 'Open results on page', 'wpdirectorykit' ),
189 'type' => \Elementor\Controls_Manager::SELECT2,
190 'default' => '',
191 'options' => $pages
192 ]
193 );
194
195 $this->add_control(
196 'conf_results_type',
197 [
198 'label' => __( 'Show type', 'wpdirectorykit' ),
199 'type' => \Elementor\Controls_Manager::SELECT,
200 'default' => 'results_locations',
201 'options' => [
202 'results_locations' => __( 'All Locations', 'wpdirectorykit' ),
203 'custom_locations' => __( 'Specific', 'wpdirectorykit' ),
204 ],
205 'separator' => 'after',
206 ]
207 );
208
209 $this->add_control(
210 'important_note',
211 [
212 'label' => '',
213 'type' => \Elementor\Controls_Manager::RAW_HTML,
214 'raw' => wdk_sprintf(__( 'Edit Locations <a href="%1$s" target="_blank"> open </a>', 'wpdirectorykit' ), admin_url('admin.php?page=wdk_location')),
215 'content_classes' => 'wdk_elementor_hint',
216 ]
217 );
218
219 $this->add_responsive_control(
220 'only_root_enable',
221 [
222 'label' => esc_html__( 'Show only Root', 'wpdirectorykit' ),
223 'type' => Controls_Manager::SWITCHER,
224 'none' => esc_html__( 'No', 'wpdirectorykit' ),
225 'block' => esc_html__( 'Yes', 'wpdirectorykit' ),
226 'return_value' => 'yes',
227 'default' => 'yes',
228 ]
229 );
230 $this->add_control(
231 'conf_limit',
232 [
233 'label' => __( 'Limit Locations', 'wpdirectorykit' ),
234 'description' => __( 'Set 0 for unlimit', 'wpdirectorykit' ),
235 'type' => \Elementor\Controls_Manager::NUMBER,
236 'min' => 0,
237 'max' => 500,
238 'step' => 1,
239 'default' => 6,
240 'separator' => 'before',
241 'conditions' => [
242 'terms' => [
243 [
244 'name' => 'conf_results_type',
245 'operator' => '==',
246 'value' => 'results_locations',
247 ]
248 ],
249 ],
250 ]
251 );
252
253 $this->add_control(
254 'conf_order_by',
255 [
256 'label' => __('Order By Column', 'wpdirectorykit'),
257 'type' => Controls_Manager::SELECT,
258 'label_block' => true,
259 'options' => [
260 '' => __('None', 'wpdirectorykit'),
261 'location_title' => __('Title', 'wpdirectorykit'),
262 'idlocation' => __('Location id', 'wpdirectorykit'),
263 'order_index' => __('Order index', 'wpdirectorykit'),
264 'listings_counter' => __('Most Listings', 'wpdirectorykit'),
265 ],
266 'default' => 'order_index',
267 'conditions' => [
268 'terms' => [
269 [
270 'name' => 'conf_results_type',
271 'operator' => '==',
272 'value' => 'results_locations',
273 ]
274 ],
275 ],
276 ]
277 );
278
279 $this->add_control(
280 'conf_order',
281 [
282 'label' => __('Order', 'wpdirectorykit'),
283 'type' => Controls_Manager::SELECT,
284 'label_block' => true,
285 'options' => [
286 'asc' => __('Ascending', 'wpdirectorykit'),
287 'desc' => __('Descending', 'wpdirectorykit')
288 ],
289 'default' => 'desc',
290 'conditions' => [
291 'terms' => [
292 [
293 'name' => 'conf_results_type',
294 'operator' => '==',
295 'value' => 'results_locations',
296 ]
297 ],
298 ],
299 ]
300 );
301
302 if(true){
303 $repeater = new Repeater();
304 $repeater->start_controls_tabs( 'locations' );
305 $repeater->add_control(
306 'location_id',
307 [
308 'label' => __( 'ID location', 'wpdirectorykit' ),
309 'type' => \Elementor\Controls_Manager::NUMBER,
310 'min' => 1,
311 'step' => 1,
312 ]
313 );
314 $repeater->end_controls_tabs();
315
316
317 $this->add_control(
318 'conf_custom_results',
319 [
320 'type' => Controls_Manager::REPEATER,
321 'fields' => $repeater->get_controls(),
322 'default' => [
323 ],
324 'title_field' => '{{{ location_id }}}',
325 'conditions' => [
326 'terms' => [
327 [
328 'name' => 'conf_results_type',
329 'operator' => '==',
330 'value' => 'custom_locations',
331 ]
332 ],
333 ],
334 ]
335 );
336 }
337
338 $this->end_controls_section();
339
340 }
341
342 private function generate_controls_layout() {
343 }
344
345 private function generate_controls_styles() {
346 $this->start_controls_section(
347 'styles_thmbn_section',
348 [
349 'label' => esc_html__('Main', 'wpdirectorykit'),
350 'tab' => Controls_Manager::TAB_STYLE,
351 ]
352 );
353
354 $this->add_responsive_control(
355 'row_gap_col',
356 [
357 'label' => __( 'Columns', 'wpdirectorykit' ),
358 'type' => Controls_Manager::SELECT,
359 'options' => [
360 '' => esc_html__('Default', 'wpdirectorykit'),
361 'auto' => esc_html__('Auto', 'wpdirectorykit'),
362 '100%' => '1',
363 '50%' => '2',
364 'calc(100% / 3)' => '3',
365 '25%' => '4',
366 '20%' => '5',
367 'auto_flexible' => 'auto flexible',
368 ],
369 'selectors_dictionary' => [
370 'auto' => 'width:auto;-webkit-flex:0 0 auto;flex:0 0 auto',
371 '100%' => 'width:100%;-webkit-flex:0 0 100%;flex:0 0 100%',
372 '50%' => 'width:50%;-webkit-flex:0 0 50%;flex:0 0 50%',
373 'calc(100% / 3)' => 'width:calc(100% / 3);-webkit-flex:0 0 calc(100% / 3);flex:0 0 calc(100% / 3)',
374 '25%' => 'width:25%;-webkit-flex:0 0 25%;flex:0 0 25%',
375 '20%' => 'width:20%;-webkit-flex:0 0 20%;flex:0 0 20%',
376 'auto' => 'width:auto;-webkit-flex:0 0 auto;flex:0 0 auto',
377 'auto_flexible' => 'width:auto;-webkit-flex:1 2 auto;flex:1 2 auto',
378 ],
379 'selectors' => [
380 '{{WRAPPER}} .wdk-row .wdk-col' => '{{UNIT}}',
381 ],
382 'default' => '25%',
383 'separator' => 'before',
384 ]
385 );
386
387 $this->add_responsive_control(
388 'column_gap',
389 [
390 'label' => esc_html__('Columns Gap', 'wpdirectorykit'),
391 'type' => Controls_Manager::SLIDER,
392 'default' => [
393 'size' => 10,
394 ],
395 'range' => [
396 'px' => [
397 'min' => 0,
398 'max' => 60,
399 ],
400 ],
401 'selectors' => [
402 '{{WRAPPER}} .wdk-row .wdk-col' => 'padding-left: {{SIZE}}{{UNIT}};padding-right: {{SIZE}}{{UNIT}};;',
403 '{{WRAPPER}} .wdk-row' => 'margin-left: -{{SIZE}}{{UNIT}};margin-right: -{{SIZE}}{{UNIT}};',
404 ],
405 ]
406 );
407
408 $this->add_responsive_control(
409 'row_gap',
410 [
411 'label' => esc_html__('Rows Gap', 'wpdirectorykit'),
412 'type' => Controls_Manager::SLIDER,
413 'default' => [
414 'size' => 10,
415 ],
416 'range' => [
417 'px' => [
418 'min' => 0,
419 'max' => 60,
420 ],
421 ],
422 'selectors' => [
423 '{{WRAPPER}} .wdk-row .wdk-col' => 'margin-bottom: {{SIZE}}{{UNIT}};',
424 '{{WRAPPER}} .wdk-row' => 'margin-bottom: -{{SIZE}}{{UNIT}};',
425 ],
426 ]
427 );
428
429 $this->end_controls_section();
430
431 $this->start_controls_section(
432 'styles_thmbn_type',
433 [
434 'label' => esc_html__('Thumbnail', 'wpdirectorykit'),
435 'tab' => Controls_Manager::TAB_STYLE,
436 ]
437 );
438
439 $this->add_control(
440 'layout_image_type',
441 [
442 'label' => __( 'Thumbnail Type', 'wpdirectorykit' ),
443 'type' => \Elementor\Controls_Manager::SELECT,
444 'default' => 'none4',
445 'options' => [
446 'none' => __( 'None', 'wpdirectorykit' ),
447 'contain' => __( 'Contain', 'wpdirectorykit' ),
448 'cover' => __( 'Cover', 'wpdirectorykit' ),
449 ],
450 ]
451 );
452
453 $this->add_control (
454 'layout_image_design',
455 [
456 'label' => __( 'Size style thumbnail', 'wpdirectorykit' ),
457 'type' => \Elementor\Controls_Manager::SELECT,
458 'default' => 'contain',
459 'options' => [
460 'contain' => __( 'Contain', 'wpdirectorykit' ),
461 'cover' => __( 'Cover', 'wpdirectorykit' ),
462 ],
463 'selectors' => [
464 '{{WRAPPER}} .wdk-locations-card .wdk-thumbnail .wdk-image' => 'object-fit: {{VALUE}}',
465 '{{WRAPPER}} .wdk-locations-card .wdk-thumbnail .wdk-icon' => 'object-fit: {{VALUE}}',
466 ],
467 ]
468 );
469
470 $selectors = array(
471 'normal' => '{{WRAPPER}} .wdk-locations-card .wdk-thumbnail',
472 );
473 $this->generate_renders_tabs($selectors, 'layout_image_dynamic', ['padding' ,'background','color']);
474
475 $this->add_responsive_control (
476 'styles_thmbn_des_height',
477 [
478 'label' => esc_html__('Height', 'wpdirectorykit'),
479 'type' => Controls_Manager::SLIDER,
480 'range' => [
481 'px' => [
482 'min' => 0,
483 'max' => 1500,
484 ],
485 'vw' => [
486 'min' => 0,
487 'max' => 100,
488 ],
489 ],
490 'size_units' => [ 'px','em', 'vw', '%', 'custom' ],
491 'default' => [
492 'size' => 350,
493 'unit' => 'px',
494 ],
495 'selectors' => [
496 '{{WRAPPER}} .wdk-locations-card .wdk-thumbnail .wdk-image' => 'height: {{SIZE}}{{UNIT}}',
497 '{{WRAPPER}} .wdk-locations-card .wdk-thumbnail .wdk-icon' => 'height: {{SIZE}}{{UNIT}}',
498 ],
499 'separator' => 'after',
500 ]
501 );
502
503 $this->end_controls_section();
504
505
506 $items = [
507 [
508 'key'=>'item_title',
509 'label'=> esc_html__('Item Title', 'wpdirectorykit'),
510 'selector'=>'.wdk-locations-grid .wdk-locations-card .wdk-title',
511 'selector_hover'=>'.wdk-locations-grid .wdk-locations-card%1$s .wdk-title',
512 'options'=>'full',
513 ],
514 [
515 'key'=>'card',
516 'label'=> esc_html__('Card', 'wpdirectorykit'),
517 'selector'=>'.wdk-locations-grid .wdk-locations-card',
518 'selector_hover'=>'.wdk-locations-grid .wdk-locations-card%1$s',
519 'options'=>'block',
520 ],
521 ];
522
523 foreach ($items as $item) {
524 $this->start_controls_section(
525 $item['key'].'_section',
526 [
527 'label' => $item['label'],
528 'tab' => Controls_Manager::TAB_STYLE,
529 ]
530 );
531 $this->add_responsive_control(
532 $item['key'].'_hide',
533 [
534 'label' => esc_html__( 'Hide Element', 'wpdirectorykit' ),
535 'type' => Controls_Manager::SWITCHER,
536 'none' => esc_html__( 'Hide', 'wpdirectorykit' ),
537 'block' => esc_html__( 'Show', 'wpdirectorykit' ),
538 'return_value' => 'none',
539 'default' => '',
540 'selectors' => [
541 '{{WRAPPER}} '.$item['selector'] => 'display: {{VALUE}};',
542 ],
543 ]
544 );
545 $selectors = array(
546 'normal' => '{{WRAPPER}} '.$item['selector'],
547 'hover'=>'{{WRAPPER}} '.$item['selector_hover'],
548 );
549 $this->generate_renders_tabs($selectors, $item['key'].'_dynamic', $item['options']);
550
551 $this->end_controls_section();
552 }
553 }
554
555 private function generate_controls_content() {
556
557 }
558
559 public function enqueue_styles_scripts() {
560 wp_enqueue_style('wdk-locations-grid');
561 }
562 }
563