Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Projects timeline #793

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions web/wp-content/themes/cncf-twenty-two/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
128 changes: 128 additions & 0 deletions web/wp-content/themes/cncf-twenty-two/includes/projects-data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php
/**
* Projects Data
*
* Functions that manipulate project maturity data.
*
* @category Components
* @package WordPress
* @author Chris Abraham
* @license https://www.gnu.org/licenses/gpl-3.0.txt GNU/GPLv3
* @link https://cncf.io
* @since 1.0.0
*/

/**
* Get project maturity data.
*/
function get_projects_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;
}

/**
* 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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down