First commit to enable Date of Birth import of Players
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
Number,Name,Positions,Teams,Leagues,Seasons,Nationality
|
DoB,Number,Name,Positions,Teams,Leagues,Seasons,Nationality
|
||||||
1,Joe Allen,Goalkeeper,Eagles,Primary League|Secondary League,2014,aus
|
1983/05/05,1,Joe Allen,Goalkeeper,Eagles,Primary League|Secondary League,2014,aus
|
||||||
3,Steven Gerrard,Defender,Kangaroos,Primary League,2014|2013,usa
|
1970/03/10,3,Steven Gerrard,Defender,Kangaroos,Primary League,2014|2013,usa
|
||||||
5,Daniel Sturridge,Midfielder|Forward,Sharks,Primary League|Secondary League,2014|2013,eng
|
1990/02/15,5,Daniel Sturridge,Midfielder|Forward,Sharks,Primary League|Secondary League,2014|2013,eng
|
||||||
6,Gabrielle Gonzalez,Forward,Kangaroos|Sharks,Primary League,2014,esp
|
1987/01/20,6,Gabrielle Gonzalez,Forward,Kangaroos|Sharks,Primary League,2014,esp
|
||||||
|
@@ -23,6 +23,7 @@ if ( class_exists( 'WP_Importer' ) ) {
|
|||||||
$this->import_page = 'sp_player_csv';
|
$this->import_page = 'sp_player_csv';
|
||||||
$this->import_label = __( 'Import Players', 'sportspress' );
|
$this->import_label = __( 'Import Players', 'sportspress' );
|
||||||
$this->columns = array(
|
$this->columns = array(
|
||||||
|
'post_date' => __( 'Date of Birth', 'sportspress' ),
|
||||||
'sp_number' => __( 'Squad Number', 'sportspress' ),
|
'sp_number' => __( 'Squad Number', 'sportspress' ),
|
||||||
'post_title' => __( 'Name', 'sportspress' ),
|
'post_title' => __( 'Name', 'sportspress' ),
|
||||||
'sp_position' => __( 'Positions', 'sportspress' ),
|
'sp_position' => __( 'Positions', 'sportspress' ),
|
||||||
@@ -51,6 +52,9 @@ if ( class_exists( 'WP_Importer' ) ) {
|
|||||||
endif;
|
endif;
|
||||||
|
|
||||||
$rows = array_chunk( $array, sizeof( $columns ) );
|
$rows = array_chunk( $array, sizeof( $columns ) );
|
||||||
|
|
||||||
|
// Get Date of Birth format from post vars
|
||||||
|
$date_format = ( empty( $_POST['sp_date_format'] ) ? 'yyyy/mm/dd' : $_POST['sp_date_format'] );
|
||||||
|
|
||||||
foreach ( $rows as $row ):
|
foreach ( $rows as $row ):
|
||||||
|
|
||||||
@@ -77,6 +81,27 @@ if ( class_exists( 'WP_Importer' ) ) {
|
|||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
$name = sp_array_value( $meta, 'post_title' );
|
$name = sp_array_value( $meta, 'post_title' );
|
||||||
|
$date = sp_array_value( $meta, 'post_date' );
|
||||||
|
|
||||||
|
// Format date of birth
|
||||||
|
$date = str_replace( '/', '-', trim( $date ) );
|
||||||
|
$date_array = explode( '-', $date );
|
||||||
|
switch ( $date_format ):
|
||||||
|
case 'dd/mm/yyyy':
|
||||||
|
$date = substr( str_pad( sp_array_value( $date_array, 2, '0000' ), 4, '0', STR_PAD_LEFT ), 0, 4 ) . '-' .
|
||||||
|
substr( str_pad( sp_array_value( $date_array, 1, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 ) . '-' .
|
||||||
|
substr( str_pad( sp_array_value( $date_array, 0, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 );
|
||||||
|
break;
|
||||||
|
case 'mm/dd/yyyy':
|
||||||
|
$date = substr( str_pad( sp_array_value( $date_array, 2, '0000' ), 4, '0', STR_PAD_LEFT ), 0, 4 ) . '-' .
|
||||||
|
substr( str_pad( sp_array_value( $date_array, 0, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 ) . '-' .
|
||||||
|
substr( str_pad( sp_array_value( $date_array, 1, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 );
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$date = substr( str_pad( sp_array_value( $date_array, 0, '0000' ), 4, '0', STR_PAD_LEFT ), 0, 4 ) . '-' .
|
||||||
|
substr( str_pad( sp_array_value( $date_array, 1, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 ) . '-' .
|
||||||
|
substr( str_pad( sp_array_value( $date_array, 2, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 );
|
||||||
|
endswitch;
|
||||||
|
|
||||||
if ( ! $name ):
|
if ( ! $name ):
|
||||||
$this->skipped++;
|
$this->skipped++;
|
||||||
@@ -210,6 +235,26 @@ if ( class_exists( 'WP_Importer' ) ) {
|
|||||||
?>
|
?>
|
||||||
<table class="form-table">
|
<table class="form-table">
|
||||||
<tbody>
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th scope="row" class="titledesc">
|
||||||
|
<?php _e( 'Date of Birth Format', 'sportspress' ); ?>
|
||||||
|
</th>
|
||||||
|
<td class="forminp forminp-radio">
|
||||||
|
<fieldset>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<label><input name="sp_date_format" value="yyyy/mm/dd" type="radio" checked> yyyy/mm/dd</label>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<label><input name="sp_date_format" value="dd/mm/yyyy" type="radio"> dd/mm/yyyy</label>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<label><input name="sp_date_format" value="mm/dd/yyyy" type="radio"> mm/dd/yyyy</label>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</fieldset>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<label>
|
<label>
|
||||||
|
|||||||
Reference in New Issue
Block a user