From: Steve Sutton Date: Fri, 17 Feb 2017 20:37:28 +0000 (-0500) Subject: Adding table for streamsend cache X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=33bc2d4d76c8612749a57ca3a566efe2cde195cb;p=WP-Plugins%2Fglm-member-db-communicator.git Adding table for streamsend cache Add table for the streamsend cache. --- diff --git a/defines.php b/defines.php index af5ea62..ecd1717 100644 --- a/defines.php +++ b/defines.php @@ -13,7 +13,7 @@ define('GLM_MEMBERS_COMMUNICATOR_PLUGIN_SLUG', 'glm-member-db-communicator'); // Database table prefixes - change if using add-on tables global $wpdb; -define('GLM_MEMBERS_COMMUNICATOR_PLUGIN_DB_PREFIX', $wpdb->prefix.'glmMembersCommunicator'); +define('GLM_MEMBERS_COMMUNICATOR_PLUGIN_DB_PREFIX', $wpdb->prefix.'glm_membersCommunicator_'); define('GLM_MEMBERS_COMMUNICATOR_PLUGIN_ACTIVE_DB_OPTION', 'glmMembersCommunicatorDbVersion'); // Determine which system we're running on - If not provided, assume PRODUCTION diff --git a/models/admin/communicator/index.php b/models/admin/communicator/index.php index 4393156..3ece396 100644 --- a/models/admin/communicator/index.php +++ b/models/admin/communicator/index.php @@ -29,7 +29,7 @@ */ //define('STREAMSEND_DEFAULT_DELIVER_WELCOME', 'false'); -class GlmMembersAdmin_communicator_index // extends GlmDataCommunicator +class GlmMembersAdmin_communicator_index { /** @@ -74,21 +74,11 @@ class GlmMembersAdmin_communicator_index // extends GlmDataCommunicator */ public function __construct ($wpdb, $config) { - // Save WordPress Database object $this->wpdb = $wpdb; // Save plugin configuration object $this->config = $config; - - /* - * Run constructor for the Communicator data class - * - * Note, the third parameter is a flag that indicates to the Contacts - * data class that it should flag a group of fields as 'view_only'. - */ - //parent::__construct(false, false, true); - } public function modelAction($actionData = false) @@ -116,7 +106,7 @@ class GlmMembersAdmin_communicator_index // extends GlmDataCommunicator if ( isset( $memberInfo['categories'] ) ) { $cats = array(); foreach ( $memberInfo['categories'] as $cat ) { - $cats[] = $cat['name']; + $cats[] = $cat['parent_name'] . '/' . $cat['name']; } $categories = implode( '|', $cats ); } @@ -133,12 +123,18 @@ class GlmMembersAdmin_communicator_index // extends GlmDataCommunicator 'member-type' => 'Member', ); //echo '
$contactData: ' . print_r( $contactData, true ) . '
'; + //break; if ( $ret->contact ) { - echo '
$ret->contact: ' . print_r( $ret->contact, true ) . '
'; + //echo '
$ret->contact: ' . print_r( $ret->contact, true ) . '
'; if ( $memberInfo['status']['value'] == 10 ) { // Update Contact if member is active + $streamsend->contactUpdate( + $ret->contact->id, + $contactData + ); } else { // Delete Contact if member is inactive + $streamsend->contactDelete( $memberInfo['email'] ); } } else { // Add Contact if member is active @@ -155,18 +151,60 @@ class GlmMembersAdmin_communicator_index // extends GlmDataCommunicator break; case 'memberContact': + $memberContact = $actionData['memberContact']['fieldData']; + //echo '
$memberContact: ' . print_r( $memberContact, true ) . '
'; + if ( isset( $memberContact['email'] ) && $memberContact['email'] ) { + $ret = $streamsend->contactSearch( $memberContact['email'] ); + $contactData = array( + 'email-address' => $memberContact['email'], + 'company' => $memberContact['ref_dest_name'], + 'address1' => $memberContact['addr1'], + 'address2' => $memberContact['addr2'], + 'city' => $memberContact['city']['name'], + 'stateprovince' => $memberContact['state']['name'], + 'postal-code' => $memberContact['zip'], + 'phone-number' => $memberContact['office_phone'], + 'member-type' => 'Member Contact', + ); + if ( $ret->contact ) { + echo '
$ret->contact: ' . print_r( $ret->contact, true ) . '
'; + if ( $memberContact['active']['value'] == 1 ) { + // Update Contact if member is active + $streamsend->contactUpdate( + $ret->contact->id, + $contactData + ); + } else { + // Delete Contact if member is inactive + $streamsend->contactDelete( $memberContact['email'] ); + } + } else { + // Add Contact if member is active + if ( $memberContact['active']['value'] == 1 ) { + $contacts = $streamsend->contactCreate( + $contactData, + STREAMSEND_DEFAULT_ACTIVATE, + STREAMSEND_DEFAULT_DELIVER_ACTIVATION, + STREAMSEND_DEFAULT_DELIVER_WELCOME + ); + } + } + } + break; + case 'deleteMemberInfo': + $memberInfo = $actionData['memberInfo']['fieldData']; + $streamsend->contactDelete( $memberInfo['email'] ); + break; + case 'deleteMemberContact': + $memberContact = $actionData['memberContact']['fieldData']; + $streamsend->contactDelete( $memberContact['email'] ); break; } } - //echo '
$config: ' . print_r( $config, true ) . '
'; - return array( 'status' => true, 'modelRedirect' => false, ); - } - - } diff --git a/models/admin/management/communicator.php b/models/admin/management/communicator.php index 486e904..ae2c43f 100644 --- a/models/admin/management/communicator.php +++ b/models/admin/management/communicator.php @@ -122,67 +122,83 @@ class GlmMembersAdmin_management_communicator extends GlmDataCommunicatorManagem switch ($option) { - case 'settings': + case 'sync': + echo '

