%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/pn/beta/64801_wp-content/themes/intosai/templates/sections/
Upload File :
Create Path :
Current File : /var/www/pn/beta/64801_wp-content/themes/intosai/templates/sections/map_landing-chart.php

<section class="content_section map-and-chart">
    <div class="wrapper">

        <a href="<?= get_field('link_to_database'); ?>">
            <div class="map_link">
                <div class="overlay">
                    <i class="fa fa-map-marker"></i><br />
                    Click here to browse our projects
                </div>
            </div>
        </a>

        <div class="chart_section">

            <?php
                // CREATE ARRAY OF ALL THE REGIONS
                $regions = array(); // Create empty region array

                if(get_field('anp_intosai', 'project_option')):
                while(has_sub_field('anp_intosai', 'project_option')):

                    $region = get_sub_field('option');
                    $sanitized = str_replace(array(' ', '-'), '', $region); // Replaces all spaces and hyphens with nothing
                    $sanitized = strtolower($sanitized); // Replaces all hyphens with nothing

                    $regions[$sanitized] = $region; // Push sanitized region name to the list of regions

                endwhile;endif;

                $chartArr = array();

                foreach($regions as $sanitized => $name){
                    $chartArr[$sanitized]['name']      = $name;
                    $chartArr[$sanitized]['count']     = 0;
                }

                // LOOP PROJECTS IN REGIONS AND ADD COUNTERS TO THE REGIONS
                $projectSetup = array(
                    'post_type'         => 'project',
                    'post_status'       => 'publish',
                    'posts_per_page'    => -1,
                    'meta_query' => array(
                        array(
                            'key'     => 'intosai_region',
                            'value'   => '',
                            'compare' => '!=',
                        ),
                    ),
                );
                $projects = new WP_Query($projectSetup);
                if($projects->have_posts()) :
                $numProjects = $projects->found_posts;
                while($projects->have_posts()) : $projects->the_post();

                    $projectRegions = get_field('intosai_region');
                    $projectRegions = explode(',', $projectRegions);

                    foreach($projectRegions as $projectRegion){
                        $projRegion = $projectRegion;
                        $projRegion = str_replace(array(' ', '-'), '', $projRegion); // Replaces all spaces and hyphens with nothing
                        $projRegion = strtolower($projRegion); // Replaces all hyphens with nothing

                        if(isset($chartArr[$projRegion])){
                            $chartArr[$projRegion]['count']++;
                            //echo $projRegion.' finns i arrayen<br/>';
                        }
                    }

                endwhile; endif;
                wp_reset_query();
            ?>

            <script>
                var intosaiRegionNames = <?php
                    echo '[';
                    foreach($chartArr as $region){
                        echo "'".$region['name']."', ";
                    }
                    echo ']';
                ?>;
                var intosaiRegionData = <?php
                    echo '[';
                    foreach($chartArr as $region){
                        echo $region['count'].", ";
                    }
                    echo ']';
                ?>;
            </script>

            <div class="numProjs">
                <?php
                    // Calculate the number of projects spread out across all regions
                    $projectCount = 0;
                    foreach($chartArr as $region){
                        $projectCount = $projectCount + $region['count'];
                    }

                    //Count all countrys that are connected to atleast one project
                    $wdiTaxonomy = get_terms('wdi', array('hide_empty' => true));
                    $countTerms = count($wdiTaxonomy);

                    //Echo the final message
                    echo "There are <span>{$projectCount}</span> projects in <span>{$countTerms}</span> locations";
                ?>

            </div>

            <div class="chart_holder">
                <canvas id="projectChart" width="400" height="400"></canvas>
            </div>
        </div>

    </div>
</section>

Zerion Mini Shell 1.0