Advertisement
rejuancse

crowdfunding-donate

Sep 14th, 2018
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.69 KB | None | 0 0
  1. <?php
  2. namespace Elementor;
  3.  
  4. if ( ! defined( 'ABSPATH' ) ) exit; # Exit if accessed directly
  5.  
  6. class Themeum_Widget_crowdfunding_Donate extends Widget_Base {
  7.  
  8.     public function get_name() {
  9.         return 'donate-product-grid';
  10.     }
  11.  
  12.     public function get_title() {
  13.         return __( 'Crowdfunding Donate', 'themeum-core' );
  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', 'themeum-core' )
  31.             ]
  32.         );
  33.         $this->add_control(
  34.           'product_number',
  35.           [
  36.             'label'         => __( 'Number of Products', 'themeum-core' ),
  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', 'themeum-core' ),
  46.                 'type'      => Controls_Manager::SELECT,
  47.                 'default'   => 4,
  48.                 'options'   => [
  49.                         '12'    => __( 'One Column', 'themeum-core' ),
  50.                         '6'     => __( 'Two Column', 'themeum-core' ),
  51.                         '4'     => __( 'Three Column', 'themeum-core' ),
  52.                         '3'     => __( 'Four Column', 'themeum-core' ),
  53.                     ],
  54.             ]
  55.         );
  56.         $this->add_control(
  57.           'product_cat',
  58.           [
  59.              'label'    => __( 'Product Category', 'themeum-core' ),
  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.             'product_pagination',
  68.             [
  69.                 'label'         => __( 'Post Pagination', 'themeum-core' ),
  70.                 'type'          => Controls_Manager::SWITCHER,
  71.                 'default'       => 'No',
  72.                 'label_on'      => __( 'Yes', 'themeum-core' ),
  73.                 'label_off'     => __( 'No', 'themeum-core' ),
  74.                 'selectors'     => [
  75.                     '{{WRAPPER}} iframe' => 'pointer-events: none;',
  76.                 ],
  77.             ]
  78.         );
  79.         $this->add_control(
  80.             'product_filter',
  81.             [
  82.                 'label'     => __( 'Product Show', 'themeum-core' ),
  83.                 'type'      => Controls_Manager::SELECT,
  84.                 'default'   => 'latest',
  85.                 'options'   => [
  86.                         'popular'       => __( 'Popular(By View)', 'themeum-core' ),
  87.                         'latest'        => __( 'Latest', 'themeum-core' ),
  88.                         'recommended'   => __( 'Recommended Pick', 'themeum-core' ),
  89.                     ],
  90.             ]
  91.         );
  92.  
  93.         $this->end_controls_section();
  94.  
  95.  
  96.         # Title Section
  97.         $this->start_controls_section(
  98.             'section_title_style',
  99.             [
  100.                 'label'     => __( 'Title', 'themeum-core' ),
  101.                 'tab'       => Controls_Manager::TAB_STYLE,
  102.             ]
  103.         );
  104.         $this->add_control(
  105.             'border_radius',
  106.             [
  107.                 'label' => __( 'Border Radius', 'themeum-core' ),
  108.                 'type' => Controls_Manager::DIMENSIONS,
  109.                 'size_units' => [ 'px', '%' ],
  110.                 'selectors' => [
  111.                     '{{WRAPPER}} .themeum-campaign-post' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
  112.                 ],
  113.             ]
  114.         );
  115.         $this->add_control(
  116.             'title_color',
  117.             [
  118.                 'label'     => __( 'Title Color', 'themeum-core' ),
  119.                 'type'      => Controls_Manager::COLOR,
  120.                 'scheme'    => [
  121.                         'type' => Scheme_Color::get_type(),
  122.                         'value' => Scheme_Color::COLOR_1,
  123.                     ],
  124.                 'selectors' => [
  125.                     '{{WRAPPER}} .themeum-campaign-post .entry-title a' => 'color: {{VALUE}};',
  126.                 ],
  127.             ]
  128.         );
  129.         $this->add_group_control(
  130.             Group_Control_Typography::get_type(),
  131.             [
  132.                 'name'      => 'typography',
  133.                 'scheme'    => Scheme_Typography::TYPOGRAPHY_1,
  134.                 'selector'  => '{{WRAPPER}} .themeum-campaign-post .entry-title a',
  135.             ]
  136.         );
  137.         $this->end_controls_section();
  138.         # Title Section End
  139.  
  140.         #Pagination Section
  141.         $this->start_controls_section(
  142.             'section_pagination_style',
  143.             [
  144.                 'label'     => __( 'Pagination', 'themeum-core' ),
  145.                 'tab'       => Controls_Manager::TAB_STYLE,
  146.             ]
  147.         );
  148.  
  149.         $this->add_responsive_control(
  150.             'post_align',
  151.             [
  152.                 'label'     => __( 'Alignment', 'themeum-core' ),
  153.                 'type'      => Controls_Manager::CHOOSE,
  154.                 'options'   => [
  155.                     'left'      => [
  156.                         'title' => __( 'Left', 'themeum-core' ),
  157.                         'icon'  => 'fa fa-align-left',
  158.                     ],
  159.                     'center'    => [
  160.                         'title' => __( 'Center', 'themeum-core' ),
  161.                         'icon'  => 'fa fa-align-center',
  162.                     ],
  163.                     'right'     => [
  164.                         'title' => __( 'Right', 'themeum-core' ),
  165.                         'icon'  => 'fa fa-align-right',
  166.                     ],
  167.                     'justify'   => [
  168.                         'title' => __( 'Justified', 'themeum-core' ),
  169.                         'icon'  => 'fa fa-align-justify',
  170.                     ],
  171.                 ],
  172.                 'default'   => 'center',
  173.                 'selectors' => [
  174.                     '{{WRAPPER}} .themeum-pagination' => 'text-align: {{VALUE}}; display: inline-block; width: 100%;',
  175.                 ],
  176.             ]
  177.         );
  178.         $this->end_controls_section();
  179.  
  180.         #Subtitle Section
  181.         $this->start_controls_section(
  182.             'section_price_style',
  183.             [
  184.                 'label'     => __( 'Subtitle', 'themeum-core' ),
  185.                 'tab'       => Controls_Manager::TAB_STYLE,
  186.             ]
  187.         );
  188.  
  189.         $this->add_control(
  190.             'content_color',
  191.             [
  192.                 'label'     => __( 'Content Color', 'themeum-core' ),
  193.                 'type'      => Controls_Manager::COLOR,
  194.                 'scheme'    => [
  195.                         'type' => Scheme_Color::get_type(),
  196.                         'value' => Scheme_Color::COLOR_2,
  197.                     ],
  198.                 'selectors' => [
  199.                     '{{WRAPPER}} .themeum-campaign-post > p' => 'color: {{VALUE}};',
  200.                 ],
  201.             ]
  202.         );
  203.  
  204.         $this->add_group_control(
  205.             Group_Control_Typography::get_type(),
  206.             [
  207.                 'name'      => 'typography2',
  208.                 'scheme'    => Scheme_Typography::TYPOGRAPHY_2,
  209.                 'selector'  => '{{WRAPPER}} .themeum-campaign-post > p',
  210.             ]
  211.         );
  212.     } # function _register_controls end
  213.  
  214.     protected function render( ) {
  215.  
  216.         $settings           = $this->get_settings();
  217.         $product_number     = $settings['product_number'];
  218.         $product_column     = $settings['product_column'];
  219.         $product_cat        = $settings['product_cat'];
  220.         $product_pagination = $settings['product_pagination'];
  221.         $product_filter     = $settings['product_filter'];
  222.         $page_numb          = max( 1, get_query_var('paged') );
  223.  
  224.         $arg = array(
  225.                     'post_type'     => 'product',
  226.                     'post_status'   => 'publish',
  227.                 );
  228.         if( $page_numb ){
  229.             $arg['paged'] = $page_numb;
  230.         }
  231.         if( $product_number ){
  232.             $arg['posts_per_page'] = $product_number;
  233.         }
  234.        
  235.         switch( $product_filter ){
  236.             case 'popular':
  237.                 $arg['order']           = 'DESC';
  238.                 $arg['orderby']         = 'meta_value_num';
  239.                 $arg['meta_key']        = '_post_views_count';
  240.                 break;
  241.             case 'recommended':
  242.                 $arg['order']           = 'ASC';
  243.                 $arg['meta_query']      = array(
  244.                                             array(
  245.                                                 'key' => 'themeum_handpick',
  246.                                                 'value' => 1,
  247.                                                 'compare' => '=',
  248.                                             )
  249.                                         );
  250.                 break;
  251.             default:
  252.                 # code...
  253.                 break;
  254.         }
  255.  
  256.         if( $product_cat ){
  257.             $cat_data = array();
  258.             $cat_data['relation'] = 'AND';
  259.             $cat_data[] = array(
  260.                         'taxonomy' => 'product_type',
  261.                         'field'    => 'slug',
  262.                         'terms'    => 'crowdfunding',
  263.                     );
  264.             if( $product_cat != 'allpost' ){
  265.                 $cat_data[] = array(
  266.                         'taxonomy'  => 'product_cat',
  267.                         'field'     => 'slug',
  268.                         'terms'     => $product_cat
  269.                     );
  270.             }
  271.             $arg['tax_query'] = $cat_data;
  272.         }
  273.        
  274.  
  275.         $data = new \WP_Query( $arg ); ?>
  276.        
  277.         <?php if( function_exists( 'wpneo_crowdfunding_price' ) ){ ?>
  278.             <div class="row">
  279.                 <?php if ( $data->have_posts() ) : ?>
  280.                 <?php while ( $data->have_posts() ) : $data->the_post(); ?>
  281.                     <!-- single item start -->
  282.                     <div class="col-md-4 col-sm-4 col-xs-12">
  283.                         <div class="rc-causes-item causes-style-two">
  284.                             <div class="rc-thumb">
  285.                                 <?php if ( has_post_thumbnail() ){ ?>
  286.                                     <a class="img-responsive" href="<?php the_permalink(); ?>">
  287.                                         <?php the_post_thumbnail('backnow-medium', array('class' => 'img-fluid')); ?>  
  288.                                     </a>
  289.                                 <?php } ?>
  290.                                 <div class="donate-btn">
  291.                                     <?php $baker_list = WPNEOCF()->getCustomersByProduct(); ?>
  292.                                     <a href="#"><i class="fa fa-heart"></i><?php echo count($baker_list); ?> <?php esc_html_e('Donators', 'backnow')?></a>
  293.                                 </div>
  294.                             </div>
  295.                             <div class="rc-causes-info">
  296.                                 <div class="causes-progress" data-sr="enter">
  297.                                     <?php $css_width = WPNEOCF()->getFundRaisedPercent(); if( $css_width >= 100 ){ $css_width = 100; } ?>
  298.                                     <div class="progress-bar left-anim" role="progressbar" style="width: <?php echo $css_width; ?>%;">
  299.                                         <span><?php echo $css_width; ?>%</span>
  300.                                     </div>
  301.                                 </div>
  302.                                 <h5><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>
  303.                                 <p> <?php echo wpneo_crowdfunding_price(wpneo_crowdfunding_get_total_fund_raised_by_campaign()); ?> <span class="theme__text">donated of</span>
  304.                                     <br><?php echo wpneo_crowdfunding_price(wpneo_crowdfunding_get_total_goal_by_campaign(get_the_ID())); ?> <span class="theme__text">goal</span></p>
  305.                             </div>
  306.                             <div class="rc-donate-btn">
  307.                                 <a href="#">Donate Now</a>
  308.                                 <a href="<?php the_permalink(); ?>"><?php esc_html_e('More Details', 'backnow'); ?></a>
  309.                             </div>
  310.                         </div>
  311.                     </div>
  312.                     <!-- END single item start -->
  313.                 <?php endwhile; ?>
  314.                 <?php wp_reset_query(); ?>
  315.                 <?php endif; ?>
  316.             </div>
  317.         <?php } ?>
  318.  
  319.  
  320.     <?php }
  321.     protected function _content_template() { }
  322. }
  323. Plugin::instance()->widgets_manager->register_widget_type( new Themeum_Widget_crowdfunding_Donate() );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement