From 6b101e5d19d08521d7bf34d804216a47dde80ea6 Mon Sep 17 00:00:00 2001 From: Chris Abraham Date: Wed, 20 Sep 2023 15:15:26 +0900 Subject: [PATCH] Generates timeline data for projects Signed-off-by: Chris Abraham --- .../themes/cncf-twenty-two/functions.php | 2 + .../includes/projects-data.php | 128 ++++++++++++++++++ .../includes/shortcodes/project-charts.php | 42 +----- 3 files changed, 132 insertions(+), 40 deletions(-) create mode 100644 web/wp-content/themes/cncf-twenty-two/includes/projects-data.php diff --git a/web/wp-content/themes/cncf-twenty-two/functions.php b/web/wp-content/themes/cncf-twenty-two/functions.php index cb3bfc7eb..6194dbe1c 100644 --- a/web/wp-content/themes/cncf-twenty-two/functions.php +++ b/web/wp-content/themes/cncf-twenty-two/functions.php @@ -103,6 +103,8 @@ function lf_theme_support_setup() { // Post excerpts. require_once 'includes/excerpts.php'; +require_once 'includes/projects-data.php'; + // Shortcodes. require_once 'includes/shortcodes/benefits.php'; require_once 'includes/shortcodes/event-banner.php'; diff --git a/web/wp-content/themes/cncf-twenty-two/includes/projects-data.php b/web/wp-content/themes/cncf-twenty-two/includes/projects-data.php new file mode 100644 index 000000000..26d3ead11 --- /dev/null +++ b/web/wp-content/themes/cncf-twenty-two/includes/projects-data.php @@ -0,0 +1,128 @@ + 'lf_project', + 'post_status' => array( 'publish' ), + 'posts_per_page' => 1000, + ); + + $project_query = new WP_Query( $query_args ); + + while ( $project_query->have_posts() ) { + $project_query->the_post(); + $name = get_the_title( get_the_ID() ); + $accepted = get_post_meta( get_the_ID(), 'lf_project_date_accepted', true ); + $incubating = get_post_meta( get_the_ID(), 'lf_project_date_incubating', true ); + $graduated = get_post_meta( get_the_ID(), 'lf_project_date_graduated', true ); + $archived = get_post_meta( get_the_ID(), 'lf_project_date_archived', true ); + + $maturity_data[ $name ] = array( + 'accepted' => $accepted, + 'incubating' => $incubating, + 'graduated' => $graduated, + 'archived' => $archived, + ); + } + wp_reset_postdata(); + set_transient( 'cncf_project_maturity_data', $maturity_data, DAY_IN_SECONDS ); + } + return $maturity_data; +} + +/** + * Get projects timeline data. + */ +function get_projects_timeline_data() { + $timeline_data = get_transient( 'cncf_project_timeline_data' ); + + if ( false === $timeline_data ) { + $timeline_data = array(); + + $query_args = array( + 'post_type' => 'lf_project', + 'post_status' => array( 'publish' ), + 'posts_per_page' => 1000, + ); + + $project_query = new WP_Query( $query_args ); + + while ( $project_query->have_posts() ) { + $project_query->the_post(); + $name = get_the_title( get_the_ID() ); + $accepted = get_post_meta( get_the_ID(), 'lf_project_date_accepted', true ); + $incubating = get_post_meta( get_the_ID(), 'lf_project_date_incubating', true ); + $graduated = get_post_meta( get_the_ID(), 'lf_project_date_graduated', true ); + $archived = get_post_meta( get_the_ID(), 'lf_project_date_archived', true ); + + if ( $accepted && $incubating == $accepted ) { + $timeline_data[] = array( + 'date' => $accepted, + 'project' => $name, + 'action' => 'was accepted into incubating', + ); + } elseif ( $accepted ) { + $timeline_data[] = array( + 'date' => $accepted, + 'project' => $name, + 'action' => 'was accepted into sandbox', + ); + } + + if ( $incubating && $incubating != $accepted ) { + $timeline_data[] = array( + 'date' => $incubating, + 'project' => $name, + 'action' => 'moved into incubating', + ); + } + + if ( $graduated ) { + $timeline_data[] = array( + 'date' => $graduated, + 'project' => $name, + 'action' => 'moved into graduated', + ); + } + + if ( $archived ) { + $timeline_data[] = array( + 'date' => $archived, + 'project' => $name, + 'action' => 'was archived', + ); + } + } + wp_reset_postdata(); + set_transient( 'cncf_project_timeline_data', $timeline_data, DAY_IN_SECONDS ); + } + return $timeline_data; +} + + +$timeline_data = get_projects_timeline_data(); +$dates = array_column( $timeline_data, 'date' ); +array_multisort( $dates, SORT_ASC, $timeline_data ); +foreach ( $timeline_data as $t ) { + echo $t['date'] . ': ' . $t['project'] . ' ' . $t['action'] . "\n"; +} diff --git a/web/wp-content/themes/cncf-twenty-two/includes/shortcodes/project-charts.php b/web/wp-content/themes/cncf-twenty-two/includes/shortcodes/project-charts.php index 0729c59d8..3dbf89d58 100644 --- a/web/wp-content/themes/cncf-twenty-two/includes/shortcodes/project-charts.php +++ b/web/wp-content/themes/cncf-twenty-two/includes/shortcodes/project-charts.php @@ -10,44 +10,6 @@ * @since 1.0.0 */ -/** - * Get project maturity data. - */ -function get_maturity_data() { - $maturity_data = get_transient( 'cncf_project_maturity_data' ); - - if ( false === $maturity_data ) { - $maturity_data = array(); - - $query_args = array( - 'post_type' => 'lf_project', - 'post_status' => array( 'publish' ), - 'posts_per_page' => 1000, - ); - - $project_query = new WP_Query( $query_args ); - - while ( $project_query->have_posts() ) { - $project_query->the_post(); - $name = get_the_title( get_the_ID() ); - $accepted = get_post_meta( get_the_ID(), 'lf_project_date_accepted', true ); - $incubating = get_post_meta( get_the_ID(), 'lf_project_date_incubating', true ); - $graduated = get_post_meta( get_the_ID(), 'lf_project_date_graduated', true ); - $archived = get_post_meta( get_the_ID(), 'lf_project_date_archived', true ); - - $maturity_data[ $name ] = array( - 'accepted' => $accepted, - 'incubating' => $incubating, - 'graduated' => $graduated, - 'archived' => $archived, - ); - } - wp_reset_postdata(); - set_transient( 'cncf_project_maturity_data', $maturity_data, DAY_IN_SECONDS ); - } - return $maturity_data; -} - /** * Processes maturity data to be ready for plotting on stacked line chart. * @@ -94,7 +56,7 @@ function get_project_chart_data( $maturity_data ) { */ function add_projects_maturity_chart_shortcode( $atts ) { - $maturity_data = get_maturity_data(); + $maturity_data = get_projects_maturity_data(); $chart_data = get_project_chart_data( $maturity_data ); $project_months = array_keys( $chart_data ); $sandbox = array(); @@ -153,7 +115,7 @@ function add_projects_maturity_chart_shortcode( $atts ) { */ function add_projects_accepted_chart_shortcode( $atts ) { - $maturity_data = get_maturity_data(); + $maturity_data = get_projects_maturity_data(); $start_year = 2016; $sanbox_accepted = array(); $incubating_accepted = array();