Please stand by whilst we sync you!

'; + + // Determine if current user can edit configurations + if (!current_user_can('glm_members_management')) { + return array( + 'status' => false, + 'menuItemRedirect' => 'error', + 'modelRedirect' => 'index', + 'view' => 'admin/error/index.html', + 'data' => array( + 'reason' => 'User does not have rights to make configuration changes.' + ) + ); + } + break; + + case 'settings': + + default: + + // Make sure option is set if default + $option = 'settings'; + + // Determine if current user can edit configurations + if (!current_user_can('glm_members_management')) { + return array( + 'status' => false, + 'menuItemRedirect' => 'error', + 'modelRedirect' => 'index', + 'view' => 'admin/error/index.html', + 'data' => array( + 'reason' => 'User does not have rights to make configuration changes.' + ) + ); + } + + // Check for submission option + $option2 = ''; + if (isset($_REQUEST['option2'])) { + $option2 = $_REQUEST['option2']; + } + + switch($option2) { + + // Update the settings and redisplay the form + case 'submit': + + // Update the event management settings + $communicator_settings = $this->updateEntry(1); + if ($communicator_settings['status']) { + $settings_updated = true; + } else { + $settings_update_error = true; + } + + break; + + // Default is to get the current settings and display the form + default: + + + break; + + } + + break; - default: - - // Make sure option is set if default - $option = 'settings'; - - // Determine if current user can edit configurations - if (!current_user_can('glm_members_management')) { - return array( - 'status' => false, - 'menuItemRedirect' => 'error', - 'modelRedirect' => 'index', - 'view' => 'admin/error/index.html', - 'data' => array( - 'reason' => 'User does not have rights to make configuration changes.' - ) - ); - } - - // Check for submission option - $option2 = ''; - if (isset($_REQUEST['option2'])) { - $option2 = $_REQUEST['option2']; - } - - switch($option2) { - - // Update the settings and redisplay the form - case 'submit': - - // Update the event management settings - $communicator_settings = $this->updateEntry(1); - if ($communicator_settings['status']) { - $settings_updated = true; - } else { - $settings_update_error = true; - } - - break; - - // Default is to get the current settings and display the form - default: - - // Try to get the first (should be only) entry for general settings. - $communicator_settings = $this->editEntry(1); - //echo '
$communicator_settings: ' . print_r( $communicator_settings, true ) . '
'; - - if ($communicator_settings === false) { - - if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { - glmMembersAdmin::addNotice("  /models/admin/management/communicator.php: Unable to load communicator management settings.", 'Alert'); - } - - } - - break; + } - } + // Try to get the first (should be only) entry for general settings. + $communicator_settings = $this->editEntry(1); - break; + if ($communicator_settings === false) { + if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) { + glmMembersAdmin::addNotice("  /models/admin/management/communicator.php: Unable to load communicator management settings.", 'Alert'); + } } @@ -191,10 +207,10 @@ class GlmMembersAdmin_management_communicator extends GlmDataCommunicatorManagem // Compile template data $template_data = array( - 'option' => $option, - 'settingsUpdated' => $settings_updated, - 'settingsUpdateError' => $settings_update_error, - 'communicatorSettings' => $communicator_settings, + 'option' => $option, + 'settingsUpdated' => $settings_updated, + 'settingsUpdateError' => $settings_update_error, + 'communicatorSettings' => $communicator_settings, ); // Return status, suggested view, and data to controller diff --git a/setup/adminHooks.php b/setup/adminHooks.php index 6ac8206..4855588 100644 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -27,16 +27,16 @@ */ // Adding Action for when the memberInfo record is saved (new or update) add_action('glm-member-db-memberinfosave', function($member){ - $memberData = array( + $this->controller( 'communicator', 'index', array( 'type' => 'memberInfo', 'memberInfo' => $member - ); - $this->controller( 'communicator', 'index', $memberData ); -}, 10, 2); + ) ); +}, 10, 1); // Adding Action for when the Member Contact record is saved (new or update) add_action('glm-member-db-membercontactsave', function($contact){ - // Code here for hook - echo '

