From: Steve Sutton Date: Fri, 27 Apr 2018 20:52:52 +0000 (-0400) Subject: WIP for member types X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=23604c4eb828c2895c9d06cc74f8c5b5619af961;p=user%2Fsteve%2Fglm-member-db-migcsa.git WIP for member types working on member types --- diff --git a/models/admin/migcsa/index.php b/models/admin/migcsa/index.php index a4b7519..312a927 100644 --- a/models/admin/migcsa/index.php +++ b/models/admin/migcsa/index.php @@ -119,6 +119,10 @@ class GlmMembersAdmin_migcsa_index } switch( $option ) { + case 'updateMemberTypes': + $view = 'memberTypes'; + $response = $this->updateMemberTypes(); + break; case 'customFields': $view = 'customFields'; $response = $this->importCustomFields(); @@ -159,6 +163,80 @@ class GlmMembersAdmin_migcsa_index return $response; } + public function updateMemberTypes() + { + $total_members = 0; + $members_updated = 0; + $accounts_updated = 0; + + // Get the invoice type data + $invoice_type_data = $this->wpdb->get_results( + "SELECT * + FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoice_types + WHERE member_type != 0", + ARRAY_A + ); + $invoice_types = array(); + if ( $invoice_type_data ) { + foreach ( $invoice_type_data as $iType ) { + $invoice_types[$iType['member_type']] = $iType['id']; + } + } + // return '
$invoice_types: ' . print_r( $invoice_types, true ) . '
'; + + $new_member_types = array( + 'H' => 7, + 'C' => 3, + 'SA' => 8, + 'I' => 10, + 'AFF' => 6, + 'EM' => 4, + 'SM' => 2, + 'A' => 1, + 'R' => 9, + 'E' => 5, + 'AA' => 13, + ); + $sql = " + SELECT member_id,member_name,member_class + FROM member + WHERE member_class != ''"; + $stmt = $this->dbh->query( $sql ); + $members = $stmt->fetchAll(); + // for each one get the new member id based on old_member_id and update the member_type + foreach ( $members as $member ) { + $new_member_id = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT id + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members + WHERE old_member_id = %d", + $member['member_id'] + ) + ); + echo '
$new_member_id: ' . print_r( $new_member_id, true ) . '
'; + if ( $new_member_id ) { + $new_member_type = $new_member_types[$member['member_class']]; + // We found a new member id then update member_type + $this->wpdb->update( + GLM_MEMBERS_PLUGIN_DB_PREFIX . 'members', + array( 'member_type' => $new_member_type ), + array( 'id' => $new_member_id ) + ); + $members_updated++; + $invoice_type = ( isset( $invoice_types[$new_member_type] ) ) ? $invoice_types[$new_member_type] : 0; + $this->wpdb->update( + GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'accounts', + array( 'invoice_type' => $invoice_type ), + array( 'ref_dest' => $new_member_id ) + ); + $accounts_updated++; + } + } + echo '
$members_updated: ' . print_r( $members_updated, true ) . '
'; + echo '
$accounts_updated: ' . print_r( $accounts_updated, true ) . '
'; + return '
$members: ' . print_r( $members, true ) . '
'; + } + public function importEmployees() { $sql = " @@ -309,6 +387,10 @@ class GlmMembersAdmin_migcsa_index 'create_time' => date( 'Y-m-d H:i:s' ), 'ref_type' => $this->config['ref_type_numb']['Member'], 'ref_dest' => $new_member_id, + 'addr1' => $member['mailing_address'], + 'city' => $mailing_city_id, + 'state' => $member['state_abb'], + 'zip' => $member['mailing_zip'], ); $contact['format'] = array( '%d', // active @@ -323,7 +405,11 @@ class GlmMembersAdmin_migcsa_index '%s', // notes '%s', // create_time '%d', // ref_type - '%d' // ref_dest + '%d', // ref_dest + '%s', // addr1 + '%s', // city + '%s', // state + '%s', // zip ); $new_contact_id = $this->importMemberContactData( $contact ); $response .= '
$new_contact_id: ' . print_r( $new_contact_id, true ) . '
'; diff --git a/views/admin/migcsa/index.html b/views/admin/migcsa/index.html index 48ca8fb..d33f1a4 100644 --- a/views/admin/migcsa/index.html +++ b/views/admin/migcsa/index.html @@ -6,3 +6,5 @@ Import Custom Fields
Import Employees +
+Update Member Types diff --git a/views/admin/migcsa/memberTypes.html b/views/admin/migcsa/memberTypes.html new file mode 100644 index 0000000..1a33819 --- /dev/null +++ b/views/admin/migcsa/memberTypes.html @@ -0,0 +1,6 @@ +

Update Member Types for members

+ +{if $response} + {$response} +{/if} +