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

Add support to use import members from CSV file Add On combined with … #31

Open
wants to merge 15 commits into
base: dev
Choose a base branch
from
Open
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
44 changes: 44 additions & 0 deletions includes/admin.php

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

I can't find the required csv structure for using this code.
Can you help me ?

Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,47 @@ function pmprogroupacct_plugin_row_meta($links, $file) {
return $links;
}
add_filter('plugin_row_meta', 'pmprogroupacct_plugin_row_meta', 10, 2);


/**
* Import group account member associations when using the Import Users From CSV plugin.
*
* @param WP_User $user The user object that was imported.
* @param int $membership_id The membership level ID that was imported.
* @param MemberOrder|null $order The order object that was created during import. Null if no order is created.
* @since TBD
*/
function pmprogroupacct_pmproiucsv_post_user_import( $user, $membership_id, $order ) {
global $wpdb;

$group_level_settings = pmprogroupacct_get_settings_for_level( $membership_id );
$parent_group = PMProGroupAcct_Group::get_group_by_parent_user_id_and_parent_level_id( $user->ID, $membership_id );
$group_id = $user->pmprogroupacct_group_id; // Child accounts would pass through the Group ID.
$seats = ! empty( $user->pmprogroupacct_group_total_seats ) ? intval( $user->pmprogroupacct_group_total_seats ) : $group_level_settings['max_seats'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we always want to default to the max seats for a group, or if the number of seats is not specified, do we instead just not want to alter group seat data?


// Add user to group if their level is a parent level and create the group if it doesn't exist.
if ( ! empty( $parent_group ) ) {
//Update seats if the user has a total seats value from CSV.
$parent_group->update_group_total_seats( $seats );
} elseif ( empty( $group_id ) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is tricky. I think we only want to create a new group if:

  1. The level being imported is a group level
  2. The number of seats for the group to be created with is specified

// There is not already a group for this user and level. Let's create one.
PMProGroupAcct_Group::create( $user->ID, $membership_id, $seats );
}

// Add the child account if the level is a child level and passed through a group ID.
if ( ! empty( $group_id ) && pmprogroupacct_level_can_be_claimed_using_group_codes( $membership_id ) ) {

// Let's set all previous instances to "inactive" before trying to insert the child record.
$wpdb->query(
$wpdb->prepare(
"UPDATE $wpdb->pmprogroupacct_group_members SET group_child_status = 'inactive' WHERE group_child_user_id = %d AND group_child_level_id = %d",
$user->ID,
$membership_id
)
);

// Add them back.
PMProGroupAcct_Group_Member::create( $user->ID, $membership_id, $group_id );
}
}
add_action( 'pmproiucsv_after_member_import', 'pmprogroupacct_pmproiucsv_post_user_import', 10, 3 );