<?php

/**
 * Use for the show the testimonials at home page and in testimonial page with shortcode
 * @param int $pageId default is null the id of a post
 * @param boolean $isCustomizer default is false if set to true it mean the output is set for the home page
 * @param int $i default null
 * @param boolean $showStaticVals default is false
 * @return string
 * @author Luzuk <support@luzuk.com>
 * */
function testimonialShortCode($pageId = null, $isCustomizer = false, $i = 0, $showStaticVals = false, $totalItems=0) {
    global $query;
    $args = array('post_type' => 'our-testimonial');
    if (!empty($pageId)) {
        $args['page_id'] = absint($pageId);
    } else {
        $args['paged'] = max(1, get_query_var('paged'));
    }
    $args['posts_per_page'] = (!empty($args['posts_per_page'])) ? $args['posts_per_page'] : -1;
    $i = !empty($i) && is_numeric($i) ? $i : 0;
    $text = '';
    $query = new WP_Query($args);
    // print_r($query);
    if ($query->have_posts()):
        $cssCls = ($isCustomizer == false) ? 'col-md-12 col-sm-12' : 'col-sm-10 col-sm-offset-1';

        ob_start();
        while ($query->have_posts()) : $query->the_post();
            $post = get_post();
            $lz_fitness_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'total-team-thumb');
           // echo"(($i == 0) || ($i%2)==0)".__LINE__;
            if(($i == 0) || ($i%1)==0){
                ?>
                <div class="item <?php if ($i == 0) { ?>active<?php } ?> ts-b wow zoomIn">
                   
                    <div class="ts-area-single ">
                        <div class="col-md-2 pd-0">
                            <div class="ts-shape-area">
                                <i class="fa fa-quote-left" aria-hidden="true"></i>
                            </div>
                        </div>
                        <div class="col-md-10 pd-0 innts-t">
                            <div class="ts-area-c section-area-text">   
                               <p>
                                <?php
                                    if (has_excerpt()) {
                                        echo get_the_excerpt();
                                    } else {
                                        echo get_the_content();
                                    }
                                    ?>
                                </p> 
                            </div> 
                        </div>
                        <div class="clearfix"></div>
                        <div class="pd-0 ts-area-bx">
                             <div class="col-md-4 col-sm-3 col-xs-3 pd-0 innts-img">
                                 <div class="ts-area-thumb">
                                    <img src="<?php echo (!empty($lz_fitness_image[0])) ? $lz_fitness_image[0] : get_template_directory_uri() . '/images/team-thumb.png' ?>" class="img-responsive" alt="<?php the_title(); ?>" />
                                </div>
                             </div>
                            <div class="col-md-8 col-sm-9 col-xs-9">
                              <h6 class="ts-area-title"><?php the_title(); ?></h6>
                            </div>
                            <div class="clearfix"></div>
                        </div>
                                    
                        <div class="clearfix"></div>
                    </div>

                </div>

    <?php
}
?>

<?php
endwhile;
$text = ob_get_contents();
ob_clean();
ob_end_flush();
endif;
wp_reset_postdata();
    // echo $text;
return $text;
}

//adding a shortcode for the team / team list 
add_shortcode('TESTIMONIALS', 'testimonialShortCode');


/**
 * Get list of all categories from woocommerce theme
 * @param int $isObject return type in array of object default is true
 * @param int $itemPerPagenumber of items per page default -1
 * @param int $isParents to show the only parents default '0'
 * @param int $orderby name of field ordeing with default 'name'
 * @param int $order assending of deseinging default 'ASC'
 * @param int $hideEmpty show the empty categories or not default 'false'
 * @return Array/Object 
 * @author Luzuk 
 * @since version 1.0
 **/
function getWooCategories($isObject = true, $id=0, $isParents = 0, $itemPerPagenumber = -1, $orderby='name', $order='ASC', $hideEmpty = false){
    $categories = array();
    // echo 'asdlkfjoasdoh';
    $args = array(
        'taxonomy' => 'product_cat',
        'orderby' => $orderby, // 'slug',
        'hide_empty' => $hideEmpty,
        'number'=> 0
    );

    if($isParents == 0 ){
        $args['parent'] = $isParents;
    }

    if(!empty($id) && $id >0 ){
        $args['term_taxonomy_id'] = $id;
    }
    $parent_terms = get_terms($args);
    // print_r($parent_terms);
    foreach ($parent_terms as $pterm) {
        if($isObject === true){
            $categories[] = $pterm;
        }elseif(!empty($pterm->term_id)){
            $categories[$pterm->term_id] = $pterm->name;
            // echo '&*&*&';
        }
        
    }
    // print_r($categories);
    return $categories;
}   
