Add venue column to event list and prompt to select details if new calendar

This commit is contained in:
Brian Miyaji
2014-03-28 14:13:15 +11:00
parent 51a7f809d6
commit 4b93f57768
10 changed files with 2332 additions and 3954 deletions

View File

@@ -43,14 +43,14 @@ class SP_Admin_Menus {
global $typenow;
if ( in_array( $typenow, array( 'sp_result', 'sp_outcome', 'sp_column', 'sp_performance', 'sp_metric' ) ) )
sportspress_highlight_admin_menu();
elseif ( $typenow == 'sp_calendar' )
sportspress_highlight_admin_menu( 'edit.php?post_type=sp_event', 'edit.php?post_type=sp_calendar' );
elseif ( $typenow == 'sp_table' )
sportspress_highlight_admin_menu( 'edit.php?post_type=sp_team', 'edit.php?post_type=sp_table' );
elseif ( $typenow == 'sp_list' )
sportspress_highlight_admin_menu( 'edit.php?post_type=sp_player', 'edit.php?post_type=sp_list' );
elseif ( $typenow == 'sp_staff' )
sportspress_highlight_admin_menu( 'edit.php?post_type=sp_player', 'edit.php?post_type=sp_staff' );
elseif ( $typenow == 'sp_directory' )
sportspress_highlight_admin_menu( 'edit.php?post_type=sp_player', 'edit.php?post_type=sp_directory' );
sportspress_highlight_admin_menu( 'edit.php?post_type=sp_staff', 'edit.php?post_type=sp_directory' );
}
/**

View File

@@ -120,7 +120,7 @@ class SP_Admin_Meta_Boxes {
add_meta_box( 'sp_shortcodediv', __( 'Shortcode', 'sportspress' ), 'SP_Meta_Box_List_Shortcode::output', 'sp_list', 'side', 'default' );
add_meta_box( 'sp_formatdiv', __( 'Layout', 'sportspress' ), 'SP_Meta_Box_List_Format::output', 'sp_list', 'side', 'default' );
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'SP_Meta_Box_List_Details::output', 'sp_list', 'side', 'default' );
add_meta_box( 'sp_datadiv', __( 'Player List', 'sportspress' ), 'SP_Meta_Box_List_Data::output', 'sp_list', 'normal', 'default' );
add_meta_box( 'sp_datadiv', __( 'Player List', 'sportspress' ), 'SP_Meta_Box_List_Data::output', 'sp_list', 'normal', 'high' );
add_meta_box( 'sp_descriptiondiv', __( 'Description', 'sportspress' ), 'SP_Meta_Box_List_Description::output', 'sp_list', 'normal', 'high' );
}

View File

@@ -402,6 +402,7 @@ class SP_Post_types {
'has_archive' => false,
'show_in_nav_menus' => true,
'show_in_menu' => 'edit.php?post_type=sp_event',
'show_in_admin_bar' => true,
)
)
);
@@ -462,6 +463,7 @@ class SP_Post_types {
'has_archive' => false,
'show_in_nav_menus' => true,
'show_in_menu' => 'edit.php?post_type=sp_team',
'show_in_admin_bar' => true,
)
)
);
@@ -522,6 +524,7 @@ class SP_Post_types {
'has_archive' => false,
'show_in_nav_menus' => true,
'show_in_menu' => 'edit.php?post_type=sp_player',
'show_in_admin_bar' => true,
)
)
);

View File

@@ -889,6 +889,12 @@ if ( !function_exists( 'sp_edit_calendar_table' ) ) {
<?php _e( 'Time', 'sportspress' ); ?>
</label>
</th>
<th class="column-venue">
<label for="sp_columns_venue">
<input type="checkbox" name="sp_columns[]" value="venue" id="sp_columns_venue" <?php checked( ! is_array( $usecolumns ) || in_array( 'venue', $usecolumns ) ); ?>>
<?php _e( 'Venue', 'sportspress' ); ?>
</label>
</th>
<th class="column-article">
<label for="sp_columns_article">
<input type="checkbox" name="sp_columns[]" value="article" id="sp_columns_article" <?php checked( ! is_array( $usecolumns ) || in_array( 'article', $usecolumns ) ); ?>>
@@ -941,6 +947,7 @@ if ( !function_exists( 'sp_edit_calendar_table' ) ) {
?>
</td>
<td><?php echo get_post_time( get_option( 'time_format' ), false, $event ); ?></td>
<td><?php the_terms( $event->ID, 'sp_venue' ); ?></td>
<td>
<a href="<?php echo get_edit_post_link( $event->ID ); ?>#sp_articlediv">
<?php if ( $video ): ?>
@@ -966,7 +973,7 @@ if ( !function_exists( 'sp_edit_calendar_table' ) ) {
else:
?>
<tr class="sp-row alternate">
<td colspan="4">
<td colspan="6">
<?php printf( __( 'Select %s', 'sportspress' ), __( 'Details', 'sportspress' ) ); ?>
</td>
</tr>
@@ -1074,27 +1081,37 @@ if ( !function_exists( 'sp_edit_player_list_table' ) ) {
</thead>
<tbody>
<?php
$i = 0;
foreach ( $data as $player_id => $player_stats ):
if ( !$player_id ) continue;
$div = get_term( $player_id, 'sp_season' );
$number = get_post_meta( $player_id, 'sp_number', true );
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<td><?php echo ( $number ? $number : '&nbsp;' ); ?></td>
<td>
<?php echo get_the_title( $player_id ); ?>
</td>
<?php foreach( $columns as $column => $label ):
$value = sportspress_array_value( $player_stats, $column, '' );
$placeholder = sportspress_array_value( sportspress_array_value( $placeholders, $player_id, array() ), $column, 0 );
?>
<td><input type="text" name="sp_players[<?php echo $player_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" placeholder="<?php echo $placeholder; ?>" /></td>
<?php endforeach; ?>
</tr>
<?php
$i++;
endforeach;
if ( is_array( $data ) && sizeof( $data ) > 0 ):
$i = 0;
foreach ( $data as $player_id => $player_stats ):
if ( !$player_id ) continue;
$div = get_term( $player_id, 'sp_season' );
$number = get_post_meta( $player_id, 'sp_number', true );
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<td><?php echo ( $number ? $number : '&nbsp;' ); ?></td>
<td>
<?php echo get_the_title( $player_id ); ?>
</td>
<?php foreach( $columns as $column => $label ):
$value = sportspress_array_value( $player_stats, $column, '' );
$placeholder = sportspress_array_value( sportspress_array_value( $placeholders, $player_id, array() ), $column, 0 );
?>
<td><input type="text" name="sp_players[<?php echo $player_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" placeholder="<?php echo $placeholder; ?>" /></td>
<?php endforeach; ?>
</tr>
<?php
$i++;
endforeach;
else:
?>
<tr class="sp-row alternate">
<td colspan="<?php $colspan = sizeof( $columns ) + 1; echo $colspan; ?>">
<?php printf( __( 'Select %s', 'sportspress' ), __( 'Players', 'sportspress' ) ); ?>
</td>
</tr>
<?php
endif;
?>
</tbody>
</table>
@@ -1607,6 +1624,7 @@ if ( !function_exists( 'sp_event_players_sub_filter' ) ) {
if ( !function_exists( 'sp_get_calendar_data' ) ) {
function sp_get_calendar_data( $post_id = null, $admin = false ) {
global $pagenow;
$args = array(
'post_type' => 'sp_event',
@@ -1620,7 +1638,7 @@ if ( !function_exists( 'sp_get_calendar_data' ) ) {
),
);
if ( $post_id ):
if ( $pagenow != 'post-new.php' && $post_id ):
$leagues = get_the_terms( $post_id, 'sp_league' );
$seasons = get_the_terms( $post_id, 'sp_season' );
$venues = get_the_terms( $post_id, 'sp_venue' );
@@ -1671,12 +1689,13 @@ if ( !function_exists( 'sp_get_calendar_data' ) ) {
),
);
endif;
$events = get_posts( $args );
else:
$usecolumns = null;
$events = null;
endif;
$events = get_posts( $args );
if ( $admin ):
return array( $events, $usecolumns );
else:

View File

@@ -10,12 +10,13 @@ class SP_Widget_Event_List extends WP_Widget {
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
$id = empty($instance['id']) ? null : $instance['id'];
$number = empty($instance['number']) ? null : $instance['number'];
$columns = empty($instance['columns']) ? null : $instance['columns'];
$show_all_events_link = empty($instance['show_all_events_link']) ? false : $instance['show_all_events_link'];
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
sp_get_template( 'event-list.php', array( 'id' => $id, 'columns' => $columns, 'show_all_events_link' => $show_all_events_link ) );
sp_get_template( 'event-list.php', array( 'id' => $id, 'number' => $number, 'columns' => $columns, 'show_all_events_link' => $show_all_events_link ) );
echo $after_widget;
}
@@ -23,6 +24,7 @@ class SP_Widget_Event_List extends WP_Widget {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['id'] = intval($new_instance['id']);
$instance['number'] = intval($new_instance['number']);
$instance['columns'] = (array)$new_instance['columns'];
$instance['show_all_events_link'] = $new_instance['show_all_events_link'];
@@ -30,9 +32,10 @@ class SP_Widget_Event_List extends WP_Widget {
}
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => null, 'columns' => null, 'show_all_events_link' => true ) );
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => null, 'number' => 5, 'columns' => null, 'show_all_events_link' => true ) );
$title = strip_tags($instance['title']);
$id = intval($instance['id']);
$number = intval($instance['number']);
$columns = $instance['columns'];
$show_all_events_link = $instance['show_all_events_link'];
?>
@@ -56,6 +59,10 @@ class SP_Widget_Event_List extends WP_Widget {
?>
</p>
<p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e( 'Number of events to show:', 'sportspress' ); ?></label>
<input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo esc_attr($number); ?>" size="3"></p>
<p class="sp-prefs">
<?php _e( 'Columns:', 'sportspress' ); ?><br>
<?php
@@ -63,6 +70,7 @@ class SP_Widget_Event_List extends WP_Widget {
'event' => __( 'Event', 'sportspress' ),
'teams' => __( 'Teams', 'sportspress' ),
'time' => __( 'Time', 'sportspress' ),
'venue' => __( 'Venue', 'sportspress' ),
'article' => __( 'Article', 'sportspress' ),
);
$field_name = $this->get_field_name('columns') . '[]';

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,121 +1,140 @@
<?php
global $sportspress_options;
$main_result = sportspress_array_value( $sportspress_options, 'main_result', null );
$primary_result = sportspress_array_value( $sportspress_options, 'sportspress_primary_result', null );
$defaults = array(
'number' => -1,
'show_all_events_link' => false,
);
extract( $defaults, EXTR_SKIP );
?>
<div class="sp-table-wrapper">
<table class="sp-event-list sp-data-table sp-responsive-table">
<thead>
<tr>
<?php
list( $data, $usecolumns ) = sportspress_get_calendar_data( $id, true );
$output = '<div class="sp-table-wrapper">' .
'<table class="sp-event-list sp-data-table sp-responsive-table">' . '<thead>' . '<tr>';
if ( isset( $columns ) )
$usecolumns = $columns;
list( $data, $usecolumns ) = sportspress_get_calendar_data( $id, true );
echo '<th class="data-date">' . SP()->text->string('Date', 'event') . '</th>';
if ( isset( $columns ) )
$usecolumns = $columns;
if ( $usecolumns == null || in_array( 'event', $usecolumns ) )
echo '<th class="data-event">' . SP()->text->string('Event', 'event') . '</th>';
$output .= '<th class="data-date">' . SP()->text->string('Date', 'event') . '</th>';
if ( $usecolumns == null || in_array( 'teams', $usecolumns ) )
echo '<th class="data-teams">' . SP()->text->string('Teams', 'event') . '</th>';
if ( $usecolumns == null || in_array( 'event', $usecolumns ) )
$output .= '<th class="data-event">' . SP()->text->string('Event', 'event') . '</th>';
if ( $usecolumns == null || in_array( 'time', $usecolumns ) )
echo '<th class="data-time">' . SP()->text->string('Time', 'event') . '</th>';
if ( $usecolumns == null || in_array( 'teams', $usecolumns ) )
$output .= '<th class="data-teams">' . SP()->text->string('Teams', 'event') . '</th>';
if ( $usecolumns == null || in_array( 'venue', $usecolumns ) )
echo '<th class="data-venue">' . SP()->text->string('Venue', 'event') . '</th>';
if ( $usecolumns == null || in_array( 'time', $usecolumns ) )
$output .= '<th class="data-time">' . SP()->text->string('Time', 'event') . '</th>';
if ( $usecolumns == null || in_array( 'article', $usecolumns ) )
echo '<th class="data-article">' . SP()->text->string('Article', 'event') . '</th>';
?>
</tr>
</thead>
<tbody>
<?php
$i = 0;
if ( $usecolumns == null || in_array( 'article', $usecolumns ) )
$output .= '<th class="data-article">' . SP()->text->string('Article', 'event') . '</th>';
if ( is_int( $number ) && $number > 0 )
$limit = $number;
$output .= '</tr>' . '</thead>' . '<tbody>';
foreach ( $data as $event ):
if ( isset( $limit ) && $i >= $limit ) continue;
$i = 0;
foreach ( $data as $event ):
$teams = get_post_meta( $event->ID, 'sp_team' );
$results = get_post_meta( $event->ID, 'sp_results', true );
$video = get_post_meta( $event->ID, 'sp_video', true );
$teams = get_post_meta( $event->ID, 'sp_team' );
$results = get_post_meta( $event->ID, 'sp_results', true );
$video = get_post_meta( $event->ID, 'sp_video', true );
$output .= '<tr class="sp-row sp-post' . ( $i % 2 == 0 ? ' alternate' : '' ) . '">';
echo '<tr class="sp-row sp-post' . ( $i % 2 == 0 ? ' alternate' : '' ) . '">';
$output .= '<td class="data-date">' . get_post_time( get_option( 'date_format' ), false, $event ) . '</td>';
echo '<td class="data-date">' . get_post_time( get_option( 'date_format' ), false, $event ) . '</td>';
if ( $usecolumns == null || in_array( 'event', $usecolumns ) )
$output .= '<td class="data-event">' . $event->post_title . '</td>';
if ( $usecolumns == null || in_array( 'event', $usecolumns ) )
echo '<td class="data-event">' . $event->post_title . '</td>';
if ( $usecolumns == null || in_array( 'teams', $usecolumns ) ):
$output .= '<td class="data-teams">';
if ( $usecolumns == null || in_array( 'teams', $usecolumns ) ):
echo '<td class="data-teams">';
$teams = get_post_meta( $event->ID, 'sp_team', false );
if ( $teams ):
foreach ( $teams as $team ):
$name = get_the_title( $team );
if ( $name ):
$team_results = sportspress_array_value( $results, $team, null );
$teams = get_post_meta( $event->ID, 'sp_team', false );
if ( $teams ):
foreach ( $teams as $team ):
$name = get_the_title( $team );
if ( $name ):
$team_results = sportspress_array_value( $results, $team, null );
if ( $main_result ):
$team_result = sportspress_array_value( $team_results, $main_result, null );
if ( $primary_result ):
$team_result = sportspress_array_value( $team_results, $primary_result, null );
else:
if ( is_array( $team_results ) ):
end( $team_results );
$team_result = prev( $team_results );
else:
$team_result = null;
endif;
endif;
echo $name;
if ( $team_result != null ):
echo ' (' . $team_result . ')';
endif;
echo '<br>';
endif;
endforeach;
else:
if ( is_array( $team_results ) ):
end( $team_results );
$team_result = prev( $team_results );
else:
$team_result = null;
endif;
echo '&mdash;';
endif;
$output .= $name;
echo '</td>';
endif;
if ( $team_result != null ):
$output .= ' (' . $team_result . ')';
endif;
if ( $usecolumns == null || in_array( 'time', $usecolumns ) )
echo '<td class="data-time">' . get_post_time( get_option( 'time_format' ), false, $event ) . '</td>';
$output .= '<br>';
if ( $usecolumns == null || in_array( 'venue', $usecolumns ) ):
echo '<td class="data-venue">';
the_terms( $event->ID, 'sp_venue' );
echo '</td>';
endif;
if ( $usecolumns == null || in_array( 'article', $usecolumns ) ):
echo '<td class="data-article">
<a href="' . get_permalink( $event->ID ) . '">';
if ( $video ):
echo '<div class="dashicons dashicons-video-alt"></div>';
elseif ( has_post_thumbnail( $event->ID ) ):
echo '<div class="dashicons dashicons-camera"></div>';
endif;
endforeach;
else:
$output .= '&mdash;';
if ( $event->post_content !== null ):
if ( $event->post_status == 'publish' ):
echo SP()->text->string('Recap', 'event');
else:
echo SP()->text->string('Preview', 'event');
endif;
endif;
echo '</a>
</td>';
endif;
$output .= '</td>';
endif;
echo '</tr>';
if ( $usecolumns == null || in_array( 'time', $usecolumns ) )
$output .= '<td class="data-time">' . get_post_time( get_option( 'time_format' ), false, $event ) . '</td>';
if ( $usecolumns == null || in_array( 'article', $usecolumns ) ):
$output .= '<td class="data-article">
<a href="' . get_permalink( $event->ID ) . '">';
if ( $video ):
$output .= '<div class="dashicons dashicons-video-alt"></div>';
elseif ( has_post_thumbnail( $event->ID ) ):
$output .= '<div class="dashicons dashicons-camera"></div>';
endif;
if ( $event->post_content !== null ):
if ( $event->post_status == 'publish' ):
$output .= SP()->text->string('Recap', 'event');
else:
$output .= SP()->text->string('Preview', 'event');
endif;
endif;
$output .= '</a>
</td>';
endif;
$output .= '</tr>';
$i++;
endforeach;
$output .= '</tbody>' . '</table>';
if ( $id && $show_all_events_link )
$output .= '<a class="sp-calendar-link" href="' . get_permalink( $id ) . '">' . SP()->text->string('View all events', 'event') . '</a>';
$output .= '</div>';
echo apply_filters( 'sportspress_event_list', $output );
$i++;
endforeach;
?>
</tbody>
</table>
<?php
if ( $id && $show_all_events_link )
echo '<a class="sp-calendar-link" href="' . get_permalink( $id ) . '">' . SP()->text->string('View all events', 'event') . '</a>';
?>
</div>