<?php /* Template Name: Page — Webiflashs liste */ ?>

<?php

    while ( have_posts() ) : the_post();
        $pageData['header_active'] = get_field('header_active');
        $pageData['header_surtitle'] = get_field('header_surtitle');
        $pageData['header_title'] = get_field('header_title');
        $pageData['header_intro'] = get_field('header_intro');
        $pageData['header_cover'] = getImageUrl(get_field('header_cover'));
        $pageData['header_cover_object'] = get_field('header_cover');

        $pageData['top_active'] = get_field('top_active');
        $pageData['top_surtitle'] = get_field('top_surtitle');
        $pageData['top_webinar'] = get_field('top_webinar');

        $pageData['list_title'] = get_field('list_title');

        $pageData['social_active'] = get_field('social_active');
        $pageData['social_surtitle'] = get_field('social_surtitle');
        $pageData['social_title'] = get_field('social_title');
        $pageData['social_link'] = get_field('social_link');
        $pageData['social_txt'] = get_field('social_txt');

        $pageData['cabinet_active'] = get_field('cabinet_active');
        $pageData['cabinet_surtitle'] = get_field('cabinet_surtitle');
        $pageData['cabinet_title'] = get_field('cabinet_title');
        $pageData['cabinet_link'] = get_field('cabinet_link');
        $pageData['cabinet_offices'] = get_field('cabinet_offices');
        $pageData['cabinet_quote'] = get_field('cabinet_quote');
        $pageData['cabinet_quoteSource'] = get_field('cabinet_quoteSource');
        $pageData['cabinet_content_title'] = get_field('cabinet_content_title');
        $pageData['cabinet_content_intro'] = get_field('cabinet_content_intro');
        $pageData['cabinet_content_text'] = get_field('cabinet_content_text');
        $pageData['cabinet_anchors'] = get_field('cabinet_anchors');

        $options = array(
            'post_type' => 'webinaire',
            'posts_per_page' => -1,
            'orderby' => 'date_filter',
            'meta_key' => 'date_filter',
            'order' => 'desc',
            'post_status' => 'publish',
            'meta_query' => array(
                array(
                    'key' => 'visible_list',
                    'value' => true
                ),
            )
        );
        
        $webinarsQuery = new WP_Query($options);
        
        $pageData['webinars_list'] = [];
        $pageData['webinars_count'] = $webinarsQuery->found_posts;

        foreach ($webinarsQuery->posts as $webinar) {
            if (get_field('date_filter', $webinar->ID)) {
                $year = DateTime::createFromFormat('d/m/Y', get_field('date_filter', $webinar->ID))->format('Y');
                $pageData['webinars_list'][$year][] = $webinar;
            }
        }

        $optionsAll = array(
            'post_type' => 'webinaire',
            'posts_per_page' => -1,
            'orderby' => 'date_filter',
            'meta_key' => 'date_filter',
            'order' => 'desc',
            'post_status' => 'publish',
        );
        $webinarsAllQuery = new WP_Query($optionsAll);
        $pageData['webinars_all'] = $webinarsAllQuery->posts;


    endwhile;

    get_header();
    include('layouts/webinaires.php');
    get_footer();

?>