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-locations-grid.php

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

565 lines 20.4 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
35 \Elementor\Controls_Manager::add_tab(
36 'tab_layout',
37 esc_html__('Layout', 'wpdirectorykit')
38 );
39
40 \Elementor\Controls_Manager::add_tab(
41 'tab_content',
42 esc_html__('Main', 'wpdirectorykit')
43 );
44
45
46 if ($this->is_edit_mode_load()) {
47 $this->enqueue_styles_scripts();
48 }
49
50 parent::__construct($data, $args);
51 }
52
53 /**
54 * Retrieve the widget name.
55 *
56 * @since 1.1.0
57 *
58 * @access public
59 *
60 * @return string Widget name.
61 */
62 public function get_name() {
63 return 'wdk-locations-grid';
64 }
65
66 /**
67 * Retrieve the widget title.
68 *
69 * @since 1.1.0
70 *
71 * @access public
72 *
73 * @return string Widget title.
74 */
75 public function get_title() {
76 return esc_html__('Wdk Locations Grid', 'wpdirectorykit');
77 }
78
79 /**
80 * Retrieve the widget icon.
81 *
82 * @since 1.1.0
83 *
84 * @access public
85 *
86 * @return string Widget icon.
87 */
88 public function get_icon() {
89 return 'eicon-product-related';
90 }
91
92 /**
93 * Register the widget controls.
94 *
95 * Adds different input fields to allow the user to change and customize the widget settings.
96 *
97 * @since 1.1.0
98 *
99 * @access protected
100 */
101 protected function register_controls() {
102 $this->generate_controls_conf();
103 $this->generate_controls_layout();
104 $this->generate_controls_styles();
105 $this->generate_controls_content();
106
107 $this->insert_pro_message('1');
108 parent::register_controls();
109 }
110
111 /**
112 * Render the widget output on the frontend.
113 *
114 * Written in PHP and used to generate the final HTML.
115 *
116 * @since 1.1.0
117 *
118 * @access protected
119 */
120 protected function render() {
121 parent::render();
122 $this->data['id_element'] = $this->get_id();
123 $this->data['settings'] = $this->get_settings();
124
125 $controller = 'location';
126 $this->WMVC->model($controller.'_m');
127 $this->WMVC->model('listing_m');
128
129 $this->data['results'] = false;
130
131 if($this->data['settings']['conf_results_type'] == 'custom_locations') {
132
133 $locations_ids = array();
134 foreach($this->data['settings']['conf_custom_results'] as $location) {
135 if(isset($location['location_id']) && !empty($location['location_id'])) {
136 $locations_ids [] = (int)$location['location_id'];
137 }
138 }
139
140 /* where in */
141 if(!empty($locations_ids)){
142
143 $this->WMVC->db->select($this->WMVC->{$controller.'_m'}->_table_name.'.*, COUNT('.$this->WMVC->listing_m->_table_name.'.post_id) AS listings_counter');
144 $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');
145 $this->WMVC->db->where($this->WMVC->{$controller.'_m'}->_table_name.'.idlocation IN(' . implode(',', $locations_ids) . ')', null, false);
146 $this->WMVC->db->order_by('FIELD('.$this->WMVC->{$controller.'_m'}->_table_name.'.idlocation, '. implode(',', $locations_ids) . ')');
147 $this->WMVC->db->group_by($this->WMVC->{$controller.'_m'}->_primary_key);
148
149 $this->data['results'] = $this->WMVC->{$controller.'_m'}->get();
150 }
151
152 } else {
153 $order_by = NULL;
154 if(!empty($this->data['settings']['conf_order_by']))
155 $order_by = wdk_esc_sql_order_by($this->data['settings']['conf_order_by'].' '.$this->data['settings']['conf_order'], $this->WMVC->{$controller.'_m'}->getAllowedOrderBy());
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 $this->data['is_edit_mode']= false;
164 if(Plugin::$instance->editor->is_edit_mode())
165 $this->data['is_edit_mode']= true;
166
167 $this->view('wdk-locations-grid', $this->data, true);
168 }
169
170
171 private function generate_controls_conf() {
172 $this->start_controls_section(
173 'tab_conf_main_section',
174 [
175 'label' => esc_html__('Main', 'wpdirectorykit'),
176 'tab' => '1',
177 ]
178 );
179
180 $pages = array('' => __('Not Selected', 'wpdirectorykit'));
181 foreach(get_pages(array('sort_column' => 'post_title')) as $page)
182 {
183 $pages[$page->ID] = $page->post_title.' #'.$page->ID;
184 }
185
186 $this->add_control(
187 'conf_link',
188 [
189 'label' => __( 'Open results on page', 'wpdirectorykit' ),
190 'type' => \Elementor\Controls_Manager::SELECT2,
191 'default' => '',
192 'options' => $pages
193 ]
194 );
195
196 $this->add_control(
197 'conf_results_type',
198 [
199 'label' => __( 'Show type', 'wpdirectorykit' ),
200 'type' => \Elementor\Controls_Manager::SELECT,
201 'default' => 'results_locations',
202 'options' => [
203 'results_locations' => __( 'All Locations', 'wpdirectorykit' ),
204 'custom_locations' => __( 'Specific', 'wpdirectorykit' ),
205 ],
206 'separator' => 'after',
207 ]
208 );
209
210 $this->add_control(
211 'important_note',
212 [
213 'label' => '',
214 'type' => \Elementor\Controls_Manager::RAW_HTML,
215 /* translators: 1: URL. */
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','em', 'vw', '%', 'custom' ],
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