Making WordPress.org

Changeset 3964


Ignore:
Timestamp:
09/05/2016 06:54:28 PM (8 years ago)
Author:
kovshenin
Message:

WordCamp Central: Add a new WordCamp info template.

This template currently shows aggregated t-shirt information
gathered from the event attendees. In the future it may show
more stuff.

Location:
sites/trunk/wordcamp.org/public_html/wp-content/themes/wordcamp-central-2012
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/themes/wordcamp-central-2012/functions.php

    r3162 r3964  
    841841        return $map_stats;
    842842    }
     843
     844    /**
     845     * Get T-shirt Sizes, a caching wrapper for _get_tshirt_sizes.
     846     *
     847     * @param int $wordcamp_id The WordCamp post ID.
     848     *
     849     * @return array An array of sizes.
     850     */
     851    public static function get_tshirt_sizes( $wordcamp_id ) {
     852        // TODO: Implement some caching.
     853        $sizes = self::_get_tshirt_sizes( $wordcamp_id );
     854    }
     855
     856    /**
     857     * Get T-shirt Sizes.
     858     *
     859     * @param int $wordcamp_id The WordCamp post ID.
     860     *
     861     * @return array An array of sizes.
     862     */
     863    private static function _get_tshirt_sizes( $wordcamp_id ) {
     864        $wordcamp = get_post( $wordcamp_id );
     865        $sizes = array();
     866
     867        $wordcamp_site_id = absint( get_wordcamp_site_id( $wordcamp ) );
     868        if ( ! $wordcamp_site_id )
     869            return $sizes;
     870
     871        wp_suspend_cache_addition( true );
     872        switch_to_blog( $wordcamp_site_id );
     873
     874        $questions = get_posts( array(
     875            'post_type' => 'tix_question',
     876            'post_status' => 'publish',
     877            'posts_per_page' => 100,
     878            'fields' => 'ids',
     879        ) );
     880
     881        // Aggregate only t-shirt questions.
     882        $tshirt_questions = array();
     883        foreach ( $questions as $question_id ) {
     884            if ( get_post_meta( $question_id, 'tix_type', true ) != 'tshirt' )
     885                continue;
     886
     887            $tshirt_questions[] = $question_id;
     888        }
     889
     890        $paged = 1;
     891        while ( $attendees = get_posts( array(
     892            'post_type' => 'tix_attendee',
     893            'post_status' => array( 'publish', 'pending' ),
     894            'posts_per_page' => 200,
     895            'paged' => $paged++,
     896            'orderby' => 'ID',
     897            'order' => 'ASC',
     898            'fields' => 'ids',
     899        ) ) ) {
     900            foreach ( $attendees as $attendee_id ) {
     901                $answers = get_post_meta( $attendee_id, 'tix_questions', true );
     902                foreach ( $answers as $question_id => $answer ) {
     903                    if ( in_array( $question_id, $tshirt_questions ) ) {
     904                        if ( ! isset( $sizes[ $answer ] ) )
     905                            $sizes[ $answer ] = 0;
     906
     907                        $sizes[ $answer ]++;
     908                    }
     909                }
     910            }
     911        }
     912
     913        restore_current_blog();
     914        wp_suspend_cache_addition( false );
     915        arsort( $sizes );
     916        return $sizes;
     917    }
    843918}
    844919
  • sites/trunk/wordcamp.org/public_html/wp-content/themes/wordcamp-central-2012/single-wordcamp.php

    r2898 r3964  
    33 * Single WordCamp (post type) template.
    44 */
     5
     6if ( get_query_var( 'wcorg-wordcamp-info' ) ) {
     7    return get_template_part( 'single-wordcamp-info' );
     8}
    59
    610get_header(); the_post();
Note: See TracChangeset for help on using the changeset viewer.