Skip to content

Commit

Permalink
Merge pull request #2219 from raftaar1191/issues-2164
Browse files Browse the repository at this point in the history
Issues 2164
  • Loading branch information
ravinderk committed Oct 17, 2017
2 parents 89cf0d2 + b2fc23d commit e8765e1
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 51 deletions.
112 changes: 64 additions & 48 deletions includes/admin/tools/import/class-give-import-donations.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,6 @@ public function render_dropdown() {

<?php
$raw_key = $this->get_importer( $csv, 0, $delimiter );
$donations = give_import_donations_options();
$donors = give_import_donor_options();
$forms = give_import_donation_form_options();
$mapto = (array) ( isset( $_REQUEST['mapto'] ) ? $_REQUEST['mapto'] : array() );

foreach ( $raw_key as $index => $value ) {
Expand All @@ -443,7 +440,7 @@ public function render_dropdown() {
<th><?php echo $value; ?></th>
<th>
<?php
$this->get_columns( $index, $donations, $donors, $forms, $value, $mapto );
$this->get_columns( $index, $value, $mapto );
?>
</th>
</tr>
Expand All @@ -459,10 +456,13 @@ public function render_dropdown() {
* @return string
*/
public function selected( $option_value, $value ) {
$option_value = strtolower( $option_value );
$value = strtolower( $value );

$selected = '';
if ( stristr( $value, $option_value ) ) {
$selected = 'selected';
} elseif ( strrpos( $value, '_' ) && stristr( $option_value, 'Import as Meta' ) ) {
} elseif ( strrpos( $value, '_' ) && stristr( $option_value, __( 'Import as Meta', 'give' ) ) ) {
$selected = 'selected';
}

Expand All @@ -473,72 +473,88 @@ public function selected( $option_value, $value ) {
* Print the columns from the CSV.
*
* @since 1.8.14
* @access private
*
* @param string $index
* @param bool $value
* @param array $mapto
*
* @return void
*/
public function get_columns( $index, $donations, $donors, $forms, $value = false, $mapto = array() ) {
private function get_columns( $index, $value = false, $mapto = array() ) {
$default = give_import_default_options();
$current_mapto = (string) ( ! empty( $mapto[ $index ] ) ? $mapto[ $index ] : '' );
?>
<select name="mapto[<?php echo $index; ?>]">
<?php
foreach ( $default as $option => $option_value ) {
$checked = ( ( $current_mapto === $option ) ? 'selected' : false );
if ( empty( $checked ) ) {
$checked = $this->selected( $option_value, $value );
}
?>
<option value="<?php echo $option; ?>" <?php echo $checked; ?> ><?php echo $option_value; ?></option>
<?php
}
?>
<optgroup label="Donations">
<?php $this->get_dropdown_option_html( $default, $current_mapto, $value ); ?>

<optgroup label="<?php _e( 'Donations', 'give' ); ?>">
<?php
foreach ( $donations as $option => $option_value ) {
$checked = ( ( $current_mapto === $option ) ? 'selected' : false );
if ( empty( $checked ) ) {
$checked = $this->selected( $option_value, $value );
}
?>
<option value="<?php echo $option; ?>" <?php echo $checked; ?> ><?php echo $option_value; ?></option>
<?php
}
$this->get_dropdown_option_html( give_import_donations_options(), $current_mapto, $value );
?>
</optgroup>

<optgroup label="Donors">
<optgroup label="<?php _e( 'Donors', 'give' ); ?>">
<?php
foreach ( $donors as $option => $option_value ) {
$checked = ( ( $current_mapto === $option ) ? 'selected' : false );
if ( empty( $checked ) ) {
$checked = $this->selected( $option_value, $value );
}
?>
<option value="<?php echo $option; ?>" <?php echo $checked; ?> ><?php echo $option_value; ?></option>
<?php
}
$this->get_dropdown_option_html( give_import_donor_options(), $current_mapto, $value );
?>
</optgroup>

<optgroup label="Forms">
<optgroup label="<?php _e( 'Forms', 'give' ); ?>">
<?php
foreach ( $forms as $option => $option_value ) {
$checked = ( ( $current_mapto === $option ) ? 'selected' : false );
if ( empty( $checked ) ) {
$checked = $this->selected( $option_value, $value );
}
?>
<option value="<?php echo $option; ?>" <?php echo $checked; ?> ><?php echo $option_value; ?></option>
<?php
}
$this->get_dropdown_option_html( give_import_donation_form_options(), $current_mapto, $value );
?>
</optgroup>

<?php
do_action( 'give_import_dropdown_option', $index, $donations, $donors, $forms, $value );
/**
* Fire the action
* You can use this filter to add new options.
*
* @since 1.8.15
*/
do_action( 'give_import_dropdown_option', $index, $value, $mapto, $current_mapto );
?>
</select>
<?php
}

/**
* Print the option html for select in importer
*
* @since 1.8.15
* @access public
*
* @param array $options
* @param string $current_mapto
* @param bool $value
*
* @return void
*/
public function get_dropdown_option_html( $options, $current_mapto, $value = false ) {
foreach ( $options as $option => $option_value ) {
$option_value_texts = (array) $option_value;
$option_text = $option_value_texts[0];

$checked = ( ( $current_mapto === $option ) ? 'selected' : false );
if ( empty( $checked ) ) {
foreach ( $option_value_texts as $option_value_text ) {
$checked = $this->selected( $option_value_text, $value );
if ( $checked ) {
break;
}
}
}

echo sprintf(
'<option value="%1$s" %2$s >%3$s</option>',
$option,
$checked,
$option_text
);
}
}

/**
* Get column count of csv file.
*
Expand Down
14 changes: 11 additions & 3 deletions includes/import-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ function give_import_get_user_from_csv( $data, $import_setting = array() ) {
*/
function give_import_default_options() {
/**
* Filter to modify defalut option in the import dropdown
* Filter to modify default option in the import dropdown
*
* @since 1.8.13
*
Expand Down Expand Up @@ -379,8 +379,16 @@ function give_import_donations_options() {
'line2' => __( 'Address 2', 'give' ),
'city' => __( 'City', 'give' ),
'state' => __( 'State', 'give' ),
'country' => __( 'Country', 'give' ),
'zip' => __( 'Zip', 'give' ),
'country' => array(
__( 'Country', 'give' ),
__( 'County', 'give' ),
__( 'Region', 'give' ),
__( 'Province', 'give' ),
),
'zip' => array(
__( 'Zip', 'give' ),
__( 'Postal Code', 'give' ),
),
'email' => __( 'Donor Email', 'give' ),
'post_status' => __( 'Donation Status', 'give' ),
'gateway' => __( 'Payment Method', 'give' ),
Expand Down

0 comments on commit e8765e1

Please sign in to comment.