<?php 
    if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    $OT_builder = new OT_home_builder; 
    //get block data
    $data = $OT_builder->get_data(); 
    //set query
    $my_query = $data[0]; 
    //extract array data
    extract($data[1]); 

    $postDate = get_option(THEME_NAME."_post_date");
    $postComments = get_option(THEME_NAME."_post_comment");
    $postAuthor = get_option(THEME_NAME."_post_author");

    // author id
    $user_ID = get_the_author_meta('ID');

   
?>
    <!-- BEGIN .def-panel -->
    <div class="def-panel">
        <?php if($title) { ?>
            <div class="panel-title">
                <h2 style="border-bottom: 2px solid #<?php echo $color;?>; color: #<?php echo $color;?>;"><?php echo $title;?></h2>
            </div>
        <?php } ?>
        <div class="review-block">
            <?php if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); ?>
                <?php 
                    $OT_builder->set_double($my_query->post->ID);
                    $ratings = get_post_meta( $post->ID, "_".THEME_NAME."_ratings", true );
                    $categories = get_the_category($post->ID); 
                    $count = count($categories);
                    $randID = rand(0,$count-1);
                ?>
                    <div class="item">
                        <a href="<?php the_permalink();?>">
                            <?php echo ot_image_html($my_query->post->ID,583,389,"item-photo"); ?>
                        </a>
                        <h3><a href="<?php the_permalink();?>"><?php the_title();?></a></h3>
                        <div class="rating-table">
                            <?php 
                                $average =  ot_avarage_rating($my_query->post->ID);
                                if($ratings) {
                                    $totalRate = array();
                                    $rating = explode(";", $ratings);
                                    foreach($rating as $rate) { 
                                        $ratingValues = explode(":", $rate);
                                        if(isset($ratingValues[1])) {
                                            $ratingPrecentage = (str_replace(",",".",$ratingValues[1]))*20;
                                        }
                                        $totalRate[] = $ratingPrecentage;
                                        if($ratingValues[0]) {

                            ?>

                                <div class="rate-item">
                                    <div class="right ot-star-rating"><span style="width:<?php echo $ratingPrecentage;?>%"><strong class="rating"><?php echo floor(($ratingPrecentage/5) * 2) / 2;?></strong> <?php esc_html_e("out of 5",'gadgetine-theme');?></span></div>
                                    <strong><?php echo $ratingValues[0];?></strong>
                                </div>
                            <?php 
                                        } 
                                    }
                                }
                            ?>

                        </div>
                        <p><?php echo get_post_meta ( $post->ID, "_".THEME_NAME."_conclusion", true );?>
                            <a href="<?php the_permalink();?>"><?php esc_html_e("Read More ...",'gadgetine-theme');?></a>
                        </p>
                    </div>
            <?php endwhile; ?>
            <?php endif; ?>
        </div>
    <!-- END .panel -->
    </div>