PluginProbe
WP Directory Kit / 1.3.4
WP Directory Kit v1.3.4
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.3.4, at elementor-elements/classes/wdk-locations-grid.php

565 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 = $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((!empty($this->data['settings']['conf_limit'])) ? $this->data['settings']['conf_limit'] : NULL, 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::SELECT2,
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 'description' => __( 'Set 0 for unlimit', 'wpdirectorykit' ),
237 'type' => \Elementor\Controls_Manager::NUMBER,
238 'min' => 0,
239 'max' => 500,
240 'step' => 1,
241 'default' => 6,
242 'separator' => 'before',
243 'conditions' => [
244 'terms' => [
245 [
246 'name' => 'conf_results_type',
247 'operator' => '==',
248 'value' => 'results_locations',
249 ]
250 ],
251 ],
252 ]
253 );
254
255 $this->add_control(
256 'conf_order_by',
257 [
258 'label' => __('Order By Column', 'wpdirectorykit'),
259 'type' => Controls_Manager::SELECT,
260 'label_block' => true,
261 'options' => [
262 '' => __('None', 'wpdirectorykit'),
263 'location_title' => __('Title', 'wpdirectorykit'),
264 'idlocation' => __('Location id', 'wpdirectorykit'),
265 'order_index' => __('Order index', 'wpdirectorykit'),
266 'listings_counter' => __('Most Listings', 'wpdirectorykit'),
267 ],
268 'default' => 'order_index',
269 'conditions' => [
270 'terms' => [
271 [
272 'name' => 'conf_results_type',
273 'operator' => '==',
274 'value' => 'results_locations',
275 ]
276 ],
277 ],
278 ]
279 );
280
281 $this->add_control(
282 'conf_order',
283 [
284 'label' => __('Order', 'wpdirectorykit'),
285 'type' => Controls_Manager::SELECT,
286 'label_block' => true,
287 'options' => [
288 'asc' => __('Ascending', 'wpdirectorykit'),
289 'desc' => __('Descending', 'wpdirectorykit')
290 ],
291 'default' => 'desc',
292 'conditions' => [
293 'terms' => [
294 [
295 'name' => 'conf_results_type',
296 'operator' => '==',
297 'value' => 'results_locations',
298 ]
299 ],
300 ],
301 ]
302 );
303
304 if(true){
305 $repeater = new Repeater();
306 $repeater->start_controls_tabs( 'locations' );
307 $repeater->add_control(
308 'location_id',
309 [
310 'label' => __( 'ID location', 'wpdirectorykit' ),
311 'type' => \Elementor\Controls_Manager::NUMBER,
312 'min' => 1,
313 'step' => 1,
314 ]
315 );
316 $repeater->end_controls_tabs();
317
318
319 $this->add_control(
320 'conf_custom_results',
321 [
322 'type' => Controls_Manager::REPEATER,
323 'fields' => $repeater->get_controls(),
324 'default' => [
325 ],
326 'title_field' => '{{{ location_id }}}',
327 'conditions' => [
328 'terms' => [
329 [
330 'name' => 'conf_results_type',
331 'operator' => '==',
332 'value' => 'custom_locations',
333 ]
334 ],
335 ],
336 ]
337 );
338 }
339
340 $this->end_controls_section();
341
342 }
343
344 private function generate_controls_layout() {
345 }
346
347 private function generate_controls_styles() {
348 $this->start_controls_section(
349 'styles_thmbn_section',
350 [
351 'label' => esc_html__('Main', 'wpdirectorykit'),
352 'tab' => Controls_Manager::TAB_STYLE,
353 ]
354 );
355
356 $this->add_responsive_control(
357 'row_gap_col',
358 [
359 'label' => __( 'Columns', 'wpdirectorykit' ),
360 'type' => Controls_Manager::SELECT,
361 'options' => [
362 '' => esc_html__('Default', 'wpdirectorykit'),
363 'auto' => esc_html__('Auto', 'wpdirectorykit'),
364 '100%' => '1',
365 '50%' => '2',
366 'calc(100% / 3)' => '3',
367 '25%' => '4',
368 '20%' => '5',
369 'auto_flexible' => 'auto flexible',
370 ],
371 'selectors_dictionary' => [
372 'auto' => 'width:auto;-webkit-flex:0 0 auto;flex:0 0 auto',
373 '100%' => 'width:100%;-webkit-flex:0 0 100%;flex:0 0 100%',
374 '50%' => 'width:50%;-webkit-flex:0 0 50%;flex:0 0 50%',
375 'calc(100% / 3)' => 'width:calc(100% / 3);-webkit-flex:0 0 calc(100% / 3);flex:0 0 calc(100% / 3)',
376 '25%' => 'width:25%;-webkit-flex:0 0 25%;flex:0 0 25%',
377 '20%' => 'width:20%;-webkit-flex:0 0 20%;flex:0 0 20%',
378 'auto' => 'width:auto;-webkit-flex:0 0 auto;flex:0 0 auto',
379 'auto_flexible' => 'width:auto;-webkit-flex:1 2 auto;flex:1 2 auto',
380 ],
381 'selectors' => [
382 '{{WRAPPER}} .wdk-row .wdk-col' => '{{UNIT}}',
383 ],
384 'default' => '25%',
385 'separator' => 'before',
386 ]
387 );
388
389 $this->add_responsive_control(
390 'column_gap',
391 [
392 'label' => esc_html__('Columns Gap', 'wpdirectorykit'),
393 'type' => Controls_Manager::SLIDER,
394 'default' => [
395 'size' => 10,
396 ],
397 'range' => [
398 'px' => [
399 'min' => 0,
400 'max' => 60,
401 ],
402 ],
403 'selectors' => [
404 '{{WRAPPER}} .wdk-row .wdk-col' => 'padding-left: {{SIZE}}{{UNIT}};padding-right: {{SIZE}}{{UNIT}};;',
405 '{{WRAPPER}} .wdk-row' => 'margin-left: -{{SIZE}}{{UNIT}};margin-right: -{{SIZE}}{{UNIT}};',
406 ],
407 ]
408 );
409
410 $this->add_responsive_control(
411 'row_gap',
412 [
413 'label' => esc_html__('Rows Gap', 'wpdirectorykit'),
414 'type' => Controls_Manager::SLIDER,
415 'default' => [
416 'size' => 10,
417 ],
418 'range' => [
419 'px' => [
420 'min' => 0,
421 'max' => 60,
422 ],
423 ],
424 'selectors' => [
425 '{{WRAPPER}} .wdk-row .wdk-col' => 'margin-bottom: {{SIZE}}{{UNIT}};',
426 '{{WRAPPER}} .wdk-row' => 'margin-bottom: -{{SIZE}}{{UNIT}};',
427 ],
428 ]
429 );
430
431 $this->end_controls_section();
432
433 $this->start_controls_section(
434 'styles_thmbn_type',
435 [
436 'label' => esc_html__('Thumbnail', 'wpdirectorykit'),
437 'tab' => Controls_Manager::TAB_STYLE,
438 ]
439 );
440
441 $this->add_control(
442 'layout_image_type',
443 [
444 'label' => __( 'Thumbnail Type', 'wpdirectorykit' ),
445 'type' => \Elementor\Controls_Manager::SELECT,
446 'default' => 'none4',
447 'options' => [
448 'none' => __( 'None', 'wpdirectorykit' ),
449 'contain' => __( 'Contain', 'wpdirectorykit' ),
450 'cover' => __( 'Cover', 'wpdirectorykit' ),
451 ],
452 ]
453 );
454
455 $this->add_control (
456 'layout_image_design',
457 [
458 'label' => __( 'Size style thumbnail', 'wpdirectorykit' ),
459 'type' => \Elementor\Controls_Manager::SELECT,
460 'default' => 'contain',
461 'options' => [
462 'contain' => __( 'Contain', 'wpdirectorykit' ),
463 'cover' => __( 'Cover', 'wpdirectorykit' ),
464 ],
465 'selectors' => [
466 '{{WRAPPER}} .wdk-locations-card .wdk-thumbnail .wdk-image' => 'object-fit: {{VALUE}}',
467 '{{WRAPPER}} .wdk-locations-card .wdk-thumbnail .wdk-icon' => 'object-fit: {{VALUE}}',
468 ],
469 ]
470 );
471
472 $selectors = array(
473 'normal' => '{{WRAPPER}} .wdk-locations-card .wdk-thumbnail',
474 );
475 $this->generate_renders_tabs($selectors, 'layout_image_dynamic', ['padding' ,'background','color']);
476
477 $this->add_responsive_control (
478 'styles_thmbn_des_height',
479 [
480 'label' => esc_html__('Height', 'wpdirectorykit'),
481 'type' => Controls_Manager::SLIDER,
482 'range' => [
483 'px' => [
484 'min' => 0,
485 'max' => 1500,
486 ],
487 'vw' => [
488 'min' => 0,
489 'max' => 100,
490 ],
491 ],
492 'size_units' => [ 'px', 'vw' ],
493 'default' => [
494 'size' => 350,
495 'unit' => 'px',
496 ],
497 'selectors' => [
498 '{{WRAPPER}} .wdk-locations-card .wdk-thumbnail .wdk-image' => 'height: {{SIZE}}{{UNIT}}',
499 '{{WRAPPER}} .wdk-locations-card .wdk-thumbnail .wdk-icon' => 'height: {{SIZE}}{{UNIT}}',
500 ],
501 'separator' => 'after',
502 ]
503 );
504
505 $this->end_controls_section();
506
507
508 $items = [
509 [
510 'key'=>'item_title',
511 'label'=> esc_html__('Item Title', 'wpdirectorykit'),
512 'selector'=>'.wdk-locations-grid .wdk-locations-card .wdk-title',
513 'selector_hover'=>'.wdk-locations-grid .wdk-locations-card%1$s .wdk-title',
514 'options'=>'full',
515 ],
516 [
517 'key'=>'card',
518 'label'=> esc_html__('Card', 'wpdirectorykit'),
519 'selector'=>'.wdk-locations-grid .wdk-locations-card',
520 'selector_hover'=>'.wdk-locations-grid .wdk-locations-card%1$s',
521 'options'=>'block',
522 ],
523 ];
524
525 foreach ($items as $item) {
526 $this->start_controls_section(
527 $item['key'].'_section',
528 [
529 'label' => $item['label'],
530 'tab' => Controls_Manager::TAB_STYLE,
531 ]
532 );
533 $this->add_responsive_control(
534 $item['key'].'_hide',
535 [
536 'label' => esc_html__( 'Hide Element', 'wpdirectorykit' ),
537 'type' => Controls_Manager::SWITCHER,
538 'none' => esc_html__( 'Hide', 'wpdirectorykit' ),
539 'block' => esc_html__( 'Show', 'wpdirectorykit' ),
540 'return_value' => 'none',
541 'default' => '',
542 'selectors' => [
543 '{{WRAPPER}} '.$item['selector'] => 'display: {{VALUE}};',
544 ],
545 ]
546 );
547 $selectors = array(
548 'normal' => '{{WRAPPER}} '.$item['selector'],
549 'hover'=>'{{WRAPPER}} '.$item['selector_hover'],
550 );
551 $this->generate_renders_tabs($selectors, $item['key'].'_dynamic', $item['options']);
552
553 $this->end_controls_section();
554 }
555 }
556
557 private function generate_controls_content() {
558
559 }
560
561 public function enqueue_styles_scripts() {
562 wp_enqueue_style('wdk-locations-grid');
563 }
564 }
565