PluginProbe
WP Directory Kit / 1.2.7
WP Directory Kit v1.2.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 1.4.1 All 35 releases
wpdirectorykit / elementor-elements / classes / wdk-locations-grid.php

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

564 lines 20.2 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 = $this->data['settings']['conf_order_by'].' '.$this->data['settings']['conf_order'];
155
156 $where = array();
157 if (!empty($this->data['settings']['only_root_enable']) && $this->data['settings']['only_root_enable'] == 'yes') {
158 $where['('.$this->WMVC->{$controller.'_m'}->_table_name.'.level = 0)'] = NULL;
159 }
160 $this->data['results'] = $this->WMVC->{$controller.'_m'}->get_pagination($this->data['settings']['conf_limit'], NULL, $where, $order_by);
161
162 }
163
164 $this->data['is_edit_mode']= false;
165 if(Plugin::$instance->editor->is_edit_mode())
166 $this->data['is_edit_mode']= true;
167
168 echo $this->view('wdk-locations-grid', $this->data);
169 }
170
171
172 private function generate_controls_conf() {
173 $this->start_controls_section(
174 'tab_conf_main_section',
175 [
176 'label' => esc_html__('Main', 'wpdirectorykit'),
177 'tab' => '1',
178 ]
179 );
180
181 $pages = array('' => __('Not Selected', 'wpdirectorykit'));
182 foreach(get_pages(array('sort_column' => 'post_title')) as $page)
183 {
184 $pages[$page->ID] = $page->post_title.' #'.$page->ID;
185 }
186
187 $this->add_control(
188 'conf_link',
189 [
190 'label' => __( 'Open results on page', 'wpdirectorykit' ),
191 'type' => \Elementor\Controls_Manager::SELECT,
192 'default' => '',
193 'options' => $pages
194 ]
195 );
196
197 $this->add_control(
198 'conf_results_type',
199 [
200 'label' => __( 'Show type', 'wpdirectorykit' ),
201 'type' => \Elementor\Controls_Manager::SELECT,
202 'default' => 'results_locations',
203 'options' => [
204 'results_locations' => __( 'All Locations', 'wpdirectorykit' ),
205 'custom_locations' => __( 'Specific', 'wpdirectorykit' ),
206 ],
207 'separator' => 'after',
208 ]
209 );
210
211 $this->add_control(
212 'important_note',
213 [
214 'label' => '',
215 'type' => \Elementor\Controls_Manager::RAW_HTML,
216 'raw' => wdk_sprintf(__( 'Edit Locations <a href="%1$s" target="_blank"> open </a>', 'wpdirectorykit' ), admin_url('admin.php?page=wdk_location')),
217 'content_classes' => 'wdk_elementor_hint',
218 ]
219 );
220
221 $this->add_responsive_control(
222 'only_root_enable',
223 [
224 'label' => esc_html__( 'Show only Root', 'wpdirectorykit' ),
225 'type' => Controls_Manager::SWITCHER,
226 'none' => esc_html__( 'No', 'wpdirectorykit' ),
227 'block' => esc_html__( 'Yes', 'wpdirectorykit' ),
228 'return_value' => 'yes',
229 'default' => 'yes',
230 ]
231 );
232 $this->add_control(
233 'conf_limit',
234 [
235 'label' => __( 'Limit Locations', 'wpdirectorykit' ),
236 'type' => \Elementor\Controls_Manager::NUMBER,
237 'min' => 1,
238 'max' => 50,
239 'step' => 1,
240 'default' => 6,
241 'separator' => 'before',
242 'conditions' => [
243 'terms' => [
244 [
245 'name' => 'conf_results_type',
246 'operator' => '==',
247 'value' => 'results_locations',
248 ]
249 ],
250 ],
251 ]
252 );
253
254 $this->add_control(
255 'conf_order_by',
256 [
257 'label' => __('Order By Column', 'wpdirectorykit'),
258 'type' => Controls_Manager::SELECT,
259 'label_block' => true,
260 'options' => [
261 '' => __('None', 'wpdirectorykit'),
262 'location_title' => __('Title', 'wpdirectorykit'),
263 'idlocation' => __('Location id', 'wpdirectorykit'),
264 'order_index' => __('Order index', 'wpdirectorykit'),
265 'listings_counter' => __('Most Listings', 'wpdirectorykit'),
266 ],
267 'default' => 'order_index',
268 'conditions' => [
269 'terms' => [
270 [
271 'name' => 'conf_results_type',
272 'operator' => '==',
273 'value' => 'results_locations',
274 ]
275 ],
276 ],
277 ]
278 );
279
280 $this->add_control(
281 'conf_order',
282 [
283 'label' => __('Order', 'wpdirectorykit'),
284 'type' => Controls_Manager::SELECT,
285 'label_block' => true,
286 'options' => [
287 'asc' => __('Ascending', 'wpdirectorykit'),
288 'desc' => __('Descending', 'wpdirectorykit')
289 ],
290 'default' => 'desc',
291 'conditions' => [
292 'terms' => [
293 [
294 'name' => 'conf_results_type',
295 'operator' => '==',
296 'value' => 'results_locations',
297 ]
298 ],
299 ],
300 ]
301 );
302
303 if(true){
304 $repeater = new Repeater();
305 $repeater->start_controls_tabs( 'locations' );
306 $repeater->add_control(
307 'location_id',
308 [
309 'label' => __( 'ID location', 'wpdirectorykit' ),
310 'type' => \Elementor\Controls_Manager::NUMBER,
311 'min' => 1,
312 'step' => 1,
313 ]
314 );
315 $repeater->end_controls_tabs();
316
317
318 $this->add_control(
319 'conf_custom_results',
320 [
321 'type' => Controls_Manager::REPEATER,
322 'fields' => $repeater->get_controls(),
323 'default' => [
324 ],
325 'title_field' => '{{{ location_id }}}',
326 'conditions' => [
327 'terms' => [
328 [
329 'name' => 'conf_results_type',
330 'operator' => '==',
331 'value' => 'custom_locations',
332 ]
333 ],
334 ],
335 ]
336 );
337 }
338
339 $this->end_controls_section();
340
341 }
342
343 private function generate_controls_layout() {
344 }
345
346 private function generate_controls_styles() {
347 $this->start_controls_section(
348 'styles_thmbn_section',
349 [
350 'label' => esc_html__('Main', 'wpdirectorykit'),
351 'tab' => Controls_Manager::TAB_STYLE,
352 ]
353 );
354
355 $this->add_responsive_control(
356 'row_gap_col',
357 [
358 'label' => __( 'Columns', 'wpdirectorykit' ),
359 'type' => Controls_Manager::SELECT,
360 'options' => [
361 '' => esc_html__('Default', 'wpdirectorykit'),
362 'auto' => esc_html__('Auto', 'wpdirectorykit'),
363 '100%' => '1',
364 '50%' => '2',
365 'calc(100% / 3)' => '3',
366 '25%' => '4',
367 '20%' => '5',
368 'auto_flexible' => 'auto flexible',
369 ],
370 'selectors_dictionary' => [
371 'auto' => 'width:auto;-webkit-flex:0 0 auto;flex:0 0 auto',
372 '100%' => 'width:100%;-webkit-flex:0 0 100%;flex:0 0 100%',
373 '50%' => 'width:50%;-webkit-flex:0 0 50%;flex:0 0 50%',
374 'calc(100% / 3)' => 'width:calc(100% / 3);-webkit-flex:0 0 calc(100% / 3);flex:0 0 calc(100% / 3)',
375 '25%' => 'width:25%;-webkit-flex:0 0 25%;flex:0 0 25%',
376 '20%' => 'width:20%;-webkit-flex:0 0 20%;flex:0 0 20%',
377 'auto' => 'width:auto;-webkit-flex:0 0 auto;flex:0 0 auto',
378 'auto_flexible' => 'width:auto;-webkit-flex:1 2 auto;flex:1 2 auto',
379 ],
380 'selectors' => [
381 '{{WRAPPER}} .wdk-row .wdk-col' => '{{UNIT}}',
382 ],
383 'default' => '25%',
384 'separator' => 'before',
385 ]
386 );
387
388 $this->add_responsive_control(
389 'column_gap',
390 [
391 'label' => esc_html__('Columns Gap', 'wpdirectorykit'),
392 'type' => Controls_Manager::SLIDER,
393 'default' => [
394 'size' => 10,
395 ],
396 'range' => [
397 'px' => [
398 'min' => 0,
399 'max' => 60,
400 ],
401 ],
402 'selectors' => [
403 '{{WRAPPER}} .wdk-row .wdk-col' => 'padding-left: {{SIZE}}{{UNIT}};padding-right: {{SIZE}}{{UNIT}};;',
404 '{{WRAPPER}} .wdk-row' => 'margin-left: -{{SIZE}}{{UNIT}};margin-right: -{{SIZE}}{{UNIT}};',
405 ],
406 ]
407 );
408
409 $this->add_responsive_control(
410 'row_gap',
411 [
412 'label' => esc_html__('Rows Gap', 'wpdirectorykit'),
413 'type' => Controls_Manager::SLIDER,
414 'default' => [
415 'size' => 10,
416 ],
417 'range' => [
418 'px' => [
419 'min' => 0,
420 'max' => 60,
421 ],
422 ],
423 'selectors' => [
424 '{{WRAPPER}} .wdk-row .wdk-col' => 'margin-bottom: {{SIZE}}{{UNIT}};',
425 '{{WRAPPER}} .wdk-row' => 'margin-bottom: -{{SIZE}}{{UNIT}};',
426 ],
427 ]
428 );
429
430 $this->end_controls_section();
431
432 $this->start_controls_section(
433 'styles_thmbn_type',
434 [
435 'label' => esc_html__('Thumbnail', 'wpdirectorykit'),
436 'tab' => Controls_Manager::TAB_STYLE,
437 ]
438 );
439
440 $this->add_control(
441 'layout_image_type',
442 [
443 'label' => __( 'Thumbnail Type', 'wpdirectorykit' ),
444 'type' => \Elementor\Controls_Manager::SELECT,
445 'default' => 'none4',
446 'options' => [
447 'none' => __( 'None', 'wpdirectorykit' ),
448 'contain' => __( 'Contain', 'wpdirectorykit' ),
449 'cover' => __( 'Cover', 'wpdirectorykit' ),
450 ],
451 ]
452 );
453
454 $this->add_control (
455 'layout_image_design',
456 [
457 'label' => __( 'Size style thumbnail', 'wpdirectorykit' ),
458 'type' => \Elementor\Controls_Manager::SELECT,
459 'default' => 'contain',
460 'options' => [
461 'contain' => __( 'Contain', 'wpdirectorykit' ),
462 'cover' => __( 'Cover', 'wpdirectorykit' ),
463 ],
464 'selectors' => [
465 '{{WRAPPER}} .wdk-locations-card .wdk-thumbnail .wdk-image' => 'object-fit: {{VALUE}}',
466 '{{WRAPPER}} .wdk-locations-card .wdk-thumbnail .wdk-icon' => 'object-fit: {{VALUE}}',
467 ],
468 ]
469 );
470
471 $selectors = array(
472 'normal' => '{{WRAPPER}} .wdk-locations-card .wdk-thumbnail',
473 );
474 $this->generate_renders_tabs($selectors, 'layout_image_dynamic', ['padding' ,'background','color']);
475
476 $this->add_responsive_control (
477 'styles_thmbn_des_height',
478 [
479 'label' => esc_html__('Height', 'wpdirectorykit'),
480 'type' => Controls_Manager::SLIDER,
481 'range' => [
482 'px' => [
483 'min' => 0,
484 'max' => 1500,
485 ],
486 'vw' => [
487 'min' => 0,
488 'max' => 100,
489 ],
490 ],
491 'size_units' => [ 'px', 'vw' ],
492 'default' => [
493 'size' => 350,
494 'unit' => 'px',
495 ],
496 'selectors' => [
497 '{{WRAPPER}} .wdk-locations-card .wdk-thumbnail .wdk-image' => 'height: {{SIZE}}{{UNIT}}',
498 '{{WRAPPER}} .wdk-locations-card .wdk-thumbnail .wdk-icon' => 'height: {{SIZE}}{{UNIT}}',
499 ],
500 'separator' => 'after',
501 ]
502 );
503
504 $this->end_controls_section();
505
506
507 $items = [
508 [
509 'key'=>'item_title',
510 'label'=> esc_html__('Item Title', 'wpdirectorykit'),
511 'selector'=>'.wdk-locations-grid .wdk-locations-card .wdk-title',
512 'selector_hover'=>'.wdk-locations-grid .wdk-locations-card%1$s .wdk-title',
513 'options'=>'full',
514 ],
515 [
516 'key'=>'card',
517 'label'=> esc_html__('Card', 'wpdirectorykit'),
518 'selector'=>'.wdk-locations-grid .wdk-locations-card',
519 'selector_hover'=>'.wdk-locations-grid .wdk-locations-card%1$s',
520 'options'=>'block',
521 ],
522 ];
523
524 foreach ($items as $item) {
525 $this->start_controls_section(
526 $item['key'].'_section',
527 [
528 'label' => $item['label'],
529 'tab' => Controls_Manager::TAB_STYLE,
530 ]
531 );
532 $this->add_responsive_control(
533 $item['key'].'_hide',
534 [
535 'label' => esc_html__( 'Hide Element', 'wpdirectorykit' ),
536 'type' => Controls_Manager::SWITCHER,
537 'none' => esc_html__( 'Hide', 'wpdirectorykit' ),
538 'block' => esc_html__( 'Show', 'wpdirectorykit' ),
539 'return_value' => 'none',
540 'default' => '',
541 'selectors' => [
542 '{{WRAPPER}} '.$item['selector'] => 'display: {{VALUE}};',
543 ],
544 ]
545 );
546 $selectors = array(
547 'normal' => '{{WRAPPER}} '.$item['selector'],
548 'hover'=>'{{WRAPPER}} '.$item['selector_hover'],
549 );
550 $this->generate_renders_tabs($selectors, $item['key'].'_dynamic', $item['options']);
551
552 $this->end_controls_section();
553 }
554 }
555
556 private function generate_controls_content() {
557
558 }
559
560 public function enqueue_styles_scripts() {
561 wp_enqueue_style('wdk-locations-grid');
562 }
563 }
564