Contact action hook

'; - echo '
$contact: ' . print_r( $contact, true ) . '
'; + $this->controller( 'communicator', 'index', array( + 'type' => 'memberContact', + 'memberContact' => $contact + ) ); }, 10, 1); diff --git a/setup/databaseScripts/create_database_V0.0.1.sql b/setup/databaseScripts/create_database_V0.0.1.sql index 76f87d9..292a4d1 100644 --- a/setup/databaseScripts/create_database_V0.0.1.sql +++ b/setup/databaseScripts/create_database_V0.0.1.sql @@ -22,7 +22,7 @@ CREATE TABLE {prefix}management ( enable_constant_contact BOOLEAN NULL, -- Constant Contact On Off Flag constant_contact_password TINYTEXT NULL, -- Constant Contact Password constant_contact_api_key TINYTEXT NULL, -- Constant Contact API Key - constant_contact_login TINYTEXT NULL, -- Constant Contact Login + constant_contact_login TINYTEXT NULL, -- Constant Contact Login constant_contact_api_path TINYTEXT NULL, -- Constant Contact API Path constant_contact_list TINYTEXT NULL, -- Constant Contact List ID enable_mailchimp BOOLEAN NULL, -- MailChimp On Off @@ -39,3 +39,16 @@ INSERT INTO {prefix}management VALUES ( 1, false, false, false ) ; + +---- + +-- StreamSend Cache Table +CREATE TABLE {prefix}streamsend_cache ( + id INT NOT NULL AUTO_INCREMENT, + field_id INT NOT NULL, -- Field id for Member Category + field_name TINYTEXT NOT NULL, -- Field Name from StreamSend + option_id INT NOT NULL, -- StreamSend field id + option_name TINYTEXT NOT NULL, -- StreamSend option name + category_id INT NOT NULL, -- Member Category id + PRIMARY KEY (id) +); diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php index 03a3548..0537496 100644 --- a/setup/databaseScripts/dbVersions.php +++ b/setup/databaseScripts/dbVersions.php @@ -14,6 +14,6 @@ */ $glmMembersCommunicatorDbVersions = array( - '0.0.1' => array('version' => '0.0.1', 'tables' => 1), + '0.0.1' => array('version' => '0.0.1', 'tables' => 2), ); diff --git a/views/admin/management/communicator.html b/views/admin/management/communicator.html index 95b932b..00e9762 100644 --- a/views/admin/management/communicator.html +++ b/views/admin/management/communicator.html @@ -7,6 +7,20 @@ + + +
+
+ + + + + + +

Sync StreamSend

+ +
+
{if $settingsUpdated}

Settings Updated

{/if}