<?php
add_action('dslc_hook_register_modules',
    create_function('', 'return dslc_register_module( "Ainex_Testimonials_1" );')
);

class Ainex_Testimonials_1 extends DSLC_Module {

 	// Module Attributes
    var $module_id = 'Ainex_Testimonials_1';
    var $module_title = 'Testimonials 1';
    var $module_icon = 'quote-left';
    var $module_category = 'Ainex - Posts';


 	// Module Options
    function options() {
    	global $ts_animation_style;
    	// The options array
    	$dslc_options = array(
   			array(
				'label' => 'Testimonials 1 - Number Testimonials',
				'id' => 'number_testimonials',
				'std' => '3',
				'type' => 'select',
				'choices' => array(
					array(
						'label' => '2 Testimonials',
						'value' => '2'
					),
					array(
						'label' => '3 Testimonials',
						'value' => '3'
					),
					array(
						'label' => '4 Testimonials',
						'value' => '4'
					),
				)
			),
			array(
				'label' => __( 'Margin Bottom', 'dslc_string' ),
				'id' => 'button_css_margin_bottom',
				'std' => '0',
				'type' => 'slider',
				'refresh_on_change' => false,
				'affect_on_change_el' => '.one_full',
				'affect_on_change_rule' => 'margin-bottom',
				'section' => 'styling',
				'ext' => 'px',
			),
			array(
				'label' => __( ' BG Text Color', 'dslc_string' ),
				'id' => 'css_bg_text_color',
				'std' => '#fff',
				'type' => 'color',
				'refresh_on_change' => false,
				'affect_on_change_el' => 'blockquote.testimonial',
				'affect_on_change_rule' => 'background-color',
				'section' => 'styling',
			),
			array(
				'label' => __( ' BG arrow down Color', 'dslc_string' ),
				'id' => 'css_bg_arrow_color',
				'std' => '#fff',
				'type' => 'color',
				'refresh_on_change' => false,
				'affect_on_change_el' => '.testimonial-arrow-down',
				'affect_on_change_rule' => 'border-top-color',
				'section' => 'styling',
			),
			array(
				'label' => __( ' Text Color', 'dslc_string' ),
				'id' => 'css_text_color',
				'std' => '#666',
				'type' => 'color',
				'refresh_on_change' => false,
				'affect_on_change_el' => 'blockquote.testimonial',
				'affect_on_change_rule' => 'color',
				'section' => 'styling',
			),

			/*
			 * Animation Style
			*/
			array(
				'label' => __( 'Animation Style', 'dslc_string' ),
				'id' => 'css_animation_class',
				'std' => 'fadeInDown',
				'type' => 'select',
				'choices' => $ts_animation_style,
				'section' => 'styling',
				'tab' => 'Ainex Animation',
			),
			array(
				'label' => __( 'Animation Duration', 'dslc_string' ),
				'id' => 'animation_duration',
				'std' => '',
				'type' => 'slider',
				'section' => 'styling',
				'tab' => 'Ainex Animation',
				'refresh_on_change' => false,
				'affect_on_change_el' => '',
				'affect_on_change_rule' => '',
				'ext' => 's',
				'min' => 0,
				'max' => 10,
				'increment' => 0.1,
			),
			array(
				'label' => __( 'Animation Delay', 'dslc_string' ),
				'id' => 'animation_delay',
				'std' => '',
				'type' => 'slider',
				'section' => 'styling',
				'tab' => 'Ainex Animation',
				'refresh_on_change' => false,
				'affect_on_change_el' => '',
				'affect_on_change_rule' => '',
				'ext' => 's',
				'min' => 0,
				'max' => 10,
				'increment' => 0.1,
			),
		);

		$dslc_options = array_merge( $dslc_options, $this->shared_options('animation_options') );

    	// Return the array
    	return apply_filters( 'dslc_module_options', $dslc_options, $this->module_id );

    }

 	// Module Output
    function output( $options ) {

    	global $dslc_active;

		if ( $dslc_active && is_user_logged_in() && current_user_can( DS_LIVE_COMPOSER_CAPABILITY ) )
			$dslc_is_admin = true;
		else
			$dslc_is_admin = false;

		//REQUIRED
		$this->module_start( $options );

		$services_active = '';
		if ( $dslc_active )
			$services_active .= 'helight';

		/**
		 * Create column class
		*/
		if ($options['number_testimonials']) {
			$number_testimonials  = $options['number_testimonials'];
			$slider_id = rand(1,1000);
			ts_testimonial_slider();
		?>
			<div class="one_full wow <?php echo $options['css_animation_class'] ?>" <?php if ($options['animation_duration']) { echo 'data-wow-duration="'.$options['animation_duration'].'s"';} ?> <?php if ($options['animation_delay']) { echo 'data-wow-delay="'.$options['animation_delay'].'s"';} ?>>
	           	<div id="owl-slider<?php echo $slider_id; ?>" class="owl-carousel">
              		<?php
              			$dem = 1;
              			$posts_array = get_posts( 'posts_per_page='.$number_testimonials.'&post_type=dslc_testimonials' );
              			foreach ($posts_array as $testimonial ) : 
              		?>
		                    <div class="item">
								<blockquote class="testimonial">
									<?php
				                  		if($testimonial->post_excerpt){
				                  			echo wp_trim_words($testimonial->post_excerpt, 30, '');
				                  		} else {
				                  			echo wp_trim_words($testimonial->post_content, 30, '');
				                  		}
				                  	?>
								</blockquote>
								<div class="testimonial-arrow-down"></div>
								<div class="testimonial-author">
									<div class="img-thumbnail img-thumbnail-small">
										<img alt="" src="<?php echo get_post_meta($testimonial->ID, 'ainex_testimonials_image', true); ?>">
									</div>
									<p>
										<strong><?php echo get_post_meta($testimonial->ID, 'ainex_testimonials_name', true); ?></strong>
										<span><?php echo get_post_meta($testimonial->ID, 'dslc_testimonial_author_pos', true); ?></span>
									</p>
								</div>
							</div>
                    <?php
		            	$dem++;
		            	endforeach;
						wp_reset_postdata();
		            ?>
	            </div>
	        </div>

			<script type="text/javascript">
				jQuery(document).ready(function($) {
			    	$("#owl-slider<?php echo $slider_id; ?>").owlCarousel({
			    		navigation : false, // Show next and prev buttons
				      	slideSpeed : 300,
				      	paginationSpeed : 400,
				      	singleItem:true
			    	});
			    });
			</script>
		<?php } else { ?>
			<div class="dslc-notification dslc-red"><?php echo __( 'No data has been set yet, edit the module to set one.', 'themestudio' ); ?></div>
	    <?php } ?>

		<?php
    	// REQUIRED
    	$this->module_end( $options );

    }

}