Advertisement
rejuancse

thm-crowdfunding-grid

Sep 18th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 11.67 KB | None | 0 0
  1. <?php
  2. namespace Elementor;
  3.  
  4. if ( ! defined( 'ABSPATH' ) ) exit; # Exit if accessed directly
  5.  
  6. class Themeum_Widget_Product_Grid extends Widget_Base {
  7.  
  8.     public function get_name() {
  9.         return 'backer-product-grid';
  10.     }
  11.  
  12.     public function get_title() {
  13.         return __( 'Themeum Crowdfunding Grid', 'backer' );
  14.     }
  15.  
  16.     public function get_icon() {
  17.         return 'eicon-inner-section';
  18.     }
  19.  
  20.     public function get_categories() {
  21.         return [ 'themeum-elementor' ];
  22.     }
  23.  
  24.  
  25.     protected function _register_controls() {
  26.  
  27.         $this->start_controls_section(
  28.             'product_element',
  29.             [
  30.                 'label'     => __( 'Product Element', 'backer' )
  31.             ]
  32.         );
  33.         $this->add_control(
  34.           'product_number',
  35.           [
  36.             'label'         => __( 'Number of Products', 'backer' ),
  37.             'type'          => Controls_Manager::NUMBER,
  38.             'label_block'   => true,
  39.             'default'       => 6
  40.           ]
  41.         );
  42.         $this->add_control(
  43.             'product_column',
  44.             [
  45.                 'label'     => __( 'Number of Column', 'backer' ),
  46.                 'type'      => Controls_Manager::SELECT,
  47.                 'default'   => 4,
  48.                 'options'   => [
  49.                         '12'    => __( 'One Column', 'backer' ),
  50.                         '6'     => __( 'Two Column', 'backer' ),
  51.                         '4'     => __( 'Three Column', 'backer' ),
  52.                         '3'     => __( 'Four Column', 'backer' ),
  53.                     ],
  54.             ]
  55.         );
  56.         $this->add_control(
  57.           'product_cat',
  58.           [
  59.              'label'    => __( 'Product Category', 'backer' ),
  60.              'type'     => Controls_Manager::SELECT,
  61.              'options'  => crowdfunding_all_category_list( 'product_cat' ),
  62.              'multiple' => true,
  63.              'default'  => 'allpost',
  64.           ]
  65.         );
  66.         $this->add_control(
  67.           'textlimit',
  68.           [
  69.             'label'         => __( 'Text Limit Of Content', 'backer' ),
  70.             'type'          => Controls_Manager::NUMBER,
  71.             'label_block'   => true,
  72.             'default'       => 280,
  73.           ]
  74.         );
  75.         $this->add_control(
  76.             'product_pagination',
  77.             [
  78.                 'label'         => __( 'Post Pagination', 'backer' ),
  79.                 'type'          => Controls_Manager::SWITCHER,
  80.                 'default'       => 'No',
  81.                 'label_on'      => __( 'Yes', 'backer' ),
  82.                 'label_off'     => __( 'No', 'backer' ),
  83.                 'selectors'     => [
  84.                     '{{WRAPPER}} iframe' => 'pointer-events: none;',
  85.                 ],
  86.             ]
  87.         );
  88.         $this->add_control(
  89.             'product_filter',
  90.             [
  91.                 'label'     => __( 'Product Show', 'backer' ),
  92.                 'type'      => Controls_Manager::SELECT,
  93.                 'default'   => 'latest',
  94.                 'options'   => [
  95.                         'popular'       => __( 'Popular(By View)', 'backer' ),
  96.                         'latest'        => __( 'Latest', 'backer' ),
  97.                         'recommended'   => __( 'Recommended Pick', 'backer' ),
  98.                     ],
  99.             ]
  100.         );
  101.  
  102.         $this->end_controls_section();
  103.  
  104.  
  105.         # Title Section
  106.         $this->start_controls_section(
  107.             'section_title_style',
  108.             [
  109.                 'label'     => __( 'Title', 'backer' ),
  110.                 'tab'       => Controls_Manager::TAB_STYLE,
  111.             ]
  112.         );
  113.         $this->add_control(
  114.             'border_radius',
  115.             [
  116.                 'label' => __( 'Border Radius', 'backer' ),
  117.                 'type' => Controls_Manager::DIMENSIONS,
  118.                 'size_units' => [ 'px', '%' ],
  119.                 'selectors' => [
  120.                     '{{WRAPPER}} .themeum-campaign-post' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
  121.                 ],
  122.             ]
  123.         );
  124.         $this->add_control(
  125.             'title_color',
  126.             [
  127.                 'label'     => __( 'Title Color', 'backer' ),
  128.                 'type'      => Controls_Manager::COLOR,
  129.                 'scheme'    => [
  130.                         'type' => Scheme_Color::get_type(),
  131.                         'value' => Scheme_Color::COLOR_1,
  132.                     ],
  133.                 'selectors' => [
  134.                     '{{WRAPPER}} .themeum-campaign-post .entry-title a' => 'color: {{VALUE}};',
  135.                 ],
  136.             ]
  137.         );
  138.         $this->add_group_control(
  139.             Group_Control_Typography::get_type(),
  140.             [
  141.                 'name'      => 'typography',
  142.                 'scheme'    => Scheme_Typography::TYPOGRAPHY_1,
  143.                 'selector'  => '{{WRAPPER}} .themeum-campaign-post .entry-title a',
  144.             ]
  145.         );
  146.         $this->end_controls_section();
  147.         # Title Section End
  148.  
  149.         #Pagination Section
  150.         $this->start_controls_section(
  151.             'section_pagination_style',
  152.             [
  153.                 'label'     => __( 'Pagination', 'backer' ),
  154.                 'tab'       => Controls_Manager::TAB_STYLE,
  155.             ]
  156.         );
  157.  
  158.         $this->add_responsive_control(
  159.             'post_align',
  160.             [
  161.                 'label'     => __( 'Alignment', 'backer' ),
  162.                 'type'      => Controls_Manager::CHOOSE,
  163.                 'options'   => [
  164.                     'left'      => [
  165.                         'title' => __( 'Left', 'backer' ),
  166.                         'icon'  => 'fa fa-align-left',
  167.                     ],
  168.                     'center'    => [
  169.                         'title' => __( 'Center', 'backer' ),
  170.                         'icon'  => 'fa fa-align-center',
  171.                     ],
  172.                     'right'     => [
  173.                         'title' => __( 'Right', 'backer' ),
  174.                         'icon'  => 'fa fa-align-right',
  175.                     ],
  176.                     'justify'   => [
  177.                         'title' => __( 'Justified', 'backer' ),
  178.                         'icon'  => 'fa fa-align-justify',
  179.                     ],
  180.                 ],
  181.                 'default'   => 'center',
  182.                 'selectors' => [
  183.                     '{{WRAPPER}} .themeum-pagination' => 'text-align: {{VALUE}}; display: inline-block; width: 100%;',
  184.                 ],
  185.             ]
  186.         );
  187.         $this->end_controls_section();
  188.  
  189.         #Subtitle Section
  190.         $this->start_controls_section(
  191.             'section_price_style',
  192.             [
  193.                 'label'     => __( 'Subtitle', 'backer' ),
  194.                 'tab'       => Controls_Manager::TAB_STYLE,
  195.             ]
  196.         );
  197.  
  198.         $this->add_control(
  199.             'content_color',
  200.             [
  201.                 'label'     => __( 'Content Color', 'backer' ),
  202.                 'type'      => Controls_Manager::COLOR,
  203.                 'scheme'    => [
  204.                         'type' => Scheme_Color::get_type(),
  205.                         'value' => Scheme_Color::COLOR_2,
  206.                     ],
  207.                 'selectors' => [
  208.                     '{{WRAPPER}} .themeum-campaign-post > p' => 'color: {{VALUE}};',
  209.                 ],
  210.             ]
  211.         );
  212.  
  213.         $this->add_group_control(
  214.             Group_Control_Typography::get_type(),
  215.             [
  216.                 'name'      => 'typography2',
  217.                 'scheme'    => Scheme_Typography::TYPOGRAPHY_2,
  218.                 'selector'  => '{{WRAPPER}} .themeum-campaign-post > p',
  219.             ]
  220.         );
  221.     } # function _register_controls end
  222.  
  223.     protected function render( ) {
  224.  
  225.         $settings           = $this->get_settings();
  226.         $product_number     = $settings['product_number'];
  227.         $product_column     = $settings['product_column'];
  228.         $product_cat        = $settings['product_cat'];
  229.         $product_pagination = $settings['product_pagination'];
  230.         $textlimit          = $settings['textlimit'];
  231.         $product_filter     = $settings['product_filter'];
  232.         $page_numb          = max( 1, get_query_var('paged') );
  233.  
  234.         $arg = array(
  235.                     'post_type'     => 'product',
  236.                     'post_status'   => 'publish',
  237.                 );
  238.         if( $page_numb ){
  239.             $arg['paged'] = $page_numb;
  240.         }
  241.         if( $product_number ){
  242.             $arg['posts_per_page'] = $product_number;
  243.         }
  244.        
  245.         switch( $product_filter ){
  246.                 case 'popular':
  247.                     $arg['order']           = 'DESC';
  248.                     $arg['orderby']         = 'meta_value_num';
  249.                     $arg['meta_key']        = '_post_views_count';
  250.                     break;
  251.                 case 'recommended':
  252.                     $arg['order']           = 'ASC';
  253.                     $arg['meta_query']      = array(
  254.                                                 array(
  255.                                                     'key' => 'themeum_handpick',
  256.                                                     'value' => 1,
  257.                                                     'compare' => '=',
  258.                                                 )
  259.                                             );
  260.                     break;
  261.                 default:
  262.                     # code...
  263.                     break;
  264.             }
  265.  
  266.  
  267.         if( $product_cat ){
  268.             $cat_data = array();
  269.             $cat_data['relation'] = 'AND';
  270.             $cat_data[] = array(
  271.                         'taxonomy' => 'product_type',
  272.                         'field'    => 'slug',
  273.                         'terms'    => 'crowdfunding',
  274.                     );
  275.             if( $product_cat != 'allpost' ){
  276.                 $cat_data[] = array(
  277.                         'taxonomy'  => 'product_cat',
  278.                         'field'     => 'slug',
  279.                         'terms'     => $product_cat
  280.                     );
  281.             }
  282.             $arg['tax_query'] = $cat_data;
  283.         }
  284.        
  285.         // echo '<pre>';
  286.         // print_r( $arg );
  287.         // echo '</pre>';
  288.  
  289.         $data = new \WP_Query( $arg );
  290.  
  291.     ?>
  292.     <?php if( function_exists( 'wpneo_crowdfunding_price' ) ){ ?>
  293.         <div class="row">
  294.             <?php if ( $data->have_posts() ) : ?>
  295.                 <?php while ( $data->have_posts() ) : $data->the_post(); ?>
  296.                     <div class="col-12 col-sm-12 col-md-6 col-lg-<?php echo $product_column; ?>"><?php /*echo get_post_meta( get_the_ID(),'_nf_duration_end',true );*/ ?>
  297.                         <div class="themeum-campaign-post">
  298.                             <?php if ( has_post_thumbnail() ){ ?>
  299.                                 <div class="themeum-campaign-img">
  300.                                     <a class="review-item-image"  href="<?php the_permalink(); ?>"><?php the_post_thumbnail('backer-portfo', array('class' => 'img-fluid')); ?></a>
  301.                                 </div>
  302.                             <?php } ?>
  303.                             <div class="themeum-campaign-post-content clearfix">
  304.                                 <h3 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
  305.                                 <span class="entry-author"><?php _e('by','backer'); ?> <a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>"><?php echo get_the_author_meta('display_name'); ?></a></span>
  306.                                 <span class="entry-category"><?php echo get_the_term_list( get_the_ID(), 'product_cat', 'in ', ', ' ); ?></span>
  307.                                 <p><?php echo backer_excerpt_max_charlength( $textlimit ); ?></p>
  308.                             </div>
  309.                             <div class="progressbar-content-wrapper">
  310.                                 <div class="thm-progress-bar">
  311.                                     <div class="lead"><span class="thm-Price-amount"><?php echo wpneo_crowdfunding_price(wpneo_crowdfunding_get_total_fund_raised_by_campaign()); ?></span> <?php _e('Raised','backer'); ?> <span class="percentag pull-right"><?php echo WPNEOCF()->getFundRaisedPercentFormat(); ?></span></div>
  312.                                     <div class="progress">
  313.                                     <?php $css_width = WPNEOCF()->getFundRaisedPercent(); if( $css_width >= 100 ){ $css_width = 100; } ?>
  314.                                     <div class="progress-bar progress-bar-primary six-sec-ease-in-out" role="progressbar" data-valuetransitiongoal="<?php echo $css_width; ?>" style="width: <?php echo $css_width; ?>%;"></div>
  315.                                     </div>
  316.                                 </div>
  317.  
  318.  
  319.                                 <div class="thm-funding-goal">
  320.                                     <div class="thm-meta-desc"><span class="thm-Price-amount"><?php echo wpneo_crowdfunding_price(wpneo_crowdfunding_get_total_goal_by_campaign(get_the_ID())); ?> </span><?php _e('Goal','backer'); ?></div>
  321.  
  322.                                     <?php
  323.                                     $wpneo_campaign_end_method = get_post_meta(get_the_ID(), 'wpneo_campaign_end_method', true);
  324.                                     if ($wpneo_campaign_end_method != 'never_end'){ ?>
  325.                                         <div class="thm-meta-name pull-right"><?php echo WPNEOCF()->dateRemaining(); ?> <?php _e('Days to Go','backer'); ?></div>
  326.                                     <?php } ?>
  327.                                 </div>
  328.  
  329.  
  330.                             </div>
  331.                             <div class="themeum-campaign-location">
  332.                             <span class="location"><i class="fa fa-map-marker"></i> <?php echo wpneo_crowdfunding_get_campaigns_location(); ?></span>
  333.                             </div>
  334.                         </div>
  335.                     </div>
  336.                 <?php endwhile; ?>
  337.                     <div class="col-12">
  338.                         <?php
  339.                             if( $product_pagination == 'yes' ){
  340.                                 $max_page = $data->max_num_pages;
  341.                                 echo backer_pagination( $page_numb, $max_page );
  342.                             }
  343.                         ?>
  344.                     </div>
  345.                 <?php wp_reset_query(); ?>
  346.             <?php endif; ?>
  347.         </div>
  348.     <?php } ?>
  349.  
  350.  
  351.     <?php }
  352.     protected function _content_template() { }
  353. }
  354. Plugin::instance()->widgets_manager->register_widget_type( new Themeum_Widget_Product_Grid() );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement