From 91597acd90cfe3520c6bfe13ef778657c677945d Mon Sep 17 00:00:00 2001 From: savvasha Date: Tue, 20 Aug 2019 19:54:44 +0300 Subject: [PATCH] First commit to enable Date of Birth import of Players --- dummy-data/players-sample.csv | 10 ++--- .../importers/class-sp-player-importer.php | 45 +++++++++++++++++++ 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/dummy-data/players-sample.csv b/dummy-data/players-sample.csv index b43df364..0f8ed02b 100644 --- a/dummy-data/players-sample.csv +++ b/dummy-data/players-sample.csv @@ -1,5 +1,5 @@ -Number,Name,Positions,Teams,Leagues,Seasons,Nationality -1,Joe Allen,Goalkeeper,Eagles,Primary League|Secondary League,2014,aus -3,Steven Gerrard,Defender,Kangaroos,Primary League,2014|2013,usa -5,Daniel Sturridge,Midfielder|Forward,Sharks,Primary League|Secondary League,2014|2013,eng -6,Gabrielle Gonzalez,Forward,Kangaroos|Sharks,Primary League,2014,esp \ No newline at end of file +DoB,Number,Name,Positions,Teams,Leagues,Seasons,Nationality +1983/05/05,1,Joe Allen,Goalkeeper,Eagles,Primary League|Secondary League,2014,aus +1970/03/10,3,Steven Gerrard,Defender,Kangaroos,Primary League,2014|2013,usa +1990/02/15,5,Daniel Sturridge,Midfielder|Forward,Sharks,Primary League|Secondary League,2014|2013,eng +1987/01/20,6,Gabrielle Gonzalez,Forward,Kangaroos|Sharks,Primary League,2014,esp \ No newline at end of file diff --git a/includes/admin/importers/class-sp-player-importer.php b/includes/admin/importers/class-sp-player-importer.php index 353dd880..98d9cdfb 100644 --- a/includes/admin/importers/class-sp-player-importer.php +++ b/includes/admin/importers/class-sp-player-importer.php @@ -23,6 +23,7 @@ if ( class_exists( 'WP_Importer' ) ) { $this->import_page = 'sp_player_csv'; $this->import_label = __( 'Import Players', 'sportspress' ); $this->columns = array( + 'post_date' => __( 'Date of Birth', 'sportspress' ), 'sp_number' => __( 'Squad Number', 'sportspress' ), 'post_title' => __( 'Name', 'sportspress' ), 'sp_position' => __( 'Positions', 'sportspress' ), @@ -51,6 +52,9 @@ if ( class_exists( 'WP_Importer' ) ) { endif; $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 ): @@ -77,6 +81,27 @@ if ( class_exists( 'WP_Importer' ) ) { endforeach; $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 ): $this->skipped++; @@ -210,6 +235,26 @@ if ( class_exists( 'WP_Importer' ) ) { ?> + + + +
+ + +
+
    +
  • + +
  • +
  • + +
  • +
  • + +
  • +
+
+