From: Steve Sutton Date: Thu, 26 Apr 2018 20:39:16 +0000 (-0400) Subject: Expired users X-Git-Tag: v1.0.0^2~31 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=b0c57218e2d4953db469b7671572b98025c550cc;p=WP-Plugins%2Fglm-member-db-billing.git Expired users Deal with wordpress user also when updating the contact_roles. --- diff --git a/classes/billingSupport.php b/classes/billingSupport.php index 821e46a..697ee6d 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -1377,18 +1377,17 @@ class GlmBillingSupport // Record the payment. $this->recordPayment( $payment_id, $account_id, $amount, $invoice_id ); - // $errors[] = $ccResult['statusText']; - // $errors[] = $ccResult['description']; - - // Need to update the members account renewal_date - // $this->updateAccountRenewalDate( $account_id ); + // Set the contact_role for the member contact so they can login now. + if ( $account_id ) { + $this->setMemberAccountActive( $account_id ); + } + // Set the contact_role (employees) for the member contact so they can login now. + if ( isset( $employees ) && is_array( $employees ) && !empty( $employees ) ) { + foreach ( $employees as $emp_account_id ) { + $this->setMemberAccountActive( $emp_account_id ); + } + } - // Need to update any employees renewal dates - // if ( isset( $employees ) && is_array( $employees ) && !empty( $employees ) ) { - // foreach ( $employees as $employee ) { - // $this->updateAccountRenewalDate( $employee ); - // } - // } $errors = $result['errors']; @@ -1400,6 +1399,40 @@ class GlmBillingSupport } + /** + * Set the member contact for this account as active user now. + * Set member contact to contact_role = 20 + */ + public function setMemberAccountActive( $account_id ) + { + $activeRole = $this->config['contact_role_numb']['EntityManager']; + $this->wpdb->query( + $this->wpdb->prepare( + "UPDATE " . GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . "contacts + SET contact_role = " . $activeRole . " + WHERE ref_dest = ( + SELECT ref_dest + FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts + WHERE id = %d + )", + $account_id + ) + ); + // Get the Wordpress user for this account. + $account = $this->getAccountById( $account_id ); + if ( isset( $account['ref_dest'] ) && $account['ref_dest'] ) { + $contactID = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT id + FROM " . GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . "contacts + WHERE ref_dest = %d", + $this->memberID + ) + ); + } + + } + /** * makePayment * diff --git a/classes/notifications.php b/classes/notifications.php index e23be30..129dba2 100644 --- a/classes/notifications.php +++ b/classes/notifications.php @@ -255,14 +255,15 @@ class GlmNotifications */ public function getNotificationsByType( $type ) { - return $this->wpdb->get_var( + return $this->wpdb->get_results( $this->wpdb->prepare( "SELECT id FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "notification_types WHERE send_by_action AND send_action = %d", $this->config['send_action_numb'][$type] - ) + ), + ARRAY_A ); } diff --git a/config/plugin.ini b/config/plugin.ini index da0cffa..87ff93a 100644 --- a/config/plugin.ini +++ b/config/plugin.ini @@ -38,10 +38,12 @@ send_date_period[40] = "Year" send_action[10] = "Create Invoice" send_action[20] = "Received Payment" send_action[30] = "New Member" +send_action[40] = "New Member Admin Notice" -send_action_numb['Create Invoice'] = 10; -send_action_numb['Received Payment'] = 20; -send_action_numb['New Member'] = 30; +send_action_numb['Create Invoice'] = 10; +send_action_numb['Received Payment'] = 20; +send_action_numb['New Member'] = 30; +send_action_numb['New Member Admin Notice'] = 40; ; Send Date When send_date_when[10] = "Before" diff --git a/models/admin/ajax/billingFlagExpiredUsers.php b/models/admin/ajax/billingFlagExpiredUsers.php index 7593c40..d31eab1 100644 --- a/models/admin/ajax/billingFlagExpiredUsers.php +++ b/models/admin/ajax/billingFlagExpiredUsers.php @@ -71,24 +71,42 @@ class GlmMembersAdmin_ajax_billingFlagExpiredUsers { echo '
$actionData: ' . print_r( $actionData, true ) . '
'; - return false; - $days_after_expired = $this->config['settings']['days_after_expired']; $current_date = date( 'Y-m-d' ); + $restrictedRole = $this->config['contact_role_numb']['LogInContact']; + echo '
$restrictedRole: ' . print_r( $restrictedRole, true ) . '
'; // Update All expired accounts so they can only be in members only not admin. // Find all member contacts (by ref_dest) with accounts that are expired. // With those set their contact_role to 30 (login only) if ( $days_after_expired = filter_var( $days_after_expired, FILTER_VALIDATE_INT ) ) { + $members = $this->wpdb->get_results( + "SELECT ref_dest + FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts + WHERE renewal_date + INTERVAL 1 YEAR + INTERVAL $days_after_expired DAY <= '$current_date'", + ARRAY_A + ); + if ( isset( $members ) && $members ) { + foreach ( $members as $member ) { + echo '
$member: ' . print_r( $member, true ) . '
'; + apply_filters( + 'glm_contact_update_user_role_by_ref_dest', + '', + $member['ref_dest'], + 'glm_members_own_entity_manager', + 'glm_members_member_contact' + ); + } + } $this->wpdb->query( "UPDATE " . GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX. "contacts - SET contact_role = 30 + SET contact_role = " . $restrictedRole . " WHERE ref_dest IN ( SELECT ref_dest FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts WHERE renewal_date + INTERVAL 1 YEAR + INTERVAL $days_after_expired DAY <= '$current_date' ) - AND contact_role <> 30" + AND contact_role <> " . $restrictedRole ); } diff --git a/models/admin/member/billing.php b/models/admin/member/billing.php index c3de638..3c6ea00 100644 --- a/models/admin/member/billing.php +++ b/models/admin/member/billing.php @@ -348,40 +348,43 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling // If the member_type is changing then update member // Get current member type - // $member_id = filter_var( $_REQUEST['member'], FILTER_VALIDATE_INT ); - // if ( $member_id ) { - // $current_member_type = $this->wpdb->get_var( - // $this->wpdb->prepare( - // "SELECT member_type - // FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members - // WHERE id = %d", - // $member_id - // ) - // ); - // $new_type = filter_var( $_REQUEST['member_renewing'], FILTER_VALIDATE_INT ); - // $new_member_type = $this->wpdb->get_var( - // $this->wpdb->prepare( - // "SELECT member_type - // FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoice_types - // WHERE id = %d", - // $new_type - // ) - // ); - // if ( $current_member_type != $new_member_type ) { - // $this->update( - // GLM_MEMBERS_PLUGIN_DB_PREFIX . 'members', - // array( 'member_type' => $new_member_type ), - // array( 'id' => $member_id ), - // array( '%d' ), - // array( '%d' ) - // ); - // } - // } + $member_id = filter_var( $_REQUEST['member'], FILTER_VALIDATE_INT ); + if ( $member_id ) { + $current_member_type = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT member_type + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members + WHERE id = %d", + $member_id + ) + ); + $new_type = filter_var( $_REQUEST['member_renewing'], FILTER_VALIDATE_INT ); + $new_member_type = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT member_type + FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoice_types + WHERE id = %d", + $new_type + ) + ); + // TODO: Need to reset account invoice_type also + if ( $current_member_type != $new_member_type ) { + $this->update( + GLM_MEMBERS_PLUGIN_DB_PREFIX . 'members', + array( 'member_type' => $new_member_type ), + array( 'id' => $member_id ), + array( '%d' ), + array( '%d' ) + ); + } + } } break; case 'account': + + // Need to see if there's an account for this member. $accountID = $this->wpdb->get_var( $this->wpdb->prepare( @@ -391,6 +394,22 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling $this->memberID ) ); + + // $contactID = $this->wpdb->get_var( + // $this->wpdb->prepare( + // "SELECT id + // FROM " . GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . "contacts + // WHERE ref_dest = %d", + // $this->memberID + // ) + // ); + // echo '
$contactID: ' . print_r( $contactID, true ) . '
'; + // require_once GLM_MEMBERS_CONTACTS_PLUGIN_CLASS_PATH . '/data/dataContacts.php'; + // $Contact = new GlmDataContacts( $this->wpdb, $this->config ); + // $user_id = $Contact->getWPUserId( $contactID ); + // echo '
$user_id: ' . print_r( $user_id, true ) . '
'; + // $Contact->updateContactRole( $contactID, 'glm_members_member_contact', 'glm_members_own_entity_manager' ); + // echo '
$accountID: ' . print_r( $accountID, true ) . '
'; // Grab the employee data if ( $accountID ) { diff --git a/models/front/billing/becomeMember.php b/models/front/billing/becomeMember.php index b01821f..5c820aa 100644 --- a/models/front/billing/becomeMember.php +++ b/models/front/billing/becomeMember.php @@ -260,7 +260,7 @@ class GlmMembersFront_billing_becomeMember // extends GlmDataBilling } // 3. Setup the contact (and wpUser) // Determine the Worpress Role to be used for contact import - Using Entity Manager right now - $contactRoleNumb = $this->config['contact_role_numb']['EntityManager']; + $contactRoleNumb = $this->config['contact_role_numb']['LogInContact']; $wpRole = $this->config['contact_role_wordpress'][$contactRoleNumb]; $memberContactEmail = filter_var( $_REQUEST['email'], FILTER_VALIDATE_EMAIL ); $memberLogin = filter_var( $_REQUEST['username'] ); @@ -463,10 +463,23 @@ class GlmMembersFront_billing_becomeMember // extends GlmDataBilling // Check for any notices for new members and send them out for this new member. $Notification = new GlmNotifications( $this->wpdb, $this->config ); - $notification = $Notification->getNotificationsByType( 'New Member' ); - if ( $notification ) { - $Notification->sendEmailNotification( $notification, $accountID ); + + // Get all new member notifications for the member and if found send them out. + $newMemberNotices = $Notification->getNotificationsByType( 'New Member' ); + if ( $newMemberNotices ) { + foreach ( $newMemberNotices as $notification ) { + $Notification->sendEmailNotification( $notification['id'], $accountID ); + } + } + + // Get all new member admin notifications for the member and if found send them out. + $adminNewMemberNotices = $Notification->getNotificationsByType( 'New Member Admin Notice' ); + if ( $adminNewMemberNotices ) { + foreach ( $adminNewMemberNotices as $notification ) { + $Notification->sendEmailNotification( $notification['id'], $accountID ); + } } + } } break; diff --git a/setup/adminHooks.php b/setup/adminHooks.php index 2c6f533..235b394 100644 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -34,22 +34,33 @@ add_filter( 1 ); -// add_filter( -// 'glm_associate_cron_request', -// function( $cron_task ){ -// $new_cron = array( -// array( -// 'menu' => 'ajax', -// 'action' => 'billingFlagExpiredUsers', -// 'daysOfWeek' => range( 1, 7 ), -// 'times' => range( 1, 24 ), -// 'params' => array() -// ) -// ); -// return array_merge( $cron_task, $new_cron ); -// } -// ); -// +/** + * Setup cron task request to run billingFlagExpiredUsers + * + * Run only once per day. Everyday. + */ +add_filter( + 'glm_associate_cron_request', + function( $cron_task ){ + $new_cron = array( + array( + 'menu' => 'ajax', + 'action' => 'billingFlagExpiredUsers', + 'daysOfWeek' => range( 1, 7 ), + // 'times' => array( 5 ), + 'times' => range( 0, 23 ), + 'params' => array() + ) + ); + return array_merge( $cron_task, $new_cron ); + } +); + +/** + * Setup cron task request to run billingSetupQueue + * + * Run only once per day. Everyday. + */ // add_filter( // 'glm_associate_cron_request', // function( $cron_task ) { @@ -58,14 +69,19 @@ add_filter( // 'menu' => 'ajax', // 'action' => 'billingSetupQueue', // 'daysOfWeek' => range( 1, 7 ), -// 'times' => range( 3 ), +// 'times' => array( 3 ), // 'params' => array() // ) // ); // return array_merge( $cron_task, $new_cron ); // } // ); -// + +/** + * Setup cron task request to run billingRunQueue + * + * Run only once per day. Everyday. + */ // add_filter( // 'glm_associate_cron_request', // function( $cron_task ) { @@ -74,7 +90,7 @@ add_filter( // 'menu' => 'ajax', // 'action' => 'billingRunQueue', // 'daysOfWeek' => range( 1, 7 ), -// 'times' => range( 4 ), +// 'times' => array( 4 ), // 'params' => array() // ) // ); diff --git a/setup/commonHooks.php b/setup/commonHooks.php index a9b4363..95b351b 100644 --- a/setup/commonHooks.php +++ b/setup/commonHooks.php @@ -47,6 +47,7 @@ add_filter( 'glm-billing-get-account-status', function( $content, $account_id ){ return $content; } // See if this member account has a paid member type + require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH.'/billingSupport.php'; $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); $paid_mem_type = $BillingSupport->getMembersInvoiceTypeByRefDest( $account['ref_dest'] ); if ( !$paid_mem_type ) { diff --git a/views/admin/settings/notificationTypes.html b/views/admin/settings/notificationTypes.html index 38140a6..a84baec 100644 --- a/views/admin/settings/notificationTypes.html +++ b/views/admin/settings/notificationTypes.html @@ -185,7 +185,7 @@ - + @@ -201,24 +201,10 @@ {else} {/if} - + @@ -249,67 +235,12 @@
IDID Notification Subject Trigger
{$t.id}{$t.id} {$t.subject}