<?php 
/**
 * The template for displaying the review breakdown
 *
 * @package WordPress
 * @subpackage Edition
 * @since Edition 1.0
 */ 
global 
$tw_entry,  // Get post options
$post,
$fields_installed;      // Get post data 

$breakdown_title      = $fields_installed ? get_field('breakdown_title') : '';
$breakdown_post_title = $fields_installed ? get_field('breakdown_post_title') : ''; ?>

<?php if ( $tw_entry->review_post == 'yes' && isset($tw_entry->review_criteria[0]) ) : ?>
	<div class="breakdown-wrap" itemscope itemtype="http://schema.org/Review">

		<div itemprop="itemReviewed" itemscope itemtype="http://schema.org/Thing">
			<meta itemprop="name" content="<?php the_title_attribute(); ?>" />
		</div>
		<span itemprop="author" itemscope itemtype="http://schema.org/Person">
            <meta itemprop="name" content="<?php echo esc_attr(get_the_author()); ?>" />
        </span>

		<div class="section-title">
			<p>
				<?php 
					if ( $breakdown_title ) {
						echo '<span>' . $breakdown_title;
						if ( $breakdown_title && $breakdown_post_title == 'yes' ) {
							echo '<span class="vertical-div"> | </span>';
						}
						echo '</span>';
					}
					if ( $breakdown_post_title == 'yes' ) {
						the_title();
					}
				?>
			</p>
		</div>

		<div class="breakdown <?php echo ($tw_entry->review_summary)  ? 'description' : 'no-description';?>" id="breakdown">
			<div class="table">
				<div class="table-row">
					<div class="table-cell verticalmiddle">
						<?php echo themewich_review_circle('title', false, true); ?>
					</div>
					<div class="table-cell verticalmiddle description-cell">
						<?php echo wp_kses_post( $tw_entry->review_summary ); ?>
						<div class="clear"></div>
					</div>
				</div>
		  	</div>
	  		<div class="clear"></div>
			
			<?php
//				foreach ( $tw_entry->review_criteria[0] as $key => $review ) :
//					if ( isset($review[0]) && isset($review[2]) ) :
						if( have_rows( 'review_criteria' ) ) : // check if the repeater field has rows of data
							while ( have_rows( 'review_criteria' ) ) : the_row(); // loop through the rows of data ?>
								<div class="reviewline">
									<span class="criteria">
										<?php the_sub_field('criteria'); ?>
									</span>

									<span class="score">
										<?php the_sub_field('rating'); ?>
									</span>
									<div class="clear"></div>

									<div class="linewrap">
										<div class="line" style="width:<?php echo (get_sub_field('rating')*10); ?>%"></div>
									</div>
									<div class="clear"></div>
								</div>
							<?php endwhile; 
						endif; 
//					endif;
//				endforeach;
			?>
		</div>
  	</div>
<!-- End Content -->
<?php endif; ?>