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